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