~ubuntu-branches/ubuntu/hardy/exim4/hardy-proposed

« back to all changes in this revision

Viewing changes to src/buildconfig.c

  • Committer: Bazaar Package Importer
  • Author(s): Marc Haber
  • Date: 2005-07-02 06:08:34 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050702060834-qk17pd52kb9nt3bj
Tags: 4.52-1
* new upstream version 4.51. (mh)
  * adapt 70_remove_exim-users_references
  * remove 37_gnutlsparams
  * adapt 36_pcre
  * adapt 31_eximmanpage
* fix package priorities to have them in sync with override again. (mh)
* Fix error in nb (Norwegian) translation.
  Thanks to Helge Hafting. (mh). Closes: #315775
* Standards-Version: 3.6.2, no changes needed. (mh)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Cambridge: exim/exim-src/src/buildconfig.c,v 1.10 2005/06/27 14:29:43 ph10 Exp $ */
 
2
 
1
3
/*************************************************
2
4
*     Exim - an Internet mail transport agent    *
3
5
*************************************************/
4
6
 
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. */
7
9
 
8
10
 
13
15
/* This auxiliary program builds the file config.h by the following
14
16
process:
15
17
 
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.
 
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.
18
25
 
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
94
101
int
95
102
main(int argc, char **argv)
96
103
{
 
104
off_t test_off_t = 0;
 
105
time_t test_time_t = 0;
97
106
FILE *base;
98
107
FILE *new;
99
108
int last_initial = 'A';
130
139
fprintf(new, "Do not edit it. Instead, edit Local/Makefile and "
131
140
  "rerun make. */\n\n");
132
141
 
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. */
 
146
 
 
147
fprintf(new, "#ifndef OFF_T_FMT\n");
 
148
if (sizeof(test_off_t) > 4)
 
149
  {
 
150
  fprintf(new, "#define OFF_T_FMT  \"%%lld\"\n");
 
151
  fprintf(new, "#define LONGLONG_T long long int\n");
 
152
  }
 
153
else
 
154
  {
 
155
  fprintf(new, "#define OFF_T_FMT  \"%%ld\"\n");
 
156
  fprintf(new, "#define LONGLONG_T long int\n");
 
157
  }
 
158
fprintf(new, "#endif\n\n");
 
159
 
 
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
 
163
off_t. */
 
164
 
 
165
fprintf(new, "#ifndef TIME_T_FMT\n");
 
166
if (sizeof(test_time_t) > 4)
 
167
  {
 
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");
 
171
  }
 
172
else
 
173
  {
 
174
  fprintf(new, "#define TIME_T_FMT  \"%%ld\"\n");
 
175
  }
 
176
fprintf(new, "#endif\n\n");
 
177
 
 
178
/* Now search the makefile for certain settings */
134
179
 
135
180
base = fopen("Makefile", "rb");
136
181
if (base == NULL)
137
182
  {
138
183
  printf("*** Buildconfig: failed to open Makefile\n");
139
 
  fclose(new);
 
184
  (void)fclose(new);
140
185
  exit(1);
141
186
  }
142
187
 
248
293
  }
249
294
 
250
295
fprintf(new, "\n");
251
 
fclose(base);
 
296
(void)fclose(base);
252
297
 
253
298
 
254
299
/* Now handle the macros listed in the defaults */
257
302
if (base == NULL)
258
303
  {
259
304
  printf("*** Buildconfig: failed to open ../src/config.h.defaults\n");
260
 
  fclose(new);
 
305
  (void)fclose(new);
261
306
  exit(1);
262
307
  }
263
308
 
470
515
    continue;
471
516
    }
472
517
 
 
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. */
 
522
 
 
523
  if (strcmp(name, "CONFIGURE_OWNER") == 0 ||
 
524
      strcmp(name, "CONFIGURE_GROUP") == 0)
 
525
    {
 
526
    int isgroup = name[10] == 'G';
 
527
    uid_t uid = 0;
 
528
    gid_t gid = 0;
 
529
    char *s;
 
530
    char *username = NULL;
 
531
    char *user = getenv(name);
 
532
 
 
533
    if (user == NULL) user = "";
 
534
    while (isspace((unsigned char)(*user))) user++;
 
535
    if (*user == 0)
 
536
      {
 
537
      fprintf(new, "/* %s not set */\n", name);
 
538
      continue;
 
539
      }
 
540
 
 
541
    for (s = user; *s != 0; s++)
 
542
      {
 
543
      if (iscntrl((unsigned char)(*s)))
 
544
        {
 
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);
 
548
        return 1;
 
549
        }
 
550
      }
 
551
 
 
552
    /* Numeric uid given */
 
553
 
 
554
    if (user[strspn(user, "0123456789")] == 0)
 
555
      {
 
556
      if (isgroup)
 
557
        gid = (gid_t)atoi(user);
 
558
      else
 
559
        uid = (uid_t)atoi(user);
 
560
      }
 
561
 
 
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:". */
 
565
 
 
566
    else if (strncmp(user, "ref:", 4) == 0)
 
