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