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 "libcli/security/dom_sid.h"
28 #define DBGC_CLASS DBGC_WINBIND
30 static char *get_trust_type_string(TALLOC_CTX *mem_ctx,
31 struct winbindd_tdc_domain *tdc,
32 struct winbindd_domain *domain)
34 enum netr_SchannelType secure_channel_type = SEC_CHAN_NULL;
38 secure_channel_type = domain->secure_channel_type;
41 switch (secure_channel_type) {
44 DBG_ERR("Missing domain [%s]\n",
48 if (domain->routing_domain == NULL) {
49 DBG_ERR("Missing routing for domain [%s]\n",
53 s = talloc_asprintf(mem_ctx, "Routed (via %s)",
54 domain->routing_domain->name);
62 s = talloc_strdup(mem_ctx, "Local");
69 s = talloc_strdup(mem_ctx, "Workstation");
76 int role = lp_server_role();
78 if (role == ROLE_DOMAIN_PDC) {
79 s = talloc_strdup(mem_ctx, "PDC");
86 if (role == ROLE_DOMAIN_BDC) {
87 s = talloc_strdup(mem_ctx, "BDC");
94 s = talloc_strdup(mem_ctx, "RWDC");
102 s = talloc_strdup(mem_ctx, "RODC");
108 case SEC_CHAN_DNS_DOMAIN:
109 if (tdc->trust_attribs & LSA_TRUST_ATTRIBUTE_QUARANTINED_DOMAIN) {
110 s = talloc_strdup(mem_ctx, "External");
116 if (tdc->trust_attribs & LSA_TRUST_ATTRIBUTE_WITHIN_FOREST) {
117 s = talloc_strdup(mem_ctx, "In Forest");
123 if (tdc->trust_attribs & LSA_TRUST_ATTRIBUTE_TREAT_AS_EXTERNAL) {
124 s = talloc_strdup(mem_ctx, "External");
130 if (tdc->trust_attribs & LSA_TRUST_ATTRIBUTE_FOREST_TRANSITIVE) {
131 s = talloc_strdup(mem_ctx, "Forest");
137 s = talloc_strdup(mem_ctx, "External");
143 case SEC_CHAN_DOMAIN:
144 s = talloc_strdup(mem_ctx, "External");
151 DBG_ERR("Unhandled secure_channel_type %d for domain[%s]\n",
152 secure_channel_type, tdc->domain_name);
159 static bool trust_is_inbound(struct winbindd_tdc_domain *domain)
161 if (domain->trust_flags & NETR_TRUST_FLAG_INBOUND) {
167 static bool trust_is_outbound(struct winbindd_tdc_domain *domain)
169 if (domain->trust_flags & NETR_TRUST_FLAG_OUTBOUND) {
175 static bool trust_is_transitive(struct winbindd_tdc_domain *domain)
177 bool transitive = false;
180 * Beware: order matters
183 if (domain->trust_attribs & LSA_TRUST_ATTRIBUTE_WITHIN_FOREST) {
187 if (domain->trust_attribs & LSA_TRUST_ATTRIBUTE_FOREST_TRANSITIVE) {
191 if (domain->trust_attribs & LSA_TRUST_ATTRIBUTE_NON_TRANSITIVE) {
195 if (domain->trust_attribs & LSA_TRUST_ATTRIBUTE_QUARANTINED_DOMAIN) {
199 if (domain->trust_flags & NETR_TRUST_FLAG_PRIMARY) {
206 bool winbindd_list_trusted_domains(struct winbindd_cli_state *state)
208 struct winbindd_tdc_domain *dom_list = NULL;
209 size_t num_domains = 0;
210 int extra_data_len = 0;
211 char *extra_data = NULL;
215 DBG_NOTICE("[%s (%u)]: list trusted domains\n",
217 (unsigned int)state->pid);
219 if( !wcache_tdc_fetch_list( &dom_list, &num_domains )) {
223 extra_data = talloc_strdup(state->mem_ctx, "");
224 if (extra_data == NULL) {
228 for ( i = 0; i < num_domains; i++ ) {
229 struct winbindd_domain *domain;
230 bool is_online = true;
231 struct winbindd_tdc_domain *d = NULL;
232 char *trust_type = NULL;
233 struct dom_sid_buf buf;
236 domain = find_domain_from_name_noinit(d->domain_name);
238 is_online = domain->online;
241 trust_type = get_trust_type_string(talloc_tos(), d, domain);
242 if (trust_type == NULL) {
246 extra_data = talloc_asprintf_append_buffer(
248 "%s\\%s\\%s\\%s\\%s\\%s\\%s\\%s\n",
250 d->dns_name ? d->dns_name : "",
251 dom_sid_str_buf(&d->sid, &buf),
253 trust_is_transitive(d) ? "Yes" : "No",
254 trust_is_inbound(d) ? "Yes" : "No",
255 trust_is_outbound(d) ? "Yes" : "No",
256 is_online ? "Online" : "Offline" );
258 TALLOC_FREE(trust_type);
261 state->response->data.num_entries = num_domains;
263 extra_data_len = strlen(extra_data);
264 if (extra_data_len > 0) {
266 /* Strip the last \n */
267 extra_data[extra_data_len-1] = '\0';
269 state->response->extra_data.data = extra_data;
270 state->response->length += extra_data_len;
275 TALLOC_FREE( dom_list );
279 enum winbindd_result winbindd_dual_list_trusted_domains(struct winbindd_domain *domain,
280 struct winbindd_cli_state *state)
283 int extra_data_len = 0;
286 bool have_own_domain = False;
287 struct netr_DomainTrustList trusts;
289 DBG_NOTICE("[%s %u]: list trusted domains\n",
291 (unsigned int)state->pid);
293 result = wb_cache_trusted_domains(domain, state->mem_ctx, &trusts);
295 if (!NT_STATUS_IS_OK(result)) {
296 DEBUG(3, ("winbindd_dual_list_trusted_domains: trusted_domains returned %s\n",
297 nt_errstr(result) ));
298 return WINBINDD_ERROR;
301 extra_data = talloc_strdup(state->mem_ctx, "");
303 for (i=0; i<trusts.count; i++) {
304 struct dom_sid_buf buf;
306 if (trusts.array[i].sid == NULL) {
309 if (dom_sid_equal(trusts.array[i].sid, &global_sid_NULL)) {
313 extra_data = talloc_asprintf_append_buffer(
314 extra_data, "%s\\%s\\%s\\%u\\%u\\%u\n",
315 trusts.array[i].netbios_name, trusts.array[i].dns_name,
316 dom_sid_str_buf(trusts.array[i].sid, &buf),
317 trusts.array[i].trust_flags,
318 (uint32_t)trusts.array[i].trust_type,
319 trusts.array[i].trust_attributes);
322 /* add our primary domain */
324 for (i=0; i<trusts.count; i++) {
325 if (strequal(trusts.array[i].netbios_name, domain->name)) {
326 have_own_domain = True;
331 if (state->request->data.list_all_domains && !have_own_domain) {
332 struct dom_sid_buf buf;
333 extra_data = talloc_asprintf_append_buffer(
334 extra_data, "%s\\%s\\%s\n", domain->name,
335 domain->alt_name != NULL ?
338 dom_sid_str_buf(&domain->sid, &buf));
341 extra_data_len = strlen(extra_data);
342 if (extra_data_len > 0) {
344 /* Strip the last \n */
345 extra_data[extra_data_len-1] = '\0';
347 state->response->extra_data.data = extra_data;
348 state->response->length += extra_data_len;
354 bool winbindd_dc_info(struct winbindd_cli_state *cli)
356 struct winbindd_domain *domain;
357 char *dc_name, *dc_ip;
359 cli->request->domain_name[sizeof(cli->request->domain_name)-1] = '\0';
361 DBG_NOTICE("[%s (%u)]: domain_info [%s]\n",
363 (unsigned int)cli->pid,
364 cli->request->domain_name);
366 if (cli->request->domain_name[0] != '\0') {
367 domain = find_trust_from_name_noinit(
368 cli->request->domain_name);
369 if (domain == NULL) {
370 DEBUG(10, ("Could not find domain %s\n",
371 cli->request->domain_name));
375 domain = find_our_domain();
378 if (!fetch_current_dc_from_gencache(
379 talloc_tos(), domain->name, &dc_name, &dc_ip)) {
380 DEBUG(10, ("fetch_current_dc_from_gencache(%s) failed\n",
385 cli->response->data.num_entries = 1;
386 cli->response->extra_data.data = talloc_asprintf(
387 cli->mem_ctx, "%s\n%s\n", dc_name, dc_ip);
389 TALLOC_FREE(dc_name);
392 if (cli->response->extra_data.data == NULL) {
396 /* must add one to length to copy the 0 for string termination */
397 cli->response->length +=
398 strlen((char *)cli->response->extra_data.data) + 1;
403 bool winbindd_ping(struct winbindd_cli_state *state)
405 DBG_NOTICE("[%s (%u)]: ping\n",
407 (unsigned int)state->pid);
411 /* List various tidbits of information */
413 bool winbindd_info(struct winbindd_cli_state *state)
416 DBG_NOTICE("[%s (%u)]: request misc info\n",
418 (unsigned int)state->pid);
420 state->response->data.info.winbind_separator = *lp_winbind_separator();
421 fstrcpy(state->response->data.info.samba_version, samba_version_string());
425 /* Tell the client the current interface version */
427 bool winbindd_interface_version(struct winbindd_cli_state *state)
429 DBG_NOTICE("[%s (%u)]: request interface version (version = %d)\n",
431 (unsigned int)state->pid,
432 WINBIND_INTERFACE_VERSION);
434 state->response->data.interface_version = WINBIND_INTERFACE_VERSION;
438 /* What domain are we a member of? */
440 bool winbindd_domain_name(struct winbindd_cli_state *state)
442 DBG_NOTICE("[%s (%u)]: request domain name\n",
444 (unsigned int)state->pid);
446 fstrcpy(state->response->data.domain_name, lp_workgroup());
450 /* What's my name again? */
452 bool winbindd_netbios_name(struct winbindd_cli_state *state)
454 DBG_NOTICE("[%s (%u)]: request netbios name\n",
456 (unsigned int)state->pid);
458 fstrcpy(state->response->data.netbios_name, lp_netbios_name());
462 /* Where can I find the privileged pipe? */
464 bool winbindd_priv_pipe_dir(struct winbindd_cli_state *state)
468 DBG_NOTICE("[%s (%u)]: request location of privileged pipe\n",
470 (unsigned int)state->pid);
472 priv_dir = get_winbind_priv_pipe_dir();
473 state->response->extra_data.data = talloc_move(state->mem_ctx,
476 /* must add one to length to copy the 0 for string termination */
477 state->response->length +=
478 strlen((char *)state->response->extra_data.data) + 1;