Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/smbd/password.c

    r596 r745  
    2020
    2121#include "includes.h"
     22#include "system/passwd.h"
     23#include "smbd/smbd.h"
    2224#include "smbd/globals.h"
     25#include "../librpc/gen_ndr/netlogon.h"
     26#include "auth.h"
     27
     28/* Fix up prototypes for OSX 10.4, where they're missing */
     29#ifndef HAVE_SETNETGRENT_PROTOTYPE
     30extern int setnetgrent(const char* netgroup);
     31#endif
     32#ifndef HAVE_GETNETGRENT_PROTOTYPE
     33extern int getnetgrent(char **host, char **user, char **domain);
     34#endif
     35#ifndef HAVE_ENDNETGRENT_PROTOTYPE
     36extern void endnetgrent(void);
     37#endif
    2338
    2439enum server_allocated_state { SERVER_ALLOCATED_REQUIRED_YES,
     
    4257                        switch (server_allocated) {
    4358                                case SERVER_ALLOCATED_REQUIRED_YES:
    44                                         if (usp->server_info == NULL) {
     59                                        if (usp->session_info == NULL) {
    4560                                                continue;
    4661                                        }
    4762                                        break;
    4863                                case SERVER_ALLOCATED_REQUIRED_NO:
    49                                         if (usp->server_info != NULL) {
     64                                        if (usp->session_info != NULL) {
    5065                                                continue;
    5166                                        }
     
    110125
    111126        if (vuser->auth_ntlmssp_state) {
    112                 auth_ntlmssp_end(&vuser->auth_ntlmssp_state);
     127                TALLOC_FREE(vuser->auth_ntlmssp_state);
    113128        }
    114129
     
    129144void invalidate_all_vuids(struct smbd_server_connection *sconn)
    130145{
    131         if (sconn->allow_smb2) {
     146        if (sconn->using_smb2) {
    132147                return;
    133148        }
     
    198213}
    199214
    200 static int register_homes_share(const char *username)
     215int register_homes_share(const char *username)
    201216{
    202217        int result;
     
    221236
    222237#ifdef __OS2__
    223                         /* On OS/2 we use drive letters which have a colon.  This is also the field
    224                            separator in master.passwd, so we use a $ instead of a colon for the drive
    225                            separator, ie e$/user instead of e:/user.  This code simply exchanges any $
    226                            for a : in the user's homedir */
    227                         if (pwd->pw_dir[1] == '$')
    228                                         pwd->pw_dir[1] = ':';
     238        /* On OS/2 we use drive letters which have a colon.  This is also the field
     239           separator in master.passwd, so we use a $ instead of a colon for the drive
     240           separator, ie e$/user instead of e:/user.  This code simply exchanges any $
     241           for a : in the user's homedir */
     242        if (pwd->pw_dir[1] == '$')
     243                pwd->pw_dir[1] = ':';
    229244#endif
    230245
     
    240255/**
    241256 *  register that a valid login has been performed, establish 'session'.
    242  *  @param server_info The token returned from the authentication process.
     257 *  @param session_info The token returned from the authentication process.
    243258 *   (now 'owned' by register_existing_vuid)
    244259 *
     
    258273int register_existing_vuid(struct smbd_server_connection *sconn,
    259274                        uint16 vuid,
    260                         auth_serversupplied_info *server_info,
     275                        struct auth_serversupplied_info *session_info,
    261276                        DATA_BLOB response_blob,
    262277                        const char *smb_name)
     
    271286
    272287        /* Use this to keep tabs on all our info from the authentication */
    273         vuser->server_info = talloc_move(vuser, &server_info);
     288        vuser->session_info = talloc_move(vuser, &session_info);
    274289
    275290        /* This is a potentially untrusted username */
    276291        alpha_strcpy(tmp, smb_name, ". _-$", sizeof(tmp));
    277292
    278         vuser->server_info->sanitized_username = talloc_strdup(
    279                 vuser->server_info, tmp);
     293        vuser->session_info->sanitized_username = talloc_strdup(
     294                vuser->session_info, tmp);
    280295
    281296        DEBUG(10,("register_existing_vuid: (%u,%u) %s %s %s guest=%d\n",
    282                   (unsigned int)vuser->server_info->utok.uid,
    283                   (unsigned int)vuser->server_info->utok.gid,
    284                   vuser->server_info->unix_name,
    285                   vuser->server_info->sanitized_username,
    286                   pdb_get_domain(vuser->server_info->sam_account),
    287                   vuser->server_info->guest ));
     297                  (unsigned int)vuser->session_info->utok.uid,
     298                  (unsigned int)vuser->session_info->utok.gid,
     299                  vuser->session_info->unix_name,
     300                  vuser->session_info->sanitized_username,
     301                  vuser->session_info->info3->base.domain.string,
     302                  vuser->session_info->guest ));
    288303
    289304        DEBUG(3, ("register_existing_vuid: User name: %s\t"
    290                   "Real name: %s\n", vuser->server_info->unix_name,
    291                   pdb_get_fullname(vuser->server_info->sam_account)));
    292 
    293         if (!vuser->server_info->ptok) {
    294                 DEBUG(1, ("register_existing_vuid: server_info does not "
     305                  "Real name: %s\n", vuser->session_info->unix_name,
     306                  vuser->session_info->info3->base.full_name.string));
     307
     308        if (!vuser->session_info->security_token) {
     309                DEBUG(1, ("register_existing_vuid: session_info does not "
    295310                        "contain a user_token - cannot continue\n"));
    296311                goto fail;
     
    298313
    299314        DEBUG(3,("register_existing_vuid: UNIX uid %d is UNIX user %s, "
    300                 "and will be vuid %u\n", (int)vuser->server_info->utok.uid,
    301                  vuser->server_info->unix_name, vuser->vuid));
    302 
    303         if (!session_claim(vuser)) {
     315                "and will be vuid %u\n", (int)vuser->session_info->utok.uid,
     316                 vuser->session_info->unix_name, vuser->vuid));
     317
     318        if (!session_claim(sconn, vuser)) {
    304319                DEBUG(1, ("register_existing_vuid: Failed to claim session "
    305320                        "for vuid=%d\n",
     
    316331        vuser->homes_snum = -1;
    317332
    318         if (!vuser->server_info->guest) {
     333        if (!vuser->session_info->guest) {
    319334                vuser->homes_snum = register_homes_share(
    320                         vuser->server_info->unix_name);
    321         }
    322 
    323         if (srv_is_signing_negotiated(smbd_server_conn) &&
    324             !vuser->server_info->guest) {
     335                        vuser->session_info->unix_name);
     336        }
     337
     338        if (srv_is_signing_negotiated(sconn) &&
     339            !vuser->session_info->guest) {
    325340                /* Try and turn on server signing on the first non-guest
    326341                 * sessionsetup. */
    327                 srv_set_signing(smbd_server_conn,
    328                                 vuser->server_info->user_session_key,
     342                srv_set_signing(sconn,
     343                                vuser->session_info->user_session_key,
    329344                                response_blob);
    330345        }
     
    332347        /* fill in the current_user_info struct */
    333348        set_current_user_info(
    334                 vuser->server_info->sanitized_username,
    335                 vuser->server_info->unix_name,
    336                 pdb_get_domain(vuser->server_info->sam_account));
     349                vuser->session_info->sanitized_username,
     350                vuser->session_info->unix_name,
     351                vuser->session_info->info3->base.domain.string);
    337352
    338353        return vuser->vuid;
     
    414429
    415430/****************************************************************************
    416  Check if a user is in a netgroup user list. If at first we don't succeed,
    417  try lower case.
    418 ****************************************************************************/
    419 
    420 bool user_in_netgroup(struct smbd_server_connection *sconn,
    421                       const char *user, const char *ngname)
    422 {
    423 #ifdef HAVE_NETGROUP
    424         fstring lowercase_user;
    425 
    426         if (sconn->smb1.sessions.my_yp_domain == NULL) {
    427                 yp_get_default_domain(&sconn->smb1.sessions.my_yp_domain);
    428         }
    429 
    430         if (sconn->smb1.sessions.my_yp_domain == NULL) {
    431                 DEBUG(5,("Unable to get default yp domain, "
    432                         "let's try without specifying it\n"));
    433         }
    434 
    435         DEBUG(5,("looking for user %s of domain %s in netgroup %s\n",
    436                 user,
    437                 sconn->smb1.sessions.my_yp_domain?
    438                 sconn->smb1.sessions.my_yp_domain:"(ANY)",
    439                 ngname));
    440 
    441         if (innetgr(ngname, NULL, user, sconn->smb1.sessions.my_yp_domain)) {
    442                 DEBUG(5,("user_in_netgroup: Found\n"));
    443                 return true;
    444         }
    445 
    446         /*
    447          * Ok, innetgr is case sensitive. Try once more with lowercase
    448          * just in case. Attempt to fix #703. JRA.
    449          */
    450         fstrcpy(lowercase_user, user);
    451         strlower_m(lowercase_user);
    452 
    453         if (strcmp(user,lowercase_user) == 0) {
    454                 /* user name was already lower case! */
    455                 return false;
    456         }
    457 
    458         DEBUG(5,("looking for user %s of domain %s in netgroup %s\n",
    459                 lowercase_user,
    460                 sconn->smb1.sessions.my_yp_domain?
    461                 sconn->smb1.sessions.my_yp_domain:"(ANY)",
    462                 ngname));
    463 
    464         if (innetgr(ngname, NULL, lowercase_user,
    465                     sconn->smb1.sessions.my_yp_domain)) {
    466                 DEBUG(5,("user_in_netgroup: Found\n"));
    467                 return true;
    468         }
    469 #endif /* HAVE_NETGROUP */
    470         return false;
    471 }
    472 
    473 /****************************************************************************
    474  Check if a user is in a user list - can check combinations of UNIX
    475  and netgroup lists.
    476 ****************************************************************************/
    477 
    478 bool user_in_list(struct smbd_server_connection *sconn,
    479                   const char *user,const char **list)
    480 {
    481         if (!list || !*list)
    482                 return False;
    483 
    484         DEBUG(10,("user_in_list: checking user %s in list\n", user));
    485 
    486         while (*list) {
    487 
    488                 DEBUG(10,("user_in_list: checking user |%s| against |%s|\n",
    489                           user, *list));
    490 
    491                 /*
    492                  * Check raw username.
    493                  */
    494                 if (strequal(user, *list))
    495                         return(True);
    496 
    497                 /*
    498                  * Now check to see if any combination
    499                  * of UNIX and netgroups has been specified.
    500                  */
    501 
    502                 if(**list == '@') {
    503                         /*
    504                          * Old behaviour. Check netgroup list
    505                          * followed by UNIX list.
    506                          */
    507                         if(user_in_netgroup(sconn, user, *list +1))
    508                                 return True;
    509                         if(user_in_group(user, *list +1))
    510                                 return True;
    511                 } else if (**list == '+') {
    512 
    513                         if((*(*list +1)) == '&') {
    514                                 /*
    515                                  * Search UNIX list followed by netgroup.
    516                                  */
    517                                 if(user_in_group(user, *list +2))
    518                                         return True;
    519                                 if(user_in_netgroup(sconn, user, *list +2))
    520                                         return True;
    521 
    522                         } else {
    523 
    524                                 /*
    525                                  * Just search UNIX list.
    526                                  */
    527 
    528                                 if(user_in_group(user, *list +1))
    529                                         return True;
    530                         }
    531 
    532                 } else if (**list == '&') {
    533 
    534                         if(*(*list +1) == '+') {
    535                                 /*
    536                                  * Search netgroup list followed by UNIX list.
    537                                  */
    538                                 if(user_in_netgroup(sconn, user, *list +2))
    539                                         return True;
    540                                 if(user_in_group(user, *list +2))
    541                                         return True;
    542                         } else {
    543                                 /*
    544                                  * Just search netgroup list.
    545                                  */
    546                                 if(user_in_netgroup(sconn, user, *list +1))
    547                                         return True;
    548                         }
    549                 }
    550 
    551                 list++;
    552         }
    553         return(False);
    554 }
    555 
    556 /****************************************************************************
    557431 Check if a username is valid.
    558432****************************************************************************/
    559433
    560 static bool user_ok(struct smbd_server_connection *sconn,
    561                     const char *user, int snum)
     434static bool user_ok(const char *user, int snum)
    562435{
    563436        bool ret;
     
    575448
    576449                        if ( invalid && str_list_sub_basic(invalid, "", "") ) {
    577                                 ret = !user_in_list(sconn, user,
     450                                ret = !user_in_list(talloc_tos(), user,
    578451                                                    (const char **)invalid);
    579452                        }
     
    592465
    593466                        if ( valid && str_list_sub_basic(valid, "", "") ) {
    594                                 ret = user_in_list(sconn, user,
     467                                ret = user_in_list(talloc_tos(), user,
    595468                                                   (const char **)valid);
    596469                        }
     
    605478                    str_list_substitute(user_list, "%S",
    606479                                        lp_servicename(snum))) {
    607                         ret = user_in_list(sconn, user,
     480                        ret = user_in_list(talloc_tos(), user,
    608481                                           (const char **)user_list);
    609482                }
     
    629502                while (getnetgrent(&host, &user, &domain)) {
    630503                        if (user) {
    631                                 if (user_ok(sconn, user, snum) &&
     504                                if (user_ok(user, snum) &&
    632505                                    password_ok(actx, enc,
    633506                                                get_session_workgroup(sconn),
     
    686559                                          "%s\n", gptr->gr_mem[i]));
    687560
    688                                 safe_strcpy(member, gptr->gr_mem[i],
     561                                strlcpy(member, gptr->gr_mem[i],
    689562                                        list_len - (member-member_list));
    690563                                member += member_len;
     
    695568                        member = member_list;
    696569                        while (*member) {
    697                                 if (user_ok(sconn, member,snum) &&
     570                                if (user_ok(member,snum) &&
    698571                                    password_ok(actx, enc,
    699572                                                get_session_workgroup(sconn),
     
    774647                        fstring user2;
    775648                        fstrcpy(user2,auser);
    776                         if (!user_ok(sconn,user2,snum))
     649                        if (!user_ok(user2,snum))
    777650                                continue;
    778651
     
    827700                                fstring user2;
    828701                                fstrcpy(user2,auser);
    829                                 if (user_ok(sconn,user2,snum) &&
     702                                if (user_ok(user2,snum) &&
    830703                                    password_ok(actx, enc,
    831704                                                get_session_workgroup(sconn),
     
    863736        }
    864737
    865         if (ok && !user_ok(sconn, user, snum)) {
     738        if (ok && !user_ok(user, snum)) {
    866739                DEBUG(0,("authorise_login: rejected invalid user %s\n",user));
    867740                ok = False;
Note: See TracChangeset for help on using the changeset viewer.