ze-filter  (ze-filter-0.8.0-develop-180218)
ze-smmacros.c
Go to the documentation of this file.
1 
2 /*
3  *
4  * ze-filter - Mail Server Filter for sendmail
5  *
6  * Copyright (c) 2001-2018 - Jose-Marcio Martins da Cruz
7  *
8  * Auteur : Jose Marcio Martins da Cruz
9  * jose.marcio.mc@gmail.org
10  *
11  * Historique :
12  * Creation : janvier 2002
13  *
14  * This program is free software, but with restricted license :
15  *
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20  *
21  * More details about ze-filter license can be found at ze-filter
22  * web site : http://foss.jose-marcio.org
23  */
24 
25 #include <ze-sys.h>
26 
27 #include "ze-filter.h"
28 #include "ze-filter-data.h"
29 
30 #undef DEBUG
31 #define DEBUG 0
32 
33 
34 /* ***************************************************************************
35  * *
36  * *
37  *****************************************************************************/
38 #if 0
39 typedef struct sm_mac_T sm_mac_T;
40 
42 void sm_macro_free(sm_mac_T *);
43 
44 void sm_macro_update(SMFICTX *, sm_mac_T *);
45 char *sm_macro_get_str(sm_mac_T *, char *);
46 int sm_macro_get_int(sm_mac_T *, char *);
47 #endif
48 
49 /* ***************************************************************************
50  * *
51  * *
52  *****************************************************************************/
53 struct sm_mac_T {
54  char *name;
55  char *value;
56  char *label;
57 };
58 
59 static sm_mac_T smmac[] = {
60  {"_", NULL, "The validated sender address"},
61  {"c", NULL, "The hop count (number of Received: lines"},
62  {"g", NULL, "The sender address relative to the recipient"},
63  {"i", NULL, "Queue ID"},
64  {"j", NULL, "The official domain name for this site"},
65  {"v", NULL, "The version number of the sendmail binary"},
66 
67  {"{auth_type}", NULL,
68  "The mechanism used for SMTP auth (only set if successful"},
69  {"{auth_authen}", NULL, ""},
70  {"{auth_ssf}", NULL, ""},
71  {"{auth_author}", NULL, ""},
72 
73  {"{daemon_addr}", NULL, ""},
74  {"{daemon_family}", NULL, ""},
75  {"{daemon_name}", NULL, ""},
76  {"{daemon_port}", NULL, ""},
77 
78  {"{cert_issuer}", NULL, "Distinguished Name of the Certification Authority"},
79  {"{cert_subject}", NULL, "Distinguished Name of the certificate"},
80  {"{cipher_bits}", NULL, "Effective key length of the symmetric key"},
81  {"{cipher}", NULL, "Cypher used for the connection"},
82  {"{tls_version}", NULL, ""},
83  {"{verify}", NULL, ""},
84 
85  {"{client_addr}", NULL, "IP address of SMTP client"},
86  {"{client_name}", NULL, "Verified hostname of the client"},
87  {"{client_ptr}", NULL, "The result of PTR lookup for the client IP address"},
88  {"{client_resolve}", NULL, "Result of the resolve call for client_name"},
89 
90 #if 1
91  {"{if_addr}", NULL, ""},
92  {"{if_name}", NULL, ""},
93 #endif
94 
95  {"{mail_addr}", NULL, ""},
96  {"{mail_host}", NULL, ""},
97 
98  {"{rcpt_addr}", NULL, ""},
99  {"{rcpt_host}", NULL, ""},
100  {"{rcpt_mailer}", NULL, ""},
101 
102  {"{nrcpts}", NULL, ""},
103 
104  {"{msg_size}", NULL, ""},
105 
106  {NULL, NULL, NULL}
107 };
108 
109 /* ***************************************************************************
110  * *
111  * *
112  *****************************************************************************/
113 sm_mac_T *
115 {
116  sm_mac_T *p;
117 
118  ZE_MessageInfo(19, "sizeof smmac : %d", sizeof smmac);
119 
120  if ((p = malloc(sizeof smmac)) != NULL) {
121  memcpy(p, smmac, sizeof (smmac));
122  } else;
123 
124  return p;
125 }
126 
127 /* ***************************************************************************
128  * *
129  * *
130  *****************************************************************************/
131 void
133  sm_mac_T *sm;
134 {
135  sm_mac_T *p = sm;
136 
137  for (p = sm; p != NULL && p->name != NULL; p++)
138  FREE(p->value);
139 
140  FREE(sm);
141 }
142 
143 /* ***************************************************************************
144  * *
145  * *
146  *****************************************************************************/
148 
149 void
151  SMFICTX *ctx;
152  sm_mac_T *sm;
153 {
154  sm_mac_T *p = sm;
155  CTXPRIV_T *priv = MLFIPRIV(ctx);
156  char *callback = NULL;
157 
158  callback = callback_name(priv->callback_id);
159  callback = STRNULL(callback, "CALLBACK");
160 
161  for (p = sm; p != NULL && p->name != NULL; p++) {
162  char *s;
163 
164  if (strlen(p->name) == 0)
165  continue;
166 
167 #if 1
168  FREE(p->value);
169 #endif
170  if ((s = smfi_getsymval(ctx, p->name)) != NULL) {
171  FREE(p->value);
172  if (s != NULL) {
173  p->value = strdup(s);
174  if (p->value == NULL)
175  ZE_LogSysError("strdup(%s)", s);
176  }
177  }
178 
179  if (log_sm_macros && p->value != NULL) {
180  ZE_MessageInfo(9, "%s : %-9s : SM Macro %-15s %s", CONNID_STR(priv->id),
181  callback, p->name, STRNULL(p->value, "(null)"));
182  }
183  }
184 }
185 
186 /* ***************************************************************************
187  * *
188  * *
189  *****************************************************************************/
190 char *
192  sm_mac_T *sm;
193  char *name;
194 {
195  sm_mac_T *p = sm;
196 
197  for (p = sm; p != NULL && p->name != NULL; p++) {
198  if (strcasecmp(name, p->name) == 0)
199  return p->value;
200  }
201  return NULL;
202 }
203 
204 /* ***************************************************************************
205  * *
206  * *
207  *****************************************************************************/
208 int
210  sm_mac_T *sm;
211  char *name;
212 {
213  sm_mac_T *p = sm;
214 
215  for (p = sm; p != NULL && p->name != NULL; p++) {
216  if (strcasecmp(name, p->name) == 0) {
217  if (p->value != NULL)
218  return atoi(p->value);
219  }
220  }
221  return 0;
222 }
223 
224 /* ***************************************************************************
225  * *
226  * *
227  *****************************************************************************/
228 void
230  char *id;
231  sm_mac_T *sm;
232 {
233  sm_mac_T *p = sm;
234 
235  id = STRNULL(id, "NOID");
236 
237  for (p = sm; p != NULL && p->name != NULL; p++) {
238  if (strlen(p->name) > 0)
239  ZE_MessageInfo(9, "%s : %-15s - %s", id, p->name,
240  STRNULL(p->value, "(null)"));
241  }
242 }
243 
244 /* ***************************************************************************
245  * *
246  * *
247  *****************************************************************************/
248 
249 
250 static name2id_T callbacks[] = {
251  {"connect", CALLBACK_CONNECT},
252  {"ehlo", CALLBACK_EHLO},
253  {"mail", CALLBACK_MAIL},
254  {"rcpt", CALLBACK_RCPT},
255  {"data", CALLBACK_DATA},
256  {"header", CALLBACK_HEADER},
257  {"eoh", CALLBACK_EOH},
258  {"body", CALLBACK_BODY},
259  {"eom", CALLBACK_EOM},
260  {"abort", CALLBACK_ABORT},
261  {"close", CALLBACK_CLOSE},
262  {NULL, -1}
263 };
264 
265 
266 char *
268  int id;
269 {
270  if (id < 0)
271  return NULL;
272 
273  return get_name_by_id(callbacks, id);
274 }
#define CALLBACK_HEADER
Definition: ze-callback.h:33
int sm_macro_get_int(sm_mac_T *sm, char *name)
Definition: ze-smmacros.c:209
sm_mac_T * sm_macro_new()
Definition: ze-smmacros.c:114
bool log_sm_macros
Definition: ze-smmacros.c:147
#define CALLBACK_CONNECT
Definition: ze-callback.h:28
#define FREE(x)
Definition: macros.h:37
#define CALLBACK_EHLO
Definition: ze-callback.h:29
#define STRNULL(x, r)
Definition: macros.h:81
#define CALLBACK_RCPT
Definition: ze-callback.h:31
#define FALSE
Definition: macros.h:160
#define MLFIPRIV(ctx)
CONNID_T id
char * name
Definition: ze-smmacros.c:54
#define CALLBACK_DATA
Definition: ze-callback.h:32
char * get_name_by_id(name2id_T *, int)
Definition: ze-name2id.c:58
#define CALLBACK_MAIL
Definition: ze-callback.h:30
#define ZE_MessageInfo(level,...)
Definition: zeSyslog.h:90
#define CALLBACK_BODY
Definition: ze-callback.h:35
char * label
Definition: ze-smmacros.c:56
#define CALLBACK_CLOSE
Definition: ze-callback.h:38
#define memcpy(d, s, n)
Definition: ze-sys.h:224
#define ZE_LogSysError(...)
Definition: zeSyslog.h:129
#define CALLBACK_ABORT
Definition: ze-callback.h:37
char * value
Definition: ze-smmacros.c:55
#define CONNID_STR(connid)
Definition: ze-filter.h:113
#define CALLBACK_EOH
Definition: ze-callback.h:34
char * callback_name(int id)
Definition: ze-smmacros.c:267
#define CALLBACK_EOM
Definition: ze-callback.h:36
char * sm_macro_get_str(sm_mac_T *sm, char *name)
Definition: ze-smmacros.c:191
void sm_macro_free(sm_mac_T *sm)
Definition: ze-smmacros.c:132
void sm_macro_update(SMFICTX *ctx, sm_mac_T *sm)
Definition: ze-smmacros.c:150
void sm_macro_log_all(char *id, sm_mac_T *sm)
Definition: ze-smmacros.c:229