/source3/modules/vfs_aixacl.c

https://bitbucket.org/knarf/samba · C · 197 lines · 136 code · 36 blank · 25 comment · 24 complexity · 2f911e6fa2b187c3288b482e309361fb MD5 · raw file

  1. /*
  2. Unix SMB/Netbios implementation.
  3. VFS module to get and set posix acls
  4. Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2006
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "includes.h"
  17. #include "system/filesys.h"
  18. #include "smbd/smbd.h"
  19. #include "vfs_aixacl_util.h"
  20. SMB_ACL_T aixacl_sys_acl_get_file(vfs_handle_struct *handle,
  21. const char *path_p,
  22. SMB_ACL_TYPE_T type,
  23. TALLOC_CTX *mem_ctx)
  24. {
  25. struct acl *file_acl = (struct acl *)NULL;
  26. struct smb_acl_t *result = (struct smb_acl_t *)NULL;
  27. int rc = 0;
  28. uid_t user_id;
  29. /* AIX has no DEFAULT */
  30. if ( type == SMB_ACL_TYPE_DEFAULT )
  31. return NULL;
  32. /* Get the acl using statacl */
  33. DEBUG(10,("Entering AIX sys_acl_get_file\n"));
  34. DEBUG(10,("path_p is %s\n",path_p));
  35. file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
  36. if(file_acl == NULL) {
  37. errno=ENOMEM;
  38. DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
  39. return(NULL);
  40. }
  41. memset(file_acl,0,BUFSIZ);
  42. rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
  43. if( (rc == -1) && (errno == ENOSPC)) {
  44. struct acl *new_acl = SMB_MALLOC(file_acl->acl_len + sizeof(struct acl));
  45. if( new_acl == NULL) {
  46. SAFE_FREE(file_acl);
  47. errno = ENOMEM;
  48. return NULL;
  49. }
  50. file_acl = new_acl;
  51. rc = statacl((char *)path_p,0,file_acl,file_acl->acl_len+sizeof(struct acl));
  52. if( rc == -1) {
  53. DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
  54. SAFE_FREE(file_acl);
  55. return(NULL);
  56. }
  57. }
  58. DEBUG(10,("Got facl and returned it\n"));
  59. result = aixacl_to_smbacl(file_acl, mem_ctx);
  60. SAFE_FREE(file_acl);
  61. return result;
  62. /*errno = ENOTSUP;
  63. return NULL;*/
  64. }
  65. SMB_ACL_T aixacl_sys_acl_get_fd(vfs_handle_struct *handle,
  66. files_struct *fsp,
  67. TALLOC_CTX *mem_ctx)
  68. {
  69. struct acl *file_acl = (struct acl *)NULL;
  70. struct smb_acl_t *result = (struct smb_acl_t *)NULL;
  71. int rc = 0;
  72. uid_t user_id;
  73. /* Get the acl using fstatacl */
  74. DEBUG(10,("Entering AIX sys_acl_get_fd\n"));
  75. DEBUG(10,("fd is %d\n",fsp->fh->fd));
  76. file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
  77. if(file_acl == NULL) {
  78. errno=ENOMEM;
  79. DEBUG(0,("Error in AIX sys_acl_get_fd is %d\n",errno));
  80. return(NULL);
  81. }
  82. memset(file_acl,0,BUFSIZ);
  83. rc = fstatacl(fsp->fh->fd,0,file_acl,BUFSIZ);
  84. if( (rc == -1) && (errno == ENOSPC)) {
  85. struct acl *new_acl = SMB_MALLOC(file_acl->acl_len + sizeof(struct acl));
  86. if( new_acl == NULL) {
  87. SAFE_FREE(file_acl);
  88. errno = ENOMEM;
  89. return NULL;
  90. }
  91. file_acl = new_acl;
  92. rc = fstatacl(fsp->fh->fd,0,file_acl,file_acl->acl_len + sizeof(struct acl));
  93. if( rc == -1) {
  94. DEBUG(0,("fstatacl returned %d with errno %d\n",rc,errno));
  95. SAFE_FREE(file_acl);
  96. return(NULL);
  97. }
  98. }
  99. DEBUG(10,("Got facl and returned it\n"));
  100. result = aixacl_to_smbacl(file_acl, mem_ctx);
  101. SAFE_FREE(file_acl);
  102. return result;
  103. /*errno = ENOTSUP;
  104. return NULL;*/
  105. }
  106. int aixacl_sys_acl_set_file(vfs_handle_struct *handle,
  107. const char *name,
  108. SMB_ACL_TYPE_T type,
  109. SMB_ACL_T theacl)
  110. {
  111. struct acl *file_acl = NULL;
  112. unsigned int rc;
  113. file_acl = aixacl_smb_to_aixacl(type, theacl);
  114. if (!file_acl)
  115. return -1;
  116. rc = chacl((char *)name,file_acl,file_acl->acl_len);
  117. DEBUG(10,("errno is %d\n",errno));
  118. DEBUG(10,("return code is %d\n",rc));
  119. SAFE_FREE(file_acl);
  120. DEBUG(10,("Exiting the aixacl_sys_acl_set_file\n"));
  121. return rc;
  122. }
  123. int aixacl_sys_acl_set_fd(vfs_handle_struct *handle,
  124. files_struct *fsp,
  125. SMB_ACL_T theacl)
  126. {
  127. struct acl *file_acl = NULL;
  128. unsigned int rc;
  129. file_acl = aixacl_smb_to_aixacl(SMB_ACL_TYPE_ACCESS, theacl);
  130. if (!file_acl)
  131. return -1;
  132. rc = fchacl(fsp->fh->fd,file_acl,file_acl->acl_len);
  133. DEBUG(10,("errno is %d\n",errno));
  134. DEBUG(10,("return code is %d\n",rc));
  135. SAFE_FREE(file_acl);
  136. DEBUG(10,("Exiting aixacl_sys_acl_set_fd\n"));
  137. return rc;
  138. }
  139. int aixacl_sys_acl_delete_def_file(vfs_handle_struct *handle,
  140. const char *path)
  141. {
  142. return 0; /* otherwise you can't set acl at upper level */
  143. }
  144. static struct vfs_fn_pointers vfs_aixacl_fns = {
  145. .sys_acl_get_file_fn = aixacl_sys_acl_get_file,
  146. .sys_acl_get_fd_fn = aixacl_sys_acl_get_fd,
  147. .sys_acl_blob_get_file_fn = posix_sys_acl_blob_get_file,
  148. .sys_acl_blob_get_fd_fn = posix_sys_acl_blob_get_fd,
  149. .sys_acl_set_file_fn = aixacl_sys_acl_set_file,
  150. .sys_acl_set_fd_fn = aixacl_sys_acl_set_fd,
  151. .sys_acl_delete_def_file_fn = aixacl_sys_acl_delete_def_file,
  152. };
  153. NTSTATUS vfs_aixacl_init(void);
  154. NTSTATUS vfs_aixacl_init(void)
  155. {
  156. return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "aixacl",
  157. &vfs_aixacl_fns);
  158. }