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

📄 tncc.c

📁 最新的Host AP 新添加了许多pcmcia 的驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
	{		TCHAR *lib = wpa_strdup_tchar(imc->path);		if (lib == NULL)			return -1;		imc->dlhandle = LoadLibrary(lib);		os_free(lib);	}#else /* UNICODE */	imc->dlhandle = LoadLibrary(imc->path);#endif /* UNICODE */	if (imc->dlhandle == NULL) {		wpa_printf(MSG_ERROR, "TNC: Failed to open IMC '%s' (%s): %d",			   imc->name, imc->path, (int) GetLastError());		return -1;	}#else /* CONFIG_NATIVE_WINDOWS */	imc->dlhandle = dlopen(imc->path, RTLD_LAZY);	if (imc->dlhandle == NULL) {		wpa_printf(MSG_ERROR, "TNC: Failed to open IMC '%s' (%s): %s",			   imc->name, imc->path, dlerror());		return -1;	}#endif /* CONFIG_NATIVE_WINDOWS */	if (tncc_imc_resolve_funcs(imc) < 0) {		wpa_printf(MSG_ERROR, "TNC: Failed to resolve IMC functions");		return -1;	}	if (tncc_imc_initialize(imc) < 0 ||	    tncc_imc_provide_bind_function(imc) < 0) {		wpa_printf(MSG_ERROR, "TNC: Failed to initialize IMC");		return -1;	}	return 0;}static void tncc_unload_imc(struct tnc_if_imc *imc){	tncc_imc_terminate(imc);	tnc_imc[imc->imcID] = NULL;	if (imc->dlhandle) {#ifdef CONFIG_NATIVE_WINDOWS		FreeLibrary(imc->dlhandle);#else /* CONFIG_NATIVE_WINDOWS */		dlclose(imc->dlhandle);#endif /* CONFIG_NATIVE_WINDOWS */	}	os_free(imc->name);	os_free(imc->path);	os_free(imc->supported_types);	os_free(imc->imc_send);}static int tncc_supported_type(struct tnc_if_imc *imc, unsigned int type){	size_t i;	unsigned int vendor, subtype;	if (imc == NULL || imc->supported_types == NULL)		return 0;	vendor = type >> 8;	subtype = type & 0xff;	for (i = 0; i < imc->num_supported_types; i++) {		unsigned int svendor, ssubtype;		svendor = imc->supported_types[i] >> 8;		ssubtype = imc->supported_types[i] & 0xff;		if ((vendor == svendor || svendor == TNC_VENDORID_ANY) &&		    (subtype == ssubtype || ssubtype == TNC_SUBTYPE_ANY))			return 1;	}	return 0;}static void tncc_send_to_imcs(struct tncc_data *tncc, unsigned int type,			      const u8 *msg, size_t len){	struct tnc_if_imc *imc;	TNC_Result res;	wpa_hexdump_ascii(MSG_MSGDUMP, "TNC: Message to IMC(s)", msg, len);	for (imc = tncc->imc; imc; imc = imc->next) {		if (imc->ReceiveMessage == NULL ||		    !tncc_supported_type(imc, type))			continue;		wpa_printf(MSG_DEBUG, "TNC: Call ReceiveMessage for IMC '%s'",			   imc->name);		res = imc->ReceiveMessage(imc->imcID, imc->connectionID,					  (TNC_BufferReference) msg, len,					  type);		wpa_printf(MSG_DEBUG, "TNC: ReceiveMessage: %lu",			   (unsigned long) res);	}}void tncc_init_connection(struct tncc_data *tncc){	struct tnc_if_imc *imc;	for (imc = tncc->imc; imc; imc = imc->next) {		tncc_imc_notify_connection_change(			imc, TNC_CONNECTION_STATE_CREATE);		tncc_imc_notify_connection_change(			imc, TNC_CONNECTION_STATE_HANDSHAKE);		os_free(imc->imc_send);		imc->imc_send = NULL;		imc->imc_send_len = 0;		tncc_imc_begin_handshake(imc);	}}size_t tncc_total_send_len(struct tncc_data *tncc){	struct tnc_if_imc *imc;	size_t len = 0;	for (imc = tncc->imc; imc; imc = imc->next)		len += imc->imc_send_len;	return len;}u8 * tncc_copy_send_buf(struct tncc_data *tncc, u8 *pos){	struct tnc_if_imc *imc;	for (imc = tncc->imc; imc; imc = imc->next) {		if (imc->imc_send == NULL)			continue;		os_memcpy(pos, imc->imc_send, imc->imc_send_len);		pos += imc->imc_send_len;		os_free(imc->imc_send);		imc->imc_send = NULL;		imc->imc_send_len = 0;	}	return pos;}char * tncc_if_tnccs_start(struct tncc_data *tncc){	char *buf = os_malloc(1000);	if (buf == NULL)		return NULL;	tncc->last_batchid++;	os_snprintf(buf, 1000, IF_TNCCS_START, tncc->last_batchid);	return buf;}char * tncc_if_tnccs_end(void){	char *buf = os_malloc(100);	if (buf == NULL)		return NULL;	os_snprintf(buf, 100, IF_TNCCS_END);	return buf;}static void tncc_notify_recommendation(struct tncc_data *tncc,				       enum tncc_process_res res){	TNC_ConnectionState state;	struct tnc_if_imc *imc;	switch (res) {	case TNCCS_RECOMMENDATION_ALLOW:		state = TNC_CONNECTION_STATE_ACCESS_ALLOWED;		break;	case TNCCS_RECOMMENDATION_NONE:		state = TNC_CONNECTION_STATE_ACCESS_NONE;		break;	case TNCCS_RECOMMENDATION_ISOLATE:		state = TNC_CONNECTION_STATE_ACCESS_ISOLATED;		break;	default:		state = TNC_CONNECTION_STATE_ACCESS_NONE;		break;	}	for (imc = tncc->imc; imc; imc = imc->next)		tncc_imc_notify_connection_change(imc, state);}static int tncc_get_type(char *start, unsigned int *type){	char *pos = os_strstr(start, "<Type>");	if (pos == NULL)		return -1;	pos += 6;	*type = strtoul(pos, NULL, 16);	return 0;}static unsigned char * tncc_get_base64(char *start, size_t *decoded_len){	char *pos, *pos2;	unsigned char *decoded;	pos = os_strstr(start, "<Base64>");	if (pos == NULL)		return NULL;	pos += 8;	pos2 = os_strstr(pos, "</Base64>");	if (pos2 == NULL)		return NULL;	*pos2 = '\0';	decoded = base64_decode((unsigned char *) pos, os_strlen(pos),				decoded_len);	*pos2 = '<';	if (decoded == NULL) {		wpa_printf(MSG_DEBUG, "TNC: Failed to decode Base64 data");	}	return decoded;}static enum tncc_process_res tncc_get_recommendation(char *start){	char *pos, *pos2, saved;	int recom;	pos = os_strstr(start, "<TNCCS-Recommendation ");	if (pos == NULL)		return TNCCS_RECOMMENDATION_ERROR;	pos += 21;	pos = os_strstr(pos, " type=");	if (pos == NULL)		return TNCCS_RECOMMENDATION_ERROR;	pos += 6;	if (*pos == '"')		pos++;	pos2 = pos;	while (*pos2 != '\0' && *pos2 != '"' && *pos2 != '>')		pos2++;	if (*pos2 == '\0')		return TNCCS_RECOMMENDATION_ERROR;	saved = *pos2;	*pos2 = '\0';	wpa_printf(MSG_DEBUG, "TNC: TNCCS-Recommendation: '%s'", pos);	recom = TNCCS_RECOMMENDATION_ERROR;	if (os_strcmp(pos, "allow") == 0)		recom = TNCCS_RECOMMENDATION_ALLOW;	else if (os_strcmp(pos, "none") == 0)		recom = TNCCS_RECOMMENDATION_NONE;	else if (os_strcmp(pos, "isolate") == 0)		recom = TNCCS_RECOMMENDATION_ISOLATE;	*pos2 = saved;	return recom;}enum tncc_process_res tncc_process_if_tnccs(struct tncc_data *tncc,					    const u8 *msg, size_t len){	char *buf, *start, *end, *pos, *pos2, *payload;	unsigned int batch_id;	unsigned char *decoded;	size_t decoded_len;	enum tncc_process_res res = TNCCS_PROCESS_OK_NO_RECOMMENDATION;	int recommendation_msg = 0;	buf = os_malloc(len + 1);	if (buf == NULL)		return TNCCS_PROCESS_ERROR;	os_memcpy(buf, msg, len);	buf[len] = '\0';	start = os_strstr(buf, "<TNCCS-Batch ");	end = os_strstr(buf, "</TNCCS-Batch>");	if (start == NULL || end == NULL || start > end) {		os_free(buf);		return TNCCS_PROCESS_ERROR;	}	start += 13;	while (*start == ' ')		start++;	*end = '\0';	pos = os_strstr(start, "BatchId=");	if (pos == NULL) {		os_free(buf);		return TNCCS_PROCESS_ERROR;	}	pos += 8;	if (*pos == '"')		pos++;	batch_id = atoi(pos);	wpa_printf(MSG_DEBUG, "TNC: Received IF-TNCCS BatchId=%u",		   batch_id);	if (batch_id != tncc->last_batchid + 1) {		wpa_printf(MSG_DEBUG, "TNC: Unexpected IF-TNCCS BatchId "			   "%u (expected %u)",			   batch_id, tncc->last_batchid + 1);		os_free(buf);		return TNCCS_PROCESS_ERROR;	}	tncc->last_batchid = batch_id;	while (*pos != '\0' && *pos != '>')		pos++;	if (*pos == '\0') {		os_free(buf);		return TNCCS_PROCESS_ERROR;	}	pos++;	payload = start;	/*	 * <IMC-IMV-Message>	 * <Type>01234567</Type>	 * <Base64>foo==</Base64>	 * </IMC-IMV-Message>	 */	while (*start) {		char *endpos;		unsigned int type;		pos = os_strstr(start, "<IMC-IMV-Message>");		if (pos == NULL)			break;		start = pos + 17;		end = os_strstr(start, "</IMC-IMV-Message>");		if (end == NULL)			break;		*end = '\0';		endpos = end;		end += 18;		if (tncc_get_type(start, &type) < 0) {			*endpos = '<';			start = end;			continue;		}		wpa_printf(MSG_DEBUG, "TNC: IMC-IMV-Message Type 0x%x", type);		decoded = tncc_get_base64(start, &decoded_len);		if (decoded == NULL) {			*endpos = '<';			start = end;			continue;		}		tncc_send_to_imcs(tncc, type, decoded, decoded_len);		os_free(decoded);		start = end;	}	/*	 * <TNCC-TNCS-Message>	 * <Type>01234567</Type>	 * <XML><TNCCS-Foo type="foo"></TNCCS-Foo></XML>	 * <Base64>foo==</Base64>	 * </TNCC-TNCS-Message>	 */	start = payload;	while (*start) {		unsigned int type;		char *xml, *xmlend, *endpos;		pos = os_strstr(start, "<TNCC-TNCS-Message>");		if (pos == NULL)			break;		start = pos + 19;		end = os_strstr(start, "</TNCC-TNCS-Message>");		if (end == NULL)			break;		*end = '\0';		endpos = end;		end += 20;		if (tncc_get_type(start, &type) < 0) {			*endpos = '<';			start = end;			continue;		}		wpa_printf(MSG_DEBUG, "TNC: TNCC-TNCS-Message Type 0x%x",			   type);		/* Base64 OR XML */		decoded = NULL;		xml = NULL;		xmlend = NULL;		pos = os_strstr(start, "<XML>");		if (pos) {			pos += 5;			pos2 = os_strstr(pos, "</XML>");			if (pos2 == NULL) {				*endpos = '<';				start = end;				continue;			}			xmlend = pos2;			xml = pos;		} else {			decoded = tncc_get_base64(start, &decoded_len);			if (decoded == NULL) {				*endpos = '<';				start = end;				continue;			}		}		if (decoded) {			wpa_hexdump_ascii(MSG_MSGDUMP,					  "TNC: TNCC-TNCS-Message Base64",					  decoded, decoded_len);			os_free(decoded);		}		if (xml) {			wpa_hexdump_ascii(MSG_MSGDUMP,					  "TNC: TNCC-TNCS-Message XML",					  (unsigned char *) xml,					  xmlend - xml);		}		if (type == TNC_TNCCS_RECOMMENDATION && xml) {			/*			 * <TNCCS-Recommendation type="allow">			 * </TNCCS-Recommendation>

⌨️ 快捷键说明

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