* user pobox entries
* maillist expansions
* sublists of maillists
+ *
+ * (c) Copyright 1988 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 <string.h>
-#include <sms.h>
-#include <sms_app.h>
+#include <moira.h>
+#include <moira_site.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
char *divide = "########################################################################";
extern int errno;
+char *whoami = "aliases.gen";
char *ingres_date_and_time();
-
+FILE *out;
main(argc, argv)
int argc;
char **argv;
{
long tm = time(NULL);
- FILE *out= stdout;
char filename[64], *targetfile;
struct stat sb;
## int flag1, flag2, flag3;
## char *filetime;
+ int ingerr();
+ out= stdout;
+ IIseterr(ingerr);
+ initialize_sms_error_table();
## ingres sms
+## set lockmode session where level = table
if (argc == 2) {
if (stat(argv[1], &sb) == 0) {
## retrieve (flag1 = int4(interval("min",tblstats.modtime - filetime)))
## where tblstats.table = "list"
## retrieve (flag2 = int4(interval("min",tblstats.modtime - filetime)))
-## where tblstats.table = "members"
+## where tblstats.table = "imembers"
## retrieve (flag3 = int4(interval("min",tblstats.modtime - filetime)))
## where tblstats.table = "users"
if (flag1 < 0 && flag2 < 0 && flag3 < 0) {
fprintf(stderr, "File %s does not need to be rebuilt.\n",
argv[1]);
- exit(SMS_NO_CHANGE);
+ exit(MR_NO_CHANGE);
}
}
targetfile = argv[1];
sprintf(filename, "%s~", targetfile);
if ((out = fopen(filename, "w")) == NULL) {
fprintf(stderr, "unable to open %s for output\n", filename);
- exit(SMS_OCONFIG);
+ exit(MR_OCONFIG);
}
} else if (argc != 1) {
fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
- exit(SMS_ARGS);
+ exit(MR_ARGS);
}
fprintf(out, "%s\n# Aliases File Extract of %s", divide, ctime(&tm));
if (fclose(out)) {
perror("close failed");
- exit(SMS_CCONFIG);
+ exit(MR_CCONFIG);
}
if (argc == 2)
fix_file(targetfile);
- exit(SMS_SUCCESS);
+ exit(MR_SUCCESS);
+}
+
+
+/*
+ * 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;
+{
+ 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);
+ critical_alert("DCM", "Alias build encountered INGRES ERROR %d", *num);
+ exit(ingres_errno);
}
int list_id;
};
struct list {
- char name[33];
+ char *name;
char maillist;
char acl_t;
- char description[256];
+ char *description;
int acl_id;
struct member *m;
};
register struct user *u;
register struct list *l;
register struct member *m;
+ register struct list *memberlist;
+
+ /* get locks */
+## retrieve (buf = list.modtime) where list.list_id = 0
+## retrieve (buf = users.modtime) where users.users_id = 0
fprintf(stderr, "Loading machines\n");
machines = create_hash(1000);
## retrieve (id = machine.mach_id, name = machine.#name) {
if (s = index(name, '.'))
*s = 0;
- sprintf(buf, "%s.LOCAL", name);
- hash_store(machines, id, strsave(buf));
+#ifdef ATHENA
+ strcat(name, ".LOCAL");
+#endif
+ hash_store(machines, id, strsave(name));
## }
fprintf(stderr, "Loading strings\n");
## }
fprintf(stderr, "Loading users\n");
- users = create_hash(15000);
+ users = create_hash(12001);
## range of u is users
## retrieve (id = u.users_id, name = u.login, type = u.potype,
-## pid = u.pop_id, bid = u.box_id) where u.status = 1 {
+## pid = u.pop_id, bid = u.box_id)
+## where u.status = 1 or u.status = 5 or u.status = 6 {
u = (struct user *) malloc(sizeof(struct user));
strcpy(u->login, strtrim(name));
- u->pobox = (char *) NULL;
if (type[0] == 'P') {
if (s = hash_lookup(machines, pid)) {
sprintf(buf, "%s@%s", name, s);
u->pobox = strsave(buf);
} else {
+ u->pobox = (char *) NULL;
fprintf(stderr, "User %s's pobox is on a missing machine!\n",
u->login);
}
} else if (type[0] == 'S') {
- if ((u->pobox = hash_lookup(strings, bid)) == NULL)
- fprintf(stderr, "User %s's pobox string is missing!\n", u->login);
- }
+ if ((u->pobox = hash_lookup(strings, bid)) == NULL) {
+ u->pobox = (char *) NULL;
+ fprintf(stderr, "User %s's pobox string is missing!\n",
+ u->login);
+ }
+ } else
+ u->pobox = (char *) NULL;
hash_store(users, id, u);
## }
fprintf(stderr, "Loading lists\n");
- lists = create_hash(15000);
+ lists = create_hash(15001);
## range of l is list
## retrieve (id = l.list_id, name = l.#name, maillistp = l.maillist,
## buf = l.desc, type = l.acl_type, acl = l.acl_id)
## where l.active != 0 {
l = (struct list *) malloc(sizeof(struct list));
- strcpy(l->name, strtrim(name));
+ l->name = strsave(strtrim(name));
l->maillist = maillistp;
- strcpy(l->description, strtrim(buf));
+ l->description = strsave(strtrim(buf));
l->acl_t = type[0];
l->acl_id = acl;
l->m = (struct member *) NULL;
fprintf(stderr, "Loading members\n");
-## range of m is members
-## retrieve (id = m.list_id, type = m.member_type, mid = m.member_id) {
+## range of m is imembers
+## retrieve (id = m.list_id, type = m.member_type, mid = m.member_id)
+## where m.direct = 1 {
if (l = (struct list *) hash_lookup(lists, id)) {
m = (struct member *) malloc(sizeof(struct member));
- m->name = (char *) NULL;
- if (type[0] == 'U') {
+ if (type[0] == 'U' &&
+ (u = (struct user *) hash_lookup(users, mid))) {
m->list_id = 0;
- if (u = (struct user *) hash_lookup(users, mid))
- m->name = u->login;
- } else if (type[0] == 'L') {
+ m->name = u->login;
+ m->next = l->m;
+ l->m = m;
+ } else if (type[0] == 'L' &&
+ (memberlist = (struct list *) hash_lookup(lists, mid))) {
m->list_id = mid;
- if (l = (struct list *) hash_lookup(lists, mid))
- m->name = l->name;
- } else if (type[0] == 'S') {
+ m->name = memberlist->name;
+ m->next = l->m;
+ l->m = m;
+ } else if (type[0] == 'S' &&
+ (s = hash_lookup(strings, mid))) {
m->list_id = 0;
- if (s = hash_lookup(strings, mid))
- m->name = s;
- }
- if (m->name != (char *) NULL) {
+ m->name = s;
m->next = l->m;
l->m = m;
}
##}
-void save_mlist(id, l, sq)
+save_mlist(id, l, force)
int id;
-struct list *l;
-struct save_queue *sq;
+register struct list *l;
+int force;
{
- if (l->maillist)
- sq_save_unique_data(sq, id);
+ register struct member *m;
+ struct list *l1;
+
+ if (l->maillist == 2 ||
+ (l->maillist == 0 && !force))
+ return;
+
+ if (l->m && l->m->next == NULL &&
+ !strcasecmp(l->name, l->m->name)) {
+ l->maillist = 0;
+ return;
+ }
+ l->maillist = 2;
+ output_mlist(id, l);
+
+ if (l->acl_t == 'L' && (l1 = (struct list *)hash_lookup(lists, l->acl_id)))
+ save_mlist(0, l1, 1);
+
+ for (m = l->m; m; m = m->next) {
+ if (m->list_id && (l1 = (struct list *)hash_lookup(lists, m->list_id)))
+ save_mlist(0, l1, 1);
+ }
}
-/* Determine if a list, given by list_id, is a user group.
- * We really need to figure out a way to do this right.
- */
+int lwid, bol, awid;
-int user_group(id)
+output_mlist(id, l)
int id;
+register struct list *l;
{
- return(0);
+ struct list *l1;
+ register struct member *m;
+ struct user *u;
+
+ put_fill(out, l->description);
+ if (l->acl_t == 'L') {
+ if (l1 = (struct list *) hash_lookup(lists, l->acl_id))
+ fprintf(out, "owner-%s: %s\n", l->name, l1->name);
+ } else if (l->acl_t == 'U') {
+ if (u = (struct user *) hash_lookup(users, l->acl_id))
+ fprintf(out, "owner-%s: %s\n", l->name, u->login);
+ }
+
+ fprintf(out, "%s: ", l->name);
+ lwid = strlen(l->name) + 2;
+ bol = 1;
+ for (m = l->m; m; m = m->next)
+ do_member(out, m->name);
+ if (l->m == (struct member *)NULL)
+ fprintf(out, "/dev/null");
+ fprintf(out, "\n\n");
}
* to be processed. If further sublists are encountered, repeat...
*/
-int lwid, bol;
-
do_mlists(out)
FILE *out;
{
- register struct list *l;
- struct list *l1;
- register struct member *m;
- struct user *u;
- register struct save_queue *sq;
- struct save_queue *sq_create();
- int id;
-
- sq = sq_create();
fprintf(out, "\n%s\n# Mailing lists\n%s\n", divide, divide);
-
- hash_step(lists, save_mlist, sq);
-
- while (sq_get_data(sq, &id)) {
- l = (struct list *) hash_lookup(lists, id);
- if (l->m && /* there's at least one member */
- l->m->next == NULL && /* there's only one member */
- !strcmp(l->name, l->m->name)) /* the member is same as list */
- continue;
- put_fill(out, l->description);
- if (l->acl_t == 'L') {
- if (l1 = (struct list *) hash_lookup(lists, l->acl_id)) {
- fprintf(out, "owner-%s: %s\n", l->name, l1->name);
- if (!user_group(l->acl_id))
- sq_save_unique_data(sq, l->acl_id);
- }
- } else if (l->acl_t == 'U') {
- if (u = (struct user *) hash_lookup(users, l->acl_id))
- fprintf(out, "owner-%s: %s\n", l->name, u->login);
- }
- fprintf(out, "%s: ", l->name);
- lwid = strlen(l->name) + 2;
- bol = 1;
- for (m = l->m; m; m = m->next) {
- if (m->list_id != 0 && user_group(m->list_id))
- sq_save_unique_data(sq, m->list_id);
- do_member(out, m->name);
- }
- fprintf(out, "\n\n");
- }
-
- sq_destroy(sq);
+ hash_step(lists, save_mlist, 0);
}
register char *s;
{
register wwid;
- static int awid;
static int cont = 1;
- strtrim(s);
wwid = strlen(s);
- if (awid + wwid + 2 > AL_MAX_WID) {
+ if (!bol && awid + wwid + 2 > AL_MAX_WID) {
fprintf(out, ",\n\tcontinuation-%d\ncontinuation-%d: ", cont, cont);
cont++;
- awid = lwid = bol = 17;
+ awid = lwid = 17 + wwid;
+ fputs(s, out);
+ return;
}
if (bol) {
lwid += wwid;
awid = lwid;
- fprintf(out, "%s", s);
+ fputs(s, out);
bol = 0;
return;
}
if (lwid + wwid + 2 > ML_WID) {
fprintf(out, ",\n\t%s", s);
- awid = lwid + wwid + 2;
+ awid += lwid + wwid + 2;
lwid = wwid + 8;
return;
}
do_poboxes(out)
FILE *out;
{
- register char *p;
- char *index();
-
fprintf(out, "\n%s\n# User Poboxes\n%s\n", divide, divide);
hash_step(users, do_pobox, out);