You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/09/15 17:54:40 UTC

svn commit: r815375 - in /commons/sandbox/runtime/trunk/src/main/native: include/acr_signals.h include/arch/windows/acr_arch.h os/win32/signals.c test/testsuite.c

Author: mturk
Date: Tue Sep 15 15:54:39 2009
New Revision: 815375

URL: http://svn.apache.org/viewvc?rev=815375&view=rev
Log:
Few signaling fixes

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr_signals.h
    commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h
    commons/sandbox/runtime/trunk/src/main/native/os/win32/signals.c
    commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_signals.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_signals.h?rev=815375&r1=815374&r2=815375&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_signals.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_signals.h Tue Sep 15 15:54:39 2009
@@ -46,11 +46,22 @@
 
 /**
  * Send a signal to the process.
- * @param sal Signal security key.
+ * @param key Signal security key.
  * @param sig signal to send.
  * @param to pid of the process
  */
-ACR_DECLARE(int) ACR_RaiseSignal(const acr_pchar_t *salt, int signum, int to);
+ACR_DECLARE(int) ACR_RaiseSignal(const acr_pchar_t *key, int signum, int to);
+
+/**
+ * Set the security key for signal messages.
+ * @param key The key to use.
+ * @notice This option is viable on certain platforms only where
+ * we implement our own signaling mechanism between processes.
+ * The key parameter is shared key used to sign the signal message.
+ * The receiver verifies the message and if the signature doesn't
+ * match the signal is rejected.
+ */
+ACR_DECLARE(int) ACR_SignalSetKey(const acr_pchar_t *key);
 
 #ifdef __cplusplus
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h?rev=815375&r1=815374&r2=815375&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h Tue Sep 15 15:54:39 2009
@@ -471,7 +471,7 @@
 #define SIG_SGE     (SIG_PF)4    /* signal gets error     */
 #define SIG_ACK     (SIG_PF)5    /* acknowledge           */
 
-#define sigmask(S)  (1 << ((S) - 1) & 31)
+#define sigmask(S)  (1 << (((S) - 1) & 31))
 #define SIG_BLOCK   1
 #define SIG_UNBLOCK 2
 #define SIG_SETMASK 3
@@ -507,7 +507,7 @@
     if (signo <= 0 || signo >= _NSIG) {
         return ERROR_INVALID_PARAMETER;
     }
-    *set |= (1 << ((signo)-1));
+    *set |= sigmask(signo);
     return 0;
 }
 
@@ -516,7 +516,7 @@
     if (signo <= 0 || signo >= _NSIG) {
         return ERROR_INVALID_PARAMETER;
     }
-    *set &= ~(1 << ((signo)-1));
+    *set &= ~sigmask(signo);
     return 0;
 }
 
@@ -524,11 +524,14 @@
 {
 
     if (signo <= 0 || signo >= _NSIG) {
-        return ERROR_INVALID_PARAMETER;
+        return 0;
     }
-    return (*set & (1 << ((signo)-1))) != 0;
+    return (*set & sigmask(signo)) != 0;
 }
 
+#define sigemptyset(S)  *(S) = 0
+#define sigfillset(S)   *(S) = ~(sigset_t)0
+
 /*
  * ---------------------------------------------------------------------
  * end   of POSIX utilities

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/signals.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/signals.c?rev=815375&r1=815374&r2=815375&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/signals.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/signals.c Tue Sep 15 15:54:39 2009
@@ -75,19 +75,29 @@
                                  DWORD sn, DWORD to)
 {
     acr_sha1_ctx_t sha;
+    unsigned char  salt[ACR_SHA1_DIGEST_LENGTH];
     acr_uint32_t me = GetCurrentProcessId();
     acr_uint32_t tc = GetTickCount();
 
     ACR_SHA1Init(&sha);
     if (key && *key) {
         acr_sha1_ctx_t sk;
-        unsigned char salt[ACR_SHA1_DIGEST_LENGTH];
         ACR_SHA1Init(&sk);
         ACR_SHA1UpdateW(&sk, key, wcslen(key));
         ACR_SHA1Update(&sk, (unsigned char *)&to, sizeof(acr_uint32_t));
         ACR_SHA1Final(salt, &sk);
-        ACR_SHA1Update(&sha, salt, ACR_SHA1_DIGEST_LENGTH);
     }
+    else {
+        /* No security set.
+         * In most of the cases setting security is not needed.
+         * One could write a malicious sofware that when installed
+         * on the box could send signals to what ever process using ACR
+         * by using this API. With security, that software would have to
+         * guess the key as well.
+         */
+        memset(salt, 0, ACR_SHA1_DIGEST_LENGTH);
+    }
+    ACR_SHA1Update(&sha, salt, ACR_SHA1_DIGEST_LENGTH);
     ACR_SHA1Update(&sha, (unsigned char *)&sn, sizeof(acr_uint32_t));
     ACR_SHA1Update(&sha, (unsigned char *)&me, sizeof(acr_uint32_t));
     ACR_SHA1Update(&sha, (unsigned char *)&tc, sizeof(acr_uint32_t));
