Before running client in off-line mode, attempt to socket-activate the server
[platform/core/security/security-manager.git] / src / common / include / protocols.h
1 /*
2  *  Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Contact: Rafal Krypa <r.krypa@samsung.com>
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License
17  */
18 /*
19  * @file        protocols.h
20  * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
21  * @version     1.0
22  * @brief       This file contains list of all protocols suported by security-manager.
23  */
24
25 #ifndef _SECURITY_MANAGER_PROTOCOLS_
26 #define _SECURITY_MANAGER_PROTOCOLS_
27
28 #include <sys/types.h>
29 #include <vector>
30 #include <string>
31 #include <dpl/serialization.h>
32
33 /**
34  * \name Return Codes
35  * exported by the foundation API.
36  * result codes begin with the start error code and extend into negative direction.
37  * @{
38 */
39
40 /*! \brief   indicating the result of the one specific API is successful */
41 #define SECURITY_MANAGER_API_SUCCESS 0
42
43 /*! \brief   indicating the socket between client and Security Manager has been failed  */
44 #define SECURITY_MANAGER_API_ERROR_SOCKET -1
45
46 /*! \brief   indicating the request to Security Manager is malformed */
47 #define SECURITY_MANAGER_API_ERROR_BAD_REQUEST -2
48
49 /*! \brief   indicating the response from Security Manager is malformed */
50 #define SECURITY_MANAGER_API_ERROR_BAD_RESPONSE -3
51
52 /*! \brief   indicating the requested service does not exist */
53 #define SECURITY_MANAGER_API_ERROR_NO_SUCH_SERVICE -4
54
55 /*! \brief   indicating requesting object is not exist */
56 #define SECURITY_MANAGER_API_ERROR_NO_SUCH_OBJECT -6
57
58 /*! \brief   indicating the authentication between client and server has been failed */
59 #define SECURITY_MANAGER_API_ERROR_AUTHENTICATION_FAILED -7
60
61 /*! \brief   indicating the API's input parameter is malformed */
62 #define SECURITY_MANAGER_API_ERROR_INPUT_PARAM -8
63
64 /*! \brief   indicating the output buffer size which is passed as parameter is too small */
65 #define SECURITY_MANAGER_API_ERROR_BUFFER_TOO_SMALL -9
66
67 /*! \brief   indicating system  is running out of memory state */
68 #define SECURITY_MANAGER_API_ERROR_OUT_OF_MEMORY -10
69
70 /*! \brief   indicating the access has been denied by Security Manager */
71 #define SECURITY_MANAGER_API_ERROR_ACCESS_DENIED -11
72
73 /*! \brief   indicating Security Manager has been failed for some reason */
74 #define SECURITY_MANAGER_API_ERROR_SERVER_ERROR -12
75
76 /*! \brief   indicating getting smack label from socket failed  */
77 #define SECURITY_MANAGER_API_ERROR_GETTING_SOCKET_LABEL_FAILED -21
78
79 /*! \brief   indicating getting smack label from file failed  */
80 #define SECURITY_MANAGER_API_ERROR_GETTING_FILE_LABEL_FAILED -22
81
82 /*! \brief   indicating setting smack label for file failed  */
83 #define SECURITY_MANAGER_API_ERROR_SETTING_FILE_LABEL_FAILED -23
84
85 /*! \brief   indicating file already exists  */
86 #define SECURITY_MANAGER_API_ERROR_FILE_EXIST -24
87
88 /*! \brief   indicating file does not exist  */
89 #define SECURITY_MANAGER_API_ERROR_FILE_NOT_EXIST -25
90
91 /*! \brief   indicating file open error  */
92 #define SECURITY_MANAGER_API_ERROR_FILE_OPEN_FAILED -26
93
94 /*! \brief   indicating file creation error  */
95 #define SECURITY_MANAGER_API_ERROR_FILE_CREATION_FAILED -27
96
97 /*! \brief   indicating file deletion error  */
98 #define SECURITY_MANAGER_API_ERROR_FILE_DELETION_FAILED -28
99
100 /*! \brief   indicating the error with unknown reason */
101 #define SECURITY_MANAGER_API_ERROR_UNKNOWN -255
102 /** @}*/
103
104
105 struct app_inst_req {
106     std::string appId;
107     std::string pkgId;
108     std::vector<std::string> privileges;
109     std::vector<std::pair<std::string, int>> appPaths;
110     uid_t uid;
111 };
112
113 struct user_req {
114     uid_t uid;
115     int utype;
116 };
117
118 namespace SecurityManager {
119
120 extern char const * const SERVICE_SOCKET;
121
122 enum class SecurityModuleCall
123 {
124     APP_INSTALL,
125     APP_UNINSTALL,
126     APP_GET_PKGID,
127     APP_GET_GROUPS,
128     USER_ADD,
129     USER_DELETE,
130     POLICY_UPDATE,
131     GET_POLICY,
132     GET_CONF_POLICY_ADMIN,
133     GET_CONF_POLICY_SELF,
134     NOOP = 0x90,
135 };
136
137 } // namespace SecurityManager
138
139 using namespace SecurityManager;
140
141 struct policy_entry : ISerializable {
142     std::string user;           // uid converted to string
143     std::string appId;          // application identifier
144     std::string privilege;      // Cynara privilege
145     std::string currentLevel;   // current level of privielege, or level asked to be set in privacy manager bucket
146     std::string maxLevel;       // holds read maximum policy status or status to be set in admin bucket
147
148     policy_entry() : user(""), appId(""), privilege(""), currentLevel(""), maxLevel("")
149     {}
150
151     policy_entry(IStream &stream) {
152         Deserialization::Deserialize(stream, user);
153         Deserialization::Deserialize(stream, appId);
154         Deserialization::Deserialize(stream, privilege);
155         Deserialization::Deserialize(stream, currentLevel);
156         Deserialization::Deserialize(stream, maxLevel);
157     }
158
159     virtual void Serialize(IStream &stream) const {
160         Serialization::Serialize(stream, user);
161         Serialization::Serialize(stream, appId);
162         Serialization::Serialize(stream, privilege);
163         Serialization::Serialize(stream, currentLevel);
164         Serialization::Serialize(stream, maxLevel);
165     }
166
167 };
168 typedef struct policy_entry policy_entry;
169
170
171 struct policy_update_req {
172     std::vector<const policy_entry *> units;
173 };
174
175
176 #endif // _SECURITY_MANAGER_PROTOCOLS_