diff options
author | Mark Salyzyn <salyzyn@google.com> | 2016-10-27 07:45:34 -0700 |
---|---|---|
committer | Mark Salyzyn <salyzyn@google.com> | 2016-11-03 13:34:26 -0700 |
commit | 62767fe29f8aaf62470781a3cf419ba11187d178 (patch) | |
tree | 42ca647c67feecbda7a82c60ec58c5e5c69a20b3 /init/descriptors.h | |
parent | 0b034d9d7b1af4e2f608ddf2dc2a0e08773e69ac (diff) | |
download | core-62767fe29f8aaf62470781a3cf419ba11187d178.tar.gz core-62767fe29f8aaf62470781a3cf419ba11187d178.tar.bz2 core-62767fe29f8aaf62470781a3cf419ba11187d178.zip |
init: service file keyword
Solve one more issue where privilege is required to open a file and
we do not want to grant such to the service. This is the service side
of the picture, android_get_control_file() in libcutils is the client.
The file's descriptor is placed into the environment as
"ANDROID_FILE_<path>". For socket and files where non-alpha and
non-numeric characters in the <name/path> are replaced with _. There
was an accompanying change in android_get_control_socket() to match
in commit 'libcutils: add android_get_control_socket() test'
Add a gTest unit test for this that tests create_file and
android_get_control_file().
Test: gTest init_tests --gtest_filter=util.create_file
Bug: 32450474
Change-Id: I96eb970c707db6d51a9885873329ba1cb1f23140
Diffstat (limited to 'init/descriptors.h')
-rw-r--r-- | init/descriptors.h | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/init/descriptors.h b/init/descriptors.h new file mode 100644 index 000000000..ff276fbc0 --- /dev/null +++ b/init/descriptors.h @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef _INIT_DESCRIPTORS_H +#define _INIT_DESCRIPTORS_H + +#include <sys/types.h> + +#include <string> + +class DescriptorInfo { + public: + DescriptorInfo(const std::string& name, const std::string& type, uid_t uid, + gid_t gid, int perm, const std::string& context); + virtual ~DescriptorInfo(); + + friend std::ostream& operator<<(std::ostream& os, const class DescriptorInfo& info); + bool operator==(const DescriptorInfo& other) const; + + void CreateAndPublish(const std::string& globalContext) const; + virtual void Clean() const; + + protected: + const std::string& name() const { return name_; } + const std::string& type() const { return type_; } + uid_t uid() const { return uid_; } + gid_t gid() const { return gid_; } + int perm() const { return perm_; } + const std::string& context() const { return context_; } + + private: + std::string name_; + std::string type_; + uid_t uid_; + gid_t gid_; + int perm_; + std::string context_; + + virtual int Create(const std::string& globalContext) const = 0; + virtual const std::string key() const = 0; +}; + +std::ostream& operator<<(std::ostream& os, const DescriptorInfo& info); + +class SocketInfo : public DescriptorInfo { + public: + SocketInfo(const std::string& name, const std::string& type, uid_t uid, + gid_t gid, int perm, const std::string& context); + void Clean() const override; + private: + virtual int Create(const std::string& context) const override; + virtual const std::string key() const override; +}; + +class FileInfo : public DescriptorInfo { + public: + FileInfo(const std::string& name, const std::string& type, uid_t uid, + gid_t gid, int perm, const std::string& context); + private: + virtual int Create(const std::string& context) const override; + virtual const std::string key() const override; +}; + +#endif |