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