Mike McCormack | 36cd6f5 | 2003-07-24 00:07:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Tokens |
| 3 | * |
| 4 | * Copyright (C) 1998 Alexandre Julliard |
| 5 | * Copyright (C) 2003 Mike McCormack |
Robert Shearman | d2ea92d | 2005-04-22 21:17:15 +0000 | [diff] [blame] | 6 | * Copyright (C) 2005 Robert Shearman |
Mike McCormack | 36cd6f5 | 2003-07-24 00:07:00 +0000 | [diff] [blame] | 7 | * |
| 8 | * This library is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU Lesser General Public |
| 10 | * License as published by the Free Software Foundation; either |
| 11 | * version 2.1 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This library is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * Lesser General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Lesser General Public |
| 19 | * License along with this library; if not, write to the Free Software |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Mike McCormack | 36cd6f5 | 2003-07-24 00:07:00 +0000 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | #include "config.h" |
| 24 | |
| 25 | #include <assert.h> |
| 26 | #include <stdio.h> |
| 27 | #include <stdlib.h> |
Ge van Geldorp | 1a1583a | 2005-11-28 17:32:54 +0100 | [diff] [blame] | 28 | #include <stdarg.h> |
Rob Shearman | 8184bcc | 2007-10-03 13:09:33 +0100 | [diff] [blame] | 29 | #include <unistd.h> |
Mike McCormack | 36cd6f5 | 2003-07-24 00:07:00 +0000 | [diff] [blame] | 30 | |
Ge van Geldorp | 1a1583a | 2005-11-28 17:32:54 +0100 | [diff] [blame] | 31 | #include "ntstatus.h" |
| 32 | #define WIN32_NO_STATUS |
Mike McCormack | 36cd6f5 | 2003-07-24 00:07:00 +0000 | [diff] [blame] | 33 | #include "windef.h" |
Ge van Geldorp | 1a1583a | 2005-11-28 17:32:54 +0100 | [diff] [blame] | 34 | #include "winternl.h" |
Mike McCormack | 36cd6f5 | 2003-07-24 00:07:00 +0000 | [diff] [blame] | 35 | |
| 36 | #include "handle.h" |
| 37 | #include "thread.h" |
| 38 | #include "process.h" |
| 39 | #include "request.h" |
Robert Shearman | d2ea92d | 2005-04-22 21:17:15 +0000 | [diff] [blame] | 40 | #include "security.h" |
| 41 | |
Robert Shearman | 91eaea5 | 2005-07-18 13:22:55 +0000 | [diff] [blame] | 42 | #include "wine/unicode.h" |
| 43 | |
Robert Shearman | 2a782c6 | 2005-05-16 17:52:46 +0000 | [diff] [blame] | 44 | #define MAX_SUBAUTH_COUNT 1 |
| 45 | |
Robert Shearman | d2ea92d | 2005-04-22 21:17:15 +0000 | [diff] [blame] | 46 | const LUID SeIncreaseQuotaPrivilege = { 5, 0 }; |
| 47 | const LUID SeSecurityPrivilege = { 8, 0 }; |
| 48 | const LUID SeTakeOwnershipPrivilege = { 9, 0 }; |
| 49 | const LUID SeLoadDriverPrivilege = { 10, 0 }; |
| 50 | const LUID SeSystemProfilePrivilege = { 11, 0 }; |
| 51 | const LUID SeSystemtimePrivilege = { 12, 0 }; |
| 52 | const LUID SeProfileSingleProcessPrivilege = { 13, 0 }; |
| 53 | const LUID SeIncreaseBasePriorityPrivilege = { 14, 0 }; |
| 54 | const LUID SeCreatePagefilePrivilege = { 15, 0 }; |
| 55 | const LUID SeBackupPrivilege = { 17, 0 }; |
| 56 | const LUID SeRestorePrivilege = { 18, 0 }; |
| 57 | const LUID SeShutdownPrivilege = { 19, 0 }; |
| 58 | const LUID SeDebugPrivilege = { 20, 0 }; |
| 59 | const LUID SeSystemEnvironmentPrivilege = { 22, 0 }; |
| 60 | const LUID SeChangeNotifyPrivilege = { 23, 0 }; |
| 61 | const LUID SeRemoteShutdownPrivilege = { 24, 0 }; |
| 62 | const LUID SeUndockPrivilege = { 25, 0 }; |
| 63 | const LUID SeManageVolumePrivilege = { 28, 0 }; |
| 64 | const LUID SeImpersonatePrivilege = { 29, 0 }; |
| 65 | const LUID SeCreateGlobalPrivilege = { 30, 0 }; |
Mike McCormack | 36cd6f5 | 2003-07-24 00:07:00 +0000 | [diff] [blame] | 66 | |
Robert Shearman | 9b82644 | 2005-06-09 09:47:28 +0000 | [diff] [blame] | 67 | static const SID world_sid = { SID_REVISION, 1, { SECURITY_WORLD_SID_AUTHORITY }, { SECURITY_WORLD_RID } }; |
| 68 | static const SID local_sid = { SID_REVISION, 1, { SECURITY_LOCAL_SID_AUTHORITY }, { SECURITY_LOCAL_RID } }; |
| 69 | static const SID interactive_sid = { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_INTERACTIVE_RID } }; |
Rob Shearman | 8184bcc | 2007-10-03 13:09:33 +0100 | [diff] [blame] | 70 | static const SID anonymous_logon_sid = { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_ANONYMOUS_LOGON_RID } }; |
Robert Shearman | 9b82644 | 2005-06-09 09:47:28 +0000 | [diff] [blame] | 71 | static const SID authenticated_user_sid = { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_AUTHENTICATED_USER_RID } }; |
| 72 | static const SID local_system_sid = { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_LOCAL_SYSTEM_RID } }; |
Rob Shearman | cb124c9 | 2007-10-03 20:19:05 +0100 | [diff] [blame] | 73 | const PSID security_world_sid = (PSID)&world_sid; |
Robert Shearman | 91eaea5 | 2005-07-18 13:22:55 +0000 | [diff] [blame] | 74 | static const PSID security_local_sid = (PSID)&local_sid; |
| 75 | const PSID security_interactive_sid = (PSID)&interactive_sid; |
| 76 | static const PSID security_authenticated_user_sid = (PSID)&authenticated_user_sid; |
Rob Shearman | cb124c9 | 2007-10-03 20:19:05 +0100 | [diff] [blame] | 77 | const PSID security_local_system_sid = (PSID)&local_system_sid; |
Robert Shearman | 9b82644 | 2005-06-09 09:47:28 +0000 | [diff] [blame] | 78 | |
Alexandre Julliard | bf17ce8 | 2007-03-07 12:43:12 +0100 | [diff] [blame] | 79 | static luid_t prev_luid_value = { 1000, 0 }; |
Rob Shearman | df0d625 | 2007-02-15 23:20:48 +0000 | [diff] [blame] | 80 | |
Mike McCormack | 36cd6f5 | 2003-07-24 00:07:00 +0000 | [diff] [blame] | 81 | struct token |
| 82 | { |
| 83 | struct object obj; /* object header */ |
Alexandre Julliard | bf17ce8 | 2007-03-07 12:43:12 +0100 | [diff] [blame] | 84 | luid_t token_id; /* system-unique id of token */ |
| 85 | luid_t modified_id; /* new id allocated every time token is modified */ |
Robert Shearman | b0f02b2 | 2005-02-11 11:52:06 +0000 | [diff] [blame] | 86 | struct list privileges; /* privileges available to the token */ |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 87 | struct list groups; /* groups that the user of this token belongs to (sid_and_attributes) */ |
Robert Shearman | 2a782c6 | 2005-05-16 17:52:46 +0000 | [diff] [blame] | 88 | SID *user; /* SID of user this token represents */ |
Vitaliy Margolen | 6413a9c | 2007-02-09 09:24:53 -0700 | [diff] [blame] | 89 | SID *primary_group; /* SID of user's primary group */ |
Robert Shearman | f95ef09 | 2005-06-14 18:10:04 +0000 | [diff] [blame] | 90 | unsigned primary; /* is this a primary or impersonation token? */ |
Robert Shearman | fbf0ea9 | 2005-07-13 19:31:27 +0000 | [diff] [blame] | 91 | ACL *default_dacl; /* the default DACL to assign to objects created by this user */ |
Robert Shearman | d18711e | 2006-03-29 18:37:39 +0100 | [diff] [blame] | 92 | TOKEN_SOURCE source; /* source of the token */ |
Alexandre Julliard | f6d871e | 2008-03-26 14:38:49 +0100 | [diff] [blame] | 93 | int impersonation_level; /* impersonation level this token is capable of if non-primary token */ |
Robert Shearman | b0f02b2 | 2005-02-11 11:52:06 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | struct privilege |
| 97 | { |
| 98 | struct list entry; |
| 99 | LUID luid; |
Michael Stefaniuc | d40517c | 2005-05-09 09:26:28 +0000 | [diff] [blame] | 100 | unsigned enabled : 1; /* is the privilege currently enabled? */ |
| 101 | unsigned def : 1; /* is the privilege enabled by default? */ |
Mike McCormack | 36cd6f5 | 2003-07-24 00:07:00 +0000 | [diff] [blame] | 102 | }; |
| 103 | |
Robert Shearman | 3396a66 | 2006-05-13 16:58:19 +0100 | [diff] [blame] | 104 | struct group |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 105 | { |
| 106 | struct list entry; |
Robert Shearman | 9b82644 | 2005-06-09 09:47:28 +0000 | [diff] [blame] | 107 | unsigned enabled : 1; /* is the sid currently enabled? */ |
| 108 | unsigned def : 1; /* is the sid enabled by default? */ |
| 109 | unsigned logon : 1; /* is this a logon sid? */ |
| 110 | unsigned mandatory: 1; /* is this sid always enabled? */ |
| 111 | unsigned owner : 1; /* can this sid be an owner of an object? */ |
| 112 | unsigned resource : 1; /* is this a domain-local group? */ |
| 113 | unsigned deny_only: 1; /* is this a sid that should be use for denying only? */ |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 114 | SID sid; |
| 115 | }; |
| 116 | |
Mike McCormack | 36cd6f5 | 2003-07-24 00:07:00 +0000 | [diff] [blame] | 117 | static void token_dump( struct object *obj, int verbose ); |
Alexandre Julliard | 5fb2e68 | 2005-12-12 15:01:08 +0100 | [diff] [blame] | 118 | static unsigned int token_map_access( struct object *obj, unsigned int access ); |
Robert Shearman | b0f02b2 | 2005-02-11 11:52:06 +0000 | [diff] [blame] | 119 | static void token_destroy( struct object *obj ); |
Mike McCormack | 36cd6f5 | 2003-07-24 00:07:00 +0000 | [diff] [blame] | 120 | |
| 121 | static const struct object_ops token_ops = |
| 122 | { |
| 123 | sizeof(struct token), /* size */ |
| 124 | token_dump, /* dump */ |
Alexandre Julliard | 8382eb0 | 2007-12-05 18:16:42 +0100 | [diff] [blame] | 125 | no_get_type, /* get_type */ |
Mike McCormack | 36cd6f5 | 2003-07-24 00:07:00 +0000 | [diff] [blame] | 126 | no_add_queue, /* add_queue */ |
| 127 | NULL, /* remove_queue */ |
| 128 | NULL, /* signaled */ |
Mike McCormack | f92fff6 | 2005-04-24 17:35:52 +0000 | [diff] [blame] | 129 | NULL, /* satisfied */ |
| 130 | no_signal, /* signal */ |
Mike McCormack | 36cd6f5 | 2003-07-24 00:07:00 +0000 | [diff] [blame] | 131 | no_get_fd, /* get_fd */ |
Alexandre Julliard | 5fb2e68 | 2005-12-12 15:01:08 +0100 | [diff] [blame] | 132 | token_map_access, /* map_access */ |
Rob Shearman | c1707d8 | 2007-10-03 13:10:37 +0100 | [diff] [blame] | 133 | default_get_sd, /* get_sd */ |
| 134 | default_set_sd, /* set_sd */ |
Vitaliy Margolen | baffcb9 | 2005-11-22 14:55:42 +0000 | [diff] [blame] | 135 | no_lookup_name, /* lookup_name */ |
Alexandre Julliard | 7e71c1d | 2007-03-22 11:44:29 +0100 | [diff] [blame] | 136 | no_open_file, /* open_file */ |
Alexandre Julliard | b9b1ea9 | 2005-06-09 15:39:52 +0000 | [diff] [blame] | 137 | no_close_handle, /* close_handle */ |
Robert Shearman | b0f02b2 | 2005-02-11 11:52:06 +0000 | [diff] [blame] | 138 | token_destroy /* destroy */ |
Mike McCormack | 36cd6f5 | 2003-07-24 00:07:00 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | |
| 142 | static void token_dump( struct object *obj, int verbose ) |
| 143 | { |
| 144 | fprintf( stderr, "Security token\n" ); |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 145 | /* FIXME: dump token members */ |
Mike McCormack | 36cd6f5 | 2003-07-24 00:07:00 +0000 | [diff] [blame] | 146 | } |
| 147 | |
Alexandre Julliard | 5fb2e68 | 2005-12-12 15:01:08 +0100 | [diff] [blame] | 148 | static unsigned int token_map_access( struct object *obj, unsigned int access ) |
| 149 | { |
| 150 | if (access & GENERIC_READ) access |= TOKEN_READ; |
| 151 | if (access & GENERIC_WRITE) access |= TOKEN_WRITE; |
| 152 | if (access & GENERIC_EXECUTE) access |= STANDARD_RIGHTS_EXECUTE; |
| 153 | if (access & GENERIC_ALL) access |= TOKEN_ALL_ACCESS; |
| 154 | return access & ~(GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | GENERIC_ALL); |
| 155 | } |
| 156 | |
Robert Shearman | 2a782c6 | 2005-05-16 17:52:46 +0000 | [diff] [blame] | 157 | static SID *security_sid_alloc( const SID_IDENTIFIER_AUTHORITY *idauthority, int subauthcount, const unsigned int subauth[] ) |
| 158 | { |
| 159 | int i; |
| 160 | SID *sid = mem_alloc( FIELD_OFFSET(SID, SubAuthority[subauthcount]) ); |
| 161 | if (!sid) return NULL; |
Robert Shearman | 9b82644 | 2005-06-09 09:47:28 +0000 | [diff] [blame] | 162 | sid->Revision = SID_REVISION; |
Robert Shearman | 2a782c6 | 2005-05-16 17:52:46 +0000 | [diff] [blame] | 163 | sid->SubAuthorityCount = subauthcount; |
| 164 | sid->IdentifierAuthority = *idauthority; |
| 165 | for (i = 0; i < subauthcount; i++) |
| 166 | sid->SubAuthority[i] = subauth[i]; |
| 167 | return sid; |
| 168 | } |
| 169 | |
Robert Shearman | 4bba216 | 2005-06-20 13:18:38 +0000 | [diff] [blame] | 170 | void security_set_thread_token( struct thread *thread, obj_handle_t handle ) |
| 171 | { |
| 172 | if (!handle) |
| 173 | { |
| 174 | if (thread->token) |
| 175 | release_object( thread->token ); |
| 176 | thread->token = NULL; |
| 177 | } |
| 178 | else |
| 179 | { |
| 180 | struct token *token = (struct token *)get_handle_obj( current->process, |
| 181 | handle, |
| 182 | TOKEN_IMPERSONATE, |
| 183 | &token_ops ); |
| 184 | if (token) |
| 185 | { |
| 186 | if (thread->token) |
| 187 | release_object( thread->token ); |
| 188 | thread->token = token; |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | |
Rob Shearman | 8184bcc | 2007-10-03 13:09:33 +0100 | [diff] [blame] | 193 | const SID *security_unix_uid_to_sid( uid_t uid ) |
| 194 | { |
| 195 | /* very simple mapping: either the current user or not the current user */ |
| 196 | if (uid == getuid()) |
| 197 | return &interactive_sid; |
| 198 | else |
| 199 | return &anonymous_logon_sid; |
| 200 | } |
| 201 | |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 202 | static int acl_is_valid( const ACL *acl, data_size_t size ) |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 203 | { |
| 204 | ULONG i; |
| 205 | const ACE_HEADER *ace; |
| 206 | |
| 207 | if (size < sizeof(ACL)) |
| 208 | return FALSE; |
| 209 | |
| 210 | size = min(size, MAX_ACL_LEN); |
| 211 | |
| 212 | size -= sizeof(ACL); |
| 213 | |
| 214 | ace = (const ACE_HEADER *)(acl + 1); |
| 215 | for (i = 0; i < acl->AceCount; i++) |
| 216 | { |
| 217 | const SID *sid; |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 218 | data_size_t sid_size; |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 219 | |
| 220 | if (size < sizeof(ACE_HEADER)) |
| 221 | return FALSE; |
| 222 | if (size < ace->AceSize) |
| 223 | return FALSE; |
| 224 | size -= ace->AceSize; |
| 225 | switch (ace->AceType) |
| 226 | { |
| 227 | case ACCESS_DENIED_ACE_TYPE: |
| 228 | sid = (const SID *)&((const ACCESS_DENIED_ACE *)ace)->SidStart; |
Robert Shearman | dacc3db | 2005-06-14 19:15:58 +0000 | [diff] [blame] | 229 | sid_size = ace->AceSize - FIELD_OFFSET(ACCESS_DENIED_ACE, SidStart); |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 230 | break; |
| 231 | case ACCESS_ALLOWED_ACE_TYPE: |
| 232 | sid = (const SID *)&((const ACCESS_ALLOWED_ACE *)ace)->SidStart; |
Robert Shearman | dacc3db | 2005-06-14 19:15:58 +0000 | [diff] [blame] | 233 | sid_size = ace->AceSize - FIELD_OFFSET(ACCESS_ALLOWED_ACE, SidStart); |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 234 | break; |
| 235 | case SYSTEM_AUDIT_ACE_TYPE: |
| 236 | sid = (const SID *)&((const SYSTEM_AUDIT_ACE *)ace)->SidStart; |
Robert Shearman | dacc3db | 2005-06-14 19:15:58 +0000 | [diff] [blame] | 237 | sid_size = ace->AceSize - FIELD_OFFSET(SYSTEM_AUDIT_ACE, SidStart); |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 238 | break; |
| 239 | case SYSTEM_ALARM_ACE_TYPE: |
| 240 | sid = (const SID *)&((const SYSTEM_ALARM_ACE *)ace)->SidStart; |
Robert Shearman | dacc3db | 2005-06-14 19:15:58 +0000 | [diff] [blame] | 241 | sid_size = ace->AceSize - FIELD_OFFSET(SYSTEM_ALARM_ACE, SidStart); |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 242 | break; |
| 243 | default: |
| 244 | return FALSE; |
| 245 | } |
Robert Shearman | dacc3db | 2005-06-14 19:15:58 +0000 | [diff] [blame] | 246 | if (sid_size < FIELD_OFFSET(SID, SubAuthority[0]) || |
| 247 | sid_size < FIELD_OFFSET(SID, SubAuthority[sid->SubAuthorityCount])) |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 248 | return FALSE; |
| 249 | ace = ace_next( ace ); |
| 250 | } |
| 251 | return TRUE; |
| 252 | } |
| 253 | |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 254 | /* checks whether all members of a security descriptor fit inside the size |
| 255 | * of memory specified */ |
Rob Shearman | 5af809a | 2007-10-02 15:54:51 +0100 | [diff] [blame] | 256 | int sd_is_valid( const struct security_descriptor *sd, data_size_t size ) |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 257 | { |
| 258 | size_t offset = sizeof(struct security_descriptor); |
| 259 | const SID *group; |
| 260 | const SID *owner; |
| 261 | const ACL *sacl; |
| 262 | const ACL *dacl; |
| 263 | int dummy; |
| 264 | |
| 265 | if (size < offset) |
| 266 | return FALSE; |
| 267 | |
| 268 | if ((sd->owner_len >= FIELD_OFFSET(SID, SubAuthority[255])) || |
| 269 | (offset + sd->owner_len > size)) |
| 270 | return FALSE; |
| 271 | owner = sd_get_owner( sd ); |
| 272 | if (owner) |
| 273 | { |
| 274 | size_t needed_size = FIELD_OFFSET(SID, SubAuthority[owner->SubAuthorityCount]); |
| 275 | if ((sd->owner_len < sizeof(SID)) || (needed_size > sd->owner_len)) |
| 276 | return FALSE; |
| 277 | } |
| 278 | offset += sd->owner_len; |
| 279 | |
| 280 | if ((sd->group_len >= FIELD_OFFSET(SID, SubAuthority[255])) || |
| 281 | (offset + sd->group_len > size)) |
| 282 | return FALSE; |
| 283 | group = sd_get_group( sd ); |
| 284 | if (group) |
| 285 | { |
| 286 | size_t needed_size = FIELD_OFFSET(SID, SubAuthority[group->SubAuthorityCount]); |
Vitaliy Margolen | aa28ed0 | 2007-02-07 21:11:18 -0700 | [diff] [blame] | 287 | if ((sd->group_len < sizeof(SID)) || (needed_size > sd->group_len)) |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 288 | return FALSE; |
| 289 | } |
| 290 | offset += sd->group_len; |
| 291 | |
| 292 | if ((sd->sacl_len >= MAX_ACL_LEN) || (offset + sd->sacl_len > size)) |
| 293 | return FALSE; |
| 294 | sacl = sd_get_sacl( sd, &dummy ); |
| 295 | if (sacl && !acl_is_valid( sacl, sd->sacl_len )) |
| 296 | return FALSE; |
| 297 | offset += sd->sacl_len; |
| 298 | |
| 299 | if ((sd->dacl_len >= MAX_ACL_LEN) || (offset + sd->dacl_len > size)) |
| 300 | return FALSE; |
| 301 | dacl = sd_get_dacl( sd, &dummy ); |
| 302 | if (dacl && !acl_is_valid( dacl, sd->dacl_len )) |
| 303 | return FALSE; |
| 304 | offset += sd->dacl_len; |
| 305 | |
| 306 | return TRUE; |
| 307 | } |
| 308 | |
Rob Shearman | dd9e392 | 2007-10-24 16:04:42 +0100 | [diff] [blame] | 309 | /* determines whether an object_attributes struct is valid in a buffer |
| 310 | * and calls set_error appropriately */ |
| 311 | int objattr_is_valid( const struct object_attributes *objattr, data_size_t size ) |
| 312 | { |
Rob Shearman | f98556c | 2007-10-26 17:01:33 +0100 | [diff] [blame] | 313 | if ((size < sizeof(*objattr)) || (size - sizeof(*objattr) < objattr->sd_len) || |
| 314 | (size - sizeof(*objattr) - objattr->sd_len < objattr->name_len)) |
Rob Shearman | dd9e392 | 2007-10-24 16:04:42 +0100 | [diff] [blame] | 315 | { |
| 316 | set_error( STATUS_ACCESS_VIOLATION ); |
| 317 | return FALSE; |
| 318 | } |
| 319 | |
| 320 | if (objattr->sd_len) |
| 321 | { |
| 322 | const struct security_descriptor *sd = (const struct security_descriptor *)(objattr + 1); |
| 323 | if (!sd_is_valid( sd, objattr->sd_len )) |
| 324 | { |
| 325 | set_error( STATUS_INVALID_SECURITY_DESCR ); |
| 326 | return FALSE; |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | return TRUE; |
| 331 | } |
| 332 | |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 333 | /* maps from generic rights to specific rights as given by a mapping */ |
| 334 | static inline void map_generic_mask(unsigned int *mask, const GENERIC_MAPPING *mapping) |
| 335 | { |
| 336 | if (*mask & GENERIC_READ) *mask |= mapping->GenericRead; |
| 337 | if (*mask & GENERIC_WRITE) *mask |= mapping->GenericWrite; |
| 338 | if (*mask & GENERIC_EXECUTE) *mask |= mapping->GenericExecute; |
| 339 | if (*mask & GENERIC_ALL) *mask |= mapping->GenericAll; |
| 340 | *mask &= 0x0FFFFFFF; |
| 341 | } |
| 342 | |
Robert Shearman | b0f02b2 | 2005-02-11 11:52:06 +0000 | [diff] [blame] | 343 | static inline int is_equal_luid( const LUID *luid1, const LUID *luid2 ) |
| 344 | { |
| 345 | return (luid1->LowPart == luid2->LowPart && luid1->HighPart == luid2->HighPart); |
| 346 | } |
| 347 | |
Alexandre Julliard | bf17ce8 | 2007-03-07 12:43:12 +0100 | [diff] [blame] | 348 | static inline void allocate_luid( luid_t *luid ) |
Rob Shearman | df0d625 | 2007-02-15 23:20:48 +0000 | [diff] [blame] | 349 | { |
Alexandre Julliard | bf17ce8 | 2007-03-07 12:43:12 +0100 | [diff] [blame] | 350 | prev_luid_value.low_part++; |
Rob Shearman | df0d625 | 2007-02-15 23:20:48 +0000 | [diff] [blame] | 351 | *luid = prev_luid_value; |
| 352 | } |
| 353 | |
Juan Lang | c2cb296 | 2007-03-06 16:33:26 -0800 | [diff] [blame] | 354 | DECL_HANDLER( allocate_locally_unique_id ) |
| 355 | { |
Alexandre Julliard | bf17ce8 | 2007-03-07 12:43:12 +0100 | [diff] [blame] | 356 | allocate_luid( &reply->luid ); |
Juan Lang | c2cb296 | 2007-03-06 16:33:26 -0800 | [diff] [blame] | 357 | } |
| 358 | |
Robert Shearman | b0f02b2 | 2005-02-11 11:52:06 +0000 | [diff] [blame] | 359 | static inline void luid_and_attr_from_privilege( LUID_AND_ATTRIBUTES *out, const struct privilege *in) |
| 360 | { |
| 361 | out->Luid = in->luid; |
| 362 | out->Attributes = |
| 363 | (in->enabled ? SE_PRIVILEGE_ENABLED : 0) | |
| 364 | (in->def ? SE_PRIVILEGE_ENABLED_BY_DEFAULT : 0); |
| 365 | } |
| 366 | |
| 367 | static struct privilege *privilege_add( struct token *token, const LUID *luid, int enabled ) |
| 368 | { |
| 369 | struct privilege *privilege = mem_alloc( sizeof(*privilege) ); |
| 370 | if (privilege) |
| 371 | { |
| 372 | privilege->luid = *luid; |
| 373 | privilege->def = privilege->enabled = (enabled != 0); |
| 374 | list_add_tail( &token->privileges, &privilege->entry ); |
| 375 | } |
| 376 | return privilege; |
| 377 | } |
| 378 | |
Robert Shearman | 2a782c6 | 2005-05-16 17:52:46 +0000 | [diff] [blame] | 379 | static inline void privilege_remove( struct privilege *privilege ) |
Robert Shearman | b0f02b2 | 2005-02-11 11:52:06 +0000 | [diff] [blame] | 380 | { |
| 381 | list_remove( &privilege->entry ); |
| 382 | free( privilege ); |
| 383 | } |
| 384 | |
| 385 | static void token_destroy( struct object *obj ) |
| 386 | { |
| 387 | struct token* token; |
| 388 | struct list *cursor, *cursor_next; |
| 389 | |
| 390 | assert( obj->ops == &token_ops ); |
| 391 | token = (struct token *)obj; |
| 392 | |
Robert Shearman | 2a782c6 | 2005-05-16 17:52:46 +0000 | [diff] [blame] | 393 | free( token->user ); |
| 394 | |
Robert Shearman | b0f02b2 | 2005-02-11 11:52:06 +0000 | [diff] [blame] | 395 | LIST_FOR_EACH_SAFE( cursor, cursor_next, &token->privileges ) |
| 396 | { |
| 397 | struct privilege *privilege = LIST_ENTRY( cursor, struct privilege, entry ); |
| 398 | privilege_remove( privilege ); |
| 399 | } |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 400 | |
| 401 | LIST_FOR_EACH_SAFE( cursor, cursor_next, &token->groups ) |
| 402 | { |
Robert Shearman | 3396a66 | 2006-05-13 16:58:19 +0100 | [diff] [blame] | 403 | struct group *group = LIST_ENTRY( cursor, struct group, entry ); |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 404 | list_remove( &group->entry ); |
| 405 | free( group ); |
| 406 | } |
Robert Shearman | fbf0ea9 | 2005-07-13 19:31:27 +0000 | [diff] [blame] | 407 | |
| 408 | free( token->default_dacl ); |
Robert Shearman | b0f02b2 | 2005-02-11 11:52:06 +0000 | [diff] [blame] | 409 | } |
| 410 | |
Robert Shearman | fbf0ea9 | 2005-07-13 19:31:27 +0000 | [diff] [blame] | 411 | /* creates a new token. |
| 412 | * groups may be NULL if group_count is 0. |
| 413 | * privs may be NULL if priv_count is 0. |
| 414 | * default_dacl may be NULL, indicating that all objects created by the user |
| 415 | * are unsecured. |
Rob Shearman | df0d625 | 2007-02-15 23:20:48 +0000 | [diff] [blame] | 416 | * modified_id may be NULL, indicating that a new modified_id luid should be |
| 417 | * allocated. |
Robert Shearman | fbf0ea9 | 2005-07-13 19:31:27 +0000 | [diff] [blame] | 418 | */ |
Robert Shearman | f95ef09 | 2005-06-14 18:10:04 +0000 | [diff] [blame] | 419 | static struct token *create_token( unsigned primary, const SID *user, |
Robert Shearman | 9b82644 | 2005-06-09 09:47:28 +0000 | [diff] [blame] | 420 | const SID_AND_ATTRIBUTES *groups, unsigned int group_count, |
Robert Shearman | fbf0ea9 | 2005-07-13 19:31:27 +0000 | [diff] [blame] | 421 | const LUID_AND_ATTRIBUTES *privs, unsigned int priv_count, |
Rob Shearman | df0d625 | 2007-02-15 23:20:48 +0000 | [diff] [blame] | 422 | const ACL *default_dacl, TOKEN_SOURCE source, |
Alexandre Julliard | bf17ce8 | 2007-03-07 12:43:12 +0100 | [diff] [blame] | 423 | const luid_t *modified_id, |
Alexandre Julliard | f6d871e | 2008-03-26 14:38:49 +0100 | [diff] [blame] | 424 | int impersonation_level ) |
Mike McCormack | 36cd6f5 | 2003-07-24 00:07:00 +0000 | [diff] [blame] | 425 | { |
| 426 | struct token *token = alloc_object( &token_ops ); |
Robert Shearman | b0f02b2 | 2005-02-11 11:52:06 +0000 | [diff] [blame] | 427 | if (token) |
| 428 | { |
Michael Stefaniuc | a624977 | 2006-07-25 10:30:04 +0200 | [diff] [blame] | 429 | unsigned int i; |
Robert Shearman | f95ef09 | 2005-06-14 18:10:04 +0000 | [diff] [blame] | 430 | |
Rob Shearman | df0d625 | 2007-02-15 23:20:48 +0000 | [diff] [blame] | 431 | allocate_luid( &token->token_id ); |
| 432 | if (modified_id) |
| 433 | token->modified_id = *modified_id; |
| 434 | else |
| 435 | allocate_luid( &token->modified_id ); |
Robert Shearman | b0f02b2 | 2005-02-11 11:52:06 +0000 | [diff] [blame] | 436 | list_init( &token->privileges ); |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 437 | list_init( &token->groups ); |
Robert Shearman | f95ef09 | 2005-06-14 18:10:04 +0000 | [diff] [blame] | 438 | token->primary = primary; |
Rob Shearman | c9b9847 | 2007-02-15 23:21:40 +0000 | [diff] [blame] | 439 | /* primary tokens don't have impersonation levels */ |
| 440 | if (primary) |
| 441 | token->impersonation_level = -1; |
| 442 | else |
| 443 | token->impersonation_level = impersonation_level; |
Vitaliy Margolen | 55fdda4 | 2007-01-24 23:43:30 -0700 | [diff] [blame] | 444 | token->default_dacl = NULL; |
Vitaliy Margolen | 6413a9c | 2007-02-09 09:24:53 -0700 | [diff] [blame] | 445 | token->primary_group = NULL; |
Robert Shearman | f95ef09 | 2005-06-14 18:10:04 +0000 | [diff] [blame] | 446 | |
Robert Shearman | 2a782c6 | 2005-05-16 17:52:46 +0000 | [diff] [blame] | 447 | /* copy user */ |
| 448 | token->user = memdup( user, FIELD_OFFSET(SID, SubAuthority[user->SubAuthorityCount]) ); |
| 449 | if (!token->user) |
| 450 | { |
| 451 | release_object( token ); |
| 452 | return NULL; |
| 453 | } |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 454 | |
Robert Shearman | 9b82644 | 2005-06-09 09:47:28 +0000 | [diff] [blame] | 455 | /* copy groups */ |
| 456 | for (i = 0; i < group_count; i++) |
| 457 | { |
Robert Shearman | 3396a66 | 2006-05-13 16:58:19 +0100 | [diff] [blame] | 458 | size_t size = FIELD_OFFSET( struct group, sid.SubAuthority[((const SID *)groups[i].Sid)->SubAuthorityCount] ); |
| 459 | struct group *group = mem_alloc( size ); |
Robert Shearman | 9e0d056 | 2006-04-07 11:16:28 +0100 | [diff] [blame] | 460 | |
| 461 | if (!group) |
| 462 | { |
| 463 | release_object( token ); |
| 464 | return NULL; |
| 465 | } |
Robert Shearman | 9b82644 | 2005-06-09 09:47:28 +0000 | [diff] [blame] | 466 | memcpy( &group->sid, groups[i].Sid, FIELD_OFFSET( SID, SubAuthority[((const SID *)groups[i].Sid)->SubAuthorityCount] ) ); |
| 467 | group->enabled = TRUE; |
| 468 | group->def = TRUE; |
H. Verbeet | 3120c08 | 2008-03-17 17:55:17 +0100 | [diff] [blame] | 469 | group->logon = (groups[i].Attributes & SE_GROUP_LOGON_ID) ? TRUE : FALSE; |
Robert Shearman | 9b82644 | 2005-06-09 09:47:28 +0000 | [diff] [blame] | 470 | group->mandatory = (groups[i].Attributes & SE_GROUP_MANDATORY) ? TRUE : FALSE; |
Vitaliy Margolen | 6413a9c | 2007-02-09 09:24:53 -0700 | [diff] [blame] | 471 | group->owner = groups[i].Attributes & SE_GROUP_OWNER ? TRUE : FALSE; |
Robert Shearman | 9b82644 | 2005-06-09 09:47:28 +0000 | [diff] [blame] | 472 | group->resource = FALSE; |
| 473 | group->deny_only = FALSE; |
| 474 | list_add_tail( &token->groups, &group->entry ); |
Vitaliy Margolen | 6413a9c | 2007-02-09 09:24:53 -0700 | [diff] [blame] | 475 | /* Use first owner capable group as an owner */ |
| 476 | if (!token->primary_group && group->owner) |
| 477 | token->primary_group = &group->sid; |
Robert Shearman | 9b82644 | 2005-06-09 09:47:28 +0000 | [diff] [blame] | 478 | } |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 479 | |
Robert Shearman | 2a782c6 | 2005-05-16 17:52:46 +0000 | [diff] [blame] | 480 | /* copy privileges */ |
Robert Shearman | b0f02b2 | 2005-02-11 11:52:06 +0000 | [diff] [blame] | 481 | for (i = 0; i < priv_count; i++) |
| 482 | { |
| 483 | /* note: we don't check uniqueness: the caller must make sure |
| 484 | * privs doesn't contain any duplicate luids */ |
| 485 | if (!privilege_add( token, &privs[i].Luid, |
| 486 | privs[i].Attributes & SE_PRIVILEGE_ENABLED )) |
| 487 | { |
| 488 | release_object( token ); |
| 489 | return NULL; |
| 490 | } |
| 491 | } |
Robert Shearman | fbf0ea9 | 2005-07-13 19:31:27 +0000 | [diff] [blame] | 492 | |
| 493 | if (default_dacl) |
| 494 | { |
| 495 | token->default_dacl = memdup( default_dacl, default_dacl->AclSize ); |
| 496 | if (!token->default_dacl) |
| 497 | { |
| 498 | release_object( token ); |
| 499 | return NULL; |
| 500 | } |
| 501 | } |
Robert Shearman | d18711e | 2006-03-29 18:37:39 +0100 | [diff] [blame] | 502 | |
| 503 | token->source = source; |
Robert Shearman | b0f02b2 | 2005-02-11 11:52:06 +0000 | [diff] [blame] | 504 | } |
Mike McCormack | 36cd6f5 | 2003-07-24 00:07:00 +0000 | [diff] [blame] | 505 | return token; |
| 506 | } |
| 507 | |
Rob Shearman | bdf964d | 2007-05-28 18:39:33 +0100 | [diff] [blame] | 508 | struct token *token_duplicate( struct token *src_token, unsigned primary, |
Alexandre Julliard | f6d871e | 2008-03-26 14:38:49 +0100 | [diff] [blame] | 509 | int impersonation_level ) |
Rob Shearman | bdf964d | 2007-05-28 18:39:33 +0100 | [diff] [blame] | 510 | { |
| 511 | const luid_t *modified_id = |
| 512 | primary || (impersonation_level == src_token->impersonation_level) ? |
| 513 | &src_token->modified_id : NULL; |
| 514 | struct token *token = NULL; |
| 515 | struct privilege *privilege; |
| 516 | struct group *group; |
| 517 | |
Alexandre Julliard | f6d871e | 2008-03-26 14:38:49 +0100 | [diff] [blame] | 518 | if (!primary && |
| 519 | (impersonation_level < SecurityAnonymous || |
| 520 | impersonation_level > SecurityDelegation || |
| 521 | (!src_token->primary && (impersonation_level > src_token->impersonation_level)))) |
Rob Shearman | bdf964d | 2007-05-28 18:39:33 +0100 | [diff] [blame] | 522 | { |
| 523 | set_error( STATUS_BAD_IMPERSONATION_LEVEL ); |
| 524 | return NULL; |
| 525 | } |
| 526 | |
Alexandre Julliard | f6d871e | 2008-03-26 14:38:49 +0100 | [diff] [blame] | 527 | token = create_token( primary, src_token->user, NULL, 0, |
| 528 | NULL, 0, src_token->default_dacl, |
| 529 | src_token->source, modified_id, |
| 530 | impersonation_level ); |
Rob Shearman | bdf964d | 2007-05-28 18:39:33 +0100 | [diff] [blame] | 531 | if (!token) return token; |
| 532 | |
| 533 | /* copy groups */ |
| 534 | LIST_FOR_EACH_ENTRY( group, &src_token->groups, struct group, entry ) |
| 535 | { |
| 536 | size_t size = FIELD_OFFSET( struct group, sid.SubAuthority[group->sid.SubAuthorityCount] ); |
| 537 | struct group *newgroup = mem_alloc( size ); |
| 538 | if (!newgroup) |
| 539 | { |
| 540 | release_object( token ); |
| 541 | return NULL; |
| 542 | } |
| 543 | memcpy( newgroup, group, size ); |
| 544 | list_add_tail( &token->groups, &newgroup->entry ); |
| 545 | } |
| 546 | token->primary_group = src_token->primary_group; |
| 547 | assert( token->primary_group ); |
| 548 | |
| 549 | /* copy privileges */ |
| 550 | LIST_FOR_EACH_ENTRY( privilege, &src_token->privileges, struct privilege, entry ) |
| 551 | if (!privilege_add( token, &privilege->luid, privilege->enabled )) |
| 552 | { |
| 553 | release_object( token ); |
| 554 | return NULL; |
| 555 | } |
| 556 | |
| 557 | return token; |
| 558 | } |
| 559 | |
Robert Shearman | fbf0ea9 | 2005-07-13 19:31:27 +0000 | [diff] [blame] | 560 | static ACL *create_default_dacl( const SID *user ) |
| 561 | { |
| 562 | ACCESS_ALLOWED_ACE *aaa; |
| 563 | ACL *default_dacl; |
| 564 | SID *sid; |
| 565 | size_t default_dacl_size = sizeof(ACL) + |
| 566 | 2*(sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD)) + |
| 567 | sizeof(local_system_sid) + |
| 568 | FIELD_OFFSET(SID, SubAuthority[user->SubAuthorityCount]); |
| 569 | |
| 570 | default_dacl = mem_alloc( default_dacl_size ); |
| 571 | if (!default_dacl) return NULL; |
| 572 | |
Rob Shearman | 45b6706 | 2007-10-02 15:57:02 +0100 | [diff] [blame] | 573 | default_dacl->AclRevision = ACL_REVISION; |
Robert Shearman | fbf0ea9 | 2005-07-13 19:31:27 +0000 | [diff] [blame] | 574 | default_dacl->Sbz1 = 0; |
| 575 | default_dacl->AclSize = default_dacl_size; |
| 576 | default_dacl->AceCount = 2; |
| 577 | default_dacl->Sbz2 = 0; |
| 578 | |
| 579 | /* GENERIC_ALL for Local System */ |
| 580 | aaa = (ACCESS_ALLOWED_ACE *)(default_dacl + 1); |
| 581 | aaa->Header.AceType = ACCESS_ALLOWED_ACE_TYPE; |
| 582 | aaa->Header.AceFlags = 0; |
| 583 | aaa->Header.AceSize = (sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD)) + |
| 584 | sizeof(local_system_sid); |
| 585 | aaa->Mask = GENERIC_ALL; |
| 586 | sid = (SID *)&aaa->SidStart; |
| 587 | memcpy( sid, &local_system_sid, sizeof(local_system_sid) ); |
| 588 | |
| 589 | /* GENERIC_ALL for specified user */ |
Andrew Talbot | 53dae9b | 2006-12-16 17:43:17 +0000 | [diff] [blame] | 590 | aaa = (ACCESS_ALLOWED_ACE *)((char *)aaa + aaa->Header.AceSize); |
Robert Shearman | fbf0ea9 | 2005-07-13 19:31:27 +0000 | [diff] [blame] | 591 | aaa->Header.AceType = ACCESS_ALLOWED_ACE_TYPE; |
| 592 | aaa->Header.AceFlags = 0; |
| 593 | aaa->Header.AceSize = (sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD)) + |
| 594 | FIELD_OFFSET( SID, SubAuthority[user->SubAuthorityCount] ); |
| 595 | aaa->Mask = GENERIC_ALL; |
| 596 | sid = (SID *)&aaa->SidStart; |
| 597 | memcpy( sid, user, FIELD_OFFSET(SID, SubAuthority[user->SubAuthorityCount]) ); |
| 598 | |
| 599 | return default_dacl; |
| 600 | } |
| 601 | |
Robert Shearman | 2a782c6 | 2005-05-16 17:52:46 +0000 | [diff] [blame] | 602 | struct sid_data |
| 603 | { |
| 604 | SID_IDENTIFIER_AUTHORITY idauth; |
| 605 | int count; |
| 606 | unsigned int subauth[MAX_SUBAUTH_COUNT]; |
| 607 | }; |
| 608 | |
Robert Shearman | d2ea92d | 2005-04-22 21:17:15 +0000 | [diff] [blame] | 609 | struct token *token_create_admin( void ) |
Robert Shearman | b0f02b2 | 2005-02-11 11:52:06 +0000 | [diff] [blame] | 610 | { |
Robert Shearman | 9b82644 | 2005-06-09 09:47:28 +0000 | [diff] [blame] | 611 | struct token *token = NULL; |
| 612 | static const SID_IDENTIFIER_AUTHORITY nt_authority = { SECURITY_NT_AUTHORITY }; |
| 613 | static const unsigned int alias_admins_subauth[] = { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS }; |
| 614 | static const unsigned int alias_users_subauth[] = { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_USERS }; |
Rob Shearman | fa074bc | 2007-05-18 10:51:50 +0100 | [diff] [blame] | 615 | /* on Windows, this value changes every time the user logs on */ |
| 616 | static const unsigned int logon_subauth[] = { SECURITY_LOGON_IDS_RID, 0, 1 /* FIXME: should be randomly generated when tokens are inherited by new processes */ }; |
Robert Shearman | 9b82644 | 2005-06-09 09:47:28 +0000 | [diff] [blame] | 617 | PSID alias_admins_sid; |
| 618 | PSID alias_users_sid; |
Rob Shearman | fa074bc | 2007-05-18 10:51:50 +0100 | [diff] [blame] | 619 | PSID logon_sid; |
Vitaliy Margolen | 97b122c | 2007-01-19 12:28:59 -0700 | [diff] [blame] | 620 | /* note: should be the owner specified in the token */ |
| 621 | ACL *default_dacl = create_default_dacl( &interactive_sid ); |
Robert Shearman | 9b82644 | 2005-06-09 09:47:28 +0000 | [diff] [blame] | 622 | |
| 623 | alias_admins_sid = security_sid_alloc( &nt_authority, sizeof(alias_admins_subauth)/sizeof(alias_admins_subauth[0]), |
| 624 | alias_admins_subauth ); |
| 625 | alias_users_sid = security_sid_alloc( &nt_authority, sizeof(alias_users_subauth)/sizeof(alias_users_subauth[0]), |
| 626 | alias_users_subauth ); |
Rob Shearman | fa074bc | 2007-05-18 10:51:50 +0100 | [diff] [blame] | 627 | logon_sid = security_sid_alloc( &nt_authority, sizeof(logon_subauth)/sizeof(logon_subauth[0]), |
| 628 | logon_subauth ); |
Robert Shearman | 9b82644 | 2005-06-09 09:47:28 +0000 | [diff] [blame] | 629 | |
Rob Shearman | fa074bc | 2007-05-18 10:51:50 +0100 | [diff] [blame] | 630 | if (alias_admins_sid && alias_users_sid && logon_sid && default_dacl) |
Robert Shearman | b0f02b2 | 2005-02-11 11:52:06 +0000 | [diff] [blame] | 631 | { |
Robert Shearman | 9b82644 | 2005-06-09 09:47:28 +0000 | [diff] [blame] | 632 | const LUID_AND_ATTRIBUTES admin_privs[] = |
| 633 | { |
| 634 | { SeChangeNotifyPrivilege , SE_PRIVILEGE_ENABLED }, |
| 635 | { SeSecurityPrivilege , 0 }, |
| 636 | { SeBackupPrivilege , 0 }, |
| 637 | { SeRestorePrivilege , 0 }, |
| 638 | { SeSystemtimePrivilege , 0 }, |
| 639 | { SeShutdownPrivilege , 0 }, |
| 640 | { SeRemoteShutdownPrivilege , 0 }, |
| 641 | { SeTakeOwnershipPrivilege , 0 }, |
| 642 | { SeDebugPrivilege , 0 }, |
| 643 | { SeSystemEnvironmentPrivilege , 0 }, |
| 644 | { SeSystemProfilePrivilege , 0 }, |
| 645 | { SeProfileSingleProcessPrivilege, 0 }, |
| 646 | { SeIncreaseBasePriorityPrivilege, 0 }, |
Peter Dons Tychsen | ec4d890 | 2007-07-27 02:05:04 +0200 | [diff] [blame] | 647 | { SeLoadDriverPrivilege , SE_PRIVILEGE_ENABLED }, |
Robert Shearman | 9b82644 | 2005-06-09 09:47:28 +0000 | [diff] [blame] | 648 | { SeCreatePagefilePrivilege , 0 }, |
| 649 | { SeIncreaseQuotaPrivilege , 0 }, |
| 650 | { SeUndockPrivilege , 0 }, |
| 651 | { SeManageVolumePrivilege , 0 }, |
| 652 | { SeImpersonatePrivilege , SE_PRIVILEGE_ENABLED }, |
| 653 | { SeCreateGlobalPrivilege , SE_PRIVILEGE_ENABLED }, |
| 654 | }; |
| 655 | /* note: we don't include non-builtin groups here for the user - |
| 656 | * telling us these is the job of a client-side program */ |
| 657 | const SID_AND_ATTRIBUTES admin_groups[] = |
| 658 | { |
| 659 | { security_world_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY }, |
| 660 | { security_local_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY }, |
| 661 | { security_interactive_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY }, |
| 662 | { security_authenticated_user_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY }, |
Vitaliy Margolen | 6413a9c | 2007-02-09 09:24:53 -0700 | [diff] [blame] | 663 | { alias_admins_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY|SE_GROUP_OWNER }, |
Robert Shearman | 9b82644 | 2005-06-09 09:47:28 +0000 | [diff] [blame] | 664 | { alias_users_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY }, |
Rob Shearman | fa074bc | 2007-05-18 10:51:50 +0100 | [diff] [blame] | 665 | { logon_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY|SE_GROUP_LOGON_ID }, |
Robert Shearman | 9b82644 | 2005-06-09 09:47:28 +0000 | [diff] [blame] | 666 | }; |
Robert Shearman | d18711e | 2006-03-29 18:37:39 +0100 | [diff] [blame] | 667 | static const TOKEN_SOURCE admin_source = {"SeMgr", {0, 0}}; |
Rob Shearman | 8184bcc | 2007-10-03 13:09:33 +0100 | [diff] [blame] | 668 | token = create_token( TRUE, security_unix_uid_to_sid( getuid() ), |
Robert Shearman | 9b82644 | 2005-06-09 09:47:28 +0000 | [diff] [blame] | 669 | admin_groups, sizeof(admin_groups)/sizeof(admin_groups[0]), |
Robert Shearman | fbf0ea9 | 2005-07-13 19:31:27 +0000 | [diff] [blame] | 670 | admin_privs, sizeof(admin_privs)/sizeof(admin_privs[0]), |
Rob Shearman | c9b9847 | 2007-02-15 23:21:40 +0000 | [diff] [blame] | 671 | default_dacl, admin_source, NULL, -1 ); |
Vitaliy Margolen | 6413a9c | 2007-02-09 09:24:53 -0700 | [diff] [blame] | 672 | /* we really need a primary group */ |
| 673 | assert( token->primary_group ); |
Robert Shearman | 9b82644 | 2005-06-09 09:47:28 +0000 | [diff] [blame] | 674 | } |
| 675 | |
Rob Shearman | fa074bc | 2007-05-18 10:51:50 +0100 | [diff] [blame] | 676 | free( logon_sid ); |
Michael Stefaniuc | 5ceccec | 2006-10-09 23:34:36 +0200 | [diff] [blame] | 677 | free( alias_admins_sid ); |
| 678 | free( alias_users_sid ); |
| 679 | free( default_dacl ); |
Robert Shearman | 9b82644 | 2005-06-09 09:47:28 +0000 | [diff] [blame] | 680 | |
Robert Shearman | 2a782c6 | 2005-05-16 17:52:46 +0000 | [diff] [blame] | 681 | return token; |
Robert Shearman | b0f02b2 | 2005-02-11 11:52:06 +0000 | [diff] [blame] | 682 | } |
| 683 | |
Robert Shearman | fbf0ea9 | 2005-07-13 19:31:27 +0000 | [diff] [blame] | 684 | static struct privilege *token_find_privilege( struct token *token, const LUID *luid, int enabled_only ) |
Robert Shearman | b0f02b2 | 2005-02-11 11:52:06 +0000 | [diff] [blame] | 685 | { |
| 686 | struct privilege *privilege; |
| 687 | LIST_FOR_EACH_ENTRY( privilege, &token->privileges, struct privilege, entry ) |
| 688 | { |
| 689 | if (is_equal_luid( luid, &privilege->luid )) |
| 690 | { |
| 691 | if (enabled_only && !privilege->enabled) |
| 692 | return NULL; |
| 693 | return privilege; |
| 694 | } |
| 695 | } |
| 696 | return NULL; |
| 697 | } |
| 698 | |
| 699 | static unsigned int token_adjust_privileges( struct token *token, const LUID_AND_ATTRIBUTES *privs, |
| 700 | unsigned int count, LUID_AND_ATTRIBUTES *mod_privs, |
Robert Shearman | fbf0ea9 | 2005-07-13 19:31:27 +0000 | [diff] [blame] | 701 | unsigned int mod_privs_count ) |
Robert Shearman | b0f02b2 | 2005-02-11 11:52:06 +0000 | [diff] [blame] | 702 | { |
Michael Stefaniuc | a624977 | 2006-07-25 10:30:04 +0200 | [diff] [blame] | 703 | unsigned int i, modified_count = 0; |
Robert Shearman | b0f02b2 | 2005-02-11 11:52:06 +0000 | [diff] [blame] | 704 | |
Rob Shearman | df0d625 | 2007-02-15 23:20:48 +0000 | [diff] [blame] | 705 | /* mark as modified */ |
| 706 | allocate_luid( &token->modified_id ); |
| 707 | |
Robert Shearman | b0f02b2 | 2005-02-11 11:52:06 +0000 | [diff] [blame] | 708 | for (i = 0; i < count; i++) |
| 709 | { |
| 710 | struct privilege *privilege = |
| 711 | token_find_privilege( token, &privs[i].Luid, FALSE ); |
| 712 | if (!privilege) |
| 713 | { |
| 714 | set_error( STATUS_NOT_ALL_ASSIGNED ); |
| 715 | continue; |
| 716 | } |
| 717 | |
| 718 | if (privs[i].Attributes & SE_PRIVILEGE_REMOVE) |
| 719 | privilege_remove( privilege ); |
| 720 | else |
| 721 | { |
| 722 | /* save previous state for caller */ |
| 723 | if (mod_privs_count) |
| 724 | { |
| 725 | luid_and_attr_from_privilege(mod_privs, privilege); |
| 726 | mod_privs++; |
| 727 | mod_privs_count--; |
| 728 | modified_count++; |
| 729 | } |
| 730 | |
| 731 | if (privs[i].Attributes & SE_PRIVILEGE_ENABLED) |
| 732 | privilege->enabled = TRUE; |
| 733 | else |
| 734 | privilege->enabled = FALSE; |
| 735 | } |
| 736 | } |
| 737 | return modified_count; |
| 738 | } |
| 739 | |
| 740 | static void token_disable_privileges( struct token *token ) |
| 741 | { |
| 742 | struct privilege *privilege; |
Rob Shearman | df0d625 | 2007-02-15 23:20:48 +0000 | [diff] [blame] | 743 | |
| 744 | /* mark as modified */ |
| 745 | allocate_luid( &token->modified_id ); |
| 746 | |
Robert Shearman | b0f02b2 | 2005-02-11 11:52:06 +0000 | [diff] [blame] | 747 | LIST_FOR_EACH_ENTRY( privilege, &token->privileges, struct privilege, entry ) |
| 748 | privilege->enabled = FALSE; |
| 749 | } |
| 750 | |
Robert Shearman | d2ea92d | 2005-04-22 21:17:15 +0000 | [diff] [blame] | 751 | int token_check_privileges( struct token *token, int all_required, |
| 752 | const LUID_AND_ATTRIBUTES *reqprivs, |
| 753 | unsigned int count, LUID_AND_ATTRIBUTES *usedprivs) |
| 754 | { |
Michael Stefaniuc | a624977 | 2006-07-25 10:30:04 +0200 | [diff] [blame] | 755 | unsigned int i, enabled_count = 0; |
Robert Shearman | d2ea92d | 2005-04-22 21:17:15 +0000 | [diff] [blame] | 756 | |
| 757 | for (i = 0; i < count; i++) |
| 758 | { |
| 759 | struct privilege *privilege = |
| 760 | token_find_privilege( token, &reqprivs[i].Luid, TRUE ); |
| 761 | |
| 762 | if (usedprivs) |
| 763 | usedprivs[i] = reqprivs[i]; |
| 764 | |
| 765 | if (privilege && privilege->enabled) |
| 766 | { |
| 767 | enabled_count++; |
| 768 | if (usedprivs) |
| 769 | usedprivs[i].Attributes |= SE_PRIVILEGE_USED_FOR_ACCESS; |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | if (all_required) |
| 774 | return (enabled_count == count); |
| 775 | else |
| 776 | return (enabled_count > 0); |
| 777 | } |
| 778 | |
Ben Peddell | b419df1 | 2009-12-10 01:31:53 +1000 | [diff] [blame] | 779 | int token_sid_present( struct token *token, const SID *sid, int deny ) |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 780 | { |
Robert Shearman | 3396a66 | 2006-05-13 16:58:19 +0100 | [diff] [blame] | 781 | struct group *group; |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 782 | |
| 783 | if (security_equal_sid( token->user, sid )) return TRUE; |
| 784 | |
Robert Shearman | 3396a66 | 2006-05-13 16:58:19 +0100 | [diff] [blame] | 785 | LIST_FOR_EACH_ENTRY( group, &token->groups, struct group, entry ) |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 786 | { |
| 787 | if (!group->enabled) continue; |
| 788 | if (group->deny_only && !deny) continue; |
| 789 | |
| 790 | if (security_equal_sid( &group->sid, sid )) return TRUE; |
| 791 | } |
| 792 | |
| 793 | return FALSE; |
| 794 | } |
| 795 | |
Vitaliy Margolen | fad936c | 2007-01-24 23:42:15 -0700 | [diff] [blame] | 796 | /* Checks access to a security descriptor. 'sd' must have been validated by |
| 797 | * caller. It returns STATUS_SUCCESS if call succeeded or an error indicating |
| 798 | * the reason. 'status' parameter will indicate if access is granted or denied. |
| 799 | * |
| 800 | * If both returned value and 'status' are STATUS_SUCCESS then access is granted. |
| 801 | */ |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 802 | static unsigned int token_access_check( struct token *token, |
| 803 | const struct security_descriptor *sd, |
| 804 | unsigned int desired_access, |
| 805 | LUID_AND_ATTRIBUTES *privs, |
| 806 | unsigned int *priv_count, |
| 807 | const GENERIC_MAPPING *mapping, |
| 808 | unsigned int *granted_access, |
| 809 | unsigned int *status ) |
| 810 | { |
| 811 | unsigned int current_access = 0; |
| 812 | unsigned int denied_access = 0; |
| 813 | ULONG i; |
| 814 | const ACL *dacl; |
| 815 | int dacl_present; |
| 816 | const ACE_HEADER *ace; |
| 817 | const SID *owner; |
| 818 | |
Vitaliy Margolen | fad936c | 2007-01-24 23:42:15 -0700 | [diff] [blame] | 819 | /* assume no access rights */ |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 820 | *granted_access = 0; |
| 821 | |
| 822 | /* fail if desired_access contains generic rights */ |
| 823 | if (desired_access & (GENERIC_READ|GENERIC_WRITE|GENERIC_EXECUTE|GENERIC_ALL)) |
| 824 | { |
| 825 | *priv_count = 0; |
Vitaliy Margolen | fad936c | 2007-01-24 23:42:15 -0700 | [diff] [blame] | 826 | return STATUS_GENERIC_NOT_MAPPED; |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | dacl = sd_get_dacl( sd, &dacl_present ); |
| 830 | owner = sd_get_owner( sd ); |
| 831 | if (!owner || !sd_get_group( sd )) |
| 832 | { |
| 833 | *priv_count = 0; |
Vitaliy Margolen | fad936c | 2007-01-24 23:42:15 -0700 | [diff] [blame] | 834 | return STATUS_INVALID_SECURITY_DESCR; |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | /* 1: Grant desired access if the object is unprotected */ |
Rob Shearman | 12e44bf | 2007-10-16 09:50:50 +0100 | [diff] [blame] | 838 | if (!dacl_present || !dacl) |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 839 | { |
| 840 | *priv_count = 0; |
| 841 | *granted_access = desired_access; |
Vitaliy Margolen | fad936c | 2007-01-24 23:42:15 -0700 | [diff] [blame] | 842 | return *status = STATUS_SUCCESS; |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 843 | } |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 844 | |
| 845 | /* 2: Check if caller wants access to system security part. Note: access |
| 846 | * is only granted if specifically asked for */ |
| 847 | if (desired_access & ACCESS_SYSTEM_SECURITY) |
| 848 | { |
| 849 | const LUID_AND_ATTRIBUTES security_priv = { SeSecurityPrivilege, 0 }; |
| 850 | LUID_AND_ATTRIBUTES retpriv = security_priv; |
| 851 | if (token_check_privileges( token, TRUE, &security_priv, 1, &retpriv )) |
| 852 | { |
| 853 | if (priv_count) |
| 854 | { |
| 855 | /* assumes that there will only be one privilege to return */ |
| 856 | if (*priv_count >= 1) |
| 857 | { |
| 858 | *priv_count = 1; |
| 859 | *privs = retpriv; |
| 860 | } |
| 861 | else |
| 862 | { |
| 863 | *priv_count = 1; |
| 864 | return STATUS_BUFFER_TOO_SMALL; |
| 865 | } |
| 866 | } |
| 867 | current_access |= ACCESS_SYSTEM_SECURITY; |
| 868 | if (desired_access == current_access) |
| 869 | { |
| 870 | *granted_access = current_access; |
Vitaliy Margolen | fad936c | 2007-01-24 23:42:15 -0700 | [diff] [blame] | 871 | return *status = STATUS_SUCCESS; |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 872 | } |
| 873 | } |
| 874 | else |
| 875 | { |
| 876 | *priv_count = 0; |
Vitaliy Margolen | fad936c | 2007-01-24 23:42:15 -0700 | [diff] [blame] | 877 | *status = STATUS_PRIVILEGE_NOT_HELD; |
| 878 | return STATUS_SUCCESS; |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 879 | } |
| 880 | } |
| 881 | else if (priv_count) *priv_count = 0; |
| 882 | |
| 883 | /* 3: Check whether the token is the owner */ |
| 884 | /* NOTE: SeTakeOwnershipPrivilege is not checked for here - it is instead |
| 885 | * checked when a "set owner" call is made, overriding the access rights |
| 886 | * determined here. */ |
| 887 | if (token_sid_present( token, owner, FALSE )) |
| 888 | { |
| 889 | current_access |= (READ_CONTROL | WRITE_DAC); |
| 890 | if (desired_access == current_access) |
| 891 | { |
| 892 | *granted_access = current_access; |
Vitaliy Margolen | fad936c | 2007-01-24 23:42:15 -0700 | [diff] [blame] | 893 | return *status = STATUS_SUCCESS; |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 894 | } |
| 895 | } |
| 896 | |
| 897 | /* 4: Grant rights according to the DACL */ |
| 898 | ace = (const ACE_HEADER *)(dacl + 1); |
Rob Shearman | e51f849 | 2007-10-25 16:19:54 +0100 | [diff] [blame] | 899 | for (i = 0; i < dacl->AceCount; i++, ace = ace_next( ace )) |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 900 | { |
| 901 | const ACCESS_ALLOWED_ACE *aa_ace; |
| 902 | const ACCESS_DENIED_ACE *ad_ace; |
| 903 | const SID *sid; |
Rob Shearman | e51f849 | 2007-10-25 16:19:54 +0100 | [diff] [blame] | 904 | |
| 905 | if (ace->AceFlags & INHERIT_ONLY_ACE) |
| 906 | continue; |
| 907 | |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 908 | switch (ace->AceType) |
| 909 | { |
| 910 | case ACCESS_DENIED_ACE_TYPE: |
| 911 | ad_ace = (const ACCESS_DENIED_ACE *)ace; |
| 912 | sid = (const SID *)&ad_ace->SidStart; |
| 913 | if (token_sid_present( token, sid, TRUE )) |
| 914 | { |
| 915 | unsigned int access = ad_ace->Mask; |
| 916 | map_generic_mask(&access, mapping); |
| 917 | if (desired_access & MAXIMUM_ALLOWED) |
| 918 | denied_access |= access; |
| 919 | else |
| 920 | { |
| 921 | denied_access |= (access & ~current_access); |
Vitaliy Margolen | fad936c | 2007-01-24 23:42:15 -0700 | [diff] [blame] | 922 | if (desired_access & access) goto done; |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 923 | } |
| 924 | } |
| 925 | break; |
| 926 | case ACCESS_ALLOWED_ACE_TYPE: |
| 927 | aa_ace = (const ACCESS_ALLOWED_ACE *)ace; |
| 928 | sid = (const SID *)&aa_ace->SidStart; |
| 929 | if (token_sid_present( token, sid, FALSE )) |
| 930 | { |
| 931 | unsigned int access = aa_ace->Mask; |
| 932 | map_generic_mask(&access, mapping); |
| 933 | if (desired_access & MAXIMUM_ALLOWED) |
| 934 | current_access |= access; |
| 935 | else |
| 936 | current_access |= (access & ~denied_access); |
| 937 | } |
| 938 | break; |
| 939 | } |
| 940 | |
| 941 | /* don't bother carrying on checking if we've already got all of |
| 942 | * rights we need */ |
| 943 | if (desired_access == *granted_access) |
| 944 | break; |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 945 | } |
| 946 | |
Vitaliy Margolen | fad936c | 2007-01-24 23:42:15 -0700 | [diff] [blame] | 947 | done: |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 948 | if (desired_access & MAXIMUM_ALLOWED) |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 949 | *granted_access = current_access & ~denied_access; |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 950 | else |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 951 | if ((current_access & desired_access) == desired_access) |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 952 | *granted_access = current_access & desired_access; |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 953 | else |
Vitaliy Margolen | fad936c | 2007-01-24 23:42:15 -0700 | [diff] [blame] | 954 | *granted_access = 0; |
| 955 | |
| 956 | *status = *granted_access ? STATUS_SUCCESS : STATUS_ACCESS_DENIED; |
| 957 | return STATUS_SUCCESS; |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 958 | } |
| 959 | |
Robert Shearman | fbf0ea9 | 2005-07-13 19:31:27 +0000 | [diff] [blame] | 960 | const ACL *token_get_default_dacl( struct token *token ) |
| 961 | { |
| 962 | return token->default_dacl; |
| 963 | } |
| 964 | |
Rob Shearman | 5af809a | 2007-10-02 15:54:51 +0100 | [diff] [blame] | 965 | const SID *token_get_user( struct token *token ) |
Vitaliy Margolen | b0e9d7e | 2007-02-07 21:43:11 -0700 | [diff] [blame] | 966 | { |
Rob Shearman | 5af809a | 2007-10-02 15:54:51 +0100 | [diff] [blame] | 967 | return token->user; |
| 968 | } |
Vitaliy Margolen | b0e9d7e | 2007-02-07 21:43:11 -0700 | [diff] [blame] | 969 | |
Rob Shearman | 5af809a | 2007-10-02 15:54:51 +0100 | [diff] [blame] | 970 | const SID *token_get_primary_group( struct token *token ) |
| 971 | { |
| 972 | return token->primary_group; |
Vitaliy Margolen | b0e9d7e | 2007-02-07 21:43:11 -0700 | [diff] [blame] | 973 | } |
| 974 | |
Rob Shearman | 6a76a0a | 2007-02-21 13:59:59 +0000 | [diff] [blame] | 975 | int check_object_access(struct object *obj, unsigned int *access) |
| 976 | { |
| 977 | GENERIC_MAPPING mapping; |
| 978 | struct token *token = current->token ? current->token : current->process->token; |
| 979 | LUID_AND_ATTRIBUTES priv; |
| 980 | unsigned int status, priv_count = 1; |
| 981 | int res; |
| 982 | |
| 983 | mapping.GenericAll = obj->ops->map_access( obj, GENERIC_ALL ); |
| 984 | |
| 985 | if (!obj->sd) |
| 986 | { |
| 987 | if (*access & MAXIMUM_ALLOWED) |
| 988 | *access = mapping.GenericAll; |
| 989 | return TRUE; |
| 990 | } |
| 991 | |
| 992 | mapping.GenericRead = obj->ops->map_access( obj, GENERIC_READ ); |
| 993 | mapping.GenericWrite = obj->ops->map_access( obj, GENERIC_WRITE ); |
| 994 | mapping.GenericExecute = obj->ops->map_access( obj, GENERIC_EXECUTE ); |
| 995 | |
| 996 | res = token_access_check( token, obj->sd, *access, &priv, &priv_count, |
| 997 | &mapping, access, &status ) == STATUS_SUCCESS && |
| 998 | status == STATUS_SUCCESS; |
| 999 | |
| 1000 | if (!res) set_error( STATUS_ACCESS_DENIED ); |
| 1001 | return res; |
| 1002 | } |
| 1003 | |
| 1004 | |
Mike McCormack | 36cd6f5 | 2003-07-24 00:07:00 +0000 | [diff] [blame] | 1005 | /* open a security token */ |
| 1006 | DECL_HANDLER(open_token) |
| 1007 | { |
Robert Shearman | 3795709 | 2005-06-10 19:54:46 +0000 | [diff] [blame] | 1008 | if (req->flags & OPEN_TOKEN_THREAD) |
Mike McCormack | 36cd6f5 | 2003-07-24 00:07:00 +0000 | [diff] [blame] | 1009 | { |
| 1010 | struct thread *thread = get_thread_from_handle( req->handle, 0 ); |
| 1011 | if (thread) |
| 1012 | { |
| 1013 | if (thread->token) |
Rob Shearman | c9b9847 | 2007-02-15 23:21:40 +0000 | [diff] [blame] | 1014 | { |
Alexandre Julliard | f6d871e | 2008-03-26 14:38:49 +0100 | [diff] [blame] | 1015 | if (!thread->token->primary && thread->token->impersonation_level <= SecurityAnonymous) |
Rob Shearman | c9b9847 | 2007-02-15 23:21:40 +0000 | [diff] [blame] | 1016 | set_error( STATUS_CANT_OPEN_ANONYMOUS ); |
| 1017 | else |
| 1018 | reply->token = alloc_handle( current->process, thread->token, |
| 1019 | req->access, req->attributes ); |
| 1020 | } |
Robert Shearman | b0f02b2 | 2005-02-11 11:52:06 +0000 | [diff] [blame] | 1021 | else |
Rob Shearman | c9b9847 | 2007-02-15 23:21:40 +0000 | [diff] [blame] | 1022 | set_error( STATUS_NO_TOKEN ); |
Mike McCormack | 36cd6f5 | 2003-07-24 00:07:00 +0000 | [diff] [blame] | 1023 | release_object( thread ); |
| 1024 | } |
| 1025 | } |
| 1026 | else |
| 1027 | { |
| 1028 | struct process *process = get_process_from_handle( req->handle, 0 ); |
| 1029 | if (process) |
| 1030 | { |
| 1031 | if (process->token) |
Alexandre Julliard | 836d07c | 2005-12-09 12:17:19 +0100 | [diff] [blame] | 1032 | reply->token = alloc_handle( current->process, process->token, req->access, |
Alexandre Julliard | 24560e7 | 2005-12-09 13:58:25 +0100 | [diff] [blame] | 1033 | req->attributes ); |
Robert Shearman | b0f02b2 | 2005-02-11 11:52:06 +0000 | [diff] [blame] | 1034 | else |
Rob Shearman | c9b9847 | 2007-02-15 23:21:40 +0000 | [diff] [blame] | 1035 | set_error( STATUS_NO_TOKEN ); |
Mike McCormack | 36cd6f5 | 2003-07-24 00:07:00 +0000 | [diff] [blame] | 1036 | release_object( process ); |
| 1037 | } |
| 1038 | } |
| 1039 | } |
Robert Shearman | b0f02b2 | 2005-02-11 11:52:06 +0000 | [diff] [blame] | 1040 | |
| 1041 | /* adjust the privileges held by a token */ |
| 1042 | DECL_HANDLER(adjust_token_privileges) |
| 1043 | { |
| 1044 | struct token *token; |
| 1045 | unsigned int access = TOKEN_ADJUST_PRIVILEGES; |
| 1046 | |
| 1047 | if (req->get_modified_state) access |= TOKEN_QUERY; |
| 1048 | |
| 1049 | if ((token = (struct token *)get_handle_obj( current->process, req->handle, |
| 1050 | access, &token_ops ))) |
| 1051 | { |
| 1052 | const LUID_AND_ATTRIBUTES *privs = get_req_data(); |
| 1053 | LUID_AND_ATTRIBUTES *modified_privs = NULL; |
| 1054 | unsigned int priv_count = get_req_data_size() / sizeof(LUID_AND_ATTRIBUTES); |
| 1055 | unsigned int modified_priv_count = 0; |
| 1056 | |
| 1057 | if (req->get_modified_state && !req->disable_all) |
| 1058 | { |
Michael Stefaniuc | a624977 | 2006-07-25 10:30:04 +0200 | [diff] [blame] | 1059 | unsigned int i; |
Robert Shearman | b0f02b2 | 2005-02-11 11:52:06 +0000 | [diff] [blame] | 1060 | /* count modified privs */ |
| 1061 | for (i = 0; i < priv_count; i++) |
| 1062 | { |
| 1063 | struct privilege *privilege = |
| 1064 | token_find_privilege( token, &privs[i].Luid, FALSE ); |
| 1065 | if (privilege && req->get_modified_state) |
| 1066 | modified_priv_count++; |
| 1067 | } |
| 1068 | reply->len = modified_priv_count; |
| 1069 | modified_priv_count = min( modified_priv_count, get_reply_max_size() / sizeof(*modified_privs) ); |
| 1070 | if (modified_priv_count) |
| 1071 | modified_privs = set_reply_data_size( modified_priv_count * sizeof(*modified_privs) ); |
| 1072 | } |
| 1073 | reply->len = modified_priv_count * sizeof(*modified_privs); |
| 1074 | |
| 1075 | if (req->disable_all) |
| 1076 | token_disable_privileges( token ); |
| 1077 | else |
| 1078 | modified_priv_count = token_adjust_privileges( token, privs, |
| 1079 | priv_count, modified_privs, modified_priv_count ); |
| 1080 | |
| 1081 | release_object( token ); |
| 1082 | } |
| 1083 | } |
| 1084 | |
| 1085 | /* retrieves the list of privileges that may be held be the token */ |
| 1086 | DECL_HANDLER(get_token_privileges) |
| 1087 | { |
| 1088 | struct token *token; |
| 1089 | |
| 1090 | if ((token = (struct token *)get_handle_obj( current->process, req->handle, |
| 1091 | TOKEN_QUERY, |
| 1092 | &token_ops ))) |
| 1093 | { |
| 1094 | int priv_count = 0; |
| 1095 | LUID_AND_ATTRIBUTES *privs; |
| 1096 | struct privilege *privilege; |
| 1097 | |
| 1098 | LIST_FOR_EACH_ENTRY( privilege, &token->privileges, struct privilege, entry ) |
| 1099 | priv_count++; |
| 1100 | |
| 1101 | reply->len = priv_count * sizeof(*privs); |
| 1102 | if (reply->len <= get_reply_max_size()) |
| 1103 | { |
| 1104 | privs = set_reply_data_size( priv_count * sizeof(*privs) ); |
| 1105 | if (privs) |
| 1106 | { |
| 1107 | int i = 0; |
| 1108 | LIST_FOR_EACH_ENTRY( privilege, &token->privileges, struct privilege, entry ) |
| 1109 | { |
| 1110 | luid_and_attr_from_privilege( &privs[i], privilege ); |
| 1111 | i++; |
| 1112 | } |
| 1113 | } |
| 1114 | } |
| 1115 | else |
| 1116 | set_error(STATUS_BUFFER_TOO_SMALL); |
| 1117 | |
| 1118 | release_object( token ); |
| 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | /* creates a duplicate of the token */ |
| 1123 | DECL_HANDLER(duplicate_token) |
| 1124 | { |
| 1125 | struct token *src_token; |
Rob Shearman | c9b9847 | 2007-02-15 23:21:40 +0000 | [diff] [blame] | 1126 | |
Robert Shearman | b0f02b2 | 2005-02-11 11:52:06 +0000 | [diff] [blame] | 1127 | if ((src_token = (struct token *)get_handle_obj( current->process, req->handle, |
| 1128 | TOKEN_DUPLICATE, |
| 1129 | &token_ops ))) |
| 1130 | { |
Rob Shearman | bdf964d | 2007-05-28 18:39:33 +0100 | [diff] [blame] | 1131 | struct token *token = token_duplicate( src_token, req->primary, req->impersonation_level ); |
Robert Shearman | b0f02b2 | 2005-02-11 11:52:06 +0000 | [diff] [blame] | 1132 | if (token) |
| 1133 | { |
Rob Shearman | bdf964d | 2007-05-28 18:39:33 +0100 | [diff] [blame] | 1134 | reply->new_handle = alloc_handle( current->process, token, req->access, req->attributes); |
Robert Shearman | b0f02b2 | 2005-02-11 11:52:06 +0000 | [diff] [blame] | 1135 | release_object( token ); |
| 1136 | } |
| 1137 | release_object( src_token ); |
| 1138 | } |
| 1139 | } |
Robert Shearman | d2ea92d | 2005-04-22 21:17:15 +0000 | [diff] [blame] | 1140 | |
| 1141 | /* checks the specified privileges are held by the token */ |
| 1142 | DECL_HANDLER(check_token_privileges) |
| 1143 | { |
| 1144 | struct token *token; |
| 1145 | |
| 1146 | if ((token = (struct token *)get_handle_obj( current->process, req->handle, |
| 1147 | TOKEN_QUERY, |
| 1148 | &token_ops ))) |
| 1149 | { |
| 1150 | unsigned int count = get_req_data_size() / sizeof(LUID_AND_ATTRIBUTES); |
Rob Shearman | c9b9847 | 2007-02-15 23:21:40 +0000 | [diff] [blame] | 1151 | |
| 1152 | if (!token->primary && token->impersonation_level <= SecurityAnonymous) |
| 1153 | set_error( STATUS_BAD_IMPERSONATION_LEVEL ); |
| 1154 | else if (get_reply_max_size() >= count * sizeof(LUID_AND_ATTRIBUTES)) |
Robert Shearman | d2ea92d | 2005-04-22 21:17:15 +0000 | [diff] [blame] | 1155 | { |
| 1156 | LUID_AND_ATTRIBUTES *usedprivs = set_reply_data_size( count * sizeof(*usedprivs) ); |
| 1157 | reply->has_privileges = token_check_privileges( token, req->all_required, get_req_data(), count, usedprivs ); |
| 1158 | } |
| 1159 | else |
| 1160 | set_error( STATUS_BUFFER_OVERFLOW ); |
| 1161 | release_object( token ); |
| 1162 | } |
| 1163 | } |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 1164 | |
| 1165 | /* checks that a user represented by a token is allowed to access an object |
| 1166 | * represented by a security descriptor */ |
| 1167 | DECL_HANDLER(access_check) |
| 1168 | { |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 1169 | data_size_t sd_size = get_req_data_size(); |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 1170 | const struct security_descriptor *sd = get_req_data(); |
| 1171 | struct token *token; |
| 1172 | |
| 1173 | if (!sd_is_valid( sd, sd_size )) |
| 1174 | { |
| 1175 | set_error( STATUS_ACCESS_VIOLATION ); |
| 1176 | return; |
| 1177 | } |
| 1178 | |
| 1179 | if ((token = (struct token *)get_handle_obj( current->process, req->handle, |
| 1180 | TOKEN_QUERY, |
| 1181 | &token_ops ))) |
| 1182 | { |
| 1183 | GENERIC_MAPPING mapping; |
| 1184 | unsigned int status; |
| 1185 | LUID_AND_ATTRIBUTES priv; |
| 1186 | unsigned int priv_count = 1; |
| 1187 | |
| 1188 | memset(&priv, 0, sizeof(priv)); |
| 1189 | |
Robert Shearman | 4bba216 | 2005-06-20 13:18:38 +0000 | [diff] [blame] | 1190 | /* only impersonation tokens may be used with this function */ |
| 1191 | if (token->primary) |
| 1192 | { |
| 1193 | set_error( STATUS_NO_IMPERSONATION_TOKEN ); |
| 1194 | release_object( token ); |
| 1195 | return; |
| 1196 | } |
Rob Shearman | c9b9847 | 2007-02-15 23:21:40 +0000 | [diff] [blame] | 1197 | /* anonymous impersonation tokens can't be used */ |
| 1198 | if (token->impersonation_level <= SecurityAnonymous) |
| 1199 | { |
| 1200 | set_error( STATUS_BAD_IMPERSONATION_LEVEL ); |
| 1201 | release_object( token ); |
| 1202 | return; |
| 1203 | } |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 1204 | |
| 1205 | mapping.GenericRead = req->mapping_read; |
| 1206 | mapping.GenericWrite = req->mapping_write; |
| 1207 | mapping.GenericExecute = req->mapping_execute; |
| 1208 | mapping.GenericAll = req->mapping_all; |
| 1209 | |
Vitaliy Margolen | fad936c | 2007-01-24 23:42:15 -0700 | [diff] [blame] | 1210 | status = token_access_check( |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 1211 | token, sd, req->desired_access, &priv, &priv_count, &mapping, |
Vitaliy Margolen | fad936c | 2007-01-24 23:42:15 -0700 | [diff] [blame] | 1212 | &reply->access_granted, &reply->access_status ); |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 1213 | |
| 1214 | reply->privileges_len = priv_count*sizeof(LUID_AND_ATTRIBUTES); |
| 1215 | |
| 1216 | if ((priv_count > 0) && (reply->privileges_len <= get_reply_max_size())) |
| 1217 | { |
| 1218 | LUID_AND_ATTRIBUTES *privs = set_reply_data_size( priv_count * sizeof(*privs) ); |
| 1219 | memcpy( privs, &priv, sizeof(priv) ); |
| 1220 | } |
| 1221 | |
Vitaliy Margolen | fad936c | 2007-01-24 23:42:15 -0700 | [diff] [blame] | 1222 | set_error( status ); |
Robert Shearman | 4ad9341 | 2005-05-24 12:32:18 +0000 | [diff] [blame] | 1223 | release_object( token ); |
| 1224 | } |
| 1225 | } |
Robert Shearman | 91eaea5 | 2005-07-18 13:22:55 +0000 | [diff] [blame] | 1226 | |
Francois Gouget | 11ae0f6 | 2006-06-15 17:38:04 +0200 | [diff] [blame] | 1227 | /* retrieves the SID of the user that the token represents */ |
Rob Shearman | bd56916 | 2009-11-16 20:11:06 +0000 | [diff] [blame] | 1228 | DECL_HANDLER(get_token_sid) |
Robert Shearman | 91eaea5 | 2005-07-18 13:22:55 +0000 | [diff] [blame] | 1229 | { |
| 1230 | struct token *token; |
| 1231 | |
Rob Shearman | bd56916 | 2009-11-16 20:11:06 +0000 | [diff] [blame] | 1232 | reply->sid_len = 0; |
Robert Shearman | 91eaea5 | 2005-07-18 13:22:55 +0000 | [diff] [blame] | 1233 | |
| 1234 | if ((token = (struct token *)get_handle_obj( current->process, req->handle, |
| 1235 | TOKEN_QUERY, |
| 1236 | &token_ops ))) |
| 1237 | { |
Rob Shearman | bd56916 | 2009-11-16 20:11:06 +0000 | [diff] [blame] | 1238 | const SID *sid = NULL; |
Robert Shearman | 91eaea5 | 2005-07-18 13:22:55 +0000 | [diff] [blame] | 1239 | |
Rob Shearman | bd56916 | 2009-11-16 20:11:06 +0000 | [diff] [blame] | 1240 | switch (req->which_sid) |
Robert Shearman | 91eaea5 | 2005-07-18 13:22:55 +0000 | [diff] [blame] | 1241 | { |
Rob Shearman | bd56916 | 2009-11-16 20:11:06 +0000 | [diff] [blame] | 1242 | case TokenUser: |
| 1243 | assert(token->user); |
| 1244 | sid = token->user; |
| 1245 | break; |
| 1246 | case TokenPrimaryGroup: |
| 1247 | sid = token->primary_group; |
| 1248 | break; |
| 1249 | case TokenOwner: |
| 1250 | { |
| 1251 | struct group *group; |
| 1252 | LIST_FOR_EACH_ENTRY( group, &token->groups, struct group, entry ) |
| 1253 | { |
| 1254 | if (group->owner) |
| 1255 | { |
| 1256 | sid = &group->sid; |
| 1257 | break; |
| 1258 | } |
| 1259 | } |
| 1260 | break; |
Robert Shearman | 91eaea5 | 2005-07-18 13:22:55 +0000 | [diff] [blame] | 1261 | } |
Rob Shearman | bd56916 | 2009-11-16 20:11:06 +0000 | [diff] [blame] | 1262 | default: |
| 1263 | set_error( STATUS_INVALID_PARAMETER ); |
| 1264 | break; |
| 1265 | } |
Robert Shearman | 91eaea5 | 2005-07-18 13:22:55 +0000 | [diff] [blame] | 1266 | |
Rob Shearman | bd56916 | 2009-11-16 20:11:06 +0000 | [diff] [blame] | 1267 | if (sid) |
| 1268 | { |
| 1269 | reply->sid_len = FIELD_OFFSET(SID, SubAuthority[sid->SubAuthorityCount]); |
| 1270 | if (reply->sid_len <= get_reply_max_size()) set_reply_data( sid, reply->sid_len ); |
| 1271 | else set_error( STATUS_BUFFER_TOO_SMALL ); |
| 1272 | } |
Robert Shearman | 91eaea5 | 2005-07-18 13:22:55 +0000 | [diff] [blame] | 1273 | release_object( token ); |
| 1274 | } |
| 1275 | } |
Robert Shearman | 3396a66 | 2006-05-13 16:58:19 +0100 | [diff] [blame] | 1276 | |
| 1277 | /* retrieves the groups that the user represented by the token belongs to */ |
| 1278 | DECL_HANDLER(get_token_groups) |
| 1279 | { |
| 1280 | struct token *token; |
| 1281 | |
| 1282 | reply->user_len = 0; |
| 1283 | |
| 1284 | if ((token = (struct token *)get_handle_obj( current->process, req->handle, |
| 1285 | TOKEN_QUERY, |
| 1286 | &token_ops ))) |
| 1287 | { |
| 1288 | size_t size_needed = sizeof(struct token_groups); |
| 1289 | unsigned int group_count = 0; |
| 1290 | const struct group *group; |
| 1291 | |
| 1292 | LIST_FOR_EACH_ENTRY( group, &token->groups, const struct group, entry ) |
| 1293 | { |
| 1294 | group_count++; |
| 1295 | size_needed += FIELD_OFFSET(SID, SubAuthority[group->sid.SubAuthorityCount]); |
| 1296 | } |
| 1297 | size_needed += sizeof(unsigned int) * group_count; |
| 1298 | |
| 1299 | reply->user_len = size_needed; |
| 1300 | |
| 1301 | if (size_needed <= get_reply_max_size()) |
| 1302 | { |
| 1303 | struct token_groups *tg = set_reply_data_size( size_needed ); |
| 1304 | if (tg) |
| 1305 | { |
| 1306 | unsigned int *attr_ptr = (unsigned int *)(tg + 1); |
| 1307 | SID *sid_ptr = (SID *)(attr_ptr + group_count); |
| 1308 | |
| 1309 | tg->count = group_count; |
| 1310 | |
| 1311 | LIST_FOR_EACH_ENTRY( group, &token->groups, const struct group, entry ) |
| 1312 | { |
| 1313 | |
| 1314 | *attr_ptr = 0; |
| 1315 | if (group->mandatory) *attr_ptr |= SE_GROUP_MANDATORY; |
| 1316 | if (group->def) *attr_ptr |= SE_GROUP_ENABLED_BY_DEFAULT; |
| 1317 | if (group->enabled) *attr_ptr |= SE_GROUP_ENABLED; |
| 1318 | if (group->owner) *attr_ptr |= SE_GROUP_OWNER; |
| 1319 | if (group->deny_only) *attr_ptr |= SE_GROUP_USE_FOR_DENY_ONLY; |
| 1320 | if (group->resource) *attr_ptr |= SE_GROUP_RESOURCE; |
H. Verbeet | 3120c08 | 2008-03-17 17:55:17 +0100 | [diff] [blame] | 1321 | if (group->logon) *attr_ptr |= SE_GROUP_LOGON_ID; |
Robert Shearman | 3396a66 | 2006-05-13 16:58:19 +0100 | [diff] [blame] | 1322 | |
| 1323 | memcpy(sid_ptr, &group->sid, FIELD_OFFSET(SID, SubAuthority[group->sid.SubAuthorityCount])); |
| 1324 | |
| 1325 | sid_ptr = (SID *)((char *)sid_ptr + FIELD_OFFSET(SID, SubAuthority[group->sid.SubAuthorityCount])); |
| 1326 | attr_ptr++; |
| 1327 | } |
| 1328 | } |
| 1329 | } |
| 1330 | else set_error( STATUS_BUFFER_TOO_SMALL ); |
| 1331 | |
| 1332 | release_object( token ); |
| 1333 | } |
| 1334 | } |
Vitaliy Margolen | b0e9d7e | 2007-02-07 21:43:11 -0700 | [diff] [blame] | 1335 | |
Rob Shearman | d342d14 | 2007-02-21 17:10:45 +0000 | [diff] [blame] | 1336 | DECL_HANDLER(get_token_impersonation_level) |
| 1337 | { |
| 1338 | struct token *token; |
| 1339 | |
| 1340 | if ((token = (struct token *)get_handle_obj( current->process, req->handle, |
| 1341 | TOKEN_QUERY, |
| 1342 | &token_ops ))) |
| 1343 | { |
| 1344 | if (token->primary) |
| 1345 | set_error( STATUS_INVALID_PARAMETER ); |
| 1346 | else |
| 1347 | reply->impersonation_level = token->impersonation_level; |
| 1348 | |
| 1349 | release_object( token ); |
| 1350 | } |
| 1351 | } |
| 1352 | |
Rob Shearman | 3f431a0 | 2007-09-13 16:47:56 +0100 | [diff] [blame] | 1353 | DECL_HANDLER(get_token_statistics) |
| 1354 | { |
| 1355 | struct token *token; |
| 1356 | |
| 1357 | if ((token = (struct token *)get_handle_obj( current->process, req->handle, |
| 1358 | TOKEN_QUERY, |
| 1359 | &token_ops ))) |
| 1360 | { |
| 1361 | reply->token_id = token->token_id; |
| 1362 | reply->modified_id = token->modified_id; |
| 1363 | reply->primary = token->primary; |
| 1364 | reply->impersonation_level = token->impersonation_level; |
| 1365 | reply->group_count = list_count( &token->groups ); |
| 1366 | reply->privilege_count = list_count( &token->privileges ); |
| 1367 | |
| 1368 | release_object( token ); |
| 1369 | } |
| 1370 | } |
Hans Leidekker | 24af6f3 | 2009-04-21 09:53:16 +0200 | [diff] [blame] | 1371 | |
| 1372 | DECL_HANDLER(get_token_default_dacl) |
| 1373 | { |
| 1374 | struct token *token; |
| 1375 | |
| 1376 | reply->acl_len = 0; |
| 1377 | |
| 1378 | if ((token = (struct token *)get_handle_obj( current->process, req->handle, |
| 1379 | TOKEN_QUERY, |
| 1380 | &token_ops ))) |
| 1381 | { |
| 1382 | if (token->default_dacl) |
| 1383 | reply->acl_len = token->default_dacl->AclSize; |
| 1384 | |
| 1385 | if (reply->acl_len <= get_reply_max_size()) |
| 1386 | { |
| 1387 | ACL *acl_reply = set_reply_data_size( reply->acl_len ); |
| 1388 | if (acl_reply) |
| 1389 | memcpy( acl_reply, token->default_dacl, reply->acl_len ); |
| 1390 | } |
| 1391 | else set_error( STATUS_BUFFER_TOO_SMALL ); |
| 1392 | |
| 1393 | release_object( token ); |
| 1394 | } |
| 1395 | } |
| 1396 | |
| 1397 | DECL_HANDLER(set_token_default_dacl) |
| 1398 | { |
| 1399 | struct token *token; |
| 1400 | |
| 1401 | if ((token = (struct token *)get_handle_obj( current->process, req->handle, |
| 1402 | TOKEN_ADJUST_DEFAULT, |
| 1403 | &token_ops ))) |
| 1404 | { |
| 1405 | const ACL *acl = get_req_data(); |
| 1406 | unsigned int acl_size = get_req_data_size(); |
| 1407 | |
| 1408 | free( token->default_dacl ); |
| 1409 | token->default_dacl = NULL; |
| 1410 | |
| 1411 | if (acl_size) |
| 1412 | token->default_dacl = memdup( acl, acl_size ); |
| 1413 | |
| 1414 | release_object( token ); |
| 1415 | } |
| 1416 | } |