1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-02 22:46:30 +02:00

common: Fix the "ignore" meta command in argparse.c

* src/argparse.c (gnupg_argparse): Factor some code out to ...
(prepare_arg_return): new.
(gnupg_argparse): No missing arg error in ignore sections.
* common/sysutils.c: Include pwd.h.
(gnupg_getusername): New.
--

Options in an [ignore] section do not anymore lead to an error if an
argument is missing.  However, if the option is also in a force
section the error is thrown.

This is a port of the fix from libgpg-error.  Also fixes the
username fixme.
This commit is contained in:
Werner Koch 2020-12-21 17:23:52 +01:00
parent 8a2e5025eb
commit 09dc59f6d4
No known key found for this signature in database
GPG key ID: E3FDFF218E45B72B
3 changed files with 123 additions and 37 deletions

View file

@ -40,6 +40,9 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#ifdef HAVE_PWD_H
# include <pwd.h>
#endif
#include <unistd.h>
#include <errno.h>
#ifdef HAVE_STAT
@ -1741,3 +1744,49 @@ gnupg_fd_valid (int fd)
close (d);
return 1;
}
/* Return a malloced copy of the current user's account name; this may
* return NULL on memory failure. Note that this should eventually be
* replaced by a gpgrt function. */
char *
gnupg_getusername (void)
{
char *result = NULL;
#ifdef HAVE_W32_SYSTEM
wchar_t wtmp[1];
wchar_t *wbuf;
DWORD wsize = 1;
GetUserNameW (wtmp, &wsize);
wbuf = xtrymalloc (wsize * sizeof *wbuf);
if (!wbuf)
{
gpg_err_set_errno (ENOMEM);
return NULL;
}
if (!GetUserNameW (wbuf, &wsize))
{
gpg_err_set_errno (EINVAL);
xfree (wbuf);
return NULL;
}
result= wchar_to_utf8 (wbuf);
xfree (wbuf);
#else /* !HAVE_W32_SYSTEM */
# if defined(HAVE_PWD_H) && defined(HAVE_GETPWUID)
struct passwd *pwd;
pwd = getpwuid (getuid());
if (pwd)
result = xtrystrdup (pwd->pw_name);
# endif /*HAVE_PWD_H*/
#endif /* !HAVE_W32_SYSTEM */
return result;
}