2 Unix SMB/CIFS implementation.
4 Copyright (C) Rafal Szczesniak <mimir@samba.org> 2005
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "libnet/libnet.h"
26 NTSTATUS libnet_CreateUser(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, struct libnet_CreateUser *r)
29 struct libnet_RpcConnect cn;
30 struct libnet_rpc_domain_open dom_io;
31 struct libnet_rpc_useradd user_io;
33 /* connect rpc service of remote DC */
34 cn.level = LIBNET_RPC_CONNECT_PDC;
35 cn.in.name = talloc_strdup(mem_ctx, r->in.domain_name);
36 cn.in.dcerpc_iface = &dcerpc_table_samr;
38 status = libnet_RpcConnect(ctx, mem_ctx, &cn);
39 if (!NT_STATUS_IS_OK(status)) {
40 r->out.error_string = talloc_asprintf(mem_ctx,
41 "Connection to SAMR pipe domain '%s' PDC failed: %s\n",
42 r->in.domain_name, nt_errstr(status));
46 ctx->pipe = cn.out.dcerpc_pipe;
48 /* open connected domain */
49 dom_io.in.domain_name = r->in.domain_name;
50 dom_io.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
52 status = libnet_rpc_domain_open(ctx->pipe, mem_ctx, &dom_io);
53 if (!NT_STATUS_IS_OK(status)) {
54 r->out.error_string = talloc_asprintf(mem_ctx,
55 "Creating user account failed: %s\n",
60 ctx->domain_handle = dom_io.out.domain_handle;
63 user_io.in.username = r->in.user_name;
64 user_io.in.domain_handle = dom_io.out.domain_handle;
66 status = libnet_rpc_useradd(ctx->pipe, mem_ctx, &user_io);
67 if (!NT_STATUS_IS_OK(status)) {
68 r->out.error_string = talloc_asprintf(mem_ctx,
69 "Creating user account failed: %s\n",
74 ctx->user_handle = user_io.out.user_handle;
79 NTSTATUS libnet_DeleteUser(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, struct libnet_DeleteUser *r)
82 struct libnet_RpcConnect cn;
83 struct libnet_rpc_domain_open dom_io;
84 struct libnet_rpc_userdel user_io;
86 /* connect rpc service of remote DC */
87 cn.level = LIBNET_RPC_CONNECT_PDC;
88 cn.in.name = talloc_strdup(mem_ctx, r->in.domain_name);
89 cn.in.dcerpc_iface = &dcerpc_table_samr;
91 status = libnet_RpcConnect(ctx, mem_ctx, &cn);
92 if (!NT_STATUS_IS_OK(status)) {
93 r->out.error_string = talloc_asprintf(mem_ctx,
94 "Connection to SAMR pipe domain '%s' PDC failed: %s\n",
95 r->in.domain_name, nt_errstr(status));
99 ctx->pipe = cn.out.dcerpc_pipe;
101 /* open connected domain */
102 dom_io.in.domain_name = r->in.domain_name;
103 dom_io.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
105 status = libnet_rpc_domain_open(ctx->pipe, mem_ctx, &dom_io);
106 if (!NT_STATUS_IS_OK(status)) {
107 r->out.error_string = talloc_asprintf(mem_ctx,
108 "Opening domain to delete user account failed: %s\n",
113 ctx->domain_handle = dom_io.out.domain_handle;
116 user_io.in.username = r->in.user_name;
117 user_io.in.domain_handle = dom_io.out.domain_handle;
119 status = libnet_rpc_userdel(ctx->pipe, mem_ctx, &user_io);
120 if (!NT_STATUS_IS_OK(status)) {
121 r->out.error_string = talloc_asprintf(mem_ctx,
122 "Deleting user account failed: %s\n",