/** * A client-side 802.1x implementation supporting EAP/TLS * * This code is released under both the GPL version 2 and BSD licenses. * Either license may be used. The respective licenses are found below. * * Copyright (C) 2002 Bryan D. Payne & Nick L. Petroni Jr. * All Rights Reserved * * --- GPL Version 2 License --- * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * --- BSD License --- * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * Maryland at College Park and its contributors. * - Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /******************************************************************* * The driver function for a Linux application layer EAPOL * implementation * File: userconf.c * * Authors: Chris.Hessing@utah.edu, Terry.Simons@utah.edu * * $Id: userconf.c,v 1.7 2003/03/13 22:31:11 chessing Exp $ * $Date: 2003/03/13 22:31:11 $ * $Log: userconf.c,v $ * Revision 1.7 2003/03/13 22:31:11 chessing * Another attempt at the wired/wireless fix. * * Revision 1.6 2003/03/04 06:10:08 npetroni * changes to allow a program to be run after successful authentication * * Revision 1.5 2003/03/01 06:55:39 npetroni * modified config parse to use lex and yacc for parsing. this may break stuff temporarily, but is good in the long run * * Revision 1.4 2003/01/14 23:52:07 chessing * More work on the TLS code. It should be mostly stable now. There is a problem if get_pass("") in eaptls_auth_challenge is called twice. * * Revision 1.3 2003/01/09 21:01:58 galimorerpg * Logging Updates and Build Fixes. * * Revision 1.2 2003/01/03 22:25:35 chessing * Turned off debugging code, (use the configure options to turn on the debugging) and added -w option to get around some problems with the Intel iANS drivers, and some wired/wireless issues with the MacOS-X wireless code. * * Revision 1.1 2003/01/02 19:29:37 chessing * Update to bring the xsupplicant code current with the development work. * * *******************************************************************/ #include #include #include #include #include "userconf.h" #include "logging.h" #ifndef DEBUG_USERCONF #define DEBUG_USERCONF 0 #endif struct userconf *user_settings=NULL; void initalize_user_conf() { user_settings = (struct userconf*)malloc(sizeof(struct userconf)); // Set all of our values to NULL. user_settings->username = NULL; user_settings->password = NULL; user_settings->root_cert = NULL; user_settings->client_cert = NULL; user_settings->key_file = NULL; user_settings->auth = NULL; user_settings->preferred_auth = NULL; user_settings->client_type = NULL; user_settings->chunk_size = 1398; // EAPTLS_MAX_SIZE from older code. user_settings->random_file = NULL; user_settings->first_auth = NULL; user_settings->after_auth = NULL; #if DEBUG_USERCONF xlogf(DEBUG_CONFIG, "initalize_user_conf() finished!\n"); if (user_settings == NULL) xlogf(DEBUG_CONFIG, "user_settings returned NULL!!!!!!\n"); #endif } void clean_user_conf() { if (user_settings->username != NULL) free(user_settings->username); if (user_settings->password != NULL) free(user_settings->password); if (user_settings->root_cert != NULL) free(user_settings->root_cert); if (user_settings->client_cert != NULL) free(user_settings->client_cert); if (user_settings->key_file != NULL) free(user_settings->key_file); if (user_settings->auth != NULL) free(user_settings->auth); if (user_settings->preferred_auth != NULL) free(user_settings->preferred_auth); if (user_settings->random_file != NULL) free(user_settings->random_file); if (user_settings->first_auth != NULL) free(user_settings->first_auth); if (user_settings->after_auth != NULL) free(user_settings->after_auth); free(user_settings); #if DEBUG_USERCONF xlogf(DEBUG_CONFIG, "clean_user_conf() called!\n"); #endif } char *get_username() { char *return_val; if (user_settings->username == NULL) return NULL; return_val = (char *)malloc(strlen(user_settings->username)+1); strncpy(return_val, user_settings->username, strlen(user_settings->username)+1); return return_val; } void set_username(char *in_username) { if (in_username != NULL) { if (user_settings->username != NULL) { free(user_settings->username); user_settings->username = NULL; } user_settings->username = (char *)malloc(strlen(in_username)+1); strncpy(user_settings->username, in_username, strlen(in_username)+1); /* free(in_username); in_username = NULL;*/ } else { #if DEBUG_USERCONF xlogf(DEBUG_CONFIG, "Username value was set to NULL!\n"); #endif } } char *get_password() { char *return_val; if (user_settings->password == NULL) return NULL; return_val = (char *)malloc(strlen(user_settings->password)+1); strncpy(return_val, user_settings->password, strlen(user_settings->password)+1); return return_val; } void set_password(char *in_password) { if (in_password != NULL) { if (user_settings->password != NULL) { free(user_settings->password); user_settings->password = NULL; } user_settings->password = (char *)malloc(strlen(in_password)+1); strncpy(user_settings->password, in_password, strlen(in_password)+1); /* free(in_password); in_password = NULL;*/ } else { #if DEBUG_USERCONF xlogf(DEBUG_CONFIG, "Password was passed in as NULL!\n"); #endif } } char *get_root_cert() { char *return_val; if (user_settings->root_cert == NULL) return NULL; return_val = (char *)malloc(strlen(user_settings->root_cert)+1); strncpy(return_val, user_settings->root_cert, strlen(user_settings->root_cert)+1); return return_val; } void set_root_cert(char *in_root_cert) { if (in_root_cert != NULL) { if (user_settings->root_cert != NULL) { free(user_settings->root_cert); user_settings->root_cert = NULL; } user_settings->root_cert = (char *)malloc(strlen(in_root_cert)+1); strncpy(user_settings->root_cert, in_root_cert, strlen(in_root_cert)+1); /* free(in_root_cert); in_root_cert = NULL;*/ } else { #if DEBUG_USERCONF xlogf(DEBUG_CONFIG, "Root cert value was passed in as NULL!\n"); #endif } } char *get_client_cert() { char *return_val; if (user_settings->client_cert == NULL) return NULL; return_val = (char *)malloc(strlen(user_settings->client_cert)+1); strncpy(return_val, user_settings->client_cert, strlen(user_settings->client_cert)+1); return return_val; } void set_client_cert(char *in_client_cert) { if (in_client_cert != NULL) { if (user_settings->client_cert != NULL) { free(user_settings->client_cert); user_settings->client_cert = NULL; } user_settings->client_cert = (char *)malloc(strlen(in_client_cert)+1); strncpy(user_settings->client_cert, in_client_cert, strlen(in_client_cert)+1); /* free(in_client_cert); in_client_cert = NULL;*/ } else { #if DEBUG_USERCONF xlogf(DEBUG_CONFIG, "Client cert value was NULL!\n"); #endif } } char *get_key_file() { char *return_val; if (user_settings->key_file == NULL) return NULL; return_val = (char *)malloc(strlen(user_settings->key_file)+1); strncpy(return_val, user_settings->key_file, strlen(user_settings->key_file)+1); return return_val; } void set_key_file(char *in_key_file) { if (in_key_file != NULL) { if (user_settings->key_file != NULL) { free(user_settings->key_file); user_settings->key_file = NULL; } user_settings->key_file = (char *)malloc(strlen(in_key_file)+1); strncpy(user_settings->key_file, in_key_file, strlen(in_key_file)+1); /*free(in_key_file); in_key_file = NULL;*/ } else { #if DEBUG_USERCONF xlogf(DEBUG_CONFIG, "Key file value was set to NULL!\n"); #endif } } char *get_auth() { char *return_val; if (user_settings->auth == NULL) return NULL; return_val = (char *)malloc(strlen(user_settings->auth)+1); strncpy(return_val, user_settings->auth, strlen(user_settings->auth)+1); return return_val; } void set_auth(char *in_auth) { if (in_auth != NULL) { if (user_settings->auth != NULL) { free(user_settings->auth); user_settings->auth = NULL; } user_settings->auth = (char *)malloc(strlen(in_auth)+1); strncpy(user_settings->auth, in_auth, strlen(in_auth)+1); /* free(in_auth); in_auth = NULL;*/ } else { #if DEBUG_USERCONF xlogf(DEBUG_CONFIG, "Auth value was NULL!\n"); #endif } } char *get_preferred_auth() { char *return_val; if (user_settings->preferred_auth == NULL) return NULL; return_val = (char *)malloc(strlen(user_settings->preferred_auth)+1); strncpy(return_val, user_settings->preferred_auth, strlen(user_settings->preferred_auth)+1); return return_val; } // We need to read the string in and set it to upper case. void set_preferred_auth(char *in_preferred_auth) { int i=0; if (in_preferred_auth != NULL) { if (user_settings->preferred_auth != NULL) { free(user_settings->preferred_auth); user_settings->preferred_auth = NULL; } // Make sure the value we are passed is in all CAPS! for (i=0; i<=strlen(in_preferred_auth); i++) { in_preferred_auth[i] = toupper(in_preferred_auth[i]); } user_settings->preferred_auth = (char *)malloc(strlen(in_preferred_auth)+1); strncpy(user_settings->preferred_auth, in_preferred_auth, strlen(in_preferred_auth)+1); /*free(in_preferred_auth); in_preferred_auth = NULL;*/ } else { #if DEBUG_USERCONF xlogf(DEBUG_CONFIG, "Preferred Authentication method was NULL!\n"); #endif } } char *get_client_type() { char *return_val; if (user_settings->client_type == NULL) return NULL; return_val = (char *)malloc(strlen(user_settings->client_type)+1); strncpy(return_val, user_settings->client_type, strlen(user_settings->client_type)+1); return return_val; } void set_client_type(char *in_client_type) { int i=0; char *tempstr; if (in_client_type != NULL) { if (user_settings->client_type != NULL) { free(user_settings->client_type); user_settings->client_type = NULL; } tempstr = (char *)malloc(strlen(in_client_type)+1); memcpy(tempstr, in_client_type, strlen(in_client_type)+1); // Make sure the value we are passed is in all CAPS! for (i=0; i<=strlen(tempstr); i++) { tempstr[i] = toupper(tempstr[i]); } user_settings->client_type = (char *)malloc(strlen(tempstr)+1); strncpy(user_settings->client_type, tempstr, strlen(tempstr)+1); free(tempstr); } else { #if DEBUG_USERCONF xlogf(DEBUG_CONFIG, "Client Type value was set to NULL!\n"); #endif } } int get_chunk_size() { return user_settings->chunk_size; } void set_chunk_size(int new_size) { if (new_size<=0) { xlogf(DEBUG_CONFIG, "Chunk size must be greater than 0!\n"); return; } user_settings->chunk_size = new_size; } char *get_random_file() { char *return_val; static char *default_file = "/dev/random"; if (user_settings->random_file == NULL) return default_file; return_val = (char *)malloc(strlen(user_settings->random_file)+1); strncpy(return_val, user_settings->random_file, strlen(user_settings->random_file)+1); return return_val; } void set_random_file(char *new_random_file) { if (new_random_file != NULL) { if (user_settings->random_file != NULL) { free(user_settings->random_file); user_settings->random_file = NULL; } user_settings->random_file = (char *)malloc(strlen(new_random_file)+1); strncpy(user_settings->random_file, new_random_file, strlen(new_random_file)+1); } else { #if DEBUG_USERCONF xlogf(DEBUG_CONFIG, "Preferred Authentication method was NULL!\n"); #endif } } char *get_first_auth() { char *return_val; if (user_settings->first_auth == NULL) return NULL; return_val = (char *)malloc(strlen(user_settings->first_auth)+1); strncpy(return_val, user_settings->first_auth, strlen(user_settings->first_auth)+1); return return_val; } void set_first_auth(char *new_first_auth) { if (new_first_auth != NULL) { if (user_settings->first_auth != NULL) { free(user_settings->first_auth); user_settings->first_auth = NULL; } user_settings->first_auth = (char *)malloc(strlen(new_first_auth)+1); strncpy(user_settings->first_auth, new_first_auth, strlen(new_first_auth)+1); } else { #if DEBUG_USERCONF xlogf(DEBUG_CONFIG, "Preferred Authentication method was NULL!\n"); #endif } } char *get_after_auth() { char *return_val; if (user_settings->after_auth == NULL) return NULL; return_val = (char *)malloc(strlen(user_settings->after_auth)+1); strncpy(return_val, user_settings->after_auth, strlen(user_settings->after_auth)+1); return return_val; } void set_after_auth(char *new_after_auth) { if (new_after_auth != NULL) { if (user_settings->after_auth != NULL) { free(user_settings->after_auth); user_settings->after_auth = NULL; } user_settings->after_auth = (char *)malloc(strlen(new_after_auth)+1); strncpy(user_settings->after_auth, new_after_auth, strlen(new_after_auth)+1); } else { #if DEBUG_USERCONF xlogf(DEBUG_CONFIG, "Preferred Authentication method was NULL!\n"); #endif } } void print_userconf() { printf("--Printing user configuration--\n"); printf("username: %s\n", get_username()); printf("root cert: %s\n", get_root_cert()); printf("client cert: %s\n", get_client_cert()); printf("key file: %s\n", get_key_file()); printf("auth type: %s\n", get_auth()); printf("preferred auth: %s\n", get_preferred_auth()); printf("client type: %s\n", get_client_type()); printf("chunk size: %d\n", get_chunk_size()); printf("random file: %s\n", get_random_file()); printf("first auth: %s\n", get_first_auth()); printf("after auth: %s\n", get_after_auth()); printf("-------------------------------\n"); }