summarylogtreecommitdiffstats
path: root/ssmtp-aliases.patch
blob: 36ef2a7dea093603eff2f6928fb50cf0a7acb293 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
--- ssmtp-2.61/Makefile.in   2008-06-07 14:41:15.000000000 -0400
+++ ssmtp-2.61.new/Makefile.in   2008-06-07 14:41:46.000000000 -0400
@@ -17,6 +17,7 @@
 # Configuration files
 CONFIGURATION_FILE=$(SSMTPCONFDIR)/ssmtp.conf
 REVALIASES_FILE=$(SSMTPCONFDIR)/revaliases
+ALIASES_FILE=/etc/aliases
 
 INSTALLED_CONFIGURATION_FILE=$(CONFIGURATION_FILE)
 INSTALLED_REVALIASES_FILE=$(REVALIASES_FILE)
@@ -34,6 +35,7 @@
 -DSSMTPCONFDIR=\"$(SSMTPCONFDIR)\" \
 -DCONFIGURATION_FILE=\"$(CONFIGURATION_FILE)\" \
 -DREVALIASES_FILE=\"$(REVALIASES_FILE)\" \
+-DALIASES_FILE=\"$(ALIASES_FILE)\" \
 
 
 CFLAGS=@DEFS@ $(EXTRADEFS) @CFLAGS@
diff -u -r -N ssmtp-2.61/ssmtp.c ssmtp-2.61.new/ssmtp.c
--- ssmtp-2.61/ssmtp.c   2008-06-07 14:41:15.000000000 -0400
+++ ssmtp-2.61.new/ssmtp.c   2008-06-07 14:41:51.000000000 -0400
@@ -429,6 +429,50 @@
 }
 
 /* 
+ * Eugene:
+ *
+ * simple aliases support:
+ * lookup aliases file and remap rcpt
+ */
+char *aliases_lookup(char *str)
+{
+	char buf[(BUF_SZ + 1)], *p;
+	char name[(BUF_SZ + 1)];
+	FILE *fp;
+	char *saveptr = NULL;
+
+	if((fp = fopen(ALIASES_FILE, "r"))) {
+		strncpy(name, str, BUF_SZ);
+		while(fgets(buf, sizeof(buf), fp)) {
+			/* Make comments invisible */
+			if((p = strchr(buf, '#'))) {
+				*p = (char)NULL;
+			}
+
+			/* Ignore malformed lines and comments */
+			if(strchr(buf, ':') == (char *)NULL) {
+				continue;
+			}
+
+			/* Parse the alias */
+			if( (p = strtok_r(buf, ": \t\r\n", &saveptr) ) && !strncmp(p, name, BUF_SZ) &&
+				(p = strtok_r(NULL, ": \t\r\n", &saveptr) )) {
+				if(log_level > 0) log_event(LOG_INFO, "Remapping: \"%s\" --> \"%s\"\n", name, p);
+				strncpy(name, p, BUF_SZ);
+			}
+		}
+
+		fclose(fp);
+		if( strcmp( str, name ) == 0 ) {
+			return strdup(name);
+		} else {
+			return aliases_lookup(name);
+		}
+
+	} else  return str; /* can't read aliases? it's not a problem */
+}
+
+/*
 from_strip() -- Transforms "Name <login@host>" into "login@host" or "login@host (Real name)"
 */
 char *from_strip(char *str)
