summaryrefslogtreecommitdiffstats
path: root/src/tests/cwrap/test_become_user.c
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2014-10-19 12:28:13 +0200
committerJakub Hrozek <jhrozek@redhat.com>2014-10-30 16:36:51 +0100
commit7b21c328e617a3dba6bbf7b1d1bab71e01ba4af9 (patch)
treee2df88229f9ba4ad097f1d7411b19ebeb9be126a /src/tests/cwrap/test_become_user.c
parentd969ba46904766480d65cf8c13e92210dc15227f (diff)
downloadsssd-7b21c328e617a3dba6bbf7b1d1bab71e01ba4af9.tar.gz
sssd-7b21c328e617a3dba6bbf7b1d1bab71e01ba4af9.tar.xz
sssd-7b21c328e617a3dba6bbf7b1d1bab71e01ba4af9.zip
KRB5: Do not switch_creds() if already the specified user
The code didn't have to handle this case previously as sssd_be was always running as root and switching to the ccache as the user logging in. Also handle NULL creds on restore_creds() in case there was no switch. One less if-condition and fewer indentation levels.
Diffstat (limited to 'src/tests/cwrap/test_become_user.c')
-rw-r--r--src/tests/cwrap/test_become_user.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/tests/cwrap/test_become_user.c b/src/tests/cwrap/test_become_user.c
index 06d3ad425..7ecea5aac 100644
--- a/src/tests/cwrap/test_become_user.c
+++ b/src/tests/cwrap/test_become_user.c
@@ -76,6 +76,7 @@ void test_switch_user(void **state)
struct passwd *sssd;
TALLOC_CTX *tmp_ctx;
struct sss_creds *saved_creds;
+ struct sss_creds *saved_creds2 = NULL;
check_leaks_push(global_talloc_context);
tmp_ctx = talloc_new(global_talloc_context);
@@ -102,6 +103,12 @@ void test_switch_user(void **state)
assert_int_equal(saved_creds->uid, 0);
assert_int_equal(saved_creds->gid, 0);
+ /* Attempt to restore creds again */
+ ret = switch_creds(tmp_ctx, sssd->pw_uid, sssd->pw_gid,
+ 0, NULL, &saved_creds2);
+ assert_int_equal(ret, EOK);
+ assert_null(saved_creds2);
+
/* restore root */
ret = restore_creds(saved_creds);
assert_int_equal(ret, EOK);