applied a patch from Norm Jacobs to allow "printcap name = lpstat"
authorAndrew Tridgell <tridge@samba.org>
Wed, 3 Dec 1997 05:08:07 +0000 (05:08 +0000)
committerAndrew Tridgell <tridge@samba.org>
Wed, 3 Dec 1997 05:08:07 +0000 (05:08 +0000)
to use lpstat to obtain the printer list on systemV systems.

I've now made this the default on all SYSV systems.

Jeremy, you were a little worried about the security of this patch. I
believe it's OK as the user has no control over the options given to
popen() and the pipe is only open for reading.
(This used to be commit 6a83de0ae954bb18d3f15382f2b0b3259fedff09)

docs/manpages/smb.conf.5
examples/smb.conf.default
source3/include/local.h
source3/param/loadparm.c
source3/printing/pcap.c
source3/printing/print_svid.c [new file with mode: 0644]

index 147b3dce9f40c5619503bb2ef32ace621d31fcbd..8937fe74ebb3c43cbdb18f54faf93dced917903f 100644 (file)
@@ -210,6 +210,12 @@ could be used simply to limit access to a subset of your local printers.
 An alias, by the way, is defined as any component of the first entry of a 
 printcap record. Records are separated by newlines, components (if there are 
 more than one) are separated by vertical bar symbols ("|").
+
+NOTE: On SYSV systems which use lpstat to determine what printers are
+defined on the system you may be able to use "printcap name = lpstat" 
+to automatically obtain a list of printers. See the "printcap name"
+option for more detils.
+
 .RE
 .SH PARAMETERS
 Parameters define the specific attributes of services.
@@ -2759,9 +2765,13 @@ This parameter may be used to override the compiled-in default printcap
 name used by the server (usually /etc/printcap). See the discussion of the
 [printers] section above for reasons why you might want to do this.
 
-For those of you without a printcap (say on SysV) you can just create a
-minimal file that looks like a printcap and set "printcap name =" in
-[global] to point at it.
+On SystemV systems that use lpstat to list available printers you
+can use "printcap name = lpstat" to automatically obtain lists of
+available printers. This is the default for systems that define 
+SYSV at compile time in Samba (this includes most SystemV based
+systems). If "printcap name" is set to lpstat on these systems then
+Samba will launch "lpstat -v" and attempt to parse the output to
+obtain a printer list.
 
 A minimal printcap file would look something like this:
 
index a7949d0585c8fbea43f0ce1feef1629952f1ab7a..fba4ecca0acbf50e5ca08c9b29890fbbb263918a 100644 (file)
 
 # If you want to automatically load your printer list rather
 # than setting them up individually then you'll need this
-   printcap name = /etc/printcap
    load printers = yes
 
+# you may wish to override the location of the printcap file
+;   printcap name = /etc/printcap
+
+# on SystemV system setting printcap name to lpstat should allow
+# you to automatically obtain a printer list from the SystemV spool
+# system
+;   printcap name = lpstat
+
 # It should not be necessary to specify the print system type unless
 # it is non-standard. Currently supported print systems include:
 # bsd, sysv, plp, lprng, aix, hpux, qnx
index ca8d231dcd99ce71dda15b5d77cdb289cf639a2e..c4bdcc80d5a5ef0745af23640cddf58ac63ab405 100644 (file)
    printcap file is a quick-n-dirty way to allow dynamic access to a subset
    of available printers.
 */
+
+#ifndef PRINTCAP_NAME
+#ifdef AIX
+#define PRINTCAP_NAME "/etc/qconfig"
+#elif defined(SYSV)
+#define PRINTCAP_NAME "lpstat"
+#else
 #define PRINTCAP_NAME "/etc/printcap"
+#endif
+#endif
 
 /* this affects server level security. With this set (recommended)
    samba will do a full NetWkstaUserLogon to confirm that the client
index abb3496f4e471dfa6f9c446e7b5cd3e2bbe3c881..a8e70717b610c037d4b3826f68edb956be7aa52b 100644 (file)
@@ -64,14 +64,6 @@ extern pstring myname;
 #define GLOBAL_NAME "global"
 #endif
 
-#ifndef PRINTCAP_NAME
-#ifdef AIX
-#define PRINTCAP_NAME "/etc/qconfig"
-#else
-#define PRINTCAP_NAME "/etc/printcap"
-#endif
-#endif
-
 #ifndef PRINTERS_NAME
 #define PRINTERS_NAME "printers"
 #endif
index 65195ab1af62d2f64a5f16604b8bb31267482fee..ff0a2b54772e47d25679f25e26a36d1caeafd893 100644 (file)
@@ -7,6 +7,8 @@
    Re-working by Martin Kiff, 1994
    
    Re-written again by Andrew Tridgell
+
+   Modified for SVID support by Norm Jacobs, 1997
    
    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,6 +51,9 @@
  *  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.
  */
 
 #include "includes.h"
