OpenDNSSEC-enforcer
1.3.15
Main Page
Data Structures
Files
File List
Globals
enforcer
ksm
ksm_purge.c
Go to the documentation of this file.
1
/*
2
* $Id: ksm_purge.c 4656 2011-03-25 08:51:54Z rb $
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
* ksm_purge.c - Purge Dead Keys
31
*
32
* Description:
33
* Holds all the functions needed to implement the "purge" command.
34
-*/
35
36
#include "
ksm/database.h
"
37
#include "
ksm/database_statement.h
"
38
#include "
ksm/db_fields.h
"
39
#include "
ksm/kmedef.h
"
40
#include "
ksm/ksm.h
"
41
42
43
/*+
44
* KsmPurge - Purge Dead Keys
45
*
46
* Description:
47
* Implements the code to execute the "purge" command, which removes
48
* dead keys from the database.
49
*
50
* Arguments:
51
* None.
52
-*/
53
54
void
KsmPurge
(
void
)
55
{
56
char
* sql = NULL;
57
char
* sql2 = NULL;
58
char
* sql3 = NULL;
59
DB_RESULT
result;
/* Result of parameter query */
60
int
where = 0;
61
int
keypair_id;
62
DB_ROW
row = NULL;
/* Row object */
63
int
status = 0;
64
65
/* Construct the SQL; don't rely on cascading delete */
66
/* select ids of keys in dead state */
67
sql =
DqsSpecifyInit
(
"KEYDATA_VIEW"
,
DB_KEYDATA_FIELDS
);
68
DqsConditionInt
(&sql,
"STATE"
,
DQS_COMPARE_EQ
,
KSM_STATE_DEAD
, where++);
69
DqsEnd
(&sql);
70
71
/* delete rows in dnsseckeys which match */
72
status =
DbExecuteSql
(
DbHandle
(), sql, &result);
73
if
(status == 0) {
74
status =
DbFetchRow
(result, &row);
75
while
(status == 0) {
76
status =
DbInt
(row,
DB_KEYDATA_ID
, &keypair_id);
77
if
(status == 0) {
78
/* delete all entries in dnsseckeys that match */
79
where = 0;
80
sql2 =
DdsInit
(
"dnsseckeys"
);
81
DdsConditionInt
(&sql2,
"keypair_id"
,
DQS_COMPARE_EQ
, keypair_id, where++);
82
DdsEnd
(&sql2);
83
(void)
DbExecuteSqlNoResult
(
DbHandle
(), sql2);
84
DdsFree
(sql2);
85
86
/* Delete the row from keypairs */
87
sql3 =
DdsInit
(
"keypairs"
);
88
DdsConditionInt
(&sql3,
"ID"
,
DQS_COMPARE_EQ
, keypair_id, 0);
89
DdsEnd
(&sql3);
90
(void)
DbExecuteSqlNoResult
(
DbHandle
(), sql3);
91
DdsFree
(sql3);
92
}
93
94
status =
DbFetchRow
(result, &row);
95
}
96
}
97
DdsFree
(sql);
98
99
DbFreeRow
(row);
100
DbFreeResult
(result);
101
102
return
;
103
}
Generated on Fri Sep 27 2013 06:39:24 for OpenDNSSEC-enforcer by
1.8.4