(mu_register_getpwnam,mu_register_getpwuid,mu_getpwnam,mu_getpwuid,mu_virtual_domain): Removed.
Showing
2 changed files
with
25 additions
and
110 deletions
... | @@ -59,17 +59,6 @@ extern char * mu_tilde_expansion __P ((const char *ref, const char *delim, const | ... | @@ -59,17 +59,6 @@ extern char * mu_tilde_expansion __P ((const char *ref, const char *delim, const |
59 | 59 | ||
60 | extern size_t mu_cpystr __P ((char *dst, const char *src, size_t size)); | 60 | extern size_t mu_cpystr __P ((char *dst, const char *src, size_t size)); |
61 | 61 | ||
62 | struct passwd; | ||
63 | |||
64 | extern void mu_register_getpwnam __P((struct passwd *(*fun) __P((const char *)))); | ||
65 | extern void mu_register_getpwuid __P((struct passwd *(*fun) __P((uid_t *)))); | ||
66 | extern struct passwd * mu_getpwnam __P((const char *name)); | ||
67 | extern struct passwd * mu_getpwuid __P((uid_t uid)); | ||
68 | |||
69 | extern int mu_virtual_domain; | ||
70 | |||
71 | extern struct passwd * getpwnam_virtual __P((const char *u)); | ||
72 | |||
73 | /* Get the host name, doing a gethostbyname() if possible. | 62 | /* Get the host name, doing a gethostbyname() if possible. |
74 | * | 63 | * |
75 | * It is the caller's responsibility to free host. | 64 | * It is the caller's responsibility to free host. | ... | ... |
... | @@ -45,6 +45,7 @@ | ... | @@ -45,6 +45,7 @@ |
45 | #include <mailutils/iterator.h> | 45 | #include <mailutils/iterator.h> |
46 | #include <mailutils/mutil.h> | 46 | #include <mailutils/mutil.h> |
47 | #include <mailutils/parse822.h> | 47 | #include <mailutils/parse822.h> |
48 | #include <mailutils/mu_auth.h> | ||
48 | 49 | ||
49 | #include "mu_asprintf.h" | 50 | #include "mu_asprintf.h" |
50 | 51 | ||
... | @@ -264,14 +265,15 @@ char * | ... | @@ -264,14 +265,15 @@ char * |
264 | mu_get_homedir (void) | 265 | mu_get_homedir (void) |
265 | { | 266 | { |
266 | char *homedir = getenv ("HOME"); | 267 | char *homedir = getenv ("HOME"); |
267 | if (!homedir) | 268 | if (homedir) |
269 | homedir = strdup (homedir); | ||
270 | else | ||
268 | { | 271 | { |
269 | struct passwd *pwd; | 272 | struct mu_auth_data *auth = mu_get_auth_by_uid (getuid ()); |
270 | 273 | if (!auth) | |
271 | pwd = mu_getpwuid (getuid ()); | ||
272 | if (!pwd) | ||
273 | return NULL; | 274 | return NULL; |
274 | homedir = pwd->pw_dir; | 275 | homedir = strdup (auth->dir); |
276 | mu_auth_data_free (auth); | ||
275 | } | 277 | } |
276 | return homedir; | 278 | return homedir; |
277 | } | 279 | } |
... | @@ -367,10 +369,11 @@ mu_tilde_expansion (const char *ref, const char *delim, const char *homedir) | ... | @@ -367,10 +369,11 @@ mu_tilde_expansion (const char *ref, const char *delim, const char *homedir) |
367 | strcat (s, p); | 369 | strcat (s, p); |
368 | free (--p); | 370 | free (--p); |
369 | p = s; | 371 | p = s; |
372 | free (homedir); | ||
370 | } | 373 | } |
371 | else | 374 | else |
372 | { | 375 | { |
373 | struct passwd *pw; | 376 | struct mu_auth_data *auth; |
374 | char *s = p; | 377 | char *s = p; |
375 | char *name; | 378 | char *name; |
376 | while (*s && *s != delim[0]) | 379 | while (*s && *s != delim[0]) |
... | @@ -378,15 +381,17 @@ mu_tilde_expansion (const char *ref, const char *delim, const char *homedir) | ... | @@ -378,15 +381,17 @@ mu_tilde_expansion (const char *ref, const char *delim, const char *homedir) |
378 | name = calloc (s - p + 1, 1); | 381 | name = calloc (s - p + 1, 1); |
379 | memcpy (name, p, s - p); | 382 | memcpy (name, p, s - p); |
380 | name [s - p] = '\0'; | 383 | name [s - p] = '\0'; |
381 | pw = mu_getpwnam (name); | 384 | |
385 | auth = mu_get_auth_by_name (name); | ||
382 | free (name); | 386 | free (name); |
383 | if (pw) | 387 | if (auth) |
384 | { | 388 | { |
385 | char *buf = calloc (strlen (pw->pw_dir) + strlen (s) + 1, 1); | 389 | char *buf = calloc (strlen (auth->dir) + strlen (s) + 1, 1); |
386 | strcpy (buf, pw->pw_dir); | 390 | strcpy (buf, auth->dir); |
387 | strcat (buf, s); | 391 | strcat (buf, s); |
388 | free (--p); | 392 | free (--p); |
389 | p = buf; | 393 | p = buf; |
394 | mu_auth_data_free (auth); | ||
390 | } | 395 | } |
391 | else | 396 | else |
392 | p--; | 397 | p--; |
... | @@ -441,86 +446,6 @@ mu_retrieve (list_t flist, void *data) | ... | @@ -441,86 +446,6 @@ mu_retrieve (list_t flist, void *data) |
441 | return p; | 446 | return p; |
442 | } | 447 | } |
443 | 448 | ||
444 | /* getpwd support: */ | ||
445 | |||
446 | static list_t _app_getpwnam = NULL; | ||
447 | |||
448 | void | ||
449 | mu_register_getpwnam (struct passwd *(*fun) __P((const char *))) | ||
450 | { | ||
451 | mu_register_retriever (&_app_getpwnam, (mu_retrieve_fp)fun); | ||
452 | } | ||
453 | |||
454 | struct passwd * | ||
455 | mu_getpwnam (const char *name) | ||
456 | { | ||
457 | struct passwd *p = getpwnam (name); | ||
458 | return p ? p : mu_retrieve (_app_getpwnam, (void*) name); | ||
459 | } | ||
460 | |||
461 | /* getpwuid support: */ | ||
462 | |||
463 | static list_t _app_getpwuid = NULL; | ||
464 | |||
465 | void | ||
466 | mu_register_getpwuid (struct passwd *(*fun) __P((uid_t *))) | ||
467 | { | ||
468 | mu_register_retriever (&_app_getpwuid, (mu_retrieve_fp)fun); | ||
469 | } | ||
470 | |||
471 | struct passwd * | ||
472 | mu_getpwuid (uid_t uid) | ||
473 | { | ||
474 | struct passwd *p = getpwuid (uid); | ||
475 | return p ? p : mu_retrieve (_app_getpwuid, &uid); | ||
476 | } | ||
477 | |||
478 | /* Virtual domains */ | ||
479 | |||
480 | int mu_virtual_domain; | ||
481 | |||
482 | #ifdef USE_VIRTUAL_DOMAINS | ||
483 | |||
484 | struct passwd * | ||
485 | getpwnam_virtual (const char *u) | ||
486 | { | ||
487 | struct passwd *pw = NULL; | ||
488 | FILE *pfile; | ||
489 | size_t i = 0, len = strlen (u), delim = 0; | ||
490 | char *filename; | ||
491 | |||
492 | mu_virtual_domain = 0; | ||
493 | for (i = 0; i < len && delim == 0; i++) | ||
494 | if (u[i] == '!' || u[i] == ':' || u[i] == '@') | ||
495 | delim = i; | ||
496 | |||
497 | if (delim == 0) | ||
498 | return NULL; | ||
499 | |||
500 | filename = malloc (strlen (SITE_VIRTUAL_PWDDIR) + | ||
501 | strlen (&u[delim + 1]) + 2 /* slash and null byte */); | ||
502 | if (filename == NULL) | ||
503 | return NULL; | ||
504 | |||
505 | sprintf (filename, "%s/%s", SITE_VIRTUAL_PWDDIR, &u[delim + 1]); | ||
506 | pfile = fopen (filename, "r"); | ||
507 | free (filename); | ||
508 | |||
509 | if (pfile) | ||
510 | while ((pw = fgetpwent (pfile)) != NULL) | ||
511 | { | ||
512 | if (strlen (pw->pw_name) == delim && !strncmp (u, pw->pw_name, delim)) | ||
513 | { | ||
514 | mu_virtual_domain = 1; | ||
515 | break; | ||
516 | } | ||
517 | } | ||
518 | |||
519 | return pw; | ||
520 | } | ||
521 | |||
522 | #endif | ||
523 | |||
524 | int | 449 | int |
525 | mu_get_host_name (char **host) | 450 | mu_get_host_name (char **host) |
526 | { | 451 | { |
... | @@ -988,11 +913,11 @@ mu_unroll_symlink (char *out, size_t outsz, const char *in) | ... | @@ -988,11 +913,11 @@ mu_unroll_symlink (char *out, size_t outsz, const char *in) |
988 | char * | 913 | char * |
989 | mu_expand_path_pattern (const char *pattern, const char *username) | 914 | mu_expand_path_pattern (const char *pattern, const char *username) |
990 | { | 915 | { |
991 | char *homedir = NULL; | ||
992 | const char *p, *startp; | 916 | const char *p, *startp; |
993 | char *q; | 917 | char *q; |
994 | char *path; | 918 | char *path; |
995 | int len = 0; | 919 | int len = 0; |
920 | struct mu_auth_data *auth = NULL; | ||
996 | 921 | ||
997 | for (p = pattern; *p; p++) | 922 | for (p = pattern; *p; p++) |
998 | { | 923 | { |
... | @@ -1004,14 +929,13 @@ mu_expand_path_pattern (const char *pattern, const char *username) | ... | @@ -1004,14 +929,13 @@ mu_expand_path_pattern (const char *pattern, const char *username) |
1004 | break; | 929 | break; |
1005 | 930 | ||
1006 | case 'h': | 931 | case 'h': |
1007 | if (!homedir) | 932 | if (!auth) |
1008 | { | 933 | { |
1009 | struct passwd *pwd = mu_getpwnam (username); | 934 | auth = mu_get_auth_by_name (username); |
1010 | if (!pwd) | 935 | if (!auth) |
1011 | return NULL; | 936 | return NULL; |
1012 | homedir = pwd->pw_dir; | ||
1013 | } | 937 | } |
1014 | len += strlen (homedir); | 938 | len += strlen (auth->dir); |
1015 | break; | 939 | break; |
1016 | 940 | ||
1017 | case '%': | 941 | case '%': |
... | @@ -1043,8 +967,8 @@ mu_expand_path_pattern (const char *pattern, const char *username) | ... | @@ -1043,8 +967,8 @@ mu_expand_path_pattern (const char *pattern, const char *username) |
1043 | break; | 967 | break; |
1044 | 968 | ||
1045 | case 'h': | 969 | case 'h': |
1046 | strcpy (q, homedir); | 970 | strcpy (q, auth->dir); |
1047 | q += strlen (homedir); | 971 | q += strlen (auth->dir); |
1048 | break; | 972 | break; |
1049 | 973 | ||
1050 | case '%': | 974 | case '%': |
... | @@ -1063,5 +987,7 @@ mu_expand_path_pattern (const char *pattern, const char *username) | ... | @@ -1063,5 +987,7 @@ mu_expand_path_pattern (const char *pattern, const char *username) |
1063 | q += strlen (startp); | 987 | q += strlen (startp); |
1064 | } | 988 | } |
1065 | *q = 0; | 989 | *q = 0; |
990 | if (auth) | ||
991 | mu_auth_data_free (auth); | ||
1066 | return path; | 992 | return path; |
1067 | } | 993 | } | ... | ... |
-
Please register or sign in to post a comment