pastebin - collaborative debugging tool
rovema.kpaste.net RSS

Difference between
modified post 6b7c6070ca by Anonymous on Thu 5th Oct 2023 09:10
original post e5f622e by Anonymous on Wed 4th Oct 2023 21:06
Download diff
Show old version | new version | both versions

    
1-
1+
/*
2-
#include <windows.h>
2+
 * sidunixuser1.c - test for Unix_User+$UID SIDs
3-
#include <stdlib.h>
3+
 *
4-
#include <stdio.h>
4+
 *
5-
#include <sddl.h>
5+
 * Test with:
6+
 * $  gcc -g -Wall sidunixuser1.c -o sidunixuser1 && gdb -ex=r --args ./sidunixuser1
611
7-
BOOL AllocateUnixUserSID(unsigned long uid, PSID *pSid)
12+
#include <windows.h>
8-
{
13+
#include <stdlib.h>
9-
    // S-1-22-1-1
14+
#include <stdio.h>
10-
#define SECURITY_SAMBA_UNIX_AUTHORITY {0,0,0,0,0,22}
15+
#include <sddl.h>
1216
1317
    /*
18+
 * Allocate a SID from SECURITY_SAMBA_UNIX_AUTHORITY, which encodes an
1420
     *
15-
     * $ getent passwd Unix_User+0
21+
 * Example:
16-
     * Unix_User+0:*:4278190080:4278190080:U-Unix_User\0,S-1-22-1-0:/:/sbin/nologin
22+
 * UID 1616 gets mapped to "Unix_User+1616", encoding the UID into the
23+
 * SID as "S-1-22-1-1616"
1726
     *
1827
     */
19-
    // Create a new SID with the given ID authority and no sub-authorities
28+
20-
    if (AllocateAndInitializeSid(&sid_id_auth, 2, 1, (DWORD)uid, 0, 0, 0, 0, 0, 0, pSid)) {
29+
/* S-1-22-1-0 for uid 0 */
21-
        DWORD sid_len = GetLengthSid(*pSid);
30+
#define SECURITY_SAMBA_UNIX_AUTHORITY { { 0,0,0,0,0,22 } }
22-
	PSID malloced_sid;
31+
SID_IDENTIFIER_AUTHORITY sid_id_auth = SECURITY_SAMBA_UNIX_AUTHORITY;
23-
        (void)printf("AllocateUnixUserSID(): Allocated Unix_User+%lu: success, len=%ld\n",
32+
24-
	    uid, (long)sid_len);
33+
BOOL AllocateUnixUserSID(unsigned long uid, PSID *pSid)
3234
    {
33-
        (void)printf("AllocateUnixUserSID(): Failed to allocate Unix_User+%lu: error code %d\n",
35+
    PSID sid = NULL;
34-
	    uid, GetLastError());
36+
    PSID malloced_sid = NULL;
35-
	return FALSE;
37+
    DWORD sid_len;
3838
39-
int fput_sidstr(FILE *f, PSID *sid)
39+
    if (AllocateAndInitializeSid(&sid_id_auth, 2, 1, (DWORD)uid, 0, 0, 0, 0, 0, 0, &sid)) {
40-
{
40+
        sid_len = GetLengthSid(sid);
41-
    LPSTR string_sid = NULL;
41+
	malloced_sid = malloc(sid_len);
5142
52-
int main(int ac, char *av[])
43+
	if (malloced_sid) {
53-
{
44+
	    /*
54-
    // S-1-22-1-1
45+
	     * |AllocateAndInitializeSid()| has an own memory
55-
    PSID sid = 0;
46+
	     * allocator, but we need the sid in memory from
56-
    PSID new_sid = 0;
47+
	     * |malloc()|
57-
    LPSTR string_sid = NULL;
48+
	     */
49+
	    if (CopySid(sid_len, malloced_sid, sid)) {
5858
59-
#if 1
59+
    FreeSid(sid);
60-
    // Create a new SID with the given ID authority and no sub-authorities
60+
    free(malloced_sid);
61-
    if (!AllocateUnixUserSID(1616, &sid)) {
61+
    (void)printf("AllocateUnixUserSID(): Failed to allocate Unix_User+%lu: error code %d\n",
62-
        (void)printf("Failed to allocate SID: error code %d\n", GetLastError());
62+
        uid, GetLastError());
63-
        return 1;
63+
    return FALSE;
6464
    }
6565
66-
    (void)printf("sid='");
66+
int fput_sidstr(FILE *f, PSID *sid)
67-
    (void)fput_sidstr(stdout, &sid);
67+
{
68-
    (void)printf("'\n");
68+
    LPSTR string_sid = NULL;
69+
    int res;
6978
70-
    // Stringify and print
79+
int main(int ac, char *av[])
71-
    if (!ConvertSidToStringSidA(sid, &string_sid)) {
80+
{
72-
        printf("Failed to convert to string: error code %d\n", GetLastError());
81+
    // S-1-22-1-1
73-
        FreeSid(sid);
82+
    PSID sid = NULL;
74-
        return 2;
83+
    PSID new_sid = NULL;
84+
    LPSTR string_sid = NULL;
7785
78-
    // Destringify and print
86+
    (void)puts("#start.");
87+
8193
    }
94+

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