1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 |
|
---|
4 | Copyright (C) Rafal Szczesniak 2006
|
---|
5 |
|
---|
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.
|
---|
10 |
|
---|
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.
|
---|
15 |
|
---|
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/>.
|
---|
18 | */
|
---|
19 |
|
---|
20 |
|
---|
21 | #include "includes.h"
|
---|
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"
|
---|
30 |
|
---|
31 |
|
---|
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*))
|
---|
37 | {
|
---|
38 | struct composite_context *domopen_req;
|
---|
39 |
|
---|
40 | if (parent_ctx == NULL || *parent_ctx == NULL) return false;
|
---|
41 |
|
---|
42 | if (domain_name == NULL) {
|
---|
43 | /*
|
---|
44 | * Try to guess the domain name from credentials,
|
---|
45 | * if it's not been explicitly specified.
|
---|
46 | */
|
---|
47 |
|
---|
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;
|
---|
52 |
|
---|
53 | } else {
|
---|
54 | composite_error(*parent_ctx, NT_STATUS_INVALID_PARAMETER);
|
---|
55 | return true;
|
---|
56 | }
|
---|
57 |
|
---|
58 | } else {
|
---|
59 | /*
|
---|
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.
|
---|
63 | */
|
---|
64 |
|
---|
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;
|
---|
70 |
|
---|
71 | } else {
|
---|
72 | /* domain has already been opened and it's the same domain
|
---|
73 | as requested */
|
---|
74 | return true;
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
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;
|
---|
81 |
|
---|
82 | composite_continue(*parent_ctx, domopen_req, continue_fn, *parent_ctx);
|
---|
83 | return false;
|
---|
84 | }
|
---|
85 |
|
---|
86 |
|
---|
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*))
|
---|
92 | {
|
---|
93 | struct composite_context *domopen_req;
|
---|
94 |
|
---|
95 | if (parent_ctx == NULL || *parent_ctx == NULL) return false;
|
---|
96 |
|
---|
97 | if (domain_name == NULL) {
|
---|
98 | /*
|
---|
99 | * Try to guess the domain name from credentials,
|
---|
100 | * if it's not been explicitly specified.
|
---|
101 | */
|
---|
102 |
|
---|
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;
|
---|
107 |
|
---|
108 | } else {
|
---|
109 | composite_error(*parent_ctx, NT_STATUS_INVALID_PARAMETER);
|
---|
110 | /* this ensures the calling function exits and composite function error
|
---|
111 | gets noticed quickly */
|
---|
112 | return true;
|
---|
113 | }
|
---|
114 |
|
---|
115 | } else {
|
---|
116 | /*
|
---|
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.
|
---|
120 | */
|
---|
121 |
|
---|
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;
|
---|
127 |
|
---|
128 | } else {
|
---|
129 | /* domain has already been opened and it's the same domain
|
---|
130 | as requested */
|
---|
131 | return true;
|
---|
132 | }
|
---|
133 | }
|
---|
134 |
|
---|
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;
|
---|
139 |
|
---|
140 | composite_continue(*parent_ctx, domopen_req, continue_fn, *parent_ctx);
|
---|
141 | return false;
|
---|
142 | }
|
---|