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