- #include <windows.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <sddl.h>
- BOOL AllocateUnixUserSID(unsigned long uid, PSID *pSid)
- {
- // S-1-22-1-1
- #define SECURITY_SAMBA_UNIX_AUTHORITY {0,0,0,0,0,22}
- SID_IDENTIFIER_AUTHORITY sid_id_auth = SECURITY_SAMBA_UNIX_AUTHORITY;
- /*
- *
- * $ getent passwd Unix_User+0
- * Unix_User+0:*:4278190080:4278190080:U-Unix_User\0,S-1-22-1-0:/:/sbin/nologin
- *
- */
- // Create a new SID with the given ID authority and no sub-authorities
- if (AllocateAndInitializeSid(&sid_id_auth, 2, 1, (DWORD)uid, 0, 0, 0, 0, 0, 0, pSid)) {
- DWORD sid_len = GetLengthSid(*pSid);
- PSID malloced_sid;
- uid, (long)sid_len);
- CopySid(sid_len, malloced_sid, *pSid);
- FreeSid(*pSid);
- *pSid = malloced_sid;
- return TRUE;
- }
- else
- {
- uid, GetLastError());
- return FALSE;
- }
- }
- int fput_sidstr(FILE *f, PSID *sid)
- {
- LPSTR string_sid = NULL;
- int res;
- if (!ConvertSidToStringSidA(*sid, &string_sid)) {
- return -1;
- }
- LocalFree(string_sid);
- return res;
- }
- int main(int ac, char *av[])
- {
- // S-1-22-1-1
- PSID sid = 0;
- PSID new_sid = 0;
- LPSTR string_sid = NULL;
- #if 1
- // Create a new SID with the given ID authority and no sub-authorities
- if (!AllocateUnixUserSID(1616, &sid)) {
- return 1;
- }
- (void)fput_sidstr(stdout, &sid);
- // Stringify and print
- if (!ConvertSidToStringSidA(sid, &string_sid)) {
- FreeSid(sid);
- return 2;
- }
- // Destringify and print
- if (ConvertStringSidToSidA(string_sid, &new_sid)) {
- }
- else {
- }
- #endif
- /* Part 2 */
- LocalFree(string_sid);
- LocalFree(new_sid);
- sid = NULL;
- new_sid = NULL;
- string_sid = NULL;
- char sid_unix_user_buf[256];
- if (ConvertStringSidToSidA(sid_unix_user_buf, &sid)) {
- }
- else {
- }
- if (!ConvertSidToStringSidA(sid, &string_sid)) {
- FreeSid(sid);
- return 2;
- }
- // Destringify and print
- if (ConvertStringSidToSidA(string_sid, &new_sid)) {
- }
- else {
- }
- if (!ConvertSidToStringSidA(new_sid, &string_sid)) {
- FreeSid(sid);
- return 2;
- }
- // Clean up
- LocalFree(string_sid);
- LocalFree(new_sid);
- FreeSid(sid);
- }
sidunixuser1.c
Posted by Anonymous on Wed 4th Oct 2023 21:06
raw | new post
view followups (newest first): sidunixuser1.c by Anonymous
modification of post by Anonymous (view diff)
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.