2 * security.h - Exports for handling security/ACLs in NTFS.
3 * Originated from the Linux-NTFS project.
5 * Copyright (c) 2004 Anton Altaparmakov
6 * Copyright (c) 2005-2006 Szabolcs Szakacsits
7 * Copyright (c) 2007-2010 Jean-Pierre Andre
9 * This program/include file is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as published
11 * by the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program/include file is distributed in the hope that it will be
15 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
16 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program (in the main directory of the NTFS-3G
21 * distribution in the file COPYING); if not, write to the Free Software
22 * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #ifndef _NTFS_SECURITY_H
26 #define _NTFS_SECURITY_H
39 * item in the mapping list
44 int xid
; /* linux id : uid or gid */
45 SID
*sid
; /* Windows id : usid or gsid */
46 int grcnt
; /* group count (for users only) */
47 gid_t
*groups
; /* groups which the user is member of */
51 * Entry in the permissions cache
52 * Note : this cache is not organized as a generic cache
55 struct CACHED_PERMISSIONS
{
61 struct POSIX_SECURITY
*pxdesc
;
62 unsigned int pxdescsize
:16;
69 * Entry in the permissions cache for directories with no security_id
72 struct CACHED_PERMISSIONS_LEGACY
{
73 struct CACHED_PERMISSIONS_LEGACY
*next
;
74 struct CACHED_PERMISSIONS_LEGACY
*previous
;
77 union ALIGNMENT payload
[0];
78 /* above fields must match "struct CACHED_GENERIC" */
80 struct CACHED_PERMISSIONS perm
;
84 * Entry in the securid cache
87 struct CACHED_SECURID
{
88 struct CACHED_SECURID
*next
;
89 struct CACHED_SECURID
*previous
;
92 union ALIGNMENT payload
[0];
93 /* above fields must match "struct CACHED_GENERIC" */
101 * Header of the security cache
102 * (has no cache structure by itself)
105 struct CACHED_PERMISSIONS_HEADER
{
107 /* statistics for permissions */
108 unsigned long p_writes
;
109 unsigned long p_reads
;
110 unsigned long p_hits
;
114 * The whole permissions cache
117 struct PERMISSIONS_CACHE
{
118 struct CACHED_PERMISSIONS_HEADER head
;
119 struct CACHED_PERMISSIONS
*cachetable
[1]; /* array of variable size */
123 * Security flags values
127 SECURITY_DEFAULT
, /* rely on fuse for permissions checking */
128 SECURITY_RAW
, /* force same ownership/permissions on files */
129 SECURITY_ACL
, /* enable Posix ACLs (when compiled in) */
130 SECURITY_ADDSECURIDS
, /* upgrade old security descriptors */
131 SECURITY_STATICGRPS
, /* use static groups for access control */
132 SECURITY_WANTED
/* a security related option was present */
136 * Security context, needed by most security functions
139 enum { MAPUSERS
, MAPGROUPS
, MAPCOUNT
} ;
141 struct SECURITY_CONTEXT
{
143 struct MAPPING
*mapping
[MAPCOUNT
];
144 struct PERMISSIONS_CACHE
**pseccache
;
145 uid_t uid
; /* uid of user requesting (not the mounter) */
146 gid_t gid
; /* gid of user requesting (not the mounter) */
147 pid_t tid
; /* thread id of thread requesting */
148 mode_t umask
; /* umask of requesting thread */
154 * Posix ACL structures
161 } __attribute__((__packed__
));
167 struct POSIX_ACE ace
[0];
168 } __attribute__((__packed__
));
170 struct POSIX_SECURITY
{
177 struct POSIX_ACL acl
;
181 * Posix tags, cpu-endian 16 bits
185 POSIX_ACL_USER_OBJ
= 1,
187 POSIX_ACL_GROUP_OBJ
= 4,
190 POSIX_ACL_OTHER
= 32,
191 POSIX_ACL_SPECIAL
= 64 /* internal use only */
194 #define POSIX_ACL_EXTENSIONS (POSIX_ACL_USER | POSIX_ACL_GROUP | POSIX_ACL_MASK)
197 * Posix permissions, cpu-endian 16 bits
204 POSIX_PERM_DENIAL
= 64 /* internal use only */
207 #define POSIX_VERSION 2
211 extern BOOL
ntfs_guid_is_zero(const GUID
*guid
);
212 extern char *ntfs_guid_to_mbs(const GUID
*guid
, char *guid_str
);
214 extern int ntfs_sid_to_mbs_size(const SID
*sid
);
215 extern char *ntfs_sid_to_mbs(const SID
*sid
, char *sid_str
,
216 size_t sid_str_size
);
217 extern void ntfs_generate_guid(GUID
*guid
);
218 extern int ntfs_sd_add_everyone(ntfs_inode
*ni
);
220 extern le32
ntfs_security_hash(const SECURITY_DESCRIPTOR_RELATIVE
*sd
,
223 int ntfs_build_mapping(struct SECURITY_CONTEXT
*scx
, const char *usermap_path
,
225 int ntfs_get_owner_mode(struct SECURITY_CONTEXT
*scx
,
226 ntfs_inode
*ni
, struct stat
*);
227 int ntfs_set_mode(struct SECURITY_CONTEXT
*scx
, ntfs_inode
*ni
, mode_t mode
);
228 BOOL
ntfs_allowed_as_owner(struct SECURITY_CONTEXT
*scx
, ntfs_inode
*ni
);
229 int ntfs_allowed_access(struct SECURITY_CONTEXT
*scx
,
230 ntfs_inode
*ni
, int accesstype
);
231 int ntfs_allowed_create(struct SECURITY_CONTEXT
*scx
,
232 ntfs_inode
*ni
, gid_t
*pgid
, mode_t
*pdsetgid
);
233 BOOL
old_ntfs_allowed_dir_access(struct SECURITY_CONTEXT
*scx
,
234 const char *path
, int accesstype
);
237 le32
ntfs_alloc_securid(struct SECURITY_CONTEXT
*scx
,
238 uid_t uid
, gid_t gid
, ntfs_inode
*dir_ni
,
239 mode_t mode
, BOOL isdir
);
241 le32
ntfs_alloc_securid(struct SECURITY_CONTEXT
*scx
,
242 uid_t uid
, gid_t gid
, mode_t mode
, BOOL isdir
);
244 int ntfs_set_owner(struct SECURITY_CONTEXT
*scx
, ntfs_inode
*ni
,
245 uid_t uid
, gid_t gid
);
246 int ntfs_set_ownmod(struct SECURITY_CONTEXT
*scx
,
247 ntfs_inode
*ni
, uid_t uid
, gid_t gid
, mode_t mode
);
249 int ntfs_set_owner_mode(struct SECURITY_CONTEXT
*scx
,
250 ntfs_inode
*ni
, uid_t uid
, gid_t gid
,
251 mode_t mode
, struct POSIX_SECURITY
*pxdesc
);
253 int ntfs_set_owner_mode(struct SECURITY_CONTEXT
*scx
,
254 ntfs_inode
*ni
, uid_t uid
, gid_t gid
, mode_t mode
);
256 le32
ntfs_inherited_id(struct SECURITY_CONTEXT
*scx
,
257 ntfs_inode
*dir_ni
, BOOL fordir
);
258 int ntfs_open_secure(ntfs_volume
*vol
);
259 int ntfs_close_secure(ntfs_volume
*vol
);
261 void ntfs_destroy_security_context(struct SECURITY_CONTEXT
*scx
);
265 int ntfs_set_inherited_posix(struct SECURITY_CONTEXT
*scx
,
266 ntfs_inode
*ni
, uid_t uid
, gid_t gid
,
267 ntfs_inode
*dir_ni
, mode_t mode
);
268 int ntfs_get_posix_acl(struct SECURITY_CONTEXT
*scx
, ntfs_inode
*ni
,
269 const char *name
, char *value
, size_t size
);
270 int ntfs_set_posix_acl(struct SECURITY_CONTEXT
*scx
, ntfs_inode
*ni
,
271 const char *name
, const char *value
, size_t size
,
273 int ntfs_remove_posix_acl(struct SECURITY_CONTEXT
*scx
, ntfs_inode
*ni
,
277 int ntfs_get_ntfs_acl(struct SECURITY_CONTEXT
*scx
, ntfs_inode
*ni
,
278 char *value
, size_t size
);
279 int ntfs_set_ntfs_acl(struct SECURITY_CONTEXT
*scx
, ntfs_inode
*ni
,
280 const char *value
, size_t size
, int flags
);
282 int ntfs_get_ntfs_attrib(ntfs_inode
*ni
, char *value
, size_t size
);
283 int ntfs_set_ntfs_attrib(ntfs_inode
*ni
,
284 const char *value
, size_t size
, int flags
);
288 * Security API for direct access to security descriptors
292 #define MAGIC_API 0x09042009
294 struct SECURITY_API
{
296 struct SECURITY_CONTEXT security
;
297 struct PERMISSIONS_CACHE
*seccache
;
301 * The following constants are used in interfacing external programs.
302 * They are not to be stored on disk and must be defined in their
303 * native cpu representation.
304 * When disk representation (le) is needed, use SE_DACL_PRESENT, etc.
306 enum { OWNER_SECURITY_INFORMATION
= 1,
307 GROUP_SECURITY_INFORMATION
= 2,
308 DACL_SECURITY_INFORMATION
= 4,
309 SACL_SECURITY_INFORMATION
= 8
312 int ntfs_get_file_security(struct SECURITY_API
*scapi
,
313 const char *path
, u32 selection
,
314 char *buf
, u32 buflen
, u32
*psize
);
315 int ntfs_set_file_security(struct SECURITY_API
*scapi
,
316 const char *path
, u32 selection
, const char *attr
);
317 int ntfs_get_file_attributes(struct SECURITY_API
*scapi
,
319 BOOL
ntfs_set_file_attributes(struct SECURITY_API
*scapi
,
320 const char *path
, s32 attrib
);
321 BOOL
ntfs_read_directory(struct SECURITY_API
*scapi
,
322 const char *path
, ntfs_filldir_t callback
, void *context
);
323 int ntfs_read_sds(struct SECURITY_API
*scapi
,
324 char *buf
, u32 size
, u32 offset
);
325 INDEX_ENTRY
*ntfs_read_sii(struct SECURITY_API
*scapi
,
327 INDEX_ENTRY
*ntfs_read_sdh(struct SECURITY_API
*scapi
,
329 struct SECURITY_API
*ntfs_initialize_file_security(const char *device
,
330 unsigned long flags
);
331 BOOL
ntfs_leave_file_security(struct SECURITY_API
*scx
);
333 int ntfs_get_usid(struct SECURITY_API
*scapi
, uid_t uid
, char *buf
);
334 int ntfs_get_gsid(struct SECURITY_API
*scapi
, gid_t gid
, char *buf
);
335 int ntfs_get_user(struct SECURITY_API
*scapi
, const SID
*usid
);
336 int ntfs_get_group(struct SECURITY_API
*scapi
, const SID
*gsid
);
338 #endif /* defined _NTFS_SECURITY_H */