Blame SOURCES/mailman-2.1.12-multimail.patch

ccdd61
diff -ruN mailman-2.1.12-a/configure.in mailman-2.1.12-b/configure.in
ccdd61
--- mailman-2.1.12-a/configure.in	2009-02-23 22:23:35.000000000 +0100
ccdd61
+++ mailman-2.1.12-b/configure.in	2009-07-28 12:19:47.000000000 +0200
ccdd61
@@ -249,26 +249,101 @@
ccdd61
 fi
ccdd61
 
ccdd61
 # new macro for finding group names
ccdd61
-AC_DEFUN([MM_FIND_GROUP_NAME], [
ccdd61
+# returns a comma separated list of quoted group names
ccdd61
+# the list is returned in the same order as specified with any duplicates removed
ccdd61
+# the filter flag must be "yes" or "no", e.g. this is permcheck
ccdd61
+#         "no"  ==> none existing groups are not filtered out
ccdd61
+#         "yes" ==> only those groups that are in the group database are included
ccdd61
+#                   in the list
ccdd61
+AC_DEFUN(MM_FIND_GROUP_LIST, [
ccdd61
 # $1 == variable name
ccdd61
-# $2 == user id to check for
ccdd61
+# $2 == white space separated list of groups to check,
ccdd61
+#       list may contain mix of id's and names
ccdd61
+# $3 == filter, if == 'yes' then remove any non-existing groups
ccdd61
 AC_SUBST($1)
ccdd61
 changequote(,)
ccdd61
 if test -z "$$1"
ccdd61
 then
ccdd61
     cat > conftest.py <
ccdd61
 import grp
ccdd61
-gid = ''
ccdd61
+group_names = []
ccdd61
+seen = {}
ccdd61
+filter = "$3"
ccdd61
+
ccdd61
 for group in "$2".split():
ccdd61
     try:
ccdd61
+        gid = int(group)
ccdd61
+        try:
ccdd61
+            gname = grp.getgrgid(gid)[0]
ccdd61
+        except KeyError:
ccdd61
+            gname = ''
ccdd61
+    except ValueError:
ccdd61
         try:
ccdd61
-            gname = grp.getgrgid(int(group))[0]
ccdd61
-            break
ccdd61
-        except ValueError:
ccdd61
             gname = grp.getgrnam(group)[0]
ccdd61
+        except KeyError:
ccdd61
+            if filter == "yes":
ccdd61
+                gname = ''
ccdd61
+            else:
ccdd61
+                gname = group
ccdd61
+    if gname:
ccdd61
+        if gname not in seen:
ccdd61
+            seen[gname] = 1
ccdd61
+            group_names.append(gname)
ccdd61
+
ccdd61
+if group_names:
ccdd61
+    val = '"' + '", "'.join(group_names) + '"'
ccdd61
+    #val = "'"+val+"'"
ccdd61
+else:
ccdd61
+    val = ''
ccdd61
+
ccdd61
+fp = open("conftest.out", "w")
ccdd61
+fp.write("%s\n" % val)
ccdd61
+fp.close()
ccdd61
+EOF
ccdd61
+    $PYTHON conftest.py
ccdd61
+    $1=`cat conftest.out`
ccdd61
+fi
ccdd61
+changequote([, ])
ccdd61
+rm -f conftest.out conftest.py])
ccdd61
+
ccdd61
+
ccdd61
+# new macro for finding group names
ccdd61
+AC_DEFUN(MM_FIND_GROUP_NAME, [
ccdd61
+# Given a list of tokens, either a name or a number (gid)
ccdd61
+# return the first one in the list that is found in the 
ccdd61
+# group database. The return value is always a name, possibly
ccdd61
+# translated from a gid. If permcheck is "no" then the group
ccdd61
+# database is not checked, instead the first token in the list
ccdd61
+# which is a name is returned (e.g. the default value). If permcheck
ccdd61
+# is no and only gid's are in the list then the null string is returned.
ccdd61
+# $1 == variable name
ccdd61
+# $2 == group id to check for
ccdd61
+# $3 == permcheck, either "yes" or "no"
ccdd61
+AC_SUBST($1)
ccdd61
+changequote(,)
ccdd61
+if test -z "$$1"
ccdd61
+then
ccdd61
+    cat > conftest.py <
ccdd61
+import grp
ccdd61
+gname=''
ccdd61
+if "$3" == "yes":
ccdd61
+    for group in "$2".split():
ccdd61
+        try:
ccdd61
+            try:
ccdd61
+                gname = grp.getgrgid(int(group))[0]
ccdd61
+                break
ccdd61
+            except ValueError:
ccdd61
+                gname = grp.getgrnam(group)[0]
ccdd61
+                break
ccdd61
+        except KeyError:
ccdd61
+            gname = ''
ccdd61
+else:
ccdd61
+    for group in "$2".split():
ccdd61
+        try:
ccdd61
+            int(group)
ccdd61
+        except ValueError:
ccdd61
+            gname = group
ccdd61
             break
ccdd61
-    except KeyError:
ccdd61
-        gname = ''
ccdd61
 fp = open("conftest.out", "w")
ccdd61
 fp.write("%s\n" % gname)
ccdd61
 fp.close()
ccdd61
@@ -282,25 +357,41 @@
ccdd61
 
ccdd61
 # new macro for finding UIDs
ccdd61
 AC_DEFUN([MM_FIND_USER_NAME], [
ccdd61
+# Given a list of tokens, either a name or a number (uid)
ccdd61
+# return the first one in the list that is found in the 
ccdd61
+# password database. The return value is always a name, possibly
ccdd61
+# translated from a uid. If permcheck is "no" then the password
ccdd61
+# database is not checked, instead the first token in the list
ccdd61
+# which is a name is returned (e.g. the default value). If permcheck
ccdd61
+# is no and only uid's are in the list then the null string is returned.
ccdd61
 # $1 == variable name
ccdd61
 # $2 == user id to check for
ccdd61
+# $3 == permcheck, either "yes" or "no"
ccdd61
 AC_SUBST($1)
ccdd61
 changequote(,)
ccdd61
 if test -z "$$1"
ccdd61
 then
ccdd61
     cat > conftest.py <
ccdd61
 import pwd
ccdd61
-uid = ''
ccdd61
-for user in "$2".split():
ccdd61
-    try:
ccdd61
+uname=''
ccdd61
+if "$3" == "yes":
ccdd61
+    for user in "$2".split():
ccdd61
         try:
ccdd61
-            uname = pwd.getpwuid(int(user))[0]
ccdd61
-            break
ccdd61
+            try:
ccdd61
+                uname = pwd.getpwuid(int(user))[0]
ccdd61
+                break
ccdd61
+            except ValueError:
ccdd61
+                uname = pwd.getpwnam(user)[0]
ccdd61
+                break
ccdd61
+        except KeyError:
ccdd61
+            uname = ''
ccdd61
+else:
ccdd61
+    for user in "$2".split():
ccdd61
+        try:
ccdd61
+            int(user)
ccdd61
         except ValueError:
ccdd61
-            uname = pwd.getpwnam(user)[0]
ccdd61
+            uname = user
ccdd61
             break
ccdd61
-    except KeyError:
ccdd61
-        uname = ''
ccdd61
 fp = open("conftest.out", "w")
ccdd61
 fp.write("%s\n" % uname)
ccdd61
 fp.close()
ccdd61
@@ -326,7 +417,7 @@
ccdd61
 # User `mailman' must exist
ccdd61
 AC_SUBST(MAILMAN_USER)
ccdd61
 AC_MSG_CHECKING(for user name \"$USERNAME\")
ccdd61
-MM_FIND_USER_NAME(MAILMAN_USER, $USERNAME)
ccdd61
+MM_FIND_USER_NAME(MAILMAN_USER, $USERNAME, $with_permcheck)
ccdd61
 if test -z "$MAILMAN_USER"
ccdd61
 then
ccdd61
   if test "$with_permcheck" = "yes"
ccdd61
@@ -357,7 +448,7 @@
ccdd61
 # Target group must exist
ccdd61
 AC_SUBST(MAILMAN_GROUP)
ccdd61
 AC_MSG_CHECKING(for group name \"$GROUPNAME\")
ccdd61
-MM_FIND_GROUP_NAME(MAILMAN_GROUP, $GROUPNAME)
ccdd61
+MM_FIND_GROUP_NAME(MAILMAN_GROUP, $GROUPNAME, $with_permcheck)
ccdd61
 if test -z "$MAILMAN_GROUP"
ccdd61
 then
ccdd61
   if test "$with_permcheck" = "yes"
ccdd61
@@ -380,11 +471,11 @@
ccdd61
 prefix = "$prefixcheck"
ccdd61
 groupname = "$GROUPNAME"
ccdd61
 mailmangroup = "$MAILMAN_GROUP"
ccdd61
-try:
ccdd61
-    mailmangid = grp.getgrnam(mailmangroup)[2]
ccdd61
-except KeyError:
ccdd61
-    mailmangid = -1
ccdd61
 problems = []
ccdd61
+try: mailmangid = grp.getgrnam(mailmangroup)[2]
ccdd61
+except KeyError:
ccdd61
+    problems.append("group doesn't exist: " + mailmangroup)
ccdd61
+    mailmangid = 41
ccdd61
 try: statdata = os.stat(prefix)
ccdd61
 except OSError:
ccdd61
     problems.append("Directory doesn't exist: " + prefix)
ccdd61
@@ -434,7 +525,7 @@
ccdd61
 then
ccdd61
     with_mail_gid="mailman other mail daemon"
ccdd61
 fi
ccdd61
-MM_FIND_GROUP_NAME(MAIL_GROUP, $with_mail_gid)
ccdd61
+MM_FIND_GROUP_LIST(MAIL_GROUP, $with_mail_gid, $with_permcheck)
ccdd61
 if test -z "$MAIL_GROUP"
ccdd61
 then
ccdd61
   if test "$with_permcheck" = "yes"
ccdd61
@@ -461,7 +552,7 @@
ccdd61
     with_cgi_gid="www www-data nobody"
ccdd61
 fi
ccdd61
 
ccdd61
-MM_FIND_GROUP_NAME(CGI_GROUP, $with_cgi_gid)
ccdd61
+MM_FIND_GROUP_LIST(CGI_GROUP, $with_cgi_gid, $with_permcheck)
ccdd61
 if test -z "$CGI_GROUP"
ccdd61
 then
ccdd61
   if test "$with_permcheck" = "yes"
ccdd61
diff -ruN mailman-2.1.12-a/src/cgi-wrapper.c mailman-2.1.12-b/src/cgi-wrapper.c
ccdd61
--- mailman-2.1.12-a/src/cgi-wrapper.c	2009-02-23 22:23:35.000000000 +0100
ccdd61
+++ mailman-2.1.12-b/src/cgi-wrapper.c	2009-07-28 12:19:47.000000000 +0200
ccdd61
@@ -28,11 +28,11 @@
ccdd61
 /* Group name that CGI scripts run as.  See your web server's documentation
ccdd61
  * for details.
ccdd61
  */
ccdd61
-#define LEGAL_PARENT_GROUP CGI_GROUP
ccdd61
+#define LEGAL_PARENT_GROUPS CGI_GROUP
ccdd61
 
ccdd61
 const char* logident = LOG_IDENT;
ccdd61
 char* script = SCRIPTNAME;
ccdd61
-const char* parentgroup = LEGAL_PARENT_GROUP;
ccdd61
+const char* parentgroups[] = {LEGAL_PARENT_GROUPS};
ccdd61
 
ccdd61
 
ccdd61
 int
ccdd61
@@ -42,7 +42,7 @@
ccdd61
         char* fake_argv[3];
ccdd61
 
ccdd61
         running_as_cgi = 1;
ccdd61
-        check_caller(logident, parentgroup);
ccdd61
+	check_caller(logident, parentgroups, sizeof(parentgroups) / sizeof(parentgroups[0]));
ccdd61
 
ccdd61
         /* For these CGI programs, we can ignore argc and argv since they
ccdd61
          * don't contain anything useful.  `script' will always be the driver
ccdd61
diff -ruN mailman-2.1.12-a/src/common.c mailman-2.1.12-b/src/common.c
ccdd61
--- mailman-2.1.12-a/src/common.c	2009-02-23 22:23:35.000000000 +0100
ccdd61
+++ mailman-2.1.12-b/src/common.c	2009-07-28 12:19:47.000000000 +0200
ccdd61
@@ -117,13 +117,14 @@
ccdd61
 /* Is the parent process allowed to call us?
ccdd61
  */
ccdd61
 void
ccdd61
-check_caller(const char* ident, const char* parentgroup)
ccdd61
+check_caller(const char* ident, const char** parentgroups, size_t numgroups)
ccdd61
 {
ccdd61
         GID_T mygid = getgid();
ccdd61
         struct group *mygroup = getgrgid(mygid);
ccdd61
         char* option;
ccdd61
         char* server;
ccdd61
         char* wrapper;
ccdd61
+	int i;
ccdd61
 
ccdd61
         if (running_as_cgi) {
ccdd61
                 option = "--with-cgi-gid";
ccdd61
@@ -136,28 +137,46 @@
ccdd61
                 wrapper = "mail";
ccdd61
         }
ccdd61
 
ccdd61
-        if (!mygroup)
ccdd61
-                fatal(ident, GROUP_NAME_NOT_FOUND,
ccdd61
-                      "Failure to find group name for GID %d.  Mailman\n"
ccdd61
-                      "expected the %s wrapper to be executed as group\n"
ccdd61
-                      "\"%s\", but the system's %s server executed the\n"
ccdd61
-                      "wrapper as GID %d for which the name could not be\n"
ccdd61
-                      "found.  Try adding GID %d to your system as \"%s\",\n"
ccdd61
-                      "or tweak your %s server to run the wrapper as group\n"
ccdd61
-                      "\"%s\".",
ccdd61
-                      mygid, wrapper, parentgroup, server, mygid, mygid,
ccdd61
-                      parentgroup, server, parentgroup);
ccdd61
+  	if (!mygroup)
ccdd61
+		fatal(ident, GROUP_ID_NOT_FOUND,
ccdd61
+		      "Failure to lookup via getgrgid() the group info for group id %d that this Mailman %s wrapper is executing under.\n"
ccdd61
+		      "This is probably due to an incorrectly configured system and is not a Mailman problem",
ccdd61
+		      mygid, wrapper);
ccdd61
+
ccdd61
+	for (i = 0; i < numgroups; i++) {
ccdd61
+		if (strcmp(parentgroups[i], mygroup->gr_name) == 0) break;
ccdd61
+	}
ccdd61
+
ccdd61
+        if (i >= numgroups) {
ccdd61
+		char *groupset = NULL;
ccdd61
+		size_t size = 0;
ccdd61
+
ccdd61
+		for (i = 0; i < numgroups; i++) {
ccdd61
+			size += strlen(parentgroups[i]) + 2;
ccdd61
+		}
ccdd61
+
ccdd61
+		groupset = malloc(size);
ccdd61
+
ccdd61
+		if (groupset) {
ccdd61
+			groupset[0] = 0;
ccdd61
+			for (i = 0; i < numgroups; i++) {
ccdd61
+				strcat(groupset, parentgroups[i]);
ccdd61
+				if (i < numgroups-1) strcat(groupset, ", ");
ccdd61
+			}
ccdd61
+		}
ccdd61
 
ccdd61
-        if (strcmp(parentgroup, mygroup->gr_name))
ccdd61
                 fatal(ident, GROUP_MISMATCH,
ccdd61
-                      "Group mismatch error.  Mailman expected the %s\n"
ccdd61
-                      "wrapper script to be executed as group \"%s\", but\n"
ccdd61
-                      "the system's %s server executed the %s script as\n"
ccdd61
-                      "group \"%s\".  Try tweaking the %s server to run the\n"
ccdd61
-                      "script as group \"%s\", or re-run configure, \n"
ccdd61
-                      "providing the command line option `%s=%s'.",
ccdd61
-                      wrapper, parentgroup, server, wrapper, mygroup->gr_name,
ccdd61
-                      server, parentgroup, option, mygroup->gr_name);
ccdd61
+		      "Group mismatch error. Mailman expected the %s wrapper script to be\n"
ccdd61
+		      "executed as one of the following groups:\n"
ccdd61
+		      "[%s],\n"
ccdd61
+		      "but the system's %s server executed the %s script as group: \"%s\".\n"
ccdd61
+		      "Try tweaking the %s server to run the script as one of these groups:\n"
ccdd61
+		      "[%s],\n"
ccdd61
+		      "or re-run configure providing the command line option:\n"
ccdd61
+		      "'%s=%s'.",
ccdd61
+		      wrapper, groupset, server, wrapper, mygroup->gr_name,
ccdd61
+		      server, groupset, option, mygroup->gr_name);
ccdd61
+	}
ccdd61
 }
ccdd61
 
ccdd61
 
ccdd61
diff -ruN mailman-2.1.12-a/src/common.h mailman-2.1.12-b/src/common.h
ccdd61
--- mailman-2.1.12-a/src/common.h	2009-02-23 22:23:35.000000000 +0100
ccdd61
+++ mailman-2.1.12-b/src/common.h	2009-07-28 12:19:47.000000000 +0200
ccdd61
@@ -33,7 +33,7 @@
ccdd61
 #define GID_T GETGROUPS_T
ccdd61
 
ccdd61
 extern void fatal(const char*, int, char*, ...);
ccdd61
-extern void check_caller(const char*, const char*);
ccdd61
+extern void check_caller(const char* ident, const char**, size_t);
ccdd61
 extern int run_script(const char*, int, char**, char**);
ccdd61
 
ccdd61
 /* Global variable used as a flag. */
ccdd61
@@ -51,7 +51,7 @@
ccdd61
 #define MAIL_USAGE_ERROR 5
ccdd61
 #define MAIL_ILLEGAL_COMMAND 6
ccdd61
 #define ADDALIAS_USAGE_ERROR 7
ccdd61
-#define GROUP_NAME_NOT_FOUND 8
ccdd61
+#define GROUP_ID_NOT_FOUND 8
ccdd61
 
ccdd61
 
ccdd61
 /*
ccdd61
diff -ruN mailman-2.1.12-a/src/mail-wrapper.c mailman-2.1.12-b/src/mail-wrapper.c
ccdd61
--- mailman-2.1.12-a/src/mail-wrapper.c	2009-02-23 22:23:35.000000000 +0100
ccdd61
+++ mailman-2.1.12-b/src/mail-wrapper.c	2009-07-28 12:19:47.000000000 +0200
ccdd61
@@ -23,9 +23,9 @@
ccdd61
 /* Group name that your mail programs run as.  See your mail server's
ccdd61
  * documentation for details.
ccdd61
  */
ccdd61
-#define LEGAL_PARENT_GROUP MAIL_GROUP
ccdd61
+#define LEGAL_PARENT_GROUPS MAIL_GROUP
ccdd61
 
ccdd61
-const char* parentgroup = LEGAL_PARENT_GROUP;
ccdd61
+const char* parentgroups[] = {LEGAL_PARENT_GROUPS};
ccdd61
 const char* logident = "Mailman mail-wrapper";
ccdd61
 
ccdd61
 
ccdd61
@@ -74,7 +74,7 @@
ccdd61
                 fatal(logident, MAIL_ILLEGAL_COMMAND,
ccdd61
                       "Illegal command: %s", argv[1]);
ccdd61
 
ccdd61
-        check_caller(logident, parentgroup);
ccdd61
+        check_caller(logident, parentgroups, sizeof(parentgroups) / sizeof(parentgroups[0]));
ccdd61
 
ccdd61
         /* If we got here, everything must be OK */
ccdd61
         status = run_script(argv[1], argc, argv, env);
ccdd61
diff -ruN mailman-2.1.12-a/src/Makefile.in mailman-2.1.12-b/src/Makefile.in
ccdd61
--- mailman-2.1.12-a/src/Makefile.in	2009-02-23 22:23:35.000000000 +0100
ccdd61
+++ mailman-2.1.12-b/src/Makefile.in	2009-07-28 12:19:47.000000000 +0200
ccdd61
@@ -49,9 +49,9 @@
ccdd61
 
ccdd61
 SHELL=		/bin/sh
ccdd61
 
ccdd61
-MAIL_FLAGS=	-DMAIL_GROUP="\"$(MAIL_GROUP)\""
ccdd61
+MAIL_FLAGS=	-DMAIL_GROUP='$(MAIL_GROUP)'
ccdd61
 
ccdd61
-CGI_FLAGS=	-DCGI_GROUP="\"$(CGI_GROUP)\""
ccdd61
+CGI_FLAGS=	-DCGI_GROUP='$(CGI_GROUP)'
ccdd61
 
ccdd61
 HELPFUL=	-DHELPFUL
ccdd61