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;
50 if (stat(argv[1], &sb) == 0) {
51 filetime = ingres_date_and_time(sb.st_mtime);
52 ## retrieve (flag1 = int4(interval("min",tblstats.modtime - filetime)))
53 ## where tblstats.table = "list"
54 ## retrieve (flag2 = int4(interval("min",tblstats.modtime - filetime)))
55 ## where tblstats.table = "members"
56 ## retrieve (flag3 = int4(interval("min",tblstats.modtime - filetime)))
57 ## where tblstats.table = "users"
58 if (flag1 < 0 && flag2 < 0 && flag3 < 0) {
59 fprintf(stderr, "File %s does not need to be rebuilt.\n",
65 sprintf(filename, "%s~", targetfile);
66 if ((out = fopen(filename, "w")) == NULL) {
67 fprintf(stderr, "unable to open %s for output\n", filename);
70 } else if (argc != 1) {
71 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
75 fprintf(out, "%s\n# Aliases File Extract of %s", divide, ctime(&tm));
76 fprintf(out, "# This file is automatically generated, do not edit it directly.\n%s\n\n", divide);
83 fprintf(stderr, "Dumping information\n");
87 fprintf(out, "\n%s\n# End of aliases file\n%s\n", divide, divide);
91 perror("close failed");
102 * ingerr: (supposedly) called when Ingres indicates an error.
103 * I have not yet been able to get this to work to intercept a
104 * database open error.
106 #define INGRES_DEADLOCK 4700
108 static int ingerr(num)
115 case INGRES_DEADLOCK:
116 ingres_errno = SMS_DEADLOCK;
119 ingres_errno = SMS_INGRES_ERR;
121 com_err(whoami, SMS_INGRES_ERR, " code %d\n", *num);
122 critical_alert("DCM", "Alias build encountered INGRES ERROR %d", *num);
127 struct hash *users, *machines, *strings, *lists;
141 char description[256];
149 ## int id, maillistp, acl, pid, bid, mid;
150 ## char name[129], type[9], buf[257];
152 register struct user *u;
153 register struct list *l;
154 register struct member *m;
155 register struct list *memberlist;
157 fprintf(stderr, "Loading machines\n");
158 machines = create_hash(1000);
159 ## retrieve (id = machine.mach_id, name = machine.#name) {
160 if (s = index(name, '.'))
162 sprintf(buf, "%s.LOCAL", name);
163 hash_store(machines, id, strsave(buf));
166 fprintf(stderr, "Loading strings\n");
167 strings = create_hash(2000);
168 ## retrieve (id = strings.string_id, name = strings.string) {
169 hash_store(strings, id, strsave(strtrim(name)));
172 fprintf(stderr, "Loading users\n");
173 users = create_hash(15000);
174 ## range of u is users
175 ## retrieve (id = u.users_id, name = u.login, type = u.potype,
176 ## pid = u.pop_id, bid = u.box_id) where u.status = 1 {
177 u = (struct user *) malloc(sizeof(struct user));
178 strcpy(u->login, strtrim(name));
179 u->pobox = (char *) NULL;
180 if (type[0] == 'P') {
181 if (s = hash_lookup(machines, pid)) {
182 sprintf(buf, "%s@%s", name, s);
183 u->pobox = strsave(buf);
185 fprintf(stderr, "User %s's pobox is on a missing machine!\n",
188 } else if (type[0] == 'S') {
189 if ((u->pobox = hash_lookup(strings, bid)) == NULL)
190 fprintf(stderr, "User %s's pobox string is missing!\n", u->login);
192 hash_store(users, id, u);
195 fprintf(stderr, "Loading lists\n");
196 lists = create_hash(15000);
197 ## range of l is list
198 ## retrieve (id = l.list_id, name = l.#name, maillistp = l.maillist,
199 ## buf = l.desc, type = l.acl_type, acl = l.acl_id)
200 ## where l.active != 0 {
201 l = (struct list *) malloc(sizeof(struct list));
202 strcpy(l->name, strtrim(name));
203 l->maillist = maillistp;
204 strcpy(l->description, strtrim(buf));
207 l->m = (struct member *) NULL;
208 hash_store(lists, id, l);
212 fprintf(stderr, "Loading members\n");
213 ## range of m is members
214 ## retrieve (id = m.list_id, type = m.member_type, mid = m.member_id) {
215 if (l = (struct list *) hash_lookup(lists, id)) {
216 m = (struct member *) malloc(sizeof(struct member));
217 m->name = (char *) NULL;
218 if (type[0] == 'U') {
220 if (u = (struct user *) hash_lookup(users, mid))
222 } else if (type[0] == 'L') {
224 if (memberlist = (struct list *) hash_lookup(lists, mid))
225 m->name = memberlist->name;
226 } else if (type[0] == 'S') {
228 if (s = hash_lookup(strings, mid))
231 if (m->name != (char *) NULL) {
240 void save_mlist(id, l, sq)
243 struct save_queue *sq;
246 sq_save_unique_data(sq, id);
250 /* Extract mailing lists. Make a list of all mailinglists, then
251 * process them, adding any sub-lists or acl lists to the list of lists
252 * to be processed. If further sublists are encountered, repeat...
260 register struct list *l;
262 register struct member *m;
264 register struct save_queue *sq;
265 struct save_queue *sq_create();
269 fprintf(out, "\n%s\n# Mailing lists\n%s\n", divide, divide);
271 hash_step(lists, save_mlist, sq);
273 while (sq_get_data(sq, &id)) {
274 l = (struct list *) hash_lookup(lists, id);
275 if (l->m && /* there's at least one member */
276 l->m->next == NULL && /* there's only one member */
277 !strcmp(l->name, l->m->name)) /* the member is same as list */
279 put_fill(out, l->description);
280 if (l->acl_t == 'L') {
281 if (l1 = (struct list *) hash_lookup(lists, l->acl_id)) {
282 fprintf(out, "owner-%s: %s\n", l->name, l1->name);
283 sq_save_unique_data(sq, l->acl_id);
285 } else if (l->acl_t == 'U') {
286 if (u = (struct user *) hash_lookup(users, l->acl_id))
287 fprintf(out, "owner-%s: %s\n", l->name, u->login);
289 fprintf(out, "%s: ", l->name);
290 lwid = strlen(l->name) + 2;
292 for (m = l->m; m; m = m->next) {
294 sq_save_unique_data(sq, m->list_id);
295 do_member(out, m->name);
297 fprintf(out, "\n\n");
300 /* Removed for speed, since this take 10 minutes to free, and we don't
301 * really need the memory reclaimed.
306 /* print out strings separated by commas, doing line breaks as appropriate */
318 if (!bol && awid + wwid + 2 > AL_MAX_WID) {
319 fprintf(out, ",\n\tcontinuation-%d\ncontinuation-%d: ", cont, cont);
321 awid = lwid = bol = 17;
327 fprintf(out, "%s", s);
331 if (lwid + wwid + 2 > ML_WID) {
332 fprintf(out, ",\n\t%s", s);
333 awid += lwid + wwid + 2;
338 fprintf(out, ", %s", s);
343 register struct user *u;
347 fprintf(out, "%s: %s\n", u->login, u->pobox);
351 /* Do user poboxes. Just step through the users table, and print any
352 * we extracted earlier.
361 fprintf(out, "\n%s\n# User Poboxes\n%s\n", divide, divide);
363 hash_step(users, do_pobox, out);
367 put_fill(aliases, string)
369 register char *string;
375 if (*string == 0) return;
376 fputs("# ", aliases);
380 while (*string && *string == ' ') string++;
381 c = (char *)index(string, ' ');
383 wwid = strlen(string);
389 if ((lwid + wwid) > ML_WID) {
390 fputs("\n# ", aliases);
392 fputs(string, aliases);
394 fputs(string, aliases);
397 if (c == (char *)0) break;
398 /* add a space after the word */
399 (void) fputc(' ', aliases);
403 /* add another if after a period */
405 (void) fputc(' ', aliases);
410 (void) fputc('\n', aliases);