dwrite: Handle allocation error (Coverity).
[wine/multimedia.git] / server / token.c
blobb66a6032b0ad4c07df4262151267c88bcce1b329
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 } };
81 const PSID security_world_sid = (PSID)&world_sid;
82 static const PSID security_local_sid = (PSID)&local_sid;
83 static const PSID security_interactive_sid = (PSID)&interactive_sid;
84 static const PSID security_authenticated_user_sid = (PSID)&authenticated_user_sid;
85 const PSID security_local_system_sid = (PSID)&local_system_sid;
86 const PSID security_local_user_sid = (PSID)&local_user_sid;
88 static luid_t prev_luid_value = { 1000, 0 };
90 struct token
92 struct object obj; /* object header */
93 luid_t token_id; /* system-unique id of token */
94 luid_t modified_id; /* new id allocated every time token is modified */
95 struct list privileges; /* privileges available to the token */
96 struct list groups; /* groups that the user of this token belongs to (sid_and_attributes) */
97 SID *user; /* SID of user this token represents */
98 SID *primary_group; /* SID of user's primary group */
99 unsigned primary; /* is this a primary or impersonation token? */
100 ACL *default_dacl; /* the default DACL to assign to objects created by this user */
101 TOKEN_SOURCE source; /* source of the token */
102 int impersonation_level; /* impersonation level this token is capable of if non-primary token */
105 struct privilege
107 struct list entry;
108 LUID luid;
109 unsigned enabled : 1; /* is the privilege currently enabled? */
110 unsigned def : 1; /* is the privilege enabled by default? */
113 struct group
115 struct list entry;
116 unsigned enabled : 1; /* is the sid currently enabled? */
117 unsigned def : 1; /* is the sid enabled by default? */
118 unsigned logon : 1; /* is this a logon sid? */
119 unsigned mandatory: 1; /* is this sid always enabled? */
120 unsigned owner : 1; /* can this sid be an owner of an object? */
121 unsigned resource : 1; /* is this a domain-local group? */
122 unsigned deny_only: 1; /* is this a sid that should be use for denying only? */
123 SID sid;
126 static void token_dump( struct object *obj, int verbose );
127 static unsigned int token_map_access( struct object *obj, unsigned int access );
128 static void token_destroy( struct object *obj );
130 static const struct object_ops token_ops =
132 sizeof(struct token), /* size */
133 token_dump, /* dump */
134 no_get_type, /* get_type */
135 no_add_queue, /* add_queue */
136 NULL, /* remove_queue */
137 NULL, /* signaled */
138 NULL, /* satisfied */
139 no_signal, /* signal */
140 no_get_fd, /* get_fd */
141 token_map_access, /* map_access */
142 default_get_sd, /* get_sd */
143 default_set_sd, /* set_sd */
144 no_lookup_name, /* lookup_name */
145 no_open_file, /* open_file */
146 no_close_handle, /* close_handle */
147 token_destroy /* destroy */
151 static void token_dump( struct object *obj, int verbose )
153 fprintf( stderr, "Security token\n" );
154 /* FIXME: dump token members */
157 static unsigned int token_map_access( struct object *obj, unsigned int access )
159 if (access & GENERIC_READ) access |= TOKEN_READ;
160 if (access & GENERIC_WRITE) access |= TOKEN_WRITE;
161 if (access & GENERIC_EXECUTE) access |= STANDARD_RIGHTS_EXECUTE;
162 if (access & GENERIC_ALL) access |= TOKEN_ALL_ACCESS;
163 return access & ~(GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | GENERIC_ALL);
166 static SID *security_sid_alloc( const SID_IDENTIFIER_AUTHORITY *idauthority, int subauthcount, const unsigned int subauth[] )
168 int i;
169 SID *sid = mem_alloc( FIELD_OFFSET(SID, SubAuthority[subauthcount]) );
170 if (!sid) return NULL;
171 sid->Revision = SID_REVISION;
172 sid->SubAuthorityCount = subauthcount;
173 sid->IdentifierAuthority = *idauthority;
174 for (i = 0; i < subauthcount; i++)
175 sid->SubAuthority[i] = subauth[i];
176 return sid;
179 void security_set_thread_token( struct thread *thread, obj_handle_t handle )
181 if (!handle)
183 if (thread->token)
184 release_object( thread->token );
185 thread->token = NULL;
187 else
189 struct token *token = (struct token *)get_handle_obj( current->process,
190 handle,
191 TOKEN_IMPERSONATE,
192 &token_ops );
193 if (token)
195 if (thread->token)
196 release_object( thread->token );
197 thread->token = token;
202 const SID *security_unix_uid_to_sid( uid_t uid )
204 /* very simple mapping: either the current user or not the current user */
205 if (uid == getuid())
206 return (const SID *)&local_user_sid;
207 else
208 return &anonymous_logon_sid;
211 static int acl_is_valid( const ACL *acl, data_size_t size )
213 ULONG i;
214 const ACE_HEADER *ace;
216 if (size < sizeof(ACL))
217 return FALSE;
219 size = min(size, MAX_ACL_LEN);
221 size -= sizeof(ACL);
223 ace = (const ACE_HEADER *)(acl + 1);
224 for (i = 0; i < acl->AceCount; i++)
226 const SID *sid;
227 data_size_t sid_size;
229 if (size < sizeof(ACE_HEADER))
230 return FALSE;
231 if (size < ace->AceSize)
232 return FALSE;
233 size -= ace->AceSize;
234 switch (ace->AceType)
236 case ACCESS_DENIED_ACE_TYPE:
237 sid = (const SID *)&((const ACCESS_DENIED_ACE *)ace)->SidStart;
238 sid_size = ace->AceSize - FIELD_OFFSET(ACCESS_DENIED_ACE, SidStart);
239 break;
240 case ACCESS_ALLOWED_ACE_TYPE:
241 sid = (const SID *)&((const ACCESS_ALLOWED_ACE *)ace)->SidStart;
242 sid_size = ace->AceSize - FIELD_OFFSET(ACCESS_ALLOWED_ACE, SidStart);
243 break;
244 case SYSTEM_AUDIT_ACE_TYPE:
245 sid = (const SID *)&((const SYSTEM_AUDIT_ACE *)ace)->SidStart;
246 sid_size = ace->AceSize - FIELD_OFFSET(SYSTEM_AUDIT_ACE, SidStart);
247 break;
248 case SYSTEM_ALARM_ACE_TYPE:
249 sid = (const SID *)&((const SYSTEM_ALARM_ACE *)ace)->SidStart;
250 sid_size = ace->AceSize - FIELD_OFFSET(SYSTEM_ALARM_ACE, SidStart);
251 break;
252 default:
253 return FALSE;
255 if (sid_size < FIELD_OFFSET(SID, SubAuthority[0]) ||
256 sid_size < FIELD_OFFSET(SID, SubAuthority[sid->SubAuthorityCount]))
257 return FALSE;
258 ace = ace_next( ace );
260 return TRUE;
263 /* checks whether all members of a security descriptor fit inside the size
264 * of memory specified */
265 int sd_is_valid( const struct security_descriptor *sd, data_size_t size )
267 size_t offset = sizeof(struct security_descriptor);
268 const SID *group;
269 const SID *owner;
270 const ACL *sacl;
271 const ACL *dacl;
272 int dummy;
274 if (size < offset)
275 return FALSE;
277 if ((sd->owner_len >= FIELD_OFFSET(SID, SubAuthority[255])) ||
278 (offset + sd->owner_len > size))
279 return FALSE;
280 owner = sd_get_owner( sd );
281 if (owner)
283 size_t needed_size = FIELD_OFFSET(SID, SubAuthority[owner->SubAuthorityCount]);
284 if ((sd->owner_len < sizeof(SID)) || (needed_size > sd->owner_len))
285 return FALSE;
287 offset += sd->owner_len;
289 if ((sd->group_len >= FIELD_OFFSET(SID, SubAuthority[255])) ||
290 (offset + sd->group_len > size))
291 return FALSE;
292 group = sd_get_group( sd );
293 if (group)
295 size_t needed_size = FIELD_OFFSET(SID, SubAuthority[group->SubAuthorityCount]);
296 if ((sd->group_len < sizeof(SID)) || (needed_size > sd->group_len))
297 return FALSE;
299 offset += sd->group_len;
301 if ((sd->sacl_len >= MAX_ACL_LEN) || (offset + sd->sacl_len > size))
302 return FALSE;
303 sacl = sd_get_sacl( sd, &dummy );
304 if (sacl && !acl_is_valid( sacl, sd->sacl_len ))
305 return FALSE;
306 offset += sd->sacl_len;
308 if ((sd->dacl_len >= MAX_ACL_LEN) || (offset + sd->dacl_len > size))
309 return FALSE;
310 dacl = sd_get_dacl( sd, &dummy );
311 if (dacl && !acl_is_valid( dacl, sd->dacl_len ))
312 return FALSE;
313 offset += sd->dacl_len;
315 return TRUE;
318 /* determines whether an object_attributes struct is valid in a buffer
319 * and calls set_error appropriately */
320 int objattr_is_valid( const struct object_attributes *objattr, data_size_t size )
322 if ((size < sizeof(*objattr)) || (size - sizeof(*objattr) < objattr->sd_len) ||
323 (size - sizeof(*objattr) - objattr->sd_len < objattr->name_len))
325 set_error( STATUS_ACCESS_VIOLATION );
326 return FALSE;
329 if (objattr->sd_len)
331 const struct security_descriptor *sd = (const struct security_descriptor *)(objattr + 1);
332 if (!sd_is_valid( sd, objattr->sd_len ))
334 set_error( STATUS_INVALID_SECURITY_DESCR );
335 return FALSE;
339 return TRUE;
342 /* maps from generic rights to specific rights as given by a mapping */
343 static inline void map_generic_mask(unsigned int *mask, const GENERIC_MAPPING *mapping)
345 if (*mask & GENERIC_READ) *mask |= mapping->GenericRead;
346 if (*mask & GENERIC_WRITE) *mask |= mapping->GenericWrite;
347 if (*mask & GENERIC_EXECUTE) *mask |= mapping->GenericExecute;
348 if (*mask & GENERIC_ALL) *mask |= mapping->GenericAll;
349 *mask &= 0x0FFFFFFF;
352 static inline int is_equal_luid( const LUID *luid1, const LUID *luid2 )
354 return (luid1->LowPart == luid2->LowPart && luid1->HighPart == luid2->HighPart);
357 static inline void allocate_luid( luid_t *luid )
359 prev_luid_value.low_part++;
360 *luid = prev_luid_value;
363 DECL_HANDLER( allocate_locally_unique_id )
365 allocate_luid( &reply->luid );
368 static inline void luid_and_attr_from_privilege( LUID_AND_ATTRIBUTES *out, const struct privilege *in)
370 out->Luid = in->luid;
371 out->Attributes =
372 (in->enabled ? SE_PRIVILEGE_ENABLED : 0) |
373 (in->def ? SE_PRIVILEGE_ENABLED_BY_DEFAULT : 0);
376 static struct privilege *privilege_add( struct token *token, const LUID *luid, int enabled )
378 struct privilege *privilege = mem_alloc( sizeof(*privilege) );
379 if (privilege)
381 privilege->luid = *luid;
382 privilege->def = privilege->enabled = (enabled != 0);
383 list_add_tail( &token->privileges, &privilege->entry );
385 return privilege;
388 static inline void privilege_remove( struct privilege *privilege )
390 list_remove( &privilege->entry );
391 free( privilege );
394 static void token_destroy( struct object *obj )
396 struct token* token;
397 struct list *cursor, *cursor_next;
399 assert( obj->ops == &token_ops );
400 token = (struct token *)obj;
402 free( token->user );
404 LIST_FOR_EACH_SAFE( cursor, cursor_next, &token->privileges )
406 struct privilege *privilege = LIST_ENTRY( cursor, struct privilege, entry );
407 privilege_remove( privilege );
410 LIST_FOR_EACH_SAFE( cursor, cursor_next, &token->groups )
412 struct group *group = LIST_ENTRY( cursor, struct group, entry );
413 list_remove( &group->entry );
414 free( group );
417 free( token->default_dacl );
420 /* creates a new token.
421 * groups may be NULL if group_count is 0.
422 * privs may be NULL if priv_count is 0.
423 * default_dacl may be NULL, indicating that all objects created by the user
424 * are unsecured.
425 * modified_id may be NULL, indicating that a new modified_id luid should be
426 * allocated.
428 static struct token *create_token( unsigned primary, const SID *user,
429 const SID_AND_ATTRIBUTES *groups, unsigned int group_count,
430 const LUID_AND_ATTRIBUTES *privs, unsigned int priv_count,
431 const ACL *default_dacl, TOKEN_SOURCE source,
432 const luid_t *modified_id,
433 int impersonation_level )
435 struct token *token = alloc_object( &token_ops );
436 if (token)
438 unsigned int i;
440 allocate_luid( &token->token_id );
441 if (modified_id)
442 token->modified_id = *modified_id;
443 else
444 allocate_luid( &token->modified_id );
445 list_init( &token->privileges );
446 list_init( &token->groups );
447 token->primary = primary;
448 /* primary tokens don't have impersonation levels */
449 if (primary)
450 token->impersonation_level = -1;
451 else
452 token->impersonation_level = impersonation_level;
453 token->default_dacl = NULL;
454 token->primary_group = NULL;
456 /* copy user */
457 token->user = memdup( user, FIELD_OFFSET(SID, SubAuthority[user->SubAuthorityCount]) );
458 if (!token->user)
460 release_object( token );
461 return NULL;
464 /* copy groups */
465 for (i = 0; i < group_count; i++)
467 size_t size = FIELD_OFFSET( struct group, sid.SubAuthority[((const SID *)groups[i].Sid)->SubAuthorityCount] );
468 struct group *group = mem_alloc( size );
470 if (!group)
472 release_object( token );
473 return NULL;
475 memcpy( &group->sid, groups[i].Sid, FIELD_OFFSET( SID, SubAuthority[((const SID *)groups[i].Sid)->SubAuthorityCount] ) );
476 group->enabled = TRUE;
477 group->def = TRUE;
478 group->logon = (groups[i].Attributes & SE_GROUP_LOGON_ID) != 0;
479 group->mandatory = (groups[i].Attributes & SE_GROUP_MANDATORY) != 0;
480 group->owner = (groups[i].Attributes & SE_GROUP_OWNER) != 0;
481 group->resource = FALSE;
482 group->deny_only = FALSE;
483 list_add_tail( &token->groups, &group->entry );
484 /* Use first owner capable group as an owner */
485 if (!token->primary_group && group->owner)
486 token->primary_group = &group->sid;
489 /* copy privileges */
490 for (i = 0; i < priv_count; i++)
492 /* note: we don't check uniqueness: the caller must make sure
493 * privs doesn't contain any duplicate luids */
494 if (!privilege_add( token, &privs[i].Luid,
495 privs[i].Attributes & SE_PRIVILEGE_ENABLED ))
497 release_object( token );
498 return NULL;
502 if (default_dacl)
504 token->default_dacl = memdup( default_dacl, default_dacl->AclSize );
505 if (!token->default_dacl)
507 release_object( token );
508 return NULL;
512 token->source = source;
514 return token;
517 struct token *token_duplicate( struct token *src_token, unsigned primary,
518 int impersonation_level )
520 const luid_t *modified_id =
521 primary || (impersonation_level == src_token->impersonation_level) ?
522 &src_token->modified_id : NULL;
523 struct token *token = NULL;
524 struct privilege *privilege;
525 struct group *group;
527 if (!primary &&
528 (impersonation_level < SecurityAnonymous ||
529 impersonation_level > SecurityDelegation ||
530 (!src_token->primary && (impersonation_level > src_token->impersonation_level))))
532 set_error( STATUS_BAD_IMPERSONATION_LEVEL );
533 return NULL;
536 token = create_token( primary, src_token->user, NULL, 0,
537 NULL, 0, src_token->default_dacl,
538 src_token->source, modified_id,
539 impersonation_level );
540 if (!token) return token;
542 /* copy groups */
543 LIST_FOR_EACH_ENTRY( group, &src_token->groups, struct group, entry )
545 size_t size = FIELD_OFFSET( struct group, sid.SubAuthority[group->sid.SubAuthorityCount] );
546 struct group *newgroup = mem_alloc( size );
547 if (!newgroup)
549 release_object( token );
550 return NULL;
552 memcpy( newgroup, group, size );
553 list_add_tail( &token->groups, &newgroup->entry );
555 token->primary_group = src_token->primary_group;
556 assert( token->primary_group );
558 /* copy privileges */
559 LIST_FOR_EACH_ENTRY( privilege, &src_token->privileges, struct privilege, entry )
560 if (!privilege_add( token, &privilege->luid, privilege->enabled ))
562 release_object( token );
563 return NULL;
566 return token;
569 static ACL *create_default_dacl( const SID *user )
571 ACCESS_ALLOWED_ACE *aaa;
572 ACL *default_dacl;
573 SID *sid;
574 size_t default_dacl_size = sizeof(ACL) +
575 2*(sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD)) +
576 sizeof(local_system_sid) +
577 FIELD_OFFSET(SID, SubAuthority[user->SubAuthorityCount]);
579 default_dacl = mem_alloc( default_dacl_size );
580 if (!default_dacl) return NULL;
582 default_dacl->AclRevision = ACL_REVISION;
583 default_dacl->Sbz1 = 0;
584 default_dacl->AclSize = default_dacl_size;
585 default_dacl->AceCount = 2;
586 default_dacl->Sbz2 = 0;
588 /* GENERIC_ALL for Local System */
589 aaa = (ACCESS_ALLOWED_ACE *)(default_dacl + 1);
590 aaa->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
591 aaa->Header.AceFlags = 0;
592 aaa->Header.AceSize = (sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD)) +
593 sizeof(local_system_sid);
594 aaa->Mask = GENERIC_ALL;
595 sid = (SID *)&aaa->SidStart;
596 memcpy( sid, &local_system_sid, sizeof(local_system_sid) );
598 /* GENERIC_ALL for specified user */
599 aaa = (ACCESS_ALLOWED_ACE *)((char *)aaa + aaa->Header.AceSize);
600 aaa->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
601 aaa->Header.AceFlags = 0;
602 aaa->Header.AceSize = (sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD)) +
603 FIELD_OFFSET( SID, SubAuthority[user->SubAuthorityCount] );
604 aaa->Mask = GENERIC_ALL;
605 sid = (SID *)&aaa->SidStart;
606 memcpy( sid, user, FIELD_OFFSET(SID, SubAuthority[user->SubAuthorityCount]) );
608 return default_dacl;
611 struct sid_data
613 SID_IDENTIFIER_AUTHORITY idauth;
614 int count;
615 unsigned int subauth[MAX_SUBAUTH_COUNT];
618 struct token *token_create_admin( void )
620 struct token *token = NULL;
621 static const SID_IDENTIFIER_AUTHORITY nt_authority = { SECURITY_NT_AUTHORITY };
622 static const unsigned int alias_admins_subauth[] = { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS };
623 static const unsigned int alias_users_subauth[] = { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_USERS };
624 /* on Windows, this value changes every time the user logs on */
625 static const unsigned int logon_subauth[] = { SECURITY_LOGON_IDS_RID, 0, 1 /* FIXME: should be randomly generated when tokens are inherited by new processes */ };
626 PSID alias_admins_sid;
627 PSID alias_users_sid;
628 PSID logon_sid;
629 /* note: should be the owner specified in the token */
630 ACL *default_dacl = create_default_dacl( &interactive_sid );
632 alias_admins_sid = security_sid_alloc( &nt_authority, sizeof(alias_admins_subauth)/sizeof(alias_admins_subauth[0]),
633 alias_admins_subauth );
634 alias_users_sid = security_sid_alloc( &nt_authority, sizeof(alias_users_subauth)/sizeof(alias_users_subauth[0]),
635 alias_users_subauth );
636 logon_sid = security_sid_alloc( &nt_authority, sizeof(logon_subauth)/sizeof(logon_subauth[0]),
637 logon_subauth );
639 if (alias_admins_sid && alias_users_sid && logon_sid && default_dacl)
641 const LUID_AND_ATTRIBUTES admin_privs[] =
643 { SeChangeNotifyPrivilege , SE_PRIVILEGE_ENABLED },
644 { SeSecurityPrivilege , 0 },
645 { SeBackupPrivilege , 0 },
646 { SeRestorePrivilege , 0 },
647 { SeSystemtimePrivilege , 0 },
648 { SeShutdownPrivilege , 0 },
649 { SeRemoteShutdownPrivilege , 0 },
650 { SeTakeOwnershipPrivilege , 0 },
651 { SeDebugPrivilege , 0 },
652 { SeSystemEnvironmentPrivilege , 0 },
653 { SeSystemProfilePrivilege , 0 },
654 { SeProfileSingleProcessPrivilege, 0 },
655 { SeIncreaseBasePriorityPrivilege, 0 },
656 { SeLoadDriverPrivilege , SE_PRIVILEGE_ENABLED },
657 { SeCreatePagefilePrivilege , 0 },
658 { SeIncreaseQuotaPrivilege , 0 },
659 { SeUndockPrivilege , 0 },
660 { SeManageVolumePrivilege , 0 },
661 { SeImpersonatePrivilege , SE_PRIVILEGE_ENABLED },
662 { SeCreateGlobalPrivilege , SE_PRIVILEGE_ENABLED },
664 /* note: we don't include non-builtin groups here for the user -
665 * telling us these is the job of a client-side program */
666 const SID_AND_ATTRIBUTES admin_groups[] =
668 { security_world_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY },
669 { security_local_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY },
670 { security_interactive_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY },
671 { security_authenticated_user_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY },
672 { alias_admins_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY|SE_GROUP_OWNER },
673 { alias_users_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY },
674 { logon_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY|SE_GROUP_LOGON_ID },
676 static const TOKEN_SOURCE admin_source = {"SeMgr", {0, 0}};
677 token = create_token( TRUE, security_unix_uid_to_sid( getuid() ),
678 admin_groups, sizeof(admin_groups)/sizeof(admin_groups[0]),
679 admin_privs, sizeof(admin_privs)/sizeof(admin_privs[0]),
680 default_dacl, admin_source, NULL, -1 );
681 /* we really need a primary group */
682 assert( token->primary_group );
685 free( logon_sid );
686 free( alias_admins_sid );
687 free( alias_users_sid );
688 free( default_dacl );
690 return token;
693 static struct privilege *token_find_privilege( struct token *token, const LUID *luid, int enabled_only )
695 struct privilege *privilege;
696 LIST_FOR_EACH_ENTRY( privilege, &token->privileges, struct privilege, entry )
698 if (is_equal_luid( luid, &privilege->luid ))
700 if (enabled_only && !privilege->enabled)
701 return NULL;
702 return privilege;
705 return NULL;
708 static unsigned int token_adjust_privileges( struct token *token, const LUID_AND_ATTRIBUTES *privs,
709 unsigned int count, LUID_AND_ATTRIBUTES *mod_privs,
710 unsigned int mod_privs_count )
712 unsigned int i, modified_count = 0;
714 /* mark as modified */
715 allocate_luid( &token->modified_id );
717 for (i = 0; i < count; i++)
719 struct privilege *privilege =
720 token_find_privilege( token, &privs[i].Luid, FALSE );
721 if (!privilege)
723 set_error( STATUS_NOT_ALL_ASSIGNED );
724 continue;
727 if (privs[i].Attributes & SE_PRIVILEGE_REMOVED)
728 privilege_remove( privilege );
729 else
731 /* save previous state for caller */
732 if (mod_privs_count)
734 luid_and_attr_from_privilege(mod_privs, privilege);
735 mod_privs++;
736 mod_privs_count--;
737 modified_count++;
740 if (privs[i].Attributes & SE_PRIVILEGE_ENABLED)
741 privilege->enabled = TRUE;
742 else
743 privilege->enabled = FALSE;
746 return modified_count;
749 static void token_disable_privileges( struct token *token )
751 struct privilege *privilege;
753 /* mark as modified */
754 allocate_luid( &token->modified_id );
756 LIST_FOR_EACH_ENTRY( privilege, &token->privileges, struct privilege, entry )
757 privilege->enabled = FALSE;
760 int token_check_privileges( struct token *token, int all_required,
761 const LUID_AND_ATTRIBUTES *reqprivs,
762 unsigned int count, LUID_AND_ATTRIBUTES *usedprivs)
764 unsigned int i, enabled_count = 0;
766 for (i = 0; i < count; i++)
768 struct privilege *privilege =
769 token_find_privilege( token, &reqprivs[i].Luid, TRUE );
771 if (usedprivs)
772 usedprivs[i] = reqprivs[i];
774 if (privilege && privilege->enabled)
776 enabled_count++;
777 if (usedprivs)
778 usedprivs[i].Attributes |= SE_PRIVILEGE_USED_FOR_ACCESS;
782 if (all_required)
783 return (enabled_count == count);
784 else
785 return (enabled_count > 0);
788 int token_sid_present( struct token *token, const SID *sid, int deny )
790 struct group *group;
792 if (security_equal_sid( token->user, sid )) return TRUE;
794 LIST_FOR_EACH_ENTRY( group, &token->groups, struct group, entry )
796 if (!group->enabled) continue;
797 if (group->deny_only && !deny) continue;
799 if (security_equal_sid( &group->sid, sid )) return TRUE;
802 return FALSE;
805 /* Checks access to a security descriptor. 'sd' must have been validated by
806 * caller. It returns STATUS_SUCCESS if call succeeded or an error indicating
807 * the reason. 'status' parameter will indicate if access is granted or denied.
809 * If both returned value and 'status' are STATUS_SUCCESS then access is granted.
811 static unsigned int token_access_check( struct token *token,
812 const struct security_descriptor *sd,
813 unsigned int desired_access,
814 LUID_AND_ATTRIBUTES *privs,
815 unsigned int *priv_count,
816 const GENERIC_MAPPING *mapping,
817 unsigned int *granted_access,
818 unsigned int *status )
820 unsigned int current_access = 0;
821 unsigned int denied_access = 0;
822 ULONG i;
823 const ACL *dacl;
824 int dacl_present;
825 const ACE_HEADER *ace;
826 const SID *owner;
828 /* assume no access rights */
829 *granted_access = 0;
831 /* fail if desired_access contains generic rights */
832 if (desired_access & (GENERIC_READ|GENERIC_WRITE|GENERIC_EXECUTE|GENERIC_ALL))
834 *priv_count = 0;
835 return STATUS_GENERIC_NOT_MAPPED;
838 dacl = sd_get_dacl( sd, &dacl_present );
839 owner = sd_get_owner( sd );
840 if (!owner || !sd_get_group( sd ))
842 *priv_count = 0;
843 return STATUS_INVALID_SECURITY_DESCR;
846 /* 1: Grant desired access if the object is unprotected */
847 if (!dacl_present || !dacl)
849 *priv_count = 0;
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 *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 LUID_AND_ATTRIBUTES priv;
989 unsigned int status, priv_count = 1;
990 int res;
992 mapping.GenericAll = obj->ops->map_access( obj, GENERIC_ALL );
994 if (!obj->sd)
996 if (*access & MAXIMUM_ALLOWED)
997 *access = mapping.GenericAll;
998 return TRUE;
1001 mapping.GenericRead = obj->ops->map_access( obj, GENERIC_READ );
1002 mapping.GenericWrite = obj->ops->map_access( obj, GENERIC_WRITE );
1003 mapping.GenericExecute = obj->ops->map_access( obj, GENERIC_EXECUTE );
1005 res = token_access_check( token, obj->sd, *access, &priv, &priv_count,
1006 &mapping, access, &status ) == STATUS_SUCCESS &&
1007 status == STATUS_SUCCESS;
1009 if (!res) set_error( STATUS_ACCESS_DENIED );
1010 return res;
1014 /* open a security token */
1015 DECL_HANDLER(open_token)
1017 if (req->flags & OPEN_TOKEN_THREAD)
1019 struct thread *thread = get_thread_from_handle( req->handle, 0 );
1020 if (thread)
1022 if (thread->token)
1024 if (!thread->token->primary && thread->token->impersonation_level <= SecurityAnonymous)
1025 set_error( STATUS_CANT_OPEN_ANONYMOUS );
1026 else
1027 reply->token = alloc_handle( current->process, thread->token,
1028 req->access, req->attributes );
1030 else
1031 set_error( STATUS_NO_TOKEN );
1032 release_object( thread );
1035 else
1037 struct process *process = get_process_from_handle( req->handle, 0 );
1038 if (process)
1040 if (process->token)
1041 reply->token = alloc_handle( current->process, process->token, req->access,
1042 req->attributes );
1043 else
1044 set_error( STATUS_NO_TOKEN );
1045 release_object( process );
1050 /* adjust the privileges held by a token */
1051 DECL_HANDLER(adjust_token_privileges)
1053 struct token *token;
1054 unsigned int access = TOKEN_ADJUST_PRIVILEGES;
1056 if (req->get_modified_state) access |= TOKEN_QUERY;
1058 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1059 access, &token_ops )))
1061 const LUID_AND_ATTRIBUTES *privs = get_req_data();
1062 LUID_AND_ATTRIBUTES *modified_privs = NULL;
1063 unsigned int priv_count = get_req_data_size() / sizeof(LUID_AND_ATTRIBUTES);
1064 unsigned int modified_priv_count = 0;
1066 if (req->get_modified_state && !req->disable_all)
1068 unsigned int i;
1069 /* count modified privs */
1070 for (i = 0; i < priv_count; i++)
1072 struct privilege *privilege =
1073 token_find_privilege( token, &privs[i].Luid, FALSE );
1074 if (privilege && req->get_modified_state)
1075 modified_priv_count++;
1077 reply->len = modified_priv_count;
1078 modified_priv_count = min( modified_priv_count, get_reply_max_size() / sizeof(*modified_privs) );
1079 if (modified_priv_count)
1080 modified_privs = set_reply_data_size( modified_priv_count * sizeof(*modified_privs) );
1082 reply->len = modified_priv_count * sizeof(*modified_privs);
1084 if (req->disable_all)
1085 token_disable_privileges( token );
1086 else
1087 modified_priv_count = token_adjust_privileges( token, privs,
1088 priv_count, modified_privs, modified_priv_count );
1090 release_object( token );
1094 /* retrieves the list of privileges that may be held be the token */
1095 DECL_HANDLER(get_token_privileges)
1097 struct token *token;
1099 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1100 TOKEN_QUERY,
1101 &token_ops )))
1103 int priv_count = 0;
1104 LUID_AND_ATTRIBUTES *privs;
1105 struct privilege *privilege;
1107 LIST_FOR_EACH_ENTRY( privilege, &token->privileges, struct privilege, entry )
1108 priv_count++;
1110 reply->len = priv_count * sizeof(*privs);
1111 if (reply->len <= get_reply_max_size())
1113 privs = set_reply_data_size( priv_count * sizeof(*privs) );
1114 if (privs)
1116 int i = 0;
1117 LIST_FOR_EACH_ENTRY( privilege, &token->privileges, struct privilege, entry )
1119 luid_and_attr_from_privilege( &privs[i], privilege );
1120 i++;
1124 else
1125 set_error(STATUS_BUFFER_TOO_SMALL);
1127 release_object( token );
1131 /* creates a duplicate of the token */
1132 DECL_HANDLER(duplicate_token)
1134 struct token *src_token;
1136 if ((src_token = (struct token *)get_handle_obj( current->process, req->handle,
1137 TOKEN_DUPLICATE,
1138 &token_ops )))
1140 struct token *token = token_duplicate( src_token, req->primary, req->impersonation_level );
1141 if (token)
1143 reply->new_handle = alloc_handle( current->process, token, req->access, req->attributes);
1144 release_object( token );
1146 release_object( src_token );
1150 /* checks the specified privileges are held by the token */
1151 DECL_HANDLER(check_token_privileges)
1153 struct token *token;
1155 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1156 TOKEN_QUERY,
1157 &token_ops )))
1159 unsigned int count = get_req_data_size() / sizeof(LUID_AND_ATTRIBUTES);
1161 if (!token->primary && token->impersonation_level <= SecurityAnonymous)
1162 set_error( STATUS_BAD_IMPERSONATION_LEVEL );
1163 else if (get_reply_max_size() >= count * sizeof(LUID_AND_ATTRIBUTES))
1165 LUID_AND_ATTRIBUTES *usedprivs = set_reply_data_size( count * sizeof(*usedprivs) );
1166 reply->has_privileges = token_check_privileges( token, req->all_required, get_req_data(), count, usedprivs );
1168 else
1169 set_error( STATUS_BUFFER_OVERFLOW );
1170 release_object( token );
1174 /* checks that a user represented by a token is allowed to access an object
1175 * represented by a security descriptor */
1176 DECL_HANDLER(access_check)
1178 data_size_t sd_size = get_req_data_size();
1179 const struct security_descriptor *sd = get_req_data();
1180 struct token *token;
1182 if (!sd_is_valid( sd, sd_size ))
1184 set_error( STATUS_ACCESS_VIOLATION );
1185 return;
1188 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1189 TOKEN_QUERY,
1190 &token_ops )))
1192 GENERIC_MAPPING mapping;
1193 unsigned int status;
1194 LUID_AND_ATTRIBUTES priv;
1195 unsigned int priv_count = 1;
1197 memset(&priv, 0, sizeof(priv));
1199 /* only impersonation tokens may be used with this function */
1200 if (token->primary)
1202 set_error( STATUS_NO_IMPERSONATION_TOKEN );
1203 release_object( token );
1204 return;
1206 /* anonymous impersonation tokens can't be used */
1207 if (token->impersonation_level <= SecurityAnonymous)
1209 set_error( STATUS_BAD_IMPERSONATION_LEVEL );
1210 release_object( token );
1211 return;
1214 mapping.GenericRead = req->mapping_read;
1215 mapping.GenericWrite = req->mapping_write;
1216 mapping.GenericExecute = req->mapping_execute;
1217 mapping.GenericAll = req->mapping_all;
1219 status = token_access_check(
1220 token, sd, req->desired_access, &priv, &priv_count, &mapping,
1221 &reply->access_granted, &reply->access_status );
1223 reply->privileges_len = priv_count*sizeof(LUID_AND_ATTRIBUTES);
1225 if ((priv_count > 0) && (reply->privileges_len <= get_reply_max_size()))
1227 LUID_AND_ATTRIBUTES *privs = set_reply_data_size( priv_count * sizeof(*privs) );
1228 memcpy( privs, &priv, sizeof(priv) );
1231 set_error( status );
1232 release_object( token );
1236 /* retrieves the SID of the user that the token represents */
1237 DECL_HANDLER(get_token_sid)
1239 struct token *token;
1241 reply->sid_len = 0;
1243 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1244 TOKEN_QUERY,
1245 &token_ops )))
1247 const SID *sid = NULL;
1249 switch (req->which_sid)
1251 case TokenUser:
1252 assert(token->user);
1253 sid = token->user;
1254 break;
1255 case TokenPrimaryGroup:
1256 sid = token->primary_group;
1257 break;
1258 case TokenOwner:
1260 struct group *group;
1261 LIST_FOR_EACH_ENTRY( group, &token->groups, struct group, entry )
1263 if (group->owner)
1265 sid = &group->sid;
1266 break;
1269 break;
1271 default:
1272 set_error( STATUS_INVALID_PARAMETER );
1273 break;
1276 if (sid)
1278 reply->sid_len = FIELD_OFFSET(SID, SubAuthority[sid->SubAuthorityCount]);
1279 if (reply->sid_len <= get_reply_max_size()) set_reply_data( sid, reply->sid_len );
1280 else set_error( STATUS_BUFFER_TOO_SMALL );
1282 release_object( token );
1286 /* retrieves the groups that the user represented by the token belongs to */
1287 DECL_HANDLER(get_token_groups)
1289 struct token *token;
1291 reply->user_len = 0;
1293 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1294 TOKEN_QUERY,
1295 &token_ops )))
1297 size_t size_needed = sizeof(struct token_groups);
1298 size_t sid_size = 0;
1299 unsigned int group_count = 0;
1300 const struct group *group;
1302 LIST_FOR_EACH_ENTRY( group, &token->groups, const struct group, entry )
1304 group_count++;
1305 sid_size += FIELD_OFFSET(SID, SubAuthority[group->sid.SubAuthorityCount]);
1307 size_needed += sid_size;
1308 /* attributes size */
1309 size_needed += sizeof(unsigned int) * group_count;
1311 /* reply buffer contains size_needed bytes formatted as:
1313 unsigned int count;
1314 unsigned int attrib[count];
1315 char sid_data[];
1317 user_len includes extra data needed for TOKEN_GROUPS representation,
1318 required caller buffer size calculated here to avoid extra server call */
1319 reply->user_len = FIELD_OFFSET( TOKEN_GROUPS, Groups[group_count] ) + sid_size;
1321 if (reply->user_len <= get_reply_max_size())
1323 struct token_groups *tg = set_reply_data_size( size_needed );
1324 if (tg)
1326 unsigned int *attr_ptr = (unsigned int *)(tg + 1);
1327 SID *sid_ptr = (SID *)(attr_ptr + group_count);
1329 tg->count = group_count;
1331 LIST_FOR_EACH_ENTRY( group, &token->groups, const struct group, entry )
1334 *attr_ptr = 0;
1335 if (group->mandatory) *attr_ptr |= SE_GROUP_MANDATORY;
1336 if (group->def) *attr_ptr |= SE_GROUP_ENABLED_BY_DEFAULT;
1337 if (group->enabled) *attr_ptr |= SE_GROUP_ENABLED;
1338 if (group->owner) *attr_ptr |= SE_GROUP_OWNER;
1339 if (group->deny_only) *attr_ptr |= SE_GROUP_USE_FOR_DENY_ONLY;
1340 if (group->resource) *attr_ptr |= SE_GROUP_RESOURCE;
1341 if (group->logon) *attr_ptr |= SE_GROUP_LOGON_ID;
1343 memcpy(sid_ptr, &group->sid, FIELD_OFFSET(SID, SubAuthority[group->sid.SubAuthorityCount]));
1345 sid_ptr = (SID *)((char *)sid_ptr + FIELD_OFFSET(SID, SubAuthority[group->sid.SubAuthorityCount]));
1346 attr_ptr++;
1350 else set_error( STATUS_BUFFER_TOO_SMALL );
1352 release_object( token );
1356 DECL_HANDLER(get_token_impersonation_level)
1358 struct token *token;
1360 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1361 TOKEN_QUERY,
1362 &token_ops )))
1364 if (token->primary)
1365 set_error( STATUS_INVALID_PARAMETER );
1366 else
1367 reply->impersonation_level = token->impersonation_level;
1369 release_object( token );
1373 DECL_HANDLER(get_token_statistics)
1375 struct token *token;
1377 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1378 TOKEN_QUERY,
1379 &token_ops )))
1381 reply->token_id = token->token_id;
1382 reply->modified_id = token->modified_id;
1383 reply->primary = token->primary;
1384 reply->impersonation_level = token->impersonation_level;
1385 reply->group_count = list_count( &token->groups );
1386 reply->privilege_count = list_count( &token->privileges );
1388 release_object( token );
1392 DECL_HANDLER(get_token_default_dacl)
1394 struct token *token;
1396 reply->acl_len = 0;
1398 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1399 TOKEN_QUERY,
1400 &token_ops )))
1402 if (token->default_dacl)
1403 reply->acl_len = token->default_dacl->AclSize;
1405 if (reply->acl_len <= get_reply_max_size())
1407 ACL *acl_reply = set_reply_data_size( reply->acl_len );
1408 if (acl_reply)
1409 memcpy( acl_reply, token->default_dacl, reply->acl_len );
1411 else set_error( STATUS_BUFFER_TOO_SMALL );
1413 release_object( token );
1417 DECL_HANDLER(set_token_default_dacl)
1419 struct token *token;
1421 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1422 TOKEN_ADJUST_DEFAULT,
1423 &token_ops )))
1425 const ACL *acl = get_req_data();
1426 unsigned int acl_size = get_req_data_size();
1428 free( token->default_dacl );
1429 token->default_dacl = NULL;
1431 if (acl_size)
1432 token->default_dacl = memdup( acl, acl_size );
1434 release_object( token );