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

📄 ipctest.c

📁 linux 下通过802.1认证的安装包
💻 C
📖 第 1 页 / 共 4 页
字号:
 * \brief Change a value in the trusted server settings.
 **/
void change_ts()
{
	struct config_trusted_server *ts = NULL;
	char *val = NULL;

	if (xsupgui_request_get_trusted_server_config("Test Server 2", &ts) != REQUEST_SUCCESS)
	{
		printf("Couldn't get trusted server settings.\n");
		die();
		return;
	}

	val = ts->store_type;
	free(ts->store_type);
	ts->store_type = _strdup("Mac OS X Store");

	if (xsupgui_request_set_trusted_server_config(ts) != REQUEST_SUCCESS)
	{
		printf("Couldn't set trusted server settings.\n");
		die();
		return;
	}

	if (xsupgui_request_get_trusted_server_config("Test Server 2", &ts)  != REQUEST_SUCCESS)
	{
		printf("Couldn't get trusted server settings the second time!\n");
		die();
		return;
	}

	printf("Store type is now set to '%s'.\n", ts->store_type);
}

/**
 * \brief Change a value in the managed network settings.
 **/
void change_mn()
{
	struct config_managed_networks *mn = NULL;
	char *val = NULL;

	if (xsupgui_request_get_managed_network_config("testme.com", &mn) != REQUEST_SUCCESS)
	{
		printf("Couldn't get managed network settings.\n");
		die();
		return;
	}

	val = mn->last_update;
	free(mn->last_update);
	mn->last_update = _strdup("GO AWAY!");

	if (xsupgui_request_set_managed_network_config(mn) != REQUEST_SUCCESS)
	{
		printf("Couldn't set managed network settings.\n");
		die();
		return;
	}

	if (xsupgui_request_get_managed_network_config("testme.com", &mn)  != REQUEST_SUCCESS)
	{
		printf("Couldn't get managed network config the second time!\n");
		die();
		return;
	}

	printf("Last update is now set to '%s'.\n", mn->last_update);
}

/**
 * \brief Get the SSID cache from the supplicant.
 **/
void doget_ssids(char *devname)
{
	ssid_info_enum *ssids = NULL;
	int i = 0;

	if (xsupgui_request_enum_ssids(devname, &ssids) != REQUEST_SUCCESS)
	{
		printf("Couldn't get supplicant's SSID cache!\n");
		die();
		return;
	}

	while (ssids[i].ssidname != NULL)
	{
		printf("SSID : %s\n", ssids[i].ssidname);
		i++;
	}

	xsupgui_request_free_ssid_enum(&ssids);
}

/**
 * \brief Request that the supplicant start a passive scan, if it can't, then 
 *        ask for an active scan.
 **/
void doscan(char *devname)
{
	if (xsupgui_request_wireless_scan(devname, TRUE) != REQUEST_SUCCESS)
	{
		printf("Failed passive scan... trying an active one..\n");
		if (xsupgui_request_wireless_scan(devname, FALSE) != REQUEST_SUCCESS)
		{
			printf("Failed active scan!\n");
			die();
			return;
		}
		else
		{
			printf("Requested active scan.\n");
			return;
		}
	}

	printf("Requested passive scan.\n");
}

void getvername()
{
	char *version;

	if (xsupgui_request_version_string(&version) != REQUEST_SUCCESS)
	{
		printf("Failed to get version string!\n");
		die();
	}
	else
	{
		printf("Version : %s\n", version);
		free(version);
	}
}

void getrootcacerts()
{
	cert_enum *casa;
	int i = 0;

	if (xsupgui_request_enum_root_ca_certs(&casa) != REQUEST_SUCCESS)
	{
		printf("Failed to get root CA certificates.\n");
		die();
	}
	else
	{
		while (casa[i].certname != NULL)
		{
			printf("Certificate : %s\n", casa[i].certname);
			printf("\tStore Type    : %s\n", casa[i].storetype);
			printf("\tFriendly Name : %s\n", casa[i].friendlyname);
			printf("\tIssuer        : %s\n", casa[i].issuer);
			printf("\tExpires       : %d/%d/%d\n", casa[i].month, casa[i].day, casa[i].year);
			printf("\tCommon Name   : %s\n", casa[i].commonname);
			printf("\tLocation      : %s\n", casa[i].location);
			printf("\n");
			i++;
		}
	}
	printf("\n");

	xsupgui_request_free_cert_enum(&casa);
}

