|
|
#1 |
|
Senior Member
Join Date: Sep 2004
Location: Nottingham
Posts: 263
|
Check a user has a certain permission
Hi guys
Wondered if there's a way to see whether a user has the Logon As Service NT privilege. I want to grant this privilege if they don't have it (which is easy - if I perform the operation and the user already has the permission the plugin I use - UserMgr - just ignores it). The issue is that I only want to remove that permission in uninstall if they didn't not already have it. So basically I want to record in the Registry to remove the user privilege only if I added it in the first place! Any ideas? Thanks |
|
|
|
|
|
#2 |
|
M.I.A.
[NSIS Dev, Mod] Join Date: Oct 2001
Location: Israel
Posts: 11,337
|
You can call LsaEnumerateAccountRights or you can try using this privilege in the installer to see if it's granted already. I don't know of any plug-in that already does that.
NSIS FAQ | NSIS Home Page | Donate $ "I hear and I forget. I see and I remember. I do and I understand." -- Confucius |
|
|
|
|
|
#4 |
|
Senior Member
|
I am also interested in this. It involves allocation of an Lsa policy handle, something which I have been trying to do for a while now without any success, as stated in this thread.
CF [Edit] In general this is what you are looking for: The above code will not work for the LsaOpenPolicy handle and I do not know why. The LsaEnumerateAccountRights function will give you an array of structures that have the format listed here and the trick is to pay attention that the structures accept the sizes in bytes.code: Hope this helps as a starting point ... Last edited by CancerFace; 26th April 2006 at 11:27. |
|
|
|
|
|
#5 |
|
Senior Member
|
If it were not for kitchik's input in this thread I wouldn't be able to write this
![]() Here is what you are looking for: $R3 in the above code will hold the number of enumerated privileges in the array found in $R2. You can pull the privilleges out by callingcode: for the first structure, then calculate its size, advance to the next buffer ($R2 + size of first structure) and call it again. Repeat $R3 times ... The names of the privilleges are listed in NTSecAPI.hcode: CF |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Sep 2004
Location: Nottingham
Posts: 263
|
Hmm, thanks for that code, it looks ace, but I'm not sure how to carry on in the way you say. I'm not too au fait with how to finish this off to find the SE_SERVICE_LOGON_NAME privilege.
|
|
|
|
|
|
#7 |
|
Senior Member
|
Between the code that I posted on my previous reply and this MSDN page you should get an idea of what you're after. The definitions of the privileges are found in NTSecAPI.h of the windows SDK. Here are the basic ones straight out of that file:
so if I am reading this right, when you enumerate the privileges, you should end up with an array of LSA_UNICODE_STRING structures and each one contains one privilege, such as SeServiceLogonRight (which is the SE_SERVICE_LOGON_NAME privilege that you're after).code: In your case, one of the elements of the array will contain the SeServiceLogonRight privilege so $3 on my last piece of code will be equal to SeServiceLogonRight: code: I'll try to write this up for you as soon as I get some time. CF |
|
|
|
|
|
#8 |
|
Senior Member
Join Date: Sep 2004
Location: Nottingham
Posts: 263
|
Yeah, I'm seeing what you're saying, although I don't think I can yet translate that into what I need for myself. I tried seeing what was in r1, r2 and r3, I think r3 was "1" when the privilege was enabled, and "0" otherwise...don't know if that helps.
Thanks for your help man, you're obviously good at this
|
|
|
|
|
|
#9 | |
|
Senior Member
|
Quote:
![]() I played around a bit with this today but I was wrong to assume that the LsaEnumerateAccountRights function gives an array of LSA_UNICODE_STRING structures that you could call as I suggested on my previous post (although this is what M$ suggests in its MSDN page) According to this page the function gives an array but in order to unmarshal it you need to do this: code: Apparently I was not the only one who thought that we could get the data out using an LSA_UNICODE_STRING array as I suggested ![]() However, I failed to translate the above code to a working NSIS system call. This is where the real pros have to jump into this discussion ... CF |
|
|
|
|
|
|
#10 |
|
Senior Member
Join Date: Sep 2004
Location: Nottingham
Posts: 263
|
Ah mate, thanks for all your help. Hopefully someone even more experienced than you can help
|
|
|
|
|
|
#11 |
|
M.I.A.
[NSIS Dev, Mod] Join Date: Oct 2001
Location: Israel
Posts: 11,337
|
CancerFace, that page is talking about C#, not C. A few problems:
If I keep the lookup call with the following SID generation code, I get meaningful results, 5 of them. This hints there's a problem with the user's SID, or that I don't have any privileges (?!). The following code generates the SID for the Users group. Maybe I inherit all of my privileges from the groups that contain my user.code: NSIS FAQ | NSIS Home Page | Donate $ "I hear and I forget. I see and I remember. I do and I understand." -- Confucius |
|
|
|
|
|
#12 | |
|
Senior Member
|
@kichik
Quote:
If I create a new user and add some privilleges (logon as a service and/or anything else) then the LsaEnumerateAccountRights function returns the correct number of privileges and I am able to get the out in $3. If however I try to get the privileges for an account that has no extra privileges added, then I get the error that you mention. CF |
|
|
|
|
|
|
#13 |
|
Senior Member
Join Date: Sep 2004
Location: Nottingham
Posts: 263
|
Is it possible to pull all of that into one script?
![]() Thanks |
|
|
|
|
|
#14 |
|
Senior Member
|
I knew there was something I forgot to post here
![]() code: Note that if your user has no extra rights then the LsaEnumerateAccountRights gives a wierd error on $R8 which you can convert to a windows error using and in that case $R9 is equal to 2 (check what kitchik was talking about a few posts up)code: The rights will have the format that I posted before (for example SeInteractiveLogonRight) The above works for me ![]() CF |
|
|
|
|
|
#15 |
|
Senior Member
Join Date: Sep 2004
Location: Nottingham
Posts: 263
|
Perfect! Thank you so much guys, that's it exactly!
|
|
|
|
![]() |
|
|||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|