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/04/28 18:14:21 UTC
svn commit: r769446 - in /commons/sandbox/runtime/trunk/src/main/native:
include/acr_users.h os/unix/group.c os/unix/user.c os/win32/group.c
os/win32/user.c
Author: mturk
Date: Tue Apr 28 16:14:20 2009
New Revision: 769446
URL: http://svn.apache.org/viewvc?rev=769446&view=rev
Log:
Make group and user function public
Added:
commons/sandbox/runtime/trunk/src/main/native/include/acr_users.h (with props)
Modified:
commons/sandbox/runtime/trunk/src/main/native/os/unix/group.c
commons/sandbox/runtime/trunk/src/main/native/os/unix/user.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/group.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/user.c
Added: commons/sandbox/runtime/trunk/src/main/native/include/acr_users.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_users.h?rev=769446&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_users.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_users.h Tue Apr 28 16:14:20 2009
@@ -0,0 +1,68 @@
+/* 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.
+ */
+
+#ifndef _ACR_USERS_H
+#define _ACR_USERS_H
+
+#include "acr.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file acr_users.h
+ * @brief
+ *
+ * ACR User and Group class functions
+ *
+ */
+
+/**
+ * Create new Group object array.
+ * @param env JNI environment to use.
+ * @param size Group object array size.
+ */
+ACR_DECLARE(jobjectArray) ACR_NewGroupArray(JNIEnv *_E, jsize len);
+
+/**
+ * Create new Group object.
+ * @param env JNI environment to use.
+ * @param name Group name which object to create.
+ */
+ACR_DECLARE(jobject) ACR_GroupObjectCreate(JNIEnv *_E,
+ const acr_pchar_t *name);
+
+/**
+ * Create new User object array.
+ * @param env JNI environment to use.
+ * @param size User object array size.
+ */
+ACR_DECLARE(jobjectArray) ACR_NewUserArray(JNIEnv *_E, jsize len);
+
+/**
+ * Create new User object.
+ * @param env JNI environment to use.
+ * @param name User name which object to create.
+ */
+ACR_DECLARE(jobject) ACR_UserObjectCreate(JNIEnv *_E,
+ const acr_pchar_t *name);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ACR_POINTER_H */
Propchange: commons/sandbox/runtime/trunk/src/main/native/include/acr_users.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/group.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/group.c?rev=769446&r1=769445&r2=769446&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/group.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/group.c Tue Apr 28 16:14:20 2009
@@ -22,6 +22,7 @@
#include "acr_memory.h"
#include "acr_string.h"
#include "acr_descriptor.h"
+#include "acr_users.h"
#include <pwd.h>
#include <grp.h>
@@ -91,11 +92,26 @@
return NULL;
}
-static jobject grp_object_create(JNIEnv *_E, struct group *gr)
+ACR_DECLARE(jobject) ACR_GroupObjectCreate(JNIEnv *_E, const char *name)
{
jobject gid;
jobject grp;
char *sid;
+ int rc;
+ struct group grb;
+ struct group *gr;
+ char buffer[4096];
+
+ rc = getgrnam_r(name, &grb, buffer, sizeof(buffer), &gr);
+ if (rc) {
+ if (ACR_STATUS_IS_EACCES(ACR_FROM_OS_ERROR(rc)))
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
+ else
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO,
+ ACR_FROM_OS_ERROR(rc));
+ }
+ if (!gr)
+ return NULL;
gid = ACR_DescriptorCreate(_E, 0, gr->gr_gid, NULL, NULL);
if (!gid) {
@@ -125,23 +141,8 @@
UNREFERENCED_O;
WITH_CSTR(name) {
- int rc;
- struct group grb;
- struct group *pp;
- char buffer[4096];
-
- rc = getgrnam_r(J2S(name), &grb, buffer, sizeof(buffer), &pp);
- if (rc) {
- if (ACR_STATUS_IS_EACCES(ACR_FROM_OS_ERROR(rc)))
- ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
- else
- ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO,
- ACR_FROM_OS_ERROR(rc));
- }
- else {
- if (pp)
- grp = grp_object_create(_E, pp);
- }
+
+ grp = ACR_GroupObjectCreate(_E, J2S(name));
} END_WITH_CSTR(name);
return grp;
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/user.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/user.c?rev=769446&r1=769445&r2=769446&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/user.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/user.c Tue Apr 28 16:14:20 2009
@@ -22,6 +22,7 @@
#include "acr_memory.h"
#include "acr_string.h"
#include "acr_descriptor.h"
+#include "acr_users.h"
#include <pwd.h>
#include <grp.h>
@@ -104,11 +105,27 @@
return NULL;
}
-static jobject usr_object_create(JNIEnv *_E, struct passwd *pw)
+ACR_DECLARE(jobject) ACR_UserObjectCreate(JNIEnv *_E, const char *name)
{
jobject uid;
jobject usr;
char *sid;
+ int rc;
+ struct passwd pwb;
+ struct passwd *pw;
+ char buffer[4096];
+
+ rc = getpwnam_r(name, &pwb, buffer, sizeof(buffer), &pw);
+ if (rc) {
+ if (ACR_STATUS_IS_EACCES(ACR_FROM_OS_ERROR(rc)))
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
+ else
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO,
+ ACR_FROM_OS_ERROR(rc));
+ return NULL;
+ }
+ if (!pw)
+ return NULL;
uid = ACR_DescriptorCreate(_E, 0, pw->pw_uid, NULL, NULL);
if (!uid) {
@@ -143,23 +160,8 @@
UNREFERENCED_O;
WITH_CSTR(name) {
- int rc;
- struct passwd pwb;
- struct passwd *pp;
- char buffer[4096];
-
- rc = getpwnam_r(J2S(name), &pwb, buffer, sizeof(buffer), &pp);
- if (rc) {
- if (ACR_STATUS_IS_EACCES(ACR_FROM_OS_ERROR(rc)))
- ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
- else
- ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO,
- ACR_FROM_OS_ERROR(rc));
- }
- else {
- if (pp)
- usr = usr_object_create(_E, pp);
- }
+
+ usr = ACR_UserObjectCreate(_E, J2S(name));
} END_WITH_CSTR(name);
return usr;
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/group.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/group.c?rev=769446&r1=769445&r2=769446&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/group.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/group.c Tue Apr 28 16:14:20 2009
@@ -22,6 +22,7 @@
#include "acr_memory.h"
#include "acr_string.h"
#include "acr_descriptor.h"
+#include "acr_users.h"
J_DECLARE_CLAZZ = {
NULL,
@@ -104,7 +105,7 @@
}
}
-static jobject grp_object_create(JNIEnv *_E, LPCWSTR name)
+ACR_DECLARE(jobject) ACR_GroupObjectCreate(JNIEnv *_E, const wchar_t *name)
{
jobject grp;
jobject gid;
@@ -164,8 +165,8 @@
UNREFERENCED_O;
WITH_WSTR(name) {
- grp = grp_object_create(_E, J2W(name));
+ grp = ACR_GroupObjectCreate(_E, J2W(name));
} END_WITH_WSTR(name);
return grp;
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=769446&r1=769445&r2=769446&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 Tue Apr 28 16:14:20 2009
@@ -22,6 +22,7 @@
#include "acr_memory.h"
#include "acr_string.h"
#include "acr_descriptor.h"
+#include "acr_users.h"
J_DECLARE_CLAZZ = {
NULL,
@@ -198,7 +199,7 @@
}
}
-static jobject usr_object_create(JNIEnv *_E, LPCWSTR name)
+ACR_DECLARE(jobject) ACR_UserObjectCreate(JNIEnv *_E, const wchar_t *name)
{
jobject usr;
jobject uid;
@@ -268,7 +269,8 @@
UNREFERENCED_O;
WITH_WSTR(name) {
- usr = usr_object_create(_E, J2W(name));
+
+ usr = ACR_UserObjectCreate(_E, J2W(name));
} END_WITH_WSTR(name);
return usr;