Steve Kondik | 2111ad7 | 2013-07-07 12:07:44 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) 2007-2008 Jean-Pierre Andre |
| 4 | * |
| 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program (in the main directory of the NTFS-3G |
| 20 | * distribution in the file COPYING); if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #ifndef ACLS_H |
| 25 | #define ACLS_H |
| 26 | |
Steve Kondik | e68cb60 | 2016-08-28 00:45:36 -0700 | [diff] [blame] | 27 | #include "endians.h" |
| 28 | |
Steve Kondik | 2111ad7 | 2013-07-07 12:07:44 -0700 | [diff] [blame] | 29 | /* |
| 30 | * JPA configuration modes for security.c / acls.c |
| 31 | * should be moved to some config file |
| 32 | */ |
| 33 | |
| 34 | #define BUFSZ 1024 /* buffer size to read mapping file */ |
| 35 | #define MAPPINGFILE ".NTFS-3G/UserMapping" /* default mapping file */ |
| 36 | #define LINESZ 120 /* maximum useful size of a mapping line */ |
| 37 | #define CACHE_PERMISSIONS_BITS 6 /* log2 of unitary allocation of permissions */ |
| 38 | #define CACHE_PERMISSIONS_SIZE 262144 /* max cacheable permissions */ |
| 39 | |
| 40 | /* |
Steve Kondik | 2111ad7 | 2013-07-07 12:07:44 -0700 | [diff] [blame] | 41 | * Macro definitions needed to share code with secaudit |
| 42 | */ |
| 43 | |
| 44 | #define NTFS_FIND_USID(map,uid,buf) ntfs_find_usid(map,uid,buf) |
| 45 | #define NTFS_FIND_GSID(map,gid,buf) ntfs_find_gsid(map,gid,buf) |
| 46 | #define NTFS_FIND_USER(map,usid) ntfs_find_user(map,usid) |
| 47 | #define NTFS_FIND_GROUP(map,gsid) ntfs_find_group(map,gsid) |
| 48 | |
| 49 | |
| 50 | /* |
| 51 | * Matching of ntfs permissions to Linux permissions |
| 52 | * these constants are adapted to endianness |
| 53 | * when setting, set them all |
| 54 | * when checking, check one is present |
| 55 | */ |
| 56 | |
| 57 | /* flags which are set to mean exec, write or read */ |
| 58 | |
| 59 | #define FILE_READ (FILE_READ_DATA) |
| 60 | #define FILE_WRITE (FILE_WRITE_DATA | FILE_APPEND_DATA \ |
| 61 | | READ_CONTROL | FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA) |
| 62 | #define FILE_EXEC (FILE_EXECUTE) |
| 63 | #define DIR_READ FILE_LIST_DIRECTORY |
| 64 | #define DIR_WRITE (FILE_ADD_FILE | FILE_ADD_SUBDIRECTORY | FILE_DELETE_CHILD \ |
| 65 | | READ_CONTROL | FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA) |
| 66 | #define DIR_EXEC (FILE_TRAVERSE) |
| 67 | |
| 68 | /* flags tested for meaning exec, write or read */ |
| 69 | /* tests for write allow for interpretation of a sticky bit */ |
| 70 | |
| 71 | #define FILE_GREAD (FILE_READ_DATA | GENERIC_READ) |
| 72 | #define FILE_GWRITE (FILE_WRITE_DATA | FILE_APPEND_DATA | GENERIC_WRITE) |
| 73 | #define FILE_GEXEC (FILE_EXECUTE | GENERIC_EXECUTE) |
| 74 | #define DIR_GREAD (FILE_LIST_DIRECTORY | GENERIC_READ) |
| 75 | #define DIR_GWRITE (FILE_ADD_FILE | FILE_ADD_SUBDIRECTORY | GENERIC_WRITE) |
| 76 | #define DIR_GEXEC (FILE_TRAVERSE | GENERIC_EXECUTE) |
| 77 | |
| 78 | /* standard owner (and administrator) rights */ |
| 79 | |
| 80 | #define OWNER_RIGHTS (DELETE | READ_CONTROL | WRITE_DAC | WRITE_OWNER \ |
| 81 | | SYNCHRONIZE \ |
| 82 | | FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES \ |
| 83 | | FILE_READ_EA | FILE_WRITE_EA) |
| 84 | |
| 85 | /* standard world rights */ |
| 86 | |
| 87 | #define WORLD_RIGHTS (READ_CONTROL | FILE_READ_ATTRIBUTES | FILE_READ_EA \ |
| 88 | | SYNCHRONIZE) |
| 89 | |
| 90 | /* inheritance flags for files and directories */ |
| 91 | |
| 92 | #define FILE_INHERITANCE NO_PROPAGATE_INHERIT_ACE |
| 93 | #define DIR_INHERITANCE (OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE) |
| 94 | |
| 95 | /* |
| 96 | * To identify NTFS ACL meaning Posix ACL granted to root |
| 97 | * we use rights always granted to anybody, so they have no impact |
| 98 | * either on Windows or on Linux. |
| 99 | */ |
| 100 | |
| 101 | #define ROOT_OWNER_UNMARK SYNCHRONIZE /* ACL granted to root as owner */ |
| 102 | #define ROOT_GROUP_UNMARK FILE_READ_EA /* ACL granted to root as group */ |
| 103 | |
| 104 | /* |
| 105 | * A type large enough to hold any SID |
| 106 | */ |
| 107 | |
| 108 | typedef char BIGSID[40]; |
| 109 | |
| 110 | /* |
| 111 | * Struct to hold the input mapping file |
| 112 | * (private to this module) |
| 113 | */ |
| 114 | |
| 115 | struct MAPLIST { |
| 116 | struct MAPLIST *next; |
| 117 | char *uidstr; /* uid text from the same record */ |
| 118 | char *gidstr; /* gid text from the same record */ |
| 119 | char *sidstr; /* sid text from the same record */ |
| 120 | char maptext[LINESZ + 1]; |
| 121 | }; |
| 122 | |
| 123 | typedef int (*FILEREADER)(void *fileid, char *buf, size_t size, off_t pos); |
| 124 | |
| 125 | /* |
| 126 | * Constants defined in acls.c |
| 127 | */ |
| 128 | |
| 129 | extern const SID *adminsid; |
| 130 | extern const SID *worldsid; |
| 131 | |
| 132 | /* |
| 133 | * Functions defined in acls.c |
| 134 | */ |
| 135 | |
| 136 | BOOL ntfs_valid_descr(const char *securattr, unsigned int attrsz); |
| 137 | BOOL ntfs_valid_pattern(const SID *sid); |
| 138 | BOOL ntfs_valid_sid(const SID *sid); |
| 139 | BOOL ntfs_same_sid(const SID *first, const SID *second); |
| 140 | |
| 141 | BOOL ntfs_is_user_sid(const SID *usid); |
| 142 | |
| 143 | |
| 144 | int ntfs_sid_size(const SID * sid); |
| 145 | unsigned int ntfs_attr_size(const char *attr); |
| 146 | |
| 147 | const SID *ntfs_find_usid(const struct MAPPING *usermapping, |
| 148 | uid_t uid, SID *pdefsid); |
| 149 | const SID *ntfs_find_gsid(const struct MAPPING *groupmapping, |
| 150 | gid_t gid, SID *pdefsid); |
| 151 | uid_t ntfs_find_user(const struct MAPPING *usermapping, const SID *usid); |
| 152 | gid_t ntfs_find_group(const struct MAPPING *groupmapping, const SID * gsid); |
| 153 | const SID *ntfs_acl_owner(const char *secattr); |
| 154 | |
| 155 | #if POSIXACLS |
| 156 | |
| 157 | BOOL ntfs_valid_posix(const struct POSIX_SECURITY *pxdesc); |
| 158 | void ntfs_sort_posix(struct POSIX_SECURITY *pxdesc); |
| 159 | int ntfs_merge_mode_posix(struct POSIX_SECURITY *pxdesc, mode_t mode); |
| 160 | struct POSIX_SECURITY *ntfs_build_inherited_posix( |
| 161 | const struct POSIX_SECURITY *pxdesc, mode_t mode, |
| 162 | mode_t umask, BOOL isdir); |
Steve Kondik | 79165c3 | 2015-11-09 19:43:00 -0800 | [diff] [blame] | 163 | struct POSIX_SECURITY *ntfs_build_basic_posix( |
| 164 | const struct POSIX_SECURITY *pxdesc, mode_t mode, |
| 165 | mode_t umask, BOOL isdir); |
Steve Kondik | 2111ad7 | 2013-07-07 12:07:44 -0700 | [diff] [blame] | 166 | struct POSIX_SECURITY *ntfs_replace_acl(const struct POSIX_SECURITY *oldpxdesc, |
| 167 | const struct POSIX_ACL *newacl, int count, BOOL deflt); |
| 168 | struct POSIX_SECURITY *ntfs_build_permissions_posix( |
| 169 | struct MAPPING* const mapping[], |
| 170 | const char *securattr, |
| 171 | const SID *usid, const SID *gsid, BOOL isdir); |
| 172 | struct POSIX_SECURITY *ntfs_merge_descr_posix(const struct POSIX_SECURITY *first, |
| 173 | const struct POSIX_SECURITY *second); |
| 174 | char *ntfs_build_descr_posix(struct MAPPING* const mapping[], |
| 175 | struct POSIX_SECURITY *pxdesc, |
| 176 | int isdir, const SID *usid, const SID *gsid); |
| 177 | |
| 178 | #endif /* POSIXACLS */ |
| 179 | |
| 180 | int ntfs_inherit_acl(const ACL *oldacl, ACL *newacl, |
| 181 | const SID *usid, const SID *gsid, |
| 182 | BOOL fordir, le16 inherited); |
| 183 | int ntfs_build_permissions(const char *securattr, |
| 184 | const SID *usid, const SID *gsid, BOOL isdir); |
| 185 | char *ntfs_build_descr(mode_t mode, |
| 186 | int isdir, const SID * usid, const SID * gsid); |
| 187 | struct MAPLIST *ntfs_read_mapping(FILEREADER reader, void *fileid); |
| 188 | struct MAPPING *ntfs_do_user_mapping(struct MAPLIST *firstitem); |
| 189 | struct MAPPING *ntfs_do_group_mapping(struct MAPLIST *firstitem); |
| 190 | void ntfs_free_mapping(struct MAPPING *mapping[]); |
| 191 | |
| 192 | #endif /* ACLS_H */ |
| 193 | |