From: probe Date: Sun, 28 Jun 1992 21:13:46 +0000 (+0000) Subject: Allow alternate Moira db to be specified (-db ...) X-Git-Tag: release77~502 X-Git-Url: http://andersk.mit.edu/gitweb/moira.git/commitdiff_plain/679196204ed619cabeb6cce68ffae470ee1b3f84 Allow alternate Moira db to be specified (-db ...) Hash id positions for faster lookups later... Lowercase users/groups before adding... --- diff --git a/afssync/sync.qc b/afssync/sync.qc index f6a5fbbb..093f294f 100644 --- a/afssync/sync.qc +++ b/afssync/sync.qc @@ -20,36 +20,50 @@ #include #define min(x,y) ((x) < (y) ? (x) : (y)) -struct hash *users = NULL; char *whoami = "sync"; char *malloc(), *strsave(); int dbase_fd; +struct hash *users; +struct hash *groups; +struct hash *idpos; main(argc, argv) int argc; char **argv; { +## char db[9]; + int status; int ingerr(); + if (!strcmp(argv[1], "-db")) { + strncpy(db, argv[2], sizeof(db)-1); + argc -= 2; + argv += 2; + } if (argc != 2) { - fprintf(stderr, "usage: %s outfile\n", argv[0]); + fprintf(stderr, "usage: %s [-db sms] outfile\n", whoami); exit(MR_ARGS); } - dbase_fd = open(argv[1], O_RDWR|O_CREAT, 0660); + dbase_fd = open(argv[1], O_RDWR|O_CREAT|O_TRUNC, 0660); if (dbase_fd < 0) { perror("opening file %s", argv[1]); exit(1); } IIseterr(ingerr); + initialize_sms_error_table(); initialize_pt_error_table(); - Initdb(); - -## ingres sms + Initdb(); /* Initialize prdb */ + + idpos = create_hash(20000); + users = create_hash(10000); + groups = create_hash(15000); + +## ingres db ## set lockmode session where level = table ## begin transaction @@ -63,52 +77,31 @@ char **argv; } -/* - * ingerr: (supposedly) called when Ingres indicates an error. - * I have not yet been able to get this to work to intercept a - * database open error. - */ -#define INGRES_DEADLOCK 4700 - -static int ingerr(num) - int *num; -{ - char buf[256]; - int ingres_errno; - - switch (*num) { - case INGRES_DEADLOCK: - ingres_errno = MR_DEADLOCK; - break; - default: - ingres_errno = MR_INGRES_ERR; - } - com_err(whoami, MR_INGRES_ERR, " code %d\n", *num); - exit(ingres_errno); -} - - - do_passwd() ##{ ## char login[9]; ## int uid, id, status; + int t; + struct prentry tentry; - fprintf(stderr, "Doing users\n"); - users = create_hash(10000); + t = time(0); + fprintf(stderr, "Doing users: %s", ctime(&t)); + ## range of u is users ## retrieve (login = u.#login, uid = u.#uid, id = u.users_id) ## where u.#uid > 0 and (u.#status = 1 or u.#status = 2) { - strtrim(login); - hash_store(users, id, uid); - if (FindByID (0, uid)) + lowercase(strtrim(login)); + + if (FindByID(0,uid)) status = PRIDEXIST; else - status = CreateEntry(0, login, &uid, 1/*idflag*/, 0/*gflag*/, + status = CreateEntry(0,login,&uid,1/*idflag*/,0/*gflag*/, SYSADMINID/*oid*/, SYSADMINID/*cid*/); if (status) fprintf(stderr, "Error adding user %s uid %d: %s\n", login, uid, error_message(status)); + else + hash_store(users, id, uid); ## } ##} @@ -116,19 +109,16 @@ do_passwd() do_groups() ##{ - struct hash *groups; long u, g, status, gpos, upos; struct prentry gentry, uentry; -## char name[33], namebuf[128]; + char namebuf[41]; + int aid, t; +## char name[33]; ## int gid, id, lid, hide; - int aid; - - fprintf(stderr, "Doing groups\n"); - /* make space for group list */ - groups = create_hash(15000); + t = time(0); + fprintf(stderr, "Doing groups: %s", ctime(&t)); - /* retrieve simple groups */ ## range of l is list ## range of m is imembers /* get lock records */ @@ -137,11 +127,11 @@ do_groups() ## retrieve (name = l.#name, gid = l.#gid, lid = l.list_id, hide = l.hidden) ## where l.group != 0 and l.active != 0 and l.#gid > 0 { - strtrim(name); + lowercase(strtrim(name)); sprintf(namebuf, "system:%s", name); - hash_store(groups, lid, -gid); aid = -gid; - if (gpos = FindByID (0, aid)) + + if (FindByID(0, aid)) status = PRIDEXIST; else status = CreateEntry(0,namebuf,&aid,1/*idflag*/,PRGRP/*gflag*/, @@ -149,24 +139,26 @@ do_groups() if (status) fprintf(stderr, "Error adding group %s id %d: %s\n", namebuf, aid, error_message(status)); + else + hash_store(groups, lid, aid); /* If this list is hidden, set the pts entry to be s---- */ if (hide && (status==0 || status==PRIDEXIST)) { - if (!gpos) - gpos = FindByID(0, aid); + gpos = get_id(aid); status = pr_ReadEntry(0, 0, gpos, &gentry); if (!status) { gentry.flags = PRGRP|PRACCESS|PRP_STATUS_ANY; status = pr_WriteEntry(0, 0, gpos, &gentry); } if (status) - fprintf(stderr, "Error setting flags on group %s: %s\n", + fprintf(stderr, + "Error setting flags on group %s: %s\n", namebuf, error_message(status)); } ## } - - fprintf(stderr, "Doing members\n"); + t = time(0); + fprintf(stderr, "Doing members: %s", ctime(&t)); ## retrieve (lid = m.list_id, id = m.member_id) ## where m.member_type = "USER" { @@ -174,7 +166,7 @@ do_groups() (g = (long) hash_lookup(groups, lid))) { if (g==ANYUSERID || g==AUTHUSERID || u==ANONYMOUSID) { status = PRPERM; - } else if ((gpos = FindByID(0, g)) && (upos = FindByID(0, u))) { + } else if ((gpos = get_id(g)) && (upos = get_id(u))) { status = pr_ReadEntry(0,0,upos,&uentry); if (!status) status = pr_ReadEntry(0,0,gpos,&gentry); if (!status) status = AddToEntry (0, &gentry, gpos, u); @@ -188,5 +180,44 @@ do_groups() } ## } + t = time(0); + fprintf(stderr, "Done: %s", ctime(&t)); + ##} + +get_id(id) +{ + long i; + + if (i=(long)hash_lookup(idpos, id)) + return i; + hash_store(idpos, id, i=FindByID(0, id)); + return i; +} + + + +/* + * ingerr: (supposedly) called when Ingres indicates an error. + * I have not yet been able to get this to work to intercept a + * database open error. + */ +#define INGRES_DEADLOCK 4700 + +static int ingerr(num) + int *num; +{ + char buf[256]; + int ingres_errno; + + switch (*num) { + case INGRES_DEADLOCK: + ingres_errno = MR_DEADLOCK; + break; + default: + ingres_errno = MR_INGRES_ERR; + } + com_err(whoami, MR_INGRES_ERR, " code %d\n", *num); + exit(ingres_errno); +}