blob: a7fc5199985b0526de856fbe0e0556dbb6d62ecc [file] [log] [blame]
Yingdi Yu8d7468f2014-02-21 14:49:45 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07002/**
3 * Copyright (c) 2013-2014, Regents of the University of California.
4 * All rights reserved.
5 *
6 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
7 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
8 *
9 * This file licensed under New BSD License. See COPYING for detailed information about
10 * ndn-cxx library copyright, permissions, and redistribution restrictions.
11 *
12 * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
Yingdi Yu8d7468f2014-02-21 14:49:45 -080013 */
14
15#ifndef NDNSEC_SET_ACL_HPP
16#define NDNSEC_SET_ACL_HPP
17
18#include "ndnsec-util.hpp"
19
20int
21ndnsec_set_acl(int argc, char** argv)
22{
23 using namespace ndn;
24 namespace po = boost::program_options;
25
Yingdi Yub61f5402014-02-26 17:46:11 -080026 std::string keyName;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080027 std::string appPath;
28
Yingdi Yub61f5402014-02-26 17:46:11 -080029 po::options_description description("General Usage\n ndnsec set-acl [-h] keyName appPath \nGeneral options");
30 description.add_options()
Yingdi Yu8d7468f2014-02-21 14:49:45 -080031 ("help,h", "produce help message")
32 ("keyName,k", po::value<std::string>(&keyName), "Key name.")
33 ("appPath,p", po::value<std::string>(&appPath), "Application path.")
34 ;
35
36 po::positional_options_description p;
37 p.add("keyName", 1);
38 p.add("appPath", 1);
39
40 po::variables_map vm;
41 try
42 {
Yingdi Yub61f5402014-02-26 17:46:11 -080043 po::store(po::command_line_parser(argc, argv).options(description).positional(p).run(),
44 vm);
Yingdi Yu8d7468f2014-02-21 14:49:45 -080045 po::notify(vm);
46 }
Yingdi Yub61f5402014-02-26 17:46:11 -080047 catch (std::exception& e)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080048 {
49 std::cerr << "ERROR: " << e.what() << std::endl;
50 return 1;
51 }
52
Yingdi Yub61f5402014-02-26 17:46:11 -080053 if (vm.count("help") != 0)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080054 {
Yingdi Yub61f5402014-02-26 17:46:11 -080055 std::cerr << description << std::endl;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080056 return 0;
57 }
58
Yingdi Yub61f5402014-02-26 17:46:11 -080059 if (vm.count("keyName") == 0)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080060 {
Yingdi Yub61f5402014-02-26 17:46:11 -080061 std::cerr << "ERROR: keyName is required!" << std::endl;
62 std::cerr << description << std::endl;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080063 return 1;
64 }
65
Yingdi Yub61f5402014-02-26 17:46:11 -080066 if (vm.count("appPath") == 0)
67 {
68 std::cerr << "ERROR: appPath is required!" << std::endl;
69 std::cerr << description << std::endl;
70 return 1;
71 }
72
73 KeyChain keyChain;
74 keyChain.addAppToACL(keyName, KEY_CLASS_PRIVATE, appPath, ACL_TYPE_PRIVATE);
75
Yingdi Yu8d7468f2014-02-21 14:49:45 -080076 return 0;
77}
78
79#endif //NDNSEC_SET_ACL_HPP