]>
Commit | Line | Data |
---|---|---|
1 | /* $Id$ | |
2 | * | |
3 | * This generates printcaps and other files for Athena print servers | |
4 | * | |
5 | * Copyright (C) 1992-1998 by the Massachusetts Institute of Technology. | |
6 | * For copying and distribution information, please see the file | |
7 | * <mit-copyright.h>. | |
8 | */ | |
9 | ||
10 | #include <mit-copyright.h> | |
11 | #include <moira.h> | |
12 | #include <moira_site.h> | |
13 | ||
14 | #include <sys/stat.h> | |
15 | #include <sys/types.h> | |
16 | ||
17 | #include <ctype.h> | |
18 | #include <stdio.h> | |
19 | #include <string.h> | |
20 | ||
21 | #include <time.h> | |
22 | #ifdef HAVE_KRB4 | |
23 | #include <krb.h> | |
24 | #endif | |
25 | #include <krb5.h> | |
26 | ||
27 | #include "util.h" | |
28 | ||
29 | EXEC SQL INCLUDE sqlca; | |
30 | ||
31 | RCSID("$Header$"); | |
32 | ||
33 | char *whoami = "cups-lpd-print.gen"; | |
34 | char *db = "moira/moira"; | |
35 | ||
36 | /* OMG, I hate this, but it's cleaner, I guess? */ | |
37 | ||
38 | void do_host(char *host); | |
39 | void sqlerr(void); | |
40 | #ifndef MAX | |
41 | #define MAX(a, b) ( (a) > (b) ? (a) : (b) ) | |
42 | #endif | |
43 | ||
44 | int main(int argc, char **argv) | |
45 | { | |
46 | EXEC SQL BEGIN DECLARE SECTION; | |
47 | char name[MACHINE_NAME_SIZE]; | |
48 | EXEC SQL END DECLARE SECTION; | |
49 | ||
50 | init_acls(); | |
51 | ||
52 | EXEC SQL CONNECT :db; | |
53 | ||
54 | EXEC SQL WHENEVER SQLERROR DO sqlerr(); | |
55 | ||
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; | |
60 | while (1) | |
61 | { | |
62 | EXEC SQL FETCH csr_hosts INTO :name; | |
63 | if (sqlca.sqlcode) | |
64 | break; | |
65 | ||
66 | strtrim(name); | |
67 | do_host(name); | |
68 | } | |
69 | EXEC SQL CLOSE csr_hosts; | |
70 | ||
71 | exit(MR_SUCCESS); | |
72 | } | |
73 | ||
74 | void printer_user_list(FILE *out, char *type, int id, char *str) | |
75 | { | |
76 | struct save_queue *sq; | |
77 | struct imember *m; | |
78 | ||
79 | sq = get_acl(type, id, NULL); | |
80 | while (sq_remove_data(sq, &m)) | |
81 | { | |
82 | if (m->type == 'U') | |
83 | fprintf(out, "%s %s\n", str, m->name); | |
84 | freeimember(m); | |
85 | } | |
86 | sq_destroy(sq); | |
87 | } | |
88 | ||
89 | ||
90 | ||
91 | void do_host(char *host) | |
92 | { | |
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; | |
101 | char *lhost; | |
102 | int ka, pc, ac, lpc_acl, top_lpc_acl, banner, rm; | |
103 | EXEC SQL END DECLARE SECTION; | |
104 | TARFILE *tf; | |
105 | FILE *out; | |
106 | char filename[MAXPATHLEN], *duptc; | |
107 | time_t mtime, now = time(NULL); | |
108 | ||
109 | lhost = (char *) strdup (host); | |
110 | for (p = lhost; *p; p++) | |
111 | *p = tolower(*p); | |
112 | ||
113 | sprintf(filename, "%s/cups-lpd/%s", DCM_DIR, host); | |
114 | tf = tarfile_open(filename); | |
115 | ||
116 | /* LPRng printers */ | |
117 | out = tarfile_start(tf, "/etc/cups/lprng.printers.txt", 0644, 0, 0, | |
118 | "root", "lp", now); | |
119 | ||
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; | |
128 | while (1) | |
129 | { | |
130 | EXEC SQL FETCH csr_lprng INTO :rp, :name, :duplexname, | |
131 | :hwtype, :hostname, :banner, :location, :contact, :ka, :ac, :prtype; | |
132 | if (sqlca.sqlcode) | |
133 | break; | |
134 | ||
135 | strtrim(rp); | |
136 | strtrim(name); | |
137 | strtrim(duplexname); | |
138 | strtrim(hwtype); | |
139 | strtrim(hostname); | |
140 | strtrim(location); | |
141 | strtrim(contact); | |
142 | strcpy(lowerhwtype, hwtype); | |
143 | for (p = lowerhwtype; *p; p++) | |
144 | *p = tolower(*p); | |
145 | for (p = name;*p;p++) | |
146 | *p = tolower(*p); | |
147 | for (p = duplexname;*p;p++) | |
148 | *p = tolower(*p); | |
149 | ||
150 | fprintf(out, "%s|%s|%s|%s|%s|%s\n", name,duplexname,hostname,location,hwtype,prtype); | |
151 | } | |
152 | EXEC SQL CLOSE csr_lprng; | |
153 | tarfile_end(tf); | |
154 | ||
155 | /* CUPS printers */ | |
156 | out = tarfile_start(tf, "/etc/cups/cups.printers.txt", 0644, 0, 0, | |
157 | "root", "lp", now); | |
158 | ||
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; | |
167 | while (1) | |
168 | { | |
169 | EXEC SQL FETCH csr_cups INTO :rp, :name, :duplexname, | |
170 | :hwtype, :hostname, :banner, :location, :contact, :ka, :ac, :prtype; | |
171 | if (sqlca.sqlcode) | |
172 | break; | |
173 | ||
174 | strtrim(rp); | |
175 | strtrim(name); | |
176 | strtrim(duplexname); | |
177 | strtrim(hwtype); | |
178 | strtrim(hostname); | |
179 | strtrim(location); | |
180 | strtrim(contact); | |
181 | strcpy(lowerhwtype, hwtype); | |
182 | for (p = lowerhwtype; *p; p++) | |
183 | *p = tolower(*p); | |
184 | for (p = name;*p;p++) | |
185 | *p = tolower(*p); | |
186 | for (p = duplexname;*p;p++) | |
187 | *p = tolower(*p); | |
188 | ||
189 | fprintf(out, "%s|%s|%s|%s|%s|%s\n", name,duplexname,hostname,location,hwtype,prtype); | |
190 | } | |
191 | EXEC SQL CLOSE csr_cups; | |
192 | tarfile_end(tf); | |
193 | tarfile_close(tf); | |
194 | } | |
195 | ||
196 | void sqlerr(void) | |
197 | { | |
198 | db_error(sqlca.sqlcode); | |
199 | } |