void getrootcainfo()
{
	cert_info *cinfo = NULL;

	if (xsupgui_request_ca_certificate_info("WINDOWS", "0048F8D37B153F6EA2798C323EF4F318A5624A9E", &cinfo) != REQUEST_SUCCESS)
	{
		printf("Couldn't get certificate information!\n");
		die();
		return;
	}

	printf("C = %s\n", cinfo->C);
	printf("S = %s\n", cinfo->S);
	printf("L = %s\n", cinfo->L);
	printf("O = %s\n", cinfo->O);
	printf("OU = %s\n", cinfo->OU);
	printf("CN = %s\n", cinfo->CN);

	xsupgui_request_free_cert_info(&cinfo);
}

void getintdata(char *intname)
{
	char *desc = NULL;
	char *mac = NULL;
	int wireless = 0;

	if (xsupgui_request_get_os_specific_int_data(intname, &desc, &mac, &wireless) != REQUEST_SUCCESS)
	{
		printf("Couldn't get interface information for interface '%s'.\n", intname);
		die();
		return;
	}

	printf("Description = %s\n", desc);
	printf("MAC Address = %s\n", mac);
	printf("Wireless    = %d\n", wireless);

	free(desc);
	free(mac);
}

void getconn_name(char *intname)
{
	char *name = NULL;

	if (xsupgui_request_get_conn_name_from_int(intname, &name) != REQUEST_SUCCESS)
	{
		printf("Couldn't get connection information for interface!\n");
		return;
	}

	printf("Using connection : %s\n", name);
	free(name);
}

void getqueuederrors()
{
	error_messages *msgs = NULL;
	int i = 0;

	if (xsupgui_request_get_error_msgs(&msgs) != REQUEST_SUCCESS)
	{
		printf("Couldn't get queued errors.  (Perhaps there were none?)\n");
		return;
	}

	while (msgs[i].errmsgs != NULL)
	{
		printf("Error : %s\n", msgs[i].errmsgs);
		i++;
	}

	xsupgui_request_free_error_msgs(&msgs);
}

void renameconnection(char *oldname, char *newname)
{
	if (xsupgui_request_rename_connection(oldname, newname) != REQUEST_SUCCESS)
	{
		printf("Failed to rename the connection!\n");
		return;
	}
}

void renameprofile(char *oldname, char *newname)
{
	if (xsupgui_request_rename_profile(oldname, newname) != REQUEST_SUCCESS)
	{
		printf("Failed to rename the profile!\n");
		return;
	}
}

void renametrusted_server(char *oldname, char *newname)
{
	int retval = 0;
	retval = xsupgui_request_rename_trusted_server(oldname, newname);
	if (retval != REQUEST_SUCCESS)
	{
		printf("Failed to rename the trusted server!  (Error : %d)\n", retval);
		return;
	}
}


/**
 * \brief Ask the supplicant for the current global settings.
 **/
void dochange_logpath()
{
	struct config_globals *myglobs;

	printf("Getting global settings...");

	if (xsupgui_request_get_globals_config(&myglobs) != REQUEST_SUCCESS)
	{
		printf("Failed!\n");
		die();
		return;
	}
	
	printf("Success...\n\n");

	printf("Setting for logging is : %s\n", myglobs->logpath);

	free(myglobs->logpath);

	myglobs->logpath = _strdup("c:\\xsup_dev");

	printf("New setting for logging is : %s\n", myglobs->logpath);

	if (xsupgui_request_set_globals_config(myglobs) != REQUEST_SUCCESS)
	{
		printf("failed!\n");
		die();
		return;
	}

	printf("Success...\n\n");
}

/**
 *  \brief  Display a header that indicates the test that is about to be run.
 *
 *  @param[in] test   The name of the test being run.
 **/
