*/
#include "includes.h"
+#include "system/filesys.h"
#include "printing.h"
#include "rpc_client/rpc_client.h"
#include "../librpc/gen_ndr/ndr_spoolss_c.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 dcerpc_binding_handle *b = NULL;
struct spoolss_DevmodeContainer devmode_ctr;
- union spoolss_DocumentInfo info;
+ struct spoolss_DocumentInfoCtr info_ctr;
+ struct spoolss_DocumentInfo1 *info1;
int fd = -1;
WERROR werr;
+ mode_t mask;
tmp_ctx = talloc_new(fsp);
if (!tmp_ctx) {
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;
goto done;
}
errno = 0;
+ mask = umask(S_IRWXO | S_IRWXG);
fd = mkstemp(pf->filename);
+ umask(mask);
if (fd == -1) {
if (errno == EACCES) {
/* Common setup error, force a report. */
status = dcerpc_spoolss_OpenPrinter(b, pf, pf->svcname,
"RAW", devmode_ctr,
- SEC_FLAG_MAXIMUM_ALLOWED,
+ PRINTER_ACCESS_USE,
&pf->handle, &werr);
if (!NT_STATUS_IS_OK(status)) {
goto done;
goto done;
}
- info.info1 = talloc(tmp_ctx, struct spoolss_DocumentInfo1);
- if (!info.info1) {
+ info1 = talloc(tmp_ctx, struct spoolss_DocumentInfo1);
+ if (info1 == NULL) {
status = NT_STATUS_NO_MEMORY;
goto done;
}
- info.info1->document_name = pf->docname;
- info.info1->output_file = pf->filename;
- info.info1->datatype = "RAW";
+ info1->document_name = pf->docname;
+ info1->output_file = pf->filename;
+ info1->datatype = "RAW";
+
+ info_ctr.level = 1;
+ info_ctr.info.info1 = info1;
- status = dcerpc_spoolss_StartDocPrinter(b, tmp_ctx, &pf->handle,
- 1, info, &pf->jobid, &werr);
+ status = dcerpc_spoolss_StartDocPrinter(b, tmp_ctx,
+ &pf->handle,
+ &info_ctr,
+ &pf->jobid,
+ &werr);
if (!NT_STATUS_IS_OK(status)) {
goto done;
}
}
/* setup a full fsp */
- status = create_synthetic_smb_fname(fsp, pf->filename, NULL,
- NULL, &fsp->fsp_name);
- if (!NT_STATUS_IS_OK(status)) {
+ fsp->fsp_name = synthetic_smb_fname(fsp, pf->filename, NULL, NULL);
+ if (fsp->fsp_name == NULL) {
+ status = NT_STATUS_NO_MEMORY;
goto done;
}