📄 xsupconfig.c
字号:
default:
case EAP_TYPE_MD5:
case EAP_TYPE_GTC:
case EAP_TYPE_LEAP:
case EAP_TYPE_OTP:
case EAP_TYPE_TLS:
case EAP_TYPE_SIM:
case EAP_TYPE_AKA:
case EAP_TYPE_MSCHAPV2:
return NULL; // No inner username here.
break;
}
return NULL;
}
/**
* \brief Clean up any memory that we have used to store the configuration information.
**/
void config_destroy()
{
TRACE
/* see if there really is something to cleanup */
xsupconfig_devices_deinit(&conf_devices);
delete_config_data();
}
//****************************************
// CONFIG QUERIES
//****************************************
/**
* \brief Go through the profiles that we read from the configuration
* file, and locate the one named 'profile_name'.
*
* @param[in] profile_name The name of the profile to locate.
*
* \retval ptr A pointer to the structure that contains the profile
* requested by 'profile_name'.
* \retval NULL The profile does not exist.
*
* \warning Do NOT free the resulting structure! It is part of the
* master linked list of profiles. Freeing it will cause
* bad things to happen!
**/
struct config_profiles *config_find_profile(char *profile_name)
{
struct config_profiles *cur;
// There was a request to find nothing, so return nothing.
if (profile_name == NULL) return NULL;
debug_printf(DEBUG_CONFIG_PARSE, "Looking for profile '%s'!\n",
profile_name);
cur = conf_profiles;
while ((cur != NULL) && (strcmp(cur->name, profile_name) != 0)) cur = cur->next;
return cur;
}
//**********************************************
// Private functions for config parsing. Do
// not call these from outside config code
//**********************************************
/********************/
/* CONFIG_TNC */
/********************/
/**
* \brief Clean up the memory used by the TNC portion of a
* configuration.
*
* @param[in] tmp_tnc A double dereferenced pointer to the TNC
* data stored in memory.
**/
void delete_config_eap_tnc(struct config_eap_tnc **tmp_tnc)
{
free(*tmp_tnc);
*tmp_tnc = NULL;
}
/**
* \brief Dump to the screen, all of the information that is stored
* in the TNC structure.
*
* @param[in] tmp_tnc A pointer to the structure that contains the TNC
* information.
**/
void dump_config_eap_tnc(struct config_eap_tnc *tmp_tnc)
{
if (!tmp_tnc)
return;
printf("\t\t^ ^ ^ ^ ^ ^ eap-tnc ^ ^ ^ ^\n");
printf("\t\t Fragment Size : %d\n", tmp_tnc->frag_size);
printf("\t\t^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^\n");
}
/*******************/
/* CONFIG_FAST */
/*******************/
/**
* \brief Free all memory that was used to store the configuration
* for EAP-FAST.
*
* @param[in] tmp_fast A double dereferenced pointer to the configuration
* information that is stored in memory.
**/
void delete_config_eap_fast(struct config_eap_fast **tmp_fast)
{
if (*tmp_fast == NULL)
return;
FREE_STRING((*tmp_fast)->pac_location);
FREE_STRING((*tmp_fast)->innerid);
free (*tmp_fast);
*tmp_fast = NULL;
}
/**
* \brief Dump to the screen, all of the configuration information
* stored in memory about EAP-FAST.
*
* @param[in] fast A pointer to the structure that contains all of the
* information about EAP-FAST.
**/
void dump_config_eap_fast(struct config_eap_fast *fast)
{
if (!fast)
return;
printf("\t---------------eap-fast-------------\n");
printf("\t PAC File: \"%s\"\n", fast->pac_location);
printf("\t TLS Chunk Size: %d\n", fast->chunk_size);
printf("\t Provisioning: ");
switch (fast->provision)
{
case RES_UNSET:
printf("UNSET\n");
break;
case RES_YES:
printf("YES\n");
break;
case RES_NO:
printf("NO\n");
break;
}
printf("\t Inner ID: %s\n", fast->innerid);
if (fast->phase2) dump_config_eap_method(fast->phase2, 1);
printf("\t------------------------------------\n");
}
/**
* \brief Dump to the screen, all of the information in memory about
* EAP-OTP.
*
* Because EAP-OTP doesn't contain any configuration information, we
* will simply print a blank set of headers, so that caller knows that
* we are aware that we should use OTP.
*
* @param[in] otp A pointer to the structure that contains all of the
* configuration information to be used with OTP.
*
* @param[in] dumplevel The phase that OTP will be used in. This allows
* the function to know how far to indent the output.
**/
void dump_config_eap_otp(struct config_pwd_only *otp, int dumplevel)
{
if (!otp)
return;
if (dumplevel == 0)
{
printf("\t--------------eap-otp---------------\n");
printf("\t------------------------------------\n");
}
else
{
printf("\t^ ^ ^ ^ ^ eap-otp ^ ^ ^ ^ ^ ^\n");
printf("\t^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^\n");
}
}
/*******************/
/* CONFIG_TLS */
/*******************/
/* take a pointer to a config_eap_tls and cleanly delete the structure
then make it NULL */
/**
* \brief Clear out all of the information that is currently in memory
* that relates to EAP-TLS.
*
* @param[in] tmp_tls A double dereferenced pointer to the configuration
* structure that contains all of the configuration
* information about EAP-TLS.
**/
void delete_config_eap_tls(struct config_eap_tls **tmp_tls)
{
if (*tmp_tls == NULL)
return;
FREE_STRING((*tmp_tls)->user_cert);
FREE_STRING((*tmp_tls)->crl_dir);
FREE_STRING((*tmp_tls)->user_key);
FREE_STRING((*tmp_tls)->user_key_pass);
FREE_STRING((*tmp_tls)->random_file);
FREE_STRING((*tmp_tls)->sc.engine_id);
FREE_STRING((*tmp_tls)->sc.opensc_so_path);
FREE_STRING((*tmp_tls)->sc.key_id);
FREE_STRING((*tmp_tls)->trusted_server);
free (*tmp_tls);
*tmp_tls = NULL;
}
/**
* \brief Dump to the screen, all the configuration information
* in memory about EAP-TLS.
*
* @param[in] tls A pointer to a structure that contains the configuration
* information that is needed to use EAP-TLS.
**/
void dump_config_eap_tls(struct config_eap_tls *tls)
{
if (!tls)
return;
printf("\t---------------eap-tls--------------\n");
printf("\t TLS Cert: \"%s\"\n", tls->user_cert);
printf("\t TLS CRL Dir: \"%s\"\n", tls->crl_dir);
printf("\t TLS Key: \"%s\"\n", tls->user_key);
printf("\t TLS Key Pass: \"%s\"\n", tls->user_key_pass);
printf("\t TLS Chunk Size: %d\n", tls->chunk_size);
printf("\t TLS Random Source: \"%s\"\n",
tls->random_file);
printf("\t TLS Session Resumption: ");
switch (tls->session_resume)
{
case RES_UNSET:
printf("UNSET\n");
break;
case RES_YES:
printf("YES\n");
break;
case RES_NO:
printf("NO\n");
break;
}
printf("\t Using Smartcard:\n");
printf("\t\tEngine : \"%s\"\n", tls->sc.engine_id);
printf("\t\tOpensc SO_PATH: \"%s\"\n", tls->sc.opensc_so_path);
printf("\t\tKey ID : \"%s\"\n", tls->sc.key_id);
//printf("\t\tCertificate ID: \"%s\"", tls.sc->cert_id);
//printf("\t\tRoot Cert ID : \"%s\"", tls.sc->root_id);
printf("\t------------------------------------\n");
}
/*******************/
/* CONFIG_PWD_ONLY */
/*******************/
/**
* \brief Clean up memory for methods that only have a password,
* and use the config_pwd_only structure.
*
* @param[in] tmp_pwd A pointer to a structure that contains a
* password.
**/
void delete_config_pwd_only(struct config_pwd_only **tmp_pwd)
{
if (*tmp_pwd == NULL)
return;
FREE_STRING((*tmp_pwd)->password);
free (*tmp_pwd);
*tmp_pwd = NULL;
}
/**
* \brief Dump to the screen, the password stored in the config_pwd_only
* structure.
*
* @param[in] pwd A pointer to a structure that contains the password to dump.
* @param[in] method A string that identifies the EAP method that we are dumpping
* the password for.
* @param[in] level The phase that the password is used in. This allows the
* output to be indented correctly in the output.
**/
void dump_config_pwd_only(struct config_pwd_only *pwd, char *method, int level)
{
if (pwd == NULL) return;
if (level == 0) {
printf("\t---------------%s--------------\n", method);
printf("\t %s Pass: \"%s\"\n", method, pwd->password);
printf("\t------------------------------------\n");
}else {
printf("\t\t^ ^ ^ %s ^ ^ ^\n", method);
printf("\t\t %s Pass: \"%s\"\n", method, pwd->password);
printf("\t\t^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^\n");
}
}
/*******************/
/* CONFIG_TTLS */
/*******************/
//-------------
// TTLS_PHASE2
//------------
/**
* \brief Clean up the memory used by phase 2 TTLS-EAP.
*
* @param[in] eapdata A double dereferenced pointer to a
* structure that contains information about the
* configuration of an EAP method.
**/
void delete_config_ttls_eap(struct config_eap_method **eapdata)
{
struct config_eap_method *tmp, *next;
if (eapdata == NULL)
{
printf("%s() was passed a NULL pointer!\n", __FUNCTION__);
return;
}
tmp = (*eapdata);
if (tmp == NULL) return;
while (tmp != NULL)
{
next = tmp->next;
delete_config_eap_method(&tmp);
tmp = next;
}
}
/**
* \brief Clear the phase 2 configuration from memory.
*
* @param[in] ttls A pointer to a structure that contains configuration
* information for EAP-TTLS. This information will also
* include the information we need to know to free the
* phase 2 method(s).
**/
void delete_config_ttls_phase2 (struct config_eap_ttls *ttls)
{
if (ttls == NULL)
return;
switch (ttls->phase2_type) {
case TTLS_PHASE2_PAP:
delete_config_pwd_only((struct config_pwd_only **)&ttls->phase2_data);
break;
case TTLS_PHASE2_CHAP:
delete_config_pwd_only((struct config_pwd_only **)&ttls->phase2_data);
break;
case TTLS_PHASE2_MSCHAP:
delete_config_pwd_only((struct config_pwd_only **)&ttls->phase2_data);
break;
case TTLS_PHASE2_MSCHAPV2:
delete_config_pwd_only((struct config_pwd_only **)&ttls->phase2_data);
break;
case TTLS_PHASE2_EAP:
delete_config_ttls_eap((struct config_eap_method **)&ttls->phase2_data);
break;
default:
printf("AAAH! Trying to delete an undefined config"
" type in %s.\nNotify developers. Type: 0x%x\n",
__FUNCTION__, ttls->phase2_type);
}
}
/**
* \brief Dump to the screen, all of the information about EAP methods that
* are configured to be used for phase 2 in EAP-TTLS.
*
* @param[in] phase2 A pointer to the phase 2 structure that contains
* information about the EAP types to clear out of
* memory.
**/
void dump_config_ttls_eap(struct config_eap_method *phase2)
{
struct config_eap_method *tmp;
tmp = phase2;
while (tmp != NULL)
{
switch(tmp->method_num)
{
case EAP_TYPE_MD5:
dump_config_pwd_only((struct config_pwd_only *)tmp->method_data,
"EAP-MD5", 2);
break;
case EAP_TYPE_TNC:
dump_config_eap_tnc((struct config_eap_tnc *)tmp->method_data);
break;
default:
printf("Unknown TTLS phase 2 EAP method. (%d)\n", tmp->method_num);
break;
}
tmp = tmp->next;
}
}
/**
* \brief Dump to the screen, all of the information we know about
* the configuration of phase 2 authentication for EAP-TTLS.
*
* @param[in] ttls A pointer to a structure that contains information
* about the configuration of EAP-TTLS. This structure
* will also contain the information needed to know how
* to dump the phase 2 information.
**/
void dump_config_ttls_phase2(struct config_eap_ttls *ttls)
{
if (ttls == NULL)
return;
switch (ttls->phase2_type) {
case TTLS_PHASE2_PAP:
dump_config_pwd_only((struct config_pwd_only *)ttls->phase2_data,
"EAP-TTLS-PAP", 2);
break;
case TTLS_PHASE2_CHAP:
dump_config_pwd_only((struct config_pwd_only *)ttls->phase2_data,
"EAP-TTLS-CHAP", 2);
break;
case TTLS_PHASE2_MSCHAP:
dump_config_pwd_only((struct config_pwd_only *)ttls->phase2_data,
"EAP-TTLS-MSCHAP", 2);
break;
case TTLS_PHASE2_MSCHAPV2:
dump_config_pwd_only((struct config_pwd_only *)ttls->phase2_data,
"EAP-TTLS-MSCHAPv2", 2);
break;
case TTLS_PHASE2_EAP:
dump_config_ttls_eap((struct config_eap_method *)ttls->phase2_data);
break;
default:
printf("AAAH! Trying to dump an undefined config"
" type in %s.\nNotify developers. Type: 0x%x\n",
__FUNCTION__, ttls->phase2_type);
}
}
/**
* \brief Clear from memory the EAP-TTLS configuration data.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -