Commit | Line | Data |
---|---|---|
c988f1f4 | 1 | /* $Cambridge: exim/src/src/buildconfig.c,v 1.5 2005/01/04 10:00:42 ph10 Exp $ */ |
059ec3d9 PH |
2 | |
3 | /************************************************* | |
4 | * Exim - an Internet mail transport agent * | |
5 | *************************************************/ | |
6 | ||
c988f1f4 | 7 | /* Copyright (c) University of Cambridge 1995 - 2005 */ |
059ec3d9 PH |
8 | /* See the file NOTICE for conditions of use and distribution. */ |
9 | ||
10 | ||
11 | /************************************************* | |
12 | * Build configuration header for Exim * | |
13 | *************************************************/ | |
14 | ||
15 | /* This auxiliary program builds the file config.h by the following | |
16 | process: | |
17 | ||
18 | First it reads Makefile, looking for certain OS-specific definitions which it | |
19 | uses to define macros. Then it reads the defaults file config.h.defaults. | |
20 | ||
21 | The defaults file contains normal C #define statements for various macros; if | |
22 | the name of a macro is found in the environment, the environment value replaces | |
23 | the default. If the default #define does not contain any value, then that macro | |
24 | is not copied to the created file unless there is some value in the | |
25 | environment. | |
26 | ||
27 | This program is compiled and run as part of the Make process and is not | |
28 | normally called independently. */ | |
29 | ||
30 | ||
31 | #include <ctype.h> | |
32 | #include <stdio.h> | |
33 | #include <stdlib.h> | |
34 | #include <string.h> | |
35 | #include <sys/types.h> | |
36 | #include <pwd.h> | |
37 | #include <grp.h> | |
38 | ||
39 | typedef struct { | |
40 | char *name; | |
41 | int *flag; | |
42 | } have_item; | |
43 | ||
44 | typedef struct { | |
45 | char *name; | |
46 | char *data; | |
47 | } save_item; | |
48 | ||
49 | static char *db_opts[] = { "", "USE_DB", "USE_GDBM", "USE_TDB" }; | |
50 | ||
51 | static int have_ipv6 = 0; | |
52 | static int have_iconv = 0; | |
53 | ||
54 | static char errno_quota[256]; | |
55 | static char ostype[256]; | |
56 | static char cc[256]; | |
57 | ||
58 | /* If any entry is an initial substring of another, the longer one must | |
59 | appear first. */ | |
60 | ||
61 | static have_item have_list[] = { | |
62 | { "HAVE_IPV6", &have_ipv6 }, | |
63 | { "HAVE_ICONV", &have_iconv }, | |
64 | { NULL, NULL} | |
65 | }; | |
66 | ||
67 | static save_item save_list[] = { | |
68 | { "ERRNO_QUOTA", errno_quota }, | |
69 | { "OSTYPE", ostype }, | |
70 | { "CC", cc }, | |
71 | { NULL, NULL} | |
72 | }; | |
73 | ||
74 | ||
75 | /* Subroutine to check a string for precisely one instance of "%s". If not, | |
76 | bomb out. */ | |
77 | ||
78 | void | |
79 | check_percent_ess(char *value, char *name) | |
80 | { | |
81 | int OK = 0; | |
82 | char *p = strstr(value, "%s"); | |
83 | if (p != NULL) OK = strstr(p+2, "%s") == NULL; | |
84 | if (!OK) | |
85 | { | |
86 | printf("\n*** \"%s\" (%s) must contain precisely one occurrence of\n" | |
87 | "*** \"%%s\". Please review your build-time configuration.\n\n/", value, | |
88 | name); | |
89 | exit(1); | |
90 | } | |
91 | } | |
92 | ||
93 | ||
94 | /* Main program */ | |
95 | ||
96 | int | |
97 | main(int argc, char **argv) | |
98 | { | |
99 | FILE *base; | |
100 | FILE *new; | |
101 | int last_initial = 'A'; | |
102 | int linecount = 0; | |
103 | int have_auth = 0; | |
104 | int in_local_makefile = 0; | |
105 | int use_which_db = 0; | |
106 | int use_which_db_in_local_makefile = 0; | |
107 | int support_crypteq = 0; | |
108 | char buffer[1024]; | |
109 | ||
110 | if (argc != 1) | |
111 | { | |
112 | printf("*** Buildconfig: called with incorrect arguments\n"); | |
113 | exit(1); | |
114 | } | |
115 | ||
116 | new = fopen("config.h", "wb"); | |
117 | if (new == NULL) | |
118 | { | |
119 | printf("*** Buildconfig: failed to open config.h for output\n"); | |
120 | exit(1); | |
121 | } | |
122 | ||
123 | printf("Building configuration file config.h\n"); | |
124 | ||
125 | fprintf(new, "/*************************************************\n"); | |
126 | fprintf(new, "* Configuration header for Exim *\n"); | |
127 | fprintf(new, "*************************************************/\n\n"); | |
128 | ||
129 | fprintf(new, "/* This file was automatically generated from Makefile and " | |
130 | "config.h.defaults,\n"); | |
131 | fprintf(new, "using values specified in the configuration file Local/Makefile.\n"); | |
132 | fprintf(new, "Do not edit it. Instead, edit Local/Makefile and " | |
133 | "rerun make. */\n\n"); | |
134 | ||
135 | /* First, search the makefile for certain settings */ | |
136 | ||
137 | base = fopen("Makefile", "rb"); | |
138 | if (base == NULL) | |
139 | { | |
140 | printf("*** Buildconfig: failed to open Makefile\n"); | |
141 | fclose(new); | |
142 | exit(1); | |
143 | } | |
144 | ||
145 | errno_quota[0] = 0; /* no over-riding value set */ | |
146 | ostype[0] = 0; /* just in case */ | |
147 | cc[0] = 0; | |
148 | ||
149 | while (fgets(buffer, sizeof(buffer), base) != NULL) | |
150 | { | |
151 | int i; | |
152 | have_item *h; | |
153 | save_item *s; | |
154 | char *p = buffer + (int)strlen(buffer); | |
155 | linecount++; | |
156 | while (p > buffer && isspace((unsigned char)p[-1])) p--; | |
157 | *p = 0; | |
158 | p = buffer; | |
159 | while (isspace((unsigned char)*p)) p++; | |
160 | ||
161 | /* Notice when we hit the user's makefile */ | |
162 | ||
163 | if (strcmp(p, "# From Local/Makefile") == 0) | |
164 | { | |
165 | in_local_makefile = 1; | |
166 | continue; | |
167 | } | |
168 | ||
169 | /* Remember the last DB option setting. If we hit two in the user's | |
170 | Makefile, complain. */ | |
171 | ||
172 | for (i = 1; i < sizeof(db_opts)/sizeof(char *); i++) | |
173 | { | |
174 | int len = (int)strlen(db_opts[i]); | |
175 | if (strncmp(p, db_opts[i], len) == 0 && (p[len] == ' ' || p[len] == '=')) | |
176 | { | |
177 | if (in_local_makefile) | |
178 | { | |
179 | if (use_which_db_in_local_makefile) | |
180 | { | |
181 | printf("*** Only one of USE_DB, USE_GDBM, or USE_TDB should be " | |
182 | "defined in Local/Makefile\n"); | |
183 | exit(1); | |
184 | } | |
185 | use_which_db_in_local_makefile = 1; | |
186 | } | |
187 | use_which_db = i; | |
188 | break; | |
189 | } | |
190 | } | |
191 | if (i < sizeof(db_opts)/sizeof(char *)) continue; | |
192 | ||
193 | /* Items where we just save a boolean */ | |
194 | ||
195 | for (h = have_list; h->name != NULL; h++) | |
196 | { | |
197 | int len = (int)strlen(h->name); | |
198 | if (strncmp(p, h->name, len) == 0) | |
199 | { | |
200 | p += len; | |
201 | while (isspace((unsigned char)*p)) p++; | |
202 | if (*p++ != '=') | |
203 | { | |
204 | printf("*** Buildconfig: syntax error in Makefile line %d\n", linecount); | |
205 | exit(1); | |
206 | } | |
207 | while (isspace((unsigned char)*p)) p++; | |
208 | if (strcmp(p, "YES") == 0 || strcmp(p, "yes") == 0) *(h->flag) = 1; | |
209 | else *(h->flag) = 0; /* Must reset in case multiple instances */ | |
210 | break; | |
211 | } | |
212 | } | |
213 | ||
214 | if (h->name != NULL) continue; | |
215 | ||
216 | /* Items where we save the complete string */ | |
217 | ||
218 | for (s = save_list; s->name != NULL; s++) | |
219 | { | |
220 | int len = (int)strlen(s->name); | |
221 | if (strncmp(p, s->name, len) == 0) | |
222 | { | |
223 | p += len; | |
224 | while (isspace((unsigned char)*p)) p++; | |
225 | if (*p++ != '=') | |
226 | { | |
227 | printf("*** Buildconfig: syntax error in Makefile line %d\n", linecount); | |
228 | exit(1); | |
229 | } | |
230 | while (isspace((unsigned char)*p)) p++; | |
231 | strcpy(s->data, p); | |
232 | } | |
233 | } | |
234 | } | |
235 | ||
236 | fprintf(new, "#define HAVE_IPV6 %s\n", | |
237 | have_ipv6? "TRUE" : "FALSE"); | |
238 | ||
239 | fprintf(new, "#define HAVE_ICONV %s\n", | |
240 | have_iconv? "TRUE" : "FALSE"); | |
241 | ||
242 | if (errno_quota[0] != 0) | |
243 | fprintf(new, "\n#define ERRNO_QUOTA %s\n", errno_quota); | |
244 | ||
245 | if (strcmp(cc, "gcc") == 0 && strstr(ostype, "IRIX") != NULL) | |
246 | { | |
247 | fprintf(new, "\n/* This switch includes the code to fix the inet_ntoa() */"); | |
248 | fprintf(new, "\n/* bug when using gcc on an IRIX system. */"); | |
249 | fprintf(new, "\n#define USE_INET_NTOA_FIX"); | |
250 | } | |
251 | ||
252 | fprintf(new, "\n"); | |
253 | fclose(base); | |
254 | ||
255 | ||
256 | /* Now handle the macros listed in the defaults */ | |
257 | ||
258 | base = fopen("../src/config.h.defaults", "rb"); | |
259 | if (base == NULL) | |
260 | { | |
261 | printf("*** Buildconfig: failed to open ../src/config.h.defaults\n"); | |
262 | fclose(new); | |
263 | exit(1); | |
264 | } | |
265 | ||
266 | while (fgets(buffer, sizeof(buffer), base) != NULL) | |
267 | { | |
268 | int i; | |
269 | char name[256]; | |
270 | char *value; | |
271 | char *p = buffer; | |
272 | char *q = name; | |
273 | ||
274 | while (*p == ' ' || *p == '\t') p++; | |
275 | ||
276 | if (strncmp(p, "#define ", 8) != 0) continue; | |
277 | ||
278 | p += 8; | |
279 | while (*p == ' ' || *p == '\t') p++; | |
280 | ||
281 | if (*p < last_initial) fprintf(new, "\n"); | |
282 | last_initial = *p; | |
283 | ||
284 | while (*p && (isalnum((unsigned char)*p) || *p == '_')) *q++ = *p++; | |
285 | *q = 0; | |
286 | ||
287 | /* USE_DB, USE_GDBM, and USE_TDB are special cases. We want to have only | |
288 | one of them set. The scan of the Makefile has saved which was the last one | |
289 | encountered. */ | |
290 | ||
291 | for (i = 1; i < sizeof(db_opts)/sizeof(char *); i++) | |
292 | { | |
293 | if (strcmp(name, db_opts[i]) == 0) | |
294 | { | |
295 | if (use_which_db == i) | |
296 | fprintf(new, "#define %s %.*syes\n", db_opts[i], | |
297 | 21 - (int)strlen(db_opts[i]), " "); | |
298 | else | |
299 | fprintf(new, "/* %s not set */\n", name); | |
300 | break; | |
301 | } | |
302 | } | |
303 | if (i < sizeof(db_opts)/sizeof(char *)) continue; | |
304 | ||
305 | /* EXIM_USER is a special case. We look in the environment for EXIM_USER or | |
306 | EXIM_UID (the latter for backward compatibility with Exim 3). If the value is | |
307 | not numeric, we look up the user, and default the GID if found. Otherwise, | |
308 | EXIM_GROUP or EXIM_GID must be in the environment. */ | |
309 | ||
310 | if (strcmp(name, "EXIM_UID") == 0) | |
311 | { | |
312 | uid_t uid = 0; | |
313 | gid_t gid = 0; | |
314 | int gid_set = 0; | |
315 | char *username = NULL; | |
316 | char *groupname = NULL; | |
317 | char *s; | |
318 | char *user = getenv("EXIM_USER"); | |
319 | char *group = getenv("EXIM_GROUP"); | |
320 | ||
321 | if (user == NULL) user = getenv("EXIM_UID"); | |
322 | if (group == NULL) group = getenv("EXIM_GID"); | |
323 | ||
324 | if (user == NULL) | |
325 | { | |
326 | printf("\n*** EXIM_USER has not been defined in any of the Makefiles in " | |
327 | "the\n \"Local\" directory. Please review your build-time " | |
328 | "configuration.\n\n"); | |
329 | return 1; | |
330 | } | |
331 | ||
332 | while (isspace((unsigned char)(*user))) user++; | |
333 | if (*user == 0) | |
334 | { | |
335 | printf("\n*** EXIM_USER is defined as an empty string in one of the " | |
336 | "files\n in the \"Local\" directory. Please review your build-time" | |
337 | "\n configuration.\n\n"); | |
338 | return 1; | |
339 | } | |
340 | ||
341 | for (s = user; *s != 0; s++) | |
342 | { | |
343 | if (iscntrl((unsigned char)(*s))) | |
344 | { | |
345 | printf("\n*** EXIM_USER contains the control character 0x%02X in one " | |
346 | "of the files\n in the \"Local\" directory. Please review your " | |
347 | "build-time\n configuration.\n\n", *s); | |
348 | return 1; | |
349 | } | |
350 | } | |
351 | ||
352 | /* Numeric uid given */ | |
353 | ||
354 | if (user[strspn(user, "0123456789")] == 0) | |
355 | { | |
356 | uid = (uid_t)atoi(user); | |
357 | } | |
358 | ||
359 | /* User name given. Normally, we look up the uid right away. However, | |
360 | people building binary distributions sometimes want to retain the name till | |
361 | runtime. This is supported if the name begins "ref:". */ | |
362 | ||
363 | else if (strncmp(user, "ref:", 4) == 0) | |
364 | { | |
365 | user += 4; | |
366 | while (isspace(*user)) user++; | |
367 | username = user; | |
368 | gid_set = 1; | |
369 | } | |
370 | ||
371 | else | |
372 | { | |
373 | struct passwd *pw = getpwnam(user); | |
374 | if (pw == NULL) | |
375 | { | |
376 | printf("\n*** User \"%s\" (specified in one of the Makefiles) does not " | |
377 | "exist.\n Please review your build-time configuration.\n\n", | |
378 | user); | |
379 | return 1; | |
380 | } | |
381 | ||
382 | uid = pw->pw_uid; | |
383 | gid = pw->pw_gid; | |
384 | gid_set = 1; | |
385 | } | |
386 | ||
387 | /* Use explicit group if set. */ | |
388 | ||
389 | if (group != NULL) | |
390 | { | |
391 | while (isspace((unsigned char)(*group))) group++; | |
392 | if (*group == 0) | |
393 | { | |
394 | printf("\n*** EXIM_GROUP is defined as an empty string in one of " | |
395 | "the files in the\n \"Local\" directory. "); | |
396 | if (gid_set) | |
397 | { | |
398 | printf("If you want the Exim group to be taken from the\n " | |
399 | "password data for the Exim user, just remove the EXIM_GROUP " | |
400 | "setting.\n Otherwise, p"); | |
401 | } | |
402 | else printf("EXIM_USER is defined numerically, so there is no" | |
403 | "\n default for EXIM_GROUP and you must set it explicitly.\n P"); | |
404 | printf("lease review your build-time configuration.\n\n"); | |
405 | return 1; | |
406 | } | |
407 | ||
408 | for (s = group; *s != 0; s++) | |
409 | { | |
410 | if (iscntrl((unsigned char)(*s))) | |
411 | { | |
412 | printf("\n*** EXIM_GROUP contains the control character 0x%02X in one " | |
413 | "of the files\n in the \"Local\" directory. Please review your " | |
414 | "build-time\n configuration.\n\n", *s); | |
415 | return 1; | |
416 | } | |
417 | } | |
418 | ||
419 | /* Group name given. This may be by reference or to be looked up now, | |
420 | as for user. */ | |
421 | ||
422 | if (strncmp(group, "ref:", 4) == 0) | |
423 | { | |
424 | group += 4; | |
425 | while (isspace(*group)) group++; | |
426 | groupname = group; | |
427 | } | |
428 | ||
429 | else if (username != NULL) | |
430 | { | |
431 | groupname = group; | |
432 | } | |
433 | ||
434 | else if (group[strspn(group, "0123456789")] == 0) | |
435 | { | |
436 | gid = (gid_t)atoi(group); | |
437 | } | |
438 | ||
439 | else | |
440 | { | |
441 | struct group *gr = getgrnam(group); | |
442 | if (gr == NULL) | |
443 | { | |
444 | printf("\n*** Group \"%s\" (specified in one of the Makefiles) does " | |
445 | "not exist.\n Please review your build-time configuration.\n\n", | |
446 | group); | |
447 | return 1; | |
448 | } | |
449 | gid = gr->gr_gid; | |
450 | } | |
451 | } | |
452 | ||
453 | /* Else trouble unless found in passwd file with user */ | |
454 | ||
455 | else if (!gid_set) | |
456 | { | |
457 | printf("\n*** No group set for Exim. Please review your build-time " | |
458 | "configuration.\n\n"); | |
459 | return 1; | |
460 | } | |
461 | ||
462 | /* Output user and group names or uid/gid. When names are set, uid/gid | |
463 | are set to zero but will be replaced at runtime. */ | |
464 | ||
465 | if (username != NULL) | |
466 | fprintf(new, "#define EXIM_USERNAME \"%s\"\n", username); | |
467 | if (groupname != NULL) | |
468 | fprintf(new, "#define EXIM_GROUPNAME \"%s\"\n", groupname); | |
469 | ||
470 | fprintf(new, "#define EXIM_UID %d\n", (int)uid); | |
471 | fprintf(new, "#define EXIM_GID %d\n", (int)gid); | |
472 | continue; | |
473 | } | |
474 | ||
35edf2ff PH |
475 | /* CONFIGURE_OWNER and CONFIGURE_GROUP are special cases. We look in the |
476 | environment for first. If the value is not numeric, we look up the user or | |
477 | group. A lot of this code is similar to that for EXIM_USER, but it's easier | |
478 | to keep it separate. */ | |
059ec3d9 | 479 | |
35edf2ff PH |
480 | if (strcmp(name, "CONFIGURE_OWNER") == 0 || |
481 | strcmp(name, "CONFIGURE_GROUP") == 0) | |
059ec3d9 | 482 | { |
35edf2ff | 483 | int isgroup = name[10] == 'G'; |
059ec3d9 | 484 | uid_t uid = 0; |
35edf2ff | 485 | gid_t gid = 0; |
059ec3d9 PH |
486 | char *s; |
487 | char *username = NULL; | |
35edf2ff | 488 | char *user = getenv(name); |
059ec3d9 PH |
489 | |
490 | if (user == NULL) user = ""; | |
491 | while (isspace((unsigned char)(*user))) user++; | |
492 | if (*user == 0) | |
493 | { | |
494 | fprintf(new, "/* %s not set */\n", name); | |
495 | continue; | |
496 | } | |
497 | ||
498 | for (s = user; *s != 0; s++) | |
499 | { | |
500 | if (iscntrl((unsigned char)(*s))) | |
501 | { | |
35edf2ff | 502 | printf("\n*** %s contains the control character 0x%02X in " |
059ec3d9 | 503 | "one of the files\n in the \"Local\" directory. Please review " |
35edf2ff | 504 | "your build-time\n configuration.\n\n", name, *s); |
059ec3d9 PH |
505 | return 1; |
506 | } | |
507 | } | |
508 | ||
509 | /* Numeric uid given */ | |
510 | ||
511 | if (user[strspn(user, "0123456789")] == 0) | |
512 | { | |
35edf2ff PH |
513 | if (isgroup) |
514 | gid = (gid_t)atoi(user); | |
515 | else | |
516 | uid = (uid_t)atoi(user); | |
059ec3d9 PH |
517 | } |
518 | ||
35edf2ff | 519 | /* Name given. Normally, we look up the uid or gid right away. However, |
059ec3d9 PH |
520 | people building binary distributions sometimes want to retain the name till |
521 | runtime. This is supported if the name begins "ref:". */ | |
522 | ||
523 | else if (strncmp(user, "ref:", 4) == 0) | |
524 | { | |
525 | user += 4; | |
526 | while (isspace(*user)) user++; | |
527 | username = user; | |
528 | } | |
529 | ||
35edf2ff PH |
530 | else if (isgroup) |
531 | { | |
532 | struct group *gr = getgrnam(user); | |
533 | if (gr == NULL) | |
534 | { | |
535 | printf("\n*** Group \"%s\" (specified in one of the Makefiles) does not " | |
536 | "exist.\n Please review your build-time configuration.\n\n", | |
537 | user); | |
538 | return 1; | |
539 | } | |
540 | gid = gr->gr_gid; | |
541 | } | |
542 | ||
059ec3d9 PH |
543 | else |
544 | { | |
545 | struct passwd *pw = getpwnam(user); | |
546 | if (pw == NULL) | |
547 | { | |
548 | printf("\n*** User \"%s\" (specified in one of the Makefiles) does not " | |
549 | "exist.\n Please review your build-time configuration.\n\n", | |
550 | user); | |
551 | return 1; | |
552 | } | |
059ec3d9 PH |
553 | uid = pw->pw_uid; |
554 | } | |
555 | ||
556 | /* Output user and group names or uid/gid. When names are set, uid/gid | |
557 | are set to zero but will be replaced at runtime. */ | |
558 | ||
559 | if (username != NULL) | |
35edf2ff PH |
560 | { |
561 | if (isgroup) | |
562 | fprintf(new, "#define CONFIGURE_GROUPNAME \"%s\"\n", username); | |
563 | else | |
564 | fprintf(new, "#define CONFIGURE_OWNERNAME \"%s\"\n", username); | |
565 | } | |
566 | ||
567 | if (isgroup) | |
568 | fprintf(new, "#define CONFIGURE_GROUP %d\n", (int)gid); | |
569 | else | |
570 | fprintf(new, "#define CONFIGURE_OWNER %d\n", (int)uid); | |
059ec3d9 PH |
571 | continue; |
572 | } | |
573 | ||
574 | /* FIXED_NEVER_USERS is another special case. Look up the uid values and | |
575 | create suitable initialization data for a vector. */ | |
576 | ||
577 | if (strcmp(name, "FIXED_NEVER_USERS") == 0) | |
578 | { | |
579 | char *list = getenv("FIXED_NEVER_USERS"); | |
580 | if (list == NULL) | |
581 | { | |
582 | fprintf(new, "#define FIXED_NEVER_USERS 0\n"); | |
583 | } | |
584 | else | |
585 | { | |
586 | int count = 1; | |
926e1192 | 587 | int i, j; |
059ec3d9 PH |
588 | uid_t *vector; |
589 | char *p = list; | |
590 | while (*p != 0) if (*p++ == ':') count++; | |
591 | ||
592 | vector = malloc((count+1) * sizeof(uid_t)); | |
593 | vector[0] = (uid_t)count; | |
594 | ||
926e1192 | 595 | for (i = 1, j = 0; i <= count; list++, i++) |
059ec3d9 PH |
596 | { |
597 | char name[64]; | |
926e1192 | 598 | |
059ec3d9 PH |
599 | p = list; |
600 | while (*list != 0 && *list != ':') list++; | |
601 | strncpy(name, p, list-p); | |
602 | name[list-p] = 0; | |
926e1192 PH |
603 | |
604 | if (name[0] == 0) | |
605 | { | |
606 | continue; | |
607 | } | |
608 | else if (name[strspn(name, "0123456789")] == 0) | |
059ec3d9 | 609 | { |
926e1192 | 610 | vector[j++] = (uid_t)atoi(name); |
059ec3d9 PH |
611 | } |
612 | else | |
613 | { | |
614 | struct passwd *pw = getpwnam(name); | |
615 | if (pw == NULL) | |
616 | { | |
617 | printf("\n*** User \"%s\" (specified for FIXED_NEVER_USERS in one of the Makefiles) does not " | |
618 | "exist.\n Please review your build-time configuration.\n\n", | |
619 | name); | |
620 | return 1; | |
621 | } | |
926e1192 | 622 | vector[j++] = pw->pw_uid; |
059ec3d9 PH |
623 | } |
624 | } | |
926e1192 PH |
625 | fprintf(new, "#define FIXED_NEVER_USERS %d", j); |
626 | for (i = 0; i < j; i++) fprintf(new, ", %d", (unsigned int)vector[i]); | |
627 | fprintf(new, "\n"); | |
059ec3d9 PH |
628 | } |
629 | continue; | |
630 | } | |
631 | ||
c6e692d7 PH |
632 | /* WITH_CONTENT_SCAN is another special case: it must be set if either it or |
633 | WITH_OLD_DEMIME is set. */ | |
634 | ||
635 | if (strcmp(name, "WITH_CONTENT_SCAN") == 0) | |
636 | { | |
637 | char *wcs = getenv("WITH_CONTENT_SCAN"); | |
638 | char *wod = getenv("WITH_OLD_DEMIME"); | |
639 | if (wcs != NULL || wod != NULL) | |
640 | fprintf(new, "#define WITH_CONTENT_SCAN yes\n"); | |
641 | else fprintf(new, "/* WITH_CONTENT_SCAN not set */\n"); | |
642 | continue; | |
643 | } | |
644 | ||
059ec3d9 PH |
645 | /* Otherwise, check whether a value exists in the environment. Remember if |
646 | it is an AUTH setting or SUPPORT_CRYPTEQ. */ | |
647 | ||
648 | if ((value = getenv(name)) != NULL) | |
649 | { | |
650 | int len; | |
651 | len = 21 - (int)strlen(name); | |
652 | ||
653 | if (strncmp(name, "AUTH_", 5) == 0) have_auth = 1; | |
654 | if (strncmp(name, "SUPPORT_CRYPTEQ", 15) == 0) support_crypteq = 1; | |
655 | ||
656 | /* The text value of LDAP_LIB_TYPE refers to a macro that gets set. */ | |
657 | ||
658 | if (strcmp(name, "LDAP_LIB_TYPE") == 0) | |
659 | { | |
660 | if (strcmp(value, "NETSCAPE") == 0 || | |
661 | strcmp(value, "UMICHIGAN") == 0 || | |
662 | strcmp(value, "OPENLDAP1") == 0 || | |
663 | strcmp(value, "OPENLDAP2") == 0 || | |
664 | strcmp(value, "SOLARIS") == 0 || | |
665 | strcmp(value, "SOLARIS7") == 0) /* Compatibility */ | |
666 | { | |
667 | fprintf(new, "#define LDAP_LIB_%s\n", value); | |
668 | } | |
669 | else | |
670 | { | |
671 | printf("\n*** LDAP_LIB_TYPE=%s is not a recognized LDAP library type." | |
672 | "\n*** Please review your build-time configuration.\n\n", value); | |
673 | return 1; | |
674 | } | |
675 | } | |
676 | ||
677 | else if (strcmp(name, "RADIUS_LIB_TYPE") == 0) | |
678 | { | |
679 | if (strcmp(value, "RADIUSCLIENT") == 0 || | |
680 | strcmp(value, "RADLIB") == 0) | |
681 | { | |
682 | fprintf(new, "#define RADIUS_LIB_%s\n", value); | |
683 | } | |
684 | else | |
685 | { | |
686 | printf("\n*** RADIUS_LIB_TYPE=%s is not a recognized RADIUS library type." | |
687 | "\n*** Please review your build-time configuration.\n\n", value); | |
688 | return 1; | |
689 | } | |
690 | } | |
691 | ||
692 | /* Other macros get set to the environment value. */ | |
693 | ||
694 | else | |
695 | { | |
696 | fprintf(new, "#define %s ", name); | |
697 | while(len-- > 0) fputc(' ', new); | |
698 | ||
699 | /* LOG_FILE_PATH is now messy because it can be a path containing %s or | |
700 | it can be "syslog" or ":syslog" or "syslog:path" or even "path:syslog". */ | |
701 | ||
702 | if (strcmp(name, "LOG_FILE_PATH") == 0) | |
703 | { | |
704 | char *ss = value; | |
705 | for(;;) | |
706 | { | |
707 | char *pp; | |
708 | char *sss = strchr(ss, ':'); | |
709 | if (sss != NULL) | |
710 | { | |
711 | strncpy(buffer, ss, sss-ss); | |
712 | buffer[sss-ss] = 0; /* For empty case */ | |
713 | } | |
714 | else strcpy(buffer, ss); | |
715 | pp = buffer + (int)strlen(buffer); | |
716 | while (pp > buffer && isspace((unsigned char)pp[-1])) pp--; | |
717 | *pp = 0; | |
718 | if (buffer[0] != 0 && strcmp(buffer, "syslog") != 0) | |
719 | check_percent_ess(buffer, name); | |
720 | if (sss == NULL) break; | |
721 | ss = sss + 1; | |
722 | while (isspace((unsigned char)*ss)) ss++; | |
723 | } | |
724 | fprintf(new, "\"%s\"\n", value); | |
725 | } | |
726 | ||
727 | /* Timezone values and HEADERS_CHARSET get quoted */ | |
728 | ||
729 | else if (strcmp(name, "TIMEZONE_DEFAULT") == 0|| | |
730 | strcmp(name, "HEADERS_CHARSET") == 0) | |
731 | fprintf(new, "\"%s\"\n", value); | |
732 | ||
733 | /* For others, quote any paths and don't quote anything else */ | |
734 | ||
735 | else | |
736 | { | |
737 | if (value[0] == '/') fprintf(new, "\"%s\"\n", value); | |
738 | else fprintf(new, "%s\n", value); | |
739 | } | |
740 | } | |
741 | } | |
742 | ||
743 | /* Value not defined in the environment; use the default */ | |
744 | ||
745 | else | |
746 | { | |
747 | char *t = p; | |
748 | while (*p == ' ' || *p == '\t') p++; | |
749 | if (*p != '\n') fputs(buffer, new); else | |
750 | { | |
751 | *t = 0; | |
752 | if (strcmp(name, "BIN_DIRECTORY") == 0 || | |
753 | strcmp(name, "CONFIGURE_FILE") == 0) | |
754 | { | |
755 | printf("\n*** %s has not been defined in any of the Makefiles in the\n" | |
756 | " \"Local\" directory. " | |
757 | "Please review your build-time configuration.\n\n", name); | |
758 | return 1; | |
759 | } | |
760 | ||
761 | if (strcmp(name, "TIMEZONE_DEFAULT") == 0) | |
762 | { | |
763 | char *tz = getenv("TZ"); | |
764 | fprintf(new, "#define TIMEZONE_DEFAULT "); | |
765 | if (tz == NULL) fprintf(new, "NULL\n"); else | |
766 | fprintf(new, "\"%s\"\n", tz); | |
767 | } | |
768 | ||
769 | else fprintf(new, "/* %s not set */\n", name); | |
770 | } | |
771 | } | |
772 | } | |
773 | ||
774 | fclose(base); | |
775 | ||
776 | /* If any AUTH macros were defined, ensure that SUPPORT_CRYPTEQ is also | |
777 | defined. */ | |
778 | ||
779 | if (have_auth) | |
780 | { | |
781 | if (!support_crypteq) fprintf(new, "/* Force SUPPORT_CRYPTEQ for AUTH */\n" | |
782 | "#define SUPPORT_CRYPTEQ\n"); | |
783 | } | |
784 | ||
785 | /* End off */ | |
786 | ||
787 | fprintf(new, "\n/* End of config.h */\n"); | |
788 | fclose(new); | |
789 | return 0; | |
790 | } | |
791 | ||
792 | /* End of buildconfig.c */ |