From: zacheiss Date: Thu, 10 Jul 2008 16:58:40 +0000 (+0000) Subject: lpcaccess DCM X-Git-Url: http://andersk.mit.edu/gitweb/moira.git/commitdiff_plain/47566befc18ff8e25b58caffef0459f9e411f177 lpcaccess DCM --- diff --git a/gen/Makefile.in b/gen/Makefile.in index 6ae0e924..8b399e57 100644 --- a/gen/Makefile.in +++ b/gen/Makefile.in @@ -31,16 +31,16 @@ LIB_CFILES=genacl.c LIB_TARGET=libdcm.a OBJS= acl.o boot.o confluence.o dhcp.o directory.o events.o hesiod.o \ - hosts.o mailhub.o ndb.o network.o nfs.o pobox.o postoffice.o print.o \ - winad.o www.o zephyr.o + hosts.o lpcaccess.o mailhub.o ndb.o network.o nfs.o pobox.o \ + postoffice.o print.o winad.o www.o zephyr.o CFILES= acl.c boot.c confluence.c dhcp.c directory.c events.c hesiod.c \ - hosts.c mailhub.c ndb.c network.c nfs.c pobox.c postoffice.c print.c \ - winad.c www.c zephyr.c + hosts.c lpcaccess.c mailhub.c ndb.c network.c nfs.c pobox.c \ + postoffice.c print.c winad.c www.c zephyr.c TARGET= acl.gen boot.gen confluence.gen dhcp.gen directory.gen events.gen \ - hesiod.gen hosts.gen mailhub.gen ndb.gen network.gen nfs.gen \ - pobox.gen postoffice.gen print.gen winad.gen www.gen zephyr.gen + hesiod.gen hosts.gen lpcaccess.gen mailhub.gen ndb.gen network.gen \ + nfs.gen pobox.gen postoffice.gen print.gen winad.gen www.gen zephyr.gen SCRIPTS=access.gen access.sh acl.sh aliases.sh boot.sh ca.gen calendar.gen \ dhcp.sh events.sh hesiod.sh ip-billing.gen \ @@ -137,3 +137,6 @@ www.gen: www.o libdcm.a $(MR_LIBDEP) winad.gen: winad.o libdcm.a $(MR_LIBDEP) $(CC) -o $@ $(LDFLAGS) winad.o libdcm.a $(SQL_LIBS) $(LIBS) + +lpcaccess.gen: lpcaccess.o libdcm.a $(MR_LIBDEP) + $(CC) -o $@ $(LDFLAGS) lpcaccess.o libdcm.a $(SQL_LIBS) $(LIBS) diff --git a/gen/lpcaccess.pc b/gen/lpcaccess.pc new file mode 100644 index 00000000..c7465f08 --- /dev/null +++ b/gen/lpcaccess.pc @@ -0,0 +1,99 @@ +/* $Id$ */ + +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include "util.h" + +EXEC SQL INCLUDE sqlca; + +char *whoami = "lpcaccess.gen"; +char *db = "moira/moira"; + +void sqlerr(void); + +int main(int argc, char **argv) +{ + EXEC SQL BEGIN DECLARE SECTION; + char name[PRINTERS_RP_SIZE], duplexname[PRINTERS_DUPLEXNAME_SIZE]; + int lpc_acl, list_id; + EXEC SQL END DECLARE SECTION; + TARFILE *tf; + FILE *out; + char filename[MAXPATHLEN]; + time_t mtime, now = time(NULL); + + init_acls(); + + EXEC SQL CONNECT :db; + + EXEC SQL WHENEVER SQLERROR DO sqlerr(); + + sprintf(filename, "%s/lpcaccess.out", DCM_DIR); + tf = tarfile_open(filename); + + EXEC SQL SELECT list_id INTO :list_id FROM list + WHERE name = 'ops-lpcaccess-top'; + + out = tarfile_start(tf, "lpcaccess.top", 0755, 1, 1, "daemon", "daemon", + now); + dump_krb_acl(out, "LIST", list_id, 5); + tarfile_end(tf); + + EXEC SQL SELECT list_id INTO :list_id FROM LIST + WHERE name = 'sap-lpcaccess-top'; + + out = tarfile_start(tf, "sap-lpcaccess.top", 0755, 1, 1, "daemon", "daemon", + now); + dump_krb_acl(out, "LIST", list_id, 5); + tarfile_end(tf); + + EXEC SQL DECLARE csr_lpc CURSOR FOR SELECT UNIQUE rp, duplexname, lpc_acl + FROM printers WHERE lpc_acl != 0; + EXEC SQL OPEN csr_lpc; + while (1) + { + EXEC SQL FETCH csr_lpc INTO :name, :duplexname, :lpc_acl; + if (sqlca.sqlcode) + break; + + strtrim(name); + + tarfile_mkdir(tf, name, 0755, 1, 1, "daemon", "daemon", now); + sprintf(filename, "%s/lpcaccess", name); + out = tarfile_start(tf, filename, 0755, 1, 1, "daemon", "daemon", now); + dump_krb_acl(out, "LIST", lpc_acl, 5); + tarfile_end(tf); + + if (*duplexname) + { + strtrim(duplexname); + + tarfile_mkdir(tf, duplexname, 0755, 1, 1, "daemon", "daemon", now); + sprintf(filename, "%s/lpcaccess", duplexname); + out = tarfile_start(tf, filename, 0755, 1, 1, "daemon", "daemon", now); + dump_krb_acl(out, "LIST", lpc_acl, 5); + tarfile_end(tf); + } + + } + EXEC SQL CLOSE csr_lpc; + + tarfile_close(tf); + + exit(MR_SUCCESS); +} + +void sqlerr(void) +{ + db_error(sqlca.sqlcode); +} + diff --git a/gen/lpcaccess.sh b/gen/lpcaccess.sh new file mode 100755 index 00000000..4ba613a7 --- /dev/null +++ b/gen/lpcaccess.sh @@ -0,0 +1,35 @@ +#!/bin/sh +# $Id$ + +outfile=/home/cups/lpcaccess.out +loadprog=/home/cups/update_acls + +PATH="/etc:/bin:/usr/bin:/usr/etc:/usr/athena/etc" + +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 + +if [ ! -f $outfile ]; then + exit $MR_MISSINGFILE +fi + +if [ ! -x $loadprog ]; then + exit $MR_MISSINGFILE +fi + +$loadprog + +# Ignore exit status from $loadprog for now. +#if [ $? != 0 ]; then +# exit $MR_MKCRED +#fi + +exit 0