00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00034 #include "config.h"
00035 #include "daemon/cfg.h"
00036 #include "parser/confparser.h"
00037 #include "shared/allocator.h"
00038 #include "shared/file.h"
00039 #include "shared/log.h"
00040 #include "shared/status.h"
00041
00042 #include <errno.h>
00043 #include <stdio.h>
00044 #include <string.h>
00045
00046 static const char* conf_str = "config";
00047
00048
00053 engineconfig_type*
00054 engine_config(allocator_type* allocator, const char* cfgfile,
00055 int cmdline_verbosity)
00056 {
00057 engineconfig_type* ecfg;
00058 const char* rngfile = ODS_SE_RNGDIR "/conf.rng";
00059 FILE* cfgfd = NULL;
00060
00061 if (!allocator) {
00062 ods_log_error("[%s] failed to read: no allocator available",
00063 conf_str);
00064 return NULL;
00065 }
00066 ods_log_assert(allocator);
00067 if (!cfgfile) {
00068 ods_log_error("[%s] failed to read: no filename given", conf_str);
00069 return NULL;
00070 }
00071 ods_log_assert(cfgfile);
00072 ods_log_verbose("[%s] read cfgfile: %s", conf_str, cfgfile);
00073
00074 ecfg = (engineconfig_type*) allocator_alloc(allocator,
00075 sizeof(engineconfig_type));
00076 if (!ecfg) {
00077 ods_log_error("[%s] failed to read: allocator failed", conf_str);
00078 return NULL;
00079 }
00080
00081 ecfg->allocator = allocator;
00082
00083
00084 if (parse_file_check(cfgfile, rngfile) != ODS_STATUS_OK) {
00085 ods_log_error("[%s] failed to read: unable to parse file %s",
00086 conf_str, cfgfile);
00087 return NULL;
00088 }
00089
00090
00091 cfgfd = ods_fopen(cfgfile, NULL, "r");
00092 if (cfgfd) {
00093
00094 ecfg->cfg_filename = allocator_strdup(allocator, cfgfile);
00095 ecfg->zonelist_filename = parse_conf_zonelist_filename(allocator,
00096 cfgfile);
00097 ecfg->zonefetch_filename = parse_conf_zonefetch_filename(allocator,
00098 cfgfile);
00099 ecfg->log_filename = parse_conf_log_filename(allocator, cfgfile);
00100 ecfg->pid_filename = parse_conf_pid_filename(allocator, cfgfile);
00101 ecfg->notify_command = parse_conf_notify_command(allocator, cfgfile);
00102 ecfg->clisock_filename = parse_conf_clisock_filename(allocator,
00103 cfgfile);
00104 ecfg->working_dir = parse_conf_working_dir(allocator, cfgfile);
00105 ecfg->username = parse_conf_username(allocator, cfgfile);
00106 ecfg->group = parse_conf_group(allocator, cfgfile);
00107 ecfg->chroot = parse_conf_chroot(allocator, cfgfile);
00108 ecfg->use_syslog = parse_conf_use_syslog(cfgfile);
00109 ecfg->num_worker_threads = parse_conf_worker_threads(cfgfile);
00110 ecfg->num_signer_threads = parse_conf_signer_threads(cfgfile);
00111 ecfg->verbosity = cmdline_verbosity;
00112 ecfg->num_adapters = 0;
00113
00114
00115 ods_fclose(cfgfd);
00116 return ecfg;
00117 }
00118
00119 ods_log_error("[%s] failed to read: unable to open file %s", conf_str,
00120 cfgfile);
00121 return NULL;
00122 }
00123
00124
00129 ods_status
00130 engine_config_check(engineconfig_type* config)
00131 {
00132 if (!config) {
00133 ods_log_error("[%s] check failed: config does not exist", conf_str);
00134 return ODS_STATUS_CFG_ERR;
00135 }
00136 if (!config->zonelist_filename) {
00137 ods_log_error("[%s] check failed: no zonelist filename", conf_str);
00138 return ODS_STATUS_CFG_ERR;
00139 }
00140 if (!config->clisock_filename) {
00141 ods_log_error("[%s] check failed: no socket filename", conf_str);
00142 return ODS_STATUS_CFG_ERR;
00143 }
00144
00145
00146
00147 return ODS_STATUS_OK;
00148 }
00149
00150
00155 void
00156 engine_config_print(FILE* out, engineconfig_type* config)
00157 {
00158 if (!out) {
00159 return;
00160 }
00161
00162 fprintf(out, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
00163 if (config) {
00164 fprintf(out, "<Configuration>\n");
00165
00166
00167 fprintf(out, "\t<Common>\n");
00168 if (config->use_syslog && config->log_filename) {
00169 fprintf(out, "\t\t<Logging>\n");
00170 fprintf(out, "\t\t\t<Syslog>\n");
00171 fprintf(out, "\t\t\t\t<Facility>%s</Facility>\n",
00172 config->log_filename);
00173 fprintf(out, "\t\t\t</Syslog>\n");
00174 fprintf(out, "\t\t</Logging>\n");
00175 } else if (config->log_filename) {
00176 fprintf(out, "\t\t<Logging>\n");
00177 fprintf(out, "\t\t\t<File>\n");
00178 fprintf(out, "\t\t\t\t<Filename>%s</Filename>\n",
00179 config->log_filename);
00180 fprintf(out, "\t\t\t</File>\n");
00181 fprintf(out, "\t\t</Logging>\n");
00182 }
00183
00184 fprintf(out, "\t\t<ZoneListFile>%s</ZoneListFile>\n",
00185 config->zonelist_filename);
00186 if (config->zonefetch_filename) {
00187 fprintf(out, "\t\t<ZoneFetchFile>%s</ZoneFetchFile>\n",
00188 config->zonefetch_filename);
00189 }
00190
00191 fprintf(out, "\t</Common>\n");
00192
00193
00194 fprintf(out, "\t<Signer>\n");
00195 if (config->username || config->group || config->chroot) {
00196 fprintf(out, "\t\t<Privileges>\n");
00197 if (config->username) {
00198 fprintf(out, "\t\t<User>%s</User>\n", config->username);
00199 }
00200 if (config->group) {
00201 fprintf(out, "\t\t<Group>%s</Group>\n", config->group);
00202 }
00203 if (config->chroot) {
00204 fprintf(out, "\t\t<Directory>%s</Directory>\n",
00205 config->chroot);
00206 }
00207 fprintf(out, "\t\t</Privileges>\n");
00208 }
00209 fprintf(out, "\t\t<WorkingDirectory>%s</WorkingDirectory>\n",
00210 config->working_dir);
00211 fprintf(out, "\t\t<WorkerThreads>%i</WorkerThreads>\n",
00212 config->num_worker_threads);
00213 fprintf(out, "\t\t<SignerThreads>%i</SignerThreads>\n",
00214 config->num_signer_threads);
00215 if (config->notify_command) {
00216 fprintf(out, "\t\t<NotifyCommand>%s</NotifyCommand>\n",
00217 config->notify_command);
00218 }
00219 fprintf(out, "\t</Signer>\n");
00220
00221 fprintf(out, "</Configuration>\n");
00222
00223
00224
00225
00226
00227 }
00228 return;
00229 }
00230
00231
00236 void
00237 engine_config_cleanup(engineconfig_type* config)
00238 {
00239 allocator_type* allocator;
00240 if (!config) {
00241 return;
00242 }
00243 allocator = config->allocator;
00244 allocator_deallocate(allocator, (void*) config->cfg_filename);
00245 allocator_deallocate(allocator, (void*) config->zonelist_filename);
00246 allocator_deallocate(allocator, (void*) config->zonefetch_filename);
00247 allocator_deallocate(allocator, (void*) config->log_filename);
00248 allocator_deallocate(allocator, (void*) config->pid_filename);
00249 allocator_deallocate(allocator, (void*) config->notify_command);
00250 allocator_deallocate(allocator, (void*) config->clisock_filename);
00251 allocator_deallocate(allocator, (void*) config->working_dir);
00252 allocator_deallocate(allocator, (void*) config->username);
00253 allocator_deallocate(allocator, (void*) config->group);
00254 allocator_deallocate(allocator, (void*) config->chroot);
00255 allocator_deallocate(allocator, (void*) config);
00256 return;
00257 }
00258