#ifdef HAVE_CONFIG_H #include "../config.h" #endif #include #include #include #include #include #include #include #include #include #include #include #include "dispatch.h" #include "map.h" #include "nis.h" #include "plugin.h" #include "portmap.h" struct { struct domain { char *name; struct map { char *name; char *search_base; int search_scope; char *entry_filter; char *key_attribute; char *value_format; time_t last_changed; struct entry { struct entry *prev, *next; char *dn; char *key; unsigned int key_len; char *value; unsigned int value_len; } *entries; } *maps; int n_maps; } *domains; int n_domains; } map_data; static struct domain * map_find_domain(struct plugin_state *state, const char *domain_name) { int i; for (i = 0; i < map_data.n_domains; i++) { if (strcmp(domain_name, map_data.domains[i].name) == 0) { return &map_data.domains[i]; } } return NULL; } static struct map * map_find_map(struct plugin_state *state, const char *domain_name, const char *map_name) { int i; struct domain *domain; domain = map_find_domain(state, domain_name); if (domain != NULL) { for (i = 0; i < domain->n_maps; i++) { if (strcmp(map_name, domain->maps[i].name) == 0) { return &domain->maps[i]; } } } return NULL; } bool_t map_supports_domain(struct plugin_state *state, const char *domain_name, bool_t *supported) { *supported = (map_find_domain(state, domain_name) != NULL); return TRUE; } bool_t map_supports_map(struct plugin_state *state, const char *domain_name, const char *map_name, bool_t *supported) { *supported = (map_find_map(state, domain_name, map_name) != NULL); return TRUE; } bool_t map_order(struct plugin_state *state, const char *domain_name, const char *map_name, unsigned int *order) { struct map *map; map = map_find_map(state, domain_name, map_name); if (map != NULL) { *order = map->last_changed & 0xffffffff; return TRUE; } else { return FALSE; } } bool_t map_match(struct plugin_state *state, const char *domain_name, const char *map_name, unsigned int key_len, char *key, unsigned int *value_len, char **value) { struct map *map; struct entry *entry; map = map_find_map(state, domain_name, map_name); if (map == NULL) { return FALSE; } for (entry = map->entries; entry != NULL; entry = entry->next) { if ((entry->key_len == key_len) && (memcmp(entry->key, key, key_len) == 0)) { *value_len = entry->value_len; *value = entry->value; return TRUE; } } return FALSE; } bool_t map_first(struct plugin_state *state, const char *domain_name, const char *map_name, unsigned int *first_key_len, char **first_key, unsigned int *first_value_len, char **first_value) { struct map *map; struct entry *entry; map = map_find_map(state, domain_name, map_name); if (map == NULL) { return FALSE; } entry = map->entries; if (entry == NULL) { return FALSE; } *first_key_len = entry->key_len; *first_key = entry->key; *first_value_len = entry->value_len; *first_value = entry->value; return TRUE; } bool_t map_next(struct plugin_state *state, const char *domain_name, const char *map_name, unsigned int prev_len, const char *prev, unsigned int *next_key_len, char **next_key, unsigned int *next_value_len, char **next_value) { struct map *map; struct entry *entry; map = map_find_map(state, domain_name, map_name); if (map == NULL) { return FALSE; } for (entry = map->entries; entry != NULL; entry = entry->next) { if ((entry->key_len == prev_len) && (memcmp(entry->key, prev, prev_len) == 0)) { entry = entry->next; if (entry == NULL) { return FALSE; } *next_key_len = entry->key_len; *next_key = entry->key; *next_value_len = entry->value_len; *next_value = entry->value; return TRUE; } } return FALSE; }