summaryrefslogtreecommitdiff
path: root/src/lib/keytab.c
diff options
context:
space:
mode:
authorbpc2003 <wpesfriendnva@gmail.com>2025-04-16 15:54:36 -0400
committerbpc2003 <wpesfriendnva@gmail.com>2025-04-16 15:54:36 -0400
commit525b5b126bae74aa9817dc191beec81714701965 (patch)
treea830eab2179cb19f04bef15c63226ac77aff0f9f /src/lib/keytab.c
parent44fa7d3682ff4e102bb7a228e9e5a100a050fea5 (diff)
Allow getkeys to take multiple keys as argument
Diffstat (limited to 'src/lib/keytab.c')
-rw-r--r--src/lib/keytab.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/src/lib/keytab.c b/src/lib/keytab.c
index c8b1f75..425b0e1 100644
--- a/src/lib/keytab.c
+++ b/src/lib/keytab.c
@@ -8,19 +8,31 @@ static int hash(char *key);
static char **getkv(char *pair);
// getkeys - gets every single key in a key table
-int *getkeys(tablist_t *list, int id)
+tabidx_t *getkeys(tablist_t *list, int id, char **keys, int klen)
{
- int len = 2;
+ int len = 1;
if (id >= list[0].len)
return NULL;
- int *indexes = calloc(len, sizeof(int));
- for (int i = 0, j = 0; i < TABLEN; ++i) {
- if (j >= len) {
- indexes = realloc(indexes, ++len * sizeof(int));
- indexes[len - 1] = 0;
+ tabidx_t *indexes = calloc(len, sizeof(tabidx_t));
+ if (klen == 0) {
+ for (int i = 0, j = 0; i < TABLEN; ++i) {
+ if (j >= len) {
+ indexes = realloc(indexes, ++len * sizeof(tabidx_t));
+ indexes[len - 1] = (tabidx_t) { NULL, 0, { 0 } };
+ }
+ if (list[id].tab[i].flag)
+ indexes[j++] = list[id].tab[i];
+ }
+ } else {
+ for (int i = 0, j = 0; i < klen; ++i) {
+ tabidx_t idx = getkey(list, id, keys[i]);
+ if (idx.flag == 0)
+ return NULL;
+ if (j >= len) {
+ indexes = realloc(indexes, ++len * sizeof(tabidx_t));
+ }
+ indexes[j++] = idx;
}
- if (list[id].tab[i].key)
- indexes[j++] = i;
}
return indexes;
}