diff src/local.c @ 205:4fd237550525

REMOVED MAILDIR SUPPORT if you want to deliver to maildir, use an MDA like procmail masqmail can pass mail to an MDA by setting `mda' in masqmail.conf
author meillo@marmaro.de
date Fri, 16 Jul 2010 16:38:50 +0200
parents d1c53e76096f
children 996b53a50f55
line wrap: on
line diff
--- a/src/local.c	Fri Jul 16 15:38:53 2010 +0200
+++ b/src/local.c	Fri Jul 16 16:38:50 2010 +0200
@@ -144,132 +144,6 @@
 	return ok;
 }
 
-#ifdef ENABLE_MAILDIR
-gboolean
-maildir_out(message * msg, GList * hdr_list, gchar * user, guint flags)
-{
-	struct passwd *pw;
-	gboolean ok = FALSE;
-
-	/* headers may be special for a local delivery */
-	if (hdr_list == NULL)
-		hdr_list = msg->hdr_list;
-
-	if ((pw = getpwnam(user))) {
-		uid_t saved_uid = geteuid();
-		gid_t saved_gid = getegid();
-		gboolean uid_ok = TRUE, gid_ok = TRUE;
-
-		if (!conf.run_as_user) {
-			uid_ok = (seteuid(0) == 0);
-			if (uid_ok) {
-				gid_ok = (setegid(conf.mail_gid) == 0);
-				uid_ok = (seteuid(pw->pw_uid) == 0);
-			}
-		}
-
-		DEBUG(5) debugf("running as euid %d, egid %d\n", geteuid(), getegid());
-
-		if (uid_ok && gid_ok) {
-			char *path = g_strdup_printf("%s/Maildir", pw->pw_dir);
-			struct stat statbuf;
-			int ret;
-
-			DEBUG(5) debugf("  path = %s\n", path);
-
-			ok = TRUE;
-			ret = stat(path, &statbuf);
-			if (ret != 0) {
-				ok = FALSE;
-				if (errno == ENOENT) {
-					logwrite(LOG_NOTICE, "directory %s does not exist, creating\n", path);
-					if (mkdir(path, 0700) == 0)
-						ok = TRUE;
-				} else
-					logwrite(LOG_ALERT, "stat of %s failed: %s\n", path, strerror(errno));
-			}
-			if (ok) {
-				ok = FALSE;
-				ret = stat(path, &statbuf);
-				if (S_ISDIR(statbuf.st_mode)) {
-					gchar *subdirs[] = { "tmp", "new", "cur" };
-					int i;
-					for (i = 0; i < 3; i++) {
-						char *path1 = g_strdup_printf("%s/%s", path, subdirs[i]);
-						ret = stat(path1, &statbuf);
-						if (ret != 0) {
-							if (errno == ENOENT) {
-								logwrite(LOG_NOTICE, "directory %s does not exist, creating\n", path1);
-								if (mkdir(path1, 0700) != 0)
-									break;
-							}
-						}
-						g_free(path1);
-					}
-					if (i == 3) {
-						FILE *out;
-						mode_t saved_mode = umask(066);
-						/* the qmail style unique works only if delivering with different process.
-						   We do not fork for each delivery, so our uid is more unique.
-						   Hope it is compatible with all MUAs.
-						 */
-						gchar *filename = g_strdup_printf("%s/tmp/%s.%s", path, msg->uid, conf.host_name);
-
-						DEBUG(5) debugf("filename = %s\n", filename);
-
-						if ((out = fopen(filename, "w"))) {
-							gchar *newname = g_strdup_printf("%s/new/%s.%s", path, msg->uid, conf.host_name);
-							message_stream(out, msg, hdr_list, flags);
-							ok = TRUE;
-							if (fflush(out) == EOF)
-								ok = FALSE;
-							else if (fdatasync(fileno(out)) != 0) {
-								if (errno != EINVAL)
-									/* some fs do not support this..  I hope this also means that it is not necessary */
-									ok = FALSE;
-							}
-							fclose(out);
-							if (rename(filename, newname) != 0) {
-								ok = FALSE;
-								logwrite(LOG_ALERT, "moving %s to %s failed: %s", filename, newname, strerror(errno));
-							}
-							g_free(newname);
-						}
-						umask(saved_mode);
-						g_free(filename);
-					}
-				} else {
-					logwrite(LOG_ALERT, "%s is not a directory\n", path);
-					errno = ENOTDIR;
-				}
-			}
-			if (!conf.run_as_user) {
-				uid_ok = (seteuid(0) == 0);
-				if (uid_ok) {
-					gid_ok = (setegid(saved_gid) == 0);
-					uid_ok = (seteuid(saved_uid) == 0);
-				}
-			}
-			if (!uid_ok || !gid_ok) {
-				/* FIXME: if this fails we HAVE to exit, because we shall not run
-				   with some users id. But we do not return, and so this message
-				   will not be finished, so the user will get the message again
-				   next time a delivery is attempted... */
-				logwrite(LOG_ALERT, "could not set back uid or gid after local delivery: %s\n", strerror(errno));
-				exit(EXIT_FAILURE);
-			}
-			g_free(path);
-		} else {
-			logwrite(LOG_ALERT, "could not set uid or gid for local delivery, uid = %d: %s\n", pw->pw_uid, strerror(errno));
-		}
-	} else {
-		logwrite(LOG_ALERT, "could not find password entry for user %s\n", user);
-		errno = ENOENT;  /* getpwnam does not set errno correctly */
-	}
-	return ok;
-}
-#endif
-
 gboolean
 pipe_out(message * msg, GList * hdr_list, address * rcpt, gchar * cmd, guint flags)
 {