• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 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 #include "appspawn_adapter.h"
16 #include <stdio.h>
17 #include <sys/prctl.h>
18 #ifdef __LINUX__
19 #include <linux/securebits.h>
20 #endif
21 
KeepCapability()22 int KeepCapability()
23 {
24 #ifdef __LINUX__
25     if (prctl(PR_SET_SECUREBITS, SECBIT_NO_SETUID_FIXUP | SECBIT_NO_SETUID_FIXUP_LOCKED)) {
26         printf("prctl failed\n");
27         return -1;
28     }
29 #endif
30     return 0;
31 }
32 
SetAmbientCapability(int cap)33 int SetAmbientCapability(int cap)
34 {
35 #ifdef __LINUX__
36     if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, cap, 0, 0)) {
37         printf("[Init] prctl PR_CAP_AMBIENT failed\n");
38         return -1;
39     }
40 #endif
41     return 0;
42 }
43 
44