blob: 7851322bc40c61601dbfa9a3bb710864ea0682a5 [file] [log] [blame]
Yingdi Yu8d7468f2014-02-21 14:49:45 -08001/* -*- 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
13int
14ndnsec_set_acl(int argc, char** argv)
15{
16 using namespace ndn;
17 namespace po = boost::program_options;
18
Yingdi Yub61f5402014-02-26 17:46:11 -080019 std::string keyName;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080020 std::string appPath;
21
Yingdi Yub61f5402014-02-26 17:46:11 -080022 po::options_description description("General Usage\n ndnsec set-acl [-h] keyName appPath \nGeneral options");
23 description.add_options()
Yingdi Yu8d7468f2014-02-21 14:49:45 -080024 ("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 Yub61f5402014-02-26 17:46:11 -080036 po::store(po::command_line_parser(argc, argv).options(description).positional(p).run(),
37 vm);
Yingdi Yu8d7468f2014-02-21 14:49:45 -080038 po::notify(vm);
39 }
Yingdi Yub61f5402014-02-26 17:46:11 -080040 catch (std::exception& e)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080041 {
42 std::cerr << "ERROR: " << e.what() << std::endl;
43 return 1;
44 }
45
Yingdi Yub61f5402014-02-26 17:46:11 -080046 if (vm.count("help") != 0)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080047 {
Yingdi Yub61f5402014-02-26 17:46:11 -080048 std::cerr << description << std::endl;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080049 return 0;
50 }
51
Yingdi Yub61f5402014-02-26 17:46:11 -080052 if (vm.count("keyName") == 0)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080053 {
Yingdi Yub61f5402014-02-26 17:46:11 -080054 std::cerr << "ERROR: keyName is required!" << std::endl;
55 std::cerr << description << std::endl;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080056 return 1;
57 }
58
Yingdi Yub61f5402014-02-26 17:46:11 -080059 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 Yu8d7468f2014-02-21 14:49:45 -080069 return 0;
70}
71
72#endif //NDNSEC_SET_ACL_HPP