]>
Commit | Line | Data |
---|---|---|
7ac48069 | 1 | /* $Id$ |
bac4ceaa | 2 | * |
3 | * This generates the zone files necessary to load a hesiod server. | |
4 | * The following zones are generated: passwd, uid, pobox, group, | |
5 | * grplist, gid, filsys, cluster, pcap, sloc, service. | |
6 | * | |
7ac48069 | 7 | * (c) Copyright 1988-1998 by the Massachusetts Institute of Technology. |
8 | * For copying and distribution information, please see the file | |
9 | * <mit-copyright.h>. | |
bac4ceaa | 10 | */ |
11 | ||
12 | #include <mit-copyright.h> | |
bac4ceaa | 13 | #include <moira.h> |
14 | #include <moira_site.h> | |
7ac48069 | 15 | |
bac4ceaa | 16 | #include <sys/stat.h> |
7ac48069 | 17 | |
18 | #include <stdio.h> | |
19 | #include <stdlib.h> | |
9c04b191 | 20 | #include <string.h> |
7ac48069 | 21 | |
22 | #include "util.h" | |
23 | ||
bac4ceaa | 24 | EXEC SQL INCLUDE sqlca; |
25 | ||
7ac48069 | 26 | RCSID("$Header$"); |
bac4ceaa | 27 | |
9c04b191 | 28 | #ifndef HTYPE |
e14de0ca | 29 | #define HTYPE "TXT" |
9c04b191 | 30 | #endif |
31 | #ifndef HCLASS | |
d8aec3bb | 32 | #define HCLASS "" |
9c04b191 | 33 | #endif |
34 | ||
35 | #ifndef HESIOD_SUBDIR | |
36 | #define HESIOD_SUBDIR "hesiod" | |
bac4ceaa | 37 | #endif |
38 | ||
5eaef520 | 39 | /* max number of bytes of a data record that can be returned in a hesiod |
d8aec3bb | 40 | * query. This is 512 - overhead (~78) [derived empirically] |
41 | * (it used to be 446 with older versions of bind) | |
4821a398 | 42 | */ |
a32927ab | 43 | #define MAXHESSIZE 256 |
4821a398 | 44 | |
dfaf9b68 | 45 | char hesiod_dir[MAXPATHLEN]; |
bac4ceaa | 46 | |
5eaef520 | 47 | #define min(x, y) ((x) < (y) ? (x) : (y)) |
bac4ceaa | 48 | struct hash *machines = NULL; |
49 | struct hash *users = NULL; | |
50 | char *whoami = "hesiod.gen"; | |
9c04b191 | 51 | char *db = "moira/moira"; |
bac4ceaa | 52 | |
53 | struct grp { | |
5eaef520 | 54 | struct grp *next; |
55 | char *lid; | |
bac4ceaa | 56 | }; |
57 | struct user { | |
dfaf9b68 | 58 | char name[USERS_LOGIN_SIZE]; |
5eaef520 | 59 | struct grp *lists; |
bac4ceaa | 60 | }; |
61 | ||
7ac48069 | 62 | /* |
63 | * Modified from sys/types.h: | |
64 | */ | |
65 | int setsize; /* = howmany(setbits, NSETBITS) */ | |
66 | ||
67 | typedef long set_mask; | |
68 | #define NSETBITS (sizeof(set_mask) * NBBY) /* bits per mask */ | |
69 | #ifndef howmany | |
70 | #define howmany(x, y) (((x) + ((y) - 1)) / (y)) | |
71 | #endif | |
72 | ||
73 | #define SET_SET(n, p) ((p)[(n)/NSETBITS] |= (1 << ((n) % NSETBITS))) | |
74 | #define SET_CLR(n, p) ((p)[(n)/NSETBITS] &= ~(1 << ((n) % NSETBITS))) | |
75 | #define SET_ISSET(n, p) ((p)[(n)/NSETBITS] & (1 << ((n) % NSETBITS))) | |
76 | #define SET_CREATE() (malloc(setsize * sizeof(set_mask))) | |
77 | #define SET_ZERO(p) memset(p, 0, setsize * sizeof(set_mask)) | |
78 | #define SET_CMP(p1, p2) (memcmp(p1, p2, setsize * sizeof(set_mask))) | |
79 | ||
80 | ||
81 | void get_mach(void); | |
82 | int nbitsset(set_mask *set); | |
2203d8f9 | 83 | int valid(char *name); |
7ac48069 | 84 | |
85 | int do_passwd(void); | |
86 | int do_groups(void); | |
87 | int do_filsys(void); | |
88 | int do_cluster(void); | |
89 | int do_printcap(void); | |
7ac48069 | 90 | int do_sloc(void); |
91 | int do_service(void); | |
bac4ceaa | 92 | |
5eaef520 | 93 | int main(int argc, char **argv) |
bac4ceaa | 94 | { |
5eaef520 | 95 | char cmd[64]; |
96 | struct stat sb; | |
97 | int changed = 0; | |
98 | ||
99 | if (argc > 2) | |
100 | { | |
101 | fprintf(stderr, "usage: %s [outfile]\n", argv[0]); | |
102 | exit(MR_ARGS); | |
bac4ceaa | 103 | } |
104 | ||
5eaef520 | 105 | initialize_sms_error_table(); |
106 | sprintf(hesiod_dir, "%s/%s", DCM_DIR, HESIOD_SUBDIR); | |
107 | ||
108 | EXEC SQL CONNECT :db; | |
109 | ||
110 | changed = do_passwd(); | |
111 | changed += do_filsys(); | |
112 | changed += do_cluster(); | |
113 | changed += do_printcap(); | |
5eaef520 | 114 | changed += do_sloc(); |
115 | changed += do_service(); | |
116 | changed += do_groups(); | |
117 | ||
118 | if (!changed) | |
119 | { | |
120 | fprintf(stderr, "No files updated.\n"); | |
121 | if (argc == 2 && stat(argv[1], &sb) == 0) | |
122 | exit(MR_NO_CHANGE); | |
bac4ceaa | 123 | } |
124 | ||
5eaef520 | 125 | if (argc == 2) |
126 | { | |
127 | fprintf(stderr, "Building tar file.\n"); | |
128 | sprintf(cmd, "cd %s; tar cf %s .", hesiod_dir, argv[1]); | |
129 | if (system(cmd)) | |
130 | exit(MR_TAR_FAIL); | |
bac4ceaa | 131 | } |
132 | ||
5eaef520 | 133 | exit(MR_SUCCESS); |
bac4ceaa | 134 | } |
135 | ||
136 | ||
7ac48069 | 137 | void get_mach(void) |
bac4ceaa | 138 | { |
5eaef520 | 139 | EXEC SQL BEGIN DECLARE SECTION; |
140 | int id; | |
dfaf9b68 | 141 | char name[MACHINE_NAME_SIZE]; |
5eaef520 | 142 | EXEC SQL END DECLARE SECTION; |
143 | ||
144 | if (machines) | |
145 | return; | |
146 | ||
147 | machines = create_hash(1000); | |
148 | EXEC SQL DECLARE m_cursor CURSOR FOR | |
149 | SELECT name, mach_id | |
150 | FROM machine | |
151 | WHERE status = 1 and mach_id != 0 | |
152 | ORDER BY mach_id; | |
153 | EXEC SQL OPEN m_cursor; | |
154 | while (1) | |
155 | { | |
156 | EXEC SQL FETCH m_cursor INTO :name, :id; | |
157 | if (sqlca.sqlcode) | |
158 | break; | |
2203d8f9 | 159 | strtrim(name); |
160 | if (!valid(name)) | |
161 | continue; | |
162 | hash_store(machines, id, strdup(name)); | |
5eaef520 | 163 | } |
164 | if (sqlca.sqlcode < 0) | |
165 | db_error(sqlca.sqlcode); | |
166 | EXEC SQL CLOSE m_cursor; | |
167 | EXEC SQL COMMIT; | |
bac4ceaa | 168 | } |
169 | ||
170 | ||
2203d8f9 | 171 | /* Determine whether or not a name is a valid DNS label. |
172 | (Can't start or end with . or have two .s in a row) */ | |
173 | int valid(char *name) | |
174 | { | |
175 | int sawdot; | |
176 | ||
177 | for (sawdot = 1; *name; name++) | |
178 | { | |
179 | if (*name == '.') | |
180 | { | |
181 | if (sawdot) | |
182 | return 0; | |
183 | else | |
184 | sawdot = 1; | |
185 | } | |
186 | else | |
187 | sawdot = 0; | |
188 | } | |
189 | return !sawdot; | |
190 | } | |
191 | ||
192 | ||
5eaef520 | 193 | int do_passwd(void) |
bac4ceaa | 194 | { |
5eaef520 | 195 | FILE *pout, *uout, *bout; |
dfaf9b68 | 196 | char poutf[MAXPATHLEN], uoutf[MAXPATHLEN], poutft[MAXPATHLEN]; |
197 | char uoutft[MAXPATHLEN], boutf[MAXPATHLEN], boutft[MAXPATHLEN]; | |
5eaef520 | 198 | struct user *u; |
199 | char *mach; | |
200 | EXEC SQL BEGIN DECLARE SECTION; | |
dfaf9b68 | 201 | char login[USERS_LOGIN_SIZE], shell[USERS_SHELL_SIZE]; |
202 | char fullname[USERS_FULLNAME_SIZE], oa[USERS_OFFICE_ADDR_SIZE]; | |
203 | char op[USERS_OFFICE_PHONE_SIZE], hp[USERS_HOME_PHONE_SIZE]; | |
d353b64a | 204 | char nn[USERS_NICKNAME_SIZE], potype[USERS_POTYPE_SIZE]; |
22bbb6f0 | 205 | int uid, id, pid, iid, eid, mid, status; |
5eaef520 | 206 | EXEC SQL END DECLARE SECTION; |
207 | ||
208 | sprintf(poutf, "%s/passwd.db", hesiod_dir); | |
209 | sprintf(uoutf, "%s/uid.db", hesiod_dir); | |
210 | sprintf(boutf, "%s/pobox.db", hesiod_dir); | |
211 | ||
5eaef520 | 212 | sprintf(poutft, "%s~", poutf); |
213 | pout = fopen(poutft, "w"); | |
214 | if (!pout) | |
215 | { | |
216 | perror("cannot open passwd.db~ for write"); | |
217 | exit(MR_OCONFIG); | |
218 | } | |
219 | sprintf(uoutft, "%s~", uoutf); | |
220 | uout = fopen(uoutft, "w"); | |
221 | if (!uout) | |
222 | { | |
223 | perror("cannot open uid.db~ for write"); | |
224 | exit(MR_OCONFIG); | |
225 | } | |
226 | sprintf(boutft, "%s~", boutf); | |
227 | bout = fopen(boutft, "w"); | |
228 | if (!bout) | |
229 | { | |
230 | perror("cannot open pobox.db for write"); | |
231 | exit(MR_OCONFIG); | |
bac4ceaa | 232 | } |
bac4ceaa | 233 | |
5eaef520 | 234 | fprintf(stderr, "Building passwd.db, uid.db, and pobox.db\n"); |
235 | get_mach(); | |
236 | ||
237 | users = create_hash(12001); | |
238 | EXEC SQL DECLARE u_cursor CURSOR FOR | |
239 | SELECT login, unix_uid, shell, fullname, nickname, office_addr, | |
22bbb6f0 | 240 | office_phone, home_phone, users_id, potype, pop_id, imap_id, exchange_id, |
241 | status | |
5eaef520 | 242 | FROM users |
3fe4e44d | 243 | WHERE status = 1 OR status = 2 OR status = 5 OR status = 6 |
5eaef520 | 244 | ORDER BY users_id; |
245 | EXEC SQL OPEN u_cursor; | |
246 | while (1) | |
247 | { | |
248 | EXEC SQL FETCH u_cursor INTO :login, :uid, :shell, :fullname, :nn, | |
22bbb6f0 | 249 | :oa, :op, :hp, :id, :potype, :pid, :iid, :eid, :status; |
5eaef520 | 250 | if (sqlca.sqlcode) |
251 | break; | |
252 | strtrim(login); | |
253 | dequote(fullname); | |
254 | dequote(nn); | |
255 | dequote(oa); | |
256 | dequote(op); | |
257 | dequote(hp); | |
258 | dequote(shell); | |
d353b64a | 259 | dequote(potype); |
5eaef520 | 260 | u = malloc(sizeof(struct user)); |
261 | strcpy(u->name, login); | |
262 | u->lists = NULL; | |
263 | hash_store(users, id, u); | |
45116bc1 | 264 | if (status == 1 || status == 2) |
5eaef520 | 265 | { |
266 | fprintf(pout, "%s.passwd\t%s %s \"%s:*:%d:101:%s,%s,%s,%s,%s:/mit/%s:%s\"\n", | |
267 | login, HCLASS, HTYPE, login, uid, fullname, nn, oa, | |
268 | op, hp, login, shell); | |
269 | fprintf(uout, "%d.uid\t%s CNAME %s.passwd\n", uid, HCLASS, login); | |
270 | } | |
46c8036a | 271 | |
22bbb6f0 | 272 | if (eid != 0) |
273 | pid = eid; | |
274 | ||
46c8036a | 275 | if (iid != 0) |
276 | { | |
277 | EXEC SQL SELECT mach_id INTO :mid FROM filesys | |
278 | WHERE filsys_id = :iid AND type = 'IMAP'; | |
279 | if (sqlca.sqlcode == 0) | |
280 | pid = mid; | |
281 | } | |
282 | ||
d353b64a | 283 | if ((strcmp(potype, "NONE") != 0) && pid != 0 && |
284 | (mach = hash_lookup(machines, pid))) | |
5eaef520 | 285 | { |
286 | fprintf(bout, "%s.pobox\t%s %s \"POP %s %s\"\n", | |
287 | login, HCLASS, HTYPE, mach, login); | |
288 | } | |
bac4ceaa | 289 | } |
5eaef520 | 290 | if (sqlca.sqlcode < 0) |
291 | db_error(sqlca.sqlcode); | |
292 | EXEC SQL CLOSE u_cursor; | |
293 | EXEC SQL COMMIT; | |
294 | ||
295 | if (fclose(pout) || fclose(uout) || fclose(bout)) | |
296 | { | |
297 | fprintf(stderr, "Unsuccessful file close of passwd.db, uid.db, or pobox.db\n"); | |
298 | exit(MR_CCONFIG); | |
299 | } | |
300 | fix_file(poutf); | |
301 | fix_file(uoutf); | |
302 | fix_file(boutf); | |
303 | return 1; | |
bac4ceaa | 304 | } |
305 | ||
306 | ||
5eaef520 | 307 | int do_groups(void) |
bac4ceaa | 308 | { |
5eaef520 | 309 | FILE *iout, *gout, *lout; |
dfaf9b68 | 310 | char ioutf[MAXPATHLEN], goutf[MAXPATHLEN], loutf[MAXPATHLEN]; |
311 | char buf[MAXPATHLEN], *l; | |
5eaef520 | 312 | struct hash *groups; |
44d12d58 | 313 | struct bucket *b, **p; |
5eaef520 | 314 | struct grp *g; |
315 | struct user *u; | |
5eaef520 | 316 | EXEC SQL BEGIN DECLARE SECTION; |
dfaf9b68 | 317 | char name[LIST_NAME_SIZE]; |
a589d269 | 318 | int gid, id, lid, len; |
5eaef520 | 319 | EXEC SQL END DECLARE SECTION; |
320 | ||
321 | /* open files */ | |
322 | sprintf(ioutf, "%s/gid.db", hesiod_dir); | |
323 | sprintf(goutf, "%s/group.db", hesiod_dir); | |
324 | sprintf(loutf, "%s/grplist.db", hesiod_dir); | |
325 | ||
5eaef520 | 326 | sprintf(buf, "%s~", ioutf); |
327 | iout = fopen(buf, "w"); | |
328 | if (!iout) | |
329 | { | |
330 | perror("cannot open gid.db for write"); | |
331 | exit(MR_OCONFIG); | |
332 | } | |
333 | sprintf(buf, "%s~", goutf); | |
334 | gout = fopen(buf, "w"); | |
335 | if (!gout) | |
336 | { | |
337 | perror("cannot open group.db for write"); | |
338 | exit(MR_OCONFIG); | |
339 | } | |
340 | sprintf(buf, "%s~", loutf); | |
341 | lout = fopen(buf, "w"); | |
342 | if (!lout) | |
343 | { | |
344 | perror("cannot open grplist.db for write"); | |
345 | exit(MR_OCONFIG); | |
346 | } | |
347 | ||
348 | fprintf(stderr, "Building gid.db, group.db, and grplist.db\n"); | |
349 | ||
350 | /* make space for group list */ | |
351 | groups = create_hash(15001); | |
352 | ||
353 | /* The following WHENEVER is declarative, not executed, | |
354 | * and applies for the remainder of this file only. | |
355 | */ | |
356 | EXEC SQL WHENEVER SQLERROR GOTO sqlerr; | |
357 | ||
358 | EXEC SQL DECLARE l_cursor CURSOR FOR | |
359 | SELECT name, gid, list_id | |
360 | FROM list | |
361 | WHERE grouplist != 0 AND active != 0 | |
362 | ORDER BY list_id; | |
363 | EXEC SQL OPEN l_cursor; | |
364 | while (1) | |
365 | { | |
dfaf9b68 | 366 | char buf[LIST_NAME_SIZE + 10]; |
367 | ||
5eaef520 | 368 | EXEC SQL FETCH l_cursor INTO :name, :gid, :lid; |
369 | if (sqlca.sqlcode) | |
370 | break; | |
371 | strtrim(name); | |
2203d8f9 | 372 | if (!valid(name)) |
373 | continue; | |
5eaef520 | 374 | sprintf(buf, "%s:%d", name, gid); |
7ac48069 | 375 | hash_store(groups, lid, strdup(buf)); |
5eaef520 | 376 | fprintf(iout, "%d.gid\t%s CNAME %s.group\n", gid, HCLASS, name); |
377 | fprintf(gout, "%s.group\t%s %s \"%s:*:%d:\"\n", | |
378 | name, HCLASS, HTYPE, name, gid); | |
379 | } | |
380 | EXEC SQL CLOSE l_cursor; | |
381 | ||
382 | fflush(iout); | |
383 | fflush(gout); | |
384 | ||
385 | /* now do grplists */ | |
386 | if (!users) | |
387 | { | |
388 | users = create_hash(12001); | |
389 | EXEC SQL DECLARE u_cursor2 CURSOR FOR | |
390 | SELECT users_id, login | |
391 | FROM users | |
b449828e | 392 | WHERE status = 1 OR status = 2; |
5eaef520 | 393 | EXEC SQL OPEN u_cursor2; |
394 | while (1) | |
395 | { | |
396 | EXEC SQL FETCH u_cursor2 INTO :id, :name; | |
397 | if (sqlca.sqlcode) | |
398 | break; | |
399 | u = malloc(sizeof(struct user)); | |
400 | strcpy(u->name, strtrim(name)); | |
401 | u->lists = NULL; | |
402 | hash_store(users, id, u); | |
bac4ceaa | 403 | } |
5eaef520 | 404 | EXEC SQL CLOSE u_cursor2; |
405 | } | |
406 | ||
407 | EXEC SQL DECLARE i_cursor CURSOR FOR | |
b449828e | 408 | SELECT m.list_id, m.member_id |
409 | FROM imembers m, list l | |
410 | WHERE m.member_type = 'USER' | |
411 | AND m.list_id = l.list_id AND l.grouplist = 1 AND l.nfsgroup = 1; | |
5eaef520 | 412 | EXEC SQL OPEN i_cursor; |
413 | while (1) | |
414 | { | |
415 | EXEC SQL FETCH i_cursor INTO :lid, :id; | |
416 | if (sqlca.sqlcode) | |
417 | break; | |
7ac48069 | 418 | if ((l = hash_lookup(groups, lid)) && (u = hash_lookup(users, id))) |
5eaef520 | 419 | { |
420 | g = malloc(sizeof(struct grp)); | |
421 | g->next = u->lists; | |
422 | u->lists = g; | |
423 | g->lid = l; | |
bac4ceaa | 424 | } |
425 | } | |
5eaef520 | 426 | EXEC SQL CLOSE i_cursor; |
427 | ||
428 | EXEC SQL COMMIT; | |
429 | ||
430 | for (p = &(users->data[users->size - 1]); p >= users->data; p--) | |
431 | { | |
432 | for (b = *p; b; b = b->next) | |
433 | { | |
434 | if (!(g = ((struct user *)b->data)->lists)) | |
435 | continue; | |
436 | fprintf(lout, "%s.grplist\t%s %s \"", | |
437 | ((struct user *)b->data)->name, HCLASS, HTYPE); | |
438 | len = 0; | |
439 | for (; g; g = g->next) | |
440 | { | |
441 | if (len + strlen(g->lid) + 1 < MAXHESSIZE) | |
442 | { | |
443 | fputs(g->lid, lout); | |
444 | if (g->next) | |
445 | putc(':', lout); | |
446 | len += strlen(g->lid) + 1; | |
447 | } | |
448 | else | |
449 | { | |
450 | com_err(whoami, 0, "truncated grp list for user %s", | |
451 | ((struct user *)b->data)->name); | |
452 | break; | |
4821a398 | 453 | } |
bac4ceaa | 454 | } |
5eaef520 | 455 | fputs("\"\n", lout); |
bac4ceaa | 456 | } |
457 | } | |
458 | ||
5eaef520 | 459 | if (fclose(iout) || fclose(gout) || fclose(lout)) |
460 | { | |
461 | fprintf(stderr, "Unsuccessful close of gid.db, group.db, or grplist.db\n"); | |
462 | exit(MR_CCONFIG); | |
bac4ceaa | 463 | } |
5eaef520 | 464 | fix_file(ioutf); |
465 | fix_file(goutf); | |
466 | fix_file(loutf); | |
467 | return 1; | |
468 | sqlerr: | |
469 | db_error(sqlca.sqlcode); | |
470 | return 0; | |
bac4ceaa | 471 | } |
472 | ||
473 | ||
5eaef520 | 474 | int do_filsys(void) |
bac4ceaa | 475 | { |
5eaef520 | 476 | FILE *out; |
dfaf9b68 | 477 | char outf[MAXPATHLEN], outft[MAXPATHLEN], *mach, *group; |
7ac48069 | 478 | struct save_queue *sq, *sq2; |
5eaef520 | 479 | EXEC SQL BEGIN DECLARE SECTION; |
dfaf9b68 | 480 | char name[FILESYS_LABEL_SIZE], type[FILESYS_TYPE_SIZE]; |
481 | char loc[FILESYS_NAME_SIZE], access[FILESYS_RWACCESS_SIZE]; | |
482 | char mount[FILESYS_MOUNT_SIZE], comments[FILESYS_COMMENTS_SIZE]; | |
483 | char key[FSGROUP_KEY_SIZE]; | |
484 | char aname[ALIAS_NAME_SIZE], trans[ALIAS_TRANS_SIZE]; | |
a589d269 | 485 | int flag, id, fid; |
5eaef520 | 486 | EXEC SQL END DECLARE SECTION; |
487 | ||
488 | sprintf(outf, "%s/filsys.db", hesiod_dir); | |
489 | ||
5eaef520 | 490 | sprintf(outft, "%s~", outf); |
491 | out = fopen(outft, "w"); | |
492 | if (!out) | |
493 | { | |
494 | perror("cannot open filsys.db for write"); | |
495 | exit(MR_OCONFIG); | |
496 | } | |
497 | ||
498 | fprintf(stderr, "Building filsys.db\n"); | |
499 | get_mach(); | |
500 | sq = sq_create(); | |
501 | sq2 = sq_create(); | |
502 | ||
503 | EXEC SQL DECLARE f_cursor CURSOR FOR | |
504 | SELECT label, type, name, mach_id, rwaccess, mount, comments, filsys_id | |
505 | FROM filesys | |
506 | ORDER BY filsys_id; | |
507 | EXEC SQL OPEN f_cursor; | |
508 | while (1) | |
509 | { | |
510 | EXEC SQL FETCH f_cursor INTO :name, :type, :loc, :id, :access, | |
511 | :mount, :comments, :fid; | |
512 | if (sqlca.sqlcode) | |
513 | break; | |
2203d8f9 | 514 | strtrim(name); |
515 | if (!valid(name)) | |
516 | continue; | |
5eaef520 | 517 | strtrim(type); |
518 | if (!strcmp(type, "NFS") || !strcmp(type, "RVD")) | |
519 | { | |
7ac48069 | 520 | if ((mach = hash_lookup(machines, id))) |
5eaef520 | 521 | { |
522 | fprintf(out, "%s.filsys\t%s %s \"%s %s %s %s %s\"\n", | |
2203d8f9 | 523 | name, HCLASS, HTYPE, type, strtrim(loc), |
5eaef520 | 524 | mach, strtrim(access), strtrim(mount)); |
bac4ceaa | 525 | } |
5eaef520 | 526 | } |
527 | else if (!strcmp(type, "AFS")) | |
528 | { | |
529 | fprintf(out, "%s.filsys\t%s %s \"AFS %s %s %s\"\n", | |
2203d8f9 | 530 | name, HCLASS, HTYPE, strtrim(loc), |
5eaef520 | 531 | strtrim(access), strtrim(mount)); |
532 | } | |
533 | else if (!strcmp(type, "ERR")) | |
534 | { | |
535 | fprintf(out, "%s.filsys\t%s %s \"ERR %s\"\n", | |
2203d8f9 | 536 | name, HCLASS, HTYPE, strtrim(comments)); |
5eaef520 | 537 | } |
538 | else if (!strcmp(type, "FSGROUP")) | |
539 | { | |
dfaf9b68 | 540 | char buf[FILESYS_NAME_SIZE + 10]; |
2203d8f9 | 541 | sprintf(buf, "%s:%d", name, fid); |
dfaf9b68 | 542 | sq_save_data(sq, strdup(buf)); |
5eaef520 | 543 | } |
544 | else if (!strcmp(type, "MUL")) | |
545 | { | |
dfaf9b68 | 546 | char buf[FILESYS_NAME_SIZE + 10]; |
2203d8f9 | 547 | sprintf(buf, "%s:%d", name, fid); |
dfaf9b68 | 548 | sq_save_data(sq2, strdup(buf)); |
bac4ceaa | 549 | } |
550 | } | |
5eaef520 | 551 | EXEC SQL CLOSE f_cursor; |
552 | ||
553 | while (sq_get_data(sq, &group)) | |
554 | { | |
555 | fid = atoi(strchr(group, ':') + 1); | |
556 | *strchr(group, ':') = 0; | |
557 | ||
558 | EXEC SQL DECLARE f_cursor2 CURSOR FOR | |
559 | SELECT DISTINCT f.type, f.name, f.mach_id, f.rwaccess, f.mount, | |
560 | f.comments, f.label, g.key | |
561 | FROM filesys f, fsgroup g | |
562 | WHERE f.filsys_id = g.filsys_id AND g.group_id = :fid | |
563 | ORDER BY key, label; | |
564 | EXEC SQL OPEN f_cursor2; | |
a589d269 | 565 | for (flag = 1; ; flag++) |
5eaef520 | 566 | { |
567 | EXEC SQL FETCH f_cursor2 INTO :type, :loc, :id, :access, :mount, | |
dfaf9b68 | 568 | :comments, :name, :key; |
5eaef520 | 569 | if (sqlca.sqlcode) |
570 | break; | |
571 | strtrim(type); | |
572 | if (!strcmp(type, "NFS") || !strcmp(type, "RVD")) | |
573 | { | |
7ac48069 | 574 | if ((mach = hash_lookup(machines, id))) |
5eaef520 | 575 | { |
576 | fprintf(out, "%s.filsys\t%s %s \"%s %s %s %s %s %d\"\n", | |
577 | group, HCLASS, HTYPE, type, strtrim(loc), mach, | |
a589d269 | 578 | strtrim(access), strtrim(mount), flag); |
bac4ceaa | 579 | } |
5eaef520 | 580 | } |
581 | else if (!strcmp(type, "AFS")) | |
582 | { | |
583 | fprintf(out, "%s.filsys\t%s %s \"AFS %s %s %s %d\"\n", | |
584 | group, HCLASS, HTYPE, strtrim(loc), strtrim(access), | |
a589d269 | 585 | strtrim(mount), flag); |
5eaef520 | 586 | } |
587 | else if (!strcmp(type, "ERR")) | |
588 | { | |
589 | fprintf(out, "%s.filsys\t%s %s \"ERR %s\"\n", | |
590 | group, HCLASS, HTYPE, strtrim(comments)); | |
bac4ceaa | 591 | } |
592 | } | |
5eaef520 | 593 | EXEC SQL CLOSE f_cursor2; |
594 | free(group); | |
595 | } | |
596 | sq_destroy(sq); | |
597 | ||
598 | while (sq_get_data(sq2, &group)) | |
599 | { | |
600 | fid = atoi(strchr(group, ':') + 1); | |
601 | *strchr(group, ':') = 0; | |
602 | fprintf(out, "%s.filsys\t%s %s \"MUL", group, HCLASS, HTYPE); | |
603 | EXEC SQL DECLARE f_cursor3 CURSOR FOR | |
604 | SELECT DISTINCT f.label, g.key | |
605 | FROM filesys f, fsgroup g | |
606 | WHERE f.filsys_id = g.filsys_id AND g.group_id = :fid | |
607 | ORDER BY key, label; | |
608 | EXEC SQL OPEN f_cursor3; | |
609 | while (1) | |
610 | { | |
dfaf9b68 | 611 | EXEC SQL FETCH f_cursor3 INTO :name, :key; |
5eaef520 | 612 | if (sqlca.sqlcode) |
613 | break; | |
614 | fprintf(out, " %s", strtrim(name)); | |
542bdacb | 615 | } |
5eaef520 | 616 | EXEC SQL CLOSE f_cursor3; |
617 | fprintf(out, "\"\n"); | |
618 | free(group); | |
619 | } | |
620 | sq_destroy(sq2); | |
621 | ||
622 | EXEC SQL DECLARE a_cursor CURSOR FOR | |
623 | SELECT name, trans | |
624 | FROM alias | |
625 | WHERE type = 'FILESYS'; | |
626 | EXEC SQL OPEN a_cursor; | |
627 | while (1) | |
628 | { | |
dfaf9b68 | 629 | EXEC SQL FETCH a_cursor INTO :aname, :trans; |
5eaef520 | 630 | if (sqlca.sqlcode) |
631 | break; | |
2203d8f9 | 632 | strtrim(aname); |
633 | strtrim(trans); | |
634 | if (!valid(aname) || !valid(trans)) | |
635 | continue; | |
5eaef520 | 636 | fprintf(out, "%s.filsys\t%s CNAME %s.filsys\n", |
2203d8f9 | 637 | aname, HCLASS, trans); |
5eaef520 | 638 | } |
639 | EXEC SQL CLOSE a_cursor; | |
640 | ||
641 | EXEC SQL COMMIT; | |
642 | ||
643 | if (fclose(out)) | |
644 | { | |
645 | fprintf(stderr, "Unsuccessful close of filsys.db\n"); | |
646 | exit(MR_CCONFIG); | |
647 | } | |
648 | fix_file(outf); | |
649 | return 1; | |
650 | sqlerr: | |
651 | db_error(sqlca.sqlcode); | |
652 | return 0; | |
bac4ceaa | 653 | } |
654 | ||
dfaf9b68 | 655 | int nbitsset(set_mask *set) |
bac4ceaa | 656 | { |
5eaef520 | 657 | int i, ret; |
658 | ret = 0; | |
659 | for (i = 0; i < setsize * NSETBITS; i++) | |
660 | { | |
bac4ceaa | 661 | if (SET_ISSET(i, set)) |
662 | ret++; | |
5eaef520 | 663 | } |
664 | return ret; | |
bac4ceaa | 665 | } |
666 | ||
667 | ||
5eaef520 | 668 | int do_cluster(void) |
bac4ceaa | 669 | { |
5eaef520 | 670 | FILE *out; |
dfaf9b68 | 671 | char outf[MAXPATHLEN], outft[MAXPATHLEN], *mach; |
672 | char machbuf[MACHINE_NAME_SIZE], clubuf[CLUSTERS_NAME_SIZE], *p; | |
5eaef520 | 673 | EXEC SQL BEGIN DECLARE SECTION; |
a589d269 | 674 | int maxmach, maxclu, mid, cid, id; |
dfaf9b68 | 675 | char name[CLUSTERS_NAME_SIZE]; |
676 | char label[SVC_SERV_LABEL_SIZE], data[SVC_SERV_CLUSTER_SIZE]; | |
5eaef520 | 677 | EXEC SQL END DECLARE SECTION; |
678 | set_mask **machs, *ms, *ps; | |
5eaef520 | 679 | |
680 | sprintf(outf, "%s/cluster.db", hesiod_dir); | |
681 | ||
5eaef520 | 682 | sprintf(outft, "%s~", outf); |
683 | out = fopen(outft, "w"); | |
684 | if (!out) | |
685 | { | |
686 | perror("cannot open cluster.db for write"); | |
687 | exit(MR_OCONFIG); | |
688 | } | |
689 | ||
690 | fprintf(stderr, "Building cluster.db\n"); | |
691 | get_mach(); | |
692 | ||
693 | EXEC SQL SELECT MAX(clu_id) INTO :maxclu FROM clusters; | |
694 | maxclu++; | |
695 | setsize = howmany(maxclu, NSETBITS); | |
696 | ||
697 | EXEC SQL SELECT MAX(mach_id) INTO :maxmach FROM machine; | |
698 | maxmach++; | |
699 | machs = malloc((maxmach + 1) * sizeof(set_mask **)); | |
700 | memset(machs, 0, (maxmach + 1) * sizeof(int)); | |
701 | ||
702 | EXEC SQL DECLARE p_cursor CURSOR FOR | |
703 | SELECT mach_id, clu_id | |
704 | FROM mcmap | |
705 | ORDER BY mach_id; | |
706 | EXEC SQL OPEN p_cursor; | |
707 | while (1) | |
708 | { | |
709 | EXEC SQL FETCH p_cursor INTO :mid, :cid; | |
710 | if (sqlca.sqlcode) | |
711 | break; | |
712 | if (!(ms = machs[mid])) | |
713 | { | |
714 | ms = machs[mid] = SET_CREATE(); | |
715 | SET_ZERO(ms); | |
716 | } | |
717 | SET_SET(cid, ms); | |
718 | } | |
719 | EXEC SQL CLOSE p_cursor; | |
720 | ||
721 | for (mid = 1; mid < maxmach; mid++) | |
722 | { | |
723 | if (!machs[mid]) | |
724 | continue; | |
725 | ms = machs[mid]; | |
726 | if (nbitsset(ms) > 1) | |
727 | { | |
ed7faf49 | 728 | sprintf(clubuf, "mrinternal-%d", mid); |
5eaef520 | 729 | for (cid = 1; cid < maxclu; cid++) |
730 | { | |
731 | if (SET_ISSET(cid, ms)) | |
732 | { | |
733 | EXEC SQL DECLARE d_cursor CURSOR FOR | |
734 | SELECT serv_label, serv_cluster | |
735 | FROM svc | |
736 | WHERE clu_id = :cid; | |
737 | EXEC SQL OPEN d_cursor; | |
738 | while (1) | |
739 | { | |
dfaf9b68 | 740 | EXEC SQL FETCH d_cursor INTO :label, :data; |
5eaef520 | 741 | if (sqlca.sqlcode) |
742 | break; | |
dfaf9b68 | 743 | strtrim(label); |
5eaef520 | 744 | strtrim(data); |
ed7faf49 | 745 | fprintf(out, "%s.cluster\t%s %s \"%s %s\"\n", |
dfaf9b68 | 746 | clubuf, HCLASS, HTYPE, label, data); |
bac4ceaa | 747 | } |
5eaef520 | 748 | EXEC SQL CLOSE d_cursor; |
bac4ceaa | 749 | } |
750 | } | |
5eaef520 | 751 | } |
752 | else | |
753 | { | |
5eaef520 | 754 | for (cid = 1; cid < maxclu; cid++) |
755 | if (SET_ISSET(cid, ms)) | |
756 | break; | |
757 | ||
758 | EXEC SQL SELECT name INTO :name FROM clusters WHERE clu_id = :cid; | |
759 | strtrim(name); | |
2203d8f9 | 760 | if (!valid(name)) |
761 | continue; | |
ed7faf49 | 762 | strcpy(clubuf, name); |
bac4ceaa | 763 | } |
764 | ||
5eaef520 | 765 | if ((mach = hash_lookup(machines, mid))) |
766 | { | |
ed7faf49 | 767 | fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n", |
768 | mach, HCLASS, clubuf); | |
5eaef520 | 769 | for (p = machbuf; *mach && *mach != '.'; mach++) |
770 | *p++ = *mach; | |
ed7faf49 | 771 | if (!strcasecmp(mach, ".mit.edu")) |
5eaef520 | 772 | { |
ed7faf49 | 773 | *p = '\0'; |
9c04b191 | 774 | fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n", |
ed7faf49 | 775 | machbuf, HCLASS, clubuf); |
5eaef520 | 776 | } |
bac4ceaa | 777 | } |
5eaef520 | 778 | for (id = mid + 1; id < maxmach; id++) |
779 | { | |
780 | if ((ps = machs[id]) && !SET_CMP(ms, ps)) | |
781 | { | |
782 | free(ps); | |
783 | machs[id] = NULL; | |
784 | if ((mach = hash_lookup(machines, id))) | |
785 | { | |
ed7faf49 | 786 | fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n", |
787 | mach, HCLASS, clubuf); | |
5eaef520 | 788 | for (p = machbuf; *mach && *mach != '.'; mach++) |
789 | *p++ = *mach; | |
ed7faf49 | 790 | if (!strcasecmp(mach, ".mit.edu")) |
5eaef520 | 791 | { |
ed7faf49 | 792 | *p = '\0'; |
9c04b191 | 793 | fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n", |
ed7faf49 | 794 | machbuf, HCLASS, clubuf); |
5eaef520 | 795 | } |
bac4ceaa | 796 | } |
797 | } | |
798 | } | |
5eaef520 | 799 | free(ms); |
800 | machs[mid] = NULL; | |
801 | } | |
802 | ||
803 | EXEC SQL DECLARE d_cursor2 CURSOR FOR | |
804 | SELECT c.name, d.serv_label, d.serv_cluster | |
805 | FROM svc d, clusters c | |
806 | WHERE c.clu_id = d.clu_id; | |
807 | EXEC SQL OPEN d_cursor2; | |
808 | while (1) | |
809 | { | |
dfaf9b68 | 810 | EXEC SQL FETCH d_cursor2 INTO :name, :label, :data; |
5eaef520 | 811 | if (sqlca.sqlcode) |
812 | break; | |
813 | strtrim(name); | |
2203d8f9 | 814 | if (!valid(name)) |
815 | continue; | |
dfaf9b68 | 816 | strtrim(label); |
5eaef520 | 817 | strtrim(data); |
818 | fprintf(out, "%s.cluster\t%s %s \"%s %s\"\n", | |
dfaf9b68 | 819 | name, HCLASS, HTYPE, label, data); |
5eaef520 | 820 | } |
821 | free(machs); | |
822 | EXEC SQL COMMIT; | |
823 | ||
824 | if (fclose(out)) | |
825 | { | |
826 | fprintf(stderr, "Unsuccessful close of cluster.db\n"); | |
827 | exit(MR_CCONFIG); | |
828 | } | |
829 | fix_file(outf); | |
830 | return 1; | |
831 | sqlerr: | |
832 | db_error(sqlca.sqlcode); | |
833 | return 0; | |
bac4ceaa | 834 | } |
835 | ||
836 | ||
5eaef520 | 837 | int do_printcap(void) |
bac4ceaa | 838 | { |
5eaef520 | 839 | FILE *out; |
dfaf9b68 | 840 | char outf[MAXPATHLEN], outft[MAXPATHLEN]; |
5eaef520 | 841 | EXEC SQL BEGIN DECLARE SECTION; |
ed9a436f | 842 | char name[PRINTERS_NAME_SIZE], duplexname[PRINTERS_DUPLEXNAME_SIZE]; |
843 | char rp[PRINTERS_RP_SIZE], type[PRINTERS_TYPE_SIZE]; | |
88b66768 | 844 | char duplexrp[PRINTERS_RP_SIZE], pskind[PRINTSERVERS_KIND_SIZE]; |
a589d269 | 845 | int ka, rm, mc; |
5eaef520 | 846 | EXEC SQL END DECLARE SECTION; |
88b66768 | 847 | char *rmname; |
5eaef520 | 848 | |
849 | sprintf(outf, "%s/printcap.db", hesiod_dir); | |
850 | ||
5eaef520 | 851 | sprintf(outft, "%s~", outf); |
852 | out = fopen(outft, "w"); | |
853 | if (!out) | |
854 | { | |
855 | perror("cannot open printcap.db for write"); | |
856 | exit(MR_OCONFIG); | |
857 | } | |
858 | ||
859 | fprintf(stderr, "Building printcap.db\n"); | |
860 | get_mach(); | |
861 | ||
862 | EXEC SQL DECLARE p_cursor2 CURSOR FOR | |
5d1420f5 | 863 | SELECT p.name, p.duplexname, p.type, p.rp, p.rm, p.ka, p.mc, ps.kind |
88b66768 | 864 | FROM printers p, printservers ps |
865 | WHERE p.rm = ps.mach_id; | |
5eaef520 | 866 | EXEC SQL OPEN p_cursor2; |
867 | while (1) | |
868 | { | |
ed9a436f | 869 | EXEC SQL FETCH p_cursor2 INTO :name, :duplexname, :type, |
5d1420f5 | 870 | :rp, :rm, :ka, :mc, :pskind; |
5eaef520 | 871 | if (sqlca.sqlcode) |
872 | break; | |
ed9a436f | 873 | if (!(rmname = hash_lookup(machines, rm))) |
5eaef520 | 874 | continue; |
875 | strtrim(name); | |
2203d8f9 | 876 | if (!valid(name)) |
877 | continue; | |
5eaef520 | 878 | strtrim(rp); |
5d1420f5 | 879 | fprintf(out, "%s.pcap\t%s %s \"%s:rp=%s:rm=%s:ka#%d:mc#%d:", |
880 | name, HCLASS, HTYPE, name, rp, rmname, ka, mc); | |
88b66768 | 881 | |
882 | strtrim(pskind); | |
883 | if (!strcmp(pskind, "BSD")) | |
884 | fprintf(out, "auth=none:remote_support=RQM:"); | |
885 | else if (!strcmp(pskind, "ATHENA")) | |
00b3c5aa | 886 | { |
887 | fprintf(out, "auth=%s:az:remote_support=RQM:", | |
888 | ka ? "kerberos4" : "none"); | |
889 | } | |
88b66768 | 890 | else if (!strcmp(pskind, "LPRNG")) |
891 | fprintf(out, "auth=kerberos5:xn:"); | |
892 | ||
893 | fputs("\"\n", out); | |
bac4ceaa | 894 | |
ed9a436f | 895 | strtrim(duplexname); |
896 | if (!valid(duplexname)) | |
897 | continue; | |
898 | if (!strcmp(strtrim(type), "ALIAS")) | |
5eaef520 | 899 | { |
ed9a436f | 900 | EXEC SQL SELECT duplexname INTO :duplexrp |
901 | FROM printers WHERE name = :rp; | |
902 | strtrim(duplexrp); | |
5eaef520 | 903 | } |
ed9a436f | 904 | else |
905 | strcpy(duplexrp, duplexname); | |
5d1420f5 | 906 | fprintf(out, "%s.pcap\t%s %s \"%s:rp=%s:rm=%s:ka#%d:mc#%d:", |
ed9a436f | 907 | duplexname, HCLASS, HTYPE, duplexname, duplexrp, |
5d1420f5 | 908 | rmname, ka, mc); |
88b66768 | 909 | |
910 | if (!strcmp(pskind, "BSD")) | |
911 | fprintf(out, "auth=none:remote_support=RQM:"); | |
912 | else if (!strcmp(pskind, "ATHENA")) | |
00b3c5aa | 913 | { |
914 | fprintf(out, "auth=%s:az:remote_support=RQM:", | |
915 | ka ? "kerberos4" : "none"); | |
916 | } | |
88b66768 | 917 | else if (!strcmp(pskind, "LPRNG")) |
918 | fprintf(out, "auth=kerberos5:xn:"); | |
919 | ||
920 | fputs("\"\n", out); | |
5eaef520 | 921 | } |
ed9a436f | 922 | EXEC SQL CLOSE p_cursor2; |
5eaef520 | 923 | |
924 | EXEC SQL COMMIT; | |
925 | ||
926 | if (fclose(out)) | |
927 | { | |
ed9a436f | 928 | fprintf(stderr, "Unsuccessful close of pcap.db\n"); |
5eaef520 | 929 | exit(MR_CCONFIG); |
930 | } | |
931 | fix_file(outf); | |
932 | return 1; | |
933 | sqlerr: | |
934 | db_error(sqlca.sqlcode); | |
935 | return 0; | |
bac4ceaa | 936 | } |
937 | ||
938 | ||
5eaef520 | 939 | int do_sloc(void) |
bac4ceaa | 940 | { |
5eaef520 | 941 | FILE *out; |
dfaf9b68 | 942 | char outf[MAXPATHLEN], outft[MAXPATHLEN], *mach; |
5eaef520 | 943 | EXEC SQL BEGIN DECLARE SECTION; |
dfaf9b68 | 944 | char service[SERVERHOSTS_SERVICE_SIZE]; |
a589d269 | 945 | int id; |
5eaef520 | 946 | EXEC SQL END DECLARE SECTION; |
947 | ||
948 | sprintf(outf, "%s/sloc.db", hesiod_dir); | |
949 | ||
5eaef520 | 950 | sprintf(outft, "%s~", outf); |
951 | out = fopen(outft, "w"); | |
952 | if (!out) | |
953 | { | |
954 | perror("cannot open sloc.db for write"); | |
955 | exit(MR_OCONFIG); | |
956 | } | |
957 | ||
958 | fprintf(stderr, "Building sloc.db\n"); | |
959 | get_mach(); | |
960 | ||
961 | EXEC SQL DECLARE s_cursor CURSOR FOR | |
962 | SELECT DISTINCT service, mach_id | |
963 | FROM serverhosts | |
964 | ORDER BY service; | |
965 | EXEC SQL OPEN s_cursor; | |
966 | while (1) | |
967 | { | |
968 | EXEC SQL FETCH s_cursor INTO :service, :id; | |
969 | if (sqlca.sqlcode) | |
970 | break; | |
971 | strtrim(service); | |
2203d8f9 | 972 | if (valid(service) && (mach = hash_lookup(machines, id))) |
5eaef520 | 973 | fprintf(out, "%s.sloc\t%s %s %s\n", service, HCLASS, HTYPE, mach); |
974 | } | |
975 | EXEC SQL CLOSE s_cursor; | |
976 | ||
977 | EXEC SQL COMMIT; | |
978 | ||
979 | if (fclose(out)) | |
980 | { | |
981 | fprintf(stderr, "Unsuccessful close of sloc.db\n"); | |
982 | exit(MR_CCONFIG); | |
983 | } | |
984 | ||
985 | fix_file(outf); | |
986 | return 1; | |
987 | sqlerr: | |
988 | db_error(sqlca.sqlcode); | |
989 | return 0; | |
bac4ceaa | 990 | } |
991 | ||
5eaef520 | 992 | int do_service(void) |
bac4ceaa | 993 | { |
5eaef520 | 994 | FILE *out; |
dfaf9b68 | 995 | char outf[MAXPATHLEN], outft[MAXPATHLEN]; |
5eaef520 | 996 | EXEC SQL BEGIN DECLARE SECTION; |
dfaf9b68 | 997 | char service[SERVICES_NAME_SIZE], protocol[SERVICES_PROTOCOL_SIZE]; |
998 | char aname[ALIAS_NAME_SIZE], trans[ALIAS_TRANS_SIZE]; | |
a589d269 | 999 | int port; |
5eaef520 | 1000 | EXEC SQL END DECLARE SECTION; |
1001 | ||
1002 | sprintf(outf, "%s/service.db", hesiod_dir); | |
1003 | ||
5eaef520 | 1004 | sprintf(outft, "%s~", outf); |
1005 | out = fopen(outft, "w"); | |
1006 | if (!out) | |
1007 | { | |
1008 | perror("cannot open service.db for write"); | |
1009 | exit(MR_OCONFIG); | |
1010 | } | |
1011 | ||
1012 | fprintf(stderr, "Building service.db\n"); | |
1013 | ||
1014 | EXEC SQL DECLARE s_cursor2 CURSOR FOR | |
1015 | SELECT name, protocol, port | |
1016 | FROM services; | |
1017 | EXEC SQL OPEN s_cursor2; | |
1018 | while (1) | |
1019 | { | |
1020 | EXEC SQL FETCH s_cursor2 INTO :service, :protocol, :port; | |
1021 | if (sqlca.sqlcode) | |
1022 | break; | |
1023 | lowercase(protocol); /* Convert protocol to lowercase */ | |
1024 | strtrim(service); | |
2203d8f9 | 1025 | if (!valid(service)) |
1026 | continue; | |
5eaef520 | 1027 | strtrim(protocol); |
1028 | fprintf(out, "%s.service\t%s %s \"%s %s %d\"\n", | |
1029 | service, HCLASS, HTYPE, service, protocol, port); | |
1030 | } | |
1031 | EXEC SQL CLOSE s_cursor2; | |
1032 | ||
1033 | EXEC SQL DECLARE a_cursor3 CURSOR FOR | |
1034 | SELECT name, trans | |
1035 | FROM alias | |
1036 | WHERE type = 'SERVICE'; | |
1037 | EXEC SQL OPEN a_cursor3; | |
1038 | while (1) | |
1039 | { | |
dfaf9b68 | 1040 | EXEC SQL FETCH a_cursor3 INTO :aname, :trans; |
5eaef520 | 1041 | if (sqlca.sqlcode) |
1042 | break; | |
dfaf9b68 | 1043 | strtrim(aname); |
1044 | strtrim(trans); | |
2203d8f9 | 1045 | if (!valid(aname) || !valid(trans)) |
1046 | continue; | |
dfaf9b68 | 1047 | fprintf(out, "%s.service\t%s CNAME %s.service\n", aname, HCLASS, |
1048 | trans); | |
5eaef520 | 1049 | } |
1050 | EXEC SQL CLOSE a_cursor3; | |
1051 | ||
1052 | EXEC SQL COMMIT; | |
1053 | ||
1054 | if (fclose(out)) | |
1055 | { | |
1056 | fprintf(stderr, "Unsuccessful close of service.db\n"); | |
1057 | exit(MR_CCONFIG); | |
1058 | } | |
1059 | fix_file(outf); | |
1060 | return 1; | |
1061 | sqlerr: | |
1062 | db_error(sqlca.sqlcode); | |
1063 | return 0; | |
bac4ceaa | 1064 | } |