Highlighted
Absent Member.
Absent Member.
355 views

[archive] need help with calling 'logonuser'

[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
);
0 Likes
3 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] need help with calling 'logonuser'

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.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] need help with calling 'logonuser'

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.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] need help with calling 'logonuser'

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)
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.