conf.c (6cec9cad762b6476313fb1f8e931a1647822db6b) | conf.c (e56bad4a94aff7e3e43200568b211de872a52aea) |
---|---|
1/* 2 * Copyright (c) 2008 The DragonFly Project. All rights reserved. 3 * 4 * This code is derived from software contributed to The DragonFly Project 5 * by Matthias Schmidt <matthias@dragonflybsd.org>, University of Marburg, 6 * Germany. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 50 unchanged lines hidden (view full) --- 59 if ((p = strchr(line, '\n'))) 60 *p = (char)0; 61 62 /* Escape leading dot in every case */ 63 linelen = strlen(line); 64 if (line[0] == '.') { 65 if ((linelen + 2) > 1000) { 66 syslog(LOG_CRIT, "Cannot escape leading dot. Buffer overflow"); | 1/* 2 * Copyright (c) 2008 The DragonFly Project. All rights reserved. 3 * 4 * This code is derived from software contributed to The DragonFly Project 5 * by Matthias Schmidt <matthias@dragonflybsd.org>, University of Marburg, 6 * Germany. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 50 unchanged lines hidden (view full) --- 59 if ((p = strchr(line, '\n'))) 60 *p = (char)0; 61 62 /* Escape leading dot in every case */ 63 linelen = strlen(line); 64 if (line[0] == '.') { 65 if ((linelen + 2) > 1000) { 66 syslog(LOG_CRIT, "Cannot escape leading dot. Buffer overflow"); |
67 exit(1); | 67 exit(EX_DATAERR); |
68 } 69 memmove((line + 1), line, (linelen + 1)); 70 line[0] = '.'; 71 } 72} 73 74static void 75chomp(char *str) --- 20 unchanged lines hidden (view full) --- 96 char line[2048]; 97 struct authuser *au; 98 FILE *a; 99 char *data; 100 int lineno = 0; 101 102 a = fopen(path, "r"); 103 if (a == NULL) { | 68 } 69 memmove((line + 1), line, (linelen + 1)); 70 line[0] = '.'; 71 } 72} 73 74static void 75chomp(char *str) --- 20 unchanged lines hidden (view full) --- 96 char line[2048]; 97 struct authuser *au; 98 FILE *a; 99 char *data; 100 int lineno = 0; 101 102 a = fopen(path, "r"); 103 if (a == NULL) { |
104 errlog(1, "can not open auth file `%s'", path); | 104 errlog(EX_NOINPUT, "can not open auth file `%s'", path); |
105 /* NOTREACHED */ 106 } 107 108 while (!feof(a)) { 109 if (fgets(line, sizeof(line), a) == NULL) 110 break; 111 lineno++; 112 113 chomp(line); 114 115 /* We hit a comment */ 116 if (*line == '#') 117 continue; 118 /* Ignore empty lines */ 119 if (*line == 0) 120 continue; 121 122 au = calloc(1, sizeof(*au)); 123 if (au == NULL) | 105 /* NOTREACHED */ 106 } 107 108 while (!feof(a)) { 109 if (fgets(line, sizeof(line), a) == NULL) 110 break; 111 lineno++; 112 113 chomp(line); 114 115 /* We hit a comment */ 116 if (*line == '#') 117 continue; 118 /* Ignore empty lines */ 119 if (*line == 0) 120 continue; 121 122 au = calloc(1, sizeof(*au)); 123 if (au == NULL) |
124 errlog(1, "calloc failed"); | 124 errlog(EX_OSERR, NULL); |
125 126 data = strdup(line); 127 au->login = strsep(&data, "|"); 128 au->host = strsep(&data, DP); 129 au->password = data; 130 131 if (au->login == NULL || 132 au->host == NULL || 133 au->password == NULL) { | 125 126 data = strdup(line); 127 au->login = strsep(&data, "|"); 128 au->host = strsep(&data, DP); 129 au->password = data; 130 131 if (au->login == NULL || 132 au->host == NULL || 133 au->password == NULL) { |
134 errlogx(1, "syntax error in authfile %s:%d", 135 path, lineno); | 134 errlogx(EX_CONFIG, "syntax error in authfile %s:%d", path, lineno); |
136 /* NOTREACHED */ 137 } 138 139 SLIST_INSERT_HEAD(&authusers, au, next); 140 } 141 142 fclose(a); 143} --- 11 unchanged lines hidden (view full) --- 155 char line[2048]; 156 int lineno = 0; 157 158 conf = fopen(config_path, "r"); 159 if (conf == NULL) { 160 /* Don't treat a non-existing config file as error */ 161 if (errno == ENOENT) 162 return; | 135 /* NOTREACHED */ 136 } 137 138 SLIST_INSERT_HEAD(&authusers, au, next); 139 } 140 141 fclose(a); 142} --- 11 unchanged lines hidden (view full) --- 154 char line[2048]; 155 int lineno = 0; 156 157 conf = fopen(config_path, "r"); 158 if (conf == NULL) { 159 /* Don't treat a non-existing config file as error */ 160 if (errno == ENOENT) 161 return; |
163 errlog(1, "can not open config `%s'", config_path); | 162 errlog(EX_NOINPUT, "can not open config `%s'", config_path); |
164 /* NOTREACHED */ 165 } 166 167 while (!feof(conf)) { 168 if (fgets(line, sizeof(line), conf) == NULL) 169 break; 170 lineno++; 171 --- 34 unchanged lines hidden (view full) --- 206 if (strrchr(data, '@')) { 207 host = strrchr(data, '@'); 208 *host = 0; 209 host++; 210 user = data; 211 } else { 212 host = data; 213 } | 163 /* NOTREACHED */ 164 } 165 166 while (!feof(conf)) { 167 if (fgets(line, sizeof(line), conf) == NULL) 168 break; 169 lineno++; 170 --- 34 unchanged lines hidden (view full) --- 205 if (strrchr(data, '@')) { 206 host = strrchr(data, '@'); 207 *host = 0; 208 host++; 209 user = data; 210 } else { 211 host = data; 212 } |
214 if (host && *host == 0) | 213 if (host && *host == 0) |
215 host = NULL; 216 if (user && *user == 0) 217 user = NULL; 218 config.masquerade_host = host; 219 config.masquerade_user = user; 220 } else if (strcmp(word, "STARTTLS") == 0 && data == NULL) 221 config.features |= STARTTLS; 222 else if (strcmp(word, "OPPORTUNISTIC_TLS") == 0 && data == NULL) --- 4 unchanged lines hidden (view full) --- 227 config.features |= DEFER; 228 else if (strcmp(word, "INSECURE") == 0 && data == NULL) 229 config.features |= INSECURE; 230 else if (strcmp(word, "FULLBOUNCE") == 0 && data == NULL) 231 config.features |= FULLBOUNCE; 232 else if (strcmp(word, "NULLCLIENT") == 0 && data == NULL) 233 config.features |= NULLCLIENT; 234 else { | 214 host = NULL; 215 if (user && *user == 0) 216 user = NULL; 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) --- 4 unchanged lines hidden (view full) --- 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; 233 else { |
235 errlogx(1, "syntax error in %s:%d", config_path, lineno); | 234 errlogx(EX_CONFIG, "syntax error in %s:%d", config_path, lineno); |
236 /* NOTREACHED */ 237 } 238 } 239 240 if ((config.features & NULLCLIENT) && config.smarthost == NULL) { | 235 /* NOTREACHED */ 236 } 237 } 238 239 if ((config.features & NULLCLIENT) && config.smarthost == NULL) { |
241 errlogx(1, "%s: NULLCLIENT requires SMARTHOST", config_path); | 240 errlogx(EX_CONFIG, "%s: NULLCLIENT requires SMARTHOST", config_path); |
242 /* NOTREACHED */ 243 } 244 245 fclose(conf); 246} | 241 /* NOTREACHED */ 242 } 243 244 fclose(conf); 245} |