567
      {
 
568
      user += 4;
 
569
      while (isspace(*user)) user++;
 
570
      username = user;
 
571
      }
 
572
 
 
573
    else if (isgroup)
 
574
      {
 
575
      struct group *gr = getgrnam(user);
 
576
      if (gr == NULL)
 
577
        {
 
578
        printf("\n*** Group \"%s\" (specified in one of the Makefiles) does not "
 
579
          "exist.\n    Please review your build-time configuration.\n\n",
 
580
          user);
 
581
        return 1;
 
582
        }
 
583
      gid = gr->gr_gid;
 
584
      }
 
585
 
 
586
    else
 
587
      {
 
588
      struct passwd *pw = getpwnam(user);
 
589
      if (pw == NULL)
 
590
        {
 
591
        printf("\n*** User \"%s\" (specified in one of the Makefiles) does not "
 
592
          "exist.\n    Please review your build-time configuration.\n\n",
 
593
          user);
 
594
        return 1;
 
595
        }
 
596
      uid = pw->pw_uid;
 
597
      }
 
598
 
 
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. */
 
601
 
 
602
    if (username != NULL)
 
603
      {
 
604
      if (isgroup)
 
605
        fprintf(new, "#define CONFIGURE_GROUPNAME         \"%s\"\n", username);
 
606
      else
 
607
        fprintf(new, "#define CONFIGURE_OWNERNAME         \"%s\"\n", username);
 
608
      }
 
609
 
 
610
    if (isgroup)
 
611
      fprintf(new, "#define CONFIGURE_GROUP              %d\n", (int)gid);
 
612
    else
 
613
      fprintf(new, "#define CONFIGURE_OWNER              %d\n", (int)uid);
 
614
    continue;
 
615
    }
 
616
 
473
617
  /* FIXED_NEVER_USERS is another special case. Look up the uid values and
474
618
  create suitable initialization data for a vector. */
475
619
 
483
627
    else
484
628
      {
485
629
      int count = 1;
486
 
      int i;
 
630
      int i, j;
487
631
      uid_t *vector;
488
632
      char *p = list;
489
633
      while (*p != 0) if (*p++ == ':') count++;
491
635
      vector = malloc((count+1) * sizeof(uid_t));
492
636
      vector[0] = (uid_t)count;
493
637
 
494
 
      for (i = 1; i <= count; list++, i++)
 
638
      for (i = 1, j = 0; i <= count; list++, i++)
495
639
        {
496
640
        char name[64];
 
641
 
497
642
        p = list;
498
643
        while (*list != 0 && *list != ':') list++;
499
644
        strncpy(name, p, list-p);
500
645
        name[list-p] = 0;
501
646
 
502
 
        if (name[strspn(name, "0123456789")] == 0)
503
 
          {
504
 
          vector[i] = (uid_t)atoi(name);
 
647
        if (name[0] == 0)
 
648
          {
 
649
          continue;
 
650
          }
 
651
        else if (name[strspn(name, "0123456789")] == 0)
 
652
          {
 
653
          vector[j++] = (uid_t)atoi(name);
505
654
          }
506
655
        else
507
656
          {
513
662
              name);
514
663
            return 1;
515
664
            }
516
 
          vector[i] = pw->pw_uid;
 
665
          vector[j++] = pw->pw_uid;
517
666
          }
518
667
        }
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]);
 
670
      fprintf(new, "\n");
523
671
      }
524
672
    continue;
525
673
    }
526
674
 
 
675
  /* WITH_CONTENT_SCAN is another special case: it must be set if either it or
 
676
  WITH_OLD_DEMIME is set. */
 
677
 
 
678
  if (strcmp(name, "WITH_CONTENT_SCAN") == 0)
 
679
    {
 
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");
 
685
    continue;
 
686
    }
 
687
 
527
688
  /* Otherwise, check whether a value exists in the environment. Remember if
528
689
  it is an AUTH setting or SUPPORT_CRYPTEQ. */
529
690
 
556
717
        }
557
718
      }
558
719
 
 
720
    else if (strcmp(name, "RADIUS_LIB_TYPE") == 0)
 
721
      {
 
722
      if (strcmp(value, "RADIUSCLIENT") == 0 ||
 
723
          strcmp(value, "RADIUSCLIENTNEW") == 0 ||
 
724
          strcmp(value, "RADLIB") == 0)
 
725
        {
 
726
        fprintf(new, "#define RADIUS_LIB_%s\n", value);
 
727
        }
 
728
      else
 
729
        {
 
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);
 
732
        return 1;
 
733
        }
 
734
      }
 
735
 
559
736
    /* Other macros get set to the environment value. */
560
737
 
561
738
    else
638
815
    }
639
816
  }
640
817
 
641
 
fclose(base);
 
818
(void)fclose(base);
642
819
 
643
820
/* If any AUTH macros were defined, ensure that SUPPORT_CRYPTEQ is also
644
821
defined. */
652
829
/* End off */
653
830
 
654
831
fprintf(new, "\n/* End of config.h */\n");
655
 
fclose(new);
 
832
(void)fclose(new);
656
833
return 0;
657
834
}
658
835