Changeset View
Changeset View
Standalone View
Standalone View
ksysguardd/PWUIDCache.c
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | |||||
46 | 46 | | |||
47 | static int uidCmp( void* p1, void* p2 ) | 47 | static int uidCmp( void* p1, void* p2 ) | ||
48 | { | 48 | { | ||
49 | return ( ((CachedPWUID*)p1)->uid - ((CachedPWUID*)p2)->uid ); | 49 | return ( ((CachedPWUID*)p1)->uid - ((CachedPWUID*)p2)->uid ); | ||
50 | } | 50 | } | ||
51 | 51 | | |||
52 | void PWUIDCache_cleanup( void* c ) | 52 | void PWUIDCache_cleanup( void* c ) | ||
53 | { | 53 | { | ||
54 | if ( c ) { | 54 | if ( c ) | ||
55 | if ( ((CachedPWUID*)c)->uName ) | | |||
56 | free ( ((CachedPWUID*)c)->uName ); | 55 | free ( ((CachedPWUID*)c)->uName ); | ||
57 | free ( c ); | 56 | free ( c ); | ||
58 | } | 57 | } | ||
59 | } | | |||
60 | 58 | | |||
61 | void initPWUIDCache() | 59 | void initPWUIDCache() | ||
62 | { | 60 | { | ||
63 | UIDCache = new_ctnr(); | 61 | UIDCache = new_ctnr(); | ||
64 | } | 62 | } | ||
65 | 63 | | |||
66 | void exitPWUIDCache() | 64 | void exitPWUIDCache() | ||
67 | { | 65 | { | ||
Show All 27 Lines | 92 | if ( ( idx = search_ctnr( UIDCache, uidCmp, &key ) ) < 0 ) { | |||
95 | struct passwd* pwent; | 93 | struct passwd* pwent; | ||
96 | 94 | | |||
97 | /* User id is not yet known */ | 95 | /* User id is not yet known */ | ||
98 | entry = (CachedPWUID*)malloc( sizeof( CachedPWUID ) ); | 96 | entry = (CachedPWUID*)malloc( sizeof( CachedPWUID ) ); | ||
99 | entry->tStamp = stamp; | 97 | entry->tStamp = stamp; | ||
100 | entry->uid = uid; | 98 | entry->uid = uid; | ||
101 | 99 | | |||
102 | pwent = getpwuid( uid ); | 100 | pwent = getpwuid( uid ); | ||
103 | if ( pwent ) | 101 | entry->uName = strdup( pwent ? pwent->pw_name : "?" ); | ||
104 | entry->uName = strdup( pwent->pw_name ); | | |||
105 | else | | |||
106 | entry->uName = strdup( "?" ); | | |||
107 | 102 | | |||
108 | push_ctnr( UIDCache, entry ); | 103 | push_ctnr( UIDCache, entry ); | ||
109 | bsort_ctnr( UIDCache, uidCmp ); | 104 | bsort_ctnr( UIDCache, uidCmp ); | ||
110 | } else { | 105 | } else { | ||
111 | /* User is is already known */ | 106 | /* User is is already known */ | ||
112 | entry = get_ctnr( UIDCache, idx ); | 107 | entry = get_ctnr( UIDCache, idx ); | ||
113 | } | 108 | } | ||
114 | 109 | | |||
115 | return entry->uName; | 110 | return entry->uName; | ||
116 | } | 111 | } |