1
/* $Cambridge: exim/exim-src/src/buildconfig.c,v 1.10 2005/06/27 14:29:43 ph10 Exp $ */
1
3
/*************************************************
2
4
* Exim - an Internet mail transport agent *
3
5
*************************************************/
5
/* Copyright (c) University of Cambridge 1995 - 2004 */
7
/* Copyright (c) University of Cambridge 1995 - 2005 */
6
8
/* See the file NOTICE for conditions of use and distribution. */
13
15
/* This auxiliary program builds the file config.h by the following
16
First it reads Makefile, looking for certain OS-specific definitions which it
17
uses to define macros. Then it reads the defaults file config.h.defaults.
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.
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
19
26
The defaults file contains normal C #define statements for various macros; if
20
27
the name of a macro is found in the environment, the environment value replaces
130
139
fprintf(new, "Do not edit it. Instead, edit Local/Makefile and "
131
140
"rerun make. */\n\n");
133
/* First, search the makefile for certain settings */
142
/* First, deal with the printing format for off_t variables. We assume that if
143
the size of off_t is greater than 4, "%lld" will be available as a format for
144
printing long long variables, and there will be support for the long long type.
145
This assumption is known to be OK for the common operating systems. */
147
fprintf(new, "#ifndef OFF_T_FMT\n");
148
if (sizeof(test_off_t) > 4)
150
fprintf(new, "#define OFF_T_FMT \"%%lld\"\n");
151
fprintf(new, "#define LONGLONG_T long long int\n");
155
fprintf(new, "#define OFF_T_FMT \"%%ld\"\n");
156
fprintf(new, "#define LONGLONG_T long int\n");
158
fprintf(new, "#endif\n\n");
160
/* Now do the same thing for time_t variables. If the length is greater than
161
4, we want to assume long long support (even if off_t was less than 4). If the
162
length is 4 or less, we can leave LONGLONG_T to whatever was defined above for
165
fprintf(new, "#ifndef TIME_T_FMT\n");
166
if (sizeof(test_time_t) > 4)
168
fprintf(new, "#define TIME_T_FMT \"%%lld\"\n");
169
fprintf(new, "#undef LONGLONG_T\n");
170
fprintf(new, "#define LONGLONG_T long long int\n");
174
fprintf(new, "#define TIME_T_FMT \"%%ld\"\n");
176
fprintf(new, "#endif\n\n");
178
/* Now search the makefile for certain settings */
135
180
base = fopen("Makefile", "rb");
136
181
if (base == NULL)
138
183
printf("*** Buildconfig: failed to open Makefile\n");
518
/* CONFIGURE_OWNER and CONFIGURE_GROUP are special cases. We look in the
519
environment for first. If the value is not numeric, we look up the user or
520
group. A lot of this code is similar to that for EXIM_USER, but it's easier
521
to keep it separate. */
523
if (strcmp(name, "CONFIGURE_OWNER") == 0 ||
524
strcmp(name, "CONFIGURE_GROUP") == 0)
526
int isgroup = name[10] == 'G';
530
char *username = NULL;
531
char *user = getenv(name);
533
if (user == NULL) user = "";
534
while (isspace((unsigned char)(*user))) user++;
537
fprintf(new, "/* %s not set */\n", name);
541
for (s = user; *s != 0; s++)
543
if (iscntrl((unsigned char)(*s)))
545
printf("\n*** %s contains the control character 0x%02X in "
546
"one of the files\n in the \"Local\" directory. Please review "
547
"your build-time\n configuration.\n\n", name, *s);
552
/* Numeric uid given */
554
if (user[strspn(user, "0123456789")] == 0)
557
gid = (gid_t)atoi(user);
559
uid = (uid_t)atoi(user);
562
/* Name given. Normally, we look up the uid or gid right away. However,
563
people building binary distributions sometimes want to retain the name till
564
runtime. This is supported if the name begins "ref:". */
566
else if (strncmp(user, "ref:", 4) == 0)
569
while (isspace(*user)) user++;
575
struct group *gr = getgrnam(user);
578
printf("\n*** Group \"%s\" (specified in one of the Makefiles) does not "
579
"exist.\n Please review your build-time configuration.\n\n",
588
struct passwd *pw = getpwnam(user);
591
printf("\n*** User \"%s\" (specified in one of the Makefiles) does not "
592
"exist.\n Please review your build-time configuration.\n\n",
599
/* Output user and group names or uid/gid. When names are set, uid/gid
600
are set to zero but will be replaced at runtime. */
602
if (username != NULL)
605
fprintf(new, "#define CONFIGURE_GROUPNAME \"%s\"\n", username);
607
fprintf(new, "#define CONFIGURE_OWNERNAME \"%s\"\n", username);
611
fprintf(new, "#define CONFIGURE_GROUP %d\n", (int)gid);
613
fprintf(new, "#define CONFIGURE_OWNER %d\n", (int)uid);
473
617
/* FIXED_NEVER_USERS is another special case. Look up the uid values and
474
618
create suitable initialization data for a vector. */
491
635
vector = malloc((count+1) * sizeof(uid_t));
492
636
vector[0] = (uid_t)count;
494
for (i = 1; i <= count; list++, i++)
638
for (i = 1, j = 0; i <= count; list++, i++)
498
643
while (*list != 0 && *list != ':') list++;
499
644
strncpy(name, p, list-p);
500
645
name[list-p] = 0;
502
if (name[strspn(name, "0123456789")] == 0)
504
vector[i] = (uid_t)atoi(name);
651
else if (name[strspn(name, "0123456789")] == 0)
653
vector[j++] = (uid_t)atoi(name);
516
vector[i] = pw->pw_uid;
665
vector[j++] = pw->pw_uid;
519
fprintf(new, "#define FIXED_NEVER_USERS %d, ", count);
520
for (i = 1; i <= count - 1; i++)
521
fprintf(new, "%d, ", (unsigned int)vector[i]);
522
fprintf(new, "%d\n", (unsigned int)vector[i]);
668
fprintf(new, "#define FIXED_NEVER_USERS %d", j);
669
for (i = 0; i < j; i++) fprintf(new, ", %d", (unsigned int)vector[i]);
675
/* WITH_CONTENT_SCAN is another special case: it must be set if either it or
676
WITH_OLD_DEMIME is set. */
678
if (strcmp(name, "WITH_CONTENT_SCAN") == 0)
680
char *wcs = getenv("WITH_CONTENT_SCAN");
681
char *wod = getenv("WITH_OLD_DEMIME");
682
if (wcs != NULL || wod != NULL)
683
fprintf(new, "#define WITH_CONTENT_SCAN yes\n");
684
else fprintf(new, "/* WITH_CONTENT_SCAN not set */\n");
527
688
/* Otherwise, check whether a value exists in the environment. Remember if
528
689
it is an AUTH setting or SUPPORT_CRYPTEQ. */
720
else if (strcmp(name, "RADIUS_LIB_TYPE") == 0)
722
if (strcmp(value, "RADIUSCLIENT") == 0 ||
723
strcmp(value, "RADIUSCLIENTNEW") == 0 ||
724
strcmp(value, "RADLIB") == 0)
726
fprintf(new, "#define RADIUS_LIB_%s\n", value);
730
printf("\n*** RADIUS_LIB_TYPE=%s is not a recognized RADIUS library type."
731
"\n*** Please review your build-time configuration.\n\n", value);
559
736
/* Other macros get set to the environment value. */