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

📄 omapi.c

📁 DHCP服务器源码
💻 C
📖 第 1 页 / 共 5 页
字号:
		} else if (!host || (host -> flags & HOST_DECL_DELETED)) {			if (*lp)			    omapi_object_dereference (lp, MDL);			if (host)				host_dereference (&host, 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 *)host, MDL);			host_dereference (&host, 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;		}		host = (struct host_decl *)0;		host_hash_lookup (&host, host_hw_addr_hash, haddr, len, MDL);		dfree (haddr, MDL);					if (*lp && *lp != (omapi_object_t *)host) {			omapi_object_dereference (lp, MDL);			if (host)				host_dereference (&host, MDL);			return ISC_R_KEYCONFLICT;		} else if (!host || (host -> flags & HOST_DECL_DELETED)) {			if (*lp)			    omapi_object_dereference (lp, MDL);			if (host)				host_dereference (&host, 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 *)host, MDL);			host_dereference (&host, MDL);		}	}	/* Now look for an ip address. */	status = omapi_get_value_str (ref, id, "ip-address", &tv);	if (status == ISC_R_SUCCESS) {		struct lease *l;		/* first find the lease for this ip address */		l = (struct lease *)0;		lease_hash_lookup (&l, lease_ip_addr_hash,				   tv -> value -> u.buffer.value,				   tv -> value -> u.buffer.len, MDL);		omapi_value_dereference (&tv, MDL);		if (!l && !*lp)			return ISC_R_NOTFOUND;		if (l) {			/* now use that to get a host */			host = (struct host_decl *)0;			host_hash_lookup (&host, host_hw_addr_hash,					  l -> hardware_addr.hbuf,					  l -> hardware_addr.hlen, MDL);						if (host && *lp && *lp != (omapi_object_t *)host) {			    omapi_object_dereference (lp, MDL);			    if (host)				host_dereference (&host, MDL);			    return ISC_R_KEYCONFLICT;			} else if (!host || (host -> flags &					     HOST_DECL_DELETED)) {			    if (host)				host_dereference (&host, MDL);			    if (!*lp)				    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 *)host,						    MDL);			    host_dereference (&host, MDL);			}			lease_dereference (&l, MDL);		}	}	/* Now look for a name. */	status = omapi_get_value_str (ref, id, "name", &tv);	if (status == ISC_R_SUCCESS) {		host = (struct host_decl *)0;		host_hash_lookup (&host, host_name_hash,				  tv -> value -> u.buffer.value,				  tv -> value -> u.buffer.len, MDL);		omapi_value_dereference (&tv, MDL);					if (*lp && *lp != (omapi_object_t *)host) {			omapi_object_dereference (lp, MDL);			if (host)			    host_dereference (&host, MDL);			return ISC_R_KEYCONFLICT;		} else if (!host || (host -> flags & HOST_DECL_DELETED)) {			if (host)			    host_dereference (&host, 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 *)host, MDL);			host_dereference (&host, MDL);		}	}	/* If we get to here without finding a host, no valid key was	   specified. */	if (!*lp)		return ISC_R_NOKEYS;	return ISC_R_SUCCESS;}isc_result_t dhcp_host_create (omapi_object_t **lp,			       omapi_object_t *id){	struct host_decl *hp;	isc_result_t status;	hp = (struct host_decl *)0;	status = host_allocate (&hp, MDL);	if (status != ISC_R_SUCCESS)		return status;	group_reference (&hp -> group, root_group, MDL);	hp -> flags = HOST_DECL_DYNAMIC;	status = omapi_object_reference (lp, (omapi_object_t *)hp, MDL);	host_dereference (&hp, MDL);	return status;}isc_result_t dhcp_host_remove (omapi_object_t *lp,			       omapi_object_t *id){	struct host_decl *hp;	if (lp -> type != dhcp_type_host)		return ISC_R_INVALIDARG;	hp = (struct host_decl *)lp;#ifdef DEBUG_OMAPI	log_debug ("OMAPI delete host %s", hp -> name);#endif	delete_host (hp, 1);	return ISC_R_SUCCESS;}isc_result_t dhcp_pool_set_value  (omapi_object_t *h,				   omapi_object_t *id,				   omapi_data_string_t *name,				   omapi_typed_data_t *value){	struct pool *pool;	isc_result_t status;	int foo;	if (h -> type != dhcp_type_pool)		return ISC_R_INVALIDARG;	pool = (struct pool *)h;	/* No values to set yet. */	/* 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_UNKNOWNATTRIBUTE;}isc_result_t dhcp_pool_get_value (omapi_object_t *h, omapi_object_t *id,				  omapi_data_string_t *name,				  omapi_value_t **value){	struct pool *pool;	isc_result_t status;	if (h -> type != dhcp_type_pool)		return ISC_R_INVALIDARG;	pool = (struct pool *)h;	/* No values to get yet. */	/* Try to find some inner object that can provide the value. */	if (h -> inner && h -> inner -> type -> get_value) {		status = ((*(h -> inner -> type -> get_value))			  (h -> inner, id, name, value));		if (status == ISC_R_SUCCESS)			return status;	}	return ISC_R_UNKNOWNATTRIBUTE;}isc_result_t dhcp_pool_destroy (omapi_object_t *h, const char *file, int line){	struct pool *pool;	isc_result_t status;	struct permit *pc, *pn;	if (h -> type != dhcp_type_pool)		return ISC_R_INVALIDARG;	pool = (struct pool *)h;#if defined (DEBUG_MEMORY_LEAKAGE) || \		defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)	if (pool -> next)		pool_dereference (&pool -> next, file, line);	if (pool -> group)		group_dereference (&pool -> group, file, line);	if (pool -> shared_network)	    shared_network_dereference (&pool -> shared_network, file, line);	if (pool -> active)		lease_dereference (&pool -> active, file, line);	if (pool -> expired)		lease_dereference (&pool -> expired, file, line);	if (pool -> free)		lease_dereference (&pool -> free, file, line);	if (pool -> backup)		lease_dereference (&pool -> backup, file, line);	if (pool -> abandoned)		lease_dereference (&pool -> abandoned, file, line);#if defined (FAILOVER_PROTOCOL)	if (pool -> failover_peer)		dhcp_failover_state_dereference (&pool -> failover_peer,						 file, line);#endif	for (pc = pool -> permit_list; pc; pc = pn) {		pn = pc -> next;		free_permit (pc, file, line);	}	pool -> permit_list = (struct permit *)0;	for (pc = pool -> prohibit_list; pc; pc = pn) {		pn = pc -> next;		free_permit (pc, file, line);	}	pool -> prohibit_list = (struct permit *)0;#endif	return ISC_R_SUCCESS;}isc_result_t dhcp_pool_signal_handler (omapi_object_t *h,				       const char *name, va_list ap){	struct pool *pool;	isc_result_t status;	int updatep = 0;	if (h -> type != dhcp_type_pool)		return ISC_R_INVALIDARG;	pool = (struct pool *)h;	/* Can't write pools yet. */	/* 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;	}	if (updatep)		return ISC_R_SUCCESS;	return ISC_R_NOTFOUND;}isc_result_t dhcp_pool_stuff_values (omapi_object_t *c,				     omapi_object_t *id,				     omapi_object_t *h){	struct pool *pool;	isc_result_t status;	if (h -> type != dhcp_type_pool)		return ISC_R_INVALIDARG;	pool = (struct pool *)h;	/* Can't stuff pool values yet. */	/* 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_pool_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 pool *pool;	/* Can't look up pools yet. */	/* If we get to here without finding a pool, no valid key was	   specified. */	if (!*lp)		return ISC_R_NOKEYS;	return ISC_R_SUCCESS;}isc_result_t dhcp_pool_create (omapi_object_t **lp,			       omapi_object_t *id){	return ISC_R_NOTIMPLEMENTED;}isc_result_t dhcp_pool_remove (omapi_object_t *lp,			       omapi_object_t *id){	return ISC_R_NOTIMPLEMENTED;}isc_result_t dhcp_class_set_value  (omapi_object_t *h,				    omapi_object_t *id,				    omapi_data_string_t *name,				    omapi_typed_data_t *value){	struct class *class;	isc_result_t status;	int foo;	if (h -> type != dhcp_type_class)		return ISC_R_INVALIDARG;	class = (struct class *)h;	/* No values to set yet. */	/* 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_UNKNOWNATTRIBUTE;}isc_result_t dhcp_class_get_value (omapi_object_t *h, omapi_object_t *id,				   omapi_data_string_t *name,				   omapi_value_t **value){	struct class *class;	isc_result_t status;	if (h -> type != dhcp_type_class)		return ISC_R_INVALIDARG;	class = (struct class *)h;	/* No values to get yet. */	/* Try to find some inner object that can provide the value. */	if (h -> inner && h -> inner -> type -> get_value) {		status = ((*(h -> inner -> type -> get_value))			  (h -> inner, id, name, value));		if (status == ISC_R_SUCCESS)			return status;	}	return ISC_R_UNKNOWNATTRIBUTE;}isc_result_t dhcp_class_destroy (omapi_object_t *h, const char *file, int line){	struct class *class;	isc_result_t status;	int i;	if (h -> type != dhcp_type_class && h -> type != dhcp_type_subclass)		return ISC_R_INVALIDARG;	class = (struct class *)h;#if defined (DEBUG_MEMORY_LEAKAGE) || \		defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)	if (class -> nic)		class_dereference (&class -> nic, file, line);	if (class -> superclass)		class_dereference (&class -> superclass, file, line);	if (class -> name) {		dfree (class -> name, file, line);		class -> name = (char *)0;	}	if (class -> billed_leases) {		for (i = 0; i < class -> lease_limit; i++) {			if (class -> billed_leases [i]) {				lease_dereference (&class -> billed_leases [i],						   file, line);			}

⌨️ 快捷键说明

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