pastebin - collaborative debugging tool
rovema.kpaste.net RSS

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+
22
#include <windows.h>
3+
#include <stdlib.h>
35
#include <sddl.h>
46
5-
int main()
7+
BOOL AllocateUnixUserSID(unsigned long uid, PSID *pSid)
68
{
79
    // S-1-22-1-1
810
#define SECURITY_SAMBA_UNIX_AUTHORITY {0,0,0,0,0,22}
911
    SID_IDENTIFIER_AUTHORITY sid_id_auth = SECURITY_SAMBA_UNIX_AUTHORITY;
1312
1413
    /*
1514
     *
1615
     * $ getent passwd Unix_User+0
1716
     * Unix_User+0:*:4278190080:4278190080:U-Unix_User\0,S-1-22-1-0:/:/sbin/nologin
1817
     *
1918
     */
20-
#if 0
2119
    // 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",
2530
    }
31+
    else
2638
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());
3246
    }
33-
    std::wcout << string_sid << std::endl;
47+
    res = fputs(string_sid, f);
48+
    LocalFree(string_sid);
3451
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;
3864
    }
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.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at