main() { time_t start_time; time_t end_time; char *p; int i; while(fgets(input,512,stdin)) { p = strchr(input,'\n'); if(p) {*p++ = '\r'; *p++ = '\n'; *p++ = '\0'; } if(!strcasecmp(input,"bench")) { show = 0; TMRESET; TMYES; for(i=0;i<100000;i++) { strcpy(parse_input,test_input); parse(parse_input,test_input+sizeof(test_input)); } TMNO; TMPRINT; TMRESET; TMYES; for(i=0;i<100000;i++) { strcpy(parse_input,test_input); new_parse(parse_input,test_input+sizeof(test_input)); } TMNO; TMPRINT; } else { show = 1; printf("old parse\n"); strcpy(parse_input,input); parse(parse_input,input+510); printf("new parse\n"); strcpy(parse_input,input); new_parse(parse_input,input+510); } } }
void read_client_leases () { int file; struct parse *cfile; const char *val; int token; /* Open the lease file. If we can't open it, just return - we can safely trust the server to remember our state. */ if ((file = open (path_dhclient_db, O_RDONLY)) < 0) return; cfile = (struct parse *)0; new_parse (&cfile, file, (char *)0, 0, path_dhclient_db, 0); do { token = next_token (&val, (unsigned *)0, cfile); if (token == END_OF_FILE) break; if (token != LEASE) { log_error ("Corrupt lease file - possible data loss!"); skip_to_semi (cfile); break; } else parse_client_lease_statement (cfile, 0); } while (1); end_parse (&cfile); }
int read_client_conf_file (const char *name, struct interface_info *ip, struct client_config *client) { int file; struct parse *cfile; const char *val; int token; isc_result_t status; if ((file = open (name, O_RDONLY)) < 0) return uerr2isc (errno); cfile = (struct parse *)0; new_parse (&cfile, file, (char *)0, 0, path_dhclient_conf, 0); do { token = peek_token (&val, (unsigned *)0, cfile); if (token == END_OF_FILE) break; parse_client_statement (cfile, ip, client); } while (1); token = next_token (&val, (unsigned *)0, cfile); status = (cfile -> warnings_occurred ? ISC_R_BADPARSE : ISC_R_SUCCESS); end_parse (&cfile); return status; }
/* * lease-file :== client-lease-statements EOF * client-lease-statements :== <nil> * | client-lease-statements LEASE client-lease-statement */ void read_client_leases(void) { FILE *cfile; char *val; int token; new_parse(path_dhclient_db); /* Open the lease file. If we can't open it, just return - we can safely trust the server to remember our state. */ if ((cfile = fopen(path_dhclient_db, "r")) == NULL) return; do { token = next_token(&val, cfile); if (token == EOF) break; if (token != TOK_LEASE) { warning("Corrupt lease file - possible data loss!"); skip_to_semi(cfile); break; } else parse_client_lease_statement(cfile, 0); } while (1); fclose(cfile); }
/* * client-conf-file :== client-declarations EOF * client-declarations :== <nil> * | client-declaration * | client-declarations client-declaration */ int read_client_conf(void) { FILE *cfile; int token; new_parse(path_dhclient_conf); /* Set some defaults... */ config->link_timeout = 30; config->timeout = 60; config->select_interval = 0; config->reboot_timeout = 10; config->retry_interval = 300; config->backoff_cutoff = 15; config->initial_interval = 3; config->bootp_policy = ACCEPT; config->script_name = _PATH_DHCLIENT_SCRIPT; config->requested_options [config->requested_option_count++] = DHO_SUBNET_MASK; config->requested_options [config->requested_option_count++] = DHO_BROADCAST_ADDRESS; config->requested_options [config->requested_option_count++] = DHO_TIME_OFFSET; config->requested_options [config->requested_option_count++] = DHO_CLASSLESS_ROUTES; config->requested_options [config->requested_option_count++] = DHO_ROUTERS; config->requested_options [config->requested_option_count++] = DHO_DOMAIN_NAME; config->requested_options [config->requested_option_count++] = DHO_DOMAIN_NAME_SERVERS; config->requested_options [config->requested_option_count++] = DHO_HOST_NAME; if ((cfile = fopen(path_dhclient_conf, "r")) != NULL) { do { token = peek_token(NULL, cfile); if (token == EOF) break; parse_client_statement(cfile); } while (1); token = next_token(NULL, cfile); /* Clear the peek buffer */ fclose(cfile); } return (!warnings_occurred); }
void read_client_leases () { int file; struct parse *cfile; const char *val; int token; /* Open the lease file. If we can't open it, just return - we can safely trust the server to remember our state. */ if ((file = open (path_dhclient_db, O_RDONLY)) < 0) return; cfile = (struct parse *)0; /* new_parse() may fail if the file is of zero length. */ if (new_parse(&cfile, file, (char *)0, 0, path_dhclient_db, 0) != ISC_R_SUCCESS) return; do { token = next_token (&val, (unsigned *)0, cfile); if (token == END_OF_FILE) break; switch (token) { case DEFAULT_DUID: parse_client_default_duid(cfile); break; case LEASE: parse_client_lease_statement(cfile, 0); break; case LEASE6: parse_client6_lease_statement(cfile); break; default: log_error ("Corrupt lease file - possible data loss!"); skip_to_semi (cfile); break; } } while (1); end_parse (&cfile); }
void read_leases () { FILE *cfile; char *val; int token; new_parse (path_dhcpd_db); /* Open the lease file. If we can't open it, fail. The reason for this is that although on initial startup, the absence of a lease file is perfectly benign, if dhcpd has been running and this file is absent, it means that dhcpd tried and failed to rewrite the lease database. If we proceed and the problem which caused the rewrite to fail has been fixed, but no human has corrected the database problem, then we are left thinking that no leases have been assigned to anybody, which could create severe network chaos. */ if ((cfile = fopen (path_dhcpd_db, "r")) == NULL) { warn ("Can't open lease database %s: %m -- %s", path_dhcpd_db, "check for failed database rewrite attempt!"); warn ("Please read the dhcpd.leases manual page if you."); error ("don't know what to do about this."); } do { token = next_token (&val, cfile); if (token == EOF) break; if (token != LEASE) { warn ("Corrupt lease file - possible data loss!"); skip_to_semi (cfile); } else { struct lease *lease; lease = parse_lease_declaration (cfile); if (lease) enter_lease (lease); else parse_warn ("possibly corrupt lease file"); } } while (1); }
int readconf () { FILE *cfile; char *val; int token; int declaration = 0; new_parse (path_dhcpd_conf); /* Set up the initial dhcp option universe. */ initialize_universes (); /* Set up the global defaults... */ root_group.default_lease_time = 43200; /* 12 hours. */ root_group.max_lease_time = 86400; /* 24 hours. */ root_group.bootp_lease_cutoff = MAX_TIME; root_group.boot_unknown_clients = 1; root_group.allow_bootp = 1; root_group.allow_booting = 1; root_group.authoritative = 1; if ((cfile = fopen (path_dhcpd_conf, "r")) == NULL) { error ("Can't open %s: %m", path_dhcpd_conf); } do { token = peek_token (&val, cfile); if (token == EOF) break; declaration = parse_statement (cfile, &root_group, ROOT_GROUP, (struct host_decl *)0, declaration); } while (1); token = next_token (&val, cfile); /* Clear the peek buffer */ return !warnings_occurred; }
isc_result_t dhcp_group_set_value (omapi_object_t *h, omapi_object_t *id, omapi_data_string_t *name, omapi_typed_data_t *value) { struct group_object *group; isc_result_t status; int foo; if (h -> type != dhcp_type_group) return ISC_R_INVALIDARG; group = (struct group_object *)h; /* XXX For now, we can only set these values on new group objects. XXX Soon, we need to be able to update group objects. */ if (!omapi_ds_strcmp (name, "name")) { if (group -> name) return ISC_R_EXISTS; if (value -> type == omapi_datatype_data || value -> type == omapi_datatype_string) { group -> name = dmalloc (value -> u.buffer.len + 1, MDL); if (!group -> name) return ISC_R_NOMEMORY; memcpy (group -> name, value -> u.buffer.value, value -> u.buffer.len); group -> name [value -> u.buffer.len] = 0; } else return ISC_R_INVALIDARG; return ISC_R_SUCCESS; } if (!omapi_ds_strcmp (name, "statements")) { if (group -> group && group -> group -> statements) return ISC_R_EXISTS; if (!group -> group) { if (!clone_group (&group -> group, root_group, MDL)) return ISC_R_NOMEMORY; } if (value -> type == omapi_datatype_data || value -> type == omapi_datatype_string) { struct parse *parse; int lose = 0; parse = (struct parse *)0; status = new_parse (&parse, -1, (char *)value -> u.buffer.value, value -> u.buffer.len, "network client", 0); if (status != ISC_R_SUCCESS) return status; if (!(parse_executable_statements (&group -> group -> statements, parse, &lose, context_any))) { end_parse (&parse); return ISC_R_BADPARSE; } end_parse (&parse); return ISC_R_SUCCESS; } else return ISC_R_INVALIDARG; } /* Try to find some inner object that can take the value. */ if (h -> inner && h -> inner -> type -> set_value) { status = ((*(h -> inner -> type -> set_value)) (h -> inner, id, name, value)); if (status == ISC_R_SUCCESS || status == ISC_R_UNCHANGED) return status; } return ISC_R_NOTFOUND; }
isc_result_t read_client_conf () { struct client_config *config; struct client_state *state; struct interface_info *ip; isc_result_t status; /* Set up the initial dhcp option universe. */ initialize_common_option_spaces (); /* Initialize the top level client configuration. */ memset (&top_level_config, 0, sizeof top_level_config); /* Set some defaults... */ top_level_config.timeout = 60; top_level_config.select_interval = 0; top_level_config.reboot_timeout = 10; top_level_config.retry_interval = 300; top_level_config.backoff_cutoff = 15; top_level_config.initial_interval = 3; top_level_config.bootp_policy = P_ACCEPT; top_level_config.script_name = path_dhclient_script; top_level_config.requested_options = default_requested_options; top_level_config.omapi_port = -1; top_level_config.do_forward_update = 1; group_allocate (&top_level_config.on_receipt, MDL); if (!top_level_config.on_receipt) log_fatal ("no memory for top-level on_receipt group"); group_allocate (&top_level_config.on_transmission, MDL); if (!top_level_config.on_transmission) log_fatal ("no memory for top-level on_transmission group"); status = read_client_conf_file (path_dhclient_conf, (struct interface_info *)0, &top_level_config); if (status != ISC_R_SUCCESS) { ; #ifdef LATER /* Set up the standard name service updater routine. */ parse = (struct parse *)0; status = new_parse (&parse, -1, default_client_config, (sizeof default_client_config) - 1, "default client configuration", 0); if (status != ISC_R_SUCCESS) log_fatal ("can't begin default client config!"); do { token = peek_token (&val, (unsigned *)0, cfile); if (token == END_OF_FILE) break; parse_client_statement (cfile, (struct interface_info *)0, &top_level_config); } while (1); end_parse (&parse); #endif } /* Set up state and config structures for clients that don't have per-interface configuration statements. */ config = (struct client_config *)0; for (ip = interfaces; ip; ip = ip -> next) { if (!ip -> client) { ip -> client = (struct client_state *) dmalloc (sizeof (struct client_state), MDL); if (!ip -> client) log_fatal ("no memory for client state."); memset (ip -> client, 0, sizeof *(ip -> client)); ip -> client -> interface = ip; } if (!ip -> client -> config) { if (!config) { config = (struct client_config *) dmalloc (sizeof (struct client_config), MDL); if (!config) log_fatal ("no memory for client config."); memcpy (config, &top_level_config, sizeof top_level_config); } ip -> client -> config = config; } } return status; }
isc_result_t read_client_conf () { struct client_config *config; struct interface_info *ip; isc_result_t status; unsigned code; /* Initialize the default request list. */ memset(default_requested_options, 0, sizeof(default_requested_options)); /* 1 */ code = DHO_SUBNET_MASK; option_code_hash_lookup(&default_requested_options[0], dhcp_universe.code_hash, &code, 0, MDL); /* 2 */ code = DHO_BROADCAST_ADDRESS; option_code_hash_lookup(&default_requested_options[1], dhcp_universe.code_hash, &code, 0, MDL); /* 3 */ code = DHO_TIME_OFFSET; option_code_hash_lookup(&default_requested_options[2], dhcp_universe.code_hash, &code, 0, MDL); /* 4 */ code = DHO_ROUTERS; option_code_hash_lookup(&default_requested_options[3], dhcp_universe.code_hash, &code, 0, MDL); /* 5 */ code = DHO_DOMAIN_NAME; option_code_hash_lookup(&default_requested_options[4], dhcp_universe.code_hash, &code, 0, MDL); /* 6 */ code = DHO_DOMAIN_NAME_SERVERS; option_code_hash_lookup(&default_requested_options[5], dhcp_universe.code_hash, &code, 0, MDL); /* 7 */ code = DHO_HOST_NAME; option_code_hash_lookup(&default_requested_options[6], dhcp_universe.code_hash, &code, 0, MDL); /* 8 */ code = D6O_NAME_SERVERS; option_code_hash_lookup(&default_requested_options[7], dhcpv6_universe.code_hash, &code, 0, MDL); /* 9 */ code = D6O_DOMAIN_SEARCH; option_code_hash_lookup(&default_requested_options[8], dhcpv6_universe.code_hash, &code, 0, MDL); for (code = 0 ; code < NUM_DEFAULT_REQUESTED_OPTS ; code++) { if (default_requested_options[code] == NULL) log_fatal("Unable to find option definition for " "index %u during default parameter request " "assembly.", code); } /* Initialize the top level client configuration. */ memset (&top_level_config, 0, sizeof top_level_config); /* Set some defaults... */ top_level_config.timeout = 60; top_level_config.select_interval = 0; top_level_config.reboot_timeout = 10; top_level_config.retry_interval = 300; top_level_config.backoff_cutoff = 15; top_level_config.initial_interval = 3; top_level_config.bootp_policy = P_ACCEPT; top_level_config.script_name = path_dhclient_script; top_level_config.requested_options = default_requested_options; top_level_config.omapi_port = -1; #if defined (NSUPDATE) top_level_config.do_forward_update = 1; #endif /* Requested lease time, used by DHCPv6 (DHCPv4 uses the option cache) */ top_level_config.requested_lease = 7200; group_allocate (&top_level_config.on_receipt, MDL); if (!top_level_config.on_receipt) log_fatal ("no memory for top-level on_receipt group"); group_allocate (&top_level_config.on_transmission, MDL); if (!top_level_config.on_transmission) log_fatal ("no memory for top-level on_transmission group"); status = read_client_conf_file (path_dhclient_conf, (struct interface_info *)0, &top_level_config); if (status != ISC_R_SUCCESS) { ; #ifdef LATER /* Set up the standard name service updater routine. */ parse = (struct parse *)0; status = new_parse (&parse, -1, default_client_config, (sizeof default_client_config) - 1, "default client configuration", 0); if (status != ISC_R_SUCCESS) log_fatal ("can't begin default client config!"); do { token = peek_token (&val, (unsigned *)0, cfile); if (token == END_OF_FILE) break; parse_client_statement (cfile, (struct interface_info *)0, &top_level_config); } while (1); end_parse (&parse); #endif } /* Set up state and config structures for clients that don't have per-interface configuration statements. */ config = (struct client_config *)0; for (ip = interfaces; ip; ip = ip -> next) { if (!ip -> client) { ip -> client = (struct client_state *) dmalloc (sizeof (struct client_state), MDL); if (!ip -> client) log_fatal ("no memory for client state."); memset (ip -> client, 0, sizeof *(ip -> client)); ip -> client -> interface = ip; } if (!ip -> client -> config) { if (!config) { config = (struct client_config *) dmalloc (sizeof (struct client_config), MDL); if (!config) log_fatal ("no memory for client config."); memcpy (config, &top_level_config, sizeof top_level_config); } ip -> client -> config = config; } } return status; }
/* * client-conf-file :== client-declarations EOF * client-declarations :== <nil> * | client-declaration * | client-declarations client-declaration */ int read_client_conf(void) { FILE *cfile; char *val; int token; struct client_config *config; new_parse(path_dhclient_conf); /* Set up the initial dhcp option universe. */ initialize_universes(); /* Initialize the top level client configuration. */ memset(&top_level_config, 0, sizeof(top_level_config)); /* Set some defaults... */ top_level_config.timeout = 60; top_level_config.select_interval = 0; top_level_config.reboot_timeout = 10; top_level_config.retry_interval = 300; top_level_config.backoff_cutoff = 15; top_level_config.initial_interval = 3; top_level_config.bootp_policy = ACCEPT; top_level_config.script_name = client_script_name; top_level_config.requested_options [top_level_config.requested_option_count++] = DHO_SUBNET_MASK; top_level_config.requested_options [top_level_config.requested_option_count++] = DHO_BROADCAST_ADDRESS; top_level_config.requested_options [top_level_config.requested_option_count++] = DHO_TIME_OFFSET; top_level_config.requested_options [top_level_config.requested_option_count++] = DHO_CLASSLESS_ROUTES; top_level_config.requested_options [top_level_config.requested_option_count++] = DHO_ROUTERS; top_level_config.requested_options [top_level_config.requested_option_count++] = DHO_DOMAIN_NAME; top_level_config.requested_options [top_level_config.requested_option_count++] = DHO_DOMAIN_NAME_SERVERS; top_level_config.requested_options [top_level_config.requested_option_count++] = DHO_HOST_NAME; top_level_config.requested_options [top_level_config.requested_option_count++] = DHO_DOMAIN_SEARCH; if ((cfile = fopen(path_dhclient_conf, "r")) != NULL) { do { token = peek_token(&val, cfile); if (token == EOF) break; parse_client_statement(cfile, NULL, &top_level_config); } while (1); token = next_token(&val, cfile); /* Clear the peek buffer */ fclose(cfile); } /* * Set up state and config structures for clients that don't * have per-interface configuration declarations. */ config = NULL; if (!ifi->client) { ifi->client = malloc(sizeof(struct client_state)); if (!ifi->client) error("no memory for client state."); memset(ifi->client, 0, sizeof(*(ifi->client))); } if (!ifi->client->config) { if (!config) { config = malloc(sizeof(struct client_config)); if (!config) error("no memory for client config."); memcpy(config, &top_level_config, sizeof(top_level_config)); } ifi->client->config = config; } return (!warnings_occurred); }