⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clparse.c

📁 DHCP服务器源码
💻 C
📖 第 1 页 / 共 3 页
字号:
			interface_dereference (&dummy_interfaces, MDL);		}		interface_reference (&dummy_interfaces, ip, MDL);	}	if (pi)		status = interface_reference (pi, ip, MDL);	interface_dereference (&ip, MDL);	if (status != ISC_R_SUCCESS)		return 0;	return 1;}void make_client_state (state)	struct client_state **state;{	*state = ((struct client_state *)dmalloc (sizeof **state, MDL));	if (!*state)		log_fatal ("no memory for client state\n");	memset (*state, 0, sizeof **state);}void make_client_config (client, config)	struct client_state *client;	struct client_config *config;{	client -> config = (((struct client_config *)			     dmalloc (sizeof (struct client_config), MDL)));	if (!client -> config)		log_fatal ("no memory for client config\n");	memcpy (client -> config, config, sizeof *config);	if (!clone_group (&client -> config -> on_receipt,			  config -> on_receipt, MDL) ||	    !clone_group (&client -> config -> on_transmission,			  config -> on_transmission, MDL))		log_fatal ("no memory for client state groups.");}/* client-lease-statement :==	RBRACE client-lease-declarations LBRACE	client-lease-declarations :==		<nil> |		client-lease-declaration |		client-lease-declarations client-lease-declaration */void parse_client_lease_statement (cfile, is_static)	struct parse *cfile;	int is_static;{	struct client_lease *lease, *lp, *pl, *next;	struct interface_info *ip = (struct interface_info *)0;	int token;	const char *val;	struct client_state *client = (struct client_state *)0;	token = next_token (&val, (unsigned *)0, cfile);	if (token != LBRACE) {		parse_warn (cfile, "expecting left brace.");		skip_to_semi (cfile);		return;	}	lease = ((struct client_lease *)		 dmalloc (sizeof (struct client_lease), MDL));	if (!lease)		log_fatal ("no memory for lease.\n");	memset (lease, 0, sizeof *lease);	lease -> is_static = is_static;	if (!option_state_allocate (&lease -> options, MDL))		log_fatal ("no memory for lease options.\n");	do {		token = peek_token (&val, (unsigned *)0, cfile);		if (token == END_OF_FILE) {			parse_warn (cfile, "unterminated lease declaration.");			return;		}		if (token == RBRACE)			break;		parse_client_lease_declaration (cfile, lease, &ip, &client);	} while (1);	token = next_token (&val, (unsigned *)0, cfile);	/* If the lease declaration didn't include an interface	   declaration that we recognized, it's of no use to us. */	if (!ip) {		destroy_client_lease (lease);		return;	}	/* Make sure there's a client state structure... */	if (!ip -> client) {		make_client_state (&ip -> client);		ip -> client -> interface = ip;	}	if (!client)		client = ip -> client;	/* If this is an alias lease, it doesn't need to be sorted in. */	if (is_static == 2) {		ip -> client -> alias = lease;		return;	}	/* The new lease may supersede a lease that's not the	   active lease but is still on the lease list, so scan the	   lease list looking for a lease with the same address, and	   if we find it, toss it. */	pl = (struct client_lease *)0;	for (lp = client -> leases; lp; lp = next) {		next = lp -> next;		if (lp -> address.len == lease -> address.len &&		    !memcmp (lp -> address.iabuf, lease -> address.iabuf,			     lease -> address.len)) {			if (pl)				pl -> next = next;			else				client -> leases = next;			destroy_client_lease (lp);			break;		} else			pl = lp;	}	/* If this is a preloaded lease, just put it on the list of recorded	   leases - don't make it the active lease. */	if (is_static) {		lease -> next = client -> leases;		client -> leases = lease;		return;	}			/* The last lease in the lease file on a particular interface is	   the active lease for that interface.    Of course, we don't know	   what the last lease in the file is until we've parsed the whole	   file, so at this point, we assume that the lease we just parsed	   is the active lease for its interface.   If there's already	   an active lease for the interface, and this lease is for the same	   ip address, then we just toss the old active lease and replace	   it with this one.   If this lease is for a different address,	   then if the old active lease has expired, we dump it; if not,	   we put it on the list of leases for this interface which are	   still valid but no longer active. */	if (client -> active) {		if (client -> active -> expiry < cur_time)			destroy_client_lease (client -> active);		else if (client -> active -> address.len ==			 lease -> address.len &&			 !memcmp (client -> active -> address.iabuf,				  lease -> address.iabuf,				  lease -> address.len))			destroy_client_lease (client -> active);		else {			client -> active -> next = client -> leases;			client -> leases = client -> active;		}	}	client -> active = lease;	/* phew. */}/* client-lease-declaration :==	BOOTP |	INTERFACE string |	FIXED_ADDR ip_address |	FILENAME string |	SERVER_NAME string |	OPTION option-decl |	RENEW time-decl |	REBIND time-decl |	EXPIRE time-decl |	KEY id */void parse_client_lease_declaration (cfile, lease, ipp, clientp)	struct parse *cfile;	struct client_lease *lease;	struct interface_info **ipp;	struct client_state **clientp;{	int token;	const char *val;	char *t, *n;	struct interface_info *ip;	struct option_cache *oc;	struct client_state *client = (struct client_state *)0;	struct data_string key_id;	switch (next_token (&val, (unsigned *)0, cfile)) {	      case KEY:		token = next_token (&val, (unsigned *)0, cfile);		if (token != STRING && !is_identifier (token)) {			parse_warn (cfile, "expecting key name.");			skip_to_semi (cfile);			break;		}		if (omapi_auth_key_lookup_name (&lease -> key, val) !=		    ISC_R_SUCCESS)			parse_warn (cfile, "unknown key %s", val);		parse_semi (cfile);		break;	      case TOKEN_BOOTP:		lease -> is_bootp = 1;		break;	      case INTERFACE:		token = next_token (&val, (unsigned *)0, cfile);		if (token != STRING) {			parse_warn (cfile,				    "expecting interface name (in quotes).");			skip_to_semi (cfile);			break;		}		interface_or_dummy (ipp, val);		break;	      case NAME:		token = next_token (&val, (unsigned *)0, cfile);		ip = *ipp;		if (!ip) {			parse_warn (cfile, "state name precedes interface.");			break;		}		for (client = ip -> client; client; client = client -> next)			if (client -> name && !strcmp (client -> name, val))				break;		if (!client)			parse_warn (cfile,				    "lease specified for unknown pseudo.");		*clientp = client;		break;	      case FIXED_ADDR:		if (!parse_ip_addr (cfile, &lease -> address))			return;		break;	      case MEDIUM:		parse_string_list (cfile, &lease -> medium, 0);		return;	      case FILENAME:		parse_string (cfile, &lease -> filename, (unsigned *)0);		return;	      case SERVER_NAME:		parse_string (cfile, &lease -> server_name, (unsigned *)0);		return;	      case RENEW:		lease -> renewal = parse_date (cfile);		return;	      case REBIND:		lease -> rebind = parse_date (cfile);		return;	      case EXPIRE:		lease -> expiry = parse_date (cfile);		return;	      case OPTION:		oc = (struct option_cache *)0;		if (parse_option_decl (&oc, cfile)) {			save_option (oc -> option -> universe,				     lease -> options, oc);			option_cache_dereference (&oc, MDL);		}		return;	      default:		parse_warn (cfile, "expecting lease declaration.");		skip_to_semi (cfile);		break;	}	token = next_token (&val, (unsigned *)0, cfile);	if (token != SEMI) {		parse_warn (cfile, "expecting semicolon.");		skip_to_semi (cfile);	}}void parse_string_list (cfile, lp, multiple)	struct parse *cfile;	struct string_list **lp;	int multiple;{	int token;	const char *val;	struct string_list *cur, *tmp;	/* Find the last medium in the media list. */	if (*lp) {		for (cur = *lp; cur -> next; cur = cur -> next)			;	} else {		cur = (struct string_list *)0;	}	do {		token = next_token (&val, (unsigned *)0, cfile);		if (token != STRING) {			parse_warn (cfile, "Expecting media options.");			skip_to_semi (cfile);			return;		}		tmp = ((struct string_list *)		       dmalloc (strlen (val) + sizeof (struct string_list),				MDL));		if (!tmp)			log_fatal ("no memory for string list entry.");		strcpy (tmp -> string, val);		tmp -> next = (struct string_list *)0;		/* Store this medium at the end of the media list. */		if (cur)			cur -> next = tmp;		else			*lp = tmp;		cur = tmp;		token = next_token (&val, (unsigned *)0, cfile);	} while (multiple && token == COMMA);	if (token != SEMI) {		parse_warn (cfile, "expecting semicolon.");		skip_to_semi (cfile);	}}void parse_reject_statement (cfile, config)	struct parse *cfile;	struct client_config *config;{	int token;	const char *val;	struct iaddr addr;	struct iaddrlist *list;	do {		if (!parse_ip_addr (cfile, &addr)) {			parse_warn (cfile, "expecting IP address.");			skip_to_semi (cfile);			return;		}		list = (struct iaddrlist *)dmalloc (sizeof (struct iaddrlist),						    MDL);		if (!list)			log_fatal ("no memory for reject list!");		list -> addr = addr;		list -> next = config -> reject_list;		config -> reject_list = list;		token = next_token (&val, (unsigned *)0, cfile);	} while (token == COMMA);	if (token != SEMI) {		parse_warn (cfile, "expecting semicolon.");		skip_to_semi (cfile);	}}	/* allow-deny-keyword :== BOOTP   			| BOOTING			| DYNAMIC_BOOTP			| UNKNOWN_CLIENTS */int parse_allow_deny (oc, cfile, flag)	struct option_cache **oc;	struct parse *cfile;	int flag;{	enum dhcp_token token;	const char *val;	unsigned char rf = flag;	struct expression *data = (struct expression *)0;	int status;	parse_warn (cfile, "allow/deny/ignore not permitted here.");	skip_to_semi (cfile);	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -