r15099: An attempt to fix BSD make portability issues. With these changes Samba 4...
[Samba.git] / source4 / libnet / libnet_user.c
blob1fca102d177acc9648b1a02f7a32ce192dccb1c7
1 /*
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.
22 #include "includes.h"
23 #include "libnet/libnet.h"
24 #include "librpc/gen_ndr/ndr_samr.h"
27 NTSTATUS libnet_CreateUser(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, struct libnet_CreateUser *r)
29 NTSTATUS status;
30 struct libnet_RpcConnect cn;
31 struct libnet_rpc_domain_open dom_io;
32 struct libnet_rpc_useradd user_io;
34 /* connect rpc service of remote DC */
35 cn.level = LIBNET_RPC_CONNECT_PDC;
36 cn.in.name = talloc_strdup(mem_ctx, r->in.domain_name);
37 cn.in.dcerpc_iface = &dcerpc_table_samr;
39 status = libnet_RpcConnect(ctx, mem_ctx, &cn);
40 if (!NT_STATUS_IS_OK(status)) {
41 r->out.error_string = talloc_asprintf(mem_ctx,
42 "Connection to SAMR pipe domain '%s' PDC failed: %s\n",
43 r->in.domain_name, nt_errstr(status));
44 return status;
47 ctx->pipe = cn.out.dcerpc_pipe;
49 /* open connected domain */
50 dom_io.in.domain_name = r->in.domain_name;
51 dom_io.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
53 status = libnet_rpc_domain_open(ctx->pipe, mem_ctx, &dom_io);
54 if (!NT_STATUS_IS_OK(status)) {
55 r->out.error_string = talloc_asprintf(mem_ctx,
56 "Creating user account failed: %s\n",
57 nt_errstr(status));
58 return status;
61 ctx->domain_handle = dom_io.out.domain_handle;
63 /* create user */
64 user_io.in.username = r->in.user_name;
65 user_io.in.domain_handle = dom_io.out.domain_handle;
67 status = libnet_rpc_useradd(ctx->pipe, mem_ctx, &user_io);
68 if (!NT_STATUS_IS_OK(status)) {
69 r->out.error_string = talloc_asprintf(mem_ctx,
70 "Creating user account failed: %s\n",
71 nt_errstr(status));
72 return status;
75 ctx->user_handle = user_io.out.user_handle;
77 return status;
80 NTSTATUS libnet_DeleteUser(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, struct libnet_DeleteUser *r)
82 NTSTATUS status;
83 struct libnet_RpcConnect cn;
84 struct libnet_rpc_domain_open dom_io;
85 struct libnet_rpc_userdel user_io;
87 /* connect rpc service of remote DC */
88 cn.level = LIBNET_RPC_CONNECT_PDC;
89 cn.in.name = talloc_strdup(mem_ctx, r->in.domain_name);
90 cn.in.dcerpc_iface = &dcerpc_table_samr;
92 status = libnet_RpcConnect(ctx, mem_ctx, &cn);
93 if (!NT_STATUS_IS_OK(status)) {
94 r->out.error_string = talloc_asprintf(mem_ctx,
95 "Connection to SAMR pipe domain '%s' PDC failed: %s\n",
96 r->in.domain_name, nt_errstr(status));
97 return status;
100 ctx->pipe = cn.out.dcerpc_pipe;
102 /* open connected domain */
103 dom_io.in.domain_name = r->in.domain_name;
104 dom_io.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
106 status = libnet_rpc_domain_open(ctx->pipe, mem_ctx, &dom_io);
107 if (!NT_STATUS_IS_OK(status)) {
108 r->out.error_string = talloc_asprintf(mem_ctx,
109 "Opening domain to delete user account failed: %s\n",
110 nt_errstr(status));
111 return status;
114 ctx->domain_handle = dom_io.out.domain_handle;
116 /* create user */
117 user_io.in.username = r->in.user_name;
118 user_io.in.domain_handle = dom_io.out.domain_handle;
120 status = libnet_rpc_userdel(ctx->pipe, mem_ctx, &user_io);
121 if (!NT_STATUS_IS_OK(status)) {
122 r->out.error_string = talloc_asprintf(mem_ctx,
123 "Deleting user account failed: %s\n",
124 nt_errstr(status));
125 return status;
128 return status;