OpenDNSSEC-enforcer
1.4.5
Main Page
Data Structures
Files
File List
Globals
enforcer
ksm
ksm_dnsseckeys.c
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2008-2009 Nominet UK. 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
27
/*
28
* ksm_dnsseckeys.c - Manipulation of dnssec key Information
29
*/
30
31
#include <assert.h>
32
#include <stdio.h>
33
#include <stdlib.h>
34
#include <string.h>
35
#include <time.h>
36
37
#include "
ksm/database.h
"
38
#include "
ksm/database_statement.h
"
39
#include "
ksm/datetime.h
"
40
#include "
ksm/db_fields.h
"
41
#include "
ksm/debug.h
"
42
#include "
ksm/ksmdef.h
"
43
#include "
ksm/ksm.h
"
44
#include "
ksm/ksm_internal.h
"
45
#include "
ksm/message.h
"
46
#include "
ksm/string_util.h
"
47
48
/*+
49
* KsmDNSSECKeysInSMCountInit - Query for Key Information
50
*
51
*
52
* Arguments:
53
* DB_RESULT* result
54
* Pointer to a handle to be used for information retrieval. Will
55
* be NULL on error.
56
*
57
* int id
58
* optional id of the security module that the keys must be in
59
*
60
*
61
* Returns:
62
* int
63
* Status return. 0 on success.
64
-*/
65
66
int
KsmDNSSECKeysInSMCountInit
(
DB_RESULT
* result,
int
id
)
67
{
68
int
where = 0;
/* WHERE clause value */
69
char
* sql = NULL;
/* SQL query */
70
int
status = 0;
/* Status return */
71
72
/* Construct the query */
73
74
sql =
DqsCountInit
(
"dnsseckeys"
);
75
if
(
id
>= 0) {
76
DqsConditionInt
(&sql,
"securitymodule_id"
,
DQS_COMPARE_EQ
,
id
, where++);
77
}
78
79
80
/* Execute query and free up the query string */
81
82
status =
DbExecuteSql
(
DbHandle
(), sql, result);
83
84
DqsFree
(sql);
85
86
return
status;
87
}
88
89
/*+
90
* KsmDNSSECKeysInSMCountInit - Query for Policy Information
91
*
92
*
93
* Arguments:
94
* DB_RESULT* result
95
* Pointer to a handle to be used for information retrieval. Will
96
* be NULL on error.
97
*
98
* policy_id
99
* id of the policy that keys must belong to
100
*
101
* key_policy
102
* key policy that the keys must be consitent with.
103
*
104
* int state
105
* state that the key must be in
106
*
107
* Returns:
108
* int
109
* Status return. 0 on success.
110
-*/
111
112
113
int
KsmDNSSECKeysStateCountInit
(
DB_RESULT
* result,
int
policy_id,
KSM_KEY_POLICY
*key_policy,
int
state)
114
{
115
int
where = 0;
/* WHERE clause value */
116
char
* sql = NULL;
/* SQL query */
117
int
status = 0;
/* Status return */
118
119
/* Check arguments */
120
if
(key_policy == NULL) {
121
return
MsgLog
(
KSM_INVARG
,
"NULL key_policy"
);
122
}
123
124
/* Construct the query */
125
126
sql =
DqsCountInit
(
"dnsseckeys"
);
127
128
DqsConditionInt
(&sql,
"securitymodule_id"
,
DQS_COMPARE_EQ
, key_policy->
sm
, where++);
129
DqsConditionInt
(&sql,
"policy_id"
,
DQS_COMPARE_EQ
, policy_id, where++);
130
DqsConditionInt
(&sql,
"size"
,
DQS_COMPARE_EQ
, key_policy->
bits
, where++);
131
DqsConditionInt
(&sql,
"algorithm"
,
DQS_COMPARE_EQ
, key_policy->
algorithm
, where++);
132
DqsConditionInt
(&sql,
"keytype"
,
DQS_COMPARE_EQ
, key_policy->
type
, where++);
133
DqsConditionInt
(&sql,
"state"
,
DQS_COMPARE_EQ
, state, where++);
134
135
136
/* Execute query and free up the query string */
137
138
status =
DbExecuteSql
(
DbHandle
(), sql, result);
139
140
DqsFree
(sql);
141
142
return
status;
143
}
144
145
/*+
146
* KsmDNSSECKeysInSMCount
147
*
148
* Arguments:
149
* DB_RESULT result
150
* Handle from KsmParameterInit
151
*
152
* count (returns)
153
* count of keys found
154
*
155
* Returns:
156
* int
157
* Status return:
158
* 0 success
159
* -1 end of record set reached
160
* non-zero some error occurred and a message has been output.
161
*
162
* If the status is non-zero, the returned data is meaningless.
163
-*/
164
165
int
KsmDNSSECKeysInSMCount
(
DB_RESULT
result,
int
* count)
166
{
167
int
status = 0;
/* Return status */
168
DB_ROW
row = NULL;
/* Row data */
169
170
/* Get the next row from the data */
171
172
status =
DbFetchRow
(result, &row);
173
if
(status == 0) {
174
175
/* Now copy the results into the output data */
176
177
status =
DbInt
(row,
DB_COUNT
, count);
178
}
179
else
if
(status == -1) {}
180
/* No rows to return (but no error) */
181
else
{
182
status =
MsgLog
(
KSM_SQLFAIL
,
DbErrmsg
(
DbHandle
()));
183
}
184
185
DbFreeRow
(row);
186
187
return
status;
188
}
Generated on Tue Jul 22 2014 00:37:50 for OpenDNSSEC-enforcer by
1.8.1.2