3 * This generates printcaps and other files for Athena print servers
5 * Copyright (C) 1992-1998 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
10 #include <mit-copyright.h>
12 #include <moira_site.h>
15 #include <sys/types.h>
29 EXEC SQL INCLUDE sqlca;
33 char *whoami = "cups-lpd-print.gen";
34 char *db = "moira/moira";
36 /* OMG, I hate this, but it's cleaner, I guess? */
38 void do_host(char *host);
41 #define MAX(a, b) ( (a) > (b) ? (a) : (b) )
44 int main(int argc, char **argv)
46 EXEC SQL BEGIN DECLARE SECTION;
47 char name[MACHINE_NAME_SIZE];
48 EXEC SQL END DECLARE SECTION;
54 EXEC SQL WHENEVER SQLERROR DO sqlerr();
56 EXEC SQL DECLARE csr_hosts CURSOR FOR
57 SELECT m.name FROM machine m, serverhosts sh
58 WHERE m.mach_id = sh.mach_id AND sh.service = 'CUPS-LPD' AND sh.enable = 1;
59 EXEC SQL OPEN csr_hosts;
62 EXEC SQL FETCH csr_hosts INTO :name;
69 EXEC SQL CLOSE csr_hosts;
74 void printer_user_list(FILE *out, char *type, int id, char *str)
76 struct save_queue *sq;
79 sq = get_acl(type, id, NULL);
80 while (sq_remove_data(sq, &m))
83 fprintf(out, "%s %s\n", str, m->name);
91 void do_host(char *host)
93 EXEC SQL BEGIN DECLARE SECTION;
94 char rp[PRINTERS_RP_SIZE], name[PRINTERS_NAME_SIZE];
95 char duplexname[PRINTERS_DUPLEXNAME_SIZE], location[PRINTERS_LOCATION_SIZE];
96 char hwtype[PRINTERS_HWTYPE_SIZE], lowerhwtype[PRINTERS_HWTYPE_SIZE];
97 char modtime[PRINTERS_MODTIME_SIZE], lmodtime[LIST_MODTIME_SIZE];
98 char contact[PRINTERS_CONTACT_SIZE], hostname[MACHINE_NAME_SIZE];
99 char cupshosts[MACHINE_NAME_SIZE], prtype [PRINTERS_TYPE_SIZE];
100 char *spoolhost = host, *unixtime_fmt = UNIXTIME_FMT, *p;
102 int ka, pc, ac, lpc_acl, top_lpc_acl, banner, rm;
103 EXEC SQL END DECLARE SECTION;
106 char filename[MAXPATHLEN], *duptc;
107 time_t mtime, now = time(NULL);
109 lhost = (char *) strdup (host);
110 for (p = lhost; *p; p++)
113 sprintf(filename, "%s/cups-lpd/%s", DCM_DIR, host);
114 tf = tarfile_open(filename);
117 out = tarfile_start(tf, "/etc/cups/lprng.printers.txt", 0644, 0, 0,
120 EXEC SQL DECLARE csr_lprng CURSOR FOR
121 SELECT pr.rp, pr.name, pr.duplexname, pr.hwtype,
122 m.name, pr.banner, pr.location, pr.contact, pr.ka,
123 pr.ac, pr.type as prtype
124 FROM printers pr, machine m, serverhosts sh
125 WHERE m.mach_id = sh.mach_id AND sh.service = 'PRINT' AND sh.enable = 1
126 AND pr.rm = m.mach_id ORDER BY pr.name;
127 EXEC SQL OPEN csr_lprng;
130 EXEC SQL FETCH csr_lprng INTO :rp, :name, :duplexname,
131 :hwtype, :hostname, :banner, :location, :contact, :ka, :ac, :prtype;
142 strcpy(lowerhwtype, hwtype);
143 for (p = lowerhwtype; *p; p++)
145 for (p = name;*p;p++)
147 for (p = duplexname;*p;p++)
150 fprintf(out, "%s|%s|%s|%s|%s|%s|%s\n", name,duplexname,hostname,location,hwtype,prtype,rp);
152 EXEC SQL CLOSE csr_lprng;
156 out = tarfile_start(tf, "/etc/cups/cups.printers.txt", 0644, 0, 0,
159 EXEC SQL DECLARE csr_cups CURSOR FOR
160 SELECT pr.rp, pr.name, pr.duplexname, pr.hwtype,
161 m.name, pr.banner, pr.location, pr.contact, pr.ka,
162 pr.ac, pr.type as prtype
163 FROM printers pr, machine m, serverhosts sh
164 WHERE m.mach_id = sh.mach_id AND sh.service = 'CUPS-PRINT' AND sh.enable = 1
165 AND pr.rm = m.mach_id ORDER BY pr.name;
166 EXEC SQL OPEN csr_cups;
169 EXEC SQL FETCH csr_cups INTO :rp, :name, :duplexname,
170 :hwtype, :hostname, :banner, :location, :contact, :ka, :ac, :prtype;
181 strcpy(lowerhwtype, hwtype);
182 for (p = lowerhwtype; *p; p++)
184 for (p = name;*p;p++)
186 for (p = duplexname;*p;p++)
189 fprintf(out, "%s|%s|%s|%s|%s|%s\n", name,duplexname,hostname,location,hwtype,prtype);
191 EXEC SQL CLOSE csr_cups;
198 db_error(sqlca.sqlcode);