From 200545fb5b96f63266e1b27195edd02217592671 Mon Sep 17 00:00:00 2001 From: zacheiss Date: Tue, 21 Jul 2009 21:39:12 +0000 Subject: [PATCH] cups-lpd DCM. --- gen/Makefile.in | 11 ++- gen/cups-lpd.pc | 199 ++++++++++++++++++++++++++++++++++++++++++++++ gen/cups-lpd.sh | 49 ++++++++++++ gen/cups-print.pc | 9 +-- 4 files changed, 259 insertions(+), 9 deletions(-) create mode 100644 gen/cups-lpd.pc create mode 100755 gen/cups-lpd.sh diff --git a/gen/Makefile.in b/gen/Makefile.in index 0171a433..f48d3907 100644 --- a/gen/Makefile.in +++ b/gen/Makefile.in @@ -32,21 +32,21 @@ LIB_OBJS=util.o tar.o genacl.o LIB_CFILES=genacl.c LIB_TARGET=libdcm.a -OBJS= acl.lo boot.lo confluence.lo cups-print.lo dhcp.lo directory.lo events.lo \ +OBJS= acl.lo boot.lo confluence.lo cups-print.lo cups-lpd.lo dhcp.lo directory.lo events.lo \ hesiod.lo hosts.lo lpcaccess.lo mailhub.lo ndb.lo network.lo nfs.lo pobox.lo \ postoffice.lo print.lo warehouse-lists.lo winad.lo www.lo zephyr.lo -CFILES= acl.c boot.c confluence.c cups-print.c dhcp.c directory.c events.c \ +CFILES= acl.c boot.c confluence.c cups-print.c cups-lpd.c dhcp.c directory.c events.c \ hesiod.c hosts.c lpcaccess.c mailhub.c ndb.c network.c nfs.c pobox.c \ postoffice.c print.c warehouse-lists.c winad.c www.c zephyr.c -TARGET= acl.gen boot.gen confluence.gen cups-print.gen dhcp.gen directory.gen \ +TARGET= acl.gen boot.gen confluence.gen cups-print.gen cups-lpd.gen dhcp.gen directory.gen \ events.gen hesiod.gen hosts.gen lpcaccess.gen mailhub.gen ndb.gen \ network.gen nfs.gen pobox.gen postoffice.gen print.gen \ warehouse-lists.gen winad.gen www.gen zephyr.gen SCRIPTS=access.gen access.sh acl.sh aliases.sh boot.sh ca.gen calendar.gen \ - cups-print.sh dhcp.sh events.sh hesiod.sh ip-billing.gen \ + cups-print.sh cups-lpd.sh dhcp.sh events.sh hesiod.sh ip-billing.gen \ ip-billing.sh ldap.gen longjobs.gen longjobs.sh mailhosts.gen \ mailhub.sh mailman.gen mailman.sh nagios-cluster.gen \ nagios-cluster.sh nagios-colo.gen nagios-colo.sh \ @@ -150,3 +150,6 @@ warehouse-lists.gen: warehouse-lists.lo libdcm.a $(MR_LIBDEP) cups-print.gen: cups-print.lo libdcm.a $(MR_LIBDEP) $(LIBTOOL) --mode=link $(CC) -static -o $@ $(LDFLAGS) cups-print.lo libdcm.a $(SQL_LIBS) $(LIBS) + +cups-lpd.gen: cups-lpd.lo libdcm.a $(MR_LIBDEP) + $(LIBTOOL) --mode=link $(CC) -static -o $@ $(LDFLAGS) cups-lpd.lo libdcm.a $(SQL_LIBS) $(LIBS) diff --git a/gen/cups-lpd.pc b/gen/cups-lpd.pc new file mode 100644 index 00000000..5652f6a8 --- /dev/null +++ b/gen/cups-lpd.pc @@ -0,0 +1,199 @@ +/* $Id$ + * + * This generates printcaps and other files for Athena print servers + * + * Copyright (C) 1992-1998 by the Massachusetts Institute of Technology. + * For copying and distribution information, please see the file + * . + */ + +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include +#ifdef HAVE_KRB4 +#include +#endif +#include + +#include "util.h" + +EXEC SQL INCLUDE sqlca; + +RCSID("$Header$"); + +char *whoami = "cups-lpd-print.gen"; +char *db = "moira/moira"; + +/* OMG, I hate this, but it's cleaner, I guess? */ + +void do_host(char *host); +void sqlerr(void); +#ifndef MAX +#define MAX(a, b) ( (a) > (b) ? (a) : (b) ) +#endif + +int main(int argc, char **argv) +{ + EXEC SQL BEGIN DECLARE SECTION; + char name[MACHINE_NAME_SIZE]; + EXEC SQL END DECLARE SECTION; + + init_acls(); + + EXEC SQL CONNECT :db; + + EXEC SQL WHENEVER SQLERROR DO sqlerr(); + + EXEC SQL DECLARE csr_hosts CURSOR FOR + SELECT m.name FROM machine m, serverhosts sh + WHERE m.mach_id = sh.mach_id AND sh.service = 'CUPS-LPD' AND sh.enable = 1; + EXEC SQL OPEN csr_hosts; + while (1) + { + EXEC SQL FETCH csr_hosts INTO :name; + if (sqlca.sqlcode) + break; + + strtrim(name); + do_host(name); + } + EXEC SQL CLOSE csr_hosts; + + exit(MR_SUCCESS); +} + +void printer_user_list(FILE *out, char *type, int id, char *str) +{ + struct save_queue *sq; + struct imember *m; + + sq = get_acl(type, id, NULL); + while (sq_remove_data(sq, &m)) + { + if (m->type == 'U') + fprintf(out, "%s %s\n", str, m->name); + freeimember(m); + } + sq_destroy(sq); +} + + + +void do_host(char *host) +{ + EXEC SQL BEGIN DECLARE SECTION; + char rp[PRINTERS_RP_SIZE], name[PRINTERS_NAME_SIZE]; + char duplexname[PRINTERS_DUPLEXNAME_SIZE], location[PRINTERS_LOCATION_SIZE]; + char hwtype[PRINTERS_HWTYPE_SIZE], lowerhwtype[PRINTERS_HWTYPE_SIZE]; + char modtime[PRINTERS_MODTIME_SIZE], lmodtime[LIST_MODTIME_SIZE]; + char contact[PRINTERS_CONTACT_SIZE], hostname[MACHINE_NAME_SIZE]; + char cupshosts[MACHINE_NAME_SIZE], prtype [PRINTERS_TYPE_SIZE]; + char *spoolhost = host, *unixtime_fmt = UNIXTIME_FMT, *p; + char *lhost; + int ka, pc, ac, lpc_acl, top_lpc_acl, banner, rm; + EXEC SQL END DECLARE SECTION; + TARFILE *tf; + FILE *out; + char filename[MAXPATHLEN], *duptc; + time_t mtime, now = time(NULL); + + lhost = (char *) strdup (host); + for (p = lhost; *p; p++) + *p = tolower(*p); + + sprintf(filename, "%s/cups-lpd/%s", DCM_DIR, host); + tf = tarfile_open(filename); + + /* LPRng printers */ + out = tarfile_start(tf, "/etc/cups/lprng.printers.txt", 0644, 0, 0, + "root", "lp", now); + + EXEC SQL DECLARE csr_lprng CURSOR FOR + SELECT pr.rp, pr.name, pr.duplexname, pr.hwtype, + m.name, pr.banner, pr.location, pr.contact, pr.ka, + pr.ac, pr.type as prtype + FROM printers pr, machine m, serverhosts sh + WHERE m.mach_id = sh.mach_id AND sh.service = 'PRINT' AND sh.enable = 1 + AND pr.rm = m.mach_id ORDER BY pr.name; + EXEC SQL OPEN csr_lprng; + while (1) + { + EXEC SQL FETCH csr_lprng INTO :rp, :name, :duplexname, + :hwtype, :hostname, :banner, :location, :contact, :ka, :ac, :prtype; + if (sqlca.sqlcode) + break; + + strtrim(rp); + strtrim(name); + strtrim(duplexname); + strtrim(hwtype); + strtrim(hostname); + strtrim(location); + strtrim(contact); + strcpy(lowerhwtype, hwtype); + for (p = lowerhwtype; *p; p++) + *p = tolower(*p); + for (p = name;*p;p++) + *p = tolower(*p); + for (p = duplexname;*p;p++) + *p = tolower(*p); + + fprintf(out, "%s|%s|%s|%s|%s|%s\n", name,duplexname,hostname,location,hwtype,prtype); + } + EXEC SQL CLOSE csr_lprng; + tarfile_end(tf); + + /* CUPS printers */ + out = tarfile_start(tf, "/etc/cups/cups.printers.txt", 0644, 0, 0, + "root", "lp", now); + + EXEC SQL DECLARE csr_cups CURSOR FOR + SELECT pr.rp, pr.name, pr.duplexname, pr.hwtype, + m.name, pr.banner, pr.location, pr.contact, pr.ka, + pr.ac, pr.type as prtype + FROM printers pr, machine m, serverhosts sh + WHERE m.mach_id = sh.mach_id AND sh.service = 'CUPS-PRINT' AND sh.enable = 1 + AND pr.rm = m.mach_id ORDER BY pr.name; + EXEC SQL OPEN csr_cups; + while (1) + { + EXEC SQL FETCH csr_cups INTO :rp, :name, :duplexname, + :hwtype, :hostname, :banner, :location, :contact, :ka, :ac, :prtype; + if (sqlca.sqlcode) + break; + + strtrim(rp); + strtrim(name); + strtrim(duplexname); + strtrim(hwtype); + strtrim(hostname); + strtrim(location); + strtrim(contact); + strcpy(lowerhwtype, hwtype); + for (p = lowerhwtype; *p; p++) + *p = tolower(*p); + for (p = name;*p;p++) + *p = tolower(*p); + for (p = duplexname;*p;p++) + *p = tolower(*p); + + fprintf(out, "%s|%s|%s|%s|%s|%s\n", name,duplexname,hostname,location,hwtype,prtype); + } + EXEC SQL CLOSE csr_cups; + tarfile_end(tf); + tarfile_close(tf); +} + +void sqlerr(void) +{ + db_error(sqlca.sqlcode); +} diff --git a/gen/cups-lpd.sh b/gen/cups-lpd.sh new file mode 100755 index 00000000..89476d52 --- /dev/null +++ b/gen/cups-lpd.sh @@ -0,0 +1,49 @@ +#! /bin/sh +# $Id$ + +if [ -d /var/athena ] && [ -w /var/athena ]; then + exec >/var/athena/moira_update.log 2>&1 +else + exec >/tmp/moira_update.log 2>&1 +fi + +# The following exit codes are defined and MUST BE CONSISTENT with the +# error codes the library uses: +MR_MISSINGFILE=47836473 +MR_MKCRED=47836474 +MR_TARERR=47836476 + +PATH=/bin +TARFILE=/var/tmp/cups-lpd.out +CUPSLOCAL=/etc/cups + +# Alert if the tar file or other needed files do not exist +test -r $TARFILE || exit $MR_MISSINGFILE +test -d $CUPSLOCAL || exit $MR_MISSINGFILE + +# Unpack the tar file, getting only files that are newer than the +# on-disk copies (-u). +cd / +tar xf $TARFILE || exit $MR_TARERR + +/etc/cups/bin/sync_lpd_ldap.pl 2>/dev/null +/etc/cups/bin/gen-ppd.pl 2>/dev/null + +/etc/init.d/cups restart + +# if Samba-enabled, then restart it too to have it pick up +# new definitions +if [ -x /etc/init.d/smb ]; then + /etc/init.d/smb restart +fi + +if [ $? != 0 ]; then + exit $MR_MKCRED +fi + +# cleanup +test -f $TARFILE && rm -f $TARFILE +test -f $0 && rm -f $0 + +exit 0 + diff --git a/gen/cups-print.pc b/gen/cups-print.pc index 0bad9ecd..b9355ecc 100644 --- a/gen/cups-print.pc +++ b/gen/cups-print.pc @@ -50,6 +50,7 @@ const char *lpcpntr = ""; const char *canceljob = ""; const char *catchall = ""; +const char *phost = "printers.MIT.EDU"; void do_host(char *host); void sqlerr(void); @@ -134,7 +135,7 @@ void do_host(char *host) /* printers.conf */ out = tarfile_start(tf, "/etc/cups/printers.conf", 0644, 0, 0, - "root", "lp", now); + "lp", "lp", now); EXEC SQL DECLARE csr_printers CURSOR FOR SELECT pr.rp, pr.name, pr.duplexname, pr.hwtype, @@ -211,7 +212,7 @@ void do_host(char *host) /* aliases are in classes.conf */ out = tarfile_start(tf, "/etc/cups/classes.conf", 0644, 0, 0, - "root", "root", now); + "lp", "lp", now); EXEC SQL DECLARE csr_duplexqs CURSOR FOR SELECT pr.rp, pr.name, pr.duplexname, pr.hwtype, m.name, pr.banner, pr.location, pr.contact, pr.ka, @@ -338,14 +339,12 @@ void do_host(char *host) fprintf(out, "ServerCertificate /etc/cups/ssl/%s-ipp-crt.pem\n", lhost); fprintf(out, "ServerKey /etc/cups/ssl/%s-ipp-key.pem\n", lhost); fprintf(out, "ServerName %s\n", lhost); + fprintf(out, "ServerAlias %s\n", phost); fprintf(out, "Krb5Keytab /etc/krb5-ipp.keytab\n"); - /* fprintf(out, "Browsing On\n"); */ - /* fprintf(out, "BrowseProtocols cups\n"); */ /* The other CUPS servers should be aware of the other hosts' queues, so we'll let them browse each other. */ fprintf(out, "Include cups.local.conf\n"); - fprintf(out, "Include cups.hosts.conf\n"); fprintf(out, "Include cups.locations.conf\n"); fprintf(out, "Include cups.policies.conf\n"); tarfile_end(tf); -- 2.45.1