smbacl.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* SPDX-License-Identifier: LGPL-2.1+ */
  2. /*
  3. * Copyright (c) International Business Machines Corp., 2007
  4. * Author(s): Steve French (sfrench@us.ibm.com)
  5. * Modified by Namjae Jeon (linkinjeon@kernel.org)
  6. */
  7. #ifndef _SMBACL_H
  8. #define _SMBACL_H
  9. #include "../common/smbacl.h"
  10. #include <linux/fs.h>
  11. #include <linux/namei.h>
  12. #include <linux/posix_acl.h>
  13. #include <linux/mnt_idmapping.h>
  14. #include "mgmt/tree_connect.h"
  15. /* Revision for ACLs */
  16. #define SD_REVISION 1
  17. /* Control flags for Security Descriptor */
  18. #define OWNER_DEFAULTED 0x0001
  19. #define GROUP_DEFAULTED 0x0002
  20. #define DACL_PRESENT 0x0004
  21. #define DACL_DEFAULTED 0x0008
  22. #define SACL_PRESENT 0x0010
  23. #define SACL_DEFAULTED 0x0020
  24. #define DACL_TRUSTED 0x0040
  25. #define SERVER_SECURITY 0x0080
  26. #define DACL_AUTO_INHERIT_REQ 0x0100
  27. #define SACL_AUTO_INHERIT_REQ 0x0200
  28. #define DACL_AUTO_INHERITED 0x0400
  29. #define SACL_AUTO_INHERITED 0x0800
  30. #define DACL_PROTECTED 0x1000
  31. #define SACL_PROTECTED 0x2000
  32. #define RM_CONTROL_VALID 0x4000
  33. #define SELF_RELATIVE 0x8000
  34. struct ksmbd_conn;
  35. struct smb_fattr {
  36. kuid_t cf_uid;
  37. kgid_t cf_gid;
  38. umode_t cf_mode;
  39. __le32 daccess;
  40. struct posix_acl *cf_acls;
  41. struct posix_acl *cf_dacls;
  42. };
  43. struct posix_ace_state {
  44. u32 allow;
  45. u32 deny;
  46. };
  47. struct posix_user_ace_state {
  48. union {
  49. kuid_t uid;
  50. kgid_t gid;
  51. };
  52. struct posix_ace_state perms;
  53. };
  54. struct posix_ace_state_array {
  55. int n;
  56. struct posix_user_ace_state aces[];
  57. };
  58. /*
  59. * while processing the nfsv4 ace, this maintains the partial permissions
  60. * calculated so far:
  61. */
  62. struct posix_acl_state {
  63. struct posix_ace_state owner;
  64. struct posix_ace_state group;
  65. struct posix_ace_state other;
  66. struct posix_ace_state everyone;
  67. struct posix_ace_state mask; /* deny unused in this case */
  68. struct posix_ace_state_array *users;
  69. struct posix_ace_state_array *groups;
  70. };
  71. int parse_sec_desc(struct mnt_idmap *idmap, struct smb_ntsd *pntsd,
  72. int acl_len, struct smb_fattr *fattr);
  73. int build_sec_desc(struct mnt_idmap *idmap, struct smb_ntsd *pntsd,
  74. struct smb_ntsd *ppntsd, int ppntsd_size, int addition_info,
  75. __u32 *secdesclen, struct smb_fattr *fattr);
  76. int init_acl_state(struct posix_acl_state *state, u16 cnt);
  77. void free_acl_state(struct posix_acl_state *state);
  78. void posix_state_to_acl(struct posix_acl_state *state,
  79. struct posix_acl_entry *pace);
  80. int compare_sids(const struct smb_sid *ctsid, const struct smb_sid *cwsid);
  81. bool smb_inherit_flags(int flags, bool is_dir);
  82. int smb_inherit_dacl(struct ksmbd_conn *conn, const struct path *path,
  83. unsigned int uid, unsigned int gid);
  84. int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,
  85. __le32 *pdaccess, int uid);
  86. int set_info_sec(struct ksmbd_conn *conn, struct ksmbd_tree_connect *tcon,
  87. const struct path *path, struct smb_ntsd *pntsd, int ntsd_len,
  88. bool type_check, bool get_write);
  89. void id_to_sid(unsigned int cid, uint sidtype, struct smb_sid *ssid);
  90. void ksmbd_init_domain(u32 *sub_auth);
  91. static inline uid_t posix_acl_uid_translate(struct mnt_idmap *idmap,
  92. struct posix_acl_entry *pace)
  93. {
  94. vfsuid_t vfsuid;
  95. /* If this is an idmapped mount, apply the idmapping. */
  96. vfsuid = make_vfsuid(idmap, &init_user_ns, pace->e_uid);
  97. /* Translate the kuid into a userspace id ksmbd would see. */
  98. return from_kuid(&init_user_ns, vfsuid_into_kuid(vfsuid));
  99. }
  100. static inline gid_t posix_acl_gid_translate(struct mnt_idmap *idmap,
  101. struct posix_acl_entry *pace)
  102. {
  103. vfsgid_t vfsgid;
  104. /* If this is an idmapped mount, apply the idmapping. */
  105. vfsgid = make_vfsgid(idmap, &init_user_ns, pace->e_gid);
  106. /* Translate the kgid into a userspace id ksmbd would see. */
  107. return from_kgid(&init_user_ns, vfsgid_into_kgid(vfsgid));
  108. }
  109. #endif /* _SMBACL_H */