aboutsummaryrefslogtreecommitdiffstats
path: root/common/homedir.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2023-12-19 09:04:49 +0000
committerWerner Koch <[email protected]>2023-12-19 09:04:49 +0000
commit8eff1d4c511088ff40d5fac13c00cdd07467eebb (patch)
treeffe065d6ac366de8a04db6b902cd6fb9784ef005 /common/homedir.c
parentcommon: Enhance dotlock, so that we can have a CLI util. (diff)
downloadgnupg-8eff1d4c511088ff40d5fac13c00cdd07467eebb.tar.gz
gnupg-8eff1d4c511088ff40d5fac13c00cdd07467eebb.zip
common: Improve the parsing of gpgconf.ctl variables.
* common/homedir.c (unix_rootdir): Simplify. -- This also relaxes the syntax in that the equal sign may now be surrounded by any number of spaces.
Diffstat (limited to 'common/homedir.c')
-rw-r--r--common/homedir.c57
1 files changed, 27 insertions, 30 deletions
diff --git a/common/homedir.c b/common/homedir.c
index 286685feb..641dba1ae 100644
--- a/common/homedir.c
+++ b/common/homedir.c
@@ -604,43 +604,40 @@ unix_rootdir (int want_sysconfdir)
sysconfdir = NULL;
while ((length = es_read_line (fp, &line, &linelen, NULL)) > 0)
{
+ static const char *names[] =
+ {
+ "rootdir",
+ "sysconfdir",
+ ".enable"
+ };
+ int i;
+ size_t n;
+
/* Strip NL and CR, if present. */
while (length > 0
&& (line[length - 1] == '\n' || line[length - 1] == '\r'))
line[--length] = 0;
trim_spaces (line);
- if (!strncmp (line, "rootdir=", 8))
- {
- name = "rootdir";
- p = line + 8;
- }
- else if (!strncmp (line, "rootdir =", 9)) /* (What a kludge) */
- {
- name = "rootdir";
- p = line + 9;
- }
- else if (!strncmp (line, "sysconfdir=", 11))
- {
- name = "sysconfdir";
- p = line + 11;
- }
- else if (!strncmp (line, "sysconfdir =", 12)) /* (What a kludge) */
+ /* Find the stamement. */
+ name = NULL;
+ for (i=0; i < DIM (names); i++)
{
- name = "sysconfdir";
- p = line + 12;
- }
- else if (!strncmp (line, ".enable=", 8))
- {
- name = ".enable";
- p = line + 8;
- }
- else if (!strncmp (line, ".enable =", 9))
- {
- name = ".enable";
- p = line + 9;
+ n = strlen (names[i]);
+ if (!strncmp (line, names[i], n))
+ {
+ while (line[n] == ' ' || line[n] == '\t')
+ n++;
+ if (line[n] == '=')
+ {
+ name = names[i];
+ p = line + n + 1;
+ break;
+ }
+ }
}
- else
- continue;
+ if (!name)
+ continue; /* Statement not known. */
+
trim_spaces (p);
p = substitute_envvars (p);
if (!p)