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
29 #include <sys/types.h>
33 #define WIN32_NO_STATUS
43 #define MAX_SUBAUTH_COUNT 1
45 const struct luid SeIncreaseQuotaPrivilege
= { 5, 0 };
46 const struct luid SeTcbPrivilege
= { 7, 0 };
47 const struct luid SeSecurityPrivilege
= { 8, 0 };
48 const struct luid SeTakeOwnershipPrivilege
= { 9, 0 };
49 const struct luid SeLoadDriverPrivilege
= { 10, 0 };
50 const struct luid SeSystemProfilePrivilege
= { 11, 0 };
51 const struct luid SeSystemtimePrivilege
= { 12, 0 };
52 const struct luid SeProfileSingleProcessPrivilege
= { 13, 0 };
53 const struct luid SeIncreaseBasePriorityPrivilege
= { 14, 0 };
54 const struct luid SeCreatePagefilePrivilege
= { 15, 0 };
55 const struct luid SeBackupPrivilege
= { 17, 0 };
56 const struct luid SeRestorePrivilege
= { 18, 0 };
57 const struct luid SeShutdownPrivilege
= { 19, 0 };
58 const struct luid SeDebugPrivilege
= { 20, 0 };
59 const struct luid SeSystemEnvironmentPrivilege
= { 22, 0 };
60 const struct luid SeChangeNotifyPrivilege
= { 23, 0 };
61 const struct luid SeRemoteShutdownPrivilege
= { 24, 0 };
62 const struct luid SeUndockPrivilege
= { 25, 0 };
63 const struct luid SeManageVolumePrivilege
= { 28, 0 };
64 const struct luid SeImpersonatePrivilege
= { 29, 0 };
65 const struct luid SeCreateGlobalPrivilege
= { 30, 0 };
69 const struct sid
*sid
;
73 const struct sid world_sid
= { SID_REVISION
, 1, SECURITY_WORLD_SID_AUTHORITY
, { SECURITY_WORLD_RID
} };
74 const struct sid local_system_sid
= { SID_REVISION
, 1, SECURITY_NT_AUTHORITY
, { SECURITY_LOCAL_SYSTEM_RID
} };
75 const struct sid high_label_sid
= { SID_REVISION
, 1, SECURITY_MANDATORY_LABEL_AUTHORITY
, { SECURITY_MANDATORY_HIGH_RID
} };
76 const struct sid local_user_sid
= { SID_REVISION
, 5, SECURITY_NT_AUTHORITY
, { SECURITY_NT_NON_UNIQUE
, 0, 0, 0, 1000 } };
77 const struct sid builtin_admins_sid
= { SID_REVISION
, 2, SECURITY_NT_AUTHORITY
, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_ADMINS
} };
78 const struct sid builtin_users_sid
= { SID_REVISION
, 2, SECURITY_NT_AUTHORITY
, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_USERS
} };
79 const struct sid domain_users_sid
= { SID_REVISION
, 5, SECURITY_NT_AUTHORITY
, { SECURITY_NT_NON_UNIQUE
, 0, 0, 0, DOMAIN_GROUP_RID_USERS
} };
81 static const struct sid local_sid
= { SID_REVISION
, 1, SECURITY_LOCAL_SID_AUTHORITY
, { SECURITY_LOCAL_RID
} };
82 static const struct sid interactive_sid
= { SID_REVISION
, 1, SECURITY_NT_AUTHORITY
, { SECURITY_INTERACTIVE_RID
} };
83 static const struct sid anonymous_logon_sid
= { SID_REVISION
, 1, SECURITY_NT_AUTHORITY
, { SECURITY_ANONYMOUS_LOGON_RID
} };
84 static const struct sid authenticated_user_sid
= { SID_REVISION
, 1, SECURITY_NT_AUTHORITY
, { SECURITY_AUTHENTICATED_USER_RID
} };
85 static const struct sid builtin_logon_sid
= { SID_REVISION
, 3, SECURITY_NT_AUTHORITY
, { SECURITY_LOGON_IDS_RID
, 0, 0 } };
87 static struct luid prev_luid_value
= { 1000, 0 };
89 static const WCHAR token_name
[] = {'T','o','k','e','n'};
91 struct type_descr token_type
=
93 { token_name
, sizeof(token_name
) }, /* name */
94 TOKEN_ALL_ACCESS
| SYNCHRONIZE
, /* valid_access */
96 STANDARD_RIGHTS_READ
| TOKEN_QUERY_SOURCE
| TOKEN_QUERY
| TOKEN_DUPLICATE
,
97 STANDARD_RIGHTS_WRITE
| TOKEN_ADJUST_SESSIONID
| TOKEN_ADJUST_DEFAULT
| TOKEN_ADJUST_GROUPS
98 | TOKEN_ADJUST_PRIVILEGES
,
99 STANDARD_RIGHTS_EXECUTE
| TOKEN_IMPERSONATE
| TOKEN_ASSIGN_PRIMARY
,
106 struct object obj
; /* object header */
107 struct luid token_id
; /* system-unique id of token */
108 struct luid modified_id
; /* new id allocated every time token is modified */
109 struct list privileges
; /* privileges available to the token */
110 struct list groups
; /* groups that the user of this token belongs to (sid_and_attributes) */
111 struct sid
*user
; /* SID of user this token represents */
112 struct sid
*owner
; /* SID of owner (points to user or one of groups) */
113 struct sid
*primary_group
; /* SID of user's primary group (points to one of groups) */
114 unsigned int primary
; /* is this a primary or impersonation token? */
115 unsigned int session_id
; /* token session id */
116 struct acl
*default_dacl
; /* the default DACL to assign to objects created by this user */
117 int impersonation_level
; /* impersonation level this token is capable of if non-primary token */
118 int elevation
; /* elevation type */
125 unsigned enabled
: 1; /* is the privilege currently enabled? */
126 unsigned def
: 1; /* is the privilege enabled by default? */
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? */
142 static void token_dump( struct object
*obj
, int verbose
);
143 static void token_destroy( struct object
*obj
);
145 static const struct object_ops token_ops
=
147 sizeof(struct token
), /* size */
148 &token_type
, /* type */
149 token_dump
, /* dump */
150 no_add_queue
, /* add_queue */
151 NULL
, /* remove_queue */
153 NULL
, /* satisfied */
154 no_signal
, /* signal */
155 no_get_fd
, /* get_fd */
156 default_map_access
, /* map_access */
157 default_get_sd
, /* get_sd */
158 default_set_sd
, /* set_sd */
159 no_get_full_name
, /* get_full_name */
160 no_lookup_name
, /* lookup_name */
161 no_link_name
, /* link_name */
162 NULL
, /* unlink_name */
163 no_open_file
, /* open_file */
164 no_kernel_obj_list
, /* get_kernel_obj_list */
165 no_close_handle
, /* close_handle */
166 token_destroy
/* destroy */
169 static void token_dump( struct object
*obj
, int verbose
)
171 struct token
*token
= (struct token
*)obj
;
172 assert( obj
->ops
== &token_ops
);
173 fprintf( stderr
, "Token id=%d.%u primary=%u impersonation level=%d\n", token
->token_id
.high_part
,
174 token
->token_id
.low_part
, token
->primary
, token
->impersonation_level
);
177 void security_set_thread_token( struct thread
*thread
, obj_handle_t handle
)
182 release_object( thread
->token
);
183 thread
->token
= NULL
;
187 struct token
*token
= (struct token
*)get_handle_obj( current
->process
,
194 release_object( thread
->token
);
195 thread
->token
= token
;
200 const struct sid
*security_unix_uid_to_sid( uid_t uid
)
202 /* very simple mapping: either the current user or not the current user */
204 return &local_user_sid
;
206 return &anonymous_logon_sid
;
209 static int acl_is_valid( const struct acl
*acl
, data_size_t size
)
212 const struct ace
*ace
;
214 if (size
< sizeof(*acl
)) return FALSE
;
216 size
= min(size
, MAX_ACL_LEN
);
217 size
-= sizeof(*acl
);
219 for (i
= 0, ace
= ace_first( acl
); i
< acl
->count
; i
++, ace
= ace_next( ace
))
221 if (size
< sizeof(*ace
) || size
< ace
->size
) return FALSE
;
225 case ACCESS_DENIED_ACE_TYPE
:
226 case ACCESS_ALLOWED_ACE_TYPE
:
227 case SYSTEM_AUDIT_ACE_TYPE
:
228 case SYSTEM_ALARM_ACE_TYPE
:
229 case SYSTEM_MANDATORY_LABEL_ACE_TYPE
:
234 if (!sid_valid_size( (const struct sid
*)(ace
+ 1), ace
->size
- sizeof(*ace
) )) return FALSE
;
239 static unsigned int get_sid_count( const struct sid
*sid
, data_size_t size
)
243 for (count
= 0; sid_valid_size( sid
, size
); count
++)
245 size
-= sid_len( sid
);
246 sid
= (const struct sid
*)((char *)sid
+ sid_len( sid
));
251 /* checks whether all members of a security descriptor fit inside the size
252 * of memory specified */
253 int sd_is_valid( const struct security_descriptor
*sd
, data_size_t size
)
255 size_t offset
= sizeof(struct security_descriptor
);
256 const struct sid
*group
;
257 const struct sid
*owner
;
258 const struct acl
*sacl
;
259 const struct acl
*dacl
;
265 if (sd
->owner_len
>= offsetof(struct sid
, sub_auth
[255]) || offset
+ sd
->owner_len
> size
) return FALSE
;
266 owner
= sd_get_owner( sd
);
267 offset
+= sd
->owner_len
;
268 if (owner
&& !sid_valid_size( owner
, sd
->owner_len
)) return FALSE
;
270 if (sd
->group_len
>= offsetof(struct sid
, sub_auth
[255]) || offset
+ sd
->group_len
> size
) return FALSE
;
271 group
= sd_get_group( sd
);
272 offset
+= sd
->group_len
;
273 if (group
&& !sid_valid_size( group
, sd
->group_len
)) return FALSE
;
275 if ((sd
->sacl_len
>= MAX_ACL_LEN
) || (offset
+ sd
->sacl_len
> size
))
277 sacl
= sd_get_sacl( sd
, &dummy
);
278 if (sacl
&& !acl_is_valid( sacl
, sd
->sacl_len
))
280 offset
+= sd
->sacl_len
;
282 if ((sd
->dacl_len
>= MAX_ACL_LEN
) || (offset
+ sd
->dacl_len
> size
))
284 dacl
= sd_get_dacl( sd
, &dummy
);
285 if (dacl
&& !acl_is_valid( dacl
, sd
->dacl_len
))
287 offset
+= sd
->dacl_len
;
292 /* extract security labels from SACL */
293 struct acl
*extract_security_labels( const struct acl
*sacl
)
295 size_t size
= sizeof(*sacl
);
296 const struct ace
*ace
;
297 struct ace
*label_ace
;
298 unsigned int i
, count
= 0;
299 struct acl
*label_acl
;
301 for (i
= 0, ace
= ace_first( sacl
); i
< sacl
->count
; i
++, ace
= ace_next( ace
))
303 if (ace
->type
== SYSTEM_MANDATORY_LABEL_ACE_TYPE
)
310 label_acl
= mem_alloc( size
);
311 if (!label_acl
) return NULL
;
313 label_acl
->revision
= sacl
->revision
;
315 label_acl
->size
= size
;
316 label_acl
->count
= count
;
319 label_ace
= ace_first( label_acl
);
320 for (i
= 0, ace
= ace_first( sacl
); i
< sacl
->count
; i
++, ace
= ace_next( ace
))
322 if (ace
->type
== SYSTEM_MANDATORY_LABEL_ACE_TYPE
)
324 memcpy( label_ace
, ace
, ace
->size
);
325 label_ace
= ace_next( label_ace
);
331 /* replace security labels in an existing SACL */
332 struct acl
*replace_security_labels( const struct acl
*old_sacl
, const struct acl
*new_sacl
)
334 const struct ace
*ace
;
335 struct ace
*replaced_ace
;
336 unsigned int i
, count
= 0;
337 unsigned char revision
= ACL_REVISION
;
338 struct acl
*replaced_acl
;
339 data_size_t size
= sizeof(*replaced_acl
);
343 revision
= max( revision
, old_sacl
->revision
);
344 for (i
= 0, ace
= ace_first( old_sacl
); i
< old_sacl
->count
; i
++, ace
= ace_next( ace
))
346 if (ace
->type
== SYSTEM_MANDATORY_LABEL_ACE_TYPE
) continue;
354 revision
= max( revision
, new_sacl
->revision
);
355 for (i
= 0, ace
= ace_first( new_sacl
); i
< new_sacl
->count
; i
++, ace
= ace_next( ace
))
357 if (ace
->type
!= SYSTEM_MANDATORY_LABEL_ACE_TYPE
) continue;
362 if (size
> MAX_ACL_LEN
)
364 set_error( STATUS_INVALID_ACL
);
368 replaced_acl
= mem_alloc( size
);
369 if (!replaced_acl
) return NULL
;
371 replaced_acl
->revision
= revision
;
372 replaced_acl
->pad1
= 0;
373 replaced_acl
->size
= size
;
374 replaced_acl
->count
= count
;
375 replaced_acl
->pad2
= 0;
377 replaced_ace
= (struct ace
*)(replaced_acl
+ 1);
380 for (i
= 0, ace
= ace_first( old_sacl
); i
< old_sacl
->count
; i
++, ace
= ace_next( ace
))
382 if (ace
->type
== SYSTEM_MANDATORY_LABEL_ACE_TYPE
) continue;
383 memcpy( replaced_ace
, ace
, ace
->size
);
384 replaced_ace
= ace_next( replaced_ace
);
390 for (i
= 0, ace
= ace_first( new_sacl
); i
< new_sacl
->count
; i
++, ace
= ace_next( ace
))
392 if (ace
->type
!= SYSTEM_MANDATORY_LABEL_ACE_TYPE
) continue;
393 memcpy( replaced_ace
, ace
, ace
->size
);
394 replaced_ace
= ace_next( replaced_ace
);
401 static inline int is_equal_luid( struct luid luid1
, struct luid luid2
)
403 return (luid1
.low_part
== luid2
.low_part
&& luid1
.high_part
== luid2
.high_part
);
406 static inline void allocate_luid( struct luid
*luid
)
408 prev_luid_value
.low_part
++;
409 *luid
= prev_luid_value
;
412 DECL_HANDLER( allocate_locally_unique_id
)
414 allocate_luid( &reply
->luid
);
417 static inline struct luid_attr
luid_and_attr_from_privilege( const struct privilege
*in
)
419 struct luid_attr ret
= { in
->luid
};
421 ret
.attrs
= (in
->enabled
? SE_PRIVILEGE_ENABLED
: 0) |
422 (in
->def
? SE_PRIVILEGE_ENABLED_BY_DEFAULT
: 0);
426 static struct privilege
*privilege_add( struct token
*token
, struct luid luid
, int enabled
)
428 struct privilege
*privilege
= mem_alloc( sizeof(*privilege
) );
431 privilege
->luid
= luid
;
432 privilege
->def
= privilege
->enabled
= (enabled
!= 0);
433 list_add_tail( &token
->privileges
, &privilege
->entry
);
438 static inline void privilege_remove( struct privilege
*privilege
)
440 list_remove( &privilege
->entry
);
444 static void token_destroy( struct object
*obj
)
447 struct list
*cursor
, *cursor_next
;
449 assert( obj
->ops
== &token_ops
);
450 token
= (struct token
*)obj
;
454 LIST_FOR_EACH_SAFE( cursor
, cursor_next
, &token
->privileges
)
456 struct privilege
*privilege
= LIST_ENTRY( cursor
, struct privilege
, entry
);
457 privilege_remove( privilege
);
460 LIST_FOR_EACH_SAFE( cursor
, cursor_next
, &token
->groups
)
462 struct group
*group
= LIST_ENTRY( cursor
, struct group
, entry
);
463 list_remove( &group
->entry
);
467 free( token
->default_dacl
);
470 /* creates a new token.
471 * groups may be NULL if group_count is 0.
472 * privs may be NULL if priv_count is 0.
473 * default_dacl may be NULL, indicating that all objects created by the user
475 * modified_id may be NULL, indicating that a new modified_id luid should be
478 static struct token
*create_token( unsigned int primary
, unsigned int session_id
, const struct sid
*user
,
479 const struct sid_attrs
*groups
, unsigned int group_count
,
480 const struct luid_attr
*privs
, unsigned int priv_count
,
481 const struct acl
*default_dacl
, const struct luid
*modified_id
,
482 int impersonation_level
, int elevation
)
484 struct token
*token
= alloc_object( &token_ops
);
489 allocate_luid( &token
->token_id
);
491 token
->modified_id
= *modified_id
;
493 allocate_luid( &token
->modified_id
);
494 list_init( &token
->privileges
);
495 list_init( &token
->groups
);
496 token
->primary
= primary
;
497 token
->session_id
= session_id
;
498 /* primary tokens don't have impersonation levels */
500 token
->impersonation_level
= -1;
502 token
->impersonation_level
= impersonation_level
;
503 token
->default_dacl
= NULL
;
504 token
->primary_group
= NULL
;
505 token
->elevation
= elevation
;
508 token
->user
= memdup( user
, sid_len( user
));
511 release_object( token
);
516 for (i
= 0; i
< group_count
; i
++)
518 size_t size
= offsetof( struct group
, sid
.sub_auth
[groups
[i
].sid
->sub_count
] );
519 struct group
*group
= mem_alloc( size
);
523 release_object( token
);
526 copy_sid( &group
->sid
, groups
[i
].sid
);
527 group
->enabled
= TRUE
;
529 group
->logon
= (groups
[i
].attrs
& SE_GROUP_LOGON_ID
) != 0;
530 group
->mandatory
= (groups
[i
].attrs
& SE_GROUP_MANDATORY
) != 0;
531 group
->owner
= (groups
[i
].attrs
& SE_GROUP_OWNER
) != 0;
532 group
->resource
= FALSE
;
533 group
->deny_only
= FALSE
;
534 list_add_tail( &token
->groups
, &group
->entry
);
535 /* Use first owner capable group as owner and primary group */
536 if (!token
->primary_group
&& group
->owner
)
538 token
->owner
= &group
->sid
;
539 token
->primary_group
= &group
->sid
;
543 /* copy privileges */
544 for (i
= 0; i
< priv_count
; i
++)
546 /* note: we don't check uniqueness: the caller must make sure
547 * privs doesn't contain any duplicate luids */
548 if (!privilege_add( token
, privs
[i
].luid
, privs
[i
].attrs
& SE_PRIVILEGE_ENABLED
))
550 release_object( token
);
557 token
->default_dacl
= memdup( default_dacl
, default_dacl
->size
);
558 if (!token
->default_dacl
)
560 release_object( token
);
568 static int filter_group( struct group
*group
, const struct sid
*filter
, unsigned int count
)
572 for (i
= 0; i
< count
; i
++)
574 if (equal_sid( &group
->sid
, filter
)) return 1;
575 filter
= (const struct sid
*)((char *)filter
+ sid_len( filter
));
581 static int filter_privilege( struct privilege
*privilege
, const struct luid_attr
*filter
, unsigned int count
)
585 for (i
= 0; i
< count
; i
++)
586 if (is_equal_luid( privilege
->luid
, filter
[i
].luid
)) return 1;
591 struct token
*token_duplicate( struct token
*src_token
, unsigned primary
,
592 int impersonation_level
, const struct security_descriptor
*sd
,
593 const struct luid_attr
*remove_privs
, unsigned int remove_priv_count
,
594 const struct sid
*remove_groups
, unsigned int remove_group_count
)
596 const struct luid
*modified_id
=
597 primary
|| (impersonation_level
== src_token
->impersonation_level
) ?
598 &src_token
->modified_id
: NULL
;
599 struct token
*token
= NULL
;
600 struct privilege
*privilege
;
604 (impersonation_level
< SecurityAnonymous
||
605 impersonation_level
> SecurityDelegation
||
606 (!src_token
->primary
&& (impersonation_level
> src_token
->impersonation_level
))))
608 set_error( STATUS_BAD_IMPERSONATION_LEVEL
);
612 token
= create_token( primary
, src_token
->session_id
, src_token
->user
, NULL
, 0,
613 NULL
, 0, src_token
->default_dacl
, modified_id
,
614 impersonation_level
, src_token
->elevation
);
615 if (!token
) return token
;
618 token
->primary_group
= NULL
;
619 LIST_FOR_EACH_ENTRY( group
, &src_token
->groups
, struct group
, entry
)
621 size_t size
= offsetof( struct group
, sid
.sub_auth
[group
->sid
.sub_count
] );
622 struct group
*newgroup
= mem_alloc( size
);
625 release_object( token
);
628 memcpy( newgroup
, group
, size
);
629 if (filter_group( group
, remove_groups
, remove_group_count
))
631 newgroup
->enabled
= 0;
633 newgroup
->deny_only
= 1;
635 list_add_tail( &token
->groups
, &newgroup
->entry
);
636 if (src_token
->primary_group
== &group
->sid
)
638 token
->owner
= &newgroup
->sid
;
639 token
->primary_group
= &newgroup
->sid
;
642 assert( token
->primary_group
);
644 /* copy privileges */
645 LIST_FOR_EACH_ENTRY( privilege
, &src_token
->privileges
, struct privilege
, entry
)
647 if (filter_privilege( privilege
, remove_privs
, remove_priv_count
)) continue;
648 if (!privilege_add( token
, privilege
->luid
, privilege
->enabled
))
650 release_object( token
);
655 if (sd
) default_set_sd( &token
->obj
, sd
, OWNER_SECURITY_INFORMATION
| GROUP_SECURITY_INFORMATION
|
656 DACL_SECURITY_INFORMATION
| SACL_SECURITY_INFORMATION
);
661 static struct acl
*create_default_dacl( const struct sid
*user
)
664 struct acl
*default_dacl
;
665 size_t default_dacl_size
= sizeof(*default_dacl
) + 2 * sizeof(*ace
) +
666 sid_len( &local_system_sid
) + sid_len( user
);
668 default_dacl
= mem_alloc( default_dacl_size
);
669 if (!default_dacl
) return NULL
;
671 default_dacl
->revision
= ACL_REVISION
;
672 default_dacl
->pad1
= 0;
673 default_dacl
->size
= default_dacl_size
;
674 default_dacl
->count
= 2;
675 default_dacl
->pad2
= 0;
677 /* GENERIC_ALL for Local System */
678 ace
= set_ace( ace_first( default_dacl
), &local_system_sid
, ACCESS_ALLOWED_ACE_TYPE
, 0, GENERIC_ALL
);
679 /* GENERIC_ALL for specified user */
680 set_ace( ace_next( ace
), user
, ACCESS_ALLOWED_ACE_TYPE
, 0, GENERIC_ALL
);
687 SID_IDENTIFIER_AUTHORITY idauth
;
689 unsigned int subauth
[MAX_SUBAUTH_COUNT
];
692 static struct security_descriptor
*create_security_label_sd( struct token
*token
, const struct sid
*label_sid
)
694 size_t sid_size
= sid_len( label_sid
), sacl_size
, sd_size
;
695 struct security_descriptor
*sd
;
698 sacl_size
= sizeof(*sacl
) + sizeof(struct ace
) + sid_size
;
699 sd_size
= sizeof(struct security_descriptor
) + sacl_size
;
700 if (!(sd
= mem_alloc( sd_size
)))
703 sd
->control
= SE_SACL_PRESENT
;
706 sd
->sacl_len
= sacl_size
;
709 sacl
= (struct acl
*)(sd
+ 1);
710 sacl
->revision
= ACL_REVISION
;
712 sacl
->size
= sacl_size
;
716 set_ace( ace_first( sacl
), label_sid
, SYSTEM_MANDATORY_LABEL_ACE_TYPE
, 0,
717 SYSTEM_MANDATORY_LABEL_NO_WRITE_UP
);
718 assert( sd_is_valid( sd
, sd_size
) );
722 int token_assign_label( struct token
*token
, const struct sid
*label
)
724 struct security_descriptor
*sd
;
727 if ((sd
= create_security_label_sd( token
, label
)))
729 ret
= set_sd_defaults_from_token( &token
->obj
, sd
, LABEL_SECURITY_INFORMATION
, token
);
736 struct token
*get_token_obj( struct process
*process
, obj_handle_t handle
, unsigned int access
)
738 return (struct token
*)get_handle_obj( process
, handle
, access
, &token_ops
);
741 struct token
*token_create_admin( unsigned primary
, int impersonation_level
, int elevation
, unsigned int session_id
)
743 struct token
*token
= NULL
;
744 struct sid alias_admins_sid
= { SID_REVISION
, 2, SECURITY_NT_AUTHORITY
, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_ADMINS
}};
745 struct sid alias_users_sid
= { SID_REVISION
, 2, SECURITY_NT_AUTHORITY
, { SECURITY_BUILTIN_DOMAIN_RID
, DOMAIN_ALIAS_RID_USERS
}};
746 /* on Windows, this value changes every time the user logs on */
747 struct sid logon_sid
= { SID_REVISION
, 3, SECURITY_NT_AUTHORITY
, { SECURITY_LOGON_IDS_RID
, 0, 1 /* FIXME: should be randomly generated when tokens are inherited by new processes */ }};
748 const struct sid
*user_sid
= security_unix_uid_to_sid( getuid() );
749 struct acl
*default_dacl
= create_default_dacl( user_sid
);
750 const struct luid_attr admin_privs
[] =
752 { SeChangeNotifyPrivilege
, SE_PRIVILEGE_ENABLED
},
753 { SeTcbPrivilege
, 0 },
754 { SeSecurityPrivilege
, 0 },
755 { SeBackupPrivilege
, 0 },
756 { SeRestorePrivilege
, 0 },
757 { SeSystemtimePrivilege
, 0 },
758 { SeShutdownPrivilege
, 0 },
759 { SeRemoteShutdownPrivilege
, 0 },
760 { SeTakeOwnershipPrivilege
, 0 },
761 { SeDebugPrivilege
, 0 },
762 { SeSystemEnvironmentPrivilege
, 0 },
763 { SeSystemProfilePrivilege
, 0 },
764 { SeProfileSingleProcessPrivilege
, 0 },
765 { SeIncreaseBasePriorityPrivilege
, 0 },
766 { SeLoadDriverPrivilege
, SE_PRIVILEGE_ENABLED
},
767 { SeCreatePagefilePrivilege
, 0 },
768 { SeIncreaseQuotaPrivilege
, 0 },
769 { SeUndockPrivilege
, 0 },
770 { SeManageVolumePrivilege
, 0 },
771 { SeImpersonatePrivilege
, SE_PRIVILEGE_ENABLED
},
772 { SeCreateGlobalPrivilege
, SE_PRIVILEGE_ENABLED
},
774 /* note: we don't include non-builtin groups here for the user -
775 * telling us these is the job of a client-side program */
776 const struct sid_attrs admin_groups
[] =
778 { &world_sid
, SE_GROUP_ENABLED
|SE_GROUP_ENABLED_BY_DEFAULT
|SE_GROUP_MANDATORY
},
779 { &local_sid
, SE_GROUP_ENABLED
|SE_GROUP_ENABLED_BY_DEFAULT
|SE_GROUP_MANDATORY
},
780 { &interactive_sid
, SE_GROUP_ENABLED
|SE_GROUP_ENABLED_BY_DEFAULT
|SE_GROUP_MANDATORY
},
781 { &authenticated_user_sid
, SE_GROUP_ENABLED
|SE_GROUP_ENABLED_BY_DEFAULT
|SE_GROUP_MANDATORY
},
782 { &domain_users_sid
, SE_GROUP_ENABLED
|SE_GROUP_ENABLED_BY_DEFAULT
|SE_GROUP_MANDATORY
|SE_GROUP_OWNER
},
783 { &alias_admins_sid
, SE_GROUP_ENABLED
|SE_GROUP_ENABLED_BY_DEFAULT
|SE_GROUP_MANDATORY
|SE_GROUP_OWNER
},
784 { &alias_users_sid
, SE_GROUP_ENABLED
|SE_GROUP_ENABLED_BY_DEFAULT
|SE_GROUP_MANDATORY
},
785 { &logon_sid
, SE_GROUP_ENABLED
|SE_GROUP_ENABLED_BY_DEFAULT
|SE_GROUP_MANDATORY
|SE_GROUP_LOGON_ID
},
788 token
= create_token( primary
, session_id
, user_sid
, admin_groups
, ARRAY_SIZE( admin_groups
),
789 admin_privs
, ARRAY_SIZE( admin_privs
), default_dacl
,
790 NULL
, impersonation_level
, elevation
);
791 /* we really need a primary group */
792 assert( token
->primary_group
);
794 free( default_dacl
);
798 static struct privilege
*token_find_privilege( struct token
*token
, struct luid luid
, int enabled_only
)
800 struct privilege
*privilege
;
801 LIST_FOR_EACH_ENTRY( privilege
, &token
->privileges
, struct privilege
, entry
)
803 if (is_equal_luid( luid
, privilege
->luid
))
805 if (enabled_only
&& !privilege
->enabled
)
813 static unsigned int token_adjust_privileges( struct token
*token
, const struct luid_attr
*privs
,
814 unsigned int count
, struct luid_attr
*mod_privs
,
815 unsigned int mod_privs_count
)
817 unsigned int i
, modified_count
= 0;
819 /* mark as modified */
820 allocate_luid( &token
->modified_id
);
822 for (i
= 0; i
< count
; i
++)
824 struct privilege
*privilege
= token_find_privilege( token
, privs
[i
].luid
, FALSE
);
827 set_error( STATUS_NOT_ALL_ASSIGNED
);
831 if (privs
[i
].attrs
& SE_PRIVILEGE_REMOVED
) privilege_remove( privilege
);
834 /* save previous state for caller */
837 *mod_privs
++ = luid_and_attr_from_privilege( privilege
);
841 privilege
->enabled
= !!(privs
[i
].attrs
& SE_PRIVILEGE_ENABLED
);
844 return modified_count
;
847 static void token_disable_privileges( struct token
*token
)
849 struct privilege
*privilege
;
851 /* mark as modified */
852 allocate_luid( &token
->modified_id
);
854 LIST_FOR_EACH_ENTRY( privilege
, &token
->privileges
, struct privilege
, entry
)
855 privilege
->enabled
= FALSE
;
858 int token_check_privileges( struct token
*token
, int all_required
, const struct luid_attr
*reqprivs
,
859 unsigned int count
, struct luid_attr
*usedprivs
)
861 unsigned int i
, enabled_count
= 0;
863 for (i
= 0; i
< count
; i
++)
865 struct privilege
*privilege
= token_find_privilege( token
, reqprivs
[i
].luid
, TRUE
);
868 usedprivs
[i
] = reqprivs
[i
];
870 if (privilege
&& privilege
->enabled
)
873 if (usedprivs
) usedprivs
[i
].attrs
|= SE_PRIVILEGE_USED_FOR_ACCESS
;
878 return (enabled_count
== count
);
880 return (enabled_count
> 0);
883 int token_sid_present( struct token
*token
, const struct sid
*sid
, int deny
)
887 if (equal_sid( token
->user
, sid
)) return TRUE
;
889 LIST_FOR_EACH_ENTRY( group
, &token
->groups
, struct group
, entry
)
891 if (!group
->enabled
) continue;
892 if (group
->deny_only
&& !deny
) continue;
893 if (equal_sid( &group
->sid
, sid
)) return TRUE
;
899 /* Checks access to a security descriptor. 'sd' must have been validated by
900 * caller. It returns STATUS_SUCCESS if call succeeded or an error indicating
901 * the reason. 'status' parameter will indicate if access is granted or denied.
903 * If both returned value and 'status' are STATUS_SUCCESS then access is granted.
905 static unsigned int token_access_check( struct token
*token
,
906 const struct security_descriptor
*sd
,
907 unsigned int desired_access
,
908 struct luid_attr
*privs
,
909 unsigned int *priv_count
,
910 const generic_map_t
*mapping
,
911 unsigned int *granted_access
,
912 unsigned int *status
)
914 unsigned int current_access
= 0;
915 unsigned int denied_access
= 0;
917 const struct acl
*dacl
;
919 const struct ace
*ace
;
920 const struct sid
*owner
;
922 /* assume no access rights */
925 /* fail if desired_access contains generic rights */
926 if (desired_access
& (GENERIC_READ
|GENERIC_WRITE
|GENERIC_EXECUTE
|GENERIC_ALL
))
928 if (priv_count
) *priv_count
= 0;
929 return STATUS_GENERIC_NOT_MAPPED
;
932 dacl
= sd_get_dacl( sd
, &dacl_present
);
933 owner
= sd_get_owner( sd
);
934 if (!owner
|| !sd_get_group( sd
))
936 if (priv_count
) *priv_count
= 0;
937 return STATUS_INVALID_SECURITY_DESCR
;
940 /* 1: Grant desired access if the object is unprotected */
941 if (!dacl_present
|| !dacl
)
943 if (priv_count
) *priv_count
= 0;
944 if (desired_access
& MAXIMUM_ALLOWED
)
945 *granted_access
= mapping
->all
;
947 *granted_access
= desired_access
;
948 return *status
= STATUS_SUCCESS
;
951 /* 2: Check if caller wants access to system security part. Note: access
952 * is only granted if specifically asked for */
953 if (desired_access
& ACCESS_SYSTEM_SECURITY
)
955 const struct luid_attr security_priv
= { SeSecurityPrivilege
, 0 };
956 struct luid_attr retpriv
= security_priv
;
957 if (token_check_privileges( token
, TRUE
, &security_priv
, 1, &retpriv
))
961 /* assumes that there will only be one privilege to return */
962 if (*priv_count
>= 1)
970 return STATUS_BUFFER_TOO_SMALL
;
973 current_access
|= ACCESS_SYSTEM_SECURITY
;
974 if (desired_access
== current_access
)
976 *granted_access
= current_access
;
977 return *status
= STATUS_SUCCESS
;
982 if (priv_count
) *priv_count
= 0;
983 *status
= STATUS_PRIVILEGE_NOT_HELD
;
984 return STATUS_SUCCESS
;
987 else if (priv_count
) *priv_count
= 0;
989 /* 3: Check whether the token is the owner */
990 /* NOTE: SeTakeOwnershipPrivilege is not checked for here - it is instead
991 * checked when a "set owner" call is made, overriding the access rights
992 * determined here. */
993 if (token_sid_present( token
, owner
, FALSE
))
995 current_access
|= (STANDARD_RIGHTS_REQUIRED
| SYNCHRONIZE
);
996 if (desired_access
== current_access
)
998 *granted_access
= current_access
;
999 return *status
= STATUS_SUCCESS
;
1003 /* 4: Grant rights according to the DACL */
1004 for (i
= 0, ace
= ace_first( dacl
); i
< dacl
->count
; i
++, ace
= ace_next( ace
))
1006 const struct sid
*sid
= (const struct sid
*)(ace
+ 1);
1008 if (ace
->flags
& INHERIT_ONLY_ACE
) continue;
1012 case ACCESS_DENIED_ACE_TYPE
:
1013 if (token_sid_present( token
, sid
, TRUE
))
1015 unsigned int access
= map_access( ace
->mask
, mapping
);
1016 if (desired_access
& MAXIMUM_ALLOWED
)
1017 denied_access
|= access
;
1020 denied_access
|= (access
& ~current_access
);
1021 if (desired_access
& access
) goto done
;
1025 case ACCESS_ALLOWED_ACE_TYPE
:
1026 if (token_sid_present( token
, sid
, FALSE
))
1028 unsigned int access
= map_access( ace
->mask
, mapping
);
1029 if (desired_access
& MAXIMUM_ALLOWED
)
1030 current_access
|= access
;
1032 current_access
|= (access
& ~denied_access
);
1037 /* don't bother carrying on checking if we've already got all of
1039 if (desired_access
== *granted_access
)
1044 if (desired_access
& MAXIMUM_ALLOWED
)
1045 *granted_access
= current_access
& ~denied_access
;
1047 if ((current_access
& desired_access
) == desired_access
)
1048 *granted_access
= current_access
& desired_access
;
1050 *granted_access
= 0;
1052 *status
= *granted_access
? STATUS_SUCCESS
: STATUS_ACCESS_DENIED
;
1053 return STATUS_SUCCESS
;
1056 const struct acl
*token_get_default_dacl( struct token
*token
)
1058 return token
->default_dacl
;
1061 const struct sid
*token_get_user( struct token
*token
)
1066 const struct sid
*token_get_primary_group( struct token
*token
)
1068 return token
->primary_group
;
1071 unsigned int token_get_session_id( struct token
*token
)
1073 return token
->session_id
;
1076 int check_object_access(struct token
*token
, struct object
*obj
, unsigned int *access
)
1078 generic_map_t mapping
;
1079 unsigned int status
;
1083 token
= current
->token
? current
->token
: current
->process
->token
;
1085 mapping
.all
= obj
->ops
->map_access( obj
, GENERIC_ALL
);
1089 if (*access
& MAXIMUM_ALLOWED
) *access
= mapping
.all
;
1093 mapping
.read
= obj
->ops
->map_access( obj
, GENERIC_READ
);
1094 mapping
.write
= obj
->ops
->map_access( obj
, GENERIC_WRITE
);
1095 mapping
.exec
= obj
->ops
->map_access( obj
, GENERIC_EXECUTE
);
1097 res
= token_access_check( token
, obj
->sd
, *access
, NULL
, NULL
,
1098 &mapping
, access
, &status
) == STATUS_SUCCESS
&&
1099 status
== STATUS_SUCCESS
;
1101 if (!res
) set_error( STATUS_ACCESS_DENIED
);
1106 /* open a security token */
1107 DECL_HANDLER(open_token
)
1109 if (req
->flags
& OPEN_TOKEN_THREAD
)
1111 struct thread
*thread
= get_thread_from_handle( req
->handle
, 0 );
1116 if (!thread
->token
->primary
&& thread
->token
->impersonation_level
<= SecurityAnonymous
)
1117 set_error( STATUS_CANT_OPEN_ANONYMOUS
);
1119 reply
->token
= alloc_handle( current
->process
, thread
->token
,
1120 req
->access
, req
->attributes
);
1123 set_error( STATUS_NO_TOKEN
);
1124 release_object( thread
);
1129 struct process
*process
= get_process_from_handle( req
->handle
, 0 );
1133 reply
->token
= alloc_handle( current
->process
, process
->token
, req
->access
,
1136 set_error( STATUS_NO_TOKEN
);
1137 release_object( process
);
1142 /* adjust the privileges held by a token */
1143 DECL_HANDLER(adjust_token_privileges
)
1145 struct token
*token
;
1146 unsigned int access
= TOKEN_ADJUST_PRIVILEGES
;
1148 if (req
->get_modified_state
) access
|= TOKEN_QUERY
;
1150 if ((token
= (struct token
*)get_handle_obj( current
->process
, req
->handle
,
1151 access
, &token_ops
)))
1153 const struct luid_attr
*privs
= get_req_data();
1154 struct luid_attr
*modified_privs
= NULL
;
1155 unsigned int priv_count
= get_req_data_size() / sizeof(*privs
);
1156 unsigned int modified_priv_count
= 0;
1158 if (req
->get_modified_state
&& !req
->disable_all
)
1161 /* count modified privs */
1162 for (i
= 0; i
< priv_count
; i
++)
1164 struct privilege
*privilege
= token_find_privilege( token
, privs
[i
].luid
, FALSE
);
1165 if (privilege
&& req
->get_modified_state
)
1166 modified_priv_count
++;
1168 reply
->len
= modified_priv_count
;
1169 modified_priv_count
= min( modified_priv_count
, get_reply_max_size() / sizeof(*modified_privs
) );
1170 if (modified_priv_count
)
1171 modified_privs
= set_reply_data_size( modified_priv_count
* sizeof(*modified_privs
) );
1173 reply
->len
= modified_priv_count
* sizeof(*modified_privs
);
1175 if (req
->disable_all
)
1176 token_disable_privileges( token
);
1178 token_adjust_privileges( token
, privs
, priv_count
, modified_privs
, modified_priv_count
);
1180 release_object( token
);
1184 /* retrieves the list of privileges that may be held be the token */
1185 DECL_HANDLER(get_token_privileges
)
1187 struct token
*token
;
1189 if ((token
= (struct token
*)get_handle_obj( current
->process
, req
->handle
,
1194 struct luid_attr
*privs
;
1195 struct privilege
*privilege
;
1197 LIST_FOR_EACH_ENTRY( privilege
, &token
->privileges
, struct privilege
, entry
)
1200 reply
->len
= priv_count
* sizeof(*privs
);
1201 if (reply
->len
<= get_reply_max_size())
1203 privs
= set_reply_data_size( priv_count
* sizeof(*privs
) );
1205 LIST_FOR_EACH_ENTRY( privilege
, &token
->privileges
, struct privilege
, entry
)
1206 *privs
++ = luid_and_attr_from_privilege( privilege
);
1209 set_error(STATUS_BUFFER_TOO_SMALL
);
1211 release_object( token
);
1215 /* creates a duplicate of the token */
1216 DECL_HANDLER(duplicate_token
)
1218 struct token
*src_token
;
1219 struct unicode_str name
;
1220 const struct security_descriptor
*sd
;
1221 const struct object_attributes
*objattr
= get_req_object_attributes( &sd
, &name
, NULL
);
1223 if (!objattr
) return;
1225 if ((src_token
= (struct token
*)get_handle_obj( current
->process
, req
->handle
,
1229 struct token
*token
= token_duplicate( src_token
, req
->primary
, req
->impersonation_level
, sd
, NULL
, 0, NULL
, 0 );
1232 unsigned int access
= req
->access
? req
->access
: get_handle_access( current
->process
, req
->handle
);
1233 reply
->new_handle
= alloc_handle_no_access_check( current
->process
, token
, access
, objattr
->attributes
);
1234 release_object( token
);
1236 release_object( src_token
);
1240 /* creates a restricted version of a token */
1241 DECL_HANDLER(filter_token
)
1243 struct token
*src_token
;
1245 if ((src_token
= (struct token
*)get_handle_obj( current
->process
, req
->handle
, TOKEN_DUPLICATE
, &token_ops
)))
1247 const struct luid_attr
*filter_privileges
= get_req_data();
1248 unsigned int priv_count
, group_count
;
1249 const struct sid
*filter_groups
;
1250 struct token
*token
;
1252 priv_count
= min( req
->privileges_size
, get_req_data_size() ) / sizeof(struct luid_attr
);
1253 filter_groups
= (const struct sid
*)((char *)filter_privileges
+ priv_count
* sizeof(struct luid_attr
));
1254 group_count
= get_sid_count( filter_groups
, get_req_data_size() - priv_count
* sizeof(struct luid_attr
) );
1256 token
= token_duplicate( src_token
, src_token
->primary
, src_token
->impersonation_level
, NULL
,
1257 filter_privileges
, priv_count
, filter_groups
, group_count
);
1260 unsigned int access
= get_handle_access( current
->process
, req
->handle
);
1261 reply
->new_handle
= alloc_handle_no_access_check( current
->process
, token
, access
, 0 );
1262 release_object( token
);
1264 release_object( src_token
);
1268 /* checks the specified privileges are held by the token */
1269 DECL_HANDLER(check_token_privileges
)
1271 struct token
*token
;
1273 if ((token
= (struct token
*)get_handle_obj( current
->process
, req
->handle
,
1277 unsigned int count
= get_req_data_size() / sizeof(struct luid_attr
);
1279 if (!token
->primary
&& token
->impersonation_level
<= SecurityAnonymous
)
1280 set_error( STATUS_BAD_IMPERSONATION_LEVEL
);
1281 else if (get_reply_max_size() >= count
* sizeof(struct luid_attr
))
1283 struct luid_attr
*usedprivs
= set_reply_data_size( count
* sizeof(*usedprivs
) );
1284 reply
->has_privileges
= token_check_privileges( token
, req
->all_required
, get_req_data(), count
, usedprivs
);
1287 set_error( STATUS_BUFFER_OVERFLOW
);
1288 release_object( token
);
1292 /* checks that a user represented by a token is allowed to access an object
1293 * represented by a security descriptor */
1294 DECL_HANDLER(access_check
)
1296 data_size_t sd_size
= get_req_data_size();
1297 const struct security_descriptor
*sd
= get_req_data();
1298 struct token
*token
;
1300 if (!sd_is_valid( sd
, sd_size
))
1302 set_error( STATUS_ACCESS_VIOLATION
);
1306 if ((token
= (struct token
*)get_handle_obj( current
->process
, req
->handle
,
1310 unsigned int status
;
1311 struct luid_attr priv
;
1312 unsigned int priv_count
= 1;
1314 memset(&priv
, 0, sizeof(priv
));
1316 /* only impersonation tokens may be used with this function */
1319 set_error( STATUS_NO_IMPERSONATION_TOKEN
);
1320 release_object( token
);
1323 /* anonymous impersonation tokens can't be used */
1324 if (token
->impersonation_level
<= SecurityAnonymous
)
1326 set_error( STATUS_BAD_IMPERSONATION_LEVEL
);
1327 release_object( token
);
1331 status
= token_access_check( token
, sd
, req
->desired_access
, &priv
, &priv_count
, &req
->mapping
,
1332 &reply
->access_granted
, &reply
->access_status
);
1334 reply
->privileges_len
= priv_count
*sizeof(struct luid_attr
);
1336 if ((priv_count
> 0) && (reply
->privileges_len
<= get_reply_max_size()))
1338 struct luid_attr
*privs
= set_reply_data_size( priv_count
* sizeof(*privs
) );
1339 memcpy( privs
, &priv
, sizeof(priv
) );
1342 set_error( status
);
1343 release_object( token
);
1347 /* retrieves an SID from the token */
1348 DECL_HANDLER(get_token_sid
)
1350 struct token
*token
;
1354 if ((token
= (struct token
*)get_handle_obj( current
->process
, req
->handle
, TOKEN_QUERY
, &token_ops
)))
1356 const struct sid
*sid
= NULL
;
1358 switch (req
->which_sid
)
1361 assert(token
->user
);
1364 case TokenPrimaryGroup
:
1365 sid
= token
->primary_group
;
1371 sid
= &builtin_logon_sid
;
1374 set_error( STATUS_INVALID_PARAMETER
);
1380 reply
->sid_len
= sid_len( sid
);
1381 if (reply
->sid_len
<= get_reply_max_size()) set_reply_data( sid
, reply
->sid_len
);
1382 else set_error( STATUS_BUFFER_TOO_SMALL
);
1384 release_object( token
);
1388 /* retrieves the groups that the user represented by the token belongs to */
1389 DECL_HANDLER(get_token_groups
)
1391 struct token
*token
;
1393 if ((token
= (struct token
*)get_handle_obj( current
->process
, req
->handle
, TOKEN_QUERY
, &token_ops
)))
1395 unsigned int group_count
= 0;
1396 const struct group
*group
;
1398 LIST_FOR_EACH_ENTRY( group
, &token
->groups
, const struct group
, entry
)
1401 reply
->sid_len
+= sid_len( &group
->sid
);
1403 reply
->attr_len
= sizeof(unsigned int) * group_count
;
1405 if (reply
->attr_len
+ reply
->sid_len
<= get_reply_max_size())
1407 unsigned int *attr_ptr
= set_reply_data_size( reply
->attr_len
+ reply
->sid_len
);
1408 struct sid
*sid
= (struct sid
*)(attr_ptr
+ group_count
);
1412 LIST_FOR_EACH_ENTRY( group
, &token
->groups
, const struct group
, entry
)
1415 if (group
->mandatory
) *attr_ptr
|= SE_GROUP_MANDATORY
;
1416 if (group
->def
) *attr_ptr
|= SE_GROUP_ENABLED_BY_DEFAULT
;
1417 if (group
->enabled
) *attr_ptr
|= SE_GROUP_ENABLED
;
1418 if (group
->owner
) *attr_ptr
|= SE_GROUP_OWNER
;
1419 if (group
->deny_only
) *attr_ptr
|= SE_GROUP_USE_FOR_DENY_ONLY
;
1420 if (group
->resource
) *attr_ptr
|= SE_GROUP_RESOURCE
;
1421 if (group
->logon
) *attr_ptr
|= SE_GROUP_LOGON_ID
;
1422 sid
= copy_sid( sid
, &group
->sid
);
1427 else set_error( STATUS_BUFFER_TOO_SMALL
);
1429 release_object( token
);
1433 DECL_HANDLER(get_token_info
)
1435 struct token
*token
;
1437 if ((token
= (struct token
*)get_handle_obj( current
->process
, req
->handle
, TOKEN_QUERY
, &token_ops
)))
1439 reply
->token_id
= token
->token_id
;
1440 reply
->modified_id
= token
->modified_id
;
1441 reply
->session_id
= token
->session_id
;
1442 reply
->primary
= token
->primary
;
1443 reply
->impersonation_level
= token
->impersonation_level
;
1444 reply
->elevation
= token
->elevation
;
1445 reply
->group_count
= list_count( &token
->groups
);
1446 reply
->privilege_count
= list_count( &token
->privileges
);
1447 release_object( token
);
1451 DECL_HANDLER(get_token_default_dacl
)
1453 struct token
*token
;
1457 if ((token
= (struct token
*)get_handle_obj( current
->process
, req
->handle
,
1461 if (token
->default_dacl
)
1462 reply
->acl_len
= token
->default_dacl
->size
;
1464 if (reply
->acl_len
<= get_reply_max_size())
1466 struct acl
*acl_reply
= set_reply_data_size( reply
->acl_len
);
1468 memcpy( acl_reply
, token
->default_dacl
, reply
->acl_len
);
1470 else set_error( STATUS_BUFFER_TOO_SMALL
);
1472 release_object( token
);
1476 DECL_HANDLER(set_token_default_dacl
)
1478 struct token
*token
;
1479 const struct acl
*acl
= get_req_data();
1480 unsigned int acl_size
= get_req_data_size();
1482 if (acl_size
&& !acl_is_valid( acl
, acl_size
))
1484 set_error( STATUS_INVALID_ACL
);
1488 if ((token
= (struct token
*)get_handle_obj( current
->process
, req
->handle
,
1489 TOKEN_ADJUST_DEFAULT
,
1492 free( token
->default_dacl
);
1493 token
->default_dacl
= NULL
;
1496 token
->default_dacl
= memdup( acl
, acl_size
);
1498 release_object( token
);
1502 DECL_HANDLER(create_linked_token
)
1504 struct token
*token
, *linked
;
1507 if ((token
= (struct token
*)get_handle_obj( current
->process
, req
->handle
,
1508 TOKEN_QUERY
, &token_ops
)))
1510 switch (token
->elevation
)
1512 case TokenElevationTypeFull
:
1513 elevation
= TokenElevationTypeLimited
;
1515 case TokenElevationTypeLimited
:
1516 elevation
= TokenElevationTypeFull
;
1519 release_object( token
);
1522 if ((linked
= token_create_admin( FALSE
, SecurityIdentification
, elevation
, token
->session_id
)))
1524 reply
->linked
= alloc_handle( current
->process
, linked
, TOKEN_ALL_ACCESS
, 0 );
1525 release_object( linked
);
1527 release_object( token
);