1f08c3bdfSopenharmony_ci/* 2f08c3bdfSopenharmony_ci * Copyright (C) International Business Machines Corp., 2001 3f08c3bdfSopenharmony_ci * Ported by Wayne Boyer 4f08c3bdfSopenharmony_ci * Adapted by Dustin Kirkland (k1rkland@us.ibm.com) 5f08c3bdfSopenharmony_ci * Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com> 6f08c3bdfSopenharmony_ci */ 7f08c3bdfSopenharmony_ci 8f08c3bdfSopenharmony_ci/*\ 9f08c3bdfSopenharmony_ci * [Description] 10f08c3bdfSopenharmony_ci * 11f08c3bdfSopenharmony_ci * Verify that setfsuid() correctly updates the filesystem uid 12f08c3bdfSopenharmony_ci * when caller is a non-root user and provided fsuid matches 13f08c3bdfSopenharmony_ci * caller's real user ID. 14f08c3bdfSopenharmony_ci */ 15f08c3bdfSopenharmony_ci 16f08c3bdfSopenharmony_ci#include <pwd.h> 17f08c3bdfSopenharmony_ci 18f08c3bdfSopenharmony_ci#include "tst_test.h" 19f08c3bdfSopenharmony_ci#include "compat_tst_16.h" 20f08c3bdfSopenharmony_ci 21f08c3bdfSopenharmony_cistatic uid_t nobody_uid; 22f08c3bdfSopenharmony_ci 23f08c3bdfSopenharmony_cistatic void setup(void) 24f08c3bdfSopenharmony_ci{ 25f08c3bdfSopenharmony_ci struct passwd *nobody; 26f08c3bdfSopenharmony_ci 27f08c3bdfSopenharmony_ci nobody = SAFE_GETPWNAM("nobody"); 28f08c3bdfSopenharmony_ci nobody_uid = nobody->pw_uid; 29f08c3bdfSopenharmony_ci} 30f08c3bdfSopenharmony_ci 31f08c3bdfSopenharmony_cistatic void run(void) 32f08c3bdfSopenharmony_ci{ 33f08c3bdfSopenharmony_ci uid_t ruid, euid, suid; 34f08c3bdfSopenharmony_ci 35f08c3bdfSopenharmony_ci SAFE_GETRESUID(&ruid, &euid, &suid); 36f08c3bdfSopenharmony_ci SAFE_SETEUID(nobody_uid); 37f08c3bdfSopenharmony_ci UID16_CHECK(ruid, setfsuid); 38f08c3bdfSopenharmony_ci 39f08c3bdfSopenharmony_ci TST_EXP_VAL_SILENT(SETFSUID(ruid), nobody_uid); 40f08c3bdfSopenharmony_ci TST_EXP_VAL(SETFSUID(-1), ruid, "setfsuid(fsuid) by non-root user:"); 41f08c3bdfSopenharmony_ci} 42f08c3bdfSopenharmony_ci 43f08c3bdfSopenharmony_cistatic struct tst_test test = { 44f08c3bdfSopenharmony_ci .needs_root = 1, 45f08c3bdfSopenharmony_ci .setup = setup, 46f08c3bdfSopenharmony_ci .test_all = run 47f08c3bdfSopenharmony_ci}; 48