| 1 | /*
|
|---|
| 2 | * Copyright (C) 1997-1998 by Norm Jacobs, Colorado Springs, Colorado, USA
|
|---|
| 3 | * Copyright (C) 1997-1998 by Sun Microsystem, Inc.
|
|---|
| 4 | * All Rights Reserved
|
|---|
| 5 | *
|
|---|
| 6 | * This program is free software; you can redistribute it and/or modify
|
|---|
| 7 | * it under the terms of the GNU General Public License as published by
|
|---|
| 8 | * the Free Software Foundation; either version 3 of the License, or
|
|---|
| 9 | * (at your option) any later version.
|
|---|
| 10 | *
|
|---|
| 11 | * This program is distributed in the hope that it will be useful,
|
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 14 | * GNU General Public License for more details.
|
|---|
| 15 | *
|
|---|
| 16 | * You should have received a copy of the GNU General Public License
|
|---|
| 17 | * along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|---|
| 18 | */
|
|---|
| 19 |
|
|---|
| 20 | /*
|
|---|
| 21 | * This module implements support for gathering and comparing available
|
|---|
| 22 | * printer information on a SVID or XPG4 compliant system. It does this
|
|---|
| 23 | * through the use of the SVID/XPG4 command "lpstat(1)".
|
|---|
| 24 | *
|
|---|
| 25 | * The expectations is that execution of the command "lpstat -v" will
|
|---|
| 26 | * generate responses in the form of:
|
|---|
| 27 | *
|
|---|
| 28 | * device for serial: /dev/term/b
|
|---|
| 29 | * system for fax: server
|
|---|
| 30 | * system for color: server (as printer chroma)
|
|---|
| 31 | */
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 | #include "includes.h"
|
|---|
| 35 |
|
|---|
| 36 | #if defined(SYSV) || defined(HPUX)
|
|---|
| 37 | bool sysv_cache_reload(void)
|
|---|
| 38 | {
|
|---|
| 39 | char **lines;
|
|---|
| 40 | int i;
|
|---|
| 41 |
|
|---|
| 42 | #if defined(HPUX)
|
|---|
| 43 | DEBUG(5, ("reloading hpux printcap cache\n"));
|
|---|
| 44 | #else
|
|---|
| 45 | DEBUG(5, ("reloading sysv printcap cache\n"));
|
|---|
| 46 | #endif
|
|---|
| 47 |
|
|---|
| 48 | if ((lines = file_lines_pload("/usr/bin/lpstat -v", NULL)) == NULL)
|
|---|
| 49 | {
|
|---|
| 50 | #if defined(HPUX)
|
|---|
| 51 |
|
|---|
| 52 | /*
|
|---|
| 53 | * if "lpstat -v" is NULL then we check if schedular is running if it is
|
|---|
| 54 | * that means no printers are added on the HP-UX system, if schedular is not
|
|---|
| 55 | * running we display reload error.
|
|---|
| 56 | */
|
|---|
| 57 |
|
|---|
| 58 | char **scheduler;
|
|---|
| 59 | scheduler = file_lines_pload("/usr/bin/lpstat -r", NULL);
|
|---|
| 60 | if(!strcmp(*scheduler,"scheduler is running")){
|
|---|
| 61 | DEBUG(3,("No Printers found!!!\n"));
|
|---|
| 62 | TALLOC_FREE(scheduler);
|
|---|
| 63 | return True;
|
|---|
| 64 | }
|
|---|
| 65 | else{
|
|---|
| 66 | DEBUG(3,("Scheduler is not running!!!\n"));
|
|---|
| 67 | TALLOC_FREE(scheduler);
|
|---|
| 68 | return False;
|
|---|
| 69 | }
|
|---|
| 70 | #else
|
|---|
| 71 | DEBUG(3,("No Printers found!!!\n"));
|
|---|
| 72 | return False;
|
|---|
| 73 | #endif
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | for (i = 0; lines[i]; i++) {
|
|---|
| 77 | char *name, *tmp;
|
|---|
| 78 | char *buf = lines[i];
|
|---|
| 79 |
|
|---|
| 80 | /* eat "system/device for " */
|
|---|
| 81 | if (((tmp = strchr_m(buf, ' ')) == NULL) ||
|
|---|
| 82 | ((tmp = strchr_m(++tmp, ' ')) == NULL))
|
|---|
| 83 | continue;
|
|---|
| 84 |
|
|---|
| 85 | /*
|
|---|
| 86 | * In case we're only at the "for ".
|
|---|
| 87 | */
|
|---|
| 88 |
|
|---|
| 89 | if(!strncmp("for ", ++tmp, 4)) {
|
|---|
| 90 | tmp=strchr_m(tmp, ' ');
|
|---|
| 91 | tmp++;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | /* Eat whitespace. */
|
|---|
| 95 |
|
|---|
| 96 | while(*tmp == ' ')
|
|---|
| 97 | ++tmp;
|
|---|
| 98 |
|
|---|
| 99 | /*
|
|---|
| 100 | * On HPUX there is an extra line that can be ignored.
|
|---|
| 101 | * d.thibadeau 2001/08/09
|
|---|
| 102 | */
|
|---|
| 103 | if(!strncmp("remote to", tmp, 9))
|
|---|
| 104 | continue;
|
|---|
| 105 |
|
|---|
| 106 | name = tmp;
|
|---|
| 107 |
|
|---|
| 108 | /* truncate the ": ..." */
|
|---|
| 109 | if ((tmp = strchr_m(name, ':')) != NULL)
|
|---|
| 110 | *tmp = '\0';
|
|---|
| 111 |
|
|---|
| 112 | /* add it to the cache */
|
|---|
| 113 | if (!pcap_cache_add(name, NULL)) {
|
|---|
| 114 | TALLOC_FREE(lines);
|
|---|
| 115 | return False;
|
|---|
| 116 | }
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | TALLOC_FREE(lines);
|
|---|
| 120 | return True;
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | #else
|
|---|
| 124 | /* this keeps fussy compilers happy */
|
|---|
| 125 | void print_svid_dummy(void);
|
|---|
| 126 | void print_svid_dummy(void) {}
|
|---|
| 127 | #endif
|
|---|