d3d11: Make extracting input signature more robust.
[wine.git] / server / token.c
blob9489529a5d1990b2d033832568197e432ee84175
1 /*
2 * Tokens
4 * Copyright (C) 1998 Alexandre Julliard
5 * Copyright (C) 2003 Mike McCormack
6 * Copyright (C) 2005 Robert Shearman
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.
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.
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
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "config.h"
25 #include <assert.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <unistd.h>
31 #include "ntstatus.h"
32 #define WIN32_NO_STATUS
33 #include "windef.h"
34 #include "winternl.h"
36 #include "handle.h"
37 #include "thread.h"
38 #include "process.h"
39 #include "request.h"
40 #include "security.h"
42 #include "wine/unicode.h"
44 #define MAX_SUBAUTH_COUNT 1
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 };
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 } };
70 static const SID anonymous_logon_sid = { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_ANONYMOUS_LOGON_RID } };
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 } };
73 static const struct /* same fields as struct SID */
75 BYTE Revision;
76 BYTE SubAuthorityCount;
77 SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
78 DWORD SubAuthority[5];
79 } local_user_sid = { SID_REVISION, 5, { SECURITY_NT_AUTHORITY }, { SECURITY_NT_NON_UNIQUE, 0, 0, 0, 1000 } };
80 static const struct /* same fields as struct SID */
82 BYTE Revision;
83 BYTE SubAuthorityCount;
84 SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
85 DWORD SubAuthority[2];
86 } builtin_admins_sid = { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS } };
87 static const struct /* same fields as struct SID */
89 BYTE Revision;
90 BYTE SubAuthorityCount;
91 SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
92 DWORD SubAuthority[2];
93 } builtin_users_sid = { SID_REVISION, 2, { SECURITY_NT_AUTHORITY }, { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_USERS } };
95 const PSID security_world_sid = (PSID)&world_sid;
96 static const PSID security_local_sid = (PSID)&local_sid;
97 static const PSID security_interactive_sid = (PSID)&interactive_sid;
98 static const PSID security_authenticated_user_sid = (PSID)&authenticated_user_sid;
99 const PSID security_local_system_sid = (PSID)&local_system_sid;
100 const PSID security_local_user_sid = (PSID)&local_user_sid;
101 const PSID security_builtin_admins_sid = (PSID)&builtin_admins_sid;
102 const PSID security_builtin_users_sid = (PSID)&builtin_users_sid;
104 static luid_t prev_luid_value = { 1000, 0 };
106 struct token
108 struct object obj; /* object header */
109 luid_t token_id; /* system-unique id of token */
110 luid_t modified_id; /* new id allocated every time token is modified */
111 struct list privileges; /* privileges available to the token */
112 struct list groups; /* groups that the user of this token belongs to (sid_and_attributes) */
113 SID *user; /* SID of user this token represents */
114 SID *primary_group; /* SID of user's primary group */
115 unsigned primary; /* is this a primary or impersonation token? */
116 ACL *default_dacl; /* the default DACL to assign to objects created by this user */
117 TOKEN_SOURCE source; /* source of the token */
118 int impersonation_level; /* impersonation level this token is capable of if non-primary token */
121 struct privilege
123 struct list entry;
124 LUID luid;
125 unsigned enabled : 1; /* is the privilege currently enabled? */
126 unsigned def : 1; /* is the privilege enabled by default? */
129 struct group
131 struct list entry;
132 unsigned enabled : 1; /* is the sid currently enabled? */
133 unsigned def : 1; /* is the sid enabled by default? */
134 unsigned logon : 1; /* is this a logon sid? */
135 unsigned mandatory: 1; /* is this sid always enabled? */
136 unsigned owner : 1; /* can this sid be an owner of an object? */
137 unsigned resource : 1; /* is this a domain-local group? */
138 unsigned deny_only: 1; /* is this a sid that should be use for denying only? */
139 SID sid;
142 static void token_dump( struct object *obj, int verbose );
143 static unsigned int token_map_access( struct object *obj, unsigned int access );
144 static void token_destroy( struct object *obj );
146 static const struct object_ops token_ops =
148 sizeof(struct token), /* size */
149 token_dump, /* dump */
150 no_get_type, /* get_type */
151 no_add_queue, /* add_queue */
152 NULL, /* remove_queue */
153 NULL, /* signaled */
154 NULL, /* satisfied */
155 no_signal, /* signal */
156 no_get_fd, /* get_fd */
157 token_map_access, /* map_access */
158 default_get_sd, /* get_sd */
159 default_set_sd, /* set_sd */
160 no_lookup_name, /* lookup_name */
161 no_link_name, /* link_name */
162 NULL, /* unlink_name */
163 no_open_file, /* open_file */
164 no_close_handle, /* close_handle */
165 token_destroy /* destroy */
169 static void token_dump( struct object *obj, int verbose )
171 fprintf( stderr, "Security token\n" );
172 /* FIXME: dump token members */
175 static unsigned int token_map_access( struct object *obj, unsigned int access )
177 if (access & GENERIC_READ) access |= TOKEN_READ;
178 if (access & GENERIC_WRITE) access |= TOKEN_WRITE;
179 if (access & GENERIC_EXECUTE) access |= STANDARD_RIGHTS_EXECUTE;
180 if (access & GENERIC_ALL) access |= TOKEN_ALL_ACCESS;
181 return access & ~(GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | GENERIC_ALL);
184 static SID *security_sid_alloc( const SID_IDENTIFIER_AUTHORITY *idauthority, int subauthcount, const unsigned int subauth[] )
186 int i;
187 SID *sid = mem_alloc( FIELD_OFFSET(SID, SubAuthority[subauthcount]) );
188 if (!sid) return NULL;
189 sid->Revision = SID_REVISION;
190 sid->SubAuthorityCount = subauthcount;
191 sid->IdentifierAuthority = *idauthority;
192 for (i = 0; i < subauthcount; i++)
193 sid->SubAuthority[i] = subauth[i];
194 return sid;
197 void security_set_thread_token( struct thread *thread, obj_handle_t handle )
199 if (!handle)
201 if (thread->token)
202 release_object( thread->token );
203 thread->token = NULL;
205 else
207 struct token *token = (struct token *)get_handle_obj( current->process,
208 handle,
209 TOKEN_IMPERSONATE,
210 &token_ops );
211 if (token)
213 if (thread->token)
214 release_object( thread->token );
215 thread->token = token;
220 const SID *security_unix_uid_to_sid( uid_t uid )
222 /* very simple mapping: either the current user or not the current user */
223 if (uid == getuid())
224 return (const SID *)&local_user_sid;
225 else
226 return &anonymous_logon_sid;
229 static int acl_is_valid( const ACL *acl, data_size_t size )
231 ULONG i;
232 const ACE_HEADER *ace;
234 if (size < sizeof(ACL))
235 return FALSE;
237 size = min(size, MAX_ACL_LEN);
239 size -= sizeof(ACL);
241 ace = (const ACE_HEADER *)(acl + 1);
242 for (i = 0; i < acl->AceCount; i++)
244 const SID *sid;
245 data_size_t sid_size;
247 if (size < sizeof(ACE_HEADER))
248 return FALSE;
249 if (size < ace->AceSize)
250 return FALSE;
251 size -= ace->AceSize;
252 switch (ace->AceType)
254 case ACCESS_DENIED_ACE_TYPE:
255 sid = (const SID *)&((const ACCESS_DENIED_ACE *)ace)->SidStart;
256 sid_size = ace->AceSize - FIELD_OFFSET(ACCESS_DENIED_ACE, SidStart);
257 break;
258 case ACCESS_ALLOWED_ACE_TYPE:
259 sid = (const SID *)&((const ACCESS_ALLOWED_ACE *)ace)->SidStart;
260 sid_size = ace->AceSize - FIELD_OFFSET(ACCESS_ALLOWED_ACE, SidStart);
261 break;
262 case SYSTEM_AUDIT_ACE_TYPE:
263 sid = (const SID *)&((const SYSTEM_AUDIT_ACE *)ace)->SidStart;
264 sid_size = ace->AceSize - FIELD_OFFSET(SYSTEM_AUDIT_ACE, SidStart);
265 break;
266 case SYSTEM_ALARM_ACE_TYPE:
267 sid = (const SID *)&((const SYSTEM_ALARM_ACE *)ace)->SidStart;
268 sid_size = ace->AceSize - FIELD_OFFSET(SYSTEM_ALARM_ACE, SidStart);
269 break;
270 case SYSTEM_MANDATORY_LABEL_ACE_TYPE:
271 sid = (const SID *)&((const SYSTEM_MANDATORY_LABEL_ACE *)ace)->SidStart;
272 sid_size = ace->AceSize - FIELD_OFFSET(SYSTEM_MANDATORY_LABEL_ACE, SidStart);
273 break;
274 default:
275 return FALSE;
277 if (sid_size < FIELD_OFFSET(SID, SubAuthority[0]) || sid_size < security_sid_len( sid ))
278 return FALSE;
279 ace = ace_next( ace );
281 return TRUE;
284 /* checks whether all members of a security descriptor fit inside the size
285 * of memory specified */
286 int sd_is_valid( const struct security_descriptor *sd, data_size_t size )
288 size_t offset = sizeof(struct security_descriptor);
289 const SID *group;
290 const SID *owner;
291 const ACL *sacl;
292 const ACL *dacl;
293 int dummy;
295 if (size < offset)
296 return FALSE;
298 if ((sd->owner_len >= FIELD_OFFSET(SID, SubAuthority[255])) ||
299 (offset + sd->owner_len > size))
300 return FALSE;
301 owner = sd_get_owner( sd );
302 if (owner)
304 size_t needed_size = security_sid_len( owner );
305 if ((sd->owner_len < sizeof(SID)) || (needed_size > sd->owner_len))
306 return FALSE;
308 offset += sd->owner_len;
310 if ((sd->group_len >= FIELD_OFFSET(SID, SubAuthority[255])) ||
311 (offset + sd->group_len > size))
312 return FALSE;
313 group = sd_get_group( sd );
314 if (group)
316 size_t needed_size = security_sid_len( group );
317 if ((sd->group_len < sizeof(SID)) || (needed_size > sd->group_len))
318 return FALSE;
320 offset += sd->group_len;
322 if ((sd->sacl_len >= MAX_ACL_LEN) || (offset + sd->sacl_len > size))
323 return FALSE;
324 sacl = sd_get_sacl( sd, &dummy );
325 if (sacl && !acl_is_valid( sacl, sd->sacl_len ))
326 return FALSE;
327 offset += sd->sacl_len;
329 if ((sd->dacl_len >= MAX_ACL_LEN) || (offset + sd->dacl_len > size))
330 return FALSE;
331 dacl = sd_get_dacl( sd, &dummy );
332 if (dacl && !acl_is_valid( dacl, sd->dacl_len ))
333 return FALSE;
334 offset += sd->dacl_len;
336 return TRUE;
339 /* maps from generic rights to specific rights as given by a mapping */
340 static inline void map_generic_mask(unsigned int *mask, const GENERIC_MAPPING *mapping)
342 if (*mask & GENERIC_READ) *mask |= mapping->GenericRead;
343 if (*mask & GENERIC_WRITE) *mask |= mapping->GenericWrite;
344 if (*mask & GENERIC_EXECUTE) *mask |= mapping->GenericExecute;
345 if (*mask & GENERIC_ALL) *mask |= mapping->GenericAll;
346 *mask &= 0x0FFFFFFF;
349 static inline int is_equal_luid( const LUID *luid1, const LUID *luid2 )
351 return (luid1->LowPart == luid2->LowPart && luid1->HighPart == luid2->HighPart);
354 static inline void allocate_luid( luid_t *luid )
356 prev_luid_value.low_part++;
357 *luid = prev_luid_value;
360 DECL_HANDLER( allocate_locally_unique_id )
362 allocate_luid( &reply->luid );
365 static inline void luid_and_attr_from_privilege( LUID_AND_ATTRIBUTES *out, const struct privilege *in)
367 out->Luid = in->luid;
368 out->Attributes =
369 (in->enabled ? SE_PRIVILEGE_ENABLED : 0) |
370 (in->def ? SE_PRIVILEGE_ENABLED_BY_DEFAULT : 0);
373 static struct privilege *privilege_add( struct token *token, const LUID *luid, int enabled )
375 struct privilege *privilege = mem_alloc( sizeof(*privilege) );
376 if (privilege)
378 privilege->luid = *luid;
379 privilege->def = privilege->enabled = (enabled != 0);
380 list_add_tail( &token->privileges, &privilege->entry );
382 return privilege;
385 static inline void privilege_remove( struct privilege *privilege )
387 list_remove( &privilege->entry );
388 free( privilege );
391 static void token_destroy( struct object *obj )
393 struct token* token;
394 struct list *cursor, *cursor_next;
396 assert( obj->ops == &token_ops );
397 token = (struct token *)obj;
399 free( token->user );
401 LIST_FOR_EACH_SAFE( cursor, cursor_next, &token->privileges )
403 struct privilege *privilege = LIST_ENTRY( cursor, struct privilege, entry );
404 privilege_remove( privilege );
407 LIST_FOR_EACH_SAFE( cursor, cursor_next, &token->groups )
409 struct group *group = LIST_ENTRY( cursor, struct group, entry );
410 list_remove( &group->entry );
411 free( group );
414 free( token->default_dacl );
417 /* creates a new token.
418 * groups may be NULL if group_count is 0.
419 * privs may be NULL if priv_count is 0.
420 * default_dacl may be NULL, indicating that all objects created by the user
421 * are unsecured.
422 * modified_id may be NULL, indicating that a new modified_id luid should be
423 * allocated.
425 static struct token *create_token( unsigned primary, const SID *user,
426 const SID_AND_ATTRIBUTES *groups, unsigned int group_count,
427 const LUID_AND_ATTRIBUTES *privs, unsigned int priv_count,
428 const ACL *default_dacl, TOKEN_SOURCE source,
429 const luid_t *modified_id,
430 int impersonation_level )
432 struct token *token = alloc_object( &token_ops );
433 if (token)
435 unsigned int i;
437 allocate_luid( &token->token_id );
438 if (modified_id)
439 token->modified_id = *modified_id;
440 else
441 allocate_luid( &token->modified_id );
442 list_init( &token->privileges );
443 list_init( &token->groups );
444 token->primary = primary;
445 /* primary tokens don't have impersonation levels */
446 if (primary)
447 token->impersonation_level = -1;
448 else
449 token->impersonation_level = impersonation_level;
450 token->default_dacl = NULL;
451 token->primary_group = NULL;
453 /* copy user */
454 token->user = memdup( user, security_sid_len( user ));
455 if (!token->user)
457 release_object( token );
458 return NULL;
461 /* copy groups */
462 for (i = 0; i < group_count; i++)
464 size_t size = FIELD_OFFSET( struct group, sid.SubAuthority[((const SID *)groups[i].Sid)->SubAuthorityCount] );
465 struct group *group = mem_alloc( size );
467 if (!group)
469 release_object( token );
470 return NULL;
472 memcpy( &group->sid, groups[i].Sid, security_sid_len( groups[i].Sid ));
473 group->enabled = TRUE;
474 group->def = TRUE;
475 group->logon = (groups[i].Attributes & SE_GROUP_LOGON_ID) != 0;
476 group->mandatory = (groups[i].Attributes & SE_GROUP_MANDATORY) != 0;
477 group->owner = (groups[i].Attributes & SE_GROUP_OWNER) != 0;
478 group->resource = FALSE;
479 group->deny_only = FALSE;
480 list_add_tail( &token->groups, &group->entry );
481 /* Use first owner capable group as an owner */
482 if (!token->primary_group && group->owner)
483 token->primary_group = &group->sid;
486 /* copy privileges */
487 for (i = 0; i < priv_count; i++)
489 /* note: we don't check uniqueness: the caller must make sure
490 * privs doesn't contain any duplicate luids */
491 if (!privilege_add( token, &privs[i].Luid,
492 privs[i].Attributes & SE_PRIVILEGE_ENABLED ))
494 release_object( token );
495 return NULL;
499 if (default_dacl)
501 token->default_dacl = memdup( default_dacl, default_dacl->AclSize );
502 if (!token->default_dacl)
504 release_object( token );
505 return NULL;
509 token->source = source;
511 return token;
514 struct token *token_duplicate( struct token *src_token, unsigned primary,
515 int impersonation_level )
517 const luid_t *modified_id =
518 primary || (impersonation_level == src_token->impersonation_level) ?
519 &src_token->modified_id : NULL;
520 struct token *token = NULL;
521 struct privilege *privilege;
522 struct group *group;
524 if (!primary &&
525 (impersonation_level < SecurityAnonymous ||
526 impersonation_level > SecurityDelegation ||
527 (!src_token->primary && (impersonation_level > src_token->impersonation_level))))
529 set_error( STATUS_BAD_IMPERSONATION_LEVEL );
530 return NULL;
533 token = create_token( primary, src_token->user, NULL, 0,
534 NULL, 0, src_token->default_dacl,
535 src_token->source, modified_id,
536 impersonation_level );
537 if (!token) return token;
539 /* copy groups */
540 token->primary_group = NULL;
541 LIST_FOR_EACH_ENTRY( group, &src_token->groups, struct group, entry )
543 size_t size = FIELD_OFFSET( struct group, sid.SubAuthority[group->sid.SubAuthorityCount] );
544 struct group *newgroup = mem_alloc( size );
545 if (!newgroup)
547 release_object( token );
548 return NULL;
550 memcpy( newgroup, group, size );
551 list_add_tail( &token->groups, &newgroup->entry );
552 if (src_token->primary_group == &group->sid)
553 token->primary_group = &newgroup->sid;
555 assert( token->primary_group );
557 /* copy privileges */
558 LIST_FOR_EACH_ENTRY( privilege, &src_token->privileges, struct privilege, entry )
559 if (!privilege_add( token, &privilege->luid, privilege->enabled ))
561 release_object( token );
562 return NULL;
565 return token;
568 static ACL *create_default_dacl( const SID *user )
570 ACCESS_ALLOWED_ACE *aaa;
571 ACL *default_dacl;
572 SID *sid;
573 size_t default_dacl_size = sizeof(ACL) +
574 2*(sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD)) +
575 sizeof(local_system_sid) +
576 security_sid_len( user );
578 default_dacl = mem_alloc( default_dacl_size );
579 if (!default_dacl) return NULL;
581 default_dacl->AclRevision = ACL_REVISION;
582 default_dacl->Sbz1 = 0;
583 default_dacl->AclSize = default_dacl_size;
584 default_dacl->AceCount = 2;
585 default_dacl->Sbz2 = 0;
587 /* GENERIC_ALL for Local System */
588 aaa = (ACCESS_ALLOWED_ACE *)(default_dacl + 1);
589 aaa->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
590 aaa->Header.AceFlags = 0;
591 aaa->Header.AceSize = (sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD)) +
592 sizeof(local_system_sid);
593 aaa->Mask = GENERIC_ALL;
594 sid = (SID *)&aaa->SidStart;
595 memcpy( sid, &local_system_sid, sizeof(local_system_sid) );
597 /* GENERIC_ALL for specified user */
598 aaa = (ACCESS_ALLOWED_ACE *)((char *)aaa + aaa->Header.AceSize);
599 aaa->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
600 aaa->Header.AceFlags = 0;
601 aaa->Header.AceSize = (sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD)) + security_sid_len( user );
602 aaa->Mask = GENERIC_ALL;
603 sid = (SID *)&aaa->SidStart;
604 memcpy( sid, user, security_sid_len( user ));
606 return default_dacl;
609 struct sid_data
611 SID_IDENTIFIER_AUTHORITY idauth;
612 int count;
613 unsigned int subauth[MAX_SUBAUTH_COUNT];
616 struct token *token_create_admin( void )
618 struct token *token = NULL;
619 static const SID_IDENTIFIER_AUTHORITY nt_authority = { SECURITY_NT_AUTHORITY };
620 static const unsigned int alias_admins_subauth[] = { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS };
621 static const unsigned int alias_users_subauth[] = { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_USERS };
622 /* on Windows, this value changes every time the user logs on */
623 static const unsigned int logon_subauth[] = { SECURITY_LOGON_IDS_RID, 0, 1 /* FIXME: should be randomly generated when tokens are inherited by new processes */ };
624 PSID alias_admins_sid;
625 PSID alias_users_sid;
626 PSID logon_sid;
627 const SID *user_sid = security_unix_uid_to_sid( getuid() );
628 ACL *default_dacl = create_default_dacl( user_sid );
630 alias_admins_sid = security_sid_alloc( &nt_authority, sizeof(alias_admins_subauth)/sizeof(alias_admins_subauth[0]),
631 alias_admins_subauth );
632 alias_users_sid = security_sid_alloc( &nt_authority, sizeof(alias_users_subauth)/sizeof(alias_users_subauth[0]),
633 alias_users_subauth );
634 logon_sid = security_sid_alloc( &nt_authority, sizeof(logon_subauth)/sizeof(logon_subauth[0]),
635 logon_subauth );
637 if (alias_admins_sid && alias_users_sid && logon_sid && default_dacl)
639 const LUID_AND_ATTRIBUTES admin_privs[] =
641 { SeChangeNotifyPrivilege , SE_PRIVILEGE_ENABLED },
642 { SeSecurityPrivilege , 0 },
643 { SeBackupPrivilege , 0 },
644 { SeRestorePrivilege , 0 },
645 { SeSystemtimePrivilege , 0 },
646 { SeShutdownPrivilege , 0 },
647 { SeRemoteShutdownPrivilege , 0 },
648 { SeTakeOwnershipPrivilege , 0 },
649 { SeDebugPrivilege , 0 },
650 { SeSystemEnvironmentPrivilege , 0 },
651 { SeSystemProfilePrivilege , 0 },
652 { SeProfileSingleProcessPrivilege, 0 },
653 { SeIncreaseBasePriorityPrivilege, 0 },
654 { SeLoadDriverPrivilege , SE_PRIVILEGE_ENABLED },
655 { SeCreatePagefilePrivilege , 0 },
656 { SeIncreaseQuotaPrivilege , 0 },
657 { SeUndockPrivilege , 0 },
658 { SeManageVolumePrivilege , 0 },
659 { SeImpersonatePrivilege , SE_PRIVILEGE_ENABLED },
660 { SeCreateGlobalPrivilege , SE_PRIVILEGE_ENABLED },
662 /* note: we don't include non-builtin groups here for the user -
663 * telling us these is the job of a client-side program */
664 const SID_AND_ATTRIBUTES admin_groups[] =
666 { security_world_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY },
667 { security_local_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY },
668 { security_interactive_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY },
669 { security_authenticated_user_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY },
670 { alias_admins_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY|SE_GROUP_OWNER },
671 { alias_users_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY },
672 { logon_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY|SE_GROUP_LOGON_ID },
674 static const TOKEN_SOURCE admin_source = {"SeMgr", {0, 0}};
675 token = create_token( TRUE, user_sid, admin_groups, sizeof(admin_groups)/sizeof(admin_groups[0]),
676 admin_privs, sizeof(admin_privs)/sizeof(admin_privs[0]), default_dacl,
677 admin_source, NULL, -1 );
678 /* we really need a primary group */
679 assert( token->primary_group );
682 free( logon_sid );
683 free( alias_admins_sid );
684 free( alias_users_sid );
685 free( default_dacl );
687 return token;
690 static struct privilege *token_find_privilege( struct token *token, const LUID *luid, int enabled_only )
692 struct privilege *privilege;
693 LIST_FOR_EACH_ENTRY( privilege, &token->privileges, struct privilege, entry )
695 if (is_equal_luid( luid, &privilege->luid ))
697 if (enabled_only && !privilege->enabled)
698 return NULL;
699 return privilege;
702 return NULL;
705 static unsigned int token_adjust_privileges( struct token *token, const LUID_AND_ATTRIBUTES *privs,
706 unsigned int count, LUID_AND_ATTRIBUTES *mod_privs,
707 unsigned int mod_privs_count )
709 unsigned int i, modified_count = 0;
711 /* mark as modified */
712 allocate_luid( &token->modified_id );
714 for (i = 0; i < count; i++)
716 struct privilege *privilege =
717 token_find_privilege( token, &privs[i].Luid, FALSE );
718 if (!privilege)
720 set_error( STATUS_NOT_ALL_ASSIGNED );
721 continue;
724 if (privs[i].Attributes & SE_PRIVILEGE_REMOVED)
725 privilege_remove( privilege );
726 else
728 /* save previous state for caller */
729 if (mod_privs_count)
731 luid_and_attr_from_privilege(mod_privs, privilege);
732 mod_privs++;
733 mod_privs_count--;
734 modified_count++;
737 if (privs[i].Attributes & SE_PRIVILEGE_ENABLED)
738 privilege->enabled = TRUE;
739 else
740 privilege->enabled = FALSE;
743 return modified_count;
746 static void token_disable_privileges( struct token *token )
748 struct privilege *privilege;
750 /* mark as modified */
751 allocate_luid( &token->modified_id );
753 LIST_FOR_EACH_ENTRY( privilege, &token->privileges, struct privilege, entry )
754 privilege->enabled = FALSE;
757 int token_check_privileges( struct token *token, int all_required,
758 const LUID_AND_ATTRIBUTES *reqprivs,
759 unsigned int count, LUID_AND_ATTRIBUTES *usedprivs)
761 unsigned int i, enabled_count = 0;
763 for (i = 0; i < count; i++)
765 struct privilege *privilege =
766 token_find_privilege( token, &reqprivs[i].Luid, TRUE );
768 if (usedprivs)
769 usedprivs[i] = reqprivs[i];
771 if (privilege && privilege->enabled)
773 enabled_count++;
774 if (usedprivs)
775 usedprivs[i].Attributes |= SE_PRIVILEGE_USED_FOR_ACCESS;
779 if (all_required)
780 return (enabled_count == count);
781 else
782 return (enabled_count > 0);
785 int token_sid_present( struct token *token, const SID *sid, int deny )
787 struct group *group;
789 if (security_equal_sid( token->user, sid )) return TRUE;
791 LIST_FOR_EACH_ENTRY( group, &token->groups, struct group, entry )
793 if (!group->enabled) continue;
794 if (group->deny_only && !deny) continue;
796 if (security_equal_sid( &group->sid, sid )) return TRUE;
799 return FALSE;
802 /* Checks access to a security descriptor. 'sd' must have been validated by
803 * caller. It returns STATUS_SUCCESS if call succeeded or an error indicating
804 * the reason. 'status' parameter will indicate if access is granted or denied.
806 * If both returned value and 'status' are STATUS_SUCCESS then access is granted.
808 static unsigned int token_access_check( struct token *token,
809 const struct security_descriptor *sd,
810 unsigned int desired_access,
811 LUID_AND_ATTRIBUTES *privs,
812 unsigned int *priv_count,
813 const GENERIC_MAPPING *mapping,
814 unsigned int *granted_access,
815 unsigned int *status )
817 unsigned int current_access = 0;
818 unsigned int denied_access = 0;
819 ULONG i;
820 const ACL *dacl;
821 int dacl_present;
822 const ACE_HEADER *ace;
823 const SID *owner;
825 /* assume no access rights */
826 *granted_access = 0;
828 /* fail if desired_access contains generic rights */
829 if (desired_access & (GENERIC_READ|GENERIC_WRITE|GENERIC_EXECUTE|GENERIC_ALL))
831 if (priv_count) *priv_count = 0;
832 return STATUS_GENERIC_NOT_MAPPED;
835 dacl = sd_get_dacl( sd, &dacl_present );
836 owner = sd_get_owner( sd );
837 if (!owner || !sd_get_group( sd ))
839 if (priv_count) *priv_count = 0;
840 return STATUS_INVALID_SECURITY_DESCR;
843 /* 1: Grant desired access if the object is unprotected */
844 if (!dacl_present || !dacl)
846 if (priv_count) *priv_count = 0;
847 if (desired_access & MAXIMUM_ALLOWED)
848 *granted_access = mapping->GenericAll;
849 else
850 *granted_access = desired_access;
851 return *status = STATUS_SUCCESS;
854 /* 2: Check if caller wants access to system security part. Note: access
855 * is only granted if specifically asked for */
856 if (desired_access & ACCESS_SYSTEM_SECURITY)
858 const LUID_AND_ATTRIBUTES security_priv = { SeSecurityPrivilege, 0 };
859 LUID_AND_ATTRIBUTES retpriv = security_priv;
860 if (token_check_privileges( token, TRUE, &security_priv, 1, &retpriv ))
862 if (priv_count)
864 /* assumes that there will only be one privilege to return */
865 if (*priv_count >= 1)
867 *priv_count = 1;
868 *privs = retpriv;
870 else
872 *priv_count = 1;
873 return STATUS_BUFFER_TOO_SMALL;
876 current_access |= ACCESS_SYSTEM_SECURITY;
877 if (desired_access == current_access)
879 *granted_access = current_access;
880 return *status = STATUS_SUCCESS;
883 else
885 if (priv_count) *priv_count = 0;
886 *status = STATUS_PRIVILEGE_NOT_HELD;
887 return STATUS_SUCCESS;
890 else if (priv_count) *priv_count = 0;
892 /* 3: Check whether the token is the owner */
893 /* NOTE: SeTakeOwnershipPrivilege is not checked for here - it is instead
894 * checked when a "set owner" call is made, overriding the access rights
895 * determined here. */
896 if (token_sid_present( token, owner, FALSE ))
898 current_access |= (READ_CONTROL | WRITE_DAC);
899 if (desired_access == current_access)
901 *granted_access = current_access;
902 return *status = STATUS_SUCCESS;
906 /* 4: Grant rights according to the DACL */
907 ace = (const ACE_HEADER *)(dacl + 1);
908 for (i = 0; i < dacl->AceCount; i++, ace = ace_next( ace ))
910 const ACCESS_ALLOWED_ACE *aa_ace;
911 const ACCESS_DENIED_ACE *ad_ace;
912 const SID *sid;
914 if (ace->AceFlags & INHERIT_ONLY_ACE)
915 continue;
917 switch (ace->AceType)
919 case ACCESS_DENIED_ACE_TYPE:
920 ad_ace = (const ACCESS_DENIED_ACE *)ace;
921 sid = (const SID *)&ad_ace->SidStart;
922 if (token_sid_present( token, sid, TRUE ))
924 unsigned int access = ad_ace->Mask;
925 map_generic_mask(&access, mapping);
926 if (desired_access & MAXIMUM_ALLOWED)
927 denied_access |= access;
928 else
930 denied_access |= (access & ~current_access);
931 if (desired_access & access) goto done;
934 break;
935 case ACCESS_ALLOWED_ACE_TYPE:
936 aa_ace = (const ACCESS_ALLOWED_ACE *)ace;
937 sid = (const SID *)&aa_ace->SidStart;
938 if (token_sid_present( token, sid, FALSE ))
940 unsigned int access = aa_ace->Mask;
941 map_generic_mask(&access, mapping);
942 if (desired_access & MAXIMUM_ALLOWED)
943 current_access |= access;
944 else
945 current_access |= (access & ~denied_access);
947 break;
950 /* don't bother carrying on checking if we've already got all of
951 * rights we need */
952 if (desired_access == *granted_access)
953 break;
956 done:
957 if (desired_access & MAXIMUM_ALLOWED)
958 *granted_access = current_access & ~denied_access;
959 else
960 if ((current_access & desired_access) == desired_access)
961 *granted_access = current_access & desired_access;
962 else
963 *granted_access = 0;
965 *status = *granted_access ? STATUS_SUCCESS : STATUS_ACCESS_DENIED;
966 return STATUS_SUCCESS;
969 const ACL *token_get_default_dacl( struct token *token )
971 return token->default_dacl;
974 const SID *token_get_user( struct token *token )
976 return token->user;
979 const SID *token_get_primary_group( struct token *token )
981 return token->primary_group;
984 int check_object_access(struct object *obj, unsigned int *access)
986 GENERIC_MAPPING mapping;
987 struct token *token = current->token ? current->token : current->process->token;
988 unsigned int status;
989 int res;
991 mapping.GenericAll = obj->ops->map_access( obj, GENERIC_ALL );
993 if (!obj->sd)
995 if (*access & MAXIMUM_ALLOWED)
996 *access = mapping.GenericAll;
997 return TRUE;
1000 mapping.GenericRead = obj->ops->map_access( obj, GENERIC_READ );
1001 mapping.GenericWrite = obj->ops->map_access( obj, GENERIC_WRITE );
1002 mapping.GenericExecute = obj->ops->map_access( obj, GENERIC_EXECUTE );
1004 res = token_access_check( token, obj->sd, *access, NULL, NULL,
1005 &mapping, access, &status ) == STATUS_SUCCESS &&
1006 status == STATUS_SUCCESS;
1008 if (!res) set_error( STATUS_ACCESS_DENIED );
1009 return res;
1013 /* open a security token */
1014 DECL_HANDLER(open_token)
1016 if (req->flags & OPEN_TOKEN_THREAD)
1018 struct thread *thread = get_thread_from_handle( req->handle, 0 );
1019 if (thread)
1021 if (thread->token)
1023 if (!thread->token->primary && thread->token->impersonation_level <= SecurityAnonymous)
1024 set_error( STATUS_CANT_OPEN_ANONYMOUS );
1025 else
1026 reply->token = alloc_handle( current->process, thread->token,
1027 req->access, req->attributes );
1029 else
1030 set_error( STATUS_NO_TOKEN );
1031 release_object( thread );
1034 else
1036 struct process *process = get_process_from_handle( req->handle, 0 );
1037 if (process)
1039 if (process->token)
1040 reply->token = alloc_handle( current->process, process->token, req->access,
1041 req->attributes );
1042 else
1043 set_error( STATUS_NO_TOKEN );
1044 release_object( process );
1049 /* adjust the privileges held by a token */
1050 DECL_HANDLER(adjust_token_privileges)
1052 struct token *token;
1053 unsigned int access = TOKEN_ADJUST_PRIVILEGES;
1055 if (req->get_modified_state) access |= TOKEN_QUERY;
1057 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1058 access, &token_ops )))
1060 const LUID_AND_ATTRIBUTES *privs = get_req_data();
1061 LUID_AND_ATTRIBUTES *modified_privs = NULL;
1062 unsigned int priv_count = get_req_data_size() / sizeof(LUID_AND_ATTRIBUTES);
1063 unsigned int modified_priv_count = 0;
1065 if (req->get_modified_state && !req->disable_all)
1067 unsigned int i;
1068 /* count modified privs */
1069 for (i = 0; i < priv_count; i++)
1071 struct privilege *privilege =
1072 token_find_privilege( token, &privs[i].Luid, FALSE );
1073 if (privilege && req->get_modified_state)
1074 modified_priv_count++;
1076 reply->len = modified_priv_count;
1077 modified_priv_count = min( modified_priv_count, get_reply_max_size() / sizeof(*modified_privs) );
1078 if (modified_priv_count)
1079 modified_privs = set_reply_data_size( modified_priv_count * sizeof(*modified_privs) );
1081 reply->len = modified_priv_count * sizeof(*modified_privs);
1083 if (req->disable_all)
1084 token_disable_privileges( token );
1085 else
1086 token_adjust_privileges( token, privs, priv_count, modified_privs, modified_priv_count );
1088 release_object( token );
1092 /* retrieves the list of privileges that may be held be the token */
1093 DECL_HANDLER(get_token_privileges)
1095 struct token *token;
1097 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1098 TOKEN_QUERY,
1099 &token_ops )))
1101 int priv_count = 0;
1102 LUID_AND_ATTRIBUTES *privs;
1103 struct privilege *privilege;
1105 LIST_FOR_EACH_ENTRY( privilege, &token->privileges, struct privilege, entry )
1106 priv_count++;
1108 reply->len = priv_count * sizeof(*privs);
1109 if (reply->len <= get_reply_max_size())
1111 privs = set_reply_data_size( priv_count * sizeof(*privs) );
1112 if (privs)
1114 int i = 0;
1115 LIST_FOR_EACH_ENTRY( privilege, &token->privileges, struct privilege, entry )
1117 luid_and_attr_from_privilege( &privs[i], privilege );
1118 i++;
1122 else
1123 set_error(STATUS_BUFFER_TOO_SMALL);
1125 release_object( token );
1129 /* creates a duplicate of the token */
1130 DECL_HANDLER(duplicate_token)
1132 struct token *src_token;
1134 if ((src_token = (struct token *)get_handle_obj( current->process, req->handle,
1135 TOKEN_DUPLICATE,
1136 &token_ops )))
1138 struct token *token = token_duplicate( src_token, req->primary, req->impersonation_level );
1139 if (token)
1141 reply->new_handle = alloc_handle( current->process, token, req->access, req->attributes);
1142 release_object( token );
1144 release_object( src_token );
1148 /* checks the specified privileges are held by the token */
1149 DECL_HANDLER(check_token_privileges)
1151 struct token *token;
1153 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1154 TOKEN_QUERY,
1155 &token_ops )))
1157 unsigned int count = get_req_data_size() / sizeof(LUID_AND_ATTRIBUTES);
1159 if (!token->primary && token->impersonation_level <= SecurityAnonymous)
1160 set_error( STATUS_BAD_IMPERSONATION_LEVEL );
1161 else if (get_reply_max_size() >= count * sizeof(LUID_AND_ATTRIBUTES))
1163 LUID_AND_ATTRIBUTES *usedprivs = set_reply_data_size( count * sizeof(*usedprivs) );
1164 reply->has_privileges = token_check_privileges( token, req->all_required, get_req_data(), count, usedprivs );
1166 else
1167 set_error( STATUS_BUFFER_OVERFLOW );
1168 release_object( token );
1172 /* checks that a user represented by a token is allowed to access an object
1173 * represented by a security descriptor */
1174 DECL_HANDLER(access_check)
1176 data_size_t sd_size = get_req_data_size();
1177 const struct security_descriptor *sd = get_req_data();
1178 struct token *token;
1180 if (!sd_is_valid( sd, sd_size ))
1182 set_error( STATUS_ACCESS_VIOLATION );
1183 return;
1186 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1187 TOKEN_QUERY,
1188 &token_ops )))
1190 GENERIC_MAPPING mapping;
1191 unsigned int status;
1192 LUID_AND_ATTRIBUTES priv;
1193 unsigned int priv_count = 1;
1195 memset(&priv, 0, sizeof(priv));
1197 /* only impersonation tokens may be used with this function */
1198 if (token->primary)
1200 set_error( STATUS_NO_IMPERSONATION_TOKEN );
1201 release_object( token );
1202 return;
1204 /* anonymous impersonation tokens can't be used */
1205 if (token->impersonation_level <= SecurityAnonymous)
1207 set_error( STATUS_BAD_IMPERSONATION_LEVEL );
1208 release_object( token );
1209 return;
1212 mapping.GenericRead = req->mapping_read;
1213 mapping.GenericWrite = req->mapping_write;
1214 mapping.GenericExecute = req->mapping_execute;
1215 mapping.GenericAll = req->mapping_all;
1217 status = token_access_check(
1218 token, sd, req->desired_access, &priv, &priv_count, &mapping,
1219 &reply->access_granted, &reply->access_status );
1221 reply->privileges_len = priv_count*sizeof(LUID_AND_ATTRIBUTES);
1223 if ((priv_count > 0) && (reply->privileges_len <= get_reply_max_size()))
1225 LUID_AND_ATTRIBUTES *privs = set_reply_data_size( priv_count * sizeof(*privs) );
1226 memcpy( privs, &priv, sizeof(priv) );
1229 set_error( status );
1230 release_object( token );
1234 /* retrieves the SID of the user that the token represents */
1235 DECL_HANDLER(get_token_sid)
1237 struct token *token;
1239 reply->sid_len = 0;
1241 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1242 TOKEN_QUERY,
1243 &token_ops )))
1245 const SID *sid = NULL;
1247 switch (req->which_sid)
1249 case TokenUser:
1250 assert(token->user);
1251 sid = token->user;
1252 break;
1253 case TokenPrimaryGroup:
1254 sid = token->primary_group;
1255 break;
1256 case TokenOwner:
1258 struct group *group;
1259 LIST_FOR_EACH_ENTRY( group, &token->groups, struct group, entry )
1261 if (group->owner)
1263 sid = &group->sid;
1264 break;
1267 break;
1269 default:
1270 set_error( STATUS_INVALID_PARAMETER );
1271 break;
1274 if (sid)
1276 reply->sid_len = security_sid_len( sid );
1277 if (reply->sid_len <= get_reply_max_size()) set_reply_data( sid, reply->sid_len );
1278 else set_error( STATUS_BUFFER_TOO_SMALL );
1280 release_object( token );
1284 /* retrieves the groups that the user represented by the token belongs to */
1285 DECL_HANDLER(get_token_groups)
1287 struct token *token;
1289 reply->user_len = 0;
1291 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1292 TOKEN_QUERY,
1293 &token_ops )))
1295 size_t size_needed = sizeof(struct token_groups);
1296 size_t sid_size = 0;
1297 unsigned int group_count = 0;
1298 const struct group *group;
1300 LIST_FOR_EACH_ENTRY( group, &token->groups, const struct group, entry )
1302 group_count++;
1303 sid_size += security_sid_len( &group->sid );
1305 size_needed += sid_size;
1306 /* attributes size */
1307 size_needed += sizeof(unsigned int) * group_count;
1309 /* reply buffer contains size_needed bytes formatted as:
1311 unsigned int count;
1312 unsigned int attrib[count];
1313 char sid_data[];
1315 user_len includes extra data needed for TOKEN_GROUPS representation,
1316 required caller buffer size calculated here to avoid extra server call */
1317 reply->user_len = FIELD_OFFSET( TOKEN_GROUPS, Groups[group_count] ) + sid_size;
1319 if (reply->user_len <= get_reply_max_size())
1321 struct token_groups *tg = set_reply_data_size( size_needed );
1322 if (tg)
1324 unsigned int *attr_ptr = (unsigned int *)(tg + 1);
1325 SID *sid_ptr = (SID *)(attr_ptr + group_count);
1327 tg->count = group_count;
1329 LIST_FOR_EACH_ENTRY( group, &token->groups, const struct group, entry )
1332 *attr_ptr = 0;
1333 if (group->mandatory) *attr_ptr |= SE_GROUP_MANDATORY;
1334 if (group->def) *attr_ptr |= SE_GROUP_ENABLED_BY_DEFAULT;
1335 if (group->enabled) *attr_ptr |= SE_GROUP_ENABLED;
1336 if (group->owner) *attr_ptr |= SE_GROUP_OWNER;
1337 if (group->deny_only) *attr_ptr |= SE_GROUP_USE_FOR_DENY_ONLY;
1338 if (group->resource) *attr_ptr |= SE_GROUP_RESOURCE;
1339 if (group->logon) *attr_ptr |= SE_GROUP_LOGON_ID;
1341 memcpy(sid_ptr, &group->sid, security_sid_len( &group->sid ));
1343 sid_ptr = (SID *)((char *)sid_ptr + security_sid_len( &group->sid ));
1344 attr_ptr++;
1348 else set_error( STATUS_BUFFER_TOO_SMALL );
1350 release_object( token );
1354 DECL_HANDLER(get_token_impersonation_level)
1356 struct token *token;
1358 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1359 TOKEN_QUERY,
1360 &token_ops )))
1362 if (token->primary)
1363 set_error( STATUS_INVALID_PARAMETER );
1364 else
1365 reply->impersonation_level = token->impersonation_level;
1367 release_object( token );
1371 DECL_HANDLER(get_token_statistics)
1373 struct token *token;
1375 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1376 TOKEN_QUERY,
1377 &token_ops )))
1379 reply->token_id = token->token_id;
1380 reply->modified_id = token->modified_id;
1381 reply->primary = token->primary;
1382 reply->impersonation_level = token->impersonation_level;
1383 reply->group_count = list_count( &token->groups );
1384 reply->privilege_count = list_count( &token->privileges );
1386 release_object( token );
1390 DECL_HANDLER(get_token_default_dacl)
1392 struct token *token;
1394 reply->acl_len = 0;
1396 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1397 TOKEN_QUERY,
1398 &token_ops )))
1400 if (token->default_dacl)
1401 reply->acl_len = token->default_dacl->AclSize;
1403 if (reply->acl_len <= get_reply_max_size())
1405 ACL *acl_reply = set_reply_data_size( reply->acl_len );
1406 if (acl_reply)
1407 memcpy( acl_reply, token->default_dacl, reply->acl_len );
1409 else set_error( STATUS_BUFFER_TOO_SMALL );
1411 release_object( token );
1415 DECL_HANDLER(set_token_default_dacl)
1417 struct token *token;
1419 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1420 TOKEN_ADJUST_DEFAULT,
1421 &token_ops )))
1423 const ACL *acl = get_req_data();
1424 unsigned int acl_size = get_req_data_size();
1426 free( token->default_dacl );
1427 token->default_dacl = NULL;
1429 if (acl_size)
1430 token->default_dacl = memdup( acl, acl_size );
1432 release_object( token );