LCOV - code coverage report
Current view: top level - src/utils - ext_password_test.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1443382998 Lines: 34 36 94.4 %
Date: 2015-09-27 Functions: 3 3 100.0 %

          Line data    Source code
       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             : 
       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           8 : static void * ext_password_test_init(const char *params)
      21             : {
      22             :         struct ext_password_test_data *data;
      23             : 
      24           8 :         data = os_zalloc(sizeof(*data));
      25           8 :         if (data == NULL)
      26           0 :                 return NULL;
      27             : 
      28           8 :         if (params)
      29           7 :                 data->params = os_strdup(params);
      30             : 
      31           8 :         return data;
      32             : }
      33             : 
      34             : 
      35           8 : static void ext_password_test_deinit(void *ctx)
      36             : {
      37           8 :         struct ext_password_test_data *data = ctx;
      38             : 
      39           8 :         str_clear_free(data->params);
      40           8 :         os_free(data);
      41           8 : }
      42             : 
      43             : 
      44          12 : static struct wpabuf * ext_password_test_get(void *ctx, const char *name)
      45             : {
      46          12 :         struct ext_password_test_data *data = ctx;
      47             :         char *pos, *pos2;
      48             :         size_t nlen;
      49             : 
      50          12 :         wpa_printf(MSG_DEBUG, "EXT PW TEST: get(%s)", name);
      51             : 
      52          12 :         pos = data->params;
      53          12 :         if (pos == NULL)
      54           1 :                 return NULL;
      55          11 :         nlen = os_strlen(name);
      56             : 
      57          27 :         while (pos && *pos) {
      58          15 :                 if (os_strncmp(pos, name, nlen) == 0 && pos[nlen] == '=') {
      59             :                         struct wpabuf *buf;
      60          10 :                         pos += nlen + 1;
      61          10 :                         pos2 = pos;
      62         217 :                         while (*pos2 != '|' && *pos2 != '\0')
      63         197 :                                 pos2++;
      64          10 :                         buf = ext_password_alloc(pos2 - pos);
      65          10 :                         if (buf == NULL)
      66           0 :                                 return NULL;
      67          10 :                         wpabuf_put_data(buf, pos, pos2 - pos);
      68          10 :                         wpa_hexdump_ascii_key(MSG_DEBUG, "EXT PW TEST: value",
      69             :                                               wpabuf_head(buf),
      70             :                                               wpabuf_len(buf));
      71          10 :                         return buf;
      72             :                 }
      73             : 
      74           5 :                 pos = os_strchr(pos + 1, '|');
      75           5 :                 if (pos)
      76           4 :                         pos++;
      77             :         }
      78             : 
      79           1 :         wpa_printf(MSG_DEBUG, "EXT PW TEST: get(%s) - not found", name);
      80             : 
      81           1 :         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             : };

Generated by: LCOV version 1.10