OpenDNSSEC-enforcer  1.3.9
kaspaccess.c
Go to the documentation of this file.
1 /*
2  * $Id: kaspaccess.c 6307 2012-05-04 09:36:03Z jerry $
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 /*
30  * kaspaccess.c kasp acccess functions needed by keygend
31  */
32 
33 
34 #include <syslog.h>
35 #include <stdlib.h>
36 
37 #include "daemon.h"
38 #include "daemon_util.h"
39 #include "kaspaccess.h"
40 #include "ksm/string_util.h"
41 #include "ksm/string_util2.h"
42 
43 /*
44 * Set defaults for policies
45 * Make sure that we set everything, any new policy items need to be added here.
46 */
47 void
48 kaspSetPolicyDefaults(KSM_POLICY *policy, char *name)
49 {
50  if (policy == NULL) {
51  log_msg(NULL, LOG_ERR, "Error in kaspSetPolicyDefaults, no policy provided");
52  return;
53  }
54 
55  if (name) {
56  snprintf(policy->name, KSM_NAME_LENGTH, "%s", name);
57  }
58 
59  policy->signer->refresh = 0;
60  policy->signer->jitter = 0;
61  policy->signer->propdelay = 0;
62  policy->signer->soamin = 0;
63  policy->signer->soattl = 0;
64  policy->signer->serial = 0;
65 
66  policy->signature->clockskew = 0;
67  policy->signature->resign = 0;
68  policy->signature->valdefault = 0;
69  policy->signature->valdenial = 0;
70 
71  policy->denial->version = 0;
72  policy->denial->resalt = 0;
73  policy->denial->algorithm = 0;
74  policy->denial->iteration = 0;
75  policy->denial->optout = 0;
76  policy->denial->ttl = 0;
77  policy->denial->saltlength = 0;
78 
79  policy->keys->ttl = 0;
80  policy->keys->retire_safety = 0;
81  policy->keys->publish_safety = 0;
82  policy->keys->share_keys = 0;
83  policy->keys->purge = -1;
84 
85  policy->ksk->algorithm = 0;
86  policy->ksk->bits = 0;
87  policy->ksk->lifetime = 0;
88  policy->ksk->sm = 0;
89  policy->ksk->overlap = 0;
90  policy->ksk->ttl = 0;
91  policy->ksk->rfc5011 = 0;
92  policy->ksk->type = KSM_TYPE_KSK;
93  policy->ksk->standby_keys = 0;
94  policy->ksk->manual_rollover = 0;
96 
97  policy->zsk->algorithm = 0;
98  policy->zsk->bits = 0;
99  policy->zsk->lifetime = 0;
100  policy->zsk->sm = 0;
101  policy->zsk->overlap = 0;
102  policy->zsk->ttl = 0;
103  policy->zsk->rfc5011 = 0;
104  policy->zsk->type = KSM_TYPE_ZSK;
105  policy->zsk->standby_keys = 0;
106  policy->zsk->manual_rollover = 0;
107  policy->zsk->rollover_scheme = 0;
108 
109  policy->enforcer->keycreate = 0;
110  policy->enforcer->backup_interval = 0;
111  policy->enforcer->keygeninterval = 0;
112 
113  policy->zone->propdelay = 0;
114  policy->zone->soa_ttl = 0;
115  policy->zone->soa_min = 0;
116  policy->zone->serial = 0;
117 
118  policy->parent->propdelay = 0;
119  policy->parent->ds_ttl = 0;
120  policy->parent->soa_ttl = 0;
121  policy->parent->soa_min = 0;
122 
123 }
124 
125 /*
126 * Connect to the DB
127 */
128 void
130 {
131  /* Note that all these XML derived strings are unsigned chars */
132  if (DbConnect(handle, (char *)config->schema, (char *)config->host, (char *)config->password, (char *)config->user, (char *)config->port) != 0) {
133  unlink(config->pidfile);
134  exit(-1);
135  }
136 
137 }
138 
139 /*
140 * Try and connect to the DB
141 */
142 int
144 {
145  /* Note that all these XML derived strings are unsigned chars */
146  if (DbConnect(handle, (char *)config->schema, (char *)config->host, (char *)config->password, (char *)config->user, (char *)config->port) != 0) {
147  return 1;
148  }
149 
150  return 0;
151 }
152 
153 /*
154 * Disconnect from the DB
155 */
156 void
158 {
159  (void) DbDisconnect(*handle);
160 }
161 
162 /*
163 * Read a policy
164 */
165 int
167 {
168  /* This fn checks that the policy exists for us */
169  return KsmPolicyRead(policy);
170 }