1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. 4f08c3bdfSopenharmony_ci * Copyright (c) 2019 Petr Vorel <petr.vorel@gmail.com> 5f08c3bdfSopenharmony_ci * Author: Saji Kumar.V.R <saji.kumar@wipro.com> 6f08c3bdfSopenharmony_ci */ 7f08c3bdfSopenharmony_ci 8f08c3bdfSopenharmony_ci#include <errno.h> 9f08c3bdfSopenharmony_ci#include <pwd.h> 10f08c3bdfSopenharmony_ci 11f08c3bdfSopenharmony_ci#include "setdomainname.h" 12f08c3bdfSopenharmony_ci 13f08c3bdfSopenharmony_cistruct passwd *ltpuser; 14f08c3bdfSopenharmony_ci 15f08c3bdfSopenharmony_cistatic void do_test(void) 16f08c3bdfSopenharmony_ci{ 17f08c3bdfSopenharmony_ci char *new = TST_VALID_DOMAIN_NAME; 18f08c3bdfSopenharmony_ci 19f08c3bdfSopenharmony_ci TEST(do_setdomainname(new, strlen(new))); 20f08c3bdfSopenharmony_ci 21f08c3bdfSopenharmony_ci if (TST_RET != -1) { 22f08c3bdfSopenharmony_ci tst_res(TFAIL, "unexpected exit code: %ld", TST_RET); 23f08c3bdfSopenharmony_ci return; 24f08c3bdfSopenharmony_ci } 25f08c3bdfSopenharmony_ci 26f08c3bdfSopenharmony_ci if (TST_ERR != EPERM) { 27f08c3bdfSopenharmony_ci tst_res(TFAIL | TTERRNO, "unexpected errno: %d, expected: EPERM", 28f08c3bdfSopenharmony_ci TST_ERR); 29f08c3bdfSopenharmony_ci return; 30f08c3bdfSopenharmony_ci } 31f08c3bdfSopenharmony_ci 32f08c3bdfSopenharmony_ci tst_res(TPASS | TTERRNO, "expected failure"); 33f08c3bdfSopenharmony_ci} 34f08c3bdfSopenharmony_ci 35f08c3bdfSopenharmony_civoid setup_setuid(void) 36f08c3bdfSopenharmony_ci{ 37f08c3bdfSopenharmony_ci ltpuser = SAFE_GETPWNAM("nobody"); 38f08c3bdfSopenharmony_ci SAFE_SETEUID(ltpuser->pw_uid); 39f08c3bdfSopenharmony_ci setup(); 40f08c3bdfSopenharmony_ci} 41f08c3bdfSopenharmony_ci 42f08c3bdfSopenharmony_cistatic void cleanup_setuid(void) 43f08c3bdfSopenharmony_ci{ 44f08c3bdfSopenharmony_ci SAFE_SETEUID(0); 45f08c3bdfSopenharmony_ci cleanup(); 46f08c3bdfSopenharmony_ci} 47f08c3bdfSopenharmony_ci 48f08c3bdfSopenharmony_cistatic struct tst_test test = { 49f08c3bdfSopenharmony_ci .needs_root = 1, 50f08c3bdfSopenharmony_ci .setup = setup_setuid, 51f08c3bdfSopenharmony_ci .cleanup = cleanup_setuid, 52f08c3bdfSopenharmony_ci .test_all = do_test, 53f08c3bdfSopenharmony_ci .test_variants = TEST_VARIANTS, 54f08c3bdfSopenharmony_ci}; 55