summaryrefslogtreecommitdiffstats
path: root/src/dummymap.c
blob: ce257d5b501c7409477a724e945ec147a294c4f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#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 <nspr.h>
#include <secport.h>
#include <plarenas.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},
};

void
map_init(struct plugin_state *state)
{
}

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;
		}
	}
	slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
			"map_supports_domain \"%s\": %s\n", domain,
			*supported ? "YES" : "NO");
	return TRUE;
}

bool_t
map_supports_map(struct plugin_state *state,
		 const char *domain, const char *map, bool_t *supported)
{
	int i, j;
	*supported = FALSE;
	for (i = 0; domains[i].domain != NULL; i++) {
		if (strcmp(domains[i].domain, domain) == 0) {
			break;
		}
	}
	if (domains[i].domain != NULL) {
		for (j = 0; domains[i].maps[j].map != NULL; j++) {
			if (strcmp(domains[i].maps[j].map, map) == 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;
}