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
61 if ((p
= strchr(line
, '\n')))
64 /* Escape leading dot in every case */
65 linelen
= strlen(line
);
67 if ((linelen
+ 2) > 1000) {
68 syslog(LOG_CRIT
, "Cannot escape leading dot. Buffer overflow");
71 memmove((line
+ 1), line
, (linelen
+ 1));
77 * Add a virtual user entry to the list of virtual users
80 add_virtuser(char *login
, char *address
)
84 v
= malloc(sizeof(struct virtuser
));
85 v
->login
= strdup(login
);
86 v
->address
= strdup(address
);
87 SLIST_INSERT_HEAD(&virtusers
, v
, next
);
91 * Read the virtual user table
94 parse_virtuser(const char *path
)
101 v
= fopen(path
, "r");
106 if (fgets(line
, sizeof(line
), v
) == NULL
)
108 /* We hit a comment */
109 if (strchr(line
, '#'))
110 *strchr(line
, '#') = 0;
111 if ((word
= strtok(line
, DP
)) != NULL
) {
112 data
= strtok(NULL
, DP
);
114 add_virtuser(word
, data
);
124 * Add entry to the SMTP auth user list
127 add_smtp_auth_user(char *userstring
, char *password
)
132 a
= malloc(sizeof(struct virtuser
));
133 a
->password
= strdup(password
);
135 temp
= strrchr(userstring
, '|');
139 a
->host
= strdup(temp
+1);
140 a
->login
= strdup(strtok(userstring
, "|"));
141 if (a
->login
== NULL
)
144 SLIST_INSERT_HEAD(&authusers
, a
, next
);
150 * Read the SMTP authentication config file
153 parse_authfile(const char *path
)
160 a
= fopen(path
, "r");
165 if (fgets(line
, sizeof(line
), a
) == NULL
)
167 /* We hit a comment */
168 if (strchr(line
, '#'))
169 *strchr(line
, '#') = 0;
170 if ((word
= strtok(line
, DP
)) != NULL
) {
171 data
= strtok(NULL
, DP
);
173 if (add_smtp_auth_user(word
, data
) < 0)
185 * Check if the user supplied a value. If not, fill in default
186 * Check for bad things[TM]
189 parse_conf(const char *config_path
)
196 conf
= fopen(config_path
, "r");
201 config
->features
= 0;
203 while (!feof(conf
)) {
204 if (fgets(line
, sizeof(line
), conf
) == NULL
)
206 /* We hit a comment */
207 if (strchr(line
, '#'))
208 *strchr(line
, '#') = 0;
209 if ((word
= strtok(line
, EQS
)) != NULL
) {
210 data
= strtok(NULL
, EQS
);
211 if (strcmp(word
, "SMARTHOST") == 0) {
213 config
->smarthost
= strdup(data
);
215 else if (strcmp(word
, "PORT") == 0) {
217 config
->port
= atoi(strdup(data
));
219 else if (strcmp(word
, "ALIASES") == 0) {
221 config
->aliases
= strdup(data
);
223 else if (strcmp(word
, "SPOOLDIR") == 0) {
225 config
->spooldir
= strdup(data
);
227 else if (strcmp(word
, "VIRTPATH") == 0) {
229 config
->virtualpath
= strdup(data
);
231 else if (strcmp(word
, "AUTHPATH") == 0) {
233 config
->authpath
= strdup(data
);
235 else if (strcmp(word
, "CERTFILE") == 0) {
237 config
->certfile
= strdup(data
);
239 else if (strcmp(word
, "MAILNAME") == 0) {
241 config
->mailname
= strdup(data
);
243 else if (strcmp(word
, "MAILNAMEFILE") == 0) {
245 config
->mailnamefile
= strdup(data
);
247 else if (strcmp(word
, "VIRTUAL") == 0)
248 config
->features
|= VIRTUAL
;
249 else if (strcmp(word
, "STARTTLS") == 0)
250 config
->features
|= STARTTLS
;
251 else if (strcmp(word
, "SECURETRANSFER") == 0)
252 config
->features
|= SECURETRANS
;
253 else if (strcmp(word
, "DEFER") == 0)
254 config
->features
|= DEFER
;
255 else if (strcmp(word
, "INSECURE") == 0)
256 config
->features
|= INSECURE
;
257 else if (strcmp(word
, "FULLBOUNCE") == 0)
258 config
->features
|= FULLBOUNCE
;