]> andersk Git - moira.git/commitdiff
cups-lpd DCM.
authorzacheiss <zacheiss>
Tue, 21 Jul 2009 21:39:12 +0000 (21:39 +0000)
committerzacheiss <zacheiss>
Tue, 21 Jul 2009 21:39:12 +0000 (21:39 +0000)
gen/Makefile.in
gen/cups-lpd.pc [new file with mode: 0644]
gen/cups-lpd.sh [new file with mode: 0755]
gen/cups-print.pc

index 0171a433ac89147f416d983609ec25d03e980537..f48d39070feb22d404ce84e87ced8527b649c592 100644 (file)
@@ -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 (file)
index 0000000..5652f6a
--- /dev/null
@@ -0,0 +1,199 @@
+/* $Id$\r
+ *\r
+ * This generates printcaps and other files for Athena print servers\r
+ *\r
+ * Copyright (C) 1992-1998 by the Massachusetts Institute of Technology.\r
+ * For copying and distribution information, please see the file\r
+ * <mit-copyright.h>.\r
+ */\r
+\r
+#include <mit-copyright.h>\r
+#include <moira.h>\r
+#include <moira_site.h>\r
+\r
+#include <sys/stat.h>\r
+#include <sys/types.h>\r
+\r
+#include <ctype.h>\r
+#include <stdio.h>\r
+#include <string.h>\r
+\r
+#include <time.h>\r
+#ifdef HAVE_KRB4\r
+#include <krb.h>\r
+#endif\r
+#include <krb5.h>\r
+\r
+#include "util.h"\r
+\r
+EXEC SQL INCLUDE sqlca;\r
+\r
+RCSID("$Header$");\r
+\r
+char *whoami = "cups-lpd-print.gen";\r
+char *db = "moira/moira";\r
+\r
+/* OMG, I hate this, but it's cleaner, I guess? */\r
+\r
+void do_host(char *host);\r
+void sqlerr(void);\r
+#ifndef MAX\r
+#define MAX(a, b) ( (a) > (b) ? (a) : (b) )\r
+#endif\r
+\r
+int main(int argc, char **argv)\r
+{\r
+  EXEC SQL BEGIN DECLARE SECTION;\r
+  char name[MACHINE_NAME_SIZE];\r
+  EXEC SQL END DECLARE SECTION;\r
+\r
+  init_acls();\r
+\r
+  EXEC SQL CONNECT :db;\r
+\r
+  EXEC SQL WHENEVER SQLERROR DO sqlerr();\r
+\r
+  EXEC SQL DECLARE csr_hosts CURSOR FOR\r
+    SELECT m.name FROM machine m, serverhosts sh\r
+    WHERE m.mach_id = sh.mach_id AND sh.service = 'CUPS-LPD' AND sh.enable = 1;\r
+  EXEC SQL OPEN csr_hosts;\r
+  while (1)\r
+    {\r
+      EXEC SQL FETCH csr_hosts INTO :name;\r
+      if (sqlca.sqlcode)\r
+       break;\r
+\r
+      strtrim(name);\r
+      do_host(name);\r
+    }\r
+  EXEC SQL CLOSE csr_hosts;\r
+\r
+  exit(MR_SUCCESS);\r
+}\r
+\r
+void printer_user_list(FILE *out, char *type, int id, char *str)\r
+{\r
+  struct save_queue *sq;\r
+  struct imember *m;\r
+\r
+  sq = get_acl(type, id, NULL);\r
+  while (sq_remove_data(sq, &m))\r
+    {\r
+      if (m->type == 'U')\r
+        fprintf(out, "%s %s\n", str, m->name);\r
+      freeimember(m);\r
+    }\r
+  sq_destroy(sq);\r
+}\r
+\r
+\r
+\r
+void do_host(char *host)\r
+{\r
+  EXEC SQL BEGIN DECLARE SECTION;\r
+  char rp[PRINTERS_RP_SIZE], name[PRINTERS_NAME_SIZE];\r
+  char duplexname[PRINTERS_DUPLEXNAME_SIZE], location[PRINTERS_LOCATION_SIZE];\r
+  char hwtype[PRINTERS_HWTYPE_SIZE], lowerhwtype[PRINTERS_HWTYPE_SIZE];\r
+  char modtime[PRINTERS_MODTIME_SIZE], lmodtime[LIST_MODTIME_SIZE];\r
+  char contact[PRINTERS_CONTACT_SIZE], hostname[MACHINE_NAME_SIZE];\r
+  char cupshosts[MACHINE_NAME_SIZE], prtype [PRINTERS_TYPE_SIZE];\r
+  char *spoolhost = host, *unixtime_fmt = UNIXTIME_FMT, *p;\r
+  char *lhost;\r
+  int ka, pc, ac, lpc_acl, top_lpc_acl, banner, rm;\r
+  EXEC SQL END DECLARE SECTION;\r
+  TARFILE *tf;\r
+  FILE *out;\r
+  char filename[MAXPATHLEN], *duptc;\r
+  time_t mtime, now = time(NULL);\r
+\r
+  lhost = (char *) strdup (host);\r
+  for (p = lhost; *p; p++)\r
+     *p = tolower(*p);\r
+\r
+  sprintf(filename, "%s/cups-lpd/%s", DCM_DIR, host);\r
+  tf = tarfile_open(filename);\r
+\r
+  /* LPRng printers */\r
+  out = tarfile_start(tf, "/etc/cups/lprng.printers.txt", 0644, 0, 0,\r
+                     "root", "lp", now);\r
+\r
+  EXEC SQL DECLARE csr_lprng CURSOR FOR\r
+    SELECT pr.rp, pr.name, pr.duplexname, pr.hwtype,\r
+    m.name, pr.banner, pr.location, pr.contact, pr.ka,\r
+    pr.ac, pr.type as prtype\r
+    FROM printers pr, machine m, serverhosts sh\r
+    WHERE m.mach_id = sh.mach_id AND sh.service = 'PRINT' AND sh.enable = 1\r
+    AND pr.rm = m.mach_id ORDER BY pr.name;\r
+  EXEC SQL OPEN csr_lprng;\r
+  while (1)\r
+    {\r
+      EXEC SQL FETCH csr_lprng INTO :rp, :name, :duplexname,\r
+       :hwtype, :hostname, :banner, :location, :contact, :ka, :ac, :prtype;\r
+      if (sqlca.sqlcode)\r
+       break;\r
+\r
+      strtrim(rp);\r
+      strtrim(name);\r
+      strtrim(duplexname);\r
+      strtrim(hwtype);\r
+      strtrim(hostname);\r
+      strtrim(location);\r
+      strtrim(contact);\r
+      strcpy(lowerhwtype, hwtype);\r
+      for (p = lowerhwtype; *p; p++)\r
+       *p = tolower(*p);\r
+      for (p = name;*p;p++)\r
+       *p = tolower(*p);\r
+      for (p = duplexname;*p;p++)\r
+       *p = tolower(*p);\r
+\r
+      fprintf(out, "%s|%s|%s|%s|%s|%s\n", name,duplexname,hostname,location,hwtype,prtype);\r
+    }\r
+  EXEC SQL CLOSE csr_lprng;\r
+  tarfile_end(tf);\r
+\r
+  /* CUPS printers */\r
+  out = tarfile_start(tf, "/etc/cups/cups.printers.txt", 0644, 0, 0,\r
+                     "root", "lp", now);\r
+\r
+  EXEC SQL DECLARE csr_cups CURSOR FOR\r
+    SELECT pr.rp, pr.name, pr.duplexname, pr.hwtype,\r
+    m.name, pr.banner, pr.location, pr.contact, pr.ka,\r
+    pr.ac, pr.type as prtype\r
+    FROM printers pr, machine m, serverhosts sh\r
+    WHERE m.mach_id = sh.mach_id AND sh.service = 'CUPS-PRINT' AND sh.enable = 1\r
+    AND pr.rm = m.mach_id ORDER BY pr.name;\r
+  EXEC SQL OPEN csr_cups;\r
+  while (1)\r
+    {\r
+      EXEC SQL FETCH csr_cups INTO :rp, :name, :duplexname,\r
+       :hwtype, :hostname, :banner, :location, :contact, :ka, :ac, :prtype;\r
+      if (sqlca.sqlcode)\r
+       break;\r
+\r
+      strtrim(rp);\r
+      strtrim(name);\r
+      strtrim(duplexname);\r
+      strtrim(hwtype);\r
+      strtrim(hostname);\r
+      strtrim(location);\r
+      strtrim(contact);\r
+      strcpy(lowerhwtype, hwtype);\r
+      for (p = lowerhwtype; *p; p++)\r
+       *p = tolower(*p);\r
+      for (p = name;*p;p++)\r
+       *p = tolower(*p);\r
+      for (p = duplexname;*p;p++)\r
+       *p = tolower(*p);\r
+\r
+      fprintf(out, "%s|%s|%s|%s|%s|%s\n", name,duplexname,hostname,location,hwtype,prtype);\r
+    }\r
+  EXEC SQL CLOSE csr_cups;\r
+  tarfile_end(tf);\r
+  tarfile_close(tf);\r
+}\r
+\r
+void sqlerr(void)\r
+{\r
+  db_error(sqlca.sqlcode);\r
+}\r
diff --git a/gen/cups-lpd.sh b/gen/cups-lpd.sh
new file mode 100755 (executable)
index 0000000..89476d5
--- /dev/null
@@ -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
+
index 0bad9ecdd73e1537da691927e86da54d0dc9793b..b9355ecc23600d30648a9d65c94d3563cfd4eb5f 100644 (file)
@@ -50,6 +50,7 @@ const char *lpcpntr = "<Limit Pause-Printer Resume-Printer Enable-Printer\
  CUPS-Accept-Jobs CUPS-Reject-Jobs>";
 const char *canceljob = "<Limit Cancel-Job CUPS-Authenticate-Job>";
 const char *catchall = "<Limit All>";
+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);
This page took 0.07698 seconds and 5 git commands to generate.