Blame SOURCES/mod_revocator-kill.patch

3515f1
diff -upN --recursive mod_revocator-1.0.3/crlhelper.cpp mod_revocator-1.0.3-kill/crlhelper.cpp
3515f1
--- mod_revocator-1.0.3/crlhelper.cpp	2010-04-13 10:11:12.000000000 -0400
3515f1
+++ mod_revocator-1.0.3-kill/crlhelper.cpp	2010-11-17 13:53:07.000000000 -0500
3515f1
@@ -18,6 +18,7 @@
3515f1
 #include <sys/types.h>
3515f1
 #include <sys/ipc.h>
3515f1
 #include <sys/sem.h>
3515f1
+#include <signal.h>
3515f1
 #include <nss.h>
3515f1
 #include <nspr.h>
3515f1
 #include <secitem.h>
3515f1
@@ -107,6 +108,7 @@ int main(int argc, char ** argv)
3515f1
     PRPollDesc pd;
3515f1
     PRIntervalTime timeout = PR_INTERVAL_NO_TIMEOUT;
3515f1
     int semid;
3515f1
+    pid_t parent_pid;
3515f1
     union semun semarg;
3515f1
     char buf[4096];
3515f1
     char url[4096];
3515f1
@@ -124,18 +126,19 @@ int main(int argc, char ** argv)
3515f1
     while (fd < fdlimit)
3515f1
         close(fd++);
3515f1
 
3515f1
-    if (argc < 3 || argc > 4) {
3515f1
-        fprintf(stderr, "Usage: crlhelper <semid> <directory> <prefix>\n");
3515f1
+    if (argc < 4 || argc > 5) {
3515f1
+        fprintf(stderr, "Usage: crlhelper <semid> <parentpid> <directory> <prefix>\n");
3515f1
         exit(1);
3515f1
     }
3515f1
 
3515f1
     semid = strtol(argv[1], NULL, 10);
3515f1
+    parent_pid = strtol(argv[2], NULL, 10);
3515f1
 
3515f1
     /* Initialize NSPR */
3515f1
     PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 256);
3515f1
  
3515f1
     /* Initialize NSS and open the certificate database read-only. */
3515f1
-    rv = NSS_Initialize(argv[2], argc == 4 ? argv[3] : NULL, argc == 4 ? argv[3] : NULL, "secmod.db", NSS_INIT_READONLY);
3515f1
+    rv = NSS_Initialize(argv[3], argc == 5 ? argv[4] : NULL, argc == 5 ? argv[4] : NULL, "secmod.db", NSS_INIT_READONLY);
3515f1
 
3515f1
     if (rv != SECSuccess) {
3515f1
         fprintf(stderr, "Unable to initialize NSS database: %d\n", rv);
3515f1
@@ -187,6 +190,10 @@ int main(int argc, char ** argv)
3515f1
                 continue;
3515f1
             }
3515f1
 #endif
3515f1
+            if (!(strcmp(url, "kill"))) {
3515f1
+                kill(parent_pid, SIGTERM);
3515f1
+                continue;
3515f1
+            }
3515f1
 
3515f1
             /*
3515f1
              * TODO: 
3515f1
diff -upN --recursive mod_revocator-1.0.3/crlmanager.cpp mod_revocator-1.0.3-kill/crlmanager.cpp
3515f1
--- mod_revocator-1.0.3/crlmanager.cpp	2010-04-13 10:11:11.000000000 -0400
3515f1
+++ mod_revocator-1.0.3-kill/crlmanager.cpp	2010-11-17 13:53:07.000000000 -0500
3515f1
@@ -66,13 +66,19 @@ RevStatus CRLInstance :: DownloadCRL(con
3515f1
     sb.sem_op = -1;
3515f1
     sb.sem_flg = SEM_UNDO;
3515f1
     if (semop(crlm->semid, &sb, 1) == -1) {
3515f1
-        perror("semop reserve resource");
3515f1
+        mystatus.setDetailedError(REV_ERROR_SEMAPHORE_ERROR,
3515f1
+                                  "Unable to reserve semaphore resource");
3515f1
+        return mystatus;
3515f1
+        /* perror("semop reserve resource"); */
3515f1
     }
3515f1
     void* data = get_crl(crlm->infd, crlm->outfd, inurl, timeout, lastfetchtime, &len, mystatus);
3515f1
     /* unlock the pipe */
3515f1
     sb.sem_op = 1;
3515f1
     if (semop(crlm->semid, &sb, 1) == -1) {
3515f1
-        perror("semop free resource id");
3515f1
+        mystatus.setDetailedError(REV_ERROR_SEMAPHORE_ERROR,
3515f1
+                                  "Unable to free semaphore resource");
3515f1
+        return mystatus;
3515f1
+        /* perror("semop free resource id"); */
3515f1
     }
