summarylogtreecommitdiffstats
path: root/ssmtp-aliases.patch
blob: 18e4286a6003e5825085d7865dfedd5b3134728c (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
157
158
159
diff --git a/Makefile.in b/Makefile.in
index 1cb7075..abdc797 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -17,6 +17,7 @@ SSMTPCONFDIR=$(etcdir)/ssmtp
 # 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 @@ EXTRADEFS=\
 -DSSMTPCONFDIR=\"$(SSMTPCONFDIR)\" \
 -DCONFIGURATION_FILE=\"$(CONFIGURATION_FILE)\" \
 -DREVALIASES_FILE=\"$(REVALIASES_FILE)\" \
+-DALIASES_FILE=\"$(ALIASES_FILE)\" \
 
 
 CFLAGS=@DEFS@ $(EXTRADEFS) @CFLAGS@
diff --git a/README b/README
index be34c9d..d3d7556 100644
--- a/README
+++ b/README
@@ -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 --git a/ssmtp.8 b/ssmtp.8
index 116c446..d7c6893 100644
--- a/ssmtp.8
+++ b/ssmtp.8
@@ -22,7 +22,8 @@ placed in dead.letter in the sender's home directory.
 .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 machines whose sendmails are too
 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 receiving host.  It especially does not deliver to pipelines.
+It does not honor .forwards, which have to be done on the receiving host.  It
+especially does not deliver to pipelines.
 
 .SH OPTIONS
 Most sendmail options are irrelevant to sSMTP. Those marked ``ignored'' or
@@ -275,6 +275,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).
diff --git a/ssmtp.c b/ssmtp.c
index e847320..c639c55 100644
--- a/ssmtp.c
+++ b/ssmtp.c
@@ -450,6 +450,50 @@ void revaliases(struct passwd *pw)
 }
 
 /* 
+ * 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)
@@ -675,9 +719,14 @@ rcpt_remap() -- Alias systems-level users to the person who
 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));
@@ -1898,7 +1947,7 @@ char **parse_options(int argc, char *argv[])
 	}
 	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;