Difference between
modified post e5f622e by Anonymous on Wed 4th Oct 2023 21:06
original post 9cfd by Anonymous on Wed 4th Oct 2023 09:17
Download diff
Show
old version |
new version |
both versions
| 1 | - | #include <iostream> | |
| 2 | - | #include <windows.h> | |
| 3 | - | #include <sddl.h> | |
| 1 | + | ||
| 2 | 2 | #include <windows.h> | |
| 3 | + | #include <stdlib.h> | |
| 3 | 5 | #include <sddl.h> | |
| 4 | 6 | ||
| 5 | - | int main() | |
| 7 | + | BOOL AllocateUnixUserSID(unsigned long uid, PSID *pSid) | |
| 6 | 8 | { | |
| 7 | 9 | // S-1-22-1-1 | |
| 8 | 10 | #define SECURITY_SAMBA_UNIX_AUTHORITY {0,0,0,0,0,22} | |
| 9 | 11 | SID_IDENTIFIER_AUTHORITY sid_id_auth = SECURITY_SAMBA_UNIX_AUTHORITY; | |
| 13 | 12 | ||
| 14 | 13 | /* | |
| 15 | 14 | * | |
| 16 | 15 | * $ getent passwd Unix_User+0 | |
| 17 | 16 | * Unix_User+0:*:4278190080:4278190080:U-Unix_User\0,S-1-22-1-0:/:/sbin/nologin | |
| 18 | 17 | * | |
| 19 | 18 | */ | |
| 20 | - | #if 0 | |
| 21 | 19 | // Create a new SID with the given ID authority and no sub-authorities | |
| 22 | - | if (!AllocateAndInitializeSid(&sid_id_auth, 2, 1, 0, 0, 0, 0, 0, 0, 0, &sid)) { | |
| 20 | + | if (AllocateAndInitializeSid(&sid_id_auth, 2, 1, (DWORD)uid, 0, 0, 0, 0, 0, 0, pSid)) { | |
| 23 | - | std::cout << "Failed to allocate SID: error code " << GetLastError() << std::endl; | |
| 21 | + | DWORD sid_len = GetLengthSid(*pSid); | |
| 24 | - | return 1; | |
| 22 | + | PSID malloced_sid; | |
| 23 | + | (void)printf("AllocateUnixUserSID(): Allocated Unix_User+%lu: success, len=%ld\n", | |
| 25 | 30 | } | |
| 31 | + | else | |
| 26 | 38 | ||
| 27 | - | // Stringify and print | |
| 39 | + | int fput_sidstr(FILE *f, PSID *sid) | |
| 28 | - | if (!ConvertSidToStringSidW(sid, &string_sid)) { | |
| 40 | + | { | |
| 29 | - | std::cout << "Failed to convert to string: error code " << GetLastError() << std::endl; | |
| 41 | + | LPSTR string_sid = NULL; | |
| 30 | - | FreeSid(sid); | |
| 42 | + | int res; | |
| 31 | - | return 2; | |
| 43 | + | if (!ConvertSidToStringSidA(*sid, &string_sid)) { | |
| 44 | + | (void)printf("fput_sidstr: Failed to convert to string: error code %d\n", GetLastError()); | |
| 32 | 46 | } | |
| 33 | - | std::wcout << string_sid << std::endl; | |
| 47 | + | res = fputs(string_sid, f); | |
| 48 | + | LocalFree(string_sid); | |
| 34 | 51 | ||
| 35 | - | // Destringify and print | |
| 52 | + | int main(int ac, char *av[]) | |
| 36 | - | if (ConvertStringSidToSidW(string_sid, &new_sid)) { | |
| 53 | + | { | |
| 37 | - | std::cout << "Success" << std::endl; | |
| 54 | + | // S-1-22-1-1 | |
| 55 | + | PSID sid = 0; | |
| 38 | 64 | } | |
| 65 | + |
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.
rovema.kpaste.net RSS