[169] | 1 | /* |
---|
| 2 | * Copyright (C) 2005,2009-2010 Timothy D. Morgan |
---|
[132] | 3 | * Copyright (C) 1992-2005 Samba development team |
---|
[133] | 4 | * |
---|
[132] | 5 | * This program is free software; you can redistribute it and/or modify |
---|
| 6 | * it under the terms of the GNU General Public License as published by |
---|
| 7 | * the Free Software Foundation; version 3 of the License. |
---|
| 8 | * |
---|
| 9 | * This program is distributed in the hope that it will be useful, |
---|
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | * GNU General Public License for more details. |
---|
| 13 | * |
---|
| 14 | * You should have received a copy of the GNU General Public License |
---|
| 15 | * along with this program; if not, write to the Free Software |
---|
| 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 17 | * |
---|
[133] | 18 | * $Id: winsec.h 169 2010-03-03 19:24:58Z tim $ |
---|
[132] | 19 | */ |
---|
| 20 | |
---|
[169] | 21 | /** |
---|
| 22 | * @file |
---|
| 23 | * |
---|
| 24 | * A small library for interpreting Windows Security Descriptors. |
---|
| 25 | * This library was originally based on Samba source from: |
---|
| 26 | * http://websvn.samba.org/cgi-bin/viewcvs.cgi/trunk/source/ |
---|
| 27 | * |
---|
| 28 | * The library has been heavily rewritten and improved based on information |
---|
| 29 | * provided by Microsoft at: |
---|
| 30 | * http://msdn.microsoft.com/en-us/library/cc230366%28PROT.10%29.aspx |
---|
| 31 | */ |
---|
| 32 | |
---|
[134] | 33 | #ifndef _WINSEC_H |
---|
| 34 | #define _WINSEC_H |
---|
| 35 | |
---|
[132] | 36 | #include <stdlib.h> |
---|
| 37 | #include <stdbool.h> |
---|
[134] | 38 | #include <stdint.h> |
---|
[132] | 39 | #include <stdio.h> |
---|
| 40 | #include <string.h> |
---|
| 41 | #include <errno.h> |
---|
| 42 | #include <fcntl.h> |
---|
| 43 | #include <sys/stat.h> |
---|
| 44 | #include <sys/types.h> |
---|
| 45 | #include <unistd.h> |
---|
| 46 | |
---|
[147] | 47 | #include "talloc.h" |
---|
[168] | 48 | #include "byteorder.h" |
---|
[132] | 49 | |
---|
| 50 | |
---|
[134] | 51 | /* This is the maximum number of subauths in a SID, as defined here: |
---|
| 52 | * http://msdn.microsoft.com/en-us/library/cc230371(PROT.10).aspx |
---|
| 53 | */ |
---|
| 54 | #define WINSEC_MAX_SUBAUTHS 15 |
---|
[132] | 55 | |
---|
[134] | 56 | #define WINSEC_DESC_HEADER_SIZE (5 * sizeof(uint32_t)) |
---|
| 57 | #define WINSEC_ACL_HEADER_SIZE (2 * sizeof(uint32_t)) |
---|
| 58 | #define WINSEC_ACE_MIN_SIZE 16 |
---|
[133] | 59 | |
---|
[148] | 60 | /* XXX: Fill in definitions of other flags */ |
---|
| 61 | /* This self relative flag means offsets contained in the descriptor are relative |
---|
| 62 | * to the descriptor's offset. This had better be true in the registry. |
---|
[134] | 63 | */ |
---|
| 64 | #define WINSEC_DESC_SELF_RELATIVE 0x8000 |
---|
| 65 | #define WINSEC_DESC_SACL_PRESENT 0x0010 |
---|
| 66 | #define WINSEC_DESC_DACL_PRESENT 0x0004 |
---|
[133] | 67 | |
---|
[134] | 68 | #define WINSEC_ACE_OBJECT_PRESENT 0x00000001 |
---|
| 69 | #define WINSEC_ACE_OBJECT_INHERITED_PRESENT 0x00000002 |
---|
| 70 | #define WINSEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT 0x5 |
---|
| 71 | #define WINSEC_ACE_TYPE_ACCESS_DENIED_OBJECT 0x6 |
---|
| 72 | #define WINSEC_ACE_TYPE_SYSTEM_AUDIT_OBJECT 0x7 |
---|
| 73 | #define WINSEC_ACE_TYPE_SYSTEM_ALARM_OBJECT 0x8 |
---|
[133] | 74 | |
---|
[134] | 75 | |
---|
[169] | 76 | /** XXX: document this. */ |
---|
[148] | 77 | typedef struct _winsec_uuid |
---|
[132] | 78 | { |
---|
[169] | 79 | /** XXX: document this. */ |
---|
| 80 | uint32_t time_low; |
---|
| 81 | |
---|
| 82 | /** XXX: document this. */ |
---|
| 83 | uint16_t time_mid; |
---|
| 84 | |
---|
| 85 | /** XXX: document this. */ |
---|
| 86 | uint16_t time_hi_and_version; |
---|
| 87 | |
---|
| 88 | /** XXX: document this. */ |
---|
| 89 | uint8_t clock_seq[2]; |
---|
| 90 | |
---|
| 91 | /** XXX: document this. */ |
---|
| 92 | uint8_t node[6]; |
---|
[134] | 93 | } WINSEC_UUID; |
---|
| 94 | |
---|
| 95 | |
---|
[169] | 96 | /** XXX: document this. */ |
---|
[134] | 97 | typedef struct _winsec_sid |
---|
| 98 | { |
---|
[169] | 99 | /** SID revision number */ |
---|
| 100 | uint8_t sid_rev_num; |
---|
| 101 | |
---|
| 102 | /** Number of sub-authorities */ |
---|
| 103 | uint8_t num_auths; |
---|
| 104 | |
---|
| 105 | /** Identifier Authority */ |
---|
| 106 | uint8_t id_auth[6]; |
---|
| 107 | |
---|
| 108 | /** Pointer to sub-authorities. |
---|
| 109 | * |
---|
[134] | 110 | * @note The values in these uint32_t's are in *native* byteorder, not |
---|
[132] | 111 | * neccessarily little-endian...... JRA. |
---|
| 112 | */ |
---|
[169] | 113 | uint32_t sub_auths[WINSEC_MAX_SUBAUTHS]; /* XXX: Make this dynamically allocated? */ |
---|
[134] | 114 | } WINSEC_DOM_SID; |
---|
[132] | 115 | |
---|
| 116 | |
---|
[169] | 117 | /** XXX: document this. */ |
---|
[134] | 118 | typedef struct _winsec_ace |
---|
[132] | 119 | { |
---|
[169] | 120 | /** xxxx_xxxx_ACE_TYPE - e.g allowed / denied etc */ |
---|
| 121 | uint8_t type; |
---|
[132] | 122 | |
---|
[169] | 123 | /** xxxx_INHERIT_xxxx - e.g OBJECT_INHERIT_ACE */ |
---|
| 124 | uint8_t flags; |
---|
[132] | 125 | |
---|
[169] | 126 | /** XXX: finish documenting */ |
---|
| 127 | uint16_t size; |
---|
[132] | 128 | |
---|
[169] | 129 | /** XXX: finish documenting */ |
---|
| 130 | uint32_t access_mask; |
---|
| 131 | |
---|
| 132 | /* This stuff may be present when type is XXXX_TYPE_XXXX_OBJECT */ |
---|
| 133 | |
---|
| 134 | /** xxxx_ACE_OBJECT_xxxx e.g present/inherited present etc */ |
---|
| 135 | uint32_t obj_flags; |
---|
| 136 | |
---|
| 137 | /** Object GUID */ |
---|
| 138 | WINSEC_UUID* obj_guid; |
---|
| 139 | |
---|
| 140 | /** Inherited object GUID */ |
---|
| 141 | WINSEC_UUID* inh_guid; |
---|
| 142 | |
---|
| 143 | /* eof object stuff */ |
---|
| 144 | |
---|
| 145 | /** XXX: finish documenting */ |
---|
| 146 | WINSEC_DOM_SID* trustee; |
---|
| 147 | |
---|
[134] | 148 | } WINSEC_ACE; |
---|
[132] | 149 | |
---|
[169] | 150 | |
---|
| 151 | /** XXX: document this. */ |
---|
[134] | 152 | typedef struct _winsec_acl |
---|
[132] | 153 | { |
---|
[169] | 154 | /** 0x0003 */ |
---|
| 155 | uint16_t revision; |
---|
[132] | 156 | |
---|
[169] | 157 | /** Size, in bytes, of the entire ACL structure */ |
---|
| 158 | uint16_t size; |
---|
[132] | 159 | |
---|
[169] | 160 | /** Number of Access Control Entries */ |
---|
| 161 | uint32_t num_aces; |
---|
| 162 | |
---|
| 163 | /** XXX: document this. */ |
---|
| 164 | WINSEC_ACE** aces; |
---|
| 165 | |
---|
[134] | 166 | } WINSEC_ACL; |
---|
[132] | 167 | |
---|
[169] | 168 | |
---|
| 169 | /** XXX: document this. */ |
---|
[134] | 170 | typedef struct _winsec_desc |
---|
[132] | 171 | { |
---|
[169] | 172 | /** 0x01 */ |
---|
| 173 | uint8_t revision; |
---|
[132] | 174 | |
---|
[169] | 175 | /** XXX: better explain this |
---|
| 176 | * |
---|
| 177 | * "If the Control field has the RM flag set, then this field contains the |
---|
| 178 | * resource manager (RM) control value. ... Otherwise, this field is reserved |
---|
| 179 | * and MUST be set to zero." -- Microsoft. |
---|
| 180 | * See: |
---|
| 181 | * http://msdn.microsoft.com/en-us/library/cc230371%28PROT.10%29.aspx |
---|
| 182 | */ |
---|
| 183 | uint8_t sbz1; |
---|
[132] | 184 | |
---|
[169] | 185 | /** WINSEC_DESC_* flags */ |
---|
| 186 | uint16_t control; |
---|
| 187 | |
---|
| 188 | /** Offset to owner sid */ |
---|
| 189 | uint32_t off_owner_sid; |
---|
[132] | 190 | |
---|
[169] | 191 | /** Offset to group sid */ |
---|
| 192 | uint32_t off_grp_sid; |
---|
| 193 | |
---|
| 194 | /** Offset to system list of permissions */ |
---|
| 195 | uint32_t off_sacl; |
---|
| 196 | |
---|
| 197 | /** Offset to list of permissions */ |
---|
| 198 | uint32_t off_dacl; |
---|
| 199 | |
---|
| 200 | /** XXX: document this */ |
---|
| 201 | WINSEC_DOM_SID* owner_sid; |
---|
| 202 | |
---|
| 203 | /** XXX: document this */ |
---|
| 204 | WINSEC_DOM_SID* grp_sid; |
---|
| 205 | |
---|
| 206 | /** System ACL */ |
---|
| 207 | WINSEC_ACL* sacl; |
---|
| 208 | |
---|
| 209 | /** User ACL */ |
---|
| 210 | WINSEC_ACL* dacl; |
---|
| 211 | |
---|
[134] | 212 | } WINSEC_DESC; |
---|
[132] | 213 | |
---|
[169] | 214 | |
---|
| 215 | /** |
---|
| 216 | * |
---|
| 217 | * XXX: finish documenting |
---|
| 218 | */ |
---|
[147] | 219 | WINSEC_DESC* winsec_parse_descriptor(const uint8_t* buf, uint32_t buf_len); |
---|
[169] | 220 | |
---|
| 221 | |
---|
| 222 | /** |
---|
| 223 | * |
---|
| 224 | * XXX: finish documenting |
---|
| 225 | */ |
---|
[147] | 226 | void winsec_free_descriptor(WINSEC_DESC* desc); |
---|
[132] | 227 | |
---|
[169] | 228 | /** |
---|
| 229 | * |
---|
| 230 | * XXX: finish documenting |
---|
| 231 | */ |
---|
[147] | 232 | WINSEC_DESC* winsec_parse_desc(void* talloc_ctx, |
---|
| 233 | const uint8_t* buf, uint32_t buf_len); |
---|
[169] | 234 | |
---|
| 235 | /** |
---|
| 236 | * |
---|
| 237 | * XXX: finish documenting |
---|
| 238 | */ |
---|
[147] | 239 | WINSEC_ACL* winsec_parse_acl(void* talloc_ctx, |
---|
| 240 | const uint8_t* buf, uint32_t buf_len); |
---|
[169] | 241 | |
---|
| 242 | /** |
---|
| 243 | * |
---|
| 244 | * XXX: finish documenting |
---|
| 245 | */ |
---|
[147] | 246 | WINSEC_ACE* winsec_parse_ace(void* talloc_ctx, |
---|
| 247 | const uint8_t* buf, uint32_t buf_len); |
---|
[169] | 248 | |
---|
| 249 | /** |
---|
| 250 | * |
---|
| 251 | * XXX: finish documenting |
---|
| 252 | */ |
---|
[147] | 253 | WINSEC_DOM_SID* winsec_parse_dom_sid(void* talloc_ctx, |
---|
| 254 | const uint8_t* buf, uint32_t buf_len); |
---|
[169] | 255 | |
---|
| 256 | /** |
---|
| 257 | * |
---|
| 258 | * XXX: finish documenting |
---|
| 259 | */ |
---|
[147] | 260 | WINSEC_UUID* winsec_parse_uuid(void* talloc_ctx, |
---|
| 261 | const uint8_t* buf, uint32_t buf_len); |
---|
[132] | 262 | |
---|
[169] | 263 | |
---|
| 264 | /** |
---|
| 265 | * |
---|
| 266 | * XXX: finish documenting |
---|
| 267 | */ |
---|
[134] | 268 | size_t winsec_sid_size(const WINSEC_DOM_SID* sid); |
---|
[169] | 269 | |
---|
| 270 | /** |
---|
| 271 | * |
---|
| 272 | * XXX: finish documenting |
---|
| 273 | */ |
---|
[134] | 274 | int winsec_sid_compare_auth(const WINSEC_DOM_SID* sid1, const WINSEC_DOM_SID* sid2); |
---|
[169] | 275 | |
---|
| 276 | /** |
---|
| 277 | * |
---|
| 278 | * XXX: finish documenting |
---|
| 279 | */ |
---|
[134] | 280 | int winsec_sid_compare(const WINSEC_DOM_SID* sid1, const WINSEC_DOM_SID* sid2); |
---|
[169] | 281 | |
---|
| 282 | /** |
---|
| 283 | * |
---|
| 284 | * XXX: finish documenting |
---|
| 285 | */ |
---|
[134] | 286 | bool winsec_sid_equal(const WINSEC_DOM_SID* sid1, const WINSEC_DOM_SID* sid2); |
---|
[169] | 287 | |
---|
| 288 | /** |
---|
| 289 | * |
---|
| 290 | * XXX: finish documenting |
---|
| 291 | */ |
---|
[134] | 292 | bool winsec_desc_equal(WINSEC_DESC* s1, WINSEC_DESC* s2); |
---|
[169] | 293 | |
---|
| 294 | /** |
---|
| 295 | * |
---|
| 296 | * XXX: finish documenting |
---|
| 297 | */ |
---|
[134] | 298 | bool winsec_acl_equal(WINSEC_ACL* s1, WINSEC_ACL* s2); |
---|
[169] | 299 | |
---|
| 300 | /** |
---|
| 301 | * |
---|
| 302 | * XXX: finish documenting |
---|
| 303 | */ |
---|
[134] | 304 | bool winsec_ace_equal(WINSEC_ACE* s1, WINSEC_ACE* s2); |
---|
[169] | 305 | |
---|
| 306 | /** |
---|
| 307 | * |
---|
| 308 | * XXX: finish documenting |
---|
| 309 | */ |
---|
[134] | 310 | bool winsec_ace_object(uint8_t type); |
---|
[132] | 311 | |
---|
[134] | 312 | #endif /* _WINSEC_H */ |
---|