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