smbd: move printfile_offset() within write_file()
authorSimo Sorce <idra@samba.org>
Wed, 28 Apr 2010 23:42:04 +0000 (19:42 -0400)
committerJeremy Allison <jra@samba.org>
Fri, 30 Apr 2010 18:52:39 +0000 (11:52 -0700)
source3/locking/locking.c
source3/printing/printfsp.c
source3/smbd/fileio.c
source3/smbd/reply.c

index a2581b1b966a3f8c2e5f4d070a21ce1884c899a0..3975a78673c6521e38333c7ab1706bc72bc6bb57 100644 (file)
@@ -241,6 +241,12 @@ struct byte_range_lock *do_lock(struct messaging_context *msg_ctx,
 {
        struct byte_range_lock *br_lck = NULL;
 
+       /* silently return ok on print files as we don't do locking there */
+       if (fsp->print_file) {
+               *perr = NT_STATUS_OK;
+               return NULL;
+       }
+
        if (!fsp->can_lock) {
                *perr = fsp->is_directory ? NT_STATUS_INVALID_DEVICE_REQUEST : NT_STATUS_INVALID_HANDLE;
                return NULL;
index e8907488c45f13643cdbf2507f7c7cadcb7d8fd4..5bb662e10f976e02b3b3efb2eff3af246c9f58fd 100644 (file)
@@ -76,7 +76,7 @@ NTSTATUS print_fsp_open(struct smb_request *req, connection_struct *conn,
        GetTimeOfDay(&fsp->open_time);
        fsp->vuid = current_vuid;
        fsp->fh->pos = -1;
-       fsp->can_lock = True;
+       fsp->can_lock = False;
        fsp->can_read = False;
        fsp->access_mask = FILE_GENERIC_WRITE;
        fsp->can_write = True;
@@ -131,6 +131,11 @@ SMB_OFF_T printfile_offset(files_struct *fsp, SMB_OFF_T offset)
 {
        SMB_STRUCT_STAT st;
 
+       if (offset & 0xffffffff00000000LL) {
+               /* offset is > 4G, skip */
+               return offset;
+       }
+
        if (sys_fstat(fsp->fh->fd, &st, false) == -1) {
                DEBUG(3,("printfile_offset: sys_fstat failed on %s (%s)\n",
                        fsp_str_dbg(fsp),
index da72e5a5f04fa6486d1cf32bb6aa375e6be9dcbb..92b7d3ed9ea0a6ead0103ac28d2a9d784f985210 100644 (file)
@@ -301,6 +301,9 @@ ssize_t write_file(struct smb_request *req,
                        return -1;
                }
 
+               /* support seeks for print files bigger than 4G */
+               pos = printfile_offset(fsp, pos);
+
                return print_job_write(SNUM(fsp->conn), jobid, data, pos, n);
        }
 
index 6469ad8306a8b5bd9ca9feb94066e3214b2938ac..571b8a8ab00dca3a520a4fa5f7dd542679c784c7 100644 (file)
@@ -3832,9 +3832,7 @@ void reply_writebraw(struct smb_request *req)
                return;
        }
 
-       if (fsp->print_file) {
-               startpos = printfile_offset(fsp, startpos);
-       } else {
+       if (!fsp->print_file) {
                init_strict_lock_struct(fsp, (uint32)req->smbpid,
                    (uint64_t)startpos, (uint64_t)tcount, WRITE_LOCK,
                    &lock);
@@ -4036,9 +4034,7 @@ void reply_writeunlock(struct smb_request *req)
        startpos = IVAL_TO_SMB_OFF_T(req->vwv+2, 0);
        data = (const char *)req->buf + 3;
 
-       if (fsp->print_file) {
-               startpos = printfile_offset(fsp, startpos);
-       } else if (numtowrite) {
+       if (!fsp->print_file && numtowrite > 0) {
                init_strict_lock_struct(fsp, (uint32)req->smbpid,
                    (uint64_t)startpos, (uint64_t)numtowrite, WRITE_LOCK,
                    &lock);
@@ -4159,9 +4155,7 @@ void reply_write(struct smb_request *req)
        startpos = IVAL_TO_SMB_OFF_T(req->vwv+2, 0);
        data = (const char *)req->buf + 3;
 
-       if (fsp->print_file) {
-               startpos = printfile_offset(fsp, startpos);
-       } else {
+       if (!fsp->print_file) {
                init_strict_lock_struct(fsp, (uint32)req->smbpid,
                        (uint64_t)startpos, (uint64_t)numtowrite, WRITE_LOCK,
                        &lock);
@@ -4779,9 +4773,7 @@ void reply_writeclose(struct smb_request *req)
        mtime = convert_time_t_to_timespec(srv_make_unix_date3(req->vwv+4));
        data = (const char *)req->buf + 1;
 
-       if (fsp->print_file) {
-               startpos = printfile_offset(fsp, startpos);
-       } else if (numtowrite) {
+       if (!fsp->print_file) {
                init_strict_lock_struct(fsp, (uint32)req->smbpid,
                    (uint64_t)startpos, (uint64_t)numtowrite, WRITE_LOCK,
                    &lock);