2 * Unix SMB/CIFS implementation.
4 * Copyright (C) Guenther Deschner 2008
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 3 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, see <http://www.gnu.org/licenses/>.
22 /****************************************************************
23 ****************************************************************/
25 WERROR libnetapi_samr_open_domain(TALLOC_CTX *mem_ctx,
26 struct rpc_pipe_client *pipe_cli,
27 uint32_t connect_mask,
29 struct policy_handle *connect_handle,
30 struct policy_handle *domain_handle,
31 struct dom_sid2 **domain_sid)
35 uint32_t resume_handle = 0;
36 uint32_t num_entries = 0;
37 struct samr_SamArray *sam = NULL;
38 const char *domain_name = NULL;
39 struct lsa_String lsa_domain_name;
40 bool domain_found = true;
43 if (!is_valid_policy_hnd(connect_handle)) {
44 status = rpccli_try_samr_connects(pipe_cli, mem_ctx,
47 if (!NT_STATUS_IS_OK(status)) {
48 werr = ntstatus_to_werror(status);
53 status = rpccli_samr_EnumDomains(pipe_cli, mem_ctx,
59 if (!NT_STATUS_IS_OK(status)) {
60 werr = ntstatus_to_werror(status);
64 for (i=0; i<num_entries; i++) {
66 domain_name = sam->entries[i].name.string;
68 if (strequal(domain_name, builtin_domain_name())) {
77 werr = WERR_NO_SUCH_DOMAIN;
81 init_lsa_String(&lsa_domain_name, domain_name);
83 status = rpccli_samr_LookupDomain(pipe_cli, mem_ctx,
87 if (!NT_STATUS_IS_OK(status)) {
88 werr = ntstatus_to_werror(status);
92 status = rpccli_samr_OpenDomain(pipe_cli, mem_ctx,
97 if (!NT_STATUS_IS_OK(status)) {
98 werr = ntstatus_to_werror(status);
108 /****************************************************************
109 ****************************************************************/
111 WERROR libnetapi_samr_open_builtin_domain(TALLOC_CTX *mem_ctx,
112 struct rpc_pipe_client *pipe_cli,
113 uint32_t connect_mask,
114 uint32_t builtin_mask,
115 struct policy_handle *connect_handle,
116 struct policy_handle *builtin_handle)
121 if (!is_valid_policy_hnd(connect_handle)) {
122 status = rpccli_try_samr_connects(pipe_cli, mem_ctx,
125 if (!NT_STATUS_IS_OK(status)) {
126 werr = ntstatus_to_werror(status);
131 status = rpccli_samr_OpenDomain(pipe_cli, mem_ctx,
134 CONST_DISCARD(DOM_SID *, &global_sid_Builtin),
136 if (!NT_STATUS_IS_OK(status)) {
137 werr = ntstatus_to_werror(status);
147 /****************************************************************
148 ****************************************************************/
150 void libnetapi_samr_close_domain_handle(struct libnetapi_ctx *ctx,
151 struct policy_handle *handle)
153 struct libnetapi_private_ctx *priv;
155 if (!is_valid_policy_hnd(handle)) {
159 priv = talloc_get_type_abort(ctx->private_data,
160 struct libnetapi_private_ctx);
162 if (!policy_hnd_equal(handle, &priv->samr.domain_handle)) {
166 rpccli_samr_Close(priv->samr.cli, ctx, handle);
168 ZERO_STRUCT(priv->samr.domain_handle);
171 /****************************************************************
172 ****************************************************************/
174 void libnetapi_samr_close_connect_handle(struct libnetapi_ctx *ctx,
175 struct policy_handle *handle)
177 struct libnetapi_private_ctx *priv;
179 if (!is_valid_policy_hnd(handle)) {
183 priv = talloc_get_type_abort(ctx->private_data,
184 struct libnetapi_private_ctx);
186 if (!policy_hnd_equal(handle, &priv->samr.connect_handle)) {
190 rpccli_samr_Close(priv->samr.cli, ctx, handle);
192 ZERO_STRUCT(priv->samr.connect_handle);