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