Difference between
modified post 20c803b87 by Anonymous on Thu 5th Oct 2023 13:32
original post fd73f by Anonymous on Wed 4th Oct 2023 09:20
Download diff
Show
old version |
new version |
both versions
| 1 | 1 | diff --git a/daemon/acl.c b/daemon/acl.c | |
| 2 | - | index 3a86735..cb58f70 100644 | |
| 2 | + | index 3a86735..1145011 100644 | |
| 3 | 3 | --- a/daemon/acl.c | |
| 4 | 4 | +++ b/daemon/acl.c | |
| 5 | - | @@ -22,6 +22,7 @@ | |
| 5 | + | @@ -60,11 +60,16 @@ static int create_unknownsid(WELL_KNOWN_SID_TYPE type, PSID *sid, | |
| 6 | - | #include <Windows.h> | |
| 6 | + | dprintf(ACLLVL, "create_unknownsid: CreateWellKnownSid type %d returned %d " | |
| 7 | - | #include <strsafe.h> | |
| 7 | + | "GetLastError %d sid len %d needed\n", type, status, | |
| 8 | - | #include <sddl.h> | |
| 8 | + | GetLastError(), *sid_len); | |
| 9 | - | +#include <ctype.h> | |
| 9 | + | - if (status) | |
| 10 | - | ||
| 10 | + | - return ERROR_INTERNAL_ERROR; | |
| 11 | - | #include "nfs41_ops.h" | |
| 11 | + | + if (status) { | |
| 12 | - | #include "delegation.h" | |
| 12 | + | + status = ERROR_INTERNAL_ERROR; | |
| 13 | - | @@ -77,6 +78,34 @@ static int create_unknownsid(WELL_KNOWN_SID_TYPE type, PSID *sid, | |
| 13 | + | + goto err; | |
| 14 | - | return status; | |
| 14 | + | + } | |
| 15 | - | } | |
| 15 | + | status = GetLastError(); | |
| 16 | - | ||
| 16 | + | if (status != ERROR_INSUFFICIENT_BUFFER) | |
| 17 | - | +static | |
| 17 | + | - return status; | |
| 18 | - | +void allocate_SECURITY_SAMBA_UNIX_AUTHORITY(PSID *p_sid) | |
| 18 | + | + goto err; | |
| 19 | - | +{ | |
| 19 | + | +#if 1 | |
| 20 | - | + // S-1-22-1-1 | |
| 20 | + | +(*sid_len) += 128; | |
| 21 | - | +#define SECURITY_SAMBA_UNIX_AUTHORITY {0,0,0,0,0,22} | |
| 21 | + | +#endif | |
| 22 | - | + SID_IDENTIFIER_AUTHORITY sid_id_auth = SECURITY_SAMBA_UNIX_AUTHORITY; | |
| 22 | + | *sid = malloc(*sid_len); | |
| 23 | - | + PSID psid = 0; | |
| 23 | + | if (*sid == NULL) | |
| 24 | - | + /* | |
| 24 | + | return ERROR_INSUFFICIENT_BUFFER; | |
| 25 | - | + * | |
| 25 | + | @@ -73,6 +78,7 @@ static int create_unknownsid(WELL_KNOWN_SID_TYPE type, PSID *sid, | |
| 26 | - | + * $ getent passwd Unix_User+0 | |
| 26 | + | return ERROR_SUCCESS; | |
| 27 | - | + * Unix_User+0:*:4278190080:4278190080:U-Unix_User\0,S-1-22-1-0:/:/sbin/nologin | |
| 27 | + | free(*sid); | |
| 28 | - | + * | |
| 28 | + | status = GetLastError(); | |
| 29 | - | + */ | |
| 29 | + | +err: | |
| 30 | - | + // Create a new SID with the given ID authority and no sub-authorities | |
| 30 | + | eprintf("create_unknownsid: CreateWellKnownSid failed with %d\n", status); | |
| 31 | - | + if (!AllocateAndInitializeSid(&sid_id_auth, 2, 1, 0, 0, 0, 0, 0, 0, 0, &psid)) { | |
| 31 | + | return status; | |
| 32 | - | + dprintf(ACLLVL, "allocate_SECURITY_SAMBA_UNIX_AUTHORITY failed\n"); | |
| 32 | + | } | |
| 33 | - | + | |
| 33 | + | @@ -90,20 +96,131 @@ static void convert_nfs4name_2_user_domain(LPSTR nfs4name, | |
| 34 | - | + PSID newsid = malloc(128); | |
| 34 | + | } | |
| 35 | - | + (void)CopySid(128, newsid, psid); | |
| 35 | + | } | |
| 36 | - | + *p_sid = newsid; | |
| 36 | + | ||
| 37 | - | + } | |
| 37 | + | +/* | |
| 38 | - | + else | |
| 38 | + | + * Allocate a SID from SECURITY_SAMBA_UNIX_AUTHORITY, which encodes an | |
| 39 | - | + { | |
| 39 | + | + * UNIX/POSIX uid directly into a SID. | |
| 40 | - | + dprintf(ACLLVL, "allocate_SECURITY_SAMBA_UNIX_AUTHORITY success\n"); | |
| 40 | + | + * | |
| 41 | - | + } | |
| 41 | + | + * Example: | |
| 42 | - | +} | |
| 42 | + | + * UID 1616 gets mapped to "Unix_User+1616", encoding the UID into the | |
| 43 | + | + * SID as "S-1-22-1-1616" | |
| 43 | 48 | + | |
| 49 | + | +/* S-1-22-1-0 for uid 0 */ | |
| 44 | 52 | + | |
| 45 | - | static void convert_nfs4name_2_user_domain(LPSTR nfs4name, | |
| 53 | + | +BOOL AllocateUnixUserSID(unsigned long uid, PSID *pSid) | |
| 46 | - | LPSTR *domain) | |
| 54 | + | +{ | |
| 47 | - | { | |
| 55 | + | + PSID sid = NULL; | |
| 48 | - | @@ -96,6 +125,34 @@ static int map_name_2_sid(DWORD *sid_len, PSID *sid, LPCSTR name) | |
| 56 | + | + PSID malloced_sid = NULL; | |
| 49 | - | SID_NAME_USE sid_type; | |
| 57 | + | + DWORD sid_len; | |
| 53 | 58 | + | |
| 54 | - | + if (isdigit(name[0])) { | |
| 59 | + | + if (AllocateAndInitializeSid(&sid_id_auth, 2, 1, (DWORD)uid, | |
| 55 | - | + unsigned long num = atol(name); | |
| 60 | + | + 0, 0, 0, 0, 0, 0, &sid)) { | |
| 56 | - | + switch (num) { | |
| 61 | + | + sid_len = GetLengthSid(sid); | |
| 57 | - | + case 1000: | |
| 62 | + | +#if 1 | |
| 58 | - | + case 197608: | |
| 63 | + | +sid_len += 128; | |
| 59 | - | + dprintf(ACLLVL, "map_name_2_sid: remap %ld to 'roland_mainz'\n", num); | |
| 64 | + | +#endif | |
| 60 | - | + name = "roland_mainz"; | |
| 65 | + | + malloced_sid = malloc(sid_len); | |
| 64 | 66 | + | |
| 65 | - | + (void)snprintf(modnamebuf, sizeof(modnamebuf), "S-1-22-1-%lu", num); | |
| 67 | + | + if (malloced_sid) { | |
| 66 | - | + SetLastError(0); | |
| 68 | + | + /* | |
| 67 | - | + if (ConvertStringSidToSidA(modnamebuf, *sid)) { | |
| 69 | + | + * |AllocateAndInitializeSid()| has an own memory | |
| 68 | - | + dprintf(ACLLVL, "map_name_2_sid: lookup Unix_User+%ld for '%s'=='%s' success\n", | |
| 70 | + | + * allocator, but we need the sid in memory from | |
| 69 | - | + num, name, modnamebuf); | |
| 71 | + | + * |malloc()| | |
| 70 | - | + return ERROR_SUCCESS; | |
| 72 | + | + */ | |
| 71 | - | + } | |
| 73 | + | + if (CopySid(sid_len, malloced_sid, sid)) { | |
| 72 | - | + status = GetLastError(); | |
| 74 | + | + FreeSid(sid); | |
| 73 | - | + dprintf(ACLLVL, "map_name_2_sid: lookup Unix_User+%ld for '%s'=='%s' returned %d\n", | |
| 75 | + | + *pSid = malloced_sid; | |
| 74 | - | + num, name, modnamebuf, status); | |
| 76 | + | + dprintf(ACLLVL, "AllocateUnixUserSID(): Allocated " | |
| 75 | - | + if (!status) | |
| 77 | + | + "Unix_User+%lu: success, len=%ld\n", | |
| 76 | - | + return status; | |
| 78 | + | + uid, (long)sid_len); | |
| 77 | - | + name = modnamebuf; | |
| 79 | + | + return TRUE; | |
| 80 | + | + } | |
| 78 | 81 | + } | |
| 79 | 82 | + } | |
| 80 | - | ||
| 83 | + | + | |
| 81 | - | status = LookupAccountName(NULL, name, NULL, sid_len, NULL, &tmp, &sid_type); | |
| 84 | + | + FreeSid(sid); | |
| 82 | - | dprintf(ACLLVL, "map_name_2_sid: LookupAccountName for %s returned %d " | |
| 85 | + | + free(malloced_sid); | |
| 83 | - | @@ -107,6 +164,10 @@ static int map_name_2_sid(DWORD *sid_len, PSID *sid, LPCSTR name) | |
| 86 | + | + dprintf(ACLLVL, "AllocateUnixUserSID(): Failed to allocate " | |
| 84 | - | status = GetLastError(); | |
| 87 | + | + "Unix_User+%lu: error code %d\n", | |
| 85 | - | switch(status) { | |
| 88 | + | + uid, GetLastError()); | |
| 86 | - | case ERROR_INSUFFICIENT_BUFFER: | |
| 89 | + | + return FALSE; | |
| 87 | - | +#if 1 | |
| 90 | + | +} | |
| 88 | - | + (*sid_len)+=128; | |
| 91 | + | + | |
| 89 | - | + tmp += 128; | |
| 92 | + | static int map_name_2_sid(DWORD *sid_len, PSID *sid, LPCSTR name) | |
| 90 | - | +#endif | |
| 93 | + | { | |
| 91 | - | *sid = malloc(*sid_len); | |
| 94 | + | int status = ERROR_INTERNAL_ERROR; | |
| 92 | - | if (*sid == NULL) { | |
| 95 | + | SID_NAME_USE sid_type; | |
| 93 | - | status = GetLastError(); | |
| 96 | + | LPSTR tmp_buf = NULL; | |
| 94 | - | @@ -798,4 +859,4 @@ const nfs41_upcall_op nfs41_op_setacl = { | |
| 97 | + | DWORD tmp = 0; | |
| 95 | - | parse_setacl, | |
| 98 | + | + signed long name_uid = -1; | |
| 96 | - | handle_setacl, | |
| 99 | + | + | |
| 97 | - | marshall_setacl | |
| 100 | + | + if (isdigit(name[0])) { | |
| 98 | - | -}; | |
| 101 | + | + /* fixme: |name| can be a group name, too */ | |
| 99 | - | \ No newline at end of file | |
| 102 | + | + name_uid = atol(name); | |
| 100 | - | +}; | |
| 103 | + | + } | |
| 101 | - | ||
| 104 | + | + else if(!strcmp(name, "nobody")) { | |
| 102 | - | ||
| 105 | + | + name_uid = 65534; | |
| 103 | - | ||
| 106 | + | + } | |
| 104 | - | ||
| 107 | + | + else if(!strcmp(name, "nogroup")) { | |
| 105 | - | ||
| 108 | + | + name_uid = 65534; | |
| 106 | - | ||
| 109 | + | + } | |
| 107 | - | ||
| 110 | + | + else if(!strcmp(name, "root")) { | |
| 108 | - | ||
| 111 | + | + name_uid = 0; | |
| 109 | - | ||
| 112 | + | + } | |
| 110 | - | ||
| 113 | + | + else if(!strcmp(name, "rmainz")) { | |
| 111 | - | ||
| 114 | + | + name_uid = 1616; | |
| 112 | - | ||
| 115 | + | + } | |
| 113 | - | ||
| 116 | + | + else if(!strcmp(name, "swulsch")) { | |
| 114 | - | ||
| 117 | + | + name_uid = 1818; | |
| 115 | - | ||
| 118 | + | + } | |
| 116 | - | ||
| 119 | + | + else if(!strcmp(name, "mwenzel")) { | |
| 117 | - | ||
| 120 | + | + name_uid = 8239; | |
| 118 | - | ||
| 121 | + | + } | |
| 119 | - | ||
| 122 | + | + else if(!strcmp(name, "test001")) { | |
| 120 | - | ||
| 123 | + | + name_uid = 1000; | |
| 121 | - | ||
| 124 | + | + } | |
| 122 | - | ||
| 125 | + | + | |
| 123 | - | ||
| 126 | + | + if (name_uid != -1) { | |
| 124 | - | ||
| 127 | + | + switch (name_uid) { | |
| 125 | - | ||
| 128 | + | + case 1000: | |
| 126 | - | ||
| 129 | + | + case 197608: | |
| 127 | - | ||
| 130 | + | + dprintf(ACLLVL, "map_name_2_sid(name='%s'): " | |
| 128 | - | ||
| 131 | + | + "remap %ld to 'roland_mainz'\n", name, name_uid); | |
| 129 | - | ||
| 132 | + | + name = "roland_mainz"; | |
| 130 | - | ||
| 133 | + | + break; | |
| 131 | - | ||
| 134 | + | + default: | |
| 132 | - | ||
| 135 | + | + if (AllocateUnixUserSID(name_uid, sid)) { | |
| 133 | - | ||
| 136 | + | + dprintf(ACLLVL, "map_name_2_sid(name='%s'): " | |
| 134 | - | ||
| 137 | + | + "AllocateUnixUserSID(uid=%ld) success\n", | |
| 135 | - | ||
| 138 | + | + name, name_uid); | |
| 136 | - | ||
| 139 | + | + return ERROR_SUCCESS; | |
| 137 | - | ||
| 140 | + | + } | |
| 138 | - | ||
| 141 | + | + | |
| 139 | - | ||
| 142 | + | + status = GetLastError(); | |
| 140 | - | ||
| 143 | + | + dprintf(ACLLVL, "map_name_2_sid(name='%s'): " | |
| 141 | - | ||
| 144 | + | + "AllocateUnixUserSID(uid=%ld) failed, error=%d\n", | |
| 142 | - | ||
| 145 | + | + name, name_uid, status); | |
| 143 | - | ||
| 146 | + | + return status; | |
| 144 | - | ||
| 147 | + | + } | |
| 145 | - | ||
| 148 | + | + } | |
| 146 | 149 | ||
| 147 | - | ||
| 150 | + | status = LookupAccountName(NULL, name, NULL, sid_len, NULL, &tmp, &sid_type); | |
| 148 | - | ||
| 151 | + | - dprintf(ACLLVL, "map_name_2_sid: LookupAccountName for %s returned %d " | |
| 149 | - | ||
| 152 | + | + dprintf(ACLLVL, "map_name_2_sid(name='%s'): LookupAccountName returned %d " | |
| 150 | - | ||
| 153 | + | "GetLastError %d name len %d domain len %d\n", name, status, | |
| 151 | - | ||
| 154 | + | GetLastError(), *sid_len, tmp); | |
| 152 | - | ||
| 155 | + | if (status) | |
| 153 | - | ||
| 156 | + | return ERROR_INTERNAL_ERROR; | |
| 154 | 157 | ||
| 155 | - | ||
| 158 | + | +#if 1 | |
| 156 | - | ||
| 159 | + | + (*sid_len)+=128; | |
| 157 | - | ||
| 160 | + | + tmp += 128; | |
| 158 | - | ||
| 161 | + | +#endif | |
| 159 | - | ||
| 162 | + | + | |
| 160 | - | ||
| 163 | + | status = GetLastError(); | |
| 161 | - | ||
| 164 | + | switch(status) { | |
| 162 | - | ||
| 165 | + | case ERROR_INSUFFICIENT_BUFFER: | |
| 163 | - | ||
| 166 | + | @@ -119,7 +236,7 @@ static int map_name_2_sid(DWORD *sid_len, PSID *sid, LPCSTR name) | |
| 164 | - | ||
| 167 | + | &tmp, &sid_type); | |
| 165 | - | ||
| 168 | + | free(tmp_buf); | |
| 166 | - | ||
| 169 | + | if (!status) { | |
| 167 | - | ||
| 170 | + | - eprintf("map_name_2_sid: LookupAccountName for %s failed " | |
| 168 | - | ||
| 171 | + | + eprintf("map_name_2_sid(name='%s'): LookupAccountName failed " | |
| 169 | - | ||
| 172 | + | "with %d\n", name, GetLastError()); | |
| 170 | - | ||
| 173 | + | goto out_free_sid; | |
| 171 | - | ||
| 174 | + | } else { | |
| 172 | - | ||
| 175 | + | @@ -140,15 +257,23 @@ static int map_name_2_sid(DWORD *sid_len, PSID *sid, LPCSTR name) | |
| 173 | - | ||
| 176 | + | status = ERROR_SUCCESS; | |
| 174 | - | ||
| 177 | + | break; | |
| 175 | - | ||
| 178 | + | case ERROR_NONE_MAPPED: | |
| 176 | - | ||
| 179 | + | + dprintf(1, "map_name_2_sid(name='%s'): none mapped, using WinNullSid mapping\n", | |
| 177 | - | ||
| 180 | + | + name); | |
| 178 | - | ||
| 181 | + | status = create_unknownsid(WinNullSid, sid, sid_len); | |
| 179 | - | ||
| 182 | + | if (status) | |
| 180 | - | ||
| 183 | + | goto out_free_sid; | |
| 181 | - | ||
| 184 | + | + break; | |
| 182 | - | ||
| 185 | + | + default: | |
| 183 | - | ||
| 186 | + | + dprintf(1, "map_name_2_sid(name='%s'): error %d not handled\n", | |
| 184 | - | ||
| 187 | + | + name, GetLastError()); | |
| 185 | - | ||
| 188 | + | + break; | |
| 186 | - | ||
| 189 | + | } | |
| 187 | - | ||
| 190 | + | out: | |
| 188 | - | ||
| 191 | + | return status; | |
| 189 | - | ||
| 192 | + | out_free_sid: | |
| 190 | - | ||
| 193 | + | status = GetLastError(); | |
| 191 | - | ||
| 194 | + | free(*sid); | |
| 192 | - | ||
| 195 | + | + *sid = NULL; | |
| 193 | - | ||
| 196 | + | goto out; | |
| 194 | - | ||
| 197 | + | } | |
| 195 | 198 | ||
| 196 | - | ||
| 199 | + | @@ -798,4 +923,4 @@ const nfs41_upcall_op nfs41_op_setacl = { | |
| 197 | - | ||
| 200 | + | parse_setacl, | |
| 198 | - | ||
| 201 | + | handle_setacl, | |
| 199 | - | ||
| 202 | + | marshall_setacl | |
| 200 | - | ||
| 203 | + | -}; | |
| 201 | - | ||
| 204 | + | \ No newline at end of file | |
| 202 | - | ||
| 205 | + | +}; | |
| 203 | 206 |
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