Remove a pointless level of indirection
[Samba/gebeck_regimport.git] / source3 / winbindd / winbindd_locator.c
blobb2a8bd7e3037ff2541a5f2ac62092328d7db05e1
1 /*
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/>.
23 #include "includes.h"
24 #include "winbindd.h"
26 #undef DBGC_CLASS
27 #define DBGC_CLASS DBGC_WINBIND
30 static const struct winbindd_child_dispatch_table locator_dispatch_table[];
32 static struct winbindd_child static_locator_child;
34 void init_locator_child(void)
36 setup_child(&static_locator_child,
37 locator_dispatch_table,
38 "log.winbindd", "locator");
41 struct winbindd_child *locator_child(void)
43 return &static_locator_child;
46 void winbindd_dsgetdcname(struct winbindd_cli_state *state)
48 state->request.domain_name
49 [sizeof(state->request.domain_name)-1] = '\0';
51 DEBUG(3, ("[%5lu]: dsgetdcname for %s\n", (unsigned long)state->pid,
52 state->request.domain_name));
54 sendto_child(state, locator_child());
57 struct wbc_flag_map {
58 uint32_t wbc_dc_flag;
59 uint32_t ds_dc_flags;
62 static uint32_t get_dsgetdc_flags(uint32_t wbc_flags)
64 struct wbc_flag_map lookup_dc_flags[] = {
65 { WBC_LOOKUP_DC_FORCE_REDISCOVERY, DS_FORCE_REDISCOVERY },
66 { WBC_LOOKUP_DC_DS_REQUIRED, DS_DIRECTORY_SERVICE_REQUIRED },
67 { WBC_LOOKUP_DC_DS_PREFERRED, DS_DIRECTORY_SERVICE_PREFERRED},
68 { WBC_LOOKUP_DC_GC_SERVER_REQUIRED, DS_GC_SERVER_REQUIRED },
69 { WBC_LOOKUP_DC_PDC_REQUIRED, DS_PDC_REQUIRED},
70 { WBC_LOOKUP_DC_BACKGROUND_ONLY, DS_BACKGROUND_ONLY },
71 { WBC_LOOKUP_DC_IP_REQUIRED, DS_IP_REQUIRED },
72 { WBC_LOOKUP_DC_KDC_REQUIRED, DS_KDC_REQUIRED },
73 { WBC_LOOKUP_DC_TIMESERV_REQUIRED, DS_TIMESERV_REQUIRED },
74 { WBC_LOOKUP_DC_WRITABLE_REQUIRED, DS_WRITABLE_REQUIRED },
75 { WBC_LOOKUP_DC_GOOD_TIMESERV_PREFERRED, DS_GOOD_TIMESERV_PREFERRED },
76 { WBC_LOOKUP_DC_AVOID_SELF, DS_AVOID_SELF },
77 { WBC_LOOKUP_DC_ONLY_LDAP_NEEDED, DS_ONLY_LDAP_NEEDED },
78 { WBC_LOOKUP_DC_IS_FLAT_NAME, DS_IS_FLAT_NAME },
79 { WBC_LOOKUP_DC_IS_DNS_NAME, DS_IS_DNS_NAME },
80 { WBC_LOOKUP_DC_TRY_NEXTCLOSEST_SITE, DS_TRY_NEXTCLOSEST_SITE },
81 { WBC_LOOKUP_DC_DS_6_REQUIRED, DS_DIRECTORY_SERVICE_6_REQUIRED },
82 { WBC_LOOKUP_DC_RETURN_DNS_NAME, DS_RETURN_DNS_NAME },
83 { WBC_LOOKUP_DC_RETURN_FLAT_NAME, DS_RETURN_FLAT_NAME }
85 uint32_t ds_flags = 0;
86 int i = 0 ;
87 int num_entries = sizeof(lookup_dc_flags) / sizeof(struct wbc_flag_map);
89 for (i=0; i<num_entries; i++) {
90 if (wbc_flags & lookup_dc_flags[i].wbc_dc_flag)
91 ds_flags |= lookup_dc_flags[i].ds_dc_flags;
94 return ds_flags;
98 static enum winbindd_result dual_dsgetdcname(struct winbindd_domain *domain,
99 struct winbindd_cli_state *state)
101 NTSTATUS result;
102 struct netr_DsRGetDCNameInfo *info = NULL;
103 const char *dc = NULL;
104 uint32_t ds_flags = 0;
106 state->request.domain_name
107 [sizeof(state->request.domain_name)-1] = '\0';
109 DEBUG(3, ("[%5lu]: dsgetdcname for %s\n", (unsigned long)state->pid,
110 state->request.domain_name));
112 ds_flags = get_dsgetdc_flags(state->request.flags);
114 result = dsgetdcname(state->mem_ctx, winbind_messaging_context(),
115 state->request.domain_name,
116 NULL, NULL, ds_flags, &info);
118 if (!NT_STATUS_IS_OK(result)) {
119 return WINBINDD_ERROR;
122 if (info->dc_address) {
123 dc = strip_hostname(info->dc_address);
126 if ((!dc || !is_ipaddress_v4(dc)) && info->dc_unc) {
127 dc = strip_hostname(info->dc_unc);
130 if (!dc || !*dc) {
131 return WINBINDD_ERROR;
134 fstrcpy(state->response.data.dc_name, dc);
136 return WINBINDD_OK;
139 static const struct winbindd_child_dispatch_table locator_dispatch_table[] = {
141 .name = "DSGETDCNAME",
142 .struct_cmd = WINBINDD_DSGETDCNAME,
143 .struct_fn = dual_dsgetdcname,
145 .name = NULL,