diff options
author | Werner Koch <wk@gnupg.org> | 2020-04-03 21:27:05 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2020-04-03 21:27:05 +0200 |
commit | d843d260f5502ba90a2a35dfe202439f32b0e9aa (patch) | |
tree | b5d04f75886c8c883aaef63746e03bbbed69ced0 /src/sysutils.c | |
parent | 85b5006d01fc64763a6e1f0d6cbda91c5cb709c1 (diff) | |
download | libgpg-error-d843d260f5502ba90a2a35dfe202439f32b0e9aa.tar.gz |
core: Implement meta command [user] for the arg parser.
* src/sysutils.c (_gpgrt_getusername): New.
* src/argparse.c (struct _gpgrt_argparse_internal_s): New flags user_*
and store the current user.
(initialize): Free new malloced field. Clear new flags.
(handle_meta_user): Implement.
(handle_metacmd): Implement user sections. Remove "group" meta
command.
(_gpgrt_argparse): Implement user sections.
(finish_read_sys): Reset new vars.
--
Implementing group would be somewhat complicated and it is doubtful
whether this really makes sense and is manageable for the admin.
Note that we have not yet implemented this for Windows.
Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'src/sysutils.c')
-rw-r--r-- | src/sysutils.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/sysutils.c b/src/sysutils.c index 6bdd76f..112c8b5 100644 --- a/src/sysutils.c +++ b/src/sysutils.c @@ -343,7 +343,7 @@ _gpgrt_getcwd (void) /* Get the standard home directory for user NAME. If NAME is NULL the - * directory for the current user is retruned. Caller must release + * directory for the current user is returned. Caller must release * the returned string. */ char * _gpgrt_getpwdir (const char *name) @@ -376,3 +376,23 @@ _gpgrt_getpwdir (const char *name) #endif /*HAVE_PWD_H*/ return result; } + + +/* Return a malloced copy of the current user's account name; this may + * return NULL on memory failure. */ +char * +_gpgrt_getusername (void) +{ + char *result = NULL; +#if defined(HAVE_PWD_H) && defined(HAVE_GETPWUID) + struct passwd *pwd; + + pwd = getpwuid (getuid()); + if (pwd) + { + result = _gpgrt_strdup (pwd->pw_name); + } + +#endif /*HAVE_PWD_H*/ + return result; +} |