Relocated code for setting/retrieving NTFS attribs
parent
0feae8177a
commit
9b996d31b9
|
@ -345,11 +345,5 @@ extern int ntfs_attr_remove(ntfs_inode *ni, const ATTR_TYPES type,
|
|||
ntfschar *name, u32 name_len);
|
||||
extern s64 ntfs_attr_get_free_bits(ntfs_attr *na);
|
||||
|
||||
int ntfs_get_ntfs_attrib(const char *path,
|
||||
char *value, size_t size, ntfs_inode *ni);
|
||||
int ntfs_set_ntfs_attrib(const char *path,
|
||||
const char *value, size_t size, int flags,
|
||||
ntfs_inode *ni);
|
||||
|
||||
#endif /* defined _NTFS_ATTRIB_H */
|
||||
|
||||
|
|
|
@ -292,6 +292,11 @@ int ntfs_get_ntfs_acl(struct SECURITY_CONTEXT *scx, const char *path,
|
|||
int ntfs_set_ntfs_acl(struct SECURITY_CONTEXT *scx, const char *path,
|
||||
const char *name, const char *value, size_t size,
|
||||
int flags, ntfs_inode *ni);
|
||||
int ntfs_get_ntfs_attrib(const char *path,
|
||||
char *value, size_t size, ntfs_inode *ni);
|
||||
int ntfs_set_ntfs_attrib(const char *path,
|
||||
const char *value, size_t size, int flags,
|
||||
ntfs_inode *ni);
|
||||
|
||||
/*
|
||||
* Security API for direct access to security descriptors
|
||||
|
|
|
@ -39,9 +39,6 @@
|
|||
#ifdef HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#endif
|
||||
#ifdef HAVE_SETXATTR
|
||||
#include <sys/xattr.h>
|
||||
#endif
|
||||
|
||||
#include "compat.h"
|
||||
#include "attrib.h"
|
||||
|
@ -5139,62 +5136,3 @@ s64 ntfs_attr_get_free_bits(ntfs_attr *na)
|
|||
return -1;
|
||||
return nr_free;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the ntfs attribute into an extended attribute
|
||||
* The attribute is returned according to cpu endianness
|
||||
*/
|
||||
|
||||
int ntfs_get_ntfs_attrib(const char *path __attribute__((unused)),
|
||||
char *value, size_t size, ntfs_inode *ni)
|
||||
{
|
||||
u32 attrib;
|
||||
size_t outsize;
|
||||
|
||||
outsize = 0; /* default to no data and no error */
|
||||
if (ni) {
|
||||
attrib = le32_to_cpu(ni->flags);
|
||||
if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)
|
||||
attrib |= const_le32_to_cpu(FILE_ATTR_DIRECTORY);
|
||||
else
|
||||
attrib &= ~const_le32_to_cpu(FILE_ATTR_DIRECTORY);
|
||||
outsize = sizeof(FILE_ATTR_FLAGS);
|
||||
if (size >= outsize) {
|
||||
if (value)
|
||||
memcpy(value,&attrib,outsize);
|
||||
else
|
||||
errno = EINVAL;
|
||||
}
|
||||
}
|
||||
return (outsize ? (int)outsize : -errno);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the ntfs attribute into an extended attribute
|
||||
* The attribute is expected according to cpu endianness
|
||||
*
|
||||
* Returns 0, or -1 if there is a problem
|
||||
*/
|
||||
|
||||
int ntfs_set_ntfs_attrib(const char *path __attribute__((unused)),
|
||||
const char *value, size_t size, int flags,
|
||||
ntfs_inode *ni)
|
||||
{
|
||||
u32 attrib;
|
||||
int res;
|
||||
|
||||
res = -1;
|
||||
if (ni && value && (size >= sizeof(FILE_ATTR_FLAGS))) {
|
||||
if (!(flags & XATTR_CREATE)) {
|
||||
/* copy to avoid alignment problems */
|
||||
memcpy(&attrib,value,sizeof(FILE_ATTR_FLAGS));
|
||||
ni->flags = (ni->flags & ~const_cpu_to_le32(0x31a7))
|
||||
| cpu_to_le32(attrib & 0x31a7);
|
||||
NInoSetDirty(ni);
|
||||
res = 0;
|
||||
} else
|
||||
errno = EEXIST;
|
||||
} else
|
||||
errno = EINVAL;
|
||||
return (res ? -1 : 0);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* Copyright (c) 2004 Anton Altaparmakov
|
||||
* Copyright (c) 2005-2006 Szabolcs Szakacsits
|
||||
* Copyright (c) 2006 Yura Pakhuchiy
|
||||
* Copyright (c) 2007-2008 Jean-Pierre Andre
|
||||
* Copyright (c) 2007-2009 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
|
||||
|
@ -69,6 +69,15 @@
|
|||
#define STUFFSZ 0x4000 /* unitary stuffing size for $SDS */
|
||||
#define FIRST_SECURITY_ID 0x100 /* Lowest security id */
|
||||
|
||||
/* Mask for attributes which can be forced */
|
||||
#define FILE_ATTR_SETTABLE ( FILE_ATTR_READONLY \
|
||||
| FILE_ATTR_HIDDEN \
|
||||
| FILE_ATTR_SYSTEM \
|
||||
| FILE_ATTR_ARCHIVE \
|
||||
| FILE_ATTR_TEMPORARY \
|
||||
| FILE_ATTR_OFFLINE \
|
||||
| FILE_ATTR_NOT_CONTENT_INDEXED )
|
||||
|
||||
struct SII { /* this is an image of an $SII index entry */
|
||||
le16 offs;
|
||||
le16 size;
|
||||
|
@ -3824,6 +3833,67 @@ int ntfs_build_mapping(struct SECURITY_CONTEXT *scx, const char *usermap_path)
|
|||
return (!scx->mapping[MAPUSERS] || link_group_members(scx));
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the ntfs attribute into an extended attribute
|
||||
* The attribute is returned according to cpu endianness
|
||||
*/
|
||||
|
||||
int ntfs_get_ntfs_attrib(const char *path __attribute__((unused)),
|
||||
char *value, size_t size, ntfs_inode *ni)
|
||||
{
|
||||
u32 attrib;
|
||||
size_t outsize;
|
||||
|
||||
outsize = 0; /* default to no data and no error */
|
||||
if (ni) {
|
||||
attrib = le32_to_cpu(ni->flags);
|
||||
if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)
|
||||
attrib |= const_le32_to_cpu(FILE_ATTR_DIRECTORY);
|
||||
else
|
||||
attrib &= ~const_le32_to_cpu(FILE_ATTR_DIRECTORY);
|
||||
if (!attrib)
|
||||
attrib |= const_le32_to_cpu(FILE_ATTR_NORMAL);
|
||||
outsize = sizeof(FILE_ATTR_FLAGS);
|
||||
if (size >= outsize) {
|
||||
if (value)
|
||||
memcpy(value,&attrib,outsize);
|
||||
else
|
||||
errno = EINVAL;
|
||||
}
|
||||
}
|
||||
return (outsize ? (int)outsize : -errno);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the ntfs attribute into an extended attribute
|
||||
* The attribute is expected according to cpu endianness
|
||||
*
|
||||
* Returns 0, or -1 if there is a problem
|
||||
*/
|
||||
|
||||
int ntfs_set_ntfs_attrib(const char *path __attribute__((unused)),
|
||||
const char *value, size_t size, int flags,
|
||||
ntfs_inode *ni)
|
||||
{
|
||||
u32 attrib;
|
||||
int res;
|
||||
|
||||
res = -1;
|
||||
if (ni && value && (size >= sizeof(FILE_ATTR_FLAGS))) {
|
||||
if (!(flags & XATTR_CREATE)) {
|
||||
/* copy to avoid alignment problems */
|
||||
memcpy(&attrib,value,sizeof(FILE_ATTR_FLAGS));
|
||||
ni->flags = (ni->flags & ~FILE_ATTR_SETTABLE)
|
||||
| (cpu_to_le32(attrib) & FILE_ATTR_SETTABLE);
|
||||
NInoSetDirty(ni);
|
||||
res = 0;
|
||||
} else
|
||||
errno = EEXIST;
|
||||
} else
|
||||
errno = EINVAL;
|
||||
return (res ? -1 : 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Open $Secure once for all
|
||||
* returns zero if it succeeds
|
||||
|
@ -4349,9 +4419,12 @@ int ntfs_get_file_attributes(struct SECURITY_API *scapi, const char *path)
|
|||
if (ni) {
|
||||
attrib = le32_to_cpu(ni->flags);
|
||||
if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)
|
||||
attrib |= 0x10;
|
||||
attrib |= const_le32_to_cpu(FILE_ATTR_DIRECTORY);
|
||||
else
|
||||
attrib &= ~0x10;
|
||||
attrib &= ~const_le32_to_cpu(FILE_ATTR_DIRECTORY);
|
||||
if (!attrib)
|
||||
attrib |= const_le32_to_cpu(FILE_ATTR_NORMAL);
|
||||
|
||||
ntfs_inode_close(ni);
|
||||
} else
|
||||
errno = ENOENT;
|
||||
|
@ -4389,8 +4462,8 @@ BOOL ntfs_set_file_attributes(struct SECURITY_API *scapi,
|
|||
if (scapi && (scapi->magic == MAGIC_API) && path) {
|
||||
ni = ntfs_pathname_to_inode(scapi->security.vol, NULL, path);
|
||||
if (ni) {
|
||||
ni->flags = (ni->flags & ~const_cpu_to_le32(0x31a7))
|
||||
| cpu_to_le32(attrib & 0x31a7);
|
||||
ni->flags = (ni->flags & ~FILE_ATTR_SETTABLE)
|
||||
| (cpu_to_le32(attrib) & FILE_ATTR_SETTABLE);
|
||||
NInoSetDirty(ni);
|
||||
if (!ntfs_inode_close(ni))
|
||||
res = -1;
|
||||
|
|
Loading…
Reference in New Issue