Example #1
0
static char *image_roothash_path(Image *image) {
        const char *fn;

        assert(image);

        fn = strjoina(image->name, ".roothash");

        return file_in_same_dir(image->path, fn);
}
Example #2
0
/* Parse a variable assignment line */
static int parse_line(const char* unit,
                      const char *filename,
                      unsigned line,
                      const char *sections,
                      ConfigItemLookup lookup,
                      const void *table,
                      bool relaxed,
                      bool allow_include,
                      char **section,
                      unsigned *section_line,
                      bool *section_ignored,
                      char *l,
                      void *userdata) {

    char *e;

    assert(filename);
    assert(line > 0);
    assert(lookup);
    assert(l);

    l = strstrip(l);

    if (!*l)
        return 0;

    if (strchr(COMMENTS "\n", *l))
        return 0;

    if (startswith(l, ".include ")) {
        _cleanup_free_ char *fn = NULL;

        /* .includes are a bad idea, we only support them here
         * for historical reasons. They create cyclic include
         * problems and make it difficult to detect
         * configuration file changes with an easy
         * stat(). Better approaches, such as .d/ drop-in
         * snippets exist.
         *
         * Support for them should be eventually removed. */

        if (!allow_include) {
            log_syntax(unit, LOG_ERR, filename, line, EBADMSG,
                       ".include not allowed here. Ignoring.");
            return 0;
        }

        fn = file_in_same_dir(filename, strstrip(l+9));
        if (!fn)
            return -ENOMEM;

        return config_parse(unit, fn, NULL, sections, lookup, table, relaxed, false, false, userdata);
    }

    if (*l == '[') {
        size_t k;
        char *n;

        k = strlen(l);
        assert(k > 0);

        if (l[k-1] != ']') {
            log_syntax(unit, LOG_ERR, filename, line, EBADMSG,
                       "Invalid section header '%s'", l);
            return -EBADMSG;
        }

        n = strndup(l+1, k-2);
        if (!n)
            return -ENOMEM;

        if (sections && !nulstr_contains(sections, n)) {

            if (!relaxed && !startswith(n, "X-"))
                log_syntax(unit, LOG_WARNING, filename, line, EINVAL,
                           "Unknown section '%s'. Ignoring.", n);

            free(n);
            free(*section);
            *section = NULL;
            *section_line = 0;
            *section_ignored = true;
        } else {
            free(*section);
            *section = n;
            *section_line = line;
            *section_ignored = false;
        }

        return 0;
    }

    if (sections && !*section) {

        if (!relaxed && !*section_ignored)
            log_syntax(unit, LOG_WARNING, filename, line, EINVAL,
                       "Assignment outside of section. Ignoring.");

        return 0;
    }

    e = strchr(l, '=');
    if (!e) {
        log_syntax(unit, LOG_WARNING, filename, line, EINVAL, "Missing '='.");
        return -EBADMSG;
    }

    *e = 0;
    e++;

    return next_assignment(unit,
                           filename,
                           line,
                           lookup,
                           table,
                           *section,
                           *section_line,
                           strstrip(l),
                           strstrip(e),
                           relaxed,
                           userdata);
}
Example #3
0
/* Parse a single logical line */
static int parse_line(
                const char* unit,
                const char *filename,
                unsigned line,
                const char *sections,
                ConfigItemLookup lookup,
                const void *table,
                ConfigParseFlags flags,
                char **section,
                unsigned *section_line,
                bool *section_ignored,
                char *l,
                void *userdata) {

        char *e, *include;

        assert(filename);
        assert(line > 0);
        assert(lookup);
        assert(l);

        l = strstrip(l);
        if (!*l)
                return 0;

        if (strchr(COMMENTS "\n", *l))
                return 0;

        include = first_word(l, ".include");
        if (include) {
                _cleanup_free_ char *fn = NULL;

                /* .includes are a bad idea, we only support them here
                 * for historical reasons. They create cyclic include
                 * problems and make it difficult to detect
                 * configuration file changes with an easy
                 * stat(). Better approaches, such as .d/ drop-in
                 * snippets exist.
                 *
                 * Support for them should be eventually removed. */

                if (!(flags & CONFIG_PARSE_ALLOW_INCLUDE)) {
                        log_syntax(unit, LOG_ERR, filename, line, 0, ".include not allowed here. Ignoring.");
                        return 0;
                }

                log_syntax(unit, LOG_WARNING, filename, line, 0,
                           ".include directives are deprecated, and support for them will be removed in a future version of systemd. "
                           "Please use drop-in files instead.");

                fn = file_in_same_dir(filename, strstrip(include));
                if (!fn)
                        return -ENOMEM;

                return config_parse(unit, fn, NULL, sections, lookup, table, flags, userdata);
        }

        if (!utf8_is_valid(l))
                return log_syntax_invalid_utf8(unit, LOG_WARNING, filename, line, l);

        if (*l == '[') {
                size_t k;
                char *n;

                k = strlen(l);
                assert(k > 0);

                if (l[k-1] != ']') {
                        log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid section header '%s'", l);
                        return -EBADMSG;
                }

                n = strndup(l+1, k-2);
                if (!n)
                        return -ENOMEM;

                if (sections && !nulstr_contains(sections, n)) {

                        if (!(flags & CONFIG_PARSE_RELAXED) && !startswith(n, "X-"))
                                log_syntax(unit, LOG_WARNING, filename, line, 0, "Unknown section '%s'. Ignoring.", n);

                        free(n);
                        *section = mfree(*section);
                        *section_line = 0;
                        *section_ignored = true;
                } else {
                        free_and_replace(*section, n);
                        *section_line = line;
                        *section_ignored = false;
                }

                return 0;
        }

        if (sections && !*section) {

                if (!(flags & CONFIG_PARSE_RELAXED) && !*section_ignored)
                        log_syntax(unit, LOG_WARNING, filename, line, 0, "Assignment outside of section. Ignoring.");

                return 0;
        }

        e = strchr(l, '=');
        if (!e) {
                log_syntax(unit, LOG_WARNING, filename, line, 0, "Missing '='.");
                return -EINVAL;
        }

        *e = 0;
        e++;

        return next_assignment(unit,
                               filename,
                               line,
                               lookup,
                               table,
                               *section,
                               *section_line,
                               strstrip(l),
                               strstrip(e),
                               flags,
                               userdata);
}
Example #4
0
/* Parse a variable assignment line */
static int parse_line(const char* unit,
                      const char *filename,
                      unsigned line,
                      const char *sections,
                      ConfigItemLookup lookup,
                      void *table,
                      bool relaxed,
                      bool allow_include,
                      char **section,
                      unsigned *section_line,
                      char *l,
                      void *userdata) {

        char *e;

        assert(filename);
        assert(line > 0);
        assert(lookup);
        assert(l);

        l = strstrip(l);

        if (!*l)
                return 0;

        if (strchr(COMMENTS "\n", *l))
                return 0;

        if (startswith(l, ".include ")) {
                _cleanup_free_ char *fn = NULL;

                if (!allow_include) {
                        log_syntax(unit, LOG_ERR, filename, line, EBADMSG,
                                   ".include not allowed here. Ignoring.");
                        return 0;
                }

                fn = file_in_same_dir(filename, strstrip(l+9));
                if (!fn)
                        return -ENOMEM;

                return config_parse(unit, fn, NULL, sections, lookup, table, relaxed, false, userdata);
        }

        if (*l == '[') {
                size_t k;
                char *n;

                k = strlen(l);
                assert(k > 0);

                if (l[k-1] != ']') {
                        log_syntax(unit, LOG_ERR, filename, line, EBADMSG,
                                   "Invalid section header '%s'", l);
                        return -EBADMSG;
                }

                n = strndup(l+1, k-2);
                if (!n)
                        return -ENOMEM;

                if (sections && !nulstr_contains(sections, n)) {

                        if (!relaxed)
                                log_syntax(unit, LOG_WARNING, filename, line, EINVAL,
                                           "Unknown section '%s'. Ignoring.", n);

                        free(n);
                        free(*section);
                        *section = NULL;
                        *section_line = 0;
                } else {
                        free(*section);
                        *section = n;
                        *section_line = line;
                }

                return 0;
        }

        if (sections && !*section) {

                if (!relaxed)
                        log_syntax(unit, LOG_WARNING, filename, line, EINVAL,
                                   "Assignment outside of section. Ignoring.");

                return 0;
        }

        e = strchr(l, '=');
        if (!e) {
                log_syntax(unit, LOG_WARNING, filename, line, EINVAL, "Missing '='.");
                return -EBADMSG;
        }

        *e = 0;
        e++;

        return next_assignment(unit,
                               filename,
                               line,
                               lookup,
                               table,
                               *section,
                               *section_line,
                               strstrip(l),
                               strstrip(e),
                               relaxed,
                               userdata);
}
Example #5
0
/* Parse a variable assignment line */
static int parse_line(
                const char *filename,
                unsigned line,
                const char *sections,
                ConfigItemLookup lookup,
                void *table,
                bool relaxed,
                char **section,
                char *l,
                void *userdata) {

        char *e;

        assert(filename);
        assert(line > 0);
        assert(lookup);
        assert(l);

        l = strstrip(l);

        if (!*l)
                return 0;

        if (strchr(COMMENTS, *l))
                return 0;

        if (startswith(l, ".include ")) {
                char *fn;
                int r;

                fn = file_in_same_dir(filename, strstrip(l+9));
                if (!fn)
                        return -ENOMEM;

                r = config_parse(fn, NULL, sections, lookup, table, relaxed, userdata);
                free(fn);

                return r;
        }

        if (*l == '[') {
                size_t k;
                char *n;

                k = strlen(l);
                assert(k > 0);

                if (l[k-1] != ']') {
                        log_error("[%s:%u] Invalid section header.", filename, line);
                        return -EBADMSG;
                }

                n = strndup(l+1, k-2);
                if (!n)
                        return -ENOMEM;

                if (sections && !nulstr_contains(sections, n)) {

                        if (!relaxed)
                                log_info("[%s:%u] Unknown section '%s'. Ignoring.", filename, line, n);

                        free(n);
                        *section = NULL;
                } else {
                        free(*section);
                        *section = n;
                }

                return 0;
        }

        if (sections && !*section) {

                if (!relaxed)
                        log_info("[%s:%u] Assignment outside of section. Ignoring.", filename, line);

                return 0;
        }

        e = strchr(l, '=');
        if (!e) {
                log_error("[%s:%u] Missing '='.", filename, line);
                return -EBADMSG;
        }

        *e = 0;
        e++;

        return next_assignment(
                        filename,
                        line,
                        lookup,
                        table,
                        *section,
                        strstrip(l),
                        strstrip(e),
                        relaxed,
                        userdata);
}