Exemplo n.º 1
0
int main(int argc, const char **argv)
{
	NET_API_STATUS status;
	struct libnetapi_ctx *ctx = NULL;
	const char *hostname = NULL;
	const char *sharename = NULL;

	poptContext pc;
	int opt;

	struct poptOption long_options[] = {
		POPT_AUTOHELP
		POPT_COMMON_LIBNETAPI_EXAMPLES
		POPT_TABLEEND
	};

	status = libnetapi_init(&ctx);
	if (status != 0) {
		return status;
	}

	pc = poptGetContext("share_del", argc, argv, long_options, 0);

	poptSetOtherOptionHelp(pc, "hostname sharename");
	while((opt = poptGetNextOpt(pc)) != -1) {
	}

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	hostname = poptGetArg(pc);

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	sharename = poptGetArg(pc);

	/* NetShareDel */

	status = NetShareDel(hostname,
			     sharename,
			     0);
	if (status != 0) {
		printf("NetShareDel failed with: %s\n",
			libnetapi_get_error_string(ctx, status));
		goto out;
	}

 out:
	libnetapi_free(ctx);
	poptFreeContext(pc);

	return status;
}
Exemplo n.º 2
0
int main(int argc, const char **argv)
{
	NET_API_STATUS status;
	struct libnetapi_ctx *ctx = NULL;
	const char *hostname = NULL;
	uint32_t level = 0;
	uint8_t *buffer = NULL;
	uint32_t entries_read = 0;
	uint32_t total_entries = 0;
	uint32_t resume_handle = 0;
	int i;

	struct SHARE_INFO_0 *i0 = NULL;
	struct SHARE_INFO_1 *i1 = NULL;
	struct SHARE_INFO_2 *i2 = NULL;

	poptContext pc;
	int opt;

	struct poptOption long_options[] = {
		POPT_AUTOHELP
		POPT_COMMON_LIBNETAPI_EXAMPLES
		POPT_TABLEEND
	};

	status = libnetapi_init(&ctx);
	if (status != 0) {
		return status;
	}

	pc = poptGetContext("share_enum", argc, argv, long_options, 0);

	poptSetOtherOptionHelp(pc, "hostname level");
	while((opt = poptGetNextOpt(pc)) != -1) {
	}

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	hostname = poptGetArg(pc);

	if (poptPeekArg(pc)) {
		level = atoi(poptGetArg(pc));
	}

	/* NetShareEnum */

	do {
		status = NetShareEnum(hostname,
				      level,
				      &buffer,
				      (uint32_t)-1,
				      &entries_read,
				      &total_entries,
				      &resume_handle);
		if (status == 0 || status == ERROR_MORE_DATA) {
			printf("total entries: %d\n", total_entries);
			switch (level) {
				case 0:
					i0 = (struct SHARE_INFO_0 *)buffer;
					break;
				case 1:
					i1 = (struct SHARE_INFO_1 *)buffer;
					break;
				case 2:
					i2 = (struct SHARE_INFO_2 *)buffer;
					break;
				default:
					break;
			}
			for (i=0; i<entries_read; i++) {
				switch (level) {
					case 0:
						printf("#%d netname: %s\n", i, i0->shi0_netname);
						i0++;
						break;
					case 1:
						printf("#%d netname: %s\n", i, i1->shi1_netname);
						printf("#%d type: %d\n", i, i1->shi1_type);
						printf("#%d remark: %s\n", i, i1->shi1_remark);
						i1++;
						break;
					case 2:
						printf("#%d netname: %s\n", i, i2->shi2_netname);
						printf("#%d type: %d\n", i, i2->shi2_type);
						printf("#%d remark: %s\n", i, i2->shi2_remark);
						printf("#%d permissions: %d\n", i, i2->shi2_permissions);
						printf("#%d max users: %d\n", i, i2->shi2_max_uses);
						printf("#%d current users: %d\n", i, i2->shi2_current_uses);
						printf("#%d path: %s\n", i, i2->shi2_path);
						printf("#%d password: %s\n", i, i2->shi2_passwd);
						i2++;
						break;
					default:
						break;
				}
			}
			NetApiBufferFree(buffer);
		}
	} while (status == ERROR_MORE_DATA);

	if (status != 0) {
		printf("NetShareEnum failed with: %s\n",
			libnetapi_get_error_string(ctx, status));
	}

 out:
	libnetapi_free(ctx);
	poptFreeContext(pc);

	return status;
}
Exemplo n.º 3
0
NET_API_STATUS netapitest_group(struct libnetapi_ctx *ctx,
				const char *hostname)
{
	NET_API_STATUS status = 0;
	const char *username, *groupname, *groupname2;
	uint8_t *buffer = NULL;
	struct GROUP_INFO_0 g0;
	uint32_t parm_err = 0;
	uint32_t levels[] = { 0, 1, 2, 3};
	uint32_t enum_levels[] = { 0, 1, 2, 3};
	uint32_t getmem_levels[] = { 0, 1};
	int i;

	printf("NetGroup tests\n");

	username = "******";
	groupname = "torture_test_group";
	groupname2 = "torture_test_group2";

	/* cleanup */
	NetGroupDel(hostname, groupname);
	NetGroupDel(hostname, groupname2);
	NetUserDel(hostname, username);

	/* add a group */

	g0.grpi0_name = groupname;

	printf("testing NetGroupAdd\n");

	status = NetGroupAdd(hostname, 0, (uint8_t *)&g0, &parm_err);
	if (status) {
		NETAPI_STATUS(ctx, status, "NetGroupAdd");
		goto out;
	}

	/* 2nd add must fail */

	status = NetGroupAdd(hostname, 0, (uint8_t *)&g0, &parm_err);
	if (status == 0) {
		NETAPI_STATUS(ctx, status, "NetGroupAdd");
		goto out;
	}

	/* test enum */

	for (i=0; i<ARRAY_SIZE(enum_levels); i++) {

		status = test_netgroupenum(hostname, enum_levels[i], groupname);
		if (status) {
			NETAPI_STATUS(ctx, status, "NetGroupEnum");
			goto out;
		}
	}

	/* basic queries */

	for (i=0; i<ARRAY_SIZE(levels); i++) {

		printf("testing NetGroupGetInfo level %d\n", levels[i]);

		status = NetGroupGetInfo(hostname, groupname, levels[i], &buffer);
		if (status && status != 124) {
			NETAPI_STATUS(ctx, status, "NetGroupGetInfo");
			goto out;
		}
	}

	/* group rename */

	g0.grpi0_name = groupname2;

	printf("testing NetGroupSetInfo level 0\n");

	status = NetGroupSetInfo(hostname, groupname, 0, (uint8_t *)&g0, &parm_err);
	switch (status) {
		case 0:
			break;
		case 50: /* not supported */
		case 124: /* not implemented */
			groupname2 = groupname;
			goto skip_rename;
		default:
			NETAPI_STATUS(ctx, status, "NetGroupSetInfo");
			goto out;
	}

	/* should not exist anymore */

	status = NetGroupDel(hostname, groupname);
	if (status == 0) {
		NETAPI_STATUS(ctx, status, "NetGroupDel");
		goto out;
	}

 skip_rename:
	/* query info */

	for (i=0; i<ARRAY_SIZE(levels); i++) {

		status = NetGroupGetInfo(hostname, groupname2, levels[i], &buffer);
		if (status && status != 124) {
			NETAPI_STATUS(ctx, status, "NetGroupGetInfo");
			goto out;
		}
	}

	/* add user to group */

	status = test_netuseradd(hostname, username);
	if (status) {
		NETAPI_STATUS(ctx, status, "NetUserAdd");
		goto out;
	}

	/* should not be member */

	for (i=0; i<ARRAY_SIZE(getmem_levels); i++) {

		status = test_netgroupgetusers(hostname, getmem_levels[i], groupname2, NULL);
		if (status) {
			NETAPI_STATUS(ctx, status, "NetGroupGetUsers");
			goto out;
		}
	}

	printf("testing NetGroupAddUser\n");

	status = NetGroupAddUser(hostname, groupname2, username);
	if (status) {
		NETAPI_STATUS(ctx, status, "NetGroupAddUser");
		goto out;
	}

	/* should be member */

	for (i=0; i<ARRAY_SIZE(getmem_levels); i++) {

		status = test_netgroupgetusers(hostname, getmem_levels[i], groupname2, username);
		if (status) {
			NETAPI_STATUS(ctx, status, "NetGroupGetUsers");
			goto out;
		}
	}

	printf("testing NetGroupDelUser\n");

	status = NetGroupDelUser(hostname, groupname2, username);
	if (status) {
		NETAPI_STATUS(ctx, status, "NetGroupDelUser");
		goto out;
	}

	/* should not be member */

	status = test_netgroupgetusers(hostname, 0, groupname2, NULL);
	if (status) {
		NETAPI_STATUS(ctx, status, "NetGroupGetUsers");
		goto out;
	}

	/* set it again via exlicit member set */

	status = test_netgroupsetusers(hostname, groupname2, 0, 1, &username);
	if (status) {
		NETAPI_STATUS(ctx, status, "NetGroupSetUsers");
		goto out;
	}

	/* should be member */

	status = test_netgroupgetusers(hostname, 0, groupname2, username);
	if (status) {
		NETAPI_STATUS(ctx, status, "NetGroupGetUsers");
		goto out;
	}
#if 0
	/* wipe out member list */

	status = test_netgroupsetusers(hostname, groupname2, 0, 0, NULL);
	if (status) {
		NETAPI_STATUS(ctx, status, "NetGroupSetUsers");
		goto out;
	}

	/* should not be member */

	status = test_netgroupgetusers(hostname, 0, groupname2, NULL);
	if (status) {
		NETAPI_STATUS(ctx, status, "NetGroupGetUsers");
		goto out;
	}
#endif
	status = NetUserDel(hostname, username);
	if (status) {
		NETAPI_STATUS(ctx, status, "NetUserDel");
		goto out;
	}

	/* delete */

	printf("testing NetGroupDel\n");

	status = NetGroupDel(hostname, groupname2);
	if (status) {
		NETAPI_STATUS(ctx, status, "NetGroupDel");
		goto out;
	};

	/* should not exist anymore */

	status = NetGroupGetInfo(hostname, groupname2, 0, &buffer);
	if (status == 0) {
		NETAPI_STATUS_MSG(ctx, status, "NetGroupGetInfo", "expected failure and error code");
		goto out;
	};

	status = 0;

	printf("NetGroup tests succeeded\n");
 out:
	if (status != 0) {
		printf("NetGroup testsuite failed with: %s\n",
			libnetapi_get_error_string(ctx, status));
	}

	return status;
}
Exemplo n.º 4
0
int main(int argc, const char **argv)
{
	NET_API_STATUS status;
	struct libnetapi_ctx *ctx = NULL;
	const char *hostname = NULL;
	const char *sharename = NULL;
	const char *comment = "NetApi generated Share comment";
	uint32_t level = 1004;
	uint8_t *buffer = NULL;
	uint32_t parm_err = 0;

	struct SHARE_INFO_1004 i1004;

	poptContext pc;
	int opt;

	struct poptOption long_options[] = {
		POPT_AUTOHELP
		POPT_COMMON_LIBNETAPI_EXAMPLES
		POPT_TABLEEND
	};

	status = libnetapi_init(&ctx);
	if (status != 0) {
		return status;
	}

	pc = poptGetContext("share_setinfo", argc, argv, long_options, 0);

	poptSetOtherOptionHelp(pc, "hostname sharename comment");
	while((opt = poptGetNextOpt(pc)) != -1) {
	}

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	hostname = poptGetArg(pc);

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	sharename = poptGetArg(pc);

	if (poptPeekArg(pc)) {
		comment = poptGetArg(pc);
	}

	/* NetShareSetInfo */
	switch (level) {
		case 1004:
			i1004.shi1004_remark = comment;
			buffer = (uint8_t *)&i1004;
			break;
		default:
			break;
	}

	status = NetShareSetInfo(hostname,
				 sharename,
				 level,
				 buffer,
				 &parm_err);
	if (status != 0) {
		printf("NetShareSetInfo failed with: %s\n",
			libnetapi_get_error_string(ctx, status));
		goto out;
	}

 out:
	libnetapi_free(ctx);
	poptFreeContext(pc);

	return status;
}
Exemplo n.º 5
0
bool torture_libnetapi_user(struct torture_context *tctx)
{
	NET_API_STATUS status = 0;
	uint8_t *buffer = NULL;
	uint32_t levels[] = { 0, 1, 2, 3, 4, 10, 11, 20, 23 };
	uint32_t enum_levels[] = { 0, 1, 2, 3, 4, 10, 11, 20, 23 };
	uint32_t getgr_levels[] = { 0, 1 };
	int i;

	struct USER_INFO_0 u0;
	struct USER_INFO_1007 u1007;
	uint32_t parm_err = 0;

	const char *hostname = torture_setting_string(tctx, "host", NULL);
	struct libnetapi_ctx *ctx;

	torture_assert(tctx, torture_libnetapi_init_context(tctx, &ctx),
		       "failed to initialize libnetapi");

	torture_comment(tctx, "NetUser tests\n");

	/* cleanup */

	NetUserDel(hostname, TORTURE_TEST_USER);
	NetUserDel(hostname, TORTURE_TEST_USER2);

	/* add a user */

	status = test_netuseradd(tctx, hostname, TORTURE_TEST_USER);
	if (status) {
		NETAPI_STATUS(tctx, ctx, status, "NetUserAdd");
		goto out;
	}

	/* enum the new user */

	for (i=0; i<ARRAY_SIZE(enum_levels); i++) {

		status = test_netuserenum(tctx, hostname, enum_levels[i], TORTURE_TEST_USER);
		if (status) {
			NETAPI_STATUS(tctx, ctx, status, "NetUserEnum");
			goto out;
		}
	}

	/* basic queries */

	for (i=0; i<ARRAY_SIZE(levels); i++) {

		torture_comment(tctx, "Testing NetUserGetInfo level %d\n", levels[i]);

		status = NetUserGetInfo(hostname, TORTURE_TEST_USER, levels[i], &buffer);
		if (status && status != 124) {
			NETAPI_STATUS(tctx, ctx, status, "NetUserGetInfo");
			goto out;
		}
	}

	/* testing getgroups */

	for (i=0; i<ARRAY_SIZE(getgr_levels); i++) {

		status = test_netusergetgroups(tctx, hostname, getgr_levels[i], TORTURE_TEST_USER, NULL);
		if (status) {
			NETAPI_STATUS(tctx, ctx, status, "NetUserGetGroups");
			goto out;
		}
	}

	/* modify description */

	torture_comment(tctx, "Testing NetUserSetInfo level %d\n", 1007);

	u1007.usri1007_comment = "NetApi modified user";

	status = NetUserSetInfo(hostname, TORTURE_TEST_USER, 1007, (uint8_t *)&u1007, &parm_err);
	if (status) {
		NETAPI_STATUS(tctx, ctx, status, "NetUserSetInfo");
		goto out;
	}

	/* query info */

	for (i=0; i<ARRAY_SIZE(levels); i++) {
		status = NetUserGetInfo(hostname, TORTURE_TEST_USER, levels[i], &buffer);
		if (status && status != 124) {
			NETAPI_STATUS(tctx, ctx, status, "NetUserGetInfo");
			goto out;
		}
	}

	torture_comment(tctx, "Testing NetUserSetInfo level 0\n");

	u0.usri0_name = TORTURE_TEST_USER2;

	status = NetUserSetInfo(hostname, TORTURE_TEST_USER, 0, (uint8_t *)&u0, &parm_err);
	if (status) {
		NETAPI_STATUS(tctx, ctx, status, "NetUserSetInfo");
		goto out;
	}

	/* delete */

	torture_comment(tctx, "Testing NetUserDel\n");

	status = NetUserDel(hostname, TORTURE_TEST_USER2);
	if (status) {
		NETAPI_STATUS(tctx, ctx, status, "NetUserDel");
		goto out;
	}

	/* should not exist anymore */

	status = NetUserGetInfo(hostname, TORTURE_TEST_USER2, 0, &buffer);
	if (status == 0) {
		NETAPI_STATUS(tctx, ctx, status, "NetUserGetInfo");
		status = -1;
		goto out;
	}

	status = test_netusermodals(tctx, ctx, hostname);
	if (status) {
		goto out;
	}

	status = 0;

	torture_comment(tctx, "NetUser tests succeeded\n");
 out:
	/* cleanup */
	NetUserDel(hostname, TORTURE_TEST_USER);
	NetUserDel(hostname, TORTURE_TEST_USER2);

	if (status != 0) {
		torture_comment(tctx, "NetUser testsuite failed with: %s\n",
			libnetapi_get_error_string(ctx, status));
		libnetapi_free(ctx);
		return false;
	}

	libnetapi_free(ctx);
	return true;
}
Exemplo n.º 6
0
int main(int argc, const char **argv)
{
	NET_API_STATUS status;
	struct libnetapi_ctx *ctx = NULL;
	const char *hostname = NULL;
	const char *username = NULL;
	uint32_t level = 0;
	uint8_t *buffer = NULL;
	uint32_t entries_read = 0;
	uint32_t total_entries = 0;
	int i;

	struct GROUP_USERS_INFO_0 *info0 = NULL;
	struct GROUP_USERS_INFO_1 *info1 = NULL;

	poptContext pc;
	int opt;

	struct poptOption long_options[] = {
		POPT_AUTOHELP
		POPT_COMMON_LIBNETAPI_EXAMPLES
		POPT_TABLEEND
	};

	status = libnetapi_init(&ctx);
	if (status != 0) {
		return status;
	}

	pc = poptGetContext("user_getgroups", argc, argv, long_options, 0);

	poptSetOtherOptionHelp(pc, "hostname username level");
	while((opt = poptGetNextOpt(pc)) != -1) {
	}

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	hostname = poptGetArg(pc);

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	username = poptGetArg(pc);

	if (poptPeekArg(pc)) {
		level = atoi(poptGetArg(pc));
	}

	/* NetUserGetGroups */

	do {
		status = NetUserGetGroups(hostname,
					  username,
					  level,
					  &buffer,
					  (uint32_t)-1,
					  &entries_read,
					  &total_entries);
		if (status == 0 || status == ERROR_MORE_DATA) {

			switch (level) {
				case 0:
					info0 = (struct GROUP_USERS_INFO_0 *)buffer;
					break;
				case 1:
					info1 = (struct GROUP_USERS_INFO_1 *)buffer;
					break;
				default:
					break;
			}

			for (i=0; i<entries_read; i++) {
				switch (level) {
					case 0:
						printf("#%d group: %s\n", i, info0->grui0_name);
						info0++;
						break;
					case 1:
						printf("#%d group: %s\n", i, info1->grui1_name);
						printf("#%d attributes: %d\n", i, info1->grui1_attributes);
						info1++;
						break;
					default:
						break;
				}
			}
			NetApiBufferFree(buffer);
		}
	} while (status == ERROR_MORE_DATA);

	if (status != 0) {
		printf("NetUserGetGroups failed with: %s\n",
			libnetapi_get_error_string(ctx, status));
	}

 out:
	libnetapi_free(ctx);
	poptFreeContext(pc);

	return status;
}
Exemplo n.º 7
0
static int net_dom_unjoin(struct net_context *c, int argc, const char **argv)
{
	const char *server_name = NULL;
	const char *account = NULL;
	const char *password = NULL;
	uint32_t unjoin_flags = NETSETUP_ACCT_DELETE |
				NETSETUP_JOIN_DOMAIN |
				NETSETUP_IGNORE_UNSUPPORTED_FLAGS;
	struct cli_state *cli = NULL;
	bool do_reboot = false;
	NTSTATUS ntstatus;
	NET_API_STATUS status;
	int ret = -1;
	int i;

	if (argc < 1 || c->display_usage) {
		return net_dom_usage(c, argc, argv);
	}

	if (c->opt_host) {
		server_name = c->opt_host;
	}

	for (i=0; i<argc; i++) {
		if (strnequal(argv[i], "account", strlen("account"))) {
			account = get_string_param(argv[i]);
			if (!account) {
				return -1;
			}
		}
		if (strnequal(argv[i], "password", strlen("password"))) {
			password = get_string_param(argv[i]);
			if (!password) {
				return -1;
			}
		}
		if (strequal(argv[i], "reboot")) {
			do_reboot = true;
		}
	}

	if (do_reboot) {
		ntstatus = net_make_ipc_connection_ex(c, c->opt_workgroup,
						      server_name, NULL, 0,
						      &cli);
		if (!NT_STATUS_IS_OK(ntstatus)) {
			return -1;
		}
	}

	status = NetUnjoinDomain(server_name, account, password, unjoin_flags);
	if (status != 0) {
		printf("Failed to unjoin domain: %s\n",
			libnetapi_get_error_string(c->netapi_ctx, status));
		goto done;
	}

	if (do_reboot) {
		c->opt_comment = "Shutting down due to a domain membership "
				 "change";
		c->opt_reboot = true;
		c->opt_timeout = 30;

		ret = run_rpc_command(c, cli,
				      &ndr_table_initshutdown.syntax_id,
				      0, rpc_init_shutdown_internals,
				      argc, argv);
		if (ret == 0) {
			goto done;
		}

		ret = run_rpc_command(c, cli, &ndr_table_winreg.syntax_id, 0,
				      rpc_reg_shutdown_internals,
				      argc, argv);
		goto done;
	}

	ret = 0;

 done:
	if (cli) {
		cli_shutdown(cli);
	}

	return ret;
}
Exemplo n.º 8
0
int main(int argc, const char **argv)
{
	NET_API_STATUS status;
	struct libnetapi_ctx *ctx = NULL;
	const char *hostname = NULL;
	const char *groupname = NULL;
	struct LOCALGROUP_MEMBERS_INFO_0 *g0;
	struct LOCALGROUP_MEMBERS_INFO_3 *g3;
	uint32_t total_entries = 0;
	uint8_t *buffer = NULL;
	uint32_t level = 3;
	const char **names = NULL;
	int i = 0;

	poptContext pc;
	int opt;

	struct poptOption long_options[] = {
		POPT_AUTOHELP
		POPT_COMMON_LIBNETAPI_EXAMPLES
		POPT_TABLEEND
	};

	status = libnetapi_init(&ctx);
	if (status != 0) {
		return status;
	}

	pc = poptGetContext("localgroup_addmembers", argc, argv, long_options, 0);

	poptSetOtherOptionHelp(pc, "hostname groupname member1 member2 ...");
	while((opt = poptGetNextOpt(pc)) != -1) {
	}

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	hostname = poptGetArg(pc);

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	groupname = poptGetArg(pc);

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}

	names = poptGetArgs(pc);
	for (i=0; names[i] != NULL; i++) {
		total_entries++;
	}

	switch (level) {
		case 0:
			status = NetApiBufferAllocate(sizeof(struct LOCALGROUP_MEMBERS_INFO_0) * total_entries,
						      (void **)&g0);
			if (status) {
				printf("NetApiBufferAllocate failed with: %s\n",
					libnetapi_get_error_string(ctx, status));
				goto out;
			}

			for (i=0; i<total_entries; i++) {
				if (!ConvertStringSidToSid(names[i], &g0[i].lgrmi0_sid)) {
					printf("could not convert sid\n");
					goto out;
				}
			}

			buffer = (uint8_t *)g0;
			break;
		case 3:
			status = NetApiBufferAllocate(sizeof(struct LOCALGROUP_MEMBERS_INFO_3) * total_entries,
						      (void **)&g3);
			if (status) {
				printf("NetApiBufferAllocate failed with: %s\n",
					libnetapi_get_error_string(ctx, status));
				goto out;
			}

			for (i=0; i<total_entries; i++) {
				g3[i].lgrmi3_domainandname = names[i];
			}

			buffer = (uint8_t *)g3;
			break;
		default:
			break;
	}

	/* NetLocalGroupAddMembers */

	status = NetLocalGroupAddMembers(hostname,
					 groupname,
					 level,
					 buffer,
					 total_entries);
	if (status != 0) {
		printf("NetLocalGroupAddMembers failed with: %s\n",
			libnetapi_get_error_string(ctx, status));
	}

 out:
	libnetapi_free(ctx);
	poptFreeContext(pc);

	return status;
}
Exemplo n.º 9
0
NET_API_STATUS netapitest_share(struct libnetapi_ctx *ctx,
				const char *hostname)
{
	NET_API_STATUS status = 0;
	const char *sharename, *comment;
	uint8_t *buffer = NULL;
	struct SHARE_INFO_2 i2;
	struct SHARE_INFO_502 i502;
	struct SHARE_INFO_1004 i1004;
	struct SHARE_INFO_501 *i501 = NULL;
	uint32_t parm_err = 0;
	uint32_t levels[] = { 0, 1, 2, 501, 1005 };
	uint32_t enum_levels[] = { 0, 1, 2 };
	int i;

	printf("NetShare tests\n");

	sharename = "torture_test_share";

	/* cleanup */
	NetShareDel(hostname, sharename, 0);

	/* add a share */

	printf("testing NetShareAdd\n");

	ZERO_STRUCT(i502);

	i502.shi502_netname = sharename;
	i502.shi502_path = "c:\\";

	status = NetShareAdd(hostname, 502, (uint8_t *)&i502, &parm_err);
	if (status) {
		NETAPI_STATUS(ctx, status, "NetShareAdd");
		goto out;
	};

	status = NetShareDel(hostname, sharename, 0);
	if (status) {
		NETAPI_STATUS(ctx, status, "NetShareDel");
		goto out;
	};

	ZERO_STRUCT(i2);

	i2.shi2_netname = sharename;
	i2.shi2_path = "c:\\";

	status = NetShareAdd(hostname, 2, (uint8_t *)&i2, &parm_err);
	if (status) {
		NETAPI_STATUS(ctx, status, "NetShareAdd");
		goto out;
	};

	/* test enum */

	for (i=0; i<ARRAY_SIZE(enum_levels); i++) {

		status = test_netshareenum(hostname, enum_levels[i], sharename);
		if (status) {
			NETAPI_STATUS(ctx, status, "NetShareEnum");
			goto out;
		}
	}

	/* basic queries */

	for (i=0; i<ARRAY_SIZE(levels); i++) {

		printf("testing NetShareGetInfo level %d\n", levels[i]);

		status = NetShareGetInfo(hostname, sharename, levels[i], &buffer);
		if (status && status != 124) {
			NETAPI_STATUS(ctx, status, "NetShareGetInfo");
			goto out;
		}
	}


	comment = "NetApi generated comment";

	i1004.shi1004_remark = comment;

	printf("testing NetShareSetInfo level 1004\n");

	status = NetShareSetInfo(hostname, sharename, 1004, (uint8_t *)&i1004, &parm_err);
	if (status) {
		NETAPI_STATUS(ctx, status, "NetShareSetInfo");
		goto out;
	}

	status = NetShareGetInfo(hostname, sharename, 501, (uint8_t **)&i501);
	if (status) {
		NETAPI_STATUS(ctx, status, "NetShareGetInfo");
		goto out;
	}

	if (strcasecmp(i501->shi501_remark, comment) != 0) {
		NETAPI_STATUS(ctx, status, "NetShareGetInfo");
		goto out;
	}

	/* delete */

	printf("testing NetShareDel\n");

	status = NetShareDel(hostname, sharename, 0);
	if (status) {
		NETAPI_STATUS(ctx, status, "NetShareDel");
		goto out;
	};

	/* should not exist anymore */

	status = NetShareGetInfo(hostname, sharename, 0, &buffer);
	if (status == 0) {
		NETAPI_STATUS(ctx, status, "NetShareGetInfo");
		goto out;
	};

	status = 0;

	printf("NetShare tests succeeded\n");
 out:
	if (status != 0) {
		printf("NetShare testsuite failed with: %s\n",
			libnetapi_get_error_string(ctx, status));
	}

	return status;
}
Exemplo n.º 10
0
int main(int argc, const char **argv)
{
	NET_API_STATUS status;
	struct libnetapi_ctx *ctx = NULL;
	const char *hostname = NULL;
	const char *username = NULL;
	uint32_t level = 0;
	uint32_t parm_err = 0;
	uint8_t *buffer = NULL;
	const char *val = NULL;

	struct USER_INFO_0 u0;
	struct USER_INFO_1 u1;
	struct USER_INFO_2 u2;
	struct USER_INFO_3 u3;
	struct USER_INFO_4 u4;
	struct USER_INFO_21 u21;
	struct USER_INFO_22 u22;
	struct USER_INFO_1003 u1003;
	struct USER_INFO_1005 u1005;
	struct USER_INFO_1006 u1006;
	struct USER_INFO_1007 u1007;
	struct USER_INFO_1008 u1008;
	struct USER_INFO_1009 u1009;
	struct USER_INFO_1010 u1010;
	struct USER_INFO_1011 u1011;
	struct USER_INFO_1012 u1012;
	struct USER_INFO_1014 u1014;
	struct USER_INFO_1017 u1017;
	struct USER_INFO_1020 u1020;
	struct USER_INFO_1024 u1024;
	struct USER_INFO_1051 u1051;
	struct USER_INFO_1052 u1052;
	struct USER_INFO_1053 u1053;

	poptContext pc;
	int opt;

	struct poptOption long_options[] = {
		POPT_AUTOHELP
		POPT_COMMON_LIBNETAPI_EXAMPLES
		POPT_TABLEEND
	};

	status = libnetapi_init(&ctx);
	if (status != 0) {
		return status;
	}

	pc = poptGetContext("user_setinfo", argc, argv, long_options, 0);

	poptSetOtherOptionHelp(pc, "hostname username level");
	while((opt = poptGetNextOpt(pc)) != -1) {
	}

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	hostname = poptGetArg(pc);

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	username = poptGetArg(pc);

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	level = atoi(poptGetArg(pc));

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	val = poptGetArg(pc);

	/* NetUserSetInfo */

	switch (level) {
		case 0:
			u0.usri0_name = val;
			buffer = (uint8_t *)&u0;
			break;
		case 1:
		case 2:
		case 3:
		case 4:
			break;
		case 21:
			break;
		case 22:
			break;
		case 1003:
			u1003.usri1003_password = val;
			buffer = (uint8_t *)&u1003;
			break;
		case 1005:
			u1005.usri1005_priv = atoi(val);
			buffer = (uint8_t *)&u1005;
			break;
		case 1006:
			u1006.usri1006_home_dir = val;
			buffer = (uint8_t *)&u1006;
			break;
		case 1007:
			u1007.usri1007_comment = val;
			buffer = (uint8_t *)&u1007;
			break;
		case 1008:
			u1008.usri1008_flags = atoi(val);
			buffer = (uint8_t *)&u1008;
			break;
		case 1009:
			u1009.usri1009_script_path = val;
			buffer = (uint8_t *)&u1009;
			break;
		case 1010:
			u1010.usri1010_auth_flags = atoi(val);
			buffer = (uint8_t *)&u1010;
			break;
		case 1011:
			u1011.usri1011_full_name = val;
			buffer = (uint8_t *)&u1011;
			break;
		case 1012:
			u1012.usri1012_usr_comment = val;
			buffer = (uint8_t *)&u1012;
			break;
		case 1014:
			u1014.usri1014_workstations = val;
			buffer = (uint8_t *)&u1014;
			break;
		case 1017:
			u1017.usri1017_acct_expires = atoi(val);
			buffer = (uint8_t *)&u1017;
			break;
		case 1020:
			break;
		case 1024:
			u1024.usri1024_country_code = atoi(val);
			buffer = (uint8_t *)&u1024;
			break;
		case 1051:
			u1051.usri1051_primary_group_id = atoi(val);
			buffer = (uint8_t *)&u1051;
			break;
		case 1052:
			u1052.usri1052_profile = val;
			buffer = (uint8_t *)&u1052;
			break;
		case 1053:
			u1053.usri1053_home_dir_drive = val;
			buffer = (uint8_t *)&u1053;
			break;
		default:
			break;
	}

	status = NetUserSetInfo(hostname,
				username,
				level,
				buffer,
				&parm_err);
	if (status != 0) {
		printf("NetUserSetInfo failed with: %s\n",
			libnetapi_get_error_string(ctx, status));
		goto out;
	}

 out:
	libnetapi_free(ctx);
	poptFreeContext(pc);

	return status;
}
int main(int argc, const char **argv)
{
	NET_API_STATUS status = 0;
	struct libnetapi_ctx *ctx = NULL;
	const char *hostname = NULL;

	poptContext pc;
	int opt;

	struct poptOption long_options[] = {
		POPT_AUTOHELP
		POPT_COMMON_LIBNETAPI_EXAMPLES
		POPT_TABLEEND
	};

	status = libnetapi_init(&ctx);
	if (status != 0) {
		return status;
	}

	pc = poptGetContext("netapitest", argc, argv, long_options, 0);

	poptSetOtherOptionHelp(pc, "hostname");
	while((opt = poptGetNextOpt(pc)) != -1) {
	}

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	hostname = poptGetArg(pc);

	status = netapitest_localgroup(ctx, hostname);
	if (status) {
		goto out;
	}

	status = netapitest_user(ctx, hostname);
	if (status) {
		goto out;
	}

	status = netapitest_group(ctx, hostname);
	if (status) {
		goto out;
	}

	status = netapitest_display(ctx, hostname);
	if (status) {
		goto out;
	}

	status = netapitest_share(ctx, hostname);
	if (status) {
		goto out;
	}

	status = netapitest_file(ctx, hostname);
	if (status) {
		goto out;
	}

 out:
	if (status != 0) {
		printf("testsuite failed with: %s\n",
			libnetapi_get_error_string(ctx, status));
	}

	libnetapi_free(ctx);
	poptFreeContext(pc);

	return status;
}
Exemplo n.º 12
0
int main(int argc, const char **argv)
{
	NET_API_STATUS status;
	struct libnetapi_ctx *ctx = NULL;
	const char *hostname = NULL;
	const char *username = NULL;
	const char *password = NULL;
	struct USER_INFO_1 info1;
	uint32_t parm_error = 0;

	poptContext pc;
	int opt;

	struct poptOption long_options[] = {
		POPT_AUTOHELP
		POPT_COMMON_LIBNETAPI_EXAMPLES
		POPT_TABLEEND
	};

	status = libnetapi_init(&ctx);
	if (status != 0) {
		return status;
	}

	pc = poptGetContext("user_add", argc, argv, long_options, 0);

	poptSetOtherOptionHelp(pc, "hostname username password");
	while((opt = poptGetNextOpt(pc)) != -1) {
	}

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	hostname = poptGetArg(pc);

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	username = poptGetArg(pc);

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	password = poptGetArg(pc);

	/* NetUserAdd */

	info1.usri1_name = username;
	info1.usri1_password = password;
	info1.usri1_password_age = 0;
	info1.usri1_priv = 0;
	info1.usri1_home_dir = NULL;
	info1.usri1_comment = "User created using Samba NetApi Example code";
	info1.usri1_flags = 0;
	info1.usri1_script_path = NULL;

	status = NetUserAdd(hostname,
			    1,
			    (uint8_t *)&info1,
			    &parm_error);
	if (status != 0) {
		printf("NetUserAdd failed with: %s\n",
			libnetapi_get_error_string(ctx, status));
	}

 out:
	libnetapi_free(ctx);
	poptFreeContext(pc);

	return status;
}
Exemplo n.º 13
0
int main(int argc, const char **argv)
{
	NET_API_STATUS status;
	struct libnetapi_ctx *ctx = NULL;
	const char *hostname = NULL;
	uint8_t *buffer = NULL;
	uint32_t entries_read = 0;
	uint32_t total_entries = 0;
	uint32_t resume_handle = 0;
	int i;

	struct USER_INFO_0 *info0;

	poptContext pc;
	int opt;

	struct poptOption long_options[] = {
		POPT_AUTOHELP
		POPT_COMMON_LIBNETAPI_EXAMPLES
		POPT_TABLEEND
	};

	status = libnetapi_init(&ctx);
	if (status != 0) {
		return status;
	}

	pc = poptGetContext("user_enum", argc, argv, long_options, 0);

	poptSetOtherOptionHelp(pc, "hostname");
	while((opt = poptGetNextOpt(pc)) != -1) {
	}

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	hostname = poptGetArg(pc);

	/* NetUserEnum */

	do {
		status = NetUserEnum(hostname,
				     0,
				     0,
				     &buffer,
				     (uint32_t)-1,
				     &entries_read,
				     &total_entries,
				     &resume_handle);
		if (status == 0 || status == ERROR_MORE_DATA) {
			info0 = (struct USER_INFO_0 *)buffer;
			for (i=0; i<entries_read; i++) {
				printf("user %d: %s\n", i, info0->usri0_name);
				info0++;
			}
			NetApiBufferFree(buffer);
		}
	} while (status == ERROR_MORE_DATA);

	if (status != 0) {
		printf("NetUserEnum failed with: %s\n",
			libnetapi_get_error_string(ctx, status));
	}

 out:
	libnetapi_free(ctx);
	poptFreeContext(pc);

	return status;
}