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/>.
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
->data
.dsgetdcname
.domain_name
49 [sizeof(state
->request
->data
.dsgetdcname
.domain_name
)-1] = '\0';
50 state
->request
->data
.dsgetdcname
.site_name
51 [sizeof(state
->request
->data
.dsgetdcname
.site_name
)-1] = '\0';
52 state
->request
->data
.dsgetdcname
.domain_guid
53 [sizeof(state
->request
->data
.dsgetdcname
.domain_guid
)-1] = '\0';
55 DEBUG(3, ("[%5lu]: dsgetdcname for %s\n", (unsigned long)state
->pid
,
56 state
->request
->data
.dsgetdcname
.domain_name
));
58 sendto_child(state
, locator_child());
66 static uint32_t get_dsgetdc_flags(uint32_t wbc_flags
)
68 struct wbc_flag_map lookup_dc_flags
[] = {
69 { WBC_LOOKUP_DC_FORCE_REDISCOVERY
, DS_FORCE_REDISCOVERY
},
70 { WBC_LOOKUP_DC_DS_REQUIRED
, DS_DIRECTORY_SERVICE_REQUIRED
},
71 { WBC_LOOKUP_DC_DS_PREFERRED
, DS_DIRECTORY_SERVICE_PREFERRED
},
72 { WBC_LOOKUP_DC_GC_SERVER_REQUIRED
, DS_GC_SERVER_REQUIRED
},
73 { WBC_LOOKUP_DC_PDC_REQUIRED
, DS_PDC_REQUIRED
},
74 { WBC_LOOKUP_DC_BACKGROUND_ONLY
, DS_BACKGROUND_ONLY
},
75 { WBC_LOOKUP_DC_IP_REQUIRED
, DS_IP_REQUIRED
},
76 { WBC_LOOKUP_DC_KDC_REQUIRED
, DS_KDC_REQUIRED
},
77 { WBC_LOOKUP_DC_TIMESERV_REQUIRED
, DS_TIMESERV_REQUIRED
},
78 { WBC_LOOKUP_DC_WRITABLE_REQUIRED
, DS_WRITABLE_REQUIRED
},
79 { WBC_LOOKUP_DC_GOOD_TIMESERV_PREFERRED
, DS_GOOD_TIMESERV_PREFERRED
},
80 { WBC_LOOKUP_DC_AVOID_SELF
, DS_AVOID_SELF
},
81 { WBC_LOOKUP_DC_ONLY_LDAP_NEEDED
, DS_ONLY_LDAP_NEEDED
},
82 { WBC_LOOKUP_DC_IS_FLAT_NAME
, DS_IS_FLAT_NAME
},
83 { WBC_LOOKUP_DC_IS_DNS_NAME
, DS_IS_DNS_NAME
},
84 { WBC_LOOKUP_DC_TRY_NEXTCLOSEST_SITE
, DS_TRY_NEXTCLOSEST_SITE
},
85 { WBC_LOOKUP_DC_DS_6_REQUIRED
, DS_DIRECTORY_SERVICE_6_REQUIRED
},
86 { WBC_LOOKUP_DC_RETURN_DNS_NAME
, DS_RETURN_DNS_NAME
},
87 { WBC_LOOKUP_DC_RETURN_FLAT_NAME
, DS_RETURN_FLAT_NAME
}
89 uint32_t ds_flags
= 0;
91 int num_entries
= sizeof(lookup_dc_flags
) / sizeof(struct wbc_flag_map
);
93 for (i
=0; i
<num_entries
; i
++) {
94 if (wbc_flags
& lookup_dc_flags
[i
].wbc_dc_flag
)
95 ds_flags
|= lookup_dc_flags
[i
].ds_dc_flags
;
101 static enum winbindd_result
dual_dsgetdcname(struct winbindd_domain
*domain
,
102 struct winbindd_cli_state
*state
)
105 struct netr_DsRGetDCNameInfo
*info
= NULL
;
106 uint32_t ds_flags
= 0;
107 struct GUID guid
, *guid_ptr
= NULL
;
108 const char *guid_str
= NULL
;
110 state
->request
->data
.dsgetdcname
.domain_name
111 [sizeof(state
->request
->data
.dsgetdcname
.domain_name
)-1] = '\0';
112 state
->request
->data
.dsgetdcname
.site_name
113 [sizeof(state
->request
->data
.dsgetdcname
.site_name
)-1] = '\0';
114 state
->request
->data
.dsgetdcname
.domain_guid
115 [sizeof(state
->request
->data
.dsgetdcname
.domain_guid
)-1] = '\0';
117 DEBUG(3, ("[%5lu]: dsgetdcname for %s\n", (unsigned long)state
->pid
,
118 state
->request
->data
.dsgetdcname
.domain_name
));
120 ds_flags
= get_dsgetdc_flags(state
->request
->flags
);
122 result
= GUID_from_string(state
->request
->data
.dsgetdcname
.domain_guid
,
124 if (NT_STATUS_IS_OK(result
) && !GUID_all_zero(&guid
)) {
128 result
= dsgetdcname(state
->mem_ctx
,
129 winbind_messaging_context(),
130 state
->request
->data
.dsgetdcname
.domain_name
,
132 state
->request
->data
.dsgetdcname
.site_name
,
136 if (!NT_STATUS_IS_OK(result
)) {
137 return WINBINDD_ERROR
;
140 guid_str
= GUID_string(state
->mem_ctx
, &info
->domain_guid
);
142 return WINBINDD_ERROR
;
145 fstrcpy(state
->response
->data
.dsgetdcname
.dc_unc
, info
->dc_unc
);
146 fstrcpy(state
->response
->data
.dsgetdcname
.dc_address
, info
->dc_address
);
147 state
->response
->data
.dsgetdcname
.dc_address_type
= info
->dc_address_type
;
148 fstrcpy(state
->response
->data
.dsgetdcname
.domain_guid
, guid_str
);
149 fstrcpy(state
->response
->data
.dsgetdcname
.domain_name
, info
->domain_name
);
150 fstrcpy(state
->response
->data
.dsgetdcname
.forest_name
, info
->forest_name
);
151 state
->response
->data
.dsgetdcname
.dc_flags
= info
->dc_flags
;
152 fstrcpy(state
->response
->data
.dsgetdcname
.dc_site_name
, info
->dc_site_name
);
153 fstrcpy(state
->response
->data
.dsgetdcname
.client_site_name
, info
->client_site_name
);
158 static const struct winbindd_child_dispatch_table locator_dispatch_table
[] = {
161 .struct_cmd
= WINBINDD_PING
,
162 .struct_fn
= winbindd_dual_ping
,
164 .name
= "DSGETDCNAME",
165 .struct_cmd
= WINBINDD_DSGETDCNAME
,
166 .struct_fn
= dual_dsgetdcname
,