3 * This generates the /usr/lib/aliases mail aliases file for the mailhub.
4 * The aliases file will contain:
7 * sublists of maillists
15 #include <sys/types.h>
21 #define AL_MAX_WID 896
23 char *divide = "########################################################################";
25 char *ingres_date_and_time();
35 ## int error, flag1, flag2, flag3;
41 if (stat(argv[1], &sb) == 0) {
42 filetime = ingres_date_and_time(sb.st_mtime);
43 ## retrieve (flag1 = int4(interval("min",tblstats.modtime - filetime)))
44 ## where tblstats.table = "list"
45 ## retrieve (flag2 = int4(interval("min",tblstats.modtime - filetime)))
46 ## where tblstats.table = "members"
47 ## retrieve (flag3 = int4(interval("min",tblstats.modtime - filetime)))
48 ## where tblstats.table = "users"
49 if (flag1 < 0 && flag2 < 0 && flag3 < 0) {
50 fprintf(stderr, "File %s does not need to be rebuilt.\n",
55 if ((out = fopen(argv[1], "w")) == NULL) {
56 fprintf(stderr, "unable to open %s for output\n", argv[1]);
59 } else if (argc != 1) {
60 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
64 ## set lockmode session where readlock = nolock
67 fprintf(out, "%s\n# Aliases File Extract of %s", divide, ctime(&tm));
68 fprintf(out, "# This file is automatically generated, do not edit it directly.\n%s\n\n", divide);
74 fprintf(out, "\n%s\n# End of aliases file\n%s\n", divide, divide);
76 ## inquire_equel(error = "errorno")
78 fprintf(out, "Ingres error %d\n", error);
85 perror("close failed");
92 /* Extract mailing lists. First dump all real mailing lists. While doing
93 * this, make a list of all mailing list IDs and all sub-list IDs. Next,
94 * as long as there are sub-lists that aren't mailing lists, extract them
95 * and add them to the list of mailing lists. If further sublists are
96 * encountered, repeat...
104 ## char name[257], desc[257], own_type[9], owner_name[33];
105 ## int id, own_id, member_id;
106 struct save_queue *sq, *sq_create();
109 fprintf(out, "\n%s\n# Mailing lists\n%s\n", divide, divide);
111 ## range of l is list
112 ## retrieve (id = l.list_id) where l.maillist != 0 {
113 sq_save_unique_data(sq, id);
116 ## range of m is members
117 ## range of u is users
118 ## range of s is strings
119 while (sq_get_data(sq, &id)) {
120 ## repeat retrieve (name= l.#name, desc = l.#desc,
121 ## own_type = l.acl_type, own_id = l.acl_id)
122 ## where l.list_id = @id
127 if (!strcmp(own_type, "LIST")) {
128 ## repeat retrieve (owner_name = l.#name) where l.list_id = @own_id
130 fprintf(out, "owner-%s: %s\n", name, owner_name);
131 sq_save_unique_data(sq, own_id);
132 } else if (!strcmp(own_type, "USER")) {
133 ## repeat retrieve (owner_name = u.#login) where u.users_id = @own_id
135 fprintf(out, "owner-%s: %s\n", name, owner_name);
137 fprintf(out, "%s: ", name);
138 lwid = strlen(name) + 2;
140 ## repeat retrieve (name = u.#login) where u.users_id = m.#member_id and
141 ## m.list_id = @id and m.member_type = "USER" {
142 do_member(out, name);
144 ## repeat retrieve (name = l.#name, member_id = m.#member_id)
145 ## where l.list_id = m.#member_id and
146 ## m.list_id = @id and m.member_type = "LIST" {
147 do_member(out, name);
148 sq_save_unique_data(sq, member_id);
150 ## repeat retrieve (name = s.#string) where s.string_id = m.#member_id and
151 ## m.list_id = @id and m.member_type = "STRING" {
152 do_member(out, name);
154 fprintf(out, "\n\n");
161 /* print out strings separated by commas, doing line breaks as appropriate */
174 if (awid + wwid + 2 > AL_MAX_WID) {
175 fprintf(out, ",\n\tcontinuation-%d\ncontinuation-%d: ", cont, cont);
177 awid = lwid = bol = 17;
183 fprintf(out, "%s", s);
187 if (lwid + wwid + 2 > ML_WID) {
188 fprintf(out, ",\n\t%s", s);
189 awid = lwid + wwid + 2;
194 fprintf(out, ", %s", s);
198 /* Extract user poboxes. First do POP boxes, where the name matches the
199 * login name and the machine name is in the pop_id. Then do SMTP boxes,
200 * where the expansion is stored in the strings table. The remaining boxes
201 * are of type NONE and should be skipped.
207 ## char login[9], name[33], box[129];
209 fprintf(out, "\n%s\n# User Poboxes\n%s\n", divide, divide);
211 ## range of u is users
212 ## range of m is machine
213 ## retrieve (login = u.#login, name = m.#name)
214 ## where u.potype = "POP" and m.mach_id = u.pop_id {
216 fprintf(out, "%s: %s@%s\n", login, login, name);
219 fprintf(out, "\n# User Forwarding\n");
221 ## range of s is strings
222 ## retrieve (login = u.#login, box = s.#string)
223 ## where u.potype = "SMTP" and u.box_id = s.string_id {
226 fprintf(out, "%s: %s\n", login, box);
235 ## char name[33], trans[129];
237 fprintf(out, "\n%s\n# Aliases\n%s\n", divide, divide);
239 ## range of a is alias
240 ## retrieve (name = a.#name, trans = a.#trans) where a.type = "MAIL" {
243 fprintf(out, "%s: %s\n", name, trans);
248 put_fill(aliases, string)
250 register char *string;
256 if (*string == 0) return;
257 fputs("# ", aliases);
261 while (*string && *string == ' ') string++;
262 c = (char *)index(string, ' ');
264 wwid = strlen(string);
270 if ((lwid + wwid) > ML_WID) {
271 fputs("\n# ", aliases);
273 fputs(string, aliases);
275 fputs(string, aliases);
278 if (c == (char *)0) break;
279 /* add a space after the word */
280 (void) fputc(' ', aliases);
284 /* add another if after a period */
286 (void) fputc(' ', aliases);
291 (void) fputc('\n', aliases);