cifsacl.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 "cifsproto.h"
  27. #include "cifs_debug.h"
  28. #include "cifsacl.h"
  29. /* security id for everyone */
  30. static const struct cifs_sid sid_everyone =
  31. {1, 1, {0, 0, 0, 0, 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}, {32, 545, 0, 0}};
  35. static int parse_sid(struct cifs_sid *psid, char *end_of_acl)
  36. {
  37. /* BB need to add parm so we can store the SID BB */
  38. /* validate that we do not go past end of acl */
  39. if (end_of_acl < (char *)psid + sizeof(struct cifs_sid)) {
  40. cERROR(1, ("ACL to small to parse SID"));
  41. return -EINVAL;
  42. }
  43. #ifdef CONFIG_CIFS_DEBUG2
  44. cFYI(1, ("revision %d num_auth %d First subauth 0x%x",
  45. psid->revision, psid->num_subauth, psid->sub_auth[0]));
  46. /* BB add length check to make sure that we do not have huge num auths
  47. and therefore go off the end */
  48. cFYI(1, ("RID 0x%x", le32_to_cpu(psid->sub_auth[psid->num_subauth])));
  49. #endif
  50. return 0;
  51. }
  52. /* Convert CIFS ACL to POSIX form */
  53. int parse_sec_desc(struct cifs_ntsd *pntsd, int acl_len)
  54. {
  55. int i, rc;
  56. int num_aces = 0;
  57. int acl_size;
  58. struct cifs_sid *owner_sid_ptr, *group_sid_ptr;
  59. struct cifs_acl *dacl_ptr; /* no need for SACL ptr */
  60. struct cifs_ntace **ppntace;
  61. struct cifs_ace **ppace;
  62. char *acl_base;
  63. char *end_of_acl = ((char *)pntsd) + acl_len;
  64. owner_sid_ptr = (struct cifs_sid *)((char *)pntsd +
  65. cpu_to_le32(pntsd->osidoffset));
  66. group_sid_ptr = (struct cifs_sid *)((char *)pntsd +
  67. cpu_to_le32(pntsd->gsidoffset));
  68. dacl_ptr = (struct cifs_acl *)((char *)pntsd +
  69. cpu_to_le32(pntsd->dacloffset));
  70. #ifdef CONFIG_CIFS_DEBUG2
  71. cFYI(1, ("revision %d type 0x%x ooffset 0x%x goffset 0x%x "
  72. "sacloffset 0x%x dacloffset 0x%x",
  73. pntsd->revision, pntsd->type,
  74. pntsd->osidoffset, pntsd->gsidoffset, pntsd->sacloffset,
  75. pntsd->dacloffset));
  76. #endif
  77. rc = parse_sid(owner_sid_ptr, end_of_acl);
  78. if (rc)
  79. return rc;
  80. rc = parse_sid(group_sid_ptr, end_of_acl);
  81. if (rc)
  82. return rc;
  83. /* cifscred->uid = owner_sid_ptr->rid;
  84. cifscred->gid = group_sid_ptr->rid;
  85. memcpy((void *)(&(cifscred->osid)), (void *)owner_sid_ptr,
  86. sizeof (struct cifs_sid));
  87. memcpy((void *)(&(cifscred->gsid)), (void *)group_sid_ptr,
  88. sizeof (struct cifs_sid)); */
  89. num_aces = cpu_to_le32(dacl_ptr->num_aces);
  90. cFYI(1, ("num aces %d", num_aces));
  91. if (num_aces > 0) {
  92. ppntace = kmalloc(num_aces * sizeof(struct cifs_ntace *),
  93. GFP_KERNEL);
  94. ppace = kmalloc(num_aces * sizeof(struct cifs_ace *),
  95. GFP_KERNEL);
  96. /* cifscred->cecount = dacl_ptr->num_aces;
  97. cifscred->ntaces = kmalloc(num_aces *
  98. sizeof(struct cifs_ntace *), GFP_KERNEL);
  99. cifscred->aces = kmalloc(num_aces *
  100. sizeof(struct cifs_ace *), GFP_KERNEL);*/
  101. acl_base = (char *)dacl_ptr;
  102. acl_size = sizeof(struct cifs_acl);
  103. for (i = 0; i < num_aces; ++i) {
  104. ppntace[i] = (struct cifs_ntace *)
  105. (acl_base + acl_size);
  106. ppace[i] = (struct cifs_ace *)
  107. ((char *)ppntace[i] +
  108. sizeof(struct cifs_ntace));
  109. /* memcpy((void *)(&(cifscred->ntaces[i])),
  110. (void *)ntace_ptrptr[i],
  111. sizeof(struct cifs_ntace));
  112. memcpy((void *)(&(cifscred->aces[i])),
  113. (void *)ace_ptrptr[i],
  114. sizeof(struct cifs_ace)); */
  115. acl_base = (char *)ppntace[i];
  116. acl_size = cpu_to_le32(ppntace[i]->size);
  117. #ifdef CONFIG_CIFS_DEBUG2
  118. cFYI(1, ("ACE revision:%d", ppace[i]->revision));
  119. #endif
  120. }
  121. kfree(ppace);
  122. kfree(ppntace);
  123. }
  124. return (0);
  125. }