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

📄 omapi.c

📁 DHCP服务器源码
💻 C
📖 第 1 页 / 共 5 页
字号:
#endif	return ISC_R_SUCCESS;}isc_result_t dhcp_lease_signal_handler (omapi_object_t *h,					const char *name, va_list ap){	struct lease *lease;	isc_result_t status;	int updatep = 0;	if (h -> type != dhcp_type_lease)		return ISC_R_INVALIDARG;	lease = (struct lease *)h;	if (!strcmp (name, "updated"))		return ISC_R_SUCCESS;	/* Try to find some inner object that can take the value. */	if (h -> inner && h -> inner -> type -> signal_handler) {		status = ((*(h -> inner -> type -> signal_handler))			  (h -> inner, name, ap));		if (status == ISC_R_SUCCESS)			return status;	}	return ISC_R_NOTFOUND;}isc_result_t dhcp_lease_stuff_values (omapi_object_t *c,				      omapi_object_t *id,				      omapi_object_t *h){	struct lease *lease;	isc_result_t status;	if (h -> type != dhcp_type_lease)		return ISC_R_INVALIDARG;	lease = (struct lease *)h;	/* Write out all the values. */	status = omapi_connection_put_name (c, "state");	if (status != ISC_R_SUCCESS)		return status;	status = omapi_connection_put_uint32 (c, sizeof (int));	if (status != ISC_R_SUCCESS)		return status;	status = omapi_connection_put_uint32 (c, lease -> binding_state);	if (status != ISC_R_SUCCESS)		return status;	status = omapi_connection_put_name (c, "ip-address");	if (status != ISC_R_SUCCESS)		return status;	status = omapi_connection_put_uint32 (c, lease -> ip_addr.len);	if (status != ISC_R_SUCCESS)		return status;	status = omapi_connection_copyin (c, lease -> ip_addr.iabuf,					  lease -> ip_addr.len);	if (status != ISC_R_SUCCESS)		return status;	if (lease -> uid_len) {		status = omapi_connection_put_name (c,						    "dhcp-client-identifier");		if (status != ISC_R_SUCCESS)			return status;		status = omapi_connection_put_uint32 (c, lease -> uid_len);		if (status != ISC_R_SUCCESS)			return status;		if (lease -> uid_len) {			status = omapi_connection_copyin (c, lease -> uid,							  lease -> uid_len);			if (status != ISC_R_SUCCESS)				return status;		}	}	if (lease -> client_hostname) {		status = omapi_connection_put_name (c, "client-hostname");		if (status != ISC_R_SUCCESS)			return status;		status =			omapi_connection_put_string (c,						     lease -> client_hostname);		if (status != ISC_R_SUCCESS)			return status;	}	if (lease -> host) {		status = omapi_connection_put_name (c, "host");		if (status != ISC_R_SUCCESS)			return status;		status = omapi_connection_put_handle (c,						      (omapi_object_t *)						      lease -> host);		if (status != ISC_R_SUCCESS)			return status;	}	status = omapi_connection_put_name (c, "subnet");	if (status != ISC_R_SUCCESS)		return status;	status = omapi_connection_put_handle		(c, (omapi_object_t *)lease -> subnet);	if (status != ISC_R_SUCCESS)		return status;	status = omapi_connection_put_name (c, "pool");	if (status != ISC_R_SUCCESS)		return status;	status = omapi_connection_put_handle (c,					      (omapi_object_t *)lease -> pool);	if (status != ISC_R_SUCCESS)		return status;	if (lease -> billing_class) {		status = omapi_connection_put_name (c, "billing-class");		if (status != ISC_R_SUCCESS)			return status;		status = omapi_connection_put_handle			(c, (omapi_object_t *)lease -> billing_class);		if (status != ISC_R_SUCCESS)			return status;	}	if (lease -> hardware_addr.hlen) {		status = omapi_connection_put_name (c, "hardware-address");		if (status != ISC_R_SUCCESS)			return status;		status = (omapi_connection_put_uint32			  (c,			   (unsigned long)(lease -> hardware_addr.hlen - 1)));		if (status != ISC_R_SUCCESS)			return status;		status = (omapi_connection_copyin			  (c, &lease -> hardware_addr.hbuf [1],			   (unsigned long)(lease -> hardware_addr.hlen - 1)));		if (status != ISC_R_SUCCESS)			return status;		status = omapi_connection_put_name (c, "hardware-type");		if (status != ISC_R_SUCCESS)			return status;		status = omapi_connection_put_uint32 (c, sizeof (int));		if (status != ISC_R_SUCCESS)			return status;		status = omapi_connection_put_uint32			(c, lease -> hardware_addr.hbuf [0]);		if (status != ISC_R_SUCCESS)			return status;	}	status = omapi_connection_put_name (c, "ends");	if (status != ISC_R_SUCCESS)		return status;	status = omapi_connection_put_uint32 (c, sizeof (TIME));	if (status != ISC_R_SUCCESS)		return status;	status = (omapi_connection_copyin		  (c, (const unsigned char *)&(lease -> ends), sizeof(TIME)));	if (status != ISC_R_SUCCESS)		return status;	status = omapi_connection_put_name (c, "starts");	if (status != ISC_R_SUCCESS)		return status;	status = omapi_connection_put_uint32 (c, sizeof (TIME));	if (status != ISC_R_SUCCESS)		return status;	status = (omapi_connection_copyin		  (c,		   (const unsigned char *)&(lease -> starts), sizeof (TIME)));	if (status != ISC_R_SUCCESS)		return status;	status = omapi_connection_put_name (c, "tstp");	if (status != ISC_R_SUCCESS)		return status;	status = omapi_connection_put_uint32 (c, sizeof (TIME));	if (status != ISC_R_SUCCESS)		return status;	status = (omapi_connection_copyin		  (c,		   (const unsigned char *)&(lease -> tstp), sizeof (TIME)));	if (status != ISC_R_SUCCESS)		return status;	status = omapi_connection_put_name (c, "tsfp");	if (status != ISC_R_SUCCESS)		return status;	status = omapi_connection_put_uint32 (c, sizeof (TIME));	if (status != ISC_R_SUCCESS)		return status;	status = (omapi_connection_copyin		  (c,		   (const unsigned char *)&(lease -> tsfp), sizeof (TIME)));	if (status != ISC_R_SUCCESS)		return status;	status = omapi_connection_put_name (c, "cltt");	if (status != ISC_R_SUCCESS)		return status;	status = omapi_connection_put_uint32 (c, sizeof (TIME));	if (status != ISC_R_SUCCESS)		return status;	status = (omapi_connection_copyin		  (c,		   (const unsigned char *)&(lease -> cltt), sizeof (TIME)));	if (status != ISC_R_SUCCESS)		return status;	if (lease -> scope) {		status = binding_scope_stuff_values (c, lease -> scope);		if (status != ISC_R_SUCCESS)			return status;	}	/* Write out the inner object, if any. */	if (h -> inner && h -> inner -> type -> stuff_values) {		status = ((*(h -> inner -> type -> stuff_values))			  (c, id, h -> inner));		if (status == ISC_R_SUCCESS)			return status;	}	return ISC_R_SUCCESS;}isc_result_t dhcp_lease_lookup (omapi_object_t **lp,				omapi_object_t *id, omapi_object_t *ref){	omapi_value_t *tv = (omapi_value_t *)0;	isc_result_t status;	struct lease *lease;	if (!ref)		return ISC_R_NOKEYS;	/* First see if we were sent a handle. */	status = omapi_get_value_str (ref, id, "handle", &tv);	if (status == ISC_R_SUCCESS) {		status = omapi_handle_td_lookup (lp, tv -> value);		omapi_value_dereference (&tv, MDL);		if (status != ISC_R_SUCCESS)			return status;		/* Don't return the object if the type is wrong. */		if ((*lp) -> type != dhcp_type_lease) {			omapi_object_dereference (lp, MDL);			return ISC_R_INVALIDARG;		}	}	/* Now look for an IP address. */	status = omapi_get_value_str (ref, id, "ip-address", &tv);	if (status == ISC_R_SUCCESS) {		lease = (struct lease *)0;		lease_hash_lookup (&lease, lease_ip_addr_hash,				   tv -> value -> u.buffer.value,				   tv -> value -> u.buffer.len, MDL);		omapi_value_dereference (&tv, MDL);		/* If we already have a lease, and it's not the same one,		   then the query was invalid. */		if (*lp && *lp != (omapi_object_t *)lease) {			omapi_object_dereference (lp, MDL);			lease_dereference (&lease, MDL);			return ISC_R_KEYCONFLICT;		} else if (!lease) {			if (*lp)				omapi_object_dereference (lp, MDL);			return ISC_R_NOTFOUND;		} else if (!*lp) {			/* XXX fix so that hash lookup itself creates			   XXX the reference. */			omapi_object_reference (lp,						(omapi_object_t *)lease, MDL);			lease_dereference (&lease, MDL);		}	}	/* Now look for a client identifier. */	status = omapi_get_value_str (ref, id, "dhcp-client-identifier", &tv);	if (status == ISC_R_SUCCESS) {		lease = (struct lease *)0;		lease_hash_lookup (&lease, lease_uid_hash,				   tv -> value -> u.buffer.value,				   tv -> value -> u.buffer.len, MDL);		omapi_value_dereference (&tv, MDL);					if (*lp && *lp != (omapi_object_t *)lease) {			omapi_object_dereference (lp, MDL);			lease_dereference (&lease, MDL);			return ISC_R_KEYCONFLICT;		} else if (!lease) {			if (*lp)			    omapi_object_dereference (lp, MDL);			return ISC_R_NOTFOUND;		} else if (lease -> n_uid) {			if (*lp)			    omapi_object_dereference (lp, MDL);			return ISC_R_MULTIPLE;		} else if (!*lp) {			/* XXX fix so that hash lookup itself creates			   XXX the reference. */			omapi_object_reference (lp,						(omapi_object_t *)lease, MDL);			lease_dereference (&lease, MDL);		}	}	/* Now look for a hardware address. */	status = omapi_get_value_str (ref, id, "hardware-address", &tv);	if (status == ISC_R_SUCCESS) {		unsigned char *haddr;		unsigned int len;		len = tv -> value -> u.buffer.len + 1;		haddr = dmalloc (len, MDL);		if (!haddr) {			omapi_value_dereference (&tv, MDL);			return ISC_R_NOMEMORY;		}		memcpy (haddr + 1, tv -> value -> u.buffer.value, len - 1);		omapi_value_dereference (&tv, MDL);		status = omapi_get_value_str (ref, id, "hardware-type", &tv);		if (status == ISC_R_SUCCESS) {			if (tv -> value -> type == omapi_datatype_data) {				if ((tv -> value -> u.buffer.len != 4) ||				    (tv -> value -> u.buffer.value[0] != 0) ||				    (tv -> value -> u.buffer.value[1] != 0) ||				    (tv -> value -> u.buffer.value[2] != 0)) {					omapi_value_dereference (&tv, MDL);					dfree (haddr, MDL);					return ISC_R_INVALIDARG;				}				haddr[0] = tv -> value -> u.buffer.value[3];			} else if (tv -> value -> type == omapi_datatype_int) {				haddr[0] = (unsigned char)					tv -> value -> u.integer;			} else {				omapi_value_dereference (&tv, MDL);				dfree (haddr, MDL);				return ISC_R_INVALIDARG;			}			omapi_value_dereference (&tv, MDL);		} else {			/* If no hardware-type is specified, default to			   ethernet.  This may or may not be a good idea,			   but Telus is currently relying on this behavior.			   - DPN */			haddr[0] = HTYPE_ETHER;		}		lease = (struct lease *)0;		lease_hash_lookup (&lease, lease_hw_addr_hash, haddr, len, MDL);		dfree (haddr, MDL);		if (*lp && *lp != (omapi_object_t *)lease) {			omapi_object_dereference (lp, MDL);			lease_dereference (&lease, MDL);			return ISC_R_KEYCONFLICT;		} else if (!lease) {			if (*lp)			    omapi_object_dereference (lp, MDL);			return ISC_R_NOTFOUND;		} else if (lease -> n_hw) {			if (*lp)			    omapi_object_dereference (lp, MDL);			lease_dereference (&lease, MDL);			return ISC_R_MULTIPLE;		} else if (!*lp) {			/* XXX fix so that hash lookup itself creates			   XXX the reference. */			omapi_object_reference (lp,						(omapi_object_t *)lease, MDL);			lease_dereference (&lease, MDL);		}	}	/* If we get to here without finding a lease, no valid key was	   specified. */	if (!*lp)		return ISC_R_NOKEYS;	return ISC_R_SUCCESS;}isc_result_t dhcp_lease_create (omapi_object_t **lp,				omapi_object_t *id){	return ISC_R_NOTIMPLEMENTED;}isc_result_t dhcp_lease_remove (omapi_object_t *lp,				omapi_object_t *id){	return ISC_R_NOTIMPLEMENTED;}isc_result_t dhcp_host_set_value  (omapi_object_t *h,				   omapi_object_t *id,				   omapi_data_string_t *name,				   omapi_typed_data_t *value){	struct host_decl *host, *hp;	isc_result_t status;	int foo;	if (h -> type != dhcp_type_host)		return ISC_R_INVALIDARG;	host = (struct host_decl *)h;	/* XXX For now, we can only set these values on new host objects. 	   XXX Soon, we need to be able to update host objects. */	if (!omapi_ds_strcmp (name, "name")) {		if (host -> name)			return ISC_R_EXISTS;		if (value && (value -> type == omapi_datatype_data ||		    	      value -> type == omapi_datatype_string)) {			host -> name = dmalloc (value -> u.buffer.len + 1,						MDL);			if (!host -> name)				return ISC_R_NOMEMORY;			memcpy (host -> name,				value -> u.buffer.value,				value -> u.buffer.len);			host -> name [value -> u.buffer.len] = 0;		} else			return ISC_R_INVALIDARG;		return ISC_R_SUCCESS;	}	if (!omapi_ds_strcmp (name, "group")) {		if (value && (value -> type == omapi_datatype_data ||		    	      value -> type == omapi_datatype_string)) {			struct group_object *group;			group = (struct group_object *)0;

⌨️ 快捷键说明

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