31 #include "cmdhandler.h"
35 #include "clientpipe.h"
43 static const char *module_str =
"policy_import_cmd";
45 static void database_error_help(
int sockfd) {
46 client_printf_err(sockfd,
47 "\nThe information in the database may have been changed during KASP update"
48 " and caused an update error, try rerunning policy import. If the problem persists"
49 " please check logs and database setup and after correcting the problem rerun policy import.\n"
58 " [--remove-missing-policies] aka -r\n"
66 "Import policies from kasp.xml into the enforcer database.\n"
68 "remove-missing-policies Remove any policies from database "
69 "that do not exist in the KASP file\n\n"
75 run(
int sockfd, cmdhandler_ctx_type* context,
const char *cmd)
81 int remove_missing_policies = 0, argc = 0;
82 int long_index = 0, opt = 0;
83 char buf[ODS_SE_MAXLINE];
84 char const *argv[
NARGV];
86 static struct option long_options[] = {
87 {
"remove-missing-policies", no_argument, 0,
'r'},
101 strncpy(buf, cmd,
sizeof(buf));
102 buf[
sizeof(buf)-1] =
'\0';
105 argc = ods_str_explode(buf,
NARGV, argv);
107 ods_log_error(
"[%s] too many arguments for %s command",
109 client_printf_err(sockfd,
"too many arguments\n");
114 while ((opt = getopt_long(argc, (
char*
const*)argv,
"r", long_options, &long_index)) != -1 ) {
117 remove_missing_policies = 1;
120 client_printf_err(sockfd,
"unknown arguments\n");
121 ods_log_error(
"[%s] unknown arguments for %s command",
127 switch (
policy_import(sockfd, engine, dbconn, remove_missing_policies)) {
141 database_error_help(sockfd);
152 "policy import", &usage, &help, NULL, &run