msxml3: For queries the get_item should change the current position.
[wine/winequartzdrv.git] / server / token.c
blob9472cf520186865c8f14ecd81b62769f87634ac8
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>
30 #include "ntstatus.h"
31 #define WIN32_NO_STATUS
32 #include "windef.h"
33 #include "winternl.h"
35 #include "handle.h"
36 #include "thread.h"
37 #include "process.h"
38 #include "request.h"
39 #include "security.h"
41 #include "wine/unicode.h"
43 #define MAX_SUBAUTH_COUNT 1
45 const LUID SeIncreaseQuotaPrivilege = { 5, 0 };
46 const LUID SeSecurityPrivilege = { 8, 0 };
47 const LUID SeTakeOwnershipPrivilege = { 9, 0 };
48 const LUID SeLoadDriverPrivilege = { 10, 0 };
49 const LUID SeSystemProfilePrivilege = { 11, 0 };
50 const LUID SeSystemtimePrivilege = { 12, 0 };
51 const LUID SeProfileSingleProcessPrivilege = { 13, 0 };
52 const LUID SeIncreaseBasePriorityPrivilege = { 14, 0 };
53 const LUID SeCreatePagefilePrivilege = { 15, 0 };
54 const LUID SeBackupPrivilege = { 17, 0 };
55 const LUID SeRestorePrivilege = { 18, 0 };
56 const LUID SeShutdownPrivilege = { 19, 0 };
57 const LUID SeDebugPrivilege = { 20, 0 };
58 const LUID SeSystemEnvironmentPrivilege = { 22, 0 };
59 const LUID SeChangeNotifyPrivilege = { 23, 0 };
60 const LUID SeRemoteShutdownPrivilege = { 24, 0 };
61 const LUID SeUndockPrivilege = { 25, 0 };
62 const LUID SeManageVolumePrivilege = { 28, 0 };
63 const LUID SeImpersonatePrivilege = { 29, 0 };
64 const LUID SeCreateGlobalPrivilege = { 30, 0 };
66 static const SID world_sid = { SID_REVISION, 1, { SECURITY_WORLD_SID_AUTHORITY }, { SECURITY_WORLD_RID } };
67 static const SID local_sid = { SID_REVISION, 1, { SECURITY_LOCAL_SID_AUTHORITY }, { SECURITY_LOCAL_RID } };
68 static const SID interactive_sid = { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_INTERACTIVE_RID } };
69 static const SID authenticated_user_sid = { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_AUTHENTICATED_USER_RID } };
70 static const SID local_system_sid = { SID_REVISION, 1, { SECURITY_NT_AUTHORITY }, { SECURITY_LOCAL_SYSTEM_RID } };
71 static const PSID security_world_sid = (PSID)&world_sid;
72 static const PSID security_local_sid = (PSID)&local_sid;
73 const PSID security_interactive_sid = (PSID)&interactive_sid;
74 static const PSID security_authenticated_user_sid = (PSID)&authenticated_user_sid;
75 static const PSID security_local_system_sid = (PSID)&local_system_sid;
77 static luid_t prev_luid_value = { 1000, 0 };
79 struct token
81 struct object obj; /* object header */
82 luid_t token_id; /* system-unique id of token */
83 luid_t modified_id; /* new id allocated every time token is modified */
84 struct list privileges; /* privileges available to the token */
85 struct list groups; /* groups that the user of this token belongs to (sid_and_attributes) */
86 SID *user; /* SID of user this token represents */
87 SID *primary_group; /* SID of user's primary group */
88 unsigned primary; /* is this a primary or impersonation token? */
89 ACL *default_dacl; /* the default DACL to assign to objects created by this user */
90 TOKEN_SOURCE source; /* source of the token */
91 SECURITY_IMPERSONATION_LEVEL impersonation_level; /* impersonation level this token is capable of if non-primary token */
94 struct privilege
96 struct list entry;
97 LUID luid;
98 unsigned enabled : 1; /* is the privilege currently enabled? */
99 unsigned def : 1; /* is the privilege enabled by default? */
102 struct group
104 struct list entry;
105 unsigned enabled : 1; /* is the sid currently enabled? */
106 unsigned def : 1; /* is the sid enabled by default? */
107 unsigned logon : 1; /* is this a logon sid? */
108 unsigned mandatory: 1; /* is this sid always enabled? */
109 unsigned owner : 1; /* can this sid be an owner of an object? */
110 unsigned resource : 1; /* is this a domain-local group? */
111 unsigned deny_only: 1; /* is this a sid that should be use for denying only? */
112 SID sid;
115 static void token_dump( struct object *obj, int verbose );
116 static unsigned int token_map_access( struct object *obj, unsigned int access );
117 static void token_destroy( struct object *obj );
119 static const struct object_ops token_ops =
121 sizeof(struct token), /* size */
122 token_dump, /* dump */
123 no_add_queue, /* add_queue */
124 NULL, /* remove_queue */
125 NULL, /* signaled */
126 NULL, /* satisfied */
127 no_signal, /* signal */
128 no_get_fd, /* get_fd */
129 token_map_access, /* map_access */
130 no_lookup_name, /* lookup_name */
131 no_open_file, /* open_file */
132 no_close_handle, /* close_handle */
133 token_destroy /* destroy */
137 static void token_dump( struct object *obj, int verbose )
139 fprintf( stderr, "Security token\n" );
140 /* FIXME: dump token members */
143 static unsigned int token_map_access( struct object *obj, unsigned int access )
145 if (access & GENERIC_READ) access |= TOKEN_READ;
146 if (access & GENERIC_WRITE) access |= TOKEN_WRITE;
147 if (access & GENERIC_EXECUTE) access |= STANDARD_RIGHTS_EXECUTE;
148 if (access & GENERIC_ALL) access |= TOKEN_ALL_ACCESS;
149 return access & ~(GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | GENERIC_ALL);
152 static SID *security_sid_alloc( const SID_IDENTIFIER_AUTHORITY *idauthority, int subauthcount, const unsigned int subauth[] )
154 int i;
155 SID *sid = mem_alloc( FIELD_OFFSET(SID, SubAuthority[subauthcount]) );
156 if (!sid) return NULL;
157 sid->Revision = SID_REVISION;
158 sid->SubAuthorityCount = subauthcount;
159 sid->IdentifierAuthority = *idauthority;
160 for (i = 0; i < subauthcount; i++)
161 sid->SubAuthority[i] = subauth[i];
162 return sid;
165 static inline int security_equal_sid( const SID *sid1, const SID *sid2 )
167 return ((sid1->SubAuthorityCount == sid2->SubAuthorityCount) &&
168 !memcmp( sid1, sid2, FIELD_OFFSET(SID, SubAuthority[sid1->SubAuthorityCount]) ));
171 void security_set_thread_token( struct thread *thread, obj_handle_t handle )
173 if (!handle)
175 if (thread->token)
176 release_object( thread->token );
177 thread->token = NULL;
179 else
181 struct token *token = (struct token *)get_handle_obj( current->process,
182 handle,
183 TOKEN_IMPERSONATE,
184 &token_ops );
185 if (token)
187 if (thread->token)
188 release_object( thread->token );
189 thread->token = token;
194 static const ACE_HEADER *ace_next( const ACE_HEADER *ace )
196 return (const ACE_HEADER *)((const char *)ace + ace->AceSize);
199 static int acl_is_valid( const ACL *acl, data_size_t size )
201 ULONG i;
202 const ACE_HEADER *ace;
204 if (size < sizeof(ACL))
205 return FALSE;
207 size = min(size, MAX_ACL_LEN);
209 size -= sizeof(ACL);
211 ace = (const ACE_HEADER *)(acl + 1);
212 for (i = 0; i < acl->AceCount; i++)
214 const SID *sid;
215 data_size_t sid_size;
217 if (size < sizeof(ACE_HEADER))
218 return FALSE;
219 if (size < ace->AceSize)
220 return FALSE;
221 size -= ace->AceSize;
222 switch (ace->AceType)
224 case ACCESS_DENIED_ACE_TYPE:
225 sid = (const SID *)&((const ACCESS_DENIED_ACE *)ace)->SidStart;
226 sid_size = ace->AceSize - FIELD_OFFSET(ACCESS_DENIED_ACE, SidStart);
227 break;
228 case ACCESS_ALLOWED_ACE_TYPE:
229 sid = (const SID *)&((const ACCESS_ALLOWED_ACE *)ace)->SidStart;
230 sid_size = ace->AceSize - FIELD_OFFSET(ACCESS_ALLOWED_ACE, SidStart);
231 break;
232 case SYSTEM_AUDIT_ACE_TYPE:
233 sid = (const SID *)&((const SYSTEM_AUDIT_ACE *)ace)->SidStart;
234 sid_size = ace->AceSize - FIELD_OFFSET(SYSTEM_AUDIT_ACE, SidStart);
235 break;
236 case SYSTEM_ALARM_ACE_TYPE:
237 sid = (const SID *)&((const SYSTEM_ALARM_ACE *)ace)->SidStart;
238 sid_size = ace->AceSize - FIELD_OFFSET(SYSTEM_ALARM_ACE, SidStart);
239 break;
240 default:
241 return FALSE;
243 if (sid_size < FIELD_OFFSET(SID, SubAuthority[0]) ||
244 sid_size < FIELD_OFFSET(SID, SubAuthority[sid->SubAuthorityCount]))
245 return FALSE;
246 ace = ace_next( ace );
248 return TRUE;
251 /* gets the discretionary access control list from a security descriptor */
252 static inline const ACL *sd_get_dacl( const struct security_descriptor *sd, int *present )
254 *present = (sd->control & SE_DACL_PRESENT ? TRUE : FALSE);
256 if (sd->dacl_len)
257 return (const ACL *)((const char *)(sd + 1) +
258 sd->owner_len + sd->group_len + sd->sacl_len);
259 else
260 return NULL;
263 /* gets the system access control list from a security descriptor */
264 static inline const ACL *sd_get_sacl( const struct security_descriptor *sd, int *present )
266 *present = (sd->control & SE_SACL_PRESENT ? TRUE : FALSE);
268 if (sd->sacl_len)
269 return (const ACL *)((const char *)(sd + 1) +
270 sd->owner_len + sd->group_len);
271 else
272 return NULL;
275 /* gets the owner from a security descriptor */
276 static inline const SID *sd_get_owner( const struct security_descriptor *sd )
278 if (sd->owner_len)
279 return (const SID *)(sd + 1);
280 else
281 return NULL;
284 /* gets the primary group from a security descriptor */
285 static inline const SID *sd_get_group( const struct security_descriptor *sd )
287 if (sd->group_len)
288 return (const SID *)((const char *)(sd + 1) + sd->owner_len);
289 else
290 return NULL;
293 /* checks whether all members of a security descriptor fit inside the size
294 * of memory specified */
295 static int sd_is_valid( const struct security_descriptor *sd, data_size_t size )
297 size_t offset = sizeof(struct security_descriptor);
298 const SID *group;
299 const SID *owner;
300 const ACL *sacl;
301 const ACL *dacl;
302 int dummy;
304 if (size < offset)
305 return FALSE;
307 if ((sd->owner_len >= FIELD_OFFSET(SID, SubAuthority[255])) ||
308 (offset + sd->owner_len > size))
309 return FALSE;
310 owner = sd_get_owner( sd );
311 if (owner)
313 size_t needed_size = FIELD_OFFSET(SID, SubAuthority[owner->SubAuthorityCount]);
314 if ((sd->owner_len < sizeof(SID)) || (needed_size > sd->owner_len))
315 return FALSE;
317 offset += sd->owner_len;
319 if ((sd->group_len >= FIELD_OFFSET(SID, SubAuthority[255])) ||
320 (offset + sd->group_len > size))
321 return FALSE;
322 group = sd_get_group( sd );
323 if (group)
325 size_t needed_size = FIELD_OFFSET(SID, SubAuthority[group->SubAuthorityCount]);
326 if ((sd->group_len < sizeof(SID)) || (needed_size > sd->group_len))
327 return FALSE;
329 offset += sd->group_len;
331 if ((sd->sacl_len >= MAX_ACL_LEN) || (offset + sd->sacl_len > size))
332 return FALSE;
333 sacl = sd_get_sacl( sd, &dummy );
334 if (sacl && !acl_is_valid( sacl, sd->sacl_len ))
335 return FALSE;
336 offset += sd->sacl_len;
338 if ((sd->dacl_len >= MAX_ACL_LEN) || (offset + sd->dacl_len > size))
339 return FALSE;
340 dacl = sd_get_dacl( sd, &dummy );
341 if (dacl && !acl_is_valid( dacl, sd->dacl_len ))
342 return FALSE;
343 offset += sd->dacl_len;
345 return TRUE;
348 /* maps from generic rights to specific rights as given by a mapping */
349 static inline void map_generic_mask(unsigned int *mask, const GENERIC_MAPPING *mapping)
351 if (*mask & GENERIC_READ) *mask |= mapping->GenericRead;
352 if (*mask & GENERIC_WRITE) *mask |= mapping->GenericWrite;
353 if (*mask & GENERIC_EXECUTE) *mask |= mapping->GenericExecute;
354 if (*mask & GENERIC_ALL) *mask |= mapping->GenericAll;
355 *mask &= 0x0FFFFFFF;
358 static inline int is_equal_luid( const LUID *luid1, const LUID *luid2 )
360 return (luid1->LowPart == luid2->LowPart && luid1->HighPart == luid2->HighPart);
363 static inline void allocate_luid( luid_t *luid )
365 prev_luid_value.low_part++;
366 *luid = prev_luid_value;
369 DECL_HANDLER( allocate_locally_unique_id )
371 allocate_luid( &reply->luid );
374 static inline void luid_and_attr_from_privilege( LUID_AND_ATTRIBUTES *out, const struct privilege *in)
376 out->Luid = in->luid;
377 out->Attributes =
378 (in->enabled ? SE_PRIVILEGE_ENABLED : 0) |
379 (in->def ? SE_PRIVILEGE_ENABLED_BY_DEFAULT : 0);
382 static struct privilege *privilege_add( struct token *token, const LUID *luid, int enabled )
384 struct privilege *privilege = mem_alloc( sizeof(*privilege) );
385 if (privilege)
387 privilege->luid = *luid;
388 privilege->def = privilege->enabled = (enabled != 0);
389 list_add_tail( &token->privileges, &privilege->entry );
391 return privilege;
394 static inline void privilege_remove( struct privilege *privilege )
396 list_remove( &privilege->entry );
397 free( privilege );
400 static void token_destroy( struct object *obj )
402 struct token* token;
403 struct list *cursor, *cursor_next;
405 assert( obj->ops == &token_ops );
406 token = (struct token *)obj;
408 free( token->user );
410 LIST_FOR_EACH_SAFE( cursor, cursor_next, &token->privileges )
412 struct privilege *privilege = LIST_ENTRY( cursor, struct privilege, entry );
413 privilege_remove( privilege );
416 LIST_FOR_EACH_SAFE( cursor, cursor_next, &token->groups )
418 struct group *group = LIST_ENTRY( cursor, struct group, entry );
419 list_remove( &group->entry );
420 free( group );
423 free( token->default_dacl );
426 /* creates a new token.
427 * groups may be NULL if group_count is 0.
428 * privs may be NULL if priv_count is 0.
429 * default_dacl may be NULL, indicating that all objects created by the user
430 * are unsecured.
431 * modified_id may be NULL, indicating that a new modified_id luid should be
432 * allocated.
434 static struct token *create_token( unsigned primary, const SID *user,
435 const SID_AND_ATTRIBUTES *groups, unsigned int group_count,
436 const LUID_AND_ATTRIBUTES *privs, unsigned int priv_count,
437 const ACL *default_dacl, TOKEN_SOURCE source,
438 const luid_t *modified_id,
439 SECURITY_IMPERSONATION_LEVEL impersonation_level )
441 struct token *token = alloc_object( &token_ops );
442 if (token)
444 unsigned int i;
446 allocate_luid( &token->token_id );
447 if (modified_id)
448 token->modified_id = *modified_id;
449 else
450 allocate_luid( &token->modified_id );
451 list_init( &token->privileges );
452 list_init( &token->groups );
453 token->primary = primary;
454 /* primary tokens don't have impersonation levels */
455 if (primary)
456 token->impersonation_level = -1;
457 else
458 token->impersonation_level = impersonation_level;
459 token->default_dacl = NULL;
460 token->primary_group = NULL;
462 /* copy user */
463 token->user = memdup( user, FIELD_OFFSET(SID, SubAuthority[user->SubAuthorityCount]) );
464 if (!token->user)
466 release_object( token );
467 return NULL;
470 /* copy groups */
471 for (i = 0; i < group_count; i++)
473 size_t size = FIELD_OFFSET( struct group, sid.SubAuthority[((const SID *)groups[i].Sid)->SubAuthorityCount] );
474 struct group *group = mem_alloc( size );
476 if (!group)
478 release_object( token );
479 return NULL;
481 memcpy( &group->sid, groups[i].Sid, FIELD_OFFSET( SID, SubAuthority[((const SID *)groups[i].Sid)->SubAuthorityCount] ) );
482 group->enabled = TRUE;
483 group->def = TRUE;
484 group->logon = FALSE;
485 group->mandatory = (groups[i].Attributes & SE_GROUP_MANDATORY) ? TRUE : FALSE;
486 group->owner = groups[i].Attributes & SE_GROUP_OWNER ? TRUE : FALSE;
487 group->resource = FALSE;
488 group->deny_only = FALSE;
489 list_add_tail( &token->groups, &group->entry );
490 /* Use first owner capable group as an owner */
491 if (!token->primary_group && group->owner)
492 token->primary_group = &group->sid;
495 /* copy privileges */
496 for (i = 0; i < priv_count; i++)
498 /* note: we don't check uniqueness: the caller must make sure
499 * privs doesn't contain any duplicate luids */
500 if (!privilege_add( token, &privs[i].Luid,
501 privs[i].Attributes & SE_PRIVILEGE_ENABLED ))
503 release_object( token );
504 return NULL;
508 if (default_dacl)
510 token->default_dacl = memdup( default_dacl, default_dacl->AclSize );
511 if (!token->default_dacl)
513 release_object( token );
514 return NULL;
518 token->source = source;
520 return token;
523 static ACL *create_default_dacl( const SID *user )
525 ACCESS_ALLOWED_ACE *aaa;
526 ACL *default_dacl;
527 SID *sid;
528 size_t default_dacl_size = sizeof(ACL) +
529 2*(sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD)) +
530 sizeof(local_system_sid) +
531 FIELD_OFFSET(SID, SubAuthority[user->SubAuthorityCount]);
533 default_dacl = mem_alloc( default_dacl_size );
534 if (!default_dacl) return NULL;
536 default_dacl->AclRevision = MAX_ACL_REVISION;
537 default_dacl->Sbz1 = 0;
538 default_dacl->AclSize = default_dacl_size;
539 default_dacl->AceCount = 2;
540 default_dacl->Sbz2 = 0;
542 /* GENERIC_ALL for Local System */
543 aaa = (ACCESS_ALLOWED_ACE *)(default_dacl + 1);
544 aaa->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
545 aaa->Header.AceFlags = 0;
546 aaa->Header.AceSize = (sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD)) +
547 sizeof(local_system_sid);
548 aaa->Mask = GENERIC_ALL;
549 sid = (SID *)&aaa->SidStart;
550 memcpy( sid, &local_system_sid, sizeof(local_system_sid) );
552 /* GENERIC_ALL for specified user */
553 aaa = (ACCESS_ALLOWED_ACE *)((char *)aaa + aaa->Header.AceSize);
554 aaa->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
555 aaa->Header.AceFlags = 0;
556 aaa->Header.AceSize = (sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD)) +
557 FIELD_OFFSET( SID, SubAuthority[user->SubAuthorityCount] );
558 aaa->Mask = GENERIC_ALL;
559 sid = (SID *)&aaa->SidStart;
560 memcpy( sid, user, FIELD_OFFSET(SID, SubAuthority[user->SubAuthorityCount]) );
562 return default_dacl;
565 struct sid_data
567 SID_IDENTIFIER_AUTHORITY idauth;
568 int count;
569 unsigned int subauth[MAX_SUBAUTH_COUNT];
572 struct token *token_create_admin( void )
574 struct token *token = NULL;
575 static const SID_IDENTIFIER_AUTHORITY nt_authority = { SECURITY_NT_AUTHORITY };
576 static const unsigned int alias_admins_subauth[] = { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS };
577 static const unsigned int alias_users_subauth[] = { SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_USERS };
578 /* on Windows, this value changes every time the user logs on */
579 static const unsigned int logon_subauth[] = { SECURITY_LOGON_IDS_RID, 0, 1 /* FIXME: should be randomly generated when tokens are inherited by new processes */ };
580 PSID alias_admins_sid;
581 PSID alias_users_sid;
582 PSID logon_sid;
583 /* note: should be the owner specified in the token */
584 ACL *default_dacl = create_default_dacl( &interactive_sid );
586 alias_admins_sid = security_sid_alloc( &nt_authority, sizeof(alias_admins_subauth)/sizeof(alias_admins_subauth[0]),
587 alias_admins_subauth );
588 alias_users_sid = security_sid_alloc( &nt_authority, sizeof(alias_users_subauth)/sizeof(alias_users_subauth[0]),
589 alias_users_subauth );
590 logon_sid = security_sid_alloc( &nt_authority, sizeof(logon_subauth)/sizeof(logon_subauth[0]),
591 logon_subauth );
593 if (alias_admins_sid && alias_users_sid && logon_sid && default_dacl)
595 const LUID_AND_ATTRIBUTES admin_privs[] =
597 { SeChangeNotifyPrivilege , SE_PRIVILEGE_ENABLED },
598 { SeSecurityPrivilege , 0 },
599 { SeBackupPrivilege , 0 },
600 { SeRestorePrivilege , 0 },
601 { SeSystemtimePrivilege , 0 },
602 { SeShutdownPrivilege , 0 },
603 { SeRemoteShutdownPrivilege , 0 },
604 { SeTakeOwnershipPrivilege , 0 },
605 { SeDebugPrivilege , 0 },
606 { SeSystemEnvironmentPrivilege , 0 },
607 { SeSystemProfilePrivilege , 0 },
608 { SeProfileSingleProcessPrivilege, 0 },
609 { SeIncreaseBasePriorityPrivilege, 0 },
610 { SeLoadDriverPrivilege , 0 },
611 { SeCreatePagefilePrivilege , 0 },
612 { SeIncreaseQuotaPrivilege , 0 },
613 { SeUndockPrivilege , 0 },
614 { SeManageVolumePrivilege , 0 },
615 { SeImpersonatePrivilege , SE_PRIVILEGE_ENABLED },
616 { SeCreateGlobalPrivilege , SE_PRIVILEGE_ENABLED },
618 /* note: we don't include non-builtin groups here for the user -
619 * telling us these is the job of a client-side program */
620 const SID_AND_ATTRIBUTES admin_groups[] =
622 { security_world_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY },
623 { security_local_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY },
624 { security_interactive_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY },
625 { security_authenticated_user_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY },
626 { alias_admins_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY|SE_GROUP_OWNER },
627 { alias_users_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY },
628 { logon_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY|SE_GROUP_LOGON_ID },
630 static const TOKEN_SOURCE admin_source = {"SeMgr", {0, 0}};
631 /* note: we just set the user sid to be the interactive builtin sid -
632 * we should really translate the UNIX user id to a sid */
633 token = create_token( TRUE, &interactive_sid,
634 admin_groups, sizeof(admin_groups)/sizeof(admin_groups[0]),
635 admin_privs, sizeof(admin_privs)/sizeof(admin_privs[0]),
636 default_dacl, admin_source, NULL, -1 );
637 /* we really need a primary group */
638 assert( token->primary_group );
641 free( logon_sid );
642 free( alias_admins_sid );
643 free( alias_users_sid );
644 free( default_dacl );
646 return token;
649 static struct privilege *token_find_privilege( struct token *token, const LUID *luid, int enabled_only )
651 struct privilege *privilege;
652 LIST_FOR_EACH_ENTRY( privilege, &token->privileges, struct privilege, entry )
654 if (is_equal_luid( luid, &privilege->luid ))
656 if (enabled_only && !privilege->enabled)
657 return NULL;
658 return privilege;
661 return NULL;
664 static unsigned int token_adjust_privileges( struct token *token, const LUID_AND_ATTRIBUTES *privs,
665 unsigned int count, LUID_AND_ATTRIBUTES *mod_privs,
666 unsigned int mod_privs_count )
668 unsigned int i, modified_count = 0;
670 /* mark as modified */
671 allocate_luid( &token->modified_id );
673 for (i = 0; i < count; i++)
675 struct privilege *privilege =
676 token_find_privilege( token, &privs[i].Luid, FALSE );
677 if (!privilege)
679 set_error( STATUS_NOT_ALL_ASSIGNED );
680 continue;
683 if (privs[i].Attributes & SE_PRIVILEGE_REMOVE)
684 privilege_remove( privilege );
685 else
687 /* save previous state for caller */
688 if (mod_privs_count)
690 luid_and_attr_from_privilege(mod_privs, privilege);
691 mod_privs++;
692 mod_privs_count--;
693 modified_count++;
696 if (privs[i].Attributes & SE_PRIVILEGE_ENABLED)
697 privilege->enabled = TRUE;
698 else
699 privilege->enabled = FALSE;
702 return modified_count;
705 static void token_disable_privileges( struct token *token )
707 struct privilege *privilege;
709 /* mark as modified */
710 allocate_luid( &token->modified_id );
712 LIST_FOR_EACH_ENTRY( privilege, &token->privileges, struct privilege, entry )
713 privilege->enabled = FALSE;
716 int token_check_privileges( struct token *token, int all_required,
717 const LUID_AND_ATTRIBUTES *reqprivs,
718 unsigned int count, LUID_AND_ATTRIBUTES *usedprivs)
720 unsigned int i, enabled_count = 0;
722 for (i = 0; i < count; i++)
724 struct privilege *privilege =
725 token_find_privilege( token, &reqprivs[i].Luid, TRUE );
727 if (usedprivs)
728 usedprivs[i] = reqprivs[i];
730 if (privilege && privilege->enabled)
732 enabled_count++;
733 if (usedprivs)
734 usedprivs[i].Attributes |= SE_PRIVILEGE_USED_FOR_ACCESS;
738 if (all_required)
739 return (enabled_count == count);
740 else
741 return (enabled_count > 0);
744 static int token_sid_present( struct token *token, const SID *sid, int deny )
746 struct group *group;
748 if (security_equal_sid( token->user, sid )) return TRUE;
750 LIST_FOR_EACH_ENTRY( group, &token->groups, struct group, entry )
752 if (!group->enabled) continue;
753 if (group->deny_only && !deny) continue;
755 if (security_equal_sid( &group->sid, sid )) return TRUE;
758 return FALSE;
761 /* Checks access to a security descriptor. 'sd' must have been validated by
762 * caller. It returns STATUS_SUCCESS if call succeeded or an error indicating
763 * the reason. 'status' parameter will indicate if access is granted or denied.
765 * If both returned value and 'status' are STATUS_SUCCESS then access is granted.
767 static unsigned int token_access_check( struct token *token,
768 const struct security_descriptor *sd,
769 unsigned int desired_access,
770 LUID_AND_ATTRIBUTES *privs,
771 unsigned int *priv_count,
772 const GENERIC_MAPPING *mapping,
773 unsigned int *granted_access,
774 unsigned int *status )
776 unsigned int current_access = 0;
777 unsigned int denied_access = 0;
778 ULONG i;
779 const ACL *dacl;
780 int dacl_present;
781 const ACE_HEADER *ace;
782 const SID *owner;
784 /* assume no access rights */
785 *granted_access = 0;
787 /* fail if desired_access contains generic rights */
788 if (desired_access & (GENERIC_READ|GENERIC_WRITE|GENERIC_EXECUTE|GENERIC_ALL))
790 *priv_count = 0;
791 return STATUS_GENERIC_NOT_MAPPED;
794 dacl = sd_get_dacl( sd, &dacl_present );
795 owner = sd_get_owner( sd );
796 if (!owner || !sd_get_group( sd ))
798 *priv_count = 0;
799 return STATUS_INVALID_SECURITY_DESCR;
802 /* 1: Grant desired access if the object is unprotected */
803 if (!dacl_present)
805 *priv_count = 0;
806 *granted_access = desired_access;
807 return *status = STATUS_SUCCESS;
809 if (!dacl)
811 *priv_count = 0;
812 *status = STATUS_ACCESS_DENIED;
813 return STATUS_SUCCESS;
816 /* 2: Check if caller wants access to system security part. Note: access
817 * is only granted if specifically asked for */
818 if (desired_access & ACCESS_SYSTEM_SECURITY)
820 const LUID_AND_ATTRIBUTES security_priv = { SeSecurityPrivilege, 0 };
821 LUID_AND_ATTRIBUTES retpriv = security_priv;
822 if (token_check_privileges( token, TRUE, &security_priv, 1, &retpriv ))
824 if (priv_count)
826 /* assumes that there will only be one privilege to return */
827 if (*priv_count >= 1)
829 *priv_count = 1;
830 *privs = retpriv;
832 else
834 *priv_count = 1;
835 return STATUS_BUFFER_TOO_SMALL;
838 current_access |= ACCESS_SYSTEM_SECURITY;
839 if (desired_access == current_access)
841 *granted_access = current_access;
842 return *status = STATUS_SUCCESS;
845 else
847 *priv_count = 0;
848 *status = STATUS_PRIVILEGE_NOT_HELD;
849 return STATUS_SUCCESS;
852 else if (priv_count) *priv_count = 0;
854 /* 3: Check whether the token is the owner */
855 /* NOTE: SeTakeOwnershipPrivilege is not checked for here - it is instead
856 * checked when a "set owner" call is made, overriding the access rights
857 * determined here. */
858 if (token_sid_present( token, owner, FALSE ))
860 current_access |= (READ_CONTROL | WRITE_DAC);
861 if (desired_access == current_access)
863 *granted_access = current_access;
864 return *status = STATUS_SUCCESS;
868 /* 4: Grant rights according to the DACL */
869 ace = (const ACE_HEADER *)(dacl + 1);
870 for (i = 0; i < dacl->AceCount; i++)
872 const ACCESS_ALLOWED_ACE *aa_ace;
873 const ACCESS_DENIED_ACE *ad_ace;
874 const SID *sid;
875 switch (ace->AceType)
877 case ACCESS_DENIED_ACE_TYPE:
878 ad_ace = (const ACCESS_DENIED_ACE *)ace;
879 sid = (const SID *)&ad_ace->SidStart;
880 if (token_sid_present( token, sid, TRUE ))
882 unsigned int access = ad_ace->Mask;
883 map_generic_mask(&access, mapping);
884 if (desired_access & MAXIMUM_ALLOWED)
885 denied_access |= access;
886 else
888 denied_access |= (access & ~current_access);
889 if (desired_access & access) goto done;
892 break;
893 case ACCESS_ALLOWED_ACE_TYPE:
894 aa_ace = (const ACCESS_ALLOWED_ACE *)ace;
895 sid = (const SID *)&aa_ace->SidStart;
896 if (token_sid_present( token, sid, FALSE ))
898 unsigned int access = aa_ace->Mask;
899 map_generic_mask(&access, mapping);
900 if (desired_access & MAXIMUM_ALLOWED)
901 current_access |= access;
902 else
903 current_access |= (access & ~denied_access);
905 break;
908 /* don't bother carrying on checking if we've already got all of
909 * rights we need */
910 if (desired_access == *granted_access)
911 break;
913 ace = ace_next( ace );
916 done:
917 if (desired_access & MAXIMUM_ALLOWED)
918 *granted_access = current_access & ~denied_access;
919 else
920 if ((current_access & desired_access) == desired_access)
921 *granted_access = current_access & desired_access;
922 else
923 *granted_access = 0;
925 *status = *granted_access ? STATUS_SUCCESS : STATUS_ACCESS_DENIED;
926 return STATUS_SUCCESS;
929 const ACL *token_get_default_dacl( struct token *token )
931 return token->default_dacl;
934 static void set_object_sd( struct object *obj, const struct security_descriptor *sd,
935 unsigned int set_info )
937 struct security_descriptor new_sd, *pnew_sd;
938 int present;
939 const SID *owner, *group;
940 const ACL *sacl, *dacl;
941 char *ptr;
943 if (!set_info) return;
945 new_sd.control = sd->control & ~SE_SELF_RELATIVE;
947 owner = sd_get_owner( sd );
948 if (set_info & OWNER_SECURITY_INFORMATION && owner)
949 new_sd.owner_len = sd->owner_len;
950 else
952 owner = current->process->token->user;
953 new_sd.owner_len = FIELD_OFFSET(SID, SubAuthority[owner->SubAuthorityCount]);
954 new_sd.control |= SE_OWNER_DEFAULTED;
957 group = sd_get_group( sd );
958 if (set_info & GROUP_SECURITY_INFORMATION && group)
959 new_sd.group_len = sd->group_len;
960 else
962 group = current->process->token->primary_group;
963 new_sd.group_len = FIELD_OFFSET(SID, SubAuthority[group->SubAuthorityCount]);
964 new_sd.control |= SE_GROUP_DEFAULTED;
967 new_sd.control |= SE_SACL_PRESENT;
968 sacl = sd_get_sacl( sd, &present );
969 if (set_info & SACL_SECURITY_INFORMATION && present)
970 new_sd.sacl_len = sd->sacl_len;
971 else
973 if (obj->sd) sacl = sd_get_sacl( obj->sd, &present );
975 if (obj->sd && present)
976 new_sd.sacl_len = obj->sd->sacl_len;
977 else
979 new_sd.sacl_len = 0;
980 new_sd.control |= SE_SACL_DEFAULTED;
984 new_sd.control |= SE_DACL_PRESENT;
985 dacl = sd_get_dacl( sd, &present );
986 if (set_info & DACL_SECURITY_INFORMATION && present)
987 new_sd.dacl_len = sd->dacl_len;
988 else
990 if (obj->sd) dacl = sd_get_dacl( obj->sd, &present );
992 if (obj->sd && present)
993 new_sd.dacl_len = obj->sd->dacl_len;
994 else
996 dacl = token_get_default_dacl( current->process->token );
997 new_sd.dacl_len = dacl->AclSize;
998 new_sd.control |= SE_DACL_DEFAULTED;
1002 ptr = mem_alloc( sizeof(new_sd) + new_sd.owner_len + new_sd.group_len +
1003 new_sd.sacl_len + new_sd.dacl_len );
1004 if (!ptr) return;
1005 pnew_sd = (struct security_descriptor*)ptr;
1007 memcpy( ptr, &new_sd, sizeof(new_sd) );
1008 ptr += sizeof(new_sd);
1009 memcpy( ptr, owner, new_sd.owner_len );
1010 ptr += new_sd.owner_len;
1011 memcpy( ptr, group, new_sd.group_len );
1012 ptr += new_sd.group_len;
1013 memcpy( ptr, sacl, new_sd.sacl_len );
1014 ptr += new_sd.sacl_len;
1015 memcpy( ptr, dacl, new_sd.dacl_len );
1017 free( obj->sd );
1018 obj->sd = pnew_sd;
1021 int check_object_access(struct object *obj, unsigned int *access)
1023 GENERIC_MAPPING mapping;
1024 struct token *token = current->token ? current->token : current->process->token;
1025 LUID_AND_ATTRIBUTES priv;
1026 unsigned int status, priv_count = 1;
1027 int res;
1029 mapping.GenericAll = obj->ops->map_access( obj, GENERIC_ALL );
1031 if (!obj->sd)
1033 if (*access & MAXIMUM_ALLOWED)
1034 *access = mapping.GenericAll;
1035 return TRUE;
1038 mapping.GenericRead = obj->ops->map_access( obj, GENERIC_READ );
1039 mapping.GenericWrite = obj->ops->map_access( obj, GENERIC_WRITE );
1040 mapping.GenericExecute = obj->ops->map_access( obj, GENERIC_EXECUTE );
1042 res = token_access_check( token, obj->sd, *access, &priv, &priv_count,
1043 &mapping, access, &status ) == STATUS_SUCCESS &&
1044 status == STATUS_SUCCESS;
1046 if (!res) set_error( STATUS_ACCESS_DENIED );
1047 return res;
1051 /* open a security token */
1052 DECL_HANDLER(open_token)
1054 if (req->flags & OPEN_TOKEN_THREAD)
1056 struct thread *thread = get_thread_from_handle( req->handle, 0 );
1057 if (thread)
1059 if (thread->token)
1061 if (thread->token->impersonation_level <= SecurityAnonymous)
1062 set_error( STATUS_CANT_OPEN_ANONYMOUS );
1063 else
1064 reply->token = alloc_handle( current->process, thread->token,
1065 req->access, req->attributes );
1067 else
1068 set_error( STATUS_NO_TOKEN );
1069 release_object( thread );
1072 else
1074 struct process *process = get_process_from_handle( req->handle, 0 );
1075 if (process)
1077 if (process->token)
1078 reply->token = alloc_handle( current->process, process->token, req->access,
1079 req->attributes );
1080 else
1081 set_error( STATUS_NO_TOKEN );
1082 release_object( process );
1087 /* adjust the privileges held by a token */
1088 DECL_HANDLER(adjust_token_privileges)
1090 struct token *token;
1091 unsigned int access = TOKEN_ADJUST_PRIVILEGES;
1093 if (req->get_modified_state) access |= TOKEN_QUERY;
1095 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1096 access, &token_ops )))
1098 const LUID_AND_ATTRIBUTES *privs = get_req_data();
1099 LUID_AND_ATTRIBUTES *modified_privs = NULL;
1100 unsigned int priv_count = get_req_data_size() / sizeof(LUID_AND_ATTRIBUTES);
1101 unsigned int modified_priv_count = 0;
1103 if (req->get_modified_state && !req->disable_all)
1105 unsigned int i;
1106 /* count modified privs */
1107 for (i = 0; i < priv_count; i++)
1109 struct privilege *privilege =
1110 token_find_privilege( token, &privs[i].Luid, FALSE );
1111 if (privilege && req->get_modified_state)
1112 modified_priv_count++;
1114 reply->len = modified_priv_count;
1115 modified_priv_count = min( modified_priv_count, get_reply_max_size() / sizeof(*modified_privs) );
1116 if (modified_priv_count)
1117 modified_privs = set_reply_data_size( modified_priv_count * sizeof(*modified_privs) );
1119 reply->len = modified_priv_count * sizeof(*modified_privs);
1121 if (req->disable_all)
1122 token_disable_privileges( token );
1123 else
1124 modified_priv_count = token_adjust_privileges( token, privs,
1125 priv_count, modified_privs, modified_priv_count );
1127 release_object( token );
1131 /* retrieves the list of privileges that may be held be the token */
1132 DECL_HANDLER(get_token_privileges)
1134 struct token *token;
1136 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1137 TOKEN_QUERY,
1138 &token_ops )))
1140 int priv_count = 0;
1141 LUID_AND_ATTRIBUTES *privs;
1142 struct privilege *privilege;
1144 LIST_FOR_EACH_ENTRY( privilege, &token->privileges, struct privilege, entry )
1145 priv_count++;
1147 reply->len = priv_count * sizeof(*privs);
1148 if (reply->len <= get_reply_max_size())
1150 privs = set_reply_data_size( priv_count * sizeof(*privs) );
1151 if (privs)
1153 int i = 0;
1154 LIST_FOR_EACH_ENTRY( privilege, &token->privileges, struct privilege, entry )
1156 luid_and_attr_from_privilege( &privs[i], privilege );
1157 i++;
1161 else
1162 set_error(STATUS_BUFFER_TOO_SMALL);
1164 release_object( token );
1168 /* creates a duplicate of the token */
1169 DECL_HANDLER(duplicate_token)
1171 struct token *src_token;
1173 if ((req->impersonation_level < SecurityAnonymous) ||
1174 (req->impersonation_level > SecurityDelegation))
1176 set_error( STATUS_BAD_IMPERSONATION_LEVEL );
1177 return;
1180 if ((src_token = (struct token *)get_handle_obj( current->process, req->handle,
1181 TOKEN_DUPLICATE,
1182 &token_ops )))
1184 const luid_t *modified_id =
1185 req->primary || (req->impersonation_level == src_token->impersonation_level) ?
1186 &src_token->modified_id : NULL;
1187 struct token *token = NULL;
1189 if (req->primary || (req->impersonation_level <= src_token->impersonation_level))
1190 token = create_token( req->primary, src_token->user, NULL, 0,
1191 NULL, 0, src_token->default_dacl,
1192 src_token->source, modified_id,
1193 req->impersonation_level );
1194 else set_error( STATUS_BAD_IMPERSONATION_LEVEL );
1196 if (token)
1198 struct privilege *privilege;
1199 struct group *group;
1200 unsigned int access;
1202 /* copy groups */
1203 LIST_FOR_EACH_ENTRY( group, &src_token->groups, struct group, entry )
1205 size_t size = FIELD_OFFSET( struct group, sid.SubAuthority[group->sid.SubAuthorityCount] );
1206 struct group *newgroup = mem_alloc( size );
1207 if (!newgroup)
1209 release_object( token );
1210 release_object( src_token );
1211 return;
1213 memcpy( newgroup, group, size );
1214 list_add_tail( &token->groups, &newgroup->entry );
1216 token->primary_group = src_token->primary_group;
1217 assert( token->primary_group );
1219 /* copy privileges */
1220 LIST_FOR_EACH_ENTRY( privilege, &src_token->privileges, struct privilege, entry )
1221 privilege_add( token, &privilege->luid, privilege->enabled );
1223 access = req->access;
1224 reply->new_handle = alloc_handle( current->process, token, access, req->attributes);
1225 release_object( token );
1227 release_object( src_token );
1231 /* checks the specified privileges are held by the token */
1232 DECL_HANDLER(check_token_privileges)
1234 struct token *token;
1236 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1237 TOKEN_QUERY,
1238 &token_ops )))
1240 unsigned int count = get_req_data_size() / sizeof(LUID_AND_ATTRIBUTES);
1242 if (!token->primary && token->impersonation_level <= SecurityAnonymous)
1243 set_error( STATUS_BAD_IMPERSONATION_LEVEL );
1244 else if (get_reply_max_size() >= count * sizeof(LUID_AND_ATTRIBUTES))
1246 LUID_AND_ATTRIBUTES *usedprivs = set_reply_data_size( count * sizeof(*usedprivs) );
1247 reply->has_privileges = token_check_privileges( token, req->all_required, get_req_data(), count, usedprivs );
1249 else
1250 set_error( STATUS_BUFFER_OVERFLOW );
1251 release_object( token );
1255 /* checks that a user represented by a token is allowed to access an object
1256 * represented by a security descriptor */
1257 DECL_HANDLER(access_check)
1259 data_size_t sd_size = get_req_data_size();
1260 const struct security_descriptor *sd = get_req_data();
1261 struct token *token;
1263 if (!sd_is_valid( sd, sd_size ))
1265 set_error( STATUS_ACCESS_VIOLATION );
1266 return;
1269 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1270 TOKEN_QUERY,
1271 &token_ops )))
1273 GENERIC_MAPPING mapping;
1274 unsigned int status;
1275 LUID_AND_ATTRIBUTES priv;
1276 unsigned int priv_count = 1;
1278 memset(&priv, 0, sizeof(priv));
1280 /* only impersonation tokens may be used with this function */
1281 if (token->primary)
1283 set_error( STATUS_NO_IMPERSONATION_TOKEN );
1284 release_object( token );
1285 return;
1287 /* anonymous impersonation tokens can't be used */
1288 if (token->impersonation_level <= SecurityAnonymous)
1290 set_error( STATUS_BAD_IMPERSONATION_LEVEL );
1291 release_object( token );
1292 return;
1295 mapping.GenericRead = req->mapping_read;
1296 mapping.GenericWrite = req->mapping_write;
1297 mapping.GenericExecute = req->mapping_execute;
1298 mapping.GenericAll = req->mapping_all;
1300 status = token_access_check(
1301 token, sd, req->desired_access, &priv, &priv_count, &mapping,
1302 &reply->access_granted, &reply->access_status );
1304 reply->privileges_len = priv_count*sizeof(LUID_AND_ATTRIBUTES);
1306 if ((priv_count > 0) && (reply->privileges_len <= get_reply_max_size()))
1308 LUID_AND_ATTRIBUTES *privs = set_reply_data_size( priv_count * sizeof(*privs) );
1309 memcpy( privs, &priv, sizeof(priv) );
1312 set_error( status );
1313 release_object( token );
1317 /* retrieves the SID of the user that the token represents */
1318 DECL_HANDLER(get_token_user)
1320 struct token *token;
1322 reply->user_len = 0;
1324 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1325 TOKEN_QUERY,
1326 &token_ops )))
1328 const SID *user = token->user;
1330 reply->user_len = FIELD_OFFSET(SID, SubAuthority[user->SubAuthorityCount]);
1331 if (reply->user_len <= get_reply_max_size())
1333 SID *user_reply = set_reply_data_size( reply->user_len );
1334 if (user_reply)
1335 memcpy( user_reply, user, reply->user_len );
1337 else set_error( STATUS_BUFFER_TOO_SMALL );
1339 release_object( token );
1343 /* retrieves the groups that the user represented by the token belongs to */
1344 DECL_HANDLER(get_token_groups)
1346 struct token *token;
1348 reply->user_len = 0;
1350 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1351 TOKEN_QUERY,
1352 &token_ops )))
1354 size_t size_needed = sizeof(struct token_groups);
1355 unsigned int group_count = 0;
1356 const struct group *group;
1358 LIST_FOR_EACH_ENTRY( group, &token->groups, const struct group, entry )
1360 group_count++;
1361 size_needed += FIELD_OFFSET(SID, SubAuthority[group->sid.SubAuthorityCount]);
1363 size_needed += sizeof(unsigned int) * group_count;
1365 reply->user_len = size_needed;
1367 if (size_needed <= get_reply_max_size())
1369 struct token_groups *tg = set_reply_data_size( size_needed );
1370 if (tg)
1372 unsigned int *attr_ptr = (unsigned int *)(tg + 1);
1373 SID *sid_ptr = (SID *)(attr_ptr + group_count);
1375 tg->count = group_count;
1377 LIST_FOR_EACH_ENTRY( group, &token->groups, const struct group, entry )
1380 *attr_ptr = 0;
1381 if (group->mandatory) *attr_ptr |= SE_GROUP_MANDATORY;
1382 if (group->def) *attr_ptr |= SE_GROUP_ENABLED_BY_DEFAULT;
1383 if (group->enabled) *attr_ptr |= SE_GROUP_ENABLED;
1384 if (group->owner) *attr_ptr |= SE_GROUP_OWNER;
1385 if (group->deny_only) *attr_ptr |= SE_GROUP_USE_FOR_DENY_ONLY;
1386 if (group->resource) *attr_ptr |= SE_GROUP_RESOURCE;
1388 memcpy(sid_ptr, &group->sid, FIELD_OFFSET(SID, SubAuthority[group->sid.SubAuthorityCount]));
1390 sid_ptr = (SID *)((char *)sid_ptr + FIELD_OFFSET(SID, SubAuthority[group->sid.SubAuthorityCount]));
1391 attr_ptr++;
1395 else set_error( STATUS_BUFFER_TOO_SMALL );
1397 release_object( token );
1401 DECL_HANDLER(get_token_impersonation_level)
1403 struct token *token;
1405 if ((token = (struct token *)get_handle_obj( current->process, req->handle,
1406 TOKEN_QUERY,
1407 &token_ops )))
1409 if (token->primary)
1410 set_error( STATUS_INVALID_PARAMETER );
1411 else
1412 reply->impersonation_level = token->impersonation_level;
1414 release_object( token );
1418 DECL_HANDLER(set_security_object)
1420 data_size_t sd_size = get_req_data_size();
1421 const struct security_descriptor *sd = get_req_data();
1422 struct object *obj;
1423 unsigned int access = 0;
1425 if (!sd_is_valid( sd, sd_size ))
1427 set_error( STATUS_ACCESS_VIOLATION );
1428 return;
1431 if (req->security_info & OWNER_SECURITY_INFORMATION ||
1432 req->security_info & GROUP_SECURITY_INFORMATION)
1433 access |= WRITE_OWNER;
1434 if (req->security_info & SACL_SECURITY_INFORMATION)
1435 access |= ACCESS_SYSTEM_SECURITY;
1436 if (req->security_info & DACL_SECURITY_INFORMATION)
1437 access |= WRITE_DAC;
1439 if (!(obj = get_handle_obj( current->process, req->handle, access, NULL ))) return;
1441 set_object_sd( obj, sd, req->security_info );
1442 release_object( obj );