2 Unix SMB/CIFS implementation.
4 endpoint server for the drsuapi pipe
7 Copyright (C) Stefan Metzmacher 2004
8 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2004-2005
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.
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.
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/>.
25 #include "librpc/gen_ndr/drsuapi.h"
26 #include "lib/events/events.h"
27 #include "rpc_server/common/common.h"
28 #include "lib/ldb/include/ldb.h"
29 #include "lib/ldb/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"
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
, uint32_t format_offered
, uint32_t format_desired
,
43 struct ldb_dn
*name_dn
, const char *name
,
44 const char *domain_filter
, const char *result_filter
,
45 struct drsuapi_DsNameInfo1
*info1
);
46 static WERROR
DsCrackNameOneSyntactical(TALLOC_CTX
*mem_ctx
,
47 uint32_t format_offered
, uint32_t format_desired
,
48 struct ldb_dn
*name_dn
, const char *name
,
49 struct drsuapi_DsNameInfo1
*info1
);
51 static WERROR
dns_domain_from_principal(TALLOC_CTX
*mem_ctx
, struct smb_krb5_context
*smb_krb5_context
,
53 struct drsuapi_DsNameInfo1
*info1
)
56 krb5_principal principal
;
57 /* perhaps it's a principal with a realm, so return the right 'domain only' response */
59 ret
= krb5_parse_name_flags(smb_krb5_context
->krb5_context
, name
,
60 KRB5_PRINCIPAL_PARSE_REQUIRE_REALM
, &principal
);
62 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
66 /* This isn't an allocation assignemnt, so it is free'ed with the krb5_free_principal */
67 realm
= krb5_principal_get_realm(smb_krb5_context
->krb5_context
, principal
);
69 info1
->dns_domain_name
= talloc_strdup(mem_ctx
, realm
);
70 krb5_free_principal(smb_krb5_context
->krb5_context
, principal
);
72 W_ERROR_HAVE_NO_MEMORY(info1
->dns_domain_name
);
74 info1
->status
= DRSUAPI_DS_NAME_STATUS_DOMAIN_ONLY
;
78 static enum drsuapi_DsNameStatus
LDB_lookup_spn_alias(krb5_context context
, struct ldb_context
*ldb_ctx
,
80 const char *alias_from
,
85 struct ldb_result
*res
;
86 struct ldb_message_element
*spnmappings
;
88 struct ldb_dn
*service_dn
;
91 const char *directory_attrs
[] = {
96 tmp_ctx
= talloc_new(mem_ctx
);
98 return DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
101 service_dn
= ldb_dn_new(tmp_ctx
, ldb_ctx
, "CN=Directory Service,CN=Windows NT,CN=Services");
102 if ( ! ldb_dn_add_base(service_dn
, samdb_config_dn(ldb_ctx
))) {
103 return DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
105 service_dn_str
= ldb_dn_alloc_linearized(tmp_ctx
, service_dn
);
106 if ( ! service_dn_str
) {
107 return DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
110 ret
= ldb_search(ldb_ctx
, tmp_ctx
, &res
, service_dn
, LDB_SCOPE_BASE
,
111 directory_attrs
, "(objectClass=nTDSService)");
113 if (ret
!= LDB_SUCCESS
&& ret
!= LDB_ERR_NO_SUCH_OBJECT
) {
114 DEBUG(1, ("ldb_search: dn: %s not found: %s", service_dn_str
, ldb_errstring(ldb_ctx
)));
115 return DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
116 } else if (ret
== LDB_ERR_NO_SUCH_OBJECT
) {
117 DEBUG(1, ("ldb_search: dn: %s not found", service_dn_str
));
118 return DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
119 } else if (res
->count
!= 1) {
121 DEBUG(1, ("ldb_search: dn: %s not found", service_dn_str
));
122 return DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
125 spnmappings
= ldb_msg_find_element(res
->msgs
[0], "sPNMappings");
126 if (!spnmappings
|| spnmappings
->num_values
== 0) {
127 DEBUG(1, ("ldb_search: dn: %s no sPNMappings attribute", service_dn_str
));
128 talloc_free(tmp_ctx
);
129 return DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
132 for (i
= 0; i
< spnmappings
->num_values
; i
++) {
133 char *mapping
, *p
, *str
;
134 mapping
= talloc_strdup(tmp_ctx
,
135 (const char *)spnmappings
->values
[i
].data
);
137 DEBUG(1, ("LDB_lookup_spn_alias: ldb_search: dn: %s did not have an sPNMapping\n", service_dn_str
));
138 talloc_free(tmp_ctx
);
139 return DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
142 /* C string manipulation sucks */
144 p
= strchr(mapping
, '=');
146 DEBUG(1, ("ldb_search: dn: %s sPNMapping malformed: %s\n",
147 service_dn_str
, mapping
));
148 talloc_free(tmp_ctx
);
149 return DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
160 if (strcasecmp(str
, alias_from
) == 0) {
162 talloc_steal(mem_ctx
, mapping
);
163 talloc_free(tmp_ctx
);
164 return DRSUAPI_DS_NAME_STATUS_OK
;
168 DEBUG(4, ("LDB_lookup_spn_alias: no alias for service %s applicable\n", alias_from
));
169 talloc_free(tmp_ctx
);
170 return DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
173 /* When cracking a ServicePrincipalName, many services may be served
174 * by the host/ servicePrincipalName. The incoming query is for cifs/
175 * but we translate it here, and search on host/. This is done after
176 * the cifs/ entry has been searched for, making this a fallback */
178 static WERROR
DsCrackNameSPNAlias(struct ldb_context
*sam_ctx
, TALLOC_CTX
*mem_ctx
,
179 struct smb_krb5_context
*smb_krb5_context
,
180 uint32_t format_flags
, uint32_t format_offered
, uint32_t format_desired
,
181 const char *name
, struct drsuapi_DsNameInfo1
*info1
)
185 krb5_principal principal
;
186 const char *service
, *dns_name
;
189 enum drsuapi_DsNameStatus namestatus
;
191 /* parse principal */
192 ret
= krb5_parse_name_flags(smb_krb5_context
->krb5_context
,
193 name
, KRB5_PRINCIPAL_PARSE_NO_REALM
, &principal
);
195 DEBUG(2, ("Could not parse principal: %s: %s",
196 name
, smb_get_krb5_error_message(smb_krb5_context
->krb5_context
,
201 /* grab cifs/, http/ etc */
203 /* This is checked for in callers, but be safe */
204 if (principal
->name
.name_string
.len
< 2) {
205 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
208 service
= principal
->name
.name_string
.val
[0];
209 dns_name
= principal
->name
.name_string
.val
[1];
212 namestatus
= LDB_lookup_spn_alias(smb_krb5_context
->krb5_context
,
214 service
, &new_service
);
216 if (namestatus
== DRSUAPI_DS_NAME_STATUS_NOT_FOUND
) {
217 info1
->status
= DRSUAPI_DS_NAME_STATUS_DOMAIN_ONLY
;
218 info1
->dns_domain_name
= talloc_strdup(mem_ctx
, dns_name
);
219 if (!info1
->dns_domain_name
) {
220 krb5_free_principal(smb_krb5_context
->krb5_context
, principal
);
224 } else if (namestatus
!= DRSUAPI_DS_NAME_STATUS_OK
) {
225 info1
->status
= namestatus
;
226 krb5_free_principal(smb_krb5_context
->krb5_context
, principal
);
230 /* ooh, very nasty playing around in the Principal... */
231 free(principal
->name
.name_string
.val
[0]);
232 principal
->name
.name_string
.val
[0] = strdup(new_service
);
233 if (!principal
->name
.name_string
.val
[0]) {
234 krb5_free_principal(smb_krb5_context
->krb5_context
, principal
);
238 /* reform principal */
239 ret
= krb5_unparse_name_flags(smb_krb5_context
->krb5_context
, principal
,
240 KRB5_PRINCIPAL_UNPARSE_NO_REALM
, &new_princ
);
243 krb5_free_principal(smb_krb5_context
->krb5_context
, principal
);
247 wret
= DsCrackNameOneName(sam_ctx
, mem_ctx
, format_flags
, format_offered
, format_desired
,
250 if (W_ERROR_IS_OK(wret
) && (info1
->status
== DRSUAPI_DS_NAME_STATUS_NOT_FOUND
)) {
251 info1
->status
= DRSUAPI_DS_NAME_STATUS_DOMAIN_ONLY
;
252 info1
->dns_domain_name
= talloc_strdup(mem_ctx
, dns_name
);
253 if (!info1
->dns_domain_name
) {
257 krb5_free_principal(smb_krb5_context
->krb5_context
, principal
);
261 /* Subcase of CrackNames, for the userPrincipalName */
263 static WERROR
DsCrackNameUPN(struct ldb_context
*sam_ctx
, TALLOC_CTX
*mem_ctx
,
264 struct smb_krb5_context
*smb_krb5_context
,
265 uint32_t format_flags
, uint32_t format_offered
, uint32_t format_desired
,
266 const char *name
, struct drsuapi_DsNameInfo1
*info1
)
270 const char *domain_filter
= NULL
;
271 const char *result_filter
= NULL
;
273 krb5_principal principal
;
275 char *unparsed_name_short
;
276 const char *domain_attrs
[] = { NULL
};
277 struct ldb_result
*domain_res
= NULL
;
279 /* Prevent recursion */
281 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
285 ret
= krb5_parse_name_flags(smb_krb5_context
->krb5_context
, name
,
286 KRB5_PRINCIPAL_PARSE_REQUIRE_REALM
, &principal
);
288 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
292 realm
= krb5_principal_get_realm(smb_krb5_context
->krb5_context
, principal
);
294 ldb_ret
= ldb_search(sam_ctx
, mem_ctx
, &domain_res
,
295 samdb_partitions_dn(sam_ctx
, mem_ctx
),
298 "(&(&(|(&(dnsRoot=%s)(nETBIOSName=*))(nETBIOSName=%s))(objectclass=crossRef))(ncName=*))",
299 ldb_binary_encode_string(mem_ctx
, realm
),
300 ldb_binary_encode_string(mem_ctx
, realm
));
302 if (ldb_ret
!= LDB_SUCCESS
) {
303 DEBUG(2, ("DsCrackNameUPN domain ref search failed: %s", ldb_errstring(sam_ctx
)));
304 info1
->status
= DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
308 switch (domain_res
->count
) {
312 return dns_domain_from_principal(mem_ctx
, smb_krb5_context
,
315 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE
;
319 ret
= krb5_unparse_name_flags(smb_krb5_context
->krb5_context
, principal
,
320 KRB5_PRINCIPAL_UNPARSE_NO_REALM
, &unparsed_name_short
);
321 krb5_free_principal(smb_krb5_context
->krb5_context
, principal
);
324 free(unparsed_name_short
);
328 /* This may need to be extended for more userPrincipalName variations */
329 result_filter
= talloc_asprintf(mem_ctx
, "(&(objectClass=user)(samAccountName=%s))",
330 ldb_binary_encode_string(mem_ctx
, unparsed_name_short
));
332 domain_filter
= talloc_asprintf(mem_ctx
, "(distinguishedName=%s)", ldb_dn_get_linearized(domain_res
->msgs
[0]->dn
));
334 if (!result_filter
|| !domain_filter
) {
335 free(unparsed_name_short
);
338 status
= DsCrackNameOneFilter(sam_ctx
, mem_ctx
,
340 format_flags
, format_offered
, format_desired
,
341 NULL
, unparsed_name_short
, domain_filter
, result_filter
,
343 free(unparsed_name_short
);
348 /* Crack a single 'name', from format_offered into format_desired, returning the result in info1 */
350 WERROR
DsCrackNameOneName(struct ldb_context
*sam_ctx
, TALLOC_CTX
*mem_ctx
,
351 uint32_t format_flags
, uint32_t format_offered
, uint32_t format_desired
,
352 const char *name
, struct drsuapi_DsNameInfo1
*info1
)
355 const char *domain_filter
= NULL
;
356 const char *result_filter
= NULL
;
357 struct ldb_dn
*name_dn
= NULL
;
359 struct smb_krb5_context
*smb_krb5_context
= NULL
;
361 info1
->status
= DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
362 info1
->dns_domain_name
= NULL
;
363 info1
->result_name
= NULL
;
366 return WERR_INVALID_PARAM
;
369 /* TODO: - fill the correct names in all cases!
370 * - handle format_flags
373 /* here we need to set the domain_filter and/or the result_filter */
374 switch (format_offered
) {
375 case DRSUAPI_DS_NAME_FORMAT_UNKNOWN
:
378 enum drsuapi_DsNameFormat formats
[] = {
379 DRSUAPI_DS_NAME_FORMAT_FQDN_1779
, DRSUAPI_DS_NAME_FORMAT_USER_PRINCIPAL
,
380 DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT
, DRSUAPI_DS_NAME_FORMAT_CANONICAL
,
381 DRSUAPI_DS_NAME_FORMAT_GUID
, DRSUAPI_DS_NAME_FORMAT_DISPLAY
,
382 DRSUAPI_DS_NAME_FORMAT_SERVICE_PRINCIPAL
,
383 DRSUAPI_DS_NAME_FORMAT_SID_OR_SID_HISTORY
,
384 DRSUAPI_DS_NAME_FORMAT_CANONICAL_EX
387 for (i
=0; i
< ARRAY_SIZE(formats
); i
++) {
388 werr
= DsCrackNameOneName(sam_ctx
, mem_ctx
, format_flags
, formats
[i
], format_desired
, name
, info1
);
389 if (!W_ERROR_IS_OK(werr
)) {
392 if (info1
->status
!= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
) {
399 case DRSUAPI_DS_NAME_FORMAT_CANONICAL
:
400 case DRSUAPI_DS_NAME_FORMAT_CANONICAL_EX
:
402 char *str
, *s
, *account
;
404 if (strlen(name
) == 0) {
405 info1
->status
= DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
409 str
= talloc_strdup(mem_ctx
, name
);
410 W_ERROR_HAVE_NO_MEMORY(str
);
412 if (format_offered
== DRSUAPI_DS_NAME_FORMAT_CANONICAL_EX
) {
413 /* Look backwards for the \n, and replace it with / */
414 s
= strrchr(str
, '\n');
416 info1
->status
= DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
422 s
= strchr(str
, '/');
424 /* there must be at least one / */
425 info1
->status
= DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
432 domain_filter
= talloc_asprintf(mem_ctx
, "(&(objectClass=crossRef)(ncName=%s))",
433 ldb_dn_get_linearized(samdb_dns_domain_to_dn(sam_ctx
, mem_ctx
, str
)));
434 W_ERROR_HAVE_NO_MEMORY(domain_filter
);
436 /* There may not be anything after the domain component (search for the domain itself) */
439 account
= strrchr(s
, '/');
445 account
= ldb_binary_encode_string(mem_ctx
, account
);
446 W_ERROR_HAVE_NO_MEMORY(account
);
447 result_filter
= talloc_asprintf(mem_ctx
, "(name=%s)",
449 W_ERROR_HAVE_NO_MEMORY(result_filter
);
453 case DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT
: {
456 const char *account
= NULL
;
458 domain
= talloc_strdup(mem_ctx
, name
);
459 W_ERROR_HAVE_NO_MEMORY(domain
);
461 p
= strchr(domain
, '\\');
463 /* invalid input format */
464 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
473 domain_filter
= talloc_asprintf(mem_ctx
,
474 "(&(&(nETBIOSName=%s)(objectclass=crossRef))(ncName=*))",
475 ldb_binary_encode_string(mem_ctx
, domain
));
476 W_ERROR_HAVE_NO_MEMORY(domain_filter
);
478 result_filter
= talloc_asprintf(mem_ctx
, "(sAMAccountName=%s)",
479 ldb_binary_encode_string(mem_ctx
, account
));
480 W_ERROR_HAVE_NO_MEMORY(result_filter
);
487 /* A LDAP DN as a string */
488 case DRSUAPI_DS_NAME_FORMAT_FQDN_1779
: {
489 domain_filter
= NULL
;
490 name_dn
= ldb_dn_new(mem_ctx
, sam_ctx
, name
);
491 if (! ldb_dn_validate(name_dn
)) {
492 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
498 /* A GUID as a string */
499 case DRSUAPI_DS_NAME_FORMAT_GUID
: {
503 domain_filter
= NULL
;
505 nt_status
= GUID_from_string(name
, &guid
);
506 if (!NT_STATUS_IS_OK(nt_status
)) {
507 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
511 ldap_guid
= ldap_encode_ndr_GUID(mem_ctx
, &guid
);
515 result_filter
= talloc_asprintf(mem_ctx
, "(objectGUID=%s)",
517 W_ERROR_HAVE_NO_MEMORY(result_filter
);
520 case DRSUAPI_DS_NAME_FORMAT_DISPLAY
: {
521 domain_filter
= NULL
;
523 result_filter
= talloc_asprintf(mem_ctx
, "(|(displayName=%s)(samAccountName=%s))",
524 ldb_binary_encode_string(mem_ctx
, name
),
525 ldb_binary_encode_string(mem_ctx
, name
));
526 W_ERROR_HAVE_NO_MEMORY(result_filter
);
530 /* A S-1234-5678 style string */
531 case DRSUAPI_DS_NAME_FORMAT_SID_OR_SID_HISTORY
: {
532 struct dom_sid
*sid
= dom_sid_parse_talloc(mem_ctx
, name
);
535 domain_filter
= NULL
;
537 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
540 ldap_sid
= ldap_encode_ndr_dom_sid(mem_ctx
,
545 result_filter
= talloc_asprintf(mem_ctx
, "(objectSid=%s)",
547 W_ERROR_HAVE_NO_MEMORY(result_filter
);
550 case DRSUAPI_DS_NAME_FORMAT_USER_PRINCIPAL
: {
551 krb5_principal principal
;
554 ret
= smb_krb5_init_context(mem_ctx
,
555 ldb_get_event_context(sam_ctx
),
556 (struct loadparm_context
*)ldb_get_opaque(sam_ctx
, "loadparm"),
563 /* Ensure we reject compleate junk first */
564 ret
= krb5_parse_name(smb_krb5_context
->krb5_context
, name
, &principal
);
566 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
570 domain_filter
= NULL
;
572 /* By getting the unparsed name here, we ensure the escaping is correct (and trust the client less) */
573 ret
= krb5_unparse_name(smb_krb5_context
->krb5_context
, principal
, &unparsed_name
);
575 krb5_free_principal(smb_krb5_context
->krb5_context
, principal
);
579 krb5_free_principal(smb_krb5_context
->krb5_context
, principal
);
581 /* The ldb_binary_encode_string() here avoid LDAP filter injection attacks */
582 result_filter
= talloc_asprintf(mem_ctx
, "(&(objectClass=user)(userPrincipalName=%s))",
583 ldb_binary_encode_string(mem_ctx
, unparsed_name
));
586 W_ERROR_HAVE_NO_MEMORY(result_filter
);
589 case DRSUAPI_DS_NAME_FORMAT_SERVICE_PRINCIPAL
: {
590 krb5_principal principal
;
591 char *unparsed_name_short
;
594 ret
= smb_krb5_init_context(mem_ctx
,
595 ldb_get_event_context(sam_ctx
),
596 (struct loadparm_context
*)ldb_get_opaque(sam_ctx
, "loadparm"),
603 ret
= krb5_parse_name(smb_krb5_context
->krb5_context
, name
, &principal
);
604 if (ret
== 0 && principal
->name
.name_string
.len
< 2) {
605 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
606 krb5_free_principal(smb_krb5_context
->krb5_context
, principal
);
609 ret
= krb5_parse_name_flags(smb_krb5_context
->krb5_context
, name
,
610 KRB5_PRINCIPAL_PARSE_NO_REALM
, &principal
);
612 krb5_free_principal(smb_krb5_context
->krb5_context
, principal
);
614 return dns_domain_from_principal(mem_ctx
, smb_krb5_context
,
618 domain_filter
= NULL
;
620 ret
= krb5_unparse_name_flags(smb_krb5_context
->krb5_context
, principal
,
621 KRB5_PRINCIPAL_UNPARSE_NO_REALM
, &unparsed_name_short
);
623 krb5_free_principal(smb_krb5_context
->krb5_context
, principal
);
627 service
= principal
->name
.name_string
.val
[0];
628 if ((principal
->name
.name_string
.len
== 2) && (strcasecmp(service
, "host") == 0)) {
629 /* the 'cn' attribute is just the leading part of the name */
631 computer_name
= talloc_strndup(mem_ctx
, principal
->name
.name_string
.val
[1],
632 strcspn(principal
->name
.name_string
.val
[1], "."));
633 if (computer_name
== NULL
) {
637 result_filter
= talloc_asprintf(mem_ctx
, "(|(&(servicePrincipalName=%s)(objectClass=user))(&(cn=%s)(objectClass=computer)))",
638 ldb_binary_encode_string(mem_ctx
, unparsed_name_short
),
639 ldb_binary_encode_string(mem_ctx
, computer_name
));
641 result_filter
= talloc_asprintf(mem_ctx
, "(&(servicePrincipalName=%s)(objectClass=user))",
642 ldb_binary_encode_string(mem_ctx
, unparsed_name_short
));
644 krb5_free_principal(smb_krb5_context
->krb5_context
, principal
);
645 free(unparsed_name_short
);
646 W_ERROR_HAVE_NO_MEMORY(result_filter
);
651 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
657 if (format_flags
& DRSUAPI_DS_NAME_FLAG_SYNTACTICAL_ONLY
) {
658 return DsCrackNameOneSyntactical(mem_ctx
, format_offered
, format_desired
,
659 name_dn
, name
, info1
);
662 return DsCrackNameOneFilter(sam_ctx
, mem_ctx
,
664 format_flags
, format_offered
, format_desired
,
666 domain_filter
, result_filter
,
670 /* Subcase of CrackNames. It is possible to translate a LDAP-style DN
671 * (FQDN_1779) into a canoical name without actually searching the
674 static WERROR
DsCrackNameOneSyntactical(TALLOC_CTX
*mem_ctx
,
675 uint32_t format_offered
, uint32_t format_desired
,
676 struct ldb_dn
*name_dn
, const char *name
,
677 struct drsuapi_DsNameInfo1
*info1
)
680 if (format_offered
!= DRSUAPI_DS_NAME_FORMAT_FQDN_1779
) {
681 info1
->status
= DRSUAPI_DS_NAME_STATUS_NO_SYNTACTICAL_MAPPING
;
685 switch (format_desired
) {
686 case DRSUAPI_DS_NAME_FORMAT_CANONICAL
:
687 cracked
= ldb_dn_canonical_string(mem_ctx
, name_dn
);
689 case DRSUAPI_DS_NAME_FORMAT_CANONICAL_EX
:
690 cracked
= ldb_dn_canonical_ex_string(mem_ctx
, name_dn
);
693 info1
->status
= DRSUAPI_DS_NAME_STATUS_NO_SYNTACTICAL_MAPPING
;
696 info1
->status
= DRSUAPI_DS_NAME_STATUS_OK
;
697 info1
->result_name
= cracked
;
705 /* Given a filter for the domain, and one for the result, perform the
706 * ldb search. The format offered and desired flags change the
707 * behaviours, including what attributes to return.
709 * The smb_krb5_context is required because we use the krb5 libs for principal parsing
712 static WERROR
DsCrackNameOneFilter(struct ldb_context
*sam_ctx
, TALLOC_CTX
*mem_ctx
,
713 struct smb_krb5_context
*smb_krb5_context
,
714 uint32_t format_flags
, uint32_t format_offered
, uint32_t format_desired
,
715 struct ldb_dn
*name_dn
, const char *name
,
716 const char *domain_filter
, const char *result_filter
,
717 struct drsuapi_DsNameInfo1
*info1
)
720 struct ldb_result
*domain_res
= NULL
;
721 const char * const *domain_attrs
;
722 const char * const *result_attrs
;
723 struct ldb_message
**result_res
= NULL
;
724 struct ldb_message
*result
= NULL
;
727 struct ldb_dn
*partitions_basedn
= samdb_partitions_dn(sam_ctx
, mem_ctx
);
729 const char * const _domain_attrs_1779
[] = { "ncName", "dnsRoot", NULL
};
730 const char * const _result_attrs_null
[] = { NULL
};
732 const char * const _domain_attrs_canonical
[] = { "ncName", "dnsRoot", NULL
};
733 const char * const _result_attrs_canonical
[] = { "canonicalName", NULL
};
735 const char * const _domain_attrs_nt4
[] = { "ncName", "dnsRoot", "nETBIOSName", NULL
};
736 const char * const _result_attrs_nt4
[] = { "sAMAccountName", "objectSid", "objectClass", NULL
};
738 const char * const _domain_attrs_guid
[] = { "ncName", "dnsRoot", NULL
};
739 const char * const _result_attrs_guid
[] = { "objectGUID", NULL
};
741 const char * const _domain_attrs_display
[] = { "ncName", "dnsRoot", NULL
};
742 const char * const _result_attrs_display
[] = { "displayName", "samAccountName", NULL
};
744 const char * const _domain_attrs_none
[] = { "ncName", "dnsRoot" , NULL
};
745 const char * const _result_attrs_none
[] = { NULL
};
747 /* here we need to set the attrs lists for domain and result lookups */
748 switch (format_desired
) {
749 case DRSUAPI_DS_NAME_FORMAT_FQDN_1779
:
750 case DRSUAPI_DS_NAME_FORMAT_CANONICAL_EX
:
751 domain_attrs
= _domain_attrs_1779
;
752 result_attrs
= _result_attrs_null
;
754 case DRSUAPI_DS_NAME_FORMAT_CANONICAL
:
755 domain_attrs
= _domain_attrs_canonical
;
756 result_attrs
= _result_attrs_canonical
;
758 case DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT
:
759 domain_attrs
= _domain_attrs_nt4
;
760 result_attrs
= _result_attrs_nt4
;
762 case DRSUAPI_DS_NAME_FORMAT_GUID
:
763 domain_attrs
= _domain_attrs_guid
;
764 result_attrs
= _result_attrs_guid
;
766 case DRSUAPI_DS_NAME_FORMAT_DISPLAY
:
767 domain_attrs
= _domain_attrs_display
;
768 result_attrs
= _result_attrs_display
;
771 domain_attrs
= _domain_attrs_none
;
772 result_attrs
= _result_attrs_none
;
777 /* if we have a domain_filter look it up and set the result_basedn and the dns_domain_name */
778 ldb_ret
= ldb_search(sam_ctx
, mem_ctx
, &domain_res
,
782 "%s", domain_filter
);
784 if (ldb_ret
!= LDB_SUCCESS
) {
785 DEBUG(2, ("DsCrackNameOneFilter domain ref search failed: %s", ldb_errstring(sam_ctx
)));
786 info1
->status
= DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
790 switch (domain_res
->count
) {
794 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
797 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE
;
801 info1
->dns_domain_name
= samdb_result_string(domain_res
->msgs
[0], "dnsRoot", NULL
);
802 W_ERROR_HAVE_NO_MEMORY(info1
->dns_domain_name
);
803 info1
->status
= DRSUAPI_DS_NAME_STATUS_DOMAIN_ONLY
;
805 info1
->dns_domain_name
= NULL
;
806 info1
->status
= DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
811 struct ldb_result
*res
;
812 uint32_t dsdb_flags
= 0;
813 struct ldb_dn
*search_dn
;
817 search_dn
= samdb_result_dn(sam_ctx
, mem_ctx
, domain_res
->msgs
[0], "ncName", NULL
);
819 dsdb_flags
= DSDB_SEARCH_SEARCH_ALL_PARTITIONS
;
820 search_dn
= ldb_get_root_basedn(sam_ctx
);
823 /* search with the 'phantom root' flag */
824 ret
= dsdb_search(sam_ctx
, mem_ctx
, &res
,
828 DSDB_SEARCH_SEARCH_ALL_PARTITIONS
,
829 "%s", result_filter
);
830 if (ret
!= LDB_SUCCESS
) {
831 DEBUG(2, ("DsCrackNameOneFilter phantom root search failed: %s",
832 ldb_errstring(sam_ctx
)));
833 info1
->status
= DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
837 ldb_ret
= res
->count
;
838 result_res
= res
->msgs
;
839 } else if (format_offered
== DRSUAPI_DS_NAME_FORMAT_FQDN_1779
) {
840 ldb_ret
= gendb_search_dn(sam_ctx
, mem_ctx
, name_dn
, &result_res
,
842 } else if (domain_res
) {
843 name_dn
= samdb_result_dn(sam_ctx
, mem_ctx
, domain_res
->msgs
[0], "ncName", NULL
);
844 ldb_ret
= gendb_search_dn(sam_ctx
, mem_ctx
, name_dn
, &result_res
,
848 DEBUG(0, ("LOGIC ERROR: DsCrackNameOneFilter domain ref search not availible: This can't happen..."));
849 info1
->status
= DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
855 result
= result_res
[0];
858 switch (format_offered
) {
859 case DRSUAPI_DS_NAME_FORMAT_SERVICE_PRINCIPAL
:
860 return DsCrackNameSPNAlias(sam_ctx
, mem_ctx
,
862 format_flags
, format_offered
, format_desired
,
865 case DRSUAPI_DS_NAME_FORMAT_USER_PRINCIPAL
:
866 return DsCrackNameUPN(sam_ctx
, mem_ctx
, smb_krb5_context
,
867 format_flags
, format_offered
, format_desired
,
870 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
873 DEBUG(2, ("DsCrackNameOneFilter result search failed: %s", ldb_errstring(sam_ctx
)));
874 info1
->status
= DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
877 switch (format_offered
) {
878 case DRSUAPI_DS_NAME_FORMAT_CANONICAL
:
879 case DRSUAPI_DS_NAME_FORMAT_CANONICAL_EX
:
881 const char *canonical_name
= NULL
; /* Not required, but we get warnings... */
882 /* We may need to manually filter further */
883 for (i
= 0; i
< ldb_ret
; i
++) {
884 switch (format_offered
) {
885 case DRSUAPI_DS_NAME_FORMAT_CANONICAL
:
886 canonical_name
= ldb_dn_canonical_string(mem_ctx
, result_res
[i
]->dn
);
888 case DRSUAPI_DS_NAME_FORMAT_CANONICAL_EX
:
889 canonical_name
= ldb_dn_canonical_ex_string(mem_ctx
, result_res
[i
]->dn
);
892 if (strcasecmp_m(canonical_name
, name
) == 0) {
893 result
= result_res
[i
];
898 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
903 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE
;
908 info1
->dns_domain_name
= ldb_dn_canonical_string(mem_ctx
, result
->dn
);
909 W_ERROR_HAVE_NO_MEMORY(info1
->dns_domain_name
);
910 p
= strchr(info1
->dns_domain_name
, '/');
915 /* here we can use result and domain_res[0] */
916 switch (format_desired
) {
917 case DRSUAPI_DS_NAME_FORMAT_FQDN_1779
: {
918 info1
->result_name
= ldb_dn_alloc_linearized(mem_ctx
, result
->dn
);
919 W_ERROR_HAVE_NO_MEMORY(info1
->result_name
);
921 info1
->status
= DRSUAPI_DS_NAME_STATUS_OK
;
924 case DRSUAPI_DS_NAME_FORMAT_CANONICAL
: {
925 info1
->result_name
= samdb_result_string(result
, "canonicalName", NULL
);
926 info1
->status
= DRSUAPI_DS_NAME_STATUS_OK
;
929 case DRSUAPI_DS_NAME_FORMAT_CANONICAL_EX
: {
930 /* Not in the virtual ldb attribute */
931 return DsCrackNameOneSyntactical(mem_ctx
,
932 DRSUAPI_DS_NAME_FORMAT_FQDN_1779
,
933 DRSUAPI_DS_NAME_FORMAT_CANONICAL_EX
,
934 result
->dn
, name
, info1
);
936 case DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT
: {
938 const struct dom_sid
*sid
= samdb_result_dom_sid(mem_ctx
, result
, "objectSid");
939 const char *_acc
= "", *_dom
= "";
941 if (samdb_find_attribute(sam_ctx
, result
, "objectClass", "domain")) {
943 ldb_ret
= ldb_search(sam_ctx
, mem_ctx
, &domain_res
,
947 "(ncName=%s)", ldb_dn_get_linearized(result
->dn
));
949 if (ldb_ret
!= LDB_SUCCESS
) {
950 DEBUG(2, ("DsCrackNameOneFilter domain ref search failed: %s", ldb_errstring(sam_ctx
)));
951 info1
->status
= DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
955 switch (domain_res
->count
) {
959 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
962 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE
;
965 _dom
= samdb_result_string(domain_res
->msgs
[0], "nETBIOSName", NULL
);
966 W_ERROR_HAVE_NO_MEMORY(_dom
);
968 _acc
= samdb_result_string(result
, "sAMAccountName", NULL
);
970 info1
->status
= DRSUAPI_DS_NAME_STATUS_NO_MAPPING
;
973 if (dom_sid_in_domain(dom_sid_parse_talloc(mem_ctx
, SID_BUILTIN
), sid
)) {
976 const char *attrs
[] = { NULL
};
977 struct ldb_result
*domain_res2
;
978 struct dom_sid
*dom_sid
= dom_sid_dup(mem_ctx
, sid
);
982 dom_sid
->num_auths
--;
983 ldb_ret
= ldb_search(sam_ctx
, mem_ctx
, &domain_res
,
987 "(&(objectSid=%s)(objectClass=domain))",
988 ldap_encode_ndr_dom_sid(mem_ctx
, dom_sid
));
990 if (ldb_ret
!= LDB_SUCCESS
) {
991 DEBUG(2, ("DsCrackNameOneFilter domain search failed: %s", ldb_errstring(sam_ctx
)));
992 info1
->status
= DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
996 switch (domain_res
->count
) {
1000 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
1003 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE
;
1007 ldb_ret
= ldb_search(sam_ctx
, mem_ctx
, &domain_res2
,
1011 "(ncName=%s)", ldb_dn_get_linearized(domain_res
->msgs
[0]->dn
));
1013 if (ldb_ret
!= LDB_SUCCESS
) {
1014 DEBUG(2, ("DsCrackNameOneFilter domain ref search failed: %s", ldb_errstring(sam_ctx
)));
1015 info1
->status
= DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
1019 switch (domain_res2
->count
) {
1023 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
1026 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE
;
1029 _dom
= samdb_result_string(domain_res2
->msgs
[0], "nETBIOSName", NULL
);
1030 W_ERROR_HAVE_NO_MEMORY(_dom
);
1034 info1
->result_name
= talloc_asprintf(mem_ctx
, "%s\\%s", _dom
, _acc
);
1035 W_ERROR_HAVE_NO_MEMORY(info1
->result_name
);
1037 info1
->status
= DRSUAPI_DS_NAME_STATUS_OK
;
1040 case DRSUAPI_DS_NAME_FORMAT_GUID
: {
1043 guid
= samdb_result_guid(result
, "objectGUID");
1045 info1
->result_name
= GUID_string2(mem_ctx
, &guid
);
1046 W_ERROR_HAVE_NO_MEMORY(info1
->result_name
);
1048 info1
->status
= DRSUAPI_DS_NAME_STATUS_OK
;
1051 case DRSUAPI_DS_NAME_FORMAT_DISPLAY
: {
1052 info1
->result_name
= samdb_result_string(result
, "displayName", NULL
);
1053 if (!info1
->result_name
) {
1054 info1
->result_name
= samdb_result_string(result
, "sAMAccountName", NULL
);
1056 if (!info1
->result_name
) {
1057 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
1059 info1
->status
= DRSUAPI_DS_NAME_STATUS_OK
;
1063 case DRSUAPI_DS_NAME_FORMAT_SERVICE_PRINCIPAL
: {
1064 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE
;
1067 case DRSUAPI_DS_NAME_FORMAT_DNS_DOMAIN
:
1068 case DRSUAPI_DS_NAME_FORMAT_SID_OR_SID_HISTORY
: {
1069 info1
->status
= DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
1073 info1
->status
= DRSUAPI_DS_NAME_STATUS_NO_MAPPING
;
1078 /* Given a user Principal Name (such as foo@bar.com),
1079 * return the user and domain DNs. This is used in the KDC to then
1080 * return the Keys and evaluate policy */
1082 NTSTATUS
crack_user_principal_name(struct ldb_context
*sam_ctx
,
1083 TALLOC_CTX
*mem_ctx
,
1084 const char *user_principal_name
,
1085 struct ldb_dn
**user_dn
,
1086 struct ldb_dn
**domain_dn
)
1089 struct drsuapi_DsNameInfo1 info1
;
1090 werr
= DsCrackNameOneName(sam_ctx
, mem_ctx
, 0,
1091 DRSUAPI_DS_NAME_FORMAT_USER_PRINCIPAL
,
1092 DRSUAPI_DS_NAME_FORMAT_FQDN_1779
,
1093 user_principal_name
,
1095 if (!W_ERROR_IS_OK(werr
)) {
1096 return werror_to_ntstatus(werr
);
1098 switch (info1
.status
) {
1099 case DRSUAPI_DS_NAME_STATUS_OK
:
1101 case DRSUAPI_DS_NAME_STATUS_NOT_FOUND
:
1102 case DRSUAPI_DS_NAME_STATUS_DOMAIN_ONLY
:
1103 case DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE
:
1104 return NT_STATUS_NO_SUCH_USER
;
1105 case DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
:
1107 return NT_STATUS_UNSUCCESSFUL
;
1110 *user_dn
= ldb_dn_new(mem_ctx
, sam_ctx
, info1
.result_name
);
1113 werr
= DsCrackNameOneName(sam_ctx
, mem_ctx
, 0,
1114 DRSUAPI_DS_NAME_FORMAT_CANONICAL
,
1115 DRSUAPI_DS_NAME_FORMAT_FQDN_1779
,
1116 talloc_asprintf(mem_ctx
, "%s/",
1117 info1
.dns_domain_name
),
1119 if (!W_ERROR_IS_OK(werr
)) {
1120 return werror_to_ntstatus(werr
);
1122 switch (info1
.status
) {
1123 case DRSUAPI_DS_NAME_STATUS_OK
:
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
:
1131 return NT_STATUS_UNSUCCESSFUL
;
1134 *domain_dn
= ldb_dn_new(mem_ctx
, sam_ctx
, info1
.result_name
);
1137 return NT_STATUS_OK
;
1140 /* Given a Service Principal Name (such as host/foo.bar.com@BAR.COM),
1141 * return the user and domain DNs. This is used in the KDC to then
1142 * return the Keys and evaluate policy */
1144 NTSTATUS
crack_service_principal_name(struct ldb_context
*sam_ctx
,
1145 TALLOC_CTX
*mem_ctx
,
1146 const char *service_principal_name
,
1147 struct ldb_dn
**user_dn
,
1148 struct ldb_dn
**domain_dn
)
1151 struct drsuapi_DsNameInfo1 info1
;
1152 werr
= DsCrackNameOneName(sam_ctx
, mem_ctx
, 0,
1153 DRSUAPI_DS_NAME_FORMAT_SERVICE_PRINCIPAL
,
1154 DRSUAPI_DS_NAME_FORMAT_FQDN_1779
,
1155 service_principal_name
,
1157 if (!W_ERROR_IS_OK(werr
)) {
1158 return werror_to_ntstatus(werr
);
1160 switch (info1
.status
) {
1161 case DRSUAPI_DS_NAME_STATUS_OK
:
1163 case DRSUAPI_DS_NAME_STATUS_NOT_FOUND
:
1164 case DRSUAPI_DS_NAME_STATUS_DOMAIN_ONLY
:
1165 case DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE
:
1166 return NT_STATUS_NO_SUCH_USER
;
1167 case DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
:
1169 return NT_STATUS_UNSUCCESSFUL
;
1172 *user_dn
= ldb_dn_new(mem_ctx
, sam_ctx
, info1
.result_name
);
1175 werr
= DsCrackNameOneName(sam_ctx
, mem_ctx
, 0,
1176 DRSUAPI_DS_NAME_FORMAT_CANONICAL
,
1177 DRSUAPI_DS_NAME_FORMAT_FQDN_1779
,
1178 talloc_asprintf(mem_ctx
, "%s/",
1179 info1
.dns_domain_name
),
1181 if (!W_ERROR_IS_OK(werr
)) {
1182 return werror_to_ntstatus(werr
);
1184 switch (info1
.status
) {
1185 case DRSUAPI_DS_NAME_STATUS_OK
:
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
:
1193 return NT_STATUS_UNSUCCESSFUL
;
1196 *domain_dn
= ldb_dn_new(mem_ctx
, sam_ctx
, info1
.result_name
);
1199 return NT_STATUS_OK
;
1202 NTSTATUS
crack_name_to_nt4_name(TALLOC_CTX
*mem_ctx
,
1203 struct tevent_context
*ev_ctx
,
1204 struct loadparm_context
*lp_ctx
,
1205 uint32_t format_offered
,
1207 const char **nt4_domain
, const char **nt4_account
)
1210 struct drsuapi_DsNameInfo1 info1
;
1211 struct ldb_context
*ldb
;
1214 /* Handle anonymous bind */
1215 if (!name
|| !*name
) {
1218 return NT_STATUS_OK
;
1221 ldb
= samdb_connect(mem_ctx
, ev_ctx
, lp_ctx
, system_session(lp_ctx
));
1223 return NT_STATUS_INTERNAL_DB_CORRUPTION
;
1226 werr
= DsCrackNameOneName(ldb
, mem_ctx
, 0,
1228 DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT
,
1231 if (!W_ERROR_IS_OK(werr
)) {
1232 return werror_to_ntstatus(werr
);
1234 switch (info1
.status
) {
1235 case DRSUAPI_DS_NAME_STATUS_OK
:
1237 case DRSUAPI_DS_NAME_STATUS_NOT_FOUND
:
1238 case DRSUAPI_DS_NAME_STATUS_DOMAIN_ONLY
:
1239 case DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE
:
1240 return NT_STATUS_NO_SUCH_USER
;
1241 case DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
:
1243 return NT_STATUS_UNSUCCESSFUL
;
1246 *nt4_domain
= talloc_strdup(mem_ctx
, info1
.result_name
);
1247 if (*nt4_domain
== NULL
) {
1248 return NT_STATUS_NO_MEMORY
;
1251 p
= strchr(*nt4_domain
, '\\');
1253 return NT_STATUS_INVALID_PARAMETER
;
1257 *nt4_account
= talloc_strdup(mem_ctx
, &p
[1]);
1258 if (*nt4_account
== NULL
) {
1259 return NT_STATUS_NO_MEMORY
;
1262 return NT_STATUS_OK
;
1265 NTSTATUS
crack_auto_name_to_nt4_name(TALLOC_CTX
*mem_ctx
,
1266 struct tevent_context
*ev_ctx
,
1267 struct loadparm_context
*lp_ctx
,
1269 const char **nt4_domain
,
1270 const char **nt4_account
)
1272 uint32_t format_offered
= DRSUAPI_DS_NAME_FORMAT_UNKNOWN
;
1274 /* Handle anonymous bind */
1275 if (!name
|| !*name
) {
1278 return NT_STATUS_OK
;
1281 if (strchr_m(name
, '=')) {
1282 format_offered
= DRSUAPI_DS_NAME_FORMAT_FQDN_1779
;
1283 } else if (strchr_m(name
, '@')) {
1284 format_offered
= DRSUAPI_DS_NAME_FORMAT_USER_PRINCIPAL
;
1285 } else if (strchr_m(name
, '\\')) {
1286 format_offered
= DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT
;
1287 } else if (strchr_m(name
, '/')) {
1288 format_offered
= DRSUAPI_DS_NAME_FORMAT_CANONICAL
;
1290 return NT_STATUS_NO_SUCH_USER
;
1293 return crack_name_to_nt4_name(mem_ctx
, ev_ctx
, lp_ctx
, format_offered
, name
, nt4_domain
, nt4_account
);