commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r770092 - in /commons/sandbox/runtime/trunk/src/main/native: include/acr_users.h os/unix/group.c os/unix/user.c
Date Thu, 30 Apr 2009 07:02:15 GMT
Author: mturk
Date: Thu Apr 30 07:02:15 2009
New Revision: 770092

URL: http://svn.apache.org/viewvc?rev=770092&view=rev
Log:
Implement current user and group on posix

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr_users.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/group.c
    commons/sandbox/runtime/trunk/src/main/native/os/unix/user.c

Modified: 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=770092&r1=770091&r2=770092&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_users.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_users.h Thu Apr 30 07:02:15
2009
@@ -47,6 +47,14 @@
                                            const acr_pchar_t *name);
 
 /**
+ * Create new Group object.
+ * @param env JNI environment to use.
+ * @param gid Group id which object to create.
+ */
+ACR_DECLARE(jobject) ACR_GroupObjectCreateFromId(JNIEnv *_E,
+                                                 acr_gid_t gid);
+
+/**
  * Create new User object array.
  * @param env JNI environment to use.
  * @param size User object array size.
@@ -61,6 +69,14 @@
 ACR_DECLARE(jobject) ACR_UserObjectCreate(JNIEnv *_E,
                                           const acr_pchar_t *name);
 
+/**
+ * Create new User object.
+ * @param env JNI environment to use.
+ * @param uid User id which object to create.
+ */
+ACR_DECLARE(jobject) ACR_UserObjectCreateFromId(JNIEnv *_E,
+                                                acr_uid_t uid);
+
 #ifdef __cplusplus
 }
 #endif

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=770092&r1=770091&r2=770092&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 Thu Apr 30 07:02:15 2009
@@ -136,6 +136,50 @@
     return grp;
 }
 
+ACR_DECLARE(jobject) ACR_GroupObjectCreateFromId(JNIEnv *_E, gid_t id)
+{
+    jobject gid;
+    jobject grp;
+    char *sid;
+    int rc;
+    struct group grb;
+    struct group *gr;
+    char   buffer[4096];
+
+    rc = getgrgid_r(id, &grb, buffer, sizeof(buffer), &gr);
+    if (rc) {
+        if (ACR_STATUS_IS_ENOENT(ACR_FROM_OS_ERROR(rc)))
+            return NULL;
+        else 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) {
+
+        return NULL;
+    }
+    grp = (*_E)->NewObject(_E, _clazzn.i, J4MID(0000), gid);
+    if (!grp) {
+
+        return NULL;
+    }
+
+    SET_IFIELD_S(0000, grp, gr->gr_name);
+    /* Comment is unknown */
+    sid = ACR_Ltoa((acr_long_t)gr->gr_gid);
+    SET_IFIELD_S(0002, grp, sid);
+    SET_IFIELD_Z(0003, grp, JNI_TRUE);
+    ACR_Free(_E, THROW_FMARK, sid);
+
+    return grp;
+}
+
 ACR_JNI_EXPORT_DECLARE(jobject, Group, get0)(ACR_JNISTDARGS,
                                              jstring name)
 {
@@ -150,6 +194,16 @@
     return grp;
 }
 
+ACR_JNI_EXPORT_DECLARE(jobject, Group, get1)(ACR_JNISTDARGS)
+{
+    jobject grp = NULL;
+    UNREFERENCED_O;
+
+    grp = ACR_GroupObjectCreateFromId(_E, getegid());
+
+    return grp;
+}
+
 ACR_JNI_EXPORT_DECLARE(jboolean, Group, equals0)(ACR_JNISTDARGS,
                                                  jobject a, jobject b)
 {

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=770092&r1=770091&r2=770092&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 Thu Apr 30 07:02:15 2009
@@ -157,6 +157,56 @@
     return usr;
 }
 
+ACR_DECLARE(jobject) ACR_UserObjectCreateFromId(JNIEnv *_E, uid_t id)
+{
+    jobject uid;
+    jobject usr;
+    char *sid;
+    int rc;
+    struct passwd pwb;
+    struct passwd *pw;
+    char   buffer[4096];
+
+    rc = getpwuid_r(id, &pwb, buffer, sizeof(buffer), &pw);
+    if (rc) {
+        if (ACR_STATUS_IS_ENOENT(ACR_FROM_OS_ERROR(rc)))
+            return NULL;
+        else 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) {
+
+        return NULL;
+    }
+    usr = (*_E)->NewObject(_E, _clazzn.i, J4MID(0000), uid);
+    if (!usr) {
+
+        return NULL;
+    }
+
+    SET_IFIELD_S(0000, usr, pw->pw_name);
+    SET_IFIELD_S(0001, usr, pw->pw_gecos);
+#ifdef DARWIN
+    /* Use user class name for comment */
+    SET_IFIELD_N(0002, usr, pw->pw_class);
+#endif
+    SET_IFIELD_S(0003, usr, pw->pw_dir);
+    SET_IFIELD_S(0004, usr, pw->pw_shell);
+    sid = ACR_Ltoa((acr_long_t)pw->pw_uid);
+    SET_IFIELD_S(0005, usr, sid);
+    ACR_Free(_E, THROW_FMARK, sid);
+
+    return usr;
+}
+
 ACR_JNI_EXPORT_DECLARE(jobject, User, get0)(ACR_JNISTDARGS,
                                             jstring name)
 {
@@ -171,6 +221,16 @@
     return usr;
 }
 
+ACR_JNI_EXPORT_DECLARE(jobject, User, get1)(ACR_JNISTDARGS)
+{
+    jobject usr = NULL;
+    UNREFERENCED_O;
+
+    usr = ACR_UserObjectCreateFromId(_E, geteuid());
+
+    return usr;
+}
+
 ACR_JNI_EXPORT_DECLARE(jboolean, User, equals0)(ACR_JNISTDARGS,
                                                 jobject a, jobject b)
 {



Mime
View raw message