1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 |
|
---|
4 | Winbind daemon - miscellaneous other functions
|
---|
5 |
|
---|
6 | Copyright (C) Tim Potter 2000
|
---|
7 | Copyright (C) Andrew Bartlett 2002
|
---|
8 |
|
---|
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.
|
---|
13 |
|
---|
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.
|
---|
18 |
|
---|
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/>.
|
---|
21 | */
|
---|
22 |
|
---|
23 | #include "includes.h"
|
---|
24 | #include "winbindd.h"
|
---|
25 |
|
---|
26 | #undef DBGC_CLASS
|
---|
27 | #define DBGC_CLASS DBGC_WINBIND
|
---|
28 |
|
---|
29 |
|
---|
30 | static struct winbindd_child static_locator_child;
|
---|
31 |
|
---|
32 | struct winbindd_child *locator_child(void)
|
---|
33 | {
|
---|
34 | return &static_locator_child;
|
---|
35 | }
|
---|
36 |
|
---|
37 | void winbindd_dsgetdcname(struct winbindd_cli_state *state)
|
---|
38 | {
|
---|
39 | state->request.data.dsgetdcname.domain_name
|
---|
40 | [sizeof(state->request.data.dsgetdcname.domain_name)-1] = '\0';
|
---|
41 | state->request.data.dsgetdcname.site_name
|
---|
42 | [sizeof(state->request.data.dsgetdcname.site_name)-1] = '\0';
|
---|
43 | state->request.data.dsgetdcname.domain_guid
|
---|
44 | [sizeof(state->request.data.dsgetdcname.domain_guid)-1] = '\0';
|
---|
45 |
|
---|
46 | DEBUG(3, ("[%5lu]: dsgetdcname for %s\n", (unsigned long)state->pid,
|
---|
47 | state->request.data.dsgetdcname.domain_name));
|
---|
48 |
|
---|
49 | sendto_child(state, locator_child());
|
---|
50 | }
|
---|
51 |
|
---|
52 | struct wbc_flag_map {
|
---|
53 | uint32_t wbc_dc_flag;
|
---|
54 | uint32_t ds_dc_flags;
|
---|
55 | };
|
---|
56 |
|
---|
57 | static uint32_t get_dsgetdc_flags(uint32_t wbc_flags)
|
---|
58 | {
|
---|
59 | struct wbc_flag_map lookup_dc_flags[] = {
|
---|
60 | { WBC_LOOKUP_DC_FORCE_REDISCOVERY, DS_FORCE_REDISCOVERY },
|
---|
61 | { WBC_LOOKUP_DC_DS_REQUIRED, DS_DIRECTORY_SERVICE_REQUIRED },
|
---|
62 | { WBC_LOOKUP_DC_DS_PREFERRED, DS_DIRECTORY_SERVICE_PREFERRED},
|
---|
63 | { WBC_LOOKUP_DC_GC_SERVER_REQUIRED, DS_GC_SERVER_REQUIRED },
|
---|
64 | { WBC_LOOKUP_DC_PDC_REQUIRED, DS_PDC_REQUIRED},
|
---|
65 | { WBC_LOOKUP_DC_BACKGROUND_ONLY, DS_BACKGROUND_ONLY },
|
---|
66 | { WBC_LOOKUP_DC_IP_REQUIRED, DS_IP_REQUIRED },
|
---|
67 | { WBC_LOOKUP_DC_KDC_REQUIRED, DS_KDC_REQUIRED },
|
---|
68 | { WBC_LOOKUP_DC_TIMESERV_REQUIRED, DS_TIMESERV_REQUIRED },
|
---|
69 | { WBC_LOOKUP_DC_WRITABLE_REQUIRED, DS_WRITABLE_REQUIRED },
|
---|
70 | { WBC_LOOKUP_DC_GOOD_TIMESERV_PREFERRED, DS_GOOD_TIMESERV_PREFERRED },
|
---|
71 | { WBC_LOOKUP_DC_AVOID_SELF, DS_AVOID_SELF },
|
---|
72 | { WBC_LOOKUP_DC_ONLY_LDAP_NEEDED, DS_ONLY_LDAP_NEEDED },
|
---|
73 | { WBC_LOOKUP_DC_IS_FLAT_NAME, DS_IS_FLAT_NAME },
|
---|
74 | { WBC_LOOKUP_DC_IS_DNS_NAME, DS_IS_DNS_NAME },
|
---|
75 | { WBC_LOOKUP_DC_TRY_NEXTCLOSEST_SITE, DS_TRY_NEXTCLOSEST_SITE },
|
---|
76 | { WBC_LOOKUP_DC_DS_6_REQUIRED, DS_DIRECTORY_SERVICE_6_REQUIRED },
|
---|
77 | { WBC_LOOKUP_DC_RETURN_DNS_NAME, DS_RETURN_DNS_NAME },
|
---|
78 | { WBC_LOOKUP_DC_RETURN_FLAT_NAME, DS_RETURN_FLAT_NAME }
|
---|
79 | };
|
---|
80 | uint32_t ds_flags = 0;
|
---|
81 | int i = 0 ;
|
---|
82 | int num_entries = sizeof(lookup_dc_flags) / sizeof(struct wbc_flag_map);
|
---|
83 |
|
---|
84 | for (i=0; i<num_entries; i++) {
|
---|
85 | if (wbc_flags & lookup_dc_flags[i].wbc_dc_flag)
|
---|
86 | ds_flags |= lookup_dc_flags[i].ds_dc_flags;
|
---|
87 | }
|
---|
88 |
|
---|
89 | return ds_flags;
|
---|
90 | }
|
---|
91 |
|
---|
92 | static enum winbindd_result dual_dsgetdcname(struct winbindd_domain *domain,
|
---|
93 | struct winbindd_cli_state *state)
|
---|
94 | {
|
---|
95 | NTSTATUS result;
|
---|
96 | struct netr_DsRGetDCNameInfo *info = NULL;
|
---|
97 | uint32_t ds_flags = 0;
|
---|
98 | struct GUID guid, *guid_ptr = NULL;
|
---|
99 | const char *guid_str = NULL;
|
---|
100 |
|
---|
101 | state->request.data.dsgetdcname.domain_name
|
---|
102 | [sizeof(state->request.data.dsgetdcname.domain_name)-1] = '\0';
|
---|
103 | state->request.data.dsgetdcname.site_name
|
---|
104 | [sizeof(state->request.data.dsgetdcname.site_name)-1] = '\0';
|
---|
105 | state->request.data.dsgetdcname.domain_guid
|
---|
106 | [sizeof(state->request.data.dsgetdcname.domain_guid)-1] = '\0';
|
---|
107 |
|
---|
108 | DEBUG(3, ("[%5lu]: dsgetdcname for %s\n", (unsigned long)state->pid,
|
---|
109 | state->request.data.dsgetdcname.domain_name));
|
---|
110 |
|
---|
111 | ds_flags = get_dsgetdc_flags(state->request.flags);
|
---|
112 |
|
---|
113 | result = GUID_from_string(state->request.data.dsgetdcname.domain_guid,
|
---|
114 | &guid);
|
---|
115 | if (NT_STATUS_IS_OK(result) && !GUID_all_zero(&guid)) {
|
---|
116 | guid_ptr = &guid;
|
---|
117 | }
|
---|
118 |
|
---|
119 | result = dsgetdcname(state->mem_ctx,
|
---|
120 | winbind_messaging_context(),
|
---|
121 | state->request.data.dsgetdcname.domain_name,
|
---|
122 | guid_ptr,
|
---|
123 | state->request.data.dsgetdcname.site_name,
|
---|
124 | ds_flags,
|
---|
125 | &info);
|
---|
126 |
|
---|
127 | if (!NT_STATUS_IS_OK(result)) {
|
---|
128 | return WINBINDD_ERROR;
|
---|
129 | }
|
---|
130 |
|
---|
131 | guid_str = GUID_string(state->mem_ctx, &info->domain_guid);
|
---|
132 | if (!guid_str) {
|
---|
133 | return WINBINDD_ERROR;
|
---|
134 | }
|
---|
135 |
|
---|
136 | fstrcpy(state->response.data.dsgetdcname.dc_unc, info->dc_unc);
|
---|
137 | fstrcpy(state->response.data.dsgetdcname.dc_address, info->dc_address);
|
---|
138 | state->response.data.dsgetdcname.dc_address_type = info->dc_address_type;
|
---|
139 | fstrcpy(state->response.data.dsgetdcname.domain_guid, guid_str);
|
---|
140 | fstrcpy(state->response.data.dsgetdcname.domain_name, info->domain_name);
|
---|
141 | fstrcpy(state->response.data.dsgetdcname.forest_name, info->forest_name);
|
---|
142 | state->response.data.dsgetdcname.dc_flags = info->dc_flags;
|
---|
143 | fstrcpy(state->response.data.dsgetdcname.dc_site_name, info->dc_site_name);
|
---|
144 | fstrcpy(state->response.data.dsgetdcname.client_site_name, info->client_site_name);
|
---|
145 |
|
---|
146 | return WINBINDD_OK;
|
---|
147 | }
|
---|
148 |
|
---|
149 | static const struct winbindd_child_dispatch_table locator_dispatch_table[] = {
|
---|
150 | {
|
---|
151 | .name = "DSGETDCNAME",
|
---|
152 | .struct_cmd = WINBINDD_DSGETDCNAME,
|
---|
153 | .struct_fn = dual_dsgetdcname,
|
---|
154 | },{
|
---|
155 | .name = NULL,
|
---|
156 | }
|
---|
157 | };
|
---|
158 |
|
---|
159 | void init_locator_child(void)
|
---|
160 | {
|
---|
161 | setup_child(&static_locator_child,
|
---|
162 | locator_dispatch_table,
|
---|
163 | "log.winbindd", "locator");
|
---|
164 | }
|
---|