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