[23740] | 1 | /* $Id: lpcaccess.pc,v 1.1 2008-07-10 16:58:40 zacheiss Exp $ */ |
---|
| 2 | |
---|
| 3 | #include <mit-copyright.h> |
---|
| 4 | #include <moira.h> |
---|
| 5 | #include <moira_site.h> |
---|
| 6 | |
---|
| 7 | #include <sys/stat.h> |
---|
| 8 | #include <sys/types.h> |
---|
| 9 | |
---|
| 10 | #include <ctype.h> |
---|
| 11 | #include <stdio.h> |
---|
| 12 | #include <string.h> |
---|
| 13 | |
---|
| 14 | #include "util.h" |
---|
| 15 | |
---|
| 16 | EXEC SQL INCLUDE sqlca; |
---|
| 17 | |
---|
| 18 | char *whoami = "lpcaccess.gen"; |
---|
| 19 | char *db = "moira/moira"; |
---|
| 20 | |
---|
| 21 | void sqlerr(void); |
---|
| 22 | |
---|
| 23 | int main(int argc, char **argv) |
---|
| 24 | { |
---|
| 25 | EXEC SQL BEGIN DECLARE SECTION; |
---|
| 26 | char name[PRINTERS_RP_SIZE], duplexname[PRINTERS_DUPLEXNAME_SIZE]; |
---|
| 27 | int lpc_acl, list_id; |
---|
| 28 | EXEC SQL END DECLARE SECTION; |
---|
| 29 | TARFILE *tf; |
---|
| 30 | FILE *out; |
---|
| 31 | char filename[MAXPATHLEN]; |
---|
| 32 | time_t mtime, now = time(NULL); |
---|
| 33 | |
---|
| 34 | init_acls(); |
---|
| 35 | |
---|
| 36 | EXEC SQL CONNECT :db; |
---|
| 37 | |
---|
| 38 | EXEC SQL WHENEVER SQLERROR DO sqlerr(); |
---|
| 39 | |
---|
| 40 | sprintf(filename, "%s/lpcaccess.out", DCM_DIR); |
---|
| 41 | tf = tarfile_open(filename); |
---|
| 42 | |
---|
| 43 | EXEC SQL SELECT list_id INTO :list_id FROM list |
---|
| 44 | WHERE name = 'ops-lpcaccess-top'; |
---|
| 45 | |
---|
| 46 | out = tarfile_start(tf, "lpcaccess.top", 0755, 1, 1, "daemon", "daemon", |
---|
| 47 | now); |
---|
| 48 | dump_krb_acl(out, "LIST", list_id, 5); |
---|
| 49 | tarfile_end(tf); |
---|
| 50 | |
---|
| 51 | EXEC SQL SELECT list_id INTO :list_id FROM LIST |
---|
| 52 | WHERE name = 'sap-lpcaccess-top'; |
---|
| 53 | |
---|
| 54 | out = tarfile_start(tf, "sap-lpcaccess.top", 0755, 1, 1, "daemon", "daemon", |
---|
| 55 | now); |
---|
| 56 | dump_krb_acl(out, "LIST", list_id, 5); |
---|
| 57 | tarfile_end(tf); |
---|
| 58 | |
---|
| 59 | EXEC SQL DECLARE csr_lpc CURSOR FOR SELECT UNIQUE rp, duplexname, lpc_acl |
---|
| 60 | FROM printers WHERE lpc_acl != 0; |
---|
| 61 | EXEC SQL OPEN csr_lpc; |
---|
| 62 | while (1) |
---|
| 63 | { |
---|
| 64 | EXEC SQL FETCH csr_lpc INTO :name, :duplexname, :lpc_acl; |
---|
| 65 | if (sqlca.sqlcode) |
---|
| 66 | break; |
---|
| 67 | |
---|
| 68 | strtrim(name); |
---|
| 69 | |
---|
| 70 | tarfile_mkdir(tf, name, 0755, 1, 1, "daemon", "daemon", now); |
---|
| 71 | sprintf(filename, "%s/lpcaccess", name); |
---|
| 72 | out = tarfile_start(tf, filename, 0755, 1, 1, "daemon", "daemon", now); |
---|
| 73 | dump_krb_acl(out, "LIST", lpc_acl, 5); |
---|
| 74 | tarfile_end(tf); |
---|
| 75 | |
---|
| 76 | if (*duplexname) |
---|
| 77 | { |
---|
| 78 | strtrim(duplexname); |
---|
| 79 | |
---|
| 80 | tarfile_mkdir(tf, duplexname, 0755, 1, 1, "daemon", "daemon", now); |
---|
| 81 | sprintf(filename, "%s/lpcaccess", duplexname); |
---|
| 82 | out = tarfile_start(tf, filename, 0755, 1, 1, "daemon", "daemon", now); |
---|
| 83 | dump_krb_acl(out, "LIST", lpc_acl, 5); |
---|
| 84 | tarfile_end(tf); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | } |
---|
| 88 | EXEC SQL CLOSE csr_lpc; |
---|
| 89 | |
---|
| 90 | tarfile_close(tf); |
---|
| 91 | |
---|
| 92 | exit(MR_SUCCESS); |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | void sqlerr(void) |
---|
| 96 | { |
---|
| 97 | db_error(sqlca.sqlcode); |
---|
| 98 | } |
---|
| 99 | |
---|