Link to home
Start Free TrialLog in
Avatar of mars
mars

asked on

LogonUser() do not work (privilege problem) !


I'm logged in as an Administrator, and i cannot execute the LogonUser()
because i have insuficients rights to execute this function, EVEN if i
set up the SE_TCB_NAME privilege. All functions execute correctly and
return 1 as "ret" parameter except LogonUser().

What are the advantages to be an Administrator if i haven't all rights
to execute functions.

I want to execute the LogonUser(), firstly, with an Administrator login and
secondly if possible, with an simple user login.


  TOKEN_PRIVILEGES tkp;
  BOOL ret;

  ret = OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &htoken2 );

  ret = LookupPrivilegeValue( NULL, SE_TCB_NAME, &tkp.Privileges[0].Luid );

  tkp.PrivilegeCount = 1;
  tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

  ret = AdjustTokenPrivileges( htoken2, FALSE, &tkp, 0, NULL, 0 );

  ret = LogonUser( "username", NULL, "password", LOGON32_LOGON_BATCH, LOGON32_PROVIDER_DEFAULT,
        &htoken );            
Avatar of jhance
jhance

Please note that checking ret is not enough.  To reference the SDK docs for AdjustTokenPrivileges:

Note:  The NewState parameter can specify privileges that the token does not have, without causing the function to fail. In this case, the function adjusts the privileges that the token does have, ignores the other privileges, and returns success. Call the GetLastError function to determine whether the function adjusted all of the specified privileges. The PreviousState parameter indicates the privileges that were adjusted.


If you check what GetLastError is returning, the problem will probably be clear.

Avatar of mars

ASKER

A) ret = LookupPrivilegeValue( NULL, SE_TCB_NAME, &tkp.Privileges[0].Luid );

I've error # 997, "An overlapping I/O operation is running"

B)ret = AdjustTokenPrivileges( htoken2, FALSE, &tkp, 0, NULL, 0 );

I've error # 1300, "The caller does not have all referenced privileges".

C)LogonUser( ... )

I've error # 1314, "Sufficient privilege missing"
   

Is this help you ?
I've error # 997, "An overlapping I/O operation is running"

Not an error from LookupPrivilegeValue.  No need to check this function's GetLastError().


I've error # 1300, "The caller does not have all referenced privileges".


So there you have it!  For some reason you requested SE_TCB_NAME but it was not granted.  Are you running this as administrator?

Actually, after looking at the SDK again I see that you shouldn't have to call AdjustTokenPrivileges at all.

From LogonUser():

The process that calls LogonUser must have the SE_TCB_NAME privilege. The privilege does not need to be enabled. The LogonUser function enables the privilege as necessary. If the calling process does not have this privilege, LogonUser fails and GetLastError returns ERROR_PRIVILEGE_NOT_HELD.


This confirms my theory that your account doesn't have this privilege enabled.  Both your call to AdjustTokenPrivileges and LogonUser fail to work.
Avatar of mars

ASKER

It's crazy, but i'm really logged in as an "Administrator". I see my account in the "AdministratorS" group.

I'm under Windows 2000, and i find very strange that i cannot detailed for each user, the pivilege granted or denied. For instance, i cannot add the "shutdown" privilege to ONE user.

Under Windows NT 4.0, it was possible.

Any ideas ?
Avatar of mars

ASKER

I runned my application under Win NT 4.0 as an Administrator user, the result is the same.

The detailed privileges under Win NT 4.0 can be modified under USRMGR.EXE, menu "Strategy", item "Users rights".
It does not exist under Win 2000 Management console.
Did you try LogonUser() without calling AdjustTokenPrivileges?
Avatar of jkr
>>I'm under Windows 2000, and i find
>>very strange that i cannot detailed
>>for each user, the pivilege granted
>>or denied. For instance, i cannot add
>>the "shutdown" privilege to ONE user.

You can. Go to the Control Panel, select the 'Administration' applet, choose 'Local Security Policy' and proceed to 'Conputer Configuration->Windows Settings->Security Settings->Local Policies->Granting User Privileges'. There you'll be able to grant 'SE_TCB_NAME' to 'Administrator' (it isn't granted by default). BTW, I'm not suer about the english names of the above (using a german Win2k).

<<The first and biggest of these restrictions is that the process calling LogonUser must have the SE_TCB_NAME privilege (in User Manager, this is the "Act as part of the Operating System" right)>>
ASKER CERTIFIED SOLUTION
Avatar of NickRepin
NickRepin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
listening...
Avatar of mars

ASKER

Great, it works perfectly. Thank you all of us.
>>If I'm not wrong, "Act as part of the Operating
>>System"  is not assigned to Administrators by default.

Err, mars, didn't I already mention this???
Avatar of mars

ASKER

Yes, you're right. I'm very disapointed about the experts exchange points. Your response helps me in DETAILED (i thank you for this). I realize TODAY, when i accepted an anwser, i made a mistake by choosing "NickRepin" answer.
NickRepin was right, but you anwsered correctly to my question before him.

I think, the points system must evolved in such a way, that i can choose not only one expert, but many experts, to be granted some SAME points (here: 100 points for each experts i grade).

Thank you for your precious help and keep going.

>>I think, the points system must
>>evolved in such a way, that i can
>>choose not only one expert, but many
>>experts, to be granted some SAME
>>points

However, you still could address the costomer service to handle such issues (http://www1.experts-exchange.com/Customer_Service/Experts_Exchange/)...
Avatar of mars

ASKER

Ok, i will suggest it.