Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2013, Regents of the University of California |
| 4 | * BSD license, See the LICENSE file for more information |
| 5 | * Author: Yingdi Yu <yingdi@cs.ucla.edu> |
| 6 | */ |
| 7 | |
| 8 | #ifndef NDNSEC_SET_ACL_HPP |
| 9 | #define NDNSEC_SET_ACL_HPP |
| 10 | |
| 11 | #include "ndnsec-util.hpp" |
| 12 | |
| 13 | int |
| 14 | ndnsec_set_acl(int argc, char** argv) |
| 15 | { |
| 16 | using namespace ndn; |
| 17 | namespace po = boost::program_options; |
| 18 | |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame^] | 19 | std::string keyName; |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 20 | std::string appPath; |
| 21 | |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame^] | 22 | po::options_description description("General Usage\n ndnsec set-acl [-h] keyName appPath \nGeneral options"); |
| 23 | description.add_options() |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 24 | ("help,h", "produce help message") |
| 25 | ("keyName,k", po::value<std::string>(&keyName), "Key name.") |
| 26 | ("appPath,p", po::value<std::string>(&appPath), "Application path.") |
| 27 | ; |
| 28 | |
| 29 | po::positional_options_description p; |
| 30 | p.add("keyName", 1); |
| 31 | p.add("appPath", 1); |
| 32 | |
| 33 | po::variables_map vm; |
| 34 | try |
| 35 | { |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame^] | 36 | po::store(po::command_line_parser(argc, argv).options(description).positional(p).run(), |
| 37 | vm); |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 38 | po::notify(vm); |
| 39 | } |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame^] | 40 | catch (std::exception& e) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 41 | { |
| 42 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 43 | return 1; |
| 44 | } |
| 45 | |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame^] | 46 | if (vm.count("help") != 0) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 47 | { |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame^] | 48 | std::cerr << description << std::endl; |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 49 | return 0; |
| 50 | } |
| 51 | |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame^] | 52 | if (vm.count("keyName") == 0) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 53 | { |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame^] | 54 | std::cerr << "ERROR: keyName is required!" << std::endl; |
| 55 | std::cerr << description << std::endl; |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 56 | return 1; |
| 57 | } |
| 58 | |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame^] | 59 | if (vm.count("appPath") == 0) |
| 60 | { |
| 61 | std::cerr << "ERROR: appPath is required!" << std::endl; |
| 62 | std::cerr << description << std::endl; |
| 63 | return 1; |
| 64 | } |
| 65 | |
| 66 | KeyChain keyChain; |
| 67 | keyChain.addAppToACL(keyName, KEY_CLASS_PRIVATE, appPath, ACL_TYPE_PRIVATE); |
| 68 | |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | #endif //NDNSEC_SET_ACL_HPP |