2 * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Bumjin Im <bj.im@samsung.com>
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
18 * @file client-common.cpp
19 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
21 * @brief This file is implementation of client-common functions.
23 #include <client-common.h>
24 #include <message-buffer.h>
25 #include <protocols.h>
27 #include <ckm/ckm-control.h>
31 class Control::ControlImpl {
34 ControlImpl(const ControlImpl &) = delete;
35 ControlImpl(ControlImpl &&) = delete;
36 ControlImpl& operator=(const ControlImpl &) = delete;
37 ControlImpl& operator=(ControlImpl &&) = delete;
39 static int unlockUserKey(uid_t user, const std::string &password) {
40 return try_catch([&] {
41 MessageBuffer send, recv;
42 Serialization::Serialize(send, static_cast<int>(ControlCommand::UNLOCK_USER_KEY));
43 Serialization::Serialize(send, user);
44 Serialization::Serialize(send, password);
48 retCode = CKM_API_ERROR_INPUT_PARAM;
52 retCode = sendToServer(
53 SERVICE_SOCKET_CKM_CONTROL,
57 if (CKM_API_SUCCESS != retCode) {
61 Deserialization::Deserialize(recv, retCode);
67 static int lockUserKey(uid_t user) {
68 return try_catch([&] {
69 MessageBuffer send, recv;
70 Serialization::Serialize(send, static_cast<int>(ControlCommand::LOCK_USER_KEY));
71 Serialization::Serialize(send, user);
75 retCode = CKM_API_ERROR_INPUT_PARAM;
79 retCode = sendToServer(
80 SERVICE_SOCKET_CKM_CONTROL,
84 if (CKM_API_SUCCESS != retCode) {
88 Deserialization::Deserialize(recv, retCode);
94 static int removeUserData(uid_t user) {
95 return try_catch([&] {
96 MessageBuffer send, recv;
97 Serialization::Serialize(send, static_cast<int>(ControlCommand::REMOVE_USER_DATA));
98 Serialization::Serialize(send, user);
102 retCode = CKM_API_ERROR_INPUT_PARAM;
106 retCode = sendToServer(
107 SERVICE_SOCKET_CKM_CONTROL,
111 if (CKM_API_SUCCESS != retCode) {
115 Deserialization::Deserialize(recv, retCode);
121 static int changeUserPassword(uid_t user, const std::string &oldPassword, const std::string &newPassword) {
122 return try_catch([&] {
123 MessageBuffer send, recv;
124 Serialization::Serialize(send, static_cast<int>(ControlCommand::CHANGE_USER_PASSWORD));
125 Serialization::Serialize(send, user);
126 Serialization::Serialize(send, oldPassword);
127 Serialization::Serialize(send, newPassword);
131 retCode = CKM_API_ERROR_INPUT_PARAM;
135 retCode = sendToServer(
136 SERVICE_SOCKET_CKM_CONTROL,
140 if (CKM_API_SUCCESS != retCode) {
144 Deserialization::Deserialize(recv, retCode);
150 static int resetUserPassword(uid_t user, const std::string &newPassword) {
151 return try_catch([&] {
152 MessageBuffer send, recv;
153 Serialization::Serialize(send, static_cast<int>(ControlCommand::RESET_USER_PASSWORD));
154 Serialization::Serialize(send, user);
155 Serialization::Serialize(send, newPassword);
159 retCode = CKM_API_ERROR_INPUT_PARAM;
163 retCode = sendToServer(
164 SERVICE_SOCKET_CKM_CONTROL,
168 if (CKM_API_SUCCESS != retCode) {
172 Deserialization::Deserialize(recv, retCode);
178 virtual ~ControlImpl(){}
182 : m_impl(new ControlImpl)
185 Control::~Control(){}
187 int Control::unlockUserKey(uid_t user, const std::string &password) const {
188 return m_impl->unlockUserKey(user, password);
191 int Control::lockUserKey(uid_t user) const {
192 return m_impl->lockUserKey(user);
195 int Control::removeUserData(uid_t user) const {
196 return m_impl->removeUserData(user);
199 int Control::changeUserPassword(uid_t user, const std::string &oldPassword, const std::string &newPassword) const {
200 return m_impl->changeUserPassword(user, oldPassword, newPassword);
203 int Control::resetUserPassword(uid_t user, const std::string &newPassword) const {
204 return m_impl->resetUserPassword(user, newPassword);