r25598: Add missing become_root/unbecome_root around calls of add_aliases.
[Samba/gebeck_regimport.git] / source3 / winbindd / winbindd_locator.c
blobade2c1539b43eecb5da0706dfa774889ec6769f8
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_domain_child(NULL,
37 &static_locator_child,
38 locator_dispatch_table,
39 "locator");
42 struct winbindd_child *locator_child(void)
44 return &static_locator_child;
47 void winbindd_dsgetdcname(struct winbindd_cli_state *state)
49 state->request.domain_name
50 [sizeof(state->request.domain_name)-1] = '\0';
52 DEBUG(3, ("[%5lu]: DsGetDcName for %s\n", (unsigned long)state->pid,
53 state->request.domain_name));
55 sendto_child(state, locator_child());
58 static enum winbindd_result dual_dsgetdcname(struct winbindd_domain *domain,
59 struct winbindd_cli_state *state)
61 NTSTATUS result;
62 struct DS_DOMAIN_CONTROLLER_INFO *info = NULL;
63 const char *dc = NULL;
65 state->request.domain_name
66 [sizeof(state->request.domain_name)-1] = '\0';
68 DEBUG(3, ("[%5lu]: DsGetDcName for %s\n", (unsigned long)state->pid,
69 state->request.domain_name));
71 result = DsGetDcName(state->mem_ctx, NULL, state->request.domain_name,
72 NULL, NULL, state->request.flags, &info);
74 if (!NT_STATUS_IS_OK(result)) {
75 return WINBINDD_ERROR;
78 if (info->domain_controller_address) {
79 dc = info->domain_controller_address;
80 if ((dc[0] == '\\') && (dc[1] == '\\')) {
81 dc += 2;
85 if ((!dc || !is_ipaddress(dc)) && info->domain_controller_name) {
86 dc = info->domain_controller_name;
89 if (!dc || !*dc) {
90 return WINBINDD_ERROR;
93 fstrcpy(state->response.data.dc_name, dc);
95 return WINBINDD_OK;
98 static const struct winbindd_child_dispatch_table locator_dispatch_table[] = {
99 { WINBINDD_DSGETDCNAME, dual_dsgetdcname, "DSGETDCNAME" },
101 { WINBINDD_NUM_CMDS, NULL, "NONE" }