2 Unix SMB/CIFS implementation.
4 Copyright (C) Rafal Szczesniak 2006
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 #include "libnet/libnet.h"
23 #include "libcli/composite/composite.h"
24 #include "auth/credentials/credentials.h"
25 #include "librpc/ndr/libndr.h"
26 #include "librpc/gen_ndr/samr.h"
27 #include "librpc/gen_ndr/ndr_samr.h"
28 #include "librpc/gen_ndr/lsa.h"
29 #include "librpc/gen_ndr/ndr_lsa.h"
32 bool samr_domain_opened(struct libnet_context
*ctx
, const char *domain_name
,
33 struct composite_context
**parent_ctx
,
34 struct libnet_DomainOpen
*domain_open
,
35 void (*continue_fn
)(struct composite_context
*),
36 void (*monitor
)(struct monitor_msg
*))
38 struct composite_context
*domopen_req
;
40 if (parent_ctx
== NULL
|| *parent_ctx
== NULL
) return false;
42 if (domain_name
== NULL
) {
44 * Try to guess the domain name from credentials,
45 * if it's not been explicitly specified.
48 if (policy_handle_empty(&ctx
->samr
.handle
)) {
49 domain_open
->in
.type
= DOMAIN_SAMR
;
50 domain_open
->in
.domain_name
= cli_credentials_get_domain(ctx
->cred
);
51 domain_open
->in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
54 composite_error(*parent_ctx
, NT_STATUS_INVALID_PARAMETER
);
60 * The domain name has been specified, so check whether the same
61 * domain is already opened. If it is - just return NULL. Start
62 * opening a new domain otherwise.
65 if (policy_handle_empty(&ctx
->samr
.handle
) ||
66 !strequal(domain_name
, ctx
->samr
.name
)) {
67 domain_open
->in
.type
= DOMAIN_SAMR
;
68 domain_open
->in
.domain_name
= domain_name
;
69 domain_open
->in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
72 /* domain has already been opened and it's the same domain
78 /* send request to open the domain */
79 domopen_req
= libnet_DomainOpen_send(ctx
, domain_open
, monitor
);
80 if (composite_nomem(domopen_req
, *parent_ctx
)) return false;
82 composite_continue(*parent_ctx
, domopen_req
, continue_fn
, *parent_ctx
);
87 bool lsa_domain_opened(struct libnet_context
*ctx
, const char *domain_name
,
88 struct composite_context
**parent_ctx
,
89 struct libnet_DomainOpen
*domain_open
,
90 void (*continue_fn
)(struct composite_context
*),
91 void (*monitor
)(struct monitor_msg
*))
93 struct composite_context
*domopen_req
;
95 if (parent_ctx
== NULL
|| *parent_ctx
== NULL
) return false;
97 if (domain_name
== NULL
) {
99 * Try to guess the domain name from credentials,
100 * if it's not been explicitly specified.
103 if (policy_handle_empty(&ctx
->lsa
.handle
)) {
104 domain_open
->in
.type
= DOMAIN_LSA
;
105 domain_open
->in
.domain_name
= cli_credentials_get_domain(ctx
->cred
);
106 domain_open
->in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
109 composite_error(*parent_ctx
, NT_STATUS_INVALID_PARAMETER
);
110 /* this ensures the calling function exits and composite function error
111 gets noticed quickly */
117 * The domain name has been specified, so check whether the same
118 * domain is already opened. If it is - just return NULL. Start
119 * opening a new domain otherwise.
122 if (policy_handle_empty(&ctx
->lsa
.handle
) ||
123 !strequal(domain_name
, ctx
->lsa
.name
)) {
124 domain_open
->in
.type
= DOMAIN_LSA
;
125 domain_open
->in
.domain_name
= domain_name
;
126 domain_open
->in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
129 /* domain has already been opened and it's the same domain
135 /* send request to open the domain */
136 domopen_req
= libnet_DomainOpen_send(ctx
, domain_open
, monitor
);
137 /* see the comment above to find out why true is returned here */
138 if (composite_nomem(domopen_req
, *parent_ctx
)) return true;
140 composite_continue(*parent_ctx
, domopen_req
, continue_fn
, *parent_ctx
);