• 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 #ifndef HAP_RESTORECON_H
17 #define HAP_RESTORECON_H
18 
19 #include <iosfwd>
20 #include <string>
21 #include <unordered_map>
22 #include <vector>
23 #include <selinux/context.h>
24 
25 #define SELINUX_HAP_RESTORECON_RECURSE 1
26 
27 // parameters of each SehapInfo in file sehap_contexts
28 struct SehapInfo {
29     std::string apl = "";
30     std::string name = "";
31     std::string domain = "";
32     std::string type = "";
33 };
34 
35 class HapContext {
36 public:
37     HapContext();
38     ~HapContext();
39     int HapFileRestorecon(std::vector<std::string> &pathNameOrig, const std::string &apl,
40                           const std::string &packageName, unsigned int flags);
41     int HapFileRestorecon(const std::string &pathNameOrig, const std::string &apl, const std::string &packageName,
42                           unsigned int flags);
43     int HapDomainSetcontext(const std::string &apl, const std::string &packageName);
44 
45 protected:
46 private:
47     int RestoreconSb(const std::string &pathname, const struct stat *sb, const std::string &apl,
48                      const std::string &packageName);
49     int HapContextsLookup(bool isDomain, const std::string &apl, const std::string &packageName, context_t con);
50     int HapLabelLookup(const std::string &apl, const std::string &packageName, char **secontextPtr);
51     int TypeSet(std::unordered_map<std::string, SehapInfo>::iterator &iter, bool isDomain, context_t con);
52 };
53 
54 #endif // HAP_RESTORECON_H
55