1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-04 08:22:08 +03:00

Fix bug #7233 - print fails with jobs >4GB from Win7 clients.

Ensure we always write at end-of-file for older write calls.

Jeremy.
This commit is contained in:
Jeremy Allison
2010-03-24 12:47:01 -07:00
parent c2d1b01103
commit 66b7fcc8ef

View File

@ -3803,6 +3803,11 @@ void reply_writebraw(struct smb_request *req)
startpos = IVAL_TO_SMB_OFF_T(req->vwv+3, 0); startpos = IVAL_TO_SMB_OFF_T(req->vwv+3, 0);
write_through = BITSETW(req->vwv+7,0); write_through = BITSETW(req->vwv+7,0);
if (fsp->print_file) {
/* Print files ignore the offset - use end of file. */
startpos = (SMB_OFF_T)-1;
}
/* We have to deal with slightly different formats depending /* We have to deal with slightly different formats depending
on whether we are using the core+ or lanman1.0 protocol */ on whether we are using the core+ or lanman1.0 protocol */
@ -3822,6 +3827,7 @@ void reply_writebraw(struct smb_request *req)
return; return;
} }
if (!fsp->print_file) {
init_strict_lock_struct(fsp, (uint32)req->smbpid, init_strict_lock_struct(fsp, (uint32)req->smbpid,
(uint64_t)startpos, (uint64_t)tcount, WRITE_LOCK, (uint64_t)startpos, (uint64_t)tcount, WRITE_LOCK,
&lock); &lock);
@ -3832,6 +3838,7 @@ void reply_writebraw(struct smb_request *req)
END_PROFILE(SMBwritebraw); END_PROFILE(SMBwritebraw);
return; return;
} }
}
if (numtowrite>0) { if (numtowrite>0) {
nwritten = write_file(req,fsp,data,startpos,numtowrite); nwritten = write_file(req,fsp,data,startpos,numtowrite);
@ -3909,7 +3916,11 @@ void reply_writebraw(struct smb_request *req)
exit_server_cleanly("secondary writebraw failed"); exit_server_cleanly("secondary writebraw failed");
} }
if (fsp->print_file) {
nwritten = write_file(req,fsp,buf+4,(SMB_OFF_T)-1,numtowrite);
} else {
nwritten = write_file(req,fsp,buf+4,startpos+nwritten,numtowrite); nwritten = write_file(req,fsp,buf+4,startpos+nwritten,numtowrite);
}
if (nwritten == -1) { if (nwritten == -1) {
TALLOC_FREE(buf); TALLOC_FREE(buf);
reply_nterror(req, map_nt_error_from_unix(errno)); reply_nterror(req, map_nt_error_from_unix(errno));
@ -3944,7 +3955,9 @@ void reply_writebraw(struct smb_request *req)
fsp->fnum, (double)startpos, (int)numtowrite, fsp->fnum, (double)startpos, (int)numtowrite,
(int)total_written)); (int)total_written));
if (!fsp->print_file) {
SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock); SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
}
/* We won't return a status if write through is not selected - this /* We won't return a status if write through is not selected - this
* follows what WfWg does */ * follows what WfWg does */
@ -3968,7 +3981,9 @@ void reply_writebraw(struct smb_request *req)
return; return;
strict_unlock: strict_unlock:
if (!fsp->print_file) {
SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock); SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
}
END_PROFILE(SMBwritebraw); END_PROFILE(SMBwritebraw);
return; return;
@ -4018,7 +4033,10 @@ void reply_writeunlock(struct smb_request *req)
startpos = IVAL_TO_SMB_OFF_T(req->vwv+2, 0); startpos = IVAL_TO_SMB_OFF_T(req->vwv+2, 0);
data = (const char *)req->buf + 3; data = (const char *)req->buf + 3;
if (numtowrite) { if (fsp->print_file) {
/* Print files ignore the offset - use end of file. */
startpos = (SMB_OFF_T)-1;
} else if (numtowrite) {
init_strict_lock_struct(fsp, (uint32)req->smbpid, init_strict_lock_struct(fsp, (uint32)req->smbpid,
(uint64_t)startpos, (uint64_t)numtowrite, WRITE_LOCK, (uint64_t)startpos, (uint64_t)numtowrite, WRITE_LOCK,
&lock); &lock);
@ -4058,7 +4076,7 @@ void reply_writeunlock(struct smb_request *req)
goto strict_unlock; goto strict_unlock;
} }
if (numtowrite) { if (numtowrite && !fsp->print_file) {
status = do_unlock(smbd_messaging_context(), status = do_unlock(smbd_messaging_context(),
fsp, fsp,
req->smbpid, req->smbpid,
@ -4080,7 +4098,7 @@ void reply_writeunlock(struct smb_request *req)
fsp->fnum, (int)numtowrite, (int)nwritten)); fsp->fnum, (int)numtowrite, (int)nwritten));
strict_unlock: strict_unlock:
if (numtowrite) { if (numtowrite && !fsp->print_file) {
SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock); SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
} }
@ -4139,6 +4157,10 @@ void reply_write(struct smb_request *req)
startpos = IVAL_TO_SMB_OFF_T(req->vwv+2, 0); startpos = IVAL_TO_SMB_OFF_T(req->vwv+2, 0);
data = (const char *)req->buf + 3; data = (const char *)req->buf + 3;
if (fsp->print_file) {
/* Print files ignore the offset - use end of file. */
startpos = (SMB_OFF_T)-1;
} else {
init_strict_lock_struct(fsp, (uint32)req->smbpid, init_strict_lock_struct(fsp, (uint32)req->smbpid,
(uint64_t)startpos, (uint64_t)numtowrite, WRITE_LOCK, (uint64_t)startpos, (uint64_t)numtowrite, WRITE_LOCK,
&lock); &lock);
@ -4148,6 +4170,7 @@ void reply_write(struct smb_request *req)
END_PROFILE(SMBwrite); END_PROFILE(SMBwrite);
return; return;
} }
}
/* /*
* X/Open SMB protocol says that if smb_vwv1 is * X/Open SMB protocol says that if smb_vwv1 is
@ -4204,7 +4227,9 @@ void reply_write(struct smb_request *req)
DEBUG(3,("write fnum=%d num=%d wrote=%d\n", fsp->fnum, (int)numtowrite, (int)nwritten)); DEBUG(3,("write fnum=%d num=%d wrote=%d\n", fsp->fnum, (int)numtowrite, (int)nwritten));
strict_unlock: strict_unlock:
if (!fsp->print_file) {
SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock); SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
}
END_PROFILE(SMBwrite); END_PROFILE(SMBwrite);
return; return;
@ -4741,7 +4766,10 @@ void reply_writeclose(struct smb_request *req)
mtime = convert_time_t_to_timespec(srv_make_unix_date3(req->vwv+4)); mtime = convert_time_t_to_timespec(srv_make_unix_date3(req->vwv+4));
data = (const char *)req->buf + 1; data = (const char *)req->buf + 1;
if (numtowrite) { if (fsp->print_file) {
/* Print files ignore the offset - use end of file. */
startpos = (SMB_OFF_T)-1;
} else if (numtowrite) {
init_strict_lock_struct(fsp, (uint32)req->smbpid, init_strict_lock_struct(fsp, (uint32)req->smbpid,
(uint64_t)startpos, (uint64_t)numtowrite, WRITE_LOCK, (uint64_t)startpos, (uint64_t)numtowrite, WRITE_LOCK,
&lock); &lock);
@ -4787,7 +4815,7 @@ void reply_writeclose(struct smb_request *req)
SSVAL(req->outbuf,smb_vwv0,nwritten); SSVAL(req->outbuf,smb_vwv0,nwritten);
strict_unlock: strict_unlock:
if (numtowrite) { if (numtowrite && !fsp->print_file) {
SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock); SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
} }
@ -5244,7 +5272,7 @@ void reply_printwrite(struct smb_request *req)
data = (const char *)req->buf + 3; data = (const char *)req->buf + 3;
if (write_file(req,fsp,data,-1,numtowrite) != numtowrite) { if (write_file(req,fsp,data,(SMB_OFF_T)-1,numtowrite) != numtowrite) {
reply_nterror(req, map_nt_error_from_unix(errno)); reply_nterror(req, map_nt_error_from_unix(errno));
END_PROFILE(SMBsplwr); END_PROFILE(SMBsplwr);
return; return;