Add smackfs check to Installer service.
[platform/core/security/security-manager.git] / src / server / client / client-get-gid.cpp
1 /*
2  *  Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Contact: Bumjin Im <bj.im@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        client-get-gid.cpp
20  * @author      Jan Olszak (j.olszak@samsung.com)
21  * @version     1.0
22  * @brief       This file constains implementation of get GID function.
23  */
24
25 #include <stdio.h>
26
27 #include <dpl/log/log.h>
28 #include <dpl/exception.h>
29
30 #include <message-buffer.h>
31 #include <client-common.h>
32 #include <protocols.h>
33
34 #include <security-server.h>
35
36 SECURITY_SERVER_API
37 int security_server_get_gid(const char *objectName) {
38     using namespace SecurityServer;
39
40     return try_catch([&] {
41         if (NULL == objectName){
42             LogDebug("Objects name is NULL");
43             return SECURITY_SERVER_API_ERROR_INPUT_PARAM;
44         }
45
46         int objectsNameLen = strlen(objectName);
47         if (0 == objectsNameLen || objectsNameLen > SECURITY_SERVER_MAX_OBJ_NAME){
48             LogDebug("Objects name is empty or too long");
49             return SECURITY_SERVER_API_ERROR_INPUT_PARAM;
50         }
51
52         MessageBuffer send, recv;
53         Serialization::Serialize(send, std::string(objectName));
54
55         int retCode = sendToServer(
56           SERVICE_SOCKET_GET_GID,
57           send.Pop(),
58           recv);
59
60         if (retCode != SECURITY_SERVER_API_SUCCESS)
61             return retCode;
62
63         Deserialization::Deserialize(recv, retCode);
64
65         // Return if errors
66         if (retCode < 0)
67             return retCode;
68
69         // No errors, return gid
70         gid_t gid;
71         Deserialization::Deserialize(recv, gid);
72         return static_cast<int>(gid);
73     });
74 }
75