• 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 <sys/fsuid.h>
17 
18 #include "test.h"
19 
20 const gid_t fsuid = 1;
21 const gid_t invalid_fsuid = -1;
22 
23 /**
24  * @tc.name      : setfsuid_0100
25  * @tc.desc      : set user identity used for filesystem checks
26  * @tc.level     : Level 0
27  */
setfsuid_0100(void)28 void setfsuid_0100(void)
29 {
30     int result = setfsuid(fsuid);
31     if (result < 0) {
32         t_error("%s failed: result = %d\n", __func__, result);
33     }
34 
35     result = setfsuid(result);
36     if (result != fsuid) {
37         t_error("%s failed: result = %d\n", __func__, result);
38     }
39 }
40 
41 /**
42  * @tc.name      : setfsuid_0200
43  * @tc.desc      : set aninvalid user identity used for filesystem checks
44  * @tc.level     : Level 2
45  */
setfsuid_0200(void)46 void setfsuid_0200(void)
47 {
48     int result = setfsuid(invalid_fsuid);
49     if (result < 0) {
50         t_error("%s failed: result = %d\n", __func__, result);
51     }
52 
53     result = setfsuid(result);
54     if (result == fsuid) {
55         t_error("%s failed: result = %d\n", __func__, result);
56     }
57 }
58 
main(int argc,char * argv[])59 int main(int argc, char *argv[])
60 {
61     // setfsuid_0100();
62     // setfsuid_0200();
63 
64     return t_status;
65 }
66