s3-printing: pass lpq command to job_submit
[ddiss/samba.git] / source3 / printing / print_generic.c
index cc4b744a11c07ac1a32af1d8cd1a1ed5c41710a8..3211705b8ec28c19b8e479f54348e2dfeb581917 100644 (file)
@@ -41,15 +41,18 @@ static int print_run_command(int snum, const char* printername, bool do_sub,
        /* check for a valid system printername and valid command to run */
 
        if ( !printername || !*printername ) {
+               va_end(ap);
                return -1;
        }
 
        if (!command || !*command) {
+               va_end(ap);
                return -1;
        }
 
        syscmd = talloc_strdup(ctx, command);
        if (!syscmd) {
+               va_end(ap);
                return -1;
        }
 
@@ -57,6 +60,7 @@ static int print_run_command(int snum, const char* printername, bool do_sub,
                char *value = va_arg(ap,char *);
                syscmd = talloc_string_sub(ctx, syscmd, arg, value);
                if (!syscmd) {
+                       va_end(ap);
                        return -1;
                }
        }
@@ -100,7 +104,7 @@ static int generic_job_delete( const char *sharename, const char *lprm_command,
        slprintf(jobstr, sizeof(jobstr)-1, "%d", pjob->sysjob);
        return print_run_command( -1, sharename, False, lprm_command, NULL,
                   "%j", jobstr,
-                  "%T", http_timestring(pjob->starttime),
+                  "%T", http_timestring(talloc_tos(), pjob->starttime),
                   NULL);
 }
 
@@ -113,7 +117,7 @@ static int generic_job_pause(int snum, struct printjob *pjob)
        
        /* need to pause the spooled entry */
        slprintf(jobstr, sizeof(jobstr)-1, "%d", pjob->sysjob);
-       return print_run_command(snum, PRINTERNAME(snum), True,
+       return print_run_command(snum, lp_printername(snum), True,
                                 lp_lppausecommand(snum), NULL,
                                 "%j", jobstr,
                                 NULL);
@@ -128,7 +132,7 @@ static int generic_job_resume(int snum, struct printjob *pjob)
 
        /* need to pause the spooled entry */
        slprintf(jobstr, sizeof(jobstr)-1, "%d", pjob->sysjob);
-       return print_run_command(snum, PRINTERNAME(snum), True,
+       return print_run_command(snum, lp_printername(snum), True,
                                 lp_lpresumecommand(snum), NULL,
                                 "%j", jobstr,
                                 NULL);
@@ -138,7 +142,9 @@ static int generic_job_resume(int snum, struct printjob *pjob)
  Submit a file for printing - called from print_job_end()
 ****************************************************************************/
 
-static int generic_job_submit(int snum, struct printjob *pjob)
+static int generic_job_submit(int snum, struct printjob *pjob,
+                             enum printing_types printing_type,
+                             char *lpq_cmd)
 {
        int ret = -1;
        char *current_directory = NULL;
@@ -151,17 +157,17 @@ static int generic_job_submit(int snum, struct printjob *pjob)
 
        /* we print from the directory path to give the best chance of
            parsing the lpq output */
-       current_directory = TALLOC_ARRAY(ctx,
-                                       char,
-                                       PATH_MAX+1);
-       if (!current_directory) {
-               return -1;
-       }
-       wd = sys_getwd(current_directory);
+       wd = sys_getwd();
        if (!wd) {
                return -1;
        }
 
+       current_directory = talloc_strdup(ctx, wd);
+       SAFE_FREE(wd);
+
+       if (!current_directory) {
+               return -1;
+       }
        print_directory = talloc_strdup(ctx, pjob->filename);
        if (!print_directory) {
                return -1;
@@ -190,7 +196,7 @@ static int generic_job_submit(int snum, struct printjob *pjob)
        slprintf(job_size, sizeof(job_size)-1, "%lu", (unsigned long)pjob->size);
 
        /* send it to the system spooler */
-       ret = print_run_command(snum, PRINTERNAME(snum), True,
+       ret = print_run_command(snum, lp_printername(snum), True,
                        lp_printcommand(snum), NULL,
                        "%s", p,
                        "%J", jobname,
@@ -201,7 +207,9 @@ static int generic_job_submit(int snum, struct printjob *pjob)
 
  out:
 
-       chdir(wd);
+       if (chdir(current_directory) == -1) {
+               smb_panic("chdir failed in generic_job_submit");
+       }
        TALLOC_FREE(current_directory);
         return ret;
 }
@@ -234,7 +242,7 @@ static int generic_queue_get(const char *printer_name,
        }
        
        numlines = 0;
-       qlines = fd_lines_load(fd, &numlines,0);
+       qlines = fd_lines_load(fd, &numlines,0,NULL);
        close(fd);
 
        /* turn the lpq output into a series of job structures */
@@ -243,7 +251,7 @@ static int generic_queue_get(const char *printer_name,
        if (numlines && qlines) {
                queue = SMB_MALLOC_ARRAY(print_queue_struct, numlines+1);
                if (!queue) {
-                       file_lines_free(qlines);
+                       TALLOC_FREE(qlines);
                        *q = NULL;
                        return 0;
                }
@@ -258,7 +266,7 @@ static int generic_queue_get(const char *printer_name,
                }               
        }
 
-       file_lines_free(qlines);
+       TALLOC_FREE(qlines);
         *q = queue;
        return qcount;
 }
@@ -268,7 +276,8 @@ static int generic_queue_get(const char *printer_name,
 ****************************************************************************/
 static int generic_queue_pause(int snum)
 {
-       return print_run_command(snum, PRINTERNAME(snum), True, lp_queuepausecommand(snum), NULL, NULL);
+       return print_run_command(snum, lp_printername(snum), True,
+                                lp_queuepausecommand(snum), NULL, NULL);
 }
 
 /****************************************************************************
@@ -276,7 +285,8 @@ static int generic_queue_pause(int snum)
 ****************************************************************************/
 static int generic_queue_resume(int snum)
 {
-       return print_run_command(snum, PRINTERNAME(snum), True, lp_queueresumecommand(snum), NULL, NULL);
+       return print_run_command(snum, lp_printername(snum), True,
+                                lp_queueresumecommand(snum), NULL, NULL);
 }
 
 /****************************************************************************