summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2022-01-02 22:23:34 +0100
committerDaniel Stenberg <daniel@haxx.se>2022-01-07 10:10:49 +0100
commit764e4f066d5719e68fa0d6b0b0d9efa0625c5c15 (patch)
tree6c45cdf13860514699deed9f95f14dec2a164389
parent4432234acaad3ecaf852b4c8a69c8fccc94ec512 (diff)
downloadcurl-764e4f066d5719e68fa0d6b0b0d9efa0625c5c15.tar.gz
tool_findfile: check ~/.config/curlrc too
... after the initial checks for .curlrc and if XDG_CONFIG_HOME is not set, use $HOME and $CURL_HOME to check if ~/.config/curlrc is present. Add test 436 to verify Reported-by: Sandro Jaeckel Fixes #8208 Closes #8213
-rw-r--r--src/tool_findfile.c41
-rw-r--r--src/tool_findfile.h10
-rw-r--r--src/tool_parsecfg.c9
-rw-r--r--tests/data/Makefile.inc2
-rw-r--r--tests/data/test43658
5 files changed, 99 insertions, 21 deletions
diff --git a/src/tool_findfile.c b/src/tool_findfile.c
index cda8c8ed8..766586f69 100644
--- a/src/tool_findfile.c
+++ b/src/tool_findfile.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -42,18 +42,25 @@
struct finder {
const char *env;
const char *append;
+ bool withoutdot;
};
+/* The order of the variables below is important, as the index number is used
+ in the findfile() function */
static const struct finder list[] = {
- { "CURL_HOME", NULL },
- { "XDG_CONFIG_HOME", NULL },
- { "HOME", NULL },
+ { "CURL_HOME", NULL, FALSE },
+ { "XDG_CONFIG_HOME", NULL, FALSE }, /* index == 1, used in the code */
+ { "HOME", NULL, FALSE },
#ifdef WIN32
- { "USERPROFILE", NULL },
- { "APPDATA", NULL },
- { "USERPROFILE", "\\Application Data"},
+ { "USERPROFILE", NULL, FALSE },
+ { "APPDATA", NULL, FALSE },
+ { "USERPROFILE", "\\Application Data", FALSE},
#endif
- { NULL, NULL }
+ /* these are for .curlrc if XDG_CONFIG_HOME is not defined */
+ { "CURL_HOME", "/.config", TRUE },
+ { "HOME", "/.config", TRUE },
+
+ { NULL, NULL, FALSE }
};
static char *checkhome(const char *home, const char *fname, bool dotscore)
@@ -90,11 +97,12 @@ static char *checkhome(const char *home, const char *fname, bool dotscore)
* the given file to be accessed there, then it is a match.
* 2. Non-windows: try getpwuid
*/
-char *findfile(const char *fname, bool dotscore)
+char *findfile(const char *fname, int dotscore)
{
int i;
+ bool xdg = FALSE;
DEBUGASSERT(fname && fname[0]);
- DEBUGASSERT(!dotscore || (fname[0] == '.'));
+ DEBUGASSERT((dotscore != 1) || (fname[0] == '.'));
if(!fname[0])
return NULL;
@@ -103,6 +111,9 @@ char *findfile(const char *fname, bool dotscore)
char *home = curl_getenv(list[i].env);
if(home) {
char *path;
+ const char *filename = fname;
+ if(i == 1 /* XDG_CONFIG_HOME */)
+ xdg = TRUE;
if(!home[0]) {
curl_free(home);
continue;
@@ -114,7 +125,15 @@ char *findfile(const char *fname, bool dotscore)
return NULL;
home = c;
}
- path = checkhome(home, fname, dotscore);
+ if(list[i].withoutdot) {
+ if(!dotscore || xdg)
+ /* this is not looking for .curlrc, or the XDG_CONFIG_HOME was
+ defined so we skip the extended check */
+ continue;
+ filename++; /* move past the leading dot */
+ dotscore = 0; /* disable it for this check */
+ }
+ path = checkhome(home, filename, dotscore ? dotscore - 1 : 0);
curl_free(home);
if(path)
return path;
diff --git a/src/tool_findfile.h b/src/tool_findfile.h
index 0f6a8eb55..412390867 100644
--- a/src/tool_findfile.h
+++ b/src/tool_findfile.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -23,6 +23,12 @@
***************************************************************************/
#include "tool_setup.h"
-char *findfile(const char *fname, bool dotscore);
+#ifdef WIN32
+#define CURLRC_DOTSCORE 2 /* look for underscore-prefixed name too */
+#else
+#define CURLRC_DOTSCORE 1 /* regular .curlrc check */
+#endif
+
+char *findfile(const char *fname, int dotscore);
#endif /* HEADER_CURL_TOOL_HOMEDIR_H */
diff --git a/src/tool_parsecfg.c b/src/tool_parsecfg.c
index ddb345c6d..3630ceca8 100644
--- a/src/tool_parsecfg.c
+++ b/src/tool_parsecfg.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -84,15 +84,10 @@ int parseconfig(const char *filename, struct GlobalConfig *global)
int rc = 0;
struct OperationConfig *operation = global->last;
char *pathalloc = NULL;
-#ifdef WIN32
-#define DOTSCORE TRUE /* look for underscore-prefixed name too */
-#else
-#define DOTSCORE FALSE
-#endif
if(!filename) {
/* NULL means load .curlrc from homedir! */
- char *curlrc = findfile(".curlrc", DOTSCORE);
+ char *curlrc = findfile(".curlrc", CURLRC_DOTSCORE);
if(curlrc) {
file = fopen(curlrc, FOPEN_READTEXT);
if(!file) {
diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc
index 8ac53b06d..6a12afe38 100644
--- a/tests/data/Makefile.inc
+++ b/tests/data/Makefile.inc
@@ -68,7 +68,7 @@ test392 test393 test394 test395 test396 test397 \
test400 test401 test402 test403 test404 test405 test406 test407 test408 \
test409 test410 \
\
-test430 test431 test432 test433 test434 test435 \
+test430 test431 test432 test433 test434 test435 test436 \
\
test490 test491 test492 test493 test494 \
\
diff --git a/tests/data/test436 b/tests/data/test436
new file mode 100644
index 000000000..0a62cfb97
--- /dev/null
+++ b/tests/data/test436
@@ -0,0 +1,58 @@
+<testcase>
+<info>
+<keywords>
+--config
+</keywords>
+</info>
+
+#
+# Server-side
+<reply>
+<data>
+HTTP/1.1 200 OK
+Content-Length: 6
+Content-Type: text/1
+
+-foo-
+</data>
+</reply>
+
+#
+# Client-side
+<client>
+<file1 name="log/.config/curlrc">
+--next
+header = "a: a"
+data = "curlrc read"
+</file1>
+<server>
+http
+</server>
+<setenv>
+CURL_HOME=%PWD/log
+XDG_CONFIG_HOME=
+</setenv>
+<name>
+Find .curlrc in .config/curlrc via CURL_HOME
+</name>
+<command>
+%HOSTIP:%HTTPPORT/%TESTNUMBER
+</command>
+</client>
+
+#
+# Verify data after the test has been "shot"
+<verify>
+<protocol nonewline="yes">
+POST /%TESTNUMBER HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+User-Agent: curl/%VERSION
+Accept: */*
+a: a
+Content-Length: 11
+Content-Type: application/x-www-form-urlencoded
+
+curlrc read
+</protocol>
+</verify>
+</testcase>