From d49c7280071445309ad5d993d3db0223b641df62 Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Thu, 27 Mar 2008 17:57:22 -0400 Subject: - hard-code a dummy map for testing --- src/Makefile | 2 +- src/dummymap.c | 192 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 193 insertions(+), 1 deletion(-) create mode 100644 src/dummymap.c diff --git a/src/Makefile b/src/Makefile index 0a544eb..9e33b3a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -3,7 +3,7 @@ LDFLAGS = -lnsl -lpthread all:: plugin.so portmap -plugin.so: dispatch.c map.c nis.c plugin.c portmap.c +plugin.so: dispatch.c dummymap.c nis.c plugin.c portmap.c $(CC) $(CFLAGS) -shared -o $@ $^ $(LDFLAGS) portmap: portmap.c $(CC) $(CFLAGS) -o $@ -DPORTMAP_MAIN $^ $(LDFLAGS) diff --git a/src/dummymap.c b/src/dummymap.c new file mode 100644 index 0000000..daed8e8 --- /dev/null +++ b/src/dummymap.c @@ -0,0 +1,192 @@ +#ifdef HAVE_CONFIG_H +#include "../config.h" +#endif + +#include +#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 entry { + char *key, *value; +}; + +struct map { + char *map; + struct entry *entries; +}; + +struct domain { + char *domain; + struct map *maps; +}; + +struct entry devel_passwd_byname[] = { + {"user1", "user1:*:1:1:User Number 1:/home/devel/user1:/bin/tcsh"}, + {"user2", "user2:*:2:2:User Number 2:/home/devel/user2:/bin/tcsh"}, + {"user3", "user3:*:3:3:User Number 3:/home/devel/user3:/bin/tcsh"}, + {"user4", "user4:*:4:4:User Number 4:/home/devel/user4:/bin/tcsh"}, + {"user5", "user5:*:5:5:User Number 5:/home/devel/user5:/bin/tcsh"}, + {NULL, NULL}, +}; + +struct entry devel_passwd_bynumber[] = { + {"1", "user1:*:1:1:User Number 1:/home/devel/user1:/bin/tcsh"}, + {"2", "user2:*:2:2:User Number 2:/home/devel/user2:/bin/tcsh"}, + {"3", "user3:*:3:3:User Number 3:/home/devel/user3:/bin/tcsh"}, + {"4", "user4:*:4:4:User Number 4:/home/devel/user4:/bin/tcsh"}, + {"5", "user5:*:5:5:User Number 5:/home/devel/user5:/bin/tcsh"}, + {NULL, NULL}, +}; + +struct map devel_maps[] = { + {"passwd.byname", devel_passwd_byname}, + {"passwd.bynumber", devel_passwd_byname}, + {NULL, NULL}, +}; + +struct domain domains[] = { + {"devel.example.com", devel_maps}, + {NULL, NULL}, +}; + +bool_t +map_supports_domain(struct plugin_state *state, + const char *domain, + bool_t *supported) +{ + int i; + *supported = FALSE; + for (i = 0; domains[i].domain != NULL; i++) { + if (strcmp(domains[i].domain, domain) == 0) { + *supported = TRUE; + break; + } + } + return TRUE; +} + + +bool_t +map_order(struct plugin_state *state, + const char *domain, const char *map, + unsigned int *order) +{ + *order = 1; + return TRUE; +} + +static struct entry * +map_find_entries(const char *domain, const char *map) +{ + int i, j; + for (i = 0; domains[i].domain != NULL; i++) { + if (strcmp(domains[i].domain, domain) == 0) { + break; + } + } + if (domains[i].domain == NULL) { + return NULL; + } + for (j = 0; domains[i].maps[j].map != NULL; j++) { + if (strcmp(domains[i].maps[j].map, map) == 0) { + break; + } + } + if (domains[i].maps[j].map == NULL) { + return NULL; + } + return domains[i].maps[j].entries; +} + +bool_t +map_match(struct plugin_state *state, + const char *domain, const char *map, + unsigned int key_len, char *key, + unsigned int *value_len, char **value) +{ + struct entry *entries; + int i; + if ((entries = map_find_entries(domain, map)) == NULL) { + return FALSE; + } + for (i = 0; entries[i].key != NULL; i++) { + if ((strlen(entries[i].key) == key_len) && + (memcmp(entries[i].key, key, key_len) == 0)) { + break; + } + } + if (entries[i].key == NULL) { + return FALSE; + } + *value = entries[i].value; + *value_len = strlen(entries[i].value); + return TRUE; +} + +bool_t +map_first(struct plugin_state *state, + const char *domain, const char *map, + unsigned int *first_key_len, char **first_key, + unsigned int *first_value_len, char **first_value) +{ + struct entry *entries; + if ((entries = map_find_entries(domain, map)) == NULL) { + return FALSE; + } + if (entries[0].key == NULL) { + return FALSE; + } + *first_key = entries[0].key; + *first_key_len = strlen(entries[0].key); + *first_value = entries[0].value; + *first_value_len = strlen(entries[0].value); + return TRUE; +} + +bool_t +map_next(struct plugin_state *state, + const char *domain, const char *map, + unsigned int prev_len, const char *prev, + unsigned int *next_key_len, char **next_key, + unsigned int *next_value_len, char **next_value) +{ + struct entry *entries; + int i; + if ((entries = map_find_entries(domain, map)) == NULL) { + return FALSE; + } + for (i = 0; entries[i].key != NULL; i++) { + if ((strlen(entries[i].key) == prev_len) && + (memcmp(entries[i].key, prev, prev_len) == 0)) { + break; + } + } + if (entries[i].key == NULL) { + return FALSE; + } + if (entries[i + 1].key == NULL) { + return FALSE; + } + *next_key = entries[i + 1].key; + *next_key_len = strlen(entries[i + 1].key); + *next_value = entries[i + 1].value; + *next_value_len = strlen(entries[i + 1].value); + return TRUE; +} -- cgit