masqmail

annotate src/libident/ident.c @ 304:d5ce2ba71e7b

manual formating of Received: hdrs; changed hdr for local receival Now the Received: headers are much friendlier to read. About folding: We must fold any line at 998 chars before transfer. We should fold the lines we produce at 78 chars. That is what RFC 2821 requests. We should think about it, somewhen. The header for locally (i.e. non-SMTP) received mail is changed to the format postfix uses. This matches RFC 2821 better. The `from' clause should contain a domain or IP, not a user name. Also, the `with' clause should contain a registered standard protocol name, which ``local'' is not.
author markus schnalke <meillo@marmaro.de>
date Thu, 09 Dec 2010 18:28:11 -0300
parents 08114f7dcc23
children
rev   line source
meillo@0 1 /*
meillo@10 2 ** ident.c High-level calls to the ident lib
meillo@0 3 **
meillo@0 4 ** Author: Pär Emanuelsson <pell@lysator.liu.se>
meillo@0 5 ** Hacked by: Peter Eriksson <pen@lysator.liu.se>
meillo@0 6 */
meillo@0 7
meillo@0 8 #ifdef NeXT3
meillo@0 9 # include <libc.h>
meillo@0 10 #endif
meillo@0 11
meillo@0 12 #include <stdio.h>
meillo@0 13
meillo@0 14 #ifdef HAVE_ANSIHEADERS
meillo@0 15 # include <stdlib.h>
meillo@0 16 # include <string.h>
meillo@0 17 #endif
meillo@0 18
meillo@0 19 #include <errno.h>
meillo@0 20
meillo@0 21 #include <sys/types.h>
meillo@0 22 #include <sys/socket.h>
meillo@0 23
meillo@0 24 #define IN_LIBIDENT_SRC
meillo@0 25 #include "ident.h"
meillo@0 26
meillo@0 27 #include <arpa/inet.h>
meillo@0 28
meillo@0 29
meillo@0 30
meillo@0 31
meillo@0 32 /* Do a complete ident query and return result */
meillo@0 33
meillo@10 34 IDENT*
meillo@10 35 ident_lookup __P2(int, fd, int, timeout)
meillo@0 36 {
meillo@10 37 struct sockaddr_in localaddr, remoteaddr;
meillo@10 38 int len;
meillo@0 39
meillo@10 40 len = sizeof(remoteaddr);
meillo@10 41 if (getpeername(fd, (struct sockaddr *) &remoteaddr, &len) < 0)
meillo@10 42 return 0;
meillo@10 43
meillo@10 44 len = sizeof(localaddr);
meillo@10 45 if (getsockname(fd, (struct sockaddr *) &localaddr, &len) < 0)
meillo@10 46 return 0;
meillo@10 47
meillo@10 48 return ident_query(&localaddr.sin_addr, &remoteaddr.sin_addr, ntohs(localaddr.sin_port), ntohs(remoteaddr.sin_port), timeout);
meillo@0 49 }
meillo@0 50
meillo@0 51
meillo@10 52 IDENT*
meillo@10 53 ident_query __P5(struct in_addr *, laddr, struct in_addr *, raddr, int, lport, int, rport, int, timeout)
meillo@0 54 {
meillo@10 55 int res;
meillo@10 56 ident_t *id;
meillo@10 57 struct timeval timout;
meillo@10 58 IDENT *ident = 0;
meillo@0 59
meillo@10 60
meillo@10 61 timout.tv_sec = timeout;
meillo@10 62 timout.tv_usec = 0;
meillo@10 63
meillo@10 64 if (timeout)
meillo@10 65 id = id_open(laddr, raddr, &timout);
meillo@10 66 else
meillo@10 67 id = id_open(laddr, raddr, (struct timeval *) 0);
meillo@10 68
meillo@10 69 if (!id) {
meillo@10 70 errno = EINVAL;
meillo@10 71 return 0;
meillo@10 72 }
meillo@10 73
meillo@10 74 if (timeout)
meillo@10 75 res = id_query(id, rport, lport, &timout);
meillo@10 76 else
meillo@10 77 res = id_query(id, rport, lport, (struct timeval *) 0);
meillo@10 78
meillo@10 79 if (res < 0) {
meillo@10 80 id_close(id);
meillo@10 81 return 0;
meillo@10 82 }
meillo@10 83
meillo@10 84 ident = (IDENT *) malloc(sizeof(IDENT));
meillo@10 85 if (!ident) {
meillo@10 86 id_close(id);
meillo@10 87 return 0;
meillo@10 88 }
meillo@10 89
meillo@10 90 if (timeout)
meillo@10 91 res = id_parse(id, &timout, &ident->lport, &ident->fport, &ident->identifier, &ident->opsys, &ident->charset);
meillo@10 92 else
meillo@10 93 res = id_parse(id, (struct timeval *) 0, &ident->lport, &ident->fport, &ident->identifier, &ident->opsys, &ident->charset);
meillo@10 94
meillo@10 95 if (res != 1) {
meillo@10 96 free(ident);
meillo@10 97 id_close(id);
meillo@10 98 return 0;
meillo@10 99 }
meillo@10 100
meillo@0 101 id_close(id);
meillo@10 102 return ident; /* At last! */
meillo@0 103 }
meillo@0 104
meillo@0 105
meillo@10 106 char*
meillo@10 107 ident_id __P2(int, fd, int, timeout)
meillo@0 108 {
meillo@10 109 IDENT *ident;
meillo@10 110 char *id = 0;
meillo@0 111
meillo@10 112 ident = ident_lookup(fd, timeout);
meillo@10 113 if (ident && ident->identifier && *ident->identifier) {
meillo@10 114 id = id_strdup(ident->identifier);
meillo@10 115 if (id == NULL)
meillo@10 116 return NULL;
meillo@10 117 }
meillo@10 118
meillo@10 119 ident_free(ident);
meillo@10 120 return id;
meillo@0 121 }
meillo@0 122
meillo@0 123
meillo@10 124 void
meillo@10 125 ident_free __P1(IDENT *, id)
meillo@0 126 {
meillo@10 127 if (!id)
meillo@10 128 return;
meillo@10 129 if (id->identifier)
meillo@10 130 free(id->identifier);
meillo@10 131 if (id->opsys)
meillo@10 132 free(id->opsys);
meillo@10 133 if (id->charset)
meillo@10 134 free(id->charset);
meillo@10 135 free(id);
meillo@0 136 }