Commit 28e55af0 28e55af09e0b54a468abc8983d19b47bb0c76d60 by Jakob Kaivo

Add virtual domain support

1 parent 0edae243
......@@ -73,7 +73,7 @@ imap4d_copy0 (char *arg, int isuid, char *resp, size_t resplen)
return RESP_BAD;
}
if (strcasecmp (name, "INBOX") == 0)
if (strcasecmp (name, "INBOX") == 0 && !is_virtual)
{
struct passwd *pw = getpwuid (getuid());
mailbox_name = strdup ((pw) ? pw->pw_name : "");
......
......@@ -149,6 +149,7 @@ extern char *homedir;
extern char *rootdir;
extern int state;
extern volatile size_t children;
extern int is_virtual;
/* Imap4 commands */
extern int imap4d_append __P ((struct imap4d_command *, char *));
......
......@@ -21,6 +21,40 @@
#include "../MySql/MySql.h"
#endif
int is_virtual = 0;
#ifdef USE_VIRTUAL_DOMAINS
static struct passwd *
imap4d_virtual (const char *u)
{
struct passwd *pw;
FILE *pfile;
int i = 0, len = strlen (u), delim = 0;
for (i = 0; i < len && delim == 0; i++)
if (u[i] == '!' || u[i] == ':' || u[i] == '@')
delim = i;
if (delim == 0)
return NULL;
chdir ("/etc/domains");
pfile = fopen (&u[delim+1], "r");
while (pfile != NULL && (pw = fgetpwent (pfile)) != NULL)
{
if (strlen (pw->pw_name) == delim && !strncmp (u, pw->pw_name, delim))
{
is_virtual = 1;
return pw;
}
}
return NULL;
}
#endif
/*
* FIXME: this should support PAM, shadow, and normal password
*/
......@@ -107,14 +141,16 @@ imap4d_login (struct imap4d_command *command, char *arg)
pw = getpwnam (username);
if (pw == NULL)
#ifdef HAVE_MYSQL
{
pw = getMpwnam (username);
if (pw == NULL)
return util_finish (command, RESP_NO, "User name or passwd rejected");
}
#else /* HAVE_MYSQL */
return util_finish (command, RESP_NO, "User name or passwd rejected");
if (pw == NULL)
#endif /* HAVE_MYSQL */
#ifdef USE_VIRTUAL_DOMAINS
pw = imap4d_virtual (username);
if (pw == NULL)
#endif /* USE_VIRTUAL_DOMAINS */
return util_finish (command, RESP_NO, "User name or passwd rejected");
#ifndef USE_LIBPAM
if (pw->pw_uid < 1)
......@@ -154,7 +190,7 @@ imap4d_login (struct imap4d_command *command, char *arg)
openlog ("gnu-imap4d", LOG_PID, LOG_MAIL);
#endif /* USE_LIBPAM */
if (pw->pw_uid > 1)
if (pw->pw_uid > 0 && !is_virtual)
setuid (pw->pw_uid);
homedir = util_normalize_path (strdup (pw->pw_dir), "/");
......
......@@ -57,7 +57,7 @@ imap4d_select0 (struct imap4d_command *command, char *arg, int flags)
imap4d_sync ();
}
if (strcasecmp (mailbox_name, "INBOX") == 0)
if (strcasecmp (mailbox_name, "INBOX") == 0 && !is_virtual)
{
pw = getpwuid (getuid ());
if (pw)
......
......@@ -45,7 +45,7 @@ imap4d_status (struct imap4d_command *command, char *arg)
if (!name || *name == '\0' || !sp || *sp == '\0')
return util_finish (command, RESP_BAD, "Too few args");
if (strcasecmp (name, "INBOX") == 0)
if (strcasecmp (name, "INBOX") == 0 && !is_virtual)
{
struct passwd *pw = getpwuid (getuid());
mailbox_name = strdup ((pw) ? pw->pw_name : "");
......