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/05/02 15:17:23 UTC

svn commit: r770951 - in /commons/sandbox/runtime/trunk/src/main/native: Makefile.msc.in include/arch/windows/acr_arch_private.h os/win32/user.c os/win32/wusec.c

Author: mturk
Date: Sat May  2 13:17:23 2009
New Revision: 770951

URL: http://svn.apache.org/viewvc?rev=770951&view=rev
Log:
Move common security functions to a separate file

Added:
    commons/sandbox/runtime/trunk/src/main/native/os/win32/wusec.c   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
    commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
    commons/sandbox/runtime/trunk/src/main/native/os/win32/user.c

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=770951&r1=770950&r2=770951&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Sat May  2 13:17:23 2009
@@ -80,6 +80,7 @@
 	$(SRCDIR)/os/win32/group.$(OBJ) \
 	$(SRCDIR)/os/win32/user.$(OBJ) \
 	$(SRCDIR)/os/win32/uuid.$(OBJ) \
+	$(SRCDIR)/os/win32/wusec.$(OBJ) \
 	$(SRCDIR)/os/win32/main.res
 
 TEST_OBJS= \

Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h?rev=770951&r1=770950&r2=770951&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h Sat May  2 13:17:23 2009
@@ -60,12 +60,13 @@
     JNIEXPORT RT JNICALL Java_org_apache_commons_runtime_platform_windows_##CL##_##FN
 
 /**
- * Local functions from user.c
+ * Local functions from wusec.c
  */
 PSID         ACR_GetSidFromAccountName(LPCWSTR name, PSID_NAME_USE sidtype);
 SID_NAME_USE ACR_GetAccountNameFromSid(LPWSTR buf, size_t blen, PSID psid);
 SID_NAME_USE ACR_GetAccountSidType(PSID psid);
 LPVOID       ACR_GetTokenInformation(JNIEnv *_E, HANDLE h, TOKEN_INFORMATION_CLASS ic);