@@ -106,9 +116,7 @@
     acr_uint32_t me = GetCurrentProcessId();
 
     ACR_SHA1Init(&sha);
-    if (sig_pipe_salt[0] && sig_pipe_salt[1])
-        ACR_SHA1Update(&sha, sig_pipe_salt, ACR_SHA1_DIGEST_LENGTH);
-
+    ACR_SHA1Update(&sha, sig_pipe_salt, ACR_SHA1_DIGEST_LENGTH);
     ACR_SHA1Update(&sha, (unsigned char *)&(msg->signal), sizeof(acr_uint32_t));
     ACR_SHA1Update(&sha, (unsigned char *)&(msg->sender), sizeof(acr_uint32_t));
     ACR_SHA1Update(&sha, (unsigned char *)&(msg->ticket), sizeof(acr_uint32_t));
@@ -125,6 +133,7 @@
 static void default_signal_handler(int sig)
 {
     JNIEnv *_E;
+
     switch (sig) {
         case SIGKILL:
             /* Call the System.exit(9)
@@ -504,6 +513,7 @@
     signal_handlers[SIGTERM] = SIG_DFL;
     signal_handlers[SIGHUP]  = SIG_DFL;
 
+    memset(sig_pipe_salt, 0, sizeof(sig_pipe_salt));
     /* Get the global signal pipe name.
      * Combined from pid and ACR_NUMSIG.
      */
@@ -533,6 +543,7 @@
  */
 DWORD ACR_DeliverSignals()
 {
+    int n = 0;
     LONG  mask;
     DWORD rc = ACR_EINTR;
     /* We are invoked from one of the waiters.
@@ -558,7 +569,7 @@
     while ((mask = (current_signal_queue & ~current_signal_mask))) {
         int i;
         for (i = 1; i < ACR_NUMSIG; i++) {
-            if (mask & sigmask(i)) {
+            if (sigismember(&mask, i)) {
                 SIG_PF sig = signal_handlers[i];
                 switch (i) {
                     case SIGKILL:
@@ -575,7 +586,15 @@
                 sigdelset(&current_signal_queue, i);
                 if (sig != SIG_IGN && sig != SIG_ERR) {
                     LeaveCriticalSection(&signal_lock);
-                    (*sig)(i);
+                    if (sig != SIG_DFL) {
+                        (*sig)(i);
+                    }
+                    else {
+                        /* TODO: Handle defaults
+                         */
+
+
+                    }
                     EnterCriticalSection(&signal_lock);
                     break;
                 }
@@ -584,7 +603,9 @@
                 break;
         }
     }
+    sigemptyset(&current_signal_queue);
     LeaveCriticalSection(&signal_lock);
+
     return rc;
 }
 
@@ -611,7 +632,7 @@
         /* Standard raise() call
          */
         EnterCriticalSection(&signal_lock);
-        current_signal_queue |= sigmask(signum);
+        sigaddset(&current_signal_queue, signum);
         /* Wake up the monitor thread.
          */
         SetEvent(sig_handle_event);
@@ -646,8 +667,9 @@
     acr_sha1_ctx_t sha;
     acr_uint32_t me = GetCurrentProcessId();
 
-    if (!key || !*key)
+    if (!key || !*key) {
         return ACR_EINVAL;
+    }
     ACR_SHA1Init(&sha);
     ACR_SHA1UpdateW(&sha, key, wcslen(key));
     ACR_SHA1Update(&sha, (unsigned char *)&me, sizeof(acr_uint32_t));

Modified: commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c?rev=815375&r1=815374&r2=815375&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c Tue Sep 15 15:54:39 2009
@@ -534,7 +534,7 @@
     if (*argv[0] == 's') {
         printf("Server waiting %d\n", getpid());
 #if defined(WIN32)
-        Sleep(10000);
+        Sleep(20000);
 #endif
     }
     else {