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
31 #define WIN32_NO_STATUS
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 prev_luid_value
= { 1000, 0 };
81 struct object obj
; /* object header */
82 LUID token_id
; /* system-unique id of token */
83 LUID 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 */
98 unsigned enabled
: 1; /* is the privilege currently enabled? */
99 unsigned def
: 1; /* is the privilege enabled by default? */
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? */
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 */
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_close_handle
, /* close_handle */
132 token_destroy
/* destroy */
136 static void token_dump( struct object
*obj
, int verbose
)
138 fprintf( stderr
, "Security token\n" );
139 /* FIXME: dump token members */
142 static unsigned int token_map_access( struct object
*obj
, unsigned int access
)
144 if (access
& GENERIC_READ
) access
|= TOKEN_READ
;
145 if (access
& GENERIC_WRITE
) access
|= TOKEN_WRITE
;
146 if (access
& GENERIC_EXECUTE
) access
|= STANDARD_RIGHTS_EXECUTE
;
147 if (access
& GENERIC_ALL
) access
|= TOKEN_ALL_ACCESS
;
148 return access
& ~(GENERIC_READ
| GENERIC_WRITE
| GENERIC_EXECUTE
| GENERIC_ALL
);
151 static SID
*security_sid_alloc( const SID_IDENTIFIER_AUTHORITY
*idauthority
, int subauthcount
, const unsigned int subauth
[] )
154 SID
*sid
= mem_alloc( FIELD_OFFSET(SID
, SubAuthority
[subauthcount
]) );
155 if (!sid
) return NULL
;
156 sid
->Revision
= SID_REVISION
;
157 sid
->SubAuthorityCount
= subauthcount
;
158 sid
->IdentifierAuthority
= *idauthority
;
159 for (i
= 0; i
< subauthcount
; i
++)
160 sid
->SubAuthority
[i
] = subauth
[i
];
164 static inline int security_equal_sid( const SID
*sid1
, const SID
*sid2
)
166 return ((sid1
->SubAuthorityCount
== sid2
->SubAuthorityCount
) &&
167 !memcmp( sid1
, sid2
, FIELD_OFFSET(SID
, SubAuthority
[sid1
->SubAuthorityCount
]) ));
170 void security_set_thread_token( struct thread
*thread
, obj_handle_t handle
)
175 release_object( thread
->token
);
176 thread
->token
= NULL
;
180 struct token
*token
= (struct token
*)get_handle_obj( current
->process
,
187 release_object( thread
->token
);
188 thread
->token
= token
;
193 static const ACE_HEADER
*ace_next( const ACE_HEADER
*ace
)
195 return (const ACE_HEADER
*)((const char *)ace
+ ace
->AceSize
);
198 static int acl_is_valid( const ACL
*acl
, data_size_t size
)
201 const ACE_HEADER
*ace
;
203 if (size
< sizeof(ACL
))
206 size
= min(size
, MAX_ACL_LEN
);
210 ace
= (const ACE_HEADER
*)(acl
+ 1);
211 for (i
= 0; i
< acl
->AceCount
; i
++)
214 data_size_t sid_size
;
216 if (size
< sizeof(ACE_HEADER
))
218 if (size
< ace
->AceSize
)
220 size
-= ace
->AceSize
;
221 switch (ace
->AceType
)
223 case ACCESS_DENIED_ACE_TYPE
:
224 sid
= (const SID
*)&((const ACCESS_DENIED_ACE
*)ace
)->SidStart
;
225 sid_size
= ace
->AceSize
- FIELD_OFFSET(ACCESS_DENIED_ACE
, SidStart
);
227 case ACCESS_ALLOWED_ACE_TYPE
:
228 sid
= (const SID
*)&((const ACCESS_ALLOWED_ACE
*)ace
)->SidStart
;
229 sid_size
= ace
->AceSize
- FIELD_OFFSET(ACCESS_ALLOWED_ACE
, SidStart
);
231 case SYSTEM_AUDIT_ACE_TYPE
:
232 sid
= (const SID
*)&((const SYSTEM_AUDIT_ACE
*)ace
)->SidStart
;
233 sid_size
= ace
->AceSize
- FIELD_OFFSET(SYSTEM_AUDIT_ACE
, SidStart
);
235 case SYSTEM_ALARM_ACE_TYPE
:
236 sid
= (const SID
*)&((const SYSTEM_ALARM_ACE
*)ace
)->SidStart
;
237 sid_size
= ace
->AceSize
- FIELD_OFFSET(SYSTEM_ALARM_ACE
, SidStart
);
242 if (sid_size
< FIELD_OFFSET(SID
, SubAuthority
[0]) ||
243 sid_size
< FIELD_OFFSET(SID
, SubAuthority
[sid
->SubAuthorityCount
]))
245 ace
= ace_next( ace
);
250 /* gets the discretionary access control list from a security descriptor */
251 static inline const ACL
*sd_get_dacl( const struct security_descriptor
*sd
, int *present
)
253 *present
= (sd
->control
& SE_DACL_PRESENT
? TRUE
: FALSE
);
256 return (const ACL
*)((const char *)(sd
+ 1) +
257 sd
->owner_len
+ sd
->group_len
+ sd
->sacl_len
);
262 /* gets the system access control list from a security descriptor */
263 static inline const ACL
*sd_get_sacl( const struct security_descriptor
*sd
, int *present
)
265 *present
= (sd
->control
& SE_SACL_PRESENT
? TRUE
: FALSE
);
268 return (const ACL
*)((const char *)(sd
+ 1) +
269 sd
->owner_len
+ sd
->group_len
);
274 /* gets the owner from a security descriptor */
275 static inline const SID
*sd_get_owner( const struct security_descriptor
*sd
)
278 return (const SID
*)(sd
+ 1);
283 /* gets the primary group from a security descriptor */
284 static inline const SID
*sd_get_group( const struct security_descriptor
*sd
)
287 return (const SID
*)((const char *)(sd
+ 1) + sd
->owner_len
);
292 /* checks whether all members of a security descriptor fit inside the size
293 * of memory specified */
294 static int sd_is_valid( const struct security_descriptor
*sd
, data_size_t size
)
296 size_t offset
= sizeof(struct security_descriptor
);
306 if ((sd
->owner_len
>= FIELD_OFFSET(SID
, SubAuthority
[255])) ||
307 (offset
+ sd
->owner_len
> size
))
309 owner
= sd_get_owner( sd
);
312 size_t needed_size
= FIELD_OFFSET(SID
, SubAuthority
[owner
->SubAuthorityCount
]);
313 if ((sd
->owner_len
< sizeof(SID
)) || (needed_size
> sd
->owner_len
))
316 offset
+= sd
->owner_len
;
318 if ((sd
->group_len
>= FIELD_OFFSET(SID
, SubAuthority
[255])) ||
319 (offset
+ sd
->group_len
> size
))
321 group
= sd_get_group( sd
);
324 size_t needed_size
= FIELD_OFFSET(SID
, SubAuthority
[group
->SubAuthorityCount
]);
325 if ((sd
->group_len
< sizeof(SID
)) || (needed_size
> sd
->group_len
))
328 offset
+= sd
->group_len
;
330 if ((sd
->sacl_len
>= MAX_ACL_LEN
) || (offset
+ sd
->sacl_len
> size
))
332 sacl
= sd_get_sacl( sd
, &dummy
);
333 if (sacl
&& !acl_is_valid( sacl
, sd
->sacl_len
))
335 offset
+= sd
->sacl_len
;
337 if ((sd
->dacl_len
>= MAX_ACL_LEN
) || (offset
+ sd
->dacl_len
> size
))
339 dacl
= sd_get_dacl( sd
, &dummy
);
340 if (dacl
&& !acl_is_valid( dacl
, sd
->dacl_len
))
342 offset
+= sd
->dacl_len
;
347 /* maps from generic rights to specific rights as given by a mapping */
348 static inline void map_generic_mask(unsigned int *mask
, const GENERIC_MAPPING
*mapping
)
350 if (*mask
& GENERIC_READ
) *mask
|= mapping
->GenericRead
;
351 if (*mask
& GENERIC_WRITE
) *mask
|= mapping
->GenericWrite
;
352 if (*mask
& GENERIC_EXECUTE
) *mask
|= mapping
->GenericExecute
;
353 if (*mask
& GENERIC_ALL
) *mask
|= mapping
->GenericAll
;
357 static inline int is_equal_luid( const LUID
*luid1
, const LUID
*luid2
)
359 return (luid1
->LowPart
== luid2
->LowPart
&& luid1
->HighPart
== luid2
->HighPart
);
362 static inline void allocate_luid( LUID
*luid
)
364 prev_luid_value
.LowPart
++;
365 *luid
= prev_luid_value
;
368 DECL_HANDLER( allocate_locally_unique_id
)
372 allocate_luid( &luid
);
373 reply
->luid
.low_part
= luid
.LowPart
;
374 reply
->luid
.high_part
= luid
.HighPart
;
377 static inline void luid_and_attr_from_privilege( LUID_AND_ATTRIBUTES
*out
, const struct privilege
*in
)
379 out
->Luid
= in
->luid
;
381 (in
->enabled
? SE_PRIVILEGE_ENABLED
: 0) |
382 (in
->def
? SE_PRIVILEGE_ENABLED_BY_DEFAULT
: 0);
385 static struct privilege
*privilege_add( struct token
*token
, const LUID
*luid
, int enabled
)
387 struct privilege
*privilege
= mem_alloc( sizeof(*privilege
) );
390 privilege
->luid
= *luid
;
391 privilege
->def
= privilege
->enabled
= (enabled
!= 0);
392 list_add_tail( &token
->privileges
, &privilege
->entry
);
397 static inline void privilege_remove( struct privilege
*privilege
)
399 list_remove( &privilege
->entry
);
403 static void token_destroy( struct object
*obj
)
406 struct list
*cursor
, *cursor_next
;
408 assert( obj
->ops
== &token_ops
);
409 token
= (struct token
*)obj
;
413 LIST_FOR_EACH_SAFE( cursor
, cursor_next
, &token
->privileges
)
415 struct privilege
*privilege
= LIST_ENTRY( cursor
, struct privilege
, entry
);
416 privilege_remove( privilege
);
419 LIST_FOR_EACH_SAFE( cursor
, cursor_next
, &token
->groups
)
421 struct group
*group
= LIST_ENTRY( cursor
, struct group
, entry
);
422 list_remove( &group
->entry
);
426 free( token
->default_dacl
);
429 /* creates a new token.
430 * groups may be NULL if group_count is 0.
431 * privs may be NULL if priv_count is 0.
432 * default_dacl may be NULL, indicating that all objects created by the user
434 * modified_id may be NULL, indicating that a new modified_id luid should be
437 static struct token
*create_token( unsigned primary
, const SID
*user
,
438 const SID_AND_ATTRIBUTES
*groups
, unsigned int group_count
,
439 const LUID_AND_ATTRIBUTES
*privs
, unsigned int priv_count
,
440 const ACL
*default_dacl
, TOKEN_SOURCE source
,
441 const LUID
*modified_id
,
442 SECURITY_IMPERSONATION_LEVEL impersonation_level
)
444 struct token
*token
= alloc_object( &token_ops
);
449 allocate_luid( &token
->token_id
);
451 token
->modified_id
= *modified_id
;
453 allocate_luid( &token
->modified_id
);
454 list_init( &token
->privileges
);
455 list_init( &token
->groups
);
456 token
->primary
= primary
;
457 /* primary tokens don't have impersonation levels */
459 token
->impersonation_level
= -1;
461 token
->impersonation_level
= impersonation_level
;
462 token
->default_dacl
= NULL
;
463 token
->primary_group
= NULL
;
466 token
->user
= memdup( user
, FIELD_OFFSET(SID
, SubAuthority
[user
->SubAuthorityCount
]) );
469 release_object( token
);
474 for (i
= 0; i
< group_count
; i
++)
476 size_t size
= FIELD_OFFSET( struct group
, sid
.SubAuthority
[((const SID
*)groups
[i
].Sid
)->SubAuthorityCount
] );
477 struct group
*group
= mem_alloc( size
);
481 release_object( token
);
484 memcpy( &group
->sid
, groups
[i
].Sid
, FIELD_OFFSET( SID
, SubAuthority
[((const SID
*)groups
[i
].Sid
)->SubAuthorityCount
] ) );
485 group
->enabled
= TRUE
;
487 group
->logon
= FALSE
;
488 group
->mandatory
= (groups
[i
].Attributes
& SE_GROUP_MANDATORY
) ? TRUE
: FALSE
;
489 group
->owner
= groups
[i
].Attributes
& SE_GROUP_OWNER
? TRUE
: FALSE
;
490 group
->resource
= FALSE
;
491 group
->deny_only
= FALSE
;
492 list_add_tail( &token
->groups
, &group
->entry
);
493 /* Use first owner capable group as an owner */
494 if (!token
->primary_group
&& group
->owner
)
495 token
->primary_group
= &group
->sid
;
498 /* copy privileges */
499 for (i
= 0; i
< priv_count
; i
++)
501 /* note: we don't check uniqueness: the caller must make sure
502 * privs doesn't contain any duplicate luids */
503 if (!privilege_add( token
, &privs
[i
].Luid
,
504 privs
[i
].Attributes
& SE_PRIVILEGE_ENABLED
))
506 release_object( token
);
513 token
->default_dacl
= memdup( default_dacl
, default_dacl
->AclSize
);
514 if (!token
->default_dacl
)
516 release_object( token
);
521 token
->source
= source
;
526 static ACL
*create_default_dacl( const SID
*user
)
528 ACCESS_ALLOWED_ACE
*aaa
;
531 size_t default_dacl_size
= sizeof(ACL
) +
532 2*(sizeof(ACCESS_ALLOWED_ACE
) - sizeof(DWORD
)) +
533 sizeof(local_system_sid
) +
534 FIELD_OFFSET(SID
, SubAuthority
[user
->SubAuthorityCount
]);
536 default_dacl
= mem_alloc( default_dacl_size
);
537 if (!default_dacl
) return NULL
;
539 default_dacl
->AclRevision
= MAX_ACL_REVISION
;
540 default_dacl
->Sbz1
= 0;
541 default_dacl
->AclSize
= default_dacl_size
;
542 default_dacl
->AceCount
= 2;
543 default_dacl
->Sbz2
= 0;
545 /* GENERIC_ALL for Local System */
546 aaa
= (ACCESS_ALLOWED_ACE
*)(default_dacl
+ 1);
547 aaa
->Header
.AceType
= ACCESS_ALLOWED_ACE_TYPE
;
548 aaa
->Header
.AceFlags
= 0;
549 aaa
->Header
.AceSize
= (sizeof(ACCESS_ALLOWED_ACE
) - sizeof(DWORD
)) +
550 sizeof(local_system_sid
);
551 aaa
->Mask
= GENERIC_ALL
;
552 sid
= (SID
*)&aaa
->SidStart
;
553 memcpy( sid
, &local_system_sid
, sizeof(local_system_sid
) );
555 /* GENERIC_ALL for specified user */
556 aaa
= (ACCESS_ALLOWED_ACE
*)((char *)aaa
+ aaa
->Header
.AceSize
);
557 aaa
->Header
.AceType
= ACCESS_ALLOWED_ACE_TYPE
;
558 aaa
->Header
.AceFlags
= 0;
559 aaa
->Header
.AceSize
= (sizeof(ACCESS_ALLOWED_ACE
) - sizeof(DWORD
)) +
560 FIELD_OFFSET( SID
, SubAuthority
[user
->SubAuthorityCount
] );
561 aaa
->Mask
= GENERIC_ALL
;
562 sid
= (SID
*)&aaa
->SidStart
;
563 memcpy( sid
, user
, FIELD_OFFSET(SID
, SubAuthority
[user
->SubAuthorityCount
]) );
570 SID_IDENTIFIER_AUTHORITY idauth
;
572 unsigned int subauth
[MAX_SUBAUTH_COUNT
];
575 struct token
*token_create_admin( void )
577 struct token
*token
= NULL
;
578 static const SID_IDENTIFIER_AUTHORITY nt_authority
= { SECURITY_NT_AUTHORITY
};
579 static const unsigned int alias_admins_subauth
[] = { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_ADMINS
};
580 static const unsigned int alias_users_subauth
[] = { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_USERS
};
581 PSID alias_admins_sid
;
582 PSID alias_users_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
);
591 if (alias_admins_sid
&& alias_users_sid
&& default_dacl
)
593 const LUID_AND_ATTRIBUTES admin_privs
[] =
595 { SeChangeNotifyPrivilege
, SE_PRIVILEGE_ENABLED
},
596 { SeSecurityPrivilege
, 0 },
597 { SeBackupPrivilege
, 0 },
598 { SeRestorePrivilege
, 0 },
599 { SeSystemtimePrivilege
, 0 },
600 { SeShutdownPrivilege
, 0 },
601 { SeRemoteShutdownPrivilege
, 0 },
602 { SeTakeOwnershipPrivilege
, 0 },
603 { SeDebugPrivilege
, 0 },
604 { SeSystemEnvironmentPrivilege
, 0 },
605 { SeSystemProfilePrivilege
, 0 },
606 { SeProfileSingleProcessPrivilege
, 0 },
607 { SeIncreaseBasePriorityPrivilege
, 0 },
608 { SeLoadDriverPrivilege
, 0 },
609 { SeCreatePagefilePrivilege
, 0 },
610 { SeIncreaseQuotaPrivilege
, 0 },
611 { SeUndockPrivilege
, 0 },
612 { SeManageVolumePrivilege
, 0 },
613 { SeImpersonatePrivilege
, SE_PRIVILEGE_ENABLED
},
614 { SeCreateGlobalPrivilege
, SE_PRIVILEGE_ENABLED
},
616 /* note: we don't include non-builtin groups here for the user -
617 * telling us these is the job of a client-side program */
618 const SID_AND_ATTRIBUTES admin_groups
[] =
620 { security_world_sid
, SE_GROUP_ENABLED
|SE_GROUP_ENABLED_BY_DEFAULT
|SE_GROUP_MANDATORY
},
621 { security_local_sid
, SE_GROUP_ENABLED
|SE_GROUP_ENABLED_BY_DEFAULT
|SE_GROUP_MANDATORY
},
622 { security_interactive_sid
, SE_GROUP_ENABLED
|SE_GROUP_ENABLED_BY_DEFAULT
|SE_GROUP_MANDATORY
},
623 { security_authenticated_user_sid
, SE_GROUP_ENABLED
|SE_GROUP_ENABLED_BY_DEFAULT
|SE_GROUP_MANDATORY
},
624 { alias_admins_sid
, SE_GROUP_ENABLED
|SE_GROUP_ENABLED_BY_DEFAULT
|SE_GROUP_MANDATORY
|SE_GROUP_OWNER
},
625 { alias_users_sid
, SE_GROUP_ENABLED
|SE_GROUP_ENABLED_BY_DEFAULT
|SE_GROUP_MANDATORY
},
627 static const TOKEN_SOURCE admin_source
= {"SeMgr", {0, 0}};
628 /* note: we just set the user sid to be the interactive builtin sid -
629 * we should really translate the UNIX user id to a sid */
630 token
= create_token( TRUE
, &interactive_sid
,
631 admin_groups
, sizeof(admin_groups
)/sizeof(admin_groups
[0]),
632 admin_privs
, sizeof(admin_privs
)/sizeof(admin_privs
[0]),
633 default_dacl
, admin_source
, NULL
, -1 );
634 /* we really need a primary group */
635 assert( token
->primary_group
);
638 free( alias_admins_sid
);
639 free( alias_users_sid
);
640 free( default_dacl
);
645 static struct privilege
*token_find_privilege( struct token
*token
, const LUID
*luid
, int enabled_only
)
647 struct privilege
*privilege
;
648 LIST_FOR_EACH_ENTRY( privilege
, &token
->privileges
, struct privilege
, entry
)
650 if (is_equal_luid( luid
, &privilege
->luid
))
652 if (enabled_only
&& !privilege
->enabled
)
660 static unsigned int token_adjust_privileges( struct token
*token
, const LUID_AND_ATTRIBUTES
*privs
,
661 unsigned int count
, LUID_AND_ATTRIBUTES
*mod_privs
,
662 unsigned int mod_privs_count
)
664 unsigned int i
, modified_count
= 0;
666 /* mark as modified */
667 allocate_luid( &token
->modified_id
);
669 for (i
= 0; i
< count
; i
++)
671 struct privilege
*privilege
=
672 token_find_privilege( token
, &privs
[i
].Luid
, FALSE
);
675 set_error( STATUS_NOT_ALL_ASSIGNED
);
679 if (privs
[i
].Attributes
& SE_PRIVILEGE_REMOVE
)
680 privilege_remove( privilege
);
683 /* save previous state for caller */
686 luid_and_attr_from_privilege(mod_privs
, privilege
);
692 if (privs
[i
].Attributes
& SE_PRIVILEGE_ENABLED
)
693 privilege
->enabled
= TRUE
;
695 privilege
->enabled
= FALSE
;
698 return modified_count
;
701 static void token_disable_privileges( struct token
*token
)
703 struct privilege
*privilege
;
705 /* mark as modified */
706 allocate_luid( &token
->modified_id
);
708 LIST_FOR_EACH_ENTRY( privilege
, &token
->privileges
, struct privilege
, entry
)
709 privilege
->enabled
= FALSE
;
712 int token_check_privileges( struct token
*token
, int all_required
,
713 const LUID_AND_ATTRIBUTES
*reqprivs
,
714 unsigned int count
, LUID_AND_ATTRIBUTES
*usedprivs
)
716 unsigned int i
, enabled_count
= 0;
718 for (i
= 0; i
< count
; i
++)
720 struct privilege
*privilege
=
721 token_find_privilege( token
, &reqprivs
[i
].Luid
, TRUE
);
724 usedprivs
[i
] = reqprivs
[i
];
726 if (privilege
&& privilege
->enabled
)
730 usedprivs
[i
].Attributes
|= SE_PRIVILEGE_USED_FOR_ACCESS
;
735 return (enabled_count
== count
);
737 return (enabled_count
> 0);
740 static int token_sid_present( struct token
*token
, const SID
*sid
, int deny
)
744 if (security_equal_sid( token
->user
, sid
)) return TRUE
;
746 LIST_FOR_EACH_ENTRY( group
, &token
->groups
, struct group
, entry
)
748 if (!group
->enabled
) continue;
749 if (group
->deny_only
&& !deny
) continue;
751 if (security_equal_sid( &group
->sid
, sid
)) return TRUE
;
757 /* Checks access to a security descriptor. 'sd' must have been validated by
758 * caller. It returns STATUS_SUCCESS if call succeeded or an error indicating
759 * the reason. 'status' parameter will indicate if access is granted or denied.
761 * If both returned value and 'status' are STATUS_SUCCESS then access is granted.
763 static unsigned int token_access_check( struct token
*token
,
764 const struct security_descriptor
*sd
,
765 unsigned int desired_access
,
766 LUID_AND_ATTRIBUTES
*privs
,
767 unsigned int *priv_count
,
768 const GENERIC_MAPPING
*mapping
,
769 unsigned int *granted_access
,
770 unsigned int *status
)
772 unsigned int current_access
= 0;
773 unsigned int denied_access
= 0;
777 const ACE_HEADER
*ace
;
780 /* assume no access rights */
783 /* fail if desired_access contains generic rights */
784 if (desired_access
& (GENERIC_READ
|GENERIC_WRITE
|GENERIC_EXECUTE
|GENERIC_ALL
))
787 return STATUS_GENERIC_NOT_MAPPED
;
790 dacl
= sd_get_dacl( sd
, &dacl_present
);
791 owner
= sd_get_owner( sd
);
792 if (!owner
|| !sd_get_group( sd
))
795 return STATUS_INVALID_SECURITY_DESCR
;
798 /* 1: Grant desired access if the object is unprotected */
802 *granted_access
= desired_access
;
803 return *status
= STATUS_SUCCESS
;
808 *status
= STATUS_ACCESS_DENIED
;
809 return STATUS_SUCCESS
;
812 /* 2: Check if caller wants access to system security part. Note: access
813 * is only granted if specifically asked for */
814 if (desired_access
& ACCESS_SYSTEM_SECURITY
)
816 const LUID_AND_ATTRIBUTES security_priv
= { SeSecurityPrivilege
, 0 };
817 LUID_AND_ATTRIBUTES retpriv
= security_priv
;
818 if (token_check_privileges( token
, TRUE
, &security_priv
, 1, &retpriv
))
822 /* assumes that there will only be one privilege to return */
823 if (*priv_count
>= 1)
831 return STATUS_BUFFER_TOO_SMALL
;
834 current_access
|= ACCESS_SYSTEM_SECURITY
;
835 if (desired_access
== current_access
)
837 *granted_access
= current_access
;
838 return *status
= STATUS_SUCCESS
;
844 *status
= STATUS_PRIVILEGE_NOT_HELD
;
845 return STATUS_SUCCESS
;
848 else if (priv_count
) *priv_count
= 0;
850 /* 3: Check whether the token is the owner */
851 /* NOTE: SeTakeOwnershipPrivilege is not checked for here - it is instead
852 * checked when a "set owner" call is made, overriding the access rights
853 * determined here. */
854 if (token_sid_present( token
, owner
, FALSE
))
856 current_access
|= (READ_CONTROL
| WRITE_DAC
);
857 if (desired_access
== current_access
)
859 *granted_access
= current_access
;
860 return *status
= STATUS_SUCCESS
;
864 /* 4: Grant rights according to the DACL */
865 ace
= (const ACE_HEADER
*)(dacl
+ 1);
866 for (i
= 0; i
< dacl
->AceCount
; i
++)
868 const ACCESS_ALLOWED_ACE
*aa_ace
;
869 const ACCESS_DENIED_ACE
*ad_ace
;
871 switch (ace
->AceType
)
873 case ACCESS_DENIED_ACE_TYPE
:
874 ad_ace
= (const ACCESS_DENIED_ACE
*)ace
;
875 sid
= (const SID
*)&ad_ace
->SidStart
;
876 if (token_sid_present( token
, sid
, TRUE
))
878 unsigned int access
= ad_ace
->Mask
;
879 map_generic_mask(&access
, mapping
);
880 if (desired_access
& MAXIMUM_ALLOWED
)
881 denied_access
|= access
;
884 denied_access
|= (access
& ~current_access
);
885 if (desired_access
& access
) goto done
;
889 case ACCESS_ALLOWED_ACE_TYPE
:
890 aa_ace
= (const ACCESS_ALLOWED_ACE
*)ace
;
891 sid
= (const SID
*)&aa_ace
->SidStart
;
892 if (token_sid_present( token
, sid
, FALSE
))
894 unsigned int access
= aa_ace
->Mask
;
895 map_generic_mask(&access
, mapping
);
896 if (desired_access
& MAXIMUM_ALLOWED
)
897 current_access
|= access
;
899 current_access
|= (access
& ~denied_access
);
904 /* don't bother carrying on checking if we've already got all of
906 if (desired_access
== *granted_access
)
909 ace
= ace_next( ace
);
913 if (desired_access
& MAXIMUM_ALLOWED
)
914 *granted_access
= current_access
& ~denied_access
;
916 if ((current_access
& desired_access
) == desired_access
)
917 *granted_access
= current_access
& desired_access
;
921 *status
= *granted_access
? STATUS_SUCCESS
: STATUS_ACCESS_DENIED
;
922 return STATUS_SUCCESS
;
925 const ACL
*token_get_default_dacl( struct token
*token
)
927 return token
->default_dacl
;
930 static void set_object_sd( struct object
*obj
, const struct security_descriptor
*sd
,
931 unsigned int set_info
)
933 struct security_descriptor new_sd
, *pnew_sd
;
935 const SID
*owner
, *group
;
936 const ACL
*sacl
, *dacl
;
939 if (!set_info
) return;
941 new_sd
.control
= sd
->control
& ~SE_SELF_RELATIVE
;
943 owner
= sd_get_owner( sd
);
944 if (set_info
& OWNER_SECURITY_INFORMATION
&& owner
)
945 new_sd
.owner_len
= sd
->owner_len
;
948 owner
= current
->process
->token
->user
;
949 new_sd
.owner_len
= FIELD_OFFSET(SID
, SubAuthority
[owner
->SubAuthorityCount
]);
950 new_sd
.control
|= SE_OWNER_DEFAULTED
;
953 group
= sd_get_group( sd
);
954 if (set_info
& GROUP_SECURITY_INFORMATION
&& group
)
955 new_sd
.group_len
= sd
->group_len
;
958 group
= current
->process
->token
->primary_group
;
959 new_sd
.group_len
= FIELD_OFFSET(SID
, SubAuthority
[group
->SubAuthorityCount
]);
960 new_sd
.control
|= SE_GROUP_DEFAULTED
;
963 new_sd
.control
|= SE_SACL_PRESENT
;
964 sacl
= sd_get_sacl( sd
, &present
);
965 if (set_info
& SACL_SECURITY_INFORMATION
&& present
)
966 new_sd
.sacl_len
= sd
->sacl_len
;
969 if (obj
->sd
) sacl
= sd_get_sacl( obj
->sd
, &present
);
971 if (obj
->sd
&& present
)
972 new_sd
.sacl_len
= obj
->sd
->sacl_len
;
976 new_sd
.control
|= SE_SACL_DEFAULTED
;
980 new_sd
.control
|= SE_DACL_PRESENT
;
981 dacl
= sd_get_dacl( sd
, &present
);
982 if (set_info
& DACL_SECURITY_INFORMATION
&& present
)
983 new_sd
.dacl_len
= sd
->dacl_len
;
986 if (obj
->sd
) dacl
= sd_get_dacl( obj
->sd
, &present
);
988 if (obj
->sd
&& present
)
989 new_sd
.dacl_len
= obj
->sd
->dacl_len
;
992 dacl
= token_get_default_dacl( current
->process
->token
);
993 new_sd
.dacl_len
= dacl
->AclSize
;
994 new_sd
.control
|= SE_DACL_DEFAULTED
;
998 ptr
= mem_alloc( sizeof(new_sd
) + new_sd
.owner_len
+ new_sd
.group_len
+
999 new_sd
.sacl_len
+ new_sd
.dacl_len
);
1001 pnew_sd
= (struct security_descriptor
*)ptr
;
1003 memcpy( ptr
, &new_sd
, sizeof(new_sd
) );
1004 ptr
+= sizeof(new_sd
);
1005 memcpy( ptr
, owner
, new_sd
.owner_len
);
1006 ptr
+= new_sd
.owner_len
;
1007 memcpy( ptr
, group
, new_sd
.group_len
);
1008 ptr
+= new_sd
.group_len
;
1009 memcpy( ptr
, sacl
, new_sd
.sacl_len
);
1010 ptr
+= new_sd
.sacl_len
;
1011 memcpy( ptr
, dacl
, new_sd
.dacl_len
);
1017 int check_object_access(struct object
*obj
, unsigned int *access
)
1019 GENERIC_MAPPING mapping
;
1020 struct token
*token
= current
->token
? current
->token
: current
->process
->token
;
1021 LUID_AND_ATTRIBUTES priv
;
1022 unsigned int status
, priv_count
= 1;
1025 mapping
.GenericAll
= obj
->ops
->map_access( obj
, GENERIC_ALL
);
1029 if (*access
& MAXIMUM_ALLOWED
)
1030 *access
= mapping
.GenericAll
;
1034 mapping
.GenericRead
= obj
->ops
->map_access( obj
, GENERIC_READ
);
1035 mapping
.GenericWrite
= obj
->ops
->map_access( obj
, GENERIC_WRITE
);
1036 mapping
.GenericExecute
= obj
->ops
->map_access( obj
, GENERIC_EXECUTE
);
1038 res
= token_access_check( token
, obj
->sd
, *access
, &priv
, &priv_count
,
1039 &mapping
, access
, &status
) == STATUS_SUCCESS
&&
1040 status
== STATUS_SUCCESS
;
1042 if (!res
) set_error( STATUS_ACCESS_DENIED
);
1047 /* open a security token */
1048 DECL_HANDLER(open_token
)
1050 if (req
->flags
& OPEN_TOKEN_THREAD
)
1052 struct thread
*thread
= get_thread_from_handle( req
->handle
, 0 );
1057 if (thread
->token
->impersonation_level
<= SecurityAnonymous
)
1058 set_error( STATUS_CANT_OPEN_ANONYMOUS
);
1060 reply
->token
= alloc_handle( current
->process
, thread
->token
,
1061 req
->access
, req
->attributes
);
1064 set_error( STATUS_NO_TOKEN
);
1065 release_object( thread
);
1070 struct process
*process
= get_process_from_handle( req
->handle
, 0 );
1074 reply
->token
= alloc_handle( current
->process
, process
->token
, req
->access
,
1077 set_error( STATUS_NO_TOKEN
);
1078 release_object( process
);
1083 /* adjust the privileges held by a token */
1084 DECL_HANDLER(adjust_token_privileges
)
1086 struct token
*token
;
1087 unsigned int access
= TOKEN_ADJUST_PRIVILEGES
;
1089 if (req
->get_modified_state
) access
|= TOKEN_QUERY
;
1091 if ((token
= (struct token
*)get_handle_obj( current
->process
, req
->handle
,
1092 access
, &token_ops
)))
1094 const LUID_AND_ATTRIBUTES
*privs
= get_req_data();
1095 LUID_AND_ATTRIBUTES
*modified_privs
= NULL
;
1096 unsigned int priv_count
= get_req_data_size() / sizeof(LUID_AND_ATTRIBUTES
);
1097 unsigned int modified_priv_count
= 0;
1099 if (req
->get_modified_state
&& !req
->disable_all
)
1102 /* count modified privs */
1103 for (i
= 0; i
< priv_count
; i
++)
1105 struct privilege
*privilege
=
1106 token_find_privilege( token
, &privs
[i
].Luid
, FALSE
);
1107 if (privilege
&& req
->get_modified_state
)
1108 modified_priv_count
++;
1110 reply
->len
= modified_priv_count
;
1111 modified_priv_count
= min( modified_priv_count
, get_reply_max_size() / sizeof(*modified_privs
) );
1112 if (modified_priv_count
)
1113 modified_privs
= set_reply_data_size( modified_priv_count
* sizeof(*modified_privs
) );
1115 reply
->len
= modified_priv_count
* sizeof(*modified_privs
);
1117 if (req
->disable_all
)
1118 token_disable_privileges( token
);
1120 modified_priv_count
= token_adjust_privileges( token
, privs
,
1121 priv_count
, modified_privs
, modified_priv_count
);
1123 release_object( token
);
1127 /* retrieves the list of privileges that may be held be the token */
1128 DECL_HANDLER(get_token_privileges
)
1130 struct token
*token
;
1132 if ((token
= (struct token
*)get_handle_obj( current
->process
, req
->handle
,
1137 LUID_AND_ATTRIBUTES
*privs
;
1138 struct privilege
*privilege
;
1140 LIST_FOR_EACH_ENTRY( privilege
, &token
->privileges
, struct privilege
, entry
)
1143 reply
->len
= priv_count
* sizeof(*privs
);
1144 if (reply
->len
<= get_reply_max_size())
1146 privs
= set_reply_data_size( priv_count
* sizeof(*privs
) );
1150 LIST_FOR_EACH_ENTRY( privilege
, &token
->privileges
, struct privilege
, entry
)
1152 luid_and_attr_from_privilege( &privs
[i
], privilege
);
1158 set_error(STATUS_BUFFER_TOO_SMALL
);
1160 release_object( token
);
1164 /* creates a duplicate of the token */
1165 DECL_HANDLER(duplicate_token
)
1167 struct token
*src_token
;
1169 if ((req
->impersonation_level
< SecurityAnonymous
) ||
1170 (req
->impersonation_level
> SecurityDelegation
))
1172 set_error( STATUS_BAD_IMPERSONATION_LEVEL
);
1176 if ((src_token
= (struct token
*)get_handle_obj( current
->process
, req
->handle
,
1180 const LUID
*modified_id
=
1181 req
->primary
|| (req
->impersonation_level
== src_token
->impersonation_level
) ?
1182 &src_token
->modified_id
: NULL
;
1183 struct token
*token
= NULL
;
1185 if (req
->primary
|| (req
->impersonation_level
<= src_token
->impersonation_level
))
1186 token
= create_token( req
->primary
, src_token
->user
, NULL
, 0,
1187 NULL
, 0, src_token
->default_dacl
,
1188 src_token
->source
, modified_id
,
1189 req
->impersonation_level
);
1190 else set_error( STATUS_BAD_IMPERSONATION_LEVEL
);
1194 struct privilege
*privilege
;
1195 struct group
*group
;
1196 unsigned int access
;
1199 LIST_FOR_EACH_ENTRY( group
, &src_token
->groups
, struct group
, entry
)
1201 size_t size
= FIELD_OFFSET( struct group
, sid
.SubAuthority
[group
->sid
.SubAuthorityCount
] );
1202 struct group
*newgroup
= mem_alloc( size
);
1205 release_object( token
);
1206 release_object( src_token
);
1209 memcpy( newgroup
, group
, size
);
1210 list_add_tail( &token
->groups
, &newgroup
->entry
);
1212 token
->primary_group
= src_token
->primary_group
;
1213 assert( token
->primary_group
);
1215 /* copy privileges */
1216 LIST_FOR_EACH_ENTRY( privilege
, &src_token
->privileges
, struct privilege
, entry
)
1217 privilege_add( token
, &privilege
->luid
, privilege
->enabled
);
1219 access
= req
->access
;
1220 reply
->new_handle
= alloc_handle( current
->process
, token
, access
, req
->attributes
);
1221 release_object( token
);
1223 release_object( src_token
);
1227 /* checks the specified privileges are held by the token */
1228 DECL_HANDLER(check_token_privileges
)
1230 struct token
*token
;
1232 if ((token
= (struct token
*)get_handle_obj( current
->process
, req
->handle
,
1236 unsigned int count
= get_req_data_size() / sizeof(LUID_AND_ATTRIBUTES
);
1238 if (!token
->primary
&& token
->impersonation_level
<= SecurityAnonymous
)
1239 set_error( STATUS_BAD_IMPERSONATION_LEVEL
);
1240 else if (get_reply_max_size() >= count
* sizeof(LUID_AND_ATTRIBUTES
))
1242 LUID_AND_ATTRIBUTES
*usedprivs
= set_reply_data_size( count
* sizeof(*usedprivs
) );
1243 reply
->has_privileges
= token_check_privileges( token
, req
->all_required
, get_req_data(), count
, usedprivs
);
1246 set_error( STATUS_BUFFER_OVERFLOW
);
1247 release_object( token
);
1251 /* checks that a user represented by a token is allowed to access an object
1252 * represented by a security descriptor */
1253 DECL_HANDLER(access_check
)
1255 data_size_t sd_size
= get_req_data_size();
1256 const struct security_descriptor
*sd
= get_req_data();
1257 struct token
*token
;
1259 if (!sd_is_valid( sd
, sd_size
))
1261 set_error( STATUS_ACCESS_VIOLATION
);
1265 if ((token
= (struct token
*)get_handle_obj( current
->process
, req
->handle
,
1269 GENERIC_MAPPING mapping
;
1270 unsigned int status
;
1271 LUID_AND_ATTRIBUTES priv
;
1272 unsigned int priv_count
= 1;
1274 memset(&priv
, 0, sizeof(priv
));
1276 /* only impersonation tokens may be used with this function */
1279 set_error( STATUS_NO_IMPERSONATION_TOKEN
);
1280 release_object( token
);
1283 /* anonymous impersonation tokens can't be used */
1284 if (token
->impersonation_level
<= SecurityAnonymous
)
1286 set_error( STATUS_BAD_IMPERSONATION_LEVEL
);
1287 release_object( token
);
1291 mapping
.GenericRead
= req
->mapping_read
;
1292 mapping
.GenericWrite
= req
->mapping_write
;
1293 mapping
.GenericExecute
= req
->mapping_execute
;
1294 mapping
.GenericAll
= req
->mapping_all
;
1296 status
= token_access_check(
1297 token
, sd
, req
->desired_access
, &priv
, &priv_count
, &mapping
,
1298 &reply
->access_granted
, &reply
->access_status
);
1300 reply
->privileges_len
= priv_count
*sizeof(LUID_AND_ATTRIBUTES
);
1302 if ((priv_count
> 0) && (reply
->privileges_len
<= get_reply_max_size()))
1304 LUID_AND_ATTRIBUTES
*privs
= set_reply_data_size( priv_count
* sizeof(*privs
) );
1305 memcpy( privs
, &priv
, sizeof(priv
) );
1308 set_error( status
);
1309 release_object( token
);
1313 /* retrieves the SID of the user that the token represents */
1314 DECL_HANDLER(get_token_user
)
1316 struct token
*token
;
1318 reply
->user_len
= 0;
1320 if ((token
= (struct token
*)get_handle_obj( current
->process
, req
->handle
,
1324 const SID
*user
= token
->user
;
1326 reply
->user_len
= FIELD_OFFSET(SID
, SubAuthority
[user
->SubAuthorityCount
]);
1327 if (reply
->user_len
<= get_reply_max_size())
1329 SID
*user_reply
= set_reply_data_size( reply
->user_len
);
1331 memcpy( user_reply
, user
, reply
->user_len
);
1333 else set_error( STATUS_BUFFER_TOO_SMALL
);
1335 release_object( token
);
1339 /* retrieves the groups that the user represented by the token belongs to */
1340 DECL_HANDLER(get_token_groups
)
1342 struct token
*token
;
1344 reply
->user_len
= 0;
1346 if ((token
= (struct token
*)get_handle_obj( current
->process
, req
->handle
,
1350 size_t size_needed
= sizeof(struct token_groups
);
1351 unsigned int group_count
= 0;
1352 const struct group
*group
;
1354 LIST_FOR_EACH_ENTRY( group
, &token
->groups
, const struct group
, entry
)
1357 size_needed
+= FIELD_OFFSET(SID
, SubAuthority
[group
->sid
.SubAuthorityCount
]);
1359 size_needed
+= sizeof(unsigned int) * group_count
;
1361 reply
->user_len
= size_needed
;
1363 if (size_needed
<= get_reply_max_size())
1365 struct token_groups
*tg
= set_reply_data_size( size_needed
);
1368 unsigned int *attr_ptr
= (unsigned int *)(tg
+ 1);
1369 SID
*sid_ptr
= (SID
*)(attr_ptr
+ group_count
);
1371 tg
->count
= group_count
;
1373 LIST_FOR_EACH_ENTRY( group
, &token
->groups
, const struct group
, entry
)
1377 if (group
->mandatory
) *attr_ptr
|= SE_GROUP_MANDATORY
;
1378 if (group
->def
) *attr_ptr
|= SE_GROUP_ENABLED_BY_DEFAULT
;
1379 if (group
->enabled
) *attr_ptr
|= SE_GROUP_ENABLED
;
1380 if (group
->owner
) *attr_ptr
|= SE_GROUP_OWNER
;
1381 if (group
->deny_only
) *attr_ptr
|= SE_GROUP_USE_FOR_DENY_ONLY
;
1382 if (group
->resource
) *attr_ptr
|= SE_GROUP_RESOURCE
;
1384 memcpy(sid_ptr
, &group
->sid
, FIELD_OFFSET(SID
, SubAuthority
[group
->sid
.SubAuthorityCount
]));
1386 sid_ptr
= (SID
*)((char *)sid_ptr
+ FIELD_OFFSET(SID
, SubAuthority
[group
->sid
.SubAuthorityCount
]));
1391 else set_error( STATUS_BUFFER_TOO_SMALL
);
1393 release_object( token
);
1397 DECL_HANDLER(get_token_impersonation_level
)
1399 struct token
*token
;
1401 if ((token
= (struct token
*)get_handle_obj( current
->process
, req
->handle
,
1406 set_error( STATUS_INVALID_PARAMETER
);
1408 reply
->impersonation_level
= token
->impersonation_level
;
1410 release_object( token
);
1414 DECL_HANDLER(set_security_object
)
1416 data_size_t sd_size
= get_req_data_size();
1417 const struct security_descriptor
*sd
= get_req_data();
1419 unsigned int access
= 0;
1421 if (!sd_is_valid( sd
, sd_size
))
1423 set_error( STATUS_ACCESS_VIOLATION
);
1427 if (req
->security_info
& OWNER_SECURITY_INFORMATION
||
1428 req
->security_info
& GROUP_SECURITY_INFORMATION
)
1429 access
|= WRITE_OWNER
;
1430 if (req
->security_info
& SACL_SECURITY_INFORMATION
)
1431 access
|= ACCESS_SYSTEM_SECURITY
;
1432 if (req
->security_info
& DACL_SECURITY_INFORMATION
)
1433 access
|= WRITE_DAC
;
1435 if (!(obj
= get_handle_obj( current
->process
, req
->handle
, access
, NULL
))) return;
1437 set_object_sd( obj
, sd
, req
->security_info
);
1438 release_object( obj
);