cifsacl.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * fs/cifs/cifsacl.c
  3. *
  4. * Copyright (C) International Business Machines Corp., 2007
  5. * Author(s): Steve French (sfrench@us.ibm.com)
  6. *
  7. * Contains the routines for mapping CIFS/NTFS ACLs
  8. *
  9. * This library is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU Lesser General Public License as published
  11. * by the Free Software Foundation; either version 2.1 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  17. * the GNU Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public License
  20. * along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. #include <linux/fs.h>
  24. #include "cifspdu.h"
  25. #include "cifsglob.h"
  26. #include "cifsacl.h"
  27. #include "cifsproto.h"
  28. #include "cifs_debug.h"
  29. /* security id for everyone */
  30. static const struct cifs_sid sid_everyone =
  31. {1, 1, {0, 0, 0, 0, 0, 0}, {}};
  32. /* group users */
  33. static const struct cifs_sid sid_user =
  34. {1, 2 , {0, 0, 0, 0, 0, 5}, {}};
  35. static void parse_ace(struct cifs_ace * pace, char * end_of_acl)
  36. {
  37. int i;
  38. int num_subauth;
  39. __u32 *psub_auth;
  40. /* validate that we do not go past end of acl */
  41. if (end_of_acl < (char *)pace + sizeof(struct cifs_ace)) {
  42. cERROR(1, ("ACL too small to parse ACE"));
  43. return;
  44. }
  45. num_subauth = cpu_to_le32(pace->num_subauth);
  46. if (num_subauth) {
  47. psub_auth = (__u32 *)((char *)pace + sizeof(struct cifs_ace));
  48. #ifdef CONFIG_CIFS_DEBUG2
  49. cFYI(1, ("ACE revision %d num_subauth %d",
  50. pace->revision, pace->num_subauth));
  51. for (i = 0; i < num_subauth; ++i) {
  52. cFYI(1, ("ACE sub_auth[%d]: 0x%x", i,
  53. le32_to_cpu(psub_auth[i])));
  54. }
  55. /* BB add length check to make sure that we do not have huge
  56. num auths and therefore go off the end */
  57. cFYI(1, ("RID %d", le32_to_cpu(psub_auth[num_subauth-1])));
  58. #endif
  59. }
  60. return;
  61. }
  62. static void parse_ntace(struct cifs_ntace * pntace, char * end_of_acl)
  63. {
  64. /* validate that we do not go past end of acl */
  65. if (end_of_acl < (char *)pntace + sizeof(struct cifs_ntace)) {
  66. cERROR(1, ("ACL too small to parse NT ACE"));
  67. return;
  68. }
  69. #ifdef CONFIG_CIFS_DEBUG2
  70. cFYI(1, ("NTACE type %d flags 0x%x size %d, access Req 0x%x",
  71. pntace->type, pntace->flags, pntace->size,
  72. pntace->access_req));
  73. #endif
  74. return;
  75. }
  76. static void parse_dacl(struct cifs_acl * pdacl, char * end_of_acl)
  77. {
  78. int i;
  79. int num_aces = 0;
  80. int acl_size;
  81. char *acl_base;
  82. struct cifs_ntace **ppntace;
  83. struct cifs_ace **ppace;
  84. /* BB need to add parm so we can store the SID BB */
  85. /* validate that we do not go past end of acl */
  86. if (end_of_acl < (char *)pdacl + pdacl->size) {
  87. cERROR(1, ("ACL too small to parse DACL"));
  88. return;
  89. }
  90. #ifdef CONFIG_CIFS_DEBUG2
  91. cFYI(1, ("DACL revision %d size %d num aces %d",
  92. pdacl->revision, pdacl->size, pdacl->num_aces));
  93. #endif
  94. acl_base = (char *)pdacl;
  95. acl_size = sizeof(struct cifs_acl);
  96. num_aces = cpu_to_le32(pdacl->num_aces);
  97. if (num_aces > 0) {
  98. ppntace = kmalloc(num_aces * sizeof(struct cifs_ntace *),
  99. GFP_KERNEL);
  100. ppace = kmalloc(num_aces * sizeof(struct cifs_ace *),
  101. GFP_KERNEL);
  102. /* cifscred->cecount = pdacl->num_aces;
  103. cifscred->ntaces = kmalloc(num_aces *
  104. sizeof(struct cifs_ntace *), GFP_KERNEL);
  105. cifscred->aces = kmalloc(num_aces *
  106. sizeof(struct cifs_ace *), GFP_KERNEL);*/
  107. for (i = 0; i < num_aces; ++i) {
  108. ppntace[i] = (struct cifs_ntace *)
  109. (acl_base + acl_size);
  110. ppace[i] = (struct cifs_ace *) ((char *)ppntace[i] +
  111. sizeof(struct cifs_ntace));
  112. parse_ntace(ppntace[i], end_of_acl);
  113. parse_ace(ppace[i], end_of_acl);
  114. /* memcpy((void *)(&(cifscred->ntaces[i])),
  115. (void *)ppntace[i],
  116. sizeof(struct cifs_ntace));
  117. memcpy((void *)(&(cifscred->aces[i])),
  118. (void *)ppace[i],
  119. sizeof(struct cifs_ace)); */
  120. acl_base = (char *)ppntace[i];
  121. acl_size = cpu_to_le32(ppntace[i]->size);
  122. }
  123. kfree(ppace);
  124. kfree(ppntace);
  125. }
  126. return;
  127. }
  128. static int parse_sid(struct cifs_sid *psid, char *end_of_acl)
  129. {
  130. int i;
  131. int num_subauth;
  132. __u32 *psub_auth;
  133. /* BB need to add parm so we can store the SID BB */
  134. /* validate that we do not go past end of acl */
  135. if (end_of_acl < (char *)psid + sizeof(struct cifs_sid)) {
  136. cERROR(1, ("ACL too small to parse SID"));
  137. return -EINVAL;
  138. }
  139. num_subauth = cpu_to_le32(psid->num_subauth);
  140. if (num_subauth) {
  141. psub_auth = (__u32 *)((char *)psid + sizeof(struct cifs_sid));
  142. #ifdef CONFIG_CIFS_DEBUG2
  143. cFYI(1, ("SID revision %d num_auth %d First subauth 0x%x",
  144. psid->revision, psid->num_subauth, psid->sub_auth[0]));
  145. for (i = 0; i < num_subauth; ++i) {
  146. cFYI(1, ("SID sub_auth[%d]: 0x%x ", i,
  147. le32_to_cpu(psub_auth[i])));
  148. }
  149. /* BB add length check to make sure that we do not have huge
  150. num auths and therefore go off the end */
  151. cFYI(1, ("RID 0x%x",
  152. le32_to_cpu(psid->sub_auth[psid->num_subauth])));
  153. #endif
  154. }
  155. return 0;
  156. }
  157. /* Convert CIFS ACL to POSIX form */
  158. int parse_sec_desc(struct cifs_ntsd *pntsd, int acl_len)
  159. {
  160. int rc;
  161. struct cifs_sid *owner_sid_ptr, *group_sid_ptr;
  162. struct cifs_acl *dacl_ptr; /* no need for SACL ptr */
  163. char *end_of_acl = ((char *)pntsd) + acl_len;
  164. owner_sid_ptr = (struct cifs_sid *)((char *)pntsd +
  165. cpu_to_le32(pntsd->osidoffset));
  166. group_sid_ptr = (struct cifs_sid *)((char *)pntsd +
  167. cpu_to_le32(pntsd->gsidoffset));
  168. dacl_ptr = (struct cifs_acl *)((char *)pntsd +
  169. cpu_to_le32(pntsd->dacloffset));
  170. #ifdef CONFIG_CIFS_DEBUG2
  171. cFYI(1, ("revision %d type 0x%x ooffset 0x%x goffset 0x%x "
  172. "sacloffset 0x%x dacloffset 0x%x",
  173. pntsd->revision, pntsd->type,
  174. pntsd->osidoffset, pntsd->gsidoffset, pntsd->sacloffset,
  175. pntsd->dacloffset));
  176. #endif
  177. rc = parse_sid(owner_sid_ptr, end_of_acl);
  178. if (rc)
  179. return rc;
  180. rc = parse_sid(group_sid_ptr, end_of_acl);
  181. if (rc)
  182. return rc;
  183. parse_dacl(dacl_ptr, end_of_acl);
  184. /* cifscred->uid = owner_sid_ptr->rid;
  185. cifscred->gid = group_sid_ptr->rid;
  186. memcpy((void *)(&(cifscred->osid)), (void *)owner_sid_ptr,
  187. sizeof (struct cifs_sid));
  188. memcpy((void *)(&(cifscred->gsid)), (void *)group_sid_ptr,
  189. sizeof (struct cifs_sid)); */
  190. return (0);
  191. }