2 * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
18 * @author Maciej J. Karpiuk (m.karpiuk2@samsung.com)
27 #include <ckm/ckm-error.h>
28 #include <ckm/ckm-control.h>
32 bool parseLong(const char *buf_ptr, long int &val)
36 long int val_tmp = strtol(buf_ptr, &temp, 0);
45 int main(int argc, char *argv[])
48 cerr << "Usage: ckm_tool [option] [opt_arg]" << endl;
49 cerr << "option: " << endl;
50 cerr << "\t-d\tdelete user database, opt_arg specified the user UID" << endl;
51 cerr << "Example: ckm_tool -l 5000" << endl;
55 // simple input arg parser
56 for (int i = 1; i < argc - 1; i++) {
57 if (!strcmp(argv[i], "-d")) {
60 if (parseLong(argv[i + 1], uid) || uid < 0) {
61 cerr << "parameter error: invalid UID provided to the -d option" << endl;
66 auto control = CKM::Control::create();
67 int ec = control->lockUserKey(static_cast<uid_t>(uid));
69 if (ec != CKM_API_SUCCESS) {
70 cerr << "Failed, lock DB error: " << ec << endl;
74 // remove the user content
75 ec = control->removeUserData(static_cast<uid_t>(uid));
77 if (ec != CKM_API_SUCCESS) {
78 cerr << "Failed, remove user data error: " << ec << endl;
82 std::cout << "Not enough or invalid arguments, please try again.\n";