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/29 10:43:10 UTC

svn commit: r769714 - in /commons/sandbox/runtime/trunk/src/main/native/os/hpux: pgroup.c puser.c

Author: mturk
Date: Wed Apr 29 08:43:07 2009
New Revision: 769714

URL: http://svn.apache.org/viewvc?rev=769714&view=rev
Log:
Add hpux private files

Added:
    commons/sandbox/runtime/trunk/src/main/native/os/hpux/pgroup.c   (with props)
    commons/sandbox/runtime/trunk/src/main/native/os/hpux/puser.c   (with props)

Added: commons/sandbox/runtime/trunk/src/main/native/os/hpux/pgroup.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/hpux/pgroup.c?rev=769714&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/hpux/pgroup.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/hpux/pgroup.c Wed Apr 29 08:43:07 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/hpux/pgroup.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/native/os/hpux/puser.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/hpux/puser.c?rev=769714&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/hpux/puser.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/hpux/puser.c Wed Apr 29 08:43:07 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, User, enum0)(ACR_JNISTDARGS)
+{
+    jobjectArray usrs = NULL;
+    struct passwd *pw;
+    jsize i, n = 0;
+    char **unames;
+
+    UNREFERENCED_O;
+
+    /* 1. stage - get the number of groups */
+    setpwent();
+    while (1) {
+        errno = 0;
+        pw = getpwent();
+        if (pw == 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 (pw == NULL)
+            break;
+        else
+            n++;
+    }
+    endpwent();
+    if (n == 0) {
+        /* No groups defined */
+        return NULL;
+    }
+    unames = (char **)ACR_Calloc(_E, THROW_FMARK, n * sizeof(char *));
+    if (!unames) {
+        return NULL;
+    }
+    usrs = ACR_NewUserArray(_E, n);
+    if (usrs == NULL) {
+        return NULL;
+    }
+    /* 2. stage - get the group names */
+    setpwent();
+    for (i = 0; i < n; i++) {
+        pw = getpwent();
+        if (pw) {
+            unames[i] = ACR_StrdupA(_E, THROW_FMARK, pw->pw_name);
+            if (!unames[i]) {
+                usrs = NULL;
+                endpwent();
+                goto cleanup;
+            }
+        }
+    }
+    endpwent();
+    /* 3. stage - create the groups */
+    for (i = 0; i < n; i++) {
+        if (unames[i]) {
+            jobject uid = ACR_UserObjectCreate(_E, unames[i]);
+            if ((*_E)->ExceptionCheck(_E) || uid == NULL) {
+                /* Object creation failed */
+                break;
+            }
+            (*_E)->SetObjectArrayElement(_E, usrs, i, uid);
+            (*_E)->DeleteLocalRef(_E, uid);
+        }
+    }
+cleanup:
+    /* 4. stage - free the temp storage */
+    for (i = 0; i < n; i++) {
+        if (unames[i])
+            free(unames[i]);
+    }
+    free(unames);
+    return usrs;
+}
+

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