dovecot-1.2: expire-tool: Use mail_uid and mail_gid settings if ...

dovecot at dovecot.org dovecot at dovecot.org
Mon May 18 03:02:44 EEST 2009


details:   http://hg.dovecot.org/dovecot-1.2/rev/cc484a16bbe4
changeset: 9048:cc484a16bbe4
user:      Timo Sirainen <tss at iki.fi>
date:      Sun May 17 20:02:37 2009 -0400
description:
expire-tool: Use mail_uid and mail_gid settings if userdb doesn't return uid/gid.

diffstat:

3 files changed, 54 insertions(+), 1 deletion(-)
src/plugins/expire/auth-client.c   |   13 +++++++++++-
src/plugins/expire/expire-plugin.h |    3 ++
src/plugins/expire/expire-tool.c   |   39 ++++++++++++++++++++++++++++++++++++

diffs (115 lines):

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 <unistd.h>
@@ -28,8 +29,18 @@ static void auth_set_env(const char *use
 		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,5 +1,8 @@
 #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 <stdlib.h>
+#include <pwd.h>
+#include <grp.h>
 
 /* ugly, but automake doesn't like having it built as both static and
    dynamic object.. */
@@ -30,6 +33,9 @@ struct expire_context {
 	struct mail_user *mail_user;
 	bool testrun;
 };
+
+uid_t global_mail_uid;
+gid_t global_mail_gid;
 
 static int user_init(struct expire_context *ctx, const char *user)
 {
@@ -179,6 +185,37 @@ mailbox_delete_old_mails(struct expire_c
 	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;
@@ -202,6 +239,8 @@ static void expire_run(bool testrun)
 		i_fatal("expire and expire_altmove settings not set");
 	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)


More information about the dovecot-cvs mailing list