("install,i", "install an application")
("uninstall,r", "uninstall an application")
("manage-users,m", po::value<std::string>(), "add or remove user, parameter is 'a' or 'add' (for add) and 'r' or 'remove' (for remove)")
+ ("paths,q", "register package paths")
;
return opts;
}
return opts;
}
+static po::options_description getPathsOptions()
+{
+ po::options_description opts("Paths options");
+ opts.add_options()
+ ("pkg,g", po::value<std::string>()->required(),
+ "package name for the application (required)")
+ /*
+ * multitoken: Specifies that the value can span multiple tokens.
+ * So it is possible to pass values to an option like
+ * this:
+ * --path=/home/user dirtype
+ * --path /home/user dirtype
+ * --path="/home/user" dirtype
+ */
+ ("path,p", po::value< std::vector<std::string> >()->multitoken(),
+ "path for setting smack labels and, in case of rw_sensitive, registering as a sensitive directory\n"
+ "(may occur more than once).\n"
+ "Format: --path <path> <path type>\n"
+ " where <path type> is: \trw, ro, public_ro, rw_others_ro, trusted_rw, rw_sensitive\n"
+ " ('trusted_rw' requires author id)\n"
+ "example:\n"
+ " \t--path=/home/user/app rw")
+ ("uid,u", po::value<uid_t>()->required(),
+ "user identifier number (required)")
+ ("install-type", po::value<std::string>(),
+ "type of installation (local, global, preloaded)")
+ ;
+ return opts;
+}
+
static po::options_description getAllOptions()
{
po::options_description opts("Allowed options");
opts.add(getInstallOptions());
opts.add(getUninstallOptions());
opts.add(getUserOptions());
+ opts.add(getPathsOptions());
return opts;
}
po::notify(vm);
}
-static bool loadPaths(const std::vector<std::string> &paths,
- struct app_inst_req &req)
+template <typename Req>
+static bool loadPaths(const std::vector<std::string> &paths, Req &req)
{
if (paths.size() & 1) {
std::cout << "Wrong number of tokens was given for path option." <<
}
}
+static void parsePathsOptions(int argc, char *argv[],
+ struct path_req &req,
+ po::variables_map &vm)
+{
+ parseCommandOptions(argc, argv, getPathsOptions(), vm);
+
+ if (vm.count("pkg"))
+ req.pkgName = vm["pkg"].as<std::string>();
+ if (vm.count("path")) {
+ const std::vector<std::string> paths =
+ vm["path"].as<std::vector<std::string> >();
+ if (!loadPaths(paths, req)) {
+ po::error e("Error in parsing path arguments.");
+ throw e;
+ }
+ }
+ if (vm.count("uid"))
+ req.uid = vm["uid"].as<uid_t>();
+ if (vm.count("install-type"))
+ req.installationType = install_type_map.at(vm["install-type"].as<std::string>());
+}
+
static int installApp(const struct app_inst_req &req)
{
int ret = EXIT_FAILURE;
return ret;
}
+static int registerPaths(const struct path_req &req)
+{
+ int ret = EXIT_FAILURE;
+
+ ret = security_manager_paths_register(&req);
+ if (SECURITY_MANAGER_SUCCESS == ret) {
+ std::cout << "Paths registration for package " << req.pkgName <<
+ " succeeded." << std::endl;
+ LogDebug("Paths registration for package " << req.pkgName << " succeeded.");
+ } else {
+ std::cout << "Failed to register paths for " << req.pkgName << ". " <<
+ security_manager_strerror(static_cast<lib_retcode>(ret)) <<
+ " (" << ret << ")." << std::endl;
+ LogError("Failed to register paths for package " << req.pkgName << ". " <<
+ security_manager_strerror(static_cast<lib_retcode>(ret)) <<
+ " (" << ret << ")." << std::endl);
+ }
+ return ret;
+}
+
int main(int argc, char *argv[])
{
po::variables_map vm;
return EXIT_FAILURE;
parseUserOptions(argc, argv, *req, vm);
return manageUserOperation(*req, operation);
+ } else if (vm.count("paths")) {
+ struct path_req *req = nullptr;
+ LogDebug("Path registration command.");
+ if (security_manager_path_req_new(&req) != SECURITY_MANAGER_SUCCESS)
+ return EXIT_FAILURE;
+ std::unique_ptr<path_req, void(*)(path_req*)> req_ptr(
+ req, security_manager_path_req_free);
+ parsePathsOptions(argc, argv, *req, vm);
+ return registerPaths(*req);
} else {
std::cout << "No command argument was given." << std::endl;
usage(std::string(argv[0]));