summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/dummymap.c100
-rw-r--r--src/map.c66
-rw-r--r--src/map.h20
3 files changed, 164 insertions, 22 deletions
diff --git a/src/dummymap.c b/src/dummymap.c
index d03fe09..ffb4ef7 100644
--- a/src/dummymap.c
+++ b/src/dummymap.c
@@ -46,7 +46,7 @@
#include "portmap.h"
struct entry {
- char *key, *value;
+ char *id, *key, *value;
};
struct map {
@@ -60,21 +60,21 @@ struct domain {
};
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},
+ {"a", "user1", "user1:*:1:1:User Number 1:/home/devel/user1:/bin/tcsh"},
+ {"b", "user2", "user2:*:2:2:User Number 2:/home/devel/user2:/bin/tcsh"},
+ {"c", "user3", "user3:*:3:3:User Number 3:/home/devel/user3:/bin/tcsh"},
+ {"d", "user4", "user4:*:4:4:User Number 4:/home/devel/user4:/bin/tcsh"},
+ {"e", "user5", "user5:*:5:5:User Number 5:/home/devel/user5:/bin/tcsh"},
+ {NULL, 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},
+ {"a", "1", "user1:*:1:1:User Number 1:/home/devel/user1:/bin/tcsh"},
+ {"b", "2", "user2:*:2:2:User Number 2:/home/devel/user2:/bin/tcsh"},
+ {"c", "3", "user3:*:3:3:User Number 3:/home/devel/user3:/bin/tcsh"},
+ {"d", "4", "user4:*:4:4:User Number 4:/home/devel/user4:/bin/tcsh"},
+ {"e", "5", "user5:*:5:5:User Number 5:/home/devel/user5:/bin/tcsh"},
+ {NULL, NULL, NULL},
};
struct map devel_maps[] = {
@@ -193,7 +193,7 @@ bool_t
map_match(struct plugin_state *state,
const char *domain, const char *map, bool_t *secure,
unsigned int key_len, char *key,
- unsigned int *value_len, char **value)
+ unsigned int *value_len, char **value, const char **id)
{
struct entry *entries;
int i;
@@ -212,6 +212,37 @@ map_match(struct plugin_state *state,
*secure = FALSE;
*value = entries[i].value;
*value_len = strlen(entries[i].value);
+ *id = entries[i].key;
+ return TRUE;
+}
+
+bool_t
+map_match_id(struct plugin_state *state,
+ const char *domain, const char *map, bool_t *secure,
+ const char *in_id,
+ unsigned int *key_len, char **key,
+ unsigned int *value_len, char **value,
+ const char **id)
+{
+ struct entry *entries;
+ int i;
+ if ((entries = map_find_entries(domain, map)) == NULL) {
+ return FALSE;
+ }
+ for (i = 0; entries[i].id != NULL; i++) {
+ if (strcmp(entries[i].id, in_id) == 0) {
+ break;
+ }
+ }
+ if (entries[i].id == NULL) {
+ return FALSE;
+ }
+ *secure = FALSE;
+ *key = entries[i].key;
+ *key_len = strlen(entries[i].key);
+ *value = entries[i].value;
+ *value_len = strlen(entries[i].value);
+ *id = entries[i].id;
return TRUE;
}
@@ -219,7 +250,8 @@ bool_t
map_first(struct plugin_state *state,
const char *domain, const char *map, bool_t *secure,
unsigned int *first_key_len, char **first_key,
- unsigned int *first_value_len, char **first_value)
+ unsigned int *first_value_len, char **first_value,
+ const char **first_id)
{
struct entry *entries;
if ((entries = map_find_entries(domain, map)) == NULL) {
@@ -233,6 +265,7 @@ map_first(struct plugin_state *state,
*first_key_len = strlen(entries[0].key);
*first_value = entries[0].value;
*first_value_len = strlen(entries[0].value);
+ *first_id = entries[0].id;
return TRUE;
}
@@ -241,7 +274,8 @@ map_next(struct plugin_state *state,
const char *domain, const char *map, bool_t *secure,
unsigned int prev_len, const char *prev,
unsigned int *next_key_len, char **next_key,
- unsigned int *next_value_len, char **next_value)
+ unsigned int *next_value_len, char **next_value,
+ const char **next_id)
{
struct entry *entries;
int i;
@@ -265,5 +299,39 @@ map_next(struct plugin_state *state,
*next_key_len = strlen(entries[i + 1].key);
*next_value = entries[i + 1].value;
*next_value_len = strlen(entries[i + 1].value);
+ *next_id = entries[i + 1].id;
+ return TRUE;
+}
+
+bool_t
+map_next_id(struct plugin_state *state,
+ const char *domain, const char *map, bool_t *secure,
+ const char *prev_id,
+ unsigned int *next_key_len, char **next_key,
+ unsigned int *next_value_len, char **next_value,
+ const char **next_id)
+{
+ struct entry *entries;
+ int i;
+ if ((entries = map_find_entries(domain, map)) == NULL) {
+ return FALSE;
+ }
+ for (i = 0; entries[i].id != NULL; i++) {
+ if (strcmp(entries[i].id, prev_id) == 0) {
+ break;
+ }
+ }
+ if (entries[i].id == NULL) {
+ return FALSE;
+ }
+ if (entries[i + 1].id == NULL) {
+ return FALSE;
+ }
+ *secure = 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);
+ *next_id = entries[i + 1].id;
return TRUE;
}
diff --git a/src/map.c b/src/map.c
index 77cdd49..0e2c190 100644
--- a/src/map.c
+++ b/src/map.c
@@ -367,7 +367,8 @@ map_match(struct plugin_state *state,
const char *domain_name, const char *map_name,
bool_t *secure,
unsigned int key_len, char *key,
- unsigned int *value_len, char **value)
+ unsigned int *value_len, char **value,
+ const char **id)
{
struct map *map;
struct map_entry *entry;
@@ -382,6 +383,35 @@ map_match(struct plugin_state *state,
*secure = map->secure;
*value_len = entry->value_len;
*value = entry->value;
+ *id = entry->id;
+ return TRUE;
+}
+
+bool_t
+map_match_id(struct plugin_state *state,
+ const char *domain_name, const char *map_name,
+ bool_t *secure,
+ const char *in_id,
+ unsigned int *key_len, char **key,
+ unsigned int *value_len, char **value,
+ const char **id)
+{
+ struct map *map;
+ struct map_entry *entry;
+ map = map_data_find_map(state, domain_name, map_name);
+ if (map == NULL) {
+ return FALSE;
+ }
+ entry = map_data_find_map_entry_id(state, map, in_id);
+ if (entry == NULL) {
+ return FALSE;
+ }
+ *secure = map->secure;
+ *key_len = entry->key_len;
+ *key = entry->key;
+ *value_len = entry->value_len;
+ *value = entry->value;
+ *id = entry->id;
return TRUE;
}
@@ -392,7 +422,8 @@ map_first(struct plugin_state *state,
const char *domain_name, const char *map_name,
bool_t *secure,
unsigned int *first_key_len, char **first_key,
- unsigned int *first_value_len, char **first_value)
+ unsigned int *first_value_len, char **first_value,
+ const char **first_id)
{
struct map *map;
struct map_entry *entry;
@@ -409,6 +440,7 @@ map_first(struct plugin_state *state,
*first_key = entry->key;
*first_value_len = entry->value_len;
*first_value = entry->value;
+ *first_id = entry->id;
return TRUE;
}
@@ -420,7 +452,8 @@ map_next(struct plugin_state *state,
const char *domain_name, const char *map_name, bool_t *secure,
unsigned int prev_len, const char *prev,
unsigned int *next_key_len, char **next_key,
- unsigned int *next_value_len, char **next_value)
+ unsigned int *next_value_len, char **next_value,
+ const char **next_id)
{
struct map *map;
struct map_entry *entry;
@@ -437,6 +470,33 @@ map_next(struct plugin_state *state,
*next_key = entry->next->key;
*next_value_len = entry->next->value_len;
*next_value = entry->next->value;
+ *next_id = entry->next->id;
+ return TRUE;
+}
+bool_t
+map_next_id(struct plugin_state *state,
+ const char *domain_name, const char *map_name, bool_t *secure,
+ const char *prev_id,
+ unsigned int *next_key_len, char **next_key,
+ unsigned int *next_value_len, char **next_value,
+ const char **next_id)
+{
+ struct map *map;
+ struct map_entry *entry;
+ map = map_data_find_map(state, domain_name, map_name);
+ if (map == NULL) {
+ return FALSE;
+ }
+ entry = map_data_find_map_entry_id(state, map, prev_id);
+ if ((entry == NULL) || (entry->next == NULL)) {
+ return FALSE;
+ }
+ *secure = map->secure;
+ *next_key_len = entry->next->key_len;
+ *next_key = entry->next->key;
+ *next_value_len = entry->next->value_len;
+ *next_value = entry->next->value;
+ *next_id = entry->next->id;
return TRUE;
}
diff --git a/src/map.h b/src/map.h
index a013b88..e0ae03f 100644
--- a/src/map.h
+++ b/src/map.h
@@ -38,16 +38,30 @@ bool_t map_supports_map(struct plugin_state *state,
bool_t map_match(struct plugin_state *state,
const char *domain, const char *map, bool_t *secure,
unsigned int key_len, char *key,
- unsigned int *value_len, char **value);
+ unsigned int *value_len, char **value, const char **id);
+bool_t map_match_id(struct plugin_state *state,
+ const char *domain, const char *map, bool_t *secure,
+ const char *id_in,
+ unsigned int *key_len, char **key,
+ unsigned int *value_len, char **value,
+ const char **id);
bool_t map_first(struct plugin_state *state,
const char *domain, const char *map, bool_t *secure,
unsigned int *first_key_len, char **first_key,
- unsigned int *first_value_len, char **first_value);
+ unsigned int *first_value_len, char **first_value,
+ const char **id);
bool_t map_next(struct plugin_state *state,
const char *domain, const char *map, bool_t *secure,
unsigned int prev_len, const char *prev,
unsigned int *next_key_len, char **next_key,
- unsigned int *next_value_len, char **next_value);
+ unsigned int *next_value_len, char **next_value,
+ const char **next_id);
+bool_t map_next_id(struct plugin_state *state,
+ const char *domain, const char *map, bool_t *secure,
+ const char *prev_id,
+ unsigned int *next_key_len, char **next_key,
+ unsigned int *next_value_len, char **next_value,
+ const char **next_id);
bool_t map_order(struct plugin_state *state,
const char *domain, const char *map, bool_t *map_secure,
unsigned int *order);