• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <stdio.h>
17 #include <sys/capability.h>
18 #include "test.h"
19 
20 /**
21  * @tc.name      : capget_0100
22  * @tc.desc      : Verify that this function can obtain process permissions
23  * @tc.level     : Level 0
24  */
capget_0100(void)25 void capget_0100(void)
26 {
27     struct __user_cap_header_struct cap_header_data;
28     cap_user_header_t cap_header = &cap_header_data;
29 
30     struct __user_cap_data_struct cap_data_data;
31     cap_user_data_t cap_data = &cap_data_data;
32 
33     cap_header->pid = getpid();
34     cap_header->version = _LINUX_CAPABILITY_VERSION_1;
35 
36     int result = capget(cap_header, cap_data);
37     if (result < 0) {
38         t_error("%s capget failed\n", __func__);
39     }
40 
41     printf("Cap data 0x%x, 0x%x, 0x%x \n", cap_data->effective, cap_data->permitted, cap_data->inheritable);
42 }
43 
44 /**
45  * @tc.name      : capget_0200
46  * @tc.desc      : Verify that this function could not obtain process permissions when parameter is invalid
47  * @tc.level     : Level 2
48  */
capget_0200(void)49 void capget_0200(void)
50 {
51     struct __user_cap_data_struct cap_data_data;
52     cap_user_data_t cap_data = &cap_data_data;
53 
54     int result = capget(NULL, cap_data);
55     if (result != -1) {
56         t_error("%s capget should be failed\n", __func__);
57     }
58 }
59 
main(int argc,char * argv[])60 int main(int argc, char *argv[])
61 {
62     capget_0100();
63     capget_0200();
64     return t_status;
65 }