s4:auth handle addition of nested aliases of domain groups.
[samba.git] / source4 / auth / sam.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Password and authentication handling
4    Copyright (C) Andrew Bartlett <abartlet@samba.org> 2001-2004
5    Copyright (C) Gerald Carter                             2003
6    Copyright (C) Stefan Metzmacher                         2005
7    Copyright (C) Matthias Dieter Wallnöfer                 2009
8    
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 3 of the License, or
12    (at your option) any later version.
13    
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 #include "includes.h"
24 #include "system/time.h"
25 #include "auth/auth.h"
26 #include <ldb.h>
27 #include "../lib/util/util_ldb.h"
28 #include "dsdb/samdb/samdb.h"
29 #include "libcli/security/security.h"
30 #include "libcli/ldap/ldap.h"
31 #include "../libcli/ldap/ldap_ndr.h"
32 #include "librpc/gen_ndr/ndr_netlogon.h"
33 #include "librpc/gen_ndr/ndr_security.h"
34 #include "param/param.h"
35 #include "auth/auth_sam.h"
36 #include "dsdb/common/util.h"
37
38 #define KRBTGT_ATTRS \
39         /* required for the krb5 kdc */         \
40         "objectClass",                          \
41         "sAMAccountName",                       \
42         "userPrincipalName",                    \
43         "servicePrincipalName",                 \
44         "msDS-KeyVersionNumber",                \
45         "supplementalCredentials",              \
46                                                 \
47         /* passwords */                         \
48         "dBCSPwd",                              \
49         "unicodePwd",                           \
50                                                 \
51         "userAccountControl",                   \
52         "objectSid",                            \
53                                                 \
54         "pwdLastSet",                           \
55         "accountExpires"                        
56
57 const char *krbtgt_attrs[] = {
58         KRBTGT_ATTRS
59 };
60
61 const char *server_attrs[] = {
62         KRBTGT_ATTRS
63 };
64
65 const char *user_attrs[] = {
66         KRBTGT_ATTRS,
67
68         "logonHours",
69
70         /* check 'allowed workstations' */
71         "userWorkstations",
72                        
73         /* required for server_info, not access control: */
74         "displayName",
75         "scriptPath",
76         "profilePath",
77         "homeDirectory",
78         "homeDrive",
79         "lastLogon",
80         "lastLogoff",
81         "accountExpires",
82         "badPwdCount",
83         "logonCount",
84         "primaryGroupID",
85         "memberOf",
86         NULL,
87 };
88
89 /****************************************************************************
90  Check if a user is allowed to logon at this time. Note this is the
91  servers local time, as logon hours are just specified as a weekly
92  bitmask.
93 ****************************************************************************/
94                                                                                                               
95 static bool logon_hours_ok(struct ldb_message *msg, const char *name_for_logs)
96 {
97         /* In logon hours first bit is Sunday from 12AM to 1AM */
98         const struct ldb_val *hours;
99         struct tm *utctime;
100         time_t lasttime;
101         const char *asct;
102         uint8_t bitmask, bitpos;
103
104         hours = ldb_msg_find_ldb_val(msg, "logonHours");
105         if (!hours) {
106                 DEBUG(5,("logon_hours_ok: No hours restrictions for user %s\n", name_for_logs));
107                 return true;
108         }
109
110         if (hours->length != 168/8) {
111                 DEBUG(5,("logon_hours_ok: malformed logon hours restrictions for user %s\n", name_for_logs));
112                 return true;            
113         }
114
115         lasttime = time(NULL);
116         utctime = gmtime(&lasttime);
117         if (!utctime) {
118                 DEBUG(1, ("logon_hours_ok: failed to get gmtime. Failing logon for user %s\n",
119                         name_for_logs));
120                 return false;
121         }
122
123         /* find the corresponding byte and bit */
124         bitpos = (utctime->tm_wday * 24 + utctime->tm_hour) % 168;
125         bitmask = 1 << (bitpos % 8);
126
127         if (! (hours->data[bitpos/8] & bitmask)) {
128                 struct tm *t = localtime(&lasttime);
129                 if (!t) {
130                         asct = "INVALID TIME";
131                 } else {
132                         asct = asctime(t);
133                         if (!asct) {
134                                 asct = "INVALID TIME";
135                         }
136                 }
137                 
138                 DEBUG(1, ("logon_hours_ok: Account for user %s not allowed to "
139                           "logon at this time (%s).\n",
140                           name_for_logs, asct ));
141                 return false;
142         }
143
144         asct = asctime(utctime);
145         DEBUG(5,("logon_hours_ok: user %s allowed to logon at this time (%s)\n",
146                 name_for_logs, asct ? asct : "UNKNOWN TIME" ));
147
148         return true;
149 }
150
151 /****************************************************************************
152  Do a specific test for a SAM_ACCOUNT being valid for this connection
153  (ie not disabled, expired and the like).
154 ****************************************************************************/
155 _PUBLIC_ NTSTATUS authsam_account_ok(TALLOC_CTX *mem_ctx,
156                                      struct ldb_context *sam_ctx,
157                                      uint32_t logon_parameters,
158                                      struct ldb_dn *domain_dn,
159                                      struct ldb_message *msg,
160                                      const char *logon_workstation,
161                                      const char *name_for_logs,
162                                      bool allow_domain_trust,
163                                      bool password_change)
164 {
165         uint16_t acct_flags;
166         const char *workstation_list;
167         NTTIME acct_expiry;
168         NTTIME must_change_time;
169
170         NTTIME now;
171         DEBUG(4,("authsam_account_ok: Checking SMB password for user %s\n", name_for_logs));
172
173         acct_flags = samdb_result_acct_flags(sam_ctx, mem_ctx, msg, domain_dn);
174         
175         acct_expiry = samdb_result_account_expires(msg);
176
177         /* Check for when we must change this password, taking the
178          * userAccountControl flags into account */
179         must_change_time = samdb_result_force_password_change(sam_ctx, mem_ctx, 
180                                                               domain_dn, msg);
181
182         workstation_list = samdb_result_string(msg, "userWorkstations", NULL);
183
184         /* Quit if the account was disabled. */
185         if (acct_flags & ACB_DISABLED) {
186                 DEBUG(1,("authsam_account_ok: Account for user '%s' was disabled.\n", name_for_logs));
187                 return NT_STATUS_ACCOUNT_DISABLED;
188         }
189
190         /* Quit if the account was locked out. */
191         if (acct_flags & ACB_AUTOLOCK) {
192                 DEBUG(1,("authsam_account_ok: Account for user %s was locked out.\n", name_for_logs));
193                 return NT_STATUS_ACCOUNT_LOCKED_OUT;
194         }
195
196         /* Test account expire time */
197         unix_to_nt_time(&now, time(NULL));
198         if (now > acct_expiry) {
199                 DEBUG(1,("authsam_account_ok: Account for user '%s' has expired.\n", name_for_logs));
200                 DEBUG(3,("authsam_account_ok: Account expired at '%s'.\n", 
201                          nt_time_string(mem_ctx, acct_expiry)));
202                 return NT_STATUS_ACCOUNT_EXPIRED;
203         }
204
205         /* check for immediate expiry "must change at next logon" (but not if this is a password change request) */
206         if ((must_change_time == 0) && !password_change) {
207                 DEBUG(1,("sam_account_ok: Account for user '%s' password must change!.\n", 
208                          name_for_logs));
209                 return NT_STATUS_PASSWORD_MUST_CHANGE;
210         }
211
212         /* check for expired password (but not if this is a password change request) */
213         if ((must_change_time < now) && !password_change) {
214                 DEBUG(1,("sam_account_ok: Account for user '%s' password expired!.\n", 
215                          name_for_logs));
216                 DEBUG(1,("sam_account_ok: Password expired at '%s' unix time.\n", 
217                          nt_time_string(mem_ctx, must_change_time)));
218                 return NT_STATUS_PASSWORD_EXPIRED;
219         }
220
221         /* Test workstation. Workstation list is comma separated. */
222         if (logon_workstation && workstation_list && *workstation_list) {
223                 bool invalid_ws = true;
224                 int i;
225                 const char **workstations = (const char **)str_list_make(mem_ctx, workstation_list, ",");
226                 
227                 for (i = 0; workstations && workstations[i]; i++) {
228                         DEBUG(10,("sam_account_ok: checking for workstation match '%s' and '%s'\n",
229                                   workstations[i], logon_workstation));
230
231                         if (strequal(workstations[i], logon_workstation)) {
232                                 invalid_ws = false;
233                                 break;
234                         }
235                 }
236
237                 talloc_free(workstations);
238
239                 if (invalid_ws) {
240                         return NT_STATUS_INVALID_WORKSTATION;
241                 }
242         }
243         
244         if (!logon_hours_ok(msg, name_for_logs)) {
245                 return NT_STATUS_INVALID_LOGON_HOURS;
246         }
247         
248         if (!allow_domain_trust) {
249                 if (acct_flags & ACB_DOMTRUST) {
250                         DEBUG(2,("sam_account_ok: Domain trust account %s denied by server\n", name_for_logs));
251                         return NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT;
252                 }
253         }
254         if (!(logon_parameters & MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT)) {
255                 if (acct_flags & ACB_SVRTRUST) {
256                         DEBUG(2,("sam_account_ok: Server trust account %s denied by server\n", name_for_logs));
257                         return NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT;
258                 }
259         }
260         if (!(logon_parameters & MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT)) {
261                 /* TODO: this fails with current solaris client. We
262                    need to work with Gordon to work out why */
263                 if (acct_flags & ACB_WSTRUST) {
264                         DEBUG(4,("sam_account_ok: Wksta trust account %s denied by server\n", name_for_logs));
265                         return NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT;
266                 }
267         }
268
269         return NT_STATUS_OK;
270 }
271
272 /* This function tests if a SID structure "sids" contains the SID "sid" */
273 static bool sids_contains_sid(const struct dom_sid **sids,
274                               const unsigned int num_sids,
275                               const struct dom_sid *sid)
276 {
277         unsigned int i;
278
279         for (i = 0; i < num_sids; i++) {
280                 if (dom_sid_equal(sids[i], sid))
281                         return true;
282         }
283         return false;
284 }
285
286
287 /*
288  * This function generates the transitive closure of a given SID "sid" (it
289  * basically expands nested groups of a SID).
290  * If the SID isn't located in the "res_sids" structure yet and the
291  * "only_childs" flag is negative, we add it to "res_sids".
292  * Then we've always to consider the "memberOf" attributes. We invoke the
293  * function recursively on each item of it with the "only_childs" flag set to
294  * "false".
295  * The "only_childs" flag is particularly useful if you have a user SID and
296  * want to include all his groups (referenced with "memberOf") without his SID
297  * itself, or considering if that SID matches the filter
298  *
299  * At the beginning "res_sids" should reference to a NULL pointer.
300  */
301 NTSTATUS authsam_expand_nested_groups(struct ldb_context *sam_ctx,
302                                       struct ldb_val *dn_val, const bool only_childs, const char *filter,
303                                       TALLOC_CTX *res_sids_ctx, struct dom_sid ***res_sids,
304                                       unsigned int *num_res_sids)
305 {
306         const char * const attrs[] = { "memberOf", NULL };
307         unsigned int i;
308         int ret;
309         bool already_there;
310         struct ldb_dn *dn;
311         struct dom_sid *sid;
312         TALLOC_CTX *tmp_ctx;
313         struct ldb_result *res;
314         NTSTATUS status;
315         const struct ldb_val *v;
316         const struct ldb_message_element *el;
317         enum ndr_err_code ndr_err;
318
319         if (*res_sids == NULL) {
320                 *num_res_sids = 0;
321         }
322
323         tmp_ctx = talloc_new(res_sids_ctx);
324
325         sid = talloc(tmp_ctx, struct dom_sid);
326         NT_STATUS_HAVE_NO_MEMORY_AND_FREE(sid, tmp_ctx);
327
328         dn = ldb_dn_from_ldb_val(tmp_ctx, sam_ctx, dn_val);
329         if (dn == NULL) {
330                 talloc_free(tmp_ctx);
331                 return NT_STATUS_INTERNAL_DB_CORRUPTION;
332         }
333         v = ldb_dn_get_extended_component(dn, "SID");
334
335         ndr_err = ndr_pull_struct_blob(v, sid, sid,
336                                        (ndr_pull_flags_fn_t)ndr_pull_dom_sid);
337         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
338                 talloc_free(tmp_ctx);
339                 return NT_STATUS_INTERNAL_DB_CORRUPTION;
340         }
341
342         if (only_childs) {
343                 ret = dsdb_search(sam_ctx, tmp_ctx, &res, dn, LDB_SCOPE_BASE, attrs, DSDB_SEARCH_SHOW_EXTENDED_DN, NULL);
344         } else {
345                 /* This is an O(n^2) linear search */
346                 already_there = sids_contains_sid((const struct dom_sid**) *res_sids,
347                                                   *num_res_sids, sid);
348                 if (already_there) {
349                         return NT_STATUS_OK;
350                 }
351
352                 ret = dsdb_search(sam_ctx, tmp_ctx, &res, dn, LDB_SCOPE_BASE, attrs, DSDB_SEARCH_SHOW_EXTENDED_DN, "%s", filter);
353         }
354
355         if (ret == LDB_ERR_NO_SUCH_OBJECT) {
356                 talloc_free(tmp_ctx);
357                 return NT_STATUS_OK;
358         }
359
360         if (ret != LDB_SUCCESS) {
361                 talloc_free(tmp_ctx);
362                 return NT_STATUS_INTERNAL_DB_CORRUPTION;
363         }
364
365         /* We may get back 0 results, if the SID didn't match the filter - such as it wasn't a domain group, for example */
366         if (res->count != 1) {
367                 talloc_free(tmp_ctx);
368                 return NT_STATUS_OK;
369         }
370
371         /* We only apply this test once we know the SID matches the filter */
372         if (!only_childs) {
373                 *res_sids = talloc_realloc(res_sids_ctx, *res_sids,
374                         struct dom_sid *, *num_res_sids + 1);
375                 NT_STATUS_HAVE_NO_MEMORY(*res_sids);
376                 (*res_sids)[*num_res_sids] = talloc_steal(*res_sids, sid);
377                 ++(*num_res_sids);
378         }
379
380         el = ldb_msg_find_element(res->msgs[0], "memberOf");
381
382         for (i = 0; el && i < el->num_values; i++) {
383                 status = authsam_expand_nested_groups(sam_ctx, &el->values[i],
384                                                       false, filter, res_sids_ctx, res_sids, num_res_sids);
385                 if (!NT_STATUS_IS_OK(status)) {
386                         talloc_free(res);
387                         talloc_free(tmp_ctx);
388                         return status;
389                 }
390         }
391
392         talloc_free(res);
393         talloc_free(tmp_ctx);
394
395         return NT_STATUS_OK;
396 }
397
398 _PUBLIC_ NTSTATUS authsam_make_server_info(TALLOC_CTX *mem_ctx,
399                                            struct ldb_context *sam_ctx,
400                                            const char *netbios_name,
401                                            const char *domain_name,
402                                            struct ldb_dn *domain_dn, 
403                                            struct ldb_message *msg,
404                                            DATA_BLOB user_sess_key,
405                                            DATA_BLOB lm_sess_key,
406                                            struct auth_serversupplied_info **_server_info)
407 {
408         NTSTATUS status;
409         struct auth_serversupplied_info *server_info;
410         const char *str, *filter;
411         /* SIDs for the account and his primary group */
412         struct dom_sid *account_sid;
413         struct dom_sid *primary_group_sid;
414         const char *primary_group_string;
415         const char *primary_group_dn;
416         DATA_BLOB primary_group_blob;
417         /* SID structures for the expanded group memberships */
418         struct dom_sid **groupSIDs = NULL;
419         unsigned int num_groupSIDs = 0, i;
420         struct dom_sid *domain_sid;
421         TALLOC_CTX *tmp_ctx;
422         struct ldb_message_element *el;
423
424         server_info = talloc(mem_ctx, struct auth_serversupplied_info);
425         NT_STATUS_HAVE_NO_MEMORY(server_info);
426
427         tmp_ctx = talloc_new(server_info);
428         NT_STATUS_HAVE_NO_MEMORY_AND_FREE(server_info, server_info);
429
430         account_sid = samdb_result_dom_sid(server_info, msg, "objectSid");
431         NT_STATUS_HAVE_NO_MEMORY_AND_FREE(account_sid, server_info);
432
433         status = dom_sid_split_rid(tmp_ctx, account_sid, &domain_sid, NULL);
434         if (!NT_STATUS_IS_OK(status)) {
435                 talloc_free(server_info);
436                 return status;
437         }
438
439         primary_group_sid = dom_sid_add_rid(server_info,
440                                             domain_sid,
441                                             samdb_result_uint(msg, "primaryGroupID", ~0));
442         NT_STATUS_HAVE_NO_MEMORY_AND_FREE(primary_group_sid, server_info);
443
444         /* Filter out builtin groups from this token.  We will search
445          * for builtin groups later, and not include them in the PAC
446          * on SamLogon validation info */
447         filter = talloc_asprintf(tmp_ctx, "(&(objectClass=group)(!(groupType:1.2.840.113556.1.4.803:=%u))(groupType:1.2.840.113556.1.4.803:=%u))", GROUP_TYPE_BUILTIN_LOCAL_GROUP, GROUP_TYPE_SECURITY_ENABLED);
448         NT_STATUS_HAVE_NO_MEMORY_AND_FREE(filter, server_info);
449
450         primary_group_string = dom_sid_string(tmp_ctx, primary_group_sid);
451         NT_STATUS_HAVE_NO_MEMORY_AND_FREE(primary_group_string, server_info);
452
453         primary_group_dn = talloc_asprintf(tmp_ctx, "<SID=%s>", primary_group_string);
454         NT_STATUS_HAVE_NO_MEMORY_AND_FREE(primary_group_dn, server_info);
455
456         primary_group_blob = data_blob_string_const(primary_group_dn);
457
458         /* Expands the primary group - this function takes in
459          * memberOf-like values, so we fake one up with the
460          * <SID=S-...> format of DN and then let it expand
461          * them, as long as they meet the filter - so only
462          * domain groups, not builtin groups
463          *
464          * The primary group is still treated specially, so we set the
465          * 'only childs' flag to true
466          */
467         status = authsam_expand_nested_groups(sam_ctx, &primary_group_blob, true, filter,
468                                               server_info, &groupSIDs, &num_groupSIDs);
469         if (!NT_STATUS_IS_OK(status)) {
470                 talloc_free(server_info);
471                 return status;
472         }
473
474         /* Expands the additional groups */
475         el = ldb_msg_find_element(msg, "memberOf");
476         for (i = 0; el && i < el->num_values; i++) {
477                 /* This function takes in memberOf values and expands
478                  * them, as long as they meet the filter - so only
479                  * domain groups, not builtin groups */
480                 status = authsam_expand_nested_groups(sam_ctx, &el->values[i], false, filter,
481                                                       server_info, &groupSIDs, &num_groupSIDs);
482                 if (!NT_STATUS_IS_OK(status)) {
483                         talloc_free(server_info);
484                         return status;
485                 }
486         }
487
488         server_info->account_sid = account_sid;
489         server_info->primary_group_sid = primary_group_sid;
490         
491         server_info->domain_groups = groupSIDs;
492         server_info->n_domain_groups = num_groupSIDs;
493
494         server_info->account_name = talloc_steal(server_info,
495                 samdb_result_string(msg, "sAMAccountName", NULL));
496
497         server_info->domain_name = talloc_strdup(server_info, domain_name);
498         NT_STATUS_HAVE_NO_MEMORY_AND_FREE(server_info->domain_name,
499                 server_info);
500
501         str = samdb_result_string(msg, "displayName", "");
502         server_info->full_name = talloc_strdup(server_info, str);
503         NT_STATUS_HAVE_NO_MEMORY_AND_FREE(server_info->full_name, server_info);
504
505         str = samdb_result_string(msg, "scriptPath", "");
506         server_info->logon_script = talloc_strdup(server_info, str);
507         NT_STATUS_HAVE_NO_MEMORY_AND_FREE(server_info->logon_script,
508                 server_info);
509
510         str = samdb_result_string(msg, "profilePath", "");
511         server_info->profile_path = talloc_strdup(server_info, str);
512         NT_STATUS_HAVE_NO_MEMORY_AND_FREE(server_info->profile_path,
513                 server_info);
514
515         str = samdb_result_string(msg, "homeDirectory", "");
516         server_info->home_directory = talloc_strdup(server_info, str);
517         NT_STATUS_HAVE_NO_MEMORY_AND_FREE(server_info->home_directory,
518                 server_info);
519
520         str = samdb_result_string(msg, "homeDrive", "");
521         server_info->home_drive = talloc_strdup(server_info, str);
522         NT_STATUS_HAVE_NO_MEMORY_AND_FREE(server_info->home_drive, server_info);
523
524         server_info->logon_server = talloc_strdup(server_info, netbios_name);
525         NT_STATUS_HAVE_NO_MEMORY_AND_FREE(server_info->logon_server,
526                 server_info);
527
528         server_info->last_logon = samdb_result_nttime(msg, "lastLogon", 0);
529         server_info->last_logoff = samdb_result_last_logoff(msg);
530         server_info->acct_expiry = samdb_result_account_expires(msg);
531         server_info->last_password_change = samdb_result_nttime(msg,
532                 "pwdLastSet", 0);
533         server_info->allow_password_change
534                 = samdb_result_allow_password_change(sam_ctx, mem_ctx, 
535                         domain_dn, msg, "pwdLastSet");
536         server_info->force_password_change
537                 = samdb_result_force_password_change(sam_ctx, mem_ctx,
538                         domain_dn, msg);
539         server_info->logon_count = samdb_result_uint(msg, "logonCount", 0);
540         server_info->bad_password_count = samdb_result_uint(msg, "badPwdCount",
541                 0);
542
543         server_info->acct_flags = samdb_result_acct_flags(sam_ctx, mem_ctx, 
544                                                           msg, domain_dn);
545
546         server_info->user_session_key = data_blob_talloc(server_info,
547                                                          user_sess_key.data,
548                                                          user_sess_key.length);
549         if (user_sess_key.data) {
550                 NT_STATUS_HAVE_NO_MEMORY_AND_FREE(server_info->user_session_key.data,
551                                                   server_info);
552         }
553         server_info->lm_session_key = data_blob_talloc(server_info,
554                                                        lm_sess_key.data,
555                                                        lm_sess_key.length);
556         if (lm_sess_key.data) {
557                 NT_STATUS_HAVE_NO_MEMORY_AND_FREE(server_info->lm_session_key.data,
558                                                   server_info);
559         }
560
561         server_info->authenticated = true;
562
563         talloc_free(tmp_ctx);
564         *_server_info = server_info;
565
566         return NT_STATUS_OK;
567 }
568
569 NTSTATUS sam_get_results_principal(struct ldb_context *sam_ctx,
570                                    TALLOC_CTX *mem_ctx, const char *principal,
571                                    const char **attrs,
572                                    struct ldb_dn **domain_dn,
573                                    struct ldb_message **msg)
574 {                          
575         struct ldb_dn *user_dn;
576         NTSTATUS nt_status;
577         TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
578         int ret;
579
580         if (!tmp_ctx) {
581                 return NT_STATUS_NO_MEMORY;
582         }
583
584         nt_status = crack_user_principal_name(sam_ctx, tmp_ctx, principal, 
585                                               &user_dn, domain_dn);
586         if (!NT_STATUS_IS_OK(nt_status)) {
587                 talloc_free(tmp_ctx);
588                 return nt_status;
589         }
590         
591         /* pull the user attributes */
592         ret = dsdb_search_one(sam_ctx, tmp_ctx, msg, user_dn,
593                               LDB_SCOPE_BASE, attrs, DSDB_SEARCH_SHOW_EXTENDED_DN, "(objectClass=*)");
594         if (ret != LDB_SUCCESS) {
595                 talloc_free(tmp_ctx);
596                 return NT_STATUS_INTERNAL_DB_CORRUPTION;
597         }
598         talloc_steal(mem_ctx, *msg);
599         talloc_steal(mem_ctx, *domain_dn);
600         talloc_free(tmp_ctx);
601         
602         return NT_STATUS_OK;
603 }