OpenDNSSEC-signer  1.4.7
ods-getconf.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 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 
32 #include "config.h"
33 #include "parser/confparser.h"
34 #include "shared/log.h"
35 
36 #include <errno.h>
37 #include <getopt.h>
38 #include <fcntl.h> /* fcntl() */
39 #include <stdio.h> /* fprintf() */
40 #include <string.h> /* strerror(), strncmp(), strlen(), strcpy(), strncat() */
41 #include <strings.h> /* bzero() */
42 #include <sys/select.h> /* select(), FD_ZERO(), FD_SET(), FD_ISSET(), FD_CLR() */
43 #include <sys/socket.h> /* socket(), connect(), shutdown() */
44 #include <sys/un.h>
45 #include <unistd.h> /* exit(), read(), write() */
46 
47 /* According to earlier standards, we need sys/time.h, sys/types.h, unistd.h for select() */
48 #include <sys/types.h>
49 #include <sys/time.h>
50 
51 
56 static void
57 usage(FILE* out)
58 {
59  fprintf(out, "Usage: %s [<expr>]\n", "ods-getconf");
60  fprintf(out, "Simple command line tool to get the value of a "
61  "configuration option.\n\n");
62  fprintf(out, "Supported options:\n");
63  fprintf(out, " -c | --config <cfgfile> Read configuration from file.\n");
64  fprintf(out, " -h | --help Show this help 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 
76 static void
77 version(FILE* out)
78 {
79  fprintf(out, "%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION);
80  exit(0);
81 }
82 
83 
88 int
89 main(int argc, char* argv[])
90 {
91  int c;
92  int options_index = 0;
93  const char* str;
94  const char* cfgfile = ODS_SE_CFGFILE;
95  static struct option long_options[] = {
96  {"config", required_argument, 0, 'c'},
97  {"help", no_argument, 0, 'h'},
98  {"version", no_argument, 0, 'V'},
99  { 0, 0, 0, 0}
100  };
101  /* parse the commandline */
102  while ((c=getopt_long(argc, argv, "c:hV",
103  long_options, &options_index)) != -1) {
104  switch (c) {
105  case 'c':
106  cfgfile = optarg;
107  break;
108  case 'h':
109  usage(stdout);
110  exit(0);
111  break;
112  case 'V':
113  version(stdout);
114  exit(0);
115  break;
116  default:
117  usage(stderr);
118  exit(2);
119  break;
120  }
121  }
122  argc -= optind;
123  argv += optind;
124 
125  if (argc != 1) {
126  usage(stderr);
127  exit(2);
128  }
129 
130  str = parse_conf_string(cfgfile, argv[0], 0);
131  if (str) {
132  fprintf(stdout, "%s", str);
133  free((void*)str);
134  }
135  fprintf(stdout, "\n");
136  return 0;
137 }
138 
int main(int argc, char *argv[])
Definition: ods-getconf.c:89
const char * parse_conf_string(const char *cfgfile, const char *expr, int required)
Definition: confparser.c:235