< prev index next >

src/jdk.security.auth/windows/native/libjaas/nt.c

Print this page


   1 /*
   2  * Copyright (c) 2000, 2014, 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
  23  * questions.
  24  */
  25 
  26 #include <jni.h>

  27 #include "com_sun_security_auth_module_NTSystem.h"
  28 
  29 #include <windows.h>
  30 #include <stdio.h>
  31 #include <wchar.h>
  32 #include <ntsecapi.h>
  33 #include <lmerr.h>
  34 
  35 static BOOL debug = FALSE;
  36 
  37 BOOL getToken(PHANDLE);
  38 BOOL getUser(HANDLE tokenHandle, LPTSTR *userName,
  39         LPTSTR *domainName, LPTSTR *userSid, LPTSTR *domainSid);
  40 BOOL getPrimaryGroup(HANDLE tokenHandle, LPTSTR *primaryGroup);
  41 BOOL getGroups(HANDLE tokenHandle, PDWORD numGroups, LPTSTR **groups);
  42 BOOL getImpersonationToken(PHANDLE impersonationToken);
  43 BOOL getTextualSid(PSID pSid, LPTSTR TextualSid, LPDWORD lpdwBufferLen);
  44 void DisplayErrorText(DWORD dwLastError);
  45 
  46 static void throwIllegalArgumentException(JNIEnv *env, const char *msg) {
  47     jclass clazz = (*env)->FindClass(env, "java/lang/IllegalArgumentException");
  48     if (clazz != NULL)
  49         (*env)->ThrowNew(env, clazz, msg);
  50 }





  51 
  52 JNIEXPORT jlong JNICALL
  53 Java_com_sun_security_auth_module_NTSystem_getImpersonationToken0
  54         (JNIEnv *env, jobject obj) {
  55     HANDLE impersonationToken = 0;      // impersonation token
  56     if (debug) {
  57         printf("getting impersonation token\n");
  58     }
  59     if (getImpersonationToken(&impersonationToken) == FALSE) {
  60         return 0;
  61     }
  62     return (jlong)impersonationToken;
  63 }
  64 
  65 JNIEXPORT void JNICALL
  66 Java_com_sun_security_auth_module_NTSystem_getCurrent
  67     (JNIEnv *env, jobject obj, jboolean debugNative) {
  68 
  69     long i, j = 0;
  70     HANDLE tokenHandle = INVALID_HANDLE_VALUE;


   1 /*
   2  * Copyright (c) 2000, 2015, 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
  23  * questions.
  24  */
  25 
  26 #include <jni.h>
  27 #include "jni_util.h"
  28 #include "com_sun_security_auth_module_NTSystem.h"
  29 
  30 #include <windows.h>
  31 #include <stdio.h>
  32 #include <wchar.h>
  33 #include <ntsecapi.h>
  34 #include <lmerr.h>
  35 
  36 static BOOL debug = FALSE;
  37 
  38 BOOL getToken(PHANDLE);
  39 BOOL getUser(HANDLE tokenHandle, LPTSTR *userName,
  40         LPTSTR *domainName, LPTSTR *userSid, LPTSTR *domainSid);
  41 BOOL getPrimaryGroup(HANDLE tokenHandle, LPTSTR *primaryGroup);
  42 BOOL getGroups(HANDLE tokenHandle, PDWORD numGroups, LPTSTR **groups);
  43 BOOL getImpersonationToken(PHANDLE impersonationToken);
  44 BOOL getTextualSid(PSID pSid, LPTSTR TextualSid, LPDWORD lpdwBufferLen);
  45 void DisplayErrorText(DWORD dwLastError);
  46 
  47 static void throwIllegalArgumentException(JNIEnv *env, const char *msg) {
  48     jclass clazz = (*env)->FindClass(env, "java/lang/IllegalArgumentException");
  49     if (clazz != NULL)
  50         (*env)->ThrowNew(env, clazz, msg);
  51 }
  52 
  53 /*
  54  * Declare library specific JNI_Onload entry if static build
  55  */
  56 DEF_STATIC_JNI_OnLoad
  57 
  58 JNIEXPORT jlong JNICALL
  59 Java_com_sun_security_auth_module_NTSystem_getImpersonationToken0
  60         (JNIEnv *env, jobject obj) {
  61     HANDLE impersonationToken = 0;      // impersonation token
  62     if (debug) {
  63         printf("getting impersonation token\n");
  64     }
  65     if (getImpersonationToken(&impersonationToken) == FALSE) {
  66         return 0;
  67     }
  68     return (jlong)impersonationToken;
  69 }
  70 
  71 JNIEXPORT void JNICALL
  72 Java_com_sun_security_auth_module_NTSystem_getCurrent
  73     (JNIEnv *env, jobject obj, jboolean debugNative) {
  74 
  75     long i, j = 0;
  76     HANDLE tokenHandle = INVALID_HANDLE_VALUE;


< prev index next >