+void         ACR_GetUserHomePath(LPWSTR buf, DWORD blen, PSID sid);
 
 /**
  * Heap allocation from main.c

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/user.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/user.c?rev=770951&r1=770950&r2=770951&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/user.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/user.c Sat May  2 13:17:23 2009
@@ -102,133 +102,6 @@
         return NULL;
 }
 
-PSID ACR_GetSidFromAccountName(LPCWSTR name, PSID_NAME_USE sidtype)
-{
-    WCHAR domain[MAX_PATH];
-    DWORD domlen = MAX_PATH;
-    DWORD sidlen = 0;
-    PSID  sid = NULL;
-
-    *sidtype = -1;
-    LookupAccountNameW(NULL, name, NULL, &sidlen,
-                       NULL, &domlen, sidtype);
-    if (sidlen) {
-        /* Give it back on the second pass with proper sidlen
-         */
-        if (!(sid = malloc(sidlen)))
-            return NULL;
-        domlen = MAX_PATH;
-        if (!LookupAccountNameW(NULL, name, sid, &sidlen,
-                                domain, &domlen, sidtype)) {
-            free(sid);
-            sid = NULL;
-        }
-    }
-    return sid;
-}
-
-SID_NAME_USE ACR_GetAccountNameFromSid(LPWSTR buf, size_t blen, PSID psid)
-{
-    WCHAR domain[MAX_PATH];
-    DWORD domlen = MAX_PATH;
-    DWORD acclen = (DWORD)blen;
-    SID_NAME_USE sidtype;
-
-    if (!LookupAccountSidW(NULL, psid,
-                           buf, &acclen,
-                           domain, &domlen,
-                           &sidtype)) {
-
-        sidtype = -1;
-        buf[0]  = L'\0';
-    }
-    return sidtype;
-}
-
-SID_NAME_USE ACR_GetAccountSidType(PSID psid)
-{
-    WCHAR domname[MAX_PATH];
-    WCHAR accname[MAX_PATH];
-    DWORD domlen = MAX_PATH;
-    DWORD acclen = MAX_PATH;
-    SID_NAME_USE sidtype;
-
-    if (!LookupAccountSidW(NULL, psid,
-                           accname, &acclen,
-                           domname, &domlen,
-                           &sidtype)) {
-
-        sidtype = -1;
-    }
-    return sidtype;
-}
-
-LPVOID ACR_GetTokenInformation(JNIEnv *_E, HANDLE h,
-                               TOKEN_INFORMATION_CLASS ic)
-{
-    LPVOID rv;
-    DWORD  sz = 0;
-    DWORD  rc;
-
-    GetTokenInformation(h, ic, NULL, sz, &sz);
-    if ((rc = GetLastError()) != ERROR_INSUFFICIENT_BUFFER) {
-        if(_E) {
-            if (ACR_STATUS_IS_EACCES(ACR_FROM_OS_ERROR(rc)))
-                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
-            else if (rc != NERR_UserNotFound && rc != NERR_GroupNotFound)
-                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO,
-                                   ACR_FROM_OS_ERROR(rc));
-        }
-        return NULL;
-    }
-    if (!(rv = ACR_Malloc(_E, THROW_FMARK, sz))) {
-        return NULL;
-    }
-    if (!GetTokenInformation(h, ic, rv, sz, &sz)) {
-        if(_E) {
-            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO,
-                               ACR_GET_OS_ERROR());
-        }
-        free(rv);
-        rv = NULL;
-    }
-    return rv;
-}
-
-static void GetUserHomePath(LPWSTR buf, DWORD blen, PSID sid)
-{
-    LPWSTR ssid = NULL;
-    WCHAR regk[ACR_MBUFF_SIZ];
-    HKEY  key;
-    DWORD rv, type;
-    DWORD keylen;
-
-    buf[0] = L'\0';
-
-    if (!ConvertSidToStringSidW(sid, &ssid)) {
-        return;
-    }
-
-    wcscpy(regk, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\");
-    wcscat(regk, ssid);
-    LocalFree(ssid);
-
-    if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, regk, 0,
-                     KEY_QUERY_VALUE, &key) == ERROR_SUCCESS) {
-        keylen = sizeof(regk);
-        rv = RegQueryValueExW(key, L"ProfileImagePath", NULL, &type,
-                                   (void *)regk, &keylen);
-        RegCloseKey(key);
-        if (rv != ERROR_SUCCESS)
-            return;
-        if (type == REG_SZ)
-            wcsncpy(buf, regk, blen);
-        else if (type == REG_EXPAND_SZ)
-            ExpandEnvironmentStringsW(regk, buf, blen);
-        buf[blen] = L'\0';
-    }
-}
-
 static int sid_descriptor_handler(ACR_JNISTDARGS, acr_descriptor_cb_type_e t,
                                   acr_descriptor_cb_t *cb)
 {
@@ -289,7 +162,7 @@
         if (pb->usri2_home_dir && *pb->usri2_home_dir)
             SET_IFIELD_W(0003, usr, pb->usri2_home_dir);
         else {
-            GetUserHomePath(home, MAX_PATH, sid);
+            ACR_GetUserHomePath(home, MAX_PATH, sid);
             SET_IFIELD_C(0003, usr, home);
         }
         NetApiBufferFree(pb);
@@ -355,7 +228,7 @@
         if (pb->usri2_home_dir && *pb->usri2_home_dir)
             SET_IFIELD_W(0003, usr, pb->usri2_home_dir);
         else {
-            GetUserHomePath(home, MAX_PATH, sid);
+            ACR_GetUserHomePath(home, MAX_PATH, sid);
             SET_IFIELD_C(0003, usr, home);
         }
         NetApiBufferFree(pb);
@@ -460,7 +333,6 @@
     usr = ACR_GetTokenInformation(_E, token, TokenOwner);
     if (usr) {
         SID_NAME_USE sidtype = ACR_GetAccountSidType(usr->Owner);
-        fprintf(stderr, "NUGI is %d\n", sidtype);
         if (sidtype == SidTypeUser)
             uid = ACR_UserObjectCreateFromId(_E, usr->Owner);
         free(usr);

Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/wusec.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/wusec.c?rev=770951&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/wusec.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/wusec.c Sat May  2 13:17:23 2009
@@ -0,0 +1,153 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "acr.h"
+#include "acr_private.h"
+#include "acr_arch.h"
+#include "acr_clazz.h"
+#include "acr_error.h"
+#include "acr_memory.h"
+#include "acr_string.h"
+#include "acr_descriptor.h"
+#include "acr_users.h"
+
+PSID ACR_GetSidFromAccountName(LPCWSTR name, PSID_NAME_USE sidtype)
+{
+    WCHAR domain[MAX_PATH];
+    DWORD domlen = MAX_PATH;
+    DWORD sidlen = 0;
+    PSID  sid = NULL;
+
+    *sidtype = -1;
+    LookupAccountNameW(NULL, name, NULL, &sidlen,
+                       NULL, &domlen, sidtype);
+    if (sidlen) {
+        /* Give it back on the second pass with proper sidlen
+         */
+        if (!(sid = malloc(sidlen)))
+            return NULL;
+        domlen = MAX_PATH;
+        if (!LookupAccountNameW(NULL, name, sid, &sidlen,
+                                domain, &domlen, sidtype)) {
+            free(sid);
+            sid = NULL;
+        }
+    }
+    return sid;
+}
+
+SID_NAME_USE ACR_GetAccountNameFromSid(LPWSTR buf, size_t blen, PSID psid)
+{
+    WCHAR domain[MAX_PATH];
+    DWORD domlen = MAX_PATH;
+    DWORD acclen = (DWORD)blen;
+    SID_NAME_USE sidtype;
+
+    if (!LookupAccountSidW(NULL, psid,
+                           buf, &acclen,
+                           domain, &domlen,
+                           &sidtype)) {
+
+        sidtype = -1;
+        buf[0]  = L'\0';
+    }
+    return sidtype;
+}
+
+SID_NAME_USE ACR_GetAccountSidType(PSID psid)
+{
+    WCHAR domname[MAX_PATH];
+    WCHAR accname[MAX_PATH];
+    DWORD domlen = MAX_PATH;
+    DWORD acclen = MAX_PATH;
+    SID_NAME_USE sidtype;
+
+    if (!LookupAccountSidW(NULL, psid,
+                           accname, &acclen,
+                           domname, &domlen,
+                           &sidtype)) {
+
+        sidtype = -1;
+    }
+    return sidtype;
+}
+
+LPVOID ACR_GetTokenInformation(JNIEnv *_E, HANDLE h,
+                               TOKEN_INFORMATION_CLASS ic)
+{
+    LPVOID rv;
+    DWORD  sz = 0;
+    DWORD  rc;
+
+    GetTokenInformation(h, ic, NULL, sz, &sz);
+    if ((rc = GetLastError()) != ERROR_INSUFFICIENT_BUFFER) {
+        if(_E) {
+            if (ACR_STATUS_IS_EACCES(ACR_FROM_OS_ERROR(rc)))
+                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
+            else if (rc != NERR_UserNotFound && rc != NERR_GroupNotFound)
+                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO,
+                                   ACR_FROM_OS_ERROR(rc));
+        }
+        return NULL;
+    }
+    if (!(rv = ACR_Malloc(_E, THROW_FMARK, sz))) {
+        return NULL;
+    }
+    if (!GetTokenInformation(h, ic, rv, sz, &sz)) {
+        if(_E) {
+            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO,
+                               ACR_GET_OS_ERROR());
+        }
+        free(rv);
+        rv = NULL;
+    }
+    return rv;
+}
+
+void ACR_GetUserHomePath(LPWSTR buf, DWORD blen, PSID sid)
+{
+    LPWSTR ssid = NULL;
+    WCHAR regk[ACR_MBUFF_SIZ];
+    HKEY  key;
+    DWORD rv, type;
+    DWORD keylen;
+
+    buf[0] = L'\0';
+
+    if (!ConvertSidToStringSidW(sid, &ssid)) {
+        return;
+    }
+
+    wcscpy(regk, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\");
+    wcscat(regk, ssid);
+    LocalFree(ssid);
+
+    if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, regk, 0,
+                     KEY_QUERY_VALUE, &key) == ERROR_SUCCESS) {
+        keylen = sizeof(regk);
+        rv = RegQueryValueExW(key, L"ProfileImagePath", NULL, &type,
+                                   (void *)regk, &keylen);
+        RegCloseKey(key);
+        if (rv != ERROR_SUCCESS)
+            return;
+        if (type == REG_SZ)
+            wcsncpy(buf, regk, blen);
+        else if (type == REG_EXPAND_SZ)
+            ExpandEnvironmentStringsW(regk, buf, blen);
+        buf[blen] = L'\0';
+    }
+}
+

Propchange: commons/sandbox/runtime/trunk/src/main/native/os/win32/wusec.c
------------------------------------------------------------------------------
    svn:eol-style = native