@@ -255,10 +260,17 @@ BOOL pcap_printername_ok(char *pszPrintername, char *pszPrintcapname)
        DEBUG(0,( "No printcap file name configured!\n"));
        return(False);
       }
+
+#ifdef SYSV
+    if (strequal(psz, "lpstat"))
+       return (sysv_printername_ok(pszPrintername));
+#endif
+
 #ifdef AIX
   if (strlocate(psz,"/qconfig") != NULL)
      return(ScanQconfig(psz,pszPrintername));
 #endif
+
   if ((pfile = fopen(psz, "r")) == NULL)
     {
       DEBUG(0,( "Unable to open printcap file %s for read!\n", psz));
@@ -292,7 +304,6 @@ BOOL pcap_printername_ok(char *pszPrintername, char *pszPrintcapname)
        }
     }
 
-
   fclose(pfile);
   return(False);
 }
@@ -317,6 +328,13 @@ void pcap_printer_fn(void (*fn)())
       return;
     }
 
+#ifdef SYSV
+    if (strequal(psz, "lpstat")) {
+      sysv_printer_fn(fn);
+      return;
+    }
+#endif
+
 #ifdef AIX
   if (strlocate(psz,"/qconfig") != NULL)
   {
@@ -324,6 +342,7 @@ void pcap_printer_fn(void (*fn)())
      return;
   }
 #endif
+
   if ((pfile = fopen(psz, "r")) == NULL)
     {
       DEBUG(0,( "Unable to open printcap file %s for read!\n", psz));
diff --git a/source3/printing/print_svid.c b/source3/printing/print_svid.c
new file mode 100644 (file)
index 0000000..5b98036
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 1997 by Norm Jacobs, Colorado Springs, Colorado, USA
+ * Copyright (C) 1997 by Sun Microsystem, Inc.
+ * All Rights Reserved
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ * This module implements support for gathering and comparing available
+ * printer information on a SVID or XPG4 compliant system.  It does this
+ * through the use of the SVID/XPG4 command "lpstat(1)".
+ *
+ * The expectations is that execution of the command "lpstat -v" will
+ * generate responses in the form of:
+ *
+ *     device for serial: /dev/term/b
+ *     system for fax: server
+ *     system for color: server (as printer chroma)
+ */
+
+
+#include "includes.h"
+#include "smb.h"
+
+#ifdef SYSV
+
+extern int DEBUGLEVEL;
+
+typedef struct printer {
+       char *name;
+       struct printer *next;
+} printer_t;
+static printer_t *printers = NULL;
+
+static void populate_printers()
+{
+       FILE *fp;
+
+       if ((fp = popen("/usr/bin/lpstat -v", "r")) != NULL) {
+               char buf[BUFSIZ];
+
+               while (fgets(buf, sizeof (buf), fp) != NULL) {
+                       printer_t *ptmp;
+                       char *name, *tmp;
+
+                       /* eat "system/device for " */
+                       if (((tmp = strchr(buf, ' ')) == NULL) ||
+                           ((tmp = strchr(++tmp, ' ')) == NULL))
+                               continue;
+                       name = tmp++;
+
+                       /* truncate the ": ..." */
+                       if ((tmp = strchr(name, ':')) != NULL)
+                               *tmp = NULL;
+
+                       /* add it to the cache */
+                       if ((ptmp = malloc(sizeof (*ptmp))) != NULL) {
+                               memset(ptmp, NULL, sizeof (*ptmp));
+                               ptmp->name = strdup(name);
+                               ptmp->next = printers;
+                               printers = ptmp;
+                       }
+               }
+               pclose(fp);
+       } else {
+               DEBUG(0,( "Unable to run lpstat!\n"));
+       }
+}
+
+
+/*
+ * provide the equivalent of pcap_printer_fn() for SVID/XPG4 conforming
+ * systems.  It was unclear why pcap_printer_fn() was tossing names longer
+ * than 8 characters.  I suspect that its a protocol limit, but amazingly
+ * names longer than 8 characters appear to work with my test
+ * clients (Win95/NT).
+ */
+void sysv_printer_fn(void (*fn)())
+{
+       printer_t *tmp;
+
+       if (printers == NULL)
+               populate_printers();
+       for (tmp = printers; tmp != NULL; tmp = tmp->next)
+               (fn)(tmp->name, "");
+}
+
+
+/*
+ * provide the equivalent of pcap_printername_ok() for SVID/XPG4 conforming
+ * systems.
+ */
+int sysv_printername_ok(char *name)
+{
+       printer_t *tmp;
+
+       if (printers == NULL)
+               populate_printers();
+       for (tmp = printers; tmp != NULL; tmp = tmp->next)
+               if (strcmp(tmp->name, name) == 0)
+                       return (True);
+       return (False);
+}
+
+#else
+/* this keeps fussy compilers happy */
+ void print_svid_dummy(void) {}
+#endif