|
|
da1e07 |
diff -up libnfsidmap-0.25/cfg.c.orig libnfsidmap-0.25/cfg.c
|
|
|
da1e07 |
--- libnfsidmap-0.25/cfg.c.orig 2011-12-05 15:28:10.000000000 -0500
|
|
|
da1e07 |
+++ libnfsidmap-0.25/cfg.c 2017-11-17 12:01:56.756692437 -0500
|
|
|
da1e07 |
@@ -210,69 +210,98 @@ static void
|
|
|
da1e07 |
conf_parse_line (int trans, char *line, size_t sz)
|
|
|
da1e07 |
{
|
|
|
da1e07 |
char *val;
|
|
|
da1e07 |
- size_t i;
|
|
|
da1e07 |
- int j;
|
|
|
da1e07 |
+ char *ptr;
|
|
|
da1e07 |
static char *section = 0;
|
|
|
da1e07 |
static int ln = 0;
|
|
|
da1e07 |
|
|
|
da1e07 |
ln++;
|
|
|
da1e07 |
|
|
|
da1e07 |
+ /* Strip off any leading blanks */
|
|
|
da1e07 |
+ while (isblank(*line))
|
|
|
da1e07 |
+ line++;
|
|
|
da1e07 |
+
|
|
|
da1e07 |
+
|
|
|
da1e07 |
/* Lines starting with '#' or ';' are comments. */
|
|
|
da1e07 |
if (*line == '#' || *line == ';')
|
|
|
da1e07 |
return;
|
|
|
da1e07 |
|
|
|
da1e07 |
/* '[section]' parsing... */
|
|
|
da1e07 |
- if (*line == '[')
|
|
|
da1e07 |
- {
|
|
|
da1e07 |
- for (i = 1; i < sz; i++)
|
|
|
da1e07 |
- if (line[i] == ']')
|
|
|
da1e07 |
- break;
|
|
|
da1e07 |
- if (section)
|
|
|
da1e07 |
- free (section);
|
|
|
da1e07 |
- if (i == sz)
|
|
|
da1e07 |
- {
|
|
|
da1e07 |
- warnx("conf_parse_line: %d:"
|
|
|
da1e07 |
- "non-matched ']', ignoring until next section", ln);
|
|
|
da1e07 |
- section = 0;
|
|
|
da1e07 |
- return;
|
|
|
da1e07 |
+ if (*line == '[') {
|
|
|
da1e07 |
+ line++;
|
|
|
da1e07 |
+
|
|
|
da1e07 |
+ if (section) free(section);
|
|
|
da1e07 |
+
|
|
|
da1e07 |
+ while (isblank(*line)) line++;
|
|
|
da1e07 |
+
|
|
|
da1e07 |
+ /* find the closing ] */
|
|
|
da1e07 |
+ ptr = strchr(line, ']');
|
|
|
da1e07 |
+
|
|
|
da1e07 |
+ if (ptr == NULL) {
|
|
|
da1e07 |
+ warnx("conf_parse_line: %d:"
|
|
|
da1e07 |
+ "non-matched ']', ignoring until next section", ln);
|
|
|
da1e07 |
+ section = NULL;
|
|
|
da1e07 |
+ return;
|
|
|
da1e07 |
}
|
|
|
da1e07 |
- section = malloc (i);
|
|
|
da1e07 |
- if (!section)
|
|
|
da1e07 |
- {
|
|
|
da1e07 |
- warnx("conf_parse_line: %d: malloc (%lu) failed", ln,
|
|
|
da1e07 |
- (unsigned long)i);
|
|
|
da1e07 |
- return;
|
|
|
da1e07 |
+
|
|
|
da1e07 |
+ /* just ignore everything after the closing ] */
|
|
|
da1e07 |
+ *(ptr--) = '\0';
|
|
|
da1e07 |
+
|
|
|
da1e07 |
+ /* strip off any blanks before ']' */
|
|
|
da1e07 |
+ while (ptr >= line && isblank(*ptr))
|
|
|
da1e07 |
+ *(ptr--) = '\0';
|
|
|
da1e07 |
+
|
|
|
da1e07 |
+ section = strdup(line);
|
|
|
da1e07 |
+ if (!section) {
|
|
|
da1e07 |
+ warnx("conf_parse_line: %d: malloc failed", ln);
|
|
|
da1e07 |
+
|
|
|
da1e07 |
}
|
|
|
da1e07 |
- strlcpy (section, line + 1, i);
|
|
|
da1e07 |
- return;
|
|
|
da1e07 |
- }
|
|
|
da1e07 |
+ return;
|
|
|
da1e07 |
+ }
|
|
|
da1e07 |
|
|
|
da1e07 |
/* Deal with assignments. */
|
|
|
da1e07 |
- for (i = 0; i < sz; i++)
|
|
|
da1e07 |
- if (line[i] == '=')
|
|
|
da1e07 |
- {
|
|
|
da1e07 |
- /* If no section, we are ignoring the lines. */
|
|
|
da1e07 |
- if (!section)
|
|
|
da1e07 |
- {
|
|
|
da1e07 |
+ ptr = strchr(line, '=');
|
|
|
da1e07 |
+
|
|
|
da1e07 |
+ /* not an assignment line */
|
|
|
da1e07 |
+ if (ptr == NULL) {
|
|
|
da1e07 |
+ /* and not just whitespace either, weird */
|
|
|
da1e07 |
+ if (line[strspn(line, " \t")])
|
|
|
da1e07 |
+ warnx("conf_parse_line: %d: syntax error", ln);
|
|
|
da1e07 |
+ return;
|
|
|
da1e07 |
+ }
|
|
|
da1e07 |
+
|
|
|
da1e07 |
+ /* If no section, we are ignoring the lines. */
|
|
|
da1e07 |
+ if (!section) {
|
|
|
da1e07 |
warnx("conf_parse_line: %d: ignoring line due to no section", ln);
|
|
|
da1e07 |
return;
|
|
|
da1e07 |
- }
|
|
|
da1e07 |
- line[strcspn (line, " \t=")] = '\0';
|
|
|
da1e07 |
- val = line + i + 1 + strspn (line + i + 1, " \t");
|
|
|
da1e07 |
- /* Skip trailing whitespace, if any */
|
|
|
da1e07 |
- for (j = sz - (val - line) - 1; j > 0 && isspace (val[j]); j--)
|
|
|
da1e07 |
- val[j] = '\0';
|
|
|
da1e07 |
- /* XXX Perhaps should we not ignore errors? */
|
|
|
da1e07 |
- conf_set (trans, section, line, val, 0, 0);
|
|
|
da1e07 |
- return;
|
|
|
da1e07 |
- }
|
|
|
da1e07 |
-
|
|
|
da1e07 |
- /* Other non-empty lines are weird. */
|
|
|
da1e07 |
- i = strspn (line, " \t");
|
|
|
da1e07 |
- if (line[i])
|
|
|
da1e07 |
- warnx("conf_parse_line: %d: syntax error", ln);
|
|
|
da1e07 |
+ }
|
|
|
da1e07 |
|
|
|
da1e07 |
- return;
|
|
|
da1e07 |
+ val = ptr + 1;
|
|
|
da1e07 |
+ *(ptr--) = '\0';
|
|
|
da1e07 |
+
|
|
|
da1e07 |
+ /* strip spaces before and after the = */
|
|
|
da1e07 |
+ while (ptr >= line && isblank(*ptr))
|
|
|
da1e07 |
+ *(ptr--) = '\0';
|
|
|
da1e07 |
+ while (*val != '\0' && isblank(*val))
|
|
|
da1e07 |
+ val++;
|
|
|
da1e07 |
+
|
|
|
da1e07 |
+ /* trim any trailing spaces or comments */
|
|
|
da1e07 |
+ if ((ptr=strchr(val, '#'))!=NULL) *ptr = '\0';
|
|
|
da1e07 |
+ if ((ptr=strchr(val, ';'))!=NULL) *ptr = '\0';
|
|
|
da1e07 |
+ ptr = val + strlen(val) - 1;
|
|
|
da1e07 |
+ while (ptr > val && isspace(*ptr))
|
|
|
da1e07 |
+ *(ptr--) = '\0';
|
|
|
da1e07 |
+
|
|
|
da1e07 |
+ if (*line == '\0') {
|
|
|
da1e07 |
+ warnx("conf_parse_line: %d: missing tag in assignment", ln);
|
|
|
da1e07 |
+ return;
|
|
|
da1e07 |
+ }
|
|
|
da1e07 |
+ if (*val == '\0') {
|
|
|
da1e07 |
+ warnx("conf_parse_line: %d: missing value in assignment", ln);
|
|
|
da1e07 |
+ return;
|
|
|
da1e07 |
+ }
|
|
|
da1e07 |
+
|
|
|
da1e07 |
+ /* XXX Perhaps should we not ignore errors? */
|
|
|
da1e07 |
+ conf_set (trans, section, line, val, 0, 0);
|
|
|
da1e07 |
}
|
|
|
da1e07 |
|
|
|
da1e07 |
/* Parse the mapped configuration file. */
|