From dffeb12f3dcb339bc258a7fbc38bbf9ec8dd928e Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 28 Apr 2010 19:42:04 -0400 Subject: smbd: move printfile_offset() within write_file() --- source3/locking/locking.c | 6 ++++++ source3/printing/printfsp.c | 7 ++++++- source3/smbd/fileio.c | 3 +++ source3/smbd/reply.c | 16 ++++------------ 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/source3/locking/locking.c b/source3/locking/locking.c index a2581b1b96..3975a78673 100644 --- a/source3/locking/locking.c +++ b/source3/locking/locking.c @@ -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; diff --git a/source3/printing/printfsp.c b/source3/printing/printfsp.c index e8907488c4..5bb662e10f 100644 --- a/source3/printing/printfsp.c +++ b/source3/printing/printfsp.c @@ -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), diff --git a/source3/smbd/fileio.c b/source3/smbd/fileio.c index da72e5a5f0..92b7d3ed9e 100644 --- a/source3/smbd/fileio.c +++ b/source3/smbd/fileio.c @@ -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); } diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c index 6469ad8306..571b8a8ab0 100644 --- a/source3/smbd/reply.c +++ b/source3/smbd/reply.c @@ -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); -- cgit