/* * Remote Laboratory FPGA Server * * 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 3 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. * * (c) 2009 Timothy Pearson * Raptor Engineering * http://www.raptorengineeringinc.com */ #include #include #include #include #include char *MakeMD5String(inString); // Username information struct passwd *pw; uid_t uid; // Configuration stuff static const char filename[] = "/etc/remotefpga_users.conf"; char linedata [256]; // Valid usernames char mdfives [10000][32]; int validateString(char *inputString) { int i; char *current_file_username; char *current_file_md5_hash; time_t mytime; FILE *file = fopen(filename, "r"); if (file != NULL) { char line [256]; // or other suitable maximum line size i=0; // read a line while (fgets(line, sizeof line, file) != NULL) { // Parse the line and update global variables (current line in variable "line") switch (i) { case 0: line[strlen(line)-1]=0; current_file_username = strdup(line); i=1; break; case 1: line[strlen(line)-1]=0; printf("Username: %s\n\rPassword: %s\n\r", current_file_username, line); current_file_username = strcat(current_file_username, line); //mytime = time(); //printf ("%s\n\r", mytime.minute()); current_file_username = strcat(current_file_username, line); printf("Authstring: %s\n\r", current_file_username); printf("MD5: %s\n\r", MakeMD5String(current_file_username)); i=0; break; } } fclose(file); } else { printf("[WARN] Unable to open configuration file %s\n\r", filename); return 1; } return 0; } int main(int argc, char *argv[]) { if (argc < 2) { printf("[FAIL] Invalid argument(s)\n\rOptions:\n\r update \n\r server\n\r"); } else { if ((strcmp(argv[1], "update") == 0) && (argc > 1)) { uid = geteuid(); pw = getpwuid(uid); if (pw) { printf("[INFO] Updating credentials for user %s\n\r", pw->pw_name); } else { printf("[FAIL] Cannot find name for user ID %lu\n\r", (unsigned long int) uid); return 1; } } else if (strcmp(argv[1], "server") == 0) { printf("[INFO] Starting server...\n\r"); validateString("1234"); } else { printf("[FAIL] Invalid argument(s)\n\rOptions:\n\r update \n\r server\n\r"); } } return EXIT_SUCCESS; }