areguera / rpms / mailman

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