OpenDNSSEC-signer 1.2.1
|
00001 /* 00002 * $Id: ods-signerd.c 4294 2011-01-13 19:58:29Z jakob $ 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 'd': 00121 daemonize = 0; 00122 break; 00123 case 'h': 00124 usage(stdout); 00125 exit(0); 00126 break; 00127 case 'i': 00128 info = 1; 00129 break; 00130 case 'v': 00131 cmdline_verbosity++; 00132 break; 00133 case 'V': 00134 version(stdout); 00135 exit(0); 00136 break; 00137 default: 00138 usage(stderr); 00139 exit(2); 00140 break; 00141 } 00142 } 00143 argc -= optind; 00144 argv += optind; 00145 if (argc != 0) { 00146 usage(stderr); 00147 exit(2); 00148 } 00149 00150 #ifdef ENFORCER_TIMESHIFT 00151 if (getenv("ENFORCER_TIMESHIFT")) { 00152 fprintf(stdout, "WARNING: timeshift %s detected, running once only\n", 00153 getenv("ENFORCER_TIMESHIFT")); 00154 single_run = 1; 00155 } else { 00156 fprintf(stdout, "DEBUG: timeshift mode enabled, but not set.\n"); 00157 } 00158 #endif /* ENFORCER_TIMESHIFT */ 00159 00160 00161 /* main stuff */ 00162 fprintf(stdout, "OpenDNSSEC signer engine version %s\n", PACKAGE_VERSION); 00163 engine_start(cfgfile, cmdline_verbosity, daemonize, info, single_run); 00164 00165 /* done */ 00166 return 0; 00167 }