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"
24 #include "libnet/composite.h"
25 #include "librpc/gen_ndr/ndr_samr.h"
28 NTSTATUS
libnet_CreateUser(struct libnet_context
*ctx
, TALLOC_CTX
*mem_ctx
, struct libnet_CreateUser
*r
)
31 union libnet_rpc_connect cn
;
32 union libnet_find_pdc fp
;
33 struct dcerpc_pipe
*pipe
;
34 struct libnet_rpc_domain_open dom_io
;
35 struct libnet_rpc_useradd user_io
;
38 fp
.generic
.level
= LIBNET_FIND_PDC_GENERIC
;
39 fp
.generic
.in
.domain_name
= r
->in
.domain_name
;
41 status
= libnet_find_pdc(ctx
, mem_ctx
, &fp
);
42 if (!NT_STATUS_IS_OK(status
)) return status
;
44 /* connect rpc service of remote server */
45 cn
.standard
.level
= LIBNET_RPC_CONNECT_STANDARD
;
46 cn
.standard
.in
.server_name
= fp
.generic
.out
.pdc_name
;
47 cn
.standard
.in
.dcerpc_iface_name
= DCERPC_SAMR_NAME
;
48 cn
.standard
.in
.dcerpc_iface_uuid
= DCERPC_SAMR_UUID
;
49 cn
.standard
.in
.dcerpc_iface_version
= DCERPC_SAMR_VERSION
;
51 status
= libnet_rpc_connect(ctx
, mem_ctx
, &cn
);
52 if (!NT_STATUS_IS_OK(status
)) {
53 r
->out
.error_string
= talloc_asprintf(mem_ctx
,
54 "Connection to SAMR pipe domain '%s' PDC failed: %s\n",
55 r
->in
.domain_name
, nt_errstr(status
));
59 ctx
->samr
= cn
.pdc
.out
.dcerpc_pipe
;
61 /* open connected domain */
62 dom_io
.in
.domain_name
= r
->in
.domain_name
;
63 dom_io
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
65 status
= libnet_rpc_domain_open(ctx
->samr
, mem_ctx
, &dom_io
);
66 if (!NT_STATUS_IS_OK(status
)) {
67 r
->out
.error_string
= talloc_asprintf(mem_ctx
,
68 "Creating user account failed: %s\n",
73 ctx
->domain_handle
= dom_io
.out
.domain_handle
;
76 user_io
.in
.username
= r
->in
.user_name
;
77 user_io
.in
.domain_handle
= dom_io
.out
.domain_handle
;
79 status
= libnet_rpc_useradd(ctx
->samr
, mem_ctx
, &user_io
);
80 if (!NT_STATUS_IS_OK(status
)) {
81 r
->out
.error_string
= talloc_asprintf(mem_ctx
,
82 "Creating user account failed: %s\n",
87 ctx
->user_handle
= user_io
.out
.user_handle
;