8160997: Solaris: deprecated <pwd.h> and <gid.h> interfaces should be replaced
Use final POSIX 1003.1c versions of getgrgid_r(), getgrnam_r(), getpwnam_r(), and getpwuid_r(). Reviewed-by: alanb, dcubed, simonis, dholmes
This commit is contained in:
parent
2446e48a5f
commit
963af328b0
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -34,7 +34,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <pwd.h>
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -46,6 +45,12 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
|
/* For POSIX-compliant getpwuid_r on Solaris */
|
||||||
|
#if defined(__solaris__)
|
||||||
|
#define _POSIX_PTHREAD_SEMANTICS
|
||||||
|
#endif
|
||||||
|
#include <pwd.h>
|
||||||
|
|
||||||
#ifdef _AIX
|
#ifdef _AIX
|
||||||
#include <sys/procfs.h>
|
#include <sys/procfs.h>
|
||||||
#endif
|
#endif
|
||||||
@ -468,12 +473,7 @@ void unix_getUserInfo(JNIEnv* env, jobject jinfo, uid_t uid) {
|
|||||||
} else {
|
} else {
|
||||||
struct passwd pwent;
|
struct passwd pwent;
|
||||||
struct passwd* p = NULL;
|
struct passwd* p = NULL;
|
||||||
|
|
||||||
#ifdef __solaris__
|
|
||||||
RESTARTABLE_RETURN_PTR(getpwuid_r(uid, &pwent, pwbuf, (size_t)getpw_buf_size), p);
|
|
||||||
#else
|
|
||||||
RESTARTABLE(getpwuid_r(uid, &pwent, pwbuf, (size_t)getpw_buf_size, &p), result);
|
RESTARTABLE(getpwuid_r(uid, &pwent, pwbuf, (size_t)getpw_buf_size, &p), result);
|
||||||
#endif
|
|
||||||
|
|
||||||
// Create the Java String if a name was found
|
// Create the Java String if a name was found
|
||||||
if (result == 0 && p != NULL &&
|
if (result == 0 && p != NULL &&
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -29,8 +29,6 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <pwd.h>
|
|
||||||
#include <grp.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -43,6 +41,13 @@
|
|||||||
#endif
|
#endif
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
/* For POSIX-compliant getpwuid_r, getgrgid_r on Solaris */
|
||||||
|
#if defined(__solaris__)
|
||||||
|
#define _POSIX_PTHREAD_SEMANTICS
|
||||||
|
#endif
|
||||||
|
#include <pwd.h>
|
||||||
|
#include <grp.h>
|
||||||
|
|
||||||
#ifdef __solaris__
|
#ifdef __solaris__
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#endif
|
#endif
|
||||||
@ -1022,11 +1027,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_getpwuid(JNIEnv* env, jclass this, jint uid
|
|||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
#ifdef __solaris__
|
RESTARTABLE(getpwuid_r((uid_t)uid, &pwent, pwbuf, (size_t)buflen, &p), res);
|
||||||
RESTARTABLE_RETURN_PTR(getpwuid_r((uid_t)uid, &pwent, pwbuf, (size_t)buflen), p);
|
|
||||||
#else
|
|
||||||
RESTARTABLE(getpwuid_r((uid_t)uid, &pwent, pwbuf, (size_t)buflen, &p), res);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (res != 0 || p == NULL || p->pw_name == NULL || *(p->pw_name) == '\0') {
|
if (res != 0 || p == NULL || p->pw_name == NULL || *(p->pw_name) == '\0') {
|
||||||
/* not found or error */
|
/* not found or error */
|
||||||
@ -1071,11 +1072,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_getgrgid(JNIEnv* env, jclass this, jint gid
|
|||||||
}
|
}
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
#ifdef __solaris__
|
RESTARTABLE(getgrgid_r((gid_t)gid, &grent, grbuf, (size_t)buflen, &g), res);
|
||||||
RESTARTABLE_RETURN_PTR(getgrgid_r((gid_t)gid, &grent, grbuf, (size_t)buflen), g);
|
|
||||||
#else
|
|
||||||
RESTARTABLE(getgrgid_r((gid_t)gid, &grent, grbuf, (size_t)buflen, &g), res);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
retry = 0;
|
retry = 0;
|
||||||
if (res != 0 || g == NULL || g->gr_name == NULL || *(g->gr_name) == '\0') {
|
if (res != 0 || g == NULL || g->gr_name == NULL || *(g->gr_name) == '\0') {
|
||||||
@ -1126,11 +1123,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_getpwnam0(JNIEnv* env, jclass this,
|
|||||||
const char* name = (const char*)jlong_to_ptr(nameAddress);
|
const char* name = (const char*)jlong_to_ptr(nameAddress);
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
#ifdef __solaris__
|
RESTARTABLE(getpwnam_r(name, &pwent, pwbuf, (size_t)buflen, &p), res);
|
||||||
RESTARTABLE_RETURN_PTR(getpwnam_r(name, &pwent, pwbuf, (size_t)buflen), p);
|
|
||||||
#else
|
|
||||||
RESTARTABLE(getpwnam_r(name, &pwent, pwbuf, (size_t)buflen, &p), res);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (res != 0 || p == NULL || p->pw_name == NULL || *(p->pw_name) == '\0') {
|
if (res != 0 || p == NULL || p->pw_name == NULL || *(p->pw_name) == '\0') {
|
||||||
/* not found or error */
|
/* not found or error */
|
||||||
@ -1171,11 +1164,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_getgrnam0(JNIEnv* env, jclass this,
|
|||||||
}
|
}
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
#ifdef __solaris__
|
RESTARTABLE(getgrnam_r(name, &grent, grbuf, (size_t)buflen, &g), res);
|
||||||
RESTARTABLE_RETURN_PTR(getgrnam_r(name, &grent, grbuf, (size_t)buflen), g);
|
|
||||||
#else
|
|
||||||
RESTARTABLE(getgrnam_r(name, &grent, grbuf, (size_t)buflen, &g), res);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
retry = 0;
|
retry = 0;
|
||||||
if (res != 0 || g == NULL || g->gr_name == NULL || *(g->gr_name) == '\0') {
|
if (res != 0 || g == NULL || g->gr_name == NULL || *(g->gr_name) == '\0') {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -26,10 +26,14 @@
|
|||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include "com_sun_security_auth_module_SolarisSystem.h"
|
#include "com_sun_security_auth_module_SolarisSystem.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <pwd.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
/* For POSIX-compliant getpwuid_r on Solaris */
|
||||||
|
#if defined(__solaris__)
|
||||||
|
#define _POSIX_PTHREAD_SEMANTICS
|
||||||
|
#endif
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
|
||||||
static void throwIllegalArgumentException(JNIEnv *env, const char *msg) {
|
static void throwIllegalArgumentException(JNIEnv *env, const char *msg) {
|
||||||
@ -43,8 +47,10 @@ Java_com_sun_security_auth_module_SolarisSystem_getSolarisInfo
|
|||||||
(JNIEnv *env, jobject obj) {
|
(JNIEnv *env, jobject obj) {
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
char pwd_buf[1024];
|
long pwd_bufsize;
|
||||||
|
char *pwd_buf = NULL;
|
||||||
struct passwd pwd;
|
struct passwd pwd;
|
||||||
|
struct passwd* p = NULL;
|
||||||
jsize numSuppGroups = getgroups(0, NULL);
|
jsize numSuppGroups = getgroups(0, NULL);
|
||||||
jfieldID fid;
|
jfieldID fid;
|
||||||
jstring jstr;
|
jstring jstr;
|
||||||
@ -53,20 +59,31 @@ Java_com_sun_security_auth_module_SolarisSystem_getSolarisInfo
|
|||||||
gid_t *groups;
|
gid_t *groups;
|
||||||
jclass cls;
|
jclass cls;
|
||||||
|
|
||||||
|
pwd_bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
|
||||||
|
if (pwd_bufsize == -1) {
|
||||||
|
pwd_bufsize = 1024;
|
||||||
|
}
|
||||||
|
pwd_buf = (char *)malloc(pwd_bufsize);
|
||||||
groups = (gid_t *)calloc(numSuppGroups, sizeof(gid_t));
|
groups = (gid_t *)calloc(numSuppGroups, sizeof(gid_t));
|
||||||
|
|
||||||
if (groups == NULL) {
|
if (pwd_buf == NULL || groups == NULL) {
|
||||||
jclass cls = (*env)->FindClass(env,"java/lang/OutOfMemoryError");
|
if (pwd_buf != NULL) {
|
||||||
if (cls != NULL)
|
free(pwd_buf);
|
||||||
|
}
|
||||||
|
if (groups != NULL) {
|
||||||
|
free(groups);
|
||||||
|
}
|
||||||
|
cls = (*env)->FindClass(env,"java/lang/OutOfMemoryError");
|
||||||
|
if (cls != NULL) {
|
||||||
(*env)->ThrowNew(env, cls, NULL);
|
(*env)->ThrowNew(env, cls, NULL);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cls = (*env)->GetObjectClass(env, obj);
|
cls = (*env)->GetObjectClass(env, obj);
|
||||||
|
|
||||||
memset(pwd_buf, 0, sizeof(pwd_buf));
|
if (getpwuid_r(getuid(), &pwd, pwd_buf, sizeof(pwd_buf), &p) != 0 &&
|
||||||
if (getpwuid_r(getuid(), &pwd, pwd_buf, sizeof(pwd_buf)) != NULL &&
|
p != NULL && getgroups(numSuppGroups, groups) != -1) {
|
||||||
getgroups(numSuppGroups, groups) != -1) {
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* set username
|
* set username
|
||||||
@ -129,7 +146,7 @@ Java_com_sun_security_auth_module_SolarisSystem_getSolarisInfo
|
|||||||
(*env)->SetObjectField(env, obj, fid, jgroups);
|
(*env)->SetObjectField(env, obj, fid, jgroups);
|
||||||
}
|
}
|
||||||
cleanupAndReturn:
|
cleanupAndReturn:
|
||||||
|
free(pwd_buf);
|
||||||
free(groups);
|
free(groups);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -23,20 +23,21 @@
|
|||||||
* questions.
|
* questions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef __solaris__
|
|
||||||
#define _POSIX_C_SOURCE 199506L
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include "jni_util.h"
|
#include "jni_util.h"
|
||||||
#include "com_sun_security_auth_module_UnixSystem.h"
|
#include "com_sun_security_auth_module_UnixSystem.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <pwd.h>
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
/* For POSIX-compliant getpwuid_r on Solaris */
|
||||||
|
#if defined(__solaris__)
|
||||||
|
#define _POSIX_PTHREAD_SEMANTICS
|
||||||
|
#endif
|
||||||
|
#include <pwd.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Declare library specific JNI_Onload entry if static build
|
* Declare library specific JNI_Onload entry if static build
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user