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);
43 int main(int argc, char* argv[])
46 cerr << "Usage: ckm_tool [option] [opt_arg]" << endl;
47 cerr << "option: " << endl;
48 cerr << "\t-d\tdelete user database, opt_arg specified the user UID" << endl;
49 cerr << "Example: ckm_tool -l 5000" << endl;
53 // simple input arg parser
54 for (int i=1; i<argc-1; i++)
57 if(!strcmp(argv[i], "-d"))
59 if(parseLong(argv[i+1], uid) || uid<0) {
60 cerr << "parameter error: invalid UID provided to the -d option" << endl;
65 auto control = CKM::Control::create();
66 int ec = control->lockUserKey(static_cast<uid_t>(uid));
67 if(ec != CKM_API_SUCCESS) {
68 cerr << "Failed, lock DB error: " << ec << endl;
72 // remove the user content
73 ec = control->removeUserData(static_cast<uid_t>(uid));
74 if(ec != CKM_API_SUCCESS) {
75 cerr << "Failed, remove user data error: " << ec << endl;
80 std::cout << "Not enough or invalid arguments, please try again.\n";