6 static struct Npusercache
{
9 } usercache
= { PTHREAD_MUTEX_INITIALIZER
, 0 };
11 static struct Npgroupcache
{
14 } groupcache
= { PTHREAD_MUTEX_INITIALIZER
, 0 };
17 np_simpl_uname2user(Npuserpool
*up
, char *uname
)
21 pthread_mutex_lock(&usercache
.lock
);
22 for(u
= usercache
.users
; u
; u
= u
->next
) {
23 if(strcmp(u
->uname
, uname
) == 0)
27 u
= np_malloc(sizeof(*u
) + strlen(uname
) + 1);
28 pthread_mutex_init(&u
->lock
, NULL
);
32 u
->uname
= (char *)u
+ sizeof(*u
);
33 strcpy(u
->uname
, uname
);
38 u
->dfltgroup
= (*up
->gname2group
)(up
, uname
);
40 u
->next
= usercache
.users
;
44 pthread_mutex_unlock(&usercache
.lock
);
49 np_simpl_uid2user(Npuserpool
*up
, u32 uid
)
55 np_simpl_gname2group(Npuserpool
*up
, char *gname
)
59 pthread_mutex_lock(&groupcache
.lock
);
60 for(g
= groupcache
.groups
; g
; g
= g
->next
) {
61 if(strcmp(g
->gname
, gname
) == 0)
66 g
= np_malloc(sizeof(*g
) + strlen(gname
) + 1);
67 pthread_mutex_init(&g
->lock
, NULL
);
71 g
->gname
= (char *)g
+ sizeof(*g
);
72 strcpy(g
->gname
, gname
);
74 g
->next
= groupcache
.groups
;
75 groupcache
.groups
= g
;
78 pthread_mutex_unlock(&groupcache
.lock
);
83 np_simpl_gid2group(Npuserpool
*up
, u32 gid
)
89 np_simpl_ismember(Npuserpool
*up
, Npuser
*u
, Npgroup
*g
)
91 return 0; // XXX something fancier?
95 np_simpl_udestroy(Npuserpool
*up
, Npuser
*u
)
100 np_simpl_gdestroy(Npuserpool
*up
, Npgroup
*g
)
104 static Npuserpool upool
= {
108 np_simpl_gname2group
,
115 Npuserpool
*np_default_users
= &upool
;