21 |
#include "../MySql/MySql.h" |
#include "../MySql/MySql.h" |
22 |
#endif |
#endif |
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 |
|
|
58 |
/* |
/* |
59 |
* FIXME: this should support PAM, shadow, and normal password |
* FIXME: this should support PAM, shadow, and normal password |
60 |
*/ |
*/ |
141 |
pw = getpwnam (username); |
pw = getpwnam (username); |
142 |
if (pw == NULL) |
if (pw == NULL) |
143 |
#ifdef HAVE_MYSQL |
#ifdef HAVE_MYSQL |
|
{ |
|
144 |
pw = getMpwnam (username); |
pw = getMpwnam (username); |
145 |
if (pw == NULL) |
|
146 |
return util_finish (command, RESP_NO, "User name or passwd rejected"); |
if (pw == NULL) |
|
} |
|
|
#else /* HAVE_MYSQL */ |
|
|
return util_finish (command, RESP_NO, "User name or passwd rejected"); |
|
147 |
#endif /* HAVE_MYSQL */ |
#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"); |
154 |
|
|
155 |
#ifndef USE_LIBPAM |
#ifndef USE_LIBPAM |
156 |
if (pw->pw_uid < 1) |
if (pw->pw_uid < 1) |
190 |
openlog ("gnu-imap4d", LOG_PID, LOG_MAIL); |
openlog ("gnu-imap4d", LOG_PID, LOG_MAIL); |
191 |
#endif /* USE_LIBPAM */ |
#endif /* USE_LIBPAM */ |
192 |
|
|
193 |
if (pw->pw_uid > 1) |
if (pw->pw_uid > 0 && !is_virtual) |
194 |
setuid (pw->pw_uid); |
setuid (pw->pw_uid); |
195 |
|
|
196 |
homedir = util_normalize_path (strdup (pw->pw_dir), "/"); |
homedir = util_normalize_path (strdup (pw->pw_dir), "/"); |