Ignore:
Timestamp:
Nov 14, 2012, 12:59:34 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to 3.6.0

File:
1 edited

Legend:

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

    r587 r740  
    2626
    2727#include "includes.h"
     28#include "system/filesys.h"
     29#include "printing.h"
     30#include "smbd/smbd.h"
    2831#include "smbd/globals.h"
     32#include "fake_file.h"
     33#include "rpc_client/rpc_client.h"
     34#include "../librpc/gen_ndr/ndr_spoolss_c.h"
     35#include "rpc_client/cli_spoolss.h"
     36#include "rpc_client/init_spoolss.h"
     37#include "rpc_server/rpc_ncacn_np.h"
     38#include "libcli/security/security.h"
     39#include "libsmb/nmblib.h"
     40#include "auth.h"
     41#include "smbprofile.h"
    2942
    3043/****************************************************************************
     
    323336                    files_struct *fsp)
    324337{
    325         if (!(fsp) || !(conn)) {
     338        if ((fsp == NULL) || (conn == NULL)) {
    326339                reply_nterror(req, NT_STATUS_INVALID_HANDLE);
    327340                return False;
    328341        }
    329         if (((conn) != (fsp)->conn) || req->vuid != (fsp)->vuid) {
     342        if ((conn != fsp->conn) || (req->vuid != fsp->vuid)) {
    330343                reply_nterror(req, NT_STATUS_INVALID_HANDLE);
    331344                return False;
     
    344357                return False;
    345358        }
    346         if ((fsp)->is_directory) {
     359        if (fsp->is_directory) {
    347360                reply_nterror(req, NT_STATUS_INVALID_DEVICE_REQUEST);
    348361                return False;
    349362        }
    350         if ((fsp)->fh->fd == -1) {
     363        if (fsp->fh->fd == -1) {
    351364                reply_nterror(req, NT_STATUS_ACCESS_DENIED);
    352365                return False;
    353366        }
    354         (fsp)->num_smb_operations++;
     367        fsp->num_smb_operations++;
    355368        return True;
    356369}
     
    387400}
    388401
    389 /****************************************************************************
    390  Check if we have a correct fsp. Replacement for the FSP_BELONGS_CONN macro
    391 ****************************************************************************/
    392 
    393 bool fsp_belongs_conn(connection_struct *conn, struct smb_request *req,
    394                       files_struct *fsp)
    395 {
    396         if ((fsp) && (conn) && ((conn)==(fsp)->conn)
    397             && (req->vuid == (fsp)->vuid)) {
    398                 return True;
    399         }
    400 
    401         reply_nterror(req, NT_STATUS_INVALID_HANDLE);
    402         return False;
    403 }
    404 
    405 static bool netbios_session_retarget(const char *name, int name_type)
     402static bool netbios_session_retarget(struct smbd_server_connection *sconn,
     403                                     const char *name, int name_type)
    406404{
    407405        char *trim_name;
     
    417415        uint8_t outbuf[10];
    418416
    419         if (get_socket_port(smbd_server_fd()) != 139) {
     417        if (get_socket_port(sconn->sock) != 139) {
    420418                return false;
    421419        }
     
    459457        if (p != NULL) {
    460458                *p++ = '\0';
    461                 sscanf(p, "%x", &retarget_type);
     459                if (sscanf(p, "%x", &retarget_type) != 1) {
     460                        goto fail;
     461                }
    462462        }
    463463
     
    480480        *(uint16_t *)(outbuf+8) = htons(retarget_port);
    481481
    482         if (!srv_send_smb(smbd_server_fd(), (char *)outbuf, false, 0, false,
     482        if (!srv_send_smb(sconn, (char *)outbuf, false, 0, false,
    483483                          NULL)) {
    484484                exit_server_cleanly("netbios_session_regarget: srv_send_smb "
     
    493493
    494494/****************************************************************************
    495  Reply to a (netbios-level) special message.
     495 Reply to a (netbios-level) special message. 
    496496****************************************************************************/
    497497
    498 void reply_special(char *inbuf, size_t inbuf_size)
     498void reply_special(struct smbd_server_connection *sconn, char *inbuf, size_t inbuf_size)
    499499{
    500500        int msg_type = CVAL(inbuf,0);
    501501        int msg_flags = CVAL(inbuf,1);
    502         struct smbd_server_connection *sconn = smbd_server_conn;
    503502        /*
    504503         * We only really use 4 bytes of the outbuf, but for the smb_setlen
     
    533532                if (name_len1 <= 0 || name_len1 > inbuf_size - 4) {
    534533                        DEBUG(0,("Invalid name length in session request\n"));
    535                         return;
     534                        break;
    536535                }
    537536                name_len2 = name_len((unsigned char *)(inbuf+4+name_len1),inbuf_size - 4 - name_len1);
    538537                if (name_len2 <= 0 || name_len2 > inbuf_size - 4 - name_len1) {
    539538                        DEBUG(0,("Invalid name length in session request\n"));
    540                         return;
     539                        break;
    541540                }
    542541
     
    548547                if (name_type1 == -1 || name_type2 == -1) {
    549548                        DEBUG(0,("Invalid name type in session request\n"));
    550                         return;
     549                        break;
    551550                }
    552551
     
    554553                         name1, name_type1, name2, name_type2));
    555554
    556                 if (netbios_session_retarget(name1, name_type1)) {
     555                if (netbios_session_retarget(sconn, name1, name_type1)) {
    557556                        exit_server_cleanly("retargeted client");
     557                }
     558
     559                /*
     560                 * Windows NT/2k uses "*SMBSERVER" and XP uses
     561                 * "*SMBSERV" arrggg!!!
     562                 */
     563                if (strequal(name1, "*SMBSERVER     ")
     564                    || strequal(name1, "*SMBSERV       "))  {
     565                        fstrcpy(name1, sconn->client_id.addr);
    558566                }
    559567
     
    579587                }
    580588
    581                 reload_services(True);
     589                reload_services(sconn->msg_ctx, sconn->sock, True);
    582590                reopen_logs();
    583591
     
    606614                    msg_type, msg_flags));
    607615
    608         srv_send_smb(smbd_server_fd(), outbuf, false, 0, false, NULL);
     616        srv_send_smb(sconn, outbuf, false, 0, false, NULL);
    609617        return;
    610618}
     
    627635        DATA_BLOB password_blob;
    628636        TALLOC_CTX *ctx = talloc_tos();
    629         struct smbd_server_connection *sconn = smbd_server_conn;
     637        struct smbd_server_connection *sconn = req->sconn;
    630638
    631639        START_PROFILE(SMBtcon);
     
    703711        const char *p, *q;
    704712        uint16 tcon_flags;
    705         struct smbd_server_connection *sconn = smbd_server_conn;
     713        struct smbd_server_connection *sconn = req->sconn;
    706714
    707715        START_PROFILE(SMBtconX);
     
    828836                                perm2 = FILE_ALL_ACCESS;
    829837                        } else {
    830                                 perm1 = CAN_WRITE(conn) ?
    831                                                 SHARE_ALL_ACCESS :
    832                                                 SHARE_READ_ONLY;
     838                                perm1 = conn->share_access;
    833839                        }
    834840
     
    944950                                return;
    945951                        }
    946                         SSVAL(p,0,fsp->rap_print_jobid);             /* Job number */
     952                        /* Job number */
     953                        if (fsp->print_file) {
     954                                SSVAL(p, 0, fsp->print_file->rap_jobid);
     955                        } else {
     956                                SSVAL(p, 0, 0);
     957                        }
    947958                        srvstr_push((char *)req->outbuf, req->flags2, p+2,
    948959                                    global_myname(), 15,
     
    10961107                under WfWg - weird! */
    10971108        if (*fname == '\0') {
    1098                 mode = aHIDDEN | aDIR;
     1109                mode = FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_DIRECTORY;
    10991110                if (!CAN_WRITE(conn)) {
    1100                         mode |= aRONLY;
     1111                        mode |= FILE_ATTRIBUTE_READONLY;
    11011112                }
    11021113                size = 0;
     
    11371148                        ZERO_STRUCT(write_time_ts);
    11381149                        fileid = vfs_file_id_from_sbuf(conn, &smb_fname->st);
    1139                         get_file_infos(fileid, NULL, &write_time_ts);
     1150                        get_file_infos(fileid, 0, NULL, &write_time_ts);
    11401151                        if (!null_timespec(write_time_ts)) {
    11411152                                update_stat_ex_mtime(&smb_fname->st, write_time_ts);
     
    11441155
    11451156                mtime = convert_timespec_to_time_t(smb_fname->st.st_ex_mtime);
    1146                 if (mode & aDIR) {
     1157                if (mode & FILE_ATTRIBUTE_DIRECTORY) {
    11471158                        size = 0;
    11481159                }
     
    12451256        if (mode != FILE_ATTRIBUTE_NORMAL) {
    12461257                if (VALID_STAT_OF_DIR(smb_fname->st))
    1247                         mode |= aDIR;
     1258                        mode |= FILE_ATTRIBUTE_DIRECTORY;
    12481259                else
    1249                         mode &= ~aDIR;
     1260                        mode &= ~FILE_ATTRIBUTE_DIRECTORY;
    12501261
    12511262                if (file_set_dosmode(conn, smb_fname, mode, NULL,
     
    13821393        bool ask_sharemode = lp_parm_bool(SNUM(conn), "smbd", "search ask sharemode", true);
    13831394        struct dptr_struct *dirptr = NULL;
    1384         struct smbd_server_connection *sconn = smbd_server_conn;
     1395        struct smbd_server_connection *sconn = req->sconn;
    13851396
    13861397        START_PROFILE(SMBsearch);
     
    14161427        p += 2;
    14171428
    1418         /* dirtype &= ~aDIR; */
     1429        /* dirtype &= ~FILE_ATTRIBUTE_DIRECTORY; */
    14191430
    14201431        if (status_len == 0) {
     
    14561467
    14571468                nt_status = dptr_create(conn,
     1469                                        NULL, /* fsp */
    14581470                                        directory,
    14591471                                        True,
     
    15071519        dptr_init_search_op(dirptr);
    15081520
    1509         if ((dirtype&0x1F) == aVOLID) {
     1521        if ((dirtype&0x1F) == FILE_ATTRIBUTE_VOLUME) {
    15101522                char buf[DIR_STRUCT_SIZE];
    15111523                memcpy(buf,status,21);
    15121524                if (!make_dir_struct(ctx,buf,"???????????",volume_label(SNUM(conn)),
    1513                                 0,aVOLID,0,!allow_long_path_components)) {
     1525                                0,FILE_ATTRIBUTE_VOLUME,0,!allow_long_path_components)) {
    15141526                        reply_nterror(req, NT_STATUS_NO_MEMORY);
    15151527                        goto out;
     
    16491661        bool path_contains_wcard = False;
    16501662        TALLOC_CTX *ctx = talloc_tos();
    1651         struct smbd_server_connection *sconn = smbd_server_conn;
     1663        struct smbd_server_connection *sconn = req->sconn;
    16521664
    16531665        START_PROFILE(SMBfclose);
     
    17141726        uint32 create_disposition;
    17151727        uint32 create_options = 0;
     1728        uint32_t private_flags = 0;
    17161729        NTSTATUS status;
    17171730        bool ask_sharemode = lp_parm_bool(SNUM(conn), "smbd", "search ask sharemode", true);
     
    17571770                                         OPENX_FILE_EXISTS_OPEN, &access_mask,
    17581771                                         &share_mode, &create_disposition,
    1759                                          &create_options)) {
     1772                                         &create_options, &private_flags)) {
    17601773                reply_force_doserror(req, ERRDOS, ERRbadaccess);
    17611774                goto out;
     
    17741787                oplock_request,                         /* oplock_request */
    17751788                0,                                      /* allocation_size */
     1789                private_flags,
    17761790                NULL,                                   /* sd */
    17771791                NULL,                                   /* ea_list */
     
    17971811
    17981812                ZERO_STRUCT(write_time_ts);
    1799                 get_file_infos(fsp->file_id, NULL, &write_time_ts);
     1813                get_file_infos(fsp->file_id, 0, NULL, &write_time_ts);
    18001814                if (!null_timespec(write_time_ts)) {
    18011815                        update_stat_ex_mtime(&smb_fname->st, write_time_ts);
     
    18051819        mtime = convert_timespec_to_time_t(smb_fname->st.st_ex_mtime);
    18061820
    1807         if (fattr & aDIR) {
     1821        if (fattr & FILE_ATTRIBUTE_DIRECTORY) {
    18081822                DEBUG(3,("attempt to open a directory %s\n",
    18091823                         fsp_str_dbg(fsp)));
     
    18731887        uint32 create_disposition;
    18741888        uint32 create_options = 0;
     1889        uint32_t private_flags = 0;
    18751890        TALLOC_CTX *ctx = talloc_tos();
    18761891
     
    19301945                                         &access_mask, &share_mode,
    19311946                                         &create_disposition,
    1932                                          &create_options)) {
     1947                                         &create_options,
     1948                                         &private_flags)) {
    19331949                reply_force_doserror(req, ERRDOS, ERRbadaccess);
    19341950                goto out;
     
    19471963                oplock_request,                         /* oplock_request */
    19481964                0,                                      /* allocation_size */
     1965                private_flags,
    19491966                NULL,                                   /* sd */
    19501967                NULL,                                   /* ea_list */
     
    19761993                        goto out;
    19771994                }
    1978                 smb_fname->st.st_ex_size =
    1979                     SMB_VFS_GET_ALLOC_SIZE(conn, fsp, &smb_fname->st);
    1980         }
    1981 
    1982         fattr = dos_mode(conn, smb_fname);
    1983         mtime = convert_timespec_to_time_t(smb_fname->st.st_ex_mtime);
    1984         if (fattr & aDIR) {
     1995                status = vfs_stat_fsp(fsp);
     1996                if (!NT_STATUS_IS_OK(status)) {
     1997                        close_file(req, fsp, ERROR_CLOSE);
     1998                        reply_nterror(req, status);
     1999                        goto out;
     2000                }
     2001        }
     2002
     2003        fattr = dos_mode(conn, fsp->fsp_name);
     2004        mtime = convert_timespec_to_time_t(fsp->fsp_name->st.st_ex_mtime);
     2005        if (fattr & FILE_ATTRIBUTE_DIRECTORY) {
    19852006                close_file(req, fsp, ERROR_CLOSE);
    19862007                reply_nterror(req, NT_STATUS_ACCESS_DENIED);
     
    20292050                srv_put_dos_date3((char *)req->outbuf,smb_vwv4,mtime);
    20302051        }
    2031         SIVAL(req->outbuf,smb_vwv6,(uint32)smb_fname->st.st_ex_size);
     2052        SIVAL(req->outbuf,smb_vwv6,(uint32)fsp->fsp_name->st.st_ex_size);
    20322053        SSVAL(req->outbuf,smb_vwv8,GET_OPENX_MODE(deny_mode));
    20332054        SSVAL(req->outbuf,smb_vwv11,smb_action);
    20342055
    20352056        if (open_flags & EXTENDED_RESPONSE_REQUIRED) {
    2036                 SIVAL(req->outbuf, smb_vwv15, STD_RIGHT_ALL_ACCESS);
     2057                SIVAL(req->outbuf, smb_vwv15, SEC_STD_ALL);
    20372058        }
    20382059
     
    20502071void reply_ulogoffX(struct smb_request *req)
    20512072{
    2052         struct smbd_server_connection *sconn = smbd_server_conn;
     2073        struct smbd_server_connection *sconn = req->sconn;
    20532074        user_struct *vuser;
    20542075
     
    20652086                open by this user */
    20662087        if ((vuser != NULL) && (lp_security() != SEC_SHARE)) {
    2067                 file_close_user(req->vuid);
     2088                file_close_user(sconn, req->vuid);
    20682089        }
    20692090
     
    21382159        }
    21392160
    2140         if (fattr & aVOLID) {
     2161        if (fattr & FILE_ATTRIBUTE_VOLUME) {
    21412162                DEBUG(0,("Attempt to create file (%s) with volid set - "
    21422163                         "please report this\n",
     
    21642185                oplock_request,                         /* oplock_request */
    21652186                0,                                      /* allocation_size */
     2187                0,                                      /* private_flags */
    21662188                NULL,                                   /* sd */
    21672189                NULL,                                   /* ea_list */
     
    22922314                oplock_request,                         /* oplock_request */
    22932315                0,                                      /* allocation_size */
     2316                0,                                      /* private_flags */
    22942317                NULL,                                   /* sd */
    22952318                NULL,                                   /* ea_list */
     
    23572380                        uint16 dirtype)
    23582381{
    2359         uint32 fmode;
    2360 
    23612382        if (!CAN_WRITE(conn)) {
    23622383                return NT_STATUS_MEDIA_WRITE_PROTECTED;
    23632384        }
    23642385
    2365         fmode = dos_mode(conn, fsp->fsp_name);
    2366         if ((fmode & ~dirtype) & (aHIDDEN | aSYSTEM)) {
    2367                 return NT_STATUS_NO_SUCH_FILE;
     2386        if ((dirtype & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) !=
     2387                        (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) {
     2388                /* Only bother to read the DOS attribute if we might deny the
     2389                   rename on the grounds of attribute missmatch. */
     2390                uint32_t fmode = dos_mode(conn, fsp->fsp_name);
     2391                if ((fmode & ~dirtype) & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) {
     2392                        return NT_STATUS_NO_SUCH_FILE;
     2393                }
    23682394        }
    23692395
     
    24252451
    24262452        if (dirtype & FILE_ATTRIBUTE_NORMAL) {
    2427                 dirtype = aDIR|aARCH|aRONLY;
    2428         }
    2429 
    2430         dirtype &= (aDIR|aARCH|aRONLY|aHIDDEN|aSYSTEM);
     2453                dirtype = FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY;
     2454        }
     2455
     2456        dirtype &= (FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM);
    24312457        if (!dirtype) {
    24322458                return NT_STATUS_NO_SUCH_FILE;
     
    24342460
    24352461        if (!dir_check_ftype(conn, fattr, dirtype)) {
    2436                 if (fattr & aDIR) {
     2462                if (fattr & FILE_ATTRIBUTE_DIRECTORY) {
    24372463                        return NT_STATUS_FILE_IS_A_DIRECTORY;
    24382464                }
     
    24652491
    24662492        /* Can't delete a directory. */
    2467         if (fattr & aDIR) {
     2493        if (fattr & FILE_ATTRIBUTE_DIRECTORY) {
    24682494                return NT_STATUS_FILE_IS_A_DIRECTORY;
    24692495        }
     
    24712497
    24722498#if 0 /* JRATEST */
    2473         else if (dirtype & aDIR) /* Asked for a directory and it isn't. */
     2499        else if (dirtype & FILE_ATTRIBUTE_DIRECTORY) /* Asked for a directory and it isn't. */
    24742500                return NT_STATUS_OBJECT_NAME_INVALID;
    24752501#endif /* JRATEST */
     
    24922518                 0,                     /* oplock_request */
    24932519                 0,                     /* allocation_size */
     2520                 0,                     /* private_flags */
    24942521                 NULL,                  /* sd */
    24952522                 NULL,                  /* ea_list */
     
    25142541
    25152542        /* The set is across all open files on this dev/inode pair. */
    2516         if (!set_delete_on_close(fsp, True, &conn->server_info->utok)) {
     2543        if (!set_delete_on_close(fsp, True, &conn->session_info->utok)) {
    25172544                close_file(req, fsp, NORMAL_CLOSE);
    25182545                return NT_STATUS_ACCESS_DENIED;
     
    25712598                 */
    25722599                TALLOC_FREE(smb_fname->base_name);
    2573                 smb_fname->base_name = talloc_asprintf(smb_fname,
    2574                                                        "%s/%s",
    2575                                                        fname_dir,
    2576                                                        fname_mask);
     2600                if (ISDOT(fname_dir)) {
     2601                        /* Ensure we use canonical names on open. */
     2602                        smb_fname->base_name = talloc_asprintf(smb_fname,
     2603                                                        "%s",
     2604                                                        fname_mask);
     2605                } else {
     2606                        smb_fname->base_name = talloc_asprintf(smb_fname,
     2607                                                        "%s/%s",
     2608                                                        fname_dir,
     2609                                                        fname_mask);
     2610                }
    25772611                if (!smb_fname->base_name) {
    25782612                        status = NT_STATUS_NO_MEMORY;
     
    26002634                char *talloced = NULL;
    26012635
    2602                 if ((dirtype & SAMBA_ATTRIBUTES_MASK) == aDIR) {
     2636                if ((dirtype & SAMBA_ATTRIBUTES_MASK) == FILE_ATTRIBUTE_DIRECTORY) {
    26032637                        status = NT_STATUS_OBJECT_NAME_INVALID;
    26042638                        goto out;
     
    26592693
    26602694                        TALLOC_FREE(smb_fname->base_name);
    2661                         smb_fname->base_name =
    2662                             talloc_asprintf(smb_fname, "%s/%s",
    2663                                             fname_dir, dname);
     2695                        if (ISDOT(fname_dir)) {
     2696                                /* Ensure we use canonical names on open. */
     2697                                smb_fname->base_name =
     2698                                        talloc_asprintf(smb_fname, "%s",
     2699                                                dname);
     2700                        } else {
     2701                                smb_fname->base_name =
     2702                                        talloc_asprintf(smb_fname, "%s/%s",
     2703                                                fname_dir, dname);
     2704                        }
    26642705
    26652706                        if (!smb_fname->base_name) {
     
    27922833****************************************************************************/
    27932834
    2794 static ssize_t fake_sendfile(files_struct *fsp, SMB_OFF_T startpos,
    2795                              size_t nread)
     2835ssize_t fake_sendfile(files_struct *fsp, SMB_OFF_T startpos, size_t nread)
    27962836{
    27972837        size_t bufsize;
     
    28292869                }
    28302870
    2831                 if (write_data(smbd_server_fd(),buf,cur_read) != cur_read) {
     2871                if (write_data(fsp->conn->sconn->sock, buf, cur_read)
     2872                    != cur_read) {
     2873                        char addr[INET6_ADDRSTRLEN];
     2874                        /*
     2875                         * Try and give an error message saying what
     2876                         * client failed.
     2877                         */
     2878                        DEBUG(0, ("write_data failed for client %s. "
     2879                                  "Error %s\n",
     2880                                  get_peer_addr(fsp->conn->sconn->sock, addr,
     2881                                                sizeof(addr)),
     2882                                  strerror(errno)));
    28322883                        SAFE_FREE(buf);
    28332884                        return -1;
     
    28412892}
    28422893
    2843 #if defined(WITH_SENDFILE)
    28442894/****************************************************************************
    28452895 Deal with the case of sendfile reading less bytes from the file than
     
    28472897****************************************************************************/
    28482898
    2849 static void sendfile_short_send(files_struct *fsp,
     2899void sendfile_short_send(files_struct *fsp,
    28502900                                ssize_t nread,
    28512901                                size_t headersize,
     
    28902940
    28912941                        to_write = MIN(SHORT_SEND_BUFSIZE, smb_maxcnt - nread);
    2892                         if (write_data(smbd_server_fd(), buf, to_write) != to_write) {
     2942                        if (write_data(fsp->conn->sconn->sock, buf, to_write)
     2943                            != to_write) {
     2944                                char addr[INET6_ADDRSTRLEN];
     2945                                /*
     2946                                 * Try and give an error message saying what
     2947                                 * client failed.
     2948                                 */
     2949                                DEBUG(0, ("write_data failed for client %s. "
     2950                                          "Error %s\n",
     2951                                          get_peer_addr(
     2952                                                  fsp->conn->sconn->sock, addr,
     2953                                                  sizeof(addr)),
     2954                                          strerror(errno)));
    28932955                                exit_server_cleanly("sendfile_short_send: "
    2894                                         "write_data failed");
     2956                                                    "write_data failed");
    28952957                        }
    28962958                        nread += to_write;
     
    28992961        }
    29002962}
    2901 #endif /* defined WITH_SENDFILE */
    29022963
    29032964/****************************************************************************
     
    29052966****************************************************************************/
    29062967
    2907 static void reply_readbraw_error(void)
     2968static void reply_readbraw_error(struct smbd_server_connection *sconn)
    29082969{
    29092970        char header[4];
     2971
    29102972        SIVAL(header,0,0);
    2911         if (write_data(smbd_server_fd(),header,4) != 4) {
     2973
     2974        smbd_lock_socket(sconn);
     2975        if (write_data(sconn->sock,header,4) != 4) {
     2976                char addr[INET6_ADDRSTRLEN];
     2977                /*
     2978                 * Try and give an error message saying what
     2979                 * client failed.
     2980                 */
     2981                DEBUG(0, ("write_data failed for client %s. "
     2982                          "Error %s\n",
     2983                          get_peer_addr(sconn->sock, addr, sizeof(addr)),
     2984                          strerror(errno)));
     2985
    29122986                fail_readraw();
    29132987        }
     2988        smbd_unlock_socket(sconn);
    29142989}
    29152990
     
    29253000                               ssize_t mincount)
    29263001{
     3002        struct smbd_server_connection *sconn = req->sconn;
    29273003        char *outbuf = NULL;
    29283004        ssize_t ret=0;
    29293005
    2930 #if defined(WITH_SENDFILE)
    29313006        /*
    29323007         * We can only use sendfile on a non-chained packet
     
    29383013        if ( !req_is_in_chain(req) && (nread > 0) && (fsp->base_fsp == NULL) &&
    29393014            (fsp->wcp == NULL) &&
    2940             lp_use_sendfile(SNUM(conn), smbd_server_conn->smb1.signing_state) ) {
     3015            lp_use_sendfile(SNUM(conn), req->sconn->smb1.signing_state) ) {
    29413016                ssize_t sendfile_read = -1;
    29423017                char header[4];
     
    29463021                header_blob = data_blob_const(header, 4);
    29473022
    2948                 if ((sendfile_read = SMB_VFS_SENDFILE(smbd_server_fd(), fsp,
    2949                                 &header_blob, startpos, nread)) == -1) {
     3023                sendfile_read = SMB_VFS_SENDFILE(sconn->sock, fsp,
     3024                                                 &header_blob, startpos,
     3025                                                 nread);
     3026                if (sendfile_read == -1) {
    29503027                        /* Returning ENOSYS means no data at all was sent.
    29513028                         * Do this as a normal read. */
     
    30013078
    30023079normal_readbraw:
    3003 #endif
    30043080
    30053081        outbuf = TALLOC_ARRAY(NULL, char, nread+4);
     
    30073083                DEBUG(0,("send_file_readbraw: TALLOC_ARRAY failed for size %u.\n",
    30083084                        (unsigned)(nread+4)));
    3009                 reply_readbraw_error();
     3085                reply_readbraw_error(sconn);
    30103086                return;
    30113087        }
     
    30233099
    30243100        _smb_setlen(outbuf,ret);
    3025         if (write_data(smbd_server_fd(),outbuf,4+ret) != 4+ret)
     3101        if (write_data(sconn->sock, outbuf, 4+ret) != 4+ret) {
     3102                char addr[INET6_ADDRSTRLEN];
     3103                /*
     3104                 * Try and give an error message saying what
     3105                 * client failed.
     3106                 */
     3107                DEBUG(0, ("write_data failed for client %s. "
     3108                          "Error %s\n",
     3109                          get_peer_addr(fsp->conn->sconn->sock, addr,
     3110                                        sizeof(addr)),
     3111                          strerror(errno)));
     3112
    30263113                fail_readraw();
     3114        }
    30273115
    30283116        TALLOC_FREE(outbuf);
     
    30363124{
    30373125        connection_struct *conn = req->conn;
     3126        struct smbd_server_connection *sconn = req->sconn;
    30383127        ssize_t maxcount,mincount;
    30393128        size_t nread = 0;
     
    30453134        START_PROFILE(SMBreadbraw);
    30463135
    3047         if (srv_is_signing_active(smbd_server_conn) ||
     3136        if (srv_is_signing_active(sconn) ||
    30483137            is_encrypted_packet(req->inbuf)) {
    30493138                exit_server_cleanly("reply_readbraw: SMB signing/sealing is active - "
     
    30523141
    30533142        if (req->wct < 8) {
    3054                 reply_readbraw_error();
     3143                reply_readbraw_error(sconn);
     3144                END_PROFILE(SMBreadbraw);
     3145                return;
     3146        }
     3147
     3148        if (sconn->smb1.echo_handler.trusted_fde) {
     3149                DEBUG(2,("SMBreadbraw rejected with NOT_SUPPORTED because of "
     3150                         "'async smb echo handler = yes'\n"));
     3151                reply_readbraw_error(sconn);
    30553152                END_PROFILE(SMBreadbraw);
    30563153                return;
     
    30803177                        "- cache prime?\n",
    30813178                        (int)SVAL(req->vwv+0, 0)));
    3082                 reply_readbraw_error();
     3179                reply_readbraw_error(sconn);
    30833180                END_PROFILE(SMBreadbraw);
    30843181                return;
     
    30913188                DEBUG(3,("reply_readbraw: fnum %d not readable.\n",
    30923189                                (int)SVAL(req->vwv+0, 0)));
    3093                 reply_readbraw_error();
     3190                reply_readbraw_error(sconn);
    30943191                END_PROFILE(SMBreadbraw);
    30953192                return;
     
    31183215                                "64 bit offsets.\n",
    31193216                        (unsigned int)IVAL(req->vwv+8, 0) ));
    3120                         reply_readbraw_error();
     3217                        reply_readbraw_error(sconn);
    31213218                        END_PROFILE(SMBreadbraw);
    31223219                        return;
     
    31293226                                "readraw offset (%.0f) !\n",
    31303227                                (double)startpos ));
    3131                         reply_readbraw_error();
     3228                        reply_readbraw_error(sconn);
    31323229                        END_PROFILE(SMBreadbraw);
    31333230                        return;
     
    31413238        maxcount = MIN(65535,maxcount);
    31423239
    3143         init_strict_lock_struct(fsp, (uint32)req->smbpid,
     3240        init_strict_lock_struct(fsp, (uint64_t)req->smbpid,
    31443241            (uint64_t)startpos, (uint64_t)maxcount, READ_LOCK,
    31453242            &lock);
    31463243
    31473244        if (!SMB_VFS_STRICT_LOCK(conn, fsp, &lock)) {
    3148                 reply_readbraw_error();
     3245                reply_readbraw_error(sconn);
    31493246                END_PROFILE(SMBreadbraw);
    31503247                return;
     
    32013298        struct byte_range_lock *br_lck = NULL;
    32023299        char *p = NULL;
    3203         struct smbd_server_connection *sconn = smbd_server_conn;
     3300        struct smbd_server_connection *sconn = req->sconn;
    32043301
    32053302        START_PROFILE(SMBlockread);
     
    32413338         */
    32423339
    3243         br_lck = do_lock(smbd_messaging_context(),
     3340        br_lck = do_lock(req->sconn->msg_ctx,
    32443341                        fsp,
    3245                         req->smbpid,
     3342                        (uint64_t)req->smbpid,
    32463343                        (uint64_t)numtoread,
    32473344                        (uint64_t)startpos,
     
    33113408        files_struct *fsp;
    33123409        struct lock_struct lock;
    3313         struct smbd_server_connection *sconn = smbd_server_conn;
     3410        struct smbd_server_connection *sconn = req->sconn;
    33143411
    33153412        START_PROFILE(SMBread);
     
    33543451        data = smb_buf(req->outbuf) + 3;
    33553452
    3356         init_strict_lock_struct(fsp, (uint32)req->smbpid,
     3453        init_strict_lock_struct(fsp, (uint64_t)req->smbpid,
    33573454            (uint64_t)startpos, (uint64_t)numtoread, READ_LOCK,
    33583455            &lock);
     
    34363533        }
    34373534
    3438         init_strict_lock_struct(fsp, (uint32)req->smbpid,
     3535        init_strict_lock_struct(fsp, (uint64_t)req->smbpid,
    34393536            (uint64_t)startpos, (uint64_t)smb_maxcnt, READ_LOCK,
    34403537            &lock);
     
    34553552        }
    34563553
    3457 #if defined(WITH_SENDFILE)
    34583554        /*
    34593555         * We can only use sendfile on a non-chained packet
     
    34653561            !is_encrypted_packet(req->inbuf) && (fsp->base_fsp == NULL) &&
    34663562            (fsp->wcp == NULL) &&
    3467             lp_use_sendfile(SNUM(conn), smbd_server_conn->smb1.signing_state) ) {
     3563            lp_use_sendfile(SNUM(conn), req->sconn->smb1.signing_state) ) {
    34683564                uint8 headerbuf[smb_size + 12 * 2];
    34693565                DATA_BLOB header;
     
    34803576                setup_readX_header(req, (char *)headerbuf, smb_maxcnt);
    34813577
    3482                 if ((nread = SMB_VFS_SENDFILE(smbd_server_fd(), fsp, &header, startpos, smb_maxcnt)) == -1) {
     3578                nread = SMB_VFS_SENDFILE(req->sconn->sock, fsp, &header,
     3579                                         startpos, smb_maxcnt);
     3580                if (nread == -1) {
    34833581                        /* Returning ENOSYS means no data at all was sent.
    34843582                           Do this as a normal read. */
     
    35463644normal_read:
    35473645
    3548 #endif
    3549 
    35503646        if ((smb_maxcnt & 0xFF0000) > 0x10000) {
    35513647                uint8 headerbuf[smb_size + 2*12];
     
    35553651
    35563652                /* Send out the header. */
    3557                 if (write_data(smbd_server_fd(), (char *)headerbuf,
     3653                if (write_data(req->sconn->sock, (char *)headerbuf,
    35583654                               sizeof(headerbuf)) != sizeof(headerbuf)) {
     3655
     3656                        char addr[INET6_ADDRSTRLEN];
     3657                        /*
     3658                         * Try and give an error message saying what
     3659                         * client failed.
     3660                         */
     3661                        DEBUG(0, ("write_data failed for client %s. "
     3662                                  "Error %s\n",
     3663                                  get_peer_addr(req->sconn->sock, addr,
     3664                                                sizeof(addr)),
     3665                                  strerror(errno)));
     3666
    35593667                        DEBUG(0,("send_file_readX: write_data failed for file "
    35603668                                 "%s (%s). Terminating\n", fsp_str_dbg(fsp),
     
    36553763                        }
    36563764                        /* We currently don't do this on signed or sealed data. */
    3657                         if (srv_is_signing_active(smbd_server_conn) ||
     3765                        if (srv_is_signing_active(req->sconn) ||
    36583766                            is_encrypted_packet(req->inbuf)) {
    36593767                                reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
     
    36983806        }
    36993807
    3700         if (!big_readX &&
    3701             schedule_aio_read_and_X(conn, req, fsp, startpos, smb_maxcnt)) {
    3702                 goto out;
    3703         }
    3704 
     3808        if (!big_readX) {
     3809                NTSTATUS status = schedule_aio_read_and_X(conn,
     3810                                        req,
     3811                                        fsp,
     3812                                        startpos,
     3813                                        smb_maxcnt);
     3814                if (NT_STATUS_IS_OK(status)) {
     3815                        /* Read scheduled - we're done. */
     3816                        goto out;
     3817                }
     3818                if (!NT_STATUS_EQUAL(status, NT_STATUS_RETRY)) {
     3819                        /* Real error - report to client. */
     3820                        END_PROFILE(SMBreadX);
     3821                        reply_nterror(req, status);
     3822                        return;
     3823                }
     3824                /* NT_STATUS_RETRY - fall back to sync read. */
     3825        }
     3826
     3827        smbd_lock_socket(req->sconn);
    37053828        send_file_readX(conn, req, fsp, startpos, smb_maxcnt);
     3829        smbd_unlock_socket(req->sconn);
    37063830
    37073831 out:
     
    37223846        memcpy(req->outbuf, old_outbuf, smb_size);
    37233847        TALLOC_FREE(old_outbuf);
     3848}
     3849
     3850/****************************************************************************
     3851 Read 4 bytes of a smb packet and return the smb length of the packet.
     3852 Store the result in the buffer. This version of the function will
     3853 never return a session keepalive (length of zero).
     3854 Timeout is in milliseconds.
     3855****************************************************************************/
     3856
     3857static NTSTATUS read_smb_length(int fd, char *inbuf, unsigned int timeout,
     3858                                size_t *len)
     3859{
     3860        uint8_t msgtype = SMBkeepalive;
     3861
     3862        while (msgtype == SMBkeepalive) {
     3863                NTSTATUS status;
     3864
     3865                status = read_smb_length_return_keepalive(fd, inbuf, timeout,
     3866                                                          len);
     3867                if (!NT_STATUS_IS_OK(status)) {
     3868                        char addr[INET6_ADDRSTRLEN];
     3869                        /* Try and give an error message
     3870                         * saying what client failed. */
     3871                        DEBUG(0, ("read_fd_with_timeout failed for "
     3872                                  "client %s read error = %s.\n",
     3873                                  get_peer_addr(fd,addr,sizeof(addr)),
     3874                                  nt_errstr(status)));
     3875                        return status;
     3876                }
     3877
     3878                msgtype = CVAL(inbuf, 0);
     3879        }
     3880
     3881        DEBUG(10,("read_smb_length: got smb length of %lu\n",
     3882                  (unsigned long)len));
     3883
     3884        return NT_STATUS_OK;
    37243885}
    37253886
     
    37523913        SCVAL(req->inbuf,smb_com,SMBwritec);
    37533914
    3754         if (srv_is_signing_active(smbd_server_conn)) {
     3915        if (srv_is_signing_active(req->sconn)) {
    37553916                END_PROFILE(SMBwritebraw);
    37563917                exit_server_cleanly("reply_writebraw: SMB signing is active - "
     
    37603921        if (req->wct < 12) {
    37613922                reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
     3923                error_to_writebrawerr(req);
     3924                END_PROFILE(SMBwritebraw);
     3925                return;
     3926        }
     3927
     3928        if (req->sconn->smb1.echo_handler.trusted_fde) {
     3929                DEBUG(2,("SMBwritebraw rejected with NOT_SUPPORTED because of "
     3930                         "'async smb echo handler = yes'\n"));
     3931                reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
    37623932                error_to_writebrawerr(req);
    37633933                END_PROFILE(SMBwritebraw);
     
    38023972        }
    38033973
    3804         init_strict_lock_struct(fsp, (uint32)req->smbpid,
    3805             (uint64_t)startpos, (uint64_t)tcount, WRITE_LOCK,
    3806             &lock);
    3807 
    3808         if (!SMB_VFS_STRICT_LOCK(conn, fsp, &lock)) {
    3809                 reply_nterror(req, NT_STATUS_FILE_LOCK_CONFLICT);
    3810                 error_to_writebrawerr(req);
    3811                 END_PROFILE(SMBwritebraw);
    3812                 return;
     3974        if (!fsp->print_file) {
     3975                init_strict_lock_struct(fsp, (uint64_t)req->smbpid,
     3976                    (uint64_t)startpos, (uint64_t)tcount, WRITE_LOCK,
     3977                    &lock);
     3978
     3979                if (!SMB_VFS_STRICT_LOCK(conn, fsp, &lock)) {
     3980                        reply_nterror(req, NT_STATUS_FILE_LOCK_CONFLICT);
     3981                        error_to_writebrawerr(req);
     3982                        END_PROFILE(SMBwritebraw);
     3983                        return;
     3984                }
    38133985        }
    38143986
     
    38464018        SSVALS(buf,smb_vwv0,0xFFFF);
    38474019        show_msg(buf);
    3848         if (!srv_send_smb(smbd_server_fd(),
     4020        if (!srv_send_smb(req->sconn,
    38494021                          buf,
    38504022                          false, 0, /* no signing */
     
    38564028
    38574029        /* Now read the raw data into the buffer and write it */
    3858         status = read_smb_length(smbd_server_fd(), buf, SMB_SECONDARY_WAIT,
     4030        status = read_smb_length(req->sconn->sock, buf, SMB_SECONDARY_WAIT,
    38594031                                 &numtowrite);
    38604032        if (!NT_STATUS_IS_OK(status)) {
     
    38804052                }
    38814053
    3882                 status = read_data(smbd_server_fd(), buf+4, numtowrite);
     4054                status = read_data(req->sconn->sock, buf+4, numtowrite);
    38834055
    38844056                if (!NT_STATUS_IS_OK(status)) {
    3885                         DEBUG(0,("reply_writebraw: Oversize secondary write "
    3886                                  "raw read failed (%s). Terminating\n",
    3887                                  nt_errstr(status)));
     4057                        char addr[INET6_ADDRSTRLEN];
     4058                        /* Try and give an error message
     4059                         * saying what client failed. */
     4060                        DEBUG(0, ("reply_writebraw: Oversize secondary write "
     4061                                  "raw read failed (%s) for client %s. "
     4062                                  "Terminating\n", nt_errstr(status),
     4063                                  get_peer_addr(req->sconn->sock, addr,
     4064                                                sizeof(addr))));
    38884065                        exit_server_cleanly("secondary writebraw failed");
    38894066                }
     
    39244101                (int)total_written));
    39254102
    3926         SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
     4103        if (!fsp->print_file) {
     4104                SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
     4105        }
    39274106
    39284107        /* We won't return a status if write through is not selected - this
     
    39384117                 * JRA.
    39394118                 */
    3940                 if (!send_keepalive(smbd_server_fd())) {
     4119                if (!send_keepalive(req->sconn->sock)) {
    39414120                        exit_server_cleanly("reply_writebraw: send of "
    39424121                                "keepalive failed");
     
    39484127
    39494128strict_unlock:
    3950         SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
     4129        if (!fsp->print_file) {
     4130                SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
     4131        }
    39514132
    39524133        END_PROFILE(SMBwritebraw);
     
    39984179        data = (const char *)req->buf + 3;
    39994180
    4000         if (numtowrite) {
    4001                 init_strict_lock_struct(fsp, (uint32)req->smbpid,
     4181        if (!fsp->print_file && numtowrite > 0) {
     4182                init_strict_lock_struct(fsp, (uint64_t)req->smbpid,
    40024183                    (uint64_t)startpos, (uint64_t)numtowrite, WRITE_LOCK,
    40034184                    &lock);
     
    40384219        }
    40394220
    4040         if (numtowrite) {
    4041                 status = do_unlock(smbd_messaging_context(),
     4221        if (numtowrite && !fsp->print_file) {
     4222                status = do_unlock(req->sconn->msg_ctx,
    40424223                                fsp,
    4043                                 req->smbpid,
     4224                                (uint64_t)req->smbpid,
    40444225                                (uint64_t)numtowrite,
    40454226                                (uint64_t)startpos,
     
    40604241
    40614242strict_unlock:
    4062         if (numtowrite) {
     4243        if (numtowrite && !fsp->print_file) {
    40634244                SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
    40644245        }
     
    41194300        data = (const char *)req->buf + 3;
    41204301
    4121         init_strict_lock_struct(fsp, (uint32)req->smbpid,
    4122             (uint64_t)startpos, (uint64_t)numtowrite, WRITE_LOCK,
    4123             &lock);
    4124 
    4125         if (!SMB_VFS_STRICT_LOCK(conn, fsp, &lock)) {
    4126                 reply_nterror(req, NT_STATUS_FILE_LOCK_CONFLICT);
    4127                 END_PROFILE(SMBwrite);
    4128                 return;
     4302        if (!fsp->print_file) {
     4303                init_strict_lock_struct(fsp, (uint64_t)req->smbpid,
     4304                        (uint64_t)startpos, (uint64_t)numtowrite, WRITE_LOCK,
     4305                        &lock);
     4306
     4307                if (!SMB_VFS_STRICT_LOCK(conn, fsp, &lock)) {
     4308                        reply_nterror(req, NT_STATUS_FILE_LOCK_CONFLICT);
     4309                        END_PROFILE(SMBwrite);
     4310                        return;
     4311                }
    41294312        }
    41304313
     
    41844367
    41854368strict_unlock:
    4186         SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
     4369        if (!fsp->print_file) {
     4370                SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
     4371        }
    41874372
    41884373        END_PROFILE(SMBwrite);
     
    41984383                                                1 /* pad byte */)
    41994384
    4200 bool is_valid_writeX_buffer(const uint8_t *inbuf)
     4385bool is_valid_writeX_buffer(struct smbd_server_connection *sconn,
     4386                            const uint8_t *inbuf)
    42014387{
    42024388        size_t numtowrite;
     
    42044390        unsigned int doff = 0;
    42054391        size_t len = smb_len_large(inbuf);
    4206         struct smbd_server_connection *sconn = smbd_server_conn;
    42074392
    42084393        if (is_encrypted_packet(inbuf)) {
     
    42934478        char *data;
    42944479        NTSTATUS status;
     4480        int saved_errno = 0;
    42954481
    42964482        START_PROFILE(SMBwriteX);
     
    43874573        }
    43884574
    4389         init_strict_lock_struct(fsp, (uint32)req->smbpid,
    4390             (uint64_t)startpos, (uint64_t)numtowrite, WRITE_LOCK,
    4391             &lock);
    4392 
    4393         if (!SMB_VFS_STRICT_LOCK(conn, fsp, &lock)) {
    4394                 reply_nterror(req, NT_STATUS_FILE_LOCK_CONFLICT);
    4395                 END_PROFILE(SMBwriteX);
    4396                 return;
    4397         }
    4398 
    43994575        /* X/Open SMB protocol says that, unlike SMBwrite
    44004576        if the length is zero then NO truncation is
     
    44054581                nwritten = 0;
    44064582        } else {
    4407 
    4408                 if ((req->unread_bytes == 0) &&
    4409                     schedule_aio_write_and_X(conn, req, fsp, data, startpos,
    4410                                              numtowrite)) {
    4411                         goto strict_unlock;
     4583                if (req->unread_bytes == 0) {
     4584                        status = schedule_aio_write_and_X(conn,
     4585                                                req,
     4586                                                fsp,
     4587                                                data,
     4588                                                startpos,
     4589                                                numtowrite);
     4590
     4591                        if (NT_STATUS_IS_OK(status)) {
     4592                                /* write scheduled - we're done. */
     4593                                goto out;
     4594                        }
     4595                        if (!NT_STATUS_EQUAL(status, NT_STATUS_RETRY)) {
     4596                                /* Real error - report to client. */
     4597                                reply_nterror(req, status);
     4598                                goto out;
     4599                        }
     4600                        /* NT_STATUS_RETRY - fall through to sync write. */
     4601                }
     4602
     4603                init_strict_lock_struct(fsp, (uint64_t)req->smbpid,
     4604                    (uint64_t)startpos, (uint64_t)numtowrite, WRITE_LOCK,
     4605                    &lock);
     4606
     4607                if (!SMB_VFS_STRICT_LOCK(conn, fsp, &lock)) {
     4608                        reply_nterror(req, NT_STATUS_FILE_LOCK_CONFLICT);
     4609                        goto out;
    44124610                }
    44134611
    44144612                nwritten = write_file(req,fsp,data,startpos,numtowrite);
     4613                saved_errno = errno;
     4614
     4615                SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
    44154616        }
    44164617
    44174618        if(nwritten < 0) {
    4418                 reply_nterror(req, map_nt_error_from_unix(errno));
    4419                 goto strict_unlock;
     4619                reply_nterror(req, map_nt_error_from_unix(saved_errno));
     4620                goto out;
    44204621        }
    44214622
    44224623        if((nwritten == 0) && (numtowrite != 0)) {
    44234624                reply_nterror(req, NT_STATUS_DISK_FULL);
    4424                 goto strict_unlock;
     4625                goto out;
    44254626        }
    44264627
     
    44424643                         fsp_str_dbg(fsp), nt_errstr(status)));
    44434644                reply_nterror(req, status);
    4444                 goto strict_unlock;
    4445         }
    4446 
    4447         SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
     4645                goto out;
     4646        }
    44484647
    44494648        END_PROFILE(SMBwriteX);
     
    44514650        return;
    44524651
    4453 strict_unlock:
    4454         SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
    4455 
     4652out:
    44564653        END_PROFILE(SMBwriteX);
    44574654        return;
     
    45984795        START_PROFILE(SMBexit);
    45994796
    4600         file_close_pid(req->smbpid, req->vuid);
     4797        file_close_pid(req->sconn, req->smbpid, req->vuid);
    46014798
    46024799        reply_outbuf(req, 0, 0);
     
    46314828         */
    46324829
    4633         if(!fsp || (fsp->conn != conn) || (fsp->vuid != req->vuid)) {
     4830        if (!check_fsp_open(conn, req, fsp)) {
    46344831                reply_nterror(req, NT_STATUS_INVALID_HANDLE);
    46354832                END_PROFILE(SMBclose);
     
    47214918        data = (const char *)req->buf + 1;
    47224919
    4723         if (numtowrite) {
    4724                 init_strict_lock_struct(fsp, (uint32)req->smbpid,
     4920        if (!fsp->print_file) {
     4921                init_strict_lock_struct(fsp, (uint64_t)req->smbpid,
    47254922                    (uint64_t)startpos, (uint64_t)numtowrite, WRITE_LOCK,
    47264923                    &lock);
     
    47674964
    47684965strict_unlock:
    4769         if (numtowrite) {
     4966        if (numtowrite && !fsp->print_file) {
    47704967                SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
    47714968        }
     
    48115008                 fsp->fh->fd, fsp->fnum, (double)offset, (double)count));
    48125009
    4813         br_lck = do_lock(smbd_messaging_context(),
     5010        br_lck = do_lock(req->sconn->msg_ctx,
    48145011                        fsp,
    4815                         req->smbpid,
     5012                        (uint64_t)req->smbpid,
    48165013                        count,
    48175014                        offset,
     
    48665063        offset = (uint64_t)IVAL(req->vwv+3, 0);
    48675064
    4868         status = do_unlock(smbd_messaging_context(),
     5065        status = do_unlock(req->sconn->msg_ctx,
    48695066                        fsp,
    4870                         req->smbpid,
     5067                        (uint64_t)req->smbpid,
    48715068                        count,
    48725069                        offset,
     
    49685165
    49695166                show_msg((char *)req->outbuf);
    4970                 if (!srv_send_smb(smbd_server_fd(),
     5167                if (!srv_send_smb(req->sconn,
    49715168                                (char *)req->outbuf,
    49725169                                true, req->seqnum+1,
     
    50165213
    50175214        /* Open for exclusive use, write only. */
    5018         status = print_fsp_open(req, conn, NULL, req->vuid, fsp);
     5215        status = print_spool_open(fsp, NULL, req->vuid);
    50195216
    50205217        if (!NT_STATUS_IS_OK(status)) {
     
    51245321
    51255322        {
    5126                 print_queue_struct *queue = NULL;
    5127                 print_status_struct status;
    5128                 int count = print_queue_status(SNUM(conn), &queue, &status);
    5129                 int num_to_get = ABS(max_count);
    5130                 int first = (max_count>0?start_index:start_index+max_count+1);
    5131                 int i;
    5132 
    5133                 if (first >= count)
    5134                         num_to_get = 0;
    5135                 else
    5136                         num_to_get = MIN(num_to_get,count-first);
    5137 
    5138 
    5139                 for (i=first;i<first+num_to_get;i++) {
     5323                TALLOC_CTX *mem_ctx = talloc_tos();
     5324                NTSTATUS status;
     5325                WERROR werr;
     5326                const char *sharename = lp_servicename(SNUM(conn));
     5327                struct rpc_pipe_client *cli = NULL;
     5328                struct dcerpc_binding_handle *b = NULL;
     5329                struct policy_handle handle;
     5330                struct spoolss_DevmodeContainer devmode_ctr;
     5331                union spoolss_JobInfo *info;
     5332                uint32_t count;
     5333                uint32_t num_to_get;
     5334                uint32_t first;
     5335                uint32_t i;
     5336
     5337                ZERO_STRUCT(handle);
     5338
     5339                status = rpc_pipe_open_interface(conn,
     5340                                                 &ndr_table_spoolss.syntax_id,
     5341                                                 conn->session_info,
     5342                                                 &conn->sconn->client_id,
     5343                                                 conn->sconn->msg_ctx,
     5344                                                 &cli);
     5345                if (!NT_STATUS_IS_OK(status)) {
     5346                        DEBUG(0, ("reply_printqueue: "
     5347                                  "could not connect to spoolss: %s\n",
     5348                                  nt_errstr(status)));
     5349                        reply_nterror(req, status);
     5350                        goto out;
     5351                }
     5352                b = cli->binding_handle;
     5353
     5354                ZERO_STRUCT(devmode_ctr);
     5355
     5356                status = dcerpc_spoolss_OpenPrinter(b, mem_ctx,
     5357                                                sharename,
     5358                                                NULL, devmode_ctr,
     5359                                                SEC_FLAG_MAXIMUM_ALLOWED,
     5360                                                &handle,
     5361                                                &werr);
     5362                if (!NT_STATUS_IS_OK(status)) {
     5363                        reply_nterror(req, status);
     5364                        goto out;
     5365                }
     5366                if (!W_ERROR_IS_OK(werr)) {
     5367                        reply_nterror(req, werror_to_ntstatus(werr));
     5368                        goto out;
     5369                }
     5370
     5371                werr = rpccli_spoolss_enumjobs(cli, mem_ctx,
     5372                                               &handle,
     5373                                               0, /* firstjob */
     5374                                               0xff, /* numjobs */
     5375                                               2, /* level */
     5376                                               0, /* offered */
     5377                                               &count,
     5378                                               &info);
     5379                if (!W_ERROR_IS_OK(werr)) {
     5380                        reply_nterror(req, werror_to_ntstatus(werr));
     5381                        goto out;
     5382                }
     5383
     5384                if (max_count > 0) {
     5385                        first = start_index;
     5386                } else {
     5387                        first = start_index + max_count + 1;
     5388                }
     5389
     5390                if (first >= count) {
     5391                        num_to_get = first;
     5392                } else {
     5393                        num_to_get = first + MIN(ABS(max_count), count - first);
     5394                }
     5395
     5396                for (i = first; i < num_to_get; i++) {
    51405397                        char blob[28];
    51415398                        char *p = blob;
    5142 
    5143                         srv_put_dos_date2(p,0,queue[i].time);
    5144                         SCVAL(p,4,(queue[i].status==LPQ_PRINTING?2:3));
    5145                         SSVAL(p,5, queue[i].job);
    5146                         SIVAL(p,7,queue[i].size);
    5147                         SCVAL(p,11,0);
     5399                        time_t qtime = spoolss_Time_to_time_t(&info[i].info2.submitted);
     5400                        int qstatus;
     5401                        uint16_t qrapjobid = pjobid_to_rap(sharename,
     5402                                                        info[i].info2.job_id);
     5403
     5404                        if (info[i].info2.status == JOB_STATUS_PRINTING) {
     5405                                qstatus = 2;
     5406                        } else {
     5407                                qstatus = 3;
     5408                        }
     5409
     5410                        srv_put_dos_date2(p, 0, qtime);
     5411                        SCVAL(p, 4, qstatus);
     5412                        SSVAL(p, 5, qrapjobid);
     5413                        SIVAL(p, 7, info[i].info2.size);
     5414                        SCVAL(p, 11, 0);
    51485415                        srvstr_push(blob, req->flags2, p+12,
    5149                                     queue[i].fs_user, 16, STR_ASCII);
     5416                                    info[i].info2.notify_name, 16, STR_ASCII);
    51505417
    51515418                        if (message_push_blob(
     
    51545421                                            blob, sizeof(blob))) == -1) {
    51555422                                reply_nterror(req, NT_STATUS_NO_MEMORY);
    5156                                 END_PROFILE(SMBsplretq);
    5157                                 return;
     5423                                goto out;
    51585424                        }
    51595425                }
     
    51675433                }
    51685434
    5169                 SAFE_FREE(queue);
    5170 
    5171                 DEBUG(3,("%d entries returned in queue\n",count));
     5435
     5436                DEBUG(3, ("%u entries returned in queue\n",
     5437                          (unsigned)count));
     5438
     5439out:
     5440                if (b && is_valid_policy_hnd(&handle)) {
     5441                        dcerpc_spoolss_ClosePrinter(b, mem_ctx, &handle, &werr);
     5442                }
     5443
    51725444        }
    51735445
     
    52025474        }
    52035475
    5204         if (!CAN_PRINT(conn)) {
     5476        if (!fsp->print_file) {
    52055477                reply_nterror(req, NT_STATUS_ACCESS_DENIED);
    52065478                END_PROFILE(SMBsplwr);
     
    52245496        data = (const char *)req->buf + 3;
    52255497
    5226         if (write_file(req,fsp,data,-1,numtowrite) != numtowrite) {
     5498        if (write_file(req,fsp,data,(SMB_OFF_T)-1,numtowrite) != numtowrite) {
    52275499                reply_nterror(req, map_nt_error_from_unix(errno));
    52285500                END_PROFILE(SMBsplwr);
     
    53165588        files_struct *fsp = NULL;
    53175589        int info = 0;
    5318         struct smbd_server_connection *sconn = smbd_server_conn;
     5590        struct smbd_server_connection *sconn = req->sconn;
    53195591
    53205592        START_PROFILE(SMBrmdir);
     
    53615633                0,                                      /* oplock_request */
    53625634                0,                                      /* allocation_size */
     5635                0,                                      /* private_flags */
    53635636                NULL,                                   /* sd */
    53645637                NULL,                                   /* ea_list */
     
    53825655        }
    53835656
    5384         if (!set_delete_on_close(fsp, true, &conn->server_info->utok)) {
     5657        if (!set_delete_on_close(fsp, true, &conn->session_info->utok)) {
    53855658                close_file(req, fsp, ERROR_CLOSE);
    53865659                reply_nterror(req, NT_STATUS_ACCESS_DENIED);
     
    55385811static void rename_open_files(connection_struct *conn,
    55395812                              struct share_mode_lock *lck,
     5813                              uint32_t orig_name_hash,
    55405814                              const struct smb_filename *smb_fname_dst)
    55415815{
     
    55435817        bool did_rename = False;
    55445818        NTSTATUS status;
    5545 
    5546         for(fsp = file_find_di_first(lck->id); fsp;
     5819        uint32_t new_name_hash;
     5820
     5821        for(fsp = file_find_di_first(conn->sconn, lck->id); fsp;
    55475822            fsp = file_find_di_next(fsp)) {
    55485823                /* fsp_name is a relative path under the fsp. To change this for other
     
    55535828                        continue;
    55545829                }
     5830                if (fsp->name_hash != orig_name_hash) {
     5831                        continue;
     5832                }
    55555833                DEBUG(10, ("rename_open_files: renaming file fnum %d "
    55565834                           "(file_id %s) from %s -> %s\n", fsp->fnum,
     
    55615839                if (NT_STATUS_IS_OK(status)) {
    55625840                        did_rename = True;
     5841                        new_name_hash = fsp->name_hash;
    55635842                }
    55645843        }
     
    55715850
    55725851        /* Send messages to all smbd's (not ourself) that the name has changed. */
    5573         rename_share_filename(smbd_messaging_context(), lck, conn->connectpath,
     5852        rename_share_filename(conn->sconn->msg_ctx, lck, conn->connectpath,
     5853                              orig_name_hash, new_name_hash,
    55745854                              smb_fname_dst);
    55755855
     
    56815961        if (!NT_STATUS_IS_OK(status)) {
    56825962                goto out;
    5683         }
    5684 
    5685         /* Ensure the dst smb_fname contains a '/' */
    5686         if(strrchr_m(smb_fname_dst->base_name,'/') == 0) {
    5687                 char * tmp;
    5688                 tmp = talloc_asprintf(smb_fname_dst, "./%s",
    5689                                       smb_fname_dst->base_name);
    5690                 if (!tmp) {
    5691                         status = NT_STATUS_NO_MEMORY;
    5692                         goto out;
    5693                 }
    5694                 TALLOC_FREE(smb_fname_dst->base_name);
    5695                 smb_fname_dst->base_name = tmp;
    56965963        }
    56975964
     
    57115978
    57125979                /*
    5713                  * Get the last component of the destination name.  Note that
    5714                  * we guarantee that destination name contains a '/' character
    5715                  * above.
     5980                 * Get the last component of the destination name.
    57165981                 */
    57175982                last_slash = strrchr_m(smb_fname_dst->base_name, '/');
    5718                 fname_dst_lcomp_base_mod = talloc_strdup(ctx, last_slash + 1);
     5983                if (last_slash) {
     5984                        fname_dst_lcomp_base_mod = talloc_strdup(ctx, last_slash + 1);
     5985                } else {
     5986                        fname_dst_lcomp_base_mod = talloc_strdup(ctx, smb_fname_dst->base_name);
     5987                }
    57195988                if (!fname_dst_lcomp_base_mod) {
    57205989                        status = NT_STATUS_NO_MEMORY;
     
    57426011                         * original.
    57436012                         */
    5744                         *last_slash = '\0'; /* Truncate at the '/' */
    5745                         tmp = talloc_asprintf(smb_fname_dst,
     6013                        if (last_slash) {
     6014                                *last_slash = '\0'; /* Truncate at the '/' */
     6015                                tmp = talloc_asprintf(smb_fname_dst,
    57466016                                        "%s/%s",
    57476017                                        smb_fname_dst->base_name,
    57486018                                        smb_fname_orig_lcomp->base_name);
     6019                        } else {
     6020                                tmp = talloc_asprintf(smb_fname_dst,
     6021                                        "%s",
     6022                                        smb_fname_orig_lcomp->base_name);
     6023                        }
    57496024                        if (tmp == NULL) {
    57506025                                status = NT_STATUS_NO_MEMORY;
     
    58196094                struct file_id fileid = vfs_file_id_from_sbuf(conn,
    58206095                    &smb_fname_dst->st);
    5821                 files_struct *dst_fsp = file_find_di_first(fileid);
     6096                files_struct *dst_fsp = file_find_di_first(conn->sconn,
     6097                                                           fileid);
    58226098                /* The file can be open when renaming a stream */
    58236099                if (dst_fsp && !new_is_stream) {
     
    58856161                              smb_fname_dst);
    58866162
    5887                 rename_open_files(conn, lck, smb_fname_dst);
     6163                rename_open_files(conn, lck, fsp->name_hash, smb_fname_dst);
    58886164
    58896165                /*
     
    60006276                 */
    60016277                TALLOC_FREE(smb_fname_src->base_name);
    6002                 smb_fname_src->base_name = talloc_asprintf(smb_fname_src,
    6003                                                            "%s/%s",
    6004                                                            fname_src_dir,
    6005                                                            fname_src_mask);
     6278                if (ISDOT(fname_src_dir)) {
     6279                        /* Ensure we use canonical names on open. */
     6280                        smb_fname_src->base_name = talloc_asprintf(smb_fname_src,
     6281                                                        "%s",
     6282                                                        fname_src_mask);
     6283                } else {
     6284                        smb_fname_src->base_name = talloc_asprintf(smb_fname_src,
     6285                                                        "%s/%s",
     6286                                                        fname_src_dir,
     6287                                                        fname_src_mask);
     6288                }
    60066289                if (!smb_fname_src->base_name) {
    60076290                        status = NT_STATUS_NO_MEMORY;
    60086291                        goto out;
    6009                 }
    6010 
    6011                 /* Ensure dst fname contains a '/' also */
    6012                 if(strrchr_m(smb_fname_dst->base_name, '/') == 0) {
    6013                         char *tmp;
    6014                         tmp = talloc_asprintf(smb_fname_dst, "./%s",
    6015                                               smb_fname_dst->base_name);
    6016                         if (!tmp) {
    6017                                 status = NT_STATUS_NO_MEMORY;
    6018                                 goto out;
    6019                         }
    6020                         TALLOC_FREE(smb_fname_dst->base_name);
    6021                         smb_fname_dst->base_name = tmp;
    60226292                }
    60236293
     
    60746344                        0,                              /* oplock_request */
    60756345                        0,                              /* allocation_size */
     6346                        0,                              /* private_flags */
    60766347                        NULL,                           /* sd */
    60776348                        NULL,                           /* ea_list */
     
    61366407                /* Quick check for "." and ".." */
    61376408                if (ISDOT(dname) || ISDOTDOT(dname)) {
    6138                         if (attrs & aDIR) {
     6409                        if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
    61396410                                sysdir_entry = True;
    61406411                        } else {
     
    61616432
    61626433                TALLOC_FREE(smb_fname_src->base_name);
    6163                 smb_fname_src->base_name = talloc_asprintf(smb_fname_src,
    6164                                                            "%s/%s",
    6165                                                            fname_src_dir,
    6166                                                            dname);
     6434                if (ISDOT(fname_src_dir)) {
     6435                        /* Ensure we use canonical names on open. */
     6436                        smb_fname_src->base_name = talloc_asprintf(smb_fname_src,
     6437                                                        "%s",
     6438                                                        dname);
     6439                } else {
     6440                        smb_fname_src->base_name = talloc_asprintf(smb_fname_src,
     6441                                                        "%s/%s",
     6442                                                        fname_src_dir,
     6443                                                        dname);
     6444                }
    61676445                if (!smb_fname_src->base_name) {
    61686446                        status = NT_STATUS_NO_MEMORY;
     
    62126490                        0,                              /* oplock_request */
    62136491                        0,                              /* allocation_size */
     6492                        0,                              /* private_flags */
    62146493                        NULL,                           /* sd */
    62156494                        NULL,                           /* ea_list */
     
    62836562        struct smb_filename *smb_fname_src = NULL;
    62846563        struct smb_filename *smb_fname_dst = NULL;
     6564        bool stream_rename = false;
    62856565
    62866566        START_PROFILE(SMBmv);
     
    63076587                goto out;
    63086588        }
     6589
     6590        if (!lp_posix_pathnames()) {
     6591                /* The newname must begin with a ':' if the
     6592                   name contains a ':'. */
     6593                if (strchr_m(name, ':')) {
     6594                        if (newname[0] != ':') {
     6595                                reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
     6596                                goto out;
     6597                        }
     6598                        stream_rename = true;
     6599                }
     6600        }
    63096601
    63106602        status = filename_convert(ctx,
     
    63446636        }
    63456637
     6638        if (stream_rename) {
     6639                /* smb_fname_dst->base_name must be the same as
     6640                   smb_fname_src->base_name. */
     6641                TALLOC_FREE(smb_fname_dst->base_name);
     6642                smb_fname_dst->base_name = talloc_strdup(smb_fname_dst,
     6643                                                smb_fname_src->base_name);
     6644                if (!smb_fname_dst->base_name) {
     6645                        reply_nterror(req, NT_STATUS_NO_MEMORY);
     6646                        goto out;
     6647                }
     6648        }
     6649
    63466650        DEBUG(3,("reply_mv : %s -> %s\n", smb_fname_str_dbg(smb_fname_src),
    63476651                 smb_fname_str_dbg(smb_fname_dst)));
     
    64326736                                                 NULL, NULL,
    64336737                                                 &new_create_disposition,
     6738                                                 NULL,
    64346739                                                 NULL)) {
    64356740                        status = NT_STATUS_INVALID_PARAMETER;
     
    64516756                INTERNAL_OPEN_ONLY,                     /* oplock_request */
    64526757                0,                                      /* allocation_size */
     6758                0,                                      /* private_flags */
    64536759                NULL,                                   /* sd */
    64546760                NULL,                                   /* ea_list */
     
    64796785                INTERNAL_OPEN_ONLY,                     /* oplock_request */
    64806786                0,                                      /* allocation_size */
     6787                0,                                      /* private_flags */
    64816788                NULL,                                   /* sd */
    64826789                NULL,                                   /* ea_list */
     
    64896796        }
    64906797
    6491         if ((ofun&3) == 1) {
    6492                 if(SMB_VFS_LSEEK(fsp2,0,SEEK_END) == -1) {
    6493                         DEBUG(0,("copy_file: error - vfs lseek returned error %s\n", strerror(errno) ));
    6494                         /*
    6495                          * Stop the copy from occurring.
    6496                          */
    6497                         ret = -1;
    6498                         smb_fname_src->st.st_ex_size = 0;
     6798        if (ofun & OPENX_FILE_EXISTS_OPEN) {
     6799                ret = SMB_VFS_LSEEK(fsp2, 0, SEEK_END);
     6800                if (ret == -1) {
     6801                        DEBUG(0, ("error - vfs lseek returned error %s\n",
     6802                                strerror(errno)));
     6803                        status = map_nt_error_from_unix(errno);
     6804                        close_file(NULL, fsp1, ERROR_CLOSE);
     6805                        close_file(NULL, fsp2, ERROR_CLOSE);
     6806                        goto out;
    64996807                }
    65006808        }
     
    65036811        if (smb_fname_src->st.st_ex_size) {
    65046812                ret = vfs_transfer_file(fsp1, fsp2, smb_fname_src->st.st_ex_size);
     6813        } else {
     6814                ret = 0;
    65056815        }
    65066816
     
    66806990                 */
    66816991                TALLOC_FREE(smb_fname_src->base_name);
    6682                 smb_fname_src->base_name = talloc_asprintf(smb_fname_src,
    6683                                                            "%s/%s",
    6684                                                            fname_src_dir,
    6685                                                            fname_src_mask);
     6992                if (ISDOT(fname_src_dir)) {
     6993                        /* Ensure we use canonical names on open. */
     6994                        smb_fname_src->base_name = talloc_asprintf(smb_fname_src,
     6995                                                        "%s",
     6996                                                        fname_src_mask);
     6997                } else {
     6998                        smb_fname_src->base_name = talloc_asprintf(smb_fname_src,
     6999                                                        "%s/%s",
     7000                                                        fname_src_dir,
     7001                                                        fname_src_mask);
     7002                }
    66867003                if (!smb_fname_src->base_name) {
    66877004                        reply_nterror(req, NT_STATUS_NO_MEMORY);
     
    67917108                        /* Get the src smb_fname struct setup. */
    67927109                        TALLOC_FREE(smb_fname_src->base_name);
    6793                         smb_fname_src->base_name =
    6794                             talloc_asprintf(smb_fname_src, "%s/%s",
    6795                                             fname_src_dir, dname);
     7110                        if (ISDOT(fname_src_dir)) {
     7111                                /* Ensure we use canonical names on open. */
     7112                                smb_fname_src->base_name =
     7113                                        talloc_asprintf(smb_fname_src, "%s",
     7114                                                dname);
     7115                        } else {
     7116                                smb_fname_src->base_name =
     7117                                        talloc_asprintf(smb_fname_src, "%s/%s",
     7118                                                fname_src_dir, dname);
     7119                        }
    67967120
    67977121                        if (!smb_fname_src->base_name) {
     
    68767200****************************************************************************/
    68777201
    6878 uint32 get_lock_pid(const uint8_t *data, int data_offset,
     7202uint64_t get_lock_pid(const uint8_t *data, int data_offset,
    68797203                    bool large_file_format)
    68807204{
    68817205        if(!large_file_format)
    6882                 return (uint32)SVAL(data,SMB_LPID_OFFSET(data_offset));
     7206                return (uint64_t)SVAL(data,SMB_LPID_OFFSET(data_offset));
    68837207        else
    6884                 return (uint32)SVAL(data,SMB_LARGE_LPID_OFFSET(data_offset));
     7208                return (uint64_t)SVAL(data,SMB_LARGE_LPID_OFFSET(data_offset));
    68857209}
    68867210
     
    70337357                          (double)e->offset,
    70347358                          (double)e->count,
    7035                           (unsigned int)e->smbpid,
     7359                          (unsigned int)e->smblctx,
    70367360                          fsp_str_dbg(fsp)));
    70377361
     
    70417365                }
    70427366
    7043                 status = do_unlock(smbd_messaging_context(),
     7367                status = do_unlock(req->sconn->msg_ctx,
    70447368                                fsp,
    7045                                 e->smbpid,
     7369                                e->smblctx,
    70467370                                e->count,
    70477371                                e->offset,
     
    70687392                struct smbd_lock_element *e = &locks[i];
    70697393
    7070                 DEBUG(10,("smbd_do_locking: lock start=%.0f, len=%.0f for pid "
    7071                           "%u, file %s timeout = %d\n",
     7394                DEBUG(10,("smbd_do_locking: lock start=%.0f, len=%.0f for smblctx "
     7395                          "%llu, file %s timeout = %d\n",
    70727396                          (double)e->offset,
    70737397                          (double)e->count,
    7074                           (unsigned int)e->smbpid,
     7398                          (unsigned long long)e->smblctx,
    70757399                          fsp_str_dbg(fsp),
    70767400                          (int)timeout));
     
    71097433                                   return the right error. */
    71107434
    7111                                 blr = blocking_lock_cancel(fsp,
    7112                                                 e->smbpid,
     7435                                blr = blocking_lock_cancel_smb1(fsp,
     7436                                                e->smblctx,
    71137437                                                e->offset,
    71147438                                                e->count,
     
    71247448                        /* Remove a matching pending lock. */
    71257449                        status = do_lock_cancel(fsp,
    7126                                                 e->smbpid,
     7450                                                e->smblctx,
    71277451                                                e->count,
    71287452                                                e->offset,
     
    71337457                        bool defer_lock = false;
    71347458                        struct byte_range_lock *br_lck;
    7135                         uint32_t block_smbpid;
    7136 
    7137                         br_lck = do_lock(smbd_messaging_context(),
     7459                        uint64_t block_smblctx;
     7460
     7461                        br_lck = do_lock(req->sconn->msg_ctx,
    71387462                                        fsp,
    7139                                         e->smbpid,
     7463                                        e->smblctx,
    71407464                                        e->count,
    71417465                                        e->offset,
     
    71447468                                        blocking_lock,
    71457469                                        &status,
    7146                                         &block_smbpid,
     7470                                        &block_smblctx,
    71477471                                        NULL);
    71487472
     
    71677491                         * Replacement for do_lock_spin(). JRA. */
    71687492
    7169                         if (br_lck && lp_blocking_locks(SNUM(conn)) &&
     7493                        if (!req->sconn->using_smb2 &&
     7494                            br_lck && lp_blocking_locks(SNUM(conn)) &&
    71707495                            lp_lock_spin_time() && !blocking_lock &&
    71717496                            NT_STATUS_EQUAL((status),
     
    71877512                                                        timeout,
    71887513                                                        i,
    7189                                                         e->smbpid,
     7514                                                        e->smblctx,
    71907515                                                        e->brltype,
    71917516                                                        WINDOWS_LOCK,
    71927517                                                        e->offset,
    71937518                                                        e->count,
    7194                                                         block_smbpid)) {
     7519                                                        block_smblctx)) {
    71957520                                        TALLOC_FREE(br_lck);
    71967521                                        *async = true;
     
    72247549                        struct smbd_lock_element *e = &locks[i];
    72257550
    7226                         do_unlock(smbd_messaging_context(),
     7551                        do_unlock(req->sconn->msg_ctx,
    72277552                                fsp,
    7228                                 e->smbpid,
     7553                                e->smblctx,
    72297554                                e->count,
    72307555                                e->offset,
     
    73917716           of smb_unlkrng structs */
    73927717        for(i = 0; i < (int)num_ulocks; i++) {
    7393                 ulocks[i].smbpid = get_lock_pid(data, i, large_file_format);
     7718                ulocks[i].smblctx = get_lock_pid(data, i, large_file_format);
    73947719                ulocks[i].count = get_lock_count(data, i, large_file_format);
    73957720                ulocks[i].offset = get_lock_offset(data, i, large_file_format, &err);
     
    74137738
    74147739        for(i = 0; i < (int)num_locks; i++) {
    7415                 locks[i].smbpid = get_lock_pid(data, i, large_file_format);
     7740                locks[i].smblctx = get_lock_pid(data, i, large_file_format);
    74167741                locks[i].count = get_lock_count(data, i, large_file_format);
    74177742                locks[i].offset = get_lock_offset(data, i, large_file_format, &err);
     
    76487973                          convert_timespec_to_time_t(fsp->fsp_name->st.st_ex_mtime));
    76497974
    7650         if (mode & aDIR) {
     7975        if (mode & FILE_ATTRIBUTE_DIRECTORY) {
    76517976                SIVAL(req->outbuf, smb_vwv6, 0);
    76527977                SIVAL(req->outbuf, smb_vwv8, 0);
Note: See TracChangeset for help on using the changeset viewer.