17 |
|
|
18 |
#include "imap4d.h" |
#include "imap4d.h" |
19 |
|
|
20 |
/* |
extern int auth_gssapi __P((struct imap4d_command *, char **username)); |
21 |
* What types of auth should be supported? |
|
22 |
*/ |
struct imap_auth { |
23 |
|
char *name; |
24 |
|
int (*handler) __P((struct imap4d_command *, char **)); |
25 |
|
} imap_auth_tab[] = { |
26 |
|
#ifdef WITH_GSSAPI |
27 |
|
{ "GSSAPI", auth_gssapi }, |
28 |
|
#endif |
29 |
|
{ NULL, NULL } |
30 |
|
}; |
31 |
|
|
32 |
int |
int |
33 |
imap4d_authenticate (struct imap4d_command *command, char *arg) |
imap4d_authenticate (struct imap4d_command *command, char *arg) |
34 |
{ |
{ |
35 |
|
char *sp = NULL; |
36 |
|
char *auth_type; |
37 |
|
struct imap_auth *ap; |
38 |
|
char *username = NULL; |
39 |
|
|
40 |
if (! (command->states & state)) |
if (! (command->states & state)) |
41 |
return util_finish (command, RESP_BAD, "Wrong state"); |
return util_finish (command, RESP_BAD, "Wrong state"); |
42 |
return util_finish (command, RESP_NO, "Command not supported"); |
|
43 |
|
auth_type = util_getword (arg, &sp); |
44 |
|
util_unquote (&auth_type); |
45 |
|
if (!auth_type) |
46 |
|
return util_finish (command, RESP_BAD, "Too few arguments"); |
47 |
|
|
48 |
|
for (ap = imap_auth_tab; ap->name; ap++) |
49 |
|
if (strcmp (auth_type, ap->name) == 0) |
50 |
|
{ |
51 |
|
if (ap->handler (command, &username)) |
52 |
|
return 1; |
53 |
|
} |
54 |
|
|
55 |
|
if (username) |
56 |
|
{ |
57 |
|
struct passwd *pw = mu_getpwnam (username); |
58 |
|
if (pw == NULL) |
59 |
|
return util_finish (command, RESP_NO, |
60 |
|
"User name or passwd rejected"); |
61 |
|
|
62 |
|
if (pw->pw_uid > 0 && !mu_virtual_domain) |
63 |
|
setuid (pw->pw_uid); |
64 |
|
|
65 |
|
homedir = mu_normalize_path (strdup (pw->pw_dir), "/"); |
66 |
|
/* FIXME: Check for errors. */ |
67 |
|
chdir (homedir); |
68 |
|
namespace_init(pw->pw_dir); |
69 |
|
syslog (LOG_INFO, "User '%s' logged in", username); |
70 |
|
return 0; |
71 |
|
} |
72 |
|
|
73 |
|
return util_finish (command, RESP_NO, |
74 |
|
"Authentication mechanism not supported"); |
75 |
} |
} |
76 |
|
|