Deleted Added
sdiff udiff text old ( 268883 ) new ( 276605 )
full compact
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 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",
794 cfg_parser->filename, 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);
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) {
1101 while(*s && isspace((int)*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 if(!isdigit((int)*s)) /* bad character */
1110 return 0;
1111 while(*s && isdigit((int)*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++)
1123 if(!isdigit(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
1149 if(len > 1 && tolower(str[len-1]) == 'g')
1150 mult = 1024*1024*1024;
1151 else if(len > 1 && tolower(str[len-1]) == 'm')
1152 mult = 1024*1024;
1153 else if(len > 1 && tolower(str[len-1]) == 'k')
1154 mult = 1024;
1155 else if(len > 0 && isdigit(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;
1318 while(*name && isspace(*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);
1337 while(type && *type && isspace(*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;
1364 while(*ip && isspace(*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 */
1419 while(*ip_end && isspace(*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 ---