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