1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 |
|
---|
4 | endpoint server for the drsuapi pipe
|
---|
5 | DsCrackNames()
|
---|
6 |
|
---|
7 | Copyright (C) Stefan Metzmacher 2004
|
---|
8 | Copyright (C) Andrew Bartlett <abartlet@samba.org> 2004-2005
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify
|
---|
11 | it under the terms of the GNU General Public License as published by
|
---|
12 | the Free Software Foundation; either version 3 of the License, or
|
---|
13 | (at your option) any later version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful,
|
---|
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | GNU General Public License for more details.
|
---|
19 |
|
---|
20 | You should have received a copy of the GNU General Public License
|
---|
21 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
22 | */
|
---|
23 |
|
---|
24 | #include "includes.h"
|
---|
25 | #include "librpc/gen_ndr/drsuapi.h"
|
---|
26 | #include "lib/events/events.h"
|
---|
27 | #include "rpc_server/common/common.h"
|
---|
28 | #include <ldb.h>
|
---|
29 | #include <ldb_errors.h>
|
---|
30 | #include "system/kerberos.h"
|
---|
31 | #include "auth/kerberos/kerberos.h"
|
---|
32 | #include "libcli/ldap/ldap_ndr.h"
|
---|
33 | #include "libcli/security/security.h"
|
---|
34 | #include "auth/auth.h"
|
---|
35 | #include "../lib/util/util_ldb.h"
|
---|
36 | #include "dsdb/samdb/samdb.h"
|
---|
37 | #include "dsdb/common/util.h"
|
---|
38 | #include "param/param.h"
|
---|
39 |
|
---|
40 | static WERROR DsCrackNameOneFilter(struct ldb_context *sam_ctx, TALLOC_CTX *mem_ctx,
|
---|
41 | struct smb_krb5_context *smb_krb5_context,
|
---|
42 | uint32_t format_flags, enum drsuapi_DsNameFormat format_offered,
|
---|
43 | enum drsuapi_DsNameFormat format_desired,
|
---|
44 | struct ldb_dn *name_dn, const char *name,
|
---|
45 | const char *domain_filter, const char *result_filter,
|
---|
46 | struct drsuapi_DsNameInfo1 *info1);
|
---|
47 | static WERROR DsCrackNameOneSyntactical(TALLOC_CTX *mem_ctx,
|
---|
48 | enum drsuapi_DsNameFormat format_offered,
|
---|
49 | enum drsuapi_DsNameFormat format_desired,
|
---|
50 | struct ldb_dn *name_dn, const char *name,
|
---|
51 | struct drsuapi_DsNameInfo1 *info1);
|
---|
52 |
|
---|
53 | static WERROR dns_domain_from_principal(TALLOC_CTX *mem_ctx, struct smb_krb5_context *smb_krb5_context,
|
---|
54 | const char *name,
|
---|
55 | struct drsuapi_DsNameInfo1 *info1)
|
---|
56 | {
|
---|
57 | krb5_error_code ret;
|
---|
58 | krb5_principal principal;
|
---|
59 | /* perhaps it's a principal with a realm, so return the right 'domain only' response */
|
---|
60 | const char *realm;
|
---|
61 | ret = krb5_parse_name_flags(smb_krb5_context->krb5_context, name,
|
---|
62 | KRB5_PRINCIPAL_PARSE_REQUIRE_REALM, &principal);
|
---|
63 | if (ret) {
|
---|
64 | info1->status = DRSUAPI_DS_NAME_STATUS_NOT_FOUND;
|
---|
65 | return WERR_OK;
|
---|
66 | }
|
---|
67 |
|
---|
68 | /* This isn't an allocation assignemnt, so it is free'ed with the krb5_free_principal */
|
---|
69 | realm = krb5_principal_get_realm(smb_krb5_context->krb5_context, principal);
|
---|
70 |
|
---|
71 | info1->dns_domain_name = talloc_strdup(mem_ctx, realm);
|
---|
72 | krb5_free_principal(smb_krb5_context->krb5_context, principal);
|
---|
73 |
|
---|
74 | W_ERROR_HAVE_NO_MEMORY(info1->dns_domain_name);
|
---|
75 |
|
---|
76 | info1->status = DRSUAPI_DS_NAME_STATUS_DOMAIN_ONLY;
|
---|
77 | return WERR_OK;
|
---|
78 | }
|
---|
79 |
|
---|
80 | static enum drsuapi_DsNameStatus LDB_lookup_spn_alias(krb5_context context, struct ldb_context *ldb_ctx,
|
---|
81 | TALLOC_CTX *mem_ctx,
|
---|
82 | const char *alias_from,
|
---|
83 | char **alias_to)
|
---|
84 | {
|
---|
85 | unsigned int i;
|
---|
86 | int ret;
|
---|
87 | struct ldb_result *res;
|
---|
88 | struct ldb_message_element *spnmappings;
|
---|
89 | TALLOC_CTX *tmp_ctx;
|
---|
90 | struct ldb_dn *service_dn;
|
---|
91 | char *service_dn_str;
|
---|
92 |
|
---|
93 | const char *directory_attrs[] = {
|
---|
94 | "sPNMappings",
|
---|
95 | NULL
|
---|
96 | };
|
---|
97 |
|
---|
98 | tmp_ctx = talloc_new(mem_ctx);
|
---|
99 | if (!tmp_ctx) {
|
---|
100 | return DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR;
|
---|
101 | }
|
---|
102 |
|
---|
103 | service_dn = ldb_dn_new(tmp_ctx, ldb_ctx, "CN=Directory Service,CN=Windows NT,CN=Services");
|
---|
104 | if ( ! ldb_dn_add_base(service_dn, ldb_get_config_basedn(ldb_ctx))) {
|
---|
105 | return DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR;
|
---|
106 | }
|
---|
107 | service_dn_str = ldb_dn_alloc_linearized(tmp_ctx, service_dn);
|
---|
108 | if ( ! service_dn_str) {
|
---|
109 | return DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR;
|
---|
110 | }
|
---|
111 |
|
---|
112 | ret = ldb_search(ldb_ctx, tmp_ctx, &res, service_dn, LDB_SCOPE_BASE,
|
---|
113 | directory_attrs, "(objectClass=nTDSService)");
|
---|
114 |
|
---|
115 | if (ret != LDB_SUCCESS && ret != LDB_ERR_NO_SUCH_OBJECT) {
|
---|
116 | DEBUG(1, ("ldb_search: dn: %s not found: %s", service_dn_str, ldb_errstring(ldb_ctx)));
|
---|
117 | return DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR;
|
---|
118 | } else if (ret == LDB_ERR_NO_SUCH_OBJECT) {
|
---|
119 | DEBUG(1, ("ldb_search: dn: %s not found", service_dn_str));
|
---|
120 | return DRSUAPI_DS_NAME_STATUS_NOT_FOUND;
|
---|
121 | } else if (res->count != 1) {
|
---|
122 | talloc_free(res);
|
---|
123 | DEBUG(1, ("ldb_search: dn: %s not found", service_dn_str));
|
---|
124 | return DRSUAPI_DS_NAME_STATUS_NOT_FOUND;
|
---|
125 | }
|
---|
126 |
|
---|
127 | spnmappings = ldb_msg_find_element(res->msgs[0], "sPNMappings");
|
---|
128 | if (!spnmappings || spnmappings->num_values == 0) {
|
---|
129 | DEBUG(1, ("ldb_search: dn: %s no sPNMappings attribute", service_dn_str));
|
---|
130 | talloc_free(tmp_ctx);
|
---|
131 | return DRSUAPI_DS_NAME_STATUS_NOT_FOUND;
|
---|
132 | }
|
---|
133 |
|
---|
134 | for (i = 0; i < spnmappings->num_values; i++) {
|
---|
135 | char *mapping, *p, *str;
|
---|
136 | mapping = talloc_strdup(tmp_ctx,
|
---|
137 | (const char *)spnmappings->values[i].data);
|
---|
138 | if (!mapping) {
|
---|
139 | DEBUG(1, ("LDB_lookup_spn_alias: ldb_search: dn: %s did not have an sPNMapping\n", service_dn_str));
|
---|
140 | talloc_free(tmp_ctx);
|
---|
141 | return DRSUAPI_DS_NAME_STATUS_NOT_FOUND;
|
---|
142 | }
|
---|
143 |
|
---|
144 | /* C string manipulation sucks */
|
---|
145 |
|
---|
146 | p = strchr(mapping, '=');
|
---|
147 | if (!p) {
|
---|
148 | DEBUG(1, ("ldb_search: dn: %s sPNMapping malformed: %s\n",
|
---|
149 | service_dn_str, mapping));
|
---|
150 | talloc_free(tmp_ctx);
|
---|
151 | return DRSUAPI_DS_NAME_STATUS_NOT_FOUND;
|
---|
152 | }
|
---|
153 | p[0] = '\0';
|
---|
154 | p++;
|
---|
155 | do {
|
---|
156 | str = p;
|
---|
157 | p = strchr(p, ',');
|
---|
158 | if (p) {
|
---|
159 | p[0] = '\0';
|
---|
160 | p++;
|
---|
161 | }
|
---|
162 | if (strcasecmp(str, alias_from) == 0) {
|
---|
163 | *alias_to = mapping;
|
---|
164 | talloc_steal(mem_ctx, mapping);
|
---|
165 | talloc_free(tmp_ctx);
|
---|
166 | return DRSUAPI_DS_NAME_STATUS_OK;
|
---|
167 | }
|
---|
168 | } while (p);
|
---|
169 | }
|
---|
170 | DEBUG(4, ("LDB_lookup_spn_alias: no alias for service %s applicable\n", alias_from));
|
---|
171 | talloc_free(tmp_ctx);
|
---|
172 | return DRSUAPI_DS_NAME_STATUS_NOT_FOUND;
|
---|
173 | }
|
---|
174 |
|
---|
175 | /* When cracking a ServicePrincipalName, many services may be served
|
---|
176 | * by the host/ servicePrincipalName. The incoming query is for cifs/
|
---|
177 | * but we translate it here, and search on host/. This is done after
|
---|
178 | * the cifs/ entry has been searched for, making this a fallback */
|
---|
179 |
|
---|
180 | static WERROR DsCrackNameSPNAlias(struct ldb_context *sam_ctx, TALLOC_CTX *mem_ctx,
|
---|
181 | struct smb_krb5_context *smb_krb5_context,
|
---|
182 | uint32_t format_flags, enum drsuapi_DsNameFormat format_offered,
|
---|
183 | enum drsuapi_DsNameFormat format_desired,
|
---|
184 | const char *name, struct drsuapi_DsNameInfo1 *info1)
|
---|
185 | {
|
---|
186 | WERROR wret;
|
---|
187 | krb5_error_code ret;
|
---|
188 | krb5_principal principal;
|
---|
189 | const char *service, *dns_name;
|
---|
190 | char *new_service;
|
---|
191 | char *new_princ;
|
---|
192 | enum drsuapi_DsNameStatus namestatus;
|
---|
193 |
|
---|
194 | /* parse principal */
|
---|
195 | ret = krb5_parse_name_flags(smb_krb5_context->krb5_context,
|
---|
196 | name, KRB5_PRINCIPAL_PARSE_NO_REALM, &principal);
|
---|
197 | if (ret) {
|
---|
198 | DEBUG(2, ("Could not parse principal: %s: %s",
|
---|
199 | name, smb_get_krb5_error_message(smb_krb5_context->krb5_context,
|
---|
200 | ret, mem_ctx)));
|
---|
201 | return WERR_NOMEM;
|
---|
202 | }
|
---|
203 |
|
---|
204 | /* grab cifs/, http/ etc */
|
---|
205 |
|
---|
206 | /* This is checked for in callers, but be safe */
|
---|
207 | if (principal->name.name_string.len < 2) {
|
---|
208 | info1->status = DRSUAPI_DS_NAME_STATUS_NOT_FOUND;
|
---|
209 | krb5_free_principal(smb_krb5_context->krb5_context, principal);
|
---|
210 | return WERR_OK;
|
---|
211 | }
|
---|
212 | service = principal->name.name_string.val[0];
|
---|
213 | dns_name = principal->name.name_string.val[1];
|
---|
214 |
|
---|
215 | /* MAP it */
|
---|
216 | namestatus = LDB_lookup_spn_alias(smb_krb5_context->krb5_context,
|
---|
217 | sam_ctx, mem_ctx,
|
---|
218 | service, &new_service);
|
---|
219 |
|
---|
220 | if (namestatus == DRSUAPI_DS_NAME_STATUS_NOT_FOUND) {
|
---|
221 | wret = WERR_OK;
|
---|
222 | info1->status = DRSUAPI_DS_NAME_STATUS_DOMAIN_ONLY;
|
---|
223 | info1->dns_domain_name = talloc_strdup(mem_ctx, dns_name);
|
---|
224 | if (!info1->dns_domain_name) {
|
---|
225 | wret = WERR_NOMEM;
|
---|
226 | }
|
---|
227 | krb5_free_principal(smb_krb5_context->krb5_context, principal);
|
---|
228 | return wret;
|
---|
229 | } else if (namestatus != DRSUAPI_DS_NAME_STATUS_OK) {
|
---|
230 | info1->status = namestatus;
|
---|
231 | krb5_free_principal(smb_krb5_context->krb5_context, principal);
|
---|
232 | return WERR_OK;
|
---|
233 | }
|
---|
234 |
|
---|
235 | /* ooh, very nasty playing around in the Principal... */
|
---|
236 | free(principal->name.name_string.val[0]);
|
---|
237 | principal->name.name_string.val[0] = strdup(new_service);
|
---|
238 | if (!principal->name.name_string.val[0]) {
|
---|
239 | krb5_free_principal(smb_krb5_context->krb5_context, principal);
|
---|
240 | return WERR_NOMEM;
|
---|
241 | }
|
---|
242 |
|
---|
243 | /* reform principal */
|
---|
244 | ret = krb5_unparse_name_flags(smb_krb5_context->krb5_context, principal,
|
---|
245 | KRB5_PRINCIPAL_UNPARSE_NO_REALM, &new_princ);
|
---|
246 |
|
---|
247 | if (ret) {
|
---|
248 | krb5_free_principal(smb_krb5_context->krb5_context, principal);
|
---|
249 | return WERR_NOMEM;
|
---|
250 | }
|
---|
251 |
|
---|
252 | wret = DsCrackNameOneName(sam_ctx, mem_ctx, format_flags, format_offered, format_desired,
|
---|
253 | new_princ, info1);
|
---|
254 | free(new_princ);
|
---|
255 | if (W_ERROR_IS_OK(wret) && (info1->status == DRSUAPI_DS_NAME_STATUS_NOT_FOUND)) {
|
---|
256 | info1->status = DRSUAPI_DS_NAME_STATUS_DOMAIN_ONLY;
|
---|
257 | info1->dns_domain_name = talloc_strdup(mem_ctx, dns_name);
|
---|
258 | if (!info1->dns_domain_name) {
|
---|
259 | wret = WERR_NOMEM;
|
---|
260 | }
|
---|
261 | }
|
---|
262 | krb5_free_principal(smb_krb5_context->krb5_context, principal);
|
---|
263 | return wret;
|
---|
264 | }
|
---|
265 |
|
---|
266 | /* Subcase of CrackNames, for the userPrincipalName */
|
---|
267 |
|
---|
268 | static WERROR DsCrackNameUPN(struct ldb_context *sam_ctx, TALLOC_CTX *mem_ctx,
|
---|
269 | struct smb_krb5_context *smb_krb5_context,
|
---|
270 | uint32_t format_flags, enum drsuapi_DsNameFormat format_offered,
|
---|
271 | enum drsuapi_DsNameFormat format_desired,
|
---|
272 | const char *name, struct drsuapi_DsNameInfo1 *info1)
|
---|
273 | {
|
---|
274 | int ldb_ret;
|
---|
275 | WERROR status;
|
---|
276 | const char *domain_filter = NULL;
|
---|
277 | const char *result_filter = NULL;
|
---|
278 | krb5_error_code ret;
|
---|
279 | krb5_principal principal;
|
---|
280 | const char *realm;
|
---|
281 | char *unparsed_name_short;
|
---|
282 | const char *domain_attrs[] = { NULL };
|
---|
283 | struct ldb_result *domain_res = NULL;
|
---|
284 |
|
---|
285 | /* Prevent recursion */
|
---|
286 | if (!name) {
|
---|
287 | info1->status = DRSUAPI_DS_NAME_STATUS_NOT_FOUND;
|
---|
288 | return WERR_OK;
|
---|
289 | }
|
---|
290 |
|
---|
291 | ret = krb5_parse_name_flags(smb_krb5_context->krb5_context, name,
|
---|
292 | KRB5_PRINCIPAL_PARSE_REQUIRE_REALM, &principal);
|
---|
293 | if (ret) {
|
---|
294 | info1->status = DRSUAPI_DS_NAME_STATUS_NOT_FOUND;
|
---|
295 | return WERR_OK;
|
---|
296 | }
|
---|
297 |
|
---|
298 | realm = krb5_principal_get_realm(smb_krb5_context->krb5_context,
|
---|
299 | principal);
|
---|
300 |
|
---|
301 | ldb_ret = ldb_search(sam_ctx, mem_ctx, &domain_res,
|
---|
302 | samdb_partitions_dn(sam_ctx, mem_ctx),
|
---|
303 | LDB_SCOPE_ONELEVEL,
|
---|
304 | domain_attrs,
|
---|
305 | "(&(&(|(&(dnsRoot=%s)(nETBIOSName=*))(nETBIOSName=%s))(objectclass=crossRef))(ncName=*))",
|
---|
306 | ldb_binary_encode_string(mem_ctx, realm),
|
---|
307 | ldb_binary_encode_string(mem_ctx, realm));
|
---|
308 |
|
---|
309 | if (ldb_ret != LDB_SUCCESS) {
|
---|
310 | DEBUG(2, ("DsCrackNameUPN domain ref search failed: %s", ldb_errstring(sam_ctx)));
|
---|
311 | info1->status = DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR;
|
---|
312 | krb5_free_principal(smb_krb5_context->krb5_context, principal);
|
---|
313 | return WERR_OK;
|
---|
314 | }
|
---|
315 |
|
---|
316 | switch (domain_res->count) {
|
---|
317 | case 1:
|
---|
318 | break;
|
---|
319 | case 0:
|
---|
320 | krb5_free_principal(smb_krb5_context->krb5_context, principal);
|
---|
321 | return dns_domain_from_principal(mem_ctx, smb_krb5_context,
|
---|
322 | name, info1);
|
---|
323 | default:
|
---|
324 | info1->status = DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE;
|
---|
325 | krb5_free_principal(smb_krb5_context->krb5_context, principal);
|
---|
326 | return WERR_OK;
|
---|
327 | }
|
---|
328 |
|
---|
329 | ret = krb5_unparse_name_flags(smb_krb5_context->krb5_context, principal,
|
---|
330 | KRB5_PRINCIPAL_UNPARSE_NO_REALM, &unparsed_name_short);
|
---|
331 | krb5_free_principal(smb_krb5_context->krb5_context, principal);
|
---|
332 |
|
---|
333 | if (ret) {
|
---|
334 | free(unparsed_name_short);
|
---|
335 | return WERR_NOMEM;
|
---|
336 | }
|
---|
337 |
|
---|
338 | /* This may need to be extended for more userPrincipalName variations */
|
---|
339 | result_filter = talloc_asprintf(mem_ctx, "(&(objectClass=user)(samAccountName=%s))",
|
---|
340 | ldb_binary_encode_string(mem_ctx, unparsed_name_short));
|
---|
341 |
|
---|
342 | domain_filter = talloc_asprintf(mem_ctx, "(distinguishedName=%s)", ldb_dn_get_linearized(domain_res->msgs[0]->dn));
|
---|
343 |
|
---|
344 | if (!result_filter || !domain_filter) {
|
---|
345 | free(unparsed_name_short);
|
---|
346 | return WERR_NOMEM;
|
---|
347 | }
|
---|
348 | status = DsCrackNameOneFilter(sam_ctx, mem_ctx,
|
---|
349 | smb_krb5_context,
|
---|
350 | format_flags, format_offered, format_desired,
|
---|
351 | NULL, unparsed_name_short, domain_filter, result_filter,
|
---|
352 | info1);
|
---|
353 | free(unparsed_name_short);
|
---|
354 |
|
---|
355 | return status;
|
---|
356 | }
|
---|
357 |
|
---|
358 | /* Crack a single 'name', from format_offered into format_desired, returning the result in info1 */
|
---|
359 |
|
---|
360 | WERROR DsCrackNameOneName(struct ldb_context *sam_ctx, TALLOC_CTX *mem_ctx,
|
---|
361 | uint32_t format_flags, enum drsuapi_DsNameFormat format_offered,
|
---|
362 | enum drsuapi_DsNameFormat format_desired,
|
---|
363 | const char *name, struct drsuapi_DsNameInfo1 *info1)
|
---|
364 | {
|
---|
365 | krb5_error_code ret;
|
---|
366 | const char *domain_filter = NULL;
|
---|
367 | const char *result_filter = NULL;
|
---|
368 | struct ldb_dn *name_dn = NULL;
|
---|
369 |
|
---|
370 | struct smb_krb5_context *smb_krb5_context = NULL;
|
---|
371 |
|
---|
372 | info1->status = DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR;
|
---|
373 | info1->dns_domain_name = NULL;
|
---|
374 | info1->result_name = NULL;
|
---|
375 |
|
---|
376 | if (!name) {
|
---|
377 | return WERR_INVALID_PARAM;
|
---|
378 | }
|
---|
379 |
|
---|
380 | /* TODO: - fill the correct names in all cases!
|
---|
381 | * - handle format_flags
|
---|
382 | */
|
---|
383 |
|
---|
384 | /* here we need to set the domain_filter and/or the result_filter */
|
---|
385 | switch (format_offered) {
|
---|
386 | case DRSUAPI_DS_NAME_FORMAT_UNKNOWN:
|
---|
387 | {
|
---|
388 | unsigned int i;
|
---|
389 | enum drsuapi_DsNameFormat formats[] = {
|
---|
390 | DRSUAPI_DS_NAME_FORMAT_FQDN_1779, DRSUAPI_DS_NAME_FORMAT_USER_PRINCIPAL,
|
---|
391 | DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT, DRSUAPI_DS_NAME_FORMAT_CANONICAL,
|
---|
392 | DRSUAPI_DS_NAME_FORMAT_GUID, DRSUAPI_DS_NAME_FORMAT_DISPLAY,
|
---|
393 | DRSUAPI_DS_NAME_FORMAT_SERVICE_PRINCIPAL,
|
---|
394 | DRSUAPI_DS_NAME_FORMAT_SID_OR_SID_HISTORY,
|
---|
395 | DRSUAPI_DS_NAME_FORMAT_CANONICAL_EX
|
---|
396 | };
|
---|
397 | WERROR werr;
|
---|
398 | for (i=0; i < ARRAY_SIZE(formats); i++) {
|
---|
399 | werr = DsCrackNameOneName(sam_ctx, mem_ctx, format_flags, formats[i], format_desired, name, info1);
|
---|
400 | if (!W_ERROR_IS_OK(werr)) {
|
---|
401 | return werr;
|
---|
402 | }
|
---|
403 | if (info1->status != DRSUAPI_DS_NAME_STATUS_NOT_FOUND) {
|
---|
404 | return werr;
|
---|
405 | }
|
---|
406 | }
|
---|
407 | return werr;
|
---|
408 | }
|
---|
409 |
|
---|
410 | case DRSUAPI_DS_NAME_FORMAT_CANONICAL:
|
---|
411 | case DRSUAPI_DS_NAME_FORMAT_CANONICAL_EX:
|
---|
412 | {
|
---|
413 | char *str, *s, *account;
|
---|
414 |
|
---|
415 | if (strlen(name) == 0) {
|
---|
416 | info1->status = DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR;
|
---|
417 | return WERR_OK;
|
---|
418 | }
|
---|
419 |
|
---|
420 | str = talloc_strdup(mem_ctx, name);
|
---|
421 | W_ERROR_HAVE_NO_MEMORY(str);
|
---|
422 |
|
---|
423 | if (format_offered == DRSUAPI_DS_NAME_FORMAT_CANONICAL_EX) {
|
---|
424 | /* Look backwards for the \n, and replace it with / */
|
---|
425 | s = strrchr(str, '\n');
|
---|
426 | if (!s) {
|
---|
427 | info1->status = DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR;
|
---|
428 | return WERR_OK;
|
---|
429 | }
|
---|
430 | s[0] = '/';
|
---|
431 | }
|
---|
432 |
|
---|
433 | s = strchr(str, '/');
|
---|
434 | if (!s) {
|
---|
435 | /* there must be at least one / */
|
---|
436 | info1->status = DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR;
|
---|
437 | return WERR_OK;
|
---|
438 | }
|
---|
439 |
|
---|
440 | s[0] = '\0';
|
---|
441 | s++;
|
---|
442 |
|
---|
443 | domain_filter = talloc_asprintf(mem_ctx, "(&(objectClass=crossRef)(ncName=%s))",
|
---|
444 | ldb_dn_get_linearized(samdb_dns_domain_to_dn(sam_ctx, mem_ctx, str)));
|
---|
445 | W_ERROR_HAVE_NO_MEMORY(domain_filter);
|
---|
446 |
|
---|
447 | /* There may not be anything after the domain component (search for the domain itself) */
|
---|
448 | if (s[0]) {
|
---|
449 |
|
---|
450 | account = strrchr(s, '/');
|
---|
451 | if (!account) {
|
---|
452 | account = s;
|
---|
453 | } else {
|
---|
454 | account++;
|
---|
455 | }
|
---|
456 | account = ldb_binary_encode_string(mem_ctx, account);
|
---|
457 | W_ERROR_HAVE_NO_MEMORY(account);
|
---|
458 | result_filter = talloc_asprintf(mem_ctx, "(name=%s)",
|
---|
459 | account);
|
---|
460 | W_ERROR_HAVE_NO_MEMORY(result_filter);
|
---|
461 | }
|
---|
462 | break;
|
---|
463 | }
|
---|
464 | case DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT: {
|
---|
465 | char *p;
|
---|
466 | char *domain;
|
---|
467 | struct ldb_dn *dn_domain;
|
---|
468 | const char *account = NULL;
|
---|
469 |
|
---|
470 | domain = talloc_strdup(mem_ctx, name);
|
---|
471 | W_ERROR_HAVE_NO_MEMORY(domain);
|
---|
472 |
|
---|
473 | p = strchr(domain, '\\');
|
---|
474 | if (!p) {
|
---|
475 | /* invalid input format */
|
---|
476 | info1->status = DRSUAPI_DS_NAME_STATUS_NOT_FOUND;
|
---|
477 | return WERR_OK;
|
---|
478 | }
|
---|
479 | p[0] = '\0';
|
---|
480 |
|
---|
481 | if (p[1]) {
|
---|
482 | account = &p[1];
|
---|
483 | }
|
---|
484 |
|
---|
485 | /* it could be in DNS domain form */
|
---|
486 | dn_domain = samdb_dns_domain_to_dn(sam_ctx, mem_ctx, domain);
|
---|
487 | W_ERROR_HAVE_NO_MEMORY(dn_domain);
|
---|
488 |
|
---|
489 | domain_filter = talloc_asprintf(mem_ctx,
|
---|
490 | "(&(&(|(nETBIOSName=%s)(nCName=%s))(objectclass=crossRef))(ncName=*))",
|
---|
491 | ldb_binary_encode_string(mem_ctx, domain),
|
---|
492 | ldb_dn_get_linearized(dn_domain));
|
---|
493 | W_ERROR_HAVE_NO_MEMORY(domain_filter);
|
---|
494 | if (account) {
|
---|
495 | result_filter = talloc_asprintf(mem_ctx, "(sAMAccountName=%s)",
|
---|
496 | ldb_binary_encode_string(mem_ctx, account));
|
---|
497 | W_ERROR_HAVE_NO_MEMORY(result_filter);
|
---|
498 | }
|
---|
499 |
|
---|
500 | talloc_free(domain);
|
---|
501 | break;
|
---|
502 | }
|
---|
503 |
|
---|
504 | /* A LDAP DN as a string */
|
---|
505 | case DRSUAPI_DS_NAME_FORMAT_FQDN_1779: {
|
---|
506 | domain_filter = NULL;
|
---|
507 | name_dn = ldb_dn_new(mem_ctx, sam_ctx, name);
|
---|
508 | if (! ldb_dn_validate(name_dn)) {
|
---|
509 | info1->status = DRSUAPI_DS_NAME_STATUS_NOT_FOUND;
|
---|
510 | return WERR_OK;
|
---|
511 | }
|
---|
512 | break;
|
---|
513 | }
|
---|
514 |
|
---|
515 | /* A GUID as a string */
|
---|
516 | case DRSUAPI_DS_NAME_FORMAT_GUID: {
|
---|
517 | struct GUID guid;
|
---|
518 | char *ldap_guid;
|
---|
519 | NTSTATUS nt_status;
|
---|
520 | domain_filter = NULL;
|
---|
521 |
|
---|
522 | nt_status = GUID_from_string(name, &guid);
|
---|
523 | if (!NT_STATUS_IS_OK(nt_status)) {
|
---|
524 | info1->status = DRSUAPI_DS_NAME_STATUS_NOT_FOUND;
|
---|
525 | return WERR_OK;
|
---|
526 | }
|
---|
527 |
|
---|
528 | ldap_guid = ldap_encode_ndr_GUID(mem_ctx, &guid);
|
---|
529 | if (!ldap_guid) {
|
---|
530 | return WERR_NOMEM;
|
---|
531 | }
|
---|
532 | result_filter = talloc_asprintf(mem_ctx, "(objectGUID=%s)",
|
---|
533 | ldap_guid);
|
---|
534 | W_ERROR_HAVE_NO_MEMORY(result_filter);
|
---|
535 | break;
|
---|
536 | }
|
---|
537 | case DRSUAPI_DS_NAME_FORMAT_DISPLAY: {
|
---|
538 | domain_filter = NULL;
|
---|
539 |
|
---|
540 | result_filter = talloc_asprintf(mem_ctx, "(|(displayName=%s)(samAccountName=%s))",
|
---|
541 | ldb_binary_encode_string(mem_ctx, name),
|
---|
542 | ldb_binary_encode_string(mem_ctx, name));
|
---|
543 | W_ERROR_HAVE_NO_MEMORY(result_filter);
|
---|
544 | break;
|
---|
545 | }
|
---|
546 |
|
---|
547 | /* A S-1234-5678 style string */
|
---|
548 | case DRSUAPI_DS_NAME_FORMAT_SID_OR_SID_HISTORY: {
|
---|
549 | struct dom_sid *sid = dom_sid_parse_talloc(mem_ctx, name);
|
---|
550 | char *ldap_sid;
|
---|
551 |
|
---|
552 | domain_filter = NULL;
|
---|
553 | if (!sid) {
|
---|
554 | info1->status = DRSUAPI_DS_NAME_STATUS_NOT_FOUND;
|
---|
555 | return WERR_OK;
|
---|
556 | }
|
---|
557 | ldap_sid = ldap_encode_ndr_dom_sid(mem_ctx,
|
---|
558 | sid);
|
---|
559 | if (!ldap_sid) {
|
---|
560 | return WERR_NOMEM;
|
---|
561 | }
|
---|
562 | result_filter = talloc_asprintf(mem_ctx, "(objectSid=%s)",
|
---|
563 | ldap_sid);
|
---|
564 | W_ERROR_HAVE_NO_MEMORY(result_filter);
|
---|
565 | break;
|
---|
566 | }
|
---|
567 | case DRSUAPI_DS_NAME_FORMAT_USER_PRINCIPAL: {
|
---|
568 | krb5_principal principal;
|
---|
569 | char *unparsed_name;
|
---|
570 |
|
---|
571 | ret = smb_krb5_init_context(mem_ctx,
|
---|
572 | ldb_get_event_context(sam_ctx),
|
---|
573 | (struct loadparm_context *)ldb_get_opaque(sam_ctx, "loadparm"),
|
---|
574 | &smb_krb5_context);
|
---|
575 |
|
---|
576 | if (ret) {
|
---|
577 | return WERR_NOMEM;
|
---|
578 | }
|
---|
579 |
|
---|
580 | /* Ensure we reject compleate junk first */
|
---|
581 | ret = krb5_parse_name(smb_krb5_context->krb5_context, name, &principal);
|
---|
582 | if (ret) {
|
---|
583 | info1->status = DRSUAPI_DS_NAME_STATUS_NOT_FOUND;
|
---|
584 | return WERR_OK;
|
---|
585 | }
|
---|
586 |
|
---|
587 | domain_filter = NULL;
|
---|
588 |
|
---|
589 | /* By getting the unparsed name here, we ensure the escaping is correct (and trust the client less) */
|
---|
590 | ret = krb5_unparse_name(smb_krb5_context->krb5_context, principal, &unparsed_name);
|
---|
591 | if (ret) {
|
---|
592 | krb5_free_principal(smb_krb5_context->krb5_context, principal);
|
---|
593 | return WERR_NOMEM;
|
---|
594 | }
|
---|
595 |
|
---|
596 | krb5_free_principal(smb_krb5_context->krb5_context, principal);
|
---|
597 |
|
---|
598 | /* The ldb_binary_encode_string() here avoid LDAP filter injection attacks */
|
---|
599 | result_filter = talloc_asprintf(mem_ctx, "(&(objectClass=user)(userPrincipalName=%s))",
|
---|
600 | ldb_binary_encode_string(mem_ctx, unparsed_name));
|
---|
601 |
|
---|
602 | free(unparsed_name);
|
---|
603 | W_ERROR_HAVE_NO_MEMORY(result_filter);
|
---|
604 | break;
|
---|
605 | }
|
---|
606 | case DRSUAPI_DS_NAME_FORMAT_SERVICE_PRINCIPAL: {
|
---|
607 | krb5_principal principal;
|
---|
608 | char *unparsed_name_short;
|
---|
609 | char *service;
|
---|
610 |
|
---|
611 | ret = smb_krb5_init_context(mem_ctx,
|
---|
612 | ldb_get_event_context(sam_ctx),
|
---|
613 | (struct loadparm_context *)ldb_get_opaque(sam_ctx, "loadparm"),
|
---|
614 | &smb_krb5_context);
|
---|
615 |
|
---|
616 | if (ret) {
|
---|
617 | return WERR_NOMEM;
|
---|
618 | }
|
---|
619 |
|
---|
620 | ret = krb5_parse_name(smb_krb5_context->krb5_context, name, &principal);
|
---|
621 | if (ret == 0 && principal->name.name_string.len < 2) {
|
---|
622 | info1->status = DRSUAPI_DS_NAME_STATUS_NOT_FOUND;
|
---|
623 | krb5_free_principal(smb_krb5_context->krb5_context, principal);
|
---|
624 | return WERR_OK;
|
---|
625 | } else if (ret == 0) {
|
---|
626 | krb5_free_principal(smb_krb5_context->krb5_context, principal);
|
---|
627 | }
|
---|
628 | ret = krb5_parse_name_flags(smb_krb5_context->krb5_context, name,
|
---|
629 | KRB5_PRINCIPAL_PARSE_NO_REALM, &principal);
|
---|
630 | if (ret) {
|
---|
631 | return dns_domain_from_principal(mem_ctx, smb_krb5_context,
|
---|
632 | name, info1);
|
---|
633 | }
|
---|
634 |
|
---|
635 | domain_filter = NULL;
|
---|
636 |
|
---|
637 | ret = krb5_unparse_name_flags(smb_krb5_context->krb5_context, principal,
|
---|
638 | KRB5_PRINCIPAL_UNPARSE_NO_REALM, &unparsed_name_short);
|
---|
639 | if (ret) {
|
---|
640 | krb5_free_principal(smb_krb5_context->krb5_context, principal);
|
---|
641 | return WERR_NOMEM;
|
---|
642 | }
|
---|
643 |
|
---|
644 | service = principal->name.name_string.val[0];
|
---|
645 | if ((principal->name.name_string.len == 2) && (strcasecmp(service, "host") == 0)) {
|
---|
646 | /* the 'cn' attribute is just the leading part of the name */
|
---|
647 | char *computer_name;
|
---|
648 | computer_name = talloc_strndup(mem_ctx, principal->name.name_string.val[1],
|
---|
649 | strcspn(principal->name.name_string.val[1], "."));
|
---|
650 | if (computer_name == NULL) {
|
---|
651 | krb5_free_principal(smb_krb5_context->krb5_context, principal);
|
---|
652 | free(unparsed_name_short);
|
---|
653 | return WERR_NOMEM;
|
---|
654 | }
|
---|
655 |
|
---|
656 | result_filter = talloc_asprintf(mem_ctx, "(|(&(servicePrincipalName=%s)(objectClass=user))(&(cn=%s)(objectClass=computer)))",
|
---|
657 | ldb_binary_encode_string(mem_ctx, unparsed_name_short),
|
---|
658 | ldb_binary_encode_string(mem_ctx, computer_name));
|
---|
659 | } else {
|
---|
660 | result_filter = talloc_asprintf(mem_ctx, "(&(servicePrincipalName=%s)(objectClass=user))",
|
---|
661 | ldb_binary_encode_string(mem_ctx, unparsed_name_short));
|
---|
662 | }
|
---|
663 | krb5_free_principal(smb_krb5_context->krb5_context, principal);
|
---|
664 | free(unparsed_name_short);
|
---|
665 | W_ERROR_HAVE_NO_MEMORY(result_filter);
|
---|
666 |
|
---|
667 | break;
|
---|
668 | }
|
---|
669 | default: {
|
---|
670 | info1->status = DRSUAPI_DS_NAME_STATUS_NOT_FOUND;
|
---|
671 | return WERR_OK;
|
---|
672 | }
|
---|
673 | }
|
---|
674 |
|
---|
675 | if (format_flags & DRSUAPI_DS_NAME_FLAG_SYNTACTICAL_ONLY) {
|
---|
676 | return DsCrackNameOneSyntactical(mem_ctx, format_offered, format_desired,
|
---|
677 | name_dn, name, info1);
|
---|
678 | }
|
---|
679 |
|
---|
680 | return DsCrackNameOneFilter(sam_ctx, mem_ctx,
|
---|
681 | smb_krb5_context,
|
---|
682 | format_flags, format_offered, format_desired,
|
---|
683 | name_dn, name,
|
---|
684 | domain_filter, result_filter,
|
---|
685 | info1);
|
---|
686 | }
|
---|
687 |
|
---|
688 | /* Subcase of CrackNames. It is possible to translate a LDAP-style DN
|
---|
689 | * (FQDN_1779) into a canoical name without actually searching the
|
---|
690 | * database */
|
---|
691 |
|
---|
692 | static WERROR DsCrackNameOneSyntactical(TALLOC_CTX *mem_ctx,
|
---|
693 | enum drsuapi_DsNameFormat format_offered,
|
---|
694 | enum drsuapi_DsNameFormat format_desired,
|
---|
695 | struct ldb_dn *name_dn, const char *name,
|
---|
696 | struct drsuapi_DsNameInfo1 *info1)
|
---|
697 | {
|
---|
698 | char *cracked;
|
---|
699 | if (format_offered != DRSUAPI_DS_NAME_FORMAT_FQDN_1779) {
|
---|
700 | info1->status = DRSUAPI_DS_NAME_STATUS_NO_SYNTACTICAL_MAPPING;
|
---|
701 | return WERR_OK;
|
---|
702 | }
|
---|
703 |
|
---|
704 | switch (format_desired) {
|
---|
705 | case DRSUAPI_DS_NAME_FORMAT_CANONICAL:
|
---|
706 | cracked = ldb_dn_canonical_string(mem_ctx, name_dn);
|
---|
707 | break;
|
---|
708 | case DRSUAPI_DS_NAME_FORMAT_CANONICAL_EX:
|
---|
709 | cracked = ldb_dn_canonical_ex_string(mem_ctx, name_dn);
|
---|
710 | break;
|
---|
711 | default:
|
---|
712 | info1->status = DRSUAPI_DS_NAME_STATUS_NO_SYNTACTICAL_MAPPING;
|
---|
713 | return WERR_OK;
|
---|
714 | }
|
---|
715 | info1->status = DRSUAPI_DS_NAME_STATUS_OK;
|
---|
716 | info1->result_name = cracked;
|
---|
717 | if (!cracked) {
|
---|
718 | return WERR_NOMEM;
|
---|
719 | }
|
---|
720 |
|
---|
721 | return WERR_OK;
|
---|
722 | }
|
---|
723 |
|
---|
724 | /* Given a filter for the domain, and one for the result, perform the
|
---|
725 | * ldb search. The format offered and desired flags change the
|
---|
726 | * behaviours, including what attributes to return.
|
---|
727 | *
|
---|
728 | * The smb_krb5_context is required because we use the krb5 libs for principal parsing
|
---|
729 | */
|
---|
730 |
|
---|
731 | static WERROR DsCrackNameOneFilter(struct ldb_context *sam_ctx, TALLOC_CTX *mem_ctx,
|
---|
732 | struct smb_krb5_context *smb_krb5_context,
|
---|
733 | uint32_t format_flags, enum drsuapi_DsNameFormat format_offered,
|
---|
734 | enum drsuapi_DsNameFormat format_desired,
|
---|
735 | struct ldb_dn *name_dn, const char *name,
|
---|
736 | const char *domain_filter, const char *result_filter,
|
---|
737 | struct drsuapi_DsNameInfo1 *info1)
|
---|
738 | {
|
---|
739 | int ldb_ret;
|
---|
740 | struct ldb_result *domain_res = NULL;
|
---|
741 | const char * const *domain_attrs;
|
---|
742 | const char * const *result_attrs;
|
---|
743 | struct ldb_message **result_res = NULL;
|
---|
744 | struct ldb_message *result = NULL;
|
---|
745 | int i;
|
---|
746 | char *p;
|
---|
747 | struct ldb_dn *partitions_basedn = samdb_partitions_dn(sam_ctx, mem_ctx);
|
---|
748 |
|
---|
749 | const char * const _domain_attrs_1779[] = { "ncName", "dnsRoot", NULL};
|
---|
750 | const char * const _result_attrs_null[] = { NULL };
|
---|
751 |
|
---|
752 | const char * const _domain_attrs_canonical[] = { "ncName", "dnsRoot", NULL};
|
---|
753 | const char * const _result_attrs_canonical[] = { "canonicalName", NULL };
|
---|
754 |
|
---|
755 | const char * const _domain_attrs_nt4[] = { "ncName", "dnsRoot", "nETBIOSName", NULL};
|
---|
756 | const char * const _result_attrs_nt4[] = { "sAMAccountName", "objectSid", "objectClass", NULL};
|
---|
757 |
|
---|
758 | const char * const _domain_attrs_guid[] = { "ncName", "dnsRoot", NULL};
|
---|
759 | const char * const _result_attrs_guid[] = { "objectGUID", NULL};
|
---|
760 |
|
---|
761 | const char * const _domain_attrs_display[] = { "ncName", "dnsRoot", NULL};
|
---|
762 | const char * const _result_attrs_display[] = { "displayName", "samAccountName", NULL};
|
---|
763 |
|
---|
764 | const char * const _domain_attrs_none[] = { "ncName", "dnsRoot" , NULL};
|
---|
765 | const char * const _result_attrs_none[] = { NULL};
|
---|
766 |
|
---|
767 | /* here we need to set the attrs lists for domain and result lookups */
|
---|
768 | switch (format_desired) {
|
---|
769 | case DRSUAPI_DS_NAME_FORMAT_FQDN_1779:
|
---|
770 | case DRSUAPI_DS_NAME_FORMAT_CANONICAL_EX:
|
---|
771 | domain_attrs = _domain_attrs_1779;
|
---|
772 | result_attrs = _result_attrs_null;
|
---|
773 | break;
|
---|
774 | case DRSUAPI_DS_NAME_FORMAT_CANONICAL:
|
---|
775 | domain_attrs = _domain_attrs_canonical;
|
---|
776 | result_attrs = _result_attrs_canonical;
|
---|
777 | break;
|
---|
778 | case DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT:
|
---|
779 | domain_attrs = _domain_attrs_nt4;
|
---|
780 | result_attrs = _result_attrs_nt4;
|
---|
781 | break;
|
---|
782 | case DRSUAPI_DS_NAME_FORMAT_GUID:
|
---|
783 | domain_attrs = _domain_attrs_guid;
|
---|
784 | result_attrs = _result_attrs_guid;
|
---|
785 | break;
|
---|
786 | case DRSUAPI_DS_NAME_FORMAT_DISPLAY:
|
---|
787 | domain_attrs = _domain_attrs_display;
|
---|
788 | result_attrs = _result_attrs_display;
|
---|
789 | break;
|
---|
790 | default:
|
---|
791 | domain_attrs = _domain_attrs_none;
|
---|
792 | result_attrs = _result_attrs_none;
|
---|
793 | break;
|
---|
794 | }
|
---|
795 |
|
---|
796 | if (domain_filter) {
|
---|
797 | /* if we have a domain_filter look it up and set the result_basedn and the dns_domain_name */
|
---|
798 | ldb_ret = ldb_search(sam_ctx, mem_ctx, &domain_res,
|
---|
799 | partitions_basedn,
|
---|
800 | LDB_SCOPE_ONELEVEL,
|
---|
801 | domain_attrs,
|
---|
802 | "%s", domain_filter);
|
---|
803 |
|
---|
804 | if (ldb_ret != LDB_SUCCESS) {
|
---|
805 | DEBUG(2, ("DsCrackNameOneFilter domain ref search failed: %s", ldb_errstring(sam_ctx)));
|
---|
806 | info1->status = DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR;
|
---|
807 | return WERR_OK;
|
---|
808 | }
|
---|
809 |
|
---|
810 | switch (domain_res->count) {
|
---|
811 | case 1:
|
---|
812 | break;
|
---|
813 | case 0:
|
---|
814 | info1->status = DRSUAPI_DS_NAME_STATUS_NOT_FOUND;
|
---|
815 | return WERR_OK;
|
---|
816 | default:
|
---|
817 | info1->status = DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE;
|
---|
818 | return WERR_OK;
|
---|
819 | }
|
---|
820 |
|
---|
821 | info1->dns_domain_name = ldb_msg_find_attr_as_string(domain_res->msgs[0], "dnsRoot", NULL);
|
---|
822 | W_ERROR_HAVE_NO_MEMORY(info1->dns_domain_name);
|
---|
823 | info1->status = DRSUAPI_DS_NAME_STATUS_DOMAIN_ONLY;
|
---|
824 | } else {
|
---|
825 | info1->dns_domain_name = NULL;
|
---|
826 | info1->status = DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR;
|
---|
827 | }
|
---|
828 |
|
---|
829 | if (result_filter) {
|
---|
830 | int ret;
|
---|
831 | struct ldb_result *res;
|
---|
832 | uint32_t dsdb_flags = 0;
|
---|
833 | struct ldb_dn *search_dn;
|
---|
834 |
|
---|
835 | if (domain_res) {
|
---|
836 | dsdb_flags = 0;
|
---|
837 | search_dn = samdb_result_dn(sam_ctx, mem_ctx, domain_res->msgs[0], "ncName", NULL);
|
---|
838 | } else {
|
---|
839 | dsdb_flags = DSDB_SEARCH_SEARCH_ALL_PARTITIONS;
|
---|
840 | search_dn = ldb_get_root_basedn(sam_ctx);
|
---|
841 | }
|
---|
842 |
|
---|
843 | /* search with the 'phantom root' flag */
|
---|
844 | ret = dsdb_search(sam_ctx, mem_ctx, &res,
|
---|
845 | search_dn,
|
---|
846 | LDB_SCOPE_SUBTREE,
|
---|
847 | result_attrs,
|
---|
848 | DSDB_SEARCH_SEARCH_ALL_PARTITIONS,
|
---|
849 | "%s", result_filter);
|
---|
850 | if (ret != LDB_SUCCESS) {
|
---|
851 | DEBUG(2, ("DsCrackNameOneFilter phantom root search failed: %s",
|
---|
852 | ldb_errstring(sam_ctx)));
|
---|
853 | info1->status = DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR;
|
---|
854 | return WERR_OK;
|
---|
855 | }
|
---|
856 |
|
---|
857 | ldb_ret = res->count;
|
---|
858 | result_res = res->msgs;
|
---|
859 | } else if (format_offered == DRSUAPI_DS_NAME_FORMAT_FQDN_1779) {
|
---|
860 | ldb_ret = gendb_search_dn(sam_ctx, mem_ctx, name_dn, &result_res,
|
---|
861 | result_attrs);
|
---|
862 | } else if (domain_res) {
|
---|
863 | name_dn = samdb_result_dn(sam_ctx, mem_ctx, domain_res->msgs[0], "ncName", NULL);
|
---|
864 | ldb_ret = gendb_search_dn(sam_ctx, mem_ctx, name_dn, &result_res,
|
---|
865 | result_attrs);
|
---|
866 | } else {
|
---|
867 | /* Can't happen */
|
---|
868 | DEBUG(0, ("LOGIC ERROR: DsCrackNameOneFilter domain ref search not available: This can't happen..."));
|
---|
869 | info1->status = DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR;
|
---|
870 | return WERR_OK;
|
---|
871 | }
|
---|
872 |
|
---|
873 | switch (ldb_ret) {
|
---|
874 | case 1:
|
---|
875 | result = result_res[0];
|
---|
876 | break;
|
---|
877 | case 0:
|
---|
878 | switch (format_offered) {
|
---|
879 | case DRSUAPI_DS_NAME_FORMAT_SERVICE_PRINCIPAL:
|
---|
880 | return DsCrackNameSPNAlias(sam_ctx, mem_ctx,
|
---|
881 | smb_krb5_context,
|
---|
882 | format_flags, format_offered, format_desired,
|
---|
883 | name, info1);
|
---|
884 |
|
---|
885 | case DRSUAPI_DS_NAME_FORMAT_USER_PRINCIPAL:
|
---|
886 | return DsCrackNameUPN(sam_ctx, mem_ctx, smb_krb5_context,
|
---|
887 | format_flags, format_offered, format_desired,
|
---|
888 | name, info1);
|
---|
889 | default:
|
---|
890 | break;
|
---|
891 | }
|
---|
892 | info1->status = DRSUAPI_DS_NAME_STATUS_NOT_FOUND;
|
---|
893 | return WERR_OK;
|
---|
894 | case -1:
|
---|
895 | DEBUG(2, ("DsCrackNameOneFilter result search failed: %s", ldb_errstring(sam_ctx)));
|
---|
896 | info1->status = DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR;
|
---|
897 | return WERR_OK;
|
---|
898 | default:
|
---|
899 | switch (format_offered) {
|
---|
900 | case DRSUAPI_DS_NAME_FORMAT_CANONICAL:
|
---|
901 | case DRSUAPI_DS_NAME_FORMAT_CANONICAL_EX:
|
---|
902 | {
|
---|
903 | const char *canonical_name = NULL; /* Not required, but we get warnings... */
|
---|
904 | /* We may need to manually filter further */
|
---|
905 | for (i = 0; i < ldb_ret; i++) {
|
---|
906 | switch (format_offered) {
|
---|
907 | case DRSUAPI_DS_NAME_FORMAT_CANONICAL:
|
---|
908 | canonical_name = ldb_dn_canonical_string(mem_ctx, result_res[i]->dn);
|
---|
909 | break;
|
---|
910 | case DRSUAPI_DS_NAME_FORMAT_CANONICAL_EX:
|
---|
911 | canonical_name = ldb_dn_canonical_ex_string(mem_ctx, result_res[i]->dn);
|
---|
912 | break;
|
---|
913 | default:
|
---|
914 | break;
|
---|
915 | }
|
---|
916 | if (strcasecmp_m(canonical_name, name) == 0) {
|
---|
917 | result = result_res[i];
|
---|
918 | break;
|
---|
919 | }
|
---|
920 | }
|
---|
921 | if (!result) {
|
---|
922 | info1->status = DRSUAPI_DS_NAME_STATUS_NOT_FOUND;
|
---|
923 | return WERR_OK;
|
---|
924 | }
|
---|
925 | }
|
---|
926 | default:
|
---|
927 | info1->status = DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE;
|
---|
928 | return WERR_OK;
|
---|
929 | }
|
---|
930 | }
|
---|
931 |
|
---|
932 | info1->dns_domain_name = ldb_dn_canonical_string(mem_ctx, result->dn);
|
---|
933 | W_ERROR_HAVE_NO_MEMORY(info1->dns_domain_name);
|
---|
934 | p = strchr(info1->dns_domain_name, '/');
|
---|
935 | if (p) {
|
---|
936 | p[0] = '\0';
|
---|
937 | }
|
---|
938 |
|
---|
939 | /* here we can use result and domain_res[0] */
|
---|
940 | switch (format_desired) {
|
---|
941 | case DRSUAPI_DS_NAME_FORMAT_FQDN_1779: {
|
---|
942 | info1->result_name = ldb_dn_alloc_linearized(mem_ctx, result->dn);
|
---|
943 | W_ERROR_HAVE_NO_MEMORY(info1->result_name);
|
---|
944 |
|
---|
945 | info1->status = DRSUAPI_DS_NAME_STATUS_OK;
|
---|
946 | return WERR_OK;
|
---|
947 | }
|
---|
948 | case DRSUAPI_DS_NAME_FORMAT_CANONICAL: {
|
---|
949 | info1->result_name = ldb_msg_find_attr_as_string(result, "canonicalName", NULL);
|
---|
950 | info1->status = DRSUAPI_DS_NAME_STATUS_OK;
|
---|
951 | return WERR_OK;
|
---|
952 | }
|
---|
953 | case DRSUAPI_DS_NAME_FORMAT_CANONICAL_EX: {
|
---|
954 | /* Not in the virtual ldb attribute */
|
---|
955 | return DsCrackNameOneSyntactical(mem_ctx,
|
---|
956 | DRSUAPI_DS_NAME_FORMAT_FQDN_1779,
|
---|
957 | DRSUAPI_DS_NAME_FORMAT_CANONICAL_EX,
|
---|
958 | result->dn, name, info1);
|
---|
959 | }
|
---|
960 | case DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT: {
|
---|
961 |
|
---|
962 | const struct dom_sid *sid = samdb_result_dom_sid(mem_ctx, result, "objectSid");
|
---|
963 | const char *_acc = "", *_dom = "";
|
---|
964 |
|
---|
965 | if (samdb_find_attribute(sam_ctx, result, "objectClass", "domain")) {
|
---|
966 |
|
---|
967 | ldb_ret = ldb_search(sam_ctx, mem_ctx, &domain_res,
|
---|
968 | partitions_basedn,
|
---|
969 | LDB_SCOPE_ONELEVEL,
|
---|
970 | domain_attrs,
|
---|
971 | "(ncName=%s)", ldb_dn_get_linearized(result->dn));
|
---|
972 |
|
---|
973 | if (ldb_ret != LDB_SUCCESS) {
|
---|
974 | DEBUG(2, ("DsCrackNameOneFilter domain ref search failed: %s", ldb_errstring(sam_ctx)));
|
---|
975 | info1->status = DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR;
|
---|
976 | return WERR_OK;
|
---|
977 | }
|
---|
978 |
|
---|
979 | switch (domain_res->count) {
|
---|
980 | case 1:
|
---|
981 | break;
|
---|
982 | case 0:
|
---|
983 | info1->status = DRSUAPI_DS_NAME_STATUS_NOT_FOUND;
|
---|
984 | return WERR_OK;
|
---|
985 | default:
|
---|
986 | info1->status = DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE;
|
---|
987 | return WERR_OK;
|
---|
988 | }
|
---|
989 | _dom = ldb_msg_find_attr_as_string(domain_res->msgs[0], "nETBIOSName", NULL);
|
---|
990 | W_ERROR_HAVE_NO_MEMORY(_dom);
|
---|
991 | } else {
|
---|
992 | _acc = ldb_msg_find_attr_as_string(result, "sAMAccountName", NULL);
|
---|
993 | if (!_acc) {
|
---|
994 | info1->status = DRSUAPI_DS_NAME_STATUS_NO_MAPPING;
|
---|
995 | return WERR_OK;
|
---|
996 | }
|
---|
997 | if (dom_sid_in_domain(dom_sid_parse_talloc(mem_ctx, SID_BUILTIN), sid)) {
|
---|
998 | _dom = "BUILTIN";
|
---|
999 | } else {
|
---|
1000 | const char *attrs[] = { NULL };
|
---|
1001 | struct ldb_result *domain_res2;
|
---|
1002 | struct dom_sid *dom_sid = dom_sid_dup(mem_ctx, sid);
|
---|
1003 | if (!dom_sid) {
|
---|
1004 | return WERR_OK;
|
---|
1005 | }
|
---|
1006 | dom_sid->num_auths--;
|
---|
1007 | ldb_ret = ldb_search(sam_ctx, mem_ctx, &domain_res,
|
---|
1008 | NULL,
|
---|
1009 | LDB_SCOPE_BASE,
|
---|
1010 | attrs,
|
---|
1011 | "(&(objectSid=%s)(objectClass=domain))",
|
---|
1012 | ldap_encode_ndr_dom_sid(mem_ctx, dom_sid));
|
---|
1013 |
|
---|
1014 | if (ldb_ret != LDB_SUCCESS) {
|
---|
1015 | DEBUG(2, ("DsCrackNameOneFilter domain search failed: %s", ldb_errstring(sam_ctx)));
|
---|
1016 | info1->status = DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR;
|
---|
1017 | return WERR_OK;
|
---|
1018 | }
|
---|
1019 |
|
---|
1020 | switch (domain_res->count) {
|
---|
1021 | case 1:
|
---|
1022 | break;
|
---|
1023 | case 0:
|
---|
1024 | info1->status = DRSUAPI_DS_NAME_STATUS_NOT_FOUND;
|
---|
1025 | return WERR_OK;
|
---|
1026 | default:
|
---|
1027 | info1->status = DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE;
|
---|
1028 | return WERR_OK;
|
---|
1029 | }
|
---|
1030 |
|
---|
1031 | ldb_ret = ldb_search(sam_ctx, mem_ctx, &domain_res2,
|
---|
1032 | partitions_basedn,
|
---|
1033 | LDB_SCOPE_ONELEVEL,
|
---|
1034 | domain_attrs,
|
---|
1035 | "(ncName=%s)", ldb_dn_get_linearized(domain_res->msgs[0]->dn));
|
---|
1036 |
|
---|
1037 | if (ldb_ret != LDB_SUCCESS) {
|
---|
1038 | DEBUG(2, ("DsCrackNameOneFilter domain ref search failed: %s", ldb_errstring(sam_ctx)));
|
---|
1039 | info1->status = DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR;
|
---|
1040 | return WERR_OK;
|
---|
1041 | }
|
---|
1042 |
|
---|
1043 | switch (domain_res2->count) {
|
---|
1044 | case 1:
|
---|
1045 | break;
|
---|
1046 | case 0:
|
---|
1047 | info1->status = DRSUAPI_DS_NAME_STATUS_NOT_FOUND;
|
---|
1048 | return WERR_OK;
|
---|
1049 | default:
|
---|
1050 | info1->status = DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE;
|
---|
1051 | return WERR_OK;
|
---|
1052 | }
|
---|
1053 | _dom = ldb_msg_find_attr_as_string(domain_res2->msgs[0], "nETBIOSName", NULL);
|
---|
1054 | W_ERROR_HAVE_NO_MEMORY(_dom);
|
---|
1055 | }
|
---|
1056 | }
|
---|
1057 |
|
---|
1058 | info1->result_name = talloc_asprintf(mem_ctx, "%s\\%s", _dom, _acc);
|
---|
1059 | W_ERROR_HAVE_NO_MEMORY(info1->result_name);
|
---|
1060 |
|
---|
1061 | info1->status = DRSUAPI_DS_NAME_STATUS_OK;
|
---|
1062 | return WERR_OK;
|
---|
1063 | }
|
---|
1064 | case DRSUAPI_DS_NAME_FORMAT_GUID: {
|
---|
1065 | struct GUID guid;
|
---|
1066 |
|
---|
1067 | guid = samdb_result_guid(result, "objectGUID");
|
---|
1068 |
|
---|
1069 | info1->result_name = GUID_string2(mem_ctx, &guid);
|
---|
1070 | W_ERROR_HAVE_NO_MEMORY(info1->result_name);
|
---|
1071 |
|
---|
1072 | info1->status = DRSUAPI_DS_NAME_STATUS_OK;
|
---|
1073 | return WERR_OK;
|
---|
1074 | }
|
---|
1075 | case DRSUAPI_DS_NAME_FORMAT_DISPLAY: {
|
---|
1076 | info1->result_name = ldb_msg_find_attr_as_string(result, "displayName", NULL);
|
---|
1077 | if (!info1->result_name) {
|
---|
1078 | info1->result_name = ldb_msg_find_attr_as_string(result, "sAMAccountName", NULL);
|
---|
1079 | }
|
---|
1080 | if (!info1->result_name) {
|
---|
1081 | info1->status = DRSUAPI_DS_NAME_STATUS_NOT_FOUND;
|
---|
1082 | } else {
|
---|
1083 | info1->status = DRSUAPI_DS_NAME_STATUS_OK;
|
---|
1084 | }
|
---|
1085 | return WERR_OK;
|
---|
1086 | }
|
---|
1087 | case DRSUAPI_DS_NAME_FORMAT_SERVICE_PRINCIPAL: {
|
---|
1088 | info1->status = DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE;
|
---|
1089 | return WERR_OK;
|
---|
1090 | }
|
---|
1091 | case DRSUAPI_DS_NAME_FORMAT_DNS_DOMAIN:
|
---|
1092 | case DRSUAPI_DS_NAME_FORMAT_SID_OR_SID_HISTORY: {
|
---|
1093 | info1->status = DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR;
|
---|
1094 | return WERR_OK;
|
---|
1095 | }
|
---|
1096 | default:
|
---|
1097 | info1->status = DRSUAPI_DS_NAME_STATUS_NO_MAPPING;
|
---|
1098 | return WERR_OK;
|
---|
1099 | }
|
---|
1100 | }
|
---|
1101 |
|
---|
1102 | /* Given a user Principal Name (such as foo@bar.com),
|
---|
1103 | * return the user and domain DNs. This is used in the KDC to then
|
---|
1104 | * return the Keys and evaluate policy */
|
---|
1105 |
|
---|
1106 | NTSTATUS crack_user_principal_name(struct ldb_context *sam_ctx,
|
---|
1107 | TALLOC_CTX *mem_ctx,
|
---|
1108 | const char *user_principal_name,
|
---|
1109 | struct ldb_dn **user_dn,
|
---|
1110 | struct ldb_dn **domain_dn)
|
---|
1111 | {
|
---|
1112 | WERROR werr;
|
---|
1113 | struct drsuapi_DsNameInfo1 info1;
|
---|
1114 | werr = DsCrackNameOneName(sam_ctx, mem_ctx, 0,
|
---|
1115 | DRSUAPI_DS_NAME_FORMAT_USER_PRINCIPAL,
|
---|
1116 | DRSUAPI_DS_NAME_FORMAT_FQDN_1779,
|
---|
1117 | user_principal_name,
|
---|
1118 | &info1);
|
---|
1119 | if (!W_ERROR_IS_OK(werr)) {
|
---|
1120 | return werror_to_ntstatus(werr);
|
---|
1121 | }
|
---|
1122 | switch (info1.status) {
|
---|
1123 | case DRSUAPI_DS_NAME_STATUS_OK:
|
---|
1124 | break;
|
---|
1125 | case DRSUAPI_DS_NAME_STATUS_NOT_FOUND:
|
---|
1126 | case DRSUAPI_DS_NAME_STATUS_DOMAIN_ONLY:
|
---|
1127 | case DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE:
|
---|
1128 | return NT_STATUS_NO_SUCH_USER;
|
---|
1129 | case DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR:
|
---|
1130 | default:
|
---|
1131 | return NT_STATUS_UNSUCCESSFUL;
|
---|
1132 | }
|
---|
1133 |
|
---|
1134 | *user_dn = ldb_dn_new(mem_ctx, sam_ctx, info1.result_name);
|
---|
1135 |
|
---|
1136 | if (domain_dn) {
|
---|
1137 | werr = DsCrackNameOneName(sam_ctx, mem_ctx, 0,
|
---|
1138 | DRSUAPI_DS_NAME_FORMAT_CANONICAL,
|
---|
1139 | DRSUAPI_DS_NAME_FORMAT_FQDN_1779,
|
---|
1140 | talloc_asprintf(mem_ctx, "%s/",
|
---|
1141 | info1.dns_domain_name),
|
---|
1142 | &info1);
|
---|
1143 | if (!W_ERROR_IS_OK(werr)) {
|
---|
1144 | return werror_to_ntstatus(werr);
|
---|
1145 | }
|
---|
1146 | switch (info1.status) {
|
---|
1147 | case DRSUAPI_DS_NAME_STATUS_OK:
|
---|
1148 | break;
|
---|
1149 | case DRSUAPI_DS_NAME_STATUS_NOT_FOUND:
|
---|
1150 | case DRSUAPI_DS_NAME_STATUS_DOMAIN_ONLY:
|
---|
1151 | case DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE:
|
---|
1152 | return NT_STATUS_NO_SUCH_USER;
|
---|
1153 | case DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR:
|
---|
1154 | default:
|
---|
1155 | return NT_STATUS_UNSUCCESSFUL;
|
---|
1156 | }
|
---|
1157 |
|
---|
1158 | *domain_dn = ldb_dn_new(mem_ctx, sam_ctx, info1.result_name);
|
---|
1159 | }
|
---|
1160 |
|
---|
1161 | return NT_STATUS_OK;
|
---|
1162 | }
|
---|
1163 |
|
---|
1164 | /* Given a Service Principal Name (such as host/foo.bar.com@BAR.COM),
|
---|
1165 | * return the user and domain DNs. This is used in the KDC to then
|
---|
1166 | * return the Keys and evaluate policy */
|
---|
1167 |
|
---|
1168 | NTSTATUS crack_service_principal_name(struct ldb_context *sam_ctx,
|
---|
1169 | TALLOC_CTX *mem_ctx,
|
---|
1170 | const char *service_principal_name,
|
---|
1171 | struct ldb_dn **user_dn,
|
---|
1172 | struct ldb_dn **domain_dn)
|
---|
1173 | {
|
---|
1174 | WERROR werr;
|
---|
1175 | struct drsuapi_DsNameInfo1 info1;
|
---|
1176 | werr = DsCrackNameOneName(sam_ctx, mem_ctx, 0,
|
---|
1177 | DRSUAPI_DS_NAME_FORMAT_SERVICE_PRINCIPAL,
|
---|
1178 | DRSUAPI_DS_NAME_FORMAT_FQDN_1779,
|
---|
1179 | service_principal_name,
|
---|
1180 | &info1);
|
---|
1181 | if (!W_ERROR_IS_OK(werr)) {
|
---|
1182 | return werror_to_ntstatus(werr);
|
---|
1183 | }
|
---|
1184 | switch (info1.status) {
|
---|
1185 | case DRSUAPI_DS_NAME_STATUS_OK:
|
---|
1186 | break;
|
---|
1187 | case DRSUAPI_DS_NAME_STATUS_NOT_FOUND:
|
---|
1188 | case DRSUAPI_DS_NAME_STATUS_DOMAIN_ONLY:
|
---|
1189 | case DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE:
|
---|
1190 | return NT_STATUS_NO_SUCH_USER;
|
---|
1191 | case DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR:
|
---|
1192 | default:
|
---|
1193 | return NT_STATUS_UNSUCCESSFUL;
|
---|
1194 | }
|
---|
1195 |
|
---|
1196 | *user_dn = ldb_dn_new(mem_ctx, sam_ctx, info1.result_name);
|
---|
1197 |
|
---|
1198 | if (domain_dn) {
|
---|
1199 | werr = DsCrackNameOneName(sam_ctx, mem_ctx, 0,
|
---|
1200 | DRSUAPI_DS_NAME_FORMAT_CANONICAL,
|
---|
1201 | DRSUAPI_DS_NAME_FORMAT_FQDN_1779,
|
---|
1202 | talloc_asprintf(mem_ctx, "%s/",
|
---|
1203 | info1.dns_domain_name),
|
---|
1204 | &info1);
|
---|
1205 | if (!W_ERROR_IS_OK(werr)) {
|
---|
1206 | return werror_to_ntstatus(werr);
|
---|
1207 | }
|
---|
1208 | switch (info1.status) {
|
---|
1209 | case DRSUAPI_DS_NAME_STATUS_OK:
|
---|
1210 | break;
|
---|
1211 | case DRSUAPI_DS_NAME_STATUS_NOT_FOUND:
|
---|
1212 | case DRSUAPI_DS_NAME_STATUS_DOMAIN_ONLY:
|
---|
1213 | case DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE:
|
---|
1214 | return NT_STATUS_NO_SUCH_USER;
|
---|
1215 | case DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR:
|
---|
1216 | default:
|
---|
1217 | return NT_STATUS_UNSUCCESSFUL;
|
---|
1218 | }
|
---|
1219 |
|
---|
1220 | *domain_dn = ldb_dn_new(mem_ctx, sam_ctx, info1.result_name);
|
---|
1221 | }
|
---|
1222 |
|
---|
1223 | return NT_STATUS_OK;
|
---|
1224 | }
|
---|
1225 |
|
---|
1226 | NTSTATUS crack_name_to_nt4_name(TALLOC_CTX *mem_ctx,
|
---|
1227 | struct tevent_context *ev_ctx,
|
---|
1228 | struct loadparm_context *lp_ctx,
|
---|
1229 | enum drsuapi_DsNameFormat format_offered,
|
---|
1230 | const char *name,
|
---|
1231 | const char **nt4_domain, const char **nt4_account)
|
---|
1232 | {
|
---|
1233 | WERROR werr;
|
---|
1234 | struct drsuapi_DsNameInfo1 info1;
|
---|
1235 | struct ldb_context *ldb;
|
---|
1236 | char *p;
|
---|
1237 |
|
---|
1238 | /* Handle anonymous bind */
|
---|
1239 | if (!name || !*name) {
|
---|
1240 | *nt4_domain = "";
|
---|
1241 | *nt4_account = "";
|
---|
1242 | return NT_STATUS_OK;
|
---|
1243 | }
|
---|
1244 |
|
---|
1245 | ldb = samdb_connect(mem_ctx, ev_ctx, lp_ctx, system_session(lp_ctx), 0);
|
---|
1246 | if (ldb == NULL) {
|
---|
1247 | return NT_STATUS_INTERNAL_DB_CORRUPTION;
|
---|
1248 | }
|
---|
1249 |
|
---|
1250 | werr = DsCrackNameOneName(ldb, mem_ctx, 0,
|
---|
1251 | format_offered,
|
---|
1252 | DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT,
|
---|
1253 | name,
|
---|
1254 | &info1);
|
---|
1255 | if (!W_ERROR_IS_OK(werr)) {
|
---|
1256 | return werror_to_ntstatus(werr);
|
---|
1257 | }
|
---|
1258 | switch (info1.status) {
|
---|
1259 | case DRSUAPI_DS_NAME_STATUS_OK:
|
---|
1260 | break;
|
---|
1261 | case DRSUAPI_DS_NAME_STATUS_NOT_FOUND:
|
---|
1262 | case DRSUAPI_DS_NAME_STATUS_DOMAIN_ONLY:
|
---|
1263 | case DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE:
|
---|
1264 | return NT_STATUS_NO_SUCH_USER;
|
---|
1265 | case DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR:
|
---|
1266 | default:
|
---|
1267 | return NT_STATUS_UNSUCCESSFUL;
|
---|
1268 | }
|
---|
1269 |
|
---|
1270 | *nt4_domain = talloc_strdup(mem_ctx, info1.result_name);
|
---|
1271 | if (*nt4_domain == NULL) {
|
---|
1272 | return NT_STATUS_NO_MEMORY;
|
---|
1273 | }
|
---|
1274 |
|
---|
1275 | p = strchr(*nt4_domain, '\\');
|
---|
1276 | if (!p) {
|
---|
1277 | return NT_STATUS_INVALID_PARAMETER;
|
---|
1278 | }
|
---|
1279 | p[0] = '\0';
|
---|
1280 |
|
---|
1281 | *nt4_account = talloc_strdup(mem_ctx, &p[1]);
|
---|
1282 | if (*nt4_account == NULL) {
|
---|
1283 | return NT_STATUS_NO_MEMORY;
|
---|
1284 | }
|
---|
1285 |
|
---|
1286 | return NT_STATUS_OK;
|
---|
1287 | }
|
---|
1288 |
|
---|
1289 | NTSTATUS crack_auto_name_to_nt4_name(TALLOC_CTX *mem_ctx,
|
---|
1290 | struct tevent_context *ev_ctx,
|
---|
1291 | struct loadparm_context *lp_ctx,
|
---|
1292 | const char *name,
|
---|
1293 | const char **nt4_domain,
|
---|
1294 | const char **nt4_account)
|
---|
1295 | {
|
---|
1296 | enum drsuapi_DsNameFormat format_offered = DRSUAPI_DS_NAME_FORMAT_UNKNOWN;
|
---|
1297 |
|
---|
1298 | /* Handle anonymous bind */
|
---|
1299 | if (!name || !*name) {
|
---|
1300 | *nt4_domain = "";
|
---|
1301 | *nt4_account = "";
|
---|
1302 | return NT_STATUS_OK;
|
---|
1303 | }
|
---|
1304 |
|
---|
1305 | if (strchr_m(name, '=')) {
|
---|
1306 | format_offered = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
|
---|
1307 | } else if (strchr_m(name, '@')) {
|
---|
1308 | format_offered = DRSUAPI_DS_NAME_FORMAT_USER_PRINCIPAL;
|
---|
1309 | } else if (strchr_m(name, '\\')) {
|
---|
1310 | format_offered = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
|
---|
1311 | } else if (strchr_m(name, '/')) {
|
---|
1312 | format_offered = DRSUAPI_DS_NAME_FORMAT_CANONICAL;
|
---|
1313 | } else {
|
---|
1314 | return NT_STATUS_NO_SUCH_USER;
|
---|
1315 | }
|
---|
1316 |
|
---|
1317 | return crack_name_to_nt4_name(mem_ctx, ev_ctx, lp_ctx, format_offered, name, nt4_domain, nt4_account);
|
---|
1318 | }
|
---|
1319 |
|
---|
1320 |
|
---|
1321 | WERROR dcesrv_drsuapi_ListRoles(struct ldb_context *sam_ctx, TALLOC_CTX *mem_ctx,
|
---|
1322 | const struct drsuapi_DsNameRequest1 *req1,
|
---|
1323 | struct drsuapi_DsNameCtr1 **ctr1)
|
---|
1324 | {
|
---|
1325 | struct drsuapi_DsNameInfo1 *names;
|
---|
1326 | uint32_t i;
|
---|
1327 | uint32_t count = 5;/*number of fsmo role owners we are going to return*/
|
---|
1328 |
|
---|
1329 | *ctr1 = talloc(mem_ctx, struct drsuapi_DsNameCtr1);
|
---|
1330 | W_ERROR_HAVE_NO_MEMORY(*ctr1);
|
---|
1331 | names = talloc_array(mem_ctx, struct drsuapi_DsNameInfo1, count);
|
---|
1332 | W_ERROR_HAVE_NO_MEMORY(names);
|
---|
1333 |
|
---|
1334 | for (i = 0; i < count; i++) {
|
---|
1335 | WERROR werr;
|
---|
1336 | struct ldb_dn *role_owner_dn, *fsmo_role_dn, *server_dn;
|
---|
1337 | werr = dsdb_get_fsmo_role_info(mem_ctx, sam_ctx, i,
|
---|
1338 | &fsmo_role_dn, &role_owner_dn);
|
---|
1339 | if(!W_ERROR_IS_OK(werr)) {
|
---|
1340 | return werr;
|
---|
1341 | }
|
---|
1342 | server_dn = ldb_dn_copy(mem_ctx, role_owner_dn);
|
---|
1343 | ldb_dn_remove_child_components(server_dn, 1);
|
---|
1344 | names[i].status = DRSUAPI_DS_NAME_STATUS_OK;
|
---|
1345 | names[i].dns_domain_name = samdb_dn_to_dnshostname(sam_ctx, mem_ctx,
|
---|
1346 | server_dn);
|
---|
1347 | if(!names[i].dns_domain_name) {
|
---|
1348 | DEBUG(4, ("list_roles: Failed to find dNSHostName for server %s",
|
---|
1349 | ldb_dn_get_linearized(server_dn)));
|
---|
1350 | }
|
---|
1351 | names[i].result_name = talloc_strdup(mem_ctx, ldb_dn_get_linearized(role_owner_dn));
|
---|
1352 | }
|
---|
1353 |
|
---|
1354 | (*ctr1)->count = count;
|
---|
1355 | (*ctr1)->array = names;
|
---|
1356 |
|
---|
1357 | return WERR_OK;
|
---|
1358 | }
|
---|
1359 |
|
---|
1360 | WERROR dcesrv_drsuapi_CrackNamesByNameFormat(struct ldb_context *sam_ctx, TALLOC_CTX *mem_ctx,
|
---|
1361 | const struct drsuapi_DsNameRequest1 *req1,
|
---|
1362 | struct drsuapi_DsNameCtr1 **ctr1)
|
---|
1363 | {
|
---|
1364 | struct drsuapi_DsNameInfo1 *names;
|
---|
1365 | uint32_t i, count;
|
---|
1366 | WERROR status;
|
---|
1367 |
|
---|
1368 | *ctr1 = talloc(mem_ctx, struct drsuapi_DsNameCtr1);
|
---|
1369 | W_ERROR_HAVE_NO_MEMORY(*ctr1);
|
---|
1370 |
|
---|
1371 | count = req1->count;
|
---|
1372 | names = talloc_array(mem_ctx, struct drsuapi_DsNameInfo1, count);
|
---|
1373 | W_ERROR_HAVE_NO_MEMORY(names);
|
---|
1374 |
|
---|
1375 | for (i=0; i < count; i++) {
|
---|
1376 | status = DsCrackNameOneName(sam_ctx, mem_ctx,
|
---|
1377 | req1->format_flags,
|
---|
1378 | req1->format_offered,
|
---|
1379 | req1->format_desired,
|
---|
1380 | req1->names[i].str,
|
---|
1381 | &names[i]);
|
---|
1382 | if (!W_ERROR_IS_OK(status)) {
|
---|
1383 | return status;
|
---|
1384 | }
|
---|
1385 | }
|
---|
1386 |
|
---|
1387 | (*ctr1)->count = count;
|
---|
1388 | (*ctr1)->array = names;
|
---|
1389 |
|
---|
1390 | return WERR_OK;
|
---|
1391 | }
|
---|