]> andersk Git - moira.git/blob - gen/cups-lpd.pc
cups-lpd DCM.
[moira.git] / gen / cups-lpd.pc
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-lpd-print.gen";\r
34 char *db = "moira/moira";\r
35 \r
36 /* OMG, I hate this, but it's cleaner, I guess? */\r
37 \r
38 void do_host(char *host);\r
39 void sqlerr(void);\r
40 #ifndef MAX\r
41 #define MAX(a, b) ( (a) > (b) ? (a) : (b) )\r
42 #endif\r
43 \r
44 int main(int argc, char **argv)\r
45 {\r
46   EXEC SQL BEGIN DECLARE SECTION;\r
47   char name[MACHINE_NAME_SIZE];\r
48   EXEC SQL END DECLARE SECTION;\r
49 \r
50   init_acls();\r
51 \r
52   EXEC SQL CONNECT :db;\r
53 \r
54   EXEC SQL WHENEVER SQLERROR DO sqlerr();\r
55 \r
56   EXEC SQL DECLARE csr_hosts CURSOR FOR\r
57     SELECT m.name FROM machine m, serverhosts sh\r
58     WHERE m.mach_id = sh.mach_id AND sh.service = 'CUPS-LPD' AND sh.enable = 1;\r
59   EXEC SQL OPEN csr_hosts;\r
60   while (1)\r
61     {\r
62       EXEC SQL FETCH csr_hosts INTO :name;\r
63       if (sqlca.sqlcode)\r
64         break;\r
65 \r
66       strtrim(name);\r
67       do_host(name);\r
68     }\r
69   EXEC SQL CLOSE csr_hosts;\r
70 \r
71   exit(MR_SUCCESS);\r
72 }\r
73 \r
74 void printer_user_list(FILE *out, char *type, int id, char *str)\r
75 {\r
76   struct save_queue *sq;\r
77   struct imember *m;\r
78 \r
79   sq = get_acl(type, id, NULL);\r
80   while (sq_remove_data(sq, &m))\r
81     {\r
82       if (m->type == 'U')\r
83         fprintf(out, "%s %s\n", str, m->name);\r
84       freeimember(m);\r
85     }\r
86   sq_destroy(sq);\r
87 }\r
88 \r
89 \r
90 \r
91 void do_host(char *host)\r
92 {\r
93   EXEC SQL BEGIN DECLARE SECTION;\r
94   char rp[PRINTERS_RP_SIZE], name[PRINTERS_NAME_SIZE];\r
95   char duplexname[PRINTERS_DUPLEXNAME_SIZE], location[PRINTERS_LOCATION_SIZE];\r
96   char hwtype[PRINTERS_HWTYPE_SIZE], lowerhwtype[PRINTERS_HWTYPE_SIZE];\r
97   char modtime[PRINTERS_MODTIME_SIZE], lmodtime[LIST_MODTIME_SIZE];\r
98   char contact[PRINTERS_CONTACT_SIZE], hostname[MACHINE_NAME_SIZE];\r
99   char cupshosts[MACHINE_NAME_SIZE], prtype [PRINTERS_TYPE_SIZE];\r
100   char *spoolhost = host, *unixtime_fmt = UNIXTIME_FMT, *p;\r
101   char *lhost;\r
102   int ka, pc, ac, lpc_acl, top_lpc_acl, banner, rm;\r
103   EXEC SQL END DECLARE SECTION;\r
104   TARFILE *tf;\r
105   FILE *out;\r
106   char filename[MAXPATHLEN], *duptc;\r
107   time_t mtime, now = time(NULL);\r
108 \r
109   lhost = (char *) strdup (host);\r
110   for (p = lhost; *p; p++)\r
111      *p = tolower(*p);\r
112 \r
113   sprintf(filename, "%s/cups-lpd/%s", DCM_DIR, host);\r
114   tf = tarfile_open(filename);\r
115 \r
116   /* LPRng printers */\r
117   out = tarfile_start(tf, "/etc/cups/lprng.printers.txt", 0644, 0, 0,\r
118                       "root", "lp", now);\r
119 \r
120   EXEC SQL DECLARE csr_lprng CURSOR FOR\r
121     SELECT pr.rp, pr.name, pr.duplexname, pr.hwtype,\r
122     m.name, pr.banner, pr.location, pr.contact, pr.ka,\r
123     pr.ac, pr.type as prtype\r
124     FROM printers pr, machine m, serverhosts sh\r
125     WHERE m.mach_id = sh.mach_id AND sh.service = 'PRINT' AND sh.enable = 1\r
126     AND pr.rm = m.mach_id ORDER BY pr.name;\r
127   EXEC SQL OPEN csr_lprng;\r
128   while (1)\r
129     {\r
130       EXEC SQL FETCH csr_lprng INTO :rp, :name, :duplexname,\r
131         :hwtype, :hostname, :banner, :location, :contact, :ka, :ac, :prtype;\r
132       if (sqlca.sqlcode)\r
133         break;\r
134 \r
135       strtrim(rp);\r
136       strtrim(name);\r
137       strtrim(duplexname);\r
138       strtrim(hwtype);\r
139       strtrim(hostname);\r
140       strtrim(location);\r
141       strtrim(contact);\r
142       strcpy(lowerhwtype, hwtype);\r
143       for (p = lowerhwtype; *p; p++)\r
144         *p = tolower(*p);\r
145       for (p = name;*p;p++)\r
146         *p = tolower(*p);\r
147       for (p = duplexname;*p;p++)\r
148         *p = tolower(*p);\r
149 \r
150       fprintf(out, "%s|%s|%s|%s|%s|%s\n", name,duplexname,hostname,location,hwtype,prtype);\r
151     }\r
152   EXEC SQL CLOSE csr_lprng;\r
153   tarfile_end(tf);\r
154 \r
155   /* CUPS printers */\r
156   out = tarfile_start(tf, "/etc/cups/cups.printers.txt", 0644, 0, 0,\r
157                       "root", "lp", now);\r
158 \r
159   EXEC SQL DECLARE csr_cups CURSOR FOR\r
160     SELECT pr.rp, pr.name, pr.duplexname, pr.hwtype,\r
161     m.name, pr.banner, pr.location, pr.contact, pr.ka,\r
162     pr.ac, pr.type as prtype\r
163     FROM printers pr, machine m, serverhosts sh\r
164     WHERE m.mach_id = sh.mach_id AND sh.service = 'CUPS-PRINT' AND sh.enable = 1\r
165     AND pr.rm = m.mach_id ORDER BY pr.name;\r
166   EXEC SQL OPEN csr_cups;\r
167   while (1)\r
168     {\r
169       EXEC SQL FETCH csr_cups INTO :rp, :name, :duplexname,\r
170         :hwtype, :hostname, :banner, :location, :contact, :ka, :ac, :prtype;\r
171       if (sqlca.sqlcode)\r
172         break;\r
173 \r
174       strtrim(rp);\r
175       strtrim(name);\r
176       strtrim(duplexname);\r
177       strtrim(hwtype);\r
178       strtrim(hostname);\r
179       strtrim(location);\r
180       strtrim(contact);\r
181       strcpy(lowerhwtype, hwtype);\r
182       for (p = lowerhwtype; *p; p++)\r
183         *p = tolower(*p);\r
184       for (p = name;*p;p++)\r
185         *p = tolower(*p);\r
186       for (p = duplexname;*p;p++)\r
187         *p = tolower(*p);\r
188 \r
189       fprintf(out, "%s|%s|%s|%s|%s|%s\n", name,duplexname,hostname,location,hwtype,prtype);\r
190     }\r
191   EXEC SQL CLOSE csr_cups;\r
192   tarfile_end(tf);\r
193   tarfile_close(tf);\r
194 }\r
195 \r
196 void sqlerr(void)\r
197 {\r
198   db_error(sqlca.sqlcode);\r
199 }\r
This page took 0.054089 seconds and 5 git commands to generate.