Add virtual domain support
Showing
5 changed files
with
47 additions
and
10 deletions
... | @@ -73,7 +73,7 @@ imap4d_copy0 (char *arg, int isuid, char *resp, size_t resplen) | ... | @@ -73,7 +73,7 @@ imap4d_copy0 (char *arg, int isuid, char *resp, size_t resplen) |
73 | return RESP_BAD; | 73 | return RESP_BAD; |
74 | } | 74 | } |
75 | 75 | ||
76 | if (strcasecmp (name, "INBOX") == 0) | 76 | if (strcasecmp (name, "INBOX") == 0 && !is_virtual) |
77 | { | 77 | { |
78 | struct passwd *pw = getpwuid (getuid()); | 78 | struct passwd *pw = getpwuid (getuid()); |
79 | mailbox_name = strdup ((pw) ? pw->pw_name : ""); | 79 | mailbox_name = strdup ((pw) ? pw->pw_name : ""); | ... | ... |
... | @@ -149,6 +149,7 @@ extern char *homedir; | ... | @@ -149,6 +149,7 @@ extern char *homedir; |
149 | extern char *rootdir; | 149 | extern char *rootdir; |
150 | extern int state; | 150 | extern int state; |
151 | extern volatile size_t children; | 151 | extern volatile size_t children; |
152 | extern int is_virtual; | ||
152 | 153 | ||
153 | /* Imap4 commands */ | 154 | /* Imap4 commands */ |
154 | extern int imap4d_append __P ((struct imap4d_command *, char *)); | 155 | extern int imap4d_append __P ((struct imap4d_command *, char *)); | ... | ... |
... | @@ -21,6 +21,40 @@ | ... | @@ -21,6 +21,40 @@ |
21 | #include "../MySql/MySql.h" | 21 | #include "../MySql/MySql.h" |
22 | #endif | 22 | #endif |
23 | 23 | ||
24 | int is_virtual = 0; | ||
25 | |||
26 | #ifdef USE_VIRTUAL_DOMAINS | ||
27 | |||
28 | static struct passwd * | ||
29 | imap4d_virtual (const char *u) | ||
30 | { | ||
31 | struct passwd *pw; | ||
32 | FILE *pfile; | ||
33 | int i = 0, len = strlen (u), delim = 0; | ||
34 | |||
35 | for (i = 0; i < len && delim == 0; i++) | ||
36 | if (u[i] == '!' || u[i] == ':' || u[i] == '@') | ||
37 | delim = i; | ||
38 | |||
39 | if (delim == 0) | ||
40 | return NULL; | ||
41 | |||
42 | chdir ("/etc/domains"); | ||
43 | pfile = fopen (&u[delim+1], "r"); | ||
44 | while (pfile != NULL && (pw = fgetpwent (pfile)) != NULL) | ||
45 | { | ||
46 | if (strlen (pw->pw_name) == delim && !strncmp (u, pw->pw_name, delim)) | ||
47 | { | ||
48 | is_virtual = 1; | ||
49 | return pw; | ||
50 | } | ||
51 | } | ||
52 | |||
53 | return NULL; | ||
54 | } | ||
55 | |||
56 | #endif | ||
57 | |||
24 | /* | 58 | /* |
25 | * FIXME: this should support PAM, shadow, and normal password | 59 | * FIXME: this should support PAM, shadow, and normal password |
26 | */ | 60 | */ |
... | @@ -107,14 +141,16 @@ imap4d_login (struct imap4d_command *command, char *arg) | ... | @@ -107,14 +141,16 @@ imap4d_login (struct imap4d_command *command, char *arg) |
107 | pw = getpwnam (username); | 141 | pw = getpwnam (username); |
108 | if (pw == NULL) | 142 | if (pw == NULL) |
109 | #ifdef HAVE_MYSQL | 143 | #ifdef HAVE_MYSQL |
110 | { | ||
111 | pw = getMpwnam (username); | 144 | pw = getMpwnam (username); |
112 | if (pw == NULL) | 145 | |
113 | return util_finish (command, RESP_NO, "User name or passwd rejected"); | 146 | if (pw == NULL) |
114 | } | ||
115 | #else /* HAVE_MYSQL */ | ||
116 | return util_finish (command, RESP_NO, "User name or passwd rejected"); | ||
117 | #endif /* HAVE_MYSQL */ | 147 | #endif /* HAVE_MYSQL */ |
148 | #ifdef USE_VIRTUAL_DOMAINS | ||
149 | pw = imap4d_virtual (username); | ||
150 | |||
151 | if (pw == NULL) | ||
152 | #endif /* USE_VIRTUAL_DOMAINS */ | ||
153 | return util_finish (command, RESP_NO, "User name or passwd rejected"); | ||
118 | 154 | ||
119 | #ifndef USE_LIBPAM | 155 | #ifndef USE_LIBPAM |
120 | if (pw->pw_uid < 1) | 156 | if (pw->pw_uid < 1) |
... | @@ -154,7 +190,7 @@ imap4d_login (struct imap4d_command *command, char *arg) | ... | @@ -154,7 +190,7 @@ imap4d_login (struct imap4d_command *command, char *arg) |
154 | openlog ("gnu-imap4d", LOG_PID, LOG_MAIL); | 190 | openlog ("gnu-imap4d", LOG_PID, LOG_MAIL); |
155 | #endif /* USE_LIBPAM */ | 191 | #endif /* USE_LIBPAM */ |
156 | 192 | ||
157 | if (pw->pw_uid > 1) | 193 | if (pw->pw_uid > 0 && !is_virtual) |
158 | setuid (pw->pw_uid); | 194 | setuid (pw->pw_uid); |
159 | 195 | ||
160 | homedir = util_normalize_path (strdup (pw->pw_dir), "/"); | 196 | homedir = util_normalize_path (strdup (pw->pw_dir), "/"); | ... | ... |
... | @@ -57,7 +57,7 @@ imap4d_select0 (struct imap4d_command *command, char *arg, int flags) | ... | @@ -57,7 +57,7 @@ imap4d_select0 (struct imap4d_command *command, char *arg, int flags) |
57 | imap4d_sync (); | 57 | imap4d_sync (); |
58 | } | 58 | } |
59 | 59 | ||
60 | if (strcasecmp (mailbox_name, "INBOX") == 0) | 60 | if (strcasecmp (mailbox_name, "INBOX") == 0 && !is_virtual) |
61 | { | 61 | { |
62 | pw = getpwuid (getuid ()); | 62 | pw = getpwuid (getuid ()); |
63 | if (pw) | 63 | if (pw) | ... | ... |
... | @@ -45,7 +45,7 @@ imap4d_status (struct imap4d_command *command, char *arg) | ... | @@ -45,7 +45,7 @@ imap4d_status (struct imap4d_command *command, char *arg) |
45 | if (!name || *name == '\0' || !sp || *sp == '\0') | 45 | if (!name || *name == '\0' || !sp || *sp == '\0') |
46 | return util_finish (command, RESP_BAD, "Too few args"); | 46 | return util_finish (command, RESP_BAD, "Too few args"); |
47 | 47 | ||
48 | if (strcasecmp (name, "INBOX") == 0) | 48 | if (strcasecmp (name, "INBOX") == 0 && !is_virtual) |
49 | { | 49 | { |
50 | struct passwd *pw = getpwuid (getuid()); | 50 | struct passwd *pw = getpwuid (getuid()); |
51 | mailbox_name = strdup ((pw) ? pw->pw_name : ""); | 51 | mailbox_name = strdup ((pw) ? pw->pw_name : ""); | ... | ... |
-
Please register or sign in to post a comment