Author: mturk
Date: Fri Aug  7 14:24:41 2009
New Revision: 802019

URL: http://svn.apache.org/viewvc?rev=802019&view=rev
Log:
Use sha1 for resource name calculation

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr_crypto.h
    commons/sandbox/runtime/trunk/src/main/native/os/win32/pmutex.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/shm.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c
    commons/sandbox/runtime/trunk/src/main/native/test/testcase.c

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_crypto.h
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_crypto.h?rev=802019&r1=802018&r2=802019&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_crypto.h 
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_crypto.h Fri Aug  
7 14:24:41 2009
@@ -35,15 +35,7 @@
  * Size of the SHA1 DIGEST
  */
 #define ACR_SHA1_DIGESTSIZE 20
-
-/**
- * Define the Magic String prefix that identifies a password as being
- * hashed using our algorithm.
- */
-#define ACR_SHA1PW_ID "{SHA}"
-
-/** length of the SHA Password */
-#define ACR_SHA1PW_IDLEN 5
+#define ACR_SHA1_BASE16SIZE 41
 
 /** @see acr_sha1_ctx_t */
 typedef struct acr_sha1_ctx_t acr_sha1_ctx_t;

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/pmutex.c
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/pmutex.c?rev=802019&r1=802018&r2=802019&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/pmutex.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/pmutex.c Fri Aug  7 
14:24:41 2009
@@ -38,7 +38,7 @@
     int rc;
     HANDLE m;
     wchar_t *reskey;
-    wchar_t  keybuf[256];
+    wchar_t  keybuf[64];
 
     if (fname == NULL) {
         reskey = NULL;
@@ -63,11 +63,12 @@
 {
     int rc;
     HANDLE m;
-    wchar_t  reskey[256];
+    wchar_t  reskey[64];
 
     if (!fname) {
         /* Reinitializing unnamed mutexes is a noop in the Unix code. */
-        return APR_SUCCESS;
+        ACR_SET_OS_ERROR(ACR_ENOTIMPL);
+        return -1;
     }
     /* res_name_from_filename turns file into a pseudo-name
      * without slashes or backslashes, and prepends the \global

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/shm.c
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/shm.c?rev=802019&r1=802018&r2=802019&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/shm.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/shm.c Fri Aug  7 
14:24:41 2009
@@ -96,8 +96,8 @@
     acr_size_t  nbytes;
     HANDLE      hmap, hfile;
     void       *base;
-    wchar_t    *mapkey;
-    wchar_t     keybuf[256];
+    wchar_t    *reskey;
+    wchar_t     keybuf[64];
     DWORD       sizelo, sizehi;
     LPDWORD     lpdwhi = NULL;
 
@@ -132,7 +132,7 @@
     /* Check if they want anonymous or name-based shared memory */
     if (filename == NULL) {
         hfile  = INVALID_HANDLE_VALUE;
-        mapkey = NULL;
+        reskey = NULL;
     }
     /* Name-based shared memory */
     else {
@@ -161,11 +161,11 @@
          * without slashes or backslashes, and prepends the \global
          * prefix on Win2K and later
          */
-        mapkey = res_name_from_filenamew(1, keybuf, filename);
+        reskey = res_name_from_filenamew(1, keybuf, filename);
 
     }
     hmap = CreateFileMappingW(hfile, NULL, PAGE_READWRITE,
-                              sizehi, sizelo, mapkey);
+                              sizehi, sizelo, reskey);
     rc = GetLastError();
     if (hfile != INVALID_HANDLE_VALUE)
         CloseHandle(hfile);
@@ -231,7 +231,7 @@
     int rc = 0;
     acr_shm_t *shm = NULL;
     HANDLE     hmap;
-    wchar_t    mapkey[256];
+    wchar_t    reskey[64];
     void      *base;
 
     if (!filename) {
@@ -241,8 +241,8 @@
     shm = ACR_Calloc(_E, THROW_FMARK, sizeof(acr_shm_t));
     if (!shm)
         return -1;
-    res_name_from_filenamew(1, mapkey, filename);
-    hmap = OpenFileMappingW(FILE_MAP_READ | FILE_MAP_WRITE, FALSE, mapkey);
+    res_name_from_filenamew(1, reskey, filename);
+    hmap = OpenFileMappingW(FILE_MAP_READ | FILE_MAP_WRITE, FALSE, reskey);
     if (!hmap) {
         rc = ACR_GET_OS_ERROR();
         goto cleanup;

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c?rev=802019&r1=802018&r2=802019&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c Fri Aug  7 
14:24:41 2009
@@ -21,32 +21,21 @@
 #include "acr_error.h"
 #include "acr_memory.h"
 #include "acr_string.h"
-#include "acr_descriptor.h"
+#include "acr_crypto.h"
 
 wchar_t *res_name_from_filenamew(int global, wchar_t *rname,
                                  const wchar_t *fname)
 {
     const wchar_t *prefix;
-    wchar_t       *ch;
-    size_t r, n = wcslen(fname);
+    size_t n = wcslen(fname);
 
     if (global)
         prefix = L"Global\\";
     else
         prefix = L"Local\\";
-    r = wcslen(prefix);
-    if (n > 255 - r) {
-        fname += n - 255 - r;
-        n = 255;
-    }
+
     wcscpy(rname, prefix);
-    wcsncat(rname, fname, 255 - r);
-    for (ch = rname + r; *ch; ++ch) {
-        if (*ch == L':' || *ch == L'/' || *ch == L'\\')
-            *ch = L'_';
-        else
-            *ch = towupper(*ch);
-    }
+    ACR_Sha1Base16W(fname, n, rname + wcslen(prefix)); 
 
     return rname;
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/test/testcase.c
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/testcase.c?rev=802019&r1=802018&r2=802019&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testcase.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testcase.c Fri Aug  7 
14:24:41 2009
@@ -649,6 +649,11 @@
     return r;
 }
 
+#if defined(WIN32)
+static const wchar_t *shr_name = L"shared";
+#else
+static const char    *shr_name = "shared";
+#endif
 ACR_JNI_EXPORT_DECLARE(jint, TestPrivate, test060)(ACR_JNISTDARGS, jint d)
 {
 
@@ -658,7 +663,7 @@
 ACR_JNI_EXPORT_DECLARE(jint, TestPrivate, test061)(ACR_JNISTDARGS, jint d)
 {
 
-    return ACR_ShmCreate(_E, d, "shared");
+    return ACR_ShmCreate(_E, d, shr_name);
 }
 
 ACR_JNI_EXPORT_DECLARE(jint, TestPrivate, test062)(ACR_JNISTDARGS, jint s)
@@ -668,12 +673,12 @@
 
 ACR_JNI_EXPORT_DECLARE(jint, TestPrivate, test063)(ACR_JNISTDARGS, jint d)
 {
-    return ACR_ShmRemove(_E, "shared");
+    return ACR_ShmRemove(_E, shr_name);
 }
 
 ACR_JNI_EXPORT_DECLARE(jint, TestPrivate, test064)(ACR_JNISTDARGS, jint d)
 {
-    return ACR_ShmAttach(_E, "shared");
+    return ACR_ShmAttach(_E, shr_name);
 }
 
 ACR_JNI_EXPORT_DECLARE(jint, TestPrivate, test065)(ACR_JNISTDARGS, jint s)


Reply via email to