changeset 345:8e5eaa8fc956

mlmmj-unsub should also setuid, and fix a bug in mlmmj-sub so -U is actually recognized as an option
author mmj
date Wed, 13 Oct 2004 21:06:39 +1000
parents 410780151412
children 86314c99da0a
files ChangeLog src/mlmmj-sub.c src/mlmmj-unsub.c
diffstat 3 files changed, 21 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Sep 24 08:30:05 2004 +1000
+++ b/ChangeLog	Wed Oct 13 21:06:39 2004 +1000
@@ -1,3 +1,4 @@
+ o mlmmj-unsub should also change user id to the listdir owner
  o Add support for not archiving the list by touching listdir/control/noarchive
  o Add 'nomail' version of lists. Subscribers to the nomail version are
    subscribed, but does not get any mail
--- a/src/mlmmj-sub.c	Fri Sep 24 08:30:05 2004 +1000
+++ b/src/mlmmj-sub.c	Wed Oct 13 21:06:39 2004 +1000
@@ -408,7 +408,7 @@
 	mlmmjsend = concatstr(2, bindir, "/mlmmj-send");
 	myfree(bindir);
 
-	while ((opt = getopt(argc, argv, "hcCdnVL:a:")) != -1) {
+	while ((opt = getopt(argc, argv, "hcCdnVUL:a:")) != -1) {
 		switch(opt) {
 		case 'a':
 			address = optarg;
--- a/src/mlmmj-unsub.c	Fri Sep 24 08:30:05 2004 +1000
+++ b/src/mlmmj-unsub.c	Wed Oct 13 21:06:39 2004 +1000
@@ -416,6 +416,7 @@
 	       " -h: This help\n"
 	       " -L: Full path to list directory\n"
 	       " -n: Subscribe to no mail version of list\n"
+	       " -U: Don't switch to the user id of the listdir owner\n"
 	       " -V: Print version\n"
 	       "When no options are specified, unsubscription silently "
 	       "happens\n", prg);
@@ -426,6 +427,7 @@
 {
 	int subread, subwrite, rlock, wlock, opt, unsubres, status, nomail = 0;
 	int confirmunsub = 0, unsubconfirm = 0, notifysub = 0, digest = 0;
+	int changeuid = 1;
 	char *listaddr, *listdir = NULL, *address = NULL, *subreadname = NULL;
 	char *subwritename, *mlmmjsend, *bindir, *subdir;
 	char *subddirname;
@@ -443,7 +445,7 @@
 	mlmmjsend = concatstr(2, bindir, "/mlmmj-send");
 	myfree(bindir);
 
-	while ((opt = getopt(argc, argv, "hcCdnVL:a:")) != -1) {
+	while ((opt = getopt(argc, argv, "hcCdnVUL:a:")) != -1) {
 		switch(opt) {
 		case 'L':
 			listdir = optarg;
@@ -466,6 +468,9 @@
 		case 'h':
 			print_help(argv[0]);
 			break;
+		case 'U':
+			changeuid = 0;
+			break;
 		case 'V':
 			print_version(argv[0]);
 			exit(0);
@@ -497,6 +502,19 @@
 	/* get the list address */
 	listaddr = getlistaddr(listdir);
 
+	if(changeuid) {
+		uid = getuid();
+		if(!uid && stat(listdir, &st) == 0) {
+			printf("Changing to uid %d, owner of %s.\n",
+					(int)st.st_uid, listdir);
+			if(setuid(st.st_uid) < 0) {
+				perror("setuid");
+				fprintf(stderr, "Continuing as uid %d\n",
+						(int)uid);
+			}
+		}
+	}
+
 	switch(typesub) {
 		case SUB_NORMAL:
 			subdir = mystrdup("/subscribers.d/");