cvs-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Cvs-cvs] Changes to ccvs/src/parseinfo.c


From: Derek Robert Price
Subject: [Cvs-cvs] Changes to ccvs/src/parseinfo.c
Date: Wed, 31 Aug 2005 12:51:10 -0400

Index: ccvs/src/parseinfo.c
diff -u ccvs/src/parseinfo.c:1.79 ccvs/src/parseinfo.c:1.80
--- ccvs/src/parseinfo.c:1.79   Wed Jun  8 14:02:33 2005
+++ ccvs/src/parseinfo.c        Wed Aug 31 16:51:02 2005
@@ -15,8 +15,6 @@
 #include "getline.h"
 #include "history.h"
 
-
-
 /*
  * Parse the INFOFILE file for the specified REPOSITORY.  Invoke CALLPROC for
  * the first line in the file that matches the REPOSITORY, or if ALL != 0, any
@@ -144,8 +142,9 @@
            if (!(opt & PIOPT_ALL))
                error (0, 0, "Keyword `ALL' is ignored at line %d in %s file",
                       line_number, infofile);
-           else if ((expanded_value = expand_path (value, true, infofile,
-                                                   line_number)) != NULL)
+           else if ((expanded_value =
+                       expand_path (value, current_parsed_root->directory,
+                                    true, infofile, line_number)))
            {
                err += callproc (repository, expanded_value, closure);
                free (expanded_value);
@@ -171,7 +170,8 @@
            continue;                           /* no match */
 
        /* it did, so do the callback and note that we did one */
-       expanded_value = expand_path (value, true, infofile, line_number);
+       expanded_value = expand_path (value, current_parsed_root->directory,
+                                     true, infofile, line_number);
        if (expanded_value)
        {
            err += callproc (repository, expanded_value, closure);
@@ -189,8 +189,9 @@
     /* if we fell through and didn't callback at all, do the default */
     if (!callback_done && default_value)
     {
-       expanded_value = expand_path (default_value, true, infofile,
-                                     line_number);
+       expanded_value = expand_path (default_value,
+                                     current_parsed_root->directory,
+                                     true, infofile, line_number);
        if (expanded_value)
        {
            err += callproc (repository, expanded_value, closure);
@@ -344,6 +345,12 @@
 
 
 
+#ifdef ALLOW_CONFIG_OVERRIDE
+const char * const allowed_config_prefixes[] = { ALLOW_CONFIG_OVERRIDE };
+#endif /* ALLOW_CONFIG_OVERRIDE */
+
+
+
 /* Parse the CVS config file.  The syntax right now is a bit ad hoc
  * but tries to draw on the best or more common features of the other
  * *info files and various unix (or non-unix) config file syntaxes.
@@ -365,9 +372,10 @@
  *   xmalloc() failures are fatal, per usual.
  */
 struct config *
-parse_config (const char *cvsroot)
+parse_config (const char *cvsroot, const char *path)
 {
-    char *infopath;
+    const char *infopath;
+    char *freeinfopath = NULL;
     FILE *fp_info;
     char *line = NULL;
     unsigned int ln;           /* Input file line counter.  */
@@ -378,9 +386,37 @@
 
     TRACE (TRACE_FUNCTION, "parse_config (%s)", cvsroot);
 
-    retval = new_config ();
+#ifdef ALLOW_CONFIG_OVERRIDE
+    if (path)
+    {
+       const char * const *prefix;
+       char *npath = xcanonicalize_file_name (path);
+       bool approved = false;
+       for (prefix = allowed_config_prefixes; *prefix != NULL; prefix++)
+       {
+           if (!isreadable (*prefix)) continue;
+           char *nprefix = xcanonicalize_file_name (*prefix);
+           if (!strncmp (nprefix, npath, strlen (nprefix))
+               && (((*prefix)[strlen (*prefix)] != '/'
+                    && strlen (npath) == strlen (nprefix))
+                   || ((*prefix)[strlen (*prefix)] == '/'
+                       && npath[strlen (nprefix)] == '/')))
+               approved = true;
+           free (nprefix);
+           if (approved) break;
+       }
+       if (!approved)
+           error (1, 0, "Invalid path to config file specified: `%s'",
+                  path);
+       infopath = path;
+       free (npath);
+    }
+    else
+#endif
+       infopath = freeinfopath =
+           Xasprintf ("%s/%s/%s", cvsroot, CVSROOTADM, CVSROOTADM_CONFIG);
 
-    infopath = Xasprintf ("%s/%s/%s", cvsroot, CVSROOTADM, CVSROOTADM_CONFIG);
+    retval = new_config ();
 
     fp_info = CVS_FOPEN (infopath, "r");
     if (!fp_info)
@@ -392,7 +428,7 @@
               value, currently at least.  */
            error (0, errno, "cannot open %s", infopath);
        }
-       free (infopath);
+       if (freeinfopath) free (freeinfopath);
        return retval;
     }
 
@@ -489,7 +525,7 @@
        {
            if (retval->lock_dir)
                free (retval->lock_dir);
-           retval->lock_dir = xstrdup (p);
+           retval->lock_dir = expand_path (p, cvsroot, false, infopath, line);
            /* Could try some validity checking, like whether we can
               opendir it or something, but I don't see any particular
               reason to do that now rather than waiting until lock.c.  */
@@ -499,7 +535,8 @@
            if (retval->HistoryLogPath) free (retval->HistoryLogPath);
 
            /* Expand ~ & $VARs.  */
-           retval->HistoryLogPath = expand_path (p, false, infopath, ln);
+           retval->HistoryLogPath = expand_path (p, cvsroot, false,
+                                                 infopath, ln);
 
            if (retval->HistoryLogPath && !ISABSOLUTE (retval->HistoryLogPath))
            {
@@ -512,7 +549,8 @@
        else if (strcmp (line, "HistorySearchPath") == 0)
        {
            if (retval->HistorySearchPath) free (retval->HistorySearchPath);
-           retval->HistorySearchPath = expand_path (p, false, infopath, ln);
+           retval->HistorySearchPath = expand_path (p, cvsroot, false,
+                                                    infopath, ln);
 
            if (retval->HistorySearchPath
                && !ISABSOLUTE (retval->HistorySearchPath))
@@ -618,7 +656,8 @@
        error (0, errno, "cannot read %s", infopath);
     if (fclose (fp_info) < 0)
        error (0, errno, "cannot close %s", infopath);
-    free (infopath);
+    if (freeinfopath) free (freeinfopath);
     if (line) free (line);
+
     return retval;
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]