2 Unix SMB/CIFS implementation.
4 Winbind daemon - miscellaneous other functions
6 Copyright (C) Tim Potter 2000
7 Copyright (C) Andrew Bartlett 2002
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "../librpc/gen_ndr/cli_netlogon.h"
28 #define DBGC_CLASS DBGC_WINBIND
30 /* Constants and helper functions for determining domain trust types */
39 const char *trust_type_strings
[] = {"External",
44 static enum trust_type
get_trust_type(struct winbindd_tdc_domain
*domain
)
46 if (domain
->trust_attribs
== NETR_TRUST_ATTRIBUTE_QUARANTINED_DOMAIN
)
48 else if (domain
->trust_attribs
== NETR_TRUST_ATTRIBUTE_FOREST_TRANSITIVE
)
50 else if (((domain
->trust_flags
& NETR_TRUST_FLAG_IN_FOREST
) == NETR_TRUST_FLAG_IN_FOREST
) &&
51 ((domain
->trust_flags
& NETR_TRUST_FLAG_PRIMARY
) == 0x0))
56 static const char *get_trust_type_string(struct winbindd_tdc_domain
*domain
)
58 return trust_type_strings
[get_trust_type(domain
)];
61 static bool trust_is_inbound(struct winbindd_tdc_domain
*domain
)
63 return (domain
->trust_flags
== 0x0) ||
64 ((domain
->trust_flags
& NETR_TRUST_FLAG_IN_FOREST
) ==
65 NETR_TRUST_FLAG_IN_FOREST
) ||
66 ((domain
->trust_flags
& NETR_TRUST_FLAG_INBOUND
) ==
67 NETR_TRUST_FLAG_INBOUND
);
70 static bool trust_is_outbound(struct winbindd_tdc_domain
*domain
)
72 return (domain
->trust_flags
== 0x0) ||
73 ((domain
->trust_flags
& NETR_TRUST_FLAG_IN_FOREST
) ==
74 NETR_TRUST_FLAG_IN_FOREST
) ||
75 ((domain
->trust_flags
& NETR_TRUST_FLAG_OUTBOUND
) ==
76 NETR_TRUST_FLAG_OUTBOUND
);
79 static bool trust_is_transitive(struct winbindd_tdc_domain
*domain
)
81 if ((domain
->trust_attribs
== NETR_TRUST_ATTRIBUTE_NON_TRANSITIVE
) ||
82 (domain
->trust_attribs
== NETR_TRUST_ATTRIBUTE_QUARANTINED_DOMAIN
) ||
83 (domain
->trust_attribs
== NETR_TRUST_ATTRIBUTE_TREAT_AS_EXTERNAL
))
88 void winbindd_list_trusted_domains(struct winbindd_cli_state
*state
)
90 struct winbindd_tdc_domain
*dom_list
= NULL
;
91 struct winbindd_tdc_domain
*d
= NULL
;
92 size_t num_domains
= 0;
93 int extra_data_len
= 0;
94 char *extra_data
= NULL
;
97 DEBUG(3, ("[%5lu]: list trusted domains\n",
98 (unsigned long)state
->pid
));
100 if( !wcache_tdc_fetch_list( &dom_list
, &num_domains
)) {
101 request_error(state
);
105 extra_data
= talloc_strdup(state
->mem_ctx
, "");
106 if (extra_data
== NULL
) {
107 request_error(state
);
111 for ( i
= 0; i
< num_domains
; i
++ ) {
112 struct winbindd_domain
*domain
;
113 bool is_online
= true;
116 domain
= find_domain_from_name_noinit(d
->domain_name
);
118 is_online
= domain
->online
;
120 extra_data
= talloc_asprintf_append_buffer(
122 "%s\\%s\\%s\\%s\\%s\\%s\\%s\\%s\n",
124 d
->dns_name
? d
->dns_name
: d
->domain_name
,
125 sid_string_talloc(state
->mem_ctx
, &d
->sid
),
126 get_trust_type_string(d
),
127 trust_is_transitive(d
) ? "Yes" : "No",
128 trust_is_inbound(d
) ? "Yes" : "No",
129 trust_is_outbound(d
) ? "Yes" : "No",
130 is_online
? "Online" : "Offline" );
133 state
->response
->data
.num_entries
= num_domains
;
135 extra_data_len
= strlen(extra_data
);
136 if (extra_data_len
> 0) {
138 /* Strip the last \n */
139 extra_data
[extra_data_len
-1] = '\0';
141 state
->response
->extra_data
.data
= extra_data
;
142 state
->response
->length
+= extra_data_len
;
147 TALLOC_FREE( dom_list
);
150 enum winbindd_result
winbindd_dual_list_trusted_domains(struct winbindd_domain
*domain
,
151 struct winbindd_cli_state
*state
)
154 int extra_data_len
= 0;
157 bool have_own_domain
= False
;
158 struct netr_DomainTrustList trusts
;
160 DEBUG(3, ("[%5lu]: list trusted domains\n",
161 (unsigned long)state
->pid
));
163 result
= domain
->methods
->trusted_domains(domain
, state
->mem_ctx
,
166 if (!NT_STATUS_IS_OK(result
)) {
167 DEBUG(3, ("winbindd_dual_list_trusted_domains: trusted_domains returned %s\n",
168 nt_errstr(result
) ));
169 return WINBINDD_ERROR
;
172 extra_data
= talloc_strdup(state
->mem_ctx
, "");
174 for (i
=0; i
<trusts
.count
; i
++) {
175 extra_data
= talloc_asprintf_append_buffer(
176 extra_data
, "%s\\%s\\%s\n",
177 trusts
.array
[i
].netbios_name
,
178 trusts
.array
[i
].dns_name
,
179 sid_string_talloc(state
->mem_ctx
,
180 trusts
.array
[i
].sid
));
183 /* add our primary domain */
185 for (i
=0; i
<trusts
.count
; i
++) {
186 if (strequal(trusts
.array
[i
].netbios_name
, domain
->name
)) {
187 have_own_domain
= True
;
192 if (state
->request
->data
.list_all_domains
&& !have_own_domain
) {
193 extra_data
= talloc_asprintf_append_buffer(
194 extra_data
, "%s\\%s\\%s\n", domain
->name
,
195 domain
->alt_name
? domain
->alt_name
: domain
->name
,
196 sid_string_talloc(state
->mem_ctx
, &domain
->sid
));
199 extra_data_len
= strlen(extra_data
);
200 if (extra_data_len
> 0) {
202 /* Strip the last \n */
203 extra_data
[extra_data_len
-1] = '\0';
205 state
->response
->extra_data
.data
= extra_data
;
206 state
->response
->length
+= extra_data_len
+1;
212 /* This is the child-only version of --sequence. It only allows for a single
213 * domain (ie "our" one) to be displayed. */
215 enum winbindd_result
winbindd_dual_show_sequence(struct winbindd_domain
*domain
,
216 struct winbindd_cli_state
*state
)
218 DEBUG(3, ("[%5lu]: show sequence\n", (unsigned long)state
->pid
));
220 /* Ensure null termination */
221 state
->request
->domain_name
[sizeof(state
->request
->domain_name
)-1]='\0';
223 domain
->methods
->sequence_number(domain
, &domain
->sequence_number
);
225 state
->response
->data
.sequence_number
=
226 domain
->sequence_number
;
231 struct domain_info_state
{
232 struct winbindd_domain
*domain
;
233 struct winbindd_cli_state
*cli
;
234 struct winbindd_request ping_request
;
237 static void domain_info_done(struct tevent_req
*req
);
239 void winbindd_domain_info(struct winbindd_cli_state
*cli
)
241 struct domain_info_state
*state
;
242 struct winbindd_domain
*domain
;
243 struct tevent_req
*req
;
245 DEBUG(3, ("[%5lu]: domain_info [%s]\n", (unsigned long)cli
->pid
,
246 cli
->request
->domain_name
));
248 domain
= find_domain_from_name_noinit(cli
->request
->domain_name
);
250 if (domain
== NULL
) {
251 DEBUG(3, ("Did not find domain [%s]\n",
252 cli
->request
->domain_name
));
257 if (domain
->initialized
) {
258 fstrcpy(cli
->response
->data
.domain_info
.name
,
260 fstrcpy(cli
->response
->data
.domain_info
.alt_name
,
262 sid_to_fstring(cli
->response
->data
.domain_info
.sid
,
264 cli
->response
->data
.domain_info
.native_mode
=
266 cli
->response
->data
.domain_info
.active_directory
=
267 domain
->active_directory
;
268 cli
->response
->data
.domain_info
.primary
=
274 state
= talloc_zero(cli
->mem_ctx
, struct domain_info_state
);
276 DEBUG(0, ("talloc failed\n"));
282 state
->domain
= domain
;
283 state
->ping_request
.cmd
= WINBINDD_PING
;
286 * Send a ping down. This implicitly initializes the domain.
289 req
= wb_domain_request_send(state
, winbind_event_context(),
290 domain
, &state
->ping_request
);
292 DEBUG(3, ("wb_domain_request_send failed\n"));
296 tevent_req_set_callback(req
, domain_info_done
, state
);
299 static void domain_info_done(struct tevent_req
*req
)
301 struct domain_info_state
*state
= tevent_req_callback_data(
302 req
, struct domain_info_state
);
303 struct winbindd_response
*response
;
306 ret
= wb_domain_request_recv(req
, req
, &response
, &err
);
309 DEBUG(10, ("wb_domain_request failed: %s\n", strerror(errno
)));
310 request_error(state
->cli
);
313 if (!state
->domain
->initialized
) {
314 DEBUG(5, ("wb_domain_request did not initialize domain %s\n",
315 state
->domain
->name
));
316 request_error(state
->cli
);
320 fstrcpy(state
->cli
->response
->data
.domain_info
.name
,
321 state
->domain
->name
);
322 fstrcpy(state
->cli
->response
->data
.domain_info
.alt_name
,
323 state
->domain
->alt_name
);
324 sid_to_fstring(state
->cli
->response
->data
.domain_info
.sid
,
325 &state
->domain
->sid
);
327 state
->cli
->response
->data
.domain_info
.native_mode
=
328 state
->domain
->native_mode
;
329 state
->cli
->response
->data
.domain_info
.active_directory
=
330 state
->domain
->active_directory
;
331 state
->cli
->response
->data
.domain_info
.primary
=
332 state
->domain
->primary
;
334 request_ok(state
->cli
);
337 /* List various tidbits of information */
339 void winbindd_info(struct winbindd_cli_state
*state
)
342 DEBUG(3, ("[%5lu]: request misc info\n", (unsigned long)state
->pid
));
344 state
->response
->data
.info
.winbind_separator
= *lp_winbind_separator();
345 fstrcpy(state
->response
->data
.info
.samba_version
, samba_version_string());
349 /* Tell the client the current interface version */
351 void winbindd_interface_version(struct winbindd_cli_state
*state
)
353 DEBUG(3, ("[%5lu]: request interface version\n",
354 (unsigned long)state
->pid
));
356 state
->response
->data
.interface_version
= WINBIND_INTERFACE_VERSION
;
360 /* What domain are we a member of? */
362 void winbindd_domain_name(struct winbindd_cli_state
*state
)
364 DEBUG(3, ("[%5lu]: request domain name\n", (unsigned long)state
->pid
));
366 fstrcpy(state
->response
->data
.domain_name
, lp_workgroup());
370 /* What's my name again? */
372 void winbindd_netbios_name(struct winbindd_cli_state
*state
)
374 DEBUG(3, ("[%5lu]: request netbios name\n",
375 (unsigned long)state
->pid
));
377 fstrcpy(state
->response
->data
.netbios_name
, global_myname());
381 /* Where can I find the privileged pipe? */
383 void winbindd_priv_pipe_dir(struct winbindd_cli_state
*state
)
386 DEBUG(3, ("[%5lu]: request location of privileged pipe\n",
387 (unsigned long)state
->pid
));
389 priv_dir
= get_winbind_priv_pipe_dir();
390 state
->response
->extra_data
.data
= talloc_move(state
->mem_ctx
,
393 /* must add one to length to copy the 0 for string termination */
394 state
->response
->length
+=
395 strlen((char *)state
->response
->extra_data
.data
) + 1;