wined3d: Pass a view to blit_shader.color_fill().
[wine.git] / server / token.c
blobda1f25575885732552c88eaa299a41a7c49511d8
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_open_file, /* open_file */
162 no_close_handle, /* close_handle */
163 token_destroy /* destroy */
167 static void token_dump( struct object *obj, int verbose )
169 fprintf( stderr, "Security token\n" );
170 /* FIXME: dump token members */
173 static unsigned int token_map_access( struct object *obj, unsigned int access )
175 if (access & GENERIC_READ) access |= TOKEN_READ;
176 if (access & GENERIC_WRITE) access |= TOKEN_WRITE;
177 if (access & GENERIC_EXECUTE) access |= STANDARD_RIGHTS_EXECUTE;
178 if (access & GENERIC_ALL) access |= TOKEN_ALL_ACCESS;
179 return access & ~(GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | GENERIC_ALL);
182 static SID *security_sid_alloc( const SID_IDENTIFIER_AUTHORITY *idauthority, int subauthcount, const unsigned int subauth[] )
184 int i;
185 SID *sid = mem_alloc( FIELD_OFFSET(SID, SubAuthority[subauthcount]) );
186 if (!sid) return NULL;
187 sid->Revision = SID_REVISION;
188 sid->SubAuthorityCount = subauthcount;
189 sid->IdentifierAuthority = *idauthority;
190 for (i = 0; i < subauthcount; i++)
191 sid->SubAuthority[i] = subauth[i];
192 return sid;
195 void security_set_thread_token( struct thread *thread, obj_handle_t handle )
197 if (!handle)
199 if (thread->token)
200 release_object( thread->token );
201 thread->token = NULL;
203 else
205 struct token *token = (struct token *)get_handle_obj( current->process,
206 handle,
207 TOKEN_IMPERSONATE,
208 &token_ops );
209 if (token)
211 if (thread->token)
212 release_object( thread->token );
213 thread->token = token;
218 const SID *security_unix_uid_to_sid( uid_t uid )
220 /* very simple mapping: either the current user or not the current user */
221 if (uid == getuid())
222 return (const SID *)&local_user_sid;
223 else
224 return &anonymous_logon_sid;
227 static int acl_is_valid( const ACL *acl, data_size_t size )
229 ULONG i;
230 const ACE_HEADER *ace;
232 if (size < sizeof(ACL))
233 return FALSE;
235 size = min(size, MAX_ACL_LEN);
237 size -= sizeof(ACL);
239 ace = (const ACE_HEADER *)(acl + 1);
240 for (i = 0; i < acl->AceCount; i++)
242 const SID *sid;
243 data_size_t sid_size;
245 if (size < sizeof(ACE_HEADER))
246 return FALSE;
247 if (size < ace->AceSize)
248 return FALSE;
249 size -= ace->AceSize;
250 switch (ace->AceType)
252 case ACCESS_DENIED_ACE_TYPE:
253 sid = (const SID *)&((const ACCESS_DENIED_ACE *)ace)->SidStart;
254 sid_size = ace->AceSize - FIELD_OFFSET(ACCESS_DENIED_ACE, SidStart);
255 break;
256 case ACCESS_ALLOWED_ACE_TYPE:
257 sid = (const SID *)&((const ACCESS_ALLOWED_ACE *)ace)->SidStart;
258 sid_size = ace->AceSize - FIELD_OFFSET(ACCESS_ALLOWED_ACE, SidStart);
259 break;
260 case SYSTEM_AUDIT_ACE_TYPE:
261 sid = (const SID *)&((const SYSTEM_AUDIT_ACE *)ace)->SidStart;
262 sid_size = ace->AceSize - FIELD_OFFSET(SYSTEM_AUDIT_ACE, SidStart);
263 break;
264 case SYSTEM_ALARM_ACE_TYPE:
265 sid = (const SID *)&((const SYSTEM_ALARM_ACE *)ace)->SidStart;
266 sid_size = ace->AceSize - FIELD_OFFSET(SYSTEM_ALARM_ACE, SidStart);
267 break;
268 case SYSTEM_MANDATORY_LABEL_ACE_TYPE:
269 sid = (const SID *)&((const SYSTEM_MANDATORY_LABEL_ACE *)ace)->SidStart;
270 sid_size = ace->AceSize - FIELD_OFFSET(SYSTEM_MANDATORY_LABEL_ACE, SidStart);
271 break;
272 default:
273 return FALSE;
275 if (sid_size < FIELD_OFFSET(SID, SubAuthority[0]) || sid_size < security_sid_len( sid ))
276 return FALSE;
277 ace = ace_next( ace );
279 return TRUE;
282 /* checks whether all members of a security descriptor fit inside the size
283 * of memory specified */
284 int sd_is_valid( const struct security_descriptor *sd, data_size_t size )
286 size_t offset = sizeof(struct security_descriptor);
287 const SID *group;
288 const SID *owner;
289 const ACL *sacl;
290 const ACL *dacl;
291 int dummy;
293 if (size < offset)
294 return FALSE;
296 if ((sd->owner_len >= FIELD_OFFSET(SID, SubAuthority[255])) ||
297 (offset + sd->owner_len > size))
298 return FALSE;
299 owner = sd_get_owner( sd );
300 if (owner)
302 size_t needed_size = security_sid_len( owner );
303 if ((sd->owner_len < sizeof(SID)) || (needed_size > sd->owner_len))
304 return FALSE;
306 offset += sd->owner_len;
308 if ((sd->group_len >= FIELD_OFFSET(SID, SubAuthority[255])) ||
309 (offset + sd->group_len > size))
310 return FALSE;
311 group = sd_get_group( sd );
312 if (group)
314 size_t needed_size = security_sid_len( group );
315 if ((sd->group_len < sizeof(SID)) || (needed_size > sd->group_len))
316 return FALSE;
318 offset += sd->group_len;
320 if ((sd->sacl_len >= MAX_ACL_LEN) || (offset + sd->sacl_len > size))
321 return FALSE;
322 sacl = sd_get_sacl( sd, &dummy );
323 if (sacl && !acl_is_valid( sacl, sd->sacl_len ))
324 return FALSE;
325 offset += sd->sacl_len;
327 if ((sd->dacl_len >= MAX_ACL_LEN) || (offset + sd->dacl_len > size))
328 return FALSE;
329 dacl = sd_get_dacl( sd, &dummy );
330 if (dacl && !acl_is_valid( dacl, sd->dacl_len ))
331 return FALSE;
332 offset += sd->dacl_len;
334 return TRUE;
337 /* maps from generic rights to specific rights as given by a mapping */
338 static inline void map_generic_mask(unsigned int *mask, const GENERIC_MAPPING *mapping)
340 if (*mask & GENERIC_READ) *mask |= mapping->GenericRead;
341 if (*mask & GENERIC_WRITE) *mask |= mapping->GenericWrite;
342 if (*mask & GENERIC_EXECUTE) *mask |= mapping->GenericExecute;
343 if (*mask & GENERIC_ALL) *mask |= mapping->GenericAll;
344 *mask &= 0x0FFFFFFF;
347 static inline int is_equal_luid( const LUID *luid1, const LUID *luid2 )
349 return (luid1->LowPart == luid2->LowPart && luid1->HighPart == luid2->HighPart);
352 static inline void allocate_luid( luid_t *luid )
354 prev_luid_value.low_part++;
355 *luid = prev_luid_value;
358 DECL_HANDLER( allocate_locally_unique_id )
360 allocate_luid( &reply->luid );
363 static inline void luid_and_attr_from_privilege( LUID_AND_ATTRIBUTES *out, const struct privilege *in)
365 out->Luid = in->luid;
366 out->Attributes =
367 (in->enabled ? SE_PRIVILEGE_ENABLED : 0) |
368 (in->def ? SE_PRIVILEGE_ENABLED_BY_DEFAULT : 0);
371 static struct privilege *privilege_add( struct token *token, const LUID *luid, int enabled )
373 struct privilege *privilege = mem_alloc( sizeof(*privilege) );
374 if (privilege)
376 privilege->luid = *luid;
377 privilege->def = privilege->enabled = (enabled != 0);
378 list_add_tail( &token->privileges, &privilege->entry );
380 return privilege;
383 static inline void privilege_remove( struct privilege *privilege )
385 list_remove( &privilege->entry );
386 free( privilege );
389 static void token_destroy( struct object *obj )
391 struct token* token;
392 struct list *cursor, *cursor_next;
394 assert( obj->ops == &token_ops );
395 token = (struct token *)obj;
397 free( token->user );
399 LIST_FOR_EACH_SAFE( cursor, cursor_next, &token->privileges )
401 struct privilege *privilege = LIST_ENTRY( cursor, struct privilege, entry );
402 privilege_remove( privilege );
405 LIST_FOR_EACH_SAFE( cursor, cursor_next, &token->groups )
407 struct group *group = LIST_ENTRY( cursor, struct group, entry );
408 list_remove( &group->entry );
409 free( group );
412 free( token->default_dacl );
415 /* creates a new token.
416 * groups may be NULL if group_count is 0.
417 * privs may be NULL if priv_count is 0.
418 * default_dacl may be NULL, indicating that all objects created by the user
419 * are unsecured.
420 * modified_id may be NULL, indicating that a new modified_id luid should be
421 * allocated.
423 static struct token *create_token( unsigned primary, const SID *user,
424 const SID_AND_ATTRIBUTES *groups, unsigned int group_count,
425 const LUID_AND_ATTRIBUTES *privs, unsigned int priv_count,
426 const ACL *default_dacl, TOKEN_SOURCE source,
427 const luid_t *modified_id,
428 int impersonation_level )
430 struct token *token = alloc_object( &token_ops );
431 if (token)
433 unsigned int i;
435 allocate_luid( &token->token_id );
436 if (modified_id)
437 token->modified_id = *modified_id;
438 else
439 allocate_luid( &token->modified_id );
440 list_init( &token->privileges );
441 list_init( &token->groups );
442 token->primary = primary;
443 /* primary tokens don't have impersonation levels */
444 if (primary)
445 token->impersonation_level = -1;
446 else
447 token->impersonation_level = impersonation_level;
448 token->default_dacl = NULL;
449 token->primary_group = NULL;
451 /* copy user */
452 token->user = memdup( user, security_sid_len( user ));
453 if (!token->user)
455 release_object( token );
456 return NULL;
459 /* copy groups */
460 for (i = 0; i < group_count; i++)
462 size_t size = FIELD_OFFSET( struct group, sid.SubAuthority[((const SID *)groups[i].Sid)->SubAuthorityCount] );
463 struct group *group = mem_alloc( size );
465 if (!group)
467 release_object( token );
468 return NULL;
470 memcpy( &group->sid, groups[i].Sid, security_sid_len( groups[i].Sid ));
471 group->enabled = TRUE;
472 group->def = TRUE;
473 group->logon = (groups[i].Attributes & SE_GROUP_LOGON_ID) != 0;
474 group->mandatory = (groups[i].Attributes & SE_GROUP_MANDATORY) != 0;
475 group->owner = (groups[i].Attributes & SE_GROUP_OWNER) != 0;
476 group->resource = FALSE;
477 group->deny_only = FALSE;
478 list_add_tail( &token->groups, &group->entry );
479 /* Use first owner capable group as an owner */
480 if (!token->primary_group && group->owner)
481 token->primary_group = &group->sid;
484 /* copy privileges */
485 for (i = 0; i < priv_count; i++)
487 /* note: we don't check uniqueness: the caller must make sure
488 * privs doesn't contain any duplicate luids */
489 if (!privilege_add( token, &privs[i].Luid,
490 privs[i].Attributes & SE_PRIVILEGE_ENABLED ))
492 release_object( token );
493 return NULL;
497 if (default_dacl)
499 token->default_dacl = memdup( default_dacl, default_dacl->AclSize );
500 if (!token->default_dacl)
502 release_object( token );
503 return NULL;
507 token->source = source;
509 return token;
512 struct token *token_duplicate( struct token *src_token, unsigned primary,
513 int impersonation_level )
515 const luid_t *modified_id =
516 primary || (impersonation_level == src_token->impersonation_level) ?
517 &src_token->modified_id : NULL;
518 struct token *token = NULL;
519 struct privilege *privilege;
520 struct group *group;
522 if (!primary &&
523 (impersonation_level < SecurityAnonymous ||
524 impersonation_level > SecurityDelegation ||
525 (!src_token->primary && (impersonation_level > src_token->impersonation_level))))
527 set_error( STATUS_BAD_IMPERSONATION_LEVEL );
528 return NULL;
531 token = create_token( primary, src_token->user, NULL, 0,
532 NULL, 0, src_token->default_dacl,
533 src_token->source, modified_id,
534 impersonation_level );
535 if (!token) return token;
537 /* copy groups */
538 token->primary_group = NULL;
539 LIST_FOR_EACH_ENTRY( group, &src_token->groups, struct group, entry )
541 size_t size = FIELD_OFFSET( struct group, sid.SubAuthority[group->sid.SubAuthorityCount] );
542 struct group *newgroup = mem_alloc( size );
543 if (!newgroup)
545 release_object( token );
546 return NULL;
548 memcpy( newgroup, group, size );
549 list_add_tail( &token->groups, &newgroup->entry );
550 if (src_token->primary_group == &group->sid)
551 token->primary_group = &newgroup->sid;
553 assert( token->primary_group );
555 /* copy privileges */
556 LIST_FOR_EACH_ENTRY( privilege, &src_token->privileges, struct privilege, entry )
557 if (!privilege_add( token, &privilege->luid, privilege->enabled ))
559 release_object( token );
560 return NULL;
563 return token;
566 static ACL *create_default_dacl( const SID *user )
568 ACCESS_ALLOWED_ACE *aaa;
569 ACL *default_dacl;
570 SID *sid;
571 size_t default_dacl_size = sizeof(ACL) +
572 2*(sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD)) +
573 sizeof(local_system_sid) +
574 security_sid_len( user );
576 default_dacl = mem_alloc( default_dacl_size );
577 if (!default_dacl) return NULL;
579 default_dacl->AclRevision = ACL_REVISION;
580 default_dacl->Sbz1 = 0;
581 default_dacl->AclSize = default_dacl_size;
582 default_dacl->AceCount = 2;
583 default_dacl->Sbz2 = 0;
585 /* GENERIC_ALL for Local System */
586 aaa = (ACCESS_ALLOWED_ACE *)(default_dacl + 1);
587 aaa->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
588 aaa->Header.AceFlags = 0;
589 aaa->Header.AceSize = (sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD)) +
590 sizeof(local_system_sid);
591 aaa->Mask = GENERIC_ALL;
592 sid = (SID *)&aaa->SidStart;
593 memcpy( sid, &local_system_sid, sizeof(local_system_sid) );
595 /* GENERIC_ALL for specified user */
596 aaa = (ACCESS_ALLOWED_ACE *)((char *)aaa + aaa->Header.AceSize);
597 aaa->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
598 aaa->Header.AceFlags = 0;
599 aaa->Header.AceSize = (sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD)) + security_sid_len( user );
600 aaa->Mask = GENERIC_ALL;
601 sid = (SID *)&aaa->SidStart;
602 memcpy( sid, user, security_sid_len( user ));
604 return default_dacl;
607 struct sid_data
609 SID_IDENTIFIER_AUTHORITY idauth;
610 int count;
611 unsigned int subauth[MAX_SUBAUTH_COUNT];
614 struct token *token_create_admin( void )
616 struct token *token = NULL;
617 static const SID_IDENTIFIER_AUTHORITY nt_authority = { SECURITY_NT_AUTHORITY };
618 static const unsigned int alias_admins_subauth[] = { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS };
619 static const unsigned int alias_users_subauth[] = { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_USERS };
620 /* on Windows, this value changes every time the user logs on */
621 static const unsigned int logon_subauth[] = { SECURITY_LOGON_IDS_RID, 0, 1 /* FIXME: should be randomly generated when tokens are inherited by new processes */ };
622 PSID alias_admins_sid;
623 PSID alias_users_sid;
624 PSID logon_sid;
625 const SID *user_sid = security_unix_uid_to_sid( getuid() );
626 ACL *default_dacl = create_default_dacl( user_sid );
628 alias_admins_sid = security_sid_alloc( &nt_authority, sizeof(alias_admins_subauth)/sizeof(alias_admins_subauth[0]),
629 alias_admins_subauth );
630 alias_users_sid = security_sid_alloc( &nt_authority, sizeof(alias_users_subauth)/sizeof(alias_users_subauth[0]),
631 alias_users_subauth );
632 logon_sid = security_sid_alloc( &nt_authority, sizeof(logon_subauth)/sizeof(logon_subauth[0]),
633 logon_subauth );
635 if (alias_admins_sid && alias_users_sid && logon_sid && default_dacl)
637 const LUID_AND_ATTRIBUTES admin_privs[] =
639 { SeChangeNotifyPrivilege , SE_PRIVILEGE_ENABLED },
640 { SeSecurityPrivilege , 0 },
641 { SeBackupPrivilege , 0 },
642 { SeRestorePrivilege , 0 },
643 { SeSystemtimePrivilege , 0 },
644 { SeShutdownPrivilege , 0 },
645 { SeRemoteShutdownPrivilege , 0 },
646 { SeTakeOwnershipPrivilege , 0 },
647 { SeDebugPrivilege , 0 },
648 { SeSystemEnvironmentPrivilege , 0 },
649 { SeSystemProfilePrivilege , 0 },
650 { SeProfileSingleProcessPrivilege, 0 },
651 { SeIncreaseBasePriorityPrivilege, 0 },
652 { SeLoadDriverPrivilege , SE_PRIVILEGE_ENABLED },
653 { SeCreatePagefilePrivilege , 0 },
654 { SeIncreaseQuotaPrivilege , 0 },
655 { SeUndockPrivilege , 0 },
656 { SeManageVolumePrivilege , 0 },
657 { SeImpersonatePrivilege , SE_PRIVILEGE_ENABLED },
658 { SeCreateGlobalPrivilege , SE_PRIVILEGE_ENABLED },
660 /* note: we don't include non-builtin groups here for the user -
661 * telling us these is the job of a client-side program */
662 const SID_AND_ATTRIBUTES admin_groups[] =
664 { security_world_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY },
665 { security_local_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY },
666 { security_interactive_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY },
667 { security_authenticated_user_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY },
668 { alias_admins_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY|SE_GROUP_OWNER },
669 { alias_users_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY },
670 { logon_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY|SE_GROUP_LOGON_ID },
672 static const TOKEN_SOURCE admin_source = {"SeMgr", {0, 0}};
673 token = create_token( TRUE, user_sid, admin_groups, sizeof(admin_groups)/sizeof(admin_groups[0]),
674 admin_privs, sizeof(admin_privs)/sizeof(admin_privs[0]), default_dacl,
675 admin_source, NULL, -1 );
676 /* we really need a primary group */
677 assert( token->primary_group );
680 free( logon_sid );
681 free( alias_admins_sid );
682 free( alias_users_sid );
683 free( default_dacl );
685 return token;
688 static struct privilege *token_find_privilege( struct token *token, const LUID *luid, int enabled_only )
690 struct privilege *privilege;
691 LIST_FOR_EACH_ENTRY( privilege, &token->privileges, struct privilege, entry )
693 if (is_equal_luid( luid, &privilege->luid ))
695 if (enabled_only && !privilege->enabled)
696 return NULL;
697 return privilege;
700 return NULL;
703 static unsigned int token_adjust_privileges( struct token *token, const LUID_AND_ATTRIBUTES *privs,
704 unsigned int count, LUID_AND_ATTRIBUTES *mod_privs,
705 unsigned int mod_privs_count )
707 unsigned int i, modified_count = 0;
709 /* mark as modified */
710 allocate_luid( &token->modified_id );
712 for (i = 0; i < count; i++)
714 struct privilege *privilege =
715 token_find_privilege( token, &privs[i].Luid, FALSE );
716 if (!privilege)
718 set_error( STATUS_NOT_ALL_ASSIGNED );
719 continue;
722 if (privs[i].Attributes & SE_PRIVILEGE_REMOVED)
723 privilege_remove( privilege );
724 else
726 /* save previous state for caller */
727 if (mod_privs_count)
729 luid_and_attr_from_privilege(mod_privs, privilege);
730 mod_privs++;
731 mod_privs_count--;
732 modified_count++;
735 if (privs[i].Attributes & SE_PRIVILEGE_ENABLED)
736 privilege->enabled = TRUE;
737 else
738 privilege->enabled = FALSE;
741 return modified_count;
744 static void token_disable_privileges( struct token *token )
746 struct privilege *privilege;
748 /* mark as modified */
749 allocate_luid( &token->modified_id );
751 LIST_FOR_EACH_ENTRY( privilege, &token->privileges, struct privilege, entry )
752 privilege->enabled = FALSE;
755 int token_check_privileges( struct token *token, int all_required,
756 const LUID_AND_ATTRIBUTES *reqprivs,
757 unsigned int count, LUID_AND_ATTRIBUTES *usedprivs)
759 unsigned int i, enabled_count = 0;
761 for (i = 0; i < count; i++)
763 struct privilege *privilege =
764 token_find_privilege( token, &reqprivs[i].Luid, TRUE );
766 if (usedprivs)
767 usedprivs[i] = reqprivs[i];
769 if (privilege && privilege->enabled)
771 enabled_count++;
772 if (usedprivs)
773 usedprivs[i].Attributes |= SE_PRIVILEGE_USED_FOR_ACCESS;
777 if (all_required)
778 return (enabled_count == count);
779 else
780 return (enabled_count > 0);
783 int token_sid_present( struct token *token, const SID *sid, int deny )
785 struct group *group;
787 if (security_equal_sid( token->user, sid )) return TRUE;
789 LIST_FOR_EACH_ENTRY( group, &token->groups, struct group, entry )
791 if (!group->enabled) continue;
792 if (group->deny_only && !deny) continue;
794 if (security_equal_sid( &group->sid, sid )) return TRUE;
797 return FALSE;
800 /* Checks access to a security descriptor. 'sd' must have been validated by
801 * caller. It returns STATUS_SUCCESS if call succeeded or an error indicating
802 * the reason. 'status' parameter will indicate if access is granted or denied.
804 * If both returned value and 'status' are STATUS_SUCCESS then access is granted.
806 static unsigned int token_access_check( struct token *token,
807 const struct security_descriptor *sd,
808 unsigned int desired_access,
809 LUID_AND_ATTRIBUTES *privs,
810 unsigned int *priv_count,
811 const GENERIC_MAPPING *mapping,
812 unsigned int *granted_access,
813 unsigned int *status )
815 unsigned int current_access = 0;
816 unsigned int denied_access = 0;
817 ULONG i;
818 const ACL *dacl;
819 int dacl_present;
820 const ACE_HEADER *ace;
821 const SID *owner;
823 /* assume no access rights */
824 *granted_access = 0;
826 /* fail if desired_access contains generic rights */
827 if (desired_access & (GENERIC_READ|GENERIC_WRITE|GENERIC_EXECUTE|GENERIC_ALL))
829 if (priv_count) *priv_count = 0;
830 return STATUS_GENERIC_NOT_MAPPED;
833 dacl = sd_get_dacl( sd, &dacl_present );
834 owner = sd_get_owner( sd );
835 if (!owner || !sd_get_group( sd ))
837 if (priv_count) *priv_count = 0;
838 return STATUS_INVALID_SECURITY_DESCR;
841 /* 1: Grant desired access if the object is unprotected */
842 if (!dacl_present || !dacl)
844 if (priv_count) *priv_count = 0;
845 *granted_access = desired_access;
846 return *status = STATUS_SUCCESS;
849 /* 2: Check if caller wants access to system security part. Note: access
850 * is only granted if specifically asked for */
851 if (desired_access & ACCESS_SYSTEM_SECURITY)
853 const LUID_AND_ATTRIBUTES security_priv = { SeSecurityPrivilege, 0 };
854 LUID_AND_ATTRIBUTES retpriv = security_priv;
855 if (token_check_privileges( token, TRUE, &security_priv, 1, &retpriv ))
857 if (priv_count)
859 /* assumes that there will only be one privilege to return */
860 if (*priv_count >= 1)
862 *priv_count = 1;
863 *privs = retpriv;
865 else
867 *priv_count = 1;
868 return STATUS_BUFFER_TOO_SMALL;
871 current_access |= ACCESS_SYSTEM_SECURITY;
872 if (desired_access == current_access)
874 *granted_access = current_access;
875 return *status = STATUS_SUCCESS;
878 else
880 if (priv_count) *priv_count = 0;
881 *status = STATUS_PRIVILEGE_NOT_HELD;
882 return STATUS_SUCCESS;
885 else if (priv_count) *priv_count = 0;
887 /* 3: Check whether the token is the owner */
888 /* NOTE: SeTakeOwnershipPrivilege is not checked for here - it is instead
889 * checked when a "set owner" call is made, overriding the access rights
890 * determined here. */
891 if (token_sid_present( token, owner, FALSE ))
893 current_access |= (READ_CONTROL | WRITE_DAC);
894 if (desired_access == current_access)
896 *granted_access = current_access;
897 return *status = STATUS_SUCCESS;
901 /* 4: Grant rights according to the DACL */
902 ace = (const ACE_HEADER *)(dacl + 1);
903 for (i = 0; i < dacl->AceCount; i++, ace = ace_next( ace ))
905 const ACCESS_ALLOWED_ACE *aa_ace;
906 const ACCESS_DENIED_ACE *ad_ace;
907 const SID *sid;
909 if (ace->AceFlags & INHERIT_ONLY_ACE)
910 continue;
912 switch (ace->AceType)
914 case ACCESS_DENIED_ACE_TYPE:
915 ad_ace = (const ACCESS_DENIED_ACE *)ace;
916 sid = (const SID *)&ad_ace->SidStart;
917 if (token_sid_present( token, sid, TRUE ))
919 unsigned int access = ad_ace->Mask;
920 map_generic_mask(&access, mapping);
921 if (desired_access & MAXIMUM_ALLOWED)
922 denied_access |= access;
923 else
925 denied_access |= (access & ~current_access);
926 if (desired_access & access) goto done;
929 break;
930 case ACCESS_ALLOWED_ACE_TYPE:
931 aa_ace = (const ACCESS_ALLOWED_ACE *)ace;
932 sid = (const SID *)&aa_ace->SidStart;
933 if (token_sid_present( token, sid, FALSE ))
935 unsigned int access = aa_ace->Mask;
936 map_generic_mask(&access, mapping);
937 if (desired_access & MAXIMUM_ALLOWED)
938 current_access |= access;
939 else
940 current_access |= (access & ~denied_access);
942 break;
945 /* don't bother carrying on checking if we've already got all of
946 * rights we need */
947 if (desired_access == *granted_access)
948 break;
951 done:
952 if (desired_access & MAXIMUM_ALLOWED)
953 *granted_access = current_access & ~denied_access;
954 else
955 if ((current_access & desired_access) == desired_access)
956 *granted_access = current_access & desired_access;
957 else
958 *granted_access = 0;
960 *status = *granted_access ? STATUS_SUCCESS : STATUS_ACCESS_DENIED;
961 return STATUS_SUCCESS;
964 const ACL *token_get_default_dacl( struct token *token )
966 return token->default_dacl;
969 const SID *token_get_user( struct token *token )
971 return token->user;
974 const SID *token_get_primary_group( struct token *token )
976 return token->primary_group;
979 int check_object_access(struct object *obj, unsigned int *access)
981 GENERIC_MAPPING mapping;
982 struct token *token = current->token ? current->token : current->process->token;
983 unsigned int status;
984 int res;
986 mapping.GenericAll = obj->ops->map_access( obj, GENERIC_ALL );
988 if (!obj->sd)
990 if (*access & MAXIMUM_ALLOWED)
991 *access = mapping.GenericAll;
992 return TRUE;
995 mapping.GenericRead = obj->ops->map_access( obj, GENERIC_READ );
996 mapping.GenericWrite = obj->ops->map_access( obj, GENERIC_WRITE );
997 mapping.GenericExecute = obj->ops->map_access( obj, GENERIC_EXECUTE );
999 res = token_access_check( token, obj->sd, *access, NULL, NULL,
1000 &mapping, access, &status ) == STATUS_SUCCESS &&
1001 status == STATUS_SUCCESS;
1003 if (!res) set_error( STATUS_ACCESS_DENIED );
1004 return res;
1008 /* open a security token */
1009 DECL_HANDLER(open_token)
1011 if (req->flags & OPEN_TOKEN_THREAD)
1013 struct thread *thread = get_thread_from_handle( req->handle, 0 );
1014 if (thread)
1016 if (thread->token)
1018 if (!thread->token->primary && thread->token->impersonation_level <= SecurityAnonymous)
1019 set_error( STATUS_CANT_OPEN_ANONYMOUS );
1020 else
1021 reply->token = alloc_handle( current->process, thread->token,
1022 req->access, req->attributes );
1024 else
1025 set_error( STATUS_NO_TOKEN );
1026 release_object( thread );
1029 else
1031 struct process *process = get_process_from_handle( req->handle, 0 );
1032 if (process)
1034 if (process->token)
1035 reply->token = alloc_handle( current->process, process->token, req->access,
1036 req->attributes );
1037 else
1038 set_error( STATUS_NO_TOKEN );
1039 release_object( process );
1044 /* adjust the privileges held by a token */
1045 DECL_HANDLER(adjust_token_privileges)
1047 struct token *token;
1048 unsigned int access = TOKEN_ADJUST_PRIVILEGES;
1050 if (req->get_modified_state) access |= TOKEN_QUERY;
1052 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1053 access, &token_ops )))
1055 const LUID_AND_ATTRIBUTES *privs = get_req_data();
1056 LUID_AND_ATTRIBUTES *modified_privs = NULL;
1057 unsigned int priv_count = get_req_data_size() / sizeof(LUID_AND_ATTRIBUTES);
1058 unsigned int modified_priv_count = 0;
1060 if (req->get_modified_state && !req->disable_all)
1062 unsigned int i;
1063 /* count modified privs */
1064 for (i = 0; i < priv_count; i++)
1066 struct privilege *privilege =
1067 token_find_privilege( token, &privs[i].Luid, FALSE );
1068 if (privilege && req->get_modified_state)
1069 modified_priv_count++;
1071 reply->len = modified_priv_count;
1072 modified_priv_count = min( modified_priv_count, get_reply_max_size() / sizeof(*modified_privs) );
1073 if (modified_priv_count)
1074 modified_privs = set_reply_data_size( modified_priv_count * sizeof(*modified_privs) );
1076 reply->len = modified_priv_count * sizeof(*modified_privs);
1078 if (req->disable_all)
1079 token_disable_privileges( token );
1080 else
1081 modified_priv_count = token_adjust_privileges( token, privs,
1082 priv_count, modified_privs, modified_priv_count );
1084 release_object( token );
1088 /* retrieves the list of privileges that may be held be the token */
1089 DECL_HANDLER(get_token_privileges)
1091 struct token *token;
1093 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1094 TOKEN_QUERY,
1095 &token_ops )))
1097 int priv_count = 0;
1098 LUID_AND_ATTRIBUTES *privs;
1099 struct privilege *privilege;
1101 LIST_FOR_EACH_ENTRY( privilege, &token->privileges, struct privilege, entry )
1102 priv_count++;
1104 reply->len = priv_count * sizeof(*privs);
1105 if (reply->len <= get_reply_max_size())
1107 privs = set_reply_data_size( priv_count * sizeof(*privs) );
1108 if (privs)
1110 int i = 0;
1111 LIST_FOR_EACH_ENTRY( privilege, &token->privileges, struct privilege, entry )
1113 luid_and_attr_from_privilege( &privs[i], privilege );
1114 i++;
1118 else
1119 set_error(STATUS_BUFFER_TOO_SMALL);
1121 release_object( token );
1125 /* creates a duplicate of the token */
1126 DECL_HANDLER(duplicate_token)
1128 struct token *src_token;
1130 if ((src_token = (struct token *)get_handle_obj( current->process, req->handle,
1131 TOKEN_DUPLICATE,
1132 &token_ops )))
1134 struct token *token = token_duplicate( src_token, req->primary, req->impersonation_level );
1135 if (token)
1137 reply->new_handle = alloc_handle( current->process, token, req->access, req->attributes);
1138 release_object( token );
1140 release_object( src_token );
1144 /* checks the specified privileges are held by the token */
1145 DECL_HANDLER(check_token_privileges)
1147 struct token *token;
1149 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1150 TOKEN_QUERY,
1151 &token_ops )))
1153 unsigned int count = get_req_data_size() / sizeof(LUID_AND_ATTRIBUTES);
1155 if (!token->primary && token->impersonation_level <= SecurityAnonymous)
1156 set_error( STATUS_BAD_IMPERSONATION_LEVEL );
1157 else if (get_reply_max_size() >= count * sizeof(LUID_AND_ATTRIBUTES))
1159 LUID_AND_ATTRIBUTES *usedprivs = set_reply_data_size( count * sizeof(*usedprivs) );
1160 reply->has_privileges = token_check_privileges( token, req->all_required, get_req_data(), count, usedprivs );
1162 else
1163 set_error( STATUS_BUFFER_OVERFLOW );
1164 release_object( token );
1168 /* checks that a user represented by a token is allowed to access an object
1169 * represented by a security descriptor */
1170 DECL_HANDLER(access_check)
1172 data_size_t sd_size = get_req_data_size();
1173 const struct security_descriptor *sd = get_req_data();
1174 struct token *token;
1176 if (!sd_is_valid( sd, sd_size ))
1178 set_error( STATUS_ACCESS_VIOLATION );
1179 return;
1182 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1183 TOKEN_QUERY,
1184 &token_ops )))
1186 GENERIC_MAPPING mapping;
1187 unsigned int status;
1188 LUID_AND_ATTRIBUTES priv;
1189 unsigned int priv_count = 1;
1191 memset(&priv, 0, sizeof(priv));
1193 /* only impersonation tokens may be used with this function */
1194 if (token->primary)
1196 set_error( STATUS_NO_IMPERSONATION_TOKEN );
1197 release_object( token );
1198 return;
1200 /* anonymous impersonation tokens can't be used */
1201 if (token->impersonation_level <= SecurityAnonymous)
1203 set_error( STATUS_BAD_IMPERSONATION_LEVEL );
1204 release_object( token );
1205 return;
1208 mapping.GenericRead = req->mapping_read;
1209 mapping.GenericWrite = req->mapping_write;
1210 mapping.GenericExecute = req->mapping_execute;
1211 mapping.GenericAll = req->mapping_all;
1213 status = token_access_check(
1214 token, sd, req->desired_access, &priv, &priv_count, &mapping,
1215 &reply->access_granted, &reply->access_status );
1217 reply->privileges_len = priv_count*sizeof(LUID_AND_ATTRIBUTES);
1219 if ((priv_count > 0) && (reply->privileges_len <= get_reply_max_size()))
1221 LUID_AND_ATTRIBUTES *privs = set_reply_data_size( priv_count * sizeof(*privs) );
1222 memcpy( privs, &priv, sizeof(priv) );
1225 set_error( status );
1226 release_object( token );
1230 /* retrieves the SID of the user that the token represents */
1231 DECL_HANDLER(get_token_sid)
1233 struct token *token;
1235 reply->sid_len = 0;
1237 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1238 TOKEN_QUERY,
1239 &token_ops )))
1241 const SID *sid = NULL;
1243 switch (req->which_sid)
1245 case TokenUser:
1246 assert(token->user);
1247 sid = token->user;
1248 break;
1249 case TokenPrimaryGroup:
1250 sid = token->primary_group;
1251 break;
1252 case TokenOwner:
1254 struct group *group;
1255 LIST_FOR_EACH_ENTRY( group, &token->groups, struct group, entry )
1257 if (group->owner)
1259 sid = &group->sid;
1260 break;
1263 break;
1265 default:
1266 set_error( STATUS_INVALID_PARAMETER );
1267 break;
1270 if (sid)
1272 reply->sid_len = security_sid_len( sid );
1273 if (reply->sid_len <= get_reply_max_size()) set_reply_data( sid, reply->sid_len );
1274 else set_error( STATUS_BUFFER_TOO_SMALL );
1276 release_object( token );
1280 /* retrieves the groups that the user represented by the token belongs to */
1281 DECL_HANDLER(get_token_groups)
1283 struct token *token;
1285 reply->user_len = 0;
1287 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1288 TOKEN_QUERY,
1289 &token_ops )))
1291 size_t size_needed = sizeof(struct token_groups);
1292 size_t sid_size = 0;
1293 unsigned int group_count = 0;
1294 const struct group *group;
1296 LIST_FOR_EACH_ENTRY( group, &token->groups, const struct group, entry )
1298 group_count++;
1299 sid_size += security_sid_len( &group->sid );
1301 size_needed += sid_size;
1302 /* attributes size */
1303 size_needed += sizeof(unsigned int) * group_count;
1305 /* reply buffer contains size_needed bytes formatted as:
1307 unsigned int count;
1308 unsigned int attrib[count];
1309 char sid_data[];
1311 user_len includes extra data needed for TOKEN_GROUPS representation,
1312 required caller buffer size calculated here to avoid extra server call */
1313 reply->user_len = FIELD_OFFSET( TOKEN_GROUPS, Groups[group_count] ) + sid_size;
1315 if (reply->user_len <= get_reply_max_size())
1317 struct token_groups *tg = set_reply_data_size( size_needed );
1318 if (tg)
1320 unsigned int *attr_ptr = (unsigned int *)(tg + 1);
1321 SID *sid_ptr = (SID *)(attr_ptr + group_count);
1323 tg->count = group_count;
1325 LIST_FOR_EACH_ENTRY( group, &token->groups, const struct group, entry )
1328 *attr_ptr = 0;
1329 if (group->mandatory) *attr_ptr |= SE_GROUP_MANDATORY;
1330 if (group->def) *attr_ptr |= SE_GROUP_ENABLED_BY_DEFAULT;
1331 if (group->enabled) *attr_ptr |= SE_GROUP_ENABLED;
1332 if (group->owner) *attr_ptr |= SE_GROUP_OWNER;
1333 if (group->deny_only) *attr_ptr |= SE_GROUP_USE_FOR_DENY_ONLY;
1334 if (group->resource) *attr_ptr |= SE_GROUP_RESOURCE;
1335 if (group->logon) *attr_ptr |= SE_GROUP_LOGON_ID;
1337 memcpy(sid_ptr, &group->sid, security_sid_len( &group->sid ));
1339 sid_ptr = (SID *)((char *)sid_ptr + security_sid_len( &group->sid ));
1340 attr_ptr++;
1344 else set_error( STATUS_BUFFER_TOO_SMALL );
1346 release_object( token );
1350 DECL_HANDLER(get_token_impersonation_level)
1352 struct token *token;
1354 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1355 TOKEN_QUERY,
1356 &token_ops )))
1358 if (token->primary)
1359 set_error( STATUS_INVALID_PARAMETER );
1360 else
1361 reply->impersonation_level = token->impersonation_level;
1363 release_object( token );
1367 DECL_HANDLER(get_token_statistics)
1369 struct token *token;
1371 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1372 TOKEN_QUERY,
1373 &token_ops )))
1375 reply->token_id = token->token_id;
1376 reply->modified_id = token->modified_id;
1377 reply->primary = token->primary;
1378 reply->impersonation_level = token->impersonation_level;
1379 reply->group_count = list_count( &token->groups );
1380 reply->privilege_count = list_count( &token->privileges );
1382 release_object( token );
1386 DECL_HANDLER(get_token_default_dacl)
1388 struct token *token;
1390 reply->acl_len = 0;
1392 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1393 TOKEN_QUERY,
1394 &token_ops )))
1396 if (token->default_dacl)
1397 reply->acl_len = token->default_dacl->AclSize;
1399 if (reply->acl_len <= get_reply_max_size())
1401 ACL *acl_reply = set_reply_data_size( reply->acl_len );
1402 if (acl_reply)
1403 memcpy( acl_reply, token->default_dacl, reply->acl_len );
1405 else set_error( STATUS_BUFFER_TOO_SMALL );
1407 release_object( token );
1411 DECL_HANDLER(set_token_default_dacl)
1413 struct token *token;
1415 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1416 TOKEN_ADJUST_DEFAULT,
1417 &token_ops )))
1419 const ACL *acl = get_req_data();
1420 unsigned int acl_size = get_req_data_size();
1422 free( token->default_dacl );
1423 token->default_dacl = NULL;
1425 if (acl_size)
1426 token->default_dacl = memdup( acl, acl_size );
1428 release_object( token );