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 20:24:00 UTC
svn commit: r769488 - in /commons/sandbox/runtime/trunk/src/main/native:
Makefile.in os/darwin/pgroup.c os/linux/pgroup.c os/solaris/pgroup.c
Author: mturk
Date: Tue Apr 28 18:23:59 2009
New Revision: 769488
URL: http://svn.apache.org/viewvc?rev=769488&view=rev
Log:
Add solaris and darwin group enums
Added:
commons/sandbox/runtime/trunk/src/main/native/os/darwin/pgroup.c (with props)
commons/sandbox/runtime/trunk/src/main/native/os/solaris/pgroup.c (with props)
Modified:
commons/sandbox/runtime/trunk/src/main/native/Makefile.in
commons/sandbox/runtime/trunk/src/main/native/os/linux/pgroup.c
Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.in?rev=769488&r1=769487&r2=769488&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.in Tue Apr 28 18:23:59 2009
@@ -98,6 +98,7 @@
$(SRCDIR)/os/unix/uuid.$(OBJ) \
$(SRCDIR)/os/unix/uutils.$(OBJ) \
$(SRCDIR)/os/solaris/platform.$(OBJ) \
+ $(SRCDIR)/os/solaris/pgroup.$(OBJ) \
$(SRCDIR)/os/solaris/os.$(OBJ)
DARWIN_OBJS= \
@@ -109,6 +110,7 @@
$(SRCDIR)/os/unix/uuid.$(OBJ) \
$(SRCDIR)/os/unix/uutils.$(OBJ) \
$(SRCDIR)/os/darwin/platform.$(OBJ) \
+ $(SRCDIR)/os/darwin/pgroup.$(OBJ) \
$(SRCDIR)/os/darwin/os.$(OBJ)
HPUX_OBJS= \
Added: commons/sandbox/runtime/trunk/src/main/native/os/darwin/pgroup.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/darwin/pgroup.c?rev=769488&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/darwin/pgroup.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/darwin/pgroup.c Tue Apr 28 18:23:59 2009
@@ -0,0 +1,106 @@
+/* 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"
+
+#include <pwd.h>
+#include <grp.h>
+
+
+ACR_JNI_EXPORT_DECLARE(jobjectArray, Group, enum0)(ACR_JNISTDARGS)
+{
+ jobjectArray grps = NULL;
+ struct group *gr;
+ jsize i, n = 0;
+ char **gnames;
+
+ UNREFERENCED_O;
+
+ /* 1. stage - get the number of groups */
+ setgrent();
+ while (1) {
+ errno = 0;
+ gr = getgrent();
+ if (gr == NULL && n == 0) {
+ if (ACR_STATUS_IS_EACCES(ACR_GET_OS_ERROR()))
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
+ else
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO,
+ ACR_GET_OS_ERROR());
+ return NULL;
+ }
+ if (gr == NULL)
+ break;
+ else
+ n++;
+ }
+ endgrent();
+ if (n == 0) {
+ /* No groups defined */
+ return NULL;
+ }
+ gnames = (char **)ACR_Calloc(_E, THROW_FMARK, n * sizeof(char *));
+ if (!gnames) {
+ return NULL;
+ }
+ grps = ACR_NewGroupArray(_E, n);
+ if (grps == NULL) {
+ return NULL;
+ }
+ /* 2. stage - get the group names */
+ setgrent();
+ for (i = 0; i < n; i++) {
+ gr = getgrent();
+ if (gr) {
+ gnames[i] = ACR_StrdupA(_E, THROW_FMARK, gr->gr_name);
+ if (!gnames[i]) {
+ grps = NULL;
+ endgrent();
+ goto cleanup;
+ }
+ }
+ }
+ endgrent();
+ /* 3. stage - create the groups */
+ for (i = 0; i < n; i++) {
+ if (gnames[i]) {
+ jobject gid = ACR_GroupObjectCreate(_E, gnames[i]);
+ if ((*_E)->ExceptionCheck(_E) || gid == NULL) {
+ /* Object creation failed */
+ break;
+ }
+ (*_E)->SetObjectArrayElement(_E, grps, i, gid);
+ (*_E)->DeleteLocalRef(_E, gid);
+ }
+ }
+cleanup:
+ /* 4. stage - free the temp storage */
+ for (i = 0; i < n; i++) {
+ if (gnames[i])
+ free(gnames[i]);
+ }
+ free(gnames);
+ return grps;
+}
+
Propchange: commons/sandbox/runtime/trunk/src/main/native/os/darwin/pgroup.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/native/os/linux/pgroup.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/linux/pgroup.c?rev=769488&r1=769487&r2=769488&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/linux/pgroup.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/linux/pgroup.c Tue Apr 28 18:23:59 2009
@@ -52,7 +52,7 @@
ACR_FROM_OS_ERROR(rc));
return NULL;
}
- if (!gr)
+ if (rc || gr == NULL)
break;
else
n++;
Added: commons/sandbox/runtime/trunk/src/main/native/os/solaris/pgroup.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/solaris/pgroup.c?rev=769488&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/solaris/pgroup.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/solaris/pgroup.c Tue Apr 28 18:23:59 2009
@@ -0,0 +1,108 @@
+/* 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"
+
+#include <pwd.h>
+#include <grp.h>
+
+
+ACR_JNI_EXPORT_DECLARE(jobjectArray, Group, enum0)(ACR_JNISTDARGS)
+{
+ jobjectArray grps = NULL;
+ struct group grp;
+ struct group *gr;
+ jsize i, n = 0;
+ char buffer[4096];
+ char **gnames;
+
+ UNREFERENCED_O;
+
+ /* 1. stage - get the number of groups */
+ setgrent();
+ while (1) {
+ errno = 0;
+ gr = getgrent_r(&grp, buffer, sizeof(buffer));
+ if (gr == NULL && n == 0) {
+ if (ACR_STATUS_IS_EACCES(ACR_GET_OS_ERROR()))
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
+ else
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO,
+ ACR_GET_OS_ERROR());
+ return NULL;
+ }
+ if (gr == NULL)
+ break;
+ else
+ n++;
+ }
+ endgrent();
+ if (n == 0) {
+ /* No groups defined */
+ return NULL;
+ }
+ gnames = (char **)ACR_Calloc(_E, THROW_FMARK, n * sizeof(char *));
+ if (!gnames) {
+ return NULL;
+ }
+ grps = ACR_NewGroupArray(_E, n);
+ if (grps == NULL) {
+ return NULL;
+ }
+ /* 2. stage - get the group names */
+ setgrent();
+ for (i = 0; i < n; i++) {
+ gr = getgrent_r(&grp, buffer, sizeof(buffer));
+ if (gr) {
+ gnames[i] = ACR_StrdupA(_E, THROW_FMARK, gr->gr_name);
+ if (!gnames[i]) {
+ grps = NULL;
+ endgrent();
+ goto cleanup;
+ }
+ }
+ }
+ endgrent();
+ /* 3. stage - create the groups */
+ for (i = 0; i < n; i++) {
+ if (gnames[i]) {
+ jobject gid = ACR_GroupObjectCreate(_E, gnames[i]);
+ if ((*_E)->ExceptionCheck(_E) || gid == NULL) {
+ /* Object creation failed */
+ break;
+ }
+ (*_E)->SetObjectArrayElement(_E, grps, i, gid);
+ (*_E)->DeleteLocalRef(_E, gid);
+ }
+ }
+cleanup:
+ /* 4. stage - free the temp storage */
+ for (i = 0; i < n; i++) {
+ if (gnames[i])
+ free(gnames[i]);
+ }
+ free(gnames);
+ return grps;
+}
+
Propchange: commons/sandbox/runtime/trunk/src/main/native/os/solaris/pgroup.c
------------------------------------------------------------------------------
svn:eol-style = native