[hackers] [ubase] Fix pw_check() semantics and style - it is now similar to pw_copy() || sin

From: <git_AT_suckless.org>
Date: Mon, 09 Jun 2014 14:05:40 +0200

commit d745889805558b4e0d03d360d66b38c54a143520
Author: sin <sin_AT_2f30.org>
Date: Mon Jun 9 12:58:40 2014 +0100

    Fix pw_check() semantics and style - it is now similar to pw_copy()

diff --git a/login.c b/login.c
index 25f6e87..895c339 100644
--- a/login.c
+++ b/login.c
_AT_@ -59,8 +59,8 @@ main(int argc, char *argv[])
         pass = getpass("Password: "); putchar('
');
         if (!pass)
                 eprintf("getpass:");
- if (pw_check(pw, pass) == 0)
- eprintf("incorrect password
");
+ if (pw_check(pw, pass) <= 0)
+ exit(EXIT_FAILURE);
 
         if (initgroups(argv[0], gid) < 0)
                 eprintf("initgroups:");
diff --git a/su.c b/su.c
index 1c69ce3..d9ec699 100644
--- a/su.c
+++ b/su.c
_AT_@ -63,8 +63,8 @@ main(int argc, char *argv[])
                 pass = getpass("Password: "); putchar('
');
                 if (!pass)
                         eprintf("getpass:");
- if (pw_check(pw, pass) == 0)
- eprintf("incorrect password
");
+ if (pw_check(pw, pass) <= 0)
+ exit(EXIT_FAILURE);
         }
 
         if (initgroups(usr, pw->pw_gid) < 0)
diff --git a/util/passwd.c b/util/passwd.c
index 8e531b0..d428b7e 100644
--- a/util/passwd.c
+++ b/util/passwd.c
_AT_@ -10,6 +10,8 @@
 #include "../text.h"
 #include "../util.h"
 
+/* Returns -1 on error, 0 for incorrect password
+ * and 1 if all went OK */
 int
 pw_check(struct passwd *pw, const char *pass)
 {
_AT_@ -17,8 +19,10 @@ pw_check(struct passwd *pw, const char *pass)
         struct spwd *spw;
 
         p = pw->pw_passwd;
- if (p[0] == '!' || p[0] == '*')
- eprintf("denied
");
+ if (p[0] == '!' || p[0] == '*') {
+ weprintf("denied
");
+ return -1;
+ }
 
         if (pw->pw_passwd[0] == '
Received on Mon Jun 09 2014 - 14:05:40 CEST

This archive was generated by hypermail 2.3.0 : Mon Jun 09 2014 - 14:12:08 CEST