(mu_getpwuid): new function. Allows
to use overloaded getpwuid() in the same way as mu_getpwnam() does it for getpwnam(). (mu_register_getpwuid): Overload getpwuid function.
Showing
1 changed file
with
35 additions
and
1 deletions
... | @@ -257,7 +257,7 @@ mu_get_homedir (void) | ... | @@ -257,7 +257,7 @@ mu_get_homedir (void) |
257 | { | 257 | { |
258 | struct passwd *pwd; | 258 | struct passwd *pwd; |
259 | 259 | ||
260 | pwd = getpwuid (getuid ()); | 260 | pwd = mu_getpwuid (getuid ()); |
261 | if (!pwd) | 261 | if (!pwd) |
262 | return NULL; | 262 | return NULL; |
263 | homedir = pwd->pw_dir; | 263 | homedir = pwd->pw_dir; |
... | @@ -365,6 +365,40 @@ mu_getpwnam (const char *name) | ... | @@ -365,6 +365,40 @@ mu_getpwnam (const char *name) |
365 | return p; | 365 | return p; |
366 | } | 366 | } |
367 | 367 | ||
368 | static list_t _app_getpwuid = NULL; | ||
369 | |||
370 | void | ||
371 | mu_register_getpwuid (struct passwd *(*fun) __P((uid_t))) | ||
372 | { | ||
373 | if (!_app_getpwuid && list_create (&_app_getpwuid)) | ||
374 | return; | ||
375 | list_append (_app_getpwuid, fun); | ||
376 | } | ||
377 | |||
378 | struct passwd * | ||
379 | mu_getpwuid (uid_t uid) | ||
380 | { | ||
381 | struct passwd *p; | ||
382 | iterator_t itr; | ||
383 | |||
384 | p = getpwuid (uid); | ||
385 | |||
386 | if (!p && iterator_create (&itr, _app_getpwuid) == 0) | ||
387 | { | ||
388 | struct passwd *(*fun) __P((uid_t)); | ||
389 | for (iterator_first (itr); !p && !iterator_is_done (itr); | ||
390 | iterator_next (itr)) | ||
391 | { | ||
392 | iterator_current (itr, (void **)&fun); | ||
393 | p = (*fun) (uid); | ||
394 | } | ||
395 | |||
396 | iterator_destroy (&itr); | ||
397 | } | ||
398 | return p; | ||
399 | } | ||
400 | |||
401 | |||
368 | int mu_virtual_domain; | 402 | int mu_virtual_domain; |
369 | 403 | ||
370 | #ifdef USE_VIRTUAL_DOMAINS | 404 | #ifdef USE_VIRTUAL_DOMAINS | ... | ... |
-
Please register or sign in to post a comment