2 * Copyright (c) 2008 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthias Schmidt <matthias@dragonflybsd.org>, University of Marburg,
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * 3. Neither the name of The DragonFly Project nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific, prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * Remove trailing \n's
59 if ((p
= strchr(line
, '\n')))
62 /* Escape leading dot in every case */
63 linelen
= strlen(line
);
65 if ((linelen
+ 2) > 1000) {
66 syslog(LOG_CRIT
, "Cannot escape leading dot. Buffer overflow");
69 memmove((line
+ 1), line
, (linelen
+ 1));
77 size_t len
= strlen(str
);
81 if (str
[len
- 1] == '\n')
86 * Read the SMTP authentication config file
91 * A line starting with # is treated as comment and ignored.
94 parse_authfile(const char *path
)
102 a
= fopen(path
, "r");
104 errlog(EX_NOINPUT
, "can not open auth file `%s'", path
);
109 if (fgets(line
, sizeof(line
), a
) == NULL
)
115 /* We hit a comment */
118 /* Ignore empty lines */
122 au
= calloc(1, sizeof(*au
));
124 errlog(EX_OSERR
, "calloc()");
127 au
->login
= strsep(&data
, "|");
128 au
->host
= strsep(&data
, DP
);
131 if (au
->login
== NULL
||
133 au
->password
== NULL
) {
134 errlogx(EX_CONFIG
, "syntax error in authfile %s:%d", path
, lineno
);
138 SLIST_INSERT_HEAD(&authusers
, au
, next
);
146 * Check for bad things[TM]
149 parse_conf(const char *config_path
)
157 conf
= fopen(config_path
, "r");
159 /* Don't treat a non-existing config file as error */
162 errlog(EX_NOINPUT
, "can not open config `%s'", config_path
);
166 while (!feof(conf
)) {
167 if (fgets(line
, sizeof(line
), conf
) == NULL
)
173 /* We hit a comment */
174 if (strchr(line
, '#'))
175 *strchr(line
, '#') = 0;
178 word
= strsep(&data
, EQS
);
180 /* Ignore empty lines */
181 if (word
== NULL
|| *word
== 0)
184 if (data
!= NULL
&& *data
!= 0)
189 if (strcmp(word
, "SMARTHOST") == 0 && data
!= NULL
)
190 config
.smarthost
= data
;
191 else if (strcmp(word
, "PORT") == 0 && data
!= NULL
)
192 config
.port
= atoi(data
);
193 else if (strcmp(word
, "ALIASES") == 0 && data
!= NULL
)
194 config
.aliases
= data
;
195 else if (strcmp(word
, "SPOOLDIR") == 0 && data
!= NULL
)
196 config
.spooldir
= data
;
197 else if (strcmp(word
, "AUTHPATH") == 0 && data
!= NULL
)
198 config
.authpath
= data
;
199 else if (strcmp(word
, "CERTFILE") == 0 && data
!= NULL
)
200 config
.certfile
= data
;
201 else if (strcmp(word
, "MAILNAME") == 0 && data
!= NULL
)
202 config
.mailname
= data
;
203 else if (strcmp(word
, "MASQUERADE") == 0 && data
!= NULL
) {
204 char *user
= NULL
, *host
= NULL
;
205 if (strrchr(data
, '@')) {
206 host
= strrchr(data
, '@');
213 if (host
&& *host
== 0)
215 if (user
&& *user
== 0)
217 config
.masquerade_host
= host
;
218 config
.masquerade_user
= user
;
219 } else if (strcmp(word
, "STARTTLS") == 0 && data
== NULL
)
220 config
.features
|= STARTTLS
;
221 else if (strcmp(word
, "OPPORTUNISTIC_TLS") == 0 && data
== NULL
)
222 config
.features
|= TLS_OPP
;
223 else if (strcmp(word
, "SECURETRANSFER") == 0 && data
== NULL
)
224 config
.features
|= SECURETRANS
;
225 else if (strcmp(word
, "DEFER") == 0 && data
== NULL
)
226 config
.features
|= DEFER
;
227 else if (strcmp(word
, "INSECURE") == 0 && data
== NULL
)
228 config
.features
|= INSECURE
;
229 else if (strcmp(word
, "FULLBOUNCE") == 0 && data
== NULL
)
230 config
.features
|= FULLBOUNCE
;
231 else if (strcmp(word
, "NULLCLIENT") == 0 && data
== NULL
)
232 config
.features
|= NULLCLIENT
;
234 errlogx(EX_CONFIG
, "syntax error in %s:%d", config_path
, lineno
);
239 if ((config
.features
& NULLCLIENT
) && config
.smarthost
== NULL
) {
240 errlogx(EX_CONFIG
, "%s: NULLCLIENT requires SMARTHOST", config_path
);