Question

nouha23 Messages postés 9 Date d'inscription lundi 30 mars 2009 Statut Membre Dernière intervention 19 avril 2009 - 7 avril 2009 à 19:10
cs_rt15 Messages postés 3874 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 7 novembre 2014 - 8 avril 2009 à 13:32
je veu comprendre le code de ce class data-config svp et ces fonctions.
/**************************************************************************/

/* WIRE1x for Vista Version 1.0.1: An open-source IEEE 802.1x supplicant */

/* for Microsoft Windows based on Xsupplicant of Open1x. */

/* */

/* This code is released under both the GPL version 2 and BSD licenses. */

/* Either license may be used. */

/* */

/* Copyright (C) 2003-2008 WIRE Lab., National Tsing Hua University, */

/* Hsinchu, Taiwan, R.O.C. All Rights Reserved. */

/**************************************************************************/

#include

"stdafx.h"#include

"data_config.h" 

extern

Network_config_data network_data;
int

store_profile(){

char str[8192];

char temp[256];sprintf_s(str,

"");HKEY hk;

DWORD dwDisp;

TCHAR szBuf[300];

// Create the event source as a subkey of the log. sprintf_s(szBuf,

"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\WIRE1x_vista\\Config");

if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, szBuf, 0, NULL, REG_OPTION_NON_VOLATILE,

KEY_WRITE, NULL, &hk, &dwDisp))

{

printf(

"Could not create the registry key."); }

strcat_s(str,

"#\n");sprintf_s(temp,

"ssid:%s\n",network_data.ssid);strcat_s(str,temp);

sprintf_s(temp,

"auth_type:%d\n",network_data.auth_type);strcat_s(str,temp);

sprintf_s(temp,

"encryp_type:%d\n",network_data.encryp_type);strcat_s(str,temp);

sprintf_s(temp,

"key:%s\n",network_data.key);strcat_s(str,temp);

sprintf_s(temp,

"eap_type:%d\n",network_data.eap_type);strcat_s(str,temp);

sprintf_s(temp,

"eap_innertype:%d\n",network_data.eap_innertype);strcat_s(str,temp);

sprintf_s(temp,

"verifycert:%d\n",network_data.verifycert);strcat_s(str,temp);

sprintf_s(temp,

"rootcertname:%s\n",network_data.rootcertname);strcat_s(str,temp);

sprintf_s(temp,

"store_name_pswd:%d\n",network_data.store_name_pswd);strcat_s(str,temp);

if(network_data.store_name_pswd == 1){sprintf_s(temp,

"username:%s\n",network_data.username);strcat_s(str,temp);

sprintf_s(temp,

"password:%s\n",network_data.password);strcat_s(str,temp);

}

else{sprintf_s(temp,

"username:%s\n",
"");strcat_s(str,temp);

sprintf_s(temp,

"password:%s\n",
"");strcat_s(str,temp);

}

strcat_s(str,

"#"); 

// Set the name of the message file.

if (RegSetValueEx(hk,
// subkey handle network_data.ssid,

// value name 0,

// must be zero REG_EXPAND_SZ,

// value type (LPBYTE) str,

// pointer to value data (DWORD) (lstrlen(str)+1)*

sizeof(TCHAR)))
// data size{

printf(

"Could not set the registry."); }

RegCloseKey(hk);

return 0;}

int

