📄 userconf.cpp
字号:
/**************************************************************************/
/* WIRE1x Version 1.0: A client-side 802.1x implementation */
/* based on xsupplicant of Open1x for Windows XP, 2000, 98, and Me */
/* */
/* 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) 2004, WIRE Lab, National Tsing Hua Univ., Hsinchu, Taiwan*/
/* All Rights Reserved */
/**************************************************************************/
/** * 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. */#include <stdafx.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include "userconf.h"#ifndef DEBUG_USERCONF#define DEBUG_USERCONF 0#endifstruct userconf *user_settings=NULL;void initalize_user_conf(){ user_settings = (struct userconf*)malloc(sizeof(struct userconf)); if (user_settings == NULL) { return; } // Set all of our values to NULL. user_settings->username = NULL; user_settings->user_persist = 0; user_settings->password = NULL; user_settings->root_cert = NULL; user_settings->root_dir = NULL; user_settings->crl_dir = 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; user_settings->phase2auth = NULL;}void clear_user_settings(){ if (user_settings->username != NULL) { free(user_settings->username); user_settings->username = NULL; } if (user_settings->password != NULL) { free(user_settings->password); user_settings->password = NULL; } if (user_settings->root_cert != NULL) { free(user_settings->root_cert); user_settings->root_cert = NULL; } if (user_settings->root_dir != NULL) { free(user_settings->root_dir); user_settings->root_dir = NULL; } if (user_settings->crl_dir != NULL) { free(user_settings->crl_dir); user_settings->crl_dir = NULL; } if (user_settings->client_cert != NULL) { free(user_settings->client_cert); user_settings->client_cert = NULL; } if (user_settings->key_file != NULL) { free(user_settings->key_file); user_settings->key_file = NULL; } if (user_settings->auth != NULL) { free(user_settings->auth); user_settings->auth = NULL; } if (user_settings->preferred_auth != NULL) { free(user_settings->preferred_auth); user_settings->preferred_auth = NULL; } if (user_settings->random_file != NULL) { free(user_settings->random_file); user_settings->random_file = NULL; } if (user_settings->first_auth != NULL) { free(user_settings->first_auth); user_settings->first_auth = NULL; } if (user_settings->after_auth != NULL) { free(user_settings->after_auth); user_settings->after_auth = NULL; } if (user_settings->phase2auth != NULL) { free(user_settings->phase2auth); user_settings->phase2auth = NULL; }}void clean_user_conf(){ clear_user_settings(); free(user_settings);}void str_set1(char *to_set, char *value, char *to_persist, int persist, int maxlen)
{
if (!((to_persist != NULL) && (*to_persist == 1)))
{
if (value != NULL)
{
strncpy(to_set, value, maxlen);
if (to_persist != NULL)
{
*to_persist = persist;
}
}
}
}void str_set(char **to_set, char *value, char *to_persist, int persist){ if (!((to_persist != NULL) && (*to_persist == 1))) { if (value != NULL) { if (*to_set != NULL) { free(*to_set); *to_set = NULL; } *to_set = (char *)malloc(strlen(value)+1); if (*to_set == NULL) { return; } strncpy(*to_set, value, strlen(value)+1); if (to_persist != NULL) *to_persist = persist; } }}char *str_get(char *getval){ char *return_val=NULL; if (getval == NULL) return NULL; return_val = (char *)malloc(strlen(getval)+1); if (return_val == NULL) { return NULL; } strncpy(return_val, getval, strlen(getval)+1); return return_val;}char *get_username(){ return str_get(user_settings->username);}void set_username(char *in_username, char persist){ str_set(&user_settings->username, in_username, &user_settings->user_persist, persist);}char *get_password(){ return str_get(user_settings->password);}void set_password(char *in_password){ str_set(&user_settings->password, in_password, NULL, 0);}char *get_root_cert(){ return str_get(user_settings->root_cert);}void set_root_cert(char *in_root_cert){ str_set(&user_settings->root_cert, in_root_cert, NULL, 0);}char *get_client_cert(){ return str_get(user_settings->client_cert);}void set_client_cert(char *in_client_cert){ str_set(&user_settings->client_cert, in_client_cert, NULL, 0);}char *get_root_dir(){ return str_get(user_settings->root_dir);}void set_root_dir(char *in_root_dir){ str_set(&user_settings->root_dir, in_root_dir, NULL, 0);}char *get_crl_dir(){ return str_get(user_settings->crl_dir);}void set_crl_dir(char *in_crl_dir){ str_set(&user_settings->crl_dir, in_crl_dir, NULL, 0);}char *get_key_file(){ return str_get(user_settings->key_file);}void set_key_file(char *in_key_file){ str_set(&user_settings->key_file, in_key_file, NULL, 0);}char *get_auth(){ return str_get(user_settings->auth);}void set_auth(char *in_auth){ str_set(&user_settings->auth, in_auth, NULL, 0);}char *get_preferred_auth(){ return str_get(user_settings->preferred_auth);}// 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) { // 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]); } str_set(&user_settings->preferred_auth, in_preferred_auth, NULL, 0); }}char *get_client_type(){ return str_get(user_settings->client_type);}void set_client_type(char *in_client_type){ int i=0; char *tempstr; if (in_client_type != NULL) { tempstr = (char *)malloc(strlen(in_client_type)+1); if (tempstr == NULL) { return; } strncpy(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]); } str_set(&user_settings->client_type, tempstr, NULL, 0); free(tempstr); tempstr = NULL; }}int get_chunk_size(){ return user_settings->chunk_size;}void set_chunk_size(int new_size){ if (new_size<=0) { return; } user_settings->chunk_size = new_size;}char *get_random_file(){ return str_get(user_settings->random_file);}void set_random_file(char *new_random_file){ str_set(&user_settings->random_file, new_random_file, NULL, 0);}char *get_first_auth(){ return str_get(user_settings->first_auth);}void set_first_auth(char *new_first_auth){ str_set(&user_settings->first_auth, new_first_auth, NULL, 0);}char *get_after_auth(){ return str_get(user_settings->after_auth);}void set_after_auth(char *new_after_auth){ str_set(&user_settings->after_auth, new_after_auth, NULL, 0);}char *get_phase2auth(){ return str_get(user_settings->phase2auth);}void set_phase2auth(char *new_phase2auth){ str_set(&user_settings->phase2auth, new_phase2auth, NULL, 0);}char *get_phase2id(){ char *phase2_id_ret; phase2_id_ret = str_get(user_settings->phase2id); if (phase2_id_ret == NULL) return str_get(user_settings->username); // Otherwise, go ahead and return the "correct" value. return phase2_id_ret;}void set_phase2id(char *new_phase2id){ str_set1((char *)&user_settings->phase2id, new_phase2id, NULL, 0, 255);}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("phase2 auth: %s\n", get_phase2auth()); printf("-------------------------------\n");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -