1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <unistd.h>
17
18 #include "test.h"
19
20 /**
21 * @tc.name : setegid_0100
22 * @tc.desc : set effective group ID
23 * @tc.level : Level 0
24 */
setegid_0100(void)25 void setegid_0100(void)
26 {
27 gid_t cegid = getegid();
28
29 gid_t segid = 1;
30 int result = setegid(segid);
31 if (result != 0) {
32 t_error("%s failed: result = %d\n", __func__, result);
33 }
34
35 gid_t egid = getegid();
36 if (egid != segid) {
37 t_error("%s failed: egid = %d\n", __func__, egid);
38 }
39
40 result = setegid(cegid);
41 if (result != 0) {
42 t_error("%s failed: result = %d\n", __func__, result);
43 }
44 }
45
46 /**
47 * @tc.name : setegid_0200
48 * @tc.desc : set effective group ID with the current effective group ID
49 * @tc.level : Level 1
50 */
setegid_0200(void)51 void setegid_0200(void)
52 {
53 gid_t cegid = getegid();
54
55 gid_t segid = cegid;
56 int result = setegid(segid);
57 if (result != 0) {
58 t_error("%s failed: result = %d\n", __func__, result);
59 }
60
61 gid_t egid = getegid();
62 if (egid != segid) {
63 t_error("%s failed: egid = %d\n", __func__, egid);
64 }
65 }
66
main(int argc,char * argv[])67 int main(int argc, char *argv[])
68 {
69 setegid_0100();
70 setegid_0200();
71
72 return t_status;
73 }
74