diff options
-rw-r--r-- | src/core/dbus-execute.c | 2 | ||||
-rw-r--r-- | src/core/load-fragment.c | 2 | ||||
-rw-r--r-- | src/journal/journal-file.c | 38 | ||||
-rw-r--r-- | src/journal/journal-file.h | 2 | ||||
-rw-r--r-- | src/shared/journal-util.c | 38 | ||||
-rw-r--r-- | src/shared/journal-util.h | 1 | ||||
-rw-r--r-- | src/systemctl/systemctl.c | 2 |
7 files changed, 43 insertions, 42 deletions
diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c index 50f7ada8ce..090c4d9660 100644 --- a/src/core/dbus-execute.c +++ b/src/core/dbus-execute.c @@ -24,7 +24,7 @@ #include "hexdecoct.h" #include "io-util.h" #include "ioprio.h" -#include "journal-util.h" +#include "journal-file.h" #include "mountpoint-util.h" #include "namespace.h" #include "parse-util.h" diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index f326526333..e9afc9b97a 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -37,7 +37,7 @@ #include "io-util.h" #include "ioprio.h" #include "ip-protocol-list.h" -#include "journal-util.h" +#include "journal-file.h" #include "limits-util.h" #include "load-fragment.h" #include "log.h" diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index 2cb5e5c51d..5bf4d40dc0 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -1525,6 +1525,44 @@ int journal_file_find_data_object( ret, ret_offset); } +bool journal_field_valid(const char *p, size_t l, bool allow_protected) { + const char *a; + + /* We kinda enforce POSIX syntax recommendations for + environment variables here, but make a couple of additional + requirements. + + http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap08.html */ + + if (l == (size_t) -1) + l = strlen(p); + + /* No empty field names */ + if (l <= 0) + return false; + + /* Don't allow names longer than 64 chars */ + if (l > 64) + return false; + + /* Variables starting with an underscore are protected */ + if (!allow_protected && p[0] == '_') + return false; + + /* Don't allow digits as first character */ + if (p[0] >= '0' && p[0] <= '9') + return false; + + /* Only allow A-Z0-9 and '_' */ + for (a = p; a < p + l; a++) + if ((*a < 'A' || *a > 'Z') && + (*a < '0' || *a > '9') && + *a != '_') + return false; + + return true; +} + static int journal_file_append_field( JournalFile *f, const void *field, uint64_t size, diff --git a/src/journal/journal-file.h b/src/journal/journal-file.h index f80bf5d26b..25d709aa2a 100644 --- a/src/journal/journal-file.h +++ b/src/journal/journal-file.h @@ -272,3 +272,5 @@ static inline bool JOURNAL_FILE_COMPRESS(JournalFile *f) { } uint64_t journal_file_hash_data(JournalFile *f, const void *data, size_t sz); + +bool journal_field_valid(const char *p, size_t l, bool allow_protected); diff --git a/src/shared/journal-util.c b/src/shared/journal-util.c index cb3762df43..26ea807daa 100644 --- a/src/shared/journal-util.c +++ b/src/shared/journal-util.c @@ -138,41 +138,3 @@ int journal_access_check_and_warn(sd_journal *j, bool quiet, bool want_other_use return r; } - -bool journal_field_valid(const char *p, size_t l, bool allow_protected) { - const char *a; - - /* We kinda enforce POSIX syntax recommendations for - environment variables here, but make a couple of additional - requirements. - - http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap08.html */ - - if (l == (size_t) -1) - l = strlen(p); - - /* No empty field names */ - if (l <= 0) - return false; - - /* Don't allow names longer than 64 chars */ - if (l > 64) - return false; - - /* Variables starting with an underscore are protected */ - if (!allow_protected && p[0] == '_') - return false; - - /* Don't allow digits as first character */ - if (p[0] >= '0' && p[0] <= '9') - return false; - - /* Only allow A-Z0-9 and '_' */ - for (a = p; a < p + l; a++) - if ((*a < 'A' || *a > 'Z') && - (*a < '0' || *a > '9') && - *a != '_') - return false; - - return true; -} diff --git a/src/shared/journal-util.h b/src/shared/journal-util.h index 34ad1bfc8e..b70bcc3af3 100644 --- a/src/shared/journal-util.h +++ b/src/shared/journal-util.h @@ -6,6 +6,5 @@ #include "sd-journal.h" -bool journal_field_valid(const char *p, size_t l, bool allow_protected); int journal_access_blocked(sd_journal *j); int journal_access_check_and_warn(sd_journal *j, bool quiet, bool want_other_users); diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index cae2e88945..0cebe888b3 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -51,7 +51,7 @@ #include "initreq.h" #include "install.h" #include "io-util.h" -#include "journal-util.h" +#include "journal-file.h" #include "list.h" #include "locale-util.h" #include "log.h" |