r21128: Fix Vista connecting to Samba in share level security.
[kai/samba.git] / source3 / smbd / password.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Password and authentication handling
4    Copyright (C) Andrew Tridgell 1992-1998
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "includes.h"
22
23 /* users from session setup */
24 static char *session_userlist = NULL;
25 static int len_session_userlist = 0;
26 /* workgroup from session setup. */
27 static char *session_workgroup = NULL;
28
29 /* this holds info on user ids that are already validated for this VC */
30 static user_struct *validated_users;
31 static int next_vuid = VUID_OFFSET;
32 static int num_validated_vuids;
33
34 /****************************************************************************
35  Check if a uid has been validated, and return an pointer to the user_struct
36  if it has. NULL if not. vuid is biased by an offset. This allows us to
37  tell random client vuid's (normally zero) from valid vuids.
38 ****************************************************************************/
39
40 user_struct *get_valid_user_struct(uint16 vuid)
41 {
42         user_struct *usp;
43         int count=0;
44
45         if (vuid == UID_FIELD_INVALID)
46                 return NULL;
47
48         for (usp=validated_users;usp;usp=usp->next,count++) {
49                 if (vuid == usp->vuid && usp->server_info) {
50                         if (count > 10) {
51                                 DLIST_PROMOTE(validated_users, usp);
52                         }
53                         return usp;
54                 }
55         }
56
57         return NULL;
58 }
59
60 /****************************************************************************
61  Get the user struct of a partial NTLMSSP login
62 ****************************************************************************/
63
64 user_struct *get_partial_auth_user_struct(uint16 vuid)
65 {
66         user_struct *usp;
67         int count=0;
68
69         if (vuid == UID_FIELD_INVALID)
70                 return NULL;
71
72         for (usp=validated_users;usp;usp=usp->next,count++) {
73                 if (vuid == usp->vuid && !usp->server_info) {
74                         if (count > 10) {
75                                 DLIST_PROMOTE(validated_users, usp);
76                         }
77                         return usp;
78                 }
79         }
80
81         return NULL;
82 }
83
84 /****************************************************************************
85  Invalidate a uid.
86 ****************************************************************************/
87
88 void invalidate_vuid(uint16 vuid)
89 {
90         user_struct *vuser = get_valid_user_struct(vuid);
91
92         if (vuser == NULL)
93                 return;
94         
95         SAFE_FREE(vuser->homedir);
96         SAFE_FREE(vuser->unix_homedir);
97         SAFE_FREE(vuser->logon_script);
98         
99         session_yield(vuser);
100         SAFE_FREE(vuser->session_keystr);
101
102         TALLOC_FREE(vuser->server_info);
103
104         data_blob_free(&vuser->session_key);
105
106         DLIST_REMOVE(validated_users, vuser);
107
108         /* clear the vuid from the 'cache' on each connection, and
109            from the vuid 'owner' of connections */
110         conn_clear_vuid_cache(vuid);
111
112         SAFE_FREE(vuser->groups);
113         TALLOC_FREE(vuser->nt_user_token);
114         SAFE_FREE(vuser);
115         num_validated_vuids--;
116 }
117
118 /****************************************************************************
119  Invalidate all vuid entries for this process.
120 ****************************************************************************/
121
122 void invalidate_all_vuids(void)
123 {
124         user_struct *usp, *next=NULL;
125
126         for (usp=validated_users;usp;usp=next) {
127                 next = usp->next;
128                 
129                 invalidate_vuid(usp->vuid);
130         }
131 }
132
133 /**
134  *  register that a valid login has been performed, establish 'session'.
135  *  @param server_info The token returned from the authentication process. 
136  *   (now 'owned' by register_vuid)
137  *
138  *  @param session_key The User session key for the login session (now also
139  *  'owned' by register_vuid)
140  *
141  *  @param respose_blob The NT challenge-response, if available.  (May be
142  *  freed after this call)
143  *
144  *  @param smb_name The untranslated name of the user
145  *
146  *  @return Newly allocated vuid, biased by an offset. (This allows us to
147  *   tell random client vuid's (normally zero) from valid vuids.)
148  *
149  */
150
151 int register_vuid(auth_serversupplied_info *server_info,
152                   DATA_BLOB session_key, DATA_BLOB response_blob,
153                   const char *smb_name)
154 {
155         user_struct *vuser = NULL;
156
157         /* Paranoia check. */
158         if(lp_security() == SEC_SHARE) {
159                 smb_panic("Tried to register uid in security=share\n");
160         }
161
162         /* Limit allowed vuids to 16bits - VUID_OFFSET. */
163         if (num_validated_vuids >= 0xFFFF-VUID_OFFSET) {
164                 data_blob_free(&session_key);
165                 return UID_FIELD_INVALID;
166         }
167
168         if((vuser = SMB_MALLOC_P(user_struct)) == NULL) {
169                 DEBUG(0,("Failed to malloc users struct!\n"));
170                 data_blob_free(&session_key);
171                 return UID_FIELD_INVALID;
172         }
173
174         ZERO_STRUCTP(vuser);
175
176         /* Allocate a free vuid. Yes this is a linear search... :-) */
177         while( get_valid_user_struct(next_vuid) != NULL ) {
178                 next_vuid++;
179                 /* Check for vuid wrap. */
180                 if (next_vuid == UID_FIELD_INVALID)
181                         next_vuid = VUID_OFFSET;
182         }
183
184         DEBUG(10,("register_vuid: allocated vuid = %u\n",
185                   (unsigned int)next_vuid ));
186
187         vuser->vuid = next_vuid;
188
189         if (!server_info) {
190                 /*
191                  * This happens in an unfinished NTLMSSP session setup. We
192                  * need to allocate a vuid between the first and second calls
193                  * to NTLMSSP.
194                  */
195                 next_vuid++;
196                 num_validated_vuids++;
197                 
198                 vuser->server_info = NULL;
199                 
200                 DLIST_ADD(validated_users, vuser);
201                 
202                 return vuser->vuid;
203         }
204
205         /* the next functions should be done by a SID mapping system (SMS) as
206          * the new real sam db won't have reference to unix uids or gids
207          */
208         
209         vuser->uid = server_info->uid;
210         vuser->gid = server_info->gid;
211         
212         vuser->n_groups = server_info->n_groups;
213         if (vuser->n_groups) {
214                 if (!(vuser->groups = (gid_t *)memdup(server_info->groups,
215                                                       sizeof(gid_t) *
216                                                       vuser->n_groups))) {
217                         DEBUG(0,("register_vuid: failed to memdup "
218                                  "vuser->groups\n"));
219                         data_blob_free(&session_key);
220                         free(vuser);
221                         TALLOC_FREE(server_info);
222                         return UID_FIELD_INVALID;
223                 }
224         }
225
226         vuser->guest = server_info->guest;
227         fstrcpy(vuser->user.unix_name, server_info->unix_name); 
228
229         /* This is a potentially untrusted username */
230         alpha_strcpy(vuser->user.smb_name, smb_name, ". _-$",
231                      sizeof(vuser->user.smb_name));
232
233         fstrcpy(vuser->user.domain, pdb_get_domain(server_info->sam_account));
234         fstrcpy(vuser->user.full_name,
235                 pdb_get_fullname(server_info->sam_account));
236
237         {
238                 /* Keep the homedir handy */
239                 const char *homedir =
240                         pdb_get_homedir(server_info->sam_account);
241                 const char *logon_script =
242                         pdb_get_logon_script(server_info->sam_account);
243
244                 if (!IS_SAM_DEFAULT(server_info->sam_account,
245                                     PDB_UNIXHOMEDIR)) {
246                         const char *unix_homedir =
247                                 pdb_get_unix_homedir(server_info->sam_account);
248                         if (unix_homedir) {
249                                 vuser->unix_homedir =
250                                         smb_xstrdup(unix_homedir);
251                         }
252                 } else {
253                         struct passwd *passwd =
254                                 getpwnam_alloc(NULL, vuser->user.unix_name);
255                         if (passwd) {
256                                 vuser->unix_homedir =
257                                         smb_xstrdup(passwd->pw_dir);
258                                 TALLOC_FREE(passwd);
259                         }
260                 }
261                 
262                 if (homedir) {
263                         vuser->homedir = smb_xstrdup(homedir);
264                 }
265                 if (logon_script) {
266                         vuser->logon_script = smb_xstrdup(logon_script);
267                 }
268         }
269
270         vuser->session_key = session_key;
271
272         DEBUG(10,("register_vuid: (%u,%u) %s %s %s guest=%d\n", 
273                   (unsigned int)vuser->uid, 
274                   (unsigned int)vuser->gid,
275                   vuser->user.unix_name, vuser->user.smb_name,
276                   vuser->user.domain, vuser->guest ));
277
278         DEBUG(3, ("User name: %s\tReal name: %s\n", vuser->user.unix_name,
279                   vuser->user.full_name));      
280
281         if (server_info->ptok) {
282                 vuser->nt_user_token = dup_nt_token(NULL, server_info->ptok);
283         } else {
284                 DEBUG(1, ("server_info does not contain a user_token - "
285                           "cannot continue\n"));
286                 TALLOC_FREE(server_info);
287                 data_blob_free(&session_key);
288                 SAFE_FREE(vuser->homedir);
289                 SAFE_FREE(vuser->unix_homedir);
290                 SAFE_FREE(vuser->logon_script);
291
292                 SAFE_FREE(vuser);
293                 return UID_FIELD_INVALID;
294         }
295
296         /* use this to keep tabs on all our info from the authentication */
297         vuser->server_info = server_info;
298
299         DEBUG(3,("UNIX uid %d is UNIX user %s, and will be vuid %u\n",
300                  (int)vuser->uid,vuser->user.unix_name, vuser->vuid));
301
302         next_vuid++;
303         num_validated_vuids++;
304
305         DLIST_ADD(validated_users, vuser);
306
307         if (!session_claim(vuser)) {
308                 DEBUG(1, ("Failed to claim session for vuid=%d\n",
309                           vuser->vuid));
310                 invalidate_vuid(vuser->vuid);
311                 return UID_FIELD_INVALID;
312         }
313
314         /* Register a home dir service for this user iff
315         
316            (a) This is not a guest connection,
317            (b) we have a home directory defined 
318            (c) there s not an existing static share by that name
319            
320            If a share exists by this name (autoloaded or not) reuse it . */
321
322         vuser->homes_snum = -1;
323
324         if ( (!vuser->guest) && vuser->unix_homedir && *(vuser->unix_homedir)) 
325         {
326                 int servicenumber = lp_servicenumber(vuser->user.unix_name);
327
328                 if ( servicenumber == -1 ) {
329                         DEBUG(3, ("Adding homes service for user '%s' using "
330                                   "home directory: '%s'\n", 
331                                 vuser->user.unix_name, vuser->unix_homedir));
332                         vuser->homes_snum =
333                                 add_home_service(vuser->user.unix_name, 
334                                                  vuser->user.unix_name,
335                                                  vuser->unix_homedir);
336                 } else {
337                         DEBUG(3, ("Using static (or previously created) "
338                                   "service for user '%s'; path = '%s'\n", 
339                                   vuser->user.unix_name,
340                                   lp_pathname(servicenumber) ));
341                         vuser->homes_snum = servicenumber;
342                 }
343         } 
344         
345         if (srv_is_signing_negotiated() && !vuser->guest &&
346             !srv_signing_started()) {
347                 /* Try and turn on server signing on the first non-guest
348                  * sessionsetup. */
349                 srv_set_signing(vuser->session_key, response_blob);
350         }
351         
352         /* fill in the current_user_info struct */
353         set_current_user_info( &vuser->user );
354
355
356         return vuser->vuid;
357 }
358
359 /****************************************************************************
360  Add a name to the session users list.
361 ****************************************************************************/
362
363 void add_session_user(const char *user)
364 {
365         fstring suser;
366         struct passwd *passwd;
367
368         if (!(passwd = Get_Pwnam(user)))
369                 return;
370
371         fstrcpy(suser,passwd->pw_name);
372
373         if(!*suser)
374                 return;
375
376         if( session_userlist && in_list(suser,session_userlist,False) )
377                 return;
378
379         if( !session_userlist ||
380             (strlen(suser) + strlen(session_userlist) + 2 >=
381              len_session_userlist) ) {
382                 char *newlist;
383
384                 if (len_session_userlist > 128 * PSTRING_LEN) {
385                         DEBUG(3,("add_session_user: session userlist already "
386                                  "too large.\n"));
387                         return;
388                 }
389                 newlist = (char *)SMB_REALLOC_KEEP_OLD_ON_ERROR(
390                         session_userlist,
391                         len_session_userlist + PSTRING_LEN );
392                 if( newlist == NULL ) {
393                         DEBUG(1,("Unable to resize session_userlist\n"));
394                         return;
395                 }
396                 if (!session_userlist) {
397                         *newlist = '\0';
398                 }
399                 session_userlist = newlist;
400                 len_session_userlist += PSTRING_LEN;
401         }
402
403         safe_strcat(session_userlist," ",len_session_userlist-1);
404         safe_strcat(session_userlist,suser,len_session_userlist-1);
405 }
406
407 /****************************************************************************
408  In security=share mode we need to store the client workgroup, as that's
409   what Vista uses for the NTLMv2 calculation.
410 ****************************************************************************/
411
412 void add_session_workgroup(const char *workgroup)
413 {
414         if (session_workgroup) {
415                 SAFE_FREE(session_workgroup);
416         }
417         session_workgroup = smb_xstrdup(workgroup);
418 }
419
420 /****************************************************************************
421  In security=share mode we need to return the client workgroup, as that's
422   what Vista uses for the NTLMv2 calculation.
423 ****************************************************************************/
424
425 const char *get_session_workgroup(void)
426 {
427         return session_workgroup;
428 }
429
430 /****************************************************************************
431  Check if a user is in a netgroup user list. If at first we don't succeed,
432  try lower case.
433 ****************************************************************************/
434
435 BOOL user_in_netgroup(const char *user, const char *ngname)
436 {
437 #ifdef HAVE_NETGROUP
438         static char *mydomain = NULL;
439         fstring lowercase_user;
440
441         if (mydomain == NULL)
442                 yp_get_default_domain(&mydomain);
443
444         if(mydomain == NULL) {
445                 DEBUG(5,("Unable to get default yp domain, let's try without specifying it\n"));
446         }
447
448         DEBUG(5,("looking for user %s of domain %s in netgroup %s\n",
449                 user, mydomain?mydomain:"(ANY)", ngname));
450
451         if (innetgr(ngname, NULL, user, mydomain)) {
452                 DEBUG(5,("user_in_netgroup: Found\n"));
453                 return (True);
454         } else {
455
456                 /*
457                  * Ok, innetgr is case sensitive. Try once more with lowercase
458                  * just in case. Attempt to fix #703. JRA.
459                  */
460
461                 fstrcpy(lowercase_user, user);
462                 strlower_m(lowercase_user);
463         
464                 DEBUG(5,("looking for user %s of domain %s in netgroup %s\n",
465                         lowercase_user, mydomain?mydomain:"(ANY)", ngname));
466
467                 if (innetgr(ngname, NULL, lowercase_user, mydomain)) {
468                         DEBUG(5,("user_in_netgroup: Found\n"));
469                         return (True);
470                 }
471         }
472 #endif /* HAVE_NETGROUP */
473         return False;
474 }
475
476 /****************************************************************************
477  Check if a user is in a user list - can check combinations of UNIX
478  and netgroup lists.
479 ****************************************************************************/
480
481 BOOL user_in_list(const char *user,const char **list)
482 {
483         if (!list || !*list)
484                 return False;
485
486         DEBUG(10,("user_in_list: checking user %s in list\n", user));
487
488         while (*list) {
489
490                 DEBUG(10,("user_in_list: checking user |%s| against |%s|\n",
491                           user, *list));
492
493                 /*
494                  * Check raw username.
495                  */
496                 if (strequal(user, *list))
497                         return(True);
498
499                 /*
500                  * Now check to see if any combination
501                  * of UNIX and netgroups has been specified.
502                  */
503
504                 if(**list == '@') {
505                         /*
506                          * Old behaviour. Check netgroup list
507                          * followed by UNIX list.
508                          */
509                         if(user_in_netgroup(user, *list +1))
510                                 return True;
511                         if(user_in_group(user, *list +1))
512                                 return True;
513                 } else if (**list == '+') {
514
515                         if((*(*list +1)) == '&') {
516                                 /*
517                                  * Search UNIX list followed by netgroup.
518                                  */
519                                 if(user_in_group(user, *list +2))
520                                         return True;
521                                 if(user_in_netgroup(user, *list +2))
522                                         return True;
523
524                         } else {
525
526                                 /*
527                                  * Just search UNIX list.
528                                  */
529
530                                 if(user_in_group(user, *list +1))
531                                         return True;
532                         }
533
534                 } else if (**list == '&') {
535
536                         if(*(*list +1) == '+') {
537                                 /*
538                                  * Search netgroup list followed by UNIX list.
539                                  */
540                                 if(user_in_netgroup(user, *list +2))
541                                         return True;
542                                 if(user_in_group(user, *list +2))
543                                         return True;
544                         } else {
545                                 /*
546                                  * Just search netgroup list.
547                                  */
548                                 if(user_in_netgroup(user, *list +1))
549                                         return True;
550                         }
551                 }
552     
553                 list++;
554         }
555         return(False);
556 }
557
558 /****************************************************************************
559  Check if a username is valid.
560 ****************************************************************************/
561
562 static BOOL user_ok(const char *user, int snum)
563 {
564         char **valid, **invalid;
565         BOOL ret;
566
567         valid = invalid = NULL;
568         ret = True;
569
570         if (lp_invalid_users(snum)) {
571                 str_list_copy(&invalid, lp_invalid_users(snum));
572                 if (invalid &&
573                     str_list_substitute(invalid, "%S", lp_servicename(snum))) {
574
575                         /* This is used in sec=share only, so no current user
576                          * around to pass to str_list_sub_basic() */
577
578                         if ( invalid && str_list_sub_basic(invalid, "", "") ) {
579                                 ret = !user_in_list(user,
580                                                     (const char **)invalid);
581                         }
582                 }
583         }
584         if (invalid)
585                 str_list_free (&invalid);
586
587         if (ret && lp_valid_users(snum)) {
588                 str_list_copy(&valid, lp_valid_users(snum));
589                 if ( valid &&
590                      str_list_substitute(valid, "%S", lp_servicename(snum)) ) {
591
592                         /* This is used in sec=share only, so no current user
593                          * around to pass to str_list_sub_basic() */
594
595                         if ( valid && str_list_sub_basic(valid, "", "") ) {
596                                 ret = user_in_list(user, (const char **)valid);
597                         }
598                 }
599         }
600         if (valid)
601                 str_list_free (&valid);
602
603         if (ret && lp_onlyuser(snum)) {
604                 char **user_list = str_list_make (lp_username(snum), NULL);
605                 if (user_list &&
606                     str_list_substitute(user_list, "%S",
607                                         lp_servicename(snum))) {
608                         ret = user_in_list(user, (const char **)user_list);
609                 }
610                 if (user_list) str_list_free (&user_list);
611         }
612
613         return(ret);
614 }
615
616 /****************************************************************************
617  Validate a group username entry. Return the username or NULL.
618 ****************************************************************************/
619
620 static char *validate_group(char *group, DATA_BLOB password,int snum)
621 {
622 #ifdef HAVE_NETGROUP
623         {
624                 char *host, *user, *domain;
625                 setnetgrent(group);
626                 while (getnetgrent(&host, &user, &domain)) {
627                         if (user) {
628                                 if (user_ok(user, snum) && 
629                                     password_ok(user,password)) {
630                                         endnetgrent();
631                                         return(user);
632                                 }
633                         }
634                 }
635                 endnetgrent();
636         }
637 #endif
638   
639 #ifdef HAVE_GETGRENT
640         {
641                 struct group *gptr;
642                 setgrent();
643                 while ((gptr = (struct group *)getgrent())) {
644                         if (strequal(gptr->gr_name,group))
645                                 break;
646                 }
647
648                 /*
649                  * As user_ok can recurse doing a getgrent(), we must
650                  * copy the member list into a pstring on the stack before
651                  * use. Bug pointed out by leon@eatworms.swmed.edu.
652                  */
653
654                 if (gptr) {
655                         pstring member_list;
656                         char *member;
657                         size_t copied_len = 0;
658                         int i;
659
660                         *member_list = '\0';
661                         member = member_list;
662
663                         for(i = 0; gptr->gr_mem && gptr->gr_mem[i]; i++) {
664                                 size_t member_len = strlen(gptr->gr_mem[i])+1;
665                                 if(copied_len+member_len < sizeof(pstring)) { 
666
667                                         DEBUG(10,("validate_group: = gr_mem = "
668                                                   "%s\n", gptr->gr_mem[i]));
669
670                                         safe_strcpy(member, gptr->gr_mem[i],
671                                                     sizeof(pstring) -
672                                                     copied_len - 1);
673                                         copied_len += member_len;
674                                         member += copied_len;
675                                 } else {
676                                         *member = '\0';
677                                 }
678                         }
679
680                         endgrent();
681
682                         member = member_list;
683                         while (*member) {
684                                 static fstring name;
685                                 fstrcpy(name,member);
686                                 if (user_ok(name,snum) &&
687                                     password_ok(name,password)) {
688                                         endgrent();
689                                         return(&name[0]);
690                                 }
691
692                                 DEBUG(10,("validate_group = member = %s\n",
693                                           member));
694
695                                 member += strlen(member) + 1;
696                         }
697                 } else {
698                         endgrent();
699                         return NULL;
700                 }
701         }
702 #endif
703         return(NULL);
704 }
705
706 /****************************************************************************
707  Check for authority to login to a service with a given username/password.
708  Note this is *NOT* used when logging on using sessionsetup_and_X.
709 ****************************************************************************/
710
711 BOOL authorise_login(int snum, fstring user, DATA_BLOB password, 
712                      BOOL *guest)
713 {
714         BOOL ok = False;
715         
716 #ifdef DEBUG_PASSWORD
717         DEBUG(100,("authorise_login: checking authorisation on "
718                    "user=%s pass=%s\n", user,password.data));
719 #endif
720
721         *guest = False;
722   
723         /* there are several possibilities:
724                 1) login as the given user with given password
725                 2) login as a previously registered username with the given 
726                    password
727                 3) login as a session list username with the given password
728                 4) login as a previously validated user/password pair
729                 5) login as the "user =" user with given password
730                 6) login as the "user =" user with no password 
731                    (guest connection)
732                 7) login as guest user with no password
733
734                 if the service is guest_only then steps 1 to 5 are skipped
735         */
736
737         /* now check the list of session users */
738         if (!ok) {
739                 char *auser;
740                 char *user_list = NULL;
741
742                 if ( session_userlist )
743                         user_list = SMB_STRDUP(session_userlist);
744                 else
745                         user_list = SMB_STRDUP("");
746
747                 if (!user_list)
748                         return(False);
749                 
750                 for (auser=strtok(user_list,LIST_SEP); !ok && auser;
751                      auser = strtok(NULL,LIST_SEP)) {
752                         fstring user2;
753                         fstrcpy(user2,auser);
754                         if (!user_ok(user2,snum))
755                                 continue;
756                         
757                         if (password_ok(user2,password)) {
758                                 ok = True;
759                                 fstrcpy(user,user2);
760                                 DEBUG(3,("authorise_login: ACCEPTED: session "
761                                          "list username (%s) and given "
762                                          "password ok\n", user));
763                         }
764                 }
765
766                 SAFE_FREE(user_list);
767         }
768         
769         /* check the user= fields and the given password */
770         if (!ok && lp_username(snum)) {
771                 char *auser;
772                 pstring user_list;
773                 pstrcpy(user_list,lp_username(snum));
774                 
775                 pstring_sub(user_list,"%S",lp_servicename(snum));
776                 
777                 for (auser=strtok(user_list,LIST_SEP); auser && !ok;
778                      auser = strtok(NULL,LIST_SEP)) {
779                         if (*auser == '@') {
780                                 auser = validate_group(auser+1,password,snum);
781                                 if (auser) {
782                                         ok = True;
783                                         fstrcpy(user,auser);
784                                         DEBUG(3,("authorise_login: ACCEPTED: "
785                                                  "group username and given "
786                                                  "password ok (%s)\n", user));
787                                 }
788                         } else {
789                                 fstring user2;
790                                 fstrcpy(user2,auser);
791                                 if (user_ok(user2,snum) &&
792                                     password_ok(user2,password)) {
793                                         ok = True;
794                                         fstrcpy(user,user2);
795                                         DEBUG(3,("authorise_login: ACCEPTED: "
796                                                  "user list username and "
797                                                  "given password ok (%s)\n",
798                                                  user));
799                                 }
800                         }
801                 }
802         }
803
804         /* check for a normal guest connection */
805         if (!ok && GUEST_OK(snum)) {
806                 fstring guestname;
807                 fstrcpy(guestname,lp_guestaccount());
808                 if (Get_Pwnam(guestname)) {
809                         fstrcpy(user,guestname);
810                         ok = True;
811                         DEBUG(3,("authorise_login: ACCEPTED: guest account "
812                                  "and guest ok (%s)\n", user));
813                 } else {
814                         DEBUG(0,("authorise_login: Invalid guest account "
815                                  "%s??\n",guestname));
816                 }
817                 *guest = True;
818         }
819
820         if (ok && !user_ok(user, snum)) {
821                 DEBUG(0,("authorise_login: rejected invalid user %s\n",user));
822                 ok = False;
823         }
824
825         return(ok);
826 }