]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap, pop3: Added -u <username> parameter to do userdb lookup.
authorTimo Sirainen <tss@iki.fi>
Thu, 25 Mar 2010 17:28:56 +0000 (19:28 +0200)
committerTimo Sirainen <tss@iki.fi>
Thu, 25 Mar 2010 17:28:56 +0000 (19:28 +0200)
--HG--
branch : HEAD

src/imap/main.c
src/pop3/main.c

index cda31956f9f3cc05fd7cc3b714da076901b05a25..321399b7a87791cc99d9e72854ef60f0ba918ffe 100644 (file)
@@ -189,7 +189,7 @@ client_create_from_input(const struct mail_storage_service_input *input,
        return 0;
 }
 
-static void main_stdio_run(void)
+static void main_stdio_run(const char *username)
 {
        struct mail_storage_service_input input;
        const char *value, *error, *input_base64;
@@ -197,7 +197,7 @@ static void main_stdio_run(void)
 
        memset(&input, 0, sizeof(input));
        input.module = input.service = "imap";
-       input.username = getenv("USER");
+       input.username = username != NULL ? username : getenv("USER");
        if (input.username == NULL && IS_STANDALONE())
                input.username = getlogin();
        if (input.username == NULL)
@@ -259,7 +259,8 @@ int main(int argc, char *argv[])
        };
        enum master_service_flags service_flags = 0;
        enum mail_storage_service_flags storage_service_flags = 0;
-       const char *postlogin_socket_path;
+       const char *postlogin_socket_path, *username = NULL;
+       int c;
 
        if (IS_STANDALONE() && getuid() == 0 &&
            net_getpeername(1, NULL, NULL) == 0) {
@@ -278,9 +279,18 @@ int main(int argc, char *argv[])
        }
 
        master_service = master_service_init("imap", service_flags,
-                                            &argc, &argv, NULL);
-       if (master_getopt(master_service) > 0)
-               return FATAL_DEFAULT;
+                                            &argc, &argv, "u:");
+       while ((c = master_getopt(master_service)) > 0) {
+               switch (c) {
+               case 'u':
+                       storage_service_flags |=
+                               MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP;
+                       username = optarg;
+                       break;
+               default:
+                       return FATAL_DEFAULT;
+               }
+       }
        postlogin_socket_path = argv[1] == NULL ? NULL : t_abspath(argv[1]);
 
        master_service_init_finish(master_service);
@@ -300,7 +310,7 @@ int main(int argc, char *argv[])
 
        if (IS_STANDALONE()) {
                T_BEGIN {
-                       main_stdio_run();
+                       main_stdio_run(username);
                } T_END;
        } else {
                master_login = master_login_init(master_service, "auth-master",
index a5350a07fce8866ba587da28a14557e5e4336686..13e4e61ba1f6692217cf1c5e2441d26566d91bb5 100644 (file)
@@ -109,7 +109,7 @@ client_create_from_input(const struct mail_storage_service_input *input,
        return 0;
 }
 
-static void main_stdio_run(void)
+static void main_stdio_run(const char *username)
 {
        struct mail_storage_service_input input;
        buffer_t *input_buf;
@@ -117,7 +117,7 @@ static void main_stdio_run(void)
 
        memset(&input, 0, sizeof(input));
        input.module = input.service = "pop3";
-       input.username = getenv("USER");
+       input.username = username != NULL ? username : getenv("USER");
        if (input.username == NULL && IS_STANDALONE())
                input.username = getlogin();
        if (input.username == NULL)
@@ -179,7 +179,8 @@ int main(int argc, char *argv[])
        };
        enum master_service_flags service_flags = 0;
        enum mail_storage_service_flags storage_service_flags = 0;
-       const char *postlogin_socket_path;
+       const char *postlogin_socket_path, *username = NULL;
+       int c;
 
        if (IS_STANDALONE() && getuid() == 0 &&
            net_getpeername(1, NULL, NULL) == 0) {
@@ -198,9 +199,18 @@ int main(int argc, char *argv[])
        }
 
        master_service = master_service_init("pop3", service_flags,
-                                            &argc, &argv, NULL);
-       if (master_getopt(master_service) > 0)
-               return FATAL_DEFAULT;
+                                            &argc, &argv, "u:");
+       while ((c = master_getopt(master_service)) > 0) {
+               switch (c) {
+               case 'u':
+                       storage_service_flags |=
+                               MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP;
+                       username = optarg;
+                       break;
+               default:
+                       return FATAL_DEFAULT;
+               }
+       }
        postlogin_socket_path = argv[1] == NULL ? NULL : t_abspath(argv[1]);
 
        master_service_init_finish(master_service);
@@ -216,7 +226,7 @@ int main(int argc, char *argv[])
 
        if (IS_STANDALONE()) {
                T_BEGIN {
-                       main_stdio_run();
+                       main_stdio_run(username);
                } T_END;
        } else {
                master_login = master_login_init(master_service, "auth-master",