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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 * Copyright 2006 The FreeRADIUS server project
30 #include <freeradius-devel/ident.h>
40 #include "eap_psk_ssm.h"
41 #include "eap_psk.h" //hex2Bin()
45 userinfo_t* pskGetUserInfo(char* path, char* peerID)
48 char buff[1024]; //FIXME: give the buffer a proper size
49 //when we know more about ID length
50 userinfo_t* uinfo = NULL;
56 fp = fopen(path, "r");
59 radlog(L_ERR, "pskGetUserInfo: failed to open PSK users file");
63 while (!found && fgets(buff, sizeof(buff), fp))
71 // read this login name
72 while (! isspace(buff[i]))
75 // is it the one we looking for?
76 if ((i != strlen(peerID))
77 || (strncmp(peerID, buff, i) != 0))
83 while (isspace(buff[i]))
86 // prepare to store user info
87 uinfo = (userinfo_t*) malloc(sizeof(userinfo_t));
90 radlog(L_ERR, "pskGetUserInfo: out of memory");
95 AK = strndup(buff + i, PSK_AK_STRLEN);
97 radlog(L_ERR, "pskGetUserInfo: out of memory");
101 //FIXME: shouldnt we check the key size?
103 else if (strlen(AK) != 32) {
108 res=pskHex2Bin(AK, &(uinfo->AK),PSK_AK_SIZE);
112 radlog(L_ERR, "pskGetUserInfo: the key isn't in hexadecimal format");
119 KDK = strndup(buff + i + PSK_AK_STRLEN, PSK_KDK_STRLEN);
121 radlog(L_ERR, "psk_get_user_info: out of memory");
126 //FIXME: shouldnt we check the key size?
128 else if (strlen(KDK) != 32) {
133 res=pskHex2Bin(KDK, &(uinfo->KDK),PSK_KDK_SIZE);
137 radlog(L_ERR, "pskGetUserInfo: the key isn't in hexadecimal format");
149 // if user was not found, NULL is returned