summaryrefslogtreecommitdiffstats
path: root/source/printing
diff options
context:
space:
mode:
Diffstat (limited to 'source/printing')
-rw-r--r--source/printing/pcap.c23
-rw-r--r--source/printing/print_svid.c17
-rw-r--r--source/printing/printing.c174
3 files changed, 115 insertions, 99 deletions
diff --git a/source/printing/pcap.c b/source/printing/pcap.c
index 242406c9748..62010706bb3 100644
--- a/source/printing/pcap.c
+++ b/source/printing/pcap.c
@@ -9,6 +9,8 @@
Re-written again by Andrew Tridgell
Modified for SVID support by Norm Jacobs, 1997
+
+ Modified for CUPS support by Michael Sweet, 1999
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -54,6 +56,9 @@
*
* Modified to call SVID/XPG4 support if printcap name is set to "lpstat"
* in smb.conf under Solaris.
+ *
+ * Modified to call CUPS support if printcap name is set to "cups"
+ * in smb.conf.
*/
#include "includes.h"
@@ -69,7 +74,7 @@ extern int DEBUGLEVEL;
****************************************** */
static int strlocate(char *xpLine,char *xpS)
{
- int iS,iL,i,iRet;
+ int iS,iL,iRet;
char *p;
iS = strlen(xpS);
iL = strlen(xpLine);
@@ -91,9 +96,9 @@ static int strlocate(char *xpLine,char *xpS)
/* ******************************************************************* */
/* * Scan qconfig and search all virtual printer (device printer) * */
/* ******************************************************************* */
-static void ScanQconfig_fn(char *psz,void (*fn)())
+static void ScanQconfig_fn(char *psz,void (*fn)(char *, char *))
{
- int iLg,iEtat;
+ int iEtat;
FILE *pfile;
char *line,*p;
pstring name,comment;
@@ -262,6 +267,11 @@ BOOL pcap_printername_ok(char *pszPrintername, char *pszPrintcapname)
return(False);
}
+#ifdef HAVE_LIBCUPS
+ if (strequal(psz, "cups"))
+ return (cups_printername_ok(pszPrintername));
+#endif /* HAVE_LIBCUPS */
+
#ifdef SYSV
if (strequal(psz, "lpstat"))
return (sysv_printername_ok(pszPrintername));
@@ -329,6 +339,13 @@ void pcap_printer_fn(void (*fn)(char *, char *))
return;
}
+#ifdef HAVE_LIBCUPS
+ if (strequal(psz, "cups")) {
+ cups_printer_fn(fn);
+ return;
+ }
+#endif /* HAVE_LIBCUPS */
+
#ifdef SYSV
if (strequal(psz, "lpstat")) {
sysv_printer_fn(fn);
diff --git a/source/printing/print_svid.c b/source/printing/print_svid.c
index 5c5eebeb502..85eaf8f95dd 100644
--- a/source/printing/print_svid.c
+++ b/source/printing/print_svid.c
@@ -60,7 +60,17 @@ static void populate_printers(void)
if (((tmp = strchr(buf, ' ')) == NULL) ||
((tmp = strchr(++tmp, ' ')) == NULL))
continue;
- name = ++tmp;
+
+ /*
+ * In case we're only at the "for ".
+ */
+
+ if(!strncmp("for ",++tmp,4))
+ {
+ tmp=strchr(tmp, ' ');
+ tmp++;
+ }
+ name = tmp;
/* truncate the ": ..." */
if ((tmp = strchr(name, ':')) != NULL)
@@ -69,9 +79,12 @@ static void populate_printers(void)
/* add it to the cache */
if ((ptmp = malloc(sizeof (*ptmp))) != NULL) {
ZERO_STRUCTP(ptmp);
- ptmp->name = strdup(name);
+ if((ptmp->name = strdup(name)) == NULL)
+ DEBUG(0,("populate_printers: malloc fail in strdup !\n"));
ptmp->next = printers;
printers = ptmp;
+ } else {
+ DEBUG(0,("populate_printers: malloc fail for ptmp\n"));
}
}
pclose(fp);
diff --git a/source/printing/printing.c b/source/printing/printing.c
index e1fb53f40dc..134a5946300 100644
--- a/source/printing/printing.c
+++ b/source/printing/printing.c
@@ -49,12 +49,12 @@ Build the print command in the supplied buffer. This means getting the
print command for the service and inserting the printer name and the
print file name. Return NULL on error, else the passed buffer pointer.
****************************************************************************/
-static char *build_print_command(connection_struct *conn, int snum,
+static char *build_print_command(connection_struct *conn,
char *command,
- char *syscmd, char *filename1)
+ char *syscmd, char *filename)
{
+ int snum = SNUM(conn);
char *tstr;
- pstring filename;
/* get the print command for the service. */
tstr = command;
@@ -72,13 +72,8 @@ static char *build_print_command(connection_struct *conn, int snum,
DEBUG(2,("WARNING! No placeholder for the filename in the print command for service %s!\n", SERVICE(snum)));
}
- if (strstr(syscmd,"%s")) {
- pstrcpy(filename,filename1);
-
- string_sub(syscmd, "%s", filename);
- }
-
- string_sub(syscmd, "%f", filename1);
+ pstring_sub(syscmd, "%s", filename);
+ pstring_sub(syscmd, "%f", filename);
/* Does the service have a printername? If not, make a fake
and empty */
@@ -90,17 +85,10 @@ static char *build_print_command(connection_struct *conn, int snum,
tstr = SERVICE(snum);
}
- string_sub(syscmd, "%p", tstr);
+ pstring_sub(syscmd, "%p", tstr);
+
+ standard_sub(conn,syscmd);
- if (conn != NULL)
- {
- standard_sub(conn, syscmd);
- }
- else
- {
- standard_sub_basic(syscmd);
- }
-
return (syscmd);
}
@@ -108,9 +96,10 @@ static char *build_print_command(connection_struct *conn, int snum,
/****************************************************************************
print a file - called on closing the file
****************************************************************************/
-void print_file(connection_struct *conn, int snum, files_struct *file)
+void print_file(connection_struct *conn, files_struct *file)
{
pstring syscmd;
+ int snum = SNUM(conn);
char *tempstr;
*syscmd = 0;
@@ -121,7 +110,7 @@ void print_file(connection_struct *conn, int snum, files_struct *file)
return;
}
- tempstr = build_print_command(conn, snum,
+ tempstr = build_print_command(conn,
PRINTCOMMAND(snum),
syscmd, file->fsp_name);
if (tempstr != NULL) {
@@ -252,7 +241,7 @@ static BOOL parse_lpq_bsd(char *line,print_queue_struct *buf,BOOL first)
return(False);
/* the Job and Total columns must be integer */
- if (!isdigit(*tok[JOBTOK]) || !isdigit(*tok[TOTALTOK])) return(False);
+ if (!isdigit((int)*tok[JOBTOK]) || !isdigit((int)*tok[TOTALTOK])) return(False);
buf->job = atoi(tok[JOBTOK]);
buf->size = atoi(tok[TOTALTOK]);
@@ -275,6 +264,8 @@ static BOOL parse_lpq_bsd(char *line,print_queue_struct *buf,BOOL first)
break;
}
}
+ /* Ensure null termination. */
+ buf->file[sizeof(buf->file)-1] = '\0';
}
#ifdef PRIOTOK
@@ -345,7 +336,7 @@ static BOOL parse_lpq_lprng(char *line,print_queue_struct *buf,BOOL first)
return(False);
}
- if (!isdigit(*tokarr[LPRNG_JOBTOK]) || !isdigit(*tokarr[LPRNG_TOTALTOK])) {
+ if (!isdigit((int)*tokarr[LPRNG_JOBTOK]) || !isdigit((int)*tokarr[LPRNG_TOTALTOK])) {
return(False);
}
@@ -354,7 +345,7 @@ static BOOL parse_lpq_lprng(char *line,print_queue_struct *buf,BOOL first)
if (strequal(tokarr[LPRNG_RANKTOK],"active")) {
buf->status = LPQ_PRINTING;
- } else if (isdigit(*tokarr[LPRNG_RANKTOK])) {
+ } else if (isdigit((int)*tokarr[LPRNG_RANKTOK])) {
buf->status = LPQ_QUEUED;
} else {
buf->status = LPQ_PAUSED;
@@ -390,6 +381,8 @@ static BOOL parse_lpq_lprng(char *line,print_queue_struct *buf,BOOL first)
break;
}
}
+ /* Ensure null termination. */
+ buf->file[sizeof(buf->file)-1] = '\0';
}
return(True);
@@ -415,9 +408,9 @@ static BOOL parse_lpq_aix(char *line,print_queue_struct *buf,BOOL first)
int count=0;
/* handle the case of "(standard input)" as a filename */
- string_sub(line,"standard input","STDIN");
- all_string_sub(line,"(","\"");
- all_string_sub(line,")","\"");
+ pstring_sub(line,"standard input","STDIN");
+ all_string_sub(line,"(","\"",0);
+ all_string_sub(line,")","\"",0);
for (count=0;
count<10 &&
@@ -532,9 +525,9 @@ static BOOL parse_lpq_hpux(char * line, print_queue_struct *buf, BOOL first)
}
if (!header_line_ok) return (False); /* incorrect header line */
/* handle the case of "(standard input)" as a filename */
- string_sub(line,"standard input","STDIN");
- all_string_sub(line,"(","\"");
- all_string_sub(line,")","\"");
+ pstring_sub(line,"standard input","STDIN");
+ all_string_sub(line,"(","\"",0);
+ all_string_sub(line,")","\"",0);
for (count=0; count<2 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ;
/* we must get 2 tokens */
@@ -570,7 +563,7 @@ static BOOL parse_lpq_hpux(char * line, print_queue_struct *buf, BOOL first)
else if (base_prio) base_prio_reset=False;
/* handle the dash in the job id */
- string_sub(line,"-"," ");
+ pstring_sub(line,"-"," ");
for (count=0; count<12 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ;
@@ -605,7 +598,7 @@ static BOOL parse_lpq_hpux(char * line, print_queue_struct *buf, BOOL first)
/****************************************************************************
-parse a lpq line
+parse a lpstat line
here is an example of "lpstat -o dcslw" output under sysv
@@ -619,27 +612,47 @@ static BOOL parse_lpq_sysv(char *line,print_queue_struct *buf,BOOL first)
int count=0;
char *p;
- /* handle the dash in the job id */
- string_sub(line,"-"," ");
-
- for (count=0; count<9 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ;
+ /*
+ * Handle the dash in the job id, but make sure that we skip over
+ * the printer name in case we have a dash in that.
+ * Patch from Dom.Mitchell@palmerharvey.co.uk.
+ */
+
+ /*
+ * Move to the first space.
+ */
+ for (p = line ; !isspace(*p) && *p; p++)
+ ;
+
+ /*
+ * Back up until the last '-' character or
+ * start of line.
+ */
+ for (; (p >= line) && (*p != '-'); p--)
+ ;
+
+ if((p >= line) && (*p == '-'))
+ *p = ' ';
+
+ for (count=0; count<9 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++)
+ ;
/* we must get 7 tokens */
if (count < 7)
return(False);
/* the 2nd and 4th, 6th columns must be integer */
- if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[3])) return(False);
- if (!isdigit((int)*tok[5])) return(False);
+ if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[3]))
+ return(False);
+ if (!isdigit((int)*tok[5]))
+ return(False);
/* if the user contains a ! then trim the first part of it */
- if ((p=strchr(tok[2],'!')))
- {
+ if ((p=strchr(tok[2],'!'))) {
fstring tmp;
fstrcpy(tmp,p+1);
fstrcpy(tok[2],tmp);
- }
-
+ }
buf->job = atoi(tok[1]);
buf->size = atoi(tok[3]);
@@ -674,14 +687,14 @@ static BOOL parse_lpq_qnx(char *line,print_queue_struct *buf,BOOL first)
DEBUG(4,("antes [%s]\n", line));
/* handle the case of "-- standard input --" as a filename */
- string_sub(line,"standard input","STDIN");
+ pstring_sub(line,"standard input","STDIN");
DEBUG(4,("despues [%s]\n", line));
- all_string_sub(line,"-- ","\"");
- all_string_sub(line," --","\"");
+ all_string_sub(line,"-- ","\"",0);
+ all_string_sub(line," --","\"",0);
DEBUG(4,("despues 1 [%s]\n", line));
- string_sub(line,"[job #","");
- string_sub(line,"]","");
+ pstring_sub(line,"[job #","");
+ pstring_sub(line,"]","");
DEBUG(4,("despues 2 [%s]\n", line));
@@ -737,9 +750,9 @@ static BOOL parse_lpq_plp(char *line,print_queue_struct *buf,BOOL first)
int count=0;
/* handle the case of "(standard input)" as a filename */
- string_sub(line,"stdin","STDIN");
- all_string_sub(line,"(","\"");
- all_string_sub(line,")","\"");
+ pstring_sub(line,"stdin","STDIN");
+ all_string_sub(line,"(","\"",0);
+ all_string_sub(line,")","\"",0);
for (count=0; count<11 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ;
@@ -807,7 +820,7 @@ static BOOL parse_lpq_softq(char *line,print_queue_struct *buf,BOOL first)
int count=0;
/* mung all the ":"s to spaces*/
- string_sub(line,":"," ");
+ pstring_sub(line,":"," ");
for (count=0; count<10 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ;
@@ -851,8 +864,8 @@ static BOOL parse_lpq_softq(char *line,print_queue_struct *buf,BOOL first)
t->tm_mon = atoi(tok[count+2]+3);
switch (*tok[count+2])
{
- case 7: case 8: case 9: t->tm_year = atoi(tok[count+2]) + 1900; break;
- default: t->tm_year = atoi(tok[count+2]) + 2000; break;
+ case 7: case 8: case 9: t->tm_year = atoi(tok[count+2]); break;
+ default: t->tm_year = atoi(tok[count+2]); break;
}
t->tm_hour = atoi(tok[count+3]);
@@ -964,7 +977,8 @@ static BOOL parse_lpq_entry(int snum,char *line,
/****************************************************************************
get a printer queue
****************************************************************************/
-int get_printqueue(int snum, connection_struct *conn, print_queue_struct **queue,
+int get_printqueue(int snum,
+ connection_struct *conn,print_queue_struct **queue,
print_status_struct *status)
{
char *lpq_command = lp_lpqcommand(snum);
@@ -993,16 +1007,9 @@ int get_printqueue(int snum, connection_struct *conn, print_queue_struct **queue
}
pstrcpy(syscmd,lpq_command);
- string_sub(syscmd,"%p",printername);
+ pstring_sub(syscmd,"%p",printername);
- if (conn != NULL)
- {
- standard_sub(conn, syscmd);
- }
- else
- {
- standard_sub_basic(syscmd);
- }
+ standard_sub(conn,syscmd);
slprintf(outfile,sizeof(outfile)-1, "%s/lpq.%08x",tmpdir(),str_checksum(syscmd));
@@ -1039,7 +1046,7 @@ int get_printqueue(int snum, connection_struct *conn, print_queue_struct **queue
break;
}
- bzero((char *)&(*queue)[count],sizeof(**queue));
+ memset((char *)&(*queue)[count],'\0',sizeof(**queue));
/* parse it */
if (!parse_lpq_entry(snum,line,
@@ -1089,16 +1096,9 @@ void del_printqueue(connection_struct *conn,int snum,int jobid)
slprintf(jobstr,sizeof(jobstr)-1,"%d",jobid);
pstrcpy(syscmd,lprm_command);
- string_sub(syscmd,"%p",printername);
- string_sub(syscmd,"%j",jobstr);
- if (conn != NULL)
- {
- standard_sub(conn, syscmd);
- }
- else
- {
- standard_sub_basic(syscmd);
- }
+ pstring_sub(syscmd,"%p",printername);
+ pstring_sub(syscmd,"%j",jobstr);
+ standard_sub(conn,syscmd);
ret = smbrun(syscmd,NULL,False);
DEBUG(3,("Running the command `%s' gave %d\n",syscmd,ret));
@@ -1134,16 +1134,9 @@ void status_printjob(connection_struct *conn,int snum,int jobid,int status)
slprintf(jobstr,sizeof(jobstr)-1,"%d",jobid);
pstrcpy(syscmd,lpstatus_command);
- string_sub(syscmd,"%p",printername);
- string_sub(syscmd,"%j",jobstr);
- if (conn != NULL)
- {
- standard_sub(conn, syscmd);
- }
- else
- {
- standard_sub_basic(syscmd);
- }
+ pstring_sub(syscmd,"%p",printername);
+ pstring_sub(syscmd,"%j",jobstr);
+ standard_sub(conn,syscmd);
ret = smbrun(syscmd,NULL,False);
DEBUG(3,("Running the command `%s' gave %d\n",syscmd,ret));
@@ -1197,15 +1190,8 @@ void status_printqueue(connection_struct *conn,int snum,int status)
}
pstrcpy(syscmd,queuestatus_command);
- string_sub(syscmd,"%p",printername);
- if (conn != NULL)
- {
- standard_sub(conn, syscmd);
- }
- else
- {
- standard_sub_basic(syscmd);
- }
+ pstring_sub(syscmd,"%p",printername);
+ standard_sub(conn,syscmd);
ret = smbrun(syscmd,NULL,False);
DEBUG(3,("Running the command `%s' gave %d\n",syscmd,ret));