[Raw Msg Headers][Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

DOMAIN_AWARE_GETPWNAM



Matti,

could you please look into the included diff?  The idea behind it: in
virtual domain environment, make possible to verify user existence on
the router stage rather than on local delivery stage.

With this diff, if your (replacement) getpwnam() handles usernames with
domain, you do *not* need to define ROUTEUSER_IN_ABNORMAL_UNIX, have one
step less in generating DSNs on nonexistent users, and in the future it
will be possible to verify user existence in the course of SNTP session.

I am more or less confident in the C code changes that I made, but much
less - in the zsh code, please could you look into it?

One unrelated thing included in the diff - on ./configure run, read in a
couple of ZENV variables from existing zmailer.conf that where left
out.  Remove this part if you think that it is inappropriate.

Thanks.

Index: SiteConfig.in
===================================================================
RCS file: /cvsroot/zmailer/SiteConfig.in,v
retrieving revision 1.25
diff -u -r1.25 SiteConfig.in
--- SiteConfig.in	2003/08/28 23:51:26	1.25
+++ SiteConfig.in	2003/10/06 17:10:14
@@ -403,7 +403,7 @@
 #     scheduler completion of a message
 #</DESC></VAR>
 #SYSLOGFLG=SRT
-SYSLOGFLG=RT
+SYSLOGFLG=@SYSLOGFLG@
 
 #<VAR><NAME>TRUSTEDUSER</NAME><DESC>
 # Per default,  ZMailer uses ``daemon'' userid when it wants to
@@ -465,3 +465,13 @@
 # of subsystem internal state.
 #</DESC></VAR>
 SNMPSHAREDFILE=@SNMPSHAREDFILE@
+
+#<VAR><NAME>DOMAIN_AWARE_GETPWNAM</NAME><DESC>
+# Define this to "1" if you use (replacement) getpwnam()
+# that handles username together with domain.
+# This is a convenient way to support virtual domains: users
+# in different domains automatically have different userids,
+# different homes etc.  Actually, this often can be arranged
+# even within standard /etc/passwd model, at least on Linux.
+#</DESC></VAR>
+DOMAIN_AWARE_GETPWNAM=@DOMAIN_AWARE_GETPWNAM@
Index: configure.in
===================================================================
RCS file: /cvsroot/zmailer/configure.in,v
retrieving revision 1.141
diff -u -r1.141 configure.in
--- configure.in	2003/09/26 23:44:48	1.141
+++ configure.in	2003/10/06 17:10:21
@@ -467,6 +467,13 @@
 fi
 AC_MSG_RESULT([Using ZMailer BINDADDR: $BINDADDR])
 
+AC_SUBST(SYSLOGFLG)
+AC_MSG_RESULT([Using ZMailer SYSLOGFLG: $SYSLOGFLG])
+AC_SUBST(SNMPSHAREDFILE)
+AC_MSG_RESULT([Using ZMailer SNMPSHAREDFILE: $SNMPSHAREDFILE])
+AC_SUBST(DOMAIN_AWARE_GETPWNAM)
+AC_MSG_RESULT([Using ZMailer DOMAIN_AWARE_GETPWNAM: $DOMAIN_AWARE_GETPWNAM])
+
 sleep 2  # Sleep a bit here too
 
 AC_SUBST(LIBMALLOC)
Index: proto/cf/aliases.cf
===================================================================
RCS file: /cvsroot/zmailer/proto/cf/aliases.cf,v
retrieving revision 1.48
diff -u -r1.48 aliases.cf
--- proto/cf/aliases.cf	2003/08/18 10:14:51	1.48
+++ proto/cf/aliases.cf	2003/10/06 17:10:21
@@ -213,6 +213,7 @@
 	local chan user host lcuser mxh al a l
 	local key attr pobox nattr homedir sender
 	local plustail2 forward priv hashomedir type
+	local sysuser
 
 	plustail2=""
 
@@ -220,6 +221,12 @@
 	chan=$(channel $quad)
 	host=$(host $quad)
 	user=$(user $quad)
+
+	if [ "$DOMAIN_AWARE_GETPWNAM" = "1" ] ; then
+		sysuser=$host		# for local chan this is user@domain
+	else
+		sysuser=$user
+	fi
 	
 	# For the expansions control tag we can use only
 	# the 'channel',  and the 'username' strings, we CAN'T
@@ -626,7 +633,7 @@
 #	only allow .forward file reading if privs allow it
 
 	hashomedir=
-	if homedir="$(homedirectory "$user")" ; then
+	if homedir="$(homedirectory "$sysuser")" ; then
 		hashomedir=1
 	else
 	    [ -n "$defer" ] &&
@@ -744,7 +751,7 @@
 	# local user with no alias and no .forward file
 
 	if [ -n "$pobox" ] ; then
-		priv=$(login2uid "$user")
+		priv=$(login2uid "$sysuser")
 		returns (((local "pob:$user" "$pobox$plustail$domain" $(newattribute $attr privilege $priv))))
 	fi
 
Index: proto/cf/server.cf
===================================================================
RCS file: /cvsroot/zmailer/proto/cf/server.cf,v
retrieving revision 1.11
diff -u -r1.11 server.cf
--- proto/cf/server.cf	2003/02/06 21:53:10	1.11
+++ proto/cf/server.cf	2003/10/06 17:10:21
@@ -17,7 +17,9 @@
 		.*
 			ssift "$user" in
 			(.*)@([^@]+)	# FQDN format address ?
-				user="\1" ;;
+				if [ "$DOMAIN_AWARE_GETPWNAM" != "1" ] ; then
+					user="\1"
+				fi
 			.*	;;
 			tfiss
 
Index: transports/mailbox/fmtmbox.c
===================================================================
RCS file: /cvsroot/zmailer/transports/mailbox/fmtmbox.c,v
retrieving revision 1.4
diff -u -r1.4 fmtmbox.c
--- transports/mailbox/fmtmbox.c	2001/01/22 23:35:11	1.4
+++ transports/mailbox/fmtmbox.c	2003/10/06 17:10:22
@@ -135,7 +135,7 @@
 			}
 			break;
 		case 'u':
