"Fossies" - the Fresh Open Source Software Archive

Member "opendnssec-2.1.4/signer/src/ods-signerd.c" (16 May 2019, 5928 Bytes) of package /linux/misc/dns/opendnssec-2.1.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ods-signerd.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (c) 2009 NLNet Labs. All rights reserved.
    3  *
    4  * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions
    6  * are met:
    7  * 1. Redistributions of source code must retain the above copyright
    8  *    notice, this list of conditions and the following disclaimer.
    9  * 2. Redistributions in binary form must reproduce the above copyright
   10  *    notice, this list of conditions and the following disclaimer in the
   11  *    documentation and/or other materials provided with the distribution.
   12  *
   13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   14  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
   15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   16  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
   17  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
   19  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
   21  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
   22  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
   23  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   24  *
   25  */
   26 
   27 /**
   28  * OpenDNSSEC signer engine daemon.
   29  *
   30  */
   31 
   32 #include "config.h"
   33 #include "locks.h"
   34 #include "daemon/engine.h"
   35 
   36 #include <getopt.h>
   37 #include <stdio.h>
   38 #include <stdlib.h>
   39 #include <libxml/parser.h>
   40 #include "parser/confparser.h"
   41 
   42 
   43 #define AUTHOR_NAME "Matthijs Mekking"
   44 #define COPYRIGHT_STR "Copyright (C) 2008-2010 NLnet Labs OpenDNSSEC"
   45 
   46 
   47 /**
   48  * Prints usage.
   49  *
   50  */
   51 static void
   52 usage(FILE* out)
   53 {
   54     fprintf(out, "Usage: %s [OPTIONS]\n", "ods-signerd");
   55     fprintf(out, "Start the OpenDNSSEC signer engine daemon.\n\n");
   56     fprintf(out, "Supported options:\n");
   57     fprintf(out, " -c | --config <cfgfile> Read configuration from file.\n");
   58     fprintf(out, " -d | --no-daemon        Do not daemonize the signer "
   59                  "engine.\n");
   60     fprintf(out, " -1 | --single-run       Run once, then exit.\n");
   61     fprintf(out, " -h | --help             Show this help and exit.\n");
   62     fprintf(out, " -i | --info             Print configuration and exit.\n");
   63     fprintf(out, " -v | --verbose          Increase verbosity.\n");
   64     fprintf(out, " -V | --version          Show version and exit.\n");
   65     fprintf(out, "\nBSD licensed, see LICENSE in source package for "
   66                  "details.\n");
   67     fprintf(out, "Version %s. Report bugs to <%s>.\n",
   68         PACKAGE_VERSION, PACKAGE_BUGREPORT);
   69 }
   70 
   71 
   72 /**
   73  * Prints version.
   74  *
   75  */
   76 static void
   77 version(FILE* out)
   78 {
   79     fprintf(out, "%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION);
   80     fprintf(out, "Written by %s.\n\n", AUTHOR_NAME);
   81     fprintf(out, "%s.  This is free software.\n", COPYRIGHT_STR);
   82     fprintf(out, "See source files for more license information\n");
   83     exit(0);
   84 }
   85 
   86 static void
   87 program_setup(const char* cfgfile, int cmdline_verbosity)
   88 {
   89     const char* file = NULL;
   90     /* open log */
   91     file = parse_conf_log_filename(cfgfile);
   92     ods_log_init("ods-signerd", parse_conf_use_syslog(cfgfile), file, cmdline_verbosity?cmdline_verbosity:parse_conf_verbosity(cfgfile));
   93 
   94     ods_log_verbose("[engine] starting signer");
   95 
   96     /* initialize */
   97     xmlInitGlobals();
   98     xmlInitParser();
   99     xmlInitThreads();
  100 
  101     tzset(); /* for portability */
  102     free((void*)file);
  103 }
  104 
  105 static void
  106 program_teardown()
  107 {
  108     xmlCleanupParser();
  109     xmlCleanupGlobals();
  110     ods_log_close();
  111 }
  112 
  113 /**
  114  * Main. start engine and run it.
  115  *
  116  */
  117 int
  118 main(int argc, char* argv[])
  119 {
  120     char* argv0;
  121     int c, returncode;
  122     int options_index = 0;
  123     int info = 0;
  124     int daemonize = 1;
  125     int cmdline_verbosity = 0;
  126     char *time_arg = NULL;
  127     const char* cfgfile = ODS_SE_CFGFILE;
  128     static struct option long_options[] = {
  129         {"config", required_argument, 0, 'c'},
  130         {"no-daemon", no_argument, 0, 'd'},
  131         {"help", no_argument, 0, 'h'},
  132         {"info", no_argument, 0, 'i'},
  133         {"verbose", no_argument, 0, 'v'},
  134         {"version", no_argument, 0, 'V'},
  135         {"set-time", required_argument, 0, 256},
  136         { 0, 0, 0, 0}
  137     };
  138 
  139     if(argv[0][0] != '/') {
  140         char *path = getcwd(NULL,0);
  141         asprintf(&argv0, "%s/%s", path, argv[0]);
  142         free(path);
  143     } else {
  144         argv0 = strdup(argv[0]);
  145     }
  146 
  147     /* parse the commandline */
  148     while ((c=getopt_long(argc, argv, "c:dhivV",
  149         long_options, &options_index)) != -1) {
  150         switch (c) {
  151             case 'c':
  152                 cfgfile = optarg;
  153                 break;
  154             case 'd':
  155                 daemonize = 0;
  156                 break;
  157             case 'h':
  158                 usage(stdout);
  159                 exit(0);
  160                 break;
  161             case 'i':
  162                 info = 1;
  163                 break;
  164             case 'v':
  165                 cmdline_verbosity++;
  166                 break;
  167             case 'V':
  168                 version(stdout);
  169                 exit(0);
  170                 break;
  171             case 256:
  172                 time_arg = optarg;
  173                 break;
  174             default:
  175                 usage(stderr);
  176                 exit(2);
  177                 break;
  178         }
  179     }
  180     argc -= optind;
  181     argv += optind;
  182     if (argc != 0) {
  183         usage(stderr);
  184         exit(2);
  185     }
  186 
  187     if (time_arg) {
  188         if(set_time_now_str(time_arg)) {
  189             fprintf(stderr, "Error: Failed to interpret start time argument.  Daemon not started.\n");
  190             return 1;
  191         }
  192     }
  193 
  194     /* main stuff */
  195     fprintf(stdout, "OpenDNSSEC signer engine version %s\n", PACKAGE_VERSION);
  196 
  197     ods_janitor_initialize(argv0);
  198     program_setup(cfgfile, cmdline_verbosity);
  199     returncode = engine_start(cfgfile, cmdline_verbosity, daemonize, info);
  200     program_teardown();
  201 
  202     free(argv0);
  203     return returncode;
  204 }