- if (pf == NULL) {
- return EBADF;
- }
- if (pf->spoolss_pipe == NULL) {
- return EBADF;
- }
- b = pf->spoolss_pipe->binding_handle;
-
- /* When print files go beyond 4GB, the 32-bit offset sent in
- * old SMBwrite calls is relative to the current 4GB chunk
- * we're writing to.
- * Discovered by Sebastian Kloska <oncaphillis@snafu.de>.
- */
- if (offset < 0xffffffff00000000LL) {
- offset = (pf->offset & 0xffffffff00000000LL) + offset;
- }
-
- if ((uint64_t)offset != pf->offset) {
- // TODO: check what windows does, with non sequential
- // writes.
- ret = EINVAL;
- goto error;
- }
-
- remaining = UINT64_MAX - pf->offset;
- if (size > remaining) {
- ret = EINVAL;
- goto error;
- }
-
- buffer = data_blob_const(data, size);
-
- status = dcerpc_spoolss_WritePrinter(b, tmp_ctx,
- &pf->handle,
- buffer,
- buffer.length,
- written,
- &werr);
- if (!NT_STATUS_IS_OK(status)) {
- ret = EINVAL;
- goto error;
- }
- if (!W_ERROR_IS_OK(werr)) {
- //status = werror_to_ntstatus(werr);
- ret = EINVAL;
- goto error;
- }
-
- if (*written > size) {
- //status = NT_STATUS_INVALID_PARAMETER;
- ret = EINVAL;
- goto error;
- }
-
- pf->offset += *written;
- return 0;
-error:
- print_spool_terminate(fsp->conn, fsp->print_file);
- return ret;