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 "librpc/gen_ndr/ndr_samr.h"
24 #include "lib/cmdline/popt_common.h"
25 #include "libnet/libnet.h"
26 #include "libnet/composite.h"
27 #include "libcli/composite/monitor.h"
30 #define TEST_USERNAME "libnetusertest"
33 static BOOL test_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
34 struct policy_handle *domain_handle, const char *username)
37 struct samr_LookupNames r1;
38 struct samr_OpenUser r2;
39 struct samr_DeleteUser r3;
41 struct samr_String names[2];
43 struct policy_handle user_handle;
45 names[0].string = username;
47 r1.in.domain_handle = domain_handle;
51 printf("user account lookup '%s'\n", username);
53 status = dcerpc_samr_LookupNames(p, mem_ctx, &r1);
54 if (!NT_STATUS_IS_OK(status)) {
55 printf("LookupNames failed - %s\n", nt_errstr(status));
59 rid = r1.out.rids.ids[0];
61 r2.in.domain_handle = domain_handle;
62 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
64 r2.out.user_handle = &user_handle;
66 printf("opening user account\n");
68 status = dcerpc_samr_OpenUser(p, mem_ctx, &r2);
69 if (!NT_STATUS_IS_OK(status)) {
70 printf("OpenUser failed - %s\n", nt_errstr(status));
74 r3.in.user_handle = &user_handle;
75 r3.out.user_handle = &user_handle;
77 printf("deleting user account\n");
79 status = dcerpc_samr_DeleteUser(p, mem_ctx, &r3);
80 if (!NT_STATUS_IS_OK(status)) {
81 printf("DeleteUser failed - %s\n", nt_errstr(status));
85 r4.in.handle = domain_handle;
86 r4.out.handle = domain_handle;
88 status = dcerpc_samr_Close(p, mem_ctx, &r4);
89 if (!NT_STATUS_IS_OK(status)) {
90 printf("Close failed - %s\n", nt_errstr(status));
98 BOOL torture_createuser(void)
103 struct libnet_context *ctx;
104 struct libnet_CreateUser req;
106 mem_ctx = talloc_init("test_createuser");
107 binding = lp_parm_string(-1, "torture", "binding");
109 ctx = libnet_context_init(NULL);
110 ctx->cred = cmdline_credentials;
112 req.in.user_name = TEST_USERNAME;
113 req.in.domain_name = lp_workgroup();
115 status = libnet_CreateUser(ctx, mem_ctx, &req);
116 if (!NT_STATUS_IS_OK(status)) {
117 printf("libnet_CreateUser call failed: %s\n", nt_errstr(status));
121 if (!test_cleanup(ctx->pipe, mem_ctx, &ctx->domain_handle, TEST_USERNAME)) {
122 printf("cleanup failed\n");