int handled_update_all_cmd(int sockfd, engine_type* engine, const char *cmd, ssize_t n) { const char *scmd = "update all"; cmd = ods_check_command(cmd,n,scmd); if (!cmd) return 0; // not handled ods_log_debug("[%s] %s command", module_str, scmd); // check that we are using a compatible protobuf version. GOOGLE_PROTOBUF_VERIFY_VERSION; time_t tstart = time(NULL); autostart(engine); /* Check all files for errors. The perform_update_*() * functions check as well but this gives us all or nothing. * Plus we get a complete check of the files mentioned in the * conf which need not be the same as the files in use by the * running enforcer!*/ char *kasp = NULL; char *zonelist = NULL; char **replist = NULL; int repcount, i; int error = 1; if (check_conf(engine->config->cfg_filename, &kasp, &zonelist, &replist, &repcount, 0)) ods_log_error_and_printf(sockfd, module_str, "Unable to validate '%s' consistency.", engine->config->cfg_filename); else if (check_kasp(kasp, replist, repcount, 0)) ods_log_error_and_printf(sockfd, module_str, "Unable to validate '%s' consistency.", kasp); else if (check_zonelist(zonelist, 0)) ods_log_error_and_printf(sockfd, module_str, "Unable to validate '%s' consistency.", zonelist); else error = 0; free(kasp); free(zonelist); if (replist) { for (i = 0; i < repcount; i++) free(replist[i]); } if (!error) error |= perform_update_repositorylist(sockfd, engine); if (!error) error |= perform_update_kasp(sockfd, engine->config); if (!error) error |= perform_update_keyzones(sockfd, engine->config); if (!error) { perform_update_hsmkeys(sockfd, engine->config, 0 /* automatic */); perform_hsmkey_gen(sockfd, engine->config, 0 /* automatic */, engine->config->automatic_keygen_duration); flush_all_tasks(sockfd, engine); } ods_printf(sockfd, "%s completed in %ld seconds.\n",scmd,time(NULL)-tstart); return 1; }
/* * Fairly basic main. */ int main (int argc, char *argv[]) { int status = 0; /* Will be non-zero on error (NOT warning) */ int ch; int option_index = 0; int i = 0; int free_config = 0; static struct option long_options[] = { {"config", required_argument, 0, 'c'}, {"help", no_argument, 0, 'h'}, {"kasp", required_argument, 0, 'k'}, {"version", no_argument, 0, 'V'}, {"verbose", no_argument, 0, 'v'}, {0,0,0,0} }; /* The program name is the last component of the program file name */ if ((progname = strrchr(argv[0], '/'))) { /* EQUALS */ ++progname; /* Point to character after last "/" */ } else { progname = argv[0]; } while ((ch = getopt_long(argc, argv, "c:hk:Vv", long_options, &option_index)) != -1) { switch (ch) { case 'c': config = StrStrdup(optarg); free_config = 1; break; case 'h': usage(); exit(0); break; case 'k': kasp = StrStrdup(optarg); break; case 'V': printf("%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION); exit(0); break; case 'v': verbose = 1; break; } } /* 0) Some basic setup */ log_init(DEFAULT_LOG_FACILITY, progname); /* 1) Check on conf.xml - set kasp.xml (if -k flag not given) */ status = check_conf(&kasp); /* 2) Checks on kasp.xml */ status += check_kasp(); if (verbose) { dual_log("DEBUG: finished %d\n", status); } xmlCleanupParser(); for (i = 0; i < repo_count; i++) { StrFree(repo_list[i]); } StrFree(repo_list); if (free_config) { StrFree(config); } StrFree(kasp); return status; }