3515f1
 
3515f1
     /* We have a special case. If we have an HTTP request and the server
3515f1
diff -upN --recursive mod_revocator-1.0.3/mod_rev.c mod_revocator-1.0.3-kill/mod_rev.c
3515f1
--- mod_revocator-1.0.3/mod_rev.c	2010-04-13 10:11:11.000000000 -0400
3515f1
+++ mod_revocator-1.0.3-kill/mod_rev.c	2010-11-19 18:43:08.000000000 -0500
3515f1
@@ -58,6 +58,8 @@ SECStatus ShutdownRevocation(void *data)
3515f1
 
3515f1
 static pid_t parent_pid;
3515f1
 
3515f1
+int infd, outfd; /* file descriptors for our semaphore-controlled pipe */
3515f1
+
3515f1
 apr_status_t rev_module_kill(void *data)
3515f1
 {
3515f1
     server_rec *s = (server_rec *)data;
3515f1
@@ -70,6 +72,12 @@ apr_status_t rev_module_kill(void *data)
3515f1
     return APR_SUCCESS;
3515f1
 }
3515f1
 
3515f1
+static void kill_apache(void) {
3515f1
+    char buffer[1024];
3515f1
+    PR_snprintf(buffer, sizeof(buffer), "%lld %s", 0, "kill");
3515f1
+    write(outfd, buffer, strlen(buffer));
3515f1
+}
3515f1
+
3515f1
 /*
3515f1
  * Create the global config
3515f1
  */
3515f1
@@ -196,6 +204,7 @@ PRBool NESRevocationFailureNotification(
3515f1
             ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL,
3515f1
                 "%s : %s %s",
3515f1
                 errMsg, url, subject ? subject : "");
3515f1
+            return PR_TRUE;
3515f1
         } else {
3515f1
             ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
3515f1
                 "Error updating CRL %s %s : %s",
3515f1
@@ -208,8 +217,8 @@ PRBool NESRevocationFailureNotification(
3515f1
         if (critical && revocatorInitialized)
3515f1
         {
3515f1
             ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
3515f1
-                "Critical CRL update failure. Shutting down server. %d", parent_pid);
3515f1
-            kill(parent_pid, 15);
3515f1
+                "Critical CRL update failure. Shutting down server pid %d", parent_pid);
3515f1
+            kill_apache();
3515f1
         }
3515f1
     }
3515f1
     return PR_TRUE;
3515f1
@@ -298,11 +307,11 @@ PRBool NESRevocationDownloadNotification
3515f1
                 {
3515f1
                     /* this CRL is outdated, log it */
3515f1
                     ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
3515f1
-                        "CRL %s %s is outdated. Shutting down server. %d",
3515f1
+                        "CRL %s %s is outdated. Shutting down server pid %d",
3515f1
                          url, subject, parent_pid);
3515f1
 
3515f1
                     /* we have to shut down the web server */
3515f1
-                    kill(parent_pid, 15);
3515f1
+                    kill_apache();
3515f1
                 }
3515f1
             }
3515f1
 
