]>
Commit | Line | Data |
---|---|---|
cfba011a | 1 | /* $Id$\r |
2 | *\r | |
3 | * This generates printcaps and other files for Athena print servers\r | |
4 | *\r | |
5 | * Copyright (C) 1992-1998 by the Massachusetts Institute of Technology.\r | |
6 | * For copying and distribution information, please see the file\r | |
7 | * <mit-copyright.h>.\r | |
8 | */\r | |
9 | \r | |
10 | #include <mit-copyright.h>\r | |
11 | #include <moira.h>\r | |
12 | #include <moira_site.h>\r | |
13 | \r | |
14 | #include <sys/stat.h>\r | |
15 | #include <sys/types.h>\r | |
16 | \r | |
17 | #include <ctype.h>\r | |
18 | #include <stdio.h>\r | |
19 | #include <string.h>\r | |
20 | \r | |
21 | #include <time.h>\r | |
22 | #ifdef HAVE_KRB4\r | |
23 | #include <krb.h>\r | |
24 | #endif\r | |
25 | #include <krb5.h>\r | |
26 | \r | |
27 | #include "util.h"\r | |
28 | \r | |
29 | EXEC SQL INCLUDE sqlca;\r | |
30 | \r | |
31 | RCSID("$Header$");\r | |
32 | \r | |
33 | char *whoami = "cups-print.gen";\r | |
34 | char *db = "moira/moira";\r | |
35 | \r | |
36 | const int krbvers = 5; /* use Kerberos 5 */\r | |
37 | \r | |
38 | /* OMG, I hate this, but it's cleaner, I guess? */\r | |
39 | \r | |
40 | const char *alterjob = "<Limit Hold-Job Release-Job\\r | |
41 | Restart-Job Purge-Jobs Reprocess-Job Set-Job-Attributes\\r | |
42 | Cancel-Current-Job Suspend-Current-Job Resume-Job CUPS-Move-Job>";\r | |
43 | const char *submitjob = "<Limit Create-Job Print-Job Print-URI Send-Document\\r | |
44 | Set-Job-Attributes Send-URI Create-Job-Subscription Renew-Subscription\\r | |
45 | Cancel-Subscription Get-Notifications CUPS-Move-Job>";\r | |
46 | const char *alterpntr = "<Limit CUPS-Add-Modify-Printer CUPS-Delete-Printer\\r | |
47 | CUPS-Add-Modify-Class CUPS-Delete-Class CUPS-Set-Default>";\r | |
48 | const char *lpcpntr = "<Limit Pause-Printer Resume-Printer Enable-Printer\\r | |
49 | Disable-Printer Pause-Printer-After-Current-Job Hold-New-Jobs\\r | |
50 | Release-Held-New-Jobs Deactivate-Printer Activate-Printer Restart-Printer\\r | |
51 | Shutdown-Printer Startup-Printer Promote-Job Schedule-Job-After\\r | |
52 | CUPS-Accept-Jobs CUPS-Reject-Jobs>";\r | |
53 | const char *canceljob = "<Limit Cancel-Job CUPS-Authenticate-Job>";\r | |
54 | const char *catchall = "<Limit All>";\r | |
55 | const char *phost = "printers.MIT.EDU";\r | |
56 | \r | |
57 | void do_host(char *host);\r | |
58 | void sqlerr(void);\r | |
59 | #ifndef MAX\r | |
60 | #define MAX(a, b) ( (a) > (b) ? (a) : (b) )\r | |
61 | #endif\r | |
62 | \r | |
63 | int main(int argc, char **argv)\r | |
64 | {\r | |
65 | EXEC SQL BEGIN DECLARE SECTION;\r | |
66 | char name[MACHINE_NAME_SIZE];\r | |
67 | EXEC SQL END DECLARE SECTION;\r | |
68 | \r | |
69 | init_acls();\r | |
70 | \r | |
71 | EXEC SQL CONNECT :db;\r | |
72 | \r | |
73 | EXEC SQL WHENEVER SQLERROR DO sqlerr();\r | |
74 | \r | |
75 | EXEC SQL DECLARE csr_hosts CURSOR FOR\r | |
76 | SELECT m.name FROM machine m, serverhosts sh\r | |
77 | WHERE m.mach_id = sh.mach_id AND sh.service = 'CUPS-CLUSTER' AND sh.enable = 1;\r | |
78 | EXEC SQL OPEN csr_hosts;\r | |
79 | while (1)\r | |
80 | {\r | |
81 | EXEC SQL FETCH csr_hosts INTO :name;\r | |
82 | if (sqlca.sqlcode)\r | |
83 | break;\r | |
84 | \r | |
85 | strtrim(name);\r | |
86 | do_host(name);\r | |
87 | }\r | |
88 | EXEC SQL CLOSE csr_hosts;\r | |
89 | \r | |
90 | exit(MR_SUCCESS);\r | |
91 | }\r | |
92 | \r | |
93 | void printer_user_list(FILE *out, char *type, int id, char *str)\r | |
94 | {\r | |
95 | struct save_queue *sq;\r | |
96 | struct imember *m;\r | |
97 | char kbuf[MAX_K_NAME_SZ];\r | |
98 | char *cp;\r | |
99 | \r | |
100 | sq = get_acl(type, id, NULL);\r | |
101 | while (sq_remove_data(sq, &m))\r | |
102 | {\r | |
103 | if (m->type != 'S' && m->type != NULL) {\r | |
104 | /* CUPS wants mmanley/root, not mmanley.root@ATHENA.MIT.EDU */\r | |
105 | canon_krb(m, krbvers, kbuf, sizeof(kbuf));\r | |
106 | \r | |
107 | /* now, take out all the @realm */\r | |
108 | for (cp=kbuf; *cp; cp++) {\r | |
109 | if (*cp == '@') *cp = '\0';\r | |
110 | }\r | |
111 | fprintf(out, "%s %s\n", str, kbuf);\r | |
112 | }\r | |
113 | freeimember(m);\r | |
114 | }\r | |
115 | sq_destroy(sq);\r | |
116 | }\r | |
117 | \r | |
118 | \r | |
119 | \r | |
120 | void do_host(char *host)\r | |
121 | {\r | |
122 | EXEC SQL BEGIN DECLARE SECTION;\r | |
123 | char rp[PRINTERS_RP_SIZE], name[PRINTERS_NAME_SIZE];\r | |
124 | char duplexname[PRINTERS_DUPLEXNAME_SIZE], location[PRINTERS_LOCATION_SIZE];\r | |
125 | char hwtype[PRINTERS_HWTYPE_SIZE], lowerhwtype[PRINTERS_HWTYPE_SIZE];\r | |
126 | char modtime[PRINTERS_MODTIME_SIZE], lmodtime[LIST_MODTIME_SIZE];\r | |
127 | char contact[PRINTERS_CONTACT_SIZE], hostname[MACHINE_NAME_SIZE];\r | |
128 | char cupshosts[MACHINE_NAME_SIZE], prtype [PRINTERS_TYPE_SIZE];\r | |
129 | char *spoolhost = host, *unixtime_fmt = UNIXTIME_FMT, *p;\r | |
130 | char *lhost;\r | |
131 | int ka, pc, ac, lpc_acl, top_lpc_acl, banner, rm;\r | |
132 | EXEC SQL END DECLARE SECTION;\r | |
133 | TARFILE *tf;\r | |
134 | FILE *out;\r | |
135 | char filename[MAXPATHLEN], *duptc;\r | |
136 | time_t mtime, now = time(NULL);\r | |
137 | \r | |
138 | lhost = (char *) strdup (host);\r | |
139 | for (p = lhost; *p; p++)\r | |
140 | *p = tolower(*p);\r | |
141 | \r | |
142 | EXEC SQL SELECT mach_id INTO :rm FROM machine\r | |
143 | WHERE name = :spoolhost;\r | |
144 | \r | |
145 | sprintf(filename, "%s/cups-cluster/%s", DCM_DIR, host);\r | |
146 | tf = tarfile_open(filename);\r | |
147 | \r | |
148 | /* printers.conf entries for locally run queues */\r | |
149 | out = tarfile_start(tf, "/etc/cups/printers.conf", 0644, 0, 0,\r | |
150 | "lp", "lp", now);\r | |
151 | \r | |
152 | EXEC SQL DECLARE csr_printers CURSOR FOR\r | |
153 | SELECT pr.rp, pr.name, pr.duplexname, pr.hwtype,\r | |
154 | m.name, pr.banner, pr.location, pr.contact, pr.ka,\r | |
155 | pr.ac, pr.lpc_acl\r | |
156 | FROM printers pr, machine m\r | |
157 | WHERE pr.rm = :rm AND m.mach_id = pr.mach_id\r | |
158 | AND (pr.type = 'DORM' or pr.type = 'CLUSTER');\r | |
159 | EXEC SQL OPEN csr_printers;\r | |
160 | while (1)\r | |
161 | {\r | |
162 | EXEC SQL FETCH csr_printers INTO :rp, :name, :duplexname,\r | |
163 | :hwtype, :hostname, :banner, :location, :contact, :ka, :ac, :lpc_acl;\r | |
164 | if (sqlca.sqlcode)\r | |
165 | break;\r | |
166 | \r | |
167 | strtrim(rp);\r | |
168 | strtrim(name);\r | |
169 | strtrim(duplexname);\r | |
170 | strtrim(hwtype);\r | |
171 | strtrim(hostname);\r | |
172 | strtrim(location);\r | |
173 | strtrim(contact);\r | |
174 | strcpy(lowerhwtype, hwtype);\r | |
175 | for (p = rp; *p; p++) /* Because uppercased printer names suck */\r | |
176 | *p = tolower(*p);\r | |
177 | for (p = lowerhwtype; *p; p++)\r | |
178 | *p = tolower(*p);\r | |
179 | \r | |
180 | fprintf(out, "<Printer %s>\n",rp);\r | |
181 | fprintf(out, "Info %s:%s\n", rp, hwtype);\r | |
182 | /* Note the use of "beh" to keep the CUPS from disabling print queues\r | |
183 | * should they not respond versus discarding the job. \r | |
184 | * See the "beh" page for details. \r | |
185 | * The 1/0/60 says "don't disable/try 20 times/try every 60s */\r | |
186 | if (!strncmp(hwtype, "HP", 2)) \r | |
187 | fprintf(out, "DeviceURI beh:/1/20/60/socket://%s:9100\n", hostname);\r | |
188 | else\r | |
189 | fprintf(out, "DeviceURI beh:/1/20/60/socket://%s\n", hostname);\r | |
190 | fprintf(out, "State Idle\n"); // Always with the Idle\r | |
191 | fprintf(out, "StateTime %ld\n", (long)time(NULL));\r | |
192 | fprintf(out, "Accepting Yes\n");\r | |
193 | fprintf(out, "Shared Yes\n");\r | |
194 | fprintf(out, "QuotaPeriod 0\n");\r | |
195 | fprintf(out, "PageLimit 0\n");\r | |
196 | fprintf(out, "Klimit 0\n");\r | |
197 | fprintf(out, "Option sides one-sided\n");\r | |
198 | fprintf(out, "Filter application/vnd.cups-raw 0 -\n");\r | |
199 | fprintf(out, "Filter application/vnd.cups-postscript 100 foomatic-rip\n");\r | |
200 | fprintf(out, "Filter application/vnd.cups-pdf 0 foomatic-rip\n");\r | |
201 | fprintf(out, "Filter application/vnd.apple-pdf 25 foomatic-rip\n");\r | |
202 | fprintf(out, "Filter application/vnd.cups-command 0 commandtops\n");\r | |
203 | if (location[0])\r | |
204 | fprintf(out, "Location %s\n", location);\r | |
205 | fprintf(out, "ErrorPolicy abort-job\n");\r | |
206 | if (ka || lpc_acl)\r | |
207 | fprintf(out, "OpPolicy %s-policy\n", rp);\r | |
208 | else\r | |
209 | fprintf(out, "OpPolicy default\n");\r | |
210 | \r | |
211 | /* Access-control list. */\r | |
212 | if (ac)\r | |
213 | {\r | |
214 | if (ka)\r | |
215 | fprintf(out, "AuthType Negotiate\n");\r | |
216 | else\r | |
217 | fprintf(out, "AuthType Default\n");\r | |
218 | printer_user_list(out, "LIST", ac, "AllowUser");\r | |
219 | }\r | |
220 | \r | |
221 | if (banner == PRN_BANNER_NONE)\r | |
222 | fprintf(out, "JobSheets none none\n");\r | |
223 | else \r | |
224 | fprintf(out, "JobSheets athena none\n");\r | |
225 | fprintf(out, "</Printer>\n");\r | |
226 | \r | |
227 | }\r | |
228 | EXEC SQL CLOSE csr_printers;\r | |
229 | \r | |
230 | /* printers.conf entries for non-local CUPS queues */\r | |
231 | EXEC SQL DECLARE csr_remote_printers CURSOR FOR\r | |
232 | SELECT pr.rp, pr.name, pr.duplexname, pr.hwtype,\r | |
233 | m.name, pr.banner, pr.location, pr.contact, pr.ka,\r | |
234 | pr.ac, pr.lpc_acl, m.name as cupshosts\r | |
235 | FROM printers pr, machine m, serverhosts sh\r | |
236 | WHERE pr.rm = m.mach_id \r | |
237 | AND (pr.type = 'CLUSTER' or pr.type = 'DORM') AND m.name <> :spoolhost AND\r | |
238 | m.mach_id = sh.mach_id AND sh.service = 'CUPS-PRINT' AND \r | |
239 | sh.enable = 1 AND m.mach_id = sh.mach_id;\r | |
240 | \r | |
241 | EXEC SQL OPEN csr_remote_printers;\r | |
242 | while (1)\r | |
243 | {\r | |
244 | EXEC SQL FETCH csr_remote_printers INTO :rp, :name, :duplexname,\r | |
245 | :hwtype, :hostname, :banner, :location, :contact, :ka, :ac, :lpc_acl, :cupshosts;\r | |
246 | if (sqlca.sqlcode)\r | |
247 | break;\r | |
248 | \r | |
249 | strtrim(rp);\r | |
250 | strtrim(name);\r | |
251 | strtrim(duplexname);\r | |
252 | strtrim(hwtype);\r | |
253 | strtrim(hostname);\r | |
254 | strtrim(location);\r | |
255 | strtrim(contact);\r | |
256 | strtrim(cupshosts);\r | |
257 | strcpy(lowerhwtype, hwtype);\r | |
258 | for (p = rp; *p; p++) /* Because uppercased printer names suck */\r | |
259 | *p = tolower(*p);\r | |
260 | for (p = lowerhwtype; *p; p++)\r | |
261 | *p = tolower(*p);\r | |
262 | \r | |
263 | fprintf(out, "<Printer %s>\n",rp);\r | |
264 | fprintf(out, "Info %s:%s\n", rp, hwtype);\r | |
265 | fprintf(out, "DeviceURI ipp://%s:631/printers/%s\n", cupshosts, rp);\r | |
266 | fprintf(out, "State Idle\n"); // Always with the Idle\r | |
267 | fprintf(out, "StateTime %ld\n", (long)time(NULL));\r | |
268 | fprintf(out, "Accepting Yes\n");\r | |
269 | fprintf(out, "Shared Yes\n");\r | |
270 | fprintf(out, "QuotaPeriod 0\n");\r | |
271 | fprintf(out, "PageLimit 0\n");\r | |
272 | fprintf(out, "Klimit 0\n");\r | |
273 | fprintf(out, "Option sides one-sided\n");\r | |
274 | fprintf(out, "Filter application/vnd.cups-raw 0 -\n");\r | |
275 | fprintf(out, "Filter application/vnd.cups-postscript 100 foomatic-rip\n");\r | |
276 | fprintf(out, "Filter application/vnd.cups-pdf 0 foomatic-rip\n");\r | |
277 | fprintf(out, "Filter application/vnd.apple-pdf 25 foomatic-rip\n");\r | |
278 | fprintf(out, "Filter application/vnd.cups-command 0 commandtops\n");\r | |
279 | if (location[0])\r | |
280 | fprintf(out, "Location %s\n", location);\r | |
281 | fprintf(out, "ErrorPolicy abort-job\n");\r | |
282 | if (ka || lpc_acl)\r | |
283 | fprintf(out, "OpPolicy %s-policy\n", rp);\r | |
284 | else\r | |
285 | fprintf(out, "OpPolicy default\n");\r | |
286 | \r | |
287 | /* Access-control list. */\r | |
288 | if (ac)\r | |
289 | {\r | |
290 | if (ka)\r | |
291 | fprintf(out, "AuthType Negotiate\n");\r | |
292 | else\r | |
293 | fprintf(out, "AuthType Default\n");\r | |
294 | printer_user_list(out, "LIST", ac, "AllowUser");\r | |
295 | }\r | |
296 | \r | |
297 | if (banner == PRN_BANNER_NONE)\r | |
298 | fprintf(out, "JobSheets none none\n");\r | |
299 | else \r | |
300 | fprintf(out, "JobSheets athena none\n");\r | |
301 | fprintf(out, "</Printer>\n");\r | |
302 | \r | |
303 | }\r | |
304 | EXEC SQL CLOSE csr_remote_printers;\r | |
305 | \r | |
306 | /* printers.conf entries for non-local LPRng queues */\r | |
307 | EXEC SQL DECLARE csr_lprng_printers CURSOR FOR\r | |
308 | SELECT pr.rp, pr.name, pr.duplexname, pr.hwtype,\r | |
309 | m.name, pr.banner, pr.location, pr.contact, pr.ka,\r | |
310 | pr.ac, pr.lpc_acl, m.name as cupshosts\r | |
311 | FROM printers pr, machine m, serverhosts sh\r | |
312 | WHERE pr.rm = m.mach_id \r | |
313 | AND (pr.type = 'DORM' or pr.type = 'CLUSTER') AND m.name <> :spoolhost AND\r | |
314 | m.mach_id = sh.mach_id AND sh.service = 'PRINT' AND \r | |
315 | sh.enable = 1;\r | |
316 | \r | |
317 | EXEC SQL OPEN csr_lprng_printers;\r | |
318 | while (1)\r | |
319 | {\r | |
320 | EXEC SQL FETCH csr_lprng_printers INTO :rp, :name, :duplexname,\r | |
321 | :hwtype, :hostname, :banner, :location, :contact, :ka, :ac, :lpc_acl, :cupshosts;\r | |
322 | if (sqlca.sqlcode)\r | |
323 | break;\r | |
324 | \r | |
325 | strtrim(rp);\r | |
326 | strtrim(name);\r | |
327 | strtrim(duplexname);\r | |
328 | strtrim(hwtype);\r | |
329 | strtrim(hostname);\r | |
330 | strtrim(location);\r | |
331 | strtrim(contact);\r | |
332 | strtrim(cupshosts);\r | |
333 | strcpy(lowerhwtype, hwtype);\r | |
334 | for (p = rp; *p; p++) /* Because uppercased printer names suck */\r | |
335 | *p = tolower(*p);\r | |
336 | for (p = lowerhwtype; *p; p++)\r | |
337 | *p = tolower(*p);\r | |
338 | \r | |
339 | fprintf(out, "<Printer %s>\n",rp);\r | |
340 | fprintf(out, "Info %s:LPRng Queue on %s\n", rp, cupshosts);\r | |
341 | fprintf(out, "DeviceURI lpd://%s/%s\n", cupshosts, rp);\r | |
342 | fprintf(out, "State Idle\n"); // Always with the Idle\r | |
343 | fprintf(out, "StateTime %ld\n", (long)time(NULL));\r | |
344 | fprintf(out, "Accepting Yes\n");\r | |
345 | fprintf(out, "Shared Yes\n");\r | |
346 | fprintf(out, "QuotaPeriod 0\n");\r | |
347 | fprintf(out, "PageLimit 0\n");\r | |
348 | fprintf(out, "Klimit 0\n");\r | |
349 | fprintf(out, "Option sides one-sided\n");\r | |
350 | fprintf(out, "Filter application/vnd.cups-raw 0 -\n");\r | |
351 | fprintf(out, "Filter application/vnd.cups-postscript 100 foomatic-rip\n");\r | |
352 | fprintf(out, "Filter application/vnd.cups-pdf 0 foomatic-rip\n");\r | |
353 | fprintf(out, "Filter application/vnd.apple-pdf 25 foomatic-rip\n");\r | |
354 | fprintf(out, "Filter application/vnd.cups-command 0 commandtops\n");\r | |
355 | if (location[0])\r | |
356 | fprintf(out, "Location %s\n", location);\r | |
357 | fprintf(out, "ErrorPolicy abort-job\n");\r | |
358 | fprintf(out, "OpPolicy default\n");\r | |
359 | fprintf(out, "JobSheets none none\n");\r | |
360 | fprintf(out, "</Printer>\n");\r | |
361 | \r | |
362 | }\r | |
363 | EXEC SQL CLOSE csr_lprng_printers;\r | |
364 | tarfile_end(tf);\r | |
365 | \r | |
366 | \r | |
367 | /* aliases are in classes.conf */\r | |
368 | out = tarfile_start(tf, "/etc/cups/classes.conf", 0644, 0, 0,\r | |
369 | "lp", "lp", now);\r | |
370 | EXEC SQL DECLARE csr_duplexqs CURSOR FOR\r | |
371 | SELECT pr.rp, pr.name, pr.duplexname, pr.hwtype,\r | |
372 | m.name, pr.banner, pr.location, pr.contact, pr.ka, \r | |
373 | pr.type as prtype, pr.ac\r | |
374 | FROM printers pr, machine m, serverhosts sh\r | |
375 | WHERE pr.rm = m.mach_id \r | |
376 | AND m.mach_id = sh.mach_id AND sh.enable = 1 \r | |
377 | AND (pr.type = 'DORM' or pr.type = 'CLUSTER')\r | |
378 | AND (sh.service = 'CUPS-PRINT' OR sh.service = 'PRINT');\r | |
379 | EXEC SQL OPEN csr_duplexqs;\r | |
380 | while (1)\r | |
381 | {\r | |
382 | EXEC SQL FETCH csr_duplexqs INTO :rp, :name, :duplexname,\r | |
383 | :hwtype, :hostname, :banner, :location, :contact, :ka, :prtype, :ac;\r | |
384 | if (sqlca.sqlcode)\r | |
385 | break;\r | |
386 | \r | |
387 | strtrim(hwtype);\r | |
388 | strtrim(rp);\r | |
389 | strtrim(location);\r | |
390 | strtrim(contact);\r | |
391 | strtrim(prtype);\r | |
392 | \r | |
393 | /* Define alias queues as classes to the regular queues for\r | |
394 | * accounting reasons. Annoyingly, classes don't always inherit\r | |
395 | * their printer definitions.\r | |
396 | */\r | |
397 | if (!strcmp(prtype,"ALIAS")) \r | |
398 | {\r | |
399 | strtrim(name);\r | |
400 | fprintf(out, "<Class %s>\n",name);\r | |
401 | fprintf(out, "Info Alias Queue to %s:%s\n", rp, hwtype);\r | |
402 | fprintf(out, "Printer %s\n", rp);\r | |
403 | fprintf(out, "Option sides one-sided\n");\r | |
404 | fprintf(out, "State Idle\n"); // Always with the Idle\r | |
405 | fprintf(out, "StateTime %ld\n", (long)time(NULL));\r | |
406 | fprintf(out, "Accepting Yes\n");\r | |
407 | fprintf(out, "Shared Yes\n");\r | |
408 | fprintf(out, "QuotaPeriod 0\n");\r | |
409 | fprintf(out, "PageLimit 0\n");\r | |
410 | if (location[0])\r | |
411 | fprintf(out, "Location %s\n", location);\r | |
412 | /* fprintf(out, "ErrorPolicy abort-job\n"); */\r | |
413 | if (ka || lpc_acl)\r | |
414 | fprintf(out, "OpPolicy %s-policy\n", rp);\r | |
415 | else\r | |
416 | fprintf(out, "OpPolicy default\n");\r | |
417 | \r | |
418 | /* Access-control list. */\r | |
419 | if (ac)\r | |
420 | {\r | |
421 | if (ka)\r | |
422 | fprintf(out, "AuthType Negotiate\n");\r | |
423 | else\r | |
424 | fprintf(out, "AuthType Default\n");\r | |
425 | printer_user_list(out, "LIST", ac, "AllowUser");\r | |
426 | }\r | |
427 | \r | |
428 | if (banner == PRN_BANNER_NONE)\r | |
429 | fprintf(out, "JobSheets none none\n");\r | |
430 | else \r | |
431 | fprintf(out, "JobSheets athena none\n");\r | |
432 | fprintf(out, "</Class>\n");\r | |
433 | }\r | |
434 | \r | |
435 | /* Define duplex queues as aliases to the regular queues for\r | |
436 | * accounting reasons. Annoyingly, classes don't always inherit\r | |
437 | * their printer definitions.\r | |
438 | */\r | |
439 | if (*duplexname)\r | |
440 | {\r | |
441 | strtrim(duplexname);\r | |
442 | fprintf(out, "<Class %s>\n",duplexname);\r | |
443 | if (!strcmp(prtype,"ALIAS")) \r | |
444 | fprintf(out, "Info Duplex Alias Queue to %s:%s\n", rp, hwtype);\r | |
445 | else\r | |
446 | fprintf(out, "Info Duplex Queue for %s:%s\n", rp, hwtype);\r | |
447 | fprintf(out, "Option sides two-sided-long-edge\n"); // duplex\r | |
448 | fprintf(out, "Printer %s\n", rp);\r | |
449 | fprintf(out, "State Idle\n"); // Always with the Idle\r | |
450 | fprintf(out, "StateTime %ld\n", (long)time(NULL));\r | |
451 | fprintf(out, "Accepting Yes\n");\r | |
452 | fprintf(out, "Shared Yes\n");\r | |
453 | fprintf(out, "QuotaPeriod 0\n");\r | |
454 | fprintf(out, "PageLimit 0\n");\r | |
455 | if (location[0])\r | |
456 | fprintf(out, "Location %s\n", location);\r | |
457 | fprintf(out, "ErrorPolicy abort-job\n");\r | |
458 | if (ka || lpc_acl)\r | |
459 | fprintf(out, "OpPolicy %s-policy\n", rp);\r | |
460 | else\r | |
461 | fprintf(out, "OpPolicy default\n");\r | |
462 | \r | |
463 | /* Access-control list. */\r | |
464 | if (ac)\r | |
465 | {\r | |
466 | if (ka)\r | |
467 | fprintf(out, "AuthType Negotiate\n");\r | |
468 | else\r | |
469 | fprintf(out, "AuthType Default\n");\r | |
470 | printer_user_list(out, "LIST", ac, "AllowUser");\r | |
471 | }\r | |
472 | \r | |
473 | if (banner == PRN_BANNER_NONE)\r | |
474 | fprintf(out, "JobSheets none none\n");\r | |
475 | else if (banner == PRN_BANNER_LAST)\r | |
476 | fprintf(out, "JobSheets athena none\n");\r | |
477 | fprintf(out, "</Class>\n");\r | |
478 | }\r | |
479 | }\r | |
480 | EXEC SQL CLOSE csr_duplexqs;\r | |
481 | tarfile_end(tf);\r | |
482 | \r | |
483 | /* cups.conf */\r | |
484 | out = tarfile_start(tf, "/etc/cups/cupsd.conf", 0755, 1, 1,\r | |
485 | "root", "lp", now);\r | |
486 | \r | |
487 | fprintf(out, "LogLevel info\n");\r | |
488 | fprintf(out, "SystemGroup sys root ops-group\n");\r | |
489 | fprintf(out, "Port 631\n");\r | |
490 | fprintf(out, "Listen /var/run/cups/cups.sock\n");\r | |
491 | fprintf(out, "Browsing On\n");\r | |
492 | fprintf(out, "BrowseOrder allow,deny\n");\r | |
493 | fprintf(out, "BrowseAllow all\n");\r | |
494 | fprintf(out, "BrowseAddress @LOCAL\n");\r | |
495 | fprintf(out, "DefaultAuthType Negotiate\n");\r | |
496 | fprintf(out, "ServerCertificate /etc/cups/ssl/%s-ipp-crt.pem\n", lhost);\r | |
497 | fprintf(out, "ServerKey /etc/cups/ssl/%s-ipp-key.pem\n", lhost);\r | |
498 | fprintf(out, "ServerName %s\n", lhost);\r | |
499 | fprintf(out, "ServerAlias %s\n", phost);\r | |
500 | fprintf(out, "Krb5Keytab /etc/krb5-ipp.keytab\n");\r | |
501 | \r | |
502 | /* The other CUPS servers should be aware of the other hosts'\r | |
503 | queues, so we'll let them browse each other. */\r | |
504 | fprintf(out, "Include cups.local.conf\n");\r | |
505 | fprintf(out, "Include cups.locations.conf\n");\r | |
506 | fprintf(out, "Include cups.policies.conf\n");\r | |
507 | tarfile_end(tf);\r | |
508 | \r | |
509 | /* cups.hosts.conf */\r | |
510 | out = tarfile_start(tf, "/etc/cups/cups.hosts.conf", 0755, 1, 1,\r | |
511 | "root", "lp", now);\r | |
512 | EXEC SQL DECLARE csr_cupshosts CURSOR FOR\r | |
513 | SELECT m.name AS cupshosts FROM machine m, printservers ps\r | |
514 | WHERE m.mach_id = ps.mach_id AND ps.kind = 'CUPS';\r | |
515 | EXEC SQL OPEN csr_cupshosts;\r | |
516 | while (1)\r | |
517 | {\r | |
518 | EXEC SQL FETCH csr_cupshosts INTO :cupshosts;\r | |
519 | if (sqlca.sqlcode)\r | |
520 | break;\r | |
521 | \r | |
522 | strtrim(cupshosts);\r | |
523 | \r | |
524 | /* Don't poll yourself looking for answers! */\r | |
525 | if (strcmp(cupshosts,host))\r | |
526 | fprintf(out, "BrowsePoll %s\n", cupshosts);\r | |
527 | }\r | |
528 | EXEC SQL CLOSE csr_cupshosts;\r | |
529 | \r | |
530 | tarfile_end(tf);\r | |
531 | \r | |
532 | /* cups.policies.conf */\r | |
533 | out = tarfile_start(tf, "/etc/cups/cups.policies.conf", 0755, 1, 1,\r | |
534 | "root", "lp", now);\r | |
535 | fprintf(out, "# Printer-specific LPC and LPR ACLs\n");\r | |
536 | /* lpcaccess.top */\r | |
537 | EXEC SQL SELECT ps.lpc_acl INTO :top_lpc_acl\r | |
538 | FROM printservers ps, machine m\r | |
539 | WHERE m.name = :spoolhost AND m.mach_id = ps.mach_id;\r | |
540 | if (!sqlca.sqlcode && lpc_acl)\r | |
541 | {\r | |
542 | fprintf (out, "<Policy default>\n");\r | |
543 | fprintf (out, "%s\n", alterjob);\r | |
544 | fprintf (out, "AuthType Default\n");\r | |
545 | fprintf (out, "Require user @OWNER @SYSTEM\n");\r | |
546 | printer_user_list(out, "LIST", top_lpc_acl, "Require user");\r | |
547 | fprintf (out, "Order deny,allow\n");\r | |
548 | fprintf (out, "</Limit>\n");\r | |
549 | fprintf (out, "%s\n", submitjob);\r | |
550 | fprintf (out, "AuthType None\n");\r | |
551 | fprintf (out, "Order deny,allow\n");\r | |
552 | fprintf (out, "Allow from all\n");\r | |
553 | fprintf (out, "</Limit>\n");\r | |
554 | fprintf (out, "%s\n", alterpntr);\r | |
555 | fprintf (out, "AuthType Default\n");\r | |
556 | fprintf (out, "Require user @SYSTEM\n");\r | |
557 | fprintf (out, "Order deny,allow\n");\r | |
558 | fprintf (out, "</Limit>\n");\r | |
559 | fprintf (out, "%s\n", lpcpntr);\r | |
560 | fprintf (out, "AuthType Default\n");\r | |
561 | fprintf (out, "Require user @SYSTEM\n");\r | |
562 | printer_user_list(out, "LIST", top_lpc_acl, "Require user");\r | |
563 | fprintf (out, "Order deny,allow\n");\r | |
564 | fprintf (out, "</Limit>\n");\r | |
565 | fprintf (out, "%s\n", canceljob);\r | |
566 | fprintf (out, "AuthType Default\n");\r | |
567 | fprintf (out, "Require user @OWNER @SYSTEM\n");\r | |
568 | printer_user_list(out, "LIST", top_lpc_acl, "Require user");\r | |
569 | fprintf (out, "Order deny,allow\n");\r | |
570 | fprintf (out, "Allow from all\n");\r | |
571 | fprintf (out, "</Limit>\n");\r | |
572 | fprintf (out, "%s\n", catchall);\r | |
573 | fprintf (out, "AuthType None\n");\r | |
574 | fprintf (out, "Order deny,allow\n");\r | |
575 | fprintf (out, "Allow from all\n");\r | |
576 | fprintf (out, "</Limit>\n");\r | |
577 | fprintf (out, "</Policy>\n");\r | |
578 | }\r | |
579 | \r | |
580 | /* restrict lists and lpcaccess policies. Sadly, we have to put the\r | |
581 | top level for each new policy since CUPS doesn't have a way of \r | |
582 | doing it otherwise (well, Unix groups, but not moira) */\r | |
583 | EXEC SQL DECLARE csr_lpc CURSOR FOR\r | |
584 | SELECT UNIQUE rp, ka, ac, lpc_acl\r | |
585 | FROM printers\r | |
586 | WHERE (ac != 0 OR lpc_acl != 0) AND rm in (SELECT m.mach_id FROM machine m, serverhosts sh\r | |
587 | WHERE m.mach_id = sh.mach_id AND sh.service = 'CUPS-PRINT' AND sh.enable = 1);\r | |
588 | EXEC SQL OPEN csr_lpc;\r | |
589 | while (1)\r | |
590 | {\r | |
591 | EXEC SQL FETCH csr_lpc INTO :name, :ka, :ac, :lpc_acl;\r | |
592 | if (sqlca.sqlcode)\r | |
593 | break;\r | |
594 | \r | |
595 | strtrim(name);\r | |
596 | \r | |
597 | fprintf (out, "<Policy %s-policy>\n", name);\r | |
598 | fprintf (out, "%s\n", alterjob);\r | |
599 | fprintf (out, "AuthType Default\n");\r | |
600 | fprintf (out, "Require user @OWNER @SYSTEM\n");\r | |
601 | printer_user_list(out, "LIST", lpc_acl, "Require user");\r | |
602 | fprintf (out, "Order deny,allow\n");\r | |
603 | fprintf (out, "Allow from all\n");\r | |
604 | fprintf (out, "</Limit>\n");\r | |
605 | fprintf (out, "%s\n", submitjob);\r | |
606 | /* If the printer is Kerberized? */\r | |
607 | if (ka)\r | |
608 | fprintf (out, "AuthType Negotiate\n");\r | |
609 | else\r | |
610 | fprintf (out, "AuthType None\n");\r | |
611 | /* Access-control list. */\r | |
612 | if (ac)\r | |
613 | printer_user_list(out, "LIST", ac, "Require user");\r | |
614 | else if (ka)\r | |
615 | fprintf (out, "Require valid-user\n");\r | |
616 | fprintf (out, "Order deny,allow\n");\r | |
617 | fprintf (out, "Allow from all\n");\r | |
618 | fprintf (out, "</Limit>\n");\r | |
619 | fprintf (out, "%s\n", alterpntr);\r | |
620 | fprintf (out, "AuthType Default\n");\r | |
621 | fprintf (out, "Require user @SYSTEM\n");\r | |
622 | fprintf (out, "Order deny,allow\n");\r | |
623 | fprintf (out, "</Limit>\n");\r | |
624 | fprintf (out, "%s\n", lpcpntr);\r | |
625 | fprintf (out, "AuthType Default\n");\r | |
626 | fprintf (out, "Require user @SYSTEM\n");\r | |
627 | /* printer-specific lpc access. */\r | |
628 | if (lpc_acl)\r | |
629 | printer_user_list(out, "LIST", lpc_acl, "Require user");\r | |
630 | printer_user_list(out, "LIST", top_lpc_acl, "Require user");\r | |
631 | fprintf (out, "Order deny,allow\n");\r | |
632 | fprintf (out, "</Limit>\n");\r | |
633 | fprintf (out, "%s\n", canceljob);\r | |
634 | fprintf (out, "AuthType Default\n");\r | |
635 | fprintf (out, "Require user @OWNER @SYSTEM\n");\r | |
636 | printer_user_list(out, "LIST", lpc_acl, "Require user");\r | |
637 | printer_user_list(out, "LIST", top_lpc_acl, "Require user");\r | |
638 | fprintf (out, "Order deny,allow\n");\r | |
639 | fprintf (out, "Allow from all\n");\r | |
640 | fprintf (out, "</Limit>\n");\r | |
641 | fprintf (out, "%s\n", catchall);\r | |
642 | fprintf (out, "AuthType None\n");\r | |
643 | fprintf (out, "Order deny,allow\n");\r | |
644 | fprintf (out, "Allow from all\n");\r | |
645 | fprintf (out, "</Limit>\n");\r | |
646 | fprintf (out, "</Policy>\n");\r | |
647 | }\r | |
648 | EXEC SQL CLOSE csr_lpc;\r | |
649 | fprintf(out, "\n");\r | |
650 | tarfile_end(tf);\r | |
651 | tarfile_close(tf);\r | |
652 | }\r | |
653 | \r | |
654 | void sqlerr(void)\r | |
655 | {\r | |
656 | db_error(sqlca.sqlcode);\r | |
657 | }\r |