s4:kdc: implement samba_kdc_check_s4u2proxy()
[kai/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-2010
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 "dsdb/samdb/samdb.h"
28 #include "libcli/security/security.h"
29 #include "auth/auth_sam.h"
30 #include "dsdb/common/util.h"
31 #include "libcli/ldap/ldap_ndr.h"
32 #include "param/param.h"
33
34 #define KRBTGT_ATTRS \
35         /* required for the krb5 kdc */         \
36         "objectClass",                          \
37         "sAMAccountName",                       \
38         "userPrincipalName",                    \
39         "servicePrincipalName",                 \
40         "msDS-KeyVersionNumber",                \
41         "msDS-SecondaryKrbTgtNumber",           \
42         "msDS-SupportedEncryptionTypes",        \
43         "supplementalCredentials",              \
44         "msDS-AllowedToDelegateTo",             \
45                                                 \
46         /* passwords */                         \
47         "dBCSPwd",                              \
48         "unicodePwd",                           \
49                                                 \
50         "userAccountControl",                   \
51         "objectSid",                            \
52                                                 \
53         "pwdLastSet",                           \
54         "accountExpires"
55
56 const char *krbtgt_attrs[] = {
57         KRBTGT_ATTRS, NULL
58 };
59
60 const char *server_attrs[] = {
61         KRBTGT_ATTRS, NULL
62 };
63
64 const char *user_attrs[] = {
65         KRBTGT_ATTRS,
66
67         "logonHours",
68
69         /* check 'allowed workstations' */
70         "userWorkstations",
71                        
72         /* required for user_info_dc, not access control: */
73         "displayName",
74         "scriptPath",
75         "profilePath",
76         "homeDirectory",
77         "homeDrive",
78         "lastLogon",
79         "lastLogoff",
80         "accountExpires",
81         "badPwdCount",
82         "logonCount",
83         "primaryGroupID",
84         "memberOf",
85         NULL,
86 };
87
88 /****************************************************************************
89  Check if a user is allowed to logon at this time. Note this is the
90  servers local time, as logon hours are just specified as a weekly
91  bitmask.
92 ****************************************************************************/
93                                                                                                               
94 static bool logon_hours_ok(struct ldb_message *msg, const char *name_for_logs)
95 {
96         /* In logon hours first bit is Sunday from 12AM to 1AM */
97         const struct ldb_val *hours;
98         struct tm *utctime;
99         time_t lasttime;
100         const char *asct;
101         uint8_t bitmask, bitpos;
102
103         hours = ldb_msg_find_ldb_val(msg, "logonHours");
104         if (!hours) {
105                 DEBUG(5,("logon_hours_ok: No hours restrictions for user %s\n", name_for_logs));
106                 return true;
107         }
108
109         if (hours->length != 168/8) {
110                 DEBUG(5,("logon_hours_ok: malformed logon hours restrictions for user %s\n", name_for_logs));
111                 return true;            
112         }
113
114         lasttime = time(NULL);
115         utctime = gmtime(&lasttime);
116         if (!utctime) {
117                 DEBUG(1, ("logon_hours_ok: failed to get gmtime. Failing logon for user %s\n",
118                         name_for_logs));
119                 return false;
120         }
121
122         /* find the corresponding byte and bit */
123         bitpos = (utctime->tm_wday * 24 + utctime->tm_hour) % 168;
124         bitmask = 1 << (bitpos % 8);
125
126         if (! (hours->data[bitpos/8] & bitmask)) {
127                 struct tm *t = localtime(&lasttime);
128                 if (!t) {
129                         asct = "INVALID TIME";
130                 } else {
131                         asct = asctime(t);
132                         if (!asct) {
133                                 asct = "INVALID TIME";
134                         }
135                 }
136                 
137                 DEBUG(1, ("logon_hours_ok: Account for user %s not allowed to "
138                           "logon at this time (%s).\n",
139                           name_for_logs, asct ));
140                 return false;
141         }
142
143         asct = asctime(utctime);
144         DEBUG(5,("logon_hours_ok: user %s allowed to logon at this time (%s)\n",
145                 name_for_logs, asct ? asct : "UNKNOWN TIME" ));
146
147         return true;
148 }
149
150 /****************************************************************************
151  Do a specific test for a SAM_ACCOUNT being valid for this connection
152  (ie not disabled, expired and the like).
153 ****************************************************************************/
154 _PUBLIC_ NTSTATUS authsam_account_ok(TALLOC_CTX *mem_ctx,
155                                      struct ldb_context *sam_ctx,
156                                      uint32_t logon_parameters,
157                                      struct ldb_dn *domain_dn,
158                                      struct ldb_message *msg,
159                                      const char *logon_workstation,
160                                      const char *name_for_logs,
161                                      bool allow_domain_trust,
162                                      bool password_change)
163 {
164         uint16_t acct_flags;
165         const char *workstation_list;
166         NTTIME acct_expiry;
167         NTTIME must_change_time;
168
169         NTTIME now;
170         DEBUG(4,("authsam_account_ok: Checking SMB password for user %s\n", name_for_logs));
171
172         acct_flags = samdb_result_acct_flags(sam_ctx, mem_ctx, msg, domain_dn);
173         
174         acct_expiry = samdb_result_account_expires(msg);
175
176         /* Check for when we must change this password, taking the
177          * userAccountControl flags into account */
178         must_change_time = samdb_result_force_password_change(sam_ctx, mem_ctx, 
179                                                               domain_dn, msg);
180
181         workstation_list = ldb_msg_find_attr_as_string(msg, "userWorkstations", NULL);
182
183         /* Quit if the account was disabled. */
184         if (acct_flags & ACB_DISABLED) {
185                 DEBUG(2,("authsam_account_ok: Account for user '%s' was disabled.\n", name_for_logs));
186                 return NT_STATUS_ACCOUNT_DISABLED;
187         }
188
189         /* Quit if the account was locked out. */
190         if (acct_flags & ACB_AUTOLOCK) {
191                 DEBUG(2,("authsam_account_ok: Account for user %s was locked out.\n", name_for_logs));
192                 return NT_STATUS_ACCOUNT_LOCKED_OUT;
193         }
194
195         /* Test account expire time */
196         unix_to_nt_time(&now, time(NULL));
197         if (now > acct_expiry) {
198                 DEBUG(2,("authsam_account_ok: Account for user '%s' has expired.\n", name_for_logs));
199                 DEBUG(3,("authsam_account_ok: Account expired at '%s'.\n", 
200                          nt_time_string(mem_ctx, acct_expiry)));
201                 return NT_STATUS_ACCOUNT_EXPIRED;
202         }
203
204         /* check for immediate expiry "must change at next logon" (but not if this is a password change request) */
205         if ((must_change_time == 0) && !password_change) {
206                 DEBUG(2,("sam_account_ok: Account for user '%s' password must change!.\n",
207                          name_for_logs));
208                 return NT_STATUS_PASSWORD_MUST_CHANGE;
209         }
210
211         /* check for expired password (but not if this is a password change request) */
212         if ((must_change_time < now) && !password_change) {
213                 DEBUG(2,("sam_account_ok: Account for user '%s' password expired!.\n",
214                          name_for_logs));
215                 DEBUG(2,("sam_account_ok: Password expired at '%s' unix time.\n",
216                          nt_time_string(mem_ctx, must_change_time)));
217                 return NT_STATUS_PASSWORD_EXPIRED;
218         }
219
220         /* Test workstation. Workstation list is comma separated. */
221         if (logon_workstation && workstation_list && *workstation_list) {
222                 bool invalid_ws = true;
223                 int i;
224                 const char **workstations = (const char **)str_list_make(mem_ctx, workstation_list, ",");
225                 
226                 for (i = 0; workstations && workstations[i]; i++) {
227                         DEBUG(10,("sam_account_ok: checking for workstation match '%s' and '%s'\n",
228                                   workstations[i], logon_workstation));
229
230                         if (strequal(workstations[i], logon_workstation)) {
231                                 invalid_ws = false;
232                                 break;
233                         }
234                 }
235
236                 talloc_free(workstations);
237
238                 if (invalid_ws) {
239                         return NT_STATUS_INVALID_WORKSTATION;
240                 }
241         }
242         
243         if (!logon_hours_ok(msg, name_for_logs)) {
244                 return NT_STATUS_INVALID_LOGON_HOURS;
245         }
246         
247         if (!allow_domain_trust) {
248                 if (acct_flags & ACB_DOMTRUST) {
249                         DEBUG(2,("sam_account_ok: Domain trust account %s denied by server\n", name_for_logs));
250                         return NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT;
251                 }
252         }
253         if (!(logon_parameters & MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT)) {
254                 if (acct_flags & ACB_SVRTRUST) {
255                         DEBUG(2,("sam_account_ok: Server trust account %s denied by server\n", name_for_logs));
256                         return NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT;
257                 }
258         }
259         if (!(logon_parameters & MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT)) {
260                 /* TODO: this fails with current solaris client. We
261                    need to work with Gordon to work out why */
262                 if (acct_flags & ACB_WSTRUST) {
263                         DEBUG(4,("sam_account_ok: Wksta trust account %s denied by server\n", name_for_logs));
264                         return NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT;
265                 }
266         }
267
268         return NT_STATUS_OK;
269 }
270
271 _PUBLIC_ NTSTATUS authsam_make_user_info_dc(TALLOC_CTX *mem_ctx,
272                                            struct ldb_context *sam_ctx,
273                                            const char *netbios_name,
274                                            const char *domain_name,
275                                            struct ldb_dn *domain_dn, 
276                                            struct ldb_message *msg,
277                                            DATA_BLOB user_sess_key,
278                                            DATA_BLOB lm_sess_key,
279                                            struct auth_user_info_dc **_user_info_dc)
280 {
281         NTSTATUS status;
282         struct auth_user_info_dc *user_info_dc;
283         struct auth_user_info *info;
284         const char *str, *filter;
285         /* SIDs for the account and his primary group */
286         struct dom_sid *account_sid;
287         const char *primary_group_string;
288         const char *primary_group_dn;
289         DATA_BLOB primary_group_blob;
290         /* SID structures for the expanded group memberships */
291         struct dom_sid *sids = NULL;
292         unsigned int num_sids = 0, i;
293         struct dom_sid *domain_sid;
294         TALLOC_CTX *tmp_ctx;
295         struct ldb_message_element *el;
296
297         user_info_dc = talloc(mem_ctx, struct auth_user_info_dc);
298         NT_STATUS_HAVE_NO_MEMORY(user_info_dc);
299
300         tmp_ctx = talloc_new(user_info_dc);
301         NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info_dc, user_info_dc);
302
303         sids = talloc_array(user_info_dc, struct dom_sid, 2);
304         NT_STATUS_HAVE_NO_MEMORY_AND_FREE(sids, user_info_dc);
305
306         num_sids = 2;
307
308         account_sid = samdb_result_dom_sid(user_info_dc, msg, "objectSid");
309         NT_STATUS_HAVE_NO_MEMORY_AND_FREE(account_sid, user_info_dc);
310
311         status = dom_sid_split_rid(tmp_ctx, account_sid, &domain_sid, NULL);
312         if (!NT_STATUS_IS_OK(status)) {
313                 talloc_free(user_info_dc);
314                 return status;
315         }
316
317         sids[PRIMARY_USER_SID_INDEX] = *account_sid;
318         sids[PRIMARY_GROUP_SID_INDEX] = *domain_sid;
319         sid_append_rid(&sids[PRIMARY_GROUP_SID_INDEX], ldb_msg_find_attr_as_uint(msg, "primaryGroupID", ~0));
320
321         /* Filter out builtin groups from this token.  We will search
322          * for builtin groups later, and not include them in the PAC
323          * on SamLogon validation info */
324         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);
325         NT_STATUS_HAVE_NO_MEMORY_AND_FREE(filter, user_info_dc);
326
327         primary_group_string = dom_sid_string(tmp_ctx, &sids[PRIMARY_GROUP_SID_INDEX]);
328         NT_STATUS_HAVE_NO_MEMORY_AND_FREE(primary_group_string, user_info_dc);
329
330         primary_group_dn = talloc_asprintf(tmp_ctx, "<SID=%s>", primary_group_string);
331         NT_STATUS_HAVE_NO_MEMORY_AND_FREE(primary_group_dn, user_info_dc);
332
333         primary_group_blob = data_blob_string_const(primary_group_dn);
334
335         /* Expands the primary group - this function takes in
336          * memberOf-like values, so we fake one up with the
337          * <SID=S-...> format of DN and then let it expand
338          * them, as long as they meet the filter - so only
339          * domain groups, not builtin groups
340          *
341          * The primary group is still treated specially, so we set the
342          * 'only childs' flag to true
343          */
344         status = dsdb_expand_nested_groups(sam_ctx, &primary_group_blob, true, filter,
345                                            user_info_dc, &sids, &num_sids);
346         if (!NT_STATUS_IS_OK(status)) {
347                 talloc_free(user_info_dc);
348                 return status;
349         }
350
351         /* Expands the additional groups */
352         el = ldb_msg_find_element(msg, "memberOf");
353         for (i = 0; el && i < el->num_values; i++) {
354                 /* This function takes in memberOf values and expands
355                  * them, as long as they meet the filter - so only
356                  * domain groups, not builtin groups */
357                 status = dsdb_expand_nested_groups(sam_ctx, &el->values[i], false, filter,
358                                                    user_info_dc, &sids, &num_sids);
359                 if (!NT_STATUS_IS_OK(status)) {
360                         talloc_free(user_info_dc);
361                         return status;
362                 }
363         }
364
365         user_info_dc->sids = sids;
366         user_info_dc->num_sids = num_sids;
367
368         user_info_dc->info = info = talloc_zero(user_info_dc, struct auth_user_info);
369         NT_STATUS_HAVE_NO_MEMORY(user_info_dc->info);
370
371         info->account_name = talloc_steal(info,
372                 ldb_msg_find_attr_as_string(msg, "sAMAccountName", NULL));
373
374         info->domain_name = talloc_strdup(info, domain_name);
375         NT_STATUS_HAVE_NO_MEMORY_AND_FREE(info->domain_name,
376                 user_info_dc);
377
378         str = ldb_msg_find_attr_as_string(msg, "displayName", "");
379         info->full_name = talloc_strdup(info, str);
380         NT_STATUS_HAVE_NO_MEMORY_AND_FREE(info->full_name, user_info_dc);
381
382         str = ldb_msg_find_attr_as_string(msg, "scriptPath", "");
383         info->logon_script = talloc_strdup(info, str);
384         NT_STATUS_HAVE_NO_MEMORY_AND_FREE(info->logon_script,
385                 user_info_dc);
386
387         str = ldb_msg_find_attr_as_string(msg, "profilePath", "");
388         info->profile_path = talloc_strdup(info, str);
389         NT_STATUS_HAVE_NO_MEMORY_AND_FREE(info->profile_path,
390                 user_info_dc);
391
392         str = ldb_msg_find_attr_as_string(msg, "homeDirectory", "");
393         info->home_directory = talloc_strdup(info, str);
394         NT_STATUS_HAVE_NO_MEMORY_AND_FREE(info->home_directory,
395                 user_info_dc);
396
397         str = ldb_msg_find_attr_as_string(msg, "homeDrive", "");
398         info->home_drive = talloc_strdup(info, str);
399         NT_STATUS_HAVE_NO_MEMORY_AND_FREE(info->home_drive, user_info_dc);
400
401         info->logon_server = talloc_strdup(info, netbios_name);
402         NT_STATUS_HAVE_NO_MEMORY_AND_FREE(info->logon_server,
403                 user_info_dc);
404
405         info->last_logon = samdb_result_nttime(msg, "lastLogon", 0);
406         info->last_logoff = samdb_result_last_logoff(msg);
407         info->acct_expiry = samdb_result_account_expires(msg);
408         info->last_password_change = samdb_result_nttime(msg,
409                 "pwdLastSet", 0);
410         info->allow_password_change
411                 = samdb_result_allow_password_change(sam_ctx, mem_ctx, 
412                         domain_dn, msg, "pwdLastSet");
413         info->force_password_change
414                 = samdb_result_force_password_change(sam_ctx, mem_ctx,
415                         domain_dn, msg);
416         info->logon_count = ldb_msg_find_attr_as_uint(msg, "logonCount", 0);
417         info->bad_password_count = ldb_msg_find_attr_as_uint(msg, "badPwdCount",
418                 0);
419
420         info->acct_flags = samdb_result_acct_flags(sam_ctx, mem_ctx,
421                                                           msg, domain_dn);
422
423         user_info_dc->user_session_key = data_blob_talloc(user_info_dc,
424                                                          user_sess_key.data,
425                                                          user_sess_key.length);
426         if (user_sess_key.data) {
427                 NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info_dc->user_session_key.data,
428                                                   user_info_dc);
429         }
430         user_info_dc->lm_session_key = data_blob_talloc(user_info_dc,
431                                                        lm_sess_key.data,
432                                                        lm_sess_key.length);
433         if (lm_sess_key.data) {
434                 NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info_dc->lm_session_key.data,
435                                                   user_info_dc);
436         }
437
438         if (info->acct_flags & ACB_SVRTRUST) {
439                 /* the SID_NT_ENTERPRISE_DCS SID gets added into the
440                    PAC */
441                 user_info_dc->sids = talloc_realloc(user_info_dc,
442                                                    user_info_dc->sids,
443                                                    struct dom_sid,
444                                                    user_info_dc->num_sids+1);
445                 NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info_dc->sids, user_info_dc);
446                 user_info_dc->sids[user_info_dc->num_sids] = global_sid_Enterprise_DCs;
447                 user_info_dc->num_sids++;
448         }
449
450         if ((info->acct_flags & (ACB_PARTIAL_SECRETS_ACCOUNT | ACB_WSTRUST)) ==
451             (ACB_PARTIAL_SECRETS_ACCOUNT | ACB_WSTRUST)) {
452                 /* the DOMAIN_RID_ENTERPRISE_READONLY_DCS PAC */
453                 user_info_dc->sids = talloc_realloc(user_info_dc,
454                                                    user_info_dc->sids,
455                                                    struct dom_sid,
456                                                    user_info_dc->num_sids+1);
457                 NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info_dc->sids, user_info_dc);
458                 user_info_dc->sids[user_info_dc->num_sids] = *domain_sid;
459                 sid_append_rid(&user_info_dc->sids[user_info_dc->num_sids],
460                             DOMAIN_RID_ENTERPRISE_READONLY_DCS);
461                 user_info_dc->num_sids++;
462         }
463
464         info->authenticated = true;
465
466         talloc_free(tmp_ctx);
467         *_user_info_dc = user_info_dc;
468
469         return NT_STATUS_OK;
470 }
471
472 NTSTATUS sam_get_results_principal(struct ldb_context *sam_ctx,
473                                    TALLOC_CTX *mem_ctx, const char *principal,
474                                    const char **attrs,
475                                    struct ldb_dn **domain_dn,
476                                    struct ldb_message **msg)
477 {                          
478         struct ldb_dn *user_dn;
479         NTSTATUS nt_status;
480         TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
481         int ret;
482
483         if (!tmp_ctx) {
484                 return NT_STATUS_NO_MEMORY;
485         }
486
487         nt_status = crack_user_principal_name(sam_ctx, tmp_ctx, principal, 
488                                               &user_dn, domain_dn);
489         if (!NT_STATUS_IS_OK(nt_status)) {
490                 talloc_free(tmp_ctx);
491                 return nt_status;
492         }
493         
494         /* pull the user attributes */
495         ret = dsdb_search_one(sam_ctx, tmp_ctx, msg, user_dn,
496                               LDB_SCOPE_BASE, attrs, DSDB_SEARCH_SHOW_EXTENDED_DN, "(objectClass=*)");
497         if (ret != LDB_SUCCESS) {
498                 talloc_free(tmp_ctx);
499                 return NT_STATUS_INTERNAL_DB_CORRUPTION;
500         }
501         talloc_steal(mem_ctx, *msg);
502         talloc_steal(mem_ctx, *domain_dn);
503         talloc_free(tmp_ctx);
504         
505         return NT_STATUS_OK;
506 }
507
508 /* Used in the gensec_gssapi and gensec_krb5 server-side code, where the PAC isn't available, and for tokenGroups in the DSDB stack.
509
510  Supply either a principal or a DN
511 */
512 NTSTATUS authsam_get_user_info_dc_principal(TALLOC_CTX *mem_ctx,
513                                            struct loadparm_context *lp_ctx,
514                                            struct ldb_context *sam_ctx,
515                                            const char *principal,
516                                            struct ldb_dn *user_dn,
517                                            struct auth_user_info_dc **user_info_dc)
518 {
519         NTSTATUS nt_status;
520         DATA_BLOB user_sess_key = data_blob(NULL, 0);
521         DATA_BLOB lm_sess_key = data_blob(NULL, 0);
522
523         struct ldb_message *msg;
524         struct ldb_dn *domain_dn;
525
526         TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
527         if (!tmp_ctx) {
528                 return NT_STATUS_NO_MEMORY;
529         }
530
531         if (principal) {
532                 nt_status = sam_get_results_principal(sam_ctx, tmp_ctx, principal,
533                                                       user_attrs, &domain_dn, &msg);
534                 if (!NT_STATUS_IS_OK(nt_status)) {
535                         talloc_free(tmp_ctx);
536                         return nt_status;
537                 }
538         } else if (user_dn) {
539                 struct dom_sid *user_sid, *domain_sid;
540                 int ret;
541                 /* pull the user attributes */
542                 ret = dsdb_search_one(sam_ctx, tmp_ctx, &msg, user_dn,
543                                       LDB_SCOPE_BASE, user_attrs, DSDB_SEARCH_SHOW_EXTENDED_DN, "(objectClass=*)");
544                 if (ret == LDB_ERR_NO_SUCH_OBJECT) {
545                         talloc_free(tmp_ctx);
546                         return NT_STATUS_NO_SUCH_USER;
547                 } else if (ret != LDB_SUCCESS) {
548                         talloc_free(tmp_ctx);
549                         return NT_STATUS_INTERNAL_DB_CORRUPTION;
550                 }
551
552                 user_sid = samdb_result_dom_sid(msg, msg, "objectSid");
553
554                 nt_status = dom_sid_split_rid(tmp_ctx, user_sid, &domain_sid, NULL);
555                 if (!NT_STATUS_IS_OK(nt_status)) {
556                         return nt_status;
557                 }
558
559                 domain_dn = samdb_search_dn(sam_ctx, mem_ctx, NULL,
560                                           "(&(objectSid=%s)(objectClass=domain))",
561                                             ldap_encode_ndr_dom_sid(tmp_ctx, domain_sid));
562                 if (!domain_dn) {
563                         DEBUG(3, ("authsam_get_user_info_dc_principal: Failed to find domain with: SID %s\n",
564                                   dom_sid_string(tmp_ctx, domain_sid)));
565                         return NT_STATUS_NO_SUCH_USER;
566                 }
567
568         } else {
569                 return NT_STATUS_INVALID_PARAMETER;
570         }
571
572         nt_status = authsam_make_user_info_dc(tmp_ctx, sam_ctx,
573                                              lpcfg_netbios_name(lp_ctx),
574                                              lpcfg_workgroup(lp_ctx),
575                                              domain_dn,
576                                              msg,
577                                              user_sess_key, lm_sess_key,
578                                              user_info_dc);
579         if (!NT_STATUS_IS_OK(nt_status)) {
580                 talloc_free(tmp_ctx);
581                 return nt_status;
582         }
583
584         talloc_steal(mem_ctx, *user_info_dc);
585         talloc_free(tmp_ctx);
586
587         return NT_STATUS_OK;
588 }