-			overflow |= put_s(&q,ebuf,pwd->pw_name);
+			overflow |= put_s(&q,ebuf,address); /* dom cut off */
 			break;
 		case 'U':
 			overflow |= put_s(&q,ebuf,pwd->pw_gecos);
@@ -149,12 +149,12 @@
 			overflow |= put_s(&q,ebuf,dom);
 			break;
 		case 'x':
-			if (!phash) phash=pjwhash32(pwd->pw_name);
+			if (!phash) phash=pjwhash32(address);
 			overflow |= put_c(&q, ebuf, 'A' + (phash % 26));
 			phash /= 26;
 			break;
 		case 'X':
-			if (!chash) chash=crc32(pwd->pw_name);
+			if (!chash) chash=crc32(address);
 			overflow |= put_c(&q, ebuf, 'A' + (chash % 26));
 			chash /= 26;
 			break;
Index: transports/mailbox/mailbox.c
===================================================================
RCS file: /cvsroot/zmailer/transports/mailbox/mailbox.c,v
retrieving revision 1.111
diff -u -r1.111 mailbox.c
--- transports/mailbox/mailbox.c	2003/09/02 17:46:33	1.111
+++ transports/mailbox/mailbox.c	2003/10/06 17:10:23
@@ -373,6 +373,8 @@
 #endif
 int	D_alloc = 0;
 
+static int domain_aware_getpwnam=0;
+
 static int zsfsetfd(fp, fd)
      Sfio_t *fp;
      int fd;
@@ -638,6 +640,15 @@
 	if (!defcharset)
 	  defcharset = DefCharset;
 
+	if (domain_aware_getpwnam == 0) {
+	  char *s=getzenv("DOMAIN_AWARE_GETPWNAM");
+	  if (s && (*s == '1')) {
+	    domain_aware_getpwnam=1;
+	  } else {
+	    domain_aware_getpwnam=-1;
+	  }
+	}
+
 	while (!getout) {
 
 	  /* Input:
@@ -766,6 +777,30 @@
 	/* Now the '*user' points to a NIL, or '@' */
 }
 
+static void rfc822dequote __((char *));
+static void
+rfc822dequote(user)
+	char *user;
+{
+	char *s = user;
+	int escaped=0;
+
+	for (;*user;user++) {
+		if (escaped) {
+			*s++=*user;
+			escaped=0;
+		} else {
+			if (*user == '"') continue;
+			if (*user == '\\') {
+				escaped=1;
+				continue;
+			}
+			*s++=*user;
+		}
+	}
+	*s='\0';
+}
+
 void
 process(dp)
 	struct ctldesc *dp;
@@ -830,7 +865,10 @@
 	  while (*user == TO_USER)
 	    ++user;
 
-	  rfc822localize(user);
+	  if (domain_aware_getpwnam == 1)
+		rfc822dequote(user);
+	  else
+	 	rfc822localize(user);
 
 	  time(&curtime);
 	  ts = ctime(&curtime);


-
To unsubscribe from this list: send the line "unsubscribe zmailer" in
the body of a message to majordomo@nic.funet.fi