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 ControlImpl : public Control {
34 ControlImpl(const ControlImpl &) = delete;
35 ControlImpl(ControlImpl &&) = delete;
36 ControlImpl& operator=(const ControlImpl &) = delete;
37 ControlImpl& operator=(ControlImpl &&) = delete;
39 virtual int unlockUserKey(uid_t user, const Password &password) {
40 return try_catch([&] {
42 return CKM_API_ERROR_INPUT_PARAM;
45 MessageBuffer send, recv;
46 Serialization::Serialize(send, static_cast<int>(ControlCommand::UNLOCK_USER_KEY));
47 Serialization::Serialize(send, user);
48 Serialization::Serialize(send, password);
50 int retCode = sendToServer(
51 SERVICE_SOCKET_CKM_CONTROL,
55 if (CKM_API_SUCCESS != retCode) {
59 Deserialization::Deserialize(recv, retCode);
65 virtual int lockUserKey(uid_t user) {
66 return try_catch([&] {
68 return CKM_API_ERROR_INPUT_PARAM;
71 MessageBuffer send, recv;
72 Serialization::Serialize(send, static_cast<int>(ControlCommand::LOCK_USER_KEY));
73 Serialization::Serialize(send, user);
75 int retCode = sendToServer(
76 SERVICE_SOCKET_CKM_CONTROL,
80 if (CKM_API_SUCCESS != retCode) {
84 Deserialization::Deserialize(recv, retCode);
90 virtual int removeUserData(uid_t user) {
91 return try_catch([&] {
93 return CKM_API_ERROR_INPUT_PARAM;
96 MessageBuffer send, recv;
97 Serialization::Serialize(send, static_cast<int>(ControlCommand::REMOVE_USER_DATA));
98 Serialization::Serialize(send, user);
100 int retCode = sendToServer(
101 SERVICE_SOCKET_CKM_CONTROL,
105 if (CKM_API_SUCCESS != retCode) {
109 Deserialization::Deserialize(recv, retCode);
115 virtual int changeUserPassword(uid_t user, const Password &oldPassword, const Password &newPassword) {
116 return try_catch([&] {
118 return CKM_API_ERROR_INPUT_PARAM;
121 MessageBuffer send, recv;
122 Serialization::Serialize(send, static_cast<int>(ControlCommand::CHANGE_USER_PASSWORD));
123 Serialization::Serialize(send, user);
124 Serialization::Serialize(send, oldPassword);
125 Serialization::Serialize(send, newPassword);
127 int retCode = sendToServer(
128 SERVICE_SOCKET_CKM_CONTROL,
132 if (CKM_API_SUCCESS != retCode) {
136 Deserialization::Deserialize(recv, retCode);
142 virtual int resetUserPassword(uid_t user, const Password &newPassword) {
143 return try_catch([&] {
145 return CKM_API_ERROR_INPUT_PARAM;
148 MessageBuffer send, recv;
149 Serialization::Serialize(send, static_cast<int>(ControlCommand::RESET_USER_PASSWORD));
150 Serialization::Serialize(send, user);
151 Serialization::Serialize(send, newPassword);
153 int retCode = sendToServer(
154 SERVICE_SOCKET_CKM_CONTROL,
158 if (CKM_API_SUCCESS != retCode) {
162 retCode = sendToServer(
163 SERVICE_SOCKET_CKM_CONTROL,
167 if (CKM_API_SUCCESS != retCode) {
171 Deserialization::Deserialize(recv, retCode);
177 virtual ~ControlImpl(){}
180 ControlShPtr Control::create() {
181 return ControlShPtr(new ControlImpl());