Ignore:
Timestamp:
May 12, 2014, 8:58:38 PM (11 years ago)
Author:
Silvan Scherrer
Message:

Samba 3.6: updated vendor to latest version

Location:
vendor/current/source3/smbd
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/smbd/conn.c

    r746 r860  
    482482                DEBUG(1,("Forcing close of all shares\n"));
    483483                conn_close_all(sconn);
    484                 return;
     484                goto done;
    485485        }
    486486
     
    513513                }
    514514        }
    515 }
     515
     516 done:
     517
     518        change_to_root_user();
     519        reload_services(msg, -1, true);
     520}
  • vendor/current/source3/smbd/dir.c

    r746 r860  
    5050        unsigned int name_cache_index;
    5151        unsigned int file_number;
     52        files_struct *fsp; /* Back pointer to containing fsp, only
     53                              set from OpenDir_fsp(). */
    5254};
    5355
     
    591593{
    592594        if (fsp->dptr) {
    593 /*
    594  * Ugly hack. We have defined fdopendir to return ENOSYS if dirfd also isn't
    595  * present. I hate Solaris. JRA.
    596  */
    597 #ifdef HAVE_DIRFD
    598                 if (fsp->fh->fd != -1 &&
    599                                 fsp->dptr->dir_hnd &&
    600                                 dirfd(fsp->dptr->dir_hnd->dir)) {
    601                         /* The call below closes the underlying fd. */
    602                         fsp->fh->fd = -1;
    603                 }
    604 #endif
     595                /*
     596                 * The destructor for the struct smb_Dir
     597                 * (fsp->dptr->dir_hnd) now handles
     598                 * all resource deallocation.
     599                 */
    605600                dptr_close_internal(fsp->dptr);
    606601                fsp->dptr = NULL;
     
    942937{
    943938        connection_struct *conn = dirptr->conn;
    944         bool needslash;
     939        size_t slashlen;
     940        size_t pathlen;
    945941
    946942        *_smb_fname = NULL;
    947943        *_mode = 0;
    948944
    949         needslash = ( dirptr->path[strlen(dirptr->path) -1] != '/');
     945        pathlen = strlen(dirptr->path);
     946        slashlen = ( dirptr->path[pathlen-1] != '/') ? 1 : 0;
    950947
    951948        while (true) {
     
    991988                }
    992989
    993                 pathreal = talloc_asprintf(ctx, "%s%s%s",
    994                                            dirptr->path,
    995                                            needslash?"/":"",
    996                                            dname);
     990                /*
     991                 * This used to be
     992                 * pathreal = talloc_asprintf(ctx, "%s%s%s", dirptr->path,
     993                 *                            needslash?"/":"", dname);
     994                 * but this was measurably slower than doing the memcpy.
     995                 */
     996
     997                pathreal = talloc_array(
     998                        ctx, char,
     999                        pathlen + slashlen + talloc_get_size(dname));
    9971000                if (!pathreal) {
    9981001                        TALLOC_FREE(dname);
     
    10001003                        return false;
    10011004                }
     1005
     1006                memcpy(pathreal, dirptr->path, pathlen);
     1007                pathreal[pathlen] = '/';
     1008                memcpy(pathreal + slashlen + pathlen, dname,
     1009                       talloc_get_size(dname));
    10021010
    10031011                /* Create smb_fname with NULL stream_name. */
     
    13331341static int smb_Dir_destructor(struct smb_Dir *dirp)
    13341342{
    1335         if (dirp->dir) {
    1336 #ifdef HAVE_DIRFD
    1337                 if (dirp->conn->sconn) {
    1338                         files_struct *fsp = file_find_fd(dirp->conn->sconn,
    1339                                                 dirfd(dirp->dir));
    1340                         if (fsp) {
    1341                                 /* The call below closes the underlying fd. */
    1342                                 fsp->fh->fd = -1;
     1343        if (dirp->dir != NULL) {
     1344                SMB_VFS_CLOSEDIR(dirp->conn,dirp->dir);
     1345                if (dirp->fsp != NULL) {
     1346                        /*
     1347                         * The SMB_VFS_CLOSEDIR above
     1348                         * closes the underlying fd inside
     1349                         * dirp->fsp.
     1350                         */
     1351                        dirp->fsp->fh->fd = -1;
     1352                        if (dirp->fsp->dptr != NULL) {
     1353                                SMB_ASSERT(dirp->fsp->dptr->dir_hnd == dirp);
     1354                                dirp->fsp->dptr->dir_hnd = NULL;
    13431355                        }
    1344                 }
    1345 #endif
    1346                 SMB_VFS_CLOSEDIR(dirp->conn,dirp->dir);
     1356                        dirp->fsp = NULL;
     1357                }
    13471358        }
    13481359        if (dirp->conn->sconn && !dirp->conn->sconn->using_smb2) {
     
    14281439        if (fsp->is_directory && fsp->fh->fd != -1) {
    14291440                dirp->dir = SMB_VFS_FDOPENDIR(fsp, mask, attr);
    1430                 if (dirp->dir == NULL) {
     1441                if (dirp->dir != NULL) {
     1442                        dirp->fsp = fsp;
     1443                } else {
    14311444                        DEBUG(10,("OpenDir_fsp: SMB_VFS_FDOPENDIR on %s returned "
    14321445                                "NULL (%s)\n",
     
    16441657*****************************************************************/
    16451658
    1646 NTSTATUS can_delete_directory(struct connection_struct *conn,
    1647                                 const char *dirname)
     1659NTSTATUS can_delete_directory_fsp(files_struct *fsp)
    16481660{
    16491661        NTSTATUS status = NT_STATUS_OK;
     
    16521664        char *talloced = NULL;
    16531665        SMB_STRUCT_STAT st;
    1654         struct smb_Dir *dir_hnd = OpenDir(talloc_tos(), conn,
    1655                                         dirname, NULL, 0);
     1666        struct connection_struct *conn = fsp->conn;
     1667        struct smb_Dir *dir_hnd = OpenDir_fsp(talloc_tos(),
     1668                                        conn,
     1669                                        fsp,
     1670                                        NULL,
     1671                                        0);
    16561672
    16571673        if (!dir_hnd) {
     
    16681684                }
    16691685
    1670                 if (!is_visible_file(conn, dirname, dname, &st, True)) {
     1686                if (!is_visible_file(conn, fsp->fsp_name->base_name, dname, &st, True)) {
    16711687                        TALLOC_FREE(talloced);
    16721688                        continue;
    16731689                }
    16741690
    1675                 DEBUG(10,("can_delete_directory: got name %s - can't delete\n",
     1691                DEBUG(10,("can_delete_directory_fsp: got name %s - can't delete\n",
    16761692                         dname ));
    16771693                status = NT_STATUS_DIRECTORY_NOT_EMPTY;
  • vendor/current/source3/smbd/dosmode.c

    r740 r860  
    485485        result = filter_mode_by_protocol(result);
    486486
     487        /*
     488         * Add in that it is a reparse point
     489         */
     490        result |= FILE_ATTRIBUTE_REPARSE_POINT;
     491
    487492        DEBUG(8,("dos_mode_msdfs returning "));
    488493
  • vendor/current/source3/smbd/filename.c

    r746 r860  
    446446                if (errno == ENOENT) {
    447447                        /* Optimization when creating a new file - only
    448                            the last component doesn't exist. */
     448                           the last component doesn't exist.
     449                           NOTE : check_parent_exists() doesn't preserve errno.
     450                        */
     451                        int saved_errno = errno;
    449452                        status = check_parent_exists(ctx,
    450453                                                conn,
     
    453456                                                &dirpath,
    454457                                                &start);
     458                        errno = saved_errno;
    455459                        if (!NT_STATUS_IS_OK(status)) {
    456460                                goto fail;
     
    525529                 * is in the last component and the client already
    526530                 * sent the correct case.
     531                 * NOTE : check_parent_exists() doesn't preserve errno.
    527532                 */
     533                int saved_errno = errno;
    528534                status = check_parent_exists(ctx,
    529535                                        conn,
     
    532538                                        &dirpath,
    533539                                        &start);
     540                errno = saved_errno;
    534541                if (!NT_STATUS_IS_OK(status)) {
    535542                        goto fail;
     
    707714                                /*
    708715                                 * ENOENT/EACCESS are the only valid errors
    709                                  * here. EACCESS needs handling here for
    710                                  * "dropboxes", i.e. directories where users
    711                                  * can only put stuff with permission -wx.
     716                                 * here.
    712717                                 */
    713                                 if ((errno != 0) && (errno != ENOENT)
    714                                     && (errno != EACCES)) {
     718                                if (errno == EACCES) {
     719                                        if (ucf_flags & UCF_CREATING_FILE) {
     720                                                /*
     721                                                 * This is the dropbox
     722                                                 * behaviour. A dropbox is a
     723                                                 * directory with only -wx
     724                                                 * permissions, so
     725                                                 * get_real_filename fails
     726                                                 * with EACCESS, it needs to
     727                                                 * list the directory. We
     728                                                 * nevertheless want to allow
     729                                                 * users creating a file.
     730                                                 */
     731                                                status = NT_STATUS_OBJECT_PATH_NOT_FOUND;
     732                                        } else {
     733                                                status = NT_STATUS_ACCESS_DENIED;
     734                                        }
     735                                        goto fail;
     736                                }
     737
     738                                if ((errno != 0) && (errno != ENOENT)) {
    715739                                        /*
    716740                                         * ENOTDIR and ELOOP both map to
  • vendor/current/source3/smbd/globals.h

    r746 r860  
    163163                               uint16_t flags2,
    164164                               unsigned int max_data_bytes,
     165                               size_t *fixed_portion,
    165166                               char **ppdata,
    166167                               unsigned int *pdata_size);
     
    180181                         uint16_t flags2,
    181182                         unsigned int max_data_bytes,
     183                         size_t *fixed_portion,
     184                         struct smb_filename *smb_fname,
    182185                         char **ppdata,
    183186                         int *ret_data_len);
     
    647650                uint32_t max_read;
    648651                uint32_t max_write;
    649                 bool compound_related_in_progress;
    650652        } smb2;
    651653};
  • vendor/current/source3/smbd/lanman.c

    r746 r860  
    26292629                goto close_domain;
    26302630        }
     2631        if (rid.count != 1) {
     2632                status = NT_STATUS_INVALID_NETWORK_RESPONSE;
     2633                goto close_domain;
     2634        }
     2635        if (type.count != 1) {
     2636                status = NT_STATUS_INVALID_NETWORK_RESPONSE;
     2637                goto close_domain;
     2638        }
    26312639
    26322640        if (type.ids[0] != SID_NAME_USER) {
     
    29372945
    29382946        return True;
    2939 }
    2940 
    2941 /****************************************************************************
    2942  Set the user password.
    2943 *****************************************************************************/
    2944 
    2945 static bool api_SetUserPassword(struct smbd_server_connection *sconn,
    2946                                 connection_struct *conn,uint16 vuid,
    2947                                 char *param, int tpscnt,
    2948                                 char *data, int tdscnt,
    2949                                 int mdrcnt,int mprcnt,
    2950                                 char **rdata,char **rparam,
    2951                                 int *rdata_len,int *rparam_len)
    2952 {
    2953         char *np = get_safe_str_ptr(param,tpscnt,param,2);
    2954         char *p = NULL;
    2955         fstring user;
    2956         fstring pass1,pass2;
    2957         TALLOC_CTX *mem_ctx = talloc_tos();
    2958         NTSTATUS status, result;
    2959         struct rpc_pipe_client *cli = NULL;
    2960         struct policy_handle connect_handle, domain_handle, user_handle;
    2961         struct lsa_String domain_name;
    2962         struct dom_sid2 *domain_sid;
    2963         struct lsa_String names;
    2964         struct samr_Ids rids;
    2965         struct samr_Ids types;
    2966         struct samr_Password old_lm_hash;
    2967         struct samr_Password new_lm_hash;
    2968         int errcode = NERR_badpass;
    2969         uint32_t rid;
    2970         int encrypted;
    2971         int min_pwd_length;
    2972         struct dcerpc_binding_handle *b = NULL;
    2973 
    2974         /* Skip 2 strings. */
    2975         p = skip_string(param,tpscnt,np);
    2976         p = skip_string(param,tpscnt,p);
    2977 
    2978         if (!np || !p) {
    2979                 return False;
    2980         }
    2981 
    2982         /* Do we have a string ? */
    2983         if (skip_string(param,tpscnt,p) == NULL) {
    2984                 return False;
    2985         }
    2986         pull_ascii_fstring(user,p);
    2987 
    2988         p = skip_string(param,tpscnt,p);
    2989         if (!p) {
    2990                 return False;
    2991         }
    2992 
    2993         memset(pass1,'\0',sizeof(pass1));
    2994         memset(pass2,'\0',sizeof(pass2));
    2995         /*
    2996          * We use 31 here not 32 as we're checking
    2997          * the last byte we want to access is safe.
    2998          */
    2999         if (!is_offset_safe(param,tpscnt,p,31)) {
    3000                 return False;
    3001         }
    3002         memcpy(pass1,p,16);
    3003         memcpy(pass2,p+16,16);
    3004 
    3005         encrypted = get_safe_SVAL(param,tpscnt,p+32,0,-1);
    3006         if (encrypted == -1) {
    3007                 errcode = W_ERROR_V(WERR_INVALID_PARAM);
    3008                 goto out;
    3009         }
    3010 
    3011         min_pwd_length = get_safe_SVAL(param,tpscnt,p+34,0,-1);
    3012         if (min_pwd_length == -1) {
    3013                 errcode = W_ERROR_V(WERR_INVALID_PARAM);
    3014                 goto out;
    3015         }
    3016 
    3017         *rparam_len = 4;
    3018         *rparam = smb_realloc_limit(*rparam,*rparam_len);
    3019         if (!*rparam) {
    3020                 return False;
    3021         }
    3022 
    3023         *rdata_len = 0;
    3024 
    3025         DEBUG(3,("Set password for <%s> (encrypted: %d, min_pwd_length: %d)\n",
    3026                 user, encrypted, min_pwd_length));
    3027 
    3028         ZERO_STRUCT(connect_handle);
    3029         ZERO_STRUCT(domain_handle);
    3030         ZERO_STRUCT(user_handle);
    3031 
    3032         status = rpc_pipe_open_interface(mem_ctx, &ndr_table_samr.syntax_id,
    3033                                         conn->session_info,
    3034                                         &conn->sconn->client_id,
    3035                                         conn->sconn->msg_ctx,
    3036                                         &cli);
    3037         if (!NT_STATUS_IS_OK(status)) {
    3038                 DEBUG(0,("api_SetUserPassword: could not connect to samr: %s\n",
    3039                           nt_errstr(status)));
    3040                 errcode = W_ERROR_V(ntstatus_to_werror(status));
    3041                 goto out;
    3042         }
    3043 
    3044         b = cli->binding_handle;
    3045 
    3046         status = dcerpc_samr_Connect2(b, mem_ctx,
    3047                                       global_myname(),
    3048                                       SAMR_ACCESS_CONNECT_TO_SERVER |
    3049                                       SAMR_ACCESS_ENUM_DOMAINS |
    3050                                       SAMR_ACCESS_LOOKUP_DOMAIN,
    3051                                       &connect_handle,
    3052                                       &result);
    3053         if (!NT_STATUS_IS_OK(status)) {
    3054                 errcode = W_ERROR_V(ntstatus_to_werror(status));
    3055                 goto out;
    3056         }
    3057         if (!NT_STATUS_IS_OK(result)) {
    3058                 errcode = W_ERROR_V(ntstatus_to_werror(result));
    3059                 goto out;
    3060         }
    3061 
    3062         init_lsa_String(&domain_name, get_global_sam_name());
    3063 
    3064         status = dcerpc_samr_LookupDomain(b, mem_ctx,
    3065                                           &connect_handle,
    3066                                           &domain_name,
    3067                                           &domain_sid,
    3068                                           &result);
    3069         if (!NT_STATUS_IS_OK(status)) {
    3070                 errcode = W_ERROR_V(ntstatus_to_werror(status));
    3071                 goto out;
    3072         }
    3073         if (!NT_STATUS_IS_OK(result)) {
    3074                 errcode = W_ERROR_V(ntstatus_to_werror(result));
    3075                 goto out;
    3076         }
    3077 
    3078         status = dcerpc_samr_OpenDomain(b, mem_ctx,
    3079                                         &connect_handle,
    3080                                         SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
    3081                                         domain_sid,
    3082                                         &domain_handle,
    3083                                         &result);
    3084         if (!NT_STATUS_IS_OK(status)) {
    3085                 errcode = W_ERROR_V(ntstatus_to_werror(status));
    3086                 goto out;
    3087         }
    3088         if (!NT_STATUS_IS_OK(result)) {
    3089                 errcode = W_ERROR_V(ntstatus_to_werror(result));
    3090                 goto out;
    3091         }
    3092 
    3093         init_lsa_String(&names, user);
    3094 
    3095         status = dcerpc_samr_LookupNames(b, mem_ctx,
    3096                                          &domain_handle,
    3097                                          1,
    3098                                          &names,
    3099                                          &rids,
    3100                                          &types,
    3101                                          &result);
    3102         if (!NT_STATUS_IS_OK(status)) {
    3103                 errcode = W_ERROR_V(ntstatus_to_werror(status));
    3104                 goto out;
    3105         }
    3106         if (!NT_STATUS_IS_OK(result)) {
    3107                 errcode = W_ERROR_V(ntstatus_to_werror(result));
    3108                 goto out;
    3109         }
    3110 
    3111         if (rids.count != 1) {
    3112                 errcode = W_ERROR_V(WERR_NO_SUCH_USER);
    3113                 goto out;
    3114         }
    3115         if (rids.count != types.count) {
    3116                 errcode = W_ERROR_V(WERR_INVALID_PARAM);
    3117                 goto out;
    3118         }
    3119         if (types.ids[0] != SID_NAME_USER) {
    3120                 errcode = W_ERROR_V(WERR_INVALID_PARAM);
    3121                 goto out;
    3122         }
    3123 
    3124         rid = rids.ids[0];
    3125 
    3126         status = dcerpc_samr_OpenUser(b, mem_ctx,
    3127                                       &domain_handle,
    3128                                       SAMR_USER_ACCESS_CHANGE_PASSWORD,
    3129                                       rid,
    3130                                       &user_handle,
    3131                                       &result);
    3132         if (!NT_STATUS_IS_OK(status)) {
    3133                 errcode = W_ERROR_V(ntstatus_to_werror(status));
    3134                 goto out;
    3135         }
    3136         if (!NT_STATUS_IS_OK(result)) {
    3137                 errcode = W_ERROR_V(ntstatus_to_werror(result));
    3138                 goto out;
    3139         }
    3140 
    3141         if (encrypted == 0) {
    3142                 E_deshash(pass1, old_lm_hash.hash);
    3143                 E_deshash(pass2, new_lm_hash.hash);
    3144         } else {
    3145                 ZERO_STRUCT(old_lm_hash);
    3146                 ZERO_STRUCT(new_lm_hash);
    3147                 memcpy(old_lm_hash.hash, pass1, MIN(strlen(pass1), 16));
    3148                 memcpy(new_lm_hash.hash, pass1, MIN(strlen(pass2), 16));
    3149         }
    3150 
    3151         status = dcerpc_samr_ChangePasswordUser(b, mem_ctx,
    3152                                                 &user_handle,
    3153                                                 true, /* lm_present */
    3154                                                 &old_lm_hash,
    3155                                                 &new_lm_hash,
    3156                                                 false, /* nt_present */
    3157                                                 NULL, /* old_nt_crypted */
    3158                                                 NULL, /* new_nt_crypted */
    3159                                                 false, /* cross1_present */
    3160                                                 NULL, /* nt_cross */
    3161                                                 false, /* cross2_present */
    3162                                                 NULL, /* lm_cross */
    3163                                                 &result);
    3164         if (!NT_STATUS_IS_OK(status)) {
    3165                 errcode = W_ERROR_V(ntstatus_to_werror(status));
    3166                 goto out;
    3167         }
    3168         if (!NT_STATUS_IS_OK(result)) {
    3169                 errcode = W_ERROR_V(ntstatus_to_werror(result));
    3170                 goto out;
    3171         }
    3172 
    3173         errcode = NERR_Success;
    3174  out:
    3175 
    3176         if (b && is_valid_policy_hnd(&user_handle)) {
    3177                 dcerpc_samr_Close(b, mem_ctx, &user_handle, &result);
    3178         }
    3179         if (b && is_valid_policy_hnd(&domain_handle)) {
    3180                 dcerpc_samr_Close(b, mem_ctx, &domain_handle, &result);
    3181         }
    3182         if (b && is_valid_policy_hnd(&connect_handle)) {
    3183                 dcerpc_samr_Close(b, mem_ctx, &connect_handle, &result);
    3184         }
    3185 
    3186         memset((char *)pass1,'\0',sizeof(fstring));
    3187         memset((char *)pass2,'\0',sizeof(fstring));
    3188 
    3189         SSVAL(*rparam,0,errcode);
    3190         SSVAL(*rparam,2,0);             /* converter word */
    3191         return(True);
    31922947}
    31932948
     
    57855540        {"NetServerEnum3",      RAP_NetServerEnum3,     api_RNetServerEnum3}, /* anon OK */
    57865541        {"WAccessGetUserPerms",RAP_WAccessGetUserPerms,api_WAccessGetUserPerms},
    5787         {"SetUserPassword",     RAP_WUserPasswordSet2,  api_SetUserPassword},
    57885542        {"WWkstaUserLogon",     RAP_WWkstaUserLogon,    api_WWkstaUserLogon},
    57895543        {"PrintJobInfo",        RAP_WPrintJobSetInfo,   api_PrintJobInfo},
  • vendor/current/source3/smbd/mangle_hash2.c

    r740 r860  
    627627                if (((unsigned int)name[0]) > 128 && (name[1] != 0)) {
    628628                        /* Possible start of mb character. */
    629                         char mbc[2];
     629                        size_t size = 0;
     630                        (void)next_codepoint(name, &size);
    630631                        /*
    631632                         * Note that if CH_UNIX is utf8 a string may be 3
     
    635636                         * JRA.
    636637                         */
    637                         if (convert_string(CH_UNIX, CH_UTF16LE, name, 2, mbc, 2, False) == 2) {
    638                                 /* Was a good mb string. */
    639                                 name += 2;
     638                        if (size > 1) {
     639                                /* Was a mb string. */
     640                                name += size;
    640641                                continue;
    641642                        }
  • vendor/current/source3/smbd/msdfs.c

    r746 r860  
    975975                DEBUG(3,("get_referred_path: No valid referrals for path %s\n",
    976976                        dfs_path));
     977                if (NT_STATUS_IS_OK(status)) {
     978                        /*
     979                         * We are in an error path here (we
     980                         * know it's not a DFS path), but
     981                         * dfs_path_lookup() can return
     982                         * NT_STATUS_OK. Ensure we always
     983                         * return a valid error code.
     984                         *
     985                         * #9588 - ACLs are not inherited to directories
     986                         *         for DFS shares.
     987                         */
     988                        status = NT_STATUS_NOT_FOUND;
     989                }
    977990                goto err_exit;
    978991        }
  • vendor/current/source3/smbd/nttrans.c

    r746 r860  
    537537                                req->flags2 & FLAGS2_DFS_PATHNAMES,
    538538                                fname,
    539                                 0,
     539                                (create_disposition == FILE_CREATE)
     540                                        ? UCF_CREATING_FILE : 0,
    540541                                NULL,
    541542                                &smb_fname);
     
    886887        /* Ensure we have at least one thing set. */
    887888        if ((security_info_sent & (SECINFO_OWNER|SECINFO_GROUP|SECINFO_DACL|SECINFO_SACL)) == 0) {
    888                 if (security_info_sent & SECINFO_LABEL) {
    889                         /* Only consider SECINFO_LABEL if no other
    890                            bits are set. Just like W2K3 we don't
    891                            store this. */
    892                         return NT_STATUS_OK;
    893                 }
    894                 return NT_STATUS_INVALID_PARAMETER;
     889                /* Just like W2K3 */
     890                return NT_STATUS_OK;
    895891        }
    896892
     
    990986                        break;
    991987                }
     988
     989                /* Integer wrap protection for the increment. */
     990                if (offset + next_offset < offset) {
     991                        break;
     992                }
     993
    992994                offset += next_offset;
     995
     996                /* Integer wrap protection for while loop. */
     997                if (offset + 4 < offset) {
     998                        break;
     999                }
     1000
    9931001        }
    9941002
     
    11591167                                req->flags2 & FLAGS2_DFS_PATHNAMES,
    11601168                                fname,
    1161                                 0,
     1169                                (create_disposition == FILE_CREATE)
     1170                                        ? UCF_CREATING_FILE : 0,
    11621171                                NULL,
    11631172                                &smb_fname);
  • vendor/current/source3/smbd/open.c

    r746 r860  
    5959        }
    6060
     61        /*
     62         * If we can access the path to this file, by
     63         * default we have FILE_READ_ATTRIBUTES from the
     64         * containing directory. See the section:
     65         * "Algorithm to Check Access to an Existing File"
     66         * in MS-FSA.pdf.
     67         */
    6168        return se_access_check(sd,
    6269                                token,
     
    143150
    144151        return status;
     152}
     153
     154/****************************************************************************
     155 Ensure when opening a base file for a stream open that we have permissions
     156 to do so given the access mask on the base file.
     157****************************************************************************/
     158
     159static NTSTATUS check_base_file_access(struct connection_struct *conn,
     160                                struct smb_filename *smb_fname,
     161                                uint32_t access_mask)
     162{
     163        uint32_t access_granted = 0;
     164        NTSTATUS status;
     165
     166        status = smbd_calculate_access_mask(conn, smb_fname,
     167                                        false,
     168                                        access_mask,
     169                                        &access_mask);
     170        if (!NT_STATUS_IS_OK(status)) {
     171                DEBUG(10, ("smbd_calculate_access_mask "
     172                        "on file %s returned %s\n",
     173                        smb_fname_str_dbg(smb_fname),
     174                        nt_errstr(status)));
     175                return status;
     176        }
     177
     178        if (access_mask & (FILE_WRITE_DATA|FILE_APPEND_DATA)) {
     179                uint32_t dosattrs;
     180                if (!CAN_WRITE(conn)) {
     181                        return NT_STATUS_ACCESS_DENIED;
     182                }
     183                dosattrs = dos_mode(conn, smb_fname);
     184                if (IS_DOS_READONLY(dosattrs)) {
     185                        return NT_STATUS_ACCESS_DENIED;
     186                }
     187        }
     188
     189
     190        return smbd_check_open_rights(conn,
     191                                smb_fname,
     192                                access_mask,
     193                                &access_granted);
    145194}
    146195
     
    14171466                        }
    14181467
    1419                         access_mask = access_granted;
     1468                        /*
     1469                         * If we can access the path to this file, by
     1470                         * default we have FILE_READ_ATTRIBUTES from the
     1471                         * containing directory. See the section.
     1472                         * "Algorithm to Check Access to an Existing File"
     1473                         * in MS-FSA.pdf.
     1474                         */
     1475                        access_mask = access_granted | FILE_READ_ATTRIBUTES;
    14201476                } else {
    14211477                        access_mask = FILE_GENERIC_ALL;
     
    19892045                        /*
    19902046                         * If we're returning a share violation, ensure we
    1991                          * cope with the braindead 1 second delay.
     2047                         * cope with the braindead 1 second delay (SMB1 only).
    19922048                         */
    19932049
    19942050                        if (!(oplock_request & INTERNAL_OPEN_ONLY) &&
     2051                            !conn->sconn->using_smb2 &&
    19952052                            lp_defer_sharing_violations()) {
    19962053                                struct timeval timeout;
     
    27532810        mtimespec = smb_dname->st.st_ex_mtime;
    27542811
    2755         /* Temporary access mask used to open the directory fd. */
    2756         fsp->access_mask = FILE_READ_DATA | FILE_READ_ATTRIBUTES;
     2812        fsp->access_mask = access_mask;
     2813
    27572814#ifdef O_DIRECTORY
    27582815        status = fd_open(conn, fsp, O_RDONLY|O_DIRECTORY, 0);
     
    32133270                        DEBUG(10, ("Unable to stat stream: %s\n",
    32143271                                   smb_fname_str_dbg(smb_fname_base)));
     3272                } else {
     3273                        /*
     3274                         * https://bugzilla.samba.org/show_bug.cgi?id=10229
     3275                         * We need to check if the requested access mask
     3276                         * could be used to open the underlying file (if
     3277                         * it existed), as we're passing in zero for the
     3278                         * access mask to the base filename.
     3279                         */
     3280                        status = check_base_file_access(conn,
     3281                                                        smb_fname_base,
     3282                                                        access_mask);
     3283
     3284                        if (!NT_STATUS_IS_OK(status)) {
     3285                                DEBUG(10, ("Permission check "
     3286                                        "for base %s failed: "
     3287                                        "%s\n", smb_fname->base_name,
     3288                                        nt_errstr(status)));
     3289                                goto fail;
     3290                        }
    32153291                }
    32163292
  • vendor/current/source3/smbd/oplock_linux.c

    r746 r860  
    7676{
    7777        int ret;
     78        int saved_errno;
     79
     80        /*
     81         * Ensure the lease owner is root to allow
     82         * correct delivery of lease-break signals.
     83         */
     84
     85        become_root();
    7886
    7987        /* First set the signal handler. */
    8088        if (linux_set_lease_sighandler(fd) == -1) {
    81                 return -1;
     89                saved_errno = errno;
     90                ret = -1;
     91                goto out;
    8292        }
    8393        ret = fcntl(fd, F_SETLEASE, leasetype);
    84         if (ret == -1 && errno == EACCES) {
    85                 set_effective_capability(LEASE_CAPABILITY);
    86                 /*
    87                  * Bug 8974 - work around Linux kernel bug
    88                  * https://bugzilla.kernel.org/show_bug.cgi?id=43336.
    89                  * "fcntl(F_SETLEASE) resets signal number when
    90                  *  called multiple times"
    91                  */
    92                 if (linux_set_lease_sighandler(fd) == -1) {
    93                         return -1;
    94                 }
    95                 ret = fcntl(fd, F_SETLEASE, leasetype);
    96         }
    97 
     94        if (ret == -1) {
     95                saved_errno = errno;
     96        }
     97
     98  out:
     99
     100        unbecome_root();
     101
     102        if (ret == -1) {
     103                errno = saved_errno;
     104        }
    98105        return ret;
    99106}
  • vendor/current/source3/smbd/posix_acls.c

    r746 r860  
    13731373                if (pace->type == SMB_ACL_USER_OBJ) {
    13741374
    1375                         if (setting_acl && !is_default_acl) {
     1375                        if (setting_acl) {
     1376                                /*
     1377                                 * Ensure we have default parameters for the
     1378                                 * user (owner) even on default ACLs.
     1379                                 */
    13761380                                apply_default_perms(params, is_directory, pace, S_IRUSR);
    13771381                        }
     
    14531457                        }
    14541458
    1455                         if (!is_default_acl) {
    1456                                 apply_default_perms(params, is_directory, pace, S_IRUSR);
    1457                         }
     1459                        /*
     1460                         * Ensure we have default parameters for the
     1461                         * user (owner) even on default ACLs.
     1462                         */
     1463                        apply_default_perms(params, is_directory, pace, S_IRUSR);
    14581464                } else {
    14591465                        pace->perms = unix_perms_to_acl_perms(pst->st_ex_mode, S_IRUSR, S_IWUSR, S_IXUSR);
  • vendor/current/source3/smbd/process.c

    r746 r860  
    152152        }
    153153
    154         len = smb_len(buf_out) + 4;
     154        len = smb_len_large(buf_out) + 4;
    155155
    156156        ret = write_data(sconn->sock, buf_out+nwritten, len - nwritten);
     
    920920        DEBUG(10,("event_add_idle: %s %p\n", result->name, result->te));
    921921        return result;
    922 }
    923 
    924 static void smbd_sig_term_handler(struct tevent_context *ev,
    925                                   struct tevent_signal *se,
    926                                   int signum,
    927                                   int count,
    928                                   void *siginfo,
    929                                   void *private_data)
    930 {
    931         exit_server_cleanly("termination signal");
    932 }
    933 
    934 void smbd_setup_sig_term_handler(void)
    935 {
    936         struct tevent_signal *se;
    937 
    938         se = tevent_add_signal(smbd_event_context(),
    939                                smbd_event_context(),
    940                                SIGTERM, 0,
    941                                smbd_sig_term_handler,
    942                                NULL);
    943         if (!se) {
    944                 exit_server("failed to setup SIGTERM handler");
    945         }
    946 }
    947 
    948 static void smbd_sig_hup_handler(struct tevent_context *ev,
    949                                   struct tevent_signal *se,
    950                                   int signum,
    951                                   int count,
    952                                   void *siginfo,
    953                                   void *private_data)
    954 {
    955         struct messaging_context *msg_ctx = talloc_get_type_abort(
    956                 private_data, struct messaging_context);
    957         change_to_root_user();
    958         DEBUG(1,("Reloading services after SIGHUP\n"));
    959         reload_services(msg_ctx, smbd_server_conn->sock, False);
    960         if (am_parent) {
    961                 pcap_cache_reload(ev, msg_ctx, &reload_pcap_change_notify);
    962         }
    963 }
    964 
    965 void smbd_setup_sig_hup_handler(struct tevent_context *ev,
    966                                 struct messaging_context *msg_ctx)
    967 {
    968         struct tevent_signal *se;
    969 
    970         se = tevent_add_signal(ev, ev, SIGHUP, 0, smbd_sig_hup_handler,
    971                                msg_ctx);
    972         if (!se) {
    973                 exit_server("failed to setup SIGHUP handler");
    974         }
    975922}
    976923
     
    20311978                 */
    20321979                req->chain_outbuf = TALLOC_REALLOC_ARRAY(
    2033                         req, req->outbuf, uint8_t, smb_len(req->outbuf) + 4);
     1980                        req, req->outbuf, uint8_t,
     1981                        smb_len_large(req->outbuf) + 4);
    20341982                if (req->chain_outbuf == NULL) {
    20351983                        smb_panic("talloc failed");
  • vendor/current/source3/smbd/proto.h

    r746 r860  
    770770/* The following definitions come from smbd/process.c  */
    771771
    772 void smbd_setup_sig_term_handler(void);
    773 void smbd_setup_sig_hup_handler(struct tevent_context *ev,
    774                                 struct messaging_context *msg_ctx);
    775772bool srv_send_smb(struct smbd_server_connection *sconn, char *buffer,
    776773                  bool no_signing, uint32_t seqnum,
     
    981978void reload_printers(struct tevent_context *ev,
    982979                     struct messaging_context *msg_ctx);
     980void reload_printers_full(struct tevent_context *ev,
     981                          struct messaging_context *msg_ctx);
    983982bool reload_services(struct messaging_context *msg_ctx, int smb_sock,
    984983                     bool test);
    985 void reload_pcap_change_notify(struct tevent_context *ev,
    986                                struct messaging_context *msg_ctx);
    987984void exit_server(const char *const explanation);
    988985void exit_server_cleanly(const char *const explanation);
  • vendor/current/source3/smbd/reply.c

    r746 r860  
    17491749        }
    17501750
     1751        if (!map_open_params_to_ntcreate(fname, deny_mode,
     1752                                        OPENX_FILE_EXISTS_OPEN, &access_mask,
     1753                                        &share_mode, &create_disposition,
     1754                                        &create_options, &private_flags)) {
     1755                reply_force_doserror(req, ERRDOS, ERRbadaccess);
     1756                goto out;
     1757        }
     1758
    17511759        status = filename_convert(ctx,
    17521760                                conn,
    17531761                                req->flags2 & FLAGS2_DFS_PATHNAMES,
    17541762                                fname,
    1755                                 0,
     1763                                (create_disposition == FILE_CREATE)
     1764                                        ? UCF_CREATING_FILE : 0,
    17561765                                NULL,
    17571766                                &smb_fname);
     
    17641773                }
    17651774                reply_nterror(req, status);
    1766                 goto out;
    1767         }
    1768 
    1769         if (!map_open_params_to_ntcreate(smb_fname->base_name, deny_mode,
    1770                                          OPENX_FILE_EXISTS_OPEN, &access_mask,
    1771                                          &share_mode, &create_disposition,
    1772                                          &create_options, &private_flags)) {
    1773                 reply_force_doserror(req, ERRDOS, ERRbadaccess);
    17741775                goto out;
    17751776        }
     
    19241925        }
    19251926
     1927        if (!map_open_params_to_ntcreate(fname, deny_mode,
     1928                                        smb_ofun,
     1929                                        &access_mask, &share_mode,
     1930                                        &create_disposition,
     1931                                        &create_options,
     1932                                        &private_flags)) {
     1933                reply_force_doserror(req, ERRDOS, ERRbadaccess);
     1934                goto out;
     1935        }
     1936
    19261937        status = filename_convert(ctx,
    19271938                                conn,
    19281939                                req->flags2 & FLAGS2_DFS_PATHNAMES,
    19291940                                fname,
    1930                                 0,
     1941                                (create_disposition == FILE_CREATE)
     1942                                        ? UCF_CREATING_FILE : 0,
    19311943                                NULL,
    19321944                                &smb_fname);
     
    19391951                }
    19401952                reply_nterror(req, status);
    1941                 goto out;
    1942         }
    1943 
    1944         if (!map_open_params_to_ntcreate(smb_fname->base_name, deny_mode,
    1945                                          smb_ofun,
    1946                                          &access_mask, &share_mode,
    1947                                          &create_disposition,
    1948                                          &create_options,
    1949                                          &private_flags)) {
    1950                 reply_force_doserror(req, ERRDOS, ERRbadaccess);
    19511953                goto out;
    19521954        }
     
    21462148                                req->flags2 & FLAGS2_DFS_PATHNAMES,
    21472149                                fname,
    2148                                 0,
     2150                                UCF_CREATING_FILE,
    21492151                                NULL,
    21502152                                &smb_fname);
     
    22402242        connection_struct *conn = req->conn;
    22412243        struct smb_filename *smb_fname = NULL;
     2244        char *wire_name = NULL;
    22422245        char *fname = NULL;
    22432246        uint32 fattr;
    22442247        files_struct *fsp;
    22452248        int oplock_request;
    2246         int tmpfd;
    22472249        char *s;
    22482250        NTSTATUS status;
     2251        int i;
    22492252        TALLOC_CTX *ctx = talloc_tos();
    22502253
     
    22592262        oplock_request = CORE_OPLOCK_REQUEST(req->inbuf);
    22602263
    2261         srvstr_get_path_req(ctx, req, &fname, (const char *)req->buf+1,
     2264        srvstr_get_path_req(ctx, req, &wire_name, (const char *)req->buf+1,
    22622265                            STR_TERMINATE, &status);
    22632266        if (!NT_STATUS_IS_OK(status)) {
     
    22652268                goto out;
    22662269        }
    2267         if (*fname) {
    2268                 fname = talloc_asprintf(ctx,
    2269                                 "%s/TMXXXXXX",
    2270                                 fname);
    2271         } else {
    2272                 fname = talloc_strdup(ctx, "TMXXXXXX");
    2273         }
    2274 
    2275         if (!fname) {
    2276                 reply_nterror(req, NT_STATUS_NO_MEMORY);
    2277                 goto out;
    2278         }
    2279 
    2280         status = filename_convert(ctx, conn,
     2270
     2271        for (i = 0; i < 10; i++) {
     2272                if (*wire_name) {
     2273                        fname = talloc_asprintf(ctx,
     2274                                        "%s/TMP%s",
     2275                                        wire_name,
     2276                                        generate_random_str_list(ctx, 5, "0123456789"));
     2277                } else {
     2278                        fname = talloc_asprintf(ctx,
     2279                                        "TMP%s",
     2280                                        generate_random_str_list(ctx, 5, "0123456789"));
     2281                }
     2282
     2283                if (!fname) {
     2284                        reply_nterror(req, NT_STATUS_NO_MEMORY);
     2285                        goto out;
     2286                }
     2287
     2288                status = filename_convert(ctx, conn,
    22812289                                req->flags2 & FLAGS2_DFS_PATHNAMES,
    22822290                                fname,
    2283                                 0,
     2291                                UCF_CREATING_FILE,
    22842292                                NULL,
    22852293                                &smb_fname);
    2286         if (!NT_STATUS_IS_OK(status)) {
    2287                 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
    2288                         reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
     2294                if (!NT_STATUS_IS_OK(status)) {
     2295                        if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
     2296                                reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
    22892297                                        ERRSRV, ERRbadpath);
     2298                                goto out;
     2299                        }
     2300                        reply_nterror(req, status);
    22902301                        goto out;
    22912302                }
     2303
     2304                /* Create the file. */
     2305                status = SMB_VFS_CREATE_FILE(
     2306                        conn,                                   /* conn */
     2307                        req,                                    /* req */
     2308                        0,                                      /* root_dir_fid */
     2309                        smb_fname,                              /* fname */
     2310                        FILE_GENERIC_READ | FILE_GENERIC_WRITE, /* access_mask */
     2311                        FILE_SHARE_READ | FILE_SHARE_WRITE,     /* share_access */
     2312                        FILE_CREATE,                            /* create_disposition*/
     2313                        0,                                      /* create_options */
     2314                        fattr,                                  /* file_attributes */
     2315                        oplock_request,                         /* oplock_request */
     2316                        0,                                      /* allocation_size */
     2317                        0,                                      /* private_flags */
     2318                        NULL,                                   /* sd */
     2319                        NULL,                                   /* ea_list */
     2320                        &fsp,                                   /* result */
     2321                        NULL);                                  /* pinfo */
     2322
     2323                if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
     2324                        TALLOC_FREE(fname);
     2325                        TALLOC_FREE(smb_fname);
     2326                        continue;
     2327                }
     2328
     2329                if (!NT_STATUS_IS_OK(status)) {
     2330                        if (open_was_deferred(req->mid)) {
     2331                                /* We have re-scheduled this call. */
     2332                                goto out;
     2333                        }
     2334                        reply_openerror(req, status);
     2335                        goto out;
     2336                }
     2337
     2338                break;
     2339        }
     2340
     2341        if (i == 10) {
     2342                /* Collision after 10 times... */
    22922343                reply_nterror(req, status);
    2293                 goto out;
    2294         }
    2295 
    2296         tmpfd = mkstemp(smb_fname->base_name);
    2297         if (tmpfd == -1) {
    2298                 reply_nterror(req, map_nt_error_from_unix(errno));
    2299                 goto out;
    2300         }
    2301 
    2302         SMB_VFS_STAT(conn, smb_fname);
    2303 
    2304         /* We should fail if file does not exist. */
    2305         status = SMB_VFS_CREATE_FILE(
    2306                 conn,                                   /* conn */
    2307                 req,                                    /* req */
    2308                 0,                                      /* root_dir_fid */
    2309                 smb_fname,                              /* fname */
    2310                 FILE_GENERIC_READ | FILE_GENERIC_WRITE, /* access_mask */
    2311                 FILE_SHARE_READ | FILE_SHARE_WRITE,     /* share_access */
    2312                 FILE_OPEN,                              /* create_disposition*/
    2313                 0,                                      /* create_options */
    2314                 fattr,                                  /* file_attributes */
    2315                 oplock_request,                         /* oplock_request */
    2316                 0,                                      /* allocation_size */
    2317                 0,                                      /* private_flags */
    2318                 NULL,                                   /* sd */
    2319                 NULL,                                   /* ea_list */
    2320                 &fsp,                                   /* result */
    2321                 NULL);                                  /* pinfo */
    2322 
    2323         /* close fd from mkstemp() */
    2324         close(tmpfd);
    2325 
    2326         if (!NT_STATUS_IS_OK(status)) {
    2327                 if (open_was_deferred(req->mid)) {
    2328                         /* We have re-scheduled this call. */
    2329                         goto out;
    2330                 }
    2331                 reply_openerror(req, status);
    23322344                goto out;
    23332345        }
     
    23702382 out:
    23712383        TALLOC_FREE(smb_fname);
     2384        TALLOC_FREE(fname);
     2385        TALLOC_FREE(wire_name);
    23722386        END_PROFILE(SMBctemp);
    23732387        return;
     
    31373151        START_PROFILE(SMBreadbraw);
    31383152
    3139         if (srv_is_signing_active(sconn) ||
    3140             is_encrypted_packet(req->inbuf)) {
     3153        if (srv_is_signing_active(sconn) || req->encrypted) {
    31413154                exit_server_cleanly("reply_readbraw: SMB signing/sealing is active - "
    31423155                        "raw reads/writes are disallowed.");
     
    35313544        int saved_errno = 0;
    35323545
    3533         if(fsp_stat(fsp) == -1) {
    3534                 reply_nterror(req, map_nt_error_from_unix(errno));
    3535                 return;
    3536         }
    3537 
    35383546        init_strict_lock_struct(fsp, (uint64_t)req->smbpid,
    35393547            (uint64_t)startpos, (uint64_t)smb_maxcnt, READ_LOCK,
     
    35433551                reply_nterror(req, NT_STATUS_FILE_LOCK_CONFLICT);
    35443552                return;
    3545         }
    3546 
    3547         if (!S_ISREG(fsp->fsp_name->st.st_ex_mode) ||
    3548                         (startpos > fsp->fsp_name->st.st_ex_size)
    3549                         || (smb_maxcnt > (fsp->fsp_name->st.st_ex_size - startpos))) {
    3550                 /*
    3551                  * We already know that we would do a short read, so don't
    3552                  * try the sendfile() path.
    3553                  */
    3554                 goto nosendfile_read;
    35553553        }
    35563554
     
    35623560
    35633561        if (!req_is_in_chain(req) &&
    3564             !is_encrypted_packet(req->inbuf) && (fsp->base_fsp == NULL) &&
     3562            !req->encrypted && (fsp->base_fsp == NULL) &&
    35653563            (fsp->wcp == NULL) &&
    35663564            lp_use_sendfile(SNUM(conn), req->sconn->smb1.signing_state) ) {
    35673565                uint8 headerbuf[smb_size + 12 * 2];
    35683566                DATA_BLOB header;
     3567
     3568                if(fsp_stat(fsp) == -1) {
     3569                        reply_nterror(req, map_nt_error_from_unix(errno));
     3570                        goto strict_unlock;
     3571                }
     3572
     3573                if (!S_ISREG(fsp->fsp_name->st.st_ex_mode) ||
     3574                    (startpos > fsp->fsp_name->st.st_ex_size) ||
     3575                    (smb_maxcnt > (fsp->fsp_name->st.st_ex_size - startpos))) {
     3576                        /*
     3577                         * We already know that we would do a short read, so don't
     3578                         * try the sendfile() path.
     3579                         */
     3580                        goto nosendfile_read;
     3581                }
    35693582
    35703583                /*
     
    37663779                        }
    37673780                        /* We currently don't do this on signed or sealed data. */
    3768                         if (srv_is_signing_active(req->sconn) ||
    3769                             is_encrypted_packet(req->inbuf)) {
     3781                        if (srv_is_signing_active(req->sconn) || req->encrypted) {
    37703782                                reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
    37713783                                END_PROFILE(SMBreadX);
     
    55305542                                 req->flags2 & FLAGS2_DFS_PATHNAMES,
    55315543                                 directory,
    5532                                  0,
     5544                                 UCF_CREATING_FILE,
    55335545                                 NULL,
    55345546                                 &smb_dname);
     
    61886200                          smb_fname_str_dbg(smb_fname_dst)));
    61896201
    6190                 if (!lp_posix_pathnames() &&
     6202                if (!fsp->is_directory &&
     6203                    !lp_posix_pathnames() &&
    61916204                    (lp_map_archive(SNUM(conn)) ||
    61926205                    lp_store_dos_attributes(SNUM(conn)))) {
  • vendor/current/source3/smbd/server.c

    r746 r860  
    109109        change_to_root_user();
    110110        reload_services(msg, smbd_server_conn->sock, False);
    111         if (am_parent) {
    112                 pcap_cache_reload(ev_ctx, msg,
    113                                   &reload_pcap_change_notify);
    114         }
     111        /* printer reload triggered by background printing process */
    115112}
    116113
     
    132129        reload_printers(ev_ctx, msg);
    133130}
     131
     132static void smbd_sig_term_handler(struct tevent_context *ev,
     133                                  struct tevent_signal *se,
     134                                  int signum,
     135                                  int count,
     136                                  void *siginfo,
     137                                  void *private_data)
     138{
     139        exit_server_cleanly("termination signal");
     140}
     141
     142static void smbd_setup_sig_term_handler(void)
     143{
     144        struct tevent_signal *se;
     145
     146        se = tevent_add_signal(smbd_event_context(),
     147                               smbd_event_context(),
     148                               SIGTERM, 0,
     149                               smbd_sig_term_handler,
     150                               NULL);
     151        if (!se) {
     152                exit_server("failed to setup SIGTERM handler");
     153        }
     154}
     155
     156static void smbd_sig_hup_handler(struct tevent_context *ev,
     157                                 struct tevent_signal *se,
     158                                 int signum,
     159                                 int count,
     160                                 void *siginfo,
     161                                 void *private_data)
     162{
     163        struct messaging_context *msg_ctx = talloc_get_type_abort(
     164                private_data, struct messaging_context);
     165        change_to_root_user();
     166        DEBUG(1,("Reloading services after SIGHUP\n"));
     167        reload_services(msg_ctx, smbd_server_conn->sock, false);
     168}
     169
     170static void smbd_setup_sig_hup_handler(struct tevent_context *ev,
     171                                       struct messaging_context *msg_ctx)
     172{
     173        struct tevent_signal *se;
     174
     175        se = tevent_add_signal(ev, ev, SIGHUP, 0, smbd_sig_hup_handler,
     176                               msg_ctx);
     177        if (!se) {
     178                exit_server("failed to setup SIGHUP handler");
     179        }
     180}
     181
    134182
    135183/*******************************************************************
     
    773821                           smb_stat_cache_delete);
    774822        messaging_register(msg_ctx, NULL, MSG_DEBUG, smbd_msg_debug);
    775         messaging_register(msg_ctx, server_event_context(), MSG_PRINTER_PCAP,
    776                            smb_pcap_updated);
    777823        brl_register_msgs(msg_ctx);
    778824
     
    12351281                exit(1);
    12361282
    1237         /* Publish nt printers, this requires a working winreg pipe */
    1238         pcap_cache_reload(server_event_context(), smbd_messaging_context(),
    1239                           &reload_printers);
    1240 
    12411283        /* only start the background queue daemon if we are
    12421284           running as a daemon -- bad things will happen if
     
    12461288        if (is_daemon && !interactive
    12471289            && lp_parm_bool(-1, "smbd", "backgroundqueue", true)) {
    1248                 start_background_queue(smbd_event_context(),
    1249                                        smbd_messaging_context());
     1290                /* background queue is responsible for printcap cache updates */
     1291                messaging_register(smbd_server_conn->msg_ctx,
     1292                                   smbd_event_context(),
     1293                                   MSG_PRINTER_PCAP, smb_pcap_updated);
     1294                start_background_queue(server_event_context(),
     1295                                       smbd_server_conn->msg_ctx);
     1296        } else {
     1297                DEBUG(3, ("running without background printer process, dynamic "
     1298                          "printer updates disabled\n"));
     1299                /* Publish nt printers, this requires a working winreg pipe */
     1300                pcap_cache_reload(server_event_context(),
     1301                                  smbd_messaging_context(),
     1302                                  &reload_printers_full);
    12501303        }
    12511304
  • vendor/current/source3/smbd/server_reload.c

    r746 r860  
    3737                     struct messaging_context *msg_ctx)
    3838{
     39        int n_services;
     40        int pnum;
     41        int snum;
     42        const char *pname;
     43
     44        n_services = lp_numservices();
     45        pnum = lp_servicenumber(PRINTERS_NAME);
     46
     47        DEBUG(10, ("reloading printer services from pcap cache\n"));
     48
     49        /*
     50         * Add default config for printers added to smb.conf file and remove
     51         * stale printers
     52         */
     53        for (snum = 0; snum < n_services; snum++) {
     54                /* avoid removing PRINTERS_NAME */
     55                if (snum == pnum) {
     56                        continue;
     57                }
     58
     59                /* skip no-printer services */
     60                if (!(lp_snum_ok(snum) && lp_print_ok(snum))) {
     61                        continue;
     62                }
     63
     64                pname = lp_printername(snum);
     65
     66                /* check printer, but avoid removing non-autoloaded printers */
     67                if (lp_autoloaded(snum) && !pcap_printername_ok(pname)) {
     68                        DEBUG(3, ("removing stale printer %s\n", pname));
     69                        lp_killservice(snum);
     70                }
     71        }
     72
     73        /* Make sure deleted printers are gone */
     74        load_printers(ev, msg_ctx);
     75}
     76
     77/****************************************************************************
     78 purge stale printers and reload from pre-populated pcap cache
     79**************************************************************************/
     80void reload_printers_full(struct tevent_context *ev,
     81                          struct messaging_context *msg_ctx)
     82{
    3983        struct auth_serversupplied_info *session_info = NULL;
    40         struct spoolss_PrinterInfo2 *pinfo2 = NULL;
    4184        int n_services;
    4285        int pnum;
     
    4689        NTSTATUS status;
    4790
    48         load_printers(ev, msg_ctx);
    49 
    5091        n_services = lp_numservices();
    5192        pnum = lp_servicenumber(PRINTERS_NAME);
    5293
    53         DEBUG(10, ("reloading printer services from pcap cache\n"));
    54 
    55         status = make_session_info_system(talloc_tos(), &session_info);
     94        status = make_session_info_system(talloc_new(NULL), &session_info);
    5695        if (!NT_STATUS_IS_OK(status)) {
    57                 DEBUG(3, ("reload_printers: "
    58                           "Could not create system session_info\n"));
     96                DEBUG(3, ("Could not create system session_info\n"));
    5997                /* can't remove stale printers before we
    6098                 * are fully initilized */
     
    82120                /* check printer, but avoid removing non-autoloaded printers */
    83121                if (lp_autoloaded(snum) && !pcap_printername_ok(pname)) {
    84                         DEBUG(3, ("removing stale printer %s\n", pname));
    85 
     122                        struct spoolss_PrinterInfo2 *pinfo2 = NULL;
    86123                        if (is_printer_published(session_info, session_info,
    87124                                                 msg_ctx,
    88                                                  NULL, lp_servicename(snum),
    89                                                  NULL, &pinfo2)) {
     125                                                 NULL,
     126                                                 lp_servicename(snum),
     127                                                 &pinfo2)) {
    90128                                nt_printer_publish(session_info,
    91129                                                   session_info,
     
    97135                        nt_printer_remove(session_info, session_info, msg_ctx,
    98136                                          pname);
    99                         lp_killservice(snum);
    100137                } else {
    101138                        DEBUG(8, ("Adding default registry entry for printer "
     
    106143        }
    107144
    108         /* Make sure deleted printers are gone */
    109         load_printers(ev, msg_ctx);
     145        /* finally, purge old snums */
     146        reload_printers(ev, msg_ctx);
    110147
    111148        TALLOC_FREE(session_info);
     
    161198        return(ret);
    162199}
    163 
    164 /****************************************************************************
    165  Notify smbds of new printcap data
    166 **************************************************************************/
    167 void reload_pcap_change_notify(struct tevent_context *ev,
    168                                struct messaging_context *msg_ctx)
    169 {
    170         /*
    171          * Reload the printers first in the background process so that
    172          * newly added printers get default values created in the registry.
    173          *
    174          * This will block the process for some time (~1 sec per printer), but
    175          * it doesn't block smbd's servering clients.
    176          */
    177         reload_printers(ev, msg_ctx);
    178 
    179         message_send_all(msg_ctx, MSG_PRINTER_PCAP, NULL, 0, NULL);
    180 }
  • vendor/current/source3/smbd/service.c

    r746 r860  
    657657                }
    658658
    659                 return make_serverinfo_from_username(mem_ctx, user, guest,
     659                return make_serverinfo_from_username(mem_ctx, user, guest, guest,
    660660                                                     presult);
    661661        }
     
    691691
    692692                status = make_serverinfo_from_username(
    693                         conn, fuser, conn->session_info->guest,
     693                        conn, fuser, false, conn->session_info->guest,
    694694                        &forced_serverinfo);
    695695                if (!NT_STATUS_IS_OK(status)) {
  • vendor/current/source3/smbd/sesssetup.c

    r746 r860  
    906906                        (unsigned int)pblob->length ));
    907907
     908                if (pblob->length > pad->needed_len) {
     909                        DEBUG(2, ("subsequent security token data length %u "
     910                                  "exceeds expected length %u\n",
     911                                  (unsigned int)pblob->length,
     912                                  (unsigned int)pad->needed_len));
     913                }
     914
    908915                tmp_blob = data_blob(NULL,
    909916                                pad->partial_data.length + copy_len);
     
    11661173        status = check_spnego_blob_complete(sconn, smbpid, vuid, &blob1);
    11671174        if (!NT_STATUS_IS_OK(status)) {
     1175                /*
     1176                 * Pack error response, ensuring to fill NativeOS, NativeLanMan
     1177                 * & PrimaryDomain fields on NT_STATUS_MORE_PROCESSING_REQUIRED
     1178                 */
     1179                reply_outbuf(req, 4, 0);
     1180                reply_sesssetup_blob(req, data_blob_null, status);
    11681181                if (!NT_STATUS_EQUAL(status,
    11691182                                NT_STATUS_MORE_PROCESSING_REQUIRED)) {
     
    11721185                }
    11731186                data_blob_free(&blob1);
    1174                 reply_nterror(req, nt_status_squash(status));
    11751187                return;
    11761188        }
  • vendor/current/source3/smbd/smb2_create.c

    r746 r860  
    695695                                          smb1req->flags2 & FLAGS2_DFS_PATHNAMES,
    696696                                          fname,
    697                                           0,
     697                                          (in_create_disposition == FILE_CREATE) ?
     698                                                UCF_CREATING_FILE : 0,
    698699                                          NULL,
    699700                                          &smb_fname);
     
    894895                return false;
    895896        }
    896         if (!smb2req->async) {
    897                 return false;
    898         }
    899897        req = smb2req->subreq;
    900898        if (!req) {
     
    903901        state = tevent_req_data(req, struct smbd_smb2_create_state);
    904902        if (!state) {
     903                return false;
     904        }
     905        if (!state->open_was_deferred) {
    905906                return false;
    906907        }
  • vendor/current/source3/smbd/smb2_getinfo.c

    r746 r860  
    149149        }
    150150
    151         if (!NT_STATUS_IS_OK(call_status)) {
     151        /* some GetInfo responses set STATUS_BUFFER_OVERFLOW and return partial,
     152           but valid data */
     153        if (!(NT_STATUS_IS_OK(call_status) ||
     154              NT_STATUS_EQUAL(call_status, STATUS_BUFFER_OVERFLOW))) {
    152155                /* Return a specific error with data. */
    153156                error = smbd_smb2_request_error_ex(req,
     
    186189        outdyn = out_output_buffer;
    187190
    188         error = smbd_smb2_request_done(req, outbody, &outdyn);
     191        error = smbd_smb2_request_done_ex(req, call_status, outbody, &outdyn, __location__);
    189192        if (!NT_STATUS_IS_OK(error)) {
    190193                smbd_server_connection_terminate(req->sconn,
     
    271274
    272275        switch (in_info_type) {
    273         case 0x01:/* SMB2_GETINFO_FILE */
     276        case SMB2_GETINFO_FILE:
    274277        {
    275278                uint16_t file_info_level;
     
    282285                int lock_data_count = 0;
    283286                char *lock_data = NULL;
     287                size_t fixed_portion;
    284288
    285289                ZERO_STRUCT(write_time_ts);
     
    369373                                               STR_UNICODE,
    370374                                               in_output_buffer_length,
     375                                               &fixed_portion,
    371376                                               &data,
    372377                                               &data_size);
     
    377382                        }
    378383                        tevent_req_nterror(req, status);
     384                        return tevent_req_post(req, ev);
     385                }
     386                if (in_output_buffer_length < fixed_portion) {
     387                        SAFE_FREE(data);
     388                        tevent_req_nterror(
     389                                req, NT_STATUS_INFO_LENGTH_MISMATCH);
    379390                        return tevent_req_post(req, ev);
    380391                }
     
    387398                                return tevent_req_post(req, ev);
    388399                        }
     400                        if (data_size > in_output_buffer_length) {
     401                                state->out_output_buffer.length =
     402                                        in_output_buffer_length;
     403                                status = STATUS_BUFFER_OVERFLOW;
     404                        }
    389405                }
    390406                SAFE_FREE(data);
     
    392408        }
    393409
    394         case 0x02:/* SMB2_GETINFO_FS */
     410        case SMB2_GETINFO_FS:
    395411        {
    396412                uint16_t file_info_level;
    397413                char *data = NULL;
    398414                int data_size = 0;
     415                size_t fixed_portion;
    399416
    400417                /* the levels directly map to the passthru levels */
     
    405422                                         STR_UNICODE,
    406423                                         in_output_buffer_length,
     424                                         &fixed_portion,
     425                                         fsp->fsp_name,
    407426                                         &data,
    408427                                         &data_size);
    409                 if (!NT_STATUS_IS_OK(status)) {
     428                /* some responses set STATUS_BUFFER_OVERFLOW and return
     429                   partial, but valid data */
     430                if (!(NT_STATUS_IS_OK(status) ||
     431                      NT_STATUS_EQUAL(status, STATUS_BUFFER_OVERFLOW))) {
    410432                        SAFE_FREE(data);
    411433                        if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_LEVEL)) {
     
    413435                        }
    414436                        tevent_req_nterror(req, status);
     437                        return tevent_req_post(req, ev);
     438                }
     439                if (in_output_buffer_length < fixed_portion) {
     440                        SAFE_FREE(data);
     441                        tevent_req_nterror(
     442                                req, NT_STATUS_INFO_LENGTH_MISMATCH);
    415443                        return tevent_req_post(req, ev);
    416444                }
     
    423451                                return tevent_req_post(req, ev);
    424452                        }
     453                        if (data_size > in_output_buffer_length) {
     454                                state->out_output_buffer.length =
     455                                        in_output_buffer_length;
     456                                status = STATUS_BUFFER_OVERFLOW;
     457                        }
    425458                }
    426459                SAFE_FREE(data);
     
    428461        }
    429462
    430         case 0x03:/* SMB2_GETINFO_SEC */
     463        case SMB2_GETINFO_SECURITY:
    431464        {
    432465                uint8_t *p_marshalled_sd = NULL;
     
    485518        }
    486519
     520        state->status = status;
    487521        tevent_req_done(req);
    488522        return tevent_req_post(req, ev);
  • vendor/current/source3/smbd/smb2_server.c

    r746 r860  
    928928        uint64_t message_id = 0;
    929929        uint64_t async_id = 0;
    930         struct iovec *outvec = NULL;
    931930
    932931        if (!tevent_req_is_in_progress(subreq)) {
     
    945944                /*
    946945                 * We're trying to go async in a compound
    947                  * request chain. This is not allowed.
    948                  * Cancel the outstanding request.
    949                  */
    950                 bool ok = tevent_req_cancel(req->subreq);
    951                 if (ok) {
    952                         return NT_STATUS_OK;
    953                 }
    954                 TALLOC_FREE(req->subreq);
    955                 return smbd_smb2_request_error(req,
    956                         NT_STATUS_INTERNAL_ERROR);
     946                 * request chain.
     947                 * This is only allowed for opens that
     948                 * cause an oplock break, otherwise it
     949                 * is not allowed. See [MS-SMB2].pdf
     950                 * note <194> on Section 3.3.5.2.7.
     951                 */
     952                const uint8_t *inhdr =
     953                        (const uint8_t *)req->in.vector[i].iov_base;
     954
     955                if (SVAL(inhdr, SMB2_HDR_OPCODE) != SMB2_OP_CREATE) {
     956                        /*
     957                         * Cancel the outstanding request.
     958                         */
     959                        bool ok = tevent_req_cancel(req->subreq);
     960                        if (ok) {
     961                                return NT_STATUS_OK;
     962                        }
     963                        TALLOC_FREE(req->subreq);
     964                        return smbd_smb2_request_error(req,
     965                                NT_STATUS_INTERNAL_ERROR);
     966                }
    957967        }
    958968
     
    963973        }
    964974
    965         if (req->out.vector_count > 4) {
    966                 /* This is a compound reply. We
    967                  * must do an interim response
    968                  * followed by the async response
    969                  * to match W2K8R2.
     975        if (i > 1) {
     976                /*
     977                 * We're going async in a compound
     978                 * chain after the first request has
     979                 * already been processed. Send an
     980                 * interim response containing the
     981                 * set of replies already generated.
    970982                 */
    971983                status = smb2_send_async_interim_response(req);
     
    974986                }
    975987
    976                 /*
    977                  * We're splitting off the last SMB2
    978                  * request in a compound set, and the
    979                  * smb2_send_async_interim_response()
    980                  * call above just sent all the replies
    981                  * for the previous SMB2 requests in
    982                  * this compound set. So we're no longer
    983                  * in the "compound_related_in_progress"
    984                  * state, and this is no longer a compound
    985                  * request.
    986                  */
    987                 req->compound_related = false;
    988                 req->sconn->smb2.compound_related_in_progress = false;
     988                req->current_idx = 1;
     989
     990                /*
     991                 * Re-arrange the in.vectors to remove what
     992                 * we just sent.
     993                 */
     994                memmove(&req->in.vector[1],
     995                        &req->in.vector[i],
     996                        sizeof(req->in.vector[0])*(req->in.vector_count - i));
     997                req->in.vector_count = 1 + (req->in.vector_count - i);
     998
     999                smb2_setup_nbt_length(req->in.vector, req->in.vector_count);
     1000
     1001                /* Re-arrange the out.vectors to match. */
     1002                memmove(&req->out.vector[1],
     1003                        &req->out.vector[i],
     1004                        sizeof(req->out.vector[0])*(req->out.vector_count - i));
     1005                req->out.vector_count = 1 + (req->out.vector_count - i);
     1006
     1007                if (req->in.vector_count == 4) {
     1008                        uint8_t *outhdr = (uint8_t *)req->out.vector[i].iov_base;
     1009                        /*
     1010                         * We only have one remaining request as
     1011                         * we've processed everything else.
     1012                         * This is no longer a compound request.
     1013                         */
     1014                        req->compound_related = false;
     1015                        flags = (IVAL(outhdr, SMB2_HDR_FLAGS) & ~SMB2_HDR_FLAG_CHAINED);
     1016                        SIVAL(outhdr, SMB2_HDR_FLAGS, flags);
     1017                }
    9891018        }
    9901019
    9911020        /* Don't return an intermediate packet on a pipe read/write. */
    9921021        if (req->tcon && req->tcon->compat_conn && IS_IPC(req->tcon->compat_conn)) {
    993                 goto ipc_out;
     1022                goto out;
    9941023        }
    9951024
     
    10811110        /* Note we're going async with this request. */
    10821111        req->async = true;
    1083 
    1084   ipc_out:
    1085 
    1086         /*
    1087          * Now manipulate req so that the outstanding async request
    1088          * is the only one left in the struct smbd_smb2_request.
    1089          */
    1090 
    1091         if (req->current_idx == 1) {
    1092                 /* There was only one. */
    1093                 goto out;
    1094         }
    1095 
    1096         /* Re-arrange the in.vectors. */
    1097         req->in.vector[1] = req->in.vector[i];
    1098         req->in.vector[2] = req->in.vector[i+1];
    1099         req->in.vector[3] = req->in.vector[i+2];
    1100         req->in.vector_count = 4;
    1101         /* Reset the new in size. */
    1102         smb2_setup_nbt_length(req->in.vector, 4);
    1103 
    1104         /* Now recreate the out.vectors. */
    1105         outvec = talloc_zero_array(req, struct iovec, 4);
    1106         if (!outvec) {
    1107                 return NT_STATUS_NO_MEMORY;
    1108         }
    1109 
    1110         /* 0 is always boilerplate and must
    1111          * be of size 4 for the length field. */
    1112 
    1113         outvec[0].iov_base = req->out.nbt_hdr;
    1114         outvec[0].iov_len = 4;
    1115         SIVAL(req->out.nbt_hdr, 0, 0);
    1116 
    1117         if (!dup_smb2_vec3(outvec, &outvec[1], &req->out.vector[i])) {
    1118                 return NT_STATUS_NO_MEMORY;
    1119         }
    1120 
    1121         TALLOC_FREE(req->out.vector);
    1122 
    1123         req->out.vector = outvec;
    1124 
    1125         req->current_idx = 1;
    1126         req->out.vector_count = 4;
    11271112
    11281113  out:
     
    11781163                uint64_t message_id;
    11791164                uint64_t async_id;
     1165
     1166                if (cur->compound_related) {
     1167                        /*
     1168                         * Never cancel anything in a compound request.
     1169                         * Way too hard to deal with the result.
     1170                         */
     1171                        continue;
     1172                }
    11801173
    11811174                i = cur->current_idx;
     
    13611354        if (flags & SMB2_HDR_FLAG_CHAINED) {
    13621355                req->compound_related = true;
    1363                 req->sconn->smb2.compound_related_in_progress = true;
    13641356        }
    13651357
     
    18031795                        return NT_STATUS_NO_MEMORY;
    18041796                }
     1797
     1798                if (req->do_signing) {
     1799                        /*
     1800                         * We sign each reply as we go along.
     1801                         * We can do this as smb2_calculate_credits()
     1802                         * grants zero credits on every part of a
     1803                         * compound reply except the last one,
     1804                         * which is signed just before calling
     1805                         * tstream_writev_queue_send().
     1806                         */
     1807                        NTSTATUS status;
     1808                        status = smb2_signing_sign_pdu(req->session->session_key,
     1809                                               &req->out.vector[i], 3);
     1810                        if (!NT_STATUS_IS_OK(status)) {
     1811                                TALLOC_FREE(im);
     1812                                return status;
     1813                        }
     1814                }
     1815
    18051816                tevent_schedule_immediate(im,
    18061817                                        req->sconn->smb2.event_ctx,
     
    18121823        if (req->compound_related) {
    18131824                req->compound_related = false;
    1814                 req->sconn->smb2.compound_related_in_progress = false;
    18151825        }
    18161826
     
    25292539        struct tevent_req *subreq;
    25302540
    2531         if (sconn->smb2.compound_related_in_progress) {
    2532                 /*
    2533                  * Can't read another until the related
    2534                  * compound is done.
    2535                  */
    2536                 return NT_STATUS_OK;
    2537         }
    2538 
    25392541        if (tevent_queue_length(sconn->smb2.recv_queue) > 0) {
    25402542                /*
  • vendor/current/source3/smbd/smb2_tcon.c

    r746 r860  
    208208        }
    209209
     210        /* Don't allow connection if encryption is required. */
     211        if (lp_smb_encrypt(snum) == Required) {
     212                DEBUG(0,("Connection refused on share %s as encryption is"
     213                        " required on this share and SMB2 does not support"
     214                        " this.\n",
     215                        lp_servicename(snum)));
     216                return NT_STATUS_ACCESS_DENIED;
     217        }
     218
    210219        /* create a new tcon as child of the session */
    211220        tcon = talloc_zero(req->session, struct smbd_smb2_tcon);
  • vendor/current/source3/smbd/trans2.c

    r746 r860  
    2525
    2626#include "includes.h"
     27#include "ntioctl.h"
    2728#include "system/filesys.h"
    2829#include "version.h"
     
    329330                }
    330331
     332                if (listp->ea.value.length == 0) {
     333                        /*
     334                         * We can never return a zero length EA.
     335                         * Windows reports the EA's as corrupted.
     336                         */
     337                        TALLOC_FREE(listp);
     338                        continue;
     339                }
     340
    331341                push_ascii_fstring(dos_ea_name, listp->ea.name);
    332342
     
    412422        uint8_t *p = (uint8_t *)pdata;
    413423        uint8_t *last_start = NULL;
     424        bool store_data = (pdata != NULL);
    414425
    415426        *ret_data_size = 0;
     
    423434                fstring dos_ea_name;
    424435                size_t this_size;
    425 
    426                 if (last_start) {
     436                size_t pad = 0;
     437
     438                if (last_start && store_data) {
    427439                        SIVAL(last_start, 0, PTR_DIFF(p, last_start));
    428440                }
     
    441453
    442454                if (ea_list->next) {
    443                         size_t pad = 4 - (this_size % 4);
     455                        pad = (4 - (this_size % 4)) % 4;
    444456                        this_size += pad;
    445457                }
     
    450462
    451463                /* We know we have room. */
    452                 SIVAL(p, 0x00, 0); /* next offset */
    453                 SCVAL(p, 0x04, ea_list->ea.flags);
    454                 SCVAL(p, 0x05, dos_namelen);
    455                 SSVAL(p, 0x06, ea_list->ea.value.length);
    456                 fstrcpy((char *)(p+0x08), dos_ea_name);
    457                 memcpy(p + 0x08 + dos_namelen + 1, ea_list->ea.value.data, ea_list->ea.value.length);
     464                if (store_data) {
     465                        SIVAL(p, 0x00, 0); /* next offset */
     466                        SCVAL(p, 0x04, ea_list->ea.flags);
     467                        SCVAL(p, 0x05, dos_namelen);
     468                        SSVAL(p, 0x06, ea_list->ea.value.length);
     469                        fstrcpy((char *)(p+0x08), dos_ea_name);
     470                        memcpy(p + 0x08 + dos_namelen + 1, ea_list->ea.value.data, ea_list->ea.value.length);
     471                        if (pad) {
     472                                memset(p + 0x08 + dos_namelen + 1 + ea_list->ea.value.length,
     473                                        '\0',
     474                                        pad);
     475                        }
     476                }
    458477
    459478                total_data_size -= this_size;
     
    469488{
    470489        size_t total_ea_len = 0;
     490        struct ea_list *ea_list = NULL;
    471491        TALLOC_CTX *mem_ctx = NULL;
    472492
     
    475495        }
    476496        mem_ctx = talloc_tos();
    477         (void)get_ea_list_from_file(mem_ctx, conn, fsp, fname, &total_ea_len);
     497        ea_list = get_ea_list_from_file(mem_ctx, conn, fsp, fname, &total_ea_len);
     498        if (ea_list == NULL) {
     499                return 0;
     500        }
     501        if(conn->sconn->using_smb2) {
     502                NTSTATUS status;
     503                unsigned int ret_data_size;
     504                /*
     505                 * We're going to be using fill_ea_chained_buffer() to
     506                 * marshall EA's - this size is significantly larger
     507                 * than the SMB1 buffer. Re-calculate the size without
     508                 * marshalling.
     509                 */
     510                status = fill_ea_chained_buffer(mem_ctx,
     511                                                NULL,
     512                                                65535,
     513                                                &ret_data_size,
     514                                                conn,
     515                                                ea_list);
     516                if (!NT_STATUS_IS_OK(status)) {
     517                        ret_data_size = 0;
     518                }
     519                total_ea_len = ret_data_size;
     520        }
     521
    478522        return total_ea_len;
    479523}
     
    17311775                SIVAL(p,0,mode); p += 4;
    17321776                q = p; p += 4; /* q is placeholder for name length. */
    1733                 {
     1777                if (mode & FILE_ATTRIBUTE_REPARSE_POINT) {
     1778                        SIVAL(p, 0, IO_REPARSE_TAG_DFS);
     1779                } else {
    17341780                        unsigned int ea_size = estimate_ea_size(conn, NULL,
    17351781                                                                smb_fname->base_name);
    17361782                        SIVAL(p,0,ea_size); /* Extended attributes */
    1737                         p += 4;
    1738                 }
     1783                }
     1784                p += 4;
    17391785                /* Clear the short name buffer. This is
    17401786                 * IMPORTANT as not doing so will trigger
     
    19081954                SIVAL(p,0,mode); p += 4;
    19091955                q = p; p += 4; /* q is placeholder for name length. */
    1910                 {
     1956                if (mode & FILE_ATTRIBUTE_REPARSE_POINT) {
     1957                        SIVAL(p, 0, IO_REPARSE_TAG_DFS);
     1958                } else {
    19111959                        unsigned int ea_size = estimate_ea_size(conn, NULL,
    19121960                                                                smb_fname->base_name);
    19131961                        SIVAL(p,0,ea_size); /* Extended attributes */
    1914                         p +=4;
    1915                 }
     1962                }
     1963                p +=4;
    19161964                SIVAL(p,0,0); p += 4; /* Unknown - reserved ? */
    19171965                SBVAL(p,0,file_index); p += 8;
     
    19542002                SIVAL(p,0,mode); p += 4;
    19552003                q = p; p += 4; /* q is placeholder for name length */
    1956                 {
     2004                if (mode & FILE_ATTRIBUTE_REPARSE_POINT) {
     2005                        SIVAL(p, 0, IO_REPARSE_TAG_DFS);
     2006                } else {
    19572007                        unsigned int ea_size = estimate_ea_size(conn, NULL,
    19582008                                                                smb_fname->base_name);
    19592009                        SIVAL(p,0,ea_size); /* Extended attributes */
    1960                         p +=4;
    1961                 }
     2010                }
     2011                p +=4;
    19622012                /* Clear the short name buffer. This is
    19632013                 * IMPORTANT as not doing so will trigger
     
    29222972                         uint16_t flags2,
    29232973                         unsigned int max_data_bytes,
     2974                         size_t *fixed_portion,
     2975                         struct smb_filename *fname,
    29242976                         char **ppdata,
    29252977                         int *ret_data_len)
     
    29302982        int snum = SNUM(conn);
    29312983        char *fstype = lp_fstype(SNUM(conn));
     2984        const char *filename = NULL;
    29322985        uint32 additional_flags = 0;
    2933         struct smb_filename smb_fname_dot;
     2986        struct smb_filename smb_fname;
    29342987        SMB_STRUCT_STAT st;
     2988        NTSTATUS status = NT_STATUS_OK;
     2989
     2990        if (fname == NULL || fname->base_name == NULL) {
     2991                filename = ".";
     2992        } else {
     2993                filename = fname->base_name;
     2994        }
    29352995
    29362996        if (IS_IPC(conn)) {
     
    29453005        DEBUG(3,("smbd_do_qfsinfo: level = %d\n", info_level));
    29463006
    2947         ZERO_STRUCT(smb_fname_dot);
    2948         smb_fname_dot.base_name = discard_const_p(char, ".");
    2949 
    2950         if(SMB_VFS_STAT(conn, &smb_fname_dot) != 0) {
     3007        ZERO_STRUCT(smb_fname);
     3008        smb_fname.base_name = discard_const_p(char, filename);
     3009
     3010        if(SMB_VFS_STAT(conn, &smb_fname) != 0) {
    29513011                DEBUG(2,("stat of . failed (%s)\n", strerror(errno)));
    29523012                return map_nt_error_from_unix(errno);
    29533013        }
    29543014
    2955         st = smb_fname_dot.st;
     3015        st = smb_fname.st;
    29563016
    29573017        *ppdata = (char *)SMB_REALLOC(
     
    29643024        memset((char *)pdata,'\0',max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
    29653025        end_data = pdata + max_data_bytes + DIR_ENTRY_SAFETY_MARGIN - 1;
     3026
     3027        *fixed_portion = 0;
    29663028
    29673029        switch (info_level) {
     
    29703032                        uint64_t dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
    29713033                        data_len = 18;
    2972                         if (get_dfree_info(conn,".",False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
     3034                        if (get_dfree_info(conn,filename,False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
    29733035                                return map_nt_error_from_unix(errno);
    29743036                        }
     
    30573119                        SIVAL(pdata,8,len);
    30583120                        data_len = 12 + len;
     3121                        if (max_data_bytes >= 16 && data_len > max_data_bytes) {
     3122                                /* the client only requested a portion of the
     3123                                   file system name */
     3124                                data_len = max_data_bytes;
     3125                                status = STATUS_BUFFER_OVERFLOW;
     3126                        }
     3127                        *fixed_portion = 16;
    30593128                        break;
    30603129
     
    30863155                        DEBUG(5,("smbd_do_qfsinfo : SMB_QUERY_FS_VOLUME_INFO namelen = %d, vol=%s serv=%s\n",
    30873156                                (int)strlen(vname),vname, lp_servicename(snum)));
     3157                        if (max_data_bytes >= 24 && data_len > max_data_bytes) {
     3158                                /* the client only requested a portion of the
     3159                                   volume label */
     3160                                data_len = max_data_bytes;
     3161                                status = STATUS_BUFFER_OVERFLOW;
     3162                        }
     3163
    30883164                        break;
    30893165
     
    30933169                        uint64_t dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
    30943170                        data_len = 24;
    3095                         if (get_dfree_info(conn,".",False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
     3171                        if (get_dfree_info(conn,filename,False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
    30963172                                return map_nt_error_from_unix(errno);
    30973173                        }
     
    31183194                        SIVAL(pdata,16,sectors_per_unit);
    31193195                        SIVAL(pdata,20,bytes_per_sector);
     3196                        *fixed_portion = 24;
    31203197                        break;
    31213198                }
     
    31253202                        uint64_t dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
    31263203                        data_len = 32;
    3127                         if (get_dfree_info(conn,".",False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
     3204                        if (get_dfree_info(conn,filename,False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
    31283205                                return map_nt_error_from_unix(errno);
    31293206                        }
     
    31513228                        SIVAL(pdata,24,sectors_per_unit); /* Sectors per allocation unit. */
    31523229                        SIVAL(pdata,28,bytes_per_sector); /* Bytes per sector. */
     3230                        *fixed_portion = 32;
    31533231                        break;
    31543232                }
     
    31653243                        SIVAL(pdata,0,FILE_DEVICE_DISK); /* dev type */
    31663244                        SIVAL(pdata,4,characteristics);
     3245                        *fixed_portion = 8;
    31673246                        break;
    31683247                }
     
    33183397                        }
    33193398
    3320                         rc = SMB_VFS_STATVFS(conn, ".", &svfs);
     3399                        rc = SMB_VFS_STATVFS(conn, filename, &svfs);
    33213400
    33223401                        if (!rc) {
     
    33393418                                return NT_STATUS_DOS(ERRSRV, ERRerror);
    33403419                        }
     3420                        *fixed_portion = 24;
    33413421                        break;
    33423422                }
     
    34693549
    34703550        *ret_data_len = data_len;
    3471         return NT_STATUS_OK;
     3551        return status;
    34723552}
    34733553
     
    34853565        uint16_t info_level;
    34863566        int data_len = 0;
     3567        size_t fixed_portion;
    34873568        NTSTATUS status;
    34883569
     
    35113592                                 req->flags2,
    35123593                                 max_data_bytes,
     3594                                 &fixed_portion,
     3595                                 NULL,
    35133596                                 ppdata, &data_len);
    35143597        if (!NT_STATUS_IS_OK(status)) {
     
    40634146        unsigned int ofs = 0;
    40644147
    4065         for (i = 0; i < num_streams && ofs <= max_data_bytes; i++) {
     4148        if (max_data_bytes < 32) {
     4149                return NT_STATUS_INFO_LENGTH_MISMATCH;
     4150        }
     4151
     4152        for (i = 0; i < num_streams; i++) {
    40664153                unsigned int next_offset;
    40674154                size_t namelen;
     
    40824169                namelen -= 2;
    40834170
     4171                /*
     4172                 * We cannot overflow ...
     4173                 */
     4174                if ((ofs + 24 + namelen) > max_data_bytes) {
     4175                        DEBUG(10, ("refusing to overflow reply at stream %u\n",
     4176                                i));
     4177                        TALLOC_FREE(namebuf);
     4178                        return STATUS_BUFFER_OVERFLOW;
     4179                }
     4180
    40844181                SIVAL(data, ofs+4, namelen);
    40854182                SOFF_T(data, ofs+8, streams[i].size);
     
    40964193                        unsigned int align = ndr_align_size(next_offset, 8);
    40974194
     4195                        if ((next_offset + align) > max_data_bytes) {
     4196                                DEBUG(10, ("refusing to overflow align "
     4197                                        "reply at stream %u\n",
     4198                                        i));
     4199                                TALLOC_FREE(namebuf);
     4200                                return STATUS_BUFFER_OVERFLOW;
     4201                        }
     4202
    40984203                        memset(data+next_offset, 0, align);
    40994204                        next_offset += align;
     
    41054210                ofs = next_offset;
    41064211        }
     4212
     4213        DEBUG(10, ("max_data: %u, data_size: %u\n", max_data_bytes, ofs));
    41074214
    41084215        *data_size = ofs;
     
    41944301                               uint16_t flags2,
    41954302                               unsigned int max_data_bytes,
     4303                               size_t *fixed_portion,
    41964304                               char **ppdata,
    41974305                               unsigned int *pdata_size)
     
    43294437        file_index = get_FileIndex(conn, psbuf);
    43304438
     4439        *fixed_portion = 0;
     4440
    43314441        switch (info_level) {
    43324442                case SMB_INFO_STANDARD:
     
    44664576                        DEBUG(5,("change: %s ", ctime(&c_time)));
    44674577                        DEBUG(5,("mode: %x\n", mode));
     4578                        *fixed_portion = data_size;
    44684579                        break;
    44694580
     
    44794590                        SCVAL(pdata,21,(mode&FILE_ATTRIBUTE_DIRECTORY)?1:0);
    44804591                        SSVAL(pdata,22,0); /* Padding. */
     4592                        *fixed_portion = 24;
    44814593                        break;
    44824594
     
    44884600                        DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_EA_INFORMATION\n"));
    44894601                        data_size = 4;
     4602                        *fixed_portion = 4;
    44904603                        SIVAL(pdata,0,ea_size);
    44914604                        break;
     
    45094622                        data_size = 4 + len;
    45104623                        SIVAL(pdata,0,len);
     4624                        *fixed_portion = 8;
    45114625                        break;
    45124626                }
     
    45724686                        pdata += 4 + len;
    45734687                        data_size = PTR_DIFF(pdata,(*ppdata));
     4688                        *fixed_portion = 10;
    45744689                        break;
    45754690                }
     
    46094724                        pdata += 4 + len;
    46104725                        data_size = PTR_DIFF(pdata,(*ppdata));
     4726                        *fixed_portion = 104;
    46114727                        break;
    46124728                }
     
    46164732                        SBVAL(pdata, 0, file_index);
    46174733                        data_size = 8;
     4734                        *fixed_portion = 8;
    46184735                        break;
    46194736
     
    46224739                        SIVAL(pdata, 0, access_mask);
    46234740                        data_size = 4;
     4741                        *fixed_portion = 4;
    46244742                        break;
    46254743
     
    46394757                        data_size = 1;
    46404758                        SCVAL(pdata,0,delete_pending);
     4759                        *fixed_portion = 1;
    46414760                        break;
    46424761
     
    46454764                        data_size = 8;
    46464765                        SOFF_T(pdata,0,pos);
     4766                        *fixed_portion = 8;
    46474767                        break;
    46484768
     
    46514771                        SIVAL(pdata,0,mode);
    46524772                        data_size = 4;
     4773                        *fixed_portion = 4;
    46534774                        break;
    46544775
     
    46574778                        SIVAL(pdata,0,0); /* No alignment needed. */
    46584779                        data_size = 4;
     4780                        *fixed_portion = 4;
    46594781                        break;
    46604782
     
    46954817                                DEBUG(10, ("marshall_stream_info failed: %s\n",
    46964818                                           nt_errstr(status)));
     4819                                TALLOC_FREE(streams);
    46974820                                return status;
    46984821                        }
    46994822
    47004823                        TALLOC_FREE(streams);
     4824
     4825                        *fixed_portion = 32;
    47014826
    47024827                        break;
     
    47094834                        SIVAL(pdata,12,0); /* ??? */
    47104835                        data_size = 16;
     4836                        *fixed_portion = 16;
    47114837                        break;
    47124838
     
    47224848                        SIVAL(pdata,52,0); /* ??? */
    47234849                        data_size = 56;
     4850                        *fixed_portion = 56;
    47244851                        break;
    47254852
     
    47294856                        SIVAL(pdata,4,0);
    47304857                        data_size = 8;
     4858                        *fixed_portion = 8;
    47314859                        break;
    47324860
     
    49985126        int lock_data_count = 0;
    49995127        char *lock_data = NULL;
     5128        size_t fixed_portion;
    50005129        NTSTATUS status = NT_STATUS_OK;
    50015130
     
    53595488                                       lock_data_count, lock_data,
    53605489                                       req->flags2, max_data_bytes,
     5490                                       &fixed_portion,
    53615491                                       ppdata, &data_size);
    53625492        if (!NT_STATUS_IS_OK(status)) {
    53635493                reply_nterror(req, status);
     5494                return;
     5495        }
     5496        if (fixed_portion > max_data_bytes) {
     5497                reply_nterror(req, NT_STATUS_INFO_LENGTH_MISMATCH);
    53645498                return;
    53655499        }
     
    73087442                        create_disp = FILE_OPEN_IF;
    73097443                        break;
     7444                case SMB_O_EXCL:
     7445                        /* O_EXCL on its own without O_CREAT is undefined.
     7446                           We deliberately ignore it as some versions of
     7447                           Linux CIFSFS can send a bare O_EXCL on the
     7448                           wire which other filesystems in the kernel
     7449                           ignore. See bug 9519 for details. */
     7450
     7451                        /* Fallthrough. */
     7452
    73107453                case 0:
    73117454                        /* File exists open. File not exist fail. */
    73127455                        create_disp = FILE_OPEN;
    73137456                        break;
    7314                 case SMB_O_EXCL:
    7315                         /* O_EXCL on its own without O_CREAT is undefined. */
    73167457                default:
    73177458                        DEBUG(5,("smb_posix_open: invalid create mode 0x%x\n",
     
    75667707                        }
    75677708                        /* Fail with sharing violation. */
     7709                        TALLOC_FREE(lck);
    75687710                        close_file(req, fsp, NORMAL_CLOSE);
    7569                         TALLOC_FREE(lck);
    75707711                        return NT_STATUS_SHARING_VIOLATION;
    75717712                }
     
    75817722                                                smb_fname);
    75827723
     7724        TALLOC_FREE(lck);
     7725
    75837726        if (!NT_STATUS_IS_OK(status)) {
    75847727                close_file(req, fsp, NORMAL_CLOSE);
    7585                 TALLOC_FREE(lck);
    75867728                return status;
    75877729        }
    7588         TALLOC_FREE(lck);
    75897730        return close_file(req, fsp, NORMAL_CLOSE);
    75907731}
Note: See TracChangeset for help on using the changeset viewer.