blob: a1b9d2a6ecc6abe222cbc8bac284ab3be75ecfb6 [file] [log] [blame]
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventobde084f2022-04-17 00:21:35 -04002/*
3 * Copyright (c) 2014-2022, Regents of the University of California
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -04004 *
5 * NAC library is free software: you can redistribute it and/or modify it under the
6 * terms of the GNU Lesser General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option) any later version.
8 *
9 * NAC library is distributed in the hope that it will be useful, but WITHOUT ANY
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
12 *
13 * You should have received copies of the GNU General Public License and GNU Lesser
14 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
15 * <http://www.gnu.org/licenses/>.
16 *
17 * See AUTHORS.md for complete list of NAC library authors and contributors.
18 */
19
20#include "ndn-nac.hpp"
21#include "access-manager.hpp"
22
Davide Pesaventobde084f2022-04-17 00:21:35 -040023namespace ndn::nac {
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040024
25int
26nac_dump_kek(int argc, char** argv)
27{
28 namespace po = boost::program_options;
29
30 Name identityName;
31 Name datasetName;
32 std::string output;
33
34 po::options_description description("General Usage\n"
35 " ndn-nac dump-kek [-h] [-o output] [-d dataset] [-i] identity \n"
36 "General options");
37 description.add_options()
38 ("help,h", "Produce help message")
39 ("output,o", po::value<std::string>(&output), "(Optional) output file, stdout if not specified")
40 ("identity,i", po::value<Name>(&identityName), "Data owner's namespace identity")
41 ("dataset,d", po::value<Name>(&datasetName), "Name of dataset to control")
42 ;
43
44 po::positional_options_description p;
45 p.add("identity", 1);
46
47 po::variables_map vm;
48 try {
49 po::store(po::command_line_parser(argc, argv).options(description).positional(p).run(), vm);
50 po::notify(vm);
51 }
52 catch (const std::exception& e) {
53 std::cerr << "ERROR: " << e.what() << std::endl;
54 std::cerr << description << std::endl;
55 return 1;
56 }
57
58 if (vm.count("help") != 0) {
59 std::cerr << description << std::endl;
60 return 0;
61 }
62
63 if (vm.count("identity") == 0) {
64 std::cerr << "ERROR: identity must be specified" << std::endl;
65 std::cerr << description << std::endl;
66 return 1;
67 }
68
69 if (vm.count("output") == 0)
70 output = "-";
71
72 try {
Alexander Afanasyev5181d892020-06-06 18:05:47 -040073 KeyChain keyChain;
74 Identity id = keyChain.getPib().getIdentity(identityName);
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040075
76 util::DummyClientFace face(keyChain); // to avoid any real IO
77 AccessManager manager(id, datasetName, keyChain, face);
78
79 if (manager.size() != 1) {
80 std::cerr << "ERROR: Incorrect state of AccessManager instance (expect 1 KDK)" << std::endl;
81 return 2;
82 }
83
84 if (output == "-")
85 io::save(*manager.begin(), std::cout);
86 else
87 io::save(*manager.begin(), output);
88
89 return 0;
90 }
91 catch (const std::runtime_error& e) {
92 std::cerr << "ERROR: " << e.what() << std::endl;
93 return 1;
94 }
95}
96
Davide Pesaventobde084f2022-04-17 00:21:35 -040097} // namespace ndn::nac