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 | |
| 19 | std::string keyName; |
| 20 | std::string appPath; |
| 21 | |
| 22 | po::options_description desc("General Usage\n ndnsec set-acl [-h] keyName appPath \nGeneral options"); |
| 23 | desc.add_options() |
| 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 | { |
| 36 | po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm); |
| 37 | po::notify(vm); |
| 38 | } |
| 39 | catch (std::exception &e) |
| 40 | { |
| 41 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 42 | return 1; |
| 43 | } |
| 44 | |
| 45 | if (vm.count("help")) |
| 46 | { |
| 47 | std::cerr << desc << std::endl; |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | try |
| 52 | { |
| 53 | KeyChain keyChain; |
| 54 | keyChain.addAppToACL(keyName, KEY_CLASS_PRIVATE, appPath, ACL_TYPE_PRIVATE); |
| 55 | |
| 56 | } |
| 57 | catch(const SecTpm::Error& e) |
| 58 | { |
| 59 | std::cerr << e.what() << std::endl; |
| 60 | return 1; |
| 61 | } |
| 62 | catch(const SecPublicInfo::Error& e) |
| 63 | { |
| 64 | std::cerr << e.what() << std::endl; |
| 65 | return 1; |
| 66 | } |
| 67 | |
| 68 | |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | #endif //NDNSEC_SET_ACL_HPP |