< prev index next >

src/jdk.security.auth/unix/native/libjaas/Unix.c

Print this page
rev 50999 : 8207233: Minor improvements of jdk C-coding
   1 /*
   2  * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  47 Java_com_sun_security_auth_module_UnixSystem_getUnixInfo
  48                                                 (JNIEnv *env, jobject obj) {
  49 
  50     int i;
  51     char pwd_buf[1024];
  52     struct passwd *pwd;
  53     struct passwd resbuf;
  54     jfieldID userNameID;
  55     jfieldID userID;
  56     jfieldID groupID;
  57     jfieldID supplementaryGroupID;
  58 
  59     jstring jstr;
  60     jlongArray jgroups;
  61     jlong *jgroupsAsArray;
  62     jsize numSuppGroups;
  63     gid_t *groups;
  64     jclass cls;
  65 
  66     numSuppGroups = getgroups(0, NULL);



  67     groups = (gid_t *)calloc(numSuppGroups, sizeof(gid_t));
  68     if (groups == NULL) {
  69         jclass cls = (*env)->FindClass(env,"java/lang/OutOfMemoryError");
  70         if (cls != NULL)
  71             (*env)->ThrowNew(env, cls, NULL);
  72         return;
  73     }
  74 
  75     cls = (*env)->GetObjectClass(env, obj);
  76 
  77     memset(pwd_buf, 0, sizeof(pwd_buf));
  78 
  79     if (getpwuid_r(getuid(), &resbuf, pwd_buf, sizeof(pwd_buf), &pwd) == 0 &&
  80         pwd != NULL &&
  81         getgroups(numSuppGroups, groups) != -1) {
  82 
  83         userNameID = (*env)->GetFieldID(env, cls, "username", "Ljava/lang/String;");
  84         if (userNameID == 0)
  85             goto cleanUpAndReturn;
  86 


   1 /*
   2  * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  47 Java_com_sun_security_auth_module_UnixSystem_getUnixInfo
  48                                                 (JNIEnv *env, jobject obj) {
  49 
  50     int i;
  51     char pwd_buf[1024];
  52     struct passwd *pwd;
  53     struct passwd resbuf;
  54     jfieldID userNameID;
  55     jfieldID userID;
  56     jfieldID groupID;
  57     jfieldID supplementaryGroupID;
  58 
  59     jstring jstr;
  60     jlongArray jgroups;
  61     jlong *jgroupsAsArray;
  62     jsize numSuppGroups;
  63     gid_t *groups;
  64     jclass cls;
  65 
  66     numSuppGroups = getgroups(0, NULL);
  67     if (numSuppGroups == -1) {
  68         return;
  69     }
  70     groups = (gid_t *)calloc(numSuppGroups, sizeof(gid_t));
  71     if (groups == NULL) {
  72         jclass cls = (*env)->FindClass(env,"java/lang/OutOfMemoryError");
  73         if (cls != NULL)
  74             (*env)->ThrowNew(env, cls, NULL);
  75         return;
  76     }
  77 
  78     cls = (*env)->GetObjectClass(env, obj);
  79 
  80     memset(pwd_buf, 0, sizeof(pwd_buf));
  81 
  82     if (getpwuid_r(getuid(), &resbuf, pwd_buf, sizeof(pwd_buf), &pwd) == 0 &&
  83         pwd != NULL &&
  84         getgroups(numSuppGroups, groups) != -1) {
  85 
  86         userNameID = (*env)->GetFieldID(env, cls, "username", "Ljava/lang/String;");
  87         if (userNameID == 0)
  88             goto cleanUpAndReturn;
  89 


< prev index next >