cifsacl.c 4.2 KB

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