@@ -654,9 +698,14 @@
 char *rcpt_remap(char *str)
 {
 	struct passwd *pw;
-	if((root==NULL) || strlen(root)==0 || strchr(str, '@') ||
-		((pw = getpwnam(str)) == NULL) || (pw->pw_uid > MAXSYSUID)) {
-		return(append_domain(str));	/* It's not a local systems-level user */
+	char *rcpt;
+
+	/* before all other mappings */
+	rcpt = aliases_lookup(str);
+
+	if((root==NULL) || strlen(root)==0 || strchr(rcpt, '@') ||
+		((pw = getpwnam(rcpt)) == NULL) || (pw->pw_uid > MAXSYSUID)) {
+		return(append_domain(rcpt));   /* It's not a local systems-level user */
 	}
 	else {
 		return(append_domain(root));
diff -up ssmtp-2.61/README.old ssmtp-2.61/README
--- ssmtp-2.61/README.old	2008-12-26 16:38:31.000000000 +0200
+++ ssmtp-2.61/README	2008-12-26 16:33:29.000000000 +0200
@@ -3,12 +3,12 @@ Purpose and value:
  send their mail via the departmental mailhub from which they pick up their
  mail (via pop, imap, rsmtp, pop_fetch, NFS... or the like).  This program
  accepts mail and sends it to the mailhub, optionally replacing the domain in
- the From: line with a different one.
+ the From: line with a different one and expanding aliases.
 
- WARNING: the above is all it does. It does not receive mail, expand aliases
- or manage a queue.  That belongs on a mailhub with a system administrator.
- The man page (ssmtp.8) and the program logic manual (ssmtp_plm) discuss the
- limitations in more detail.
+ WARNING: the above is all it does. It does not receive mail, or manage a
+ queue.  That belongs on a mailhub with a system administrator.  The man page
+ (ssmtp.8) and the program logic manual (ssmtp_plm) discuss the limitations in
+ more detail. Expanding aliases is only available after release 2.61-11.8.
 
  It uses a minimum of external configuration information, and so can be
  installed by copying the (right!) binary and an optional four-line config
diff -up ssmtp-2.61/ssmtp.8.old ssmtp-2.61/ssmtp.8
--- ssmtp-2.61/ssmtp.8.old	2008-12-26 16:38:49.000000000 +0200
+++ ssmtp-2.61/ssmtp.8	2008-12-26 16:46:33.000000000 +0200
@@ -22,7 +22,8 @@ placed in dead.letter in the sender's ho
 .PP
 Config files allow one to specify the address to receive mail from
 root, daemon, etc.; a default mailhub; a default domain to be used in
-From: lines; and per-user From: addresses and mailhub names.
+From: lines; per-user From: addresses and mailhub names; and aliases in the
+traditional format used by sendmail for the /etc/aliases file.
 .sp
 .PP
 It does not attempt to provide all the functionality of sendmail: it is
@@ -32,9 +33,8 @@ spool option for non-Sun machines, for m
 difficult (or various) to configure, for machines with known disfeatures in
 their sendmails or for ones where there are ``mysterious problems''. 
 .PP
-It does not do aliasing, which must be done either in the user agent
-or on the mailhub. Nor does it honor .forwards, which have to be done
-on the recieving host.  It especially does not deliver to pipelines.
+It does not honor .forwards, which have to be done on the recieving host.  It
+especially does not deliver to pipelines.
 
 .SH OPTIONS
 Most sendmail options are irrelevent to sSMTP. Those marked ``ignored'' or
@@ -271,6 +271,8 @@ through mail.isp.com.
  /etc/ssmtp/ssmtp.conf - configuration file
 .br
  /etc/ssmtp/revaliases - reverse aliases file
+.br
+ /etc/aliases - aliases file
 
 .SH SEE ALSO
 RFC821, RFC822, ssmtp.conf(5).
--- ssmtp-2.64/ssmtp.c.orig	2012-07-01 02:33:18.966734682 +0300
+++ ssmtp-2.64/ssmtp.c	2012-07-01 02:33:53.102942337 +0300
@@ -1781,7 +1781,7 @@ char **parse_options(int argc, char *arg
 	}
 	else if(strcmp(prog, "newaliases") == 0) {
 		/* Someone wanted to rebuild aliases */
-		paq("newaliases: Aliases are not used in sSMTP\n");
+		paq("newaliases: In sSMTP aliases are read from a plain text file\n");
 	}
 
 	i = 1;