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"
27 #define TEST_USERNAME "libnetusertest"
30 static BOOL test_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
31 struct policy_handle *domain_handle, const char *username)
34 struct samr_LookupNames r1;
35 struct samr_OpenUser r2;
36 struct samr_DeleteUser r3;
38 struct lsa_String names[2];
40 struct policy_handle user_handle;
42 names[0].string = username;
44 r1.in.domain_handle = domain_handle;
48 printf("user account lookup '%s'\n", username);
50 status = dcerpc_samr_LookupNames(p, mem_ctx, &r1);
51 if (!NT_STATUS_IS_OK(status)) {
52 printf("LookupNames failed - %s\n", nt_errstr(status));
56 rid = r1.out.rids.ids[0];
58 r2.in.domain_handle = domain_handle;
59 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
61 r2.out.user_handle = &user_handle;
63 printf("opening user account\n");
65 status = dcerpc_samr_OpenUser(p, mem_ctx, &r2);
66 if (!NT_STATUS_IS_OK(status)) {
67 printf("OpenUser failed - %s\n", nt_errstr(status));
71 r3.in.user_handle = &user_handle;
72 r3.out.user_handle = &user_handle;
74 printf("deleting user account\n");
76 status = dcerpc_samr_DeleteUser(p, mem_ctx, &r3);
77 if (!NT_STATUS_IS_OK(status)) {
78 printf("DeleteUser failed - %s\n", nt_errstr(status));
82 r4.in.handle = domain_handle;
83 r4.out.handle = domain_handle;
85 status = dcerpc_samr_Close(p, mem_ctx, &r4);
86 if (!NT_STATUS_IS_OK(status)) {
87 printf("Close failed - %s\n", nt_errstr(status));
95 BOOL torture_createuser(void)
100 struct libnet_context *ctx;
101 struct libnet_CreateUser req;
103 mem_ctx = talloc_init("test_createuser");
104 binding = lp_parm_string(-1, "torture", "binding");
106 ctx = libnet_context_init(NULL);
107 ctx->cred = cmdline_credentials;
109 req.in.user_name = TEST_USERNAME;
110 req.in.domain_name = lp_workgroup();
112 status = libnet_CreateUser(ctx, mem_ctx, &req);
113 if (!NT_STATUS_IS_OK(status)) {
114 printf("libnet_CreateUser call failed: %s\n", nt_errstr(status));
118 if (!test_cleanup(ctx->pipe, mem_ctx, &ctx->domain_handle, TEST_USERNAME)) {
119 printf("cleanup failed\n");