masqmail-0.2
diff src/conf.c @ 10:26e34ae9a3e3
changed indention and line wrapping to a more consistent style
author | meillo@marmaro.de |
---|---|
date | Mon, 27 Oct 2008 16:23:10 +0100 |
parents | 08114f7dcc23 |
children | 49dab67fe461 |
line diff
1.1 --- a/src/conf.c Mon Oct 27 16:21:27 2008 +0100 1.2 +++ b/src/conf.c Mon Oct 27 16:23:10 2008 +0100 1.3 @@ -23,973 +23,973 @@ 1.4 1.5 masqmail_conf conf; 1.6 1.7 -void init_conf() 1.8 +void 1.9 +init_conf() 1.10 { 1.11 - struct passwd *passwd; 1.12 - struct group *group; 1.13 + struct passwd *passwd; 1.14 + struct group *group; 1.15 1.16 - memset(&conf, 0, sizeof(masqmail_conf)); 1.17 + memset(&conf, 0, sizeof(masqmail_conf)); 1.18 1.19 - conf.orig_uid = getuid(); 1.20 - conf.orig_gid = getgid(); 1.21 + conf.orig_uid = getuid(); 1.22 + conf.orig_gid = getgid(); 1.23 1.24 - if((passwd = getpwnam(DEF_MAIL_USER))) 1.25 - conf.mail_uid = passwd->pw_uid; 1.26 - else{ 1.27 - fprintf(stderr, "user %s not found! (terminating)\n", DEF_MAIL_USER); 1.28 - exit(EXIT_FAILURE); 1.29 - } 1.30 - if((group = getgrnam(DEF_MAIL_GROUP))) 1.31 - conf.mail_gid = group->gr_gid; 1.32 - else{ 1.33 - fprintf(stderr, "group %s not found! (terminating)\n", DEF_MAIL_GROUP); 1.34 - exit(EXIT_FAILURE); 1.35 - } 1.36 + if ((passwd = getpwnam(DEF_MAIL_USER))) 1.37 + conf.mail_uid = passwd->pw_uid; 1.38 + else { 1.39 + fprintf(stderr, "user %s not found! (terminating)\n", DEF_MAIL_USER); 1.40 + exit(EXIT_FAILURE); 1.41 + } 1.42 + if ((group = getgrnam(DEF_MAIL_GROUP))) 1.43 + conf.mail_gid = group->gr_gid; 1.44 + else { 1.45 + fprintf(stderr, "group %s not found! (terminating)\n", DEF_MAIL_GROUP); 1.46 + exit(EXIT_FAILURE); 1.47 + } 1.48 } 1.49 1.50 -static gchar *true_strings[] = 1.51 -{ 1.52 - "yes", "on", "true", NULL 1.53 +static gchar* true_strings[] = { 1.54 + "yes", "on", "true", NULL 1.55 }; 1.56 1.57 -static gchar *false_strings[] = 1.58 -{ 1.59 - "no", "off", "false", NULL 1.60 +static gchar *false_strings[] = { 1.61 + "no", "off", "false", NULL 1.62 }; 1.63 1.64 -static 1.65 -gboolean parse_boolean(gchar *rval) 1.66 +static gboolean 1.67 +parse_boolean(gchar * rval) 1.68 { 1.69 - gchar **str; 1.70 + gchar **str; 1.71 1.72 - DEBUG(6) fprintf(stderr, "parse_boolean: %s\n", rval); 1.73 + DEBUG(6) fprintf(stderr, "parse_boolean: %s\n", rval); 1.74 1.75 - str = true_strings; 1.76 - while(*str){ 1.77 - if(strncasecmp(*str, rval, strlen(*str)) == 0) 1.78 - return TRUE; 1.79 - str++; 1.80 - } 1.81 + str = true_strings; 1.82 + while (*str) { 1.83 + if (strncasecmp(*str, rval, strlen(*str)) == 0) 1.84 + return TRUE; 1.85 + str++; 1.86 + } 1.87 1.88 - str = false_strings; 1.89 - while(*str){ 1.90 - if(strncasecmp(*str, rval, strlen(*str)) == 0) 1.91 - return FALSE; 1.92 - str++; 1.93 - } 1.94 + str = false_strings; 1.95 + while (*str) { 1.96 + if (strncasecmp(*str, rval, strlen(*str)) == 0) 1.97 + return FALSE; 1.98 + str++; 1.99 + } 1.100 1.101 - fprintf(stderr, "cannot parse value '%s'\n", rval); 1.102 - exit(EXIT_FAILURE); 1.103 + fprintf(stderr, "cannot parse value '%s'\n", rval); 1.104 + exit(EXIT_FAILURE); 1.105 } 1.106 1.107 /* make a list from each line in a file */ 1.108 -static 1.109 -GList *parse_list_file(gchar *fname) 1.110 +static GList* 1.111 +parse_list_file(gchar * fname) 1.112 { 1.113 - GList *list = NULL; 1.114 - FILE *fptr; 1.115 + GList *list = NULL; 1.116 + FILE *fptr; 1.117 1.118 - if((fptr = fopen(fname, "rt"))){ 1.119 - gchar buf[256]; 1.120 + if ((fptr = fopen(fname, "rt"))) { 1.121 + gchar buf[256]; 1.122 1.123 - while(!feof(fptr)){ 1.124 - fgets(buf, 255, fptr); 1.125 - if(buf[0] && (buf[0] != '#') && (buf[0] != '\n')){ 1.126 - g_strchomp(buf); 1.127 - list = g_list_append(list, g_strdup(buf)); 1.128 - } 1.129 - } 1.130 - fclose(fptr); 1.131 - }else{ 1.132 - logwrite(LOG_ALERT, "could not open %s for reading: %s\n", fname, strerror(errno)); 1.133 - exit(EXIT_FAILURE); 1.134 - } 1.135 + while (!feof(fptr)) { 1.136 + fgets(buf, 255, fptr); 1.137 + if (buf[0] && (buf[0] != '#') && (buf[0] != '\n')) { 1.138 + g_strchomp(buf); 1.139 + list = g_list_append(list, g_strdup(buf)); 1.140 + } 1.141 + } 1.142 + fclose(fptr); 1.143 + } else { 1.144 + logwrite(LOG_ALERT, "could not open %s for reading: %s\n", fname, strerror(errno)); 1.145 + exit(EXIT_FAILURE); 1.146 + } 1.147 1.148 - return list; 1.149 + return list; 1.150 } 1.151 1.152 /* given a semicolon separated string, this function 1.153 makes a GList out of it. 1.154 */ 1.155 -GList *parse_list(gchar *line, gboolean read_file) 1.156 +GList* 1.157 +parse_list(gchar * line, gboolean read_file) 1.158 { 1.159 - GList *list = NULL; 1.160 - gchar buf[256]; 1.161 - gchar *p, *q; 1.162 + GList *list = NULL; 1.163 + gchar buf[256]; 1.164 + gchar *p, *q; 1.165 1.166 - DEBUG(6) fprintf(stderr, "parsing list %s\n", line); 1.167 + DEBUG(6) fprintf(stderr, "parsing list %s\n", line); 1.168 1.169 - p = line; 1.170 - while(*p != 0){ 1.171 - q = buf; 1.172 + p = line; 1.173 + while (*p != 0) { 1.174 + q = buf; 1.175 1.176 - while(*p && (*p != ';') && (q < buf+255)) 1.177 - *(q++) = *(p++); 1.178 - *q = 0; 1.179 + while (*p && (*p != ';') && (q < buf + 255)) 1.180 + *(q++) = *(p++); 1.181 + *q = 0; 1.182 1.183 - if((buf[0] == '/') && (read_file)) 1.184 - /* item is a filename, include its contents */ 1.185 - list = g_list_concat(list, parse_list_file(buf)); 1.186 - else 1.187 - /* just a normal item */ 1.188 - list = g_list_append(list, g_strdup(buf)); 1.189 + if ((buf[0] == '/') && (read_file)) 1.190 + /* item is a filename, include its contents */ 1.191 + list = g_list_concat(list, parse_list_file(buf)); 1.192 + else 1.193 + /* just a normal item */ 1.194 + list = g_list_append(list, g_strdup(buf)); 1.195 1.196 - DEBUG(6) printf("item = %s\n", buf); 1.197 + DEBUG(6) printf("item = %s\n", buf); 1.198 1.199 - if(*p) p++; 1.200 - } 1.201 - return list; 1.202 + if (*p) 1.203 + p++; 1.204 + } 1.205 + return list; 1.206 } 1.207 1.208 -static 1.209 -GList *parse_address_list(gchar *line, gboolean read_file) 1.210 +static GList* 1.211 +parse_address_list(gchar * line, gboolean read_file) 1.212 { 1.213 - GList *plain_list = parse_list(line, read_file); 1.214 - GList *node; 1.215 - GList *list = NULL; 1.216 + GList *plain_list = parse_list(line, read_file); 1.217 + GList *node; 1.218 + GList *list = NULL; 1.219 1.220 - foreach(plain_list, node){ 1.221 - gchar *item = (gchar *)(node->data); 1.222 - address *addr = create_address(item, TRUE); 1.223 - if(addr) 1.224 - list = g_list_append(list, addr); 1.225 - g_free(item); 1.226 - } 1.227 - g_list_free(plain_list); 1.228 + foreach(plain_list, node) { 1.229 + gchar *item = (gchar *) (node->data); 1.230 + address *addr = create_address(item, TRUE); 1.231 + if (addr) 1.232 + list = g_list_append(list, addr); 1.233 + g_free(item); 1.234 + } 1.235 + g_list_free(plain_list); 1.236 1.237 - return list; 1.238 + return list; 1.239 } 1.240 1.241 -static 1.242 -GList *parse_resolve_list(gchar *line) 1.243 +static GList* 1.244 +parse_resolve_list(gchar * line) 1.245 { 1.246 - GList *list; 1.247 - GList *list_node; 1.248 - GList *res_list = NULL; 1.249 + GList *list; 1.250 + GList *list_node; 1.251 + GList *res_list = NULL; 1.252 1.253 - list = parse_list(line, FALSE); 1.254 - if(list){ 1.255 - foreach(list, list_node){ 1.256 - gchar *item = (gchar *)(list_node->data); 1.257 - if(strcmp(item, "byname") == 0){ 1.258 - res_list = g_list_append(res_list, resolve_byname); 1.259 + list = parse_list(line, FALSE); 1.260 + if (list) { 1.261 + foreach(list, list_node) { 1.262 + gchar *item = (gchar *) (list_node->data); 1.263 + if (strcmp(item, "byname") == 0) { 1.264 + res_list = g_list_append(res_list, resolve_byname); 1.265 #ifdef ENABLE_RESOLVER 1.266 - }else if(strcmp(item, "dns_a") == 0){ 1.267 - res_list = g_list_append(res_list, resolve_dns_a); 1.268 - }else if(strcmp(item, "dns_mx") == 0){ 1.269 - res_list = g_list_append(res_list, resolve_dns_mx); 1.270 + } else if (strcmp(item, "dns_a") == 0) { 1.271 + res_list = g_list_append(res_list, resolve_dns_a); 1.272 + } else if (strcmp(item, "dns_mx") == 0) { 1.273 + res_list = g_list_append(res_list, resolve_dns_mx); 1.274 #endif 1.275 - }else{ 1.276 - logwrite(LOG_ALERT, "unknown resolver %s\n", item); 1.277 - exit(EXIT_FAILURE); 1.278 - } 1.279 - g_free(item); 1.280 - } 1.281 - g_list_free(list); 1.282 - } 1.283 - return res_list; 1.284 + } else { 1.285 + logwrite(LOG_ALERT, "unknown resolver %s\n", item); 1.286 + exit(EXIT_FAILURE); 1.287 + } 1.288 + g_free(item); 1.289 + } 1.290 + g_list_free(list); 1.291 + } 1.292 + return res_list; 1.293 } 1.294 1.295 -static 1.296 -interface *parse_interface(gchar *line, gint def_port) 1.297 +static interface* 1.298 +parse_interface(gchar * line, gint def_port) 1.299 { 1.300 - gchar buf[256]; 1.301 - gchar *p, *q; 1.302 - interface *iface; 1.303 + gchar buf[256]; 1.304 + gchar *p, *q; 1.305 + interface *iface; 1.306 1.307 - DEBUG(6) fprintf(stderr, "parse_interface: %s\n", line); 1.308 + DEBUG(6) fprintf(stderr, "parse_interface: %s\n", line); 1.309 1.310 - p = line; 1.311 - q = buf; 1.312 - while((*p != 0) && (*p != ':') && (q < buf+255)) 1.313 - *(q++) = *(p++); 1.314 - *q = 0; 1.315 + p = line; 1.316 + q = buf; 1.317 + while ((*p != 0) && (*p != ':') && (q < buf + 255)) 1.318 + *(q++) = *(p++); 1.319 + *q = 0; 1.320 1.321 - iface = g_malloc(sizeof(interface)); 1.322 - iface->address = g_strdup(buf); 1.323 + iface = g_malloc(sizeof(interface)); 1.324 + iface->address = g_strdup(buf); 1.325 1.326 - if(*p){ 1.327 - p++; 1.328 - iface->port = atoi(p); 1.329 - }else 1.330 - iface->port = def_port; 1.331 + if (*p) { 1.332 + p++; 1.333 + iface->port = atoi(p); 1.334 + } else 1.335 + iface->port = def_port; 1.336 1.337 - return iface; 1.338 + return iface; 1.339 } 1.340 1.341 -#ifdef ENABLE_IDENT /* so far used for that only */ 1.342 -static 1.343 -struct in_addr *parse_network(gchar *line, gint def_port) 1.344 +#ifdef ENABLE_IDENT /* so far used for that only */ 1.345 +static struct in_addr* 1.346 +parse_network(gchar * line, gint def_port) 1.347 { 1.348 - gchar buf[256]; 1.349 - gchar *p, *q; 1.350 - struct in_addr addr, mask_addr, net_addr, *p_net_addr; 1.351 - guint n; 1.352 + gchar buf[256]; 1.353 + gchar *p, *q; 1.354 + struct in_addr addr, mask_addr, net_addr, *p_net_addr; 1.355 + guint n; 1.356 1.357 - DEBUG(6) fprintf(stderr, "parse_network: %s\n", line); 1.358 + DEBUG(6) fprintf(stderr, "parse_network: %s\n", line); 1.359 1.360 - p = line; 1.361 - q = buf; 1.362 - while((*p != 0) && (*p != '/') && (q < buf+255)) 1.363 - *(q++) = *(p++); 1.364 - *q = 0; 1.365 + p = line; 1.366 + q = buf; 1.367 + while ((*p != 0) && (*p != '/') && (q < buf + 255)) 1.368 + *(q++) = *(p++); 1.369 + *q = 0; 1.370 1.371 - if((addr.s_addr = inet_addr(buf)) != INADDR_NONE){ 1.372 - if(*p){ 1.373 - guint i; 1.374 - p++; 1.375 - i = atoi(p); 1.376 - if((i >= 0) && (i <= 32)) 1.377 - n = i ? ~((1 << (32 - i)) - 1) : 0; 1.378 - else{ 1.379 - fprintf(stderr, "'%d' is not a valid net mask (must be >= 0 and <= 32)\n", i); 1.380 - exit(EXIT_FAILURE); 1.381 - } 1.382 - }else 1.383 - n = 0; 1.384 - 1.385 - mask_addr.s_addr = htonl(n); 1.386 - net_addr.s_addr = mask_addr.s_addr & addr.s_addr; 1.387 - }else{ 1.388 - fprintf(stderr, "'%s' is not a valid address (must be ip)\n", buf); 1.389 - exit(EXIT_FAILURE); 1.390 - } 1.391 + if ((addr.s_addr = inet_addr(buf)) != INADDR_NONE) { 1.392 + if (*p) { 1.393 + guint i; 1.394 + p++; 1.395 + i = atoi(p); 1.396 + if ((i >= 0) && (i <= 32)) 1.397 + n = i ? ~((1 << (32 - i)) - 1) : 0; 1.398 + else { 1.399 + fprintf(stderr, "'%d' is not a valid net mask (must be >= 0 and <= 32)\n", i); 1.400 + exit(EXIT_FAILURE); 1.401 + } 1.402 + } else 1.403 + n = 0; 1.404 1.405 - p_net_addr = g_malloc(sizeof(struct in_addr)); 1.406 - p_net_addr->s_addr = net_addr.s_addr; 1.407 - return p_net_addr; 1.408 + mask_addr.s_addr = htonl(n); 1.409 + net_addr.s_addr = mask_addr.s_addr & addr.s_addr; 1.410 + } else { 1.411 + fprintf(stderr, "'%s' is not a valid address (must be ip)\n", buf); 1.412 + exit(EXIT_FAILURE); 1.413 + } 1.414 + 1.415 + p_net_addr = g_malloc(sizeof(struct in_addr)); 1.416 + p_net_addr->s_addr = net_addr.s_addr; 1.417 + return p_net_addr; 1.418 } 1.419 #endif 1.420 1.421 -static 1.422 -gboolean eat_comments(FILE *in) 1.423 +static gboolean 1.424 +eat_comments(FILE * in) 1.425 { 1.426 - gint c; 1.427 + gint c; 1.428 1.429 - for(c = fgetc(in); (c == '#' || isspace(c)) && c != EOF; c = fgetc(in)){ 1.430 - if(c == '#'){ 1.431 - gint c; 1.432 - for(c = fgetc(in); (c != '\n') && (c != EOF); c = fgetc(in)); 1.433 - } 1.434 - } 1.435 - if(c == EOF) return FALSE; 1.436 - ungetc(c, in); 1.437 - return TRUE; 1.438 + for (c = fgetc(in); (c == '#' || isspace(c)) && c != EOF; 1.439 + c = fgetc(in)) { 1.440 + if (c == '#') { 1.441 + gint c; 1.442 + for (c = fgetc(in); (c != '\n') && (c != EOF); c = fgetc(in)); 1.443 + } 1.444 + } 1.445 + if (c == EOF) 1.446 + return FALSE; 1.447 + ungetc(c, in); 1.448 + return TRUE; 1.449 } 1.450 1.451 /* after parsing, eat trailing character until LF */ 1.452 -static 1.453 -gboolean eat_line_trailing(FILE *in) 1.454 +static gboolean 1.455 +eat_line_trailing(FILE * in) 1.456 { 1.457 - gint c; 1.458 + gint c; 1.459 1.460 - for(c = fgetc(in); c != EOF && c != '\n'; c = fgetc(in)); 1.461 - if(c == EOF) return FALSE; 1.462 - return TRUE; 1.463 + for (c = fgetc(in); c != EOF && c != '\n'; c = fgetc(in)); 1.464 + if (c == EOF) 1.465 + return FALSE; 1.466 + return TRUE; 1.467 } 1.468 1.469 -static 1.470 -gboolean eat_spaces(FILE *in) 1.471 +static gboolean 1.472 +eat_spaces(FILE * in) 1.473 { 1.474 - gint c; 1.475 - 1.476 - for(c = fgetc(in); c != EOF && isspace(c); c = fgetc(in)); 1.477 - if(c == EOF) return FALSE; 1.478 - ungetc(c, in); 1.479 - return TRUE; 1.480 + gint c; 1.481 + 1.482 + for (c = fgetc(in); c != EOF && isspace(c); c = fgetc(in)); 1.483 + if (c == EOF) 1.484 + return FALSE; 1.485 + ungetc(c, in); 1.486 + return TRUE; 1.487 } 1.488 1.489 -static 1.490 -gboolean read_lval(FILE *in, gchar *buf, gint size) 1.491 +static gboolean 1.492 +read_lval(FILE * in, gchar * buf, gint size) 1.493 { 1.494 - gint c; 1.495 - gchar *ptr = buf; 1.496 - 1.497 - DEBUG(6) fprintf(stderr, "read_lval()\n"); 1.498 + gint c; 1.499 + gchar *ptr = buf; 1.500 1.501 - if(!eat_spaces(in)) return FALSE; 1.502 + DEBUG(6) fprintf(stderr, "read_lval()\n"); 1.503 1.504 - c = fgetc(in); 1.505 - DEBUG(6) fprintf(stderr, "read_lval() 2\n"); 1.506 - while((isalnum(c) || c == '_' || c == '-' || c == '.') 1.507 - && (ptr < buf+size-1) 1.508 - && (c != EOF) 1.509 - ){ 1.510 - *ptr = c; ptr++; 1.511 - c = fgetc(in); 1.512 - } 1.513 - *ptr = 0; 1.514 - ungetc(c, in); 1.515 + if (!eat_spaces(in)) 1.516 + return FALSE; 1.517 1.518 - if(c == EOF){ 1.519 - fprintf(stderr, "unexpected EOF after %s\n", buf); 1.520 - return FALSE; 1.521 - }else if(ptr >= buf+size-1){ 1.522 - fprintf(stderr, "lval too long\n"); 1.523 - } 1.524 + c = fgetc(in); 1.525 + DEBUG(6) fprintf(stderr, "read_lval() 2\n"); 1.526 + while ((isalnum(c) || c == '_' || c == '-' || c == '.') 1.527 + && (ptr < buf + size - 1) 1.528 + && (c != EOF)) { 1.529 + *ptr = c; 1.530 + ptr++; 1.531 + c = fgetc(in); 1.532 + } 1.533 + *ptr = 0; 1.534 + ungetc(c, in); 1.535 1.536 - eat_spaces(in); 1.537 + if (c == EOF) { 1.538 + fprintf(stderr, "unexpected EOF after %s\n", buf); 1.539 + return FALSE; 1.540 + } else if (ptr >= buf + size - 1) { 1.541 + fprintf(stderr, "lval too long\n"); 1.542 + } 1.543 1.544 - DEBUG(6) fprintf(stderr, "lval = %s\n", buf); 1.545 + eat_spaces(in); 1.546 1.547 - return buf[0] != 0; 1.548 + DEBUG(6) fprintf(stderr, "lval = %s\n", buf); 1.549 + 1.550 + return buf[0] != 0; 1.551 } 1.552 1.553 -static 1.554 -gboolean read_rval(FILE *in, gchar *buf, gint size) 1.555 +static gboolean 1.556 +read_rval(FILE * in, gchar * buf, gint size) 1.557 { 1.558 - gint c; 1.559 - gchar *ptr = buf; 1.560 - 1.561 - DEBUG(6) fprintf(stderr, "read_rval()\n"); 1.562 + gint c; 1.563 + gchar *ptr = buf; 1.564 1.565 - if(!eat_spaces(in)) return FALSE; 1.566 + DEBUG(6) fprintf(stderr, "read_rval()\n"); 1.567 1.568 - c = fgetc(in); 1.569 - if(c != '\"'){ 1.570 - while((isalnum(c) || c == '_' || c == '-' || c == '.' || c == '/' || c == '@' || c == ';') 1.571 - && (ptr < buf+size-1) 1.572 - && (c != EOF) 1.573 - ){ 1.574 - *ptr = c; ptr++; 1.575 - c = fgetc(in); 1.576 - } 1.577 - *ptr = 0; 1.578 - ungetc(c, in); 1.579 - }else{ 1.580 - gboolean escape = FALSE; 1.581 - c = fgetc(in); 1.582 - while(((c != '\"') || escape) && (ptr < buf+size-1)){ 1.583 - if(c != '\n'){ /* ignore line breaks */ 1.584 - if((c == '\\') && (!escape)){ 1.585 - escape = TRUE; 1.586 - }else{ 1.587 - *ptr = c; ptr++; 1.588 - escape = FALSE; 1.589 + if (!eat_spaces(in)) 1.590 + return FALSE; 1.591 + 1.592 + c = fgetc(in); 1.593 + if (c != '\"') { 1.594 + while ((isalnum(c) || c == '_' || c == '-' || c == '.' || c == '/' 1.595 + || c == '@' || c == ';') 1.596 + && (ptr < buf + size - 1) 1.597 + && (c != EOF)) { 1.598 + *ptr = c; 1.599 + ptr++; 1.600 + c = fgetc(in); 1.601 + } 1.602 + *ptr = 0; 1.603 + ungetc(c, in); 1.604 + } else { 1.605 + gboolean escape = FALSE; 1.606 + c = fgetc(in); 1.607 + while (((c != '\"') || escape) && (ptr < buf + size - 1)) { 1.608 + if (c != '\n') { /* ignore line breaks */ 1.609 + if ((c == '\\') && (!escape)) { 1.610 + escape = TRUE; 1.611 + } else { 1.612 + *ptr = c; 1.613 + ptr++; 1.614 + escape = FALSE; 1.615 + } 1.616 + } 1.617 + c = fgetc(in); 1.618 + } 1.619 + *ptr = 0; 1.620 } 1.621 - } 1.622 - c = fgetc(in); 1.623 - } 1.624 - *ptr = 0; 1.625 - } 1.626 - 1.627 - eat_line_trailing(in); 1.628 1.629 - DEBUG(6) fprintf(stderr, "rval = %s\n", buf); 1.630 + eat_line_trailing(in); 1.631 1.632 - return TRUE; 1.633 + DEBUG(6) fprintf(stderr, "rval = %s\n", buf); 1.634 + 1.635 + return TRUE; 1.636 } 1.637 1.638 -static 1.639 -gboolean read_statement(FILE *in, 1.640 - gchar *lval, gint lsize, 1.641 - gchar *rval, gint rsize) 1.642 +static gboolean 1.643 +read_statement(FILE * in, gchar * lval, gint lsize, gchar * rval, gint rsize) 1.644 { 1.645 - gint c; 1.646 + gint c; 1.647 1.648 - DEBUG(6) fprintf(stderr, "read_statement()\n"); 1.649 + DEBUG(6) fprintf(stderr, "read_statement()\n"); 1.650 1.651 - /* eat comments and empty lines: */ 1.652 - if(!eat_comments(in)) return FALSE; 1.653 + /* eat comments and empty lines: */ 1.654 + if (!eat_comments(in)) 1.655 + return FALSE; 1.656 1.657 - DEBUG(6) fprintf(stderr, "read_statement() 1\n"); 1.658 + DEBUG(6) fprintf(stderr, "read_statement() 1\n"); 1.659 1.660 - if(read_lval(in, lval, lsize)){ 1.661 - DEBUG(6) fprintf(stderr, "lval = %s\n", lval); 1.662 - if((c = fgetc(in) == '=')){ 1.663 - if(read_rval(in, rval, rsize)){ 1.664 - DEBUG(6) fprintf(stderr, "rval = %s\n", rval); 1.665 - return TRUE; 1.666 - } 1.667 - }else{ 1.668 - fprintf(stderr, "'=' expected after %s, char was '%c'\n", lval, c); 1.669 - } 1.670 - } 1.671 - return FALSE; 1.672 + if (read_lval(in, lval, lsize)) { 1.673 + DEBUG(6) fprintf(stderr, "lval = %s\n", lval); 1.674 + if ((c = fgetc(in) == '=')) { 1.675 + if (read_rval(in, rval, rsize)) { 1.676 + DEBUG(6) fprintf(stderr, "rval = %s\n", rval); 1.677 + return TRUE; 1.678 + } 1.679 + } else { 1.680 + fprintf(stderr, "'=' expected after %s, char was '%c'\n", lval, 1.681 + c); 1.682 + } 1.683 + } 1.684 + return FALSE; 1.685 } 1.686 1.687 -gboolean read_conf(gchar *filename) 1.688 +gboolean 1.689 +read_conf(gchar * filename) 1.690 { 1.691 - FILE *in; 1.692 + FILE *in; 1.693 1.694 - conf.log_max_pri = 7; 1.695 + conf.log_max_pri = 7; 1.696 + conf.remote_port = 25; 1.697 + conf.do_relay = TRUE; 1.698 + conf.alias_local_cmp = strcmp; 1.699 + conf.max_defer_time = 86400 * 4; /* 4 days */ 1.700 1.701 - conf.remote_port = 25; 1.702 + if ((in = fopen(filename, "r"))) { 1.703 + gchar lval[256], rval[2048]; 1.704 + while (read_statement(in, lval, 256, rval, 2048)) { 1.705 + if (strcmp(lval, "debug_level") == 0) 1.706 + conf.debug_level = atoi(rval); 1.707 + else if (strcmp(lval, "run_as_user") == 0) { 1.708 + if (!conf.run_as_user) /* you should not be able to reset that flag */ 1.709 + conf.run_as_user = parse_boolean(rval); 1.710 + } else if (strcmp(lval, "use_syslog") == 0) 1.711 + conf.use_syslog = parse_boolean(rval); 1.712 + else if (strcmp(lval, "mail_dir") == 0) 1.713 + conf.mail_dir = g_strdup(rval); 1.714 + else if (strcmp(lval, "lock_dir") == 0) 1.715 + conf.lock_dir = g_strdup(rval); 1.716 + else if (strcmp(lval, "spool_dir") == 0) 1.717 + conf.spool_dir = g_strdup(rval); 1.718 + else if (strcmp(lval, "log_dir") == 0) 1.719 + conf.log_dir = g_strdup(rval); 1.720 + else if (strcmp(lval, "host_name") == 0) { 1.721 + if (rval[0] != '/') 1.722 + conf.host_name = g_strdup(rval); 1.723 + else { 1.724 + char buf[256]; 1.725 + FILE *fptr = fopen(rval, "rt"); 1.726 + if (fptr) { 1.727 + fgets(buf, 255, fptr); 1.728 + g_strchomp(buf); 1.729 + conf.host_name = g_strdup(buf); 1.730 + fclose(fptr); 1.731 + } else { 1.732 + fprintf(stderr, "could not open %s: %s\n", rval, 1.733 + strerror(errno)); 1.734 + return FALSE; 1.735 + } 1.736 + } 1.737 + } else if (strcmp(lval, "remote_port") == 0) { 1.738 + fprintf(stderr, "the remote_port option is now deprecated. Use 'mail_host' in the\n" 1.739 + "route configuration instead. See man masqmail.route\n"); 1.740 + conf.remote_port = atoi(rval); 1.741 + } else if (strcmp(lval, "local_hosts") == 0) 1.742 + conf.local_hosts = parse_list(rval, FALSE); 1.743 + else if (strcmp(lval, "local_addresses") == 0) 1.744 + conf.local_addresses = parse_list(rval, TRUE); 1.745 + else if (strcmp(lval, "not_local_addresses") == 0) 1.746 + conf.not_local_addresses = parse_list(rval, TRUE); 1.747 + else if (strcmp(lval, "local_nets") == 0) 1.748 + conf.local_nets = parse_list(rval, FALSE); 1.749 + else if (strcmp(lval, "do_save_envelope_to") == 0) 1.750 + conf.do_save_envelope_to = parse_boolean(rval); 1.751 + else if (strcmp(lval, "defer_all") == 0) 1.752 + conf.defer_all = parse_boolean(rval); 1.753 + else if (strcmp(lval, "do_relay") == 0) 1.754 + conf.do_relay = parse_boolean(rval); 1.755 + else if (strcmp(lval, "alias_file") == 0) { 1.756 + conf.alias_file = g_strdup(rval); 1.757 + } else if (strcmp(lval, "alias_local_caseless") == 0) { 1.758 + conf.alias_local_cmp = parse_boolean(rval) ? strcasecmp : strcmp; 1.759 + } else if (strcmp(lval, "mbox_default") == 0) { 1.760 + conf.mbox_default = g_strdup(rval); 1.761 + } else if (strcmp(lval, "mbox_users") == 0) { 1.762 + conf.mbox_users = parse_list(rval, TRUE); 1.763 + } else if (strcmp(lval, "mda_users") == 0) { 1.764 + conf.mda_users = parse_list(rval, TRUE); 1.765 + } else if (strcmp(lval, "maildir_users") == 0) { 1.766 + conf.maildir_users = parse_list(rval, TRUE); 1.767 + } else if (strcmp(lval, "mda") == 0) { 1.768 + conf.mda = g_strdup(rval); 1.769 + } else if (strcmp(lval, "mda_fromline") == 0) { 1.770 + conf.mda_fromline = parse_boolean(rval); 1.771 + } else if (strcmp(lval, "mda_fromhack") == 0) { 1.772 + conf.mda_fromhack = parse_boolean(rval); 1.773 + } else if (strcmp(lval, "pipe_fromline") == 0) { 1.774 + conf.pipe_fromline = parse_boolean(rval); 1.775 + } else if (strcmp(lval, "pipe_fromhack") == 0) { 1.776 + conf.pipe_fromhack = parse_boolean(rval); 1.777 + } else if (strcmp(lval, "listen_addresses") == 0) { 1.778 + GList *node; 1.779 + GList *tmp_list = parse_list(rval, FALSE); 1.780 1.781 - conf.do_relay = TRUE; 1.782 + conf.listen_addresses = NULL; 1.783 + foreach(tmp_list, node) { 1.784 + conf.listen_addresses = g_list_append(conf.listen_addresses, parse_interface((gchar *) (node-> data), 25)); 1.785 + g_free(node->data); 1.786 + } 1.787 + g_list_free(tmp_list); 1.788 + } else if (strcmp(lval, "ident_trusted_nets") == 0) { 1.789 +#ifdef ENABLE_IDENT 1.790 + GList *node; 1.791 + GList *tmp_list = parse_list(rval, FALSE); 1.792 1.793 - conf.alias_local_cmp = strcmp; 1.794 + conf.ident_trusted_nets = NULL; 1.795 + foreach(tmp_list, node) { 1.796 + conf.ident_trusted_nets = g_list_append(conf.ident_trusted_nets, parse_network((gchar *) (node->data), 25)); 1.797 + g_free(node->data); 1.798 + } 1.799 + g_list_free(tmp_list); 1.800 +#else 1.801 + fprintf(stderr, "%s ignored: not compiled with ident support\n", lval); 1.802 +#endif 1.803 + } else if ((strncmp(lval, "connect_route.", 14) == 0) 1.804 + || (strncmp(lval, "online_routes.", 14) == 0)) { 1.805 + GList *file_list = parse_list(rval, FALSE); 1.806 + table_pair *pair = create_pair(&(lval[14]), file_list); 1.807 + conf.connect_routes = g_list_append(conf.connect_routes, pair); 1.808 + } else if (strcmp(lval, "local_net_route") == 0) { 1.809 + conf.local_net_routes = parse_list(rval, FALSE); 1.810 + } else if (strcmp(lval, "online_detect") == 0) 1.811 + conf.online_detect = g_strdup(rval); 1.812 + else if (strcmp(lval, "online_file") == 0) 1.813 + conf.online_file = g_strdup(rval); 1.814 + else if (strcmp(lval, "online_pipe") == 0) 1.815 + conf.online_pipe = g_strdup(rval); 1.816 + else if (strcmp(lval, "mserver_iface") == 0) 1.817 + conf.mserver_iface = parse_interface(rval, 224); 1.818 + else if (strcmp(lval, "do_queue") == 0) 1.819 + conf.do_queue = parse_boolean(rval); 1.820 + else if (strncmp(lval, "get.", 4) == 0) { 1.821 +#ifdef ENABLE_POP3 1.822 + table_pair *pair = create_pair_string(&(lval[4]), rval); 1.823 + conf.get_names = g_list_append(conf.get_names, pair); 1.824 +#else 1.825 + fprintf(stderr, "get.<name> ignored: not compiled with pop support\n"); 1.826 +#endif 1.827 + } else if (strncmp(lval, "online_gets.", 12) == 0) { 1.828 +#ifdef ENABLE_POP3 1.829 + GList *file_list = parse_list(rval, FALSE); 1.830 + table_pair *pair = create_pair(&(lval[12]), file_list); 1.831 + conf.online_gets = g_list_append(conf.online_gets, pair); 1.832 +#else 1.833 + fprintf(stderr, "online_gets.<name> ignored: not compiled with pop support\n"); 1.834 +#endif 1.835 + } else if (strcmp(lval, "errmsg_file") == 0) 1.836 + conf.errmsg_file = g_strdup(rval); 1.837 + else if (strcmp(lval, "warnmsg_file") == 0) 1.838 + conf.warnmsg_file = g_strdup(rval); 1.839 + else if (strcmp(lval, "warn_intervals") == 0) 1.840 + conf.warn_intervals = parse_list(rval, FALSE); 1.841 + else if (strcmp(lval, "max_defer_time") == 0) { 1.842 + gint dummy; 1.843 + gint ival = time_interval(rval, &dummy); 1.844 + if (ival < 0) 1.845 + fprintf(stderr, "invalid time interval for 'max_defer_time': %s\n", rval); 1.846 + else 1.847 + conf.max_defer_time = ival; 1.848 + } else if (strcmp(lval, "log_user") == 0) 1.849 + conf.log_user = g_strdup(rval); 1.850 1.851 - conf.max_defer_time = 86400*4; /* 4 days */ 1.852 + else 1.853 + fprintf(stderr, "var '%s' not (yet) known, ignored\n", lval); 1.854 + } 1.855 + fclose(in); 1.856 1.857 - if((in = fopen(filename, "r"))){ 1.858 - gchar lval[256], rval[2048]; 1.859 - while(read_statement(in, lval, 256, rval, 2048)){ 1.860 - if(strcmp(lval, "debug_level") == 0) 1.861 - conf.debug_level = atoi(rval); 1.862 - else if(strcmp(lval, "run_as_user") == 0){ 1.863 - if(!conf.run_as_user) /* you should not be able 1.864 - to reset that flag */ 1.865 - conf.run_as_user = parse_boolean(rval); 1.866 - }else if(strcmp(lval, "use_syslog") == 0) 1.867 - conf.use_syslog = parse_boolean(rval); 1.868 - else if(strcmp(lval, "mail_dir") == 0) 1.869 - conf.mail_dir = g_strdup(rval); 1.870 - else if(strcmp(lval, "lock_dir") == 0) 1.871 - conf.lock_dir = g_strdup(rval); 1.872 - else if(strcmp(lval, "spool_dir") == 0) 1.873 - conf.spool_dir = g_strdup(rval); 1.874 - else if(strcmp(lval, "log_dir") == 0) 1.875 - conf.log_dir = g_strdup(rval); 1.876 - else if(strcmp(lval, "host_name") == 0){ 1.877 - if(rval[0] != '/') 1.878 - conf.host_name = g_strdup(rval); 1.879 - else{ 1.880 - char buf[256]; 1.881 - FILE *fptr = fopen(rval, "rt"); 1.882 - if(fptr){ 1.883 - fgets(buf, 255, fptr); 1.884 - g_strchomp(buf); 1.885 - conf.host_name = g_strdup(buf); 1.886 - fclose(fptr); 1.887 - }else{ 1.888 - fprintf(stderr, "could not open %s: %s\n", rval, strerror(errno)); 1.889 - return FALSE; 1.890 - } 1.891 - } 1.892 - } 1.893 - else if(strcmp(lval, "remote_port") == 0){ 1.894 - fprintf(stderr, 1.895 - "the remote_port option is now deprecated. Use 'mail_host' in the\n" 1.896 - "route configuration instead. See man masqmail.route\n"); 1.897 - conf.remote_port = atoi(rval); 1.898 - }else if(strcmp(lval, "local_hosts") == 0) 1.899 - conf.local_hosts = parse_list(rval, FALSE); 1.900 - else if(strcmp(lval, "local_addresses") == 0) 1.901 - conf.local_addresses = parse_list(rval, TRUE); 1.902 - else if(strcmp(lval, "not_local_addresses") == 0) 1.903 - conf.not_local_addresses = parse_list(rval, TRUE); 1.904 - else if(strcmp(lval, "local_nets") == 0) 1.905 - conf.local_nets = parse_list(rval, FALSE); 1.906 - else if(strcmp(lval, "do_save_envelope_to") == 0) 1.907 - conf.do_save_envelope_to = parse_boolean(rval); 1.908 - else if(strcmp(lval, "defer_all") == 0) 1.909 - conf.defer_all = parse_boolean(rval); 1.910 - else if(strcmp(lval, "do_relay") == 0) 1.911 - conf.do_relay = parse_boolean(rval); 1.912 - else if(strcmp(lval, "alias_file") == 0){ 1.913 - conf.alias_file = g_strdup(rval); 1.914 - }else if(strcmp(lval, "alias_local_caseless") == 0){ 1.915 - conf.alias_local_cmp = parse_boolean(rval) ? strcasecmp : strcmp; 1.916 - }else if(strcmp(lval, "mbox_default") == 0){ 1.917 - conf.mbox_default = g_strdup(rval); 1.918 - }else if(strcmp(lval, "mbox_users") == 0){ 1.919 - conf.mbox_users = parse_list(rval, TRUE); 1.920 - }else if(strcmp(lval, "mda_users") == 0){ 1.921 - conf.mda_users = parse_list(rval, TRUE); 1.922 - }else if(strcmp(lval, "maildir_users") == 0){ 1.923 - conf.maildir_users = parse_list(rval, TRUE); 1.924 - }else if(strcmp(lval, "mda") == 0){ 1.925 - conf.mda = g_strdup(rval); 1.926 - }else if(strcmp(lval, "mda_fromline") == 0){ 1.927 - conf.mda_fromline = parse_boolean(rval); 1.928 - }else if(strcmp(lval, "mda_fromhack") == 0){ 1.929 - conf.mda_fromhack = parse_boolean(rval); 1.930 - }else if(strcmp(lval, "pipe_fromline") == 0){ 1.931 - conf.pipe_fromline = parse_boolean(rval); 1.932 - }else if(strcmp(lval, "pipe_fromhack") == 0){ 1.933 - conf.pipe_fromhack = parse_boolean(rval); 1.934 - }else if(strcmp(lval, "listen_addresses") == 0){ 1.935 - GList *node; 1.936 - GList *tmp_list = parse_list(rval, FALSE); 1.937 - 1.938 - conf.listen_addresses = NULL; 1.939 - foreach(tmp_list, node){ 1.940 - conf.listen_addresses = 1.941 - g_list_append(conf.listen_addresses, 1.942 - parse_interface((gchar *)(node->data), 25)); 1.943 - g_free(node->data); 1.944 - } 1.945 - g_list_free(tmp_list); 1.946 - } 1.947 - else if(strcmp(lval, "ident_trusted_nets") == 0){ 1.948 -#ifdef ENABLE_IDENT 1.949 - GList *node; 1.950 - GList *tmp_list = parse_list(rval, FALSE); 1.951 - 1.952 - conf.ident_trusted_nets = NULL; 1.953 - foreach(tmp_list, node){ 1.954 - conf.ident_trusted_nets = 1.955 - g_list_append(conf.ident_trusted_nets, 1.956 - parse_network((gchar *)(node->data), 25)); 1.957 - g_free(node->data); 1.958 - } 1.959 - g_list_free(tmp_list); 1.960 -#else 1.961 - fprintf(stderr, "%s ignored: not compiled with ident support\n", lval); 1.962 -#endif 1.963 - } 1.964 - else if((strncmp(lval, "connect_route.", 14) == 0) || 1.965 - (strncmp(lval, "online_routes.", 14) == 0)){ 1.966 - GList *file_list = parse_list(rval, FALSE); 1.967 - table_pair *pair = create_pair(&(lval[14]), file_list); 1.968 - conf.connect_routes = g_list_append(conf.connect_routes, pair); 1.969 - } 1.970 - else if(strcmp(lval, "local_net_route") == 0){ 1.971 - conf.local_net_routes = parse_list(rval, FALSE); 1.972 - } 1.973 - else if(strcmp(lval, "online_detect") == 0) 1.974 - conf.online_detect = g_strdup(rval); 1.975 - else if(strcmp(lval, "online_file") == 0) 1.976 - conf.online_file = g_strdup(rval); 1.977 - else if(strcmp(lval, "online_pipe") == 0) 1.978 - conf.online_pipe = g_strdup(rval); 1.979 - else if(strcmp(lval, "mserver_iface") == 0) 1.980 - conf.mserver_iface = parse_interface(rval, 224); 1.981 - else if(strcmp(lval, "do_queue") == 0) 1.982 - conf.do_queue = parse_boolean(rval); 1.983 - else if(strncmp(lval, "get.", 4) == 0){ 1.984 -#ifdef ENABLE_POP3 1.985 - table_pair *pair = create_pair_string(&(lval[4]), rval); 1.986 - conf.get_names = g_list_append(conf.get_names, pair); 1.987 -#else 1.988 - fprintf(stderr, "get.<name> ignored: not compiled with pop support\n"); 1.989 -#endif 1.990 - } 1.991 - else if(strncmp(lval, "online_gets.", 12) == 0){ 1.992 -#ifdef ENABLE_POP3 1.993 - GList *file_list = parse_list(rval, FALSE); 1.994 - table_pair *pair = create_pair(&(lval[12]), file_list); 1.995 - conf.online_gets = g_list_append(conf.online_gets, pair); 1.996 -#else 1.997 - fprintf(stderr, "online_gets.<name> ignored: not compiled with pop support\n"); 1.998 -#endif 1.999 - } 1.1000 - else if(strcmp(lval, "errmsg_file") == 0) 1.1001 - conf.errmsg_file = g_strdup(rval); 1.1002 - else if(strcmp(lval, "warnmsg_file") == 0) 1.1003 - conf.warnmsg_file = g_strdup(rval); 1.1004 - else if(strcmp(lval, "warn_intervals") == 0) 1.1005 - conf.warn_intervals = parse_list(rval, FALSE); 1.1006 - else if(strcmp(lval, "max_defer_time") == 0){ 1.1007 - gint dummy; 1.1008 - gint ival = time_interval(rval, &dummy); 1.1009 - if(ival < 0) 1.1010 - fprintf(stderr, "invalid time interval for 'max_defer_time': %s\n", rval); 1.1011 - else 1.1012 - conf.max_defer_time = ival; 1.1013 - }else if(strcmp(lval, "log_user") == 0) 1.1014 - conf.log_user = g_strdup(rval); 1.1015 + if (conf.errmsg_file == NULL) 1.1016 + conf.errmsg_file = g_strdup(DATA_DIR "/tpl/failmsg.tpl"); 1.1017 + if (conf.warnmsg_file == NULL) 1.1018 + conf.warnmsg_file = g_strdup(DATA_DIR "/tpl/warnmsg.tpl"); 1.1019 1.1020 - else 1.1021 - fprintf(stderr, "var '%s' not (yet) known, ignored\n", lval); 1.1022 - } 1.1023 - fclose(in); 1.1024 + if (conf.lock_dir == NULL) 1.1025 + conf.lock_dir = g_strdup_printf("%s/lock/", conf.spool_dir); 1.1026 1.1027 - if(conf.errmsg_file == NULL) 1.1028 - conf.errmsg_file = g_strdup(DATA_DIR"/tpl/failmsg.tpl"); 1.1029 - if(conf.warnmsg_file == NULL) 1.1030 - conf.warnmsg_file = g_strdup(DATA_DIR"/tpl/warnmsg.tpl"); 1.1031 + if (conf.mbox_default == NULL) 1.1032 + conf.mbox_default = g_strdup("mbox"); 1.1033 1.1034 - if(conf.lock_dir == NULL) 1.1035 - conf.lock_dir = g_strdup_printf("%s/lock/", conf.spool_dir); 1.1036 + if (conf.warn_intervals == NULL) 1.1037 + conf.warn_intervals = parse_list("1h;4h;8h;1d;2d;3d", FALSE); 1.1038 1.1039 - if(conf.mbox_default == NULL) 1.1040 - conf.mbox_default = g_strdup("mbox"); 1.1041 - 1.1042 - if(conf.warn_intervals == NULL) 1.1043 - conf.warn_intervals = parse_list("1h;4h;8h;1d;2d;3d", FALSE); 1.1044 - 1.1045 - return TRUE; 1.1046 - }else 1.1047 - fprintf(stderr, "could not open config file %s: %s\n", filename, strerror(errno)); 1.1048 - return FALSE; 1.1049 + return TRUE; 1.1050 + } else 1.1051 + fprintf(stderr, "could not open config file %s: %s\n", filename, strerror(errno)); 1.1052 + return FALSE; 1.1053 } 1.1054 1.1055 -connect_route *read_route(gchar *filename, gboolean is_local_net) 1.1056 +connect_route* 1.1057 +read_route(gchar * filename, gboolean is_local_net) 1.1058 { 1.1059 - gboolean ok = FALSE; 1.1060 - FILE *in; 1.1061 + gboolean ok = FALSE; 1.1062 + FILE *in; 1.1063 1.1064 - connect_route *route = g_malloc(sizeof(connect_route)); 1.1065 - memset(route, 0, sizeof(connect_route)); 1.1066 + connect_route *route = g_malloc(sizeof(connect_route)); 1.1067 + memset(route, 0, sizeof(connect_route)); 1.1068 1.1069 - DEBUG(5) debugf("read_route, filename = %s\n", filename); 1.1070 + DEBUG(5) debugf("read_route, filename = %s\n", filename); 1.1071 1.1072 - route->filename = g_strdup(filename); 1.1073 - route->name = g_strdup(filename); /* quick hack */ 1.1074 + route->filename = g_strdup(filename); 1.1075 + route->name = g_strdup(filename); /* quick hack */ 1.1076 1.1077 - route->protocol = g_strdup("smtp"); 1.1078 - route->expand_h_sender_address = TRUE; 1.1079 + route->protocol = g_strdup("smtp"); 1.1080 + route->expand_h_sender_address = TRUE; 1.1081 1.1082 - route->is_local_net = is_local_net; 1.1083 + route->is_local_net = is_local_net; 1.1084 1.1085 - route->do_pipelining = TRUE; 1.1086 + route->do_pipelining = TRUE; 1.1087 1.1088 - if((in = fopen(route->filename, "r"))){ 1.1089 - gchar lval[256], rval[2048]; 1.1090 - while(read_statement(in, lval, 256, rval, 2048)){ 1.1091 - if(strcmp(lval, "protocol") == 0) 1.1092 - route->protocol = g_strdup(rval); 1.1093 - else if(strcmp(lval, "mail_host") == 0) 1.1094 - route->mail_host = parse_interface(rval, conf.remote_port); 1.1095 - else if(strcmp(lval, "helo_name") == 0) 1.1096 - route->helo_name = g_strdup(rval); 1.1097 - else if(strcmp(lval, "wrapper") == 0) 1.1098 - route->wrapper = g_strdup(rval); 1.1099 - else if(strcmp(lval, "connect_error_fail") == 0) 1.1100 - route->connect_error_fail = parse_boolean(rval); 1.1101 - else if(strcmp(lval, "do_correct_helo") == 0) 1.1102 - route->do_correct_helo = parse_boolean(rval); 1.1103 - else if(strcmp(lval, "do_pipelining") == 0) 1.1104 - route->do_pipelining = parse_boolean(rval); 1.1105 - else if(strcmp(lval, "allowed_return_paths") == 0) 1.1106 - route->allowed_return_paths = parse_address_list(rval, TRUE); 1.1107 - else if(strcmp(lval, "allowed_mail_locals") == 0) 1.1108 - route->allowed_mail_locals = parse_list(rval, TRUE); 1.1109 - else if(strcmp(lval, "not_allowed_return_paths") == 0) 1.1110 - route->not_allowed_return_paths = parse_address_list(rval, TRUE); 1.1111 - else if(strcmp(lval, "not_allowed_mail_locals") == 0) 1.1112 - route->not_allowed_mail_locals = parse_list(rval, TRUE); 1.1113 - else if(strcmp(lval, "allowed_rcpt_domains") == 0) 1.1114 - route->allowed_rcpt_domains = parse_list(rval, TRUE); 1.1115 - else if(strcmp(lval, "not_allowed_rcpt_domains") == 0) 1.1116 - route->not_allowed_rcpt_domains = parse_list(rval, TRUE); 1.1117 - else if(strcmp(lval, "set_h_from_domain") == 0) 1.1118 - route->set_h_from_domain = g_strdup(rval); 1.1119 - else if(strcmp(lval, "set_h_reply_to_domain") == 0) 1.1120 - route->set_h_reply_to_domain = g_strdup(rval); 1.1121 - else if(strcmp(lval, "set_return_path_domain") == 0) 1.1122 - route->set_return_path_domain = g_strdup(rval); 1.1123 - else if(strcmp(lval, "map_return_path_addresses") == 0){ 1.1124 - GList *node, *list; 1.1125 + if ((in = fopen(route->filename, "r"))) { 1.1126 + gchar lval[256], rval[2048]; 1.1127 + while (read_statement(in, lval, 256, rval, 2048)) { 1.1128 + if (strcmp(lval, "protocol") == 0) 1.1129 + route->protocol = g_strdup(rval); 1.1130 + else if (strcmp(lval, "mail_host") == 0) 1.1131 + route->mail_host = parse_interface(rval, conf.remote_port); 1.1132 + else if (strcmp(lval, "helo_name") == 0) 1.1133 + route->helo_name = g_strdup(rval); 1.1134 + else if (strcmp(lval, "wrapper") == 0) 1.1135 + route->wrapper = g_strdup(rval); 1.1136 + else if (strcmp(lval, "connect_error_fail") == 0) 1.1137 + route->connect_error_fail = parse_boolean(rval); 1.1138 + else if (strcmp(lval, "do_correct_helo") == 0) 1.1139 + route->do_correct_helo = parse_boolean(rval); 1.1140 + else if (strcmp(lval, "do_pipelining") == 0) 1.1141 + route->do_pipelining = parse_boolean(rval); 1.1142 + else if (strcmp(lval, "allowed_return_paths") == 0) 1.1143 + route->allowed_return_paths = parse_address_list(rval, TRUE); 1.1144 + else if (strcmp(lval, "allowed_mail_locals") == 0) 1.1145 + route->allowed_mail_locals = parse_list(rval, TRUE); 1.1146 + else if (strcmp(lval, "not_allowed_return_paths") == 0) 1.1147 + route->not_allowed_return_paths = parse_address_list(rval, TRUE); 1.1148 + else if (strcmp(lval, "not_allowed_mail_locals") == 0) 1.1149 + route->not_allowed_mail_locals = parse_list(rval, TRUE); 1.1150 + else if (strcmp(lval, "allowed_rcpt_domains") == 0) 1.1151 + route->allowed_rcpt_domains = parse_list(rval, TRUE); 1.1152 + else if (strcmp(lval, "not_allowed_rcpt_domains") == 0) 1.1153 + route->not_allowed_rcpt_domains = parse_list(rval, TRUE); 1.1154 + else if (strcmp(lval, "set_h_from_domain") == 0) 1.1155 + route->set_h_from_domain = g_strdup(rval); 1.1156 + else if (strcmp(lval, "set_h_reply_to_domain") == 0) 1.1157 + route->set_h_reply_to_domain = g_strdup(rval); 1.1158 + else if (strcmp(lval, "set_return_path_domain") == 0) 1.1159 + route->set_return_path_domain = g_strdup(rval); 1.1160 + else if (strcmp(lval, "map_return_path_addresses") == 0) { 1.1161 + GList *node, *list; 1.1162 1.1163 - list = parse_list(rval, TRUE); 1.1164 - foreach(list, node){ 1.1165 - gchar *item = (gchar *)(node->data); 1.1166 - table_pair *pair = parse_table_pair(item, ':'); 1.1167 - address *addr = create_address((gchar *)(pair->value), TRUE); 1.1168 - g_free(pair->value); 1.1169 - pair->value = (gpointer *)addr; 1.1170 - route->map_return_path_addresses = 1.1171 - g_list_append(route->map_return_path_addresses, pair); 1.1172 - g_free(item); 1.1173 + list = parse_list(rval, TRUE); 1.1174 + foreach(list, node) { 1.1175 + gchar *item = (gchar *) (node->data); 1.1176 + table_pair *pair = parse_table_pair(item, ':'); 1.1177 + address *addr = create_address((gchar *) (pair->value), TRUE); 1.1178 + g_free(pair->value); 1.1179 + pair->value = (gpointer *) addr; 1.1180 + route->map_return_path_addresses = g_list_append(route->map_return_path_addresses, pair); 1.1181 + g_free(item); 1.1182 + } 1.1183 + g_list_free(list); 1.1184 + } else if (strcmp(lval, "map_h_from_addresses") == 0) { 1.1185 + GList *list, *node; 1.1186 + 1.1187 + list = parse_list(rval, TRUE); 1.1188 + foreach(list, node) { 1.1189 + gchar *item = (gchar *) (node->data); 1.1190 + table_pair *pair = parse_table_pair(item, ':'); 1.1191 + route->map_h_from_addresses = g_list_append(route->map_h_from_addresses, pair); 1.1192 + g_free(item); 1.1193 + } 1.1194 + g_list_free(list); 1.1195 + } else if (strcmp(lval, "map_h_reply_to_addresses") == 0) { 1.1196 + GList *list, *node; 1.1197 + 1.1198 + list = parse_list(rval, TRUE); 1.1199 + foreach(list, node) { 1.1200 + gchar *item = (gchar *) (node->data); 1.1201 + table_pair *pair = parse_table_pair(item, ':'); 1.1202 + route->map_h_reply_to_addresses = g_list_append(route->map_h_reply_to_addresses, pair); 1.1203 + g_free(item); 1.1204 + } 1.1205 + g_list_free(list); 1.1206 + } else if (strcmp(lval, "map_h_mail_followup_to_addresses") == 0) { 1.1207 + GList *list, *node; 1.1208 + 1.1209 + list = parse_list(rval, TRUE); 1.1210 + foreach(list, node) { 1.1211 + gchar *item = (gchar *) (node->data); 1.1212 + table_pair *pair = parse_table_pair(item, ':'); 1.1213 + route->map_h_mail_followup_to_addresses = g_list_append(route->map_h_mail_followup_to_addresses, pair); 1.1214 + g_free(item); 1.1215 + } 1.1216 + g_list_free(list); 1.1217 + } else if (strcmp(lval, "expand_h_sender_domain") == 0) { 1.1218 + route->expand_h_sender_domain = parse_boolean(rval); 1.1219 + } else if (strcmp(lval, "expand_h_sender_address") == 0) { 1.1220 + route->expand_h_sender_address = parse_boolean(rval); 1.1221 + } else if (strcmp(lval, "resolve_list") == 0) 1.1222 + route->resolve_list = parse_resolve_list(rval); 1.1223 + else if (strcmp(lval, "do_ssl") == 0) { 1.1224 + /* we ignore this. This option is used by sqilconf */ 1.1225 + ; 1.1226 + } 1.1227 +#ifdef ENABLE_AUTH 1.1228 + else if (strcmp(lval, "auth_name") == 0) { 1.1229 + route->auth_name = g_strdup(rval); 1.1230 + } else if (strcmp(lval, "auth_login") == 0) { 1.1231 + route->auth_login = g_strdup(rval); 1.1232 + } else if (strcmp(lval, "auth_secret") == 0) { 1.1233 + route->auth_secret = g_strdup(rval); 1.1234 + } 1.1235 +#else 1.1236 + else if ((strcmp(lval, "auth_name") == 0) 1.1237 + || (strcmp(lval, "auth_login") == 0) 1.1238 + || (strcmp(lval, "auth_secret") == 0)) { 1.1239 + logwrite(LOG_WARNING, "%s ignored: not compiled with auth support.\n", lval); 1.1240 + } 1.1241 +#endif 1.1242 + else if (strcmp(lval, "pop3_login") == 0) { 1.1243 +#ifdef ENABLE_POP3 1.1244 + route->pop3_login = g_strdup(rval); 1.1245 +#else 1.1246 + logwrite(LOG_WARNING, "pop3_login ignored: not compiled with pop support.\n"); 1.1247 +#endif 1.1248 + } else if (strcmp(lval, "pipe") == 0) { 1.1249 + route->pipe = g_strdup(rval); 1.1250 + } else if (strcmp(lval, "pipe_fromline") == 0) { 1.1251 + route->pipe_fromline = parse_boolean(rval); 1.1252 + } else if (strcmp(lval, "pipe_fromhack") == 0) { 1.1253 + route->pipe_fromhack = parse_boolean(rval); 1.1254 + } else if (strcmp(lval, "last_route") == 0) { 1.1255 + route->last_route = parse_boolean(rval); 1.1256 + } else 1.1257 + logwrite(LOG_WARNING, "var '%s' not (yet) known, ignored\n", lval); 1.1258 + } 1.1259 + 1.1260 + if (route->resolve_list == NULL) { 1.1261 + if (is_local_net) { 1.1262 + route->resolve_list = g_list_append(NULL, resolve_byname); 1.1263 + } else { 1.1264 +#ifdef ENABLE_RESOLVER 1.1265 + route->resolve_list = g_list_append(route->resolve_list, resolve_dns_mx); 1.1266 + route->resolve_list = g_list_append(route->resolve_list, resolve_dns_a); 1.1267 +#endif 1.1268 + route->resolve_list = g_list_append(route->resolve_list, resolve_byname); 1.1269 + } 1.1270 + } 1.1271 + fclose(in); 1.1272 + ok = TRUE; 1.1273 + 1.1274 + /* warn user about misconfigurations: */ 1.1275 + if ((route->map_h_from_addresses != NULL) 1.1276 + && (route->set_h_from_domain != NULL)) { 1.1277 + logwrite(LOG_WARNING, "'map_h_from_addresses' overrides 'set_h_from_domain'\n"); 1.1278 + g_free(route->set_h_from_domain); 1.1279 + route->set_h_from_domain = NULL; 1.1280 + } 1.1281 + if ((route->map_h_reply_to_addresses != NULL) 1.1282 + && (route->set_h_reply_to_domain != NULL)) { 1.1283 + logwrite(LOG_WARNING, "'map_h_reply_to_addresses' overrides 'set_h_reply_to_domain'\n"); 1.1284 + g_free(route->set_h_reply_to_domain); 1.1285 + route->set_h_reply_to_domain = NULL; 1.1286 + } 1.1287 + } else { 1.1288 + logwrite(LOG_ALERT, "could not open route file %s: %s\n", route->filename, strerror(errno)); 1.1289 + } 1.1290 + 1.1291 + if (!ok) { 1.1292 + g_free(route); 1.1293 + route = NULL; 1.1294 + } 1.1295 + 1.1296 + return route; 1.1297 +} 1.1298 + 1.1299 +static void 1.1300 +_g_list_free_all(GList * list) 1.1301 +{ 1.1302 + GList *node; 1.1303 + if (list) { 1.1304 + foreach(list, node) 1.1305 + g_free(node->data); 1.1306 + g_list_free(list); 1.1307 + } 1.1308 +} 1.1309 + 1.1310 +void 1.1311 +destroy_route(connect_route * r) 1.1312 +{ 1.1313 + if (r->filename) 1.1314 + g_free(r->filename); 1.1315 + if (r->protocol) 1.1316 + g_free(r->protocol); 1.1317 + if (r->mail_host) { 1.1318 + g_free(r->mail_host->address); 1.1319 + g_free(r->mail_host); 1.1320 + } 1.1321 + if (r->wrapper) 1.1322 + g_free(r->wrapper); 1.1323 + if (r->helo_name) 1.1324 + g_free(r->helo_name); 1.1325 + _g_list_free_all(r->allowed_mail_locals); 1.1326 + _g_list_free_all(r->not_allowed_mail_locals); 1.1327 + _g_list_free_all(r->allowed_rcpt_domains); 1.1328 + _g_list_free_all(r->not_allowed_rcpt_domains); 1.1329 + if (r->set_h_from_domain) 1.1330 + g_free(r->set_h_from_domain); 1.1331 + if (r->set_h_reply_to_domain) 1.1332 + g_free(r->set_h_reply_to_domain); 1.1333 + if (r->set_return_path_domain) 1.1334 + g_free(r->set_return_path_domain); 1.1335 + if (r->map_h_reply_to_addresses) 1.1336 + destroy_table(r->map_h_reply_to_addresses); 1.1337 + if (r->resolve_list) 1.1338 + g_list_free(r->resolve_list); 1.1339 +#ifdef ENABLE_AUTH 1.1340 + if (r->auth_name) 1.1341 + g_free(r->auth_name); 1.1342 + if (r->auth_login) 1.1343 + g_free(r->auth_login); 1.1344 + if (r->auth_secret) 1.1345 + g_free(r->auth_secret); 1.1346 +#endif 1.1347 +#ifdef ENABLE_POP3 1.1348 + if (r->pop3_login) 1.1349 + g_free(r->pop3_login); 1.1350 +#endif 1.1351 + if (r->pipe) 1.1352 + g_free(r->pipe); 1.1353 + g_free(r); 1.1354 +} 1.1355 + 1.1356 +GList* 1.1357 +read_route_list(GList * rf_list, gboolean is_local_net) 1.1358 +{ 1.1359 + GList *list = NULL; 1.1360 + GList *node; 1.1361 + uid_t saved_uid, saved_gid; 1.1362 + 1.1363 + if (!conf.run_as_user) { 1.1364 + set_euidgid(0, 0, &saved_uid, &saved_gid); 1.1365 + } 1.1366 + 1.1367 + foreach(rf_list, node) { 1.1368 + gchar *fname = (gchar *) (node->data); 1.1369 + connect_route *route = read_route(fname, is_local_net); 1.1370 + if (route) 1.1371 + list = g_list_append(list, route); 1.1372 + else 1.1373 + logwrite(LOG_ALERT, "could not read route configuration %s\n", fname); 1.1374 + } 1.1375 + 1.1376 + /* set uid and gid back */ 1.1377 + if (!conf.run_as_user) { 1.1378 + set_euidgid(saved_uid, saved_gid, NULL, NULL); 1.1379 + } 1.1380 + 1.1381 + return list; 1.1382 +} 1.1383 + 1.1384 +void 1.1385 +destroy_route_list(GList * list) 1.1386 +{ 1.1387 + GList *node; 1.1388 + 1.1389 + foreach(list, node) { 1.1390 + connect_route *route = (connect_route *) (node->data); 1.1391 + destroy_route(route); 1.1392 } 1.1393 g_list_free(list); 1.1394 - } 1.1395 - else if(strcmp(lval, "map_h_from_addresses") == 0){ 1.1396 - GList *list, *node; 1.1397 - 1.1398 - list = parse_list(rval, TRUE); 1.1399 - foreach(list, node){ 1.1400 - gchar *item = (gchar *)(node->data); 1.1401 - table_pair *pair = parse_table_pair(item, ':'); 1.1402 - route->map_h_from_addresses = 1.1403 - g_list_append(route->map_h_from_addresses, pair); 1.1404 - g_free(item); 1.1405 - } 1.1406 - g_list_free(list); 1.1407 - } 1.1408 - else if(strcmp(lval, "map_h_reply_to_addresses") == 0){ 1.1409 - GList *list, *node; 1.1410 - 1.1411 - list = parse_list(rval, TRUE); 1.1412 - foreach(list, node){ 1.1413 - gchar *item = (gchar *)(node->data); 1.1414 - table_pair *pair = parse_table_pair(item, ':'); 1.1415 - route->map_h_reply_to_addresses = 1.1416 - g_list_append(route->map_h_reply_to_addresses, pair); 1.1417 - g_free(item); 1.1418 - } 1.1419 - g_list_free(list); 1.1420 - } 1.1421 - else if(strcmp(lval, "map_h_mail_followup_to_addresses") == 0){ 1.1422 - GList *list, *node; 1.1423 - 1.1424 - list = parse_list(rval, TRUE); 1.1425 - foreach(list, node){ 1.1426 - gchar *item = (gchar *)(node->data); 1.1427 - table_pair *pair = parse_table_pair(item, ':'); 1.1428 - route->map_h_mail_followup_to_addresses = 1.1429 - g_list_append(route->map_h_mail_followup_to_addresses, pair); 1.1430 - g_free(item); 1.1431 - } 1.1432 - g_list_free(list); 1.1433 - } 1.1434 - else if(strcmp(lval, "expand_h_sender_domain") == 0){ 1.1435 - route->expand_h_sender_domain = parse_boolean(rval); 1.1436 - } 1.1437 - else if(strcmp(lval, "expand_h_sender_address") == 0){ 1.1438 - route->expand_h_sender_address = parse_boolean(rval); 1.1439 - } 1.1440 - else if(strcmp(lval, "resolve_list") == 0) 1.1441 - route->resolve_list = parse_resolve_list(rval); 1.1442 - else if(strcmp(lval, "do_ssl") == 0){ 1.1443 - /* we ignore this. This option is used by sqilconf */ 1.1444 - ; 1.1445 - } 1.1446 -#ifdef ENABLE_AUTH 1.1447 - else if(strcmp(lval, "auth_name") == 0){ 1.1448 - route->auth_name = g_strdup(rval); 1.1449 - } 1.1450 - else if(strcmp(lval, "auth_login") == 0){ 1.1451 - route->auth_login = g_strdup(rval); 1.1452 - } 1.1453 - else if(strcmp(lval, "auth_secret") == 0){ 1.1454 - route->auth_secret = g_strdup(rval); 1.1455 - } 1.1456 -#else 1.1457 - else if((strcmp(lval, "auth_name") == 0) || 1.1458 - (strcmp(lval, "auth_login") == 0) || 1.1459 - (strcmp(lval, "auth_secret") == 0)){ 1.1460 - logwrite(LOG_WARNING, "%s ignored: not compiled with auth support.\n", lval); 1.1461 - } 1.1462 -#endif 1.1463 - else if(strcmp(lval, "pop3_login") == 0){ 1.1464 -#ifdef ENABLE_POP3 1.1465 - route->pop3_login = g_strdup(rval); 1.1466 -#else 1.1467 - logwrite(LOG_WARNING, "pop3_login ignored: not compiled with pop support.\n"); 1.1468 -#endif 1.1469 - } 1.1470 - else if(strcmp(lval, "pipe") == 0){ 1.1471 - route->pipe = g_strdup(rval); 1.1472 - } 1.1473 - else if(strcmp(lval, "pipe_fromline") == 0){ 1.1474 - route->pipe_fromline = parse_boolean(rval); 1.1475 - } 1.1476 - else if(strcmp(lval, "pipe_fromhack") == 0){ 1.1477 - route->pipe_fromhack = parse_boolean(rval); 1.1478 - } 1.1479 - else if(strcmp(lval, "last_route") == 0){ 1.1480 - route->last_route = parse_boolean(rval); 1.1481 - } 1.1482 - else 1.1483 - logwrite(LOG_WARNING, "var '%s' not (yet) known, ignored\n", lval); 1.1484 - } 1.1485 - 1.1486 - if(route->resolve_list == NULL){ 1.1487 - if(is_local_net){ 1.1488 - route->resolve_list = 1.1489 - g_list_append(NULL, resolve_byname); 1.1490 - }else{ 1.1491 -#ifdef ENABLE_RESOLVER 1.1492 - route->resolve_list = 1.1493 - g_list_append(route->resolve_list, resolve_dns_mx); 1.1494 - route->resolve_list = 1.1495 - g_list_append(route->resolve_list, resolve_dns_a); 1.1496 -#endif 1.1497 - route->resolve_list = 1.1498 - g_list_append(route->resolve_list, resolve_byname); 1.1499 - } 1.1500 - } 1.1501 - fclose(in); 1.1502 - ok = TRUE; 1.1503 - 1.1504 - /* warn user about misconfigurations: */ 1.1505 - if((route->map_h_from_addresses != NULL) && (route->set_h_from_domain != NULL)){ 1.1506 - logwrite(LOG_WARNING, "'map_h_from_addresses' overrides 'set_h_from_domain'\n"); 1.1507 - g_free(route->set_h_from_domain); 1.1508 - route->set_h_from_domain = NULL; 1.1509 - } 1.1510 - if((route->map_h_reply_to_addresses != NULL) && (route->set_h_reply_to_domain != NULL)){ 1.1511 - logwrite(LOG_WARNING, "'map_h_reply_to_addresses' overrides 'set_h_reply_to_domain'\n"); 1.1512 - g_free(route->set_h_reply_to_domain); 1.1513 - route->set_h_reply_to_domain = NULL; 1.1514 - } 1.1515 - }else{ 1.1516 - logwrite(LOG_ALERT, "could not open route file %s: %s\n", 1.1517 - route->filename, strerror(errno)); 1.1518 - } 1.1519 - 1.1520 - if(!ok){ 1.1521 - g_free(route); 1.1522 - route = NULL; 1.1523 - } 1.1524 - 1.1525 - return route; 1.1526 -} 1.1527 - 1.1528 -static 1.1529 -void _g_list_free_all(GList *list) 1.1530 -{ 1.1531 - GList *node; 1.1532 - if(list){ 1.1533 - foreach(list, node) 1.1534 - g_free(node->data); 1.1535 - g_list_free(list); 1.1536 - } 1.1537 -} 1.1538 - 1.1539 -void destroy_route(connect_route *r) 1.1540 -{ 1.1541 - if(r->filename) g_free(r->filename); 1.1542 - if(r->protocol) g_free(r->protocol); 1.1543 - if(r->mail_host){ 1.1544 - g_free(r->mail_host->address); 1.1545 - g_free(r->mail_host); 1.1546 - } 1.1547 - if(r->wrapper) g_free(r->wrapper); 1.1548 - if(r->helo_name) g_free(r->helo_name); 1.1549 - _g_list_free_all(r->allowed_mail_locals); 1.1550 - _g_list_free_all(r->not_allowed_mail_locals); 1.1551 - _g_list_free_all(r->allowed_rcpt_domains); 1.1552 - _g_list_free_all(r->not_allowed_rcpt_domains); 1.1553 - if(r->set_h_from_domain) g_free(r->set_h_from_domain); 1.1554 - if(r->set_h_reply_to_domain) g_free(r->set_h_reply_to_domain); 1.1555 - if(r->set_return_path_domain) g_free(r->set_return_path_domain); 1.1556 - if(r->map_h_reply_to_addresses) destroy_table(r->map_h_reply_to_addresses); 1.1557 - if(r->resolve_list) g_list_free(r->resolve_list); 1.1558 -#ifdef ENABLE_AUTH 1.1559 - if(r->auth_name) g_free(r->auth_name); 1.1560 - if(r->auth_login) g_free(r->auth_login); 1.1561 - if(r->auth_secret) g_free(r->auth_secret); 1.1562 -#endif 1.1563 -#ifdef ENABLE_POP3 1.1564 - if(r->pop3_login) g_free(r->pop3_login); 1.1565 -#endif 1.1566 - if(r->pipe) g_free(r->pipe); 1.1567 - g_free(r); 1.1568 -} 1.1569 - 1.1570 -GList *read_route_list(GList *rf_list, gboolean is_local_net) 1.1571 -{ 1.1572 - GList *list = NULL; 1.1573 - GList *node; 1.1574 - uid_t saved_uid, saved_gid; 1.1575 - 1.1576 - if(!conf.run_as_user){ 1.1577 - set_euidgid(0, 0, &saved_uid, &saved_gid); 1.1578 - } 1.1579 - 1.1580 - foreach(rf_list, node){ 1.1581 - gchar *fname = (gchar *)(node->data); 1.1582 - connect_route *route = read_route(fname, is_local_net); 1.1583 - if(route) 1.1584 - list = g_list_append(list, route); 1.1585 - else 1.1586 - logwrite(LOG_ALERT, "could not read route configuration %s\n", fname); 1.1587 - } 1.1588 - 1.1589 - /* set uid and gid back */ 1.1590 - if(!conf.run_as_user){ 1.1591 - set_euidgid(saved_uid, saved_gid, NULL, NULL); 1.1592 - } 1.1593 - 1.1594 - return list; 1.1595 -} 1.1596 - 1.1597 -void destroy_route_list(GList *list) 1.1598 -{ 1.1599 - GList *node; 1.1600 - 1.1601 - foreach(list, node){ 1.1602 - connect_route *route = (connect_route *)(node->data); 1.1603 - destroy_route(route); 1.1604 - } 1.1605 - g_list_free(list); 1.1606 } 1.1607 1.1608 #ifdef ENABLE_POP3 1.1609 1.1610 -get_conf *read_get_conf(gchar *filename) 1.1611 +get_conf* 1.1612 +read_get_conf(gchar * filename) 1.1613 { 1.1614 - FILE *in; 1.1615 + FILE *in; 1.1616 1.1617 - get_conf *gc = g_malloc(sizeof(get_conf)); 1.1618 - memset(gc, 0, sizeof(get_conf)); 1.1619 + get_conf *gc = g_malloc(sizeof(get_conf)); 1.1620 + memset(gc, 0, sizeof(get_conf)); 1.1621 1.1622 - gc->server_port = 110; 1.1623 + gc->server_port = 110; 1.1624 1.1625 - if((in = fopen(filename, "r"))){ 1.1626 - gchar lval[256], rval[2048]; 1.1627 - while(read_statement(in, lval, 256, rval, 2048)){ 1.1628 - if(strcmp(lval, "protocol") == 0) 1.1629 - gc->protocol = g_strdup(rval); 1.1630 - else if(strcmp(lval, "server") == 0) 1.1631 - gc->server_name = g_strdup(rval); 1.1632 - else if(strcmp(lval, "port") == 0) 1.1633 - gc->server_port = atoi(rval); 1.1634 - else if(strcmp(lval, "wrapper") == 0) 1.1635 - gc->wrapper = g_strdup(rval); 1.1636 - else if(strcmp(lval, "user") == 0) 1.1637 - gc->login_user = g_strdup(rval); 1.1638 - else if(strcmp(lval, "pass") == 0) 1.1639 - gc->login_pass = g_strdup(rval); 1.1640 - else if(strcmp(lval, "address") == 0) 1.1641 - gc->address = create_address_qualified(rval, TRUE, conf.host_name); 1.1642 - else if(strcmp(lval, "return_path") == 0) 1.1643 - gc->return_path = create_address_qualified(rval, TRUE, conf.host_name); 1.1644 - else if(strcmp(lval, "do_ssl") == 0) 1.1645 - /* we ignore this. This option is used by sqilconf */ 1.1646 - ; 1.1647 - else if(strcmp(lval, "do_keep") == 0) 1.1648 - gc->do_keep = parse_boolean(rval); 1.1649 - else if(strcmp(lval, "do_uidl") == 0) 1.1650 - gc->do_uidl = parse_boolean(rval); 1.1651 - else if(strcmp(lval, "do_uidl_dele") == 0) 1.1652 - gc->do_uidl_dele = parse_boolean(rval); 1.1653 - else if(strcmp(lval, "max_size") == 0) 1.1654 - gc->max_size = atoi(rval); 1.1655 - else if(strcmp(lval, "max_size_delete") == 0) 1.1656 - gc->max_size = parse_boolean(rval); 1.1657 - else if(strcmp(lval, "max_count") == 0) 1.1658 - gc->max_count = atoi(rval); 1.1659 - else if(strcmp(lval, "resolve_list") == 0) 1.1660 - gc->resolve_list = parse_resolve_list(rval); 1.1661 - else 1.1662 - logwrite(LOG_WARNING, "var '%s' not (yet) known, ignored\n", lval); 1.1663 - } 1.1664 - fclose(in); 1.1665 + if ((in = fopen(filename, "r"))) { 1.1666 + gchar lval[256], rval[2048]; 1.1667 + while (read_statement(in, lval, 256, rval, 2048)) { 1.1668 + if (strcmp(lval, "protocol") == 0) 1.1669 + gc->protocol = g_strdup(rval); 1.1670 + else if (strcmp(lval, "server") == 0) 1.1671 + gc->server_name = g_strdup(rval); 1.1672 + else if (strcmp(lval, "port") == 0) 1.1673 + gc->server_port = atoi(rval); 1.1674 + else if (strcmp(lval, "wrapper") == 0) 1.1675 + gc->wrapper = g_strdup(rval); 1.1676 + else if (strcmp(lval, "user") == 0) 1.1677 + gc->login_user = g_strdup(rval); 1.1678 + else if (strcmp(lval, "pass") == 0) 1.1679 + gc->login_pass = g_strdup(rval); 1.1680 + else if (strcmp(lval, "address") == 0) 1.1681 + gc->address = create_address_qualified(rval, TRUE, conf.host_name); 1.1682 + else if (strcmp(lval, "return_path") == 0) 1.1683 + gc->return_path = create_address_qualified(rval, TRUE, conf.host_name); 1.1684 + else if (strcmp(lval, "do_ssl") == 0) 1.1685 + /* we ignore this. This option is used by sqilconf */ 1.1686 + ; 1.1687 + else if (strcmp(lval, "do_keep") == 0) 1.1688 + gc->do_keep = parse_boolean(rval); 1.1689 + else if (strcmp(lval, "do_uidl") == 0) 1.1690 + gc->do_uidl = parse_boolean(rval); 1.1691 + else if (strcmp(lval, "do_uidl_dele") == 0) 1.1692 + gc->do_uidl_dele = parse_boolean(rval); 1.1693 + else if (strcmp(lval, "max_size") == 0) 1.1694 + gc->max_size = atoi(rval); 1.1695 + else if (strcmp(lval, "max_size_delete") == 0) 1.1696 + gc->max_size = parse_boolean(rval); 1.1697 + else if (strcmp(lval, "max_count") == 0) 1.1698 + gc->max_count = atoi(rval); 1.1699 + else if (strcmp(lval, "resolve_list") == 0) 1.1700 + gc->resolve_list = parse_resolve_list(rval); 1.1701 + else 1.1702 + logwrite(LOG_WARNING, "var '%s' not (yet) known, ignored\n", lval); 1.1703 + } 1.1704 + fclose(in); 1.1705 1.1706 - if(gc->resolve_list == NULL){ 1.1707 + if (gc->resolve_list == NULL) { 1.1708 #ifdef ENABLE_RESOLVER 1.1709 - gc->resolve_list = 1.1710 - g_list_append(NULL, resolve_dns_a); 1.1711 + gc->resolve_list = g_list_append(NULL, resolve_dns_a); 1.1712 #endif 1.1713 - gc->resolve_list = 1.1714 - g_list_append(NULL, resolve_byname); 1.1715 - } 1.1716 - 1.1717 - if(gc->protocol == NULL) 1.1718 - gc->protocol = g_strdup("pop3"); 1.1719 - return gc; 1.1720 - } 1.1721 - logwrite(LOG_ALERT, "could not open get file %s: %s\n", filename, strerror(errno)); 1.1722 + gc->resolve_list = g_list_append(NULL, resolve_byname); 1.1723 + } 1.1724 1.1725 - g_free(gc); 1.1726 - return NULL; 1.1727 + if (gc->protocol == NULL) 1.1728 + gc->protocol = g_strdup("pop3"); 1.1729 + return gc; 1.1730 + } 1.1731 + logwrite(LOG_ALERT, "could not open get file %s: %s\n", filename, strerror(errno)); 1.1732 + 1.1733 + g_free(gc); 1.1734 + return NULL; 1.1735 } 1.1736 1.1737 -void destroy_get_conf(get_conf *gc) 1.1738 +void 1.1739 +destroy_get_conf(get_conf * gc) 1.1740 { 1.1741 - if(gc->protocol) g_free(gc->protocol); 1.1742 - if(gc->server_name) g_free(gc->server_name); 1.1743 - if(gc->login_user) g_free(gc->login_user); 1.1744 - if(gc->login_pass) g_free(gc->login_pass); 1.1745 - if(gc->wrapper) g_free(gc->wrapper); 1.1746 - if(gc->address) destroy_address(gc->address); 1.1747 - if(gc->return_path) destroy_address(gc->return_path); 1.1748 - if(gc->resolve_list) g_list_free(gc->resolve_list); 1.1749 - g_free(gc); 1.1750 + if (gc->protocol) 1.1751 + g_free(gc->protocol); 1.1752 + if (gc->server_name) 1.1753 + g_free(gc->server_name); 1.1754 + if (gc->login_user) 1.1755 + g_free(gc->login_user); 1.1756 + if (gc->login_pass) 1.1757 + g_free(gc->login_pass); 1.1758 + if (gc->wrapper) 1.1759 + g_free(gc->wrapper); 1.1760 + if (gc->address) 1.1761 + destroy_address(gc->address); 1.1762 + if (gc->return_path) 1.1763 + destroy_address(gc->return_path); 1.1764 + if (gc->resolve_list) 1.1765 + g_list_free(gc->resolve_list); 1.1766 + g_free(gc); 1.1767 } 1.1768 1.1769 #endif 1.1770 1.1771 -connect_route *create_local_route() 1.1772 +connect_route* 1.1773 +create_local_route() 1.1774 { 1.1775 - connect_route *route; 1.1776 + connect_route *route; 1.1777 1.1778 - route = g_malloc(sizeof(connect_route)); 1.1779 - if(route){ 1.1780 - memset(route, 0, sizeof(connect_route)); 1.1781 - route->protocol = g_strdup("smtp"); 1.1782 - route->is_local_net = TRUE; 1.1783 - route->name = g_strdup("local_net (default)"); 1.1784 - route->expand_h_sender_address = TRUE; 1.1785 - route->resolve_list = 1.1786 - g_list_append(NULL, resolve_byname); 1.1787 - route->connect_error_fail = TRUE; 1.1788 - } 1.1789 - return route; 1.1790 + route = g_malloc(sizeof(connect_route)); 1.1791 + if (route) { 1.1792 + memset(route, 0, sizeof(connect_route)); 1.1793 + route->protocol = g_strdup("smtp"); 1.1794 + route->is_local_net = TRUE; 1.1795 + route->name = g_strdup("local_net (default)"); 1.1796 + route->expand_h_sender_address = TRUE; 1.1797 + route->resolve_list = g_list_append(NULL, resolve_byname); 1.1798 + route->connect_error_fail = TRUE; 1.1799 + } 1.1800 + return route; 1.1801 }