|
|
d8d8bc |
From a1dfd3c737f7dad832b0f6ec975bcc5c9cc80ffe Mon Sep 17 00:00:00 2001
|
|
|
d8d8bc |
From: Karel Zak <kzak@redhat.com>
|
|
|
d8d8bc |
Date: Wed, 24 Aug 2022 12:20:25 +0200
|
|
|
d8d8bc |
Subject: lslogins: support more password methods
|
|
|
d8d8bc |
|
|
|
d8d8bc |
* detect more hashing methods
|
|
|
d8d8bc |
|
|
|
d8d8bc |
* don't care about hash size
|
|
|
d8d8bc |
|
|
|
d8d8bc |
* follow crypt(5) when check for valid chars
|
|
|
d8d8bc |
|
|
|
d8d8bc |
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2094216
|
|
|
d8d8bc |
Upstream: http://github.com/util-linux/util-linux/commit/2b9373e06243d5adf93d627916a5421b34a7e63f
|
|
|
d8d8bc |
Reported-by: Radka Skvarilova <rskvaril@redhat.com>
|
|
|
d8d8bc |
Signed-off-by: Karel Zak <kzak@redhat.com>
|
|
|
d8d8bc |
---
|
|
|
d8d8bc |
login-utils/lslogins.c | 66 +++++++++++++++++++++++++++---------------
|
|
|
d8d8bc |
1 file changed, 42 insertions(+), 24 deletions(-)
|
|
|
d8d8bc |
|
|
|
d8d8bc |
diff --git a/login-utils/lslogins.c b/login-utils/lslogins.c
|
|
|
d8d8bc |
index 56431212d..22e3cd23e 100644
|
|
|
d8d8bc |
--- a/login-utils/lslogins.c
|
|
|
d8d8bc |
+++ b/login-utils/lslogins.c
|
|
|
d8d8bc |
@@ -598,7 +598,7 @@ static int get_nprocs(const uid_t uid)
|
|
|
d8d8bc |
}
|
|
|
d8d8bc |
#endif
|
|
|
d8d8bc |
|
|
|
d8d8bc |
-static const char *get_pwd_method(const char *str, const char **next, unsigned int *sz)
|
|
|
d8d8bc |
+static const char *get_pwd_method(const char *str, const char **next)
|
|
|
d8d8bc |
{
|
|
|
d8d8bc |
const char *p = str;
|
|
|
d8d8bc |
const char *res = NULL;
|
|
|
d8d8bc |
@@ -606,32 +606,50 @@ static const char *get_pwd_method(const char *str, const char **next, unsigned i
|
|
|
d8d8bc |
if (!p || *p++ != '$')
|
|
|
d8d8bc |
return NULL;
|
|
|
d8d8bc |
|
|
|
d8d8bc |
- if (sz)
|
|
|
d8d8bc |
- *sz = 0;
|
|
|
d8d8bc |
-
|
|
|
d8d8bc |
switch (*p) {
|
|
|
d8d8bc |
case '1':
|
|
|
d8d8bc |
res = "MD5";
|
|
|
d8d8bc |
- if (sz)
|
|
|
d8d8bc |
- *sz = 22;
|
|
|
d8d8bc |
break;
|
|
|
d8d8bc |
case '2':
|
|
|
d8d8bc |
- p++;
|
|
|
d8d8bc |
- if (*p == 'a' || *p == 'y')
|
|
|
d8d8bc |
+ switch(*(p+1)) {
|
|
|
d8d8bc |
+ case 'a':
|
|
|
d8d8bc |
+ case 'y':
|
|
|
d8d8bc |
+ p++;
|
|
|
d8d8bc |
res = "Blowfish";
|
|
|
d8d8bc |
+ break;
|
|
|
d8d8bc |
+ case 'b':
|
|
|
d8d8bc |
+ p++;
|
|
|
d8d8bc |
+ res = "bcrypt";
|
|
|
d8d8bc |
+ break;
|
|
|
d8d8bc |
+ }
|
|
|
d8d8bc |
+ break;
|
|
|
d8d8bc |
+ case '3':
|
|
|
d8d8bc |
+ res = "NT";
|
|
|
d8d8bc |
break;
|
|
|
d8d8bc |
case '5':
|
|
|
d8d8bc |
res = "SHA-256";
|
|
|
d8d8bc |
- if (sz)
|
|
|
d8d8bc |
- *sz = 43;
|
|
|
d8d8bc |
break;
|
|
|
d8d8bc |
case '6':
|
|
|
d8d8bc |
res = "SHA-512";
|
|
|
d8d8bc |
- if (sz)
|
|
|
d8d8bc |
- *sz = 86;
|
|
|
d8d8bc |
+ break;
|
|
|
d8d8bc |
+ case '7':
|
|
|
d8d8bc |
+ res = "scrypt";
|
|
|
d8d8bc |
+ break;
|
|
|
d8d8bc |
+ case 'y':
|
|
|
d8d8bc |
+ res = "yescrypt";
|
|
|
d8d8bc |
+ break;
|
|
|
d8d8bc |
+ case 'g':
|
|
|
d8d8bc |
+ if (*(p + 1) == 'y') {
|
|
|
d8d8bc |
+ p++;
|
|
|
d8d8bc |
+ res = "gost-yescrypt";
|
|
|
d8d8bc |
+ }
|
|
|
d8d8bc |
+ break;
|
|
|
d8d8bc |
+ case '_':
|
|
|
d8d8bc |
+ res = "bsdicrypt";
|
|
|
d8d8bc |
break;
|
|
|
d8d8bc |
default:
|
|
|
d8d8bc |
- return NULL;
|
|
|
d8d8bc |
+ res = "unknown";
|
|
|
d8d8bc |
+ break;
|
|
|
d8d8bc |
}
|
|
|
d8d8bc |
p++;
|
|
|
d8d8bc |
|
|
|
d8d8bc |
@@ -642,7 +660,10 @@ static const char *get_pwd_method(const char *str, const char **next, unsigned i
|
|
|
d8d8bc |
return res;
|
|
|
d8d8bc |
}
|
|
|
d8d8bc |
|
|
|
d8d8bc |
-#define is_valid_pwd_char(x) (isalnum((unsigned char) (x)) || (x) == '.' || (x) == '/')
|
|
|
d8d8bc |
+#define is_invalid_pwd_char(x) (isspace((unsigned char) (x)) || \
|
|
|
d8d8bc |
+ (x) == ':' || (x) == ';' || (x) == '*' || \
|
|
|
d8d8bc |
+ (x) == '!' || (x) == '\\')
|
|
|
d8d8bc |
+#define is_valid_pwd_char(x) (isascii((unsigned char) (x)) && !is_invalid_pwd_char(x))
|
|
|
d8d8bc |
|
|
|
d8d8bc |
/*
|
|
|
d8d8bc |
* This function do not accept empty passwords or locked accouns.
|
|
|
d8d8bc |
@@ -650,17 +671,16 @@ static const char *get_pwd_method(const char *str, const char **next, unsigned i
|
|
|
d8d8bc |
static int valid_pwd(const char *str)
|
|
|
d8d8bc |
{
|
|
|
d8d8bc |
const char *p = str;
|
|
|
d8d8bc |
- unsigned int sz = 0, n;
|
|
|
d8d8bc |
|
|
|
d8d8bc |
if (!str || !*str)
|
|
|
d8d8bc |
return 0;
|
|
|
d8d8bc |
|
|
|
d8d8bc |
/* $id$ */
|
|
|
d8d8bc |
- if (get_pwd_method(str, &p, &sz) == NULL)
|
|
|
d8d8bc |
+ if (get_pwd_method(str, &p) == NULL)
|
|
|
d8d8bc |
return 0;
|
|
|
d8d8bc |
+
|
|
|
d8d8bc |
if (!p || !*p)
|
|
|
d8d8bc |
return 0;
|
|
|
d8d8bc |
-
|
|
|
d8d8bc |
/* salt$ */
|
|
|
d8d8bc |
for (; *p; p++) {
|
|
|
d8d8bc |
if (*p == '$') {
|
|
|
d8d8bc |
@@ -670,17 +690,15 @@ static int valid_pwd(const char *str)
|
|
|
d8d8bc |
if (!is_valid_pwd_char(*p))
|
|
|
d8d8bc |
return 0;
|
|
|
d8d8bc |
}
|
|
|
d8d8bc |
+
|
|
|
d8d8bc |
if (!*p)
|
|
|
d8d8bc |
return 0;
|
|
|
d8d8bc |
-
|
|
|
d8d8bc |
/* encrypted */
|
|
|
d8d8bc |
- for (n = 0; *p; p++, n++) {
|
|
|
d8d8bc |
- if (!is_valid_pwd_char(*p))
|
|
|
d8d8bc |
+ for (; *p; p++) {
|
|
|
d8d8bc |
+ if (!is_valid_pwd_char(*p)) {
|
|
|
d8d8bc |
return 0;
|
|
|
d8d8bc |
+ }
|
|
|
d8d8bc |
}
|
|
|
d8d8bc |
-
|
|
|
d8d8bc |
- if (sz && n != sz)
|
|
|
d8d8bc |
- return 0;
|
|
|
d8d8bc |
return 1;
|
|
|
d8d8bc |
}
|
|
|
d8d8bc |
|
|
|
d8d8bc |
@@ -863,7 +881,7 @@ static struct lslogins_user *get_user_info(struct lslogins_control *ctl, const c
|
|
|
d8d8bc |
|
|
|
d8d8bc |
while (p && (*p == '!' || *p == '*'))
|
|
|
d8d8bc |
p++;
|
|
|
d8d8bc |
- user->pwd_method = get_pwd_method(p, NULL, NULL);
|
|
|
d8d8bc |
+ user->pwd_method = get_pwd_method(p, NULL);
|
|
|
d8d8bc |
} else
|
|
|
d8d8bc |
user->pwd_method = NULL;
|
|
|
d8d8bc |
break;
|
|
|
d8d8bc |
--
|
|
|
d8d8bc |
2.37.2
|
|
|
d8d8bc |
|