read_profile(){

DWORD BufferSize=65535;

char *profile_p;profile_p = (

char *)malloc(BufferSize);HKEY hkey;

TCHAR szBuf[300];

sprintf_s(szBuf,

"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\WIRE1x_vista\\Config");RegOpenKeyEx(HKEY_LOCAL_MACHINE, szBuf, 0,

KEY_QUERY_VALUE, &hkey);

if (RegQueryValueEx(hkey, network_data.ssid, NULL, NULL,

// value type (LPBYTE)profile_p,

// pointer to value data &BufferSize))

{

printf(

"Could not get the registry.");

return -1;}

RegCloseKey(hkey);

char *str;str = strtok(profile_p,

"\n");str = strtok(NULL,

"\n");strncpy(network_data.ssid,str+5 ,strlen(str)-5+1);

str = strtok(NULL,

"\n");network_data.auth_type = (Auth_type_config) atoi(str+10);

str = strtok(NULL,

"\n");network_data.encryp_type = (Encryp_type_config) atoi(str+12);

str = strtok(NULL,

"\n");strncpy(network_data.key,str+4 ,strlen(str)-4+1);

str = strtok(NULL,

"\n");network_data.eap_type = (Eap_type_config) atoi(str+9);

str = strtok(NULL,

"\n");network_data.eap_innertype = (Eap_innertype_config)atoi(str+14);

str = strtok(NULL,

"\n");network_data.verifycert = atoi(str+11);

str = strtok(NULL,

"\n");strncpy(network_data.rootcertname,str+13 ,strlen(str)-13+1);

str = strtok(NULL,

"\n");network_data.store_name_pswd = atoi(str+16);

str = strtok(NULL,

"\n");strncpy(network_data.username,str+9 ,strlen(str)-9+1);

str = strtok(NULL,

"\n");strncpy(network_data.password,str+9 ,strlen(str)-9+1);

free(profile_p);

return 0;}

int

read_customize_profile(){

DWORD BufferSize=65535;

char *profile_p;profile_p = (

char *)malloc(BufferSize);HKEY hkey;

TCHAR szBuf[300];

sprintf_s(szBuf,

"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\WIRE1x_vista\\Customize_Config");RegOpenKeyEx(HKEY_LOCAL_MACHINE, szBuf, 0,

KEY_QUERY_VALUE, &hkey);

if (RegQueryValueEx(hkey, network_data.ssid, NULL, NULL,

// value type (LPBYTE)profile_p,

// pointer to value data &BufferSize))

{

printf(

"Could not get the registry.");

return -1;}

RegCloseKey(hkey);

char *str;str = strtok(profile_p,

"\n");str = strtok(NULL,

"\n");strncpy(network_data.ssid,str+5 ,strlen(str)-5+1);

str = strtok(NULL,

"\n");network_data.auth_type = (Auth_type_config) atoi(str+10);

str = strtok(NULL,

"\n");network_data.encryp_type = (Encryp_type_config) atoi(str+12);

str = strtok(NULL,

"\n");strncpy(network_data.key,str+4 ,strlen(str)-4+1);

str = strtok(NULL,

"\n");network_data.eap_type = (Eap_type_config) atoi(str+9);

str = strtok(NULL,

"\n");network_data.eap_innertype = (Eap_innertype_config)atoi(str+14);

str = strtok(NULL,

"\n");network_data.verifycert = atoi(str+11);

str = strtok(NULL,

"\n");strncpy(network_data.rootcertname,str+13 ,strlen(str)-13+1);

str = strtok(NULL,

"\n");network_data.store_name_pswd = atoi(str+16);

str = strtok(NULL,

"\n");strncpy(network_data.username,str+9 ,strlen(str)-9+1);

str = strtok(NULL,

"\n");strncpy(network_data.password,str+9 ,strlen(str)-9+1);

free(profile_p);

return 0;}

int

write_customize(){

char str[8192]; sprintf_s(str,

"");HKEY hk;

DWORD dwDisp;

TCHAR szBuf[300];

DWORD BufferSize=65535;

char *profile_p;profile_p = (

char *)malloc(BufferSize);HKEY hkey;

 

sprintf_s(szBuf,

"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\WIRE1x_vista\\Customize_Config");RegOpenKeyEx(HKEY_LOCAL_MACHINE, szBuf, 0,

KEY_QUERY_VALUE, &hkey);

if (RegQueryValueEx(hkey,
"NTHU_FIRST_CONNECT", NULL, NULL,

// value type (LPBYTE)profile_p,

// pointer to value data &BufferSize))

{

strcat_s(str,

"#\nssid:nthu\nauth_type:0\nencryp_type:1\nkey:\neap_type:2\neap_innertype:4\nverifycert:1\nrootcertname:Class 3 Public Primary Certification Authority|\nstore_name_pswd:2\nusername:\npassword:\n#"); }

else{strcat_s(str,

"#\nssid:nthu\nauth_type:0\nencryp_type:1\nkey:\neap_type:2\neap_innertype:4\nverifycert:0\nrootcertname:\nstore_name_pswd:2\nusername:\npassword:\n#");}

 

 

// Create the event source as a subkey of the log. sprintf_s(szBuf,

"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\WIRE1x_vista\\Customize_Config");

if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, szBuf, 0, NULL, REG_OPTION_NON_VOLATILE,

KEY_WRITE, NULL, &hk, &dwDisp))

{

printf(

"Could not create the registry key."); }

// Set the name of the message file.

if (RegSetValueEx(hk,
// subkey handle

"nthu",
// value name 0,

// must be zero REG_EXPAND_SZ,

// value type (LPBYTE) str,

// pointer to value data (DWORD) (lstrlen(str)+1)*

sizeof(TCHAR)))
// data size{

printf(

"Could not set the registry."); }

RegCloseKey(hk);

return 0;}

int

store_temp_data_for_dll(){

char str[256];

char temp[100];HKEY hk;

DWORD dwDisp;

TCHAR szBuf[300];

sprintf_s(str,

"");

// Create the event source as a subkey of the log. sprintf_s(szBuf,

"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\WIRE1x_vista");

if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, szBuf, 0, NULL, REG_OPTION_NON_VOLATILE,

KEY_WRITE, NULL, &hk, &dwDisp))

