security.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * Security Management
  3. *
  4. * Copyright (C) 2005 Robert Shearman
  5. *
  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.
  10. *
  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.
  15. *
  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
  19. */
  20. #ifndef __WINE_SERVER_SECURITY_H
  21. #define __WINE_SERVER_SECURITY_H
  22. #include <sys/types.h>
  23. extern const struct luid SeIncreaseQuotaPrivilege;
  24. extern const struct luid SeSecurityPrivilege;
  25. extern const struct luid SeTakeOwnershipPrivilege;
  26. extern const struct luid SeLoadDriverPrivilege;
  27. extern const struct luid SeSystemProfilePrivilege;
  28. extern const struct luid SeSystemtimePrivilege;
  29. extern const struct luid SeProfileSingleProcessPrivilege;
  30. extern const struct luid SeIncreaseBasePriorityPrivilege;
  31. extern const struct luid SeCreatePagefilePrivilege;
  32. extern const struct luid SeBackupPrivilege;
  33. extern const struct luid SeRestorePrivilege;
  34. extern const struct luid SeShutdownPrivilege;
  35. extern const struct luid SeDebugPrivilege;
  36. extern const struct luid SeSystemEnvironmentPrivilege;
  37. extern const struct luid SeChangeNotifyPrivilege;
  38. extern const struct luid SeRemoteShutdownPrivilege;
  39. extern const struct luid SeUndockPrivilege;
  40. extern const struct luid SeManageVolumePrivilege;
  41. extern const struct luid SeImpersonatePrivilege;
  42. extern const struct luid SeCreateGlobalPrivilege;
  43. extern const struct sid world_sid;
  44. extern const struct sid local_user_sid;
  45. extern const struct sid local_system_sid;
  46. extern const struct sid builtin_users_sid;
  47. extern const struct sid builtin_admins_sid;
  48. extern const struct sid domain_users_sid;
  49. extern const struct sid high_label_sid;
  50. struct ace
  51. {
  52. unsigned char type;
  53. unsigned char flags;
  54. unsigned short size;
  55. unsigned int mask;
  56. };
  57. /* token functions */
  58. extern struct token *get_token_obj( struct process *process, obj_handle_t handle, unsigned int access );
  59. extern struct token *token_create_admin( unsigned primary, int impersonation_level, int elevation, unsigned int session_id );
  60. extern int token_assign_label( struct token *token, const struct sid *label );
  61. extern struct token *token_duplicate( struct token *src_token, unsigned primary,
  62. int impersonation_level, const struct security_descriptor *sd,
  63. const struct luid_attr *remove_privs, unsigned int remove_priv_count,
  64. const struct sid *remove_groups, unsigned int remove_group_count );
  65. extern int token_check_privileges( struct token *token, int all_required,
  66. const struct luid_attr *reqprivs,
  67. unsigned int count, struct luid_attr *usedprivs );
  68. extern const struct acl *token_get_default_dacl( struct token *token );
  69. extern const struct sid *token_get_user( struct token *token );
  70. extern const struct sid *token_get_primary_group( struct token *token );
  71. extern unsigned int token_get_session_id( struct token *token );
  72. extern int token_sid_present( struct token *token, const struct sid *sid, int deny );
  73. static inline struct ace *ace_first( const struct acl *acl )
  74. {
  75. return (struct ace *)(acl + 1);
  76. }
  77. static inline struct ace *ace_next( const struct ace *ace )
  78. {
  79. return (struct ace *)((char *)ace + ace->size);
  80. }
  81. static inline size_t sid_len( const struct sid *sid )
  82. {
  83. return offsetof( struct sid, sub_auth[sid->sub_count] );
  84. }
  85. static inline int equal_sid( const struct sid *sid1, const struct sid *sid2 )
  86. {
  87. return ((sid1->sub_count == sid2->sub_count) && !memcmp( sid1, sid2, sid_len( sid1 )));
  88. }
  89. static inline void *copy_sid( struct sid *dst, const struct sid *src )
  90. {
  91. memcpy( dst, src, sid_len( src ));
  92. return (char *)dst + sid_len( src );
  93. }
  94. static inline int sid_valid_size( const struct sid *sid, data_size_t size )
  95. {
  96. return (size >= offsetof( struct sid, sub_auth[0] ) && size >= sid_len( sid ));
  97. }
  98. static inline struct ace *set_ace( struct ace *ace, const struct sid *sid, unsigned char type,
  99. unsigned char flags, unsigned int mask )
  100. {
  101. ace->type = type;
  102. ace->flags = flags;
  103. ace->size = sizeof(*ace) + sid_len( sid );
  104. ace->mask = mask;
  105. memcpy( ace + 1, sid, sid_len( sid ));
  106. return ace;
  107. }
  108. extern void security_set_thread_token( struct thread *thread, obj_handle_t handle );
  109. extern const struct sid *security_unix_uid_to_sid( uid_t uid );
  110. extern int check_object_access( struct token *token, struct object *obj, unsigned int *access );
  111. static inline int thread_single_check_privilege( struct thread *thread, struct luid priv )
  112. {
  113. struct token *token = thread_get_impersonation_token( thread );
  114. const struct luid_attr privs = { priv, 0 };
  115. if (!token) return FALSE;
  116. return token_check_privileges( token, TRUE, &privs, 1, NULL );
  117. }
  118. /* security descriptor helper functions */
  119. extern int sd_is_valid( const struct security_descriptor *sd, data_size_t size );
  120. extern struct acl *extract_security_labels( const struct acl *sacl );
  121. extern struct acl *replace_security_labels( const struct acl *old_sacl, const struct acl *new_sacl );
  122. /* gets the discretionary access control list from a security descriptor */
  123. static inline const struct acl *sd_get_dacl( const struct security_descriptor *sd, int *present )
  124. {
  125. *present = (sd->control & SE_DACL_PRESENT) != 0;
  126. if (sd->dacl_len)
  127. return (const struct acl *)((const char *)(sd + 1) +
  128. sd->owner_len + sd->group_len + sd->sacl_len);
  129. else
  130. return NULL;
  131. }
  132. /* gets the system access control list from a security descriptor */
  133. static inline const struct acl *sd_get_sacl( const struct security_descriptor *sd, int *present )
  134. {
  135. *present = (sd->control & SE_SACL_PRESENT) != 0;
  136. if (sd->sacl_len)
  137. return (const struct acl *)((const char *)(sd + 1) +
  138. sd->owner_len + sd->group_len);
  139. else
  140. return NULL;
  141. }
  142. /* gets the owner from a security descriptor */
  143. static inline const struct sid *sd_get_owner( const struct security_descriptor *sd )
  144. {
  145. if (sd->owner_len)
  146. return (const struct sid *)(sd + 1);
  147. else
  148. return NULL;
  149. }
  150. /* gets the primary group from a security descriptor */
  151. static inline const struct sid *sd_get_group( const struct security_descriptor *sd )
  152. {
  153. if (sd->group_len)
  154. return (const struct sid *)((const char *)(sd + 1) + sd->owner_len);
  155. else
  156. return NULL;
  157. }
  158. #endif /* __WINE_SERVER_SECURITY_H */