[svn-upgrade] Integrating new upstream version, iodine (0.4.1)
[debian/iodine.git] / src / common.c
index 521d2e6e75cfab2ab842aebe69606de1144815a9..73cf24d24e051030f5dfe0551943e12a914bdeb1 100644 (file)
@@ -29,6 +29,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <ctype.h>
+#include <termios.h>
 
 #include "common.h"
 
@@ -71,13 +72,11 @@ close_dns(int fd)
 void
 do_chroot(char *newroot)
 {
-       if (newroot) {
-               if (chroot(newroot) != 0 || chdir("/") != 0)
-                       err(1, "%s", newroot);
+       if (chroot(newroot) != 0 || chdir("/") != 0)
+               err(1, "%s", newroot);
 
-               seteuid(geteuid());
-               setuid(getuid());
-       }
+       seteuid(geteuid());
+       setuid(getuid());
 }
 
 void
@@ -88,3 +87,27 @@ do_detach()
        umask(0);
        alarm(0);
 }
+
+void
+read_password(char *buf, size_t len)
+{
+       struct termios old;
+       struct termios tp;
+       char pwd[80];
+
+       tcgetattr(0, &tp);
+       old = tp;
+       
+       tp.c_lflag &= (~ECHO);
+       tcsetattr(0, TCSANOW, &tp);
+
+       printf("Enter password: ");
+       fflush(stdout);
+       scanf("%79s", pwd);
+       printf("\n");
+
+       tcsetattr(0, TCSANOW, &old);    
+
+       strncpy(buf, pwd, len);
+       buf[len-1] = '\0';
+}