/* Mac-Telnet - Connect to RouterOS routers via MAC address Copyright (C) 2010, Håkon Nessjøen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include "users.h" #include "config.h" struct mt_credentials mt_users[MT_CRED_MAXNUM]; void readUserfile() { FILE *file = fopen(USERSFILE, "r"); unsigned char line [BUFSIZ]; int i = 0; if (file == NULL) { perror(USERSFILE); exit(1); } while ( fgets(line, sizeof line, file) ) { unsigned char *user; unsigned char *password; user = (unsigned char *)strtok(line, ":"); password = (unsigned char *)strtok(NULL, "\n"); if (user == NULL || password == NULL) { continue; } if (user[0] == '#') continue; memcpy(mt_users[i].username, user, strlen(user) < MT_CRED_LEN - 1? strlen(user) : MT_CRED_LEN); memcpy(mt_users[i++].password, password, strlen(password) < MT_CRED_LEN - 1? strlen(password) : MT_CRED_LEN); if (i == MT_CRED_MAXNUM) break; mt_users[i].username[0] = '\0'; } fclose(file); } struct mt_credentials* findUser(unsigned char *username) { int i = 0; while (i < MT_CRED_MAXNUM && mt_users[i].username[0] != 0) { if (strcmp(username, mt_users[i].username) == 0) { return &(mt_users[i]); } i++; } return NULL; }