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

📄 config.c

📁 WLAN无线网络管理的最新程序
💻 C
📖 第 1 页 / 共 3 页
字号:
			wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",				   line, start);			os_free(buf);			return -1;		}		if (last)			break;		start = end + 1;	}	os_free(buf);	if (val == 0) {		wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",			   line);		return -1;	}	return val;}static char * wpa_config_write_cipher(int cipher){	char *buf, *pos, *end;	int ret;	pos = buf = os_zalloc(50);	if (buf == NULL)		return NULL;	end = buf + 50;	if (cipher & WPA_CIPHER_CCMP) {		ret = os_snprintf(pos, end - pos, "%sCCMP",				  pos == buf ? "" : " ");		if (ret < 0 || ret >= end - pos) {			end[-1] = '\0';			return buf;		}		pos += ret;	}	if (cipher & WPA_CIPHER_TKIP) {		ret = os_snprintf(pos, end - pos, "%sTKIP",				  pos == buf ? "" : " ");		if (ret < 0 || ret >= end - pos) {			end[-1] = '\0';			return buf;		}		pos += ret;	}	if (cipher & WPA_CIPHER_WEP104) {		ret = os_snprintf(pos, end - pos, "%sWEP104",				  pos == buf ? "" : " ");		if (ret < 0 || ret >= end - pos) {			end[-1] = '\0';			return buf;		}		pos += ret;	}	if (cipher & WPA_CIPHER_WEP40) {		ret = os_snprintf(pos, end - pos, "%sWEP40",				  pos == buf ? "" : " ");		if (ret < 0 || ret >= end - pos) {			end[-1] = '\0';			return buf;		}		pos += ret;	}	if (cipher & WPA_CIPHER_NONE) {		ret = os_snprintf(pos, end - pos, "%sNONE",				  pos == buf ? "" : " ");		if (ret < 0 || ret >= end - pos) {			end[-1] = '\0';			return buf;		}		pos += ret;	}	return buf;}static int wpa_config_parse_pairwise(const struct parse_data *data,				     struct wpa_ssid *ssid, int line,				     const char *value){	int val;	val = wpa_config_parse_cipher(line, value);	if (val == -1)		return -1;	if (val & ~(WPA_CIPHER_CCMP | WPA_CIPHER_TKIP | WPA_CIPHER_NONE)) {		wpa_printf(MSG_ERROR, "Line %d: not allowed pairwise cipher "			   "(0x%x).", line, val);		return -1;	}	wpa_printf(MSG_MSGDUMP, "pairwise: 0x%x", val);	ssid->pairwise_cipher = val;	return 0;}static char * wpa_config_write_pairwise(const struct parse_data *data,					struct wpa_ssid *ssid){	return wpa_config_write_cipher(ssid->pairwise_cipher);}static int wpa_config_parse_group(const struct parse_data *data,				  struct wpa_ssid *ssid, int line,				  const char *value){	int val;	val = wpa_config_parse_cipher(line, value);	if (val == -1)		return -1;	if (val & ~(WPA_CIPHER_CCMP | WPA_CIPHER_TKIP | WPA_CIPHER_WEP104 |		    WPA_CIPHER_WEP40)) {		wpa_printf(MSG_ERROR, "Line %d: not allowed group cipher "			   "(0x%x).", line, val);		return -1;	}	wpa_printf(MSG_MSGDUMP, "group: 0x%x", val);	ssid->group_cipher = val;	return 0;}static char * wpa_config_write_group(const struct parse_data *data,				     struct wpa_ssid *ssid){	return wpa_config_write_cipher(ssid->group_cipher);}static int wpa_config_parse_auth_alg(const struct parse_data *data,				     struct wpa_ssid *ssid, int line,				     const char *value){	int val = 0, last, errors = 0;	char *start, *end, *buf;	buf = os_strdup(value);	if (buf == NULL)		return -1;	start = buf;	while (*start != '\0') {		while (*start == ' ' || *start == '\t')			start++;		if (*start == '\0')			break;		end = start;		while (*end != ' ' && *end != '\t' && *end != '\0')			end++;		last = *end == '\0';		*end = '\0';		if (os_strcmp(start, "OPEN") == 0)			val |= WPA_AUTH_ALG_OPEN;		else if (os_strcmp(start, "SHARED") == 0)			val |= WPA_AUTH_ALG_SHARED;		else if (os_strcmp(start, "LEAP") == 0)			val |= WPA_AUTH_ALG_LEAP;		else {			wpa_printf(MSG_ERROR, "Line %d: invalid auth_alg '%s'",				   line, start);			errors++;		}		if (last)			break;		start = end + 1;	}	os_free(buf);	if (val == 0) {		wpa_printf(MSG_ERROR,			   "Line %d: no auth_alg values configured.", line);		errors++;	}	wpa_printf(MSG_MSGDUMP, "auth_alg: 0x%x", val);	ssid->auth_alg = val;	return errors ? -1 : 0;}static char * wpa_config_write_auth_alg(const struct parse_data *data,					struct wpa_ssid *ssid){	char *buf, *pos, *end;	int ret;	pos = buf = os_zalloc(30);	if (buf == NULL)		return NULL;	end = buf + 30;	if (ssid->auth_alg & WPA_AUTH_ALG_OPEN) {		ret = os_snprintf(pos, end - pos, "%sOPEN",				  pos == buf ? "" : " ");		if (ret < 0 || ret >= end - pos) {			end[-1] = '\0';			return buf;		}		pos += ret;	}	if (ssid->auth_alg & WPA_AUTH_ALG_SHARED) {		ret = os_snprintf(pos, end - pos, "%sSHARED",				  pos == buf ? "" : " ");		if (ret < 0 || ret >= end - pos) {			end[-1] = '\0';			return buf;		}		pos += ret;	}	if (ssid->auth_alg & WPA_AUTH_ALG_LEAP) {		ret = os_snprintf(pos, end - pos, "%sLEAP",				  pos == buf ? "" : " ");		if (ret < 0 || ret >= end - pos) {			end[-1] = '\0';			return buf;		}		pos += ret;	}	return buf;}#ifdef IEEE8021X_EAPOLstatic int wpa_config_parse_eap(const struct parse_data *data,				struct wpa_ssid *ssid, int line,				const char *value){	int last, errors = 0;	char *start, *end, *buf;	struct eap_method_type *methods = NULL, *tmp;	size_t num_methods = 0;	buf = os_strdup(value);	if (buf == NULL)		return -1;	start = buf;	while (*start != '\0') {		while (*start == ' ' || *start == '\t')			start++;		if (*start == '\0')			break;		end = start;		while (*end != ' ' && *end != '\t' && *end != '\0')			end++;		last = *end == '\0';		*end = '\0';		tmp = methods;		methods = os_realloc(methods,				     (num_methods + 1) * sizeof(*methods));		if (methods == NULL) {			os_free(tmp);			os_free(buf);			return -1;		}		methods[num_methods].method = eap_get_type(			start, &methods[num_methods].vendor);		if (methods[num_methods].vendor == EAP_VENDOR_IETF &&		    methods[num_methods].method == EAP_TYPE_NONE) {			wpa_printf(MSG_ERROR, "Line %d: unknown EAP method "				   "'%s'", line, start);			wpa_printf(MSG_ERROR, "You may need to add support for"				   " this EAP method during wpa_supplicant\n"				   "build time configuration.\n"				   "See README for more information.");			errors++;		} else if (methods[num_methods].vendor == EAP_VENDOR_IETF &&			   methods[num_methods].method == EAP_TYPE_LEAP)			ssid->leap++;		else			ssid->non_leap++;		num_methods++;		if (last)			break;		start = end + 1;	}	os_free(buf);	tmp = methods;	methods = os_realloc(methods, (num_methods + 1) * sizeof(*methods));	if (methods == NULL) {		os_free(tmp);		return -1;	}	methods[num_methods].vendor = EAP_VENDOR_IETF;	methods[num_methods].method = EAP_TYPE_NONE;	num_methods++;	wpa_hexdump(MSG_MSGDUMP, "eap methods",		    (u8 *) methods, num_methods * sizeof(*methods));	ssid->eap_methods = methods;	return errors ? -1 : 0;}static char * wpa_config_write_eap(const struct parse_data *data,				   struct wpa_ssid *ssid){	int i, ret;	char *buf, *pos, *end;	const struct eap_method_type *eap_methods = ssid->eap_methods;	const char *name;	if (eap_methods == NULL)		return NULL;	pos = buf = os_zalloc(100);	if (buf == NULL)		return NULL;	end = buf + 100;	for (i = 0; eap_methods[i].vendor != EAP_VENDOR_IETF ||		     eap_methods[i].method != EAP_TYPE_NONE; i++) {		name = eap_get_name(eap_methods[i].vendor,				    eap_methods[i].method);		if (name) {			ret = os_snprintf(pos, end - pos, "%s%s",					  pos == buf ? "" : " ", name);			if (ret < 0 || ret >= end - pos)				break;			pos += ret;		}	}	end[-1] = '\0';	return buf;}#endif /* IEEE8021X_EAPOL */static int wpa_config_parse_wep_key(u8 *key, size_t *len, int line,				    const char *value, int idx){	char *buf, title[20];	buf = wpa_config_parse_string(value, len);	if (buf == NULL) {		wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key %d '%s'.",			   line, idx, value);		return -1;	}	if (*len > MAX_WEP_KEY_LEN) {		wpa_printf(MSG_ERROR, "Line %d: Too long WEP key %d '%s'.",			   line, idx, value);		os_free(buf);		return -1;	}	os_memcpy(key, buf, *len);	os_free(buf);	os_snprintf(title, sizeof(title), "wep_key%d", idx);	wpa_hexdump_key(MSG_MSGDUMP, title, key, *len);	return 0;}static int wpa_config_parse_wep_key0(const struct parse_data *data,				     struct wpa_ssid *ssid, int line,				     const char *value){	return wpa_config_parse_wep_key(ssid->wep_key[0],					&ssid->wep_key_len[0], line,					value, 0);}static int wpa_config_parse_wep_key1(const struct parse_data *data,				     struct wpa_ssid *ssid, int line,				     const char *value){	return wpa_config_parse_wep_key(ssid->wep_key[1],					&ssid->wep_key_len[1], line,					value, 1);}static int wpa_config_parse_wep_key2(const struct parse_data *data,				     struct wpa_ssid *ssid, int line,				     const char *value){	return wpa_config_parse_wep_key(ssid->wep_key[2],					&ssid->wep_key_len[2], line,					value, 2);}static int wpa_config_parse_wep_key3(const struct parse_data *data,				     struct wpa_ssid *ssid, int line,				     const char *value){	return wpa_config_parse_wep_key(ssid->wep_key[3],					&ssid->wep_key_len[3], line,					value, 3);}static char * wpa_config_write_wep_key(struct wpa_ssid *ssid, int idx){	if (ssid->wep_key_len[idx] == 0)		return NULL;	return wpa_config_write_string(ssid->wep_key[idx],				       ssid->wep_key_len[idx]);}static char * wpa_config_write_wep_key0(const struct parse_data *data,					struct wpa_ssid *ssid){	return wpa_config_write_wep_key(ssid, 0);}static char * wpa_config_write_wep_key1(const struct parse_data *data,					struct wpa_ssid *ssid){	return wpa_config_write_wep_key(ssid, 1);}static char * wpa_config_write_wep_key2(const struct parse_data *data,					struct wpa_ssid *ssid){	return wpa_config_write_wep_key(ssid, 2);}static char * wpa_config_write_wep_key3(const struct parse_data *data,					struct wpa_ssid *ssid){	return wpa_config_write_wep_key(ssid, 3);}/* Helper macros for network block parser */#ifdef OFFSET#undef OFFSET#endif /* OFFSET *//* OFFSET: Get offset of a variable within the wpa_ssid structure */#define OFFSET(v) ((void *) &((struct wpa_ssid *) 0)->v)/* STR: Define a string variable for an ASCII string; f = field name */#define _STR(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(f)#define STR(f) _STR(f), NULL, NULL, NULL, 0#define STR_KEY(f) _STR(f), NULL, NULL, NULL, 1/* STR_LEN: Define a string variable with a separate variable for storing the * data length. Unlike STR(), this can be used to store arbitrary binary data * (i.e., even nul termination character). */#define _STR_LEN(f) _STR(f), OFFSET(f ## _len)#define STR_LEN(f) _STR_LEN(f), NULL, NULL, 0#define STR_LEN_KEY(f) _STR_LEN(f), NULL, NULL, 1/* STR_RANGE: Like STR_LEN(), but with minimum and maximum allowed length * explicitly specified. */#define _STR_RANGE(f, min, max) _STR_LEN(f), (void *) (min), (void *) (max)#define STR_RANGE(f, min, max) _STR_RANGE(f, min, max), 0#define STR_RANGE_KEY(f, min, max) _STR_RANGE(f, min, max), 1#define _INT(f) #f, wpa_config_parse_int, wpa_config_write_int, \	OFFSET(f), (void *) 0/* INT: Define an integer variable */#define INT(f) _INT(f), NULL, NULL, 0/* INT_RANGE: Define an integer variable with allowed value range */#define INT_RANGE(f, min, max) _INT(f), (void *) (min), (void *) (max), 0/* FUNC: Define a configuration variable that uses a custom function for * parsing and writing the value. */#define _FUNC(f) #f, wpa_config_parse_ ## f, wpa_config_write_ ## f, \	NULL, NULL, NULL, NULL#define FUNC(f) _FUNC(f), 0#define FUNC_KEY(f) _FUNC(f), 1/* * Table of network configuration variables. This table is used to parse each * network configuration variable, e.g., each line in wpa_supplicant.conf file * that is inside a network block. * * This table is generated using the helper macros defined above and with * generous help from the C pre-processor. The field name is stored as a string * into .name and for STR and INT types, the offset of the target buffer within * struct wpa_ssid is stored in .param1. .param2 (if not NULL) is similar * offset to the field containing the length of the configuration variable. * .param3 and .param4 can be used to mark the allowed range (length for STR * and value for INT). * * For each configuration line in wpa_supplicant.conf, the parser goes through * this table and select the entry that matches with the field name. The parser * function (.parser) is then called to parse the actual value of the field. * * This kind of mechanism makes it easy to add new configuration parameters, * since only one line needs to be added into this table and into the * struct wpa_ssid definition if the new variable is either a string or * integer. More complex types will need to use their own parser and writer * functions. */static const struct parse_data ssid_fields[] = {	{ STR_RANGE(ssid, 0, MAX_SSID_LEN) },	{ INT_RANGE(scan_ssid, 0, 1) },	{ FUNC(bssid) },	{ FUNC_KEY(psk) },	{ FUNC(proto) },	{ FUNC(key_mgmt) },	{ FUNC(pairwise) },	{ FUNC(group) },	{ FUNC(auth_alg) },#ifdef IEEE8021X_EAPOL	{ FUNC(eap) },	{ STR_LEN(identity) },	{ STR_LEN(anonymous_identity) },	{ STR_RANGE_KEY(eappsk, EAP_PSK_LEN_MIN, EAP_PSK_LEN_MAX) },	{ STR_LEN(nai) },	{ STR_LEN_KEY(password) },	{ STR(ca_cert) },	{ STR(ca_path) },	{ STR(client_cert) },	{ STR(private_key) },	{ STR_KEY(private_key_passwd) },	{ STR(dh_file) },	{ STR(subject_match) },	{ STR(altsubject_match) },	{ STR(ca_cert2) },	{ STR(ca_path2) },	{ STR(client_cert2) },	{ STR(private_key2) },	{ STR_KEY(private_key2_passwd) },	{ STR(dh_file2) },	{ STR(subject_match2) },	{ STR(altsubject_match2) },	{ STR(phase1) },	{ STR(phase2) },	{ STR(pcsc) },	{ STR_KEY(pin) },	{ STR(engine_id) },	{ STR(key_id) },	{ INT(engine) },	{ INT(eapol_flags) },#endif /* IEEE8021X_EAPOL */	{ FUNC_KEY(wep_key0) },	{ FUNC_KEY(wep_key1) },	{ FUNC_KEY(wep_key2) },	{ FUNC_KEY(wep_key3) },	{ INT(wep_tx_keyidx) },	{ INT(priority) },#ifdef IEEE8021X_EAPOL	{ INT(eap_workaround) },	{ STR(pac_file) },	{ INT(fragment_size) },#endif /* IEEE8021X_EAPOL */	{ INT_RANGE(mode, 0, 1) },	{ INT_RANGE(proactive_key_caching, 0, 1) },	{ INT_RANGE(disabled, 0, 1) },	{ STR(id_str) },#ifdef CONFIG_IEEE80211W	{ INT_RANGE(ieee80211w, 0, 2) },#endif /* CONFIG_IEEE80211W */	{ INT_RANGE(peerkey, 0, 1) },	{ INT_RANGE(mixed_cell, 0, 1) },	{ INT_RANGE(frequency, 0, 10000) }};#undef OFFSET#undef _STR#undef STR#undef STR_KEY#undef _STR_LEN#undef STR_LEN#undef STR_LEN_KEY#undef _STR_RANGE#undef STR_RANGE

⌨️ 快捷键说明

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