#include "includes.h"
#include "printing.h"
-#include "../librpc/gen_ndr/cli_spoolss.h"
+#include "rpc_client/rpc_client.h"
+#include "../librpc/gen_ndr/ndr_spoolss_c.h"
+#include "rpc_server/rpc_ncacn_np.h"
+#include "smbd/globals.h"
+#include "../libcli/security/security.h"
+
+struct print_file_data {
+ char *svcname;
+ char *docname;
+ char *filename;
+ struct policy_handle handle;
+ uint32_t jobid;
+ uint16 rap_jobid;
+};
+
+uint16_t print_spool_rap_jobid(struct print_file_data *print_file)
+{
+ if (print_file == NULL) {
+ return 0;
+ }
+
+ return print_file->rap_jobid;
+}
void print_spool_terminate(struct connection_struct *conn,
struct print_file_data *print_file);
NTSTATUS print_spool_open(files_struct *fsp,
const char *fname,
- uint16_t current_vuid)
+ uint64_t current_vuid)
{
NTSTATUS status;
TALLOC_CTX *tmp_ctx;
struct print_file_data *pf;
- struct rpc_pipe_client *cli;
+ struct dcerpc_binding_handle *b = NULL;
struct spoolss_DevmodeContainer devmode_ctr;
union spoolss_DocumentInfo info;
int fd = -1;
status = NT_STATUS_NO_MEMORY;
goto done;
}
- pf->svcname = talloc_strdup(pf, lp_servicename(SNUM(fsp->conn)));
+ pf->svcname = lp_servicename(pf, SNUM(fsp->conn));
/* the document name is derived from the file name.
* "Remote Downlevel Document" is added in front to
}
}
- /* Ok, now we have to open an actual file.
+ /*
+ * Ok, now we have to open an actual file.
* Here is the reason:
* We want to write the spool job to this file in
* smbd for scalability reason (and also because
* to spoolss in output_file so it can monitor and
* take over once we call EndDocPrinter().
* Of course we will not start writing until
- * StartDocPrinter() actually gives the ok. */
+ * StartDocPrinter() actually gives the ok.
+ * smbd spooler files do not include a print jobid
+ * path component, as the jobid is only known after
+ * calling StartDocPrinter().
+ */
- pf->filename = talloc_asprintf(pf, "%s/%s.XXXXXX",
- lp_pathname(SNUM(fsp->conn)),
+ pf->filename = talloc_asprintf(pf, "%s/%sXXXXXX",
+ lp_pathname(talloc_tos(),
+ SNUM(fsp->conn)),
PRINT_SPOOL_PREFIX);
if (!pf->filename) {
status = NT_STATUS_NO_MEMORY;
* all printer verification, and eventually assigns
* a job id */
- status = rpc_connect_spoolss_pipe(fsp->conn, &cli);
+ status = rpc_pipe_open_interface(fsp->conn,
+ &ndr_table_spoolss.syntax_id,
+ fsp->conn->session_info,
+ fsp->conn->sconn->remote_address,
+ fsp->conn->sconn->msg_ctx,
+ &fsp->conn->spoolss_pipe);
if (!NT_STATUS_IS_OK(status)) {
goto done;
}
+ b = fsp->conn->spoolss_pipe->binding_handle;
ZERO_STRUCT(devmode_ctr);
- status = rpccli_spoolss_OpenPrinter(cli, pf, pf->svcname,
+ status = dcerpc_spoolss_OpenPrinter(b, pf, pf->svcname,
"RAW", devmode_ctr,
SEC_FLAG_MAXIMUM_ALLOWED,
&pf->handle, &werr);
info.info1->output_file = pf->filename;
info.info1->datatype = "RAW";
- status = rpccli_spoolss_StartDocPrinter(cli, tmp_ctx, &pf->handle,
+ status = dcerpc_spoolss_StartDocPrinter(b, tmp_ctx, &pf->handle,
1, info, &pf->jobid, &werr);
if (!NT_STATUS_IS_OK(status)) {
goto done;
}
fsp->file_id = vfs_file_id_from_sbuf(fsp->conn, &fsp->fsp_name->st);
- fsp->mode = fsp->fsp_name->st.st_ex_mode;
fsp->fh->fd = fd;
fsp->vuid = current_vuid;
if (!NT_STATUS_IS_OK(status)) {
if (fd != -1) {
close(fd);
- unlink(fsp->print_file->filename);
+ if (fsp->print_file) {
+ unlink(fsp->print_file->filename);
+ }
}
/* We need to delete the job from spoolss too */
if (pf->jobid) {
int print_spool_write(files_struct *fsp,
const char *data, uint32_t size,
- SMB_OFF_T offset, uint32_t *written)
+ off_t offset, uint32_t *written)
{
SMB_STRUCT_STAT st;
ssize_t n;
void print_spool_end(files_struct *fsp, enum file_close_type close_type)
{
- struct rpc_pipe_client *cli;
NTSTATUS status;
WERROR werr;
+ struct dcerpc_binding_handle *b = NULL;
- status = rpc_connect_spoolss_pipe(fsp->conn, &cli);
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(0, ("print_spool_end: "
- "Failed to get spoolss pipe [%s]\n",
- nt_errstr(status)));
- return;
- }
+ b = fsp->conn->spoolss_pipe->binding_handle;
switch (close_type) {
case NORMAL_CLOSE:
case SHUTDOWN_CLOSE:
/* this also automatically calls spoolss_EndDocPrinter */
- status = rpccli_spoolss_ClosePrinter(cli, fsp->print_file,
+ status = dcerpc_spoolss_ClosePrinter(b, fsp->print_file,
&fsp->print_file->handle,
&werr);
if (!NT_STATUS_IS_OK(status) ||
void print_spool_terminate(struct connection_struct *conn,
struct print_file_data *print_file)
{
- struct rpc_pipe_client *cli;
NTSTATUS status;
WERROR werr;
+ struct dcerpc_binding_handle *b = NULL;
rap_jobid_delete(print_file->svcname, print_file->jobid);
- status = rpc_connect_spoolss_pipe(conn, &cli);
+ status = rpc_pipe_open_interface(conn,
+ &ndr_table_spoolss.syntax_id,
+ conn->session_info,
+ conn->sconn->remote_address,
+ conn->sconn->msg_ctx,
+ &conn->spoolss_pipe);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("print_spool_terminate: "
"Failed to get spoolss pipe [%s]\n",
nt_errstr(status)));
return;
}
+ b = conn->spoolss_pipe->binding_handle;
- status = rpccli_spoolss_SetJob(cli, print_file,
+ status = dcerpc_spoolss_SetJob(b, print_file,
&print_file->handle,
print_file->jobid,
NULL, SPOOLSS_JOB_CONTROL_DELETE,
print_file->jobid, nt_errstr(status)));
return;
}
- status = rpccli_spoolss_ClosePrinter(cli, print_file,
+ status = dcerpc_spoolss_ClosePrinter(b, print_file,
&print_file->handle,
&werr);
if (!NT_STATUS_IS_OK(status) ||