winegstreamer: Register stub ResamplerMediaObject transform.
[wine.git] / server / security.h
blobfa91b81b77cecbaf51e329e9f2b367b2fb9a6e0d
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;
53 extern const struct sid high_label_sid;
55 struct ace
57 unsigned char type;
58 unsigned char flags;
59 unsigned short size;
60 unsigned int mask;
63 /* token functions */
65 extern struct token *get_token_obj( struct process *process, obj_handle_t handle, unsigned int access );
66 extern struct token *token_create_admin( unsigned primary, int impersonation_level, int elevation, unsigned int session_id );
67 extern int token_assign_label( struct token *token, const struct sid *label );
68 extern struct token *token_duplicate( struct token *src_token, unsigned primary,
69 int impersonation_level, const struct security_descriptor *sd,
70 const struct luid_attr *remove_privs, unsigned int remove_priv_count,
71 const struct sid *remove_groups, unsigned int remove_group_count );
72 extern int token_check_privileges( struct token *token, int all_required,
73 const struct luid_attr *reqprivs,
74 unsigned int count, struct luid_attr *usedprivs );
75 extern const struct acl *token_get_default_dacl( struct token *token );
76 extern const struct sid *token_get_user( struct token *token );
77 extern const struct sid *token_get_primary_group( struct token *token );
78 extern unsigned int token_get_session_id( struct token *token );
79 extern int token_sid_present( struct token *token, const struct sid *sid, int deny );
81 static inline struct ace *ace_first( const struct acl *acl )
83 return (struct ace *)(acl + 1);
86 static inline struct ace *ace_next( const struct ace *ace )
88 return (struct ace *)((char *)ace + ace->size);
91 static inline size_t sid_len( const struct sid *sid )
93 return offsetof( struct sid, sub_auth[sid->sub_count] );
96 static inline int equal_sid( const struct sid *sid1, const struct sid *sid2 )
98 return ((sid1->sub_count == sid2->sub_count) && !memcmp( sid1, sid2, sid_len( sid1 )));
101 static inline void *copy_sid( struct sid *dst, const struct sid *src )
103 memcpy( dst, src, sid_len( src ));
104 return (char *)dst + sid_len( src );
107 static inline int sid_valid_size( const struct sid *sid, data_size_t size )
109 return (size >= offsetof( struct sid, sub_auth[0] ) && size >= sid_len( sid ));
112 static inline struct ace *set_ace( struct ace *ace, const struct sid *sid, unsigned char type,
113 unsigned char flags, unsigned int mask )
115 ace->type = type;
116 ace->flags = flags;
117 ace->size = sizeof(*ace) + sid_len( sid );
118 ace->mask = mask;
119 memcpy( ace + 1, sid, sid_len( sid ));
120 return ace;
123 extern void security_set_thread_token( struct thread *thread, obj_handle_t handle );
124 extern const struct sid *security_unix_uid_to_sid( uid_t uid );
125 extern int check_object_access( struct token *token, struct object *obj, unsigned int *access );
127 static inline int thread_single_check_privilege( struct thread *thread, struct luid priv )
129 struct token *token = thread_get_impersonation_token( thread );
130 const struct luid_attr privs = { priv, 0 };
132 if (!token) return FALSE;
134 return token_check_privileges( token, TRUE, &privs, 1, NULL );
138 /* security descriptor helper functions */
140 extern int sd_is_valid( const struct security_descriptor *sd, data_size_t size );
141 extern struct acl *extract_security_labels( const struct acl *sacl );
142 extern struct acl *replace_security_labels( const struct acl *old_sacl, const struct acl *new_sacl );
144 /* gets the discretionary access control list from a security descriptor */
145 static inline const struct acl *sd_get_dacl( const struct security_descriptor *sd, int *present )
147 *present = (sd->control & SE_DACL_PRESENT) != 0;
149 if (sd->dacl_len)
150 return (const struct acl *)((const char *)(sd + 1) +
151 sd->owner_len + sd->group_len + sd->sacl_len);
152 else
153 return NULL;
156 /* gets the system access control list from a security descriptor */
157 static inline const struct acl *sd_get_sacl( const struct security_descriptor *sd, int *present )
159 *present = (sd->control & SE_SACL_PRESENT) != 0;
161 if (sd->sacl_len)
162 return (const struct acl *)((const char *)(sd + 1) +
163 sd->owner_len + sd->group_len);
164 else
165 return NULL;
168 /* gets the owner from a security descriptor */
169 static inline const struct sid *sd_get_owner( const struct security_descriptor *sd )
171 if (sd->owner_len)
172 return (const struct sid *)(sd + 1);
173 else
174 return NULL;
177 /* gets the primary group from a security descriptor */
178 static inline const struct sid *sd_get_group( const struct security_descriptor *sd )
180 if (sd->group_len)
181 return (const struct sid *)((const char *)(sd + 1) + sd->owner_len);
182 else
183 return NULL;
186 #endif /* __WINE_SERVER_SECURITY_H */