Ignore:
Timestamp:
May 13, 2014, 11:39:04 AM (11 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update trunk to 3.6.23

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

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

    r751 r862  
    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);
     
    61956207                          smb_fname_str_dbg(smb_fname_dst)));
    61966208
    6197                 if (!lp_posix_pathnames() &&
     6209                if (!fsp->is_directory &&
     6210                    !lp_posix_pathnames() &&
    61986211                    (lp_map_archive(SNUM(conn)) ||
    61996212                    lp_store_dos_attributes(SNUM(conn)))) {
Note: See TracChangeset for help on using the changeset viewer.