chiark / gitweb /
crypto: to show stars or not to show them
[elogind.git] / src / ask-password-api.c
index 9c3dad965e03099bd509ef9b3e379fc84ed6db82..022f1cae8caddff65f28a8fbecff8fc1a19449e6 100644 (file)
@@ -18,7 +18,7 @@
   You should have received a copy of the GNU General Public License
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
-
+#include <stdbool.h>
 #include <termios.h>
 #include <unistd.h>
 #include <sys/poll.h>
@@ -48,6 +48,7 @@ int ask_password_tty(
         int r, ttyfd = -1, notify = -1;
         struct pollfd pollfd[2];
         bool reset_tty = false;
+        bool silent_mode = false;
         enum {
                 POLL_TTY,
                 POLL_INOTIFY
@@ -156,7 +157,6 @@ int ask_password_tty(
                 if (c == '\n')
                         break;
                 else if (c == 21) {
-
                         while (p > 0) {
                                 p--;
 
@@ -165,7 +165,10 @@ int ask_password_tty(
                         }
 
                 } else if (c == '\b' || c == 127) {
-                        if (p > 0) {
+                        if (p == 0 && !silent_mode) {
+                                silent_mode = true;
+                                loop_write(ttyfd, "(no echo) ", 10, false);
+                        } else if (p > 0) {
                                 p--;
 
                                 if (ttyfd >= 0)
@@ -174,7 +177,7 @@ int ask_password_tty(
                 } else {
                         passphrase[p++] = c;
 
-                        if (ttyfd >= 0)
+                        if (!silent_mode && ttyfd >= 0)
                                 loop_write(ttyfd, "*", 1, false);
                 }
         }
@@ -223,7 +226,7 @@ static int create_socket(char **name) {
 
         zero(sa);
         sa.un.sun_family = AF_UNIX;
-        snprintf(sa.un.sun_path, sizeof(sa.un.sun_path)-1, "/dev/.run/systemd/ask-password/sck.%llu", random_ull());
+        snprintf(sa.un.sun_path, sizeof(sa.un.sun_path)-1, "/run/systemd/ask-password/sck.%llu", random_ull());
 
         if (bind(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(sa.un.sun_path)) < 0) {
                 r = -errno;
@@ -265,7 +268,7 @@ int ask_password_agent(
                 _FD_MAX
         };
 
-        char temp[] = "/dev/.run/systemd/ask-password/tmp.XXXXXX";
+        char temp[] = "/run/systemd/ask-password/tmp.XXXXXX";
         char final[sizeof(temp)] = "";
         int fd = -1, r;
         FILE *f = NULL;
@@ -280,7 +283,7 @@ int ask_password_agent(
         sigset_add_many(&mask, SIGINT, SIGTERM, -1);
         assert_se(sigprocmask(SIG_BLOCK, &mask, &oldmask) == 0);
 
-        mkdir_p("/dev/.run/systemd/ask-password", 0755);
+        mkdir_p("/run/systemd/ask-password", 0755);
 
         if ((fd = mkostemp(temp, O_CLOEXEC|O_CREAT|O_WRONLY)) < 0) {
                 log_error("Failed to create password file: %m");