sysacls.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /*
  2. * Unix SMB/Netbios implementation.
  3. * Version 2.2.x
  4. * Portable SMB ACL interface
  5. * Copyright (C) Jeremy Allison 2000
  6. * Copyright (C) 2007-2008 Wayne Davison
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program 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
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * with this program; if not, visit the http://fsf.org website.
  20. */
  21. #ifdef SUPPORT_ACLS
  22. #ifdef HAVE_SYS_ACL_H
  23. #include <sys/acl.h>
  24. #endif
  25. #ifdef HAVE_ACL_LIBACL_H
  26. #include <acl/libacl.h>
  27. #endif
  28. #define SMB_MALLOC(cnt) new_array(char, cnt)
  29. #define SMB_MALLOC_P(obj) new_array(obj, 1)
  30. #define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
  31. #define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
  32. #define slprintf snprintf
  33. #if defined HAVE_POSIX_ACLS /*-----------------------------------------------*/
  34. /* This is an identity mapping (just remove the SMB_). */
  35. #define SMB_ACL_TAG_T acl_tag_t
  36. #define SMB_ACL_TYPE_T acl_type_t
  37. /* Types of ACLs. */
  38. #define SMB_ACL_USER ACL_USER
  39. #define SMB_ACL_USER_OBJ ACL_USER_OBJ
  40. #define SMB_ACL_GROUP ACL_GROUP
  41. #define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
  42. #define SMB_ACL_OTHER ACL_OTHER
  43. #define SMB_ACL_MASK ACL_MASK
  44. #define SMB_ACL_T acl_t
  45. #define SMB_ACL_ENTRY_T acl_entry_t
  46. #define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
  47. #define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
  48. #define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
  49. #define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
  50. #define SMB_ACL_VALID_NAME_BITS (4 | 2 | 1)
  51. #define SMB_ACL_VALID_OBJ_BITS (4 | 2 | 1)
  52. #define SMB_ACL_NEED_SORT
  53. #elif defined HAVE_TRU64_ACLS /*---------------------------------------------*/
  54. /* This is for DEC/Compaq Tru64 UNIX */
  55. #define SMB_ACL_TAG_T acl_tag_t
  56. #define SMB_ACL_TYPE_T acl_type_t
  57. /* Types of ACLs. */
  58. #define SMB_ACL_USER ACL_USER
  59. #define SMB_ACL_USER_OBJ ACL_USER_OBJ
  60. #define SMB_ACL_GROUP ACL_GROUP
  61. #define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
  62. #define SMB_ACL_OTHER ACL_OTHER
  63. #define SMB_ACL_MASK ACL_MASK
  64. #define SMB_ACL_T acl_t
  65. #define SMB_ACL_ENTRY_T acl_entry_t
  66. #define SMB_ACL_FIRST_ENTRY 0
  67. #define SMB_ACL_NEXT_ENTRY 1
  68. #define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
  69. #define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
  70. #define SMB_ACL_VALID_NAME_BITS (4 | 2 | 1)
  71. #define SMB_ACL_VALID_OBJ_BITS (4 | 2 | 1)
  72. #define SMB_ACL_NEED_SORT
  73. #elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS /*-------------*/
  74. /* Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
  75. * Modified by Toomas Soome <tsoome@ut.ee> for Solaris. */
  76. /* SVR4.2 ES/MP ACLs */
  77. typedef int SMB_ACL_TAG_T;
  78. typedef int SMB_ACL_TYPE_T;
  79. /* Types of ACLs. */
  80. #define SMB_ACL_USER USER
  81. #define SMB_ACL_USER_OBJ USER_OBJ
  82. #define SMB_ACL_GROUP GROUP
  83. #define SMB_ACL_GROUP_OBJ GROUP_OBJ
  84. #define SMB_ACL_OTHER OTHER_OBJ
  85. #define SMB_ACL_MASK CLASS_OBJ
  86. typedef struct SMB_ACL_T {
  87. int size;
  88. int count;
  89. int next;
  90. struct acl acl[1];
  91. } *SMB_ACL_T;
  92. typedef struct acl *SMB_ACL_ENTRY_T;
  93. #define SMB_ACL_FIRST_ENTRY 0
  94. #define SMB_ACL_NEXT_ENTRY 1
  95. #define SMB_ACL_TYPE_ACCESS 0
  96. #define SMB_ACL_TYPE_DEFAULT 1
  97. #define SMB_ACL_VALID_NAME_BITS (4 | 2 | 1)
  98. #define SMB_ACL_VALID_OBJ_BITS (4 | 2 | 1)
  99. #define SMB_ACL_NEED_SORT
  100. #ifdef __CYGWIN__
  101. #define SMB_ACL_LOSES_SPECIAL_MODE_BITS
  102. #endif
  103. #elif defined HAVE_HPUX_ACLS /*----------------------------------------------*/
  104. /* Based on the Solaris & UnixWare code. */
  105. #undef GROUP
  106. #include <sys/aclv.h>
  107. /* SVR4.2 ES/MP ACLs */
  108. typedef int SMB_ACL_TAG_T;
  109. typedef int SMB_ACL_TYPE_T;
  110. /* Types of ACLs. */
  111. #define SMB_ACL_USER USER
  112. #define SMB_ACL_USER_OBJ USER_OBJ
  113. #define SMB_ACL_GROUP GROUP
  114. #define SMB_ACL_GROUP_OBJ GROUP_OBJ
  115. #define SMB_ACL_OTHER OTHER_OBJ
  116. #define SMB_ACL_MASK CLASS_OBJ
  117. typedef struct SMB_ACL_T {
  118. int size;
  119. int count;
  120. int next;
  121. struct acl acl[1];
  122. } *SMB_ACL_T;
  123. typedef struct acl *SMB_ACL_ENTRY_T;
  124. #define SMB_ACL_FIRST_ENTRY 0
  125. #define SMB_ACL_NEXT_ENTRY 1
  126. #define SMB_ACL_TYPE_ACCESS 0
  127. #define SMB_ACL_TYPE_DEFAULT 1
  128. #define SMB_ACL_VALID_NAME_BITS (4 | 2 | 1)
  129. #define SMB_ACL_VALID_OBJ_BITS (4 | 2 | 1)
  130. #define SMB_ACL_NEED_SORT
  131. #elif defined HAVE_IRIX_ACLS /*----------------------------------------------*/
  132. /* IRIX ACLs */
  133. #define SMB_ACL_TAG_T acl_tag_t
  134. #define SMB_ACL_TYPE_T acl_type_t
  135. /* Types of ACLs. */
  136. #define SMB_ACL_USER ACL_USER
  137. #define SMB_ACL_USER_OBJ ACL_USER_OBJ
  138. #define SMB_ACL_GROUP ACL_GROUP
  139. #define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
  140. #define SMB_ACL_OTHER ACL_OTHER_OBJ
  141. #define SMB_ACL_MASK ACL_MASK
  142. typedef struct SMB_ACL_T {
  143. int next;
  144. BOOL freeaclp;
  145. struct acl *aclp;
  146. } *SMB_ACL_T;
  147. #define SMB_ACL_ENTRY_T acl_entry_t
  148. #define SMB_ACL_FIRST_ENTRY 0
  149. #define SMB_ACL_NEXT_ENTRY 1
  150. #define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
  151. #define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
  152. #define SMB_ACL_VALID_NAME_BITS (4 | 2 | 1)
  153. #define SMB_ACL_VALID_OBJ_BITS (4 | 2 | 1)
  154. #define SMB_ACL_NEED_SORT
  155. #elif defined HAVE_AIX_ACLS /*-----------------------------------------------*/
  156. /* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
  157. #include "/usr/include/acl.h"
  158. struct acl_entry_link{
  159. struct acl_entry_link *prevp;
  160. struct new_acl_entry *entryp;
  161. struct acl_entry_link *nextp;
  162. int count;
  163. };
  164. struct new_acl_entry{
  165. unsigned short ace_len;
  166. unsigned short ace_type;
  167. unsigned int ace_access;
  168. struct ace_id ace_id[1];
  169. };
  170. #define SMB_ACL_ENTRY_T struct new_acl_entry*
  171. #define SMB_ACL_T struct acl_entry_link*
  172. #define SMB_ACL_TAG_T unsigned short
  173. #define SMB_ACL_TYPE_T int
  174. /* Types of ACLs. */
  175. #define SMB_ACL_USER ACEID_USER
  176. #define SMB_ACL_USER_OBJ 3
  177. #define SMB_ACL_GROUP ACEID_GROUP
  178. #define SMB_ACL_GROUP_OBJ 4
  179. #define SMB_ACL_OTHER 5
  180. #define SMB_ACL_MASK 6
  181. #define SMB_ACL_FIRST_ENTRY 1
  182. #define SMB_ACL_NEXT_ENTRY 2
  183. #define SMB_ACL_TYPE_ACCESS 0
  184. #define SMB_ACL_TYPE_DEFAULT 1
  185. #define SMB_ACL_VALID_NAME_BITS (4 | 2 | 1)
  186. #define SMB_ACL_VALID_OBJ_BITS (4 | 2 | 1)
  187. #define SMB_ACL_NEED_SORT
  188. #elif defined(HAVE_OSX_ACLS) /*----------------------------------------------*/
  189. /* Special handling for OS X ACLs */
  190. #define SMB_ACL_TAG_T acl_tag_t
  191. #define SMB_ACL_TYPE_T acl_type_t
  192. #define SMB_ACL_T acl_t
  193. #define SMB_ACL_ENTRY_T acl_entry_t
  194. #define SMB_ACL_USER 1
  195. #define SMB_ACL_GROUP 2
  196. #define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
  197. #define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
  198. #define SMB_ACL_TYPE_ACCESS ACL_TYPE_EXTENDED
  199. #define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
  200. #define SMB_ACL_VALID_NAME_BITS ((1<<25)-1)
  201. #define SMB_ACL_VALID_OBJ_BITS 0
  202. /*#undef SMB_ACL_NEED_SORT*/
  203. #else /*---------------------------------------------------------------------*/
  204. /* Unknown platform. */
  205. #error Cannot handle ACLs on this platform!
  206. #endif
  207. int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
  208. int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
  209. int sys_acl_get_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T *tag_type_p, uint32 *bits_p, id_t *u_g_id_p);
  210. SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
  211. SMB_ACL_T sys_acl_get_fd(int fd);
  212. SMB_ACL_T sys_acl_init(int count);
  213. int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
  214. int sys_acl_set_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype, uint32 bits, id_t u_g_id);
  215. int sys_acl_set_access_bits(SMB_ACL_ENTRY_T entry, uint32 bits);
  216. int sys_acl_valid(SMB_ACL_T theacl);
  217. int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
  218. int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
  219. int sys_acl_delete_def_file(const char *name);
  220. int sys_acl_free_acl(SMB_ACL_T the_acl);
  221. int no_acl_syscall_error(int err);
  222. #endif /* SUPPORT_ACLS */