Run when EXIM_USER=notroot specified.
[exim.git] / src / src / buildconfig.c
1 /* $Cambridge: exim/src/src/buildconfig.c,v 1.19 2010/06/07 18:25:57 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 ((username != NULL) && (
536 (strcmp(username, "root") == 0) ||
537 (strcmp(username, "toor") == 0) )))
538 {
539 printf("\n*** Exim's internal user must not be root.\n\n");
540 return 1;
541 }
542
543 /* Output user and group names or uid/gid. When names are set, uid/gid
544 are set to zero but will be replaced at runtime. */
545
546 if (username != NULL)
547 fprintf(new, "#define EXIM_USERNAME \"%s\"\n", username);
548 if (groupname != NULL)
549 fprintf(new, "#define EXIM_GROUPNAME \"%s\"\n", groupname);
550
551 fprintf(new, "#define EXIM_UID %d\n", (int)uid);
552 fprintf(new, "#define EXIM_GID %d\n", (int)gid);
553 continue;
554 }
555
556 /* CONFIGURE_OWNER and CONFIGURE_GROUP are special cases. We look in the
557 environment for first. If the value is not numeric, we look up the user or
558 group. A lot of this code is similar to that for EXIM_USER, but it's easier
559 to keep it separate. */
560
561 if (strcmp(name, "CONFIGURE_OWNER") == 0 ||
562 strcmp(name, "CONFIGURE_GROUP") == 0)
563 {
564 int isgroup = name[10] == 'G';
565 uid_t uid = 0;
566 gid_t gid = 0;
567 char *s;
568 char *username = NULL;
569 char *user = getenv(name);
570
571 if (user == NULL) user = "";
572 while (isspace((unsigned char)(*user))) user++;
573 if (*user == 0)
574 {
575 fprintf(new, "/* %s not set */\n", name);
576 continue;
577 }
578
579 for (s = user; *s != 0; s++)
580 {
581 if (iscntrl((unsigned char)(*s)))
582 {
583 printf("\n*** %s contains the control character 0x%02X in "
584 "one of the files\n in the \"Local\" directory. Please review "
585 "your build-time\n configuration.\n\n", name, *s);
586 return 1;
587 }
588 }
589
590 /* Numeric uid given */
591
592 if (user[strspn(user, "0123456789")] == 0)
593 {
594 if (isgroup)
595 gid = (gid_t)atoi(user);
596 else
597 uid = (uid_t)atoi(user);
598 }
599
600 /* Name given. Normally, we look up the uid or gid right away. However,
601 people building binary distributions sometimes want to retain the name till
602 runtime. This is supported if the name begins "ref:". */
603
604 else if (strncmp(user, "ref:", 4) == 0)
605 {
606 user += 4;
607 while (isspace(*user)) user++;
608 username = user;
609 }
610
611 else if (isgroup)
612 {
613 struct group *gr = getgrnam(user);
614 if (gr == NULL)
615 {
616 printf("\n*** Group \"%s\" (specified in one of the Makefiles) does not "
617 "exist.\n Please review your build-time configuration.\n\n",
618 user);
619 return 1;
620 }
621 gid = gr->gr_gid;
622 }
623
624 else
625 {
626 struct passwd *pw = getpwnam(user);
627 if (pw == NULL)
628 {
629 printf("\n*** User \"%s\" (specified in one of the Makefiles) does not "
630 "exist.\n Please review your build-time configuration.\n\n",
631 user);
632 return 1;
633 }
634 uid = pw->pw_uid;
635 }
636
637 /* Output user and group names or uid/gid. When names are set, uid/gid
638 are set to zero but will be replaced at runtime. */
639
640 if (username != NULL)
641 {
642 if (isgroup)
643 fprintf(new, "#define CONFIGURE_GROUPNAME \"%s\"\n", username);
644 else
645 fprintf(new, "#define CONFIGURE_OWNERNAME \"%s\"\n", username);
646 }
647
648 if (isgroup)
649 fprintf(new, "#define CONFIGURE_GROUP %d\n", (int)gid);
650 else
651 fprintf(new, "#define CONFIGURE_OWNER %d\n", (int)uid);
652 continue;
653 }
654
655 /* FIXED_NEVER_USERS is another special case. Look up the uid values and
656 create suitable initialization data for a vector. */
657
658 if (strcmp(name, "FIXED_NEVER_USERS") == 0)
659 {
660 char *list = getenv("FIXED_NEVER_USERS");
661 if (list == NULL)
662 {
663 fprintf(new, "#define FIXED_NEVER_USERS 0\n");
664 }
665 else
666 {
667 int count = 1;
668 int i, j;
669 uid_t *vector;
670 char *p = list;
671 while (*p != 0) if (*p++ == ':') count++;
672
673 vector = malloc((count+1) * sizeof(uid_t));
674 vector[0] = (uid_t)count;
675
676 for (i = 1, j = 0; i <= count; list++, i++)
677 {
678 char name[64];
679
680 p = list;
681 while (*list != 0 && *list != ':') list++;
682 strncpy(name, p, list-p);
683 name[list-p] = 0;
684
685 if (name[0] == 0)
686 {
687 continue;
688 }
689 else if (name[strspn(name, "0123456789")] == 0)
690 {
691 vector[j++] = (uid_t)atoi(name);
692 }
693 else
694 {
695 struct passwd *pw = getpwnam(name);
696 if (pw == NULL)
697 {
698 printf("\n*** User \"%s\" (specified for FIXED_NEVER_USERS in one of the Makefiles) does not "
699 "exist.\n Please review your build-time configuration.\n\n",
700 name);
701 return 1;
702 }
703 vector[j++] = pw->pw_uid;
704 }
705 }
706 fprintf(new, "#define FIXED_NEVER_USERS %d", j);
707 for (i = 0; i < j; i++) fprintf(new, ", %d", (unsigned int)vector[i]);
708 fprintf(new, "\n");
709 }
710 continue;
711 }
712
713 /* WITH_CONTENT_SCAN is another special case: it must be set if either it or
714 WITH_OLD_DEMIME is set. */
715
716 if (strcmp(name, "WITH_CONTENT_SCAN") == 0)
717 {
718 char *wcs = getenv("WITH_CONTENT_SCAN");
719 char *wod = getenv("WITH_OLD_DEMIME");
720 char *dcc = getenv("EXPERIMENTAL_DCC");
721 if (wcs != NULL || wod != NULL || dcc != NULL)
722 fprintf(new, "#define WITH_CONTENT_SCAN yes\n");
723 else fprintf(new, "/* WITH_CONTENT_SCAN not set */\n");
724 continue;
725 }
726
727 /* Otherwise, check whether a value exists in the environment. Remember if
728 it is an AUTH setting or SUPPORT_CRYPTEQ. */
729
730 if ((value = getenv(name)) != NULL)
731 {
732 int len;
733 len = 21 - (int)strlen(name);
734
735 if (strncmp(name, "AUTH_", 5) == 0) have_auth = 1;
736 if (strncmp(name, "SUPPORT_CRYPTEQ", 15) == 0) support_crypteq = 1;
737
738 /* The text value of LDAP_LIB_TYPE refers to a macro that gets set. */
739
740 if (strcmp(name, "LDAP_LIB_TYPE") == 0)
741 {
742 if (strcmp(value, "NETSCAPE") == 0 ||
743 strcmp(value, "UMICHIGAN") == 0 ||
744 strcmp(value, "OPENLDAP1") == 0 ||
745 strcmp(value, "OPENLDAP2") == 0 ||
746 strcmp(value, "SOLARIS") == 0 ||
747 strcmp(value, "SOLARIS7") == 0) /* Compatibility */
748 {
749 fprintf(new, "#define LDAP_LIB_%s\n", value);
750 }
751 else
752 {
753 printf("\n*** LDAP_LIB_TYPE=%s is not a recognized LDAP library type."
754 "\n*** Please review your build-time configuration.\n\n", value);
755 return 1;
756 }
757 }
758
759 else if (strcmp(name, "RADIUS_LIB_TYPE") == 0)
760 {
761 if (strcmp(value, "RADIUSCLIENT") == 0 ||
762 strcmp(value, "RADIUSCLIENTNEW") == 0 ||
763 strcmp(value, "RADLIB") == 0)
764 {
765 fprintf(new, "#define RADIUS_LIB_%s\n", value);
766 }
767 else
768 {
769 printf("\n*** RADIUS_LIB_TYPE=%s is not a recognized RADIUS library type."
770 "\n*** Please review your build-time configuration.\n\n", value);
771 return 1;
772 }
773 }
774
775 /* Other macros get set to the environment value. */
776
777 else
778 {
779 fprintf(new, "#define %s ", name);
780 while(len-- > 0) fputc(' ', new);
781
782 /* LOG_FILE_PATH is now messy because it can be a path containing %s or
783 it can be "syslog" or ":syslog" or "syslog:path" or even "path:syslog". */
784
785 if (strcmp(name, "LOG_FILE_PATH") == 0)
786 {
787 char *ss = value;
788 for(;;)
789 {
790 char *pp;
791 char *sss = strchr(ss, ':');
792 if (sss != NULL)
793 {
794 strncpy(buffer, ss, sss-ss);
795 buffer[sss-ss] = 0; /* For empty case */
796 }
797 else strcpy(buffer, ss);
798 pp = buffer + (int)strlen(buffer);
799 while (pp > buffer && isspace((unsigned char)pp[-1])) pp--;
800 *pp = 0;
801 if (buffer[0] != 0 && strcmp(buffer, "syslog") != 0)
802 check_percent_ess(buffer, name);
803 if (sss == NULL) break;
804 ss = sss + 1;
805 while (isspace((unsigned char)*ss)) ss++;
806 }
807 fprintf(new, "\"%s\"\n", value);
808 }
809
810 /* Timezone values and HEADERS_CHARSET get quoted */
811
812 else if (strcmp(name, "TIMEZONE_DEFAULT") == 0||
813 strcmp(name, "HEADERS_CHARSET") == 0)
814 fprintf(new, "\"%s\"\n", value);
815
816 /* For others, quote any paths and don't quote anything else */
817
818 else
819 {
820 if (value[0] == '/') fprintf(new, "\"%s\"\n", value);
821 else fprintf(new, "%s\n", value);
822 }
823 }
824 }
825
826 /* Value not defined in the environment; use the default */
827
828 else
829 {
830 char *t = p;
831 while (*p == ' ' || *p == '\t') p++;
832 if (*p != '\n') fputs(buffer, new); else
833 {
834 *t = 0;
835 if (strcmp(name, "BIN_DIRECTORY") == 0 ||
836 strcmp(name, "CONFIGURE_FILE") == 0)
837 {
838 printf("\n*** %s has not been defined in any of the Makefiles in the\n"
839 " \"Local\" directory. "
840 "Please review your build-time configuration.\n\n", name);
841 return 1;
842 }
843
844 if (strcmp(name, "TIMEZONE_DEFAULT") == 0)
845 {
846 char *tz = getenv("TZ");
847 fprintf(new, "#define TIMEZONE_DEFAULT ");
848 if (tz == NULL) fprintf(new, "NULL\n"); else
849 fprintf(new, "\"%s\"\n", tz);
850 }
851
852 else fprintf(new, "/* %s not set */\n", name);
853 }
854 }
855 }
856
857 (void)fclose(base);
858
859 /* If any AUTH macros were defined, ensure that SUPPORT_CRYPTEQ is also
860 defined. */
861
862 if (have_auth)
863 {
864 if (!support_crypteq) fprintf(new, "/* Force SUPPORT_CRYPTEQ for AUTH */\n"
865 "#define SUPPORT_CRYPTEQ\n");
866 }
867
868 /* End off */
869
870 fprintf(new, "\n/* End of config.h */\n");
871 (void)fclose(new);
872 return 0;
873 }
874
875 /* End of buildconfig.c */