7 * Implementation of the user management
10 * Copyright (C) France Télécom R&D (DR&D/MAPS/NSS)
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 #include "eap_psk_ssm.h"
37 #include "eap_psk.h" //hex2Bin()
41 userinfo_t* pskGetUserInfo(char* path, char* peerID)
44 char buff[1024]; //FIXME: give the buffer a proper size
45 //when we know more about ID length
46 userinfo_t* uinfo = NULL;
52 fp = fopen(path, "r");
55 radlog(L_ERR, "pskGetUserInfo: failed to open PSK users file");
59 while (!found && fgets(buff, sizeof(buff), fp))
67 // read this login name
68 while (! isspace(buff[i]))
71 // is it the one we looking for?
72 if ((i != strlen(peerID))
73 || (strncmp(peerID, buff, i) != 0))
79 while (isspace(buff[i]))
82 // prepare to store user info
83 uinfo = (userinfo_t*) malloc(sizeof(userinfo_t));
86 radlog(L_ERR, "pskGetUserInfo: out of memory");
91 AK = strndup(buff + i, PSK_AK_STRLEN);
93 radlog(L_ERR, "pskGetUserInfo: out of memory");
97 //FIXME: shouldnt we check the key size?
99 else if (strlen(AK) != 32) {
104 res=pskHex2Bin(AK, &(uinfo->AK),PSK_AK_SIZE);
108 radlog(L_ERR, "pskGetUserInfo: the key isn't in hexadecimal format");
115 KDK = strndup(buff + i + PSK_AK_STRLEN, PSK_KDK_STRLEN);
117 radlog(L_ERR, "psk_get_user_info: out of memory");
122 //FIXME: shouldnt we check the key size?
124 else if (strlen(KDK) != 32) {
129 res=pskHex2Bin(KDK, &(uinfo->KDK),PSK_KDK_SIZE);
133 radlog(L_ERR, "pskGetUserInfo: the key isn't in hexadecimal format");
145 // if user was not found, NULL is returned