# HG changeset patch # User Timo Sirainen # Date 1242604957 14400 # Node ID cc484a16bbe4b5e6f4e246517826e88dffa6b4e5 # Parent c5b16d6c39c9f920a9f6ac299c6c2c51b8ff2d14 expire-tool: Use mail_uid and mail_gid settings if userdb doesn't return uid/gid. diff -r c5b16d6c39c9 -r cc484a16bbe4 src/plugins/expire/auth-client.c --- a/src/plugins/expire/auth-client.c Sun May 17 18:45:23 2009 -0400 +++ b/src/plugins/expire/auth-client.c Sun May 17 20:02:37 2009 -0400 @@ -5,6 +5,7 @@ #include "env-util.h" #include "restrict-access.h" #include "auth-client.h" +#include "expire-plugin.h" #include "auth-master.h" #include @@ -28,8 +29,18 @@ i_error("userdb(%s) didn't return a home directory", user); return; } + if (reply->uid == (uid_t)-1) + reply->uid = global_mail_uid; if (reply->uid == (uid_t)-1) { - i_error("userdb(%s) didn't return uid", user); + i_error("userdb(%s) didn't return uid and mail_uid not set", + user); + return; + } + if (reply->gid == (gid_t)-1) + reply->gid = global_mail_gid; + if (reply->gid == (gid_t)-1) { + i_error("userdb(%s) didn't return gid and mail_gid not set", + user); return; } diff -r c5b16d6c39c9 -r cc484a16bbe4 src/plugins/expire/expire-plugin.h --- a/src/plugins/expire/expire-plugin.h Sun May 17 18:45:23 2009 -0400 +++ b/src/plugins/expire/expire-plugin.h Sun May 17 20:02:37 2009 -0400 @@ -1,6 +1,9 @@ #ifndef EXPIRE_PLUGIN_H #define EXPIRE_PLUGIN_H +extern uid_t global_mail_uid; +extern gid_t global_mail_gid; + void expire_plugin_init(void); void expire_plugin_deinit(void); diff -r c5b16d6c39c9 -r cc484a16bbe4 src/plugins/expire/expire-tool.c --- a/src/plugins/expire/expire-tool.c Sun May 17 18:45:23 2009 -0400 +++ b/src/plugins/expire/expire-tool.c Sun May 17 20:02:37 2009 -0400 @@ -14,8 +14,11 @@ #include "auth-client.h" #include "auth-master.h" #include "expire-env.h" +#include "expire-plugin.h" #include +#include +#include /* ugly, but automake doesn't like having it built as both static and dynamic object.. */ @@ -31,6 +34,9 @@ bool testrun; }; +uid_t global_mail_uid; +gid_t global_mail_gid; + static int user_init(struct expire_context *ctx, const char *user) { int ret; @@ -179,6 +185,37 @@ return ret < 0 ? -1 : 0; } +static void expire_get_global_mail_ids(void) +{ + const struct passwd *pw; + const struct group *gr; + const char *str; + + str = getenv("MAIL_UID"); + if (str == NULL) + global_mail_uid = (uid_t)-1; + else if (is_numeric(str, '\0')) + global_mail_uid = strtoul(str, NULL, 10); + else { + pw = getpwnam(str); + if (pw == NULL) + i_fatal("mail_uid: User %s doesn't exist", str); + global_mail_uid = pw->pw_uid; + } + + str = getenv("MAIL_GID"); + if (str == NULL) + global_mail_gid = (gid_t)-1; + else if (is_numeric(str, '\0')) + global_mail_gid = strtoul(str, NULL, 10); + else { + gr = getgrnam(str); + if (gr == NULL) + i_fatal("mail_gid: Group %s doesn't exist", str); + global_mail_gid = gr->gr_gid; + } +} + static void expire_run(bool testrun) { struct expire_context ctx; @@ -203,6 +240,8 @@ if (getenv("EXPIRE_DICT") == NULL) i_fatal("expire_dict setting not set"); + expire_get_global_mail_ids(); + auth_socket = getenv("AUTH_SOCKET_PATH"); if (auth_socket == NULL) auth_socket = DEFAULT_AUTH_SOCKET_PATH;