summaryrefslogtreecommitdiffstats
path: root/src/dummymap.c
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-03-27 17:57:22 -0400
committerNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-03-27 17:57:22 -0400
commitd49c7280071445309ad5d993d3db0223b641df62 (patch)
treed77dd732cfda451f8d653223843767b54c6ef75a /src/dummymap.c
parentfde6d0ba63dc2493f625bb21556d5efdc4ada777 (diff)
downloadslapi-nis-d49c7280071445309ad5d993d3db0223b641df62.tar.gz
slapi-nis-d49c7280071445309ad5d993d3db0223b641df62.tar.xz
slapi-nis-d49c7280071445309ad5d993d3db0223b641df62.zip
- hard-code a dummy map for testing
Diffstat (limited to 'src/dummymap.c')
-rw-r--r--src/dummymap.c192
1 files changed, 192 insertions, 0 deletions
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 <sys/types.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <rpc/rpc.h>
+#include <rpcsvc/yp_prot.h>
+
+#include <nspr.h>
+#include <secport.h>
+#include <plarenas.h>
+#include <dirsrv/slapi-plugin.h>
+
+#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;
+}