update_conf_cmd.c
Go to the documentation of this file.
/*
* Copyright (c) 2014 .SE (The Internet Infrastructure Foundation).
* Copyright (c) 2014 OpenDNSSEC AB (svb)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "daemon/engine.h"
#include "cmdhandler.h"
#include "daemon/enforcercommands.h"
#include "log.h"
#include "str.h"
#include "clientpipe.h"
#include "utils/kc_helper.h"
#include "enforcer/update_conf_cmd.h"
#include <pthread.h>
static const char *module_str = "update_conf_cmd";
static void
usage(int sockfd)
{
client_printf(sockfd,
"update conf\n");
}
static void
help(int sockfd)
{
client_printf(sockfd,
"Update the configuration from conf.xml and reload the Enforcer.\n\n"
);
}
static int
run(int sockfd, cmdhandler_ctx_type* context, const char *cmd)
{
char *kasp = NULL;
char *zonelist = NULL;
char **repositories = NULL;
int repository_count = 0;
int i;
db_connection_t* dbconn = getconnectioncontext(context);
engine_type* engine = getglobalcontext(context);
(void)cmd;
ods_log_debug("[%s] %s command", module_str, update_conf_funcblock.cmdname);
if (check_conf(engine->config->cfg_filename, &kasp, &zonelist, &repositories, &repository_count, (ods_log_verbosity() >= 3))) {
client_printf_err(sockfd, "Unable to validate '%s' consistency.",
engine->config->cfg_filename);
free(kasp);
free(zonelist);
if (repositories) {
for (i = 0; i < repository_count; i++) {
free(repositories[i]);
}
free(repositories);
}
return 1;
}
free(kasp);
free(zonelist);
if (repositories) {
for (i = 0; i < repository_count; i++) {
free(repositories[i]);
}
free(repositories);
}
engine->need_to_reload = 1;
pthread_cond_signal(&engine->signal_cond);
return 0;
}
struct cmd_func_block update_conf_funcblock = {
"update conf", &usage, &help, NULL, &run
};
engineconfig_struct::cfg_filename
const char * cfg_filename
Definition: cfg.h:55
check_conf
int check_conf(const char *conf, char **kasp, char **zonelist, char ***repo_listout, int *repo_countout, int verbose)
Definition: kc_helper.c:1386
engine.h
update_conf_funcblock
struct cmd_func_block update_conf_funcblock
Definition: update_conf_cmd.c:102
getglobalcontext
engine_type * getglobalcontext(cmdhandler_ctx_type *context)
Definition: enforcercommands.c:102
update_conf_cmd.h
engine_struct::signal_cond
pthread_cond_t signal_cond
Definition: engine.h:64
getconnectioncontext
db_connection_t * getconnectioncontext(cmdhandler_ctx_type *context)
Definition: enforcercommands.c:108
kc_helper.h
engine_struct::config
engineconfig_type * config
Definition: engine.h:48
enforcercommands.h
engine_struct
Definition: engine.h:47
db_connection
Definition: db_connection.h:46
engine_struct::need_to_reload
int need_to_reload
Definition: engine.h:56