]>
git.proxmox.com Git - systemd.git/blob - src/reply-password/reply-password.c
2 This file is part of systemd.
4 Copyright 2010 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
23 #include <sys/socket.h>
29 #include "string-util.h"
32 static int send_on_socket(int fd
, const char *socket_name
, const void *packet
, size_t size
) {
35 struct sockaddr_un un
;
37 .un
.sun_family
= AF_UNIX
,
44 strncpy(sa
.un
.sun_path
, socket_name
, sizeof(sa
.un
.sun_path
));
46 if (sendto(fd
, packet
, size
, MSG_NOSIGNAL
, &sa
.sa
, offsetof(struct sockaddr_un
, sun_path
) + strlen(socket_name
)) < 0)
47 return log_error_errno(errno
, "Failed to send: %m");
52 int main(int argc
, char *argv
[]) {
53 _cleanup_close_
int fd
= -1;
54 char packet
[LINE_MAX
];
58 log_set_target(LOG_TARGET_AUTO
);
59 log_parse_environment();
63 log_error("Wrong number of arguments.");
67 if (streq(argv
[1], "1")) {
70 if (!fgets(packet
+1, sizeof(packet
)-1, stdin
)) {
71 r
= log_error_errno(errno
, "Failed to read password: %m");
75 truncate_nl(packet
+1);
76 length
= 1 + strlen(packet
+1) + 1;
77 } else if (streq(argv
[1], "0")) {
81 log_error("Invalid first argument %s", argv
[1]);
86 fd
= socket(AF_UNIX
, SOCK_DGRAM
|SOCK_CLOEXEC
|SOCK_NONBLOCK
, 0);
88 r
= log_error_errno(errno
, "socket() failed: %m");
92 r
= send_on_socket(fd
, argv
[2], packet
, length
);
95 memory_erase(packet
, sizeof(packet
));
97 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;