3 * This generates the /usr/lib/aliases mail aliases file for the mailhub.
4 * The aliases file will contain:
7 * sublists of maillists
17 #define AL_MAX_WID 896
19 char *divide = "########################################################################";
32 if ((out = fopen(argv[1], "w")) == NULL) {
33 fprintf(stderr, "unable to open %s for output\n", argv[1]);
36 } else if (argc != 1) {
37 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
42 ## set lockmode session where readlock = nolock
45 fprintf(out, "%s\n# Aliases File Extract of %s", divide, ctime(&tm));
46 fprintf(out, "# This file is automatically generated, do not edit it directly.\n%s\n\n", divide);
52 fprintf(out, "\n%s\n# End of aliases file\n%s\n", divide, divide);
54 ## inquire_equel(error = "errorno")
56 fprintf(out, "Ingres error %d\n", error);
63 perror("close failed");
70 /* Extract mailing lists. First dump all real mailing lists. While doing
71 * this, make a list of all mailing list IDs and all sub-list IDs. Next,
72 * as long as there are sub-lists that aren't mailing lists, extract them
73 * and add them to the list of mailing lists. If further sublists are
74 * encountered, repeat...
82 ## char name[257], desc[257], own_type[9], owner_name[33];
83 ## int id, own_id, member_id;
84 struct save_queue *sq, *sq_create();
87 fprintf(out, "\n%s\n# Mailing lists\n%s\n", divide, divide);
90 ## retrieve (id = l.list_id) where l.maillist != 0 {
91 sq_save_unique_data(sq, id);
94 ## range of m is members
95 ## range of u is users
96 ## range of s is strings
97 while (sq_get_data(sq, &id)) {
98 ## repeat retrieve (name= l.#name, desc = l.#desc,
99 ## own_type = l.acl_type, own_id = l.acl_id)
100 ## where l.list_id = @id
105 if (!strcmp(own_type, "LIST")) {
106 ## repeat retrieve (owner_name = l.#name) where l.list_id = @own_id
108 fprintf(out, "owner-%s: %s\n", name, owner_name);
109 sq_save_unique_data(sq, own_id);
110 } else if (!strcmp(own_type, "USER")) {
111 ## repeat retrieve (owner_name = u.#login) where u.users_id = @own_id
113 fprintf(out, "owner-%s: %s\n", name, owner_name);
115 fprintf(out, "%s: ", name);
116 lwid = strlen(name) + 2;
118 ## repeat retrieve (name = u.#login) where u.users_id = m.#member_id and
119 ## m.list_id = @id and m.member_type = "USER" {
120 do_member(out, name);
122 ## repeat retrieve (name = l.#name, member_id = m.#member_id)
123 ## where l.list_id = m.#member_id and
124 ## m.list_id = @id and m.member_type = "LIST" {
125 do_member(out, name);
126 sq_save_unique_data(sq, member_id);
128 ## repeat retrieve (name = s.#string) where s.string_id = m.#member_id and
129 ## m.list_id = @id and m.member_type = "STRING" {
130 do_member(out, name);
132 fprintf(out, "\n\n");
139 /* print out strings separated by commas, doing line breaks as appropriate */
152 if (awid + wwid + 2 > AL_MAX_WID) {
153 fprintf(out, ",\n\tcontinuation-%d\ncontinuation-%d: ", cont, cont);
155 awid = lwid = bol = 17;
161 fprintf(out, "%s", s);
165 if (lwid + wwid + 2 > ML_WID) {
166 fprintf(out, ",\n\t%s", s);
167 awid = lwid + wwid + 2;
172 fprintf(out, ", %s", s);
176 /* Extract user poboxes. First do POP boxes, where the name matches the
177 * login name and the machine name is in the pop_id. Then do SMTP boxes,
178 * where the expansion is stored in the strings table. The remaining boxes
179 * are of type NONE and should be skipped.
185 ## char login[9], name[33], box[129];
187 fprintf(out, "\n%s\n# User Poboxes\n%s\n", divide, divide);
189 ## range of u is users
190 ## range of m is machine
191 ## retrieve (login = u.#login, name = m.#name)
192 ## where u.potype = "POP" and m.mach_id = u.pop_id {
194 fprintf(out, "%s: %s@%s\n", login, login, name);
197 fprintf(out, "\n# User Forwarding\n");
199 ## range of s is strings
200 ## retrieve (login = u.#login, box = s.#string)
201 ## where u.potype = "SMTP" and u.box_id = s.string_id {
204 fprintf(out, "%s: %s\n", login, box);
213 ## char name[33], trans[129];
215 fprintf(out, "\n%s\n# Aliases\n%s\n", divide, divide);
217 ## range of a is alias
218 ## retrieve (name = a.#name, trans = a.#trans) where a.type = "MAIL" {
221 fprintf(out, "%s: %s\n", name, trans);
226 put_fill(aliases, string)
228 register char *string;
234 if (*string == 0) return;
235 fputs("# ", aliases);
239 while (*string && *string == ' ') string++;
240 c = (char *)index(string, ' ');
242 wwid = strlen(string);
248 if ((lwid + wwid) > ML_WID) {
249 fputs("\n# ", aliases);
251 fputs(string, aliases);
253 fputs(string, aliases);
256 if (c == (char *)0) break;
257 /* add a space after the word */
258 (void) fputc(' ', aliases);
262 /* add another if after a period */
264 (void) fputc(' ', aliases);
269 (void) fputc('\n', aliases);