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 namespace android { 26 namespace init { 27 28 class DescriptorInfo { 29 public: 30 DescriptorInfo(const std::string& name, const std::string& type, uid_t uid, 31 gid_t gid, int perm, const std::string& context); 32 virtual ~DescriptorInfo(); 33 34 friend std::ostream& operator<<(std::ostream& os, const class DescriptorInfo& info); 35 bool operator==(const DescriptorInfo& other) const; 36 37 void CreateAndPublish(const std::string& globalContext) const; 38 virtual void Clean() const; 39 40 protected: name()41 const std::string& name() const { return name_; } type()42 const std::string& type() const { return type_; } uid()43 uid_t uid() const { return uid_; } gid()44 gid_t gid() const { return gid_; } perm()45 int perm() const { return perm_; } context()46 const std::string& context() const { return context_; } 47 48 private: 49 std::string name_; 50 std::string type_; 51 uid_t uid_; 52 gid_t gid_; 53 int perm_; 54 std::string context_; 55 56 virtual int Create(const std::string& globalContext) const = 0; 57 virtual const std::string key() const = 0; 58 }; 59 60 std::ostream& operator<<(std::ostream& os, const DescriptorInfo& info); 61 62 class SocketInfo : public DescriptorInfo { 63 public: 64 SocketInfo(const std::string& name, const std::string& type, uid_t uid, 65 gid_t gid, int perm, const std::string& context); 66 void Clean() const override; 67 private: 68 virtual int Create(const std::string& context) const override; 69 virtual const std::string key() const override; 70 }; 71 72 class FileInfo : public DescriptorInfo { 73 public: 74 FileInfo(const std::string& name, const std::string& type, uid_t uid, 75 gid_t gid, int perm, const std::string& context); 76 private: 77 virtual int Create(const std::string& context) const override; 78 virtual const std::string key() const override; 79 }; 80 81 } // namespace init 82 } // namespace android 83 84 #endif 85