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 "rpc_server/common/common.h"
27 #include "lib/events/events.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 "librpc/gen_ndr/ndr_misc.h"
35 #include "auth/auth.h"
36 #include "../lib/util/util_ldb.h"
37 #include "dsdb/samdb/samdb.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_MUST_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_princ_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_MUST_REALM
, &principal
);
288 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
292 realm
= krb5_princ_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 ret
= krb5_parse_name(smb_krb5_context
->krb5_context
, name
, &principal
);
565 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
569 domain_filter
= NULL
;
571 ret
= krb5_unparse_name(smb_krb5_context
->krb5_context
, principal
, &unparsed_name
);
573 krb5_free_principal(smb_krb5_context
->krb5_context
, principal
);
577 krb5_free_principal(smb_krb5_context
->krb5_context
, principal
);
578 result_filter
= talloc_asprintf(mem_ctx
, "(&(objectClass=user)(userPrincipalName=%s))",
579 ldb_binary_encode_string(mem_ctx
, unparsed_name
));
582 W_ERROR_HAVE_NO_MEMORY(result_filter
);
585 case DRSUAPI_DS_NAME_FORMAT_SERVICE_PRINCIPAL
: {
586 krb5_principal principal
;
587 char *unparsed_name_short
;
590 ret
= smb_krb5_init_context(mem_ctx
,
591 ldb_get_event_context(sam_ctx
),
592 (struct loadparm_context
*)ldb_get_opaque(sam_ctx
, "loadparm"),
599 ret
= krb5_parse_name(smb_krb5_context
->krb5_context
, name
, &principal
);
600 if (ret
== 0 && principal
->name
.name_string
.len
< 2) {
601 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
602 krb5_free_principal(smb_krb5_context
->krb5_context
, principal
);
605 ret
= krb5_parse_name_flags(smb_krb5_context
->krb5_context
, name
,
606 KRB5_PRINCIPAL_PARSE_NO_REALM
, &principal
);
608 krb5_free_principal(smb_krb5_context
->krb5_context
, principal
);
610 return dns_domain_from_principal(mem_ctx
, smb_krb5_context
,
614 domain_filter
= NULL
;
616 ret
= krb5_unparse_name_flags(smb_krb5_context
->krb5_context
, principal
,
617 KRB5_PRINCIPAL_UNPARSE_NO_REALM
, &unparsed_name_short
);
619 krb5_free_principal(smb_krb5_context
->krb5_context
, principal
);
623 service
= principal
->name
.name_string
.val
[0];
624 if ((principal
->name
.name_string
.len
== 2) && (strcasecmp(service
, "host") == 0)) {
625 /* the 'cn' attribute is just the leading part of the name */
627 computer_name
= talloc_strndup(mem_ctx
, principal
->name
.name_string
.val
[1],
628 strcspn(principal
->name
.name_string
.val
[1], "."));
629 if (computer_name
== NULL
) {
633 result_filter
= talloc_asprintf(mem_ctx
, "(|(&(servicePrincipalName=%s)(objectClass=user))(&(cn=%s)(objectClass=computer)))",
634 ldb_binary_encode_string(mem_ctx
, unparsed_name_short
),
635 ldb_binary_encode_string(mem_ctx
, computer_name
));
637 result_filter
= talloc_asprintf(mem_ctx
, "(&(servicePrincipalName=%s)(objectClass=user))",
638 ldb_binary_encode_string(mem_ctx
, unparsed_name_short
));
640 krb5_free_principal(smb_krb5_context
->krb5_context
, principal
);
641 free(unparsed_name_short
);
642 W_ERROR_HAVE_NO_MEMORY(result_filter
);
647 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
653 if (format_flags
& DRSUAPI_DS_NAME_FLAG_SYNTACTICAL_ONLY
) {
654 return DsCrackNameOneSyntactical(mem_ctx
, format_offered
, format_desired
,
655 name_dn
, name
, info1
);
658 return DsCrackNameOneFilter(sam_ctx
, mem_ctx
,
660 format_flags
, format_offered
, format_desired
,
662 domain_filter
, result_filter
,
666 /* Subcase of CrackNames. It is possible to translate a LDAP-style DN
667 * (FQDN_1779) into a canoical name without actually searching the
670 static WERROR
DsCrackNameOneSyntactical(TALLOC_CTX
*mem_ctx
,
671 uint32_t format_offered
, uint32_t format_desired
,
672 struct ldb_dn
*name_dn
, const char *name
,
673 struct drsuapi_DsNameInfo1
*info1
)
676 if (format_offered
!= DRSUAPI_DS_NAME_FORMAT_FQDN_1779
) {
677 info1
->status
= DRSUAPI_DS_NAME_STATUS_NO_SYNTACTICAL_MAPPING
;
681 switch (format_desired
) {
682 case DRSUAPI_DS_NAME_FORMAT_CANONICAL
:
683 cracked
= ldb_dn_canonical_string(mem_ctx
, name_dn
);
685 case DRSUAPI_DS_NAME_FORMAT_CANONICAL_EX
:
686 cracked
= ldb_dn_canonical_ex_string(mem_ctx
, name_dn
);
689 info1
->status
= DRSUAPI_DS_NAME_STATUS_NO_SYNTACTICAL_MAPPING
;
692 info1
->status
= DRSUAPI_DS_NAME_STATUS_OK
;
693 info1
->result_name
= cracked
;
701 /* Given a filter for the domain, and one for the result, perform the
702 * ldb search. The format offered and desired flags change the
703 * behaviours, including what attributes to return.
705 * The smb_krb5_context is required because we use the krb5 libs for principal parsing
708 static WERROR
DsCrackNameOneFilter(struct ldb_context
*sam_ctx
, TALLOC_CTX
*mem_ctx
,
709 struct smb_krb5_context
*smb_krb5_context
,
710 uint32_t format_flags
, uint32_t format_offered
, uint32_t format_desired
,
711 struct ldb_dn
*name_dn
, const char *name
,
712 const char *domain_filter
, const char *result_filter
,
713 struct drsuapi_DsNameInfo1
*info1
)
716 struct ldb_result
*domain_res
= NULL
;
717 const char * const *domain_attrs
;
718 const char * const *result_attrs
;
719 struct ldb_message
**result_res
= NULL
;
720 struct ldb_message
*result
= NULL
;
721 struct ldb_dn
*result_basedn
= NULL
;
724 struct ldb_dn
*partitions_basedn
= samdb_partitions_dn(sam_ctx
, mem_ctx
);
726 const char * const _domain_attrs_1779
[] = { "ncName", "dnsRoot", NULL
};
727 const char * const _result_attrs_null
[] = { NULL
};
729 const char * const _domain_attrs_canonical
[] = { "ncName", "dnsRoot", NULL
};
730 const char * const _result_attrs_canonical
[] = { "canonicalName", NULL
};
732 const char * const _domain_attrs_nt4
[] = { "ncName", "dnsRoot", "nETBIOSName", NULL
};
733 const char * const _result_attrs_nt4
[] = { "sAMAccountName", "objectSid", "objectClass", NULL
};
735 const char * const _domain_attrs_guid
[] = { "ncName", "dnsRoot", NULL
};
736 const char * const _result_attrs_guid
[] = { "objectGUID", NULL
};
738 const char * const _domain_attrs_display
[] = { "ncName", "dnsRoot", NULL
};
739 const char * const _result_attrs_display
[] = { "displayName", "samAccountName", NULL
};
741 const char * const _domain_attrs_none
[] = { "ncName", "dnsRoot" , NULL
};
742 const char * const _result_attrs_none
[] = { NULL
};
744 /* here we need to set the attrs lists for domain and result lookups */
745 switch (format_desired
) {
746 case DRSUAPI_DS_NAME_FORMAT_FQDN_1779
:
747 case DRSUAPI_DS_NAME_FORMAT_CANONICAL_EX
:
748 domain_attrs
= _domain_attrs_1779
;
749 result_attrs
= _result_attrs_null
;
751 case DRSUAPI_DS_NAME_FORMAT_CANONICAL
:
752 domain_attrs
= _domain_attrs_canonical
;
753 result_attrs
= _result_attrs_canonical
;
755 case DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT
:
756 domain_attrs
= _domain_attrs_nt4
;
757 result_attrs
= _result_attrs_nt4
;
759 case DRSUAPI_DS_NAME_FORMAT_GUID
:
760 domain_attrs
= _domain_attrs_guid
;
761 result_attrs
= _result_attrs_guid
;
763 case DRSUAPI_DS_NAME_FORMAT_DISPLAY
:
764 domain_attrs
= _domain_attrs_display
;
765 result_attrs
= _result_attrs_display
;
768 domain_attrs
= _domain_attrs_none
;
769 result_attrs
= _result_attrs_none
;
774 /* if we have a domain_filter look it up and set the result_basedn and the dns_domain_name */
775 ldb_ret
= ldb_search(sam_ctx
, mem_ctx
, &domain_res
,
779 "%s", domain_filter
);
781 if (ldb_ret
!= LDB_SUCCESS
) {
782 DEBUG(2, ("DsCrackNameOneFilter domain ref search failed: %s", ldb_errstring(sam_ctx
)));
783 info1
->status
= DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
787 switch (domain_res
->count
) {
791 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
794 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE
;
798 info1
->dns_domain_name
= samdb_result_string(domain_res
->msgs
[0], "dnsRoot", NULL
);
799 W_ERROR_HAVE_NO_MEMORY(info1
->dns_domain_name
);
800 info1
->status
= DRSUAPI_DS_NAME_STATUS_DOMAIN_ONLY
;
802 info1
->dns_domain_name
= NULL
;
803 info1
->status
= DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
808 struct ldb_result
*res
;
810 result_basedn
= samdb_result_dn(sam_ctx
, mem_ctx
, domain_res
->msgs
[0], "ncName", NULL
);
812 ret
= ldb_search(sam_ctx
, mem_ctx
, &res
,
813 result_basedn
, LDB_SCOPE_SUBTREE
,
814 result_attrs
, "%s", result_filter
);
815 if (ret
!= LDB_SUCCESS
) {
816 talloc_free(result_res
);
817 info1
->status
= DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
820 ldb_ret
= res
->count
;
821 result_res
= res
->msgs
;
823 /* search with the 'phantom root' flag */
824 struct ldb_request
*req
;
826 res
= talloc_zero(mem_ctx
, struct ldb_result
);
827 W_ERROR_HAVE_NO_MEMORY(res
);
829 ret
= ldb_build_search_req(&req
, sam_ctx
, mem_ctx
,
830 ldb_get_root_basedn(sam_ctx
),
836 ldb_search_default_callback
,
838 if (ret
== LDB_SUCCESS
) {
839 struct ldb_search_options_control
*search_options
;
840 search_options
= talloc(req
, struct ldb_search_options_control
);
841 W_ERROR_HAVE_NO_MEMORY(search_options
);
842 search_options
->search_options
= LDB_SEARCH_OPTION_PHANTOM_ROOT
;
844 ret
= ldb_request_add_control(req
, LDB_CONTROL_SEARCH_OPTIONS_OID
, false, search_options
);
846 if (ret
!= LDB_SUCCESS
) {
848 info1
->status
= DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
852 ret
= ldb_request(sam_ctx
, req
);
854 if (ret
== LDB_SUCCESS
) {
855 ret
= ldb_wait(req
->handle
, LDB_WAIT_ALL
);
860 if (ret
!= LDB_SUCCESS
) {
861 DEBUG(2, ("DsCrackNameOneFilter phantom root search failed: %s",
862 ldb_errstring(sam_ctx
)));
863 info1
->status
= DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
866 ldb_ret
= res
->count
;
867 result_res
= res
->msgs
;
869 } else if (format_offered
== DRSUAPI_DS_NAME_FORMAT_FQDN_1779
) {
870 ldb_ret
= gendb_search_dn(sam_ctx
, mem_ctx
, name_dn
, &result_res
,
872 } else if (domain_res
) {
873 name_dn
= samdb_result_dn(sam_ctx
, mem_ctx
, domain_res
->msgs
[0], "ncName", NULL
);
874 ldb_ret
= gendb_search_dn(sam_ctx
, mem_ctx
, name_dn
, &result_res
,
878 DEBUG(0, ("LOGIC ERROR: DsCrackNameOneFilter domain ref search not availible: This can't happen..."));
879 info1
->status
= DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
885 result
= result_res
[0];
888 switch (format_offered
) {
889 case DRSUAPI_DS_NAME_FORMAT_SERVICE_PRINCIPAL
:
890 return DsCrackNameSPNAlias(sam_ctx
, mem_ctx
,
892 format_flags
, format_offered
, format_desired
,
895 case DRSUAPI_DS_NAME_FORMAT_USER_PRINCIPAL
:
896 return DsCrackNameUPN(sam_ctx
, mem_ctx
, smb_krb5_context
,
897 format_flags
, format_offered
, format_desired
,
900 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
903 DEBUG(2, ("DsCrackNameOneFilter result search failed: %s", ldb_errstring(sam_ctx
)));
904 info1
->status
= DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
907 switch (format_offered
) {
908 case DRSUAPI_DS_NAME_FORMAT_CANONICAL
:
909 case DRSUAPI_DS_NAME_FORMAT_CANONICAL_EX
:
911 const char *canonical_name
= NULL
; /* Not required, but we get warnings... */
912 /* We may need to manually filter further */
913 for (i
= 0; i
< ldb_ret
; i
++) {
914 switch (format_offered
) {
915 case DRSUAPI_DS_NAME_FORMAT_CANONICAL
:
916 canonical_name
= ldb_dn_canonical_string(mem_ctx
, result_res
[i
]->dn
);
918 case DRSUAPI_DS_NAME_FORMAT_CANONICAL_EX
:
919 canonical_name
= ldb_dn_canonical_ex_string(mem_ctx
, result_res
[i
]->dn
);
922 if (strcasecmp_m(canonical_name
, name
) == 0) {
923 result
= result_res
[i
];
928 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
933 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE
;
938 info1
->dns_domain_name
= ldb_dn_canonical_string(mem_ctx
, result
->dn
);
939 W_ERROR_HAVE_NO_MEMORY(info1
->dns_domain_name
);
940 p
= strchr(info1
->dns_domain_name
, '/');
945 /* here we can use result and domain_res[0] */
946 switch (format_desired
) {
947 case DRSUAPI_DS_NAME_FORMAT_FQDN_1779
: {
948 info1
->result_name
= ldb_dn_alloc_linearized(mem_ctx
, result
->dn
);
949 W_ERROR_HAVE_NO_MEMORY(info1
->result_name
);
951 info1
->status
= DRSUAPI_DS_NAME_STATUS_OK
;
954 case DRSUAPI_DS_NAME_FORMAT_CANONICAL
: {
955 info1
->result_name
= samdb_result_string(result
, "canonicalName", NULL
);
956 info1
->status
= DRSUAPI_DS_NAME_STATUS_OK
;
959 case DRSUAPI_DS_NAME_FORMAT_CANONICAL_EX
: {
960 /* Not in the virtual ldb attribute */
961 return DsCrackNameOneSyntactical(mem_ctx
,
962 DRSUAPI_DS_NAME_FORMAT_FQDN_1779
,
963 DRSUAPI_DS_NAME_FORMAT_CANONICAL_EX
,
964 result
->dn
, name
, info1
);
966 case DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT
: {
968 const struct dom_sid
*sid
= samdb_result_dom_sid(mem_ctx
, result
, "objectSid");
969 const char *_acc
= "", *_dom
= "";
971 if (samdb_find_attribute(sam_ctx
, result
, "objectClass", "domain")) {
973 ldb_ret
= ldb_search(sam_ctx
, mem_ctx
, &domain_res
,
977 "(ncName=%s)", ldb_dn_get_linearized(result
->dn
));
979 if (ldb_ret
!= LDB_SUCCESS
) {
980 DEBUG(2, ("DsCrackNameOneFilter domain ref search failed: %s", ldb_errstring(sam_ctx
)));
981 info1
->status
= DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
985 switch (domain_res
->count
) {
989 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
992 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE
;
995 _dom
= samdb_result_string(domain_res
->msgs
[0], "nETBIOSName", NULL
);
996 W_ERROR_HAVE_NO_MEMORY(_dom
);
998 _acc
= samdb_result_string(result
, "sAMAccountName", NULL
);
1000 info1
->status
= DRSUAPI_DS_NAME_STATUS_NO_MAPPING
;
1003 if (dom_sid_in_domain(dom_sid_parse_talloc(mem_ctx
, SID_BUILTIN
), sid
)) {
1006 const char *attrs
[] = { NULL
};
1007 struct ldb_result
*domain_res2
;
1008 struct dom_sid
*dom_sid
= dom_sid_dup(mem_ctx
, sid
);
1012 dom_sid
->num_auths
--;
1013 ldb_ret
= ldb_search(sam_ctx
, mem_ctx
, &domain_res
,
1017 "(&(objectSid=%s)(objectClass=domain))",
1018 ldap_encode_ndr_dom_sid(mem_ctx
, dom_sid
));
1020 if (ldb_ret
!= LDB_SUCCESS
) {
1021 DEBUG(2, ("DsCrackNameOneFilter domain search failed: %s", ldb_errstring(sam_ctx
)));
1022 info1
->status
= DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
1026 switch (domain_res
->count
) {
1030 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
1033 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE
;
1037 ldb_ret
= ldb_search(sam_ctx
, mem_ctx
, &domain_res2
,
1041 "(ncName=%s)", ldb_dn_get_linearized(domain_res
->msgs
[0]->dn
));
1043 if (ldb_ret
!= LDB_SUCCESS
) {
1044 DEBUG(2, ("DsCrackNameOneFilter domain ref search failed: %s", ldb_errstring(sam_ctx
)));
1045 info1
->status
= DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
1049 switch (domain_res2
->count
) {
1053 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
1056 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE
;
1059 _dom
= samdb_result_string(domain_res2
->msgs
[0], "nETBIOSName", NULL
);
1060 W_ERROR_HAVE_NO_MEMORY(_dom
);
1064 info1
->result_name
= talloc_asprintf(mem_ctx
, "%s\\%s", _dom
, _acc
);
1065 W_ERROR_HAVE_NO_MEMORY(info1
->result_name
);
1067 info1
->status
= DRSUAPI_DS_NAME_STATUS_OK
;
1070 case DRSUAPI_DS_NAME_FORMAT_GUID
: {
1073 guid
= samdb_result_guid(result
, "objectGUID");
1075 info1
->result_name
= GUID_string2(mem_ctx
, &guid
);
1076 W_ERROR_HAVE_NO_MEMORY(info1
->result_name
);
1078 info1
->status
= DRSUAPI_DS_NAME_STATUS_OK
;
1081 case DRSUAPI_DS_NAME_FORMAT_DISPLAY
: {
1082 info1
->result_name
= samdb_result_string(result
, "displayName", NULL
);
1083 if (!info1
->result_name
) {
1084 info1
->result_name
= samdb_result_string(result
, "sAMAccountName", NULL
);
1086 if (!info1
->result_name
) {
1087 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_FOUND
;
1089 info1
->status
= DRSUAPI_DS_NAME_STATUS_OK
;
1093 case DRSUAPI_DS_NAME_FORMAT_SERVICE_PRINCIPAL
: {
1094 info1
->status
= DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE
;
1097 case DRSUAPI_DS_NAME_FORMAT_DNS_DOMAIN
:
1098 case DRSUAPI_DS_NAME_FORMAT_SID_OR_SID_HISTORY
: {
1099 info1
->status
= DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
;
1103 info1
->status
= DRSUAPI_DS_NAME_STATUS_NO_MAPPING
;
1108 /* Given a user Principal Name (such as foo@bar.com),
1109 * return the user and domain DNs. This is used in the KDC to then
1110 * return the Keys and evaluate policy */
1112 NTSTATUS
crack_user_principal_name(struct ldb_context
*sam_ctx
,
1113 TALLOC_CTX
*mem_ctx
,
1114 const char *user_principal_name
,
1115 struct ldb_dn
**user_dn
,
1116 struct ldb_dn
**domain_dn
)
1119 struct drsuapi_DsNameInfo1 info1
;
1120 werr
= DsCrackNameOneName(sam_ctx
, mem_ctx
, 0,
1121 DRSUAPI_DS_NAME_FORMAT_USER_PRINCIPAL
,
1122 DRSUAPI_DS_NAME_FORMAT_FQDN_1779
,
1123 user_principal_name
,
1125 if (!W_ERROR_IS_OK(werr
)) {
1126 return werror_to_ntstatus(werr
);
1128 switch (info1
.status
) {
1129 case DRSUAPI_DS_NAME_STATUS_OK
:
1131 case DRSUAPI_DS_NAME_STATUS_NOT_FOUND
:
1132 case DRSUAPI_DS_NAME_STATUS_DOMAIN_ONLY
:
1133 case DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE
:
1134 return NT_STATUS_NO_SUCH_USER
;
1135 case DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
:
1137 return NT_STATUS_UNSUCCESSFUL
;
1140 *user_dn
= ldb_dn_new(mem_ctx
, sam_ctx
, info1
.result_name
);
1143 werr
= DsCrackNameOneName(sam_ctx
, mem_ctx
, 0,
1144 DRSUAPI_DS_NAME_FORMAT_CANONICAL
,
1145 DRSUAPI_DS_NAME_FORMAT_FQDN_1779
,
1146 talloc_asprintf(mem_ctx
, "%s/",
1147 info1
.dns_domain_name
),
1149 if (!W_ERROR_IS_OK(werr
)) {
1150 return werror_to_ntstatus(werr
);
1152 switch (info1
.status
) {
1153 case DRSUAPI_DS_NAME_STATUS_OK
:
1155 case DRSUAPI_DS_NAME_STATUS_NOT_FOUND
:
1156 case DRSUAPI_DS_NAME_STATUS_DOMAIN_ONLY
:
1157 case DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE
:
1158 return NT_STATUS_NO_SUCH_USER
;
1159 case DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
:
1161 return NT_STATUS_UNSUCCESSFUL
;
1164 *domain_dn
= ldb_dn_new(mem_ctx
, sam_ctx
, info1
.result_name
);
1167 return NT_STATUS_OK
;
1171 /* Given a Service Principal Name (such as host/foo.bar.com@BAR.COM),
1172 * return the user and domain DNs. This is used in the KDC to then
1173 * return the Keys and evaluate policy */
1175 NTSTATUS
crack_service_principal_name(struct ldb_context
*sam_ctx
,
1176 TALLOC_CTX
*mem_ctx
,
1177 const char *service_principal_name
,
1178 struct ldb_dn
**user_dn
,
1179 struct ldb_dn
**domain_dn
)
1182 struct drsuapi_DsNameInfo1 info1
;
1183 werr
= DsCrackNameOneName(sam_ctx
, mem_ctx
, 0,
1184 DRSUAPI_DS_NAME_FORMAT_SERVICE_PRINCIPAL
,
1185 DRSUAPI_DS_NAME_FORMAT_FQDN_1779
,
1186 service_principal_name
,
1188 if (!W_ERROR_IS_OK(werr
)) {
1189 return werror_to_ntstatus(werr
);
1191 switch (info1
.status
) {
1192 case DRSUAPI_DS_NAME_STATUS_OK
:
1194 case DRSUAPI_DS_NAME_STATUS_NOT_FOUND
:
1195 case DRSUAPI_DS_NAME_STATUS_DOMAIN_ONLY
:
1196 case DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE
:
1197 return NT_STATUS_NO_SUCH_USER
;
1198 case DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
:
1200 return NT_STATUS_UNSUCCESSFUL
;
1203 *user_dn
= ldb_dn_new(mem_ctx
, sam_ctx
, info1
.result_name
);
1206 werr
= DsCrackNameOneName(sam_ctx
, mem_ctx
, 0,
1207 DRSUAPI_DS_NAME_FORMAT_CANONICAL
,
1208 DRSUAPI_DS_NAME_FORMAT_FQDN_1779
,
1209 talloc_asprintf(mem_ctx
, "%s/",
1210 info1
.dns_domain_name
),
1212 if (!W_ERROR_IS_OK(werr
)) {
1213 return werror_to_ntstatus(werr
);
1215 switch (info1
.status
) {
1216 case DRSUAPI_DS_NAME_STATUS_OK
:
1218 case DRSUAPI_DS_NAME_STATUS_NOT_FOUND
:
1219 case DRSUAPI_DS_NAME_STATUS_DOMAIN_ONLY
:
1220 case DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE
:
1221 return NT_STATUS_NO_SUCH_USER
;
1222 case DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
:
1224 return NT_STATUS_UNSUCCESSFUL
;
1227 *domain_dn
= ldb_dn_new(mem_ctx
, sam_ctx
, info1
.result_name
);
1230 return NT_STATUS_OK
;
1234 NTSTATUS
crack_name_to_nt4_name(TALLOC_CTX
*mem_ctx
,
1235 struct tevent_context
*ev_ctx
,
1236 struct loadparm_context
*lp_ctx
,
1237 uint32_t format_offered
,
1239 const char **nt4_domain
, const char **nt4_account
)
1242 struct drsuapi_DsNameInfo1 info1
;
1243 struct ldb_context
*ldb
;
1246 /* Handle anonymous bind */
1247 if (!name
|| !*name
) {
1250 return NT_STATUS_OK
;
1253 ldb
= samdb_connect(mem_ctx
, ev_ctx
, lp_ctx
, system_session(mem_ctx
, lp_ctx
));
1255 return NT_STATUS_INTERNAL_DB_CORRUPTION
;
1258 werr
= DsCrackNameOneName(ldb
, mem_ctx
, 0,
1260 DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT
,
1263 if (!W_ERROR_IS_OK(werr
)) {
1264 return werror_to_ntstatus(werr
);
1266 switch (info1
.status
) {
1267 case DRSUAPI_DS_NAME_STATUS_OK
:
1269 case DRSUAPI_DS_NAME_STATUS_NOT_FOUND
:
1270 case DRSUAPI_DS_NAME_STATUS_DOMAIN_ONLY
:
1271 case DRSUAPI_DS_NAME_STATUS_NOT_UNIQUE
:
1272 return NT_STATUS_NO_SUCH_USER
;
1273 case DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR
:
1275 return NT_STATUS_UNSUCCESSFUL
;
1278 *nt4_domain
= talloc_strdup(mem_ctx
, info1
.result_name
);
1280 p
= strchr(*nt4_domain
, '\\');
1282 return NT_STATUS_INVALID_PARAMETER
;
1287 *nt4_account
= talloc_strdup(mem_ctx
, &p
[1]);
1290 if (!*nt4_account
|| !*nt4_domain
) {
1291 return NT_STATUS_NO_MEMORY
;
1294 return NT_STATUS_OK
;
1297 NTSTATUS
crack_auto_name_to_nt4_name(TALLOC_CTX
*mem_ctx
,
1298 struct tevent_context
*ev_ctx
,
1299 struct loadparm_context
*lp_ctx
,
1301 const char **nt4_domain
,
1302 const char **nt4_account
)
1304 uint32_t format_offered
= DRSUAPI_DS_NAME_FORMAT_UNKNOWN
;
1306 /* Handle anonymous bind */
1307 if (!name
|| !*name
) {
1310 return NT_STATUS_OK
;
1313 if (strchr_m(name
, '=')) {
1314 format_offered
= DRSUAPI_DS_NAME_FORMAT_FQDN_1779
;
1315 } else if (strchr_m(name
, '@')) {
1316 format_offered
= DRSUAPI_DS_NAME_FORMAT_USER_PRINCIPAL
;
1317 } else if (strchr_m(name
, '\\')) {
1318 format_offered
= DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT
;
1319 } else if (strchr_m(name
, '/')) {
1320 format_offered
= DRSUAPI_DS_NAME_FORMAT_CANONICAL
;
1322 return NT_STATUS_NO_SUCH_USER
;
1325 return crack_name_to_nt4_name(mem_ctx
, ev_ctx
, lp_ctx
, format_offered
, name
, nt4_domain
, nt4_account
);