Remove duplicate group initialisation function.
[ira/wip.git] / source3 / smbd / password.c
1 #define OLD_NTDOMAIN 1
2
3 /* 
4    Unix SMB/Netbios implementation.
5    Version 1.9.
6    Password and authentication handling
7    Copyright (C) Andrew Tridgell 1992-1998
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 2 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, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 #include "includes.h"
25
26 extern int DEBUGLEVEL;
27 extern int Protocol;
28 extern struct in_addr ipzero;
29
30 /* users from session setup */
31 static pstring session_users="";
32
33 extern pstring global_myname;
34 extern fstring global_myworkgroup;
35
36 /* Data to do lanman1/2 password challenge. */
37 static unsigned char saved_challenge[8];
38 static BOOL challenge_sent=False;
39
40 /*******************************************************************
41 Get the next challenge value - no repeats.
42 ********************************************************************/
43 void generate_next_challenge(char *challenge)
44 {
45 #if 0
46         /* 
47          * Leave this ifdef'd out while we test
48          * the new crypto random number generator.
49          * JRA.
50          */
51         unsigned char buf[16];
52         static int counter = 0;
53         struct timeval tval;
54         int v1,v2;
55
56         /* get a sort-of random number */
57         GetTimeOfDay(&tval);
58         v1 = (counter++) + sys_getpid() + tval.tv_sec;
59         v2 = (counter++) * sys_getpid() + tval.tv_usec;
60         SIVAL(challenge,0,v1);
61         SIVAL(challenge,4,v2);
62
63         /* mash it up with md4 */
64         mdfour(buf, (unsigned char *)challenge, 8);
65 #else
66         unsigned char buf[8];
67
68         generate_random_buffer(buf,8,False);
69 #endif 
70         memcpy(saved_challenge, buf, 8);
71         memcpy(challenge,buf,8);
72         challenge_sent = True;
73 }
74
75 /*******************************************************************
76 set the last challenge sent, usually from a password server
77 ********************************************************************/
78 BOOL set_challenge(unsigned char *challenge)
79 {
80   memcpy(saved_challenge,challenge,8);
81   challenge_sent = True;
82   return(True);
83 }
84
85 /*******************************************************************
86 get the last challenge sent
87 ********************************************************************/
88 static BOOL last_challenge(unsigned char *challenge)
89 {
90   if (!challenge_sent) return(False);
91   memcpy(challenge,saved_challenge,8);
92   return(True);
93 }
94
95 /* this holds info on user ids that are already validated for this VC */
96 static user_struct *validated_users = NULL;
97 static int num_validated_users = 0;
98
99 /****************************************************************************
100 check if a uid has been validated, and return an pointer to the user_struct
101 if it has. NULL if not. vuid is biased by an offset. This allows us to
102 tell random client vuid's (normally zero) from valid vuids.
103 ****************************************************************************/
104 user_struct *get_valid_user_struct(uint16 vuid)
105 {
106   if (vuid == UID_FIELD_INVALID)
107     return NULL;
108   vuid -= VUID_OFFSET;
109   if ((vuid >= (uint16)num_validated_users) || 
110      (validated_users[vuid].uid == (uid_t)-1) || (validated_users[vuid].gid == (gid_t)-1))
111     return NULL;
112   return &validated_users[vuid];
113 }
114
115 /****************************************************************************
116 invalidate a uid
117 ****************************************************************************/
118 void invalidate_vuid(uint16 vuid)
119 {
120         user_struct *vuser = get_valid_user_struct(vuid);
121
122         if (vuser == NULL)
123                 return;
124
125         vuser->uid = (uid_t)-1;
126         vuser->gid = (gid_t)-1;
127
128         /* same number of igroups as groups */
129         vuser->n_groups = 0;
130
131         if (vuser->groups)
132                 free((char *)vuser->groups);
133
134         vuser->groups  = NULL;
135
136         delete_nt_token(&vuser->nt_user_token);
137 }
138
139 /****************************************************************************
140 return a validated username
141 ****************************************************************************/
142 char *validated_username(uint16 vuid)
143 {
144         user_struct *vuser = get_valid_user_struct(vuid);
145         if (vuser == NULL)
146                 return 0;
147         return(vuser->user.unix_name);
148 }
149
150 /****************************************************************************
151 return a validated domain
152 ****************************************************************************/
153 char *validated_domain(uint16 vuid)
154 {
155         user_struct *vuser = get_valid_user_struct(vuid);
156         if (vuser == NULL)
157                 return 0;
158         return(vuser->user.domain);
159 }
160
161
162 /****************************************************************************
163  Create the SID list for this user.
164 ****************************************************************************/
165
166 NT_USER_TOKEN *create_nt_token(uid_t uid, gid_t gid, int ngroups, gid_t *groups)
167 {
168         NT_USER_TOKEN *token;
169         DOM_SID *psids;
170         int i, psid_ndx = 0;
171
172         if ((token = (NT_USER_TOKEN *)malloc( sizeof(NT_USER_TOKEN) ) ) == NULL)
173                 return NULL;
174
175         ZERO_STRUCTP(token);
176
177         if ((token->user_sids = (DOM_SID *)malloc( (ngroups + 2)*sizeof(DOM_SID))) == NULL) {
178                 free(token);
179                 return NULL;
180         }
181
182         psids = token->user_sids;
183
184         token->num_sids = 2;
185
186         uid_to_sid( &psids[0], uid);
187         gid_to_sid( &psids[1], gid);
188
189         for (i = 0; i < ngroups; i++) {
190                 if (groups[i] != gid) {
191                         gid_to_sid( &psids[psid_ndx+2], groups[i]);
192                         psid_ndx++;
193                         token->num_sids++;
194                 }
195         }
196
197         return token;
198 }
199
200 /****************************************************************************
201 register a uid/name pair as being valid and that a valid password
202 has been given. vuid is biased by an offset. This allows us to
203 tell random client vuid's (normally zero) from valid vuids.
204 ****************************************************************************/
205
206 uint16 register_vuid(uid_t uid,gid_t gid, char *unix_name, char *requested_name, 
207                      char *domain,BOOL guest)
208 {
209   user_struct *vuser;
210   struct passwd *pwfile; /* for getting real name from passwd file */
211
212   /* Ensure no vuid gets registered in share level security. */
213   if(lp_security() == SEC_SHARE)
214     return UID_FIELD_INVALID;
215
216   validated_users = (user_struct *)Realloc(validated_users,
217                            sizeof(user_struct)*
218                            (num_validated_users+1));
219   
220   if (!validated_users) {
221       DEBUG(0,("Failed to realloc users struct!\n"));
222       num_validated_users = 0;
223       return UID_FIELD_INVALID;
224   }
225
226   vuser = &validated_users[num_validated_users];
227   num_validated_users++;
228
229   vuser->uid = uid;
230   vuser->gid = gid;
231   vuser->guest = guest;
232   fstrcpy(vuser->user.unix_name,unix_name);
233   fstrcpy(vuser->user.smb_name,requested_name);
234   fstrcpy(vuser->user.domain,domain);
235
236   vuser->n_groups = 0;
237   vuser->groups  = NULL;
238
239   /* Find all the groups this uid is in and store them. 
240      Used by become_user() */
241   initialise_groups(unix_name, uid, gid);
242   get_current_groups( &vuser->n_groups, &vuser->groups);
243
244   /* Create an NT_USER_TOKEN struct for this user. */
245   vuser->nt_user_token = create_nt_token(uid,gid, vuser->n_groups, vuser->groups);
246
247   DEBUG(3,("uid %d registered to name %s\n",(int)uid,unix_name));
248
249   DEBUG(3, ("Clearing default real name\n"));
250   fstrcpy(vuser->user.full_name, "<Full Name>");
251   if (lp_unix_realname()) {
252     if ((pwfile=sys_getpwnam(vuser->user.unix_name))!= NULL) {
253       DEBUG(3, ("User name: %s\tReal name: %s\n",vuser->user.unix_name,pwfile->pw_gecos));
254       fstrcpy(vuser->user.full_name, pwfile->pw_gecos);
255     }
256   }
257
258   memset(&vuser->dc, '\0', sizeof(vuser->dc));
259
260   return (uint16)((num_validated_users - 1) + VUID_OFFSET);
261 }
262
263
264 /****************************************************************************
265 add a name to the session users list
266 ****************************************************************************/
267 void add_session_user(char *user)
268 {
269   fstring suser;
270   StrnCpy(suser,user,sizeof(suser)-1);
271
272   if (!Get_Pwnam(suser,True)) return;
273
274   if (suser && *suser && !in_list(suser,session_users,False))
275     {
276       if (strlen(suser) + strlen(session_users) + 2 >= sizeof(pstring))
277         DEBUG(1,("Too many session users??\n"));
278       else
279         {
280           pstrcat(session_users," ");
281           pstrcat(session_users,suser);
282         }
283     }
284 }
285
286
287 /****************************************************************************
288 update the encrypted smbpasswd file from the plaintext username and password
289 *****************************************************************************/
290 static BOOL update_smbpassword_file(char *user, char *password)
291 {
292         struct smb_passwd *smbpw;
293         BOOL ret;
294         
295         become_root();
296         smbpw = getsmbpwnam(user);
297         unbecome_root();
298
299         if(smbpw == NULL) {
300                 DEBUG(0,("getsmbpwnam returned NULL\n"));
301                 return False;
302         }
303
304         /*
305          * Remove the account disabled flag - we are updating the
306          * users password from a login.
307          */
308         smbpw->acct_ctrl &= ~ACB_DISABLED;
309
310         /* Here, the flag is one, because we want to ignore the
311            XXXXXXX'd out password */
312         ret = change_oem_password( smbpw, password, True);
313         if (ret == False) {
314                 DEBUG(3,("change_oem_password returned False\n"));
315         }
316
317         return ret;
318 }
319
320
321
322
323
324 /****************************************************************************
325 core of smb password checking routine.
326 ****************************************************************************/
327 BOOL smb_password_check(char *password, unsigned char *part_passwd, unsigned char *c8)
328 {
329   /* Finish the encryption of part_passwd. */
330   unsigned char p21[21];
331   unsigned char p24[24];
332
333   if (part_passwd == NULL)
334     DEBUG(10,("No password set - allowing access\n"));
335   /* No password set - always true ! */
336   if (part_passwd == NULL)
337     return 1;
338
339   memset(p21,'\0',21);
340   memcpy(p21,part_passwd,16);
341   E_P24(p21, c8, p24);
342 #if DEBUG_PASSWORD
343   {
344     int i;
345     DEBUG(100,("Part password (P16) was |"));
346     for(i = 0; i < 16; i++)
347       DEBUG(100,("%X ", (unsigned char)part_passwd[i]));
348     DEBUG(100,("|\n"));
349     DEBUG(100,("Password from client was |"));
350     for(i = 0; i < 24; i++)
351       DEBUG(100,("%X ", (unsigned char)password[i]));
352     DEBUG(100,("|\n"));
353     DEBUG(100,("Given challenge was |"));
354     for(i = 0; i < 8; i++)
355       DEBUG(100,("%X ", (unsigned char)c8[i]));
356     DEBUG(100,("|\n"));
357     DEBUG(100,("Value from encryption was |"));
358     for(i = 0; i < 24; i++)
359       DEBUG(100,("%X ", (unsigned char)p24[i]));
360     DEBUG(100,("|\n"));
361   }
362 #endif
363   return (memcmp(p24, password, 24) == 0);
364 }
365
366 /****************************************************************************
367  Do a specific test for an smb password being correct, given a smb_password and
368  the lanman and NT responses.
369 ****************************************************************************/
370 BOOL smb_password_ok(struct smb_passwd *smb_pass, uchar chal[8],
371                      uchar lm_pass[24], uchar nt_pass[24])
372 {
373         uchar challenge[8];
374
375         if (!lm_pass || !smb_pass) return(False);
376
377         DEBUG(4,("Checking SMB password for user %s\n", 
378                  smb_pass->smb_name));
379
380         if(smb_pass->acct_ctrl & ACB_DISABLED) {
381                 DEBUG(1,("account for user %s was disabled.\n", 
382                          smb_pass->smb_name));
383                 return(False);
384         }
385
386         if (chal == NULL)
387         {
388                 DEBUG(5,("use last SMBnegprot challenge\n"));
389                 if (!last_challenge(challenge))
390                 {
391                         DEBUG(1,("no challenge done - password failed\n"));
392                         return False;
393                 }
394         }
395         else
396         {
397                 DEBUG(5,("challenge received\n"));
398                 memcpy(challenge, chal, 8);
399         }
400
401         if ((Protocol >= PROTOCOL_NT1) && (smb_pass->smb_nt_passwd != NULL)) {
402                 /* We have the NT MD4 hash challenge available - see if we can
403                    use it (ie. does it exist in the smbpasswd file).
404                 */
405                 DEBUG(4,("smb_password_ok: Checking NT MD4 password\n"));
406                 if (smb_password_check((char *)nt_pass, 
407                                        (uchar *)smb_pass->smb_nt_passwd, 
408                                        challenge)) {
409                         DEBUG(4,("NT MD4 password check succeeded\n"));
410                         return(True);
411                 }
412                 DEBUG(4,("NT MD4 password check failed\n"));
413         }
414
415         /* Try against the lanman password. smb_pass->smb_passwd == NULL means
416            no password, allow access. */
417
418         DEBUG(4,("Checking LM MD4 password\n"));
419
420         if((smb_pass->smb_passwd == NULL) && 
421            (smb_pass->acct_ctrl & ACB_PWNOTREQ)) {
422                 DEBUG(4,("no password required for user %s\n",
423                          smb_pass->smb_name));
424                 return True;
425         }
426
427         if((smb_pass->smb_passwd != NULL) && 
428            smb_password_check((char *)lm_pass, 
429                               (uchar *)smb_pass->smb_passwd, challenge)) {
430                 DEBUG(4,("LM MD4 password check succeeded\n"));
431                 return(True);
432         }
433
434         DEBUG(4,("LM MD4 password check failed\n"));
435
436         return False;
437 }
438
439
440 /****************************************************************************
441 check if a username/password is OK assuming the password is a 24 byte
442 SMB hash
443 return True if the password is correct, False otherwise
444 ****************************************************************************/
445
446 BOOL pass_check_smb(char *user, char *domain,
447                 uchar *chal, uchar *lm_pwd, uchar *nt_pwd,
448                 struct passwd *pwd)
449 {
450         struct passwd *pass;
451         struct smb_passwd *smb_pass;
452
453         if (!lm_pwd || !nt_pwd)
454         {
455                 return(False);
456         }
457
458         if (pwd != NULL && user == NULL)
459         {
460                 pass = (struct passwd *) pwd;
461                 user = pass->pw_name;
462         }
463         else
464         {
465                 pass = smb_getpwnam(user,True);
466         }
467
468         if (pass == NULL)
469         {
470                 DEBUG(1,("Couldn't find user '%s' in UNIX password database.\n",user));
471                 return(False);
472         }
473
474         smb_pass = getsmbpwnam(user);
475
476         if (smb_pass == NULL)
477         {
478                 DEBUG(1,("Couldn't find user '%s' in smb_passwd file.\n", user));
479                 return(False);
480         }
481
482         /* Quit if the account was disabled. */
483         if(smb_pass->acct_ctrl & ACB_DISABLED) {
484                 DEBUG(1,("Account for user '%s' was disabled.\n", user));
485                 return(False);
486         }
487
488         /* Ensure the uid's match */
489         if (smb_pass->smb_userid != pass->pw_uid)
490         {
491                 DEBUG(0,("Error : UNIX and SMB uids in password files do not match for user '%s'!\n", user));
492                 return(False);
493         }
494
495         if (smb_pass->acct_ctrl & ACB_PWNOTREQ) {
496                 if (lp_null_passwords()) {
497                         DEBUG(3,("Account for user '%s' has no password and null passwords are allowed.\n", smb_pass->smb_name));
498                         return(True);
499                 } else {
500                         DEBUG(3,("Account for user '%s' has no password and null passwords are NOT allowed.\n", smb_pass->smb_name));
501                         return(False);
502                 }               
503         }
504
505         if (smb_password_ok(smb_pass, chal, lm_pwd, nt_pwd))
506         {
507                 return(True);
508         }
509         
510         DEBUG(2,("pass_check_smb failed - invalid password for user [%s]\n", user));
511         return False;
512 }
513
514 /****************************************************************************
515 check if a username/password pair is OK either via the system password
516 database or the encrypted SMB password database
517 return True if the password is correct, False otherwise
518 ****************************************************************************/
519 BOOL password_ok(char *user, char *password, int pwlen, struct passwd *pwd)
520 {
521         if (pwlen == 24 || (lp_encrypted_passwords() && (pwlen == 0) && lp_null_passwords()))
522         {
523                 /* if 24 bytes long assume it is an encrypted password */
524                 uchar challenge[8];
525
526                 if (!last_challenge(challenge))
527                 {
528                         DEBUG(0,("Error: challenge not done for user=%s\n", user));
529                         return False;
530                 }
531
532                 return pass_check_smb(user, global_myworkgroup,
533                                       challenge, (uchar *)password, (uchar *)password, pwd);
534         } 
535
536         return pass_check(user, password, pwlen, pwd, 
537                           lp_update_encrypted() ? 
538                           update_smbpassword_file : NULL);
539 }
540
541 /****************************************************************************
542 check if a username is valid
543 ****************************************************************************/
544 BOOL user_ok(char *user,int snum)
545 {
546         pstring valid, invalid;
547         BOOL ret;
548
549         StrnCpy(valid, lp_valid_users(snum), sizeof(pstring)-1);
550         StrnCpy(invalid, lp_invalid_users(snum), sizeof(pstring)-1);
551
552         pstring_sub(valid,"%S",lp_servicename(snum));
553         pstring_sub(invalid,"%S",lp_servicename(snum));
554         
555         ret = !user_in_list(user,invalid);
556         
557         if (ret && valid && *valid) {
558                 ret = user_in_list(user,valid);
559         }
560
561         if (ret && lp_onlyuser(snum)) {
562                 char *user_list = lp_username(snum);
563                 pstring_sub(user_list,"%S",lp_servicename(snum));
564                 ret = user_in_list(user,user_list);
565         }
566
567         return(ret);
568 }
569
570
571
572
573 /****************************************************************************
574 validate a group username entry. Return the username or NULL
575 ****************************************************************************/
576 static char *validate_group(char *group,char *password,int pwlen,int snum)
577 {
578 #ifdef HAVE_NETGROUP
579         {
580                 char *host, *user, *domain;
581                 setnetgrent(group);
582                 while (getnetgrent(&host, &user, &domain)) {
583                         if (user) {
584                                 if (user_ok(user, snum) && 
585                                     password_ok(user,password,pwlen,NULL)) {
586                                         endnetgrent();
587                                         return(user);
588                                 }
589                         }
590                 }
591                 endnetgrent();
592         }
593 #endif
594   
595 #ifdef HAVE_GETGRENT
596         {
597                 struct group *gptr;
598                 setgrent();
599                 while ((gptr = (struct group *)getgrent())) {
600                         if (strequal(gptr->gr_name,group))
601                                 break;
602                 }
603
604                 /*
605                  * As user_ok can recurse doing a getgrent(), we must
606                  * copy the member list into a pstring on the stack before
607                  * use. Bug pointed out by leon@eatworms.swmed.edu.
608                  */
609
610                 if (gptr) {
611                         pstring member_list;
612                         char *member;
613                         size_t copied_len = 0;
614                         int i;
615
616                         *member_list = '\0';
617                         member = member_list;
618
619                         for(i = 0; gptr->gr_mem && gptr->gr_mem[i]; i++) {
620                                 size_t member_len = strlen(gptr->gr_mem[i]) + 1;
621                                 if( copied_len + member_len < sizeof(pstring)) { 
622
623                                         DEBUG(10,("validate_group: = gr_mem = %s\n", gptr->gr_mem[i]));
624
625                                         safe_strcpy(member, gptr->gr_mem[i], sizeof(pstring) - copied_len - 1);
626                                         copied_len += member_len;
627                                         member += copied_len;
628                                 } else {
629                                         *member = '\0';
630                                 }
631                         }
632
633                         endgrent();
634
635                         member = member_list;
636                         while (*member) {
637                                 static fstring name;
638                                 fstrcpy(name,member);
639                                 if (user_ok(name,snum) &&
640                                     password_ok(name,password,pwlen,NULL)) {
641                                         endgrent();
642                                         return(&name[0]);
643                                 }
644
645                                 DEBUG(10,("validate_group = member = %s\n", member));
646
647                                 member += strlen(member) + 1;
648                         }
649                 } else {
650                         endgrent();
651                         return NULL;
652                 }
653         }
654 #endif
655         return(NULL);
656 }
657
658
659
660 /****************************************************************************
661 check for authority to login to a service with a given username/password
662 ****************************************************************************/
663 BOOL authorise_login(int snum,char *user,char *password, int pwlen, 
664                      BOOL *guest,BOOL *force,uint16 vuid)
665 {
666   BOOL ok = False;
667   
668   *guest = False;
669   
670 #if DEBUG_PASSWORD
671   DEBUG(100,("checking authorisation on user=%s pass=%s\n",user,password));
672 #endif
673
674   /* there are several possibilities:
675      1) login as the given user with given password
676      2) login as a previously registered username with the given password
677      3) login as a session list username with the given password
678      4) login as a previously validated user/password pair
679      5) login as the "user =" user with given password
680      6) login as the "user =" user with no password (guest connection)
681      7) login as guest user with no password
682
683      if the service is guest_only then steps 1 to 5 are skipped
684   */
685
686   if (GUEST_ONLY(snum)) *force = True;
687
688   if (!(GUEST_ONLY(snum) && GUEST_OK(snum)))
689     {
690
691       user_struct *vuser = get_valid_user_struct(vuid);
692
693       /* check the given username and password */
694       if (!ok && (*user) && user_ok(user,snum)) {
695         ok = password_ok(user,password, pwlen, NULL);
696         if (ok) DEBUG(3,("ACCEPTED: given username password ok\n"));
697       }
698
699       /* check for a previously registered guest username */
700       if (!ok && (vuser != 0) && vuser->guest) {          
701         if (user_ok(vuser->user.unix_name,snum) &&
702             password_ok(vuser->user.unix_name, password, pwlen, NULL)) {
703           fstrcpy(user, vuser->user.unix_name);
704           vuser->guest = False;
705           DEBUG(3,("ACCEPTED: given password with registered user %s\n", user));
706           ok = True;
707         }
708       }
709
710
711       /* now check the list of session users */
712     if (!ok)
713     {
714       char *auser;
715       char *user_list = strdup(session_users);
716       if (!user_list) return(False);
717
718       for (auser=strtok(user_list,LIST_SEP); 
719            !ok && auser; 
720            auser = strtok(NULL,LIST_SEP))
721       {
722         fstring user2;
723         fstrcpy(user2,auser);
724         if (!user_ok(user2,snum)) continue;
725                   
726         if (password_ok(user2,password, pwlen, NULL)) {
727           ok = True;
728           fstrcpy(user,user2);
729           DEBUG(3,("ACCEPTED: session list username and given password ok\n"));
730         }
731       }
732       free(user_list);
733     }
734
735     /* check for a previously validated username/password pair */
736     if (!ok && (lp_security() > SEC_SHARE) &&
737         (vuser != 0) && !vuser->guest &&
738         user_ok(vuser->user.unix_name,snum)) {
739       fstrcpy(user,vuser->user.unix_name);
740       *guest = False;
741       DEBUG(3,("ACCEPTED: validated uid ok as non-guest\n"));
742       ok = True;
743     }
744
745       /* check for a rhosts entry */
746       if (!ok && user_ok(user,snum) && check_hosts_equiv(user)) {
747         ok = True;
748         DEBUG(3,("ACCEPTED: hosts equiv or rhosts entry\n"));
749       }
750
751       /* check the user= fields and the given password */
752       if (!ok && lp_username(snum)) {
753         char *auser;
754         pstring user_list;
755         StrnCpy(user_list,lp_username(snum),sizeof(pstring));
756
757         pstring_sub(user_list,"%S",lp_servicename(snum));
758           
759         for (auser=strtok(user_list,LIST_SEP);
760              auser && !ok;
761              auser = strtok(NULL,LIST_SEP))
762           {
763             if (*auser == '@')
764               {
765                 auser = validate_group(auser+1,password,pwlen,snum);
766                 if (auser)
767                   {
768                     ok = True;
769                     fstrcpy(user,auser);
770                     DEBUG(3,("ACCEPTED: group username and given password ok\n"));
771                   }
772               }
773             else
774               {
775                 fstring user2;
776                 fstrcpy(user2,auser);
777                 if (user_ok(user2,snum) && 
778                     password_ok(user2,password,pwlen,NULL))
779                   {
780                     ok = True;
781                     fstrcpy(user,user2);
782                     DEBUG(3,("ACCEPTED: user list username and given password ok\n"));
783                   }
784               }
785           }
786       }      
787     } /* not guest only */
788
789   /* check for a normal guest connection */
790   if (!ok && GUEST_OK(snum))
791     {
792       fstring guestname;
793       StrnCpy(guestname,lp_guestaccount(snum),sizeof(guestname)-1);
794       if (Get_Pwnam(guestname,True))
795         {
796           fstrcpy(user,guestname);
797           ok = True;
798           DEBUG(3,("ACCEPTED: guest account and guest ok\n"));
799         }
800       else
801         DEBUG(0,("Invalid guest account %s??\n",guestname));
802       *guest = True;
803     }
804
805   if (ok && !user_ok(user,snum))
806     {
807       DEBUG(0,("rejected invalid user %s\n",user));
808       ok = False;
809     }
810
811   return(ok);
812 }
813
814
815 /****************************************************************************
816 read the a hosts.equiv or .rhosts file and check if it
817 allows this user from this machine
818 ****************************************************************************/
819 static BOOL check_user_equiv(char *user, char *remote, char *equiv_file)
820 {
821   int plus_allowed = 1;
822   char *file_host;
823   char *file_user;
824   char **lines = file_lines_load(equiv_file, NULL);
825   int i;
826
827   DEBUG(5, ("check_user_equiv %s %s %s\n", user, remote, equiv_file));
828   if (! lines) return False;
829   for (i=0; lines[i]; i++) {
830     char *buf = lines[i];
831     trim_string(buf," "," ");
832
833     if (buf[0] != '#' && buf[0] != '\n') 
834     {
835       BOOL is_group = False;
836       int plus = 1;
837       char *bp = buf;
838       if (strcmp(buf, "NO_PLUS\n") == 0)
839       {
840         DEBUG(6, ("check_user_equiv NO_PLUS\n"));
841         plus_allowed = 0;
842       }
843       else {
844         if (buf[0] == '+') 
845         {
846           bp++;
847           if (*bp == '\n' && plus_allowed) 
848           {
849             /* a bare plus means everbody allowed */
850             DEBUG(6, ("check_user_equiv everybody allowed\n"));
851             file_lines_free(lines);
852             return True;
853           }
854         }
855         else if (buf[0] == '-')
856         {
857           bp++;
858           plus = 0;
859         }
860         if (*bp == '@') 
861         {
862           is_group = True;
863           bp++;
864         }
865         file_host = strtok(bp, " \t\n");
866         file_user = strtok(NULL, " \t\n");
867         DEBUG(7, ("check_user_equiv %s %s\n", file_host ? file_host : "(null)", 
868                  file_user ? file_user : "(null)" ));
869         if (file_host && *file_host) 
870         {
871           BOOL host_ok = False;
872
873 #if defined(HAVE_NETGROUP) && defined(HAVE_YP_GET_DEFAULT_DOMAIN)
874           if (is_group)
875             {
876               static char *mydomain = NULL;
877               if (!mydomain)
878                 yp_get_default_domain(&mydomain);
879               if (mydomain && innetgr(file_host,remote,user,mydomain))
880                 host_ok = True;
881             }
882 #else
883           if (is_group)
884             {
885               DEBUG(1,("Netgroups not configured\n"));
886               continue;
887             }
888 #endif
889
890           /* is it this host */
891           /* the fact that remote has come from a call of gethostbyaddr
892            * means that it may have the fully qualified domain name
893            * so we could look up the file version to get it into
894            * a canonical form, but I would rather just type it
895            * in full in the equiv file
896            */
897           if (!host_ok && !is_group && strequal(remote, file_host))
898             host_ok = True;
899
900           if (!host_ok)
901             continue;
902
903           /* is it this user */
904           if (file_user == 0 || strequal(user, file_user)) 
905             {
906               DEBUG(5, ("check_user_equiv matched %s%s %s\n",
907                         (plus ? "+" : "-"), file_host,
908                         (file_user ? file_user : "")));
909               file_lines_free(lines);
910               return (plus ? True : False);
911             }
912         }
913       }
914     }
915   }
916   file_lines_free(lines);
917   return False;
918 }
919
920
921 /****************************************************************************
922 check for a possible hosts equiv or rhosts entry for the user
923 ****************************************************************************/
924 BOOL check_hosts_equiv(char *user)
925 {
926   char *fname = NULL;
927   pstring rhostsfile;
928   struct passwd *pass = Get_Pwnam(user,True);
929
930   if (!pass) 
931     return(False);
932
933   fname = lp_hosts_equiv();
934
935   /* note: don't allow hosts.equiv on root */
936   if (fname && *fname && (pass->pw_uid != 0)) {
937           if (check_user_equiv(user,client_name(),fname))
938                   return(True);
939   }
940   
941   if (lp_use_rhosts())
942     {
943       char *home = get_user_home_dir(user);
944       if (home) {
945               slprintf(rhostsfile, sizeof(rhostsfile)-1, "%s/.rhosts", home);
946               if (check_user_equiv(user,client_name(),rhostsfile))
947                       return(True);
948       }
949     }
950
951   return(False);
952 }
953
954
955 /****************************************************************************
956  Return the client state structure.
957 ****************************************************************************/
958
959 struct cli_state *server_client(void)
960 {
961         static struct cli_state pw_cli;
962         return &pw_cli;
963 }
964
965 /****************************************************************************
966  Support for server level security.
967 ****************************************************************************/
968
969 struct cli_state *server_cryptkey(void)
970 {
971         struct cli_state *cli;
972         fstring desthost;
973         struct in_addr dest_ip;
974         char *p, *pserver;
975         BOOL connected_ok = False;
976
977         cli = server_client();
978
979         if (!cli_initialise(cli))
980                 return NULL;
981
982         pserver = strdup(lp_passwordserver());
983         p = pserver;
984
985         while(next_token( &p, desthost, LIST_SEP, sizeof(desthost))) {
986                 standard_sub_basic(desthost);
987                 strupper(desthost);
988
989                 if(!resolve_name( desthost, &dest_ip, 0x20)) {
990                         DEBUG(1,("server_cryptkey: Can't resolve address for %s\n",desthost));
991                         continue;
992                 }
993
994                 if (ismyip(dest_ip)) {
995                         DEBUG(1,("Password server loop - disabling password server %s\n",desthost));
996                         continue;
997                 }
998
999                 if (cli_connect(cli, desthost, &dest_ip)) {
1000                         DEBUG(3,("connected to password server %s\n",desthost));
1001                         connected_ok = True;
1002                         break;
1003                 }
1004         }
1005
1006         free(pserver);
1007
1008         if (!connected_ok) {
1009                 DEBUG(0,("password server not available\n"));
1010                 cli_shutdown(cli);
1011                 return NULL;
1012         }
1013
1014         if (!attempt_netbios_session_request(cli, global_myname, desthost, &dest_ip))
1015                 return NULL;
1016
1017         DEBUG(3,("got session\n"));
1018
1019         if (!cli_negprot(cli)) {
1020                 DEBUG(1,("%s rejected the negprot\n",desthost));
1021                 cli_shutdown(cli);
1022                 return NULL;
1023         }
1024
1025         if (cli->protocol < PROTOCOL_LANMAN2 ||
1026             !(cli->sec_mode & 1)) {
1027                 DEBUG(1,("%s isn't in user level security mode\n",desthost));
1028                 cli_shutdown(cli);
1029                 return NULL;
1030         }
1031
1032         DEBUG(3,("password server OK\n"));
1033
1034         return cli;
1035 }
1036
1037 /****************************************************************************
1038  Validate a password with the password server.
1039 ****************************************************************************/
1040
1041 BOOL server_validate(char *user, char *domain, 
1042                      char *pass, int passlen,
1043                      char *ntpass, int ntpasslen)
1044 {
1045   struct cli_state *cli;
1046   static unsigned char badpass[24];
1047   static BOOL tested_password_server = False;
1048   static BOOL bad_password_server = False;
1049
1050   cli = server_client();
1051
1052   if (!cli->initialised) {
1053     DEBUG(1,("password server %s is not connected\n", cli->desthost));
1054     return(False);
1055   }  
1056
1057   if(badpass[0] == 0)
1058     memset(badpass, 0x1f, sizeof(badpass));
1059
1060   if((passlen == sizeof(badpass)) && !memcmp(badpass, pass, passlen)) {
1061     /* 
1062      * Very unlikely, our random bad password is the same as the users
1063      * password. */
1064     memset(badpass, badpass[0]+1, sizeof(badpass));
1065   }
1066
1067   /*
1068    * Attempt a session setup with a totally incorrect password.
1069    * If this succeeds with the guest bit *NOT* set then the password
1070    * server is broken and is not correctly setting the guest bit. We
1071    * need to detect this as some versions of NT4.x are broken. JRA.
1072    */
1073
1074   if(!tested_password_server) {
1075     if (cli_session_setup(cli, user, (char *)badpass, sizeof(badpass), 
1076                               (char *)badpass, sizeof(badpass), domain)) {
1077
1078       /*
1079        * We connected to the password server so we
1080        * can say we've tested it.
1081        */
1082       tested_password_server = True;
1083
1084       if ((SVAL(cli->inbuf,smb_vwv2) & 1) == 0) {
1085         DEBUG(0,("server_validate: password server %s allows users as non-guest \
1086 with a bad password.\n", cli->desthost));
1087         DEBUG(0,("server_validate: This is broken (and insecure) behaviour. Please do not \
1088 use this machine as the password server.\n"));
1089         cli_ulogoff(cli);
1090
1091         /*
1092          * Password server has the bug.
1093          */
1094         bad_password_server = True;
1095         return False;
1096       }
1097       cli_ulogoff(cli);
1098     }
1099   } else {
1100
1101     /*
1102      * We have already tested the password server.
1103      * Fail immediately if it has the bug.
1104      */
1105
1106     if(bad_password_server) {
1107       DEBUG(0,("server_validate: [1] password server %s allows users as non-guest \
1108 with a bad password.\n", cli->desthost));
1109       DEBUG(0,("server_validate: [1] This is broken (and insecure) behaviour. Please do not \
1110 use this machine as the password server.\n"));
1111       return False;
1112     }
1113   }
1114
1115   /*
1116    * Now we know the password server will correctly set the guest bit, or is
1117    * not guest enabled, we can try with the real password.
1118    */
1119
1120   if (!cli_session_setup(cli, user, pass, passlen, ntpass, ntpasslen, domain)) {
1121     DEBUG(1,("password server %s rejected the password\n", cli->desthost));
1122     return False;
1123   }
1124
1125   /* if logged in as guest then reject */
1126   if ((SVAL(cli->inbuf,smb_vwv2) & 1) != 0) {
1127     DEBUG(1,("password server %s gave us guest only\n", cli->desthost));
1128     cli_ulogoff(cli);
1129     return(False);
1130   }
1131
1132   cli_ulogoff(cli);
1133
1134   return(True);
1135 }
1136
1137 /***********************************************************************
1138  Connect to a remote machine for domain security authentication
1139  given a name or IP address.
1140 ************************************************************************/
1141
1142 static BOOL connect_to_domain_password_server(struct cli_state *pcli, char *remote_machine,
1143                                               unsigned char *trust_passwd)
1144 {
1145   struct in_addr dest_ip;
1146
1147   if(cli_initialise(pcli) == False) {
1148     DEBUG(0,("connect_to_domain_password_server: unable to initialize client connection.\n"));
1149     return False;
1150   }
1151
1152   standard_sub_basic(remote_machine);
1153   strupper(remote_machine);
1154
1155   if(!resolve_name( remote_machine, &dest_ip, 0x20)) {
1156     DEBUG(1,("connect_to_domain_password_server: Can't resolve address for %s\n", remote_machine));
1157     cli_shutdown(pcli);
1158     return False;
1159   }
1160   
1161   if (ismyip(dest_ip)) {
1162     DEBUG(1,("connect_to_domain_password_server: Password server loop - not using password server %s\n",
1163          remote_machine));
1164     cli_shutdown(pcli);
1165     return False;
1166   }
1167   
1168   if (!cli_connect(pcli, remote_machine, &dest_ip)) {
1169     DEBUG(0,("connect_to_domain_password_server: unable to connect to SMB server on \
1170 machine %s. Error was : %s.\n", remote_machine, cli_errstr(pcli) ));
1171     cli_shutdown(pcli);
1172     return False;
1173   }
1174   
1175   if (!attempt_netbios_session_request(pcli, global_myname, remote_machine, &dest_ip)) {
1176     DEBUG(0,("connect_to_password_server: machine %s rejected the NetBIOS \
1177 session request. Error was : %s.\n", remote_machine, cli_errstr(pcli) ));
1178     return False;
1179   }
1180   
1181   pcli->protocol = PROTOCOL_NT1;
1182
1183   if (!cli_negprot(pcli)) {
1184     DEBUG(0,("connect_to_domain_password_server: machine %s rejected the negotiate protocol. \
1185 Error was : %s.\n", remote_machine, cli_errstr(pcli) ));
1186     cli_shutdown(pcli);
1187     return False;
1188   }
1189
1190   if (pcli->protocol != PROTOCOL_NT1) {
1191     DEBUG(0,("connect_to_domain_password_server: machine %s didn't negotiate NT protocol.\n",
1192                    remote_machine));
1193     cli_shutdown(pcli);
1194     return False;
1195   }
1196
1197   /*
1198    * Do an anonymous session setup.
1199    */
1200
1201   if (!cli_session_setup(pcli, "", "", 0, "", 0, "")) {
1202     DEBUG(0,("connect_to_domain_password_server: machine %s rejected the session setup. \
1203 Error was : %s.\n", remote_machine, cli_errstr(pcli) ));
1204     cli_shutdown(pcli);
1205     return False;
1206   }
1207
1208   if (!(pcli->sec_mode & 1)) {
1209     DEBUG(1,("connect_to_domain_password_server: machine %s isn't in user level security mode\n",
1210                remote_machine));
1211     cli_shutdown(pcli);
1212     return False;
1213   }
1214
1215   if (!cli_send_tconX(pcli, "IPC$", "IPC", "", 1)) {
1216     DEBUG(0,("connect_to_domain_password_server: machine %s rejected the tconX on the IPC$ share. \
1217 Error was : %s.\n", remote_machine, cli_errstr(pcli) ));
1218     cli_shutdown(pcli);
1219     return False;
1220   }
1221
1222   /*
1223    * We now have an anonymous connection to IPC$ on the domain password server.
1224    */
1225
1226   /*
1227    * Even if the connect succeeds we need to setup the netlogon
1228    * pipe here. We do this as we may just have changed the domain
1229    * account password on the PDC and yet we may be talking to
1230    * a BDC that doesn't have this replicated yet. In this case
1231    * a successful connect to a DC needs to take the netlogon connect
1232    * into account also. This patch from "Bjart Kvarme" <bjart.kvarme@usit.uio.no>.
1233    */
1234
1235   if(cli_nt_session_open(pcli, PIPE_NETLOGON) == False) {
1236     DEBUG(0,("connect_to_domain_password_server: unable to open the domain client session to \
1237 machine %s. Error was : %s.\n", remote_machine, cli_errstr(pcli)));
1238     cli_nt_session_close(pcli);
1239     cli_ulogoff(pcli);
1240     cli_shutdown(pcli);
1241     return False;
1242   }
1243
1244   if (cli_nt_setup_creds(pcli, trust_passwd) == False) {
1245     DEBUG(0,("connect_to_domain_password_server: unable to setup the PDC credentials to machine \
1246 %s. Error was : %s.\n", remote_machine, cli_errstr(pcli)));
1247     cli_nt_session_close(pcli);
1248     cli_ulogoff(pcli);
1249     cli_shutdown(pcli);
1250     return(False);
1251   }
1252
1253   return True;
1254 }
1255
1256 /***********************************************************************
1257  Utility function to attempt a connection to an IP address of a DC.
1258 ************************************************************************/
1259
1260 static BOOL attempt_connect_to_dc(struct cli_state *pcli, struct in_addr *ip, unsigned char *trust_passwd)
1261 {
1262   fstring dc_name;
1263
1264   /*
1265    * Ignore addresses we have already tried.
1266    */
1267
1268   if (ip_equal(ipzero, *ip))
1269           return False;
1270
1271   if (!lookup_pdc_name(global_myname, lp_workgroup(), ip, dc_name))
1272           return False;
1273
1274   return connect_to_domain_password_server(pcli, dc_name, trust_passwd);
1275 }
1276
1277
1278
1279 /***********************************************************************
1280  We have been asked to dynamcially determine the IP addresses of
1281  the PDC and BDC's for this DOMAIN, and query them in turn.
1282 ************************************************************************/
1283 static BOOL find_connect_pdc(struct cli_state *pcli, unsigned char *trust_passwd)
1284 {
1285         struct in_addr *ip_list = NULL;
1286         int count = 0;
1287         int i;
1288         BOOL connected_ok = False;
1289
1290         if (!get_dc_list(lp_workgroup(), &ip_list, &count))
1291                 return False;
1292
1293         /*
1294          * Firstly try and contact a PDC/BDC who has the same
1295          * network address as any of our interfaces.
1296          */
1297         for(i = 0; i < count; i++) {
1298                 if(!is_local_net(ip_list[i]))
1299                         continue;
1300
1301                 if((connected_ok = attempt_connect_to_dc(pcli, &ip_list[i], trust_passwd))) 
1302                         break;
1303                 
1304                 ip_list[i] = ipzero; /* Tried and failed. */
1305         }
1306
1307         /*
1308          * Secondly try and contact a random PDC/BDC.
1309          */
1310         if(!connected_ok) {
1311                 i = (sys_random() % count);
1312
1313                 if (!(connected_ok = attempt_connect_to_dc(pcli, &ip_list[i], trust_passwd)))
1314                         ip_list[i] = ipzero; /* Tried and failed. */
1315         }
1316
1317         /*
1318          * Finally go through the IP list in turn, ignoring any addresses
1319          * we have already tried.
1320          */
1321         if(!connected_ok) {
1322                 /*
1323                  * Try and connect to any of the other IP addresses in the PDC/BDC list.
1324                  * Note that from a WINS server the #1 IP address is the PDC.
1325                  */
1326                 for(i = 0; i < count; i++) {
1327                         if((connected_ok = attempt_connect_to_dc(pcli, &ip_list[i], trust_passwd)))
1328                                 break;
1329                 }
1330         }
1331
1332         if(ip_list != NULL)
1333                 free((char *)ip_list);
1334
1335
1336         return connected_ok;
1337 }
1338
1339
1340
1341 /***********************************************************************
1342  Do the same as security=server, but using NT Domain calls and a session
1343  key from the machine password.
1344 ************************************************************************/
1345
1346 BOOL domain_client_validate( char *user, char *domain, 
1347                              char *smb_apasswd, int smb_apasslen, 
1348                              char *smb_ntpasswd, int smb_ntpasslen,
1349                              BOOL *user_exists)
1350 {
1351   unsigned char local_challenge[8];
1352   unsigned char local_lm_response[24];
1353   unsigned char local_nt_response[24];
1354   unsigned char trust_passwd[16];
1355   fstring remote_machine;
1356   char *p, *pserver;
1357   NET_ID_INFO_CTR ctr;
1358   NET_USER_INFO_3 info3;
1359   struct cli_state cli;
1360   uint32 smb_uid_low;
1361   BOOL connected_ok = False;
1362
1363   if(user_exists != NULL)
1364     *user_exists = True; /* Only set false on a very specific error. */
1365  
1366   /* 
1367    * Check that the requested domain is not our own machine name.
1368    * If it is, we should never check the PDC here, we use our own local
1369    * password file.
1370    */
1371
1372   if(strequal( domain, global_myname)) {
1373     DEBUG(3,("domain_client_validate: Requested domain was for this machine.\n"));
1374     return False;
1375   }
1376
1377   /*
1378    * Next, check that the passwords given were encrypted.
1379    */
1380
1381   if(((smb_apasslen != 24) && (smb_apasslen != 0)) || 
1382      ((smb_ntpasslen != 24) && (smb_ntpasslen != 0))) {
1383
1384     /*
1385      * Not encrypted - do so.
1386      */
1387
1388     DEBUG(3,("domain_client_validate: User passwords not in encrypted format.\n"));
1389     generate_random_buffer( local_challenge, 8, False);
1390     SMBencrypt( (uchar *)smb_apasswd, local_challenge, local_lm_response);
1391     SMBNTencrypt((uchar *)smb_ntpasswd, local_challenge, local_nt_response);
1392     smb_apasslen = 24;
1393     smb_ntpasslen = 24;
1394     smb_apasswd = (char *)local_lm_response;
1395     smb_ntpasswd = (char *)local_nt_response;
1396   } else {
1397
1398     /*
1399      * Encrypted - get the challenge we sent for these
1400      * responses.
1401      */
1402
1403     if (!last_challenge(local_challenge)) {
1404       DEBUG(0,("domain_client_validate: no challenge done - password failed\n"));
1405       return False;
1406     }
1407   }
1408
1409   /*
1410    * Get the machine account password for our primary domain
1411    */
1412   if (!secrets_fetch_trust_account_password(lp_workgroup(), trust_passwd, NULL))
1413   {
1414     return False;
1415   }
1416
1417   /*
1418    * At this point, smb_apasswd points to the lanman response to
1419    * the challenge in local_challenge, and smb_ntpasswd points to
1420    * the NT response to the challenge in local_challenge. Ship
1421    * these over the secure channel to a domain controller and
1422    * see if they were valid.
1423    */
1424
1425   ZERO_STRUCT(cli);
1426
1427   /*
1428    * Treat each name in the 'password server =' line as a potential
1429    * PDC/BDC. Contact each in turn and try and authenticate.
1430    */
1431
1432   pserver = lp_passwordserver();
1433   if (! *pserver) pserver = "*";
1434   p = pserver;
1435
1436   while (!connected_ok &&
1437          next_token(&p,remote_machine,LIST_SEP,sizeof(remote_machine))) {
1438           if(strequal(remote_machine, "*")) {
1439                   connected_ok = find_connect_pdc(&cli, trust_passwd);
1440           } else {
1441                   connected_ok = connect_to_domain_password_server(&cli, remote_machine, trust_passwd);
1442           }
1443   }
1444
1445   if (!connected_ok) {
1446     DEBUG(0,("domain_client_validate: Domain password server not available.\n"));
1447     cli_shutdown(&cli);
1448     return False;
1449   }
1450
1451   /* We really don't care what LUID we give the user. */
1452   generate_random_buffer( (unsigned char *)&smb_uid_low, 4, False);
1453
1454   ZERO_STRUCT(info3);
1455
1456   if(cli_nt_login_network(&cli, domain, user, smb_uid_low, (char *)local_challenge,
1457                           ((smb_apasslen != 0) ? smb_apasswd : NULL),
1458                           ((smb_ntpasslen != 0) ? smb_ntpasswd : NULL),
1459                           &ctr, &info3) == False) {
1460     uint32 nt_rpc_err;
1461
1462     cli_error(&cli, NULL, NULL, &nt_rpc_err);
1463     DEBUG(0,("domain_client_validate: unable to validate password for user %s in domain \
1464 %s to Domain controller %s. Error was %s.\n", user, domain, remote_machine, cli_errstr(&cli)));
1465     cli_nt_session_close(&cli);
1466     cli_ulogoff(&cli);
1467     cli_shutdown(&cli);
1468
1469     if((nt_rpc_err == NT_STATUS_NO_SUCH_USER) && (user_exists != NULL))
1470       *user_exists = False;
1471
1472     return False;
1473   }
1474
1475   /*
1476    * Here, if we really want it, we have lots of info about the user in info3.
1477    */
1478
1479 #if 0
1480   /* 
1481    * We don't actually need to do this - plus it fails currently with
1482    * NT_STATUS_INVALID_INFO_CLASS - we need to know *exactly* what to
1483    * send here. JRA.
1484    */
1485
1486   if(cli_nt_logoff(&cli, &ctr) == False) {
1487     DEBUG(0,("domain_client_validate: unable to log off user %s in domain \
1488 %s to Domain controller %s. Error was %s.\n", user, domain, remote_machine, cli_errstr(&cli)));        
1489     cli_nt_session_close(&cli);
1490     cli_ulogoff(&cli);
1491     cli_shutdown(&cli);
1492     return False;
1493   }
1494 #endif /* 0 */
1495
1496   /* Note - once the cli stream is shutdown the mem_ctx used
1497    to allocate the other_sids and gids structures has been deleted - so
1498    these pointers are no longer valid..... */
1499
1500   cli_nt_session_close(&cli);
1501   cli_ulogoff(&cli);
1502   cli_shutdown(&cli);
1503   return True;
1504 }
1505
1506 #undef OLD_NTDOMAIN