Ejemplo n.º 1
0
static void test_EnumProcesses(void)
{
    DWORD pid, cbUsed = 0xdeadbeef;

    if(w32_suc(pEnumProcesses(NULL, 0, &cbUsed)))
        ok(cbUsed == 0, "cbUsed=%d\n", cbUsed);
    if(w32_suc(pEnumProcesses(&pid, 4, &cbUsed)))
        ok(cbUsed == 4, "cbUsed=%d\n", cbUsed);
}
Ejemplo n.º 2
0
static void test_EnumProcesses(void)
{
    DWORD pid, ret, cbUsed = 0xdeadbeef;

    SetLastError(0xdeadbeef);
    ret = pEnumProcesses(NULL, 0, &cbUsed);
    ok(ret == 1, "failed with %d\n", GetLastError());
    ok(cbUsed == 0, "cbUsed=%d\n", cbUsed);

    SetLastError(0xdeadbeef);
    ret = pEnumProcesses(&pid, 4, &cbUsed);
    ok(ret == 1, "failed with %d\n", GetLastError());
    ok(cbUsed == 4, "cbUsed=%d\n", cbUsed);
}
Ejemplo n.º 3
0
BOOL
load_config(const char *config)
{
	char *section = NULL, *p;
	DWORD n, pids[100];
	BOOL result = FALSE;
	int line, chain, i;

	if (!read_config(config))
		return FALSE;

	// save config to global variable (for get_host_by_name)
	g_config_file = config;

	// load information about users
	if (!load_users(config)) {
		error("start: Fatal error! Can't load users information!\n");
		goto done;
	}

	// parse & add rules default and process-related

	section = (char *)malloc(MAX_SECTION_SIZE);
	if (section == NULL) {
		liberr("malloc");
		goto done;
	}

	GetPrivateProfileSection("_main_", section, MAX_SECTION_SIZE, config);
	
	// get lines
	chain = 0;
	for (p = section, line = 1; *p != '\0'; p += strlen(p) + 1, line++) {
		char *p2;

		if (*p == ';' || *p == '#')
			continue;		// comment

		p2 = strchr(p, '=');
		if (p2 == NULL) {
			error("%s:[_main_]:%d: invalid line format (no '=' character)", config, line);
			continue;
		}

		if (chain >= MAX_CHAINS_COUNT) {
			error("%s:[_main_]:%d: too many rules lines!", config, line);
			break;
		}

		*p2 = '\0';		// temporary kill '='
		add_rules_name(p, config, chain);
		*p2 = '=';		// recover '=' to make strlen(p) works right

		chain++;
	}

	// try to get names for existing processes
	if (pEnumProcesses != NULL && pEnumProcesses(pids, sizeof(pids), &n)) {
		DWORD i;

		n /= sizeof(DWORD);

		for (i = 0; i < n; i++) {
			char pname[MAX_PATH];
			if (get_pname_by_pid(pids[i], pname + sizeof(DWORD), sizeof(pname) - sizeof(DWORD))) {
				// send information to driver about pid and pname
				
				DWORD nn;
				
				*(DWORD *)pname = pids[i];

				if (!DeviceIoControl(g_device, IOCTL_CMD_SETPNAME, pname,
					sizeof(DWORD) + strlen(pname + sizeof(DWORD)) + 1,
					NULL, 0, &nn, NULL))
					winerr("DeviceIoControl");
			}
		}
	}

	// activate all chains!
	for (i = 0; i < chain; i++) {
		// activate chain #i
		if (!DeviceIoControl(g_device, IOCTL_CMD_ACTIVATECHAIN, &i, sizeof(i),
				NULL, 0, &n, NULL))
			winerr("start: DeviceIoControl");
	}

	result = TRUE;
done:
	free(section);
	return result;
}