Deleted Added
full compact
main.c (66494) main.c (77349)
1/*
1/*
2 * Copyright (c) 1999-2000 Sendmail, Inc. and its suppliers.
2 * Copyright (c) 1999-2001 Sendmail, Inc. and its suppliers.
3 * All rights reserved.
4 *
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
8 *
9 */
10
11#ifndef lint
3 * All rights reserved.
4 *
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
8 *
9 */
10
11#ifndef lint
12static char id[] = "@(#)$Id: main.c,v 8.34.4.9 2000/09/09 02:23:03 gshapiro Exp $";
12static char id[] = "@(#)$Id: main.c,v 8.34.4.11 2001/05/07 22:06:37 gshapiro Exp $";
13#endif /* ! lint */
14
15#if _FFR_MILTER
16#define _DEFINE 1
17#include "libmilter.h"
18#include <fcntl.h>
19#include <sys/stat.h>
20
21
22static smfiDesc_ptr smfi = NULL;
23
24/*
25** SMFI_REGISTER -- register a filter description
26**
27** Parameters:
28** smfilter -- description of filter to register
29**
30** Returns:
31** MI_SUCCESS/MI_FAILURE
32*/
33
34int
35smfi_register(smfilter)
36 smfiDesc_str smfilter;
37{
38 size_t len;
39
40 if (smfi == NULL)
41 {
42 smfi = (smfiDesc_ptr) malloc(sizeof *smfi);
43 if (smfi == NULL)
44 return MI_FAILURE;
45 }
46 (void) memcpy(smfi, &smfilter, sizeof *smfi);
47 if (smfilter.xxfi_name == NULL)
48 smfilter.xxfi_name = "Unknown";
49
50 len = strlen(smfilter.xxfi_name) + 1;
51 smfi->xxfi_name = (char *) malloc(len);
52 if (smfi->xxfi_name == NULL)
53 return MI_FAILURE;
54 (void) strlcpy(smfi->xxfi_name, smfilter.xxfi_name, len);
55
56 /* compare milter version with hard coded version */
57 if (smfi->xxfi_version != SMFI_VERSION)
58 {
59 /* hard failure for now! */
60 smi_log(SMI_LOG_ERR,
61 "%s: smfi_register: version mismatch application: %d != milter: %d",
62 smfi->xxfi_name, smfi->xxfi_version,
63 (int) SMFI_VERSION);
64 return MI_FAILURE;
65 }
66
67 return MI_SUCCESS;
68}
69
70 /*
71** SMFI_STOP -- stop milter
72**
73** Parameters:
74** none.
75**
76** Returns:
77** success.
78*/
79
80int
81smfi_stop()
82{
83 mi_stop_milters(MILTER_STOP);
84 return MI_SUCCESS;
85}
86
87static int dbg = 0;
88static char *conn = NULL;
89static int timeout = MI_TIMEOUT;
90static int backlog= MI_SOMAXCONN;
91
92int
93smfi_setdbg(odbg)
94 int odbg;
95{
96 dbg = odbg;
97 return MI_SUCCESS;
98}
99
100int
101smfi_settimeout(otimeout)
102 int otimeout;
103{
104 timeout = otimeout;
105 return MI_SUCCESS;
106}
107
108int
109smfi_setconn(oconn)
110 char *oconn;
111{
112 size_t l;
113
114 if (oconn == NULL || *oconn == '\0')
115 return MI_FAILURE;
116 l = strlen(oconn) + 1;
117 if ((conn = (char *) malloc(l)) == NULL)
118 return MI_FAILURE;
119 if (strlcpy(conn, oconn, l) >= l)
120 return MI_FAILURE;
121 return MI_SUCCESS;
122}
123
124int
125smfi_setbacklog(obacklog)
126 int obacklog;
127{
128 if (obacklog <= 0)
129 return MI_FAILURE;
130 backlog = obacklog;
131 return MI_SUCCESS;
132}
133
13#endif /* ! lint */
14
15#if _FFR_MILTER
16#define _DEFINE 1
17#include "libmilter.h"
18#include <fcntl.h>
19#include <sys/stat.h>
20
21
22static smfiDesc_ptr smfi = NULL;
23
24/*
25** SMFI_REGISTER -- register a filter description
26**
27** Parameters:
28** smfilter -- description of filter to register
29**
30** Returns:
31** MI_SUCCESS/MI_FAILURE
32*/
33
34int
35smfi_register(smfilter)
36 smfiDesc_str smfilter;
37{
38 size_t len;
39
40 if (smfi == NULL)
41 {
42 smfi = (smfiDesc_ptr) malloc(sizeof *smfi);
43 if (smfi == NULL)
44 return MI_FAILURE;
45 }
46 (void) memcpy(smfi, &smfilter, sizeof *smfi);
47 if (smfilter.xxfi_name == NULL)
48 smfilter.xxfi_name = "Unknown";
49
50 len = strlen(smfilter.xxfi_name) + 1;
51 smfi->xxfi_name = (char *) malloc(len);
52 if (smfi->xxfi_name == NULL)
53 return MI_FAILURE;
54 (void) strlcpy(smfi->xxfi_name, smfilter.xxfi_name, len);
55
56 /* compare milter version with hard coded version */
57 if (smfi->xxfi_version != SMFI_VERSION)
58 {
59 /* hard failure for now! */
60 smi_log(SMI_LOG_ERR,
61 "%s: smfi_register: version mismatch application: %d != milter: %d",
62 smfi->xxfi_name, smfi->xxfi_version,
63 (int) SMFI_VERSION);
64 return MI_FAILURE;
65 }
66
67 return MI_SUCCESS;
68}
69
70 /*
71** SMFI_STOP -- stop milter
72**
73** Parameters:
74** none.
75**
76** Returns:
77** success.
78*/
79
80int
81smfi_stop()
82{
83 mi_stop_milters(MILTER_STOP);
84 return MI_SUCCESS;
85}
86
87static int dbg = 0;
88static char *conn = NULL;
89static int timeout = MI_TIMEOUT;
90static int backlog= MI_SOMAXCONN;
91
92int
93smfi_setdbg(odbg)
94 int odbg;
95{
96 dbg = odbg;
97 return MI_SUCCESS;
98}
99
100int
101smfi_settimeout(otimeout)
102 int otimeout;
103{
104 timeout = otimeout;
105 return MI_SUCCESS;
106}
107
108int
109smfi_setconn(oconn)
110 char *oconn;
111{
112 size_t l;
113
114 if (oconn == NULL || *oconn == '\0')
115 return MI_FAILURE;
116 l = strlen(oconn) + 1;
117 if ((conn = (char *) malloc(l)) == NULL)
118 return MI_FAILURE;
119 if (strlcpy(conn, oconn, l) >= l)
120 return MI_FAILURE;
121 return MI_SUCCESS;
122}
123
124int
125smfi_setbacklog(obacklog)
126 int obacklog;
127{
128 if (obacklog <= 0)
129 return MI_FAILURE;
130 backlog = obacklog;
131 return MI_SUCCESS;
132}
133
134
134int
135smfi_main()
136{
135int
136smfi_main()
137{
138
137 signal(SIGPIPE, SIG_IGN);
138 if (conn == NULL)
139 {
140 smi_log(SMI_LOG_FATAL, "%s: missing connection information",
141 smfi->xxfi_name);
142 return MI_FAILURE;
143 }
144
145 (void) atexit(mi_clean_signals);
146 if (mi_control_startup(smfi->xxfi_name) != MI_SUCCESS)
147 {
148 smi_log(SMI_LOG_FATAL,
149 "%s: Couldn't start signal thread",
150 smfi->xxfi_name);
151 return MI_FAILURE;
152 }
153
139 signal(SIGPIPE, SIG_IGN);
140 if (conn == NULL)
141 {
142 smi_log(SMI_LOG_FATAL, "%s: missing connection information",
143 smfi->xxfi_name);
144 return MI_FAILURE;
145 }
146
147 (void) atexit(mi_clean_signals);
148 if (mi_control_startup(smfi->xxfi_name) != MI_SUCCESS)
149 {
150 smi_log(SMI_LOG_FATAL,
151 "%s: Couldn't start signal thread",
152 smfi->xxfi_name);
153 return MI_FAILURE;
154 }
155
156
154 /* Startup the listener */
155 if (mi_listener(conn, dbg, smfi, timeout, backlog) != MI_SUCCESS)
156 return MI_FAILURE;
157
158 return MI_SUCCESS;
159}
160#endif /* _FFR_MILTER */
157 /* Startup the listener */
158 if (mi_listener(conn, dbg, smfi, timeout, backlog) != MI_SUCCESS)
159 return MI_FAILURE;
160
161 return MI_SUCCESS;
162}
163#endif /* _FFR_MILTER */