Reset separator char after string_nextinlist() calls
[exim.git] / src / src / buildconfig.c
index 6dd0d51120ebcb49038a897cee2b01e060a80d3c..6cc5e9abf685048dd9e842b40db1cd0a25d676ab 100644 (file)
@@ -1,10 +1,10 @@
-/* $Cambridge: exim/src/src/buildconfig.c,v 1.1 2004/10/07 10:39:01 ph10 Exp $ */
+/* $Cambridge: exim/src/src/buildconfig.c,v 1.5 2005/01/04 10:00:42 ph10 Exp $ */
 
 /*************************************************
 *     Exim - an Internet mail transport agent    *
 *************************************************/
 
-/* Copyright (c) University of Cambridge 1995 - 2004 */
+/* Copyright (c) University of Cambridge 1995 - 2005 */
 /* See the file NOTICE for conditions of use and distribution. */
 
 
@@ -472,17 +472,20 @@ while (fgets(buffer, sizeof(buffer), base) != NULL)
     continue;
     }
 
-  /* CONFIGURE_OWNER is a special case. We look in the environment for
-  CONFIGURE_OWNER. If the value is not numeric, we look up the user. A lot of
-  this code is similar to that for EXIM_USER, but we aren't interested in a gid
-  here, and it's all optional, so just keep it separate. */
+  /* CONFIGURE_OWNER and CONFIGURE_GROUP are special cases. We look in the
+  environment for first. If the value is not numeric, we look up the user or
+  group. A lot of this code is similar to that for EXIM_USER, but it's easier
+  to keep it separate. */
 
-  if (strcmp(name, "CONFIGURE_OWNER") == 0)
+  if (strcmp(name, "CONFIGURE_OWNER") == 0 ||
+      strcmp(name, "CONFIGURE_GROUP") == 0)
     {
+    int isgroup = name[10] == 'G'; 
     uid_t uid = 0;
+    gid_t gid = 0; 
     char *s;
     char *username = NULL;
-    char *user = getenv("CONFIGURE_OWNER");
+    char *user = getenv(name);
 
     if (user == NULL) user = "";
     while (isspace((unsigned char)(*user))) user++;
@@ -496,9 +499,9 @@ while (fgets(buffer, sizeof(buffer), base) != NULL)
       {
       if (iscntrl((unsigned char)(*s)))
         {
-        printf("\n*** CONFIGURE_OWNER contains the control character 0x%02X in "
+        printf("\n*** %s contains the control character 0x%02X in "
           "one of the files\n    in the \"Local\" directory. Please review "
-          "your build-time\n    configuration.\n\n", *s);
+          "your build-time\n    configuration.\n\n", name, *s);
         return 1;
         }
       }
@@ -507,10 +510,13 @@ while (fgets(buffer, sizeof(buffer), base) != NULL)
 
     if (user[strspn(user, "0123456789")] == 0)
       {
-      uid = (uid_t)atoi(user);
+      if (isgroup)
+        gid = (gid_t)atoi(user);
+      else    
+        uid = (uid_t)atoi(user);
       }
 
-    /* User name given. Normally, we look up the uid right away. However,
+    /* Name given. Normally, we look up the uid or gid right away. However,
     people building binary distributions sometimes want to retain the name till
     runtime. This is supported if the name begins "ref:". */
 
@@ -521,6 +527,19 @@ while (fgets(buffer, sizeof(buffer), base) != NULL)
       username = user;
       }
 
+    else if (isgroup)
+      {
+      struct group *gr = getgrnam(user);
+      if (gr == NULL)
+        {
+        printf("\n*** Group \"%s\" (specified in one of the Makefiles) does not "
+          "exist.\n    Please review your build-time configuration.\n\n",
+          user);
+        return 1;
+        }
+      gid = gr->gr_gid;
+      }
+
     else
       {
       struct passwd *pw = getpwnam(user);
@@ -531,7 +550,6 @@ while (fgets(buffer, sizeof(buffer), base) != NULL)
           user);
         return 1;
         }
-
       uid = pw->pw_uid;
       }
 
@@ -539,8 +557,17 @@ while (fgets(buffer, sizeof(buffer), base) != NULL)
     are set to zero but will be replaced at runtime. */
 
     if (username != NULL)
-      fprintf(new, "#define CONFIGURE_OWNERNAME         \"%s\"\n", username);
-    fprintf(new, "#define CONFIGURE_OWNER              %d\n", (int)uid);
+      {
+      if (isgroup)
+        fprintf(new, "#define CONFIGURE_GROUPNAME         \"%s\"\n", username);
+      else 
+        fprintf(new, "#define CONFIGURE_OWNERNAME         \"%s\"\n", username);
+      }
+    
+    if (isgroup)
+      fprintf(new, "#define CONFIGURE_GROUP              %d\n", (int)gid);
+    else   
+      fprintf(new, "#define CONFIGURE_OWNER              %d\n", (int)uid);
     continue;
     }
 
@@ -557,7 +584,7 @@ while (fgets(buffer, sizeof(buffer), base) != NULL)
     else
       {
       int count = 1;
-      int i;
+      int i, j;
       uid_t *vector;
       char *p = list;
       while (*p != 0) if (*p++ == ':') count++;
@@ -565,17 +592,22 @@ while (fgets(buffer, sizeof(buffer), base) != NULL)
       vector = malloc((count+1) * sizeof(uid_t));
       vector[0] = (uid_t)count;
 
-      for (i = 1; i <= count; list++, i++)
+      for (i = 1, j = 0; i <= count; list++, i++)
         {
         char name[64];
+         
         p = list;
         while (*list != 0 && *list != ':') list++;
         strncpy(name, p, list-p);
         name[list-p] = 0;
-
-        if (name[strspn(name, "0123456789")] == 0)
+        
+        if (name[0] == 0)
+          {
+          continue; 
+          }  
+        else if (name[strspn(name, "0123456789")] == 0)
           {
-          vector[i] = (uid_t)atoi(name);
+          vector[j++] = (uid_t)atoi(name);
           }
         else
           {
@@ -587,17 +619,29 @@ while (fgets(buffer, sizeof(buffer), base) != NULL)
               name);
             return 1;
             }
-          vector[i] = pw->pw_uid;
+          vector[j++] = pw->pw_uid;
           }
         }
-      fprintf(new, "#define FIXED_NEVER_USERS     %d, ", count);
-      for (i = 1; i <= count - 1; i++)
-        fprintf(new, "%d, ", (unsigned int)vector[i]);
-      fprintf(new, "%d\n", (unsigned int)vector[i]);
+      fprintf(new, "#define FIXED_NEVER_USERS     %d", j);
+      for (i = 0; i < j; i++) fprintf(new, ", %d", (unsigned int)vector[i]);
+      fprintf(new, "\n");
       }
     continue;
     }
 
+  /* WITH_CONTENT_SCAN is another special case: it must be set if either it or 
+  WITH_OLD_DEMIME is set. */  
+
+  if (strcmp(name, "WITH_CONTENT_SCAN") == 0)
+    {
+    char *wcs = getenv("WITH_CONTENT_SCAN");
+    char *wod = getenv("WITH_OLD_DEMIME");
+    if (wcs != NULL || wod != NULL)
+      fprintf(new, "#define WITH_CONTENT_SCAN     yes\n");
+    else fprintf(new, "/* WITH_CONTENT_SCAN not set */\n");
+    continue;
+    } 
+
   /* Otherwise, check whether a value exists in the environment. Remember if
   it is an AUTH setting or SUPPORT_CRYPTEQ. */