00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "includes.h"
00022 #include "printing.h"
00023
00024 extern struct current_user current_user;
00025 extern userdom_struct current_user_info;
00026
00027
00028
00029
00030
00031
00032 static int print_run_command(int snum, const char* printername, BOOL do_sub,
00033 const char *command, int *outfd, ...)
00034 {
00035 pstring syscmd;
00036 char *arg;
00037 int ret;
00038 va_list ap;
00039 va_start(ap, outfd);
00040
00041
00042
00043 if ( !printername || !*printername )
00044 return -1;
00045
00046 if (!command || !*command)
00047 return -1;
00048
00049 pstrcpy(syscmd, command);
00050
00051 while ((arg = va_arg(ap, char *))) {
00052 char *value = va_arg(ap,char *);
00053 pstring_sub(syscmd, arg, value);
00054 }
00055 va_end(ap);
00056
00057 pstring_sub( syscmd, "%p", printername );
00058
00059 if ( do_sub && snum != -1 )
00060 standard_sub_advanced(lp_servicename(snum),
00061 current_user_info.unix_name, "",
00062 current_user.ut.gid,
00063 get_current_username(),
00064 current_user_info.domain,
00065 syscmd, sizeof(syscmd));
00066
00067 ret = smbrun_no_sanitize(syscmd,outfd);
00068
00069 DEBUG(3,("Running the command `%s' gave %d\n",syscmd,ret));
00070
00071 return ret;
00072 }
00073
00074
00075
00076
00077
00078 static int generic_job_delete( const char *sharename, const char *lprm_command, struct printjob *pjob)
00079 {
00080 fstring jobstr;
00081
00082
00083 slprintf(jobstr, sizeof(jobstr)-1, "%d", pjob->sysjob);
00084 return print_run_command( -1, sharename, False, lprm_command, NULL,
00085 "%j", jobstr,
00086 "%T", http_timestring(pjob->starttime),
00087 NULL);
00088 }
00089
00090
00091
00092
00093 static int generic_job_pause(int snum, struct printjob *pjob)
00094 {
00095 fstring jobstr;
00096
00097
00098 slprintf(jobstr, sizeof(jobstr)-1, "%d", pjob->sysjob);
00099 return print_run_command(snum, PRINTERNAME(snum), True,
00100 lp_lppausecommand(snum), NULL,
00101 "%j", jobstr,
00102 NULL);
00103 }
00104
00105
00106
00107
00108 static int generic_job_resume(int snum, struct printjob *pjob)
00109 {
00110 fstring jobstr;
00111
00112
00113 slprintf(jobstr, sizeof(jobstr)-1, "%d", pjob->sysjob);
00114 return print_run_command(snum, PRINTERNAME(snum), True,
00115 lp_lpresumecommand(snum), NULL,
00116 "%j", jobstr,
00117 NULL);
00118 }
00119
00120
00121
00122
00123
00124 static int generic_job_submit(int snum, struct printjob *pjob)
00125 {
00126 int ret;
00127 pstring current_directory;
00128 pstring print_directory;
00129 char *wd, *p;
00130 pstring jobname;
00131 fstring job_page_count, job_size;
00132
00133
00134
00135 wd = sys_getwd(current_directory);
00136 if (!wd)
00137 return 0;
00138
00139 pstrcpy(print_directory, pjob->filename);
00140 p = strrchr_m(print_directory,'/');
00141 if (!p)
00142 return 0;
00143 *p++ = 0;
00144
00145 if (chdir(print_directory) != 0)
00146 return 0;
00147
00148 pstrcpy(jobname, pjob->jobname);
00149 pstring_sub(jobname, "'", "_");
00150 slprintf(job_page_count, sizeof(job_page_count)-1, "%d", pjob->page_count);
00151 slprintf(job_size, sizeof(job_size)-1, "%lu", (unsigned long)pjob->size);
00152
00153
00154 ret = print_run_command(snum, PRINTERNAME(snum), True,
00155 lp_printcommand(snum), NULL,
00156 "%s", p,
00157 "%J", jobname,
00158 "%f", p,
00159 "%z", job_size,
00160 "%c", job_page_count,
00161 NULL);
00162
00163 chdir(wd);
00164
00165 return ret;
00166 }
00167
00168
00169
00170
00171
00172 static int generic_queue_get(const char *printer_name,
00173 enum printing_types printing_type,
00174 char *lpq_command,
00175 print_queue_struct **q,
00176 print_status_struct *status)
00177 {
00178 char **qlines;
00179 int fd;
00180 int numlines, i, qcount;
00181 print_queue_struct *queue = NULL;
00182
00183
00184
00185
00186
00187 print_run_command(-1, printer_name, False, lpq_command, &fd, NULL);
00188
00189 if (fd == -1) {
00190 DEBUG(5,("generic_queue_get: Can't read print queue status for printer %s\n",
00191 printer_name ));
00192 return 0;
00193 }
00194
00195 numlines = 0;
00196 qlines = fd_lines_load(fd, &numlines,0);
00197 close(fd);
00198
00199
00200 qcount = 0;
00201 ZERO_STRUCTP(status);
00202 if (numlines && qlines) {
00203 queue = SMB_MALLOC_ARRAY(print_queue_struct, numlines+1);
00204 if (!queue) {
00205 file_lines_free(qlines);
00206 *q = NULL;
00207 return 0;
00208 }
00209 memset(queue, '\0', sizeof(print_queue_struct)*(numlines+1));
00210
00211 for (i=0; i<numlines; i++) {
00212
00213 if (parse_lpq_entry(printing_type,qlines[i],
00214 &queue[qcount],status,qcount==0)) {
00215 qcount++;
00216 }
00217 }
00218 }
00219
00220 file_lines_free(qlines);
00221 *q = queue;
00222 return qcount;
00223 }
00224
00225
00226
00227
00228 static int generic_queue_pause(int snum)
00229 {
00230 return print_run_command(snum, PRINTERNAME(snum), True, lp_queuepausecommand(snum), NULL, NULL);
00231 }
00232
00233
00234
00235
00236 static int generic_queue_resume(int snum)
00237 {
00238 return print_run_command(snum, PRINTERNAME(snum), True, lp_queueresumecommand(snum), NULL, NULL);
00239 }
00240
00241
00242
00243
00244
00245 struct printif generic_printif =
00246 {
00247 DEFAULT_PRINTING,
00248 generic_queue_get,
00249 generic_queue_pause,
00250 generic_queue_resume,
00251 generic_job_delete,
00252 generic_job_pause,
00253 generic_job_resume,
00254 generic_job_submit,
00255 };
00256