2009-06-15 178 views
0

C++ noob在这里想知道如何通过Java servlet来验证Windows用户。JNI调用来使用LogonUser对用户进行身份验证?

这里是我已经把拿在JNI调用从我的Java Servlet与用户的用户名域和密码的代码:在编译的时候

#include <stdio.h> 
#include <string.h> 
#include <sys/stat.h> 
#include <stdlib.h> 

#include "Validate.h"  

JNIEXPORT jstring JNICALL Java_Validate_takeInfo(JNIEnv *env, jobject obj, jstring domain, jstring id, jstring idca, jstring password) 
{ 
    const char *nt_domain; 
    const char *nt_id; 
    const char *nt_idca; 
    const char *nt_password; 

    nt_domain = env->GetStringUTFChars(domain, NULL); 
    nt_id = env->GetStringUTFChars(id, NULL); 
    nt_idca= env->GetStringUTFChars(idca, NULL); 
    nt_password = env->GetStringUTFChars(password, NULL); 

    handle hToken = 0; 
    char *otherString; 
    otherString = LogonUser(nt_id, nt_domain, nt_password, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &hToken); 

    jstring newString = env->NewStringUTF((const char*)otherString); 
    return newString; 
} 

我得到这些错误:

D:\JNI\Validate.cpp(21) : error C2065: 'handle' : undeclared identifier 
D:\JNI\Validate.cpp(21) : error C2146: syntax error : missing ';' before 
ier 'hToken' 
D:\JNI\Validate.cpp(21) : error C2065: 'hToken' : undeclared identifier 
D:\JNI\Validate.cpp(24) : error C2065: 'LOGON32_LOGON_NETWORK' : undeclar 
tifier 
D:\JNI\Validate.cpp(24) : error C2065: 'LOGON32_PROVIDER_DEFAULT' : undec 
dentifier 
D:\JNI\Validate.cpp(24) : error C3861: 'LogonUser': identifier not found 

我假设我不包括我需要的东西。任何帮助是极大的赞赏。

回答

0

您的编译器找不到LogonUser,表明您缺少Windows头文件。包括windows.h

另外,通用窗口句柄类型拼写为HANDLE,全部在大写字母中。

查看the LogonUser docs了解更多详情。