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

📄 xsupconfwrite.c

📁 Linux上的802.1x 的supplicant的实现。很多supplicant程序都是基于它开发的
💻 C
📖 第 1 页 / 共 5 页
字号:
	    {#ifdef DEBUG	      printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	      return XSUPCONFWRITE_GENIOERR;	    }	  	  comma = 1;	}            if (TEST_FLAG(cur->flags, CONFIG_NET_ALLOW_MD5))	{	  retval = xsupconfwrite_write_comma(fileid, comma);	  if (retval < 0) return retval;      	  if (fprintf(fileid, "eap-md5") < 0) 	    {#ifdef DEBUG	      printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	      return XSUPCONFWRITE_GENIOERR;	    }	  	  comma = 1;	}            if (TEST_FLAG(cur->flags, CONFIG_NET_ALLOW_TTLS))	{	  retval = xsupconfwrite_write_comma(fileid, comma);	  if (retval < 0) return retval;	  if (fprintf(fileid, "eap-ttls") < 0) 	    {#ifdef DEBUG	      printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	      return XSUPCONFWRITE_GENIOERR;	    }	  	  comma = 1;	}            if (TEST_FLAG(cur->flags, CONFIG_NET_ALLOW_LEAP))	{	  retval = xsupconfwrite_write_comma(fileid, comma);	  if (retval < 0) return retval;	  if (fprintf(fileid, "eap-leap") < 0) 	    {#ifdef DEBUG	      printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	      return XSUPCONFWRITE_GENIOERR;	    }	  	  comma = 1;	}            if (TEST_FLAG(cur->flags, CONFIG_NET_ALLOW_MSCV2))	{	  retval = xsupconfwrite_write_comma(fileid, comma);	  if (retval < 0) return retval;	  if (fprintf(fileid, "eap-mschapv2") < 0) 	    {#ifdef DEBUG	      printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	      return XSUPCONFWRITE_GENIOERR;	    }	  	  comma = 1;	}            if (TEST_FLAG(cur->flags, CONFIG_NET_ALLOW_PEAP))	{	  retval = xsupconfwrite_write_comma(fileid, comma);	  if (retval < 0) return retval;      	  if (fprintf(fileid, "eap-peap") < 0) 	    {#ifdef DEBUG	      printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	      return XSUPCONFWRITE_GENIOERR;	    }	  	  comma = 1;	}            if (TEST_FLAG(cur->flags, CONFIG_NET_ALLOW_SIM))	{	  retval = xsupconfwrite_write_comma(fileid, comma);	  if (retval < 0) return retval;	  if (fprintf(fileid, "eap-sim") < 0) 	    {#ifdef DEBUG	      printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	      return XSUPCONFWRITE_GENIOERR;	    }	  	  comma = 1;	}            if (TEST_FLAG(cur->flags, CONFIG_NET_ALLOW_GTC))	{	  retval = xsupconfwrite_write_comma(fileid, comma);	  if (retval < 0) return retval;      	  if (fprintf(fileid, "eap-gtc") < 0) 	    {#ifdef DEBUG	      printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	      return XSUPCONFWRITE_GENIOERR;	    }	  	  comma = 1;	}            if (TEST_FLAG(cur->flags, CONFIG_NET_ALLOW_OTP))	{	  retval = xsupconfwrite_write_comma(fileid, comma);	  if (retval < 0) return retval;      	  if (fprintf(fileid, "eap-otp") < 0) 	    {#ifdef DEBUG	      printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	      return XSUPCONFWRITE_GENIOERR;	    }	  	  comma = 1;	}      if (TEST_FLAG(cur->flags, CONFIG_NET_ALLOW_AKA))	{	  retval = xsupconfwrite_write_comma(fileid, comma);	  if (retval < 0) return retval;      	  if (fprintf(fileid, "eap-aka") < 0) 	    {#ifdef DEBUG	      printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	      return XSUPCONFWRITE_GENIOERR;	    }	  	  comma = 1;	}            if (TEST_FLAG(cur->flags, CONFIG_NET_ALLOW_WPA_PSK))	{	  retval = xsupconfwrite_write_comma(fileid, comma);	  if (retval < 0) return retval;      	  if (fprintf(fileid, "wpa-psk") < 0) 	    {#ifdef DEBUG	      printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	      return XSUPCONFWRITE_GENIOERR;	    }	  	  comma = 1;	}            if (fprintf(fileid, "\n\n") < 0) 	{#ifdef DEBUG	  printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	  return XSUPCONFWRITE_GENIOERR;	}    }  return XSUPCONFWRITE_ERRNONE;}/******************************************************************* * * Write the text representation of the crypto method we want to use. * *******************************************************************/int xsupconfwrite_write_crypt(FILE *fileid, int crypt){  switch (crypt)    {    case CRYPT_WEP40:      if (fprintf(fileid, "WEP40") < 0) 	{#ifdef DEBUG	  printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	  return XSUPCONFWRITE_GENIOERR;	}      break;    case CRYPT_TKIP:      if (fprintf(fileid, "TKIP") < 0) 	{#ifdef DEBUG	  printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	  return XSUPCONFWRITE_GENIOERR;	}      break;    case CRYPT_WRAP:      // Nobody uses this one, but we put it in here for kicks anyway. ;)      if (fprintf(fileid, "WRAP") < 0) 	{#ifdef DEBUG	  printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	  return XSUPCONFWRITE_GENIOERR;	}      break;    case CRYPT_CCMP:      if (fprintf(fileid, "CCMP") < 0) 	{#ifdef DEBUG	  printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	  return XSUPCONFWRITE_GENIOERR;	}      break;    case CRYPT_WEP104:      if (fprintf(fileid, "WEP104") < 0) 	{#ifdef DEBUG	  printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	  return XSUPCONFWRITE_GENIOERR;	}      break;    default:      return XSUPCONFWRITE_INVALIDCRYPTO;    }  return XSUPCONFWRITE_ERRNONE;}/******************************************************************* * * Write the configuration information for the smartcard part of EAP-TLS * if it is needed. * *******************************************************************/int xsupconfwrite_write_tls_smartcard(FILE *fileid, 				      struct config_eap_tls *eaptls){  if (!fileid)    {#ifdef DEBUG      printf("Error : %s, at %s():%d!\n", 	     xsupconfwrite_strerr(XSUPCONFWRITE_NOFILEHANDLE),	     __FUNCTION__, __LINE__);#endif      return XSUPCONFWRITE_NOFILEHANDLE;    }  if (!eaptls)    {#ifdef DEBUG      printf("Error : %s, at %s():%d!\n",	     xsupconfwrite_strerr(XSUPCONFWRITE_NOEAPDATA),	     __FUNCTION__, __LINE__);#endif      return XSUPCONFWRITE_NOEAPDATA;    }  // This is icky, but we need to determine if any of the smartcard values  // contain valid data before we write anything to the file.  if ((eaptls->sc.opensc_so_path) && ((eaptls->sc.engine_id) || 				      (eaptls->sc.key_id)))    {      // We have valid data.      if (fprintf(fileid, "\n\t\tsmartcard\n") < 0) 	{#ifdef DEBUG	  printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	  return XSUPCONFWRITE_GENIOERR;	}      if (fprintf(fileid, "\t\t{\n") < 0)	{#ifdef DEBUG	  printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	  return XSUPCONFWRITE_GENIOERR;	}      if (eaptls->sc.opensc_so_path)	{	  if (fprintf(fileid, "\t\t\topensc_so_path = \"%s\"\n",		      eaptls->sc.opensc_so_path) < 0)	    {#ifdef DEBUG	      printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	      return XSUPCONFWRITE_GENIOERR;	    }	}      if (eaptls->sc.engine_id)	{	  if (fprintf(fileid, "\t\t\tengine_id = %s\n",		      eaptls->sc.engine_id) < 0)	    {#ifdef DEBUG	      printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	      return XSUPCONFWRITE_GENIOERR;	    }	}      if (eaptls->sc.key_id)	{	  if (fprintf(fileid, "\t\t\tkey_id = %s\n",		      eaptls->sc.key_id) < 0)	    {#ifdef DEBUG	      printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	      return XSUPCONFWRITE_GENIOERR;	    }	}      if (fprintf(fileid, "\t\t}\n") < 0)	{#ifdef DEBUG	  printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	  return XSUPCONFWRITE_GENIOERR;	}    }  return XSUPCONFWRITE_ERRNONE;}/******************************************************************** * * Write the configuration information for EAP-MD5 * ********************************************************************/int xsupconfwrite_eap_md5(FILE *fileid, struct config_eap_method *cur, 			  int phase){  struct config_eap_md5 *eapmd5;    if (!fileid)    {#ifdef DEBUG      printf("Error : %s, at %s():%d!\n", 	     xsupconfwrite_strerr(XSUPCONFWRITE_NOFILEHANDLE),	     __FUNCTION__, __LINE__);#endif      return XSUPCONFWRITE_NOFILEHANDLE;    }    if (!cur)    {#ifdef DEBUG      printf("Error : %s, at %s():%d!\n",	     xsupconfwrite_strerr(XSUPCONFWRITE_NOEAPDATA),	     __FUNCTION__, __LINE__);#endif      return XSUPCONFWRITE_NOEAPDATA;    }  eapmd5 = (struct config_eap_md5 *)cur->method_data;  if (!eapmd5)    {#ifdef DEBUG      printf("The EAP-MD5 structure is NULL!\n");#endif      return XSUPCONFWRITE_NOEAPDATA;    }  if (phase ==2)    {      if (fprintf(fileid, "\t") < 0) 	{#ifdef DEBUG	  printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	  return XSUPCONFWRITE_GENIOERR;	}    }  if (fprintf(fileid, "\teap-md5\n") < 0)     {#ifdef DEBUG      printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif      return XSUPCONFWRITE_GENIOERR;    }  if (phase ==2)    {      if (fprintf(fileid, "\t") < 0) 	{#ifdef DEBUG	  printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	  return XSUPCONFWRITE_GENIOERR;	}    }  if (fprintf(fileid, "\t{\n") < 0)     {#ifdef DEBUG      printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif      return XSUPCONFWRITE_GENIOERR;    }  if (eapmd5->username)    {      if (phase ==2)	{	  if (fprintf(fileid, "\t") < 0) 	    {#ifdef DEBUG	      printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	      return XSUPCONFWRITE_GENIOERR;	    }	}      if (fprintf(fileid, "\t\tusername = \"%s\"\n", eapmd5->username) < 0)	{#ifdef DEBUG	  printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	  return XSUPCONFWRITE_GENIOERR;	}    }  if (eapmd5->password)    {      if (phase ==2)	{	  if (fprintf(fileid, "\t") < 0) 	    {#ifdef DEBUG	      printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	      return XSUPCONFWRITE_GENIOERR;	    }	}      if (fprintf(fileid, "\t\tpassword = \"%s\"\n", eapmd5->password) < 0)	{#ifdef DEBUG	  printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	  return XSUPCONFWRITE_GENIOERR;	}    }  if (phase ==2)    {      if (fprintf(fileid, "\t") < 0) 	{#ifdef DEBUG	  printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	  return XSUPCONFWRITE_GENIOERR;	}    }  if (fprintf(fileid, "\t}\n\n") < 0)    {#ifdef DEBUG      printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif      return XSUPCONFWRITE_GENIOERR;    }    return XSUPCONFWRITE_ERRNONE;  }/******************************************************************** * * Write the configuration information for LEAP * ********************************************************************/int xsupconfwrite_eap_leap(FILE *fileid, struct config_eap_method *cur,			   int phase){  struct config_eap_leap *eapleap;    if (!fileid)    {#ifdef DEBUG      printf("Error : %s, at %s():%d!\n", 	     xsupconfwrite_strerr(XSUPCONFWRITE_NOFILEHANDLE),	     __FUNCTION__, __LINE__);#endif      return XSUPCONFWRITE_NOFILEHANDLE;    }    if (!cur)    {#ifdef DEBUG      printf("Error : %s, at %s():%d!\n",	     xsupconfwrite_strerr(XSUPCONFWRITE_NOEAPDATA),	     __FUNCTION__, __LINE__);#endif      return XSUPCONFWRITE_NOEAPDATA;    }  eapleap = (struct config_eap_leap *)cur->method_data;  if (!eapleap)    {#ifdef DEBUG      printf("The EAP-LEAP structure is NULL!\n");#endif      return XSUPCONFWRITE_NOEAPDATA;    }  if (phase ==2)    {      if (fprintf(fileid, "\t") < 0) 	{#ifdef DEBUG	  printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif	  return XSUPCONFWRITE_GENIOERR;	}    }  if (fprintf(fileid, "\teap-leap\n") < 0)     {#ifdef DEBUG      printf("Error writing to file @ %s():%d\n", __FUNCTION__, __LINE__);#endif      return XSUPCONFWRITE_GENIOERR;

⌨️ 快捷键说明

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