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