X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;ds=sidebyside;f=src%2Fshared%2Futil.c;h=c53f9cdb6acb1c3cd055bd7698d18b03a97c7082;hb=63c372cb9df3bee01e3bf8cd7f96f336bddda846;hp=5157b94a34600cb1b7ca556f38de5f6fe0f26054;hpb=a2e0337875addaf08225fbf9b231435ba12a88b5;p=elogind.git diff --git a/src/shared/util.c b/src/shared/util.c index 5157b94a3..c53f9cdb6 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -1539,6 +1539,10 @@ _pure_ static bool hidden_file_allow_backup(const char *filename) { endswith(filename, ".dpkg-old") || endswith(filename, ".dpkg-new") || endswith(filename, ".dpkg-tmp") || + endswith(filename, ".dpkg-dist") || + endswith(filename, ".dpkg-bak") || + endswith(filename, ".dpkg-backup") || + endswith(filename, ".dpkg-remove") || endswith(filename, ".swp"); } @@ -4244,6 +4248,11 @@ bool hostname_is_valid(const char *s) { if (isempty(s)) return false; + /* Doesn't accept empty hostnames, hostnames with trailing or + * leading dots, and hostnames with multiple dots in a + * sequence. Also ensures that the length stays below + * HOST_NAME_MAX. */ + for (p = s, dot = true; *p; p++) { if (*p == '.') { if (dot) @@ -5458,6 +5467,19 @@ int getenv_for_pid(pid_t pid, const char *field, char **_value) { return r; } +bool http_etag_is_valid(const char *etag) { + if (isempty(etag)) + return false; + + if (!endswith(etag, "\"")) + return false; + + if (!startswith(etag, "\"") && !startswith(etag, "W/\"")) + return false; + + return true; +} + bool http_url_is_valid(const char *url) { const char *p; @@ -6430,7 +6452,7 @@ int container_get_leader(const char *machine, pid_t *pid) { assert(machine); assert(pid); - p = strappenda("/run/systemd/machines/", machine); + p = strjoina("/run/systemd/machines/", machine); r = parse_env_file(p, NEWLINE, "LEADER", &s, "CLASS", &class, NULL); if (r == -ENOENT) return -EHOSTDOWN; @@ -6669,7 +6691,7 @@ int open_tmpfile(const char *path, int flags) { #endif /* Fall back to unguessable name + unlinking */ - p = strappenda(path, "/systemd-tmp-XXXXXX"); + p = strjoina(path, "/systemd-tmp-XXXXXX"); fd = mkostemp_safe(p, flags); if (fd < 0) @@ -7198,7 +7220,7 @@ int take_password_lock(const char *root) { * awfully racy, and thus we just won't do them. */ if (root) - path = strappenda(root, "/etc/.pwd.lock"); + path = strjoina(root, "/etc/.pwd.lock"); else path = "/etc/.pwd.lock"; @@ -8011,3 +8033,55 @@ ssize_t sparse_write(int fd, const void *p, size_t sz, size_t run_length) { return q - (const uint8_t*) p; } + +void sigkill_wait(pid_t *pid) { + if (!pid) + return; + if (*pid <= 1) + return; + + if (kill(*pid, SIGKILL) > 0) + (void) wait_for_terminate(*pid, NULL); +} + +int syslog_parse_priority(const char **p, int *priority, bool with_facility) { + int a = 0, b = 0, c = 0; + int k; + + assert(p); + assert(*p); + assert(priority); + + if ((*p)[0] != '<') + return 0; + + if (!strchr(*p, '>')) + return 0; + + if ((*p)[2] == '>') { + c = undecchar((*p)[1]); + k = 3; + } else if ((*p)[3] == '>') { + b = undecchar((*p)[1]); + c = undecchar((*p)[2]); + k = 4; + } else if ((*p)[4] == '>') { + a = undecchar((*p)[1]); + b = undecchar((*p)[2]); + c = undecchar((*p)[3]); + k = 5; + } else + return 0; + + if (a < 0 || b < 0 || c < 0 || + (!with_facility && (a || b || c > 7))) + return 0; + + if (with_facility) + *priority = a*100 + b*10 + c; + else + *priority = (*priority & LOG_FACMASK) | c; + + *p += k; + return 1; +}