Unix SMB/Netbios implementation.
Version 1.9.
printcap parsing
- Copyright (C) Karl Auer 1993-1997
+ 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
* 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"
****************************************** */
static int strlocate(char *xpLine,char *xpS)
{
- int iS,iL,i,iRet;
+ int iS,iL,iRet;
char *p;
iS = strlen(xpS);
iL = strlen(xpLine);
/* ******************************************************************* */
/* * 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;
*name = 0;
*comment = 0;
- if ((pfile = fopen(psz, "r")) == NULL)
+ if ((pfile = sys_fopen(psz, "r")) == NULL)
{
DEBUG(0,( "Unable to open qconfig file %s for read!\n", psz));
return;
p = strtok(line,":");
if (strcmp(p,"bsh")!=0)
{
- strcpy(name,p);
+ pstrcpy(name,p);
iEtat = 1;
continue;
}
DEBUG(0,(" Unable to allocate memory for printer %s\n",pszPrintername));
return(False);
}
- if ((pfile = fopen(psz, "r")) == NULL)
+ if ((pfile = sys_fopen(psz, "r")) == 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;
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
DEBUG(0,( "No printcap file name configured!\n"));
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));
+#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 = sys_fopen(psz, "r")) == NULL)
{
DEBUG(0,( "Unable to open printcap file %s for read!\n", psz));
return(False);
if (strequal(p,pszPrintername))
{
/* normalise the case */
- strcpy(pszPrintername,p);
+ pstrcpy(pszPrintername,p);
free(line);
fclose(pfile);
return(True);
}
}
-
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)
***************************************************************************/
-void pcap_printer_fn(void (*fn)())
+void pcap_printer_fn(void (*fn)(char *, char *))
{
pstring name,comment;
char *line;
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);
+ 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 = sys_fopen(psz, "r")) == NULL)
{
DEBUG(0,( "Unable to open printcap file %s for read!\n", psz));
return;
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;
}
}
comment[60] = 0;
- name[8] = 0;
+ name[MAXPRINTERLEN] = 0;
if (*name)
fn(name,comment);