2 Unix SMB/CIFS implementation.
3 Test suite for libnet calls.
5 Copyright (C) Rafal Szczesniak 2005
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "lib/cmdline/popt_common.h"
24 #include "libnet/libnet.h"
25 #include "librpc/gen_ndr/ndr_samr_c.h"
26 #include "torture/torture.h"
29 #define TEST_USERNAME "libnetusertest"
32 static BOOL test_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
33 struct policy_handle *domain_handle, const char *username)
36 struct samr_LookupNames r1;
37 struct samr_OpenUser r2;
38 struct samr_DeleteUser r3;
40 struct lsa_String names[2];
42 struct policy_handle user_handle;
44 names[0].string = username;
46 r1.in.domain_handle = domain_handle;
50 printf("user account lookup '%s'\n", username);
52 status = dcerpc_samr_LookupNames(p, mem_ctx, &r1);
53 if (!NT_STATUS_IS_OK(status)) {
54 printf("LookupNames failed - %s\n", nt_errstr(status));
58 rid = r1.out.rids.ids[0];
60 r2.in.domain_handle = domain_handle;
61 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
63 r2.out.user_handle = &user_handle;
65 printf("opening user account\n");
67 status = dcerpc_samr_OpenUser(p, mem_ctx, &r2);
68 if (!NT_STATUS_IS_OK(status)) {
69 printf("OpenUser failed - %s\n", nt_errstr(status));
73 r3.in.user_handle = &user_handle;
74 r3.out.user_handle = &user_handle;
76 printf("deleting user account\n");
78 status = dcerpc_samr_DeleteUser(p, mem_ctx, &r3);
79 if (!NT_STATUS_IS_OK(status)) {
80 printf("DeleteUser failed - %s\n", nt_errstr(status));
84 r4.in.handle = domain_handle;
85 r4.out.handle = domain_handle;
87 status = dcerpc_samr_Close(p, mem_ctx, &r4);
88 if (!NT_STATUS_IS_OK(status)) {
89 printf("Close failed - %s\n", nt_errstr(status));
97 BOOL torture_createuser(struct torture_context *torture)
102 struct libnet_context *ctx;
103 struct libnet_CreateUser req;
105 mem_ctx = talloc_init("test_createuser");
106 binding = lp_parm_string(-1, "torture", "binding");
108 ctx = libnet_context_init(NULL);
109 ctx->cred = cmdline_credentials;
111 req.in.user_name = TEST_USERNAME;
112 req.in.domain_name = lp_workgroup();
114 status = libnet_CreateUser(ctx, mem_ctx, &req);
115 if (!NT_STATUS_IS_OK(status)) {
116 printf("libnet_CreateUser call failed: %s\n", nt_errstr(status));
120 if (!test_cleanup(ctx->pipe, mem_ctx, &ctx->domain_handle, TEST_USERNAME)) {
121 printf("cleanup failed\n");