};
struct adouble {
- vfs_handle_struct *ad_handle;
int ad_fd;
bool ad_opened;
adouble_type_t ad_type;
{0, 0, 0}
};
-/*
- * Fake AppleDouble entry oder for resource fork xattr. The xattr
- * isn't an AppleDouble file, it simply contains the resource data,
- * but in order to be able to use some API calls like ad_getentryoff()
- * we build a fake/helper struct adouble with this entry order struct.
- */
-static const
-struct ad_entry_order entry_order_rsrc_xattr[ADEID_NUM_RSRC_XATTR + 1] = {
- {ADEID_RFORK, 0, 0},
- {0, 0, 0}
-};
-
/* Conversion from enumerated id to on-disk AppleDouble id */
#define AD_EID_DISK(a) (set_eid[a])
static const uint32_t set_eid[] = {
/*
* Forward declarations
*/
-static struct adouble *ad_init(TALLOC_CTX *ctx, vfs_handle_struct *handle,
+static struct adouble *ad_init(TALLOC_CTX *ctx,
adouble_type_t type);
static struct adouble *ad_get(TALLOC_CTX *ctx,
vfs_handle_struct *handle,
return true;
}
-static bool ad_convert_xattr(struct adouble *ad,
+static bool ad_convert_xattr(vfs_handle_struct *handle,
+ struct adouble *ad,
const struct smb_filename *smb_fname,
bool *converted_xattr)
{
files_struct *fsp = NULL;
ssize_t nwritten;
- status = string_replace_allocate(ad->ad_handle->conn,
+ status = string_replace_allocate(handle->conn,
e->adx_name,
string_replace_cmaps,
talloc_tos(),
DBG_DEBUG("stream_name: %s\n", smb_fname_str_dbg(stream_name));
status = SMB_VFS_CREATE_FILE(
- ad->ad_handle->conn, /* conn */
+ handle->conn, /* conn */
NULL, /* req */
0, /* root_dir_fid */
stream_name, /* fname */
return ok;
}
-static bool ad_convert_finderinfo(struct adouble *ad,
+static bool ad_convert_finderinfo(vfs_handle_struct *handle,
+ struct adouble *ad,
const struct smb_filename *smb_fname)
{
char *p_ad = NULL;
DBG_DEBUG("stream_name: %s\n", smb_fname_str_dbg(stream_name));
status = SMB_VFS_CREATE_FILE(
- ad->ad_handle->conn, /* conn */
+ handle->conn, /* conn */
NULL, /* req */
0, /* root_dir_fid */
stream_name, /* fname */
return true;
}
-static bool ad_convert_blank_rfork(struct adouble *ad,
+static bool ad_convert_blank_rfork(vfs_handle_struct *handle,
+ struct adouble *ad,
bool *blank)
{
struct fruit_config_data *config = NULL;
*blank = false;
- SMB_VFS_HANDLE_GET_DATA(ad->ad_handle, config,
+ SMB_VFS_HANDLE_GET_DATA(handle, config,
struct fruit_config_data, return false);
if (!config->wipe_intentionally_left_blank_rfork) {
return true;
}
-static bool ad_convert_delete_adfile(struct adouble *ad,
+static bool ad_convert_delete_adfile(vfs_handle_struct *handle,
+ struct adouble *ad,
const struct smb_filename *smb_fname)
{
struct fruit_config_data *config = NULL;
return true;
}
- SMB_VFS_HANDLE_GET_DATA(ad->ad_handle, config,
+ SMB_VFS_HANDLE_GET_DATA(handle, config,
struct fruit_config_data, return false);
if (!config->delete_empty_adfiles) {
return false;
}
- rc = SMB_VFS_NEXT_UNLINK(ad->ad_handle, ad_name);
+ rc = SMB_VFS_NEXT_UNLINK(handle, ad_name);
if (rc != 0) {
DBG_ERR("Unlinking [%s] failed: %s\n",
smb_fname_str_dbg(ad_name), strerror(errno));
return 0;
}
- ok = ad_convert_xattr(ad, smb_fname, &converted_xattr);
+ ok = ad_convert_xattr(handle, ad, smb_fname, &converted_xattr);
if (!ok) {
ret = -1;
goto done;
}
- ok = ad_convert_blank_rfork(ad, &blank);
+ ok = ad_convert_blank_rfork(handle, ad, &blank);
if (!ok) {
ret = -1;
goto done;
}
}
- ok = ad_convert_finderinfo(ad, smb_fname);
+ ok = ad_convert_finderinfo(handle, ad, smb_fname);
if (!ok) {
DBG_ERR("Failed to convert [%s]\n",
smb_fname_str_dbg(smb_fname));
goto done;
}
- ok = ad_convert_delete_adfile(ad, smb_fname);
+ ok = ad_convert_delete_adfile(handle, ad, smb_fname);
if (!ok) {
ret = -1;
goto done;
return ealen;
}
-static int ad_open_rsrc_xattr(const struct smb_filename *smb_fname,
- int flags,
- mode_t mode)
-{
-#ifdef HAVE_ATTROPEN
- /* FIXME: direct Solaris xattr syscall */
- return attropen(smb_fname->base_name,
- AFPRESOURCE_EA_NETATALK, flags, mode);
-#else
- errno = ENOSYS;
- return -1;
-#endif
-}
-
static int ad_open_rsrc_adouble(const struct smb_filename *smb_fname,
int flags,
mode_t mode)
int flags,
mode_t mode)
{
- struct fruit_config_data *config = NULL;
- int fd;
-
- SMB_VFS_HANDLE_GET_DATA(handle, config,
- struct fruit_config_data, return -1);
-
- if (config->rsrc == FRUIT_RSRC_XATTR) {
- fd = ad_open_rsrc_xattr(smb_fname, flags, mode);
- } else {
- fd = ad_open_rsrc_adouble(smb_fname, flags, mode);
- }
-
- return fd;
+ return ad_open_rsrc_adouble(smb_fname, flags, mode);
}
/*
return 0;
}
-static ssize_t ad_read_rsrc_xattr(struct adouble *ad)
-{
- int ret;
- SMB_STRUCT_STAT st;
-
- /* FIXME: direct sys_fstat(), don't have an fsp */
- ret = sys_fstat(ad->ad_fd, &st,
- lp_fake_directory_create_times(
- SNUM(ad->ad_handle->conn)));
- if (ret != 0) {
- return -1;
- }
-
- ad_setentrylen(ad, ADEID_RFORK, st.st_ex_size);
- return st.st_ex_size;
-}
-
-static ssize_t ad_read_rsrc_adouble(struct adouble *ad,
- const struct smb_filename *smb_fname)
+static ssize_t ad_read_rsrc_adouble(vfs_handle_struct *handle,
+ struct adouble *ad,
+ const struct smb_filename *smb_fname)
{
SMB_STRUCT_STAT sbuf;
char *p_ad = NULL;
bool ok;
ret = sys_fstat(ad->ad_fd, &sbuf, lp_fake_directory_create_times(
- SNUM(ad->ad_handle->conn)));
+ SNUM(handle->conn)));
if (ret != 0) {
return -1;
}
/**
* Read and parse resource fork, either ._ AppleDouble file or xattr
**/
-static ssize_t ad_read_rsrc(struct adouble *ad,
- const struct smb_filename *smb_fname)
+static ssize_t ad_read_rsrc(vfs_handle_struct *handle,
+ struct adouble *ad,
+ const struct smb_filename *smb_fname)
{
- struct fruit_config_data *config = NULL;
- ssize_t len;
-
- SMB_VFS_HANDLE_GET_DATA(ad->ad_handle, config,
- struct fruit_config_data, return -1);
-
- if (config->rsrc == FRUIT_RSRC_XATTR) {
- len = ad_read_rsrc_xattr(ad);
- } else {
- len = ad_read_rsrc_adouble(ad, smb_fname);
- }
-
- return len;
+ return ad_read_rsrc_adouble(handle, ad, smb_fname);
}
/**
case ADOUBLE_META:
return ad_read_meta(handle, ad, smb_fname);
case ADOUBLE_RSRC:
- return ad_read_rsrc(ad, smb_fname);
+ return ad_read_rsrc(handle, ad, smb_fname);
default:
return -1;
}
*
* @return adouble handle
**/
-static struct adouble *ad_alloc(TALLOC_CTX *ctx, vfs_handle_struct *handle,
+static struct adouble *ad_alloc(TALLOC_CTX *ctx,
adouble_type_t type)
{
int rc = 0;
size_t adsize = 0;
struct adouble *ad;
- struct fruit_config_data *config;
-
- SMB_VFS_HANDLE_GET_DATA(handle, config,
- struct fruit_config_data, return NULL);
switch (type) {
case ADOUBLE_META:
adsize = AD_DATASZ_XATTR;
break;
case ADOUBLE_RSRC:
- if (config->rsrc == FRUIT_RSRC_ADFILE) {
- adsize = AD_DATASZ_DOT_UND;
- }
+ adsize = AD_DATASZ_DOT_UND;
break;
default:
return NULL;
}
}
- ad->ad_handle = handle;
ad->ad_type = type;
ad->ad_magic = AD_MAGIC;
ad->ad_version = AD_VERSION;
* Allocate and initialize a new struct adouble
*
* @param[in] ctx talloc context
- * @param[in] handle vfs handle
* @param[in] type type of AppleDouble, ADOUBLE_META or ADOUBLE_RSRC
*
* @return adouble handle, initialized
**/
-static struct adouble *ad_init(TALLOC_CTX *ctx, vfs_handle_struct *handle,
+static struct adouble *ad_init(TALLOC_CTX *ctx,
adouble_type_t type)
{
int rc = 0;
const struct ad_entry_order *eid;
struct adouble *ad = NULL;
- struct fruit_config_data *config;
time_t t = time(NULL);
- SMB_VFS_HANDLE_GET_DATA(handle, config,
- struct fruit_config_data, return NULL);
-
switch (type) {
case ADOUBLE_META:
eid = entry_order_meta_xattr;
break;
case ADOUBLE_RSRC:
- if (config->rsrc == FRUIT_RSRC_ADFILE) {
- eid = entry_order_dot_und;
- } else {
- eid = entry_order_rsrc_xattr;
- }
+ eid = entry_order_dot_und;
break;
default:
return NULL;
}
- ad = ad_alloc(ctx, handle, type);
+ ad = ad_alloc(ctx, type);
if (ad == NULL) {
return NULL;
}
type == ADOUBLE_META ? "meta" : "rsrc",
smb_fname->base_name));
- ad = ad_alloc(ctx, handle, type);
+ ad = ad_alloc(ctx, type);
if (ad == NULL) {
rc = -1;
goto exit;
return false;
}
+static bool is_adouble_file(const char *path)
+{
+ const char *p = NULL;
+ int match;
+
+ p = strrchr(path, '/');
+ if (p == NULL) {
+ p = path;
+ } else {
+ p++;
+ }
+
+ match = strncmp(p,
+ ADOUBLE_NAME_PREFIX,
+ strlen(ADOUBLE_NAME_PREFIX));
+ if (match != 0) {
+ return false;
+ }
+ return true;
+}
+
/**
* Initialize config struct from our smb.conf config parameters
**/
switch (config->rsrc) {
case FRUIT_RSRC_ADFILE:
- case FRUIT_RSRC_XATTR:
rfork_size = readdir_attr_rfork_size_adouble(handle,
smb_fname);
break;
- case FRUIT_META_STREAM:
+ case FRUIT_RSRC_XATTR:
+ case FRUIT_RSRC_STREAM:
rfork_size = readdir_attr_rfork_size_stream(handle,
smb_fname);
break;
}
if (flags & (O_CREAT | O_TRUNC)) {
- ad = ad_init(fsp, handle, ADOUBLE_RSRC);
+ ad = ad_init(fsp, ADOUBLE_RSRC);
if (ad == NULL) {
rc = -1;
goto exit;
return fruit_unlink_meta(handle, smb_fname);
} else if (is_afpresource_stream(smb_fname)) {
return fruit_unlink_rsrc(handle, smb_fname, false);
- } if (is_ntfs_stream_smb_fname(smb_fname)) {
+ } else if (is_ntfs_stream_smb_fname(smb_fname)) {
+ return SMB_VFS_NEXT_UNLINK(handle, smb_fname);
+ } else if (is_adouble_file(smb_fname->base_name)) {
return SMB_VFS_NEXT_UNLINK(handle, smb_fname);
}
}
while ((de = SMB_VFS_READDIR(handle->conn, dh, NULL)) != NULL) {
- int match;
struct adouble *ad = NULL;
char *p = NULL;
struct smb_filename *ad_smb_fname = NULL;
int ret;
- match = strncmp(de->d_name,
- ADOUBLE_NAME_PREFIX,
- strlen(ADOUBLE_NAME_PREFIX));
- if (match != 0) {
+ if (!is_adouble_file(de->d_name)) {
continue;
}
ad = ad_fget(talloc_tos(), handle, fsp, ADOUBLE_META);
if (ad == NULL) {
- ad = ad_init(talloc_tos(), handle, ADOUBLE_META);
+ ad = ad_init(talloc_tos(), ADOUBLE_META);
if (ad == NULL) {
return -1;
}