3515f1
@@ -335,6 +344,25 @@ init_Module(apr_pool_t *p, apr_pool_t *p
3515f1
         
3515f1
     sc->nInitCount++;
3515f1
 
3515f1
+    if (sc->nInitCount == 1) {
3515f1
+        struct sembuf sb;
3515f1
+        sc->semid = semget(IPC_PRIVATE, 1, IPC_CREAT | IPC_EXCL | 0600);
3515f1
+        if (sc->semid == -1) {
3515f1
+            ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
3515f1
+                "Unable to obtain semaphore.");
3515f1
+            nss_die();
3515f1
+        }
3515f1
+
3515f1
+        /* Initialize the semaphore */
3515f1
+        sb.sem_num = 0;
3515f1
+        sb.sem_op = 1;
3515f1
+        sb.sem_flg = 0;
3515f1
+        if ((semop(sc->semid, &sb, 1)) == -1) {
3515f1
+            ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
3515f1
+                "Unable to initialize semaphore.");
3515f1
+            nss_die();
3515f1
+        }
3515f1
+
3515f1
     /* The first pass through this function will create the semaphore that
3515f1
      * will be used to lock the pipe. The user is still root at that point
3515f1
      * so for any later calls the semaphore ops will fail with permission
3515f1
@@ -345,12 +373,11 @@ init_Module(apr_pool_t *p, apr_pool_t *p
3515f1
         status.sem_perm.uid = user_id;
3515f1
         semctl(sc->semid,0,IPC_SET,&status);
3515f1
     }
3515f1
-
3515f1
-    if (sc->nInitCount == 1) {
3515f1
+    } else if (sc->nInitCount == 2) {
3515f1
         const char * child_argv[5];
3515f1
         apr_status_t rv;
3515f1
-        struct sembuf sb;
3515f1
         char sembuf[32];
3515f1
+        char pidbuf[32];
3515f1
 
3515f1
         if (sc->crlhelper == NULL) {
3515f1
             ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
3515f1
@@ -358,29 +385,16 @@ init_Module(apr_pool_t *p, apr_pool_t *p
3515f1
             nss_die();
3515f1
         }
3515f1
 
3515f1
-        sc->semid = semget(IPC_PRIVATE, 1, IPC_CREAT | IPC_EXCL | 0600);
3515f1
-        if (sc->semid == -1) {
3515f1
-            ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
3515f1
-                "Unable to obtain semaphore.");
3515f1
-            nss_die();
3515f1
-        }
3515f1
-
3515f1
-        /* Initialize the semaphore */
3515f1
-        sb.sem_num = 0;
3515f1
-        sb.sem_op = 1;
3515f1
-        sb.sem_flg = 0;
3515f1
-        if ((semop(sc->semid, &sb, 1)) == -1) {
3515f1
-            ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
3515f1
-                "Unable to initialize semaphore.");
3515f1
-            nss_die();
3515f1
-        }
3515f1
-
3515f1
         PR_snprintf(sembuf, 32, "%d", sc->semid);
3515f1
+        PR_snprintf(pidbuf, 32, "%d", parent_pid);
3515f1
         child_argv[0] = sc->crlhelper;
3515f1
         child_argv[1] = sembuf;
3515f1
-        child_argv[2] = sc->database;
3515f1
-        child_argv[3] = sc->dbprefix;
3515f1
-        child_argv[4] = NULL;
3515f1
+        child_argv[2] = pidbuf;
3515f1
+        child_argv[3] = sc->database;
3515f1
+        child_argv[4] = sc->dbprefix;
3515f1
+        child_argv[5] = NULL;
3515f1
+        ap_log_error(APLOG_MARK, APLOG_INFO, 0, s,
3515f1
+            "Parent PID is %d", parent_pid);
3515f1
 
3515f1
         rv = apr_procattr_create(&sc->procattr, s->process->pool);
3515f1
 
3515f1
@@ -428,7 +442,6 @@ InitRevocation(apr_pool_t *p, server_rec
3515f1
     void* critical = (void *)sc->crlcritical;
3515f1
     Rev_SetFailureCallbackEntryPoint setfcb = NULL;
3515f1
     Rev_SetDownloadCallbackEntryPoint setncb = NULL;
3515f1
-    int infd, outfd;
3515f1
 
3515f1
     /* Do nothing until Apache is ready to run */
3515f1
     if (sc->nInitCount < 2) return APR_SUCCESS;
3515f1
@@ -499,7 +512,10 @@ InitRevocation(apr_pool_t *p, server_rec
3515f1
             free(configstring);
3515f1
             apr_dso_unload(dlh);
3515f1
             ap_log_error(APLOG_MARK, APLOG_ERR, 0, base_server,
3515f1
-                 "Unable to load secmod module: %d", PR_GetError());
3515f1
+                 "Unable to load Revocation module, NSS error %d. %s", PR_GetError(), critical ? "" : "CRL retrieval will be disabled.");
3515f1
+            if (critical) {
3515f1
+                kill_apache();
3515f1
+            }
3515f1
             return APR_EGENERAL;
3515f1
         }
3515f1
         free(configstring);
3515f1
diff -upN --recursive mod_revocator-1.0.3/reverror.h mod_revocator-1.0.3-kill/reverror.h
3515f1
--- mod_revocator-1.0.3/reverror.h	2007-06-05 10:38:58.000000000 -0400
3515f1
+++ mod_revocator-1.0.3-kill/reverror.h	2010-11-17 13:53:07.000000000 -0500
3515f1
@@ -54,6 +54,7 @@ const PRInt32 REV_ERROR_BAD_ISSUER_USAGE
3515f1
 const PRInt32 REV_ERROR_MISSING_CRL_DATA    = 1014;
3515f1
 const PRInt32 REV_ERROR_BAD_ISSUER_TRUST    = 1015;
3515f1
 const PRInt32 REV_ERROR_NOUPDATE_AVAILABLE  = 1016;
3515f1
+const PRInt32 REV_ERROR_SEMAPHORE_ERROR     = 1017;
3515f1
 
3515f1
 #endif
3515f1