131 lines
3.3 KiB
Diff
131 lines
3.3 KiB
Diff
From aa752cb9d30072912dd3b5d51a86ab2fe6f08970 Mon Sep 17 00:00:00 2001
|
|
From: Changqing Li <changqing.li@windriver.com>
|
|
Date: Mon, 11 Jan 2021 15:40:21 +0800
|
|
Subject: [PATCH] pam_faillock: add option to accept uid as argument
|
|
|
|
Add options '--uid' for command pam_faillock to accept uid as argument.
|
|
|
|
Upstream-Status: Submitted [https://github.com/linux-pam/linux-pam/pull/595]
|
|
|
|
Signed-off-by: Changqing Li <changqing.li@windriver.com>
|
|
---
|
|
modules/pam_faillock/main.c | 62 ++++++++++++++++++++++++++++++++++---
|
|
1 file changed, 58 insertions(+), 4 deletions(-)
|
|
|
|
diff --git a/modules/pam_faillock/main.c b/modules/pam_faillock/main.c
|
|
index c6dd19c..ff0e647 100644
|
|
--- a/modules/pam_faillock/main.c
|
|
+++ b/modules/pam_faillock/main.c
|
|
@@ -56,10 +56,29 @@
|
|
#include "faillock.h"
|
|
#include "faillock_config.h"
|
|
|
|
+static int get_uid (const char *uidstr, uid_t *uid)
|
|
+{
|
|
+ long long int val;
|
|
+ char *endptr;
|
|
+
|
|
+ errno = 0;
|
|
+ val = strtoll (uidstr, &endptr, 10);
|
|
+ if ( ('\0' == *uidstr)
|
|
+ || ('\0' != *endptr)
|
|
+ || (ERANGE == errno)
|
|
+ || (val != (uid_t)val)) {
|
|
+ return 0;
|
|
+ }
|
|
+
|
|
+ *uid = (uid_t)val;
|
|
+ return 1;
|
|
+}
|
|
+
|
|
static int
|
|
args_parse(int argc, char **argv, struct options *opts)
|
|
{
|
|
int i;
|
|
+ int cline_user = 0;
|
|
int rv;
|
|
const char *dir = NULL;
|
|
const char *conf = NULL;
|
|
@@ -67,6 +86,7 @@ args_parse(int argc, char **argv, struct options *opts)
|
|
memset(opts, 0, sizeof(*opts));
|
|
|
|
opts->progname = argv[0];
|
|
+ opts->uid = (uid_t)-1;
|
|
|
|
for (i = 1; i < argc; ++i) {
|
|
if (strcmp(argv[i], "--conf") == 0) {
|
|
@@ -94,6 +114,24 @@ args_parse(int argc, char **argv, struct options *opts)
|
|
return -1;
|
|
}
|
|
opts->user = argv[i];
|
|
+ cline_user++;
|
|
+ }
|
|
+ else if (strcmp(argv[i], "--uid") == 0) {
|
|
+ ++i;
|
|
+ if(i >= argc || strlen(argv[i]) == 0) {
|
|
+ fprintf(stderr, "%s: No user id supplied.\n", argv[0]);
|
|
+ return -1;
|
|
+ }
|
|
+ uid_t user_id = (uid_t)-1;
|
|
+ if ( (get_uid (argv[i], &user_id) ==0)
|
|
+ || (user_id == (uid_t)-1)) {
|
|
+ fprintf (stderr,
|
|
+ _("%s: invalid user ID '%s'\n"),
|
|
+ argv[0], argv[i]);
|
|
+ return -1;
|
|
+ }
|
|
+ opts->uid = user_id;
|
|
+ cline_user++;
|
|
}
|
|
else if (strcmp(argv[i], "--reset") == 0) {
|
|
opts->reset = 1;
|
|
@@ -121,6 +159,10 @@ args_parse(int argc, char **argv, struct options *opts)
|
|
}
|
|
}
|
|
|
|
+ if (cline_user > 1) {
|
|
+ fprintf(stderr, "--user and --uid are mutually exclusive options!\n");
|
|
+ return -1;
|
|
+ }
|
|
return 0;
|
|
}
|
|
|
|
@@ -129,8 +171,8 @@ usage(const char *progname)
|
|
{
|
|
fprintf(stderr,
|
|
_("Usage: %s [--dir /path/to/tally-directory]"
|
|
- " [--user username] [--reset] [--legacy-output]\n"), progname);
|
|
-
|
|
+ " [--user username] [--uid userid] [--reset] [--legacy-output]\n"), progname);
|
|
+ fprintf(stderr, "NOTE: --user and --uid are mutually exclusive options, userid must be non-negative.\n");
|
|
}
|
|
|
|
static int
|
|
@@ -323,9 +365,21 @@ main (int argc, char *argv[])
|
|
return 1;
|
|
}
|
|
|
|
- if (opts.user == NULL) {
|
|
+ if (opts.user == NULL && opts.uid == (uid_t)-1) {
|
|
return do_allusers(&opts);
|
|
}
|
|
|
|
- return do_user(&opts, opts.user);
|
|
+ if (opts.user != NULL) {
|
|
+ return do_user(&opts, opts.user);
|
|
+ }
|
|
+ else {
|
|
+ errno = 0;
|
|
+ struct passwd *pwd = getpwuid(opts.uid);
|
|
+ if (pwd) {
|
|
+ return do_user(&opts, pwd->pw_name);
|
|
+ }
|
|
+ else {
|
|
+ fprintf(stderr, "%s: No matching passwd found, errno: %d\n", opts.progname, errno);
|
|
+ }
|
|
+ }
|
|
}
|
|
--
|
|
2.25.1
|
|
|