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