void nt(char *test)
{
	if (test != NULL)
	{
		printf("-----------------(%s)--------------------\n", test);
	}
	else
	{
		printf("----------------------------------------\n");
	}
}

int main(int argc, char *argv[])
{
  struct options opts[] = 
    {
      { 1, "connection", "Force the connection to use", "C", 1},
      { 2, "interface", "Use this interface", "i", 1}
    };

  int op = 0; 
  char *args = NULL;
  char *conn = NULL;
  char *intface = NULL;

  while((op = getopts(argc, argv, opts, &args)) != 0)
    {
      switch(op)
	{
	case 1:
	  {
	    printf("Connection: %s\n", args);
	    conn = args;
	  }
	case 2:
	  {
	    printf("Interface: %s\n", args);
	    intface = args;
	  }
	}
    }

	if (argc < 2)
	{
		printf("ipctest  <OS Device Name>\n");
		printf("\n");
		return 1;
	}

	printf("Connecting to xsupplicant..\n");
	if (xsupgui_connect() != 0)
	{
		printf("Error connecting socket/pipe!\n");
		return 1;
	}

#if 0
	getcapabilities(intface);
	return 0;
#endif

#if 1
	nt("Terminate Supplicant");
	doterminate();
	exit(1);
#endif

#if 0
	add_cert();
#endif

#if 0
	build_tt();
	return 0;
#endif

#if 0
	dochangeconn(intface, conn);

	return 0;
#endif 

#if 0
	nt("Renaming a trusted server");
	renametrusted_server("OSC Root CA", "My Root & CA");
	nt("Renaming a profile");
	renameprofile("Radiator Profile", "My Radiator & Profile");
	nt("Renaming the connection");
	renameconnection("Radiator Connection", "My & Radiator & Connection");
	nt("Writing the config to 'test.out'.");
	dowrite_conf("test.out");
	return 0;
#endif

#if 0
	nt("Enumerating possible connections");
	doget_possible_connections();

	nt("Getting connections");
	dogetconnections();

	nt("Getting a connection config");
	doget_connection();
#endif

#if 1
	nt("Requesting Version String");
	getvername();
#endif 

#if 1
	nt("Enumerating Certificates");
	getrootcacerts();
	
	nt("Getting data on one Root CA");
	getrootcainfo();
#endif

#if 1
	nt("Enumerate Certificates...");
	docerts_enum();
#endif

#if 0
	nt("Changing log path");
	dochange_logpath();
#endif

#if 1
	nt("Get Physical State");
	dogetphysicalstate(argv[1]);  
#endif

#if 0
	getupwd("Home WPA 2 PSK Network");
	xsupgui_disconnect();
	return 0;
#endif

#if 0
	nt("Getting interface data");
	getintdata(argv[1]);
#endif

#if 0
	nt("Changing Connection");
	dochangeconn(argv[1], "Office Wired Test");
	xsupgui_disconnect();
	return 0;
#endif

#if 0
	nt("Writing configuration to 'test.out'...");
	dowrite_conf("test.out");
#endif

#if 0
	nt("Writing config.\n");
	dowrite_conf(NULL);
	exit(1);
#endif

#if 0
	nt("Terminate Supplicant");
	doterminate();
#endif

	nt("Ping Test");
	doping();

	nt("Get Time Authenticated");
	dogettimeauthed(argv[1]);  

	nt("Getting queued errors");
	getqueuederrors();
	exit(1);
	nt("Enumerate Interfaces");
	doint_enum();
	nt("Enumerate EAP Methods");
	doeap_enum();
//	nt("Reload Config Test");     // Need to fix this on the supplicant side! (The contexts need to be updated following the reload.)
//	doreload();
	nt("Get 802.1X state");
	doget1xstate(argv[1]);  
	nt("Get EAP state");
	dogeteapstate(argv[1]);  
	nt("Get Backend State");
	dogetbackendstate(argv[1]);  
	nt("Get Physical State");
	dogetphysicalstate(argv[1]);  
	nt("Get Pairwise Key Type");
	dogetpairwisetype(argv[1]);  
	nt("Get Group Key Type");
	dogetgrouptype(argv[1]); 
	nt("Get EAP Type");
	dogeteaptype(argv[1]);
	nt("Get SSID");
	dogetssid(argv[1]); 
	nt("Get BSSID");
	dogetbssid(argv[1]); 
	nt("Get Time Authenticated");
	dogettimeauthed(argv[1]);  
	nt("Get Signal");
	dogetsignal(argv[1]);  
	nt("Get Connections");
	dogetconnections(argv[1]);  
	nt("Get Credentials from 'Home WPA 2 PSK Network'");
	getupwd("Home WPA 2 PSK Network");
	nt("Get Credentials from 'Home WPA EAP-TTLS Network'");
	getupwd("Home WPA EAP-TTLS Network");
	nt("Get Association Type for test interface");
	getassoctype(argv[1]);
	nt("Changing Username/Password for 'Home WPA 2 PSK Network'");
	setupwd("Home WPA 2 PSK Network", NULL, "newpassword");
	/*
	nt("Changing Username/Password for 'Home WPA EAP-TTLS Network'");
	setupwd("Home WPA EAP-TTLS Network", "foo", "bar");
	*/
	nt("Get Credentials from 'Home WPA 2 PSK Network'");
	getupwd("Home WPA 2 PSK Network");

	nt("Get Credentials from 'Home WPA EAP-TTLS Network'");
	getupwd("Home WPA EAP-TTLS Network");

	/*
	nt("Force Changing the Connection on an Interface");
	dochangeconn(argv[1], "Office Wired Test");

	nt("Disassociating...");
	setdisassoc("\\DEVICE\\{57FB2BD9-E1F7-47EE-813A-64FF1B4B65F0}");
	nt("Pausing...");
	setpause("\\DEVICE\\{57FB2BD9-E1F7-47EE-813A-64FF1B4B65F0}");
*/

	nt("Get IP Address information...");
	getipaddr(argv[1]);

	nt("Enumerate Profiles...");
	doprof_enum();

	nt("Enumerate Certificates...");
	docerts_enum();

	nt("Writing configuration to 'test.out'...");
	dowrite_conf("test.out");

	nt("Getting Global Settings...");
	doget_globals();

	nt("Getting Profile Settings...");
	doget_profile();

	nt("Getting Connection Settings...");
	doget_connection();

	nt("Getting Trusted Server...");
	doget_ts();

	nt("Getting interface information...");
	doget_int();

	nt("Getting interfaces defined in the configuration file.");
	doint_conf_enum();

	nt("Enumerating Managed Networks...");
	doget_enum_managed_nets();

#if 0
	nt("Get 'testme.com' managed network");
	get_managed_net();

	//nt("Deleting 'testme.com' from the managed network list in memory");
	//del_managed_net();
#endif

	nt("Deleting 'Beat me!' profile");
	del_profile();

	nt("Deleting 'RSA Test' connection");
	del_connection();

	nt("Deleting interface 'Intel IPW3945'");
	del_interface();

#if 0
	nt("Deleting trusted server 'Test Server 1'");
	del_trusted_server();

	nt("Changing logpath in global settings.");
	change_globals();

	nt("Changing connection settings.");
	change_conn();

	nt("Changing profile settings.");
	change_prof();

	nt("Changing trusted server settings");
	change_ts();

	nt("Changing managed networks settings");
	change_mn();
#endif

	nt("Writing config to 'test2.out'...");
	dowrite_conf("test2.out");

	nt("Getting list of known SSIDs...");
	doget_ssids(argv[1]);

	nt("Requesting a scan");
	doscan(argv[1]);

	nt("Requesting Version String");
	getvername();

	nt("Getting connection name");
	getconn_name(argv[1]);

	nt("Getting root CA information");
	getrootcainfo();

	nt("Getting interface data");
	getintdata(argv[1]);

	// You may want to comment this one out! ;)
#if 0
	nt("Terminate Supplicant");
	doterminate();
#endif

	nt(NULL);

	printf("Disconnecting.\n");
	xsupgui_disconnect();

	return 0;
}

⌨️ 快捷键说明

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