diff options
author | David Zeuthen <davidz@redhat.com> | 2009-12-15 12:03:53 -0500 |
---|---|---|
committer | David Zeuthen <davidz@redhat.com> | 2009-12-15 12:03:53 -0500 |
commit | 2a91f171e23a90aa837bdafe9bb4b3a66fddbb39 (patch) | |
tree | e7071af8b47969fdbd609beb681a0145a13013a6 /src/programs | |
parent | 3b7dfe47a66db58cd1f895771545f4cb3d1ae8e2 (diff) | |
download | polkit-2a91f171e23a90aa837bdafe9bb4b3a66fddbb39.tar.gz |
Properly handle return value from getpwnam_r()
Pointed out by Kay Sievers - thanks!
Signed-off-by: David Zeuthen <davidz@redhat.com>
Diffstat (limited to 'src/programs')
-rw-r--r-- | src/programs/pkexec.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/programs/pkexec.c b/src/programs/pkexec.c index ba6ab36..ae0d842 100644 --- a/src/programs/pkexec.c +++ b/src/programs/pkexec.c @@ -214,6 +214,7 @@ main (int argc, char *argv[]) { guint n; guint ret; + gint rc; gboolean opt_show_help; gboolean opt_show_version; PolkitAuthority *authority; @@ -384,10 +385,18 @@ main (int argc, char *argv[]) goto out; } - /* Look up information about the user we care about */ - if (getpwnam_r (opt_user, &pwstruct, pwbuf, sizeof pwbuf, &pw) != 0) + /* Look up information about the user we care about - yes, the return + * value of this function is a bit funky + */ + rc = getpwnam_r (opt_user, &pwstruct, pwbuf, sizeof pwbuf, &pw); + if (rc == 0 && pw == NULL) + { + g_printerr ("User `%s' does not exist.\n", opt_user); + goto out; + } + else if (pw == NULL) { - g_printerr ("Error getting information for user %s: %s\n", opt_user, g_strerror (errno)); + g_printerr ("Error getting information for user `%s': %s\n", opt_user, g_strerror (rc)); goto out; } |