s3-auth: session keys in validation level 6 samlogon replies are *not* encrypted.
[kai/samba.git] / source3 / auth / server_info.c
1 /*
2    Unix SMB/CIFS implementation.
3    Authentication utility functions
4    Copyright (C) Volker Lendecke 2010
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "includes.h"
21 #include "auth.h"
22 #include "../lib/crypto/arcfour.h"
23 #include "../librpc/gen_ndr/netlogon.h"
24 #include "../libcli/security/security.h"
25 #include "rpc_client/util_netlogon.h"
26 #include "nsswitch/libwbclient/wbclient.h"
27 #include "passdb.h"
28
29 #undef DBGC_CLASS
30 #define DBGC_CLASS DBGC_AUTH
31
32 /***************************************************************************
33  Make a server_info struct. Free with TALLOC_FREE().
34 ***************************************************************************/
35
36 struct auth_serversupplied_info *make_server_info(TALLOC_CTX *mem_ctx)
37 {
38         struct auth_serversupplied_info *result;
39
40         result = talloc_zero(mem_ctx, struct auth_serversupplied_info);
41         if (result == NULL) {
42                 DEBUG(0, ("talloc failed\n"));
43                 return NULL;
44         }
45
46         /* Initialise the uid and gid values to something non-zero
47            which may save us from giving away root access if there
48            is a bug in allocating these fields. */
49
50         result->utok.uid = -1;
51         result->utok.gid = -1;
52
53         return result;
54 }
55
56 /****************************************************************************
57  inits a netr_SamInfo2 structure from an auth_serversupplied_info. sam2 must
58  already be initialized and is used as the talloc parent for its members.
59 *****************************************************************************/
60
61 NTSTATUS serverinfo_to_SamInfo2(struct auth_serversupplied_info *server_info,
62                                 uint8_t *pipe_session_key,
63                                 size_t pipe_session_key_len,
64                                 struct netr_SamInfo2 *sam2)
65 {
66         struct netr_SamInfo3 *info3;
67
68         info3 = copy_netr_SamInfo3(sam2, server_info->info3);
69         if (!info3) {
70                 return NT_STATUS_NO_MEMORY;
71         }
72
73         if (server_info->session_key.length) {
74                 memcpy(info3->base.key.key,
75                        server_info->session_key.data,
76                        MIN(sizeof(info3->base.key.key),
77                            server_info->session_key.length));
78                 if (pipe_session_key) {
79                         arcfour_crypt(info3->base.key.key,
80                                       pipe_session_key, 16);
81                 }
82         }
83         if (server_info->lm_session_key.length) {
84                 memcpy(info3->base.LMSessKey.key,
85                        server_info->lm_session_key.data,
86                        MIN(sizeof(info3->base.LMSessKey.key),
87                            server_info->lm_session_key.length));
88                 if (pipe_session_key) {
89                         arcfour_crypt(info3->base.LMSessKey.key,
90                                       pipe_session_key, 8);
91                 }
92         }
93
94         sam2->base = info3->base;
95
96         return NT_STATUS_OK;
97 }
98
99 /****************************************************************************
100  inits a netr_SamInfo3 structure from an auth_serversupplied_info. sam3 must
101  already be initialized and is used as the talloc parent for its members.
102 *****************************************************************************/
103
104 NTSTATUS serverinfo_to_SamInfo3(const struct auth_serversupplied_info *server_info,
105                                 uint8_t *pipe_session_key,
106                                 size_t pipe_session_key_len,
107                                 struct netr_SamInfo3 *sam3)
108 {
109         struct netr_SamInfo3 *info3;
110
111         info3 = copy_netr_SamInfo3(sam3, server_info->info3);
112         if (!info3) {
113                 return NT_STATUS_NO_MEMORY;
114         }
115
116         if (server_info->session_key.length) {
117                 memcpy(info3->base.key.key,
118                        server_info->session_key.data,
119                        MIN(sizeof(info3->base.key.key),
120                            server_info->session_key.length));
121                 if (pipe_session_key) {
122                         arcfour_crypt(info3->base.key.key,
123                                       pipe_session_key, 16);
124                 }
125         }
126         if (server_info->lm_session_key.length) {
127                 memcpy(info3->base.LMSessKey.key,
128                        server_info->lm_session_key.data,
129                        MIN(sizeof(info3->base.LMSessKey.key),
130                            server_info->lm_session_key.length));
131                 if (pipe_session_key) {
132                         arcfour_crypt(info3->base.LMSessKey.key,
133                                       pipe_session_key, 8);
134                 }
135         }
136
137         sam3->base = info3->base;
138
139         sam3->sidcount          = 0;
140         sam3->sids              = NULL;
141
142         return NT_STATUS_OK;
143 }
144
145 /****************************************************************************
146  inits a netr_SamInfo6 structure from an auth_serversupplied_info. sam6 must
147  already be initialized and is used as the talloc parent for its members.
148 *****************************************************************************/
149
150 NTSTATUS serverinfo_to_SamInfo6(struct auth_serversupplied_info *server_info,
151                                 uint8_t *pipe_session_key,
152                                 size_t pipe_session_key_len,
153                                 struct netr_SamInfo6 *sam6)
154 {
155         struct pdb_domain_info *dominfo;
156         struct netr_SamInfo3 *info3;
157
158         if ((pdb_capabilities() & PDB_CAP_ADS) == 0) {
159                 DEBUG(10,("Not adding validation info level 6 "
160                            "without ADS passdb backend\n"));
161                 return NT_STATUS_INVALID_INFO_CLASS;
162         }
163
164         dominfo = pdb_get_domain_info(sam6);
165         if (dominfo == NULL) {
166                 return NT_STATUS_NO_MEMORY;
167         }
168
169         info3 = copy_netr_SamInfo3(sam6, server_info->info3);
170         if (!info3) {
171                 return NT_STATUS_NO_MEMORY;
172         }
173
174         if (server_info->session_key.length) {
175                 memcpy(info3->base.key.key,
176                        server_info->session_key.data,
177                        MIN(sizeof(info3->base.key.key),
178                            server_info->session_key.length));
179         }
180         if (server_info->lm_session_key.length) {
181                 memcpy(info3->base.LMSessKey.key,
182                        server_info->lm_session_key.data,
183                        MIN(sizeof(info3->base.LMSessKey.key),
184                            server_info->lm_session_key.length));
185         }
186
187         sam6->base = info3->base;
188
189         sam6->sidcount          = 0;
190         sam6->sids              = NULL;
191
192         sam6->dns_domainname.string = talloc_strdup(sam6, dominfo->dns_domain);
193         if (sam6->dns_domainname.string == NULL) {
194                 return NT_STATUS_NO_MEMORY;
195         }
196
197         sam6->principle.string  = talloc_asprintf(sam6, "%s@%s",
198                                                   sam6->base.account_name.string,
199                                                   sam6->dns_domainname.string);
200         if (sam6->principle.string == NULL) {
201                 return NT_STATUS_NO_MEMORY;
202         }
203
204         return NT_STATUS_OK;
205 }
206
207 static NTSTATUS append_netr_SidAttr(TALLOC_CTX *mem_ctx,
208                                     struct netr_SidAttr **sids,
209                                     uint32_t *count,
210                                     const struct dom_sid2 *asid,
211                                     uint32_t attributes)
212 {
213         uint32_t t = *count;
214
215         *sids = talloc_realloc(mem_ctx, *sids, struct netr_SidAttr, t + 1);
216         if (*sids == NULL) {
217                 return NT_STATUS_NO_MEMORY;
218         }
219         (*sids)[t].sid = dom_sid_dup(*sids, asid);
220         if ((*sids)[t].sid == NULL) {
221                 return NT_STATUS_NO_MEMORY;
222         }
223         (*sids)[t].attributes = attributes;
224         *count = t + 1;
225
226         return NT_STATUS_OK;
227 }
228
229 /* Fills the samr_RidWithAttributeArray with the provided sids.
230  * If it happens that we have additional groups that do not belong
231  * to the domain, add their sids as extra sids */
232 static NTSTATUS group_sids_to_info3(struct netr_SamInfo3 *info3,
233                                     const struct dom_sid *sids,
234                                     size_t num_sids)
235 {
236         uint32_t attributes = SE_GROUP_MANDATORY |
237                                 SE_GROUP_ENABLED_BY_DEFAULT |
238                                 SE_GROUP_ENABLED;
239         struct samr_RidWithAttributeArray *groups;
240         struct dom_sid *domain_sid;
241         unsigned int i;
242         NTSTATUS status;
243         uint32_t rid;
244         bool ok;
245
246         domain_sid = info3->base.domain_sid;
247         groups = &info3->base.groups;
248
249         groups->rids = talloc_array(info3,
250                                     struct samr_RidWithAttribute, num_sids);
251         if (!groups->rids) {
252                 return NT_STATUS_NO_MEMORY;
253         }
254
255         for (i = 0; i < num_sids; i++) {
256                 ok = sid_peek_check_rid(domain_sid, &sids[i], &rid);
257                 if (ok) {
258                         /* store domain group rid */
259                         groups->rids[groups->count].rid = rid;
260                         groups->rids[groups->count].attributes = attributes;
261                         groups->count++;
262                         continue;
263                 }
264
265                 /* if this wasn't a domain sid, add it as extra sid */
266                 status = append_netr_SidAttr(info3, &info3->sids,
267                                              &info3->sidcount,
268                                              &sids[i], attributes);
269                 if (!NT_STATUS_IS_OK(status)) {
270                         return status;
271                 }
272         }
273
274         return NT_STATUS_OK;
275 }
276
277 #define RET_NOMEM(ptr) do { \
278         if (!ptr) { \
279                 TALLOC_FREE(info3); \
280                 return NT_STATUS_NO_MEMORY; \
281         } } while(0)
282
283 NTSTATUS samu_to_SamInfo3(TALLOC_CTX *mem_ctx,
284                           struct samu *samu,
285                           const char *login_server,
286                           struct netr_SamInfo3 **_info3,
287                           struct extra_auth_info *extra)
288 {
289         struct netr_SamInfo3 *info3;
290         const struct dom_sid *user_sid;
291         const struct dom_sid *group_sid;
292         struct dom_sid domain_sid;
293         struct dom_sid *group_sids;
294         uint32_t num_group_sids = 0;
295         const char *tmp;
296         gid_t *gids;
297         NTSTATUS status;
298         bool ok;
299
300         user_sid = pdb_get_user_sid(samu);
301         group_sid = pdb_get_group_sid(samu);
302
303         if (!user_sid || !group_sid) {
304                 DEBUG(1, ("Sam account is missing sids!\n"));
305                 return NT_STATUS_UNSUCCESSFUL;
306         }
307
308         info3 = talloc_zero(mem_ctx, struct netr_SamInfo3);
309         if (!info3) {
310                 return NT_STATUS_NO_MEMORY;
311         }
312
313         ZERO_STRUCT(domain_sid);
314
315         /* check if this is a "Unix Users" domain user,
316          * we need to handle it in a special way if that's the case */
317         if (sid_check_is_in_unix_users(user_sid)) {
318                 /* in info3 you can only set rids for the user and the
319                  * primary group, and the domain sid must be that of
320                  * the sam domain.
321                  *
322                  * Store a completely bogus value here.
323                  * The real SID is stored in the extra sids.
324                  * Other code will know to look there if (-1) is found
325                  */
326                 info3->base.rid = (uint32_t)(-1);
327                 sid_copy(&extra->user_sid, user_sid);
328
329                 DEBUG(10, ("Unix User found in struct samu. Rid marked as "
330                            "special and sid (%s) saved as extra sid\n",
331                            sid_string_dbg(user_sid)));
332         } else {
333                 sid_copy(&domain_sid, user_sid);
334                 sid_split_rid(&domain_sid, &info3->base.rid);
335         }
336
337         if (is_null_sid(&domain_sid)) {
338                 sid_copy(&domain_sid, get_global_sam_sid());
339         }
340
341         /* check if this is a "Unix Groups" domain group,
342          * if so we need special handling */
343         if (sid_check_is_in_unix_groups(group_sid)) {
344                 /* in info3 you can only set rids for the user and the
345                  * primary group, and the domain sid must be that of
346                  * the sam domain.
347                  *
348                  * Store a completely bogus value here.
349                  * The real SID is stored in the extra sids.
350                  * Other code will know to look there if (-1) is found
351                  */
352                 info3->base.primary_gid = (uint32_t)(-1);
353                 sid_copy(&extra->pgid_sid, group_sid);
354
355                 DEBUG(10, ("Unix Group found in struct samu. Rid marked as "
356                            "special and sid (%s) saved as extra sid\n",
357                            sid_string_dbg(group_sid)));
358
359         } else {
360                 ok = sid_peek_check_rid(&domain_sid, group_sid,
361                                         &info3->base.primary_gid);
362                 if (!ok) {
363                         DEBUG(1, ("The primary group domain sid(%s) does not "
364                                   "match the domain sid(%s) for %s(%s)\n",
365                                   sid_string_dbg(group_sid),
366                                   sid_string_dbg(&domain_sid),
367                                   pdb_get_username(samu),
368                                   sid_string_dbg(user_sid)));
369                         TALLOC_FREE(info3);
370                         return NT_STATUS_UNSUCCESSFUL;
371                 }
372         }
373
374         unix_to_nt_time(&info3->base.logon_time, pdb_get_logon_time(samu));
375         unix_to_nt_time(&info3->base.logoff_time, get_time_t_max());
376         unix_to_nt_time(&info3->base.kickoff_time, get_time_t_max());
377         unix_to_nt_time(&info3->base.last_password_change,
378                         pdb_get_pass_last_set_time(samu));
379         unix_to_nt_time(&info3->base.allow_password_change,
380                         pdb_get_pass_can_change_time(samu));
381         unix_to_nt_time(&info3->base.force_password_change,
382                         pdb_get_pass_must_change_time(samu));
383
384         tmp = pdb_get_username(samu);
385         if (tmp) {
386                 info3->base.account_name.string = talloc_strdup(info3, tmp);
387                 RET_NOMEM(info3->base.account_name.string);
388         }
389         tmp = pdb_get_fullname(samu);
390         if (tmp) {
391                 info3->base.full_name.string = talloc_strdup(info3, tmp);
392                 RET_NOMEM(info3->base.full_name.string);
393         }
394         tmp = pdb_get_logon_script(samu);
395         if (tmp) {
396                 info3->base.logon_script.string = talloc_strdup(info3, tmp);
397                 RET_NOMEM(info3->base.logon_script.string);
398         }
399         tmp = pdb_get_profile_path(samu);
400         if (tmp) {
401                 info3->base.profile_path.string = talloc_strdup(info3, tmp);
402                 RET_NOMEM(info3->base.profile_path.string);
403         }
404         tmp = pdb_get_homedir(samu);
405         if (tmp) {
406                 info3->base.home_directory.string = talloc_strdup(info3, tmp);
407                 RET_NOMEM(info3->base.home_directory.string);
408         }
409         tmp = pdb_get_dir_drive(samu);
410         if (tmp) {
411                 info3->base.home_drive.string = talloc_strdup(info3, tmp);
412                 RET_NOMEM(info3->base.home_drive.string);
413         }
414
415         info3->base.logon_count = pdb_get_logon_count(samu);
416         info3->base.bad_password_count = pdb_get_bad_password_count(samu);
417
418         info3->base.logon_domain.string = talloc_strdup(info3,
419                                                   pdb_get_domain(samu));
420         RET_NOMEM(info3->base.logon_domain.string);
421
422         info3->base.domain_sid = dom_sid_dup(info3, &domain_sid);
423         RET_NOMEM(info3->base.domain_sid);
424
425         status = pdb_enum_group_memberships(mem_ctx, samu,
426                                             &group_sids, &gids,
427                                             &num_group_sids);
428         if (!NT_STATUS_IS_OK(status)) {
429                 DEBUG(1, ("Failed to get groups from sam account.\n"));
430                 TALLOC_FREE(info3);
431                 return status;
432         }
433
434         if (num_group_sids) {
435                 status = group_sids_to_info3(info3, group_sids, num_group_sids);
436                 if (!NT_STATUS_IS_OK(status)) {
437                         TALLOC_FREE(info3);
438                         return status;
439                 }
440         }
441
442         /* We don't need sids and gids after the conversion */
443         TALLOC_FREE(group_sids);
444         TALLOC_FREE(gids);
445         num_group_sids = 0;
446
447         /* FIXME: should we add other flags ? */
448         info3->base.user_flags = NETLOGON_EXTRA_SIDS;
449
450         if (login_server) {
451                 info3->base.logon_server.string = talloc_strdup(info3, login_server);
452                 RET_NOMEM(info3->base.logon_server.string);
453         }
454
455         info3->base.acct_flags = pdb_get_acct_ctrl(samu);
456
457         *_info3 = info3;
458         return NT_STATUS_OK;
459 }
460
461 #undef RET_NOMEM
462
463 #define RET_NOMEM(ptr) do { \
464         if (!ptr) { \
465                 TALLOC_FREE(info3); \
466                 return NULL; \
467         } } while(0)
468
469 struct netr_SamInfo3 *copy_netr_SamInfo3(TALLOC_CTX *mem_ctx,
470                                          struct netr_SamInfo3 *orig)
471 {
472         struct netr_SamInfo3 *info3;
473         unsigned int i;
474         NTSTATUS status;
475
476         info3 = talloc_zero(mem_ctx, struct netr_SamInfo3);
477         if (!info3) return NULL;
478
479         status = copy_netr_SamBaseInfo(info3, &orig->base, &info3->base);
480         if (!NT_STATUS_IS_OK(status)) {
481                 TALLOC_FREE(info3);
482                 return NULL;
483         }
484
485         if (orig->sidcount) {
486                 info3->sidcount = orig->sidcount;
487                 info3->sids = talloc_array(info3, struct netr_SidAttr,
488                                            orig->sidcount);
489                 RET_NOMEM(info3->sids);
490                 for (i = 0; i < orig->sidcount; i++) {
491                         info3->sids[i].sid = dom_sid_dup(info3->sids,
492                                                             orig->sids[i].sid);
493                         RET_NOMEM(info3->sids[i].sid);
494                         info3->sids[i].attributes =
495                                 orig->sids[i].attributes;
496                 }
497         }
498
499         return info3;
500 }
501
502 static NTSTATUS wbcsids_to_samr_RidWithAttributeArray(
503                                 TALLOC_CTX *mem_ctx,
504                                 struct samr_RidWithAttributeArray *groups,
505                                 const struct dom_sid *domain_sid,
506                                 const struct wbcSidWithAttr *sids,
507                                 size_t num_sids)
508 {
509         unsigned int i, j = 0;
510         bool ok;
511
512         groups->rids = talloc_array(mem_ctx,
513                                     struct samr_RidWithAttribute, num_sids);
514         if (!groups->rids) {
515                 return NT_STATUS_NO_MEMORY;
516         }
517
518         /* a wbcDomainSid is the same as a dom_sid */
519         for (i = 0; i < num_sids; i++) {
520                 ok = sid_peek_check_rid(domain_sid,
521                                         (const struct dom_sid *)&sids[i].sid,
522                                         &groups->rids[j].rid);
523                 if (!ok) continue;
524
525                 groups->rids[j].attributes = SE_GROUP_MANDATORY |
526                                              SE_GROUP_ENABLED_BY_DEFAULT |
527                                              SE_GROUP_ENABLED;
528                 j++;
529         }
530
531         groups->count = j;
532         return NT_STATUS_OK;
533 }
534
535 static NTSTATUS wbcsids_to_netr_SidAttrArray(
536                                 const struct dom_sid *domain_sid,
537                                 const struct wbcSidWithAttr *sids,
538                                 size_t num_sids,
539                                 TALLOC_CTX *mem_ctx,
540                                 struct netr_SidAttr **_info3_sids,
541                                 uint32_t *info3_num_sids)
542 {
543         unsigned int i, j = 0;
544         struct netr_SidAttr *info3_sids;
545
546         info3_sids = talloc_array(mem_ctx, struct netr_SidAttr, num_sids);
547         if (info3_sids == NULL) {
548                 return NT_STATUS_NO_MEMORY;
549         }
550
551         /* a wbcDomainSid is the same as a dom_sid */
552         for (i = 0; i < num_sids; i++) {
553                 const struct dom_sid *sid;
554
555                 sid = (const struct dom_sid *)&sids[i].sid;
556
557                 if (dom_sid_in_domain(domain_sid, sid)) {
558                         continue;
559                 }
560
561                 info3_sids[j].sid = dom_sid_dup(info3_sids, sid);
562                 if (info3_sids[j].sid == NULL) {
563                         talloc_free(info3_sids);
564                         return NT_STATUS_NO_MEMORY;
565                 }
566                 info3_sids[j].attributes = SE_GROUP_MANDATORY |
567                                            SE_GROUP_ENABLED_BY_DEFAULT |
568                                            SE_GROUP_ENABLED;
569                 j++;
570         }
571
572         *info3_num_sids = j;
573         *_info3_sids = info3_sids;
574         return NT_STATUS_OK;
575 }
576
577 struct netr_SamInfo3 *wbcAuthUserInfo_to_netr_SamInfo3(TALLOC_CTX *mem_ctx,
578                                         const struct wbcAuthUserInfo *info)
579 {
580         struct netr_SamInfo3 *info3;
581         struct dom_sid user_sid;
582         struct dom_sid group_sid;
583         struct dom_sid domain_sid;
584         NTSTATUS status;
585         bool ok;
586
587         memcpy(&user_sid, &info->sids[0].sid, sizeof(user_sid));
588         memcpy(&group_sid, &info->sids[1].sid, sizeof(group_sid));
589
590         info3 = talloc_zero(mem_ctx, struct netr_SamInfo3);
591         if (!info3) return NULL;
592
593         info3->base.logon_time = info->logon_time;
594         info3->base.logoff_time = info->logoff_time;
595         info3->base.kickoff_time = info->kickoff_time;
596         unix_to_nt_time(&info3->base.last_password_change, info->pass_last_set_time);
597         unix_to_nt_time(&info3->base.allow_password_change,
598                         info->pass_can_change_time);
599         unix_to_nt_time(&info3->base.force_password_change,
600                         info->pass_must_change_time);
601
602         if (info->account_name) {
603                 info3->base.account_name.string =
604                                 talloc_strdup(info3, info->account_name);
605                 RET_NOMEM(info3->base.account_name.string);
606         }
607         if (info->full_name) {
608                 info3->base.full_name.string =
609                                 talloc_strdup(info3, info->full_name);
610                 RET_NOMEM(info3->base.full_name.string);
611         }
612         if (info->logon_script) {
613                 info3->base.logon_script.string =
614                                 talloc_strdup(info3, info->logon_script);
615                 RET_NOMEM(info3->base.logon_script.string);
616         }
617         if (info->profile_path) {
618                 info3->base.profile_path.string =
619                                 talloc_strdup(info3, info->profile_path);
620                 RET_NOMEM(info3->base.profile_path.string);
621         }
622         if (info->home_directory) {
623                 info3->base.home_directory.string =
624                                 talloc_strdup(info3, info->home_directory);
625                 RET_NOMEM(info3->base.home_directory.string);
626         }
627         if (info->home_drive) {
628                 info3->base.home_drive.string =
629                                 talloc_strdup(info3, info->home_drive);
630                 RET_NOMEM(info3->base.home_drive.string);
631         }
632
633         info3->base.logon_count = info->logon_count;
634         info3->base.bad_password_count = info->bad_password_count;
635
636         sid_copy(&domain_sid, &user_sid);
637         sid_split_rid(&domain_sid, &info3->base.rid);
638
639         ok = sid_peek_check_rid(&domain_sid, &group_sid,
640                                 &info3->base.primary_gid);
641         if (!ok) {
642                 DEBUG(1, ("The primary group sid domain does not"
643                           "match user sid domain for user: %s\n",
644                           info->account_name));
645                 TALLOC_FREE(info3);
646                 return NULL;
647         }
648
649         status = wbcsids_to_samr_RidWithAttributeArray(info3,
650                                                        &info3->base.groups,
651                                                        &domain_sid,
652                                                        &info->sids[1],
653                                                        info->num_sids - 1);
654         if (!NT_STATUS_IS_OK(status)) {
655                 TALLOC_FREE(info3);
656                 return NULL;
657         }
658
659         status = wbcsids_to_netr_SidAttrArray(&domain_sid,
660                                               &info->sids[1],
661                                               info->num_sids - 1,
662                                               info3,
663                                               &info3->sids,
664                                               &info3->sidcount);
665         if (!NT_STATUS_IS_OK(status)) {
666                 TALLOC_FREE(info3);
667                 return NULL;
668         }
669
670         info3->base.user_flags = info->user_flags;
671         memcpy(info3->base.key.key, info->user_session_key, 16);
672
673         if (info->logon_server) {
674                 info3->base.logon_server.string =
675                                 talloc_strdup(info3, info->logon_server);
676                 RET_NOMEM(info3->base.logon_server.string);
677         }
678         if (info->domain_name) {
679                 info3->base.logon_domain.string =
680                                 talloc_strdup(info3, info->domain_name);
681                 RET_NOMEM(info3->base.logon_domain.string);
682         }
683
684         info3->base.domain_sid = dom_sid_dup(info3, &domain_sid);
685         RET_NOMEM(info3->base.domain_sid);
686
687         memcpy(info3->base.LMSessKey.key, info->lm_session_key, 8);
688         info3->base.acct_flags = info->acct_flags;
689
690         return info3;
691 }