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; }
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; }