changeset 295:db3bd20566aa

uid check et al
author mmj
date Wed, 18 Aug 2004 05:10:04 +1000
parents 1fef8f37fb4a
children 21f477d65e57
files ChangeLog VERSION src/mlmmj-process.c src/mlmmj-recieve.c src/mlmmj-send.c
diffstat 5 files changed, 68 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Aug 17 23:51:05 2004 +1000
+++ b/ChangeLog	Wed Aug 18 05:10:04 2004 +1000
@@ -1,3 +1,6 @@
+ o Make sure that only either root or the listdir owner can execute the
+   binaries when it has something to do with lists.
+ o Don't leave bounces-help@ mails lying around in queue/
  o Remove unanchored ".*" from beginning of regexp
 0.8.3
  o Have mlmmj-make-ml.sh remind people about using cron if they want
--- a/VERSION	Tue Aug 17 23:51:05 2004 +1000
+++ b/VERSION	Wed Aug 18 05:10:04 2004 +1000
@@ -1,1 +1,1 @@
-0.8.3
+0.8.4
--- a/src/mlmmj-process.c	Tue Aug 17 23:51:05 2004 +1000
+++ b/src/mlmmj-process.c	Wed Aug 18 05:10:04 2004 +1000
@@ -342,6 +342,8 @@
 	char *listfqdn, *listname, *fromaddr, *fromstr, *subject;
 	char *queuefilename, *recipdelim, *owner = NULL;
 	char *maildata[4];
+	struct stat st;
+	uid_t uid;
 	struct email_container fromemails = { 0, NULL };
 	struct email_container toemails = { 0, NULL };
 	struct email_container ccemails = { 0, NULL };
@@ -387,12 +389,32 @@
 			exit(EXIT_SUCCESS);
 		}
 	}
+
 	if(listdir == NULL || mailfile == NULL) {
 		fprintf(stderr, "You have to specify -L and -m\n");
 		fprintf(stderr, "%s -h for help\n", argv[0]);
 		exit(EXIT_FAILURE);
 	}
 
+	/* Lets make sure no random user tries to send mail to the list */
+	if(listdir) {
+		if(stat(listdir, &st) == 0) {
+			uid = getuid();
+			if(uid && uid != st.st_uid) {
+				log_error(LOG_ARGS,
+					"Have to invoke either as root "
+					"or as the user owning listdir");
+				writen(STDERR_FILENO,
+					"Have to invoke either as root "
+					"or as the user owning listdir\n", 60);
+				exit(EXIT_FAILURE);
+			}
+		} else {
+			log_error(LOG_ARGS, "Could not stat %s", listdir);
+			exit(EXIT_FAILURE);
+		}
+	}
+
         do {
                 myfree(donemailname);
                 myfree(randomstr);
--- a/src/mlmmj-recieve.c	Tue Aug 17 23:51:05 2004 +1000
+++ b/src/mlmmj-recieve.c	Wed Aug 18 05:10:04 2004 +1000
@@ -57,6 +57,8 @@
 	char *randomstr = random_str();
 	char *mlmmjprocess, *bindir;
 	int fd, opt, noprocess = 0, nofork = 0;
+	struct stat st;
+	uid_t uid;
 	pid_t childpid;
 
 	CHECKFULLPATH(argv[0]);
@@ -86,12 +88,32 @@
 			exit(0);
 		}
 	}
+
 	if(listdir == NULL) {
 		fprintf(stderr, "You have to specify -L\n");
 		fprintf(stderr, "%s -h for help\n", argv[0]);
 		exit(EXIT_FAILURE);
 	}
 	
+	/* Lets make sure no random user tries to send mail to the list */
+	if(listdir) {
+		if(stat(listdir, &st) == 0) {
+			uid = getuid();
+			if(uid && uid != st.st_uid) {
+				log_error(LOG_ARGS,
+					"Have to invoke either as root "
+					"or as the user owning listdir");
+				writen(STDERR_FILENO,
+					"Have to invoke either as root "
+					"or as the user owning listdir\n", 60);
+				exit(EXIT_FAILURE);
+			}
+		} else {
+			log_error(LOG_ARGS, "Could not stat %s", listdir);
+			exit(EXIT_FAILURE);
+		}
+	}
+	
 	infilename = concatstr(3, listdir, "/incoming/", randomstr);
 	myfree(randomstr);
 	fd = open(infilename, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR);
--- a/src/mlmmj-send.c	Tue Aug 17 23:51:05 2004 +1000
+++ b/src/mlmmj-send.c	Wed Aug 18 05:10:04 2004 +1000
@@ -471,6 +471,7 @@
 	struct dirent *dp;
 	struct stat st;
 	struct hostent *relayent;
+	uid_t uid;
 
 	CHECKFULLPATH(argv[0]);
 	
@@ -527,6 +528,25 @@
 		exit(EXIT_FAILURE);
 	}
 
+	/* Lets make sure no random user tries to send mail to the list */
+	if(listdir) {
+		if(stat(listdir, &st) == 0) {
+			uid = getuid();
+			if(uid && uid != st.st_uid) {
+				log_error(LOG_ARGS,
+					"Have to invoke either as root "
+					"or as the user owning listdir");
+				writen(STDERR_FILENO,
+					"Have to invoke either as root "
+					"or as the user owning listdir\n", 60);
+				exit(EXIT_FAILURE);
+			}
+		} else {
+			log_error(LOG_ARGS, "Could not stat %s", listdir);
+			exit(EXIT_FAILURE);
+		}
+	}
+
 	if(!listctrl)
 		listctrl = mystrdup("0");