Globally replace 'global_sam_sid' with get_global_sam_sid(), a self
[samba.git] / source3 / rpc_server / srv_netlog_nt.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  RPC Pipe client / server routines
4  *  Copyright (C) Andrew Tridgell              1992-1997,
5  *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
6  *  Copyright (C) Paul Ashton                       1997.
7  *  Copyright (C) Jeremy Allison               1998-2001.
8  *  Copyirht  (C) Andrew Bartlett                   2001.
9  *
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 2 of the License, or
13  *  (at your option) any later version.
14  *  
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.
19  *  
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program; if not, write to the Free Software
22  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  */
24
25 /* This is the implementation of the netlogon pipe. */
26
27 #include "includes.h"
28
29 extern pstring global_myname;
30
31 /*************************************************************************
32  init_net_r_req_chal:
33  *************************************************************************/
34
35 static void init_net_r_req_chal(NET_R_REQ_CHAL *r_c,
36                                 DOM_CHAL *srv_chal, NTSTATUS status)
37 {
38         DEBUG(6,("init_net_r_req_chal: %d\n", __LINE__));
39         memcpy(r_c->srv_chal.data, srv_chal->data, sizeof(srv_chal->data));
40         r_c->status = status;
41 }
42
43 /*************************************************************************
44  error messages cropping up when using nltest.exe...
45  *************************************************************************/
46
47 #define ERROR_NO_SUCH_DOMAIN   0x54b
48 #define ERROR_NO_LOGON_SERVERS 0x51f
49
50 /*************************************************************************
51  net_reply_logon_ctrl:
52  *************************************************************************/
53
54 /* Some flag values reverse engineered from NLTEST.EXE */
55
56 #define LOGON_CTRL_IN_SYNC          0x00
57 #define LOGON_CTRL_REPL_NEEDED      0x01
58 #define LOGON_CTRL_REPL_IN_PROGRESS 0x02
59
60 NTSTATUS _net_logon_ctrl(pipes_struct *p, NET_Q_LOGON_CTRL *q_u, 
61                        NET_R_LOGON_CTRL *r_u)
62 {
63         uint32 flags = 0x0;
64         uint32 pdc_connection_status = 0x00; /* Maybe a win32 error code? */
65         
66         /* Setup the Logon Control response */
67
68         init_net_r_logon_ctrl(r_u, q_u->query_level, flags, 
69                               pdc_connection_status);
70
71         return r_u->status;
72 }
73
74 /****************************************************************************
75 Send a message to smbd to do a sam synchronisation
76 **************************************************************************/
77 static void send_sync_message(void)
78 {
79         TDB_CONTEXT *tdb;
80
81         tdb = tdb_open_log(lock_path("connections.tdb"), 0,
82                            TDB_DEFAULT, O_RDONLY, 0);
83
84         if (!tdb) {
85                 DEBUG(3, ("send_sync_message(): failed to open connections "
86                           "database\n"));
87                 return;
88         }
89
90         DEBUG(3, ("sending sam synchronisation message\n"));
91         
92         message_send_all(tdb, MSG_SMB_SAM_SYNC, NULL, 0, False, NULL);
93
94         tdb_close(tdb);
95 }
96
97 /*************************************************************************
98  net_reply_logon_ctrl2:
99  *************************************************************************/
100
101 NTSTATUS _net_logon_ctrl2(pipes_struct *p, NET_Q_LOGON_CTRL2 *q_u, NET_R_LOGON_CTRL2 *r_u)
102 {
103         uint32 flags = 0x0;
104         uint32 pdc_connection_status = 0x0;
105         uint32 logon_attempts = 0x0;
106         uint32 tc_status = ERROR_NO_LOGON_SERVERS;
107         char *trusted_domain = "test_domain";
108
109         DEBUG(0, ("*** net long ctrl2 %d, %d, %d\n",
110                   q_u->function_code, q_u->query_level, q_u->switch_value));
111
112         DEBUG(6,("_net_logon_ctrl2: %d\n", __LINE__));
113
114
115         /* set up the Logon Control2 response */
116         init_net_r_logon_ctrl2(r_u, q_u->query_level,
117                                flags, pdc_connection_status, logon_attempts,
118                                tc_status, trusted_domain);
119
120         if (lp_server_role() == ROLE_DOMAIN_BDC)
121                 send_sync_message();
122
123         DEBUG(6,("_net_logon_ctrl2: %d\n", __LINE__));
124
125         return r_u->status;
126 }
127
128 /*************************************************************************
129  net_reply_trust_dom_list:
130  *************************************************************************/
131
132 NTSTATUS _net_trust_dom_list(pipes_struct *p, NET_Q_TRUST_DOM_LIST *q_u, NET_R_TRUST_DOM_LIST *r_u)
133 {
134         char *trusted_domain = "test_domain";
135         uint32 num_trust_domains = 1;
136
137         DEBUG(6,("_net_trust_dom_list: %d\n", __LINE__));
138
139         /* set up the Trusted Domain List response */
140         init_r_trust_dom(r_u, num_trust_domains, trusted_domain);
141
142         DEBUG(6,("_net_trust_dom_list: %d\n", __LINE__));
143
144         return r_u->status;
145 }
146
147 /***********************************************************************************
148  init_net_r_srv_pwset:
149  ***********************************************************************************/
150
151 static void init_net_r_srv_pwset(NET_R_SRV_PWSET *r_s,
152                                  DOM_CRED *srv_cred, NTSTATUS status)  
153 {
154         DEBUG(5,("init_net_r_srv_pwset: %d\n", __LINE__));
155
156         memcpy(&r_s->srv_cred, srv_cred, sizeof(r_s->srv_cred));
157         r_s->status = status;
158
159         DEBUG(5,("init_net_r_srv_pwset: %d\n", __LINE__));
160 }
161
162 /******************************************************************
163  gets a machine password entry.  checks access rights of the host.
164  ******************************************************************/
165
166 static BOOL get_md4pw(char *md4pw, char *mach_acct)
167 {
168         SAM_ACCOUNT *sampass = NULL;
169         const uint8 *pass;
170         BOOL ret;
171         uint32 acct_ctrl;
172
173 #if 0
174     /*
175      * Currently this code is redundent as we already have a filter
176      * by hostname list. What this code really needs to do is to 
177      * get a hosts allowed/hosts denied list from the SAM database
178      * on a per user basis, and make the access decision there.
179      * I will leave this code here for now as a reminder to implement
180      * this at a later date. JRA.
181      */
182
183         if (!allow_access(lp_domain_hostsdeny(), lp_domain_hostsallow(),
184                           client_name(), client_addr()))
185         {
186                 DEBUG(0,("get_md4pw: Workstation %s denied access to domain\n", mach_acct));
187                 return False;
188         }
189 #endif /* 0 */
190
191         if(!NT_STATUS_IS_OK(pdb_init_sam(&sampass)))
192                 return False;
193
194         /* JRA. This is ok as it is only used for generating the challenge. */
195         become_root();
196         ret=pdb_getsampwnam(sampass, mach_acct);
197         unbecome_root();
198  
199         if (ret==False) {
200                 DEBUG(0,("get_md4pw: Workstation %s: no account in domain\n", mach_acct));
201                 pdb_free_sam(&sampass);
202                 return False;
203         }
204
205         acct_ctrl = pdb_get_acct_ctrl(sampass);
206         if (!(acct_ctrl & ACB_DISABLED) &&
207             ((acct_ctrl & ACB_DOMTRUST) ||
208              (acct_ctrl & ACB_WSTRUST) ||
209              (acct_ctrl & ACB_SVRTRUST)) &&
210             ((pass=pdb_get_nt_passwd(sampass)) != NULL)) {
211                 memcpy(md4pw, pass, 16);
212                 dump_data(5, md4pw, 16);
213                 pdb_free_sam(&sampass);
214                 return True;
215         }
216         
217         DEBUG(0,("get_md4pw: Workstation %s: no account in domain\n", mach_acct));
218         pdb_free_sam(&sampass);
219         return False;
220
221 }
222
223 /*************************************************************************
224  _net_req_chal
225  *************************************************************************/
226
227 NTSTATUS _net_req_chal(pipes_struct *p, NET_Q_REQ_CHAL *q_u, NET_R_REQ_CHAL *r_u)
228 {
229         NTSTATUS status = NT_STATUS_OK;
230
231         rpcstr_pull(p->dc.remote_machine,q_u->uni_logon_clnt.buffer,sizeof(fstring),q_u->uni_logon_clnt.uni_str_len*2,0);
232
233         /* create a server challenge for the client */
234         /* Set these to random values. */
235         generate_random_buffer(p->dc.srv_chal.data, 8, False);
236         
237         memcpy(p->dc.srv_cred.challenge.data, p->dc.srv_chal.data, 8);
238
239         memcpy(p->dc.clnt_chal.data          , q_u->clnt_chal.data, sizeof(q_u->clnt_chal.data));
240         memcpy(p->dc.clnt_cred.challenge.data, q_u->clnt_chal.data, sizeof(q_u->clnt_chal.data));
241
242         memset((char *)p->dc.sess_key, '\0', sizeof(p->dc.sess_key));
243
244         p->dc.challenge_sent = True;
245         /* set up the LSA REQUEST CHALLENGE response */
246         init_net_r_req_chal(r_u, &p->dc.srv_chal, status);
247         
248         return status;
249 }
250
251 /*************************************************************************
252  init_net_r_auth:
253  *************************************************************************/
254
255 static void init_net_r_auth(NET_R_AUTH *r_a, DOM_CHAL *resp_cred, NTSTATUS status)
256 {
257         memcpy(r_a->srv_chal.data, resp_cred->data, sizeof(resp_cred->data));
258         r_a->status = status;
259 }
260
261 /*************************************************************************
262  _net_auth
263  *************************************************************************/
264
265 NTSTATUS _net_auth(pipes_struct *p, NET_Q_AUTH *q_u, NET_R_AUTH *r_u)
266 {
267         NTSTATUS status = NT_STATUS_OK;
268         DOM_CHAL srv_cred;
269         UTIME srv_time;
270         fstring mach_acct;
271
272         srv_time.time = 0;
273
274         rpcstr_pull(mach_acct, q_u->clnt_id.uni_acct_name.buffer,sizeof(fstring),q_u->clnt_id.uni_acct_name.uni_str_len*2,0);
275
276         if (p->dc.challenge_sent && get_md4pw((char *)p->dc.md4pw, mach_acct)) {
277
278                 /* from client / server challenges and md4 password, generate sess key */
279                 cred_session_key(&p->dc.clnt_chal, &p->dc.srv_chal,
280                                  (char *)p->dc.md4pw, p->dc.sess_key);
281                 
282                 /* check that the client credentials are valid */
283                 if (cred_assert(&q_u->clnt_chal, p->dc.sess_key, &p->dc.clnt_cred.challenge, srv_time)) {
284                         
285                         /* create server challenge for inclusion in the reply */
286                         cred_create(p->dc.sess_key, &p->dc.srv_cred.challenge, srv_time, &srv_cred);
287                 
288                         /* copy the received client credentials for use next time */
289                         memcpy(p->dc.clnt_cred.challenge.data, q_u->clnt_chal.data, sizeof(q_u->clnt_chal.data));
290                         memcpy(p->dc.srv_cred .challenge.data, q_u->clnt_chal.data, sizeof(q_u->clnt_chal.data));
291                         
292                         /* Save the machine account name. */
293                         fstrcpy(p->dc.mach_acct, mach_acct);
294                 
295                         p->dc.authenticated = True;
296
297                 } else {
298                         status = NT_STATUS_ACCESS_DENIED;
299                 }
300         } else {
301                 status = NT_STATUS_ACCESS_DENIED;
302         }
303         
304         /* set up the LSA AUTH response */
305         init_net_r_auth(r_u, &srv_cred, status);
306
307         return r_u->status;
308 }
309
310 /*************************************************************************
311  init_net_r_auth_2:
312  *************************************************************************/
313
314 static void init_net_r_auth_2(NET_R_AUTH_2 *r_a,
315                               DOM_CHAL *resp_cred, NEG_FLAGS *flgs, NTSTATUS status)
316 {
317         memcpy(r_a->srv_chal.data, resp_cred->data, sizeof(resp_cred->data));
318         memcpy(&r_a->srv_flgs, flgs, sizeof(r_a->srv_flgs));
319         r_a->status = status;
320 }
321
322 /*************************************************************************
323  _net_auth_2
324  *************************************************************************/
325
326 NTSTATUS _net_auth_2(pipes_struct *p, NET_Q_AUTH_2 *q_u, NET_R_AUTH_2 *r_u)
327 {
328         NTSTATUS status = NT_STATUS_OK;
329         DOM_CHAL srv_cred;
330         UTIME srv_time;
331         NEG_FLAGS srv_flgs;
332         fstring mach_acct;
333
334         srv_time.time = 0;
335
336         rpcstr_pull(mach_acct, q_u->clnt_id.uni_acct_name.buffer,sizeof(fstring),q_u->clnt_id.uni_acct_name.uni_str_len*2,0);
337
338         if (p->dc.challenge_sent && get_md4pw((char *)p->dc.md4pw, mach_acct)) {
339                 
340                 /* from client / server challenges and md4 password, generate sess key */
341                 cred_session_key(&p->dc.clnt_chal, &p->dc.srv_chal,
342                                  (char *)p->dc.md4pw, p->dc.sess_key);
343                 
344                 /* check that the client credentials are valid */
345                 if (cred_assert(&q_u->clnt_chal, p->dc.sess_key, &p->dc.clnt_cred.challenge, srv_time)) {
346                         
347                         /* create server challenge for inclusion in the reply */
348                         cred_create(p->dc.sess_key, &p->dc.srv_cred.challenge, srv_time, &srv_cred);
349                         
350                         /* copy the received client credentials for use next time */
351                         memcpy(p->dc.clnt_cred.challenge.data, q_u->clnt_chal.data, sizeof(q_u->clnt_chal.data));
352                         memcpy(p->dc.srv_cred .challenge.data, q_u->clnt_chal.data, sizeof(q_u->clnt_chal.data));
353                         
354                         /* Save the machine account name. */
355                         fstrcpy(p->dc.mach_acct, mach_acct);
356                         
357                         p->dc.authenticated = True;
358
359                 } else {
360                         status = NT_STATUS_ACCESS_DENIED;
361                 }
362         } else {
363                 status = NT_STATUS_ACCESS_DENIED;
364         }
365         
366         srv_flgs.neg_flags = 0x000001ff;
367
368         /* set up the LSA AUTH 2 response */
369         init_net_r_auth_2(r_u, &srv_cred, &srv_flgs, status);
370
371         return r_u->status;
372 }
373
374 /*************************************************************************
375  _net_srv_pwset
376  *************************************************************************/
377
378 NTSTATUS _net_srv_pwset(pipes_struct *p, NET_Q_SRV_PWSET *q_u, NET_R_SRV_PWSET *r_u)
379 {
380         NTSTATUS status = NT_STATUS_ACCESS_DENIED;
381         DOM_CRED srv_cred;
382         pstring workstation;
383         SAM_ACCOUNT *sampass=NULL;
384         BOOL ret = False;
385         unsigned char pwd[16];
386         int i;
387         uint32 acct_ctrl;
388
389         /* checks and updates credentials.  creates reply credentials */
390         if (!(p->dc.authenticated && deal_with_creds(p->dc.sess_key, &p->dc.clnt_cred, &q_u->clnt_id.cred, &srv_cred)))
391                 return NT_STATUS_INVALID_HANDLE;
392
393         memcpy(&p->dc.srv_cred, &p->dc.clnt_cred, sizeof(p->dc.clnt_cred));
394
395         DEBUG(5,("_net_srv_pwset: %d\n", __LINE__));
396
397         rpcstr_pull(workstation,q_u->clnt_id.login.uni_comp_name.buffer,
398                     sizeof(workstation),q_u->clnt_id.login.uni_comp_name.uni_str_len*2,0);
399
400         DEBUG(3,("Server Password Set by Wksta:[%s] on account [%s]\n", workstation, p->dc.mach_acct));
401         
402         pdb_init_sam(&sampass);
403
404         become_root();
405         ret=pdb_getsampwnam(sampass, p->dc.mach_acct);
406         unbecome_root();
407
408         /* Ensure the account exists and is a machine account. */
409         
410         acct_ctrl = pdb_get_acct_ctrl(sampass);
411
412         if (!(ret 
413               && (acct_ctrl & ACB_WSTRUST ||
414                       acct_ctrl & ACB_SVRTRUST ||
415                       acct_ctrl & ACB_DOMTRUST))) {
416                 pdb_free_sam(&sampass);
417                 return NT_STATUS_NO_SUCH_USER;
418         }
419         
420         if (pdb_get_acct_ctrl(sampass) & ACB_DISABLED) {
421                 pdb_free_sam(&sampass);
422                 return NT_STATUS_ACCOUNT_DISABLED;
423         }
424
425         DEBUG(100,("Server password set : new given value was :\n"));
426         for(i = 0; i < 16; i++)
427                 DEBUG(100,("%02X ", q_u->pwd[i]));
428         DEBUG(100,("\n"));
429
430         cred_hash3( pwd, q_u->pwd, p->dc.sess_key, 0);
431
432         /* lies!  nt and lm passwords are _not_ the same: don't care */
433         if (!pdb_set_lanman_passwd (sampass, pwd)) {
434                 pdb_free_sam(&sampass);
435                 return NT_STATUS_NO_MEMORY;
436         }
437
438         if (!pdb_set_nt_passwd     (sampass, pwd)) {
439                 pdb_free_sam(&sampass);
440                 return NT_STATUS_NO_MEMORY;
441         }
442
443         if (!pdb_set_pass_changed_now     (sampass)) {
444                 pdb_free_sam(&sampass);
445                 /* Not quite sure what this one qualifies as, but this will do */
446                 return NT_STATUS_UNSUCCESSFUL; 
447         }
448  
449         become_root();
450         ret = pdb_update_sam_account (sampass);
451         unbecome_root();
452  
453         if (ret)
454                 status = NT_STATUS_OK;
455
456         /* set up the LSA Server Password Set response */
457         init_net_r_srv_pwset(r_u, &srv_cred, status);
458
459         pdb_free_sam(&sampass);
460         return r_u->status;
461 }
462
463
464 /*************************************************************************
465  _net_sam_logoff:
466  *************************************************************************/
467
468 NTSTATUS _net_sam_logoff(pipes_struct *p, NET_Q_SAM_LOGOFF *q_u, NET_R_SAM_LOGOFF *r_u)
469 {
470         DOM_CRED srv_cred;
471
472         if (!get_valid_user_struct(p->vuid))
473                 return NT_STATUS_NO_SUCH_USER;
474
475         /* checks and updates credentials.  creates reply credentials */
476         if (!(p->dc.authenticated && deal_with_creds(p->dc.sess_key, &p->dc.clnt_cred, 
477                                                      &q_u->sam_id.client.cred, &srv_cred)))
478                 return NT_STATUS_INVALID_HANDLE;
479
480         memcpy(&p->dc.srv_cred, &p->dc.clnt_cred, sizeof(p->dc.clnt_cred));
481
482         /* XXXX maybe we want to say 'no', reject the client's credentials */
483         r_u->buffer_creds = 1; /* yes, we have valid server credentials */
484         memcpy(&r_u->srv_creds, &srv_cred, sizeof(r_u->srv_creds));
485
486         r_u->status = NT_STATUS_OK;
487
488         return r_u->status;
489 }
490
491
492 /*************************************************************************
493  _net_sam_logon
494  *************************************************************************/
495
496 NTSTATUS _net_sam_logon(pipes_struct *p, NET_Q_SAM_LOGON *q_u, NET_R_SAM_LOGON *r_u)
497 {
498         NTSTATUS status = NT_STATUS_OK;
499         NET_USER_INFO_3 *usr_info = NULL;
500         NET_ID_INFO_CTR *ctr = q_u->sam_id.ctr;
501         DOM_CRED srv_cred;
502         UNISTR2 *uni_samlogon_user = NULL;
503         UNISTR2 *uni_samlogon_domain = NULL;
504         UNISTR2 *uni_samlogon_workstation = NULL;
505         fstring nt_username, nt_domain, nt_workstation;
506         auth_usersupplied_info *user_info = NULL;
507         auth_serversupplied_info *server_info = NULL;
508         extern userdom_struct current_user_info;
509         SAM_ACCOUNT *sampw;
510                 
511         usr_info = (NET_USER_INFO_3 *)talloc(p->mem_ctx, sizeof(NET_USER_INFO_3));
512         if (!usr_info)
513                 return NT_STATUS_NO_MEMORY;
514
515         ZERO_STRUCTP(usr_info);
516
517         /* store the user information, if there is any. */
518         r_u->user = usr_info;
519         r_u->switch_value = 0; /* indicates no info */
520         r_u->auth_resp = 1; /* authoritative response */
521         r_u->switch_value = 3; /* indicates type of validation user info */
522  
523         if (!get_valid_user_struct(p->vuid))
524                 return NT_STATUS_NO_SUCH_USER;
525     
526         /* checks and updates credentials.  creates reply credentials */
527         if (!(p->dc.authenticated && deal_with_creds(p->dc.sess_key, &p->dc.clnt_cred, &q_u->sam_id.client.cred, &srv_cred)))
528                 return NT_STATUS_INVALID_HANDLE;
529
530         memcpy(&p->dc.srv_cred, &p->dc.clnt_cred, sizeof(p->dc.clnt_cred));
531     
532         r_u->buffer_creds = 1; /* yes, we have valid server credentials */
533         memcpy(&r_u->srv_creds, &srv_cred, sizeof(r_u->srv_creds));
534
535         /* find the username */
536     
537         switch (q_u->sam_id.logon_level) {
538         case INTERACTIVE_LOGON_TYPE:
539                 uni_samlogon_user = &ctr->auth.id1.uni_user_name;
540                 uni_samlogon_domain = &ctr->auth.id1.uni_domain_name;
541
542                 uni_samlogon_workstation = &ctr->auth.id1.uni_wksta_name;
543             
544                 DEBUG(3,("SAM Logon (Interactive). Domain:[%s].  ", lp_workgroup()));
545                 break;
546         case NET_LOGON_TYPE:
547                 uni_samlogon_user = &ctr->auth.id2.uni_user_name;
548                 uni_samlogon_domain = &ctr->auth.id2.uni_domain_name;
549                 uni_samlogon_workstation = &ctr->auth.id2.uni_wksta_name;
550             
551                 DEBUG(3,("SAM Logon (Network). Domain:[%s].  ", lp_workgroup()));
552                 break;
553         default:
554                 DEBUG(2,("SAM Logon: unsupported switch value\n"));
555                 return NT_STATUS_INVALID_INFO_CLASS;
556         } /* end switch */
557
558         /* check username exists */
559
560         rpcstr_pull(nt_username,uni_samlogon_user->buffer,sizeof(nt_username),uni_samlogon_user->uni_str_len*2,0);
561         rpcstr_pull(nt_domain,uni_samlogon_domain->buffer,sizeof(nt_domain),uni_samlogon_domain->uni_str_len*2,0);
562         rpcstr_pull(nt_workstation,uni_samlogon_workstation->buffer,sizeof(nt_workstation),uni_samlogon_workstation->uni_str_len*2,0);
563
564         DEBUG(3,("User:[%s@%s] Requested Domain:[%s]\n", nt_username, 
565                  nt_workstation, nt_domain));
566         
567         pstrcpy(current_user_info.smb_name, nt_username);
568      
569         /*
570          * Convert to a UNIX username.
571          */
572
573         DEBUG(5,("Attempting validation level %d for unmapped username %s.\n", q_u->sam_id.ctr->switch_value, nt_username));
574
575         switch (ctr->switch_value) {
576         case NET_LOGON_TYPE:
577         {
578                 struct auth_context *auth_context = NULL;
579                 if (!NT_STATUS_IS_OK(status = make_auth_context_fixed(&auth_context, ctr->auth.id2.lm_chal))) {
580                         return status;
581                 }
582
583                 /* Standard challenge/response authenticaion */
584                 if (!make_user_info_netlogon_network(&user_info, 
585                                                      nt_username, nt_domain, 
586                                                      nt_workstation, 
587                                                      ctr->auth.id2.lm_chal_resp.buffer,
588                                                      ctr->auth.id2.lm_chal_resp.str_str_len,
589                                                      ctr->auth.id2.nt_chal_resp.buffer,
590                                                      ctr->auth.id2.nt_chal_resp.str_str_len)) {
591                         status = NT_STATUS_NO_MEMORY;
592                 } else {
593                         status = auth_context->check_ntlm_password(auth_context, user_info, &server_info);
594                 }
595                 (auth_context->free)(&auth_context);
596                         
597                 break;
598         }
599         case INTERACTIVE_LOGON_TYPE:
600                 /* 'Interactive' autheticaion, supplies the password in its
601                    MD4 form, encrypted with the session key.  We will
602                    convert this to chellange/responce for the auth
603                    subsystem to chew on */
604         {
605                 struct auth_context *auth_context = NULL;
606                 const uint8 *chal;
607                 if (!NT_STATUS_IS_OK(status = make_auth_context_subsystem(&auth_context))) {
608                         return status;
609                 }
610                 
611                 chal = auth_context->get_ntlm_challenge(auth_context);
612
613                 if (!make_user_info_netlogon_interactive(&user_info, 
614                                                          nt_username, nt_domain, 
615                                                          nt_workstation, chal,
616                                                          ctr->auth.id1.lm_owf.data, 
617                                                          ctr->auth.id1.nt_owf.data, 
618                                                          p->dc.sess_key)) {
619                         status = NT_STATUS_NO_MEMORY;
620                 } else {
621                         status = auth_context->check_ntlm_password(auth_context, user_info, &server_info);
622                 }
623
624                 (auth_context->free)(&auth_context);
625
626                 break;
627         }
628         default:
629                 DEBUG(2,("SAM Logon: unsupported switch value\n"));
630                 return NT_STATUS_INVALID_INFO_CLASS;
631         } /* end switch */
632         
633         free_user_info(&user_info);
634         
635         DEBUG(5, ("_net_sam_logon: check_password returned status %s\n", 
636                   nt_errstr(status)));
637
638         /* Check account and password */
639     
640         if (!NT_STATUS_IS_OK(status)) {
641                 free_server_info(&server_info);
642                 return status;
643         }
644
645         if (server_info->guest) {
646                 /* We don't like guest domain logons... */
647                 DEBUG(5,("_net_sam_logon: Attempted domain logon as GUEST denied.\n"));
648                 free_server_info(&server_info);
649                 return NT_STATUS_LOGON_FAILURE;
650         }
651
652         /* This is the point at which, if the login was successful, that
653            the SAM Local Security Authority should record that the user is
654            logged in to the domain.  */
655     
656         {
657                 DOM_GID *gids = NULL;
658                 int num_gids = 0;
659                 pstring my_name;
660                 pstring my_workgroup;
661         
662                 /* set up pointer indicating user/password failed to be found */
663                 usr_info->ptr_user_info = 0;
664         
665                 pstrcpy(my_workgroup, lp_workgroup());
666                 pstrcpy(my_name, global_myname);
667                 strupper(my_name);
668
669                 /*
670                  * This is the point at which we get the group
671                  * database - we should be getting the gid_t list
672                  * from /etc/group and then turning the uids into
673                  * rids and then into machine sids for this user.
674                  * JRA.
675                  */
676
677                 gids = NULL;
678                 get_domain_user_groups(p->mem_ctx, &num_gids, &gids, server_info->sam_account);
679         
680                 sampw = server_info->sam_account;
681
682                 init_net_user_info3(p->mem_ctx, usr_info, 
683                                     pdb_get_user_rid(sampw),
684                                     pdb_get_group_rid(sampw),
685                                     
686                                     pdb_get_username(sampw),
687                                     pdb_get_fullname(sampw),
688                                     pdb_get_homedir(sampw),
689                                     pdb_get_dirdrive(sampw),
690                                     pdb_get_logon_script(sampw),
691                                     pdb_get_profile_path(sampw),
692                                     pdb_get_logon_time(sampw),
693                                     pdb_get_logoff_time(sampw),
694                                     pdb_get_kickoff_time(sampw),
695                                     pdb_get_pass_last_set_time(sampw),
696                                     pdb_get_pass_can_change_time(sampw),
697                                     pdb_get_pass_must_change_time(sampw),
698                                     
699                                     0, /* logon_count */
700                                     0, /* bad_pw_count */
701                                     num_gids,    /* uint32 num_groups */
702                                     gids    , /* DOM_GID *gids */
703                                     0x20    , /* uint32 user_flgs (?) */
704                                     NULL, /* uchar sess_key[16] */
705                                     my_name     , /* char *logon_srv */
706                                     my_workgroup, /* char *logon_dom */
707                                     get_global_sam_sid(),     /* DOM_SID *dom_sid */  
708                                     /* Should be users domain sid, not servers - for trusted domains */
709                                   
710                                     NULL); /* char *other_sids */
711         }
712         free_server_info(&server_info);
713         return status;
714 }
715
716