OpenDNSSEC-signer  1.3.8
/build/buildd/opendnssec-1.3.8/signer/src/ods-signerd.c
Go to the documentation of this file.
00001 /*
00002  * $Id: ods-signerd.c 5984 2012-01-02 14:50:59Z matthijs $
00003  *
00004  * Copyright (c) 2009 NLNet Labs. All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  *
00015  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00016  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00017  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00018  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
00019  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00020  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00021  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
00023  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00024  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
00025  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  *
00027  */
00028 
00034 #include "config.h"
00035 #include "daemon/engine.h"
00036 
00037 #include <getopt.h>
00038 #include <stdio.h>
00039 #include <stdlib.h>
00040 
00041 
00042 #define AUTHOR_NAME "Matthijs Mekking"
00043 #define COPYRIGHT_STR "Copyright (C) 2008-2010 NLnet Labs OpenDNSSEC"
00044 
00045 
00050 static void
00051 usage(FILE* out)
00052 {
00053     fprintf(out, "Usage: %s [OPTIONS]\n", "ods-signerd");
00054     fprintf(out, "Start the OpenDNSSEC signer engine daemon.\n\n");
00055     fprintf(out, "Supported options:\n");
00056     fprintf(out, " -c | --config <cfgfile> Read configuration from file.\n");
00057     fprintf(out, " -d | --no-daemon        Do not daemonize the signer "
00058                  "engine.\n");
00059     fprintf(out, " -1 | --single-run       Run once, then exit.\n");
00060     fprintf(out, " -h | --help             Show this help and exit.\n");
00061     fprintf(out, " -i | --info             Print configuration and exit.\n");
00062     fprintf(out, " -v | --verbose          Increase verbosity.\n");
00063     fprintf(out, " -V | --version          Show version and exit.\n");
00064     fprintf(out, "\nBSD licensed, see LICENSE in source package for "
00065                  "details.\n");
00066     fprintf(out, "Version %s. Report bugs to <%s>.\n",
00067         PACKAGE_VERSION, PACKAGE_BUGREPORT);
00068 }
00069 
00070 
00075 static void
00076 version(FILE* out)
00077 {
00078     fprintf(out, "%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION);
00079     fprintf(out, "Written by %s.\n\n", AUTHOR_NAME);
00080     fprintf(out, "%s.  This is free software.\n", COPYRIGHT_STR);
00081     fprintf(out, "See source files for more license information\n");
00082     exit(0);
00083 }
00084 
00085 
00086 
00087 
00092 int
00093 main(int argc, char* argv[])
00094 {
00095     int c;
00096     int options_index = 0;
00097     int info = 0;
00098     int single_run = 0;
00099     int daemonize = 1;
00100     int cmdline_verbosity = 0;
00101     const char* cfgfile = ODS_SE_CFGFILE;
00102     static struct option long_options[] = {
00103         {"single-run", no_argument, 0, '1'},
00104         {"config", required_argument, 0, 'c'},
00105         {"no-daemon", no_argument, 0, 'd'},
00106         {"help", no_argument, 0, 'h'},
00107         {"info", no_argument, 0, 'i'},
00108         {"verbose", no_argument, 0, 'v'},
00109         {"version", no_argument, 0, 'V'},
00110         { 0, 0, 0, 0}
00111     };
00112 
00113     /* parse the commandline */
00114     while ((c=getopt_long(argc, argv, "1c:dhivV",
00115         long_options, &options_index)) != -1) {
00116         switch (c) {
00117             case '1':
00118                 single_run = 1;
00119                 break;
00120             case 'c':
00121                 cfgfile = optarg;
00122                 break;
00123             case 'd':
00124                 daemonize = 0;
00125                 break;
00126             case 'h':
00127                 usage(stdout);
00128                 exit(0);
00129                 break;
00130             case 'i':
00131                 info = 1;
00132                 break;
00133             case 'v':
00134                 cmdline_verbosity++;
00135                 break;
00136             case 'V':
00137                 version(stdout);
00138                 exit(0);
00139                 break;
00140             default:
00141                 usage(stderr);
00142                 exit(2);
00143                 break;
00144         }
00145     }
00146     argc -= optind;
00147     argv += optind;
00148     if (argc != 0) {
00149         usage(stderr);
00150         exit(2);
00151     }
00152 
00153 #ifdef ENFORCER_TIMESHIFT
00154     if (getenv("ENFORCER_TIMESHIFT")) {
00155         fprintf(stdout, "WARNING: timeshift %s detected, running once only\n",
00156             getenv("ENFORCER_TIMESHIFT"));
00157         single_run = 1;
00158     } else {
00159         fprintf(stdout, "DEBUG: timeshift mode enabled, but not set.\n");
00160     }
00161 #endif /* ENFORCER_TIMESHIFT */
00162 
00163     /* main stuff */
00164     fprintf(stdout, "OpenDNSSEC signer engine version %s\n", PACKAGE_VERSION);
00165     engine_start(cfgfile, cmdline_verbosity, daemonize, info, single_run);
00166 
00167     /* done */
00168     return 0;
00169 }