X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fask-password-api.c;h=3941605ceceda64730943f5dcee30f49af84ef32;hb=682524fb67e18338b7029404d0ef036c3be1aaf2;hp=41049d79bd9d626c0c4bbaaa10a2080cd86d44a5;hpb=56f64d95763a799ba4475daf44d8e9f72a1bd474;p=elogind.git diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c index 41049d79b..3941605ce 100644 --- a/src/shared/ask-password-api.c +++ b/src/shared/ask-password-api.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include @@ -32,9 +32,12 @@ #include #include "util.h" +#include "formats-util.h" #include "mkdir.h" #include "strv.h" - +#include "random-util.h" +#include "terminal-util.h" +#include "signal-util.h" #include "ask-password-api.h" static void backspace_chars(int ttyfd, size_t p) { @@ -258,10 +261,8 @@ static int create_socket(char **name) { assert(name); fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0); - if (fd < 0) { - log_error_errno(errno, "socket() failed: %m"); - return -errno; - } + if (fd < 0) + return log_error_errno(errno, "socket() failed: %m"); snprintf(sa.un.sun_path, sizeof(sa.un.sun_path)-1, "/run/systemd/ask-password/sck.%" PRIx64, random_u64()); @@ -322,9 +323,9 @@ int ask_password_agent( assert(_passphrases); - assert_se(sigemptyset(&mask) == 0); - sigset_add_many(&mask, SIGINT, SIGTERM, -1); - assert_se(sigprocmask(SIG_BLOCK, &mask, &oldmask) == 0); + assert_se(sigemptyset(&mask) >= 0); + assert_se(sigset_add_many(&mask, SIGINT, SIGTERM, -1) >= 0); + assert_se(sigprocmask(SIG_BLOCK, &mask, &oldmask) >= 0); mkdir_p_label("/run/systemd/ask-password", 0755); @@ -477,6 +478,8 @@ int ask_password_agent( goto finish; } + cmsg_close_all(&msghdr); + if (n <= 0) { log_error("Message too short"); continue;