1 diff -urN -x '*~' postfix-2.2.5/src/global/mail_params.h postfix-2.2.5-ident/src/global/mail_params.h
2 --- postfix-2.2.5/src/global/mail_params.h 2006-02-22 16:20:15.000000000 +0100
3 +++ postfix-2.2.5-ident/src/global/mail_params.h 2006-02-22 15:56:31.000000000 +0100
5 #define DEF_SMTP_EHLO_DIS_MAPS ""
6 extern char *var_smtp_ehlo_dis_maps;
8 +#define VAR_SMTPD_IDENT_LOOKUP "smtpd_ident_lookup"
9 +#define DEF_SMTPD_IDENT_LOOKUP ""
10 +extern char *var_smtpd_ident_lookup;
14 diff -urN -x '*~' postfix-2.2.5/src/smtpd/smtpd_ident.c postfix-2.2.5-ident/src/smtpd/smtpd_ident.c
15 --- postfix-2.2.5/src/smtpd/smtpd_ident.c 1970-01-01 01:00:00.000000000 +0100
16 +++ postfix-2.2.5-ident/src/smtpd/smtpd_ident.c 2006-02-22 15:56:31.000000000 +0100
18 +#include <sys_defs.h>
19 +#include <sys/socket.h>
20 +#include <netinet/in.h>
21 +#include <arpa/inet.h>
22 +#include <stdio.h> /* strerror() */
25 +#include <mymalloc.h>
26 +#include <sys/types.h>
27 +#include <sys/time.h>
34 +#define IDENT_MSGSIZE 256
35 +#define IDENT_TIMEOUT 10
37 +#define CHOMP(STR) { char *tmp; tmp = STR; while (*tmp) { \
38 + if (*tmp == '\n' || *tmp == '\r') *tmp = '\0'; tmp++ ; } }
40 +char *smtpd_ident(struct sockaddr_in *peer_addr, struct sockaddr_in *smtpd_addr)
43 + char ident_msg[IDENT_MSGSIZE + 1], *sp;
44 + char ident_user[IDENT_MSGSIZE + 1];
45 + struct sockaddr_in local_addr;
46 + struct sockaddr_in ident_addr;
48 + VSTREAM *ident_stream;
50 + memset(ident_msg, 0, IDENT_MSGSIZE + 1);
51 + memset(ident_user, 0, IDENT_MSGSIZE + 1);
54 + * Bind the local sockaddr to the same interface as smtpd before
55 + * connecting back to the auth port on the peer. This helps
56 + * with multihomed postfix servers. First, set up the address.
59 + /* Local sockname */
61 + memset((char *) &local_addr, 0, sizeof(local_addr));
62 + local_addr.sin_family = AF_INET;
63 + memcpy((void *) &local_addr.sin_addr, (void *) &smtpd_addr->sin_addr, sizeof(local_addr.sin_addr));
65 + /* Remote sockname + port */
67 + memset((char *) &ident_addr, 0, sizeof(ident_addr));
68 + ident_addr.sin_family = AF_INET;
69 + memcpy((void *) &ident_addr.sin_addr, (void *) &peer_addr->sin_addr, sizeof(ident_addr.sin_addr));
70 + ident_addr.sin_port = htons(113);
75 + if ((ident_sock = socket(ident_addr.sin_family, SOCK_STREAM, 0)) < 0) {
76 + msg_warn("Can't allocate socket for ident lookup: %s", strerror(errno));
80 + /* Now bind the local sock to the interface */
82 + if (bind(ident_sock, (struct sockaddr *)&local_addr, sizeof(local_addr)) < 0) {
83 + msg_warn("local bind of ident sock failed: %s", strerror(errno));
87 + /* connect() back to the smtp client host on port 113 */
89 + if (connect(ident_sock, (struct sockaddr *) &ident_addr, sizeof(ident_addr )) < 0) {
90 + msg_warn( "ident connect to %s: %s", inet_ntoa(peer_addr->sin_addr),
95 + /* Ok, make this a vstream */
97 + ident_stream = vstream_fdopen(ident_sock, O_RDWR);
98 + ident_stream->timeout = IDENT_TIMEOUT;
100 + /* Print the ident message to the remote host */
102 + vstream_fprintf(ident_stream, "%d, %d\n", ntohs(peer_addr->sin_port), ntohs(smtpd_addr->sin_port));
103 + if (vstream_ftimeout(ident_stream)) {
104 + msg_warn( "ident write timed out to %s", inet_ntoa(peer_addr->sin_addr));
108 + /* Read back the result */
110 + vstream_fread(ident_stream, ident_msg, IDENT_MSGSIZE);
111 + if (vstream_ftimeout(ident_stream)) {
112 + msg_warn( "ident read timed out to %s", inet_ntoa(peer_addr->sin_addr));
117 + * Should I even bother with this?
119 + * Even if so, don't worry about this failing, set the timeout low
122 + ident_stream->timeout = 2;
123 + vstream_fwrite(ident_stream, "quit\n", strlen("quit\n"));
125 + if (strlen(ident_msg) == 0) {
126 + msg_warn( "Failed to get ident string from %s", inet_ntoa(peer_addr->sin_addr));
130 + if ((sp = strrchr(ident_msg, ':')) == NULL) {
131 + msg_warn( "Invalid ident string from %s", inet_ntoa(peer_addr->sin_addr));
136 + while (*sp && (*sp == ' ' || *sp == '\t')) {
140 + /* If we break before this line, we know we had some sort of bad error */
142 + strncpy(ident_user, sp, IDENT_MSGSIZE);
143 + msg_info( "Received ident string %s from %s", sp, inet_ntoa(peer_addr->sin_addr));
147 + if (strlen(ident_user) == 0) {
148 + msg_warn( "Failed to get ident user for %s", inet_ntoa(peer_addr->sin_addr));
152 + vstream_fclose(ident_stream);
153 + return_val = mystrdup(ident_user);
156 --- postfix-2.3-RC9/src/smtpd/smtpd.c.orig 2006-07-11 20:13:27.780850288 +0200
157 +++ postfix-2.3-RC9/src/smtpd/smtpd.c 2006-07-11 20:27:06.515383720 +0200
158 @@ -1024,6 +1024,7 @@
159 char *var_local_rwr_clients;
160 char *var_smtpd_ehlo_dis_words;
161 char *var_smtpd_ehlo_dis_maps;
162 +char *var_smtpd_ident_lookup;
164 char *var_smtpd_tls_level;
165 bool var_smtpd_use_tls;
166 @@ -1119,6 +1120,11 @@
167 int smtpd_input_transp_mask;
170 + * Hosts that should be ident-queried
172 +NAMADR_LIST *smtpd_ident_lookup;
175 * Forward declarations.
177 static void helo_reset(SMTPD_STATE *);
178 @@ -2503,10 +2509,18 @@
179 * intermediate proxy.
181 if (!proxy || state->xforward.flags == 0) {
182 - out_fprintf(out_stream, REC_TYPE_NORM,
183 - "Received: from %s (%s [%s])",
184 - state->helo_name ? state->helo_name : state->name,
185 - state->name, state->rfc_addr);
186 + if (namadr_list_match(smtpd_ident_lookup, state->name, state->addr)) {
187 + out_fprintf(out_stream, REC_TYPE_NORM,
188 + "Received: from %s (%s [%s] ident=%s)",
189 + state->helo_name ? state->helo_name : state->name,
190 + state->name, state->rfc_addr,
191 + state->ident_user);
193 + out_fprintf(out_stream, REC_TYPE_NORM,
194 + "Received: from %s (%s [%s])",
195 + state->helo_name ? state->helo_name : state->name,
196 + state->name, state->rfc_addr);
199 #define VSTRING_STRDUP(s) vstring_strcpy(vstring_alloc(strlen(s) + 1), (s))
201 @@ -4451,6 +4451,9 @@
202 xclient_hosts = namadr_list_init(MATCH_FLAG_NONE, var_xclient_hosts);
203 xforward_hosts = namadr_list_init(MATCH_FLAG_NONE, var_xforward_hosts);
204 hogger_list = namadr_list_init(MATCH_FLAG_NONE, var_smtpd_hoggers);
205 + smtpd_ident_lookup =
206 + namadr_list_init(match_parent_style(VAR_SMTPD_IDENT_LOOKUP),
207 + var_smtpd_ident_lookup);
210 * Open maps before dropping privileges so we can read passwords etc.
211 @@ -5076,6 +5093,7 @@
212 VAR_MILT_V, DEF_MILT_V, &var_milt_v, 1, 0,
213 VAR_STRESS, DEF_STRESS, &var_stress, 0, 0,
214 VAR_REJECT_REPLY_MSG_ACCESS_DENIED, DEF_REJECT_REPLY_MSG_ACCESS_DENIED, &var_reject_reply_msg_access_denied, 1, 0,
215 + VAR_SMTPD_IDENT_LOOKUP, DEF_SMTPD_IDENT_LOOKUP, &var_smtpd_ident_lookup, 0, 0,
216 VAR_UNV_FROM_WHY, DEF_UNV_FROM_WHY, &var_unv_from_why, 0, 0,
217 VAR_UNV_RCPT_WHY, DEF_UNV_RCPT_WHY, &var_unv_rcpt_why, 0, 0,
218 VAR_REJECT_TMPF_ACT, DEF_REJECT_TMPF_ACT, &var_reject_tmpf_act, 1, 0,
219 --- postfix-2.3-RC9/src/smtpd/smtpd.h.orig 2006-07-09 21:49:21.000000000 +0200
220 +++ postfix-2.3-RC9/src/smtpd/smtpd.h 2006-07-11 20:30:43.993322048 +0200
222 char *addr; /* client host address string */
223 char *namaddr; /* combined name and address */
224 char *rfc_addr; /* address for RFC 2821 */
225 + char *ident_user; /* user name returned by ident RFC 1413 */
226 int addr_family; /* address family */
227 struct sockaddr_storage sockaddr; /* binary client endpoint */
228 int name_status; /* 2=ok 4=soft 5=hard 6=forged */
230 extern void smtpd_peer_init(SMTPD_STATE *state);
231 extern void smtpd_peer_reset(SMTPD_STATE *state);
233 +extern char *smtpd_ident(struct sockaddr_in *peer_addr, struct sockaddr_in *smtpd_addr);
235 #define SMTPD_PEER_CODE_OK 2
236 #define SMTPD_PEER_CODE_TEMP 4
237 #define SMTPD_PEER_CODE_PERM 5
238 --- postfix-2.3-RC9/src/smtpd/smtpd_peer.c.orig 2006-07-08 02:51:33.000000000 +0200
239 +++ postfix-2.3-RC9/src/smtpd/smtpd_peer.c 2006-07-11 20:41:04.935924424 +0200
242 #include <sys_defs.h>
243 #include <sys/socket.h>
244 +#include <sys/types.h>
245 #include <netinet/in.h>
246 #include <arpa/inet.h>
247 #include <stdio.h> /* strerror() */
250 /* Global library. */
252 +#include <namadr_list.h>
253 #include <mail_proto.h>
254 #include <valid_mailhost_addr.h>
255 #include <mail_params.h>
260 +extern NAMADR_LIST *smtpd_ident_lookup;
262 /* smtpd_peer_init - initialize peer information */
264 void smtpd_peer_init(SMTPD_STATE *state)
266 const char *myname = "smtpd_peer_init";
267 SOCKADDR_SIZE sa_length;
269 + struct sockaddr_in serv_sin;
270 + char *ident_user = NULL;
271 + SOCKADDR_SIZE sa_len;
272 INET_PROTO_INFO *proto_info = inet_proto_info();
274 sa = (struct sockaddr *) & (state->sockaddr);
276 state->addr_family = AF_UNSPEC;
277 state->name_status = SMTPD_PEER_CODE_PERM;
278 state->reverse_name_status = SMTPD_PEER_CODE_PERM;
279 + state->ident_user = mystrdup("NO-USER");
280 state->port = mystrdup(CLIENT_PORT_UNKNOWN);
285 msg_warn("%s: hostname %s verification failed: %s",
286 state->addr, state->name, MAI_STRERROR(aierr));
287 + state->ident_user = mystrdup("NO-USER");
288 REJECT_PEER_NAME(state, (TEMP_AI_ERROR(aierr) ?
289 SMTPD_PEER_CODE_TEMP : SMTPD_PEER_CODE_FORGED));
296 + if (namadr_list_match(smtpd_ident_lookup, state->name, state->addr)) {
297 + /* If getsockname fails, just forget it */
298 + sa_len = sizeof(serv_sin);
299 + if (getsockname(vstream_fileno(state->client), (struct sockaddr *)&serv_sin, &sa_len) >= 0) {
300 + ident_user = smtpd_ident((struct sockaddr_in *)sa, &serv_sin);
301 + if (ident_user == NULL)
302 + state->ident_user = mystrdup("NO-USER");
304 + state->ident_user = ident_user;
306 + msg_warn("getsockname failed while doing ident lookup: %s", strerror(errno));
308 + state->ident_user = mystrdup("NO-USER");
313 state->name_status = SMTPD_PEER_CODE_OK;
314 state->reverse_name_status = SMTPD_PEER_CODE_OK;
315 state->port = mystrdup("0"); /* XXX bogus. */
317 + state->ident_user = mystrdup("NO-USER");
321 * Do the name[addr]:port formatting for pretty reports.
324 myfree(state->namaddr);
325 myfree(state->rfc_addr);
326 + myfree(state->ident_user);
329 --- postfix-2.8.3/src/smtpd/Makefile.in~ 2011-05-17 14:28:28.406666872 +0200
330 +++ postfix-2.8.3/src/smtpd/Makefile.in 2011-05-17 14:31:06.946666872 +0200
332 SRCS = smtpd.c smtpd_token.c smtpd_check.c smtpd_chat.c smtpd_state.c \
333 smtpd_peer.c smtpd_sasl_proto.c smtpd_sasl_glue.c smtpd_proxy.c \
334 smtpd_xforward.c smtpd_dsn_fix.c smtpd_milter.c smtpd_resolve.c \
336 + smtpd_expand.c smtpd_ident.c
337 OBJS = smtpd.o smtpd_token.o smtpd_check.o smtpd_chat.o smtpd_state.o \
338 smtpd_peer.o smtpd_sasl_proto.o smtpd_sasl_glue.o smtpd_proxy.o \
339 smtpd_xforward.o smtpd_dsn_fix.o smtpd_milter.o smtpd_resolve.o \
341 + smtpd_expand.o smtpd_ident.o
342 HDRS = smtpd_token.h smtpd_check.h smtpd_chat.h smtpd_sasl_proto.h \
343 smtpd_sasl_glue.h smtpd_proxy.h smtpd_dsn_fix.h smtpd_milter.h \
344 smtpd_resolve.h smtpd_expand.h