s3-param: Rename loadparm_s3_context -> loadparm_s3_helpers
[kai/samba.git] / source3 / printing / printspoolss.c
index 01137df7efc8a335a7a9909d184be3c743587cc2..b94314e4204f78dd8cc5aca29fbe2c70c156af2b 100644 (file)
 
 #include "includes.h"
 #include "printing.h"
+#include "rpc_client/rpc_client.h"
 #include "../librpc/gen_ndr/ndr_spoolss_c.h"
 #include "rpc_server/rpc_ncacn_np.h"
-#include "smbd/smbd.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);
 
@@ -39,7 +57,7 @@ void print_spool_terminate(struct connection_struct *conn,
 
 NTSTATUS print_spool_open(files_struct *fsp,
                          const char *fname,
-                         uint16_t current_vuid)
+                         uint64_t current_vuid)
 {
        NTSTATUS status;
        TALLOC_CTX *tmp_ctx;
@@ -82,7 +100,8 @@ NTSTATUS print_spool_open(files_struct *fsp,
                }
        }
 
-       /* 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
@@ -92,9 +111,13 @@ NTSTATUS print_spool_open(files_struct *fsp,
         * 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",
+       pf->filename = talloc_asprintf(pf, "%s/%sXXXXXX",
                                        lp_pathname(SNUM(fsp->conn)),
                                        PRINT_SPOOL_PREFIX);
        if (!pf->filename) {
@@ -127,7 +150,7 @@ NTSTATUS print_spool_open(files_struct *fsp,
        status = rpc_pipe_open_interface(fsp->conn,
                                         &ndr_table_spoolss.syntax_id,
                                         fsp->conn->session_info,
-                                        &fsp->conn->sconn->client_id,
+                                        fsp->conn->sconn->remote_address,
                                         fsp->conn->sconn->msg_ctx,
                                         &fsp->conn->spoolss_pipe);
        if (!NT_STATUS_IS_OK(status)) {
@@ -189,7 +212,6 @@ NTSTATUS print_spool_open(files_struct *fsp,
        }
 
        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;
@@ -224,7 +246,7 @@ done:
 
 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;
@@ -277,18 +299,6 @@ void print_spool_end(files_struct *fsp, enum file_close_type close_type)
        WERROR werr;
        struct dcerpc_binding_handle *b = NULL;
 
-       status = rpc_pipe_open_interface(fsp->conn,
-                                        &ndr_table_spoolss.syntax_id,
-                                        fsp->conn->session_info,
-                                        &fsp->conn->sconn->client_id,
-                                        fsp->conn->sconn->msg_ctx,
-                                        &fsp->conn->spoolss_pipe);
-       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) {
@@ -323,7 +333,7 @@ void print_spool_terminate(struct connection_struct *conn,
        status = rpc_pipe_open_interface(conn,
                                         &ndr_table_spoolss.syntax_id,
                                         conn->session_info,
-                                        &conn->sconn->client_id,
+                                        conn->sconn->remote_address,
                                         conn->sconn->msg_ctx,
                                         &conn->spoolss_pipe);
        if (!NT_STATUS_IS_OK(status)) {