summaryrefslogtreecommitdiff
Diffstat
-rwxr-xr-xAndroid.mk138
-rwxr-xr-xAndroid.mk.bak89
-rwxr-xr-xCREDITS20
-rwxr-xr-xINSTALL200
-rwxr-xr-xMakefile715
-rwxr-xr-xMakefile.am106
-rwxr-xr-xMakefile.in955
-rwxr-xr-xNEWS4
-rwxr-xr-xREADME80
-rwxr-xr-xTODO.ntfsprogs126
-rwxr-xr-xaclocal.m47091
-rwxr-xr-xcompile21
-rwxr-xr-xconfig.guess292
-rw-r--r--[-rwxr-xr-x]config.h165
-rwxr-xr-xconfig.h.in110
-rwxr-xr-xconfig.log3290
-rwxr-xr-xconfig.status1220
-rwxr-xr-xconfig.sub104
-rwxr-xr-xconfigure26448
-rwxr-xr-xconfigure.ac291
-rwxr-xr-xdepcomp87
-rwxr-xr-xinclude/Makefile.in181
-rwxr-xr-xinclude/fuse-lite/Makefile.in112
-rwxr-xr-xinclude/fuse-lite/fuse.h61
-rwxr-xr-xinclude/fuse-lite/fuse_common.h49
-rwxr-xr-xinclude/fuse-lite/fuse_kernel.h6
-rwxr-xr-xinclude/fuse-lite/fuse_lowlevel.h20
-rwxr-xr-xinclude/ntfs-3g/Makefile.am4
-rwxr-xr-xinclude/ntfs-3g/Makefile.in163
-rwxr-xr-xinclude/ntfs-3g/acls.h3
-rwxr-xr-xinclude/ntfs-3g/attrib.h50
-rwxr-xr-xinclude/ntfs-3g/cache.h7
-rwxr-xr-xinclude/ntfs-3g/compat.h6
-rwxr-xr-xinclude/ntfs-3g/compress.h6
-rwxr-xr-xinclude/ntfs-3g/debug.h4
-rwxr-xr-xinclude/ntfs-3g/device.h18
-rwxr-xr-xinclude/ntfs-3g/device_io.h21
-rwxr-xr-xinclude/ntfs-3g/dir.h11
-rwxr-xr-xinclude/ntfs-3g/layout.h32
-rwxr-xr-xinclude/ntfs-3g/lcnalloc.h1
-rwxr-xr-xinclude/ntfs-3g/logging.h3
-rwxr-xr-xinclude/ntfs-3g/mst.h3
-rwxr-xr-xinclude/ntfs-3g/ntfstime.h12
-rwxr-xr-xinclude/ntfs-3g/param.h72
-rwxr-xr-xinclude/ntfs-3g/realpath.h24
-rwxr-xr-xinclude/ntfs-3g/runlist.h3
-rwxr-xr-xinclude/ntfs-3g/security.h20
-rwxr-xr-xinclude/ntfs-3g/types.h8
-rwxr-xr-xinclude/ntfs-3g/unistr.h13
-rwxr-xr-xinclude/ntfs-3g/volume.h78
-rwxr-xr-xinclude/ntfs-3g/xattrs.h75
-rwxr-xr-xinstall-sh5
-rwxr-xr-xlibfuse-lite/Makefile.am3
-rwxr-xr-xlibfuse-lite/Makefile.in188
-rwxr-xr-xlibfuse-lite/fuse.c418
-rwxr-xr-xlibfuse-lite/fuse_kern_chan.c2
-rwxr-xr-xlibfuse-lite/fuse_lowlevel.c53
-rwxr-xr-xlibfuse-lite/fuse_opt.c20
-rwxr-xr-xlibfuse-lite/fuse_session.c12
-rwxr-xr-xlibfuse-lite/fusermount.c97
-rwxr-xr-xlibfuse-lite/helper.c21
-rwxr-xr-xlibfuse-lite/mount.c486
-rwxr-xr-xlibfuse-lite/mount_util.c246
-rwxr-xr-xlibfuse-lite/mount_util.h11
-rwxr-xr-xlibntfs-3g/Makefile.am15
-rwxr-xr-xlibntfs-3g/Makefile.in420
-rwxr-xr-xlibntfs-3g/acls.c219
-rwxr-xr-xlibntfs-3g/attrib.c1205
-rwxr-xr-xlibntfs-3g/bootsect.c4
-rwxr-xr-xlibntfs-3g/cache.c7
-rwxr-xr-xlibntfs-3g/compress.c962
-rwxr-xr-xlibntfs-3g/device.c252
-rwxr-xr-xlibntfs-3g/dir.c374
-rwxr-xr-xlibntfs-3g/efs.c217
-rwxr-xr-xlibntfs-3g/index.c30
-rwxr-xr-xlibntfs-3g/inode.c46
-rwxr-xr-xlibntfs-3g/lcnalloc.c36
-rw-r--r--libntfs-3g/libntfs-3g.pc10
-rw-r--r--libntfs-3g/libntfs-3g.script.so2
-rwxr-xr-xlibntfs-3g/logfile.c23
-rwxr-xr-xlibntfs-3g/logging.c24
-rwxr-xr-xlibntfs-3g/mft.c12
-rwxr-xr-xlibntfs-3g/mst.c24
-rwxr-xr-xlibntfs-3g/object_id.c9
-rwxr-xr-xlibntfs-3g/realpath.c103
-rwxr-xr-xlibntfs-3g/reparse.c67
-rwxr-xr-xlibntfs-3g/runlist.c62
-rwxr-xr-xlibntfs-3g/security.c345
-rwxr-xr-xlibntfs-3g/unistr.c244
-rwxr-xr-xlibntfs-3g/unix_io.c19
-rwxr-xr-xlibntfs-3g/volume.c365
-rwxr-xr-xlibntfs-3g/win32_io.c708
-rwxr-xr-xlibntfs-3g/xattrs.c791
-rwxr-xr-xlibtool9301
-rwxr-xr-xltmain.sh8439
-rwxr-xr-xm4/libtool.m47377
-rwxr-xr-xm4/ltoptions.m4368
-rwxr-xr-xm4/ltsugar.m4123
-rwxr-xr-xm4/ltversion.m423
-rwxr-xr-xm4/lt~obsolete.m492
-rwxr-xr-xmissing49
-rwxr-xr-xntfsprogs/Makefile.am154
-rwxr-xr-xntfsprogs/Makefile.in1199
-rwxr-xr-xntfsprogs/attrdef.c168
-rwxr-xr-xntfsprogs/attrdef.h7
-rwxr-xr-xntfsprogs/boot.c268
-rwxr-xr-xntfsprogs/boot.h7
-rwxr-xr-xntfsprogs/cluster.c118
-rwxr-xr-xntfsprogs/cluster.h39
-rwxr-xr-xntfsprogs/list.h194
-rw-r--r--ntfsprogs/mkntfs.8290
-rwxr-xr-xntfsprogs/mkntfs.8.in290
-rwxr-xr-xntfsprogs/mkntfs.c5177
-rw-r--r--ntfsprogs/ntfscat.8136
-rwxr-xr-xntfsprogs/ntfscat.8.in136
-rwxr-xr-xntfsprogs/ntfscat.c440
-rwxr-xr-xntfsprogs/ntfscat.h46
-rwxr-xr-xntfsprogs/ntfsck.c883
-rw-r--r--ntfsprogs/ntfsclone.8391
-rwxr-xr-xntfsprogs/ntfsclone.8.in391
-rwxr-xr-xntfsprogs/ntfsclone.c2701
-rw-r--r--ntfsprogs/ntfscluster.8124
-rwxr-xr-xntfsprogs/ntfscluster.8.in124
-rwxr-xr-xntfsprogs/ntfscluster.c563
-rwxr-xr-xntfsprogs/ntfscluster.h63
-rw-r--r--ntfsprogs/ntfscmp.877
-rwxr-xr-xntfsprogs/ntfscmp.8.in77
-rwxr-xr-xntfsprogs/ntfscmp.c1012
-rw-r--r--ntfsprogs/ntfscp.8111
-rwxr-xr-xntfsprogs/ntfscp.8.in111
-rwxr-xr-xntfsprogs/ntfscp.c590
-rwxr-xr-xntfsprogs/ntfsdecrypt.c1436
-rwxr-xr-xntfsprogs/ntfsdump_logfile.c779
-rw-r--r--ntfsprogs/ntfsfix.881
-rwxr-xr-xntfsprogs/ntfsfix.8.in81
-rwxr-xr-xntfsprogs/ntfsfix.c1657
-rw-r--r--ntfsprogs/ntfsinfo.889
-rwxr-xr-xntfsprogs/ntfsinfo.8.in89
-rwxr-xr-xntfsprogs/ntfsinfo.c2384
-rw-r--r--ntfsprogs/ntfslabel.8118
-rwxr-xr-xntfsprogs/ntfslabel.8.in118
-rwxr-xr-xntfsprogs/ntfslabel.c458
-rw-r--r--ntfsprogs/ntfsls.8172
-rwxr-xr-xntfsprogs/ntfsls.8.in172
-rwxr-xr-xntfsprogs/ntfsls.c717
-rwxr-xr-xntfsprogs/ntfsmftalloc.c368
-rwxr-xr-xntfsprogs/ntfsmove.c923
-rwxr-xr-xntfsprogs/ntfsmove.h46
-rw-r--r--ntfsprogs/ntfsprogs.869
-rwxr-xr-xntfsprogs/ntfsprogs.8.in69
-rw-r--r--ntfsprogs/ntfsresize.8326
-rwxr-xr-xntfsprogs/ntfsresize.8.in326
-rwxr-xr-xntfsprogs/ntfsresize.c4497
-rwxr-xr-xntfsprogs/ntfstruncate.c809
-rw-r--r--ntfsprogs/ntfsundelete.8324
-rwxr-xr-xntfsprogs/ntfsundelete.8.in324
-rwxr-xr-xntfsprogs/ntfsundelete.c2490
-rwxr-xr-xntfsprogs/ntfsundelete.h112
-rwxr-xr-xntfsprogs/ntfswipe.c2131
-rwxr-xr-xntfsprogs/ntfswipe.h54
-rwxr-xr-xntfsprogs/sd.c607
-rwxr-xr-xntfsprogs/sd.h11
-rwxr-xr-xntfsprogs/utils.c1184
-rwxr-xr-xntfsprogs/utils.h137
-rwxr-xr-xprog.IAB1071
-rwxr-xr-xprog.IAD5
-rwxr-xr-xprog.IMB466
-rwxr-xr-xprog.IMD2
-rwxr-xr-xprog.PFI2
-rwxr-xr-xprog.PO1
-rwxr-xr-xprog.PR14
-rwxr-xr-xprog.PRI219
-rwxr-xr-xprog.PS979
-rwxr-xr-xprog.SearchResults3
-rwxr-xr-xprog.WK39
-rwxr-xr-xsrc/Makefile.am86
-rwxr-xr-xsrc/Makefile.in938
-rwxr-xr-xsrc/lowntfs-3g.c1538
-rw-r--r--src/ntfs-3g.8448
-rwxr-xr-xsrc/ntfs-3g.8.in217
-rwxr-xr-xsrc/ntfs-3g.c1357
-rw-r--r--src/ntfs-3g.probe.881
-rwxr-xr-xsrc/ntfs-3g.probe.8.in4
-rwxr-xr-xsrc/ntfs-3g.probe.c9
-rw-r--r--src/ntfs-3g.secaudit.8184
-rwxr-xr-xsrc/ntfs-3g.secaudit.8.in15
-rw-r--r--src/ntfs-3g.usermap.896
-rwxr-xr-xsrc/ntfs-3g_common.c745
-rwxr-xr-xsrc/ntfs-3g_common.h185
-rwxr-xr-xsrc/secaudit.c673
-rwxr-xr-xsrc/secaudit.h32
-rwxr-xr-xsrc/usermap.c3
-rw-r--r--[-rwxr-xr-x]stamp-h10
193 files changed, 80411 insertions, 44563 deletions
diff --git a/libntfs-3g/security.c b/libntfs-3g/security.c
index 2d5905a..c731509 100755
--- a/libntfs-3g/security.c
+++ b/libntfs-3g/security.c
@@ -4,7 +4,7 @@
* Copyright (c) 2004 Anton Altaparmakov
* Copyright (c) 2005-2006 Szabolcs Szakacsits
* Copyright (c) 2006 Yura Pakhuchiy
- * Copyright (c) 2007-2009 Jean-Pierre Andre
+ * Copyright (c) 2007-2012 Jean-Pierre Andre
*
* This program/include file is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
@@ -52,6 +52,7 @@
#include <pwd.h>
#include <grp.h>
+#include "compat.h"
#include "param.h"
#include "types.h"
#include "layout.h"
@@ -366,6 +367,8 @@ void ntfs_generate_guid(GUID *guid)
unsigned int i;
u8 *p = (u8 *)guid;
+ /* this is called at most once from mkntfs */
+ srandom(time((time_t*)NULL) ^ (getpid() << 16));
for (i = 0; i < sizeof(GUID); i++) {
p[i] = (u8)(random() & 0xFF);
if (i == 7)
@@ -405,91 +408,6 @@ le32 ntfs_security_hash(const SECURITY_DESCRIPTOR_RELATIVE *sd, const u32 len)
}
/*
- * Internal read
- * copied and pasted from ntfs_fuse_read() and made independent
- * of fuse context
- */
-
-static int ntfs_local_read(ntfs_inode *ni,
- ntfschar *stream_name, int stream_name_len,
- char *buf, size_t size, off_t offset)
-{
- ntfs_attr *na = NULL;
- int res, total = 0;
-
- na = ntfs_attr_open(ni, AT_DATA, stream_name, stream_name_len);
- if (!na) {
- res = -errno;
- goto exit;
- }
- if ((size_t)offset < (size_t)na->data_size) {
- if (offset + size > (size_t)na->data_size)
- size = na->data_size - offset;
- while (size) {
- res = ntfs_attr_pread(na, offset, size, buf);
- if ((off_t)res < (off_t)size)
- ntfs_log_perror("ntfs_attr_pread partial read "
- "(%lld : %lld <> %d)",
- (long long)offset,
- (long long)size, res);
- if (res <= 0) {
- res = -errno;
- goto exit;
- }
- size -= res;
- offset += res;
- total += res;
- }
- }
- res = total;
-exit:
- if (na)
- ntfs_attr_close(na);
- return res;
-}
-
-
-/*
- * Internal write
- * copied and pasted from ntfs_fuse_write() and made independent
- * of fuse context
- */
-
-static int ntfs_local_write(ntfs_inode *ni,
- ntfschar *stream_name, int stream_name_len,
- char *buf, size_t size, off_t offset)
-{
- ntfs_attr *na = NULL;
- int res, total = 0;
-
- na = ntfs_attr_open(ni, AT_DATA, stream_name, stream_name_len);
- if (!na) {
- res = -errno;
- goto exit;
- }
- while (size) {
- res = ntfs_attr_pwrite(na, offset, size, buf);
- if (res < (s64)size)
- ntfs_log_perror("ntfs_attr_pwrite partial write (%lld: "
- "%lld <> %d)", (long long)offset,
- (long long)size, res);
- if (res <= 0) {
- res = -errno;
- goto exit;
- }
- size -= res;
- offset += res;
- total += res;
- }
- res = total;
-exit:
- if (na)
- ntfs_attr_close(na);
- return res;
-}
-
-
-/*
* Get the first entry of current index block
* cut and pasted form ntfs_ie_get_first() in index.c
*/
@@ -531,7 +449,7 @@ static int entersecurity_stuff(ntfs_volume *vol, off_t offs)
if (stuff) {
memset(stuff, 0, STUFFSZ);
do {
- written = ntfs_local_write(vol->secure_ni,
+ written = ntfs_attr_data_write(vol->secure_ni,
STREAM_SDS, 4, stuff, STUFFSZ, offs);
if (written == STUFFSZ) {
total += STUFFSZ;
@@ -589,10 +507,10 @@ static int entersecurity_data(ntfs_volume *vol,
phsds->security_id = keyid;
phsds->offset = cpu_to_le64(offs);
phsds->length = cpu_to_le32(fullsz - gap);
- written1 = ntfs_local_write(vol->secure_ni,
+ written1 = ntfs_attr_data_write(vol->secure_ni,
STREAM_SDS, 4, fullattr, fullsz,
offs - gap);
- written2 = ntfs_local_write(vol->secure_ni,
+ written2 = ntfs_attr_data_write(vol->secure_ni,
STREAM_SDS, 4, fullattr, fullsz,
offs - gap + ALIGN_SDS_BLOCK);
if ((written1 == fullsz)
@@ -950,7 +868,7 @@ static le32 setsecurityattr(ntfs_volume *vol,
+ sizeof(SECURITY_DESCRIPTOR_HEADER);
oldattr = (char*)ntfs_malloc(size);
if (oldattr) {
- rdsize = ntfs_local_read(
+ rdsize = ntfs_attr_data_read(
vol->secure_ni,
STREAM_SDS, 4,
oldattr, size, offs);
@@ -1101,7 +1019,6 @@ static int update_secur_descr(ntfs_volume *vol,
/* mark node as dirty */
NInoSetDirty(ni);
- ntfs_inode_sync(ni); /* useful ? */
return (res);
}
@@ -1150,7 +1067,6 @@ static int upgrade_secur_desc(ntfs_volume *vol,
na = ntfs_attr_open(ni, AT_STANDARD_INFORMATION,
AT_UNNAMED, 0);
if (na) {
- res = 0;
/* expand standard information attribute to v3.x */
res = ntfs_attr_truncate(na,
(s64)sizeof(STANDARD_INFORMATION));
@@ -1170,9 +1086,8 @@ static int upgrade_secur_desc(ntfs_volume *vol,
}
} else
res = -1;
- /* mark node as dirty */
- NInoSetDirty(ni);
- ntfs_inode_sync(ni); /* useful ? */
+ /* mark node as dirty */
+ NInoSetDirty(ni);
} else
res = 1;
@@ -1216,10 +1131,86 @@ static BOOL staticgroupmember(struct SECURITY_CONTEXT *scx, uid_t uid, gid_t gid
return (ingroup);
}
+#if defined(__sun) && defined (__SVR4)
/*
* Check whether current thread owner is member of file group
+ * Solaris/OpenIndiana version
+ * Should not be called for user root, however the group may be root
*
+ * The group list is available in "/proc/$PID/cred"
+ *
+ */
+
+static BOOL groupmember(struct SECURITY_CONTEXT *scx, uid_t uid, gid_t gid)
+{
+ typedef struct prcred {
+ uid_t pr_euid; /* effective user id */
+ uid_t pr_ruid; /* real user id */
+ uid_t pr_suid; /* saved user id (from exec) */
+ gid_t pr_egid; /* effective group id */
+ gid_t pr_rgid; /* real group id */
+ gid_t pr_sgid; /* saved group id (from exec) */
+ int pr_ngroups; /* number of supplementary groups */
+ gid_t pr_groups[1]; /* array of supplementary groups */
+ } prcred_t;
+ enum { readset = 16 };
+
+ prcred_t basecreds;
+ gid_t groups[readset];
+ char filename[64];
+ int fd;
+ int k;
+ int cnt;
+ gid_t *p;
+ BOOL ismember;
+ int got;
+ pid_t tid;
+
+ if (scx->vol->secure_flags & (1 << SECURITY_STATICGRPS))
+ ismember = staticgroupmember(scx, uid, gid);
+ else {
+ ismember = FALSE; /* default return */
+ tid = scx->tid;
+ sprintf(filename,"/proc/%u/cred",tid);
+ fd = open(filename,O_RDONLY);
+ if (fd >= 0) {
+ got = read(fd, &basecreds, sizeof(prcred_t));
+ if (got == sizeof(prcred_t)) {
+ if (basecreds.pr_egid == gid)
+ ismember = TRUE;
+ p = basecreds.pr_groups;
+ cnt = 1;
+ k = 0;
+ while (!ismember
+ && (k < basecreds.pr_ngroups)
+ && (cnt > 0)
+ && (*p != gid)) {
+ k++;
+ cnt--;
+ p++;
+ if (cnt <= 0) {
+ got = read(fd, groups,
+ readset*sizeof(gid_t));
+ cnt = got/sizeof(gid_t);
+ p = groups;
+ }
+ }
+ if ((cnt > 0)
+ && (k < basecreds.pr_ngroups))
+ ismember = TRUE;
+ }
+ close(fd);
+ }
+ }
+ return (ismember);
+}
+
+#else /* defined(__sun) && defined (__SVR4) */
+
+/*
+ * Check whether current thread owner is member of file group
+ * Linux version
* Should not be called for user root, however the group may be root
*
* As indicated by Miklos Szeredi :
@@ -1322,6 +1313,8 @@ static BOOL groupmember(struct SECURITY_CONTEXT *scx, uid_t uid, gid_t gid)
return (ismember);
}
+#endif /* defined(__sun) && defined (__SVR4) */
+
/*
* Cacheing is done two-way :
* - from uid, gid and perm to securid (CACHED_SECURID)
@@ -1774,7 +1767,7 @@ static char *retrievesecurityattr(ntfs_volume *vol, SII_INDEX_KEY id)
securattr = (char*)ntfs_malloc(size);
if (securattr) {
- rdsize = ntfs_local_read(
+ rdsize = ntfs_attr_data_read(
ni, STREAM_SDS, 4,
securattr, size, offs);
if ((rdsize != size)
@@ -1885,7 +1878,7 @@ static int access_check_posix(struct SECURITY_CONTEXT *scx,
if (!scx->uid) {
/* root access if owner or other execution */
if (perms & 0101)
- perms = 07777;
+ perms |= 01777;
else {
/* root access if some group execution */
groupperms = 0;
@@ -1987,7 +1980,7 @@ static int access_check_posix(struct SECURITY_CONTEXT *scx,
*
* returns -1 if there is a problem
*/
-#if 0
+#if 0
static int ntfs_get_perm(struct SECURITY_CONTEXT *scx,
ntfs_inode * ni, mode_t request)
{
@@ -2081,6 +2074,7 @@ static int ntfs_get_perm(struct SECURITY_CONTEXT *scx,
return (perm);
}
#endif
+
/*
* Get a Posix ACL
*
@@ -2100,7 +2094,6 @@ int ntfs_get_posix_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
const SID *gsid; /* group of file/directory */
uid_t uid;
gid_t gid;
- int perm;
BOOL isdir;
size_t outsize;
@@ -2135,7 +2128,6 @@ int ntfs_get_posix_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
* fetch owner and group for cacheing
*/
if (pxdesc) {
- perm = pxdesc->mode & 07777;
/*
* Create a security id if there were none
* and upgrade option is selected
@@ -2149,11 +2141,10 @@ int ntfs_get_posix_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
#if OWNERFROMACL
uid = ntfs_find_user(scx->mapping[MAPUSERS],usid);
#else
- if (!perm && ntfs_same_sid(usid, adminsid)) {
+ if (!(pxdesc->mode & 07777)
+ && ntfs_same_sid(usid, adminsid)) {
uid = find_tenant(scx,
securattr);
- if (uid)
- perm = 0700;
} else
uid = ntfs_find_user(scx->mapping[MAPUSERS],usid);
#endif
@@ -2223,7 +2214,7 @@ int ntfs_get_posix_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
*
* returns -1 if there is a problem
*/
-#if 0
+#if 0
static int ntfs_get_perm(struct SECURITY_CONTEXT *scx,
ntfs_inode *ni, mode_t request)
{
@@ -2304,7 +2295,7 @@ static int ntfs_get_perm(struct SECURITY_CONTEXT *scx,
if (!scx->uid) {
/* root access and execution */
if (perm & 0111)
- perm = 07777;
+ perm |= 01777;
else
perm = 0;
} else
@@ -2328,6 +2319,7 @@ static int ntfs_get_perm(struct SECURITY_CONTEXT *scx,
return (perm);
}
#endif
+
#endif /* POSIXACLS */
/*
@@ -2980,7 +2972,6 @@ int ntfs_set_posix_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
uid_t uid;
uid_t gid;
int res;
- mode_t mode;
BOOL isdir;
BOOL deflt;
BOOL exist;
@@ -2997,14 +2988,15 @@ int ntfs_set_posix_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
count = 0;
isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) != const_cpu_to_le16(0);
newpxdesc = (struct POSIX_SECURITY*)NULL;
- if (!deflt || isdir || !size) {
+ if ((!value
+ || (((const struct POSIX_ACL*)value)->version == POSIX_VERSION))
+ && (!deflt || isdir || (!size && !value))) {
cached = fetch_cache(scx, ni);
if (cached) {
uid = cached->uid;
gid = cached->gid;
oldpxdesc = cached->pxdesc;
if (oldpxdesc) {
- mode = oldpxdesc->mode;
newpxdesc = ntfs_replace_acl(oldpxdesc,
(const struct POSIX_ACL*)value,count,deflt);
}
@@ -3031,7 +3023,6 @@ int ntfs_set_posix_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
|| (!exist && (flags & XATTR_REPLACE))) {
errno = (exist ? EEXIST : ENODATA);
} else {
- mode = oldpxdesc->mode;
newpxdesc = ntfs_replace_acl(oldpxdesc,
(const struct POSIX_ACL*)value,count,deflt);
}
@@ -3338,9 +3329,7 @@ int ntfs_allowed_access(struct SECURITY_CONTEXT *scx,
ntfs_inode *ni,
int accesstype) /* access type required (S_Ixxx values) */
{
- return 1;
-
-#if 0
+#if 0
int perm;
int res;
int allow;
@@ -3409,7 +3398,61 @@ int ntfs_allowed_access(struct SECURITY_CONTEXT *scx,
allow = 0;
}
return (allow);
-#endif
+#endif
+ return (1);
+}
+
+/*
+ * Check whether user can create a file (or directory)
+ *
+ * Returns TRUE if access is allowed,
+ * Also returns the gid and dsetgid applicable to the created file
+ */
+
+int ntfs_allowed_create(struct SECURITY_CONTEXT *scx,
+ ntfs_inode *dir_ni, gid_t *pgid, mode_t *pdsetgid)
+{
+#if 0
+ int perm;
+ int res;
+ int allow;
+ struct stat stbuf;
+
+ /*
+ * Always allow for root.
+ * Also always allow if no mapping has been defined
+ */
+ if (!scx->mapping[MAPUSERS])
+ perm = 0777;
+ else
+ perm = ntfs_get_perm(scx, dir_ni, S_IWRITE + S_IEXEC);
+ if (!scx->mapping[MAPUSERS]
+ || !scx->uid) {
+ allow = 1;
+ } else {
+ perm = ntfs_get_perm(scx, dir_ni, S_IWRITE + S_IEXEC);
+ if (perm >= 0) {
+ res = EACCES;
+ allow = ((perm & (S_IWUSR | S_IWGRP | S_IWOTH)) != 0)
+ && ((perm & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0);
+ if (!allow)
+ errno = res;
+ } else
+ allow = 0;
+ }
+ *pgid = scx->gid;
+ *pdsetgid = 0;
+ /* return directory group if S_ISGID is set */
+ if (allow && (perm & S_ISGID)) {
+ if (ntfs_get_owner_mode(scx, dir_ni, &stbuf) >= 0) {
+ *pdsetgid = stbuf.st_mode & S_ISGID;
+ if (perm & S_ISGID)
+ *pgid = stbuf.st_gid;
+ }
+ }
+ return (allow);
+#endif
+ return (1);
}
#if 0 /* not needed any more */
@@ -3563,10 +3606,12 @@ int ntfs_set_owner(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
uid = fileuid;
if ((int)gid < 0)
gid = filegid;
+#if !defined(__sun) || !defined (__SVR4)
/* clear setuid and setgid if owner has changed */
/* unless request originated by root */
if (uid && (fileuid != uid))
mode &= 01777;
+#endif
#if POSIXACLS
res = ntfs_set_owner_mode(scx, ni, uid, gid,
mode, pxdesc);
@@ -3602,16 +3647,16 @@ int ntfs_set_owner(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
int ntfs_set_ownmod(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
uid_t uid, gid_t gid, const mode_t mode)
{
- const SECURITY_DESCRIPTOR_RELATIVE *phead;
const struct CACHED_PERMISSIONS *cached;
char *oldattr;
- const SID *usid;
- const SID *gsid;
uid_t fileuid;
uid_t filegid;
- BOOL isdir;
int res;
#if POSIXACLS
+ const SECURITY_DESCRIPTOR_RELATIVE *phead;
+ const SID *usid;
+ const SID *gsid;
+ BOOL isdir;
const struct POSIX_SECURITY *oldpxdesc;
struct POSIX_SECURITY *newpxdesc = (struct POSIX_SECURITY*)NULL;
int pxsize;
@@ -3644,6 +3689,7 @@ int ntfs_set_ownmod(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
filegid = 0;
oldattr = getsecurityattr(scx->vol, ni);
if (oldattr) {
+#if POSIXACLS
isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)
!= const_cpu_to_le16(0);
phead = (const SECURITY_DESCRIPTOR_RELATIVE*)
@@ -3656,7 +3702,6 @@ int ntfs_set_ownmod(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
usid = (const SID*)
&oldattr[le32_to_cpu(phead->owner)];
#endif
-#if POSIXACLS
newpxdesc = ntfs_build_permissions_posix(scx->mapping, oldattr,
usid, gsid, isdir);
if (!newpxdesc || ntfs_merge_mode_posix(newpxdesc, mode))
@@ -3775,7 +3820,9 @@ static le32 build_inherited_id(struct SECURITY_CONTEXT *scx,
pnhead = (SECURITY_DESCRIPTOR_RELATIVE*)newattr;
pnhead->revision = SECURITY_DESCRIPTOR_REVISION;
pnhead->alignment = 0;
- pnhead->control = SE_SELF_RELATIVE;
+ pnhead->control = (pphead->control
+ & (SE_DACL_AUTO_INHERITED | SE_SACL_AUTO_INHERITED))
+ | SE_SELF_RELATIVE;
pos = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
/*
* locate and inherit DACL
@@ -3786,7 +3833,9 @@ static le32 build_inherited_id(struct SECURITY_CONTEXT *scx,
offpacl = le32_to_cpu(pphead->dacl);
ppacl = (const ACL*)&parentattr[offpacl];
pnacl = (ACL*)&newattr[pos];
- aclsz = ntfs_inherit_acl(ppacl, pnacl, usid, gsid, fordir);
+ aclsz = ntfs_inherit_acl(ppacl, pnacl, usid, gsid,
+ fordir, pphead->control
+ & SE_DACL_AUTO_INHERITED);
if (aclsz) {
pnhead->dacl = cpu_to_le32(pos);
pos += aclsz;
@@ -3801,7 +3850,9 @@ static le32 build_inherited_id(struct SECURITY_CONTEXT *scx,
offpacl = le32_to_cpu(pphead->sacl);
ppacl = (const ACL*)&parentattr[offpacl];
pnacl = (ACL*)&newattr[pos];
- aclsz = ntfs_inherit_acl(ppacl, pnacl, usid, gsid, fordir);
+ aclsz = ntfs_inherit_acl(ppacl, pnacl, usid, gsid,
+ fordir, pphead->control
+ & SE_SACL_AUTO_INHERITED);
if (aclsz) {
pnhead->sacl = cpu_to_le32(pos);
pos += aclsz;
@@ -3819,7 +3870,7 @@ static le32 build_inherited_id(struct SECURITY_CONTEXT *scx,
*/
memcpy(&newattr[pos],gsid,gsidsz);
pnhead->group = cpu_to_le32(pos);
- pos += usidsz;
+ pos += gsidsz;
securid = setsecurityattr(scx->vol,
(SECURITY_DESCRIPTOR_RELATIVE*)newattr, pos);
free(newattr);
@@ -3974,14 +4025,13 @@ static int link_group_members(struct SECURITY_CONTEXT *scx)
return (res);
}
-
/*
* Apply default single user mapping
* returns zero if successful
*/
static int ntfs_do_default_mapping(struct SECURITY_CONTEXT *scx,
- const SID *usid)
+ uid_t uid, gid_t gid, const SID *usid)
{
struct MAPPING *usermapping;
struct MAPPING *groupmapping;
@@ -3999,10 +4049,10 @@ static int ntfs_do_default_mapping(struct SECURITY_CONTEXT *scx,
groupmapping = (struct MAPPING*)ntfs_malloc(sizeof(struct MAPPING));
if (groupmapping) {
usermapping->sid = sid;
- usermapping->xid = scx->uid;
+ usermapping->xid = uid;
usermapping->next = (struct MAPPING*)NULL;
groupmapping->sid = sid;
- groupmapping->xid = scx->uid;
+ groupmapping->xid = gid;
groupmapping->next = (struct MAPPING*)NULL;
scx->mapping[MAPUSERS] = usermapping;
scx->mapping[MAPGROUPS] = groupmapping;
@@ -4011,7 +4061,6 @@ static int ntfs_do_default_mapping(struct SECURITY_CONTEXT *scx,
}
}
return (res);
-
}
/*
@@ -4053,6 +4102,8 @@ static BOOL check_mapping(const struct MAPPING *usermapping,
#endif
+#if 0 /* not used any more */
+
/*
* Try and apply default single user mapping
* returns zero if successful
@@ -4074,7 +4125,8 @@ static int ntfs_default_mapping(struct SECURITY_CONTEXT *scx)
phead = (const SECURITY_DESCRIPTOR_RELATIVE*)securattr;
usid = (SID*)&securattr[le32_to_cpu(phead->owner)];
if (ntfs_is_user_sid(usid))
- res = ntfs_do_default_mapping(scx,usid);
+ res = ntfs_do_default_mapping(scx,
+ scx->uid, scx->gid, usid);
free(securattr);
}
ntfs_inode_close(ni);
@@ -4082,6 +4134,8 @@ static int ntfs_default_mapping(struct SECURITY_CONTEXT *scx)
return (res);
}
+#endif
+
/*
* Basic read from a user mapping file on another volume
*/
@@ -4098,7 +4152,7 @@ static int basicread(void *fileid, char *buf, size_t size, off_t offs __attribut
static int localread(void *fileid, char *buf, size_t size, off_t offs)
{
- return (ntfs_local_read((ntfs_inode*)fileid,
+ return (ntfs_attr_data_read((ntfs_inode*)fileid,
AT_UNNAMED, 0, buf, size, offs));
}
@@ -4114,7 +4168,8 @@ static int localread(void *fileid, char *buf, size_t size, off_t offs)
* (failure should not be interpreted as an error)
*/
-int ntfs_build_mapping(struct SECURITY_CONTEXT *scx, const char *usermap_path)
+int ntfs_build_mapping(struct SECURITY_CONTEXT *scx, const char *usermap_path,
+ BOOL allowdef)
{
struct MAPLIST *item;
struct MAPLIST *firstitem;
@@ -4122,6 +4177,22 @@ int ntfs_build_mapping(struct SECURITY_CONTEXT *scx, const char *usermap_path)
struct MAPPING *groupmapping;
ntfs_inode *ni;
int fd;
+ static struct {
+ u8 revision;
+ u8 levels;
+ be16 highbase;
+ be32 lowbase;
+ le32 level1;
+ le32 level2;
+ le32 level3;
+ le32 level4;
+ le32 level5;
+ } defmap = {
+ 1, 5, const_cpu_to_be16(0), const_cpu_to_be32(5),
+ const_cpu_to_le32(21),
+ const_cpu_to_le32(DEFSECAUTH1), const_cpu_to_le32(DEFSECAUTH2),
+ const_cpu_to_le32(DEFSECAUTH3), const_cpu_to_le32(DEFSECBASE)
+ } ;
/* be sure not to map anything until done */
scx->mapping[MAPUSERS] = (struct MAPPING*)NULL;
@@ -4161,9 +4232,10 @@ int ntfs_build_mapping(struct SECURITY_CONTEXT *scx, const char *usermap_path)
firstitem = item;
}
} else {
- /* no mapping file, try default mapping */
- if (scx->uid && scx->gid) {
- if (!ntfs_default_mapping(scx))
+ /* no mapping file, try a default mapping */
+ if (allowdef) {
+ if (!ntfs_do_default_mapping(scx,
+ 0, 0, (const SID*)&defmap))
ntfs_log_info("Using default user mapping\n");
}
}
@@ -4852,6 +4924,7 @@ BOOL ntfs_set_file_attributes(struct SECURITY_API *scapi,
ni->flags = (ni->flags & ~settable)
| (cpu_to_le32(attrib) & settable);
NInoSetDirty(ni);
+ NInoFileNameSetDirty(ni);
}
if (!ntfs_inode_close(ni))
res = -1;
@@ -4902,7 +4975,7 @@ int ntfs_read_sds(struct SECURITY_API *scapi,
got = -1; /* default return */
if (scapi && (scapi->magic == MAGIC_API)) {
if (scapi->security.vol->secure_ni)
- got = ntfs_local_read(scapi->security.vol->secure_ni,
+ got = ntfs_attr_data_read(scapi->security.vol->secure_ni,
STREAM_SDS, 4, buf, size, offset);
else
errno = EOPNOTSUPP;
@@ -5098,7 +5171,7 @@ int ntfs_get_group(struct SECURITY_API *scapi, const SID *gsid)
*/
struct SECURITY_API *ntfs_initialize_file_security(const char *device,
- int flags)
+ unsigned long flags)
{
ntfs_volume *vol;
unsigned long mntflag;
@@ -5124,7 +5197,7 @@ struct SECURITY_API *ntfs_initialize_file_security(const char *device,
scx->pseccache = &scapi->seccache;
scx->vol->secure_flags = 0;
/* accept no mapping and no $Secure */
- ntfs_build_mapping(scx,(const char*)NULL);
+ ntfs_build_mapping(scx,(const char*)NULL,TRUE);
ntfs_open_secure(vol);
} else {
if (scapi)