• 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  * AUTHOR: Aniruddha Marathe <aniruddha.marathe@wipro.com>
5  */
6 
7 /*\
8  * [Description]
9  * This test case checks whether reboot(2) system call returns appropriate
10  * error number for invalid flag parameter or invalid user.
11  *
12  * [Algorithm]
13  * Execute system call with invaid flag parameter and then for invalid user
14  * check return value and errno.
15  *
16  * [Restrictions]
17  * For lib4 and lib5 reboot(2) system call is implemented as
18  * int reboot(int magic, int magic2, int flag, void *arg); This test case
19  * is written for int reboot(int flag); which is implemented under glibc
20  * Therefore this testcase may not work under libc4 and libc5 libraries
21  */
22 
23 #include <unistd.h>
24 #include <sys/reboot.h>
25 #include <linux/reboot.h>
26 #include <pwd.h>
27 #include "tst_test.h"
28 
29 #define INVALID_PARAMETER 100
30 
31 char nobody_uid[] = "nobody";
32 struct passwd *ltpuser;
33 
34 static struct tcase {
35 	int flag;
36 	int exp_errno;
37 	const char *option_message;
38 } tcases[] = {
39 	{INVALID_PARAMETER, EINVAL, "INVALID_PARAMETER"},
40 	{LINUX_REBOOT_CMD_CAD_ON, EPERM, "LINUX_REBOOT_CMD_CAD_ON"},
41 };
42 
run(unsigned int n)43 static void run(unsigned int n)
44 {
45 	struct tcase *tc = &tcases[n];
46 
47 	if (n == 0)
48 		TST_EXP_FAIL(reboot(tc->flag),
49 			tc->exp_errno, "%s", tc->option_message);
50 	else {
51 		ltpuser = SAFE_GETPWNAM(nobody_uid);
52 		SAFE_SETEUID(ltpuser->pw_uid);
53 
54 		TST_EXP_FAIL(reboot(tc->flag),
55 			tc->exp_errno, "%s", tc->option_message);
56 
57 		SAFE_SETEUID(0);
58 	}
59 }
60 
61 static struct tst_test test = {
62 	.needs_root = 1,
63 	.test = run,
64 	.tcnt = ARRAY_SIZE(tcases),
65 };
66