OpenDNSSEC-enforcer
1.3.8
|
00001 /* 00002 * $Id: database_init_rundown.c 2120 2009-10-07 08:40:35Z sion $ 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 * database_init_rundown.c - Database Access Initialization 00031 * 00032 * Description: 00033 * Contains the functions needed to initialize and run down the 00034 * database access module. 00035 -*/ 00036 00037 #include "ksm/database.h" 00038 #include "ksm/dbsdef.h" 00039 #include "ksm/dbsmsg.h" 00040 #include "ksm/kmedef.h" 00041 #include "ksm/message.h" 00042 00043 /* Flag as to whether the database modules have been initialized */ 00044 00045 static int m_initialized = 0; /* Default is not */ 00046 00047 00048 00049 /*+ 00050 * DbInit - Initialize Database Access 00051 * 00052 * Description: 00053 * Initializes the Database Modules if not already initialized. 00054 * 00055 * Arguments: 00056 * None. 00057 -*/ 00058 00059 void DbInit(void) 00060 { 00061 if (! m_initialized) { 00062 MsgRegister(DBS_MIN_VALUE, DBS_MAX_VALUE, d_messages, NULL); 00063 m_initialized = 1; 00064 } 00065 00066 return; 00067 } 00068 00069 00070 00071 /*+ 00072 * DbRundown - Rundown Database Access 00073 * 00074 * Description: 00075 * Performs any rundown needed of the database module. 00076 * 00077 * Arguments: 00078 * None. 00079 -*/ 00080 00081 void DbRundown(void) 00082 { 00083 return; 00084 } 00085 00086 int DbFlavour(void) 00087 { 00088 #ifdef USE_MYSQL 00089 return MYSQL_DB; 00090 #else 00091 return SQLITE_DB; 00092 #endif 00093 } 00094 00095 /*+ 00096 * db_version_check 00097 * 00098 * Description: 00099 * Check the version of the database against the version in database.h 00100 * 00101 * Arguments: 00102 * None 00103 -*/ 00104 00105 int db_version_check(void) 00106 { 00107 char* sql = "select version from dbadmin"; /* SQL query */ 00108 int status = 0; /* Status return */ 00109 DB_RESULT result; /* Result of the query */ 00110 DB_ROW row = NULL; /* Row data */ 00111 int version = 0; /* Version returned */ 00112 00113 /* Select rows */ 00114 status = DbExecuteSql(DbHandle(), sql, &result); 00115 if (status == 0) { 00116 status = DbFetchRow(result, &row); 00117 while (status == 0) { 00118 /* Got a row, print it */ 00119 DbInt(row, 0, &version); 00120 00121 /* Check it */ 00122 if (version != KSM_DB_VERSION) { 00123 DbFreeRow(row); 00124 DbFreeResult(result); 00125 return MsgLog(KME_WRONG_DB_VER, KSM_DB_VERSION, version); 00126 } 00127 00128 status = DbFetchRow(result, &row); 00129 /* should only have one row */ 00130 if (status == 0) { 00131 DbFreeRow(row); 00132 DbFreeResult(result); 00133 return MsgLog(KME_DB_ADMIN); 00134 } 00135 } 00136 00137 /* Convert EOF status to success */ 00138 if (status == -1) { 00139 status = 0; 00140 } 00141 00142 DbFreeResult(result); 00143 } 00144 00145 DbFreeRow(row); 00146 return status; 00147 }