[Opendnssec-commits] [keihatsu.kirei.se/svn/dnssec] r3767 - in branches/OpenDNSSEC-sion/enforcer: ksm utils

Sion Lloyd sion at nominet.org.uk
Fri Aug 20 16:02:54 CEST 2010


Author: sion
Date: 2010-08-20 16:02:53 +0200 (Fri, 20 Aug 2010)
New Revision: 3767

Modified:
   branches/OpenDNSSEC-sion/enforcer/ksm/ksm_import.c
   branches/OpenDNSSEC-sion/enforcer/ksm/ksm_list.c
   branches/OpenDNSSEC-sion/enforcer/utils/ksmutil.c
Log:
Low level warning if key backup finds no work to do. List now indicates that prepared keys need to be committed.


Modified: branches/OpenDNSSEC-sion/enforcer/ksm/ksm_import.c
===================================================================
--- branches/OpenDNSSEC-sion/enforcer/ksm/ksm_import.c	2010-08-20 11:41:33 UTC (rev 3766)
+++ branches/OpenDNSSEC-sion/enforcer/ksm/ksm_import.c	2010-08-20 14:02:53 UTC (rev 3767)
@@ -494,7 +494,33 @@
 {
     char*       sql = NULL;     /* SQL query */
     int         status = 0;     /* Status return */
+    int         count = -1;     /* How many keys get marked */
 
+    /* Count how many we will mark */
+    sql = DqsCountInit("keypairs");
+    if (repo_id != -1) {
+        DqsConditionInt(&sql, "securitymodule_id", DQS_COMPARE_EQ, repo_id, 0);
+        StrAppend(&sql, " and pre_backup is null");
+    } else {
+        StrAppend(&sql, " where pre_backup is null");
+    }
+    DqsEnd(&sql);
+
+    /* Execute query and free up the query string */
+    status = DbIntQuery(DbHandle(), &count, sql);
+    DqsFree(sql);
+    
+    if (status != 0)
+    {
+        status = MsgLog(KSM_SQLFAIL, DbErrmsg(DbHandle()));
+        return status;
+	}
+
+    if (count == 0) {
+        /* No work to do */
+        return -1;
+    }
+
     /* Update rows */
     sql = DusInit("keypairs");
     DusSetString(&sql, "PRE_BACKUP", datetime, 0);
@@ -531,7 +557,35 @@
 {
     char*       sql = NULL;     /* SQL query */
     int         status = 0;     /* Status return */
+    int         count = -1;     /* How many keys get marked */
 
+    /* Count how many we will mark */
+    sql = DqsCountInit("keypairs");
+    if (repo_id != -1) {
+        DqsConditionInt(&sql, "securitymodule_id", DQS_COMPARE_EQ, repo_id, 0);
+        StrAppend(&sql, " and pre_backup is not null");
+        StrAppend(&sql, " and backup is null");
+    } else {
+        StrAppend(&sql, " where pre_backup is not null");
+        StrAppend(&sql, " and backup is null");
+    }
+    DqsEnd(&sql);
+
+    /* Execute query and free up the query string */
+    status = DbIntQuery(DbHandle(), &count, sql);
+    DqsFree(sql);
+    
+    if (status != 0)
+    {
+        status = MsgLog(KSM_SQLFAIL, DbErrmsg(DbHandle()));
+        return status;
+	}
+
+    if (count == 0) {
+        /* No work to do */
+        return -1;
+    }
+
     /* Update rows */
     sql = DusInit("keypairs");
     DusSetString(&sql, "PRE_BACKUP", NULL, 0);
@@ -573,7 +627,35 @@
 {
     char*       sql = NULL;     /* SQL query */
     int         status = 0;     /* Status return */
+    int         count = -1;     /* How many keys get marked */
 
+    /* Count how many we will mark */
+    sql = DqsCountInit("keypairs");
+    if (repo_id != -1) {
+        DqsConditionInt(&sql, "securitymodule_id", DQS_COMPARE_EQ, repo_id, 0);
+        StrAppend(&sql, " and pre_backup is not null");
+        StrAppend(&sql, " and backup is null");
+    } else {
+        StrAppend(&sql, " where pre_backup is not null");
+        StrAppend(&sql, " and backup is null");
+    }
+    DqsEnd(&sql);
+
+    /* Execute query and free up the query string */
+    status = DbIntQuery(DbHandle(), &count, sql);
+    DqsFree(sql);
+    
+    if (status != 0)
+    {
+        status = MsgLog(KSM_SQLFAIL, DbErrmsg(DbHandle()));
+        return status;
+	}
+
+    if (count == 0) {
+        /* No work to do */
+        return -1;
+    }
+
     /* Update rows */
     sql = DusInit("keypairs");
     DusSetString(&sql, "BACKUP", datetime, 0);

Modified: branches/OpenDNSSEC-sion/enforcer/ksm/ksm_list.c
===================================================================
--- branches/OpenDNSSEC-sion/enforcer/ksm/ksm_list.c	2010-08-20 11:41:33 UTC (rev 3766)
+++ branches/OpenDNSSEC-sion/enforcer/ksm/ksm_list.c	2010-08-20 14:02:53 UTC (rev 3767)
@@ -75,6 +75,7 @@
     DB_ROW      row2 = NULL;     /* Row data */
 
     char*       temp_date = NULL; /* place to store date returned */
+    char*       temp_pre_date = NULL; /* place to store pre-backup date returned */
     char*       temp_repo = NULL; /* place to store repository returned */
     int         temp_backup_req = 0; /* place to store backuprequired returned */
 
@@ -164,6 +165,47 @@
     DbFreeRow(row2);
     DbStringFree(temp_repo);
 
+    /* List repos which need a backup commit */
+    sql2 = NULL;
+    StrAppend(&sql2, "select s.name from keypairs k, securitymodules s ");
+    StrAppend(&sql2, "where s.id = k.securitymodule_id ");
+    if (repo_id != -1) {
+        StrAppend(&sql2, "and s.id = ");
+        snprintf(stringval, KSM_INT_STR_SIZE, "%d", repo_id);
+        StrAppend(&sql2, stringval);
+    }
+    StrAppend(&sql2, " and k.backup is null");
+    StrAppend(&sql2, " and k.pre_backup is not null");
+    StrAppend(&sql2, " group by s.name order by s.name");
+
+    DusEnd(&sql2);
+
+    status = DbExecuteSql(DbHandle(), sql2, &result2);
+
+    if (status == 0) {
+        status = DbFetchRow(result2, &row2);
+        while (status == 0) {
+            /* Got a row, print it */
+            DbString(row2, 0, &temp_repo);
+
+            printf("Repository %s has keys prepared for back up which have not been committed\n", temp_repo);
+            
+            status = DbFetchRow(result2, &row2);
+        }
+
+        /* Convert EOF status to success */
+
+        if (status == -1) {
+            status = 0;
+        }
+
+        DbFreeResult(result2);
+    }
+
+    DusFree(sql2);
+    DbFreeRow(row2);
+    DbStringFree(temp_repo);
+
     return status;
 }
 

Modified: branches/OpenDNSSEC-sion/enforcer/utils/ksmutil.c
===================================================================
--- branches/OpenDNSSEC-sion/enforcer/utils/ksmutil.c	2010-08-20 11:41:33 UTC (rev 3766)
+++ branches/OpenDNSSEC-sion/enforcer/utils/ksmutil.c	2010-08-20 14:02:53 UTC (rev 3767)
@@ -1715,17 +1715,21 @@
     if (strncmp(qualifier, "PREPARE", 7) == 0 ||
             strncmp(qualifier, "DONE", 4) == 0 ) {
         status = KsmMarkPreBackup(repo_id, datetime);
-        if (status != 0) {
+        if (status == -1) {
+            printf("There were no keys to mark\n");
+        }
+        else if (status != 0) {
             printf("Error: failed to mark pre_backup as done\n");
             db_disconnect(lock_fd);
             StrFree(datetime);
             return status;
-        }
-        if (strncmp(qualifier, "PREPARE", 7) == 0) {
-            if (o_repository != NULL) {
-                printf("Marked repository %s as pre-backed up at %s\n", o_repository, datetime);
-            } else {
-                printf("Marked all repositories as pre-backed up at %s\n", datetime);
+        } else {
+            if (strncmp(qualifier, "PREPARE", 7) == 0) {
+                if (o_repository != NULL) {
+                    printf("Marked repository %s as pre-backed up at %s\n", o_repository, datetime);
+                } else {
+                    printf("Marked all repositories as pre-backed up at %s\n", datetime);
+                }
             }
         }
     }
@@ -1734,33 +1738,40 @@
     if (strncmp(qualifier, "COMMIT", 6) == 0 ||
             strncmp(qualifier, "DONE", 4) == 0 ) {
         status = KsmMarkBackup(repo_id, datetime);
-        if (status != 0) {
+        if (status == -1) {
+            printf("There were no keys to mark\n");
+        }
+        else if (status != 0) {
             printf("Error: failed to mark backup as done\n");
             db_disconnect(lock_fd);
             StrFree(datetime);
             return status;
-        }
-
-        if (o_repository != NULL) {
-            printf("Marked repository %s as backed up at %s\n", o_repository, datetime);
         } else {
-            printf("Marked all repositories as backed up at %s\n", datetime);
+            if (o_repository != NULL) {
+                printf("Marked repository %s as backed up at %s\n", o_repository, datetime);
+            } else {
+                printf("Marked all repositories as backed up at %s\n", datetime);
+            }
         }
     }
 
     /* Finally rollback */
     if (strncmp(qualifier, "ROLLBACK", 6) == 0 ) {
         status = KsmRollbackMarkPreBackup(repo_id);
-        if (status != 0) {
+        if (status == -1) {
+            printf("There were no keys to rollback\n");
+        }
+        else if (status != 0) {
             printf("Error: failed to mark backup as done\n");
             db_disconnect(lock_fd);
             StrFree(datetime);
             return status;
-        }
-        if (o_repository != NULL) {
-            printf("Rolled back pre-backup of repository %s\n", o_repository);
         } else {
-            printf("Rolled back pre-backup of all repositories\n");
+            if (o_repository != NULL) {
+                printf("Rolled back pre-backup of repository %s\n", o_repository);
+            } else {
+                printf("Rolled back pre-backup of all repositories\n");
+            }
         }
     }
 




More information about the Opendnssec-commits mailing list