From 7a668a7641cd747455b7a9854dbc208a3e4bc7ef Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 3 Dec 1997 05:08:07 +0000 Subject: applied a patch from Norm Jacobs to allow "printcap name = lpstat" 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) --- source3/printing/print_svid.c | 121 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 source3/printing/print_svid.c (limited to 'source3/printing/print_svid.c') diff --git a/source3/printing/print_svid.c b/source3/printing/print_svid.c new file mode 100644 index 0000000000..5b98036e08 --- /dev/null +++ b/source3/printing/print_svid.c @@ -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 -- cgit