-/* $Header$
+/* $Id$
*
* This generates the zone files necessary to load a hesiod server.
* The following zones are generated: passwd, uid, pobox, group,
* grplist, gid, filsys, cluster, pcap, sloc, service.
*
- * (c) Copyright 1988, 1990 by the Massachusetts Institute of Technology.
- * For copying and distribution information, please see the file
- * <mit-copyright.h>.
+ * (c) Copyright 1988-1998 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, please see the file
+ * <mit-copyright.h>.
*/
#include <mit-copyright.h>
-#include <stdio.h>
-#include <stdlib.h>
#include <moira.h>
#include <moira_site.h>
-#include <sys/types.h>
+
#include <sys/stat.h>
-#include <sys/time.h>
-#include <ctype.h>
+
+#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
+
+#include "util.h"
+
EXEC SQL INCLUDE sqlca;
+RCSID("$Header$");
#ifndef HTYPE
#define HTYPE "TXT"
#endif
#ifndef HCLASS
-#define HCLASS "IN"
+#define HCLASS ""
#endif
#ifndef HESIOD_SUBDIR
#endif
/* max number of bytes of a data record that can be returned in a hesiod
- * query. This is 512 - overhead (~66) [derived empirically]
+ * query. This is 512 - overhead (~78) [derived empirically]
+ * (it used to be 446 with older versions of bind)
*/
-#define MAXHESSIZE 446
+#define MAXHESSIZE 256
-char hesiod_dir[64];
+char hesiod_dir[MAXPATHLEN];
#define min(x, y) ((x) < (y) ? (x) : (y))
struct hash *machines = NULL;
char *lid;
};
struct user {
- char name[9];
+ char name[USERS_LOGIN_SIZE];
struct grp *lists;
};
+/*
+ * Modified from sys/types.h:
+ */
+int setsize; /* = howmany(setbits, NSETBITS) */
+
+typedef long set_mask;
+#define NSETBITS (sizeof(set_mask) * NBBY) /* bits per mask */
+#ifndef howmany
+#define howmany(x, y) (((x) + ((y) - 1)) / (y))
+#endif
+
+#define SET_SET(n, p) ((p)[(n)/NSETBITS] |= (1 << ((n) % NSETBITS)))
+#define SET_CLR(n, p) ((p)[(n)/NSETBITS] &= ~(1 << ((n) % NSETBITS)))
+#define SET_ISSET(n, p) ((p)[(n)/NSETBITS] & (1 << ((n) % NSETBITS)))
+#define SET_CREATE() (malloc(setsize * sizeof(set_mask)))
+#define SET_ZERO(p) memset(p, 0, setsize * sizeof(set_mask))
+#define SET_CMP(p1, p2) (memcmp(p1, p2, setsize * sizeof(set_mask)))
+
+
+void get_mach(void);
+int nbitsset(set_mask *set);
+int valid(char *name);
+
+int do_passwd(void);
+int do_groups(void);
+int do_filsys(void);
+int do_cluster(void);
+int do_printcap(void);
+int do_sloc(void);
+int do_service(void);
int main(int argc, char **argv)
{
changed += do_filsys();
changed += do_cluster();
changed += do_printcap();
- changed += do_palladium();
changed += do_sloc();
changed += do_service();
changed += do_groups();
}
-get_mach(void)
+void get_mach(void)
{
EXEC SQL BEGIN DECLARE SECTION;
int id;
- char name[41];
+ char name[MACHINE_NAME_SIZE];
EXEC SQL END DECLARE SECTION;
if (machines)
EXEC SQL FETCH m_cursor INTO :name, :id;
if (sqlca.sqlcode)
break;
- hash_store(machines, id, strsave(strtrim(name)));
+ strtrim(name);
+ if (!valid(name))
+ continue;
+ hash_store(machines, id, strdup(name));
}
if (sqlca.sqlcode < 0)
db_error(sqlca.sqlcode);
}
+/* Determine whether or not a name is a valid DNS label.
+ (Can't start or end with . or have two .s in a row) */
+int valid(char *name)
+{
+ int sawdot;
+
+ for (sawdot = 1; *name; name++)
+ {
+ if (*name == '$')
+ return 0;
+ if (*name == '.')
+ {
+ if (sawdot)
+ return 0;
+ else
+ sawdot = 1;
+ }
+ else
+ sawdot = 0;
+ }
+ return !sawdot;
+}
+
+
int do_passwd(void)
{
FILE *pout, *uout, *bout;
- char poutf[64], uoutf[64], poutft[64], uoutft[64], boutf[64], boutft[64];
- struct stat psb, usb, bsb;
- time_t ftime;
+ char poutf[MAXPATHLEN], uoutf[MAXPATHLEN], poutft[MAXPATHLEN];
+ char uoutft[MAXPATHLEN], boutf[MAXPATHLEN], boutft[MAXPATHLEN];
struct user *u;
char *mach;
EXEC SQL BEGIN DECLARE SECTION;
- char login[9], shell[33], fullname[33], oa[17], op[13], hp[17];
- char nn[17], ptype[9];
- int uid, flag1, flag2, id, pid, status;
+ char login[USERS_LOGIN_SIZE], shell[USERS_SHELL_SIZE];
+ char fullname[USERS_FULLNAME_SIZE], oa[USERS_OFFICE_ADDR_SIZE];
+ char op[USERS_OFFICE_PHONE_SIZE], hp[USERS_HOME_PHONE_SIZE];
+ char nn[USERS_NICKNAME_SIZE], potype[USERS_POTYPE_SIZE];
+ int uid, id, pid, iid, eid, mid, status;
EXEC SQL END DECLARE SECTION;
sprintf(poutf, "%s/passwd.db", hesiod_dir);
sprintf(uoutf, "%s/uid.db", hesiod_dir);
sprintf(boutf, "%s/pobox.db", hesiod_dir);
- if (stat(poutf, &psb) == 0 && stat(uoutf, &usb) == 0 &&
- stat(boutf, &bsb) == 0)
- {
- ftime = min(min(psb.st_mtime, usb.st_mtime), bsb.st_mtime);
- if (ModDiff (&flag1, "users", ftime) ||
- ModDiff (&flag2, "machine", ftime))
- exit(MR_DATE);
- if (flag1 < 0 && flag2 < 0)
- {
- fprintf(stderr, "Files passwd.db, uid.db, and pobox.db "
- "do not need to be rebuilt.\n");
- return 0;
- }
- }
-
sprintf(poutft, "%s~", poutf);
pout = fopen(poutft, "w");
if (!pout)
users = create_hash(12001);
EXEC SQL DECLARE u_cursor CURSOR FOR
SELECT login, unix_uid, shell, fullname, nickname, office_addr,
- office_phone, home_phone, users_id, pop_id, potype, status
+ office_phone, home_phone, users_id, potype, pop_id, imap_id, exchange_id,
+ status
FROM users
- WHERE status = 1 or status = 5 or status = 6
+ WHERE status = 1 OR status = 2 OR status = 5 OR status = 6
ORDER BY users_id;
EXEC SQL OPEN u_cursor;
while (1)
{
EXEC SQL FETCH u_cursor INTO :login, :uid, :shell, :fullname, :nn,
- :oa, :op, :hp, :id, :pid, :ptype, :status;
+ :oa, :op, :hp, :id, :potype, :pid, :iid, :eid, :status;
if (sqlca.sqlcode)
break;
strtrim(login);
dequote(op);
dequote(hp);
dequote(shell);
+ dequote(potype);
u = malloc(sizeof(struct user));
strcpy(u->name, login);
u->lists = NULL;
hash_store(users, id, u);
- if (status == 1)
+ if (status == 1 || status == 2)
{
fprintf(pout, "%s.passwd\t%s %s \"%s:*:%d:101:%s,%s,%s,%s,%s:/mit/%s:%s\"\n",
login, HCLASS, HTYPE, login, uid, fullname, nn, oa,
op, hp, login, shell);
fprintf(uout, "%d.uid\t%s CNAME %s.passwd\n", uid, HCLASS, login);
}
- if (pid != 0 && (mach = hash_lookup(machines, pid)))
+
+ if (eid != 0)
+ {
+ /* Check for IMAP. Can't use iid because it should be zero. */
+ EXEC SQL SELECT mach_id INTO :mid FROM filesys
+ WHERE label = :login || '.po' AND type = 'IMAP';
+ if (sqlca.sqlcode == 0)
+ pid = mid;
+ else
+ {
+ /* EXCHANGE user with no IMAP filesystem. Give them
+ * IMAP.EXCHANGE.MIT.EDU instead of EXCHANGE.MIT.EDU.
+ */
+ EXEC SQL SELECT mach_id INTO :eid FROM machine
+ WHERE name = 'IMAP.EXCHANGE.MIT.EDU';
+ if (sqlca.sqlcode == 0)
+ pid = eid;
+ }
+ }
+
+ if (iid != 0)
+ {
+ EXEC SQL SELECT mach_id INTO :mid FROM filesys
+ WHERE filsys_id = :iid AND type = 'IMAP';
+ if (sqlca.sqlcode == 0)
+ pid = mid;
+ }
+
+ if ((strcmp(potype, "NONE") != 0) && pid != 0 &&
+ (mach = hash_lookup(machines, pid)))
{
fprintf(bout, "%s.pobox\t%s %s \"POP %s %s\"\n",
login, HCLASS, HTYPE, mach, login);
int do_groups(void)
{
FILE *iout, *gout, *lout;
- char ioutf[64], goutf[64], loutf[64], buf[2048], *l;
+ char ioutf[MAXPATHLEN], goutf[MAXPATHLEN], loutf[MAXPATHLEN];
+ char buf[MAXPATHLEN], *l;
struct hash *groups;
- register struct bucket *b, **p;
+ struct bucket *b, **p;
struct grp *g;
struct user *u;
- struct stat isb, gsb, lsb;
- time_t ftime;
EXEC SQL BEGIN DECLARE SECTION;
- char name[33];
- int gid, id, lid, flag1, flag2, flag3, len;
+ char name[LIST_NAME_SIZE];
+ int gid, id, lid, len;
EXEC SQL END DECLARE SECTION;
/* open files */
sprintf(goutf, "%s/group.db", hesiod_dir);
sprintf(loutf, "%s/grplist.db", hesiod_dir);
- if (stat(ioutf, &isb) == 0 && stat(goutf, &gsb) == 0 &&
- stat(loutf, &lsb) == 0)
- {
- ftime = min(isb.st_mtime, min(gsb.st_mtime, lsb.st_mtime));
- if (ModDiff (&flag1, "users", ftime) ||
- ModDiff (&flag2, "list", ftime) ||
- ModDiff (&flag3, "imembers", ftime))
- exit(MR_DATE);
- if (flag1 < 0 && flag2 < 0 && flag3 < 0)
- {
- fprintf(stderr, "Files gid.db, group.db and grplist.db "
- "do not need to be rebuilt.\n");
- return 0;
- }
- }
-
sprintf(buf, "%s~", ioutf);
iout = fopen(buf, "w");
if (!iout)
EXEC SQL OPEN l_cursor;
while (1)
{
+ char buf[LIST_NAME_SIZE + 10];
+
EXEC SQL FETCH l_cursor INTO :name, :gid, :lid;
if (sqlca.sqlcode)
break;
strtrim(name);
+ if (!valid(name))
+ continue;
sprintf(buf, "%s:%d", name, gid);
- hash_store(groups, lid, strsave(buf));
+ hash_store(groups, lid, strdup(buf));
fprintf(iout, "%d.gid\t%s CNAME %s.group\n", gid, HCLASS, name);
fprintf(gout, "%s.group\t%s %s \"%s:*:%d:\"\n",
name, HCLASS, HTYPE, name, gid);
EXEC SQL DECLARE u_cursor2 CURSOR FOR
SELECT users_id, login
FROM users
- WHERE status = 1
- ORDER BY users_id;
+ WHERE status = 1 OR status = 2;
EXEC SQL OPEN u_cursor2;
while (1)
{
}
EXEC SQL DECLARE i_cursor CURSOR FOR
- SELECT list_id, member_id
- FROM imembers
- WHERE member_type = 'USER'
- ORDER BY list_id;
+ SELECT m.list_id, m.member_id
+ FROM imembers m, list l
+ WHERE m.member_type = 'USER'
+ AND m.list_id = l.list_id AND l.grouplist = 1 AND l.nfsgroup = 1;
EXEC SQL OPEN i_cursor;
while (1)
{
EXEC SQL FETCH i_cursor INTO :lid, :id;
if (sqlca.sqlcode)
break;
- if ((l = hash_lookup(groups, lid)) &&
- (u = (struct user *) hash_lookup(users, id)))
+ if ((l = hash_lookup(groups, lid)) && (u = hash_lookup(users, id)))
{
g = malloc(sizeof(struct grp));
g->next = u->lists;
int do_filsys(void)
{
FILE *out;
- char outf[64], outft[64], *mach, *group;
- register char *p;
- struct stat sb;
- time_t ftime;
- struct save_queue *sq, *sq2, *sq_create();
+ char outf[MAXPATHLEN], outft[MAXPATHLEN], *mach, *group;
+ struct save_queue *sq, *sq2;
EXEC SQL BEGIN DECLARE SECTION;
- char name[33], type[9], loc[81], access[2], mount[33], trans[257];
- char comments[65];
- int flag1, flag2, flag3, flag4, id, fid;
+ char name[FILESYS_LABEL_SIZE], type[FILESYS_TYPE_SIZE];
+ char loc[FILESYS_NAME_SIZE], access[FILESYS_RWACCESS_SIZE];
+ char mount[FILESYS_MOUNT_SIZE], comments[FILESYS_COMMENTS_SIZE];
+ char key[FSGROUP_KEY_SIZE];
+ char aname[ALIAS_NAME_SIZE], trans[ALIAS_TRANS_SIZE];
+ int flag, id, fid;
EXEC SQL END DECLARE SECTION;
sprintf(outf, "%s/filsys.db", hesiod_dir);
- if (stat(outf, &sb) == 0)
- {
- ftime = sb.st_mtime;
-
- if (ModDiff(&flag1, "filesys", ftime))
- exit(MR_DATE);
- if (ModDiff(&flag2, "machine", ftime))
- exit(MR_DATE);
- if (ModDiff(&flag3, "alias", ftime))
- exit(MR_DATE);
- if (ModDiff(&flag4, "fsgroup", ftime))
- exit(MR_DATE);
-
- if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0)
- {
- fprintf(stderr, "File filsys.db does not need to be rebuilt.\n");
- return 0;
- }
- }
-
sprintf(outft, "%s~", outf);
out = fopen(outft, "w");
if (!out)
:mount, :comments, :fid;
if (sqlca.sqlcode)
break;
+ strtrim(name);
+ if (!valid(name))
+ continue;
strtrim(type);
if (!strcmp(type, "NFS") || !strcmp(type, "RVD"))
{
- if (mach = hash_lookup(machines, id))
+ if ((mach = hash_lookup(machines, id)))
{
fprintf(out, "%s.filsys\t%s %s \"%s %s %s %s %s\"\n",
- strtrim(name), HCLASS, HTYPE, type, strtrim(loc),
+ name, HCLASS, HTYPE, type, strtrim(loc),
mach, strtrim(access), strtrim(mount));
}
}
else if (!strcmp(type, "AFS"))
{
fprintf(out, "%s.filsys\t%s %s \"AFS %s %s %s\"\n",
- strtrim(name), HCLASS, HTYPE, strtrim(loc),
+ name, HCLASS, HTYPE, strtrim(loc),
strtrim(access), strtrim(mount));
}
else if (!strcmp(type, "ERR"))
{
fprintf(out, "%s.filsys\t%s %s \"ERR %s\"\n",
- strtrim(name), HCLASS, HTYPE, strtrim(comments));
+ name, HCLASS, HTYPE, strtrim(comments));
}
else if (!strcmp(type, "FSGROUP"))
{
- sprintf(trans, "%s:%d", strtrim(name), fid);
- sq_save_data(sq, strsave(trans));
+ char buf[FILESYS_NAME_SIZE + 10];
+ sprintf(buf, "%s:%d", name, fid);
+ sq_save_data(sq, strdup(buf));
}
else if (!strcmp(type, "MUL"))
{
- sprintf(trans, "%s:%d", strtrim(name), fid);
- sq_save_data(sq2, strsave(trans));
+ char buf[FILESYS_NAME_SIZE + 10];
+ sprintf(buf, "%s:%d", name, fid);
+ sq_save_data(sq2, strdup(buf));
}
}
EXEC SQL CLOSE f_cursor;
WHERE f.filsys_id = g.filsys_id AND g.group_id = :fid
ORDER BY key, label;
EXEC SQL OPEN f_cursor2;
- for (flag1 = 1; ; flag1++)
+ for (flag = 1; ; flag++)
{
EXEC SQL FETCH f_cursor2 INTO :type, :loc, :id, :access, :mount,
- :comments, :name, :trans;
+ :comments, :name, :key;
if (sqlca.sqlcode)
break;
strtrim(type);
if (!strcmp(type, "NFS") || !strcmp(type, "RVD"))
{
- if (mach = hash_lookup(machines, id))
+ if ((mach = hash_lookup(machines, id)))
{
fprintf(out, "%s.filsys\t%s %s \"%s %s %s %s %s %d\"\n",
group, HCLASS, HTYPE, type, strtrim(loc), mach,
- strtrim(access), strtrim(mount), flag1);
+ strtrim(access), strtrim(mount), flag);
}
}
else if (!strcmp(type, "AFS"))
{
fprintf(out, "%s.filsys\t%s %s \"AFS %s %s %s %d\"\n",
group, HCLASS, HTYPE, strtrim(loc), strtrim(access),
- strtrim(mount), flag1);
+ strtrim(mount), flag);
}
else if (!strcmp(type, "ERR"))
{
EXEC SQL OPEN f_cursor3;
while (1)
{
- EXEC SQL FETCH f_cursor3 INTO :name, :trans;
+ EXEC SQL FETCH f_cursor3 INTO :name, :key;
if (sqlca.sqlcode)
break;
fprintf(out, " %s", strtrim(name));
EXEC SQL OPEN a_cursor;
while (1)
{
- EXEC SQL FETCH a_cursor INTO :name, :trans;
+ EXEC SQL FETCH a_cursor INTO :aname, :trans;
if (sqlca.sqlcode)
break;
+ strtrim(aname);
+ strtrim(trans);
+ if (!valid(aname) || !valid(trans))
+ continue;
fprintf(out, "%s.filsys\t%s CNAME %s.filsys\n",
- strtrim(name), HCLASS, strtrim(trans));
+ aname, HCLASS, trans);
}
EXEC SQL CLOSE a_cursor;
return 0;
}
-
-/*
- * Modified from sys/types.h:
- */
-int setsize; /* = howmany(setbits, NSETBITS) */
-
-typedef long set_mask;
-#define NSETBITS (sizeof(set_mask) * NBBY) /* bits per mask */
-#ifndef howmany
-#define howmany(x, y) (((x) + ((y) - 1)) / (y))
-#endif
-
-#define SET_SET(n, p) ((p)[(n)/NSETBITS] |= (1 << ((n) % NSETBITS)))
-#define SET_CLR(n, p) ((p)[(n)/NSETBITS] &= ~(1 << ((n) % NSETBITS)))
-#define SET_ISSET(n, p) ((p)[(n)/NSETBITS] & (1 << ((n) % NSETBITS)))
-#define SET_CREATE() (malloc(setsize * sizeof(set_mask)))
-#define SET_ZERO(p) memset(p, 0, setsize * sizeof(set_mask))
-#define SET_CMP(p1, p2) (memcmp(p1, p2, setsize * sizeof(set_mask)))
-
int nbitsset(set_mask *set)
{
int i, ret;
int do_cluster(void)
{
FILE *out;
- char outf[64], outft[64], *mach, machbuf[41], *p;
- struct stat sb;
- time_t ftime;
+ char outf[MAXPATHLEN], outft[MAXPATHLEN], *mach;
+ char machbuf[MACHINE_NAME_SIZE], clubuf[CLUSTERS_NAME_SIZE], *p;
EXEC SQL BEGIN DECLARE SECTION;
- int flag1, flag2, flag3, flag4, maxmach, maxclu, mid, cid, id;
- char name[41], label2[17], data[33];
+ int maxmach, maxclu, mid, cid, id;
+ char name[CLUSTERS_NAME_SIZE];
+ char label[SVC_SERV_LABEL_SIZE], data[SVC_SERV_CLUSTER_SIZE];
EXEC SQL END DECLARE SECTION;
set_mask **machs, *ms, *ps;
- int oneclu;
sprintf(outf, "%s/cluster.db", hesiod_dir);
- if (stat(outf, &sb) == 0)
- {
- ftime = sb.st_mtime;
- if (ModDiff (&flag1, "clusters", ftime)
- || ModDiff (&flag2, "machine", ftime)
- || ModDiff (&flag3, "mcmap", ftime)
- || ModDiff (&flag4, "svc", ftime))
- exit(MR_DATE);
- if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0)
- {
- fprintf(stderr, "File cluster.db does not need to be rebuilt.\n");
- return 0;
- }
- }
-
sprintf(outft, "%s~", outf);
out = fopen(outft, "w");
if (!out)
ms = machs[mid];
if (nbitsset(ms) > 1)
{
- oneclu = 0;
+ sprintf(clubuf, "mrinternal-%d", mid);
for (cid = 1; cid < maxclu; cid++)
{
if (SET_ISSET(cid, ms))
EXEC SQL OPEN d_cursor;
while (1)
{
- EXEC SQL FETCH d_cursor INTO :label2, :data;
+ EXEC SQL FETCH d_cursor INTO :label, :data;
if (sqlca.sqlcode)
break;
- strtrim(label2);
+ strtrim(label);
strtrim(data);
- fprintf(out, "mrinternal-%d.cluster\t%s %s \"%s %s\"\n",
- mid, HCLASS, HTYPE, label2, data);
+ fprintf(out, "%s.cluster\t%s %s \"%s %s\"\n",
+ clubuf, HCLASS, HTYPE, label, data);
}
EXEC SQL CLOSE d_cursor;
}
}
else
{
- oneclu = 1;
for (cid = 1; cid < maxclu; cid++)
if (SET_ISSET(cid, ms))
break;
EXEC SQL SELECT name INTO :name FROM clusters WHERE clu_id = :cid;
strtrim(name);
+ if (!valid(name))
+ continue;
+ strcpy(clubuf, name);
}
if ((mach = hash_lookup(machines, mid)))
{
+ fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
+ mach, HCLASS, clubuf);
for (p = machbuf; *mach && *mach != '.'; mach++)
*p++ = *mach;
- *p = '\0';
- if (oneclu)
+ if (!strcasecmp(mach, ".mit.edu"))
{
+ *p = '\0';
fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
- machbuf, HCLASS, name);
- }
- else
- {
- fprintf(out, "%s.cluster\t%s CNAME mrinternal-%d.cluster\n",
- machbuf, HCLASS, mid);
+ machbuf, HCLASS, clubuf);
}
}
for (id = mid + 1; id < maxmach; id++)
machs[id] = NULL;
if ((mach = hash_lookup(machines, id)))
{
+ fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
+ mach, HCLASS, clubuf);
for (p = machbuf; *mach && *mach != '.'; mach++)
*p++ = *mach;
- *p = '\0';
- if (oneclu)
+ if (!strcasecmp(mach, ".mit.edu"))
{
+ *p = '\0';
fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
- machbuf, HCLASS, name);
- }
- else
- {
- fprintf(out,
- "%s.cluster\t%s CNAME mrinternal-%d.cluster\n",
- machbuf, HCLASS, mid);
+ machbuf, HCLASS, clubuf);
}
}
}
EXEC SQL OPEN d_cursor2;
while (1)
{
- EXEC SQL FETCH d_cursor2 INTO :name, :label2, :data;
+ EXEC SQL FETCH d_cursor2 INTO :name, :label, :data;
if (sqlca.sqlcode)
break;
strtrim(name);
- strtrim(label2);
+ if (!valid(name))
+ continue;
+ strtrim(label);
strtrim(data);
fprintf(out, "%s.cluster\t%s %s \"%s %s\"\n",
- name, HCLASS, HTYPE, label2, data);
+ name, HCLASS, HTYPE, label, data);
}
free(machs);
EXEC SQL COMMIT;
int do_printcap(void)
{
FILE *out;
- char outf[64], outft[64];
- struct stat sb;
- time_t ftime;
+ char outf[MAXPATHLEN], outft[MAXPATHLEN];
EXEC SQL BEGIN DECLARE SECTION;
- char name[17], rp[17], sd[33];
- int flag1, flag2, ka, pc, rm, rq;
+ char name[PRINTERS_NAME_SIZE], duplexname[PRINTERS_DUPLEXNAME_SIZE];
+ char rp[PRINTERS_RP_SIZE], type[PRINTERS_TYPE_SIZE];
+ char duplexrp[PRINTERS_RP_SIZE], pskind[PRINTSERVERS_KIND_SIZE];
+ int ka, rm, mc;
EXEC SQL END DECLARE SECTION;
+ char *rmname;
sprintf(outf, "%s/printcap.db", hesiod_dir);
- if (stat(outf, &sb) == 0)
- {
- ftime = sb.st_mtime;
- if (ModDiff (&flag1, "printcap", ftime)
- || ModDiff (&flag2, "machine", ftime))
- exit(MR_DATE);
- if (flag1 < 0 && flag2 < 0)
- {
- fprintf(stderr, "File printcap.db does not need to be rebuilt.\n");
- return 0;
- }
- }
-
sprintf(outft, "%s~", outf);
out = fopen(outft, "w");
if (!out)
get_mach();
EXEC SQL DECLARE p_cursor2 CURSOR FOR
- SELECT name, rp, dir, mach_id, auth, price, quotaserver
- FROM printcap;
+ SELECT p.name, p.duplexname, p.type, p.rp, p.rm, p.ka, p.mc, ps.kind
+ FROM printers p, printservers ps
+ WHERE p.rm = ps.mach_id;
EXEC SQL OPEN p_cursor2;
while (1)
{
- EXEC SQL FETCH p_cursor2 INTO :name, :rp, :sd, :rm, :ka, :pc, :rq;
+ EXEC SQL FETCH p_cursor2 INTO :name, :duplexname, :type,
+ :rp, :rm, :ka, :mc, :pskind;
if (sqlca.sqlcode)
break;
- if (!hash_lookup(machines, rm))
+ if (!(rmname = hash_lookup(machines, rm)))
continue;
strtrim(name);
+ if (!valid(name))
+ continue;
strtrim(rp);
- strtrim(sd);
- fprintf(out, "%s.pcap\t%s %s \"%s:rp=%s:rm=%s:sd=%s:ka#%d:pc#%d",
- name, HCLASS, HTYPE, name, rp, hash_lookup(machines, rm),
- sd, ka, pc);
- if (rq && hash_lookup(machines, rq))
- fprintf(out, ":rq=%s\"\n", hash_lookup(machines, rq));
- else
- fputs("\"\n", out);
- }
- EXEC SQL CLOSE p_cursor2;
-
- EXEC SQL COMMIT;
+ fprintf(out, "%s.pcap\t%s %s \"%s:rp=%s:rm=%s:ka#%d:mc#%d:",
+ name, HCLASS, HTYPE, name, rp, rmname, ka, mc);
- if (fclose(out))
- {
- fprintf(stderr, "Unsuccessful close of pcap.db\n");
- exit(MR_CCONFIG);
- }
- fix_file(outf);
- return 1;
-sqlerr:
- db_error(sqlca.sqlcode);
- return 0;
-}
-
-
-int do_palladium(void)
-{
- FILE *out;
- char outf[64], outft[64];
- struct stat sb;
- time_t ftime;
- EXEC SQL BEGIN DECLARE SECTION;
- char name[33], trans[129];
- int flag, flag1, identifier, rm;
- EXEC SQL END DECLARE SECTION;
-
- sprintf(outf, "%s/palladium.db", hesiod_dir);
-
- if (stat(outf, &sb) == 0)
- {
- ftime = sb.st_mtime;
- if ((ModDiff (&flag, "palladium", ftime)) ||
- (ModDiff (&flag1, "alias", ftime)))
- exit(MR_DATE);
- if (flag < 0 && flag1 < 0)
+ strtrim(pskind);
+ if (!strcmp(pskind, "BSD"))
+ fprintf(out, "auth=none:remote_support=RQM:");
+ else if (!strcmp(pskind, "ATHENA"))
{
- fprintf(stderr, "File palladium.db does not need to be rebuilt.\n");
- return 0;
+ fprintf(out, "auth=%s:az:remote_support=RQM:",
+ ka ? "kerberos4" : "none");
}
- }
-
- sprintf(outft, "%s~", outf);
- out = fopen(outft, "w");
- if (!out)
- {
- perror("cannot open palladium.db for write");
- exit(MR_OCONFIG);
- }
+ else if (!strcmp(pskind, "LPRNG"))
+ fprintf(out, "auth=kerberos5:xn:");
- fprintf(stderr, "Building palladium.db\n");
- get_mach();
+ fputs("\"\n", out);
- EXEC SQL DECLARE p_cursor3 CURSOR FOR
- SELECT name, identifier, mach_id
- FROM palladium;
- EXEC SQL OPEN p_cursor3;
- while (1)
- {
- EXEC SQL FETCH p_cursor3 INTO :name, :identifier, :rm;
- if (sqlca.sqlcode)
- break;
- if (!hash_lookup(machines, rm))
- break;
- strtrim(name);
- fprintf(out, "%s.palladium\t%s %s \"%s %d %s interface directory\"\n",
- name, HCLASS, HTYPE, hash_lookup(machines, rm), identifier,
- name);
- }
- EXEC SQL CLOSE p_cursor3;
+ strtrim(duplexname);
+ if (!valid(duplexname))
+ continue;
+ if (!strcmp(strtrim(type), "ALIAS"))
+ {
+ EXEC SQL SELECT duplexname INTO :duplexrp
+ FROM printers WHERE name = :rp;
+ strtrim(duplexrp);
+ }
+ else
+ strcpy(duplexrp, duplexname);
+ fprintf(out, "%s.pcap\t%s %s \"%s:rp=%s:rm=%s:ka#%d:mc#%d:",
+ duplexname, HCLASS, HTYPE, duplexname, duplexrp,
+ rmname, ka, mc);
+
+ if (!strcmp(pskind, "BSD"))
+ fprintf(out, "auth=none:remote_support=RQM:");
+ else if (!strcmp(pskind, "ATHENA"))
+ {
+ fprintf(out, "auth=%s:az:remote_support=RQM:",
+ ka ? "kerberos4" : "none");
+ }
+ else if (!strcmp(pskind, "LPRNG"))
+ fprintf(out, "auth=kerberos5:xn:");
- EXEC SQL DECLARE a_cursor2 CURSOR FOR
- SELECT name, trans
- FROM alias
- WHERE type = 'PALLADIUM';
- EXEC SQL OPEN a_cursor2;
- while (1)
- {
- EXEC SQL FETCH a_cursor2 INTO :name, :trans;
- if (sqlca.sqlcode)
- break;
- strtrim(name);
- strtrim(trans);
- fprintf(out, "%s.palladium\t%s %s \"%s\"\n", name, HCLASS, HTYPE, trans);
+ fputs("\"\n", out);
}
- EXEC SQL CLOSE a_cursor2;
+ EXEC SQL CLOSE p_cursor2;
EXEC SQL COMMIT;
if (fclose(out))
{
- fprintf(stderr, "Unsuccessful close of palladium.db\n");
+ fprintf(stderr, "Unsuccessful close of pcap.db\n");
exit(MR_CCONFIG);
}
fix_file(outf);
int do_sloc(void)
{
FILE *out;
- char outf[64], outft[64], *mach;
- struct stat sb;
- time_t ftime;
+ char outf[MAXPATHLEN], outft[MAXPATHLEN], *mach;
EXEC SQL BEGIN DECLARE SECTION;
- char service[17];
- int flag1, flag2, id;
+ char service[SERVERHOSTS_SERVICE_SIZE];
+ int id;
EXEC SQL END DECLARE SECTION;
sprintf(outf, "%s/sloc.db", hesiod_dir);
- if (stat(outf, &sb) == 0)
- {
- ftime = sb.st_mtime;
- if ((ModDiff (&flag1, "serverhosts", ftime)) ||
- (ModDiff (&flag2, "machine", ftime)))
- exit(MR_DATE);
- if (flag1 < 0 && flag2 < 0)
- {
- fprintf(stderr, "File sloc.db does not need to be rebuilt.\n");
- return 0;
- }
- }
-
sprintf(outft, "%s~", outf);
out = fopen(outft, "w");
if (!out)
if (sqlca.sqlcode)
break;
strtrim(service);
- if (mach = hash_lookup(machines, id))
+ if (valid(service) && (mach = hash_lookup(machines, id)))
fprintf(out, "%s.sloc\t%s %s %s\n", service, HCLASS, HTYPE, mach);
}
EXEC SQL CLOSE s_cursor;
int do_service(void)
{
FILE *out;
- char outf[64], outft[64];
- struct stat sb;
- time_t ftime;
+ char outf[MAXPATHLEN], outft[MAXPATHLEN];
EXEC SQL BEGIN DECLARE SECTION;
- char service[33], protocol[9], altserv[129];
- int port, flag1;
+ char service[SERVICES_NAME_SIZE], protocol[SERVICES_PROTOCOL_SIZE];
+ char aname[ALIAS_NAME_SIZE], trans[ALIAS_TRANS_SIZE];
+ int port;
EXEC SQL END DECLARE SECTION;
sprintf(outf, "%s/service.db", hesiod_dir);
- if (stat(outf, &sb) == 0)
- {
- ftime = sb.st_mtime;
- if (ModDiff (&flag1, "services", ftime))
- exit(MR_DATE);
- if (flag1 < 0)
- {
- fprintf(stderr, "File service.db does not need to be rebuilt.\n");
- return 0;
- }
- }
-
sprintf(outft, "%s~", outf);
out = fopen(outft, "w");
if (!out)
break;
lowercase(protocol); /* Convert protocol to lowercase */
strtrim(service);
+ if (!valid(service))
+ continue;
strtrim(protocol);
fprintf(out, "%s.service\t%s %s \"%s %s %d\"\n",
service, HCLASS, HTYPE, service, protocol, port);
EXEC SQL OPEN a_cursor3;
while (1)
{
- EXEC SQL FETCH a_cursor3 INTO :service, :altserv;
+ EXEC SQL FETCH a_cursor3 INTO :aname, :trans;
if (sqlca.sqlcode)
break;
- strtrim(service);
- strtrim(altserv);
- fprintf(out, "%s.service\t%s CNAME %s.service\n", service, HCLASS,
- altserv);
+ strtrim(aname);
+ strtrim(trans);
+ if (!valid(aname) || !valid(trans))
+ continue;
+ fprintf(out, "%s.service\t%s CNAME %s.service\n", aname, HCLASS,
+ trans);
}
EXEC SQL CLOSE a_cursor3;