⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xsupconfig_parse_eap_sim.c

📁 linux 下通过802.1认证的安装包
💻 C
字号:
/**
 * Licensed under a dual GPL/BSD license.  (See LICENSE file for more info.)
 *
 * \file xsupconfig_parse_eap_sim.c
 *
 * \author chris@open1x.org
 *
 * $Id: xsupconfig_parse_eap_sim.c,v 1.1.2.15 2007/07/11 01:12:34 chessing Exp $
 * $Date: 2007/07/11 01:12:34 $
 **/

#include <stdio.h>

#ifndef WINDOWS
#include <stdint.h>
#include <strings.h>
#endif

#include <libxml/parser.h>
#include <libxml/tree.h>
#include <string.h>

#include "xsupconfig_structs.h"
#include "../../src/xsup_common.h"
#include "xsupconfig.h"
#include "xsupconfig_common.h"
#include "xsupconfig_parse.h"
#include "xsupconfig_parse_eap_sim.h"

void *xsupconfig_parse_eap_sim(void **attr, xmlNodePtr node)
{
  struct config_eap_method *meth;

  meth = (*attr);

  if (meth == NULL)
  {
	meth = xsupconfig_alloc_method(meth, "EAP-SIM");
	(*attr) = meth;
  }
  else
  {
	  meth = xsupconfig_alloc_method(meth, "EAP-SIM");
  }

  if (meth == NULL) return NULL;

#ifdef PARSE_DEBUG
  printf("Parsing method 'EAP-SIM'.\n");
#endif

  meth->method_num = EAP_TYPE_SIM;
  meth->method_data = malloc(sizeof(struct config_eap_sim));
  if (meth->method_data == NULL)
    {
      printf("Couldn't allocate memory to store EAP-SIM data."
	     "  (Line %ld)\n", xsupconfig_parse_get_line_num());
      exit(2);
    }

  memset(meth->method_data, 0x00, sizeof(struct config_eap_sim));

  return meth->method_data;
}

void *xsupconfig_parse_eap_sim_username(void **attr, xmlNodePtr node)
{
  struct config_eap_sim *sim;
  char *value;

  value = xmlNodeGetContent(node);

  sim = (*attr);

#ifdef PARSE_DEBUG
  printf("Username for EAP-SIM  is '%s'!\n", value);
#endif

	if ((value == NULL) || (strlen(value) == 0))
	{
		free(value);
		sim->username = NULL;
	}
	else
	{
		sim->username = value;
	}

  return sim;
}

void *xsupconfig_parse_eap_sim_password(void **attr, xmlNodePtr node)
{
  struct config_eap_sim *sim;
  char *value;

  value = xmlNodeGetContent(node);

  sim = (*attr);

#ifdef PARSE_DEBUG
  printf("Password for EAP-SIM is '%s'!\n", value);
#endif

	if ((value == NULL) || (strlen(value) == 0))
	{
		free(value);
		sim->password = NULL;
	}
	else
	{
		sim->password = value;
	}

  return sim;
}

void *xsupconfig_parse_eap_sim_enc_password(void **attr, xmlNodePtr node)
{
  struct config_eap_sim *sim = NULL;
  char *value = NULL;
  int size  = 0;

  value = xmlNodeGetContent(node);

  sim = (*attr);

#ifdef PARSE_DEBUG
  printf("Password (Encrypted) for EAP-SIM is '%s'!\n", value);
#endif

	if ((value == NULL) || (strlen(value) == 0))
	{
		free(value);
		return sim;
	}

  if (pwcrypt_decrypt(value, strlen(value), &sim->password, &size) != 0)
  {
	  free(value);
	  sim->password = NULL;
	  return sim;
  }

  if ((sim->password != NULL) && (strlen(sim->password) == 0))
  {
	  FREE(sim->password);
  }

  free(value);

  return sim;
}

void *xsupconfig_parse_eap_sim_auto_realm(void **attr, xmlNodePtr node)
{
  struct config_eap_sim *sim;
  uint8_t result;
  char *value;

  value = xmlNodeGetContent(node);

  sim = (*attr);

#ifdef PARSE_DEBUG
  printf("Auto Realm for EAP-SIM is '%s'!\n", value);
#endif

  result = xsupconfig_common_yesno(value);

  if (result == 1)
    {
      sim->auto_realm = TRUE;
    }
  else if (result == 0)
    {
      sim->auto_realm = FALSE;
    }
  else
    {
      xsupconfig_common_log("Invalid value for 'Auto_Realm', using default of no.  (Line %ld)"
	     "\n", xsupconfig_parse_get_line_num());
      sim->auto_realm = FALSE;
    }

  FREE(value);

  return sim;
}

parser eap_sim[] = {
  {"Username", NULL, FALSE, &xsupconfig_parse_eap_sim_username},
  {"Password", NULL, FALSE, &xsupconfig_parse_eap_sim_password},
  {"Encrypted_Password", NULL, FALSE, &xsupconfig_parse_eap_sim_enc_password},
  {"Auto_Realm", NULL, FALSE, &xsupconfig_parse_eap_sim_auto_realm},
  {"Type", NULL, FALSE, xsupcommon_do_nothing},

  {NULL, NULL, FALSE, NULL}};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -