#include <mit-copyright.h>
#include <stdio.h>
#include <sys/file.h>
+#include <strings.h>
#include <rx/xdr.h>
#include "ptint.h"
#include <moira_site.h>
#include <ctype.h>
+/* The following enables the processing of .root instances */
+#define DO_KERBEROS
+
EXEC SQL INCLUDE sqlca;
+EXEC SQL BEGIN DECLARE SECTION;
+char db[33] = "moira";
+EXEC SQL END DECLARE SECTION;
+
#define min(x,y) ((x) < (y) ? (x) : (y))
char *whoami = "sync";
-char *malloc(), *strsave();
int dbase_fd;
int ucount = 0;
int gcount = 0;
+int kcount = 0;
int mcount = 0;
struct hash *users;
struct hash *groups;
+#ifdef DO_KERBEROS
+struct hash *strings;
+#endif
struct member {
struct entry *user;
struct member *members;
};
-int ingerr();
-
main(argc, argv)
int argc;
char **argv;
{
- EXEC SQL BEGIN DECLARE SECTION;
- char db[9];
- EXEC SQL END DECLARE SECTION;
-
int status;
long t;
- strcpy(db, "moira");
-
if (argc > 2 && !strcmp(argv[1], "-db")) {
strncpy(db, argv[2], sizeof(db)-1);
argc -= 2;
initialize_sms_error_table();
initialize_pt_error_table();
Initdb(); /* Initialize prdb */
+ setlinebuf(stdout);
users = create_hash(10000);
groups = create_hash(15000);
+#ifdef DO_KERBEROS
+ strings = create_hash(1000);
+#endif
EXEC SQL WHENEVER SQLERROR CALL sqlerr;
#ifsql INGRES
do_groups();
t = time(0);
- fprintf(stderr, "Done (%d users, %d groups, %d members): %s",
- ucount, gcount, mcount, ctime(&t));
+ fprintf(stderr, "Done (%d users, %d groups, %d kerberos, %d members): %s",
+ ucount, gcount, kcount, mcount, ctime(&t));
#ifsql INGRES
EXEC SQL DISCONNECT;
do_groups()
{
EXEC SQL BEGIN DECLARE SECTION;
- char name[33];
- int gid, id, lid, hide;
+ char name[33], string[129];
+ int gid, id, lid, hide, ustatus;
EXEC SQL END DECLARE SECTION;
long status, pos;
EXEC SQL CLOSE l_cursor;
t = time(0);
- fprintf(stderr, "Doing user members: %s", ctime(&t));
+ fprintf(stderr, "Reading/preparing members: %s", ctime(&t));
EXEC SQL DECLARE m_cursor CURSOR FOR
- SELECT m.list_id, m.member_id
+ SELECT m.list_id, m.member_id, m.member_type
FROM imembers m
- WHERE m.member_type='USER'
ORDER BY member_id;
EXEC SQL OPEN m_cursor;
while (1) {
- EXEC SQL FETCH m_cursor INTO :lid, :id;
+ EXEC SQL FETCH m_cursor INTO :lid, :id, :name;
if (sqlca.sqlcode != 0) break;
-
- if ((u = (struct entry *)hash_lookup(users, id)) &&
- (g = (struct entry *)hash_lookup(groups, lid))) {
+
+ if (!(g = (struct entry *)hash_lookup(groups, lid)))
+ continue;
+
+ strtrim(name);
+ if (!strcmp(name, "USER")) {
+ if (u = (struct entry *)hash_lookup(users, id)) {
+ m = (struct member *)malloc(sizeof(struct member));
+ m->user = u;
+ m->group = g;
+ m->unext = u->members;
+ m->gnext = g->members;
+ u->members = g->members = m;
+ mcount++;
+ }
+ }
+#ifdef DO_KERBEROS
+ else if (!strcmp(name, "KERBEROS")) {
+ if (!(u = (struct entry *)hash_lookup(strings, id))) {
+ char *p;
+
+ EXEC SQL SELECT string INTO :string
+ FROM strings WHERE string_id = :id;
+
+ aid = 0;
+ strtrim(string);
+
+ if (p = (char *)index(string, '@')) {
+ *p = 0;
+ if (strcmp(p+1, "ATHENA.MIT.EDU")) aid = -1;
+ } else aid = -1;
+
+ if ((p = (char *)index(string, '.')) && (p-string) < 9 &&
+ !strcmp(p+1, "root"))
+ {
+ strncpy(name, string, p-string);
+ name[p-string] = 0;
+ } else aid = -1;
+
+ if (aid == 0) {
+ EXEC SQL DECLARE k_cursor2 CURSOR FOR
+ SELECT uid, status
+ FROM users
+ WHERE login = :name
+ ORDER BY uid;
+ EXEC SQL OPEN k_cursor2;
+ while (1) {
+ if (sqlca.sqlcode) break;
+ EXEC SQL FETCH k_cursor2 INTO :lid, :ustatus;
+ if (ustatus==1 || ustatus==2) aid = lid+65536;
+ }
+ EXEC SQL CLOSE k_cursor2;
+ }
+
+ if (aid > 0) {
+ if (FindByID(0,aid))
+ status = PRIDEXIST;
+ else
+ status = CreateEntry(0, string, &aid, 1 /*idflag*/,
+ 0 /*gflag*/, SYSADMINID /*oid*/,
+ SYSADMINID /*cid */);
+ if (status) {
+ fprintf(stderr, "Error adding %s (id %d): %s\n",
+ string, aid, error_message(status));
+ if (status != PRIDEXIST) aid = 0;
+ }
+ } else
+ aid = 0;
+
+ u = (struct entry *)malloc(sizeof(struct entry));
+ u->id = aid;
+ u->members = 0;
+ hash_store(strings, id, u);
+ if (aid) kcount++;
+ }
+ if (u->id == 0) continue;
+
m = (struct member *)malloc(sizeof(struct member));
m->user = u;
m->group = g;
u->members = g->members = m;
mcount++;
}
+#endif
}
EXEC SQL CLOSE m_cursor;
+ t = time(0);
+ fprintf(stderr, "Doing members: %s", ctime(&t));
+
/* Do the bulk of the membership quickly.
* Add PRSIZE members into the user/group record. After that, we
* require the use of continuation records, but we assume this is
}
}
}
+#ifdef DO_KERBEROS
+ for (p = &(strings->data[strings->size - 1]); p >= strings->data; p--) {
+ for (b = *p; b; b = b->next) {
+ if ((u = (struct entry *)b->data)->members == 0)
+ continue;
+ pos = FindByID(0, u->id);
+ pr_Read(0, 0, pos, &uentry, sizeof(uentry));
+ for (t=0, m=u->members; m && t<PRSIZE; m=m->unext, t++)
+ uentry.entries[t] = htonl(m->group->id);
+ uentry.count = htonl(t);
+ pr_Write(0, 0, pos, &uentry, sizeof(uentry));
+ if (m) {
+ pr_ReadEntry(0, 0, pos, &uentry);
+ while (m) {
+ AddToEntry(0, &uentry, pos, m->group->id);
+ m = m->unext;
+ }
+ }
+ }
+ }
+#endif
for (p = &(groups->data[groups->size - 1]); p >= groups->data; p--) {
for (b = *p; b; b = b->next) {
if ((g = (struct entry *)b->data)->members == 0)