1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 18 #ifndef _INIT_DESCRIPTORS_H 19 #define _INIT_DESCRIPTORS_H 20 21 #include <sys/types.h> 22 23 #include <string> 24 25 class DescriptorInfo { 26 public: 27 DescriptorInfo(const std::string& name, const std::string& type, uid_t uid, 28 gid_t gid, int perm, const std::string& context); 29 virtual ~DescriptorInfo(); 30 31 friend std::ostream& operator<<(std::ostream& os, const class DescriptorInfo& info); 32 bool operator==(const DescriptorInfo& other) const; 33 34 void CreateAndPublish(const std::string& globalContext) const; 35 virtual void Clean() const; 36 37 protected: name()38 const std::string& name() const { return name_; } type()39 const std::string& type() const { return type_; } uid()40 uid_t uid() const { return uid_; } gid()41 gid_t gid() const { return gid_; } perm()42 int perm() const { return perm_; } context()43 const std::string& context() const { return context_; } 44 45 private: 46 std::string name_; 47 std::string type_; 48 uid_t uid_; 49 gid_t gid_; 50 int perm_; 51 std::string context_; 52 53 virtual int Create(const std::string& globalContext) const = 0; 54 virtual const std::string key() const = 0; 55 }; 56 57 std::ostream& operator<<(std::ostream& os, const DescriptorInfo& info); 58 59 class SocketInfo : public DescriptorInfo { 60 public: 61 SocketInfo(const std::string& name, const std::string& type, uid_t uid, 62 gid_t gid, int perm, const std::string& context); 63 void Clean() const override; 64 private: 65 virtual int Create(const std::string& context) const override; 66 virtual const std::string key() const override; 67 }; 68 69 class FileInfo : public DescriptorInfo { 70 public: 71 FileInfo(const std::string& name, const std::string& type, uid_t uid, 72 gid_t gid, int perm, const std::string& context); 73 private: 74 virtual int Create(const std::string& context) const override; 75 virtual const std::string key() const override; 76 }; 77 78 #endif 79