summaryrefslogtreecommitdiff
path: root/source3/printing/pcap.c
diff options
context:
space:
mode:
Diffstat (limited to 'source3/printing/pcap.c')
-rw-r--r--source3/printing/pcap.c127
1 files changed, 82 insertions, 45 deletions
diff --git a/source3/printing/pcap.c b/source3/printing/pcap.c
index 8973b1627f..920c6f354e 100644
--- a/source3/printing/pcap.c
+++ b/source3/printing/pcap.c
@@ -1,12 +1,15 @@
/*
- Unix SMB/Netbios implementation.
- Version 1.9.
+ Unix SMB/CIFS implementation.
printcap parsing
- Copyright (C) Karl Auer 1993,1994
+ Copyright (C) Karl Auer 1993-1998
Re-working by Martin Kiff, 1994
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
@@ -49,15 +52,17 @@
* Opening a pipe for "lpc status" and reading that would probably
* be pretty effective. Code to do this already exists in the freely
* distributable PCNFS server code.
+ *
+ * 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"
#include "smb.h"
-#include "loadparm.h"
-#include "pcap.h"
-
-extern int DEBUGLEVEL;
#ifdef AIX
/* ******************************************
@@ -66,7 +71,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);
@@ -88,17 +93,17 @@ 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;
- FILE *pfile;
+ int iEtat;
+ XFILE *pfile;
char *line,*p;
pstring name,comment;
line = NULL;
*name = 0;
*comment = 0;
- if ((pfile = fopen(psz, "r")) == NULL)
+ if ((pfile = x_fopen(psz, O_RDONLY, 0)) == NULL)
{
DEBUG(0,( "Unable to open qconfig file %s for read!\n", psz));
return;
@@ -114,13 +119,13 @@ static void ScanQconfig_fn(char *psz,void (*fn)())
{
case 0: /* locate an entry */
if (*line == '\t' || *line == ' ') continue;
- if ((p=strchr(line,':')))
+ if ((p=strchr_m(line,':')))
{
*p = '\0';
p = strtok(line,":");
if (strcmp(p,"bsh")!=0)
{
- strcpy(name,p);
+ pstrcpy(name,p);
iEtat = 1;
continue;
}
@@ -152,7 +157,7 @@ static void ScanQconfig_fn(char *psz,void (*fn)())
break;
}
}
- fclose(pfile);
+ x_fclose(pfile);
}
/* Scan qconfig file and locate de printername */
@@ -160,7 +165,7 @@ static void ScanQconfig_fn(char *psz,void (*fn)())
static BOOL ScanQconfig(char *psz,char *pszPrintername)
{
int iLg,iEtat;
- FILE *pfile;
+ XFILE *pfile;
char *pName;
char *line;
@@ -173,13 +178,13 @@ static BOOL ScanQconfig(char *psz,char *pszPrintername)
DEBUG(0,(" Unable to allocate memory for printer %s\n",pszPrintername));
return(False);
}
- if ((pfile = fopen(psz, "r")) == NULL)
+ if ((pfile = x_fopen(psz, O_RDONLY, 0)) == NULL)
{
DEBUG(0,( "Unable to open qconfig file %s for read!\n", psz));
free(pName);
return(False);
}
- sprintf(pName,"%s:",pszPrintername);
+ slprintf(pName, iLg + 9, "%s:",pszPrintername);
iLg = strlen(pName);
/*DEBUG(3,( " Looking for entry %s\n",pName));*/
iEtat = 0;
@@ -226,23 +231,27 @@ static BOOL ScanQconfig(char *psz,char *pszPrintername)
}
}
free (pName);
- fclose(pfile);
+ x_fclose(pfile);
return(False);
}
+#endif /* AIX */
+
-#endif
/***************************************************************************
Scan printcap file pszPrintcapname for a printer called pszPrintername.
Return True if found, else False. Returns False on error, too, after logging
the error at level 0. For generality, the printcap name may be passed - if
-passed as NULL, the configuration will be queried for the name.
+passed as NULL, the configuration will be queried for the name. pszPrintername
+must be in DOS codepage.
+The xxx_printername_ok functions need fixing to understand they are being
+given a DOS codepage. FIXME !! JRA.
***************************************************************************/
BOOL pcap_printername_ok(char *pszPrintername, char *pszPrintcapname)
{
char *line=NULL;
char *psz;
char *p,*q;
- FILE *pfile;
+ XFILE *pfile;
if (pszPrintername == NULL || pszPrintername[0] == '\0')
{
@@ -257,11 +266,23 @@ BOOL pcap_printername_ok(char *pszPrintername, char *pszPrintcapname)
DEBUG(0,( "No printcap file name configured!\n"));
return(False);
}
+
+#ifdef HAVE_CUPS
+ if (strequal(psz, "cups"))
+ return (cups_printername_ok(pszPrintername));
+#endif /* HAVE_CUPS */
+
+#ifdef SYSV
+ if (strequal(psz, "lpstat"))
+ return (sysv_printername_ok(pszPrintername));
+#endif
+
#ifdef AIX
- if (strlocate(psz,"/qconfig") != NULL)
+ if (strlocate(psz,"/qconfig"))
return(ScanQconfig(psz,pszPrintername));
#endif
- if ((pfile = fopen(psz, "r")) == NULL)
+
+ if ((pfile = x_fopen(psz, O_RDONLY, 0)) == NULL)
{
DEBUG(0,( "Unable to open printcap file %s for read!\n", psz));
return(False);
@@ -273,44 +294,45 @@ BOOL pcap_printername_ok(char *pszPrintername, char *pszPrintcapname)
continue;
/* now we have a real printer line - cut it off at the first : */
- p = strchr(line,':');
+ p = strchr_m(line,':');
if (p) *p = 0;
/* now just check if the name is in the list */
/* NOTE: I avoid strtok as the fn calling this one may be using it */
for (p=line; p; p=q)
{
- if ((q = strchr(p,'|'))) *q++ = 0;
+ if ((q = strchr_m(p,'|'))) *q++ = 0;
if (strequal(p,pszPrintername))
{
/* normalise the case */
- strcpy(pszPrintername,p);
+ pstrcpy(pszPrintername,p);
free(line);
- fclose(pfile);
+ x_fclose(pfile);
return(True);
}
p = q;
}
}
-
- fclose(pfile);
+ x_fclose(pfile);
return(False);
}
/***************************************************************************
run a function on each printer name in the printcap file. The function is
-passed the primary name and the comment (if possible)
+passed the primary name and the comment (if possible). Note the fn() takes
+strings in DOS codepage. This means the xxx_printer_fn() calls must be fixed
+to return DOS codepage. FIXME !! JRA.
***************************************************************************/
-void pcap_printer_fn(void (*fn)())
+void pcap_printer_fn(void (*fn)(char *, char *))
{
pstring name,comment;
char *line;
char *psz;
char *p,*q;
- FILE *pfile;
+ XFILE *pfile;
/* only go looking if no printcap name supplied */
if (((psz = lp_printcapname()) == NULL) || (psz[0] == '\0'))
@@ -319,14 +341,29 @@ void pcap_printer_fn(void (*fn)())
return;
}
+#ifdef HAVE_CUPS
+ if (strequal(psz, "cups")) {
+ cups_printer_fn(fn);
+ return;
+ }
+#endif /* HAVE_CUPS */
+
+#ifdef SYSV
+ if (strequal(psz, "lpstat")) {
+ sysv_printer_fn(fn);
+ return;
+ }
+#endif
+
#ifdef AIX
- if (strlocate(psz,"/qconfig") != NULL)
+ if (strlocate(psz,"/qconfig"))
{
ScanQconfig_fn(psz,fn);
return;
}
#endif
- if ((pfile = fopen(psz, "r")) == NULL)
+
+ if ((pfile = x_fopen(psz, O_RDONLY, 0)) == NULL)
{
DEBUG(0,( "Unable to open printcap file %s for read!\n", psz));
return;
@@ -338,7 +375,7 @@ void pcap_printer_fn(void (*fn)())
continue;
/* now we have a real printer line - cut it off at the first : */
- p = strchr(line,':');
+ p = strchr_m(line,':');
if (p) *p = 0;
/* now find the most likely printer name and comment
@@ -348,9 +385,9 @@ void pcap_printer_fn(void (*fn)())
for (p=line; p; p=q)
{
BOOL has_punctuation;
- if ((q = strchr(p,'|'))) *q++ = 0;
+ if ((q = strchr_m(p,'|'))) *q++ = 0;
- has_punctuation = (strchr(p,' ') || strchr(p,'(') || strchr(p,')'));
+ has_punctuation = (strchr_m(p,' ') || strchr_m(p,'\t') || strchr_m(p,'(') || strchr_m(p,')'));
if (strlen(p)>strlen(comment) && has_punctuation)
{
@@ -358,14 +395,14 @@ void pcap_printer_fn(void (*fn)())
continue;
}
- if (strlen(p) <= 8 && strlen(p)>strlen(name) && !has_punctuation)
+ if (strlen(p) <= MAXPRINTERLEN && strlen(p)>strlen(name) && !has_punctuation)
{
- if (!*comment) strcpy(comment,name);
- strcpy(name,p);
+ if (!*comment) pstrcpy(comment,name);
+ pstrcpy(name,p);
continue;
}
- if (!strchr(comment,' ') &&
+ if (!strchr_m(comment,' ') &&
strlen(p) > strlen(comment))
{
StrnCpy(comment,p,sizeof(comment)-1);
@@ -374,10 +411,10 @@ void pcap_printer_fn(void (*fn)())
}
comment[60] = 0;
- name[8] = 0;
+ name[MAXPRINTERLEN] = 0;
- if (*name)
+ if (*name)
fn(name,comment);
}
- fclose(pfile);
+ x_fclose(pfile);
}