ext_password_test.c 1.7 KB

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