config_file.c (268883) | config_file.c (276605) |
---|---|
1/* 2 * util/config_file.c - reads and stores the config file for unbound. 3 * 4 * Copyright (c) 2007, NLnet Labs. All rights reserved. 5 * 6 * This software is open source. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 197 unchanged lines hidden (view full) --- 206 if(!(cfg->control_key_file = strdup(RUN_DIR"/unbound_control.key"))) 207 goto error_exit; 208 if(!(cfg->control_cert_file = strdup(RUN_DIR"/unbound_control.pem"))) 209 goto error_exit; 210 211 if(!(cfg->module_conf = strdup("validator iterator"))) goto error_exit; 212 if(!(cfg->val_nsec3_key_iterations = 213 strdup("1024 150 2048 500 4096 2500"))) goto error_exit; | 1/* 2 * util/config_file.c - reads and stores the config file for unbound. 3 * 4 * Copyright (c) 2007, NLnet Labs. All rights reserved. 5 * 6 * This software is open source. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 197 unchanged lines hidden (view full) --- 206 if(!(cfg->control_key_file = strdup(RUN_DIR"/unbound_control.key"))) 207 goto error_exit; 208 if(!(cfg->control_cert_file = strdup(RUN_DIR"/unbound_control.pem"))) 209 goto error_exit; 210 211 if(!(cfg->module_conf = strdup("validator iterator"))) goto error_exit; 212 if(!(cfg->val_nsec3_key_iterations = 213 strdup("1024 150 2048 500 4096 2500"))) goto error_exit; |
214#if defined(DNSTAP_SOCKET_PATH) 215 if(!(cfg->dnstap_socket_path = strdup(DNSTAP_SOCKET_PATH))) 216 goto error_exit; 217#endif |
|
214 return cfg; 215error_exit: 216 config_delete(cfg); 217 return NULL; 218} 219 220struct config_file* config_create_forlib(void) 221{ --- 564 unchanged lines hidden (view full) --- 786 } 787 create_cfg_parser(cfg, fname, chroot); 788 ub_c_in = in; 789 ub_c_parse(); 790 fclose(in); 791 792 if(cfg_parser->errors != 0) { 793 fprintf(stderr, "read %s failed: %d errors in configuration file\n", | 218 return cfg; 219error_exit: 220 config_delete(cfg); 221 return NULL; 222} 223 224struct config_file* config_create_forlib(void) 225{ --- 564 unchanged lines hidden (view full) --- 790 } 791 create_cfg_parser(cfg, fname, chroot); 792 ub_c_in = in; 793 ub_c_parse(); 794 fclose(in); 795 796 if(cfg_parser->errors != 0) { 797 fprintf(stderr, "read %s failed: %d errors in configuration file\n", |
794 cfg_parser->filename, cfg_parser->errors); | 798 fname, cfg_parser->errors); |
795 errno=EINVAL; 796 return 0; 797 } 798 return 1; 799} 800 801void 802config_delstrlist(struct config_strlist* p) --- 80 unchanged lines hidden (view full) --- 883 config_deldblstrlist(cfg->local_zones); 884 config_delstrlist(cfg->local_zones_nodefault); 885 config_delstrlist(cfg->local_data); 886 config_delstrlist(cfg->control_ifs); 887 free(cfg->server_key_file); 888 free(cfg->server_cert_file); 889 free(cfg->control_key_file); 890 free(cfg->control_cert_file); | 799 errno=EINVAL; 800 return 0; 801 } 802 return 1; 803} 804 805void 806config_delstrlist(struct config_strlist* p) --- 80 unchanged lines hidden (view full) --- 887 config_deldblstrlist(cfg->local_zones); 888 config_delstrlist(cfg->local_zones_nodefault); 889 config_delstrlist(cfg->local_data); 890 config_delstrlist(cfg->control_ifs); 891 free(cfg->server_key_file); 892 free(cfg->server_cert_file); 893 free(cfg->control_key_file); 894 free(cfg->control_cert_file); |
895 free(cfg->dnstap_socket_path); 896 free(cfg->dnstap_identity); 897 free(cfg->dnstap_version); |
|
891 free(cfg); 892} 893 894static void 895init_outgoing_availports(int* a, int num) 896{ 897 /* generated with make iana_update */ 898 const int iana_assigned[] = { --- 194 unchanged lines hidden (view full) --- 1093int 1094cfg_count_numbers(const char* s) 1095{ 1096 /* format ::= (sp num)+ sp */ 1097 /* num ::= [-](0-9)+ */ 1098 /* sp ::= (space|tab)* */ 1099 int num = 0; 1100 while(*s) { | 898 free(cfg); 899} 900 901static void 902init_outgoing_availports(int* a, int num) 903{ 904 /* generated with make iana_update */ 905 const int iana_assigned[] = { --- 194 unchanged lines hidden (view full) --- 1100int 1101cfg_count_numbers(const char* s) 1102{ 1103 /* format ::= (sp num)+ sp */ 1104 /* num ::= [-](0-9)+ */ 1105 /* sp ::= (space|tab)* */ 1106 int num = 0; 1107 while(*s) { |
1101 while(*s && isspace((int)*s)) | 1108 while(*s && isspace((unsigned char)*s)) |
1102 s++; 1103 if(!*s) /* end of string */ 1104 break; 1105 if(*s == '-') 1106 s++; 1107 if(!*s) /* only - not allowed */ 1108 return 0; | 1109 s++; 1110 if(!*s) /* end of string */ 1111 break; 1112 if(*s == '-') 1113 s++; 1114 if(!*s) /* only - not allowed */ 1115 return 0; |
1109 if(!isdigit((int)*s)) /* bad character */ | 1116 if(!isdigit((unsigned char)*s)) /* bad character */ |
1110 return 0; | 1117 return 0; |
1111 while(*s && isdigit((int)*s)) | 1118 while(*s && isdigit((unsigned char)*s)) |
1112 s++; 1113 num++; 1114 } 1115 return num; 1116} 1117 1118/** all digit number */ 1119static int isalldigit(const char* str, size_t l) 1120{ 1121 size_t i; 1122 for(i=0; i<l; i++) | 1119 s++; 1120 num++; 1121 } 1122 return num; 1123} 1124 1125/** all digit number */ 1126static int isalldigit(const char* str, size_t l) 1127{ 1128 size_t i; 1129 for(i=0; i<l; i++) |
1123 if(!isdigit(str[i])) | 1130 if(!isdigit((unsigned char)str[i])) |
1124 return 0; 1125 return 1; 1126} 1127 1128int 1129cfg_parse_memsize(const char* str, size_t* res) 1130{ 1131 size_t len; --- 9 unchanged lines hidden (view full) --- 1141 /* check appended num */ 1142 while(len>0 && str[len-1]==' ') 1143 len--; 1144 if(len > 1 && str[len-1] == 'b') 1145 len--; 1146 else if(len > 1 && str[len-1] == 'B') 1147 len--; 1148 | 1131 return 0; 1132 return 1; 1133} 1134 1135int 1136cfg_parse_memsize(const char* str, size_t* res) 1137{ 1138 size_t len; --- 9 unchanged lines hidden (view full) --- 1148 /* check appended num */ 1149 while(len>0 && str[len-1]==' ') 1150 len--; 1151 if(len > 1 && str[len-1] == 'b') 1152 len--; 1153 else if(len > 1 && str[len-1] == 'B') 1154 len--; 1155 |
1149 if(len > 1 && tolower(str[len-1]) == 'g') | 1156 if(len > 1 && tolower((unsigned char)str[len-1]) == 'g') |
1150 mult = 1024*1024*1024; | 1157 mult = 1024*1024*1024; |
1151 else if(len > 1 && tolower(str[len-1]) == 'm') | 1158 else if(len > 1 && tolower((unsigned char)str[len-1]) == 'm') |
1152 mult = 1024*1024; | 1159 mult = 1024*1024; |
1153 else if(len > 1 && tolower(str[len-1]) == 'k') | 1160 else if(len > 1 && tolower((unsigned char)str[len-1]) == 'k') |
1154 mult = 1024; | 1161 mult = 1024; |
1155 else if(len > 0 && isdigit(str[len-1])) | 1162 else if(len > 0 && isdigit((unsigned char)str[len-1])) |
1156 mult = 1; 1157 else { 1158 log_err("unknown size specifier: '%s'", str); 1159 return 0; 1160 } 1161 while(len>1 && str[len-2]==' ') 1162 len--; 1163 --- 146 unchanged lines hidden (view full) --- 1310int 1311cfg_parse_local_zone(struct config_file* cfg, const char* val) 1312{ 1313 const char *type, *name_end, *name; 1314 char buf[256]; 1315 1316 /* parse it as: [zone_name] [between stuff] [zone_type] */ 1317 name = val; | 1163 mult = 1; 1164 else { 1165 log_err("unknown size specifier: '%s'", str); 1166 return 0; 1167 } 1168 while(len>1 && str[len-2]==' ') 1169 len--; 1170 --- 146 unchanged lines hidden (view full) --- 1317int 1318cfg_parse_local_zone(struct config_file* cfg, const char* val) 1319{ 1320 const char *type, *name_end, *name; 1321 char buf[256]; 1322 1323 /* parse it as: [zone_name] [between stuff] [zone_type] */ 1324 name = val; |
1318 while(*name && isspace(*name)) | 1325 while(*name && isspace((unsigned char)*name)) |
1319 name++; 1320 if(!*name) { 1321 log_err("syntax error: too short: %s", val); 1322 return 0; 1323 } 1324 name_end = next_space_pos(name); 1325 if(!name_end || !*name_end) { 1326 log_err("syntax error: expected zone type: %s", val); 1327 return 0; 1328 } 1329 if (name_end - name > 255) { 1330 log_err("syntax error: bad zone name: %s", val); 1331 return 0; 1332 } 1333 (void)strlcpy(buf, name, sizeof(buf)); 1334 buf[name_end-name] = '\0'; 1335 1336 type = last_space_pos(name_end); | 1326 name++; 1327 if(!*name) { 1328 log_err("syntax error: too short: %s", val); 1329 return 0; 1330 } 1331 name_end = next_space_pos(name); 1332 if(!name_end || !*name_end) { 1333 log_err("syntax error: expected zone type: %s", val); 1334 return 0; 1335 } 1336 if (name_end - name > 255) { 1337 log_err("syntax error: bad zone name: %s", val); 1338 return 0; 1339 } 1340 (void)strlcpy(buf, name, sizeof(buf)); 1341 buf[name_end-name] = '\0'; 1342 1343 type = last_space_pos(name_end); |
1337 while(type && *type && isspace(*type)) | 1344 while(type && *type && isspace((unsigned char)*type)) |
1338 type++; 1339 if(!type || !*type) { 1340 log_err("syntax error: expected zone type: %s", val); 1341 return 0; 1342 } 1343 1344 if(strcmp(type, "nodefault")==0) { 1345 return cfg_strlist_insert(&cfg->local_zones_nodefault, --- 10 unchanged lines hidden (view full) --- 1356 char* name; 1357 char* result; 1358 char buf[1024]; 1359 struct sockaddr_storage addr; 1360 socklen_t addrlen; 1361 1362 /* parse it as: [IP] [between stuff] [name] */ 1363 ip = str; | 1345 type++; 1346 if(!type || !*type) { 1347 log_err("syntax error: expected zone type: %s", val); 1348 return 0; 1349 } 1350 1351 if(strcmp(type, "nodefault")==0) { 1352 return cfg_strlist_insert(&cfg->local_zones_nodefault, --- 10 unchanged lines hidden (view full) --- 1363 char* name; 1364 char* result; 1365 char buf[1024]; 1366 struct sockaddr_storage addr; 1367 socklen_t addrlen; 1368 1369 /* parse it as: [IP] [between stuff] [name] */ 1370 ip = str; |
1364 while(*ip && isspace(*ip)) | 1371 while(*ip && isspace((unsigned char)*ip)) |
1365 ip++; 1366 if(!*ip) { 1367 log_err("syntax error: too short: %s", str); 1368 return NULL; 1369 } 1370 ip_end = next_space_pos(ip); 1371 if(!ip_end || !*ip_end) { 1372 log_err("syntax error: expected name: %s", str); --- 38 unchanged lines hidden (view full) --- 1411 memmove(ad, &((struct sockaddr_in*)&addr)->sin_addr, 1412 sizeof(ad)); 1413 snprintf(buf, sizeof(buf), "%u.%u.%u.%u.in-addr.arpa. ", 1414 (unsigned)ad[3], (unsigned)ad[2], 1415 (unsigned)ad[1], (unsigned)ad[0]); 1416 } 1417 1418 /* printed the reverse address, now the between goop and name on end */ | 1372 ip++; 1373 if(!*ip) { 1374 log_err("syntax error: too short: %s", str); 1375 return NULL; 1376 } 1377 ip_end = next_space_pos(ip); 1378 if(!ip_end || !*ip_end) { 1379 log_err("syntax error: expected name: %s", str); --- 38 unchanged lines hidden (view full) --- 1418 memmove(ad, &((struct sockaddr_in*)&addr)->sin_addr, 1419 sizeof(ad)); 1420 snprintf(buf, sizeof(buf), "%u.%u.%u.%u.in-addr.arpa. ", 1421 (unsigned)ad[3], (unsigned)ad[2], 1422 (unsigned)ad[1], (unsigned)ad[0]); 1423 } 1424 1425 /* printed the reverse address, now the between goop and name on end */ |
1419 while(*ip_end && isspace(*ip_end)) | 1426 while(*ip_end && isspace((unsigned char)*ip_end)) |
1420 ip_end++; 1421 if(name>ip_end) { 1422 snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), "%.*s", 1423 (int)(name-ip_end), ip_end); 1424 } 1425 snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), " PTR %s", name); 1426 1427 result = strdup(buf); --- 137 unchanged lines hidden --- | 1427 ip_end++; 1428 if(name>ip_end) { 1429 snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), "%.*s", 1430 (int)(name-ip_end), ip_end); 1431 } 1432 snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), " PTR %s", name); 1433 1434 result = strdup(buf); --- 137 unchanged lines hidden --- |