📄 omapi.c
字号:
group_hash_lookup (&group, group_name_hash, (char *)value -> u.buffer.value, value -> u.buffer.len, MDL); if (!group || (group -> flags & GROUP_OBJECT_DELETED)) return ISC_R_NOTFOUND; if (host -> group) group_dereference (&host -> group, MDL); group_reference (&host -> group, group -> group, MDL); if (host -> named_group) group_object_dereference (&host -> named_group, MDL); group_object_reference (&host -> named_group, group, MDL); group_object_dereference (&group, MDL); } else return ISC_R_INVALIDARG; return ISC_R_SUCCESS; } if (!omapi_ds_strcmp (name, "hardware-address")) { if (host -> interface.hlen) return ISC_R_EXISTS; if (value && (value -> type == omapi_datatype_data || value -> type == omapi_datatype_string)) { if (value -> u.buffer.len > (sizeof host -> interface.hbuf) - 1) return ISC_R_INVALIDARG; memcpy (&host -> interface.hbuf [1], value -> u.buffer.value, value -> u.buffer.len); host -> interface.hlen = value -> u.buffer.len + 1; } else return ISC_R_INVALIDARG; return ISC_R_SUCCESS; } if (!omapi_ds_strcmp (name, "hardware-type")) { int type; if (value && (value -> type == omapi_datatype_data && value -> u.buffer.len == sizeof type)) { if (value -> u.buffer.len > sizeof type) return ISC_R_INVALIDARG; memcpy (&type, value -> u.buffer.value, value -> u.buffer.len); type = ntohl (type); } else if (value -> type == omapi_datatype_int) type = value -> u.integer; else return ISC_R_INVALIDARG; host -> interface.hbuf [0] = type; return ISC_R_SUCCESS; } if (!omapi_ds_strcmp (name, "dhcp-client-identifier")) { if (host -> client_identifier.data) return ISC_R_EXISTS; if (value && (value -> type == omapi_datatype_data || value -> type == omapi_datatype_string)) { if (!buffer_allocate (&host -> client_identifier.buffer, value -> u.buffer.len, MDL)) return ISC_R_NOMEMORY; host -> client_identifier.data = &host -> client_identifier.buffer -> data [0]; memcpy (host -> client_identifier.buffer -> data, value -> u.buffer.value, value -> u.buffer.len); host -> client_identifier.len = value -> u.buffer.len; } else return ISC_R_INVALIDARG; return ISC_R_SUCCESS; } if (!omapi_ds_strcmp (name, "ip-address")) { if (host -> fixed_addr) option_cache_dereference (&host -> fixed_addr, MDL); if (!value) return ISC_R_SUCCESS; if (value && (value -> type == omapi_datatype_data || value -> type == omapi_datatype_string)) { struct data_string ds; memset (&ds, 0, sizeof ds); ds.len = value -> u.buffer.len; if (!buffer_allocate (&ds.buffer, ds.len, MDL)) return ISC_R_NOMEMORY; ds.data = (&ds.buffer -> data [0]); memcpy (ds.buffer -> data, value -> u.buffer.value, ds.len); if (!option_cache (&host -> fixed_addr, &ds, (struct expression *)0, (struct option *)0, MDL)) { data_string_forget (&ds, MDL); return ISC_R_NOMEMORY; } data_string_forget (&ds, MDL); } else return ISC_R_INVALIDARG; return ISC_R_SUCCESS; } if (!omapi_ds_strcmp (name, "statements")) { if (!host -> group) { if (!clone_group (&host -> group, root_group, MDL)) return ISC_R_NOMEMORY; } else { if (host -> group -> statements && (!host -> named_group || host -> group != host -> named_group -> group) && host -> group != root_group) return ISC_R_EXISTS; if (!clone_group (&host -> group, host -> group, MDL)) return ISC_R_NOMEMORY; } if (!host -> group) return ISC_R_NOMEMORY; if (value && (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 (&host -> group -> statements, parse, &lose, context_any))) { end_parse (&parse); return ISC_R_BADPARSE; } end_parse (&parse); } else return ISC_R_INVALIDARG; return ISC_R_SUCCESS; } /* The "known" flag isn't supported in the database yet, but it's legitimate. */ if (!omapi_ds_strcmp (name, "known")) { return ISC_R_SUCCESS; } /* 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_host_get_value (omapi_object_t *h, omapi_object_t *id, omapi_data_string_t *name, omapi_value_t **value){ struct host_decl *host; isc_result_t status; struct data_string ip_addrs; if (h -> type != dhcp_type_host) return ISC_R_INVALIDARG; host = (struct host_decl *)h; if (!omapi_ds_strcmp (name, "ip-addresses")) { memset (&ip_addrs, 0, sizeof ip_addrs); if (host -> fixed_addr && evaluate_option_cache (&ip_addrs, (struct packet *)0, (struct lease *)0, (struct client_state *)0, (struct option_state *)0, (struct option_state *)0, &global_scope, host -> fixed_addr, MDL)) { status = omapi_make_const_value (value, name, ip_addrs.data, ip_addrs.len, MDL); data_string_forget (&ip_addrs, MDL); return status; } return ISC_R_NOTFOUND; } if (!omapi_ds_strcmp (name, "dhcp-client-identifier")) { if (!host -> client_identifier.len) return ISC_R_NOTFOUND; return omapi_make_const_value (value, name, host -> client_identifier.data, host -> client_identifier.len, MDL); } if (!omapi_ds_strcmp (name, "name")) return omapi_make_string_value (value, name, host -> name, MDL); if (!omapi_ds_strcmp (name, "hardware-address")) { if (!host -> interface.hlen) return ISC_R_NOTFOUND; return (omapi_make_const_value (value, name, &host -> interface.hbuf [1], (unsigned long)(host -> interface.hlen - 1), MDL)); } if (!omapi_ds_strcmp (name, "hardware-type")) { if (!host -> interface.hlen) return ISC_R_NOTFOUND; return omapi_make_int_value (value, name, host -> interface.hbuf [0], MDL); } /* Try to find some inner object that can take 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_host_destroy (omapi_object_t *h, const char *file, int line){ struct host_decl *host; isc_result_t status; if (h -> type != dhcp_type_host) return ISC_R_INVALIDARG; host = (struct host_decl *)h;#if defined (DEBUG_MEMORY_LEAKAGE) || \ defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT) if (host -> n_ipaddr) host_dereference (&host -> n_ipaddr, file, line); if (host -> n_dynamic) host_dereference (&host -> n_dynamic, file, line); if (host -> name) { dfree (host -> name, file, line); host -> name = (char *)0; } data_string_forget (&host -> client_identifier, file, line); if (host -> fixed_addr) option_cache_dereference (&host -> fixed_addr, file, line); if (host -> group) group_dereference (&host -> group, file, line); if (host -> named_group) omapi_object_dereference ((omapi_object_t **) &host -> named_group, file, line); data_string_forget (&host -> auth_key_id, file, line);#endif return ISC_R_SUCCESS;}isc_result_t dhcp_host_signal_handler (omapi_object_t *h, const char *name, va_list ap){ struct host_decl *host; isc_result_t status; int updatep = 0; if (h -> type != dhcp_type_host) return ISC_R_INVALIDARG; host = (struct host_decl *)h; if (!strcmp (name, "updated")) { /* There must be a client identifier of some sort. */ if (host -> interface.hlen == 0 && !host -> client_identifier.len) return ISC_R_INVALIDARG; if (!host -> name) { char hnbuf [64]; sprintf (hnbuf, "nh%08lx%08lx", (unsigned long)cur_time, (unsigned long)host); host -> name = dmalloc (strlen (hnbuf) + 1, MDL); if (!host -> name) return ISC_R_NOMEMORY; strcpy (host -> name, hnbuf); }#ifdef DEBUG_OMAPI log_debug ("OMAPI added host %s", host -> name);#endif status = enter_host (host, 1, 1); if (status != ISC_R_SUCCESS) return status; updatep = 1; } /* 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_host_stuff_values (omapi_object_t *c, omapi_object_t *id, omapi_object_t *h){ struct host_decl *host; isc_result_t status; struct data_string ip_addrs; if (h -> type != dhcp_type_host) return ISC_R_INVALIDARG; host = (struct host_decl *)h; /* Write out all the values. */ memset (&ip_addrs, 0, sizeof ip_addrs); if (host -> fixed_addr && evaluate_option_cache (&ip_addrs, (struct packet *)0, (struct lease *)0, (struct client_state *)0, (struct option_state *)0, (struct option_state *)0, &global_scope, host -> fixed_addr, MDL)) { status = omapi_connection_put_name (c, "ip-address"); if (status != ISC_R_SUCCESS) return status; status = omapi_connection_put_uint32 (c, ip_addrs.len); if (status != ISC_R_SUCCESS) return status; status = omapi_connection_copyin (c, ip_addrs.data, ip_addrs.len); if (status != ISC_R_SUCCESS) return status; } if (host -> client_identifier.len) { status = omapi_connection_put_name (c, "dhcp-client-identifier"); if (status != ISC_R_SUCCESS) return status; status = (omapi_connection_put_uint32 (c, host -> client_identifier.len)); if (status != ISC_R_SUCCESS) return status; status = (omapi_connection_copyin (c, host -> client_identifier.data, host -> client_identifier.len)); if (status != ISC_R_SUCCESS) return status; } if (host -> name) { status = omapi_connection_put_name (c, "name"); if (status != ISC_R_SUCCESS) return status; status = omapi_connection_put_string (c, host -> name); if (status != ISC_R_SUCCESS) return status; } if (host -> interface.hlen) { status = omapi_connection_put_name (c, "hardware-address"); if (status != ISC_R_SUCCESS) return status; status = (omapi_connection_put_uint32 (c, (unsigned long)(host -> interface.hlen - 1))); if (status != ISC_R_SUCCESS) return status; status = (omapi_connection_copyin (c, &host -> interface.hbuf [1], (unsigned long)(host -> interface.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, host -> interface.hbuf [0])); 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_host_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 host_decl *host; 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_host) { omapi_object_dereference (lp, MDL); return ISC_R_INVALIDARG; } if (((struct host_decl *)(*lp)) -> flags & HOST_DECL_DELETED) { omapi_object_dereference (lp, MDL); } } /* Now look for a client identifier. */ status = omapi_get_value_str (ref, id, "dhcp-client-identifier", &tv); if (status == ISC_R_SUCCESS) { host = (struct host_decl *)0; host_hash_lookup (&host, host_uid_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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -