OpenDNSSEC-enforcer
1.3.4
|
00001 /* 00002 * $Id: ksm_purge.c 4656 2011-03-25 08:51:54Z rb $ 00003 * 00004 * Copyright (c) 2008-2009 Nominet UK. All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions 00008 * are met: 00009 * 1. Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * 2. Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * 00015 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00016 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00017 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00018 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 00019 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00020 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 00021 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00022 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00023 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 00024 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 00025 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 * 00027 */ 00028 00029 /*+ 00030 * ksm_purge.c - Purge Dead Keys 00031 * 00032 * Description: 00033 * Holds all the functions needed to implement the "purge" command. 00034 -*/ 00035 00036 #include "ksm/database.h" 00037 #include "ksm/database_statement.h" 00038 #include "ksm/db_fields.h" 00039 #include "ksm/kmedef.h" 00040 #include "ksm/ksm.h" 00041 00042 00043 /*+ 00044 * KsmPurge - Purge Dead Keys 00045 * 00046 * Description: 00047 * Implements the code to execute the "purge" command, which removes 00048 * dead keys from the database. 00049 * 00050 * Arguments: 00051 * None. 00052 -*/ 00053 00054 void KsmPurge(void) 00055 { 00056 char* sql = NULL; 00057 char* sql2 = NULL; 00058 char* sql3 = NULL; 00059 DB_RESULT result; /* Result of parameter query */ 00060 int where = 0; 00061 int keypair_id; 00062 DB_ROW row = NULL; /* Row object */ 00063 int status = 0; 00064 00065 /* Construct the SQL; don't rely on cascading delete */ 00066 /* select ids of keys in dead state */ 00067 sql = DqsSpecifyInit("KEYDATA_VIEW", DB_KEYDATA_FIELDS); 00068 DqsConditionInt(&sql, "STATE", DQS_COMPARE_EQ, KSM_STATE_DEAD, where++); 00069 DqsEnd(&sql); 00070 00071 /* delete rows in dnsseckeys which match */ 00072 status = DbExecuteSql(DbHandle(), sql, &result); 00073 if (status == 0) { 00074 status = DbFetchRow(result, &row); 00075 while (status == 0) { 00076 status = DbInt(row, DB_KEYDATA_ID, &keypair_id); 00077 if (status == 0) { 00078 /* delete all entries in dnsseckeys that match */ 00079 where = 0; 00080 sql2 = DdsInit("dnsseckeys"); 00081 DdsConditionInt(&sql2, "keypair_id", DQS_COMPARE_EQ, keypair_id, where++); 00082 DdsEnd(&sql2); 00083 (void) DbExecuteSqlNoResult(DbHandle(), sql2); 00084 DdsFree(sql2); 00085 00086 /* Delete the row from keypairs */ 00087 sql3 = DdsInit("keypairs"); 00088 DdsConditionInt(&sql3, "ID", DQS_COMPARE_EQ, keypair_id, 0); 00089 DdsEnd(&sql3); 00090 (void) DbExecuteSqlNoResult(DbHandle(), sql3); 00091 DdsFree(sql3); 00092 } 00093 00094 status = DbFetchRow(result, &row); 00095 } 00096 } 00097 DdsFree(sql); 00098 00099 DbFreeRow(row); 00100 DbFreeResult(result); 00101 00102 return; 00103 }