include/mscvpdb.h: Use flexible array members for the rest of structures.
[wine.git] / server / security.h
blobf4dff67917910b06ccc7df67da24246f715678f7
1 /*
2 * Security Management
4 * Copyright (C) 2005 Robert Shearman
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #ifndef __WINE_SERVER_SECURITY_H
22 #define __WINE_SERVER_SECURITY_H
24 #include <sys/types.h>
26 extern const struct luid SeIncreaseQuotaPrivilege;
27 extern const struct luid SeSecurityPrivilege;
28 extern const struct luid SeTakeOwnershipPrivilege;
29 extern const struct luid SeLoadDriverPrivilege;
30 extern const struct luid SeSystemProfilePrivilege;
31 extern const struct luid SeSystemtimePrivilege;
32 extern const struct luid SeProfileSingleProcessPrivilege;
33 extern const struct luid SeIncreaseBasePriorityPrivilege;
34 extern const struct luid SeCreatePagefilePrivilege;
35 extern const struct luid SeBackupPrivilege;
36 extern const struct luid SeRestorePrivilege;
37 extern const struct luid SeShutdownPrivilege;
38 extern const struct luid SeDebugPrivilege;
39 extern const struct luid SeSystemEnvironmentPrivilege;
40 extern const struct luid SeChangeNotifyPrivilege;
41 extern const struct luid SeRemoteShutdownPrivilege;
42 extern const struct luid SeUndockPrivilege;
43 extern const struct luid SeManageVolumePrivilege;
44 extern const struct luid SeImpersonatePrivilege;
45 extern const struct luid SeCreateGlobalPrivilege;
47 extern const struct sid world_sid;
48 extern const struct sid local_user_sid;
49 extern const struct sid local_system_sid;
50 extern const struct sid builtin_users_sid;
51 extern const struct sid builtin_admins_sid;
52 extern const struct sid domain_users_sid;
54 struct ace
56 unsigned char type;
57 unsigned char flags;
58 unsigned short size;
59 unsigned int mask;
62 /* token functions */
64 extern struct token *get_token_obj( struct process *process, obj_handle_t handle, unsigned int access );
65 extern struct token *token_create_admin( unsigned primary, int impersonation_level, int elevation, unsigned int session_id );
66 extern int token_assign_label( struct token *token, const struct sid *label );
67 extern struct token *token_duplicate( struct token *src_token, unsigned primary,
68 int impersonation_level, const struct security_descriptor *sd,
69 const struct luid_attr *remove_privs, unsigned int remove_priv_count,
70 const struct sid *remove_groups, unsigned int remove_group_count );
71 extern int token_check_privileges( struct token *token, int all_required,
72 const struct luid_attr *reqprivs,
73 unsigned int count, struct luid_attr *usedprivs );
74 extern const struct acl *token_get_default_dacl( struct token *token );
75 extern const struct sid *token_get_owner( struct token *token );
76 extern const struct sid *token_get_primary_group( struct token *token );
77 extern unsigned int token_get_session_id( struct token *token );
78 extern int token_sid_present( struct token *token, const struct sid *sid, int deny );
80 static inline struct ace *ace_first( const struct acl *acl )
82 return (struct ace *)(acl + 1);
85 static inline struct ace *ace_next( const struct ace *ace )
87 return (struct ace *)((char *)ace + ace->size);
90 static inline size_t sid_len( const struct sid *sid )
92 return offsetof( struct sid, sub_auth[sid->sub_count] );
95 static inline int equal_sid( const struct sid *sid1, const struct sid *sid2 )
97 return ((sid1->sub_count == sid2->sub_count) && !memcmp( sid1, sid2, sid_len( sid1 )));
100 static inline void *copy_sid( struct sid *dst, const struct sid *src )
102 memcpy( dst, src, sid_len( src ));
103 return (char *)dst + sid_len( src );
106 static inline int sid_valid_size( const struct sid *sid, data_size_t size )
108 return (size >= offsetof( struct sid, sub_auth[0] ) && size >= sid_len( sid ));
111 static inline struct ace *set_ace( struct ace *ace, const struct sid *sid, unsigned char type,
112 unsigned char flags, unsigned int mask )
114 ace->type = type;
115 ace->flags = flags;
116 ace->size = sizeof(*ace) + sid_len( sid );
117 ace->mask = mask;
118 memcpy( ace + 1, sid, sid_len( sid ));
119 return ace;
122 extern void security_set_thread_token( struct thread *thread, obj_handle_t handle );
123 extern const struct sid *security_unix_uid_to_sid( uid_t uid );
124 extern int check_object_access( struct token *token, struct object *obj, unsigned int *access );
126 static inline int thread_single_check_privilege( struct thread *thread, struct luid priv )
128 struct token *token = thread_get_impersonation_token( thread );
129 const struct luid_attr privs = { priv, 0 };
131 if (!token) return FALSE;
133 return token_check_privileges( token, TRUE, &privs, 1, NULL );
137 /* security descriptor helper functions */
139 extern int sd_is_valid( const struct security_descriptor *sd, data_size_t size );
140 extern struct acl *extract_security_labels( const struct acl *sacl );
141 extern struct acl *replace_security_labels( const struct acl *old_sacl, const struct acl *new_sacl );
143 /* gets the discretionary access control list from a security descriptor */
144 static inline const struct acl *sd_get_dacl( const struct security_descriptor *sd, int *present )
146 *present = (sd->control & SE_DACL_PRESENT) != 0;
148 if (sd->dacl_len)
149 return (const struct acl *)((const char *)(sd + 1) +
150 sd->owner_len + sd->group_len + sd->sacl_len);
151 else
152 return NULL;
155 /* gets the system access control list from a security descriptor */
156 static inline const struct acl *sd_get_sacl( const struct security_descriptor *sd, int *present )
158 *present = (sd->control & SE_SACL_PRESENT) != 0;
160 if (sd->sacl_len)
161 return (const struct acl *)((const char *)(sd + 1) +
162 sd->owner_len + sd->group_len);
163 else
164 return NULL;
167 /* gets the owner from a security descriptor */
168 static inline const struct sid *sd_get_owner( const struct security_descriptor *sd )
170 if (sd->owner_len)
171 return (const struct sid *)(sd + 1);
172 else
173 return NULL;
176 /* gets the primary group from a security descriptor */
177 static inline const struct sid *sd_get_group( const struct security_descriptor *sd )
179 if (sd->group_len)
180 return (const struct sid *)((const char *)(sd + 1) + sd->owner_len);
181 else
182 return NULL;
185 #endif /* __WINE_SERVER_SECURITY_H */