OpenDNSSEC-enforcer  1.4.1
daemon.h
Go to the documentation of this file.
1 /*
2  * $Id: daemon.h 7018 2013-02-05 13:59:43Z sion $
3  *
4  * Copyright (c) 2008-2009 Nominet UK. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
25  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  */
28 
29 #ifndef ENFORCER_DAEMON_H
30 #define ENFORCER_DAEMON_H
31 /*
32  * daemon.h code needed to get a daemon up and running
33  *
34  * edit the DAEMONCONFIG and cmlParse function
35  * in daemon_util.[c|h] to add options specific
36  * to your app
37  *
38  * gcc -o daemon daemon_util.c daemon.c
39  *
40  * Most of this is based on stuff I have seen in NSD
41  */
42 #include "config.h"
43 #include <inttypes.h>
44 
45 #ifdef HAVE_STDBOOL_H
46 # include <stdbool.h>
47 #else
48 # ifndef HAVE__BOOL
49 # ifdef __cplusplus
50 typedef bool _Bool;
51 # else
52 # define _Bool signed char
53 # endif /* __cplusplus */
54 # endif /* HAVE__BOOL */
55 # define bool _Bool
56 # define false 0
57 # define true 1
58 # define __bool_true_false_are_defined 1
59 #endif /* HAVE_STDBOOL_H */
60 
61 #include <stdint.h>
62 #include <unistd.h>
63 #include <syslog.h>
64 
65 /* Define some lengths of the char*s in the struct
66  MySQL allows e.g. 81 characters for the username,
67  set these stupidly high though */
68 #define MAX_PROG_NAME_LENGTH 255
69 #define MAX_USER_LENGTH 255
70 #define MAX_HOST_LENGTH 255
71 #define MAX_PASSWORD_LENGTH 255
72 #define MAX_SCHEMA_LENGTH 255
73 #define MAX_PORT_LENGTH 16
74 #define MAX_PID_LENGTH 255
75 #define MAX_LOG_USER_LENGTH 32
76 
77 #ifdef LOG_DAEMON
78 #define DEFAULT_LOG_FACILITY LOG_DAEMON
79 #define DEFAULT_LOG_FACILITY_STRING "LOG_DAEMON"
80 #else
81 #define DEFAULT_LOG_FACILITY LOG_USER
82 #define DEFAULT_LOG_FACILITY_STRING "LOG_USER"
83 #endif /* LOG_DAEMON */
84 
85 /* struct to hold configuration */
86 typedef struct
87 {
88  /* stuff that daemons always have */
89  const char *program;
90  bool debug;
91  bool once;
92  pid_t pid;
93  char *pidfile;
94  uid_t uid;
95  gid_t gid;
96  char *username;
97  char *groupname;
98 #if 0
99  char *chrootdir;
100 #endif
101  /* flag to indicate that SIGTERM was recieved */
102  int term;
103 
104  /* Add app specific stuff here */
105  char *configfile;
106  unsigned char* user;
107  unsigned char* host;
108  unsigned char* password;
109  unsigned char* schema;
110  unsigned char* port;
111  uint16_t interval;
112  uint16_t keygeninterval; /* TODO remove this */
116  char* DSSubmitCmd;
118 
119  int log_user; /* log facility (or default of LOG_DAEMON) */
120 
121 } DAEMONCONFIG;
122 
123 extern int daemon_our_pidfile;
124 
125 #define AUTHOR_NAME "John Dickinson"
126 #define COPYRIGHT_STR "Copyright (C) 2008 2009 Nominet UK"
127 
128 #endif /* ENFORCER_DAEMON_H */