There is setgroups(size_t size, const gid_t *list) method in C which would allow me to set the supplementary group ids of the calling process.
Question 1:
But in order run this we need to have proper rights so the only way I got to run this program without getting Operation not permitted error is to run it using root. But does that mean using this method we could only set the groups of root??
Question 2:
On the other hand what I intend to do is given a particular user and a list of gid's I want to set the given gid's as the supplementary groups to given user. Is there a method defined for this in C/C++?
Thanks in advance
Technically under Linux you need the CAP_SETGID capability, which need not be root (but normally is).
Note that this works with the effective gid, not the actual gid. Note also the actual / effective gid of the calling process is not necessarily the same as the actual / effective uid. You should have a look at the manpages for setuid, seteuid, setgid and setegid for more details, but one scenario would be for a SUID program to setegid back to an unprivileged group then use setgroups.
Related
Is anyone aware of an easy (easier) way to obtain or create some 'mainstream' SECURITY_DESCRIPTOR ?
In my case i just need something like an "Everyone can do anything to this" for a CreateMutex call (if I pass NULL(meaning default) a non-elevated user cannot obtain the mutex created by an elevated one). This is sort of the same thing you see when you look at the security tab of a file - and it can be quite verbose.
MSDN has an example of how to create one from scratch:
https://learn.microsoft.com/da-dk/windows/desktop/SecAuthZ/creating-a-security-descriptor-for-a-new-object-in-c--
As you can see, it is very verbose (4-5 steps needed). I guess Im hoping for a higher level function that makes this trivial or something like query the system for the "Everyone" group and copy from that, etc.
I have a BHO which on the first run is gathering activation information and storing this in the registry.
(I think) due to IE's permission's I am only able to store this in the registry branch
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\InternetRegistry\REGISTRY\USER\S-0-0-00-000000000-000000000-000000000-0000\Software\MyBHO\MyKey
Where S-0-0-00-000000000-000000000-000000000-0000 is a unique key for each user.
Which is fine using RegCreateKey() with "Software\MyBHO\MyKey". It's all created and running lovely. It determines where in space to store the Key with no problems.
The Problem:
When I carry out an uninstall I want to remove this key and as this is run outside of IE I have no way to determine where that key is / what the user string is.
Options I have in mind:
Option 1 (Ideal)
Find out this user string first to then build a new path for the key I wish to remove and remove it. How?
Option 2
At the point of activation store the path to the key in another registry value that can be accessed. Then read, and delete both (Which seems a bit backwards and probably wont work due to the access restrictions of the BHO on the registry (Thus it being written there in the first place))
Do you know if there is any way to find this User key or even how to find the parent dir.
Edit Upon continued research I've found that the thing I'm referring to as "user key" is the current Users "SID". Maybe this will yield me better results.
Call GetUserName to get the user name, and LookupAccountName to get his SID.
ConvertSidToStringSid is a useful utility function to format a SID as a S-1-5-32-00000000-00000000-00000000-00000000-0000 string
If you really want to write per-user data to the registry, use IEGetWriteableHKCU().
In general there is no good way to remove per-user data at uninstall. For example, what if you install as user A and the uninstall as user B? Are you going to go find all of them and delete them? Just leave the turds behind.
Alternatively you could consider using a different data store. Do you really need the registry? Can you store this data in a file? What about Web Storage?
I am writing some C++ code for the Windows(XP/7) platform to check the permission associated to a file. I want to verify that the file I am reading cannot be written by accounts with non elevated privileges. This is what I am currently doing:
I get the DACL associated with the file calling GetNamedSecurityInfo
I call CreateWellKnownSid with well known Sids, such as WinAuthenticatedUserSid (the Users group)
I call BuildTrusteeWithSid to build a TRUSTEE with the previous SID
I call GetEffectiveRightsFromAcl with the previously created trustee to get the effective acl
I check that the ACL does not contain the Write Flag set.
This code is working perfectly for the Users group. What about the other groups such as Everyone, Guests, or other specific users which may have specific write access on the file? I would like to find a solution where I don't need to enumerate all possible SID and check against all of them. Is there a SID I could use such as "anything but not admin"?
Regards,
Ant
I'd take a slightly different approach:
Get all ACE's via GetExplicitEntriesFromAcl, for the file and all its parents
Select the GRANT_ACCESS and SET_ACCESS ACE's
Get the list of trustees from the selected ACE's
For each of the trustees, perform an access check. GetEffectiveRightsFromAcl is probably the easiest solution here.
You'll want to think specifically what you want to do with the OWNER. He can alter the rights at any time.
Using my c++ program how can I find out what group the current user running my program belongs to? So my program need to figure out a couple of things :
The current username of the user
The group the user belongs to
How can do the above 2 using c++ on a RedHat / Linux machine?
With getuid(2) and getgid(2). See credentials(7) for more information.
Use getpwuid(3) and getgrgid(3) for the names.
You can find some of the information via getgid() (real GID) and getegid() (effective GID). For the other auxilliary groups, you need to use getgroups().
In practice, the real and effective GID are normally the same, but it is the effective GID that is used when creating a file. Usually, the group list returned by getgroups() includes the real group - though it is not clear that it actually has to do so.
You use getuid(2) and getgid(2) to get the numeric user and group ids, then use getpwuid(3) and getgrgid(3) to look up those ids in the user/group databases and turn them into text names.
Would someone be able to point me to the C++ API's that I can use to display a list of processes and the user name in Windows?
My current code uses the CreateToolhelp32Snapshot Function which shows all the processes running for all users, but I do not know what API's to use to retreieve the user name so I can filter it by user. I do not need to use CreateToolhelp32Snapshot, and I have seen other methods to retrieve the process list, but none seem to get me the user name that is running the process.
Thanks for any help.
I know that using GetTokenInformation with TokenUser gets you the SID, and a quick serach reveals that LookupAccountSid should get you the corresponding account. Havent't tried that last one myself though.
Well this link appears to have helpful code for you. Apply the code contained there in to the Token handle you get from calling OpenProcessToken on the handle you get from Process32First/Next.