S
songhy
Unregistered / Unconfirmed
GUEST, unregistred user!
这个问题为
http://www.delphibbs.com/delphibbs/dispq.asp?lid=3439542
的后续问题
我用ADsValidateUser现在可以在普通gui程序中用AD验证用户了,但我把同样的函数应用到Webservice中就发生问题了,始终返回验证失败值,通过跟踪,发现lADsOpenObject返回2147023570或者2147016662,通过查询msdn,修改ADS_SECURE_AUTHENTICATION也没用。
我的Webservice程序用delphi6,运行在IIS下,采用cgi方式
附上完整函数,希望高手帮忙解决:
unit AdsHelper;
interface
uses
Classes;
function ADsValidateUser(const aDomainName, aUsername, aPassword:WideString): Boolean;
implementation
uses
Windows, SysUtils, Registry, ActiveX;
type
IADs = interface(IDispatch)
['{FD8256D0-FD15-11CE-ABC4-02608C9E7553}']
function Get_Name: WideString; safecall;
function Get_Class_: WideString; safecall;
function Get_GUID: WideString; safecall;
function Get_ADsPath: WideString; safecall;
function Get_Parent: WideString; safecall;
function Get_Schema: WideString; safecall;
procedure GetInfo; safecall;
procedure SetInfo; safecall;
function Get(const bstrName: WideString): OleVariant; safecall;
procedure Put(const bstrName: WideString; vProp: OleVariant); safecall;
function GetEx(const bstrName: WideString): OleVariant; safecall;
procedure PutEx(lnControlCode: Integer; const bstrName: WideString;vProp: OleVariant); safecall;
procedure GetInfoEx(vProperties: OleVariant; lnReserved: Integer);safecall;
property Name: WideString read Get_Name;
property Class_: WideString read Get_Class_;
property GUID: WideString read Get_GUID;
property ADsPath: WideString read Get_ADsPath;
property Parent: WideString read Get_Parent;
property Schema: WideString read Get_Schema;
end;
function ADsValidateUser(const aDomainName, aUsername, aPassword:WideString): Boolean;
const
ADsLibName = 'activeds.dll';
ADS_SECURE_AUTHENTICATION = $00000001;
type
TADsOpenObject = function (
lpszPathName: PWideChar;
lpszUserName: PWideChar;
lpszPassword: PWideChar;
dwReserved: DWORD;
const riid: TGUID;
out pObject
): HRESULT; stdcall;
var
hLib: THandle;
lADsOpenObject: TADsOpenObject;
Obj: IADs;
Ret: HRESULT;
begin
Result := False;
hLib := LoadLibrary(PChar(ADsLibName));
if hLib = 0 then
raise Exception.CreateFmt('Unable to load required library %s.',[ADsLibName]);
try
lADsOpenObject := GetProcAddress(hLib, 'ADsOpenObject');
if not Assigned(lADsOpenObject) then
raise Exception.Create('Unable to find required ADSI api.');
CoInitialize(nil);
try
Ret := lADsOpenObject(
//PWideChar('LDAP://' + aDomainName),
'LDAP://server-main.chabridge.cn',
PWideChar(aUsername),
PWideChar(aPassword),
ADS_SECURE_AUTHENTICATION,
IADs,
Obj
);
Obj := nil;
Result := Succeeded(Ret);
finally
CoUninitialize;
end;
finally
FreeLibrary(hLib);
end;
end;
end.
http://www.delphibbs.com/delphibbs/dispq.asp?lid=3439542
的后续问题
我用ADsValidateUser现在可以在普通gui程序中用AD验证用户了,但我把同样的函数应用到Webservice中就发生问题了,始终返回验证失败值,通过跟踪,发现lADsOpenObject返回2147023570或者2147016662,通过查询msdn,修改ADS_SECURE_AUTHENTICATION也没用。
我的Webservice程序用delphi6,运行在IIS下,采用cgi方式
附上完整函数,希望高手帮忙解决:
unit AdsHelper;
interface
uses
Classes;
function ADsValidateUser(const aDomainName, aUsername, aPassword:WideString): Boolean;
implementation
uses
Windows, SysUtils, Registry, ActiveX;
type
IADs = interface(IDispatch)
['{FD8256D0-FD15-11CE-ABC4-02608C9E7553}']
function Get_Name: WideString; safecall;
function Get_Class_: WideString; safecall;
function Get_GUID: WideString; safecall;
function Get_ADsPath: WideString; safecall;
function Get_Parent: WideString; safecall;
function Get_Schema: WideString; safecall;
procedure GetInfo; safecall;
procedure SetInfo; safecall;
function Get(const bstrName: WideString): OleVariant; safecall;
procedure Put(const bstrName: WideString; vProp: OleVariant); safecall;
function GetEx(const bstrName: WideString): OleVariant; safecall;
procedure PutEx(lnControlCode: Integer; const bstrName: WideString;vProp: OleVariant); safecall;
procedure GetInfoEx(vProperties: OleVariant; lnReserved: Integer);safecall;
property Name: WideString read Get_Name;
property Class_: WideString read Get_Class_;
property GUID: WideString read Get_GUID;
property ADsPath: WideString read Get_ADsPath;
property Parent: WideString read Get_Parent;
property Schema: WideString read Get_Schema;
end;
function ADsValidateUser(const aDomainName, aUsername, aPassword:WideString): Boolean;
const
ADsLibName = 'activeds.dll';
ADS_SECURE_AUTHENTICATION = $00000001;
type
TADsOpenObject = function (
lpszPathName: PWideChar;
lpszUserName: PWideChar;
lpszPassword: PWideChar;
dwReserved: DWORD;
const riid: TGUID;
out pObject
): HRESULT; stdcall;
var
hLib: THandle;
lADsOpenObject: TADsOpenObject;
Obj: IADs;
Ret: HRESULT;
begin
Result := False;
hLib := LoadLibrary(PChar(ADsLibName));
if hLib = 0 then
raise Exception.CreateFmt('Unable to load required library %s.',[ADsLibName]);
try
lADsOpenObject := GetProcAddress(hLib, 'ADsOpenObject');
if not Assigned(lADsOpenObject) then
raise Exception.Create('Unable to find required ADSI api.');
CoInitialize(nil);
try
Ret := lADsOpenObject(
//PWideChar('LDAP://' + aDomainName),
'LDAP://server-main.chabridge.cn',
PWideChar(aUsername),
PWideChar(aPassword),
ADS_SECURE_AUTHENTICATION,
IADs,
Obj
);
Obj := nil;
Result := Succeeded(Ret);
finally
CoUninitialize;
end;
finally
FreeLibrary(hLib);
end;
end;
end.