areguera / rpms / mailman

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