/* $Id: print.pc 4030 2011-03-04 21:01:14Z zacheiss $ * * 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 "util.h" EXEC SQL INCLUDE sqlca; RCSID("$HeadURL: svn+ssh://svn.mit.edu/moira/trunk/moira/gen/print.pc $ $Id: print.pc 4030 2011-03-04 21:01:14Z zacheiss $"); char *whoami = "print.gen"; char *db = "moira/moira"; 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 = 'PRINT' 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 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 *spoolhost = host, *unixtime_fmt = UNIXTIME_FMT, *p; int ka, pc, ac, lpc_acl, banner, rm; EXEC SQL END DECLARE SECTION; TARFILE *tf; FILE *out; char filename[MAXPATHLEN], *duptc; time_t mtime, now = time(NULL); EXEC SQL SELECT mach_id INTO :rm FROM machine WHERE name = :spoolhost; sprintf(filename, "%s/print/%s", DCM_DIR, host); tf = tarfile_open(filename); /* printcap */ out = tarfile_start(tf, "/etc/printcap.moira", 0644, 0, 0, "root", "root", now); EXEC SQL DECLARE csr_printcap CURSOR FOR SELECT pr.rp, pr.name, pr.duplexname, pr.hwtype, m.name, pr.banner, pr.location, pr.contact FROM printers pr, machine m WHERE pr.rm = :rm AND m.mach_id = pr.mach_id AND (pr.status = 1 OR pr.status = 2) AND m.status != 3 AND pr.type != 'ALIAS' AND ( pr.hwtype LIKE 'HP%' OR pr.hwtype LIKE 'LPR%' ); EXEC SQL OPEN csr_printcap; while (1) { EXEC SQL FETCH csr_printcap INTO :rp, :name, :duplexname, :hwtype, :hostname, :banner, :location, :contact; 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); if (location[0]) fprintf(out, "# %s: %s\n", name, location); else fprintf(out, "# %s\n", name); if (strcmp(location, contact)) fprintf(out, "# contact: %s\n", contact); fprintf(out, "%s\n\t:server:cm=%s %s\n\t", rp, hwtype, location); if (banner == PRN_BANNER_NONE) fprintf(out, ":sh"); else if (banner == PRN_BANNER_LAST) fprintf(out, ":hl"); if (!strncmp(hwtype, "HP", 2)) { fprintf(out, ":lp=%s%%9100:ifhp=model=%s:tc=.hp\n\n", hostname, lowerhwtype); duptc = ".hp2"; } else if (!strncmp(hwtype, "LPR", 3)) { fprintf(out, ":lp=raw@%s:tc=.apple\n\n", hostname); duptc = ".apple2"; } if (*duplexname) { fprintf(out, "%s\n\t:server:bq=%s:cm=%s duplex queue\n\t", duplexname, rp, rp); if (!strncmp(hwtype, "HP", 2)) fprintf(out, ":ifhp=model=%s", lowerhwtype); fprintf(out, ":tc=%s\n\n", duptc); } } EXEC SQL CLOSE csr_printcap; tarfile_end(tf); /* lpd.perms */ out = tarfile_start(tf, "/etc/lpd.perms", 0755, 1, 1, "daemon", "daemon", now); fprintf(out, "# Allow anybody to connect, get status, list queue, or " "print (once a\n# job is spooled)\n"); fprintf(out, "ACCEPT SERVICE=X,S,Q,P\nACCEPT LPC=status,lpq,printcap\n\n"); fprintf(out, "# Only trust certain host keys to forward jobs/commands\n"); fprintf(out, "REJECT SERVICE=R AUTHFROM=?* " "PRINTER=