#include "smbd/smbd.h"
#include "system/filesys.h"
#include "lib/util/time.h"
-#include "../lib/crypto/md5.h"
#include "system/shmem.h"
#include "locking/proto.h"
#include "smbd/globals.h"
#include "offload_token.h"
#include "string_replace.h"
+#include <gnutls/gnutls.h>
+#include <gnutls/crypto.h>
+
/*
* Enhanced OS X and Netatalk compatibility
* ========================================
};
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 int ad_set(struct adouble *ad, const struct smb_filename *smb_fname);
-static int ad_fset(struct adouble *ad, files_struct *fsp);
+static struct adouble *ad_get(TALLOC_CTX *ctx,
+ vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname,
+ adouble_type_t type);
+static int ad_set(vfs_handle_struct *handle,
+ struct adouble *ad,
+ const struct smb_filename *smb_fname);
+static int ad_fset(struct vfs_handle_struct *handle,
+ struct adouble *ad,
+ files_struct *fsp);
static int adouble_path(TALLOC_CTX *ctx,
const struct smb_filename *smb_fname__in,
struct smb_filename **ppsmb_fname_out);
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 -1 in case an error occurred, 0 if no conversion was done, 1
* otherwise
**/
-static int ad_convert(struct adouble *ad,
+static int ad_convert(struct vfs_handle_struct *handle,
const struct smb_filename *smb_fname)
{
+ struct adouble *ad = NULL;
bool ok;
bool converted_xattr = false;
bool blank;
+ int ret;
- ok = ad_convert_xattr(ad, smb_fname, &converted_xattr);
+ ad = ad_get(talloc_tos(), handle, smb_fname, ADOUBLE_RSRC);
+ if (ad == NULL) {
+ return 0;
+ }
+
+ ok = ad_convert_xattr(handle, ad, smb_fname, &converted_xattr);
if (!ok) {
- return -1;
+ ret = -1;
+ goto done;
}
- ok = ad_convert_blank_rfork(ad, &blank);
+ ok = ad_convert_blank_rfork(handle, ad, &blank);
if (!ok) {
- return -1;
+ ret = -1;
+ goto done;
}
if (converted_xattr || blank) {
ok = ad_convert_truncate(ad, smb_fname);
if (!ok) {
- return -1;
+ 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));
- return -1;
+ ret = -1;
+ goto done;
}
- ok = ad_convert_delete_adfile(ad, smb_fname);
+ ok = ad_convert_delete_adfile(handle, ad, smb_fname);
if (!ok) {
- return -1;
+ ret = -1;
+ goto done;
}
- return 0;
+ ret = 0;
+done:
+ TALLOC_FREE(ad);
+ return ret;
}
/**
* Read and parse Netatalk AppleDouble metadata xattr
**/
-static ssize_t ad_read_meta(struct adouble *ad,
- const struct smb_filename *smb_fname)
+static ssize_t ad_read_meta(vfs_handle_struct *handle,
+ struct adouble *ad,
+ const struct smb_filename *smb_fname)
{
int rc = 0;
ssize_t ealen;
DEBUG(10, ("reading meta xattr for %s\n", smb_fname->base_name));
- ealen = SMB_VFS_GETXATTR(ad->ad_handle->conn, smb_fname,
+ ealen = SMB_VFS_GETXATTR(handle->conn, smb_fname,
AFPINFO_EA_NETATALK, ad->ad_data,
AD_DATASZ_XATTR);
if (ealen == -1) {
ealen = -1;
if (errno == EINVAL) {
become_root();
- removexattr(smb_fname->base_name, AFPINFO_EA_NETATALK);
+ (void)SMB_VFS_REMOVEXATTR(handle->conn,
+ smb_fname,
+ AFPINFO_EA_NETATALK);
unbecome_root();
errno = ENOENT;
}
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;
}
return -1;
}
- /*
- * Try to fixup AppleDouble files created by OS X with xattrs
- * appended to the ADEID_FINDERI entry.
- */
-
- ret = ad_convert(ad, smb_fname);
- if (ret != 0) {
- DBG_WARNING("Failed to convert [%s]\n", smb_fname->base_name);
- return len;
- }
-
return len;
}
/**
* 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);
}
/**
* Read and unpack an AppleDouble metadata xattr or resource
**/
-static ssize_t ad_read(struct adouble *ad, const struct smb_filename *smb_fname)
+static ssize_t ad_read(vfs_handle_struct *handle,
+ struct adouble *ad,
+ const struct smb_filename *smb_fname)
{
switch (ad->ad_type) {
case ADOUBLE_META:
- return ad_read_meta(ad, smb_fname);
+ 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;
}
- len = ad_read(ad, smb_fname);
+ len = ad_read(handle, ad, smb_fname);
if (len == -1) {
DEBUG(10, ("error reading AppleDouble for %s\n",
smb_fname->base_name));
*
* @return status code, 0 means success
**/
-static int ad_set(struct adouble *ad, const struct smb_filename *smb_fname)
+static int ad_set(vfs_handle_struct *handle,
+ struct adouble *ad,
+ const struct smb_filename *smb_fname)
{
bool ok;
int ret;
return -1;
}
- ret = SMB_VFS_SETXATTR(ad->ad_handle->conn,
+ ret = SMB_VFS_SETXATTR(handle->conn,
smb_fname,
AFPINFO_EA_NETATALK,
ad->ad_data,
*
* @return status code, 0 means success
**/
-static int ad_fset(struct adouble *ad, files_struct *fsp)
+static int ad_fset(struct vfs_handle_struct *handle,
+ struct adouble *ad,
+ files_struct *fsp)
{
int rc = -1;
ssize_t len;
switch (ad->ad_type) {
case ADOUBLE_META:
- rc = SMB_VFS_NEXT_SETXATTR(ad->ad_handle,
+ rc = SMB_VFS_NEXT_SETXATTR(handle,
fsp->fsp_name,
AFPINFO_EA_NETATALK,
ad->ad_data,
break;
case ADOUBLE_RSRC:
- len = SMB_VFS_NEXT_PWRITE(ad->ad_handle,
+ len = SMB_VFS_NEXT_PWRITE(handle,
fsp,
ad->ad_data,
AD_DATASZ_DOT_UND,
}
/**
- * Test whether stream is an Apple stream, not used atm
+ * Test whether stream is an Apple stream.
**/
-#if 0
static bool is_apple_stream(const struct smb_filename *smb_fname)
{
if (is_afpinfo_stream(smb_fname)) {
}
return false;
}
-#endif
+
+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
**/
static SMB_INO_T fruit_inode(const SMB_STRUCT_STAT *sbuf, const char *sname)
{
- MD5_CTX ctx;
+ gnutls_hash_hd_t hash_hnd = NULL;
unsigned char hash[16];
- SMB_INO_T result;
+ SMB_INO_T result = 0;
char *upper_sname;
+ int rc;
DBG_DEBUG("fruit_inode called for %ju/%ju [%s]\n",
(uintmax_t)sbuf->st_ex_dev,
upper_sname = talloc_strdup_upper(talloc_tos(), sname);
SMB_ASSERT(upper_sname != NULL);
- MD5Init(&ctx);
- MD5Update(&ctx, (const unsigned char *)&(sbuf->st_ex_dev),
- sizeof(sbuf->st_ex_dev));
- MD5Update(&ctx, (const unsigned char *)&(sbuf->st_ex_ino),
- sizeof(sbuf->st_ex_ino));
- MD5Update(&ctx, (unsigned char *)upper_sname,
- talloc_get_size(upper_sname)-1);
- MD5Final(hash, &ctx);
+ rc = gnutls_hash_init(&hash_hnd, GNUTLS_DIG_MD5);
+ if (rc < 0) {
+ goto out;
+ }
- TALLOC_FREE(upper_sname);
+ rc = gnutls_hash(hash_hnd, &(sbuf->st_ex_dev), sizeof(sbuf->st_ex_dev));
+ if (rc < 0) {
+ gnutls_hash_deinit(hash_hnd, NULL);
+ goto out;
+ }
+ rc = gnutls_hash(hash_hnd,
+ &(sbuf->st_ex_ino),
+ sizeof(sbuf->st_ex_ino));
+ if (rc < 0) {
+ gnutls_hash_deinit(hash_hnd, NULL);
+ goto out;
+ }
+ rc = gnutls_hash(hash_hnd,
+ upper_sname,
+ talloc_get_size(upper_sname) - 1);
+ if (rc < 0) {
+ gnutls_hash_deinit(hash_hnd, NULL);
+ goto out;
+ }
+
+ gnutls_hash_deinit(hash_hnd, hash);
/* Hopefully all the variation is in the lower 4 (or 8) bytes! */
memcpy(&result, hash, sizeof(result));
+ ZERO_ARRAY(hash);
DBG_DEBUG("fruit_inode \"%s\": ino=%ju\n",
sname, (uintmax_t)result);
+out:
+ TALLOC_FREE(upper_sname);
+
return result;
}
off_t offset = in_offset;
off_t len = 1;
int type = F_WRLCK;
- pid_t pid;
+ pid_t pid = 0;
result = SMB_VFS_GETLOCK(fsp, &offset, &len, &type, &pid);
if (result == false) {
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;
fsp->fh->fd = hostfd;
- rc = ad_fset(ad, fsp);
+ rc = ad_fset(handle, ad, fsp);
fsp->fh->fd = -1;
if (rc != 0) {
rc = -1;
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;
}
memcpy(p, &ai->afpi_FinderInfo[0], ADEDLEN_FINDERI);
- ret = ad_fset(ad, fsp);
+ ret = ad_fset(handle, ad, fsp);
if (ret != 0) {
DBG_ERR("ad_pwrite [%s] failed\n", fsp_str_dbg(fsp));
TALLOC_FREE(ad);
if ((n + offset) > ad_getentrylen(ad, ADEID_RFORK)) {
ad_setentrylen(ad, ADEID_RFORK, n + offset);
- ret = ad_fset(ad, fsp);
+ ret = ad_fset(handle, ad, fsp);
if (ret != 0) {
DBG_ERR("ad_pwrite [%s] failed\n", fsp_str_dbg(fsp));
TALLOC_FREE(ad);
ad_setdate(ad, AD_DATE_CREATE | AD_DATE_UNIX,
convert_time_t_to_uint32_t(ft->create_time.tv_sec));
- rc = ad_set(ad, smb_fname);
+ rc = ad_set(handle, ad, smb_fname);
exit:
ad_setentrylen(ad, ADEID_RFORK, offset);
- rc = ad_fset(ad, fsp);
+ rc = ad_fset(handle, ad, fsp);
if (rc != 0) {
DBG_ERR("ad_fset [%s] failed [%s]\n",
fsp_str_dbg(fsp), strerror(errno));
struct fruit_config_data *config = NULL;
files_struct *fsp = NULL;
struct fio *fio = NULL;
+ bool internal_open = (oplock_request & INTERNAL_OPEN_ONLY);
+ int ret;
status = check_aapl(handle, req, in_context_blobs, out_context_blobs);
if (!NT_STATUS_IS_OK(status)) {
SMB_VFS_HANDLE_GET_DATA(handle, config, struct fruit_config_data,
return NT_STATUS_UNSUCCESSFUL);
+ if (is_apple_stream(smb_fname) && !internal_open) {
+ ret = ad_convert(handle, smb_fname);
+ if (ret != 0) {
+ DBG_ERR("ad_convert() failed\n");
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+ }
+
status = SMB_VFS_NEXT_CREATE_FILE(
handle, req, root_dir_fid, smb_fname,
access_mask, share_access,
struct fruit_config_data *config = NULL;
struct readdir_attr_data *attr_data;
NTSTATUS status;
+ int ret;
SMB_VFS_HANDLE_GET_DATA(handle, config,
struct fruit_config_data,
DEBUG(10, ("fruit_readdir_attr %s\n", fname->base_name));
+ ret = ad_convert(handle, fname);
+ if (ret != 0) {
+ DBG_ERR("ad_convert() failed\n");
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
*pattr_data = talloc_zero(mem_ctx, struct readdir_attr_data);
if (*pattr_data == NULL) {
return NT_STATUS_UNSUCCESSFUL;