|
|
5113bc |
From f769cb435c4db2e7f6d11e14fe87a1c81e0912fe Mon Sep 17 00:00:00 2001
|
|
|
5113bc |
From: Karel Zak <kzak@redhat.com>
|
|
|
5113bc |
Date: Wed, 23 May 2018 12:43:26 +0200
|
|
|
5113bc |
Subject: [PATCH 155/173] lslogins: fix password verification
|
|
|
5113bc |
|
|
|
5113bc |
Let's follow the standard $id$salt$encrypted password format in
|
|
|
5113bc |
verification code.
|
|
|
5113bc |
|
|
|
5113bc |
The current code is useless and for example PWD-LOCK column is always
|
|
|
5113bc |
FALSE.
|
|
|
5113bc |
|
|
|
5113bc |
Upstream: http://github.com/karelzak/util-linux/commit/214fbec40abf0432b8e7968f05024ee76d11b3c7
|
|
|
5113bc |
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1581611
|
|
|
5113bc |
Signed-off-by: Karel Zak <kzak@redhat.com>
|
|
|
5113bc |
---
|
|
|
5113bc |
login-utils/lslogins.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++---
|
|
|
5113bc |
1 file changed, 74 insertions(+), 4 deletions(-)
|
|
|
5113bc |
|
|
|
5113bc |
diff --git a/login-utils/lslogins.c b/login-utils/lslogins.c
|
|
|
5113bc |
index d7a24b1fb..041053625 100644
|
|
|
5113bc |
--- a/login-utils/lslogins.c
|
|
|
5113bc |
+++ b/login-utils/lslogins.c
|
|
|
5113bc |
@@ -541,14 +541,84 @@ static int get_nprocs(const uid_t uid)
|
|
|
5113bc |
return nprocs;
|
|
|
5113bc |
}
|
|
|
5113bc |
|
|
|
5113bc |
+static const char *get_pwd_method(const char *str, const char **next, unsigned int *sz)
|
|
|
5113bc |
+{
|
|
|
5113bc |
+ const char *p = str;
|
|
|
5113bc |
+ const char *res = NULL;
|
|
|
5113bc |
+
|
|
|
5113bc |
+ if (!p || *p++ != '$')
|
|
|
5113bc |
+ return NULL;
|
|
|
5113bc |
+
|
|
|
5113bc |
+ if (sz)
|
|
|
5113bc |
+ *sz = 0;
|
|
|
5113bc |
+
|
|
|
5113bc |
+ switch (*p) {
|
|
|
5113bc |
+ case '1':
|
|
|
5113bc |
+ res = "MD5";
|
|
|
5113bc |
+ if (sz)
|
|
|
5113bc |
+ *sz = 22;
|
|
|
5113bc |
+ break;
|
|
|
5113bc |
+ case '2':
|
|
|
5113bc |
+ p++;
|
|
|
5113bc |
+ if (*p == 'a' || *p == 'y')
|
|
|
5113bc |
+ res = "Blowfish";
|
|
|
5113bc |
+ break;
|
|
|
5113bc |
+ case '5':
|
|
|
5113bc |
+ res = "SHA-256";
|
|
|
5113bc |
+ if (sz)
|
|
|
5113bc |
+ *sz = 43;
|
|
|
5113bc |
+ break;
|
|
|
5113bc |
+ case '6':
|
|
|
5113bc |
+ res = "SHA-512";
|
|
|
5113bc |
+ if (sz)
|
|
|
5113bc |
+ *sz = 86;
|
|
|
5113bc |
+ break;
|
|
|
5113bc |
+ default:
|
|
|
5113bc |
+ return NULL;
|
|
|
5113bc |
+ }
|
|
|
5113bc |
+ p++;
|
|
|
5113bc |
+
|
|
|
5113bc |
+ if (!*p || *p != '$')
|
|
|
5113bc |
+ return NULL;
|
|
|
5113bc |
+ if (next)
|
|
|
5113bc |
+ *next = ++p;
|
|
|
5113bc |
+ return res;
|
|
|
5113bc |
+}
|
|
|
5113bc |
+
|
|
|
5113bc |
+#define is_valid_pwd_char(x) (isalnum((unsigned char) (x)) || (x) == '.' || (x) == '/')
|
|
|
5113bc |
+
|
|
|
5113bc |
static int valid_pwd(const char *str)
|
|
|
5113bc |
{
|
|
|
5113bc |
- const char *p;
|
|
|
5113bc |
+ const char *p = str;
|
|
|
5113bc |
+ unsigned int sz = 0, n;
|
|
|
5113bc |
+
|
|
|
5113bc |
+ /* $id$ */
|
|
|
5113bc |
+ if (get_pwd_method(str, &p, &sz) == NULL)
|
|
|
5113bc |
+ return 0;
|
|
|
5113bc |
+ if (!*p)
|
|
|
5113bc |
+ return 0;
|
|
|
5113bc |
|
|
|
5113bc |
- for (p = str; p && *p; p++)
|
|
|
5113bc |
- if (!isalnum((unsigned int) *p))
|
|
|
5113bc |
+ /* salt$ */
|
|
|
5113bc |
+ for (; p && *p; p++) {
|
|
|
5113bc |
+ if (*p == '$') {
|
|
|
5113bc |
+ p++;
|
|
|
5113bc |
+ break;
|
|
|
5113bc |
+ }
|
|
|
5113bc |
+ if (!is_valid_pwd_char(*p))
|
|
|
5113bc |
return 0;
|
|
|
5113bc |
- return p > str ? 1 : 0;
|
|
|
5113bc |
+ }
|
|
|
5113bc |
+ if (!*p)
|
|
|
5113bc |
+ return 0;
|
|
|
5113bc |
+
|
|
|
5113bc |
+ /* encrypted */
|
|
|
5113bc |
+ for (n = 0; p && *p; p++, n++) {
|
|
|
5113bc |
+ if (!is_valid_pwd_char(*p))
|
|
|
5113bc |
+ return 0;
|
|
|
5113bc |
+ }
|
|
|
5113bc |
+
|
|
|
5113bc |
+ if (sz && n != sz)
|
|
|
5113bc |
+ return 0;
|
|
|
5113bc |
+ return 1;
|
|
|
5113bc |
}
|
|
|
5113bc |
|
|
|
5113bc |
static struct lslogins_user *get_user_info(struct lslogins_control *ctl, const char *username)
|
|
|
5113bc |
--
|
|
|
5113bc |
2.14.4
|
|
|
5113bc |
|