{

printf(

"Could not create the registry key."); }

//outer identitystrcat_s(str,network_data.username);

strcat_s(str,

"\n");

//user namestrcat_s(str,network_data.username);

strcat_s(str,

"\n");

//passwordstrcat_s(str,network_data.password);

strcat_s(str,

"\n");

//eap typesprintf_s(temp,

"%d\n",network_data.eap_type);strcat_s(str,temp);

//eap inner typesprintf_s(temp,

"%d\n",network_data.eap_innertype);strcat_s(str,temp);

//verify server certificatesprintf_s(temp,

"%d\n",network_data.verifycert);strcat_s(str,temp);

//selected server certificatestrcat_s(str,network_data.rootcertname);

strcat_s(str,

"\n");strcat_s(str,

"#\n");

// Set the name of the message file.

if (RegSetValueEx(hk,
// subkey handle

"tempuserdata",
// value name 0,

// must be zero REG_EXPAND_SZ,

// value type (LPBYTE) str,

// pointer to value data (DWORD) (lstrlen(str)+1)*

sizeof(TCHAR)))
// data size{

printf(

"Could not set the registry."); }

RegCloseKey(hk);

return 0;}

void

clear_setting(){

network_data.auth_type = open;

network_data.eap_innertype = no_inner;

network_data.eap_type = no_eap;

network_data.encryp_type = none;

strcpy_s(network_data.key,

"");strcpy_s(network_data.password,

"");strcpy_s(network_data.rootcertname,

"");strcpy_s(network_data.ssid,

"");network_data.store_name_pswd = 0;

strcpy_s(network_data.username,

"");network_data.verifycert = 0;

}

1 réponse

cs_rt15 Messages postés 3874 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 7 novembre 2014 13
8 avril 2009 à 13:32
Salut,

Globalement :
La fonction store_profile sauvegarde des données dans le registre (Aide sur les fonctions du registre). Ces données proviennent d'une structure network_data de type Network_config_data. L'instance et la structure sont probablement définies dans le .h.

La fonction read_profile fait l'opération inverse : registre -> network_data.

Ensuite, tu as read_customize_profile et write_customize qui ont l'air tout à fait similaires.

Ensuite store_temp_data_for_dll, pareil, ressemble à store.

Et finalement clear_setting qui nettoie network_data.

Soit dit en passant, le code est très moche... Il y a certainement moyen de factoriser.

Donc globalement chargement/déchargement d'une structure dans le registre. Une structure en rapport avec le réseaux manifestement. Peut être pour le 802.1X si on en croit les commentaires.
0
Rejoignez-nous