1 /* 2 * External password backend 3 * Copyright (c) 2012, Jouni Malinen <j (at) w1.fi> 4 * 5 * This software may be distributed under the terms of the BSD license. 6 * See README for more details. 7 */ 8 9 #include "includes.h" 10 11 #include "common.h" 12 #include "ext_password_i.h" 13 14 15 struct ext_password_test_data { 16 char *params; 17 }; 18 19 20 static void * ext_password_test_init(const char *params) 21 { 22 struct ext_password_test_data *data; 23 24 data = os_zalloc(sizeof(*data)); 25 if (data == NULL) 26 return NULL; 27 28 if (params) 29 data->params = os_strdup(params); 30 31 return data; 32 } 33 34 35 static void ext_password_test_deinit(void *ctx) 36 { 37 struct ext_password_test_data *data = ctx; 38 39 os_free(data->params); 40 os_free(data); 41 } 42 43 44 static struct wpabuf * ext_password_test_get(void *ctx, const char *name) 45 { 46 struct ext_password_test_data *data = ctx; 47 char *pos, *pos2; 48 size_t nlen; 49 50 wpa_printf(MSG_DEBUG, "EXT PW TEST: get(%s)", name); 51 52 pos = data->params; 53 if (pos == NULL) 54 return NULL; 55 nlen = os_strlen(name); 56 57 while (pos && *pos) { 58 if (os_strncmp(pos, name, nlen) == 0 && pos[nlen] == '=') { 59 struct wpabuf *buf; 60 pos += nlen + 1; 61 pos2 = pos; 62 while (*pos2 != '|' && *pos2 != '\0') 63 pos2++; 64 buf = ext_password_alloc(pos2 - pos); 65 if (buf == NULL) 66 return NULL; 67 wpabuf_put_data(buf, pos, pos2 - pos); 68 wpa_hexdump_ascii_key(MSG_DEBUG, "EXT PW TEST: value", 69 wpabuf_head(buf), 70 wpabuf_len(buf)); 71 return buf; 72 } 73 74 pos = os_strchr(pos + 1, '|'); 75 if (pos) 76 pos++; 77 } 78 79 wpa_printf(MSG_DEBUG, "EXT PW TEST: get(%s) - not found", name); 80 81 return NULL; 82 } 83 84 85 const struct ext_password_backend ext_password_test = { 86 .name = "test", 87 .init = ext_password_test_init, 88 .deinit = ext_password_test_deinit, 89 .get = ext_password_test_get, 90 }; 91