3 * This generates the /usr/lib/aliases mail aliases file for the mailhub.
4 * The aliases file will contain:
7 * sublists of maillists
9 * (c) Copyright 1988 by the Massachusetts Institute of Technology.
10 * For copying and distribution information, please see the file
15 #include <mit-copyright.h>
20 #include <sys/types.h>
26 #define AL_MAX_WID 896
28 char *divide = "########################################################################";
30 char *whoami = "aliases.gen";
31 char *ingres_date_and_time();
40 char filename[64], *targetfile;
42 ## int flag1, flag2, flag3;
48 ## set lockmode session where level = table
51 if (stat(argv[1], &sb) == 0) {
52 filetime = ingres_date_and_time(sb.st_mtime);
53 ## retrieve (flag1 = int4(interval("min",tblstats.modtime - filetime)))
54 ## where tblstats.table = "list"
55 ## retrieve (flag2 = int4(interval("min",tblstats.modtime - filetime)))
56 ## where tblstats.table = "members"
57 ## retrieve (flag3 = int4(interval("min",tblstats.modtime - filetime)))
58 ## where tblstats.table = "users"
59 if (flag1 < 0 && flag2 < 0 && flag3 < 0) {
60 fprintf(stderr, "File %s does not need to be rebuilt.\n",
66 sprintf(filename, "%s~", targetfile);
67 if ((out = fopen(filename, "w")) == NULL) {
68 fprintf(stderr, "unable to open %s for output\n", filename);
71 } else if (argc != 1) {
72 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
76 fprintf(out, "%s\n# Aliases File Extract of %s", divide, ctime(&tm));
77 fprintf(out, "# This file is automatically generated, do not edit it directly.\n%s\n\n", divide);
84 fprintf(stderr, "Dumping information\n");
88 fprintf(out, "\n%s\n# End of aliases file\n%s\n", divide, divide);
92 perror("close failed");
103 * ingerr: (supposedly) called when Ingres indicates an error.
104 * I have not yet been able to get this to work to intercept a
105 * database open error.
107 #define INGRES_DEADLOCK 4700
109 static int ingerr(num)
116 case INGRES_DEADLOCK:
117 ingres_errno = SMS_DEADLOCK;
120 ingres_errno = SMS_INGRES_ERR;
122 com_err(whoami, SMS_INGRES_ERR, " code %d\n", *num);
123 critical_alert("DCM", "Alias build encountered INGRES ERROR %d", *num);
128 struct hash *users, *machines, *strings, *lists;
142 char description[256];
150 ## int id, maillistp, acl, pid, bid, mid;
151 ## char name[129], type[9], buf[257];
153 register struct user *u;
154 register struct list *l;
155 register struct member *m;
156 register struct list *memberlist;
159 ## retrieve (buf = list.modtime) where list.list_id = 0
160 ## retrieve (buf = users.modtime) where users.users_id = 0
162 fprintf(stderr, "Loading machines\n");
163 machines = create_hash(1000);
164 ## retrieve (id = machine.mach_id, name = machine.#name) {
165 if (s = index(name, '.'))
167 sprintf(buf, "%s.LOCAL", name);
168 hash_store(machines, id, strsave(buf));
171 fprintf(stderr, "Loading strings\n");
172 strings = create_hash(2000);
173 ## retrieve (id = strings.string_id, name = strings.string) {
174 hash_store(strings, id, strsave(strtrim(name)));
177 fprintf(stderr, "Loading users\n");
178 users = create_hash(15000);
179 ## range of u is users
180 ## retrieve (id = u.users_id, name = u.login, type = u.potype,
181 ## pid = u.pop_id, bid = u.box_id) where u.status = 1 {
182 u = (struct user *) malloc(sizeof(struct user));
183 strcpy(u->login, strtrim(name));
184 u->pobox = (char *) NULL;
185 if (type[0] == 'P') {
186 if (s = hash_lookup(machines, pid)) {
187 sprintf(buf, "%s@%s", name, s);
188 u->pobox = strsave(buf);
190 fprintf(stderr, "User %s's pobox is on a missing machine!\n",
193 } else if (type[0] == 'S') {
194 if ((u->pobox = hash_lookup(strings, bid)) == NULL)
195 fprintf(stderr, "User %s's pobox string is missing!\n", u->login);
197 hash_store(users, id, u);
200 fprintf(stderr, "Loading lists\n");
201 lists = create_hash(15000);
202 ## range of l is list
203 ## retrieve (id = l.list_id, name = l.#name, maillistp = l.maillist,
204 ## buf = l.desc, type = l.acl_type, acl = l.acl_id)
205 ## where l.active != 0 {
206 l = (struct list *) malloc(sizeof(struct list));
207 strcpy(l->name, strtrim(name));
208 l->maillist = maillistp;
209 strcpy(l->description, strtrim(buf));
212 l->m = (struct member *) NULL;
213 hash_store(lists, id, l);
217 fprintf(stderr, "Loading members\n");
218 ## range of m is members
219 ## retrieve (id = m.list_id, type = m.member_type, mid = m.member_id) {
220 if (l = (struct list *) hash_lookup(lists, id)) {
221 m = (struct member *) malloc(sizeof(struct member));
222 m->name = (char *) NULL;
223 if (type[0] == 'U') {
225 if (u = (struct user *) hash_lookup(users, mid))
227 } else if (type[0] == 'L') {
229 if (memberlist = (struct list *) hash_lookup(lists, mid))
230 m->name = memberlist->name;
231 } else if (type[0] == 'S') {
233 if (s = hash_lookup(strings, mid))
236 if (m->name != (char *) NULL) {
245 void save_mlist(id, l, sq)
248 struct save_queue *sq;
251 sq_save_unique_data(sq, id);
255 /* Extract mailing lists. Make a list of all mailinglists, then
256 * process them, adding any sub-lists or acl lists to the list of lists
257 * to be processed. If further sublists are encountered, repeat...
265 register struct list *l;
267 register struct member *m;
269 register struct save_queue *sq;
270 struct save_queue *sq_create();
274 fprintf(out, "\n%s\n# Mailing lists\n%s\n", divide, divide);
276 hash_step(lists, save_mlist, sq);
278 while (sq_get_data(sq, &id)) {
279 l = (struct list *) hash_lookup(lists, id);
280 if (l->m && /* there's at least one member */
281 l->m->next == NULL && /* there's only one member */
282 !strcmp(l->name, l->m->name)) /* the member is same as list */
284 put_fill(out, l->description);
285 if (l->acl_t == 'L') {
286 if (l1 = (struct list *) hash_lookup(lists, l->acl_id)) {
287 fprintf(out, "owner-%s: %s\n", l->name, l1->name);
288 sq_save_unique_data(sq, l->acl_id);
290 } else if (l->acl_t == 'U') {
291 if (u = (struct user *) hash_lookup(users, l->acl_id))
292 fprintf(out, "owner-%s: %s\n", l->name, u->login);
294 fprintf(out, "%s: ", l->name);
295 lwid = strlen(l->name) + 2;
297 for (m = l->m; m; m = m->next) {
299 sq_save_unique_data(sq, m->list_id);
300 do_member(out, m->name);
302 fprintf(out, "\n\n");
305 /* Removed for speed, since this take 10 minutes to free, and we don't
306 * really need the memory reclaimed.
311 /* print out strings separated by commas, doing line breaks as appropriate */
323 if (!bol && awid + wwid + 2 > AL_MAX_WID) {
324 fprintf(out, ",\n\tcontinuation-%d\ncontinuation-%d: ", cont, cont);
326 awid = lwid = bol = 17;
332 fprintf(out, "%s", s);
336 if (lwid + wwid + 2 > ML_WID) {
337 fprintf(out, ",\n\t%s", s);
338 awid += lwid + wwid + 2;
343 fprintf(out, ", %s", s);
348 register struct user *u;
352 fprintf(out, "%s: %s\n", u->login, u->pobox);
356 /* Do user poboxes. Just step through the users table, and print any
357 * we extracted earlier.
366 fprintf(out, "\n%s\n# User Poboxes\n%s\n", divide, divide);
368 hash_step(users, do_pobox, out);
372 put_fill(aliases, string)
374 register char *string;
380 if (*string == 0) return;
381 fputs("# ", aliases);
385 while (*string && *string == ' ') string++;
386 c = (char *)index(string, ' ');
388 wwid = strlen(string);
394 if ((lwid + wwid) > ML_WID) {
395 fputs("\n# ", aliases);
397 fputs(string, aliases);
399 fputs(string, aliases);
402 if (c == (char *)0) break;
403 /* add a space after the word */
404 (void) fputc(' ', aliases);
408 /* add another if after a period */
410 (void) fputc(' ', aliases);
415 (void) fputc('\n', aliases);