bef4124af79339ba0d822ee3f13dfd567c325efd
[platform/core/security/security-manager.git] / src / server / client / client-get-object-name.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-object-name.cpp
20  * @author      Jan Olszak (j.olszak@samsung.com)
21  * @version     1.0
22  * @brief       This file constains implementation of get NAME 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_object_name(gid_t gid, char *pObjectName, size_t maxObjectSize)
38  {
39     using namespace SecurityServer;
40     return try_catch([&] {
41         if (pObjectName == NULL){
42             LogDebug("Objects name is NULL or empty");
43             return SECURITY_SERVER_API_ERROR_INPUT_PARAM;
44         }
45
46         MessageBuffer send, recv;
47         Serialization::Serialize(send, gid);
48
49         int result = sendToServer(
50           SERVICE_SOCKET_GET_OBJECT_NAME,
51           send.Pop(),
52           recv);
53
54
55         if (result != SECURITY_SERVER_API_SUCCESS)
56             return result;
57
58         Deserialization::Deserialize(recv, result);
59
60         std::string retObjectName;
61         Deserialization::Deserialize(recv, retObjectName);
62
63         if(retObjectName.size() > maxObjectSize){
64             LogError("Objects name is too big. Need more space in pObjectName buffer.");
65             return SECURITY_SERVER_API_ERROR_BUFFER_TOO_SMALL;
66         }
67
68         strcpy(pObjectName,retObjectName.c_str());
69
70         return result;
71
72     });
73 }
74