コード例 #1
0
ファイル: advproc.c プロジェクト: angelkyo/openwrt-maz1
/**
创建需要用到的proc文件

@return 成功返回 RR_OK,失败返回 RR_FAIL。
*/
int create_proc_file(void)
{
	int ret = ADV_KILL_OK;
	//web config
	advkillconfdata = (char *)ADVKILL_CALLOC(1, MAX_ADVKILL_CONF_LEN);
	if (advkillconfdata == NULL)
		return ADV_KILL_FAIL;
	
	proc_dir = proc_mkdir(ADV_KILL_PROC_DIRECTORY, NULL);
	if (proc_dir == NULL) 
	{
		ret = -ENOMEM;
		printk(KERN_ERR "Couldn't create proc dir[/proc/%s]\n", ADV_KILL_PROC_DIRECTORY);
		goto exit_fail;
	}
	else
	{
#if (LINUX_VERSION_CODE < KERNEL_VERSION (3, 10, 0))
		proc_advkill_conf = create_proc_entry(ADV_KILL_PROC_FILE, 0644, proc_dir);
		if (proc_advkill_conf == NULL)
		{
			printk(KERN_ERR "Couldn't create proc entry[/proc/%s/%s]\n", ADV_KILL_PROC_DIRECTORY, ADV_KILL_PROC_FILE);
			ret = -ENOMEM;
			goto exit_fail;
		}
		proc_advkill_conf->read_proc = advkill_conf_read;
		proc_advkill_conf->write_proc = advkill_conf_write;
#else
		proc_advkill_conf = proc_create(ADV_KILL_PROC_FILE, 0644, proc_dir, &advkill_fops);
		if (proc_advkill_conf == NULL)
		{
			printk(KERN_ERR "Couldn't create proc entry[/proc/%s/%s]\n", ADV_KILL_PROC_DIRECTORY, ADV_KILL_PROC_FILE);
			ret = -ENOMEM;
			goto exit_fail;
		}
#endif
	}

	return ret;

exit_fail:
	if (advkillconfdata != NULL)
	{
		ADVKILL_FREE(advkillconfdata, MAX_ADVKILL_CONF_LEN);
		advkillconfdata = NULL;
	}
	if (proc_dir != NULL)
	{
		remove_proc_entry(ADV_KILL_PROC_FILE, proc_dir);
		proc_dir = NULL;
	}
	return ret;	
}
コード例 #2
0
ファイル: pkgoper.c プロジェクト: angelkyo/openwrt-maz1
/*
 发送伪造的HTTP200响应
 @param skb 原始的sk_buff结构地址 CType Content-Type Cont 网页内容
 @return 成功返回 ADV_KILL_OK,失败返回 ADV_KILL_FAIL。
HTTP/1.1 200 OK\r\n
Server: QWS\r\n
Content-Type: text/xml\r\n
Content-Length: 125\r\n
Connection: close\r\n
Accept-Ranges: bytes\r\n\r\n
*/
int send_client_fake_message(struct sk_buff *skb, const char * CType, const char * Cont)
{
	char *new_data = NULL;
	int retval = 0, datlen = 0;

	if(!skb)
		return ADV_KILL_FAIL;

	datlen = strlen(CType)+strlen(Cont)+120;
	new_data = (char *)ADVKILL_CALLOC(1, datlen);
	if(new_data==NULL)
		return ADV_KILL_FAIL;
	sprintf(new_data,"HTTP/1.1 200 OK\r\nServer: QWS\r\nContent-Type: %s\r\nContent-Length: %d\r\nConnection: close\r\nAccept-Ranges: bytes\r\n\r\n%s",CType,strlen(Cont),Cont);
	retval=pkg_skbuff_dev_xmit(skb, new_data, strlen(new_data));
	ADVKILL_FREE(new_data, datlen);
	return retval;
}
コード例 #3
0
ファイル: pkgoper.c プロジェクト: sniperpr/adkill
/**
根据Host生成location字符串

@param httplen 生成的location长度
@param host Host字符串内容
@return 成功返回location地址,失败返回NULL。
*/
char *http_location_str_generate(int *httplen, char *host)
{
	char *new_data = NULL;
	int http_len = 0, new_offset = 0;
	char *response_head = HTTP_RESPONSE_HEAD_NOT_FIND;
	char *location = HTTP_RESPONSE_LOCATION;
	char *ending = HTTP_RESPONSE_END;
	int hostlen = 0;

	if(!httplen || !host)
		return NULL;

	hostlen = strlen(host);
	http_len = (HTTP_RESPONSE_HEAD_NOT_FIND_LEN + HTTP_RESPONSE_LOCATION_LEN + hostlen + 4);
	*httplen = http_len;
	new_data = (char *)ADVKILL_CALLOC(1, http_len+1);
	if(new_data == NULL)
	{
		goto err;
	}
	//http 302
	memcpy(new_data, response_head, HTTP_RESPONSE_HEAD_NOT_FIND_LEN);
	new_offset += HTTP_RESPONSE_HEAD_NOT_FIND_LEN;
	//location
	memcpy(new_data + new_offset, location, HTTP_RESPONSE_LOCATION_LEN);
	new_offset += HTTP_RESPONSE_LOCATION_LEN;
	//host
	memcpy(new_data + new_offset, host, hostlen);
	new_offset += hostlen;
	//\r\n
	memcpy(new_data + new_offset, ending, HTTP_RESPONSE_END_LEN);
	new_offset += HTTP_RESPONSE_END_LEN;
	memcpy(new_data + new_offset, ending, HTTP_RESPONSE_END_LEN);

	return new_data;

err:
	return NULL;
}