Skip to main content

[archive] need help with calling 'logonuser'

  • October 1, 2006
  • 3 replies
  • 0 views

[Migrated content. Thread originally posted on 20 September 2006]

In short I am interested in calling the DLL (Advapi32.dll) and calling subroutine (logonuser). Reason being I am trying to impersonate another user to avoid an active directory conflict while trying connect to our sql server. I have no exceptions while calling Advapi32 (CALL"Advapi32.dll@WINAPI" ON EXCEPTION GO TO 9999-INITIALIZE-ERR) but when I call 'logonuser' I get an exception. I have no problems calling sub routines 'getusernameA' or 'GetCurrentProcessId' because the parameters passed are easier understood. As for 'logonuser' I am not sure how to set up the passing parameters and the return value any help on getting this to work would be greatly appreciated.
thanks
jp

BOOL LogonUser(
LPTSTR lpszUsername,
LPTSTR lpszDomain,
LPTSTR lpszPassword,
DWORD dwLogonType,
DWORD dwLogonProvider,
PHANDLE phToken
);

3 replies

[Migrated content. Thread originally posted on 20 September 2006]

In short I am interested in calling the DLL (Advapi32.dll) and calling subroutine (logonuser). Reason being I am trying to impersonate another user to avoid an active directory conflict while trying connect to our sql server. I have no exceptions while calling Advapi32 (CALL"Advapi32.dll@WINAPI" ON EXCEPTION GO TO 9999-INITIALIZE-ERR) but when I call 'logonuser' I get an exception. I have no problems calling sub routines 'getusernameA' or 'GetCurrentProcessId' because the parameters passed are easier understood. As for 'logonuser' I am not sure how to set up the passing parameters and the return value any help on getting this to work would be greatly appreciated.
thanks
jp

BOOL LogonUser(
LPTSTR lpszUsername,
LPTSTR lpszDomain,
LPTSTR lpszPassword,
DWORD dwLogonType,
DWORD dwLogonProvider,
PHANDLE phToken
);
To see how you code this in COBOL would be a better start for helping you, however, if I shall guess, I suspect this function appears in both unicode and ansi versions, thus suffix the function name with capital A, like: LogonUserA should do.

[Migrated content. Thread originally posted on 20 September 2006]

In short I am interested in calling the DLL (Advapi32.dll) and calling subroutine (logonuser). Reason being I am trying to impersonate another user to avoid an active directory conflict while trying connect to our sql server. I have no exceptions while calling Advapi32 (CALL"Advapi32.dll@WINAPI" ON EXCEPTION GO TO 9999-INITIALIZE-ERR) but when I call 'logonuser' I get an exception. I have no problems calling sub routines 'getusernameA' or 'GetCurrentProcessId' because the parameters passed are easier understood. As for 'logonuser' I am not sure how to set up the passing parameters and the return value any help on getting this to work would be greatly appreciated.
thanks
jp

BOOL LogonUser(
LPTSTR lpszUsername,
LPTSTR lpszDomain,
LPTSTR lpszPassword,
DWORD dwLogonType,
DWORD dwLogonProvider,
PHANDLE phToken
);
working storage...
01 USER-NAME.
05 FILLER PIC X(25).
05 FILLER PIC X VALUE X'00'.

01 DOMAIN-NAME.
05 FILLER PIC X(20).
05 FILLER PIC X VALUE X'00'.
01 DOMAIN-PASSWORD.
05 FILLER PIC X(20).
05 FILLER PIC X VALUE X'00'.
77 BOOL-VALUE PIC x(4) COMP-N.
77 LOGON-TYPE PIC X(4) COMP-N.
77 LOGON-PROVIDER PIC X(4) COMP-N.
77 EVENT-HANDLE USAGE HANDLE.

**SNIPPETS FROM PROCEDURE DIVISION..
**move data in and call.....
CALL "Advapi32.dll@WINAPI"
ON EXCEPTION
DISPLAY "EXCEPTION"
STOP RUN.

MOVE "\\\\UNITRININC\\\\THEUSERNAME" TO USER-NAME.

INSPECT USER-NAME REPLACING TRAILING SPACES BY LOW-VALUES.
MOVE "UNITRININC" TO DOMAIN-NAME.
INSPECT DOMAIN-NAME REPLACING TRAILING SPACES BY LOW-VALUES.

MOVE "THEPASSWORD" TO DOMAIN-PASSWORD.
INSPECT DOMAIN-PASSWORD REPLACING TRAILING SPACES BY LOW-VALUES.

CALL "logonUserA"
USING
BY REFERENCE USER-NAME
BY REFERENCE DOMAIN-NAME
BY REFERENCE DOMAIN-PASSWORD
BY VALUE 3
BY VALUE 0
BY REFERENCE EVENT-HANDLE
RETURNING BOOL-VALUE
ON EXCEPTION
DISPLAY "EXCEPTION".
.....
When I run this in debugger I always make it to CALL "logonUserA" but after the call it goes straight to the exception every time. also originally I just had the user name in user-name but then changed it to \\\\Domain\\\\username thinking this might work.

[Migrated content. Thread originally posted on 20 September 2006]

In short I am interested in calling the DLL (Advapi32.dll) and calling subroutine (logonuser). Reason being I am trying to impersonate another user to avoid an active directory conflict while trying connect to our sql server. I have no exceptions while calling Advapi32 (CALL"Advapi32.dll@WINAPI" ON EXCEPTION GO TO 9999-INITIALIZE-ERR) but when I call 'logonuser' I get an exception. I have no problems calling sub routines 'getusernameA' or 'GetCurrentProcessId' because the parameters passed are easier understood. As for 'logonuser' I am not sure how to set up the passing parameters and the return value any help on getting this to work would be greatly appreciated.
thanks
jp

BOOL LogonUser(
LPTSTR lpszUsername,
LPTSTR lpszDomain,
LPTSTR lpszPassword,
DWORD dwLogonType,
DWORD dwLogonProvider,
PHANDLE phToken
);
From my documentation it says to use capital L as in LogonUser, so try change to "LogonUserA".

Also, I cannot see you set the calling convention, make sure you set calling convention to 1 (windows)