1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

s3/vfs_glusterfs: Dynamically determine NAME_MAX

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13872

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Guenther Deschner <gd@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
This commit is contained in:
Anoop C S 2019-04-25 16:41:53 +05:30 committed by Günther Deschner
parent b50ca16273
commit 8e3a042eb9

View File

@ -1454,20 +1454,36 @@ static int vfs_gluster_chflags(struct vfs_handle_struct *handle,
static int vfs_gluster_get_real_filename(struct vfs_handle_struct *handle,
const char *path, const char *name,
TALLOC_CTX *mem_ctx, char **found_name)
TALLOC_CTX *mem_ctx, char **_found_name)
{
int ret;
char key_buf[NAME_MAX + 64];
char val_buf[NAME_MAX + 1];
char *key_buf = NULL, *val_buf = NULL;
long name_max;
char *found_name = NULL;
if (strlen(name) >= NAME_MAX) {
name_max = pathconf(path, _PC_NAME_MAX);
if ((name_max + 1) < 1) {
errno = EINVAL;
return -1;
}
if (strlen(name) >= name_max) {
errno = ENAMETOOLONG;
return -1;
}
snprintf(key_buf, NAME_MAX + 64,
"glusterfs.get_real_filename:%s", name);
key_buf = talloc_asprintf(mem_ctx, "glusterfs.get_real_filename:%s",
name);
if (key_buf == NULL) {
errno = ENOMEM;
return -1;
}
val_buf = talloc_zero_array(mem_ctx, char, name_max + 1);
if (val_buf == NULL) {
errno = ENOMEM;
return -1;
}
ret = glfs_getxattr(handle->data, path, key_buf, val_buf, NAME_MAX + 1);
if (ret == -1) {
if (errno == ENOATTR) {
@ -1476,11 +1492,16 @@ static int vfs_gluster_get_real_filename(struct vfs_handle_struct *handle,
return -1;
}
*found_name = talloc_strdup(mem_ctx, val_buf);
if (found_name[0] == NULL) {
found_name = talloc_strdup(mem_ctx, val_buf);
if (found_name == NULL) {
errno = ENOMEM;
return -1;
}
*_found_name = found_name;
TALLOC_FREE(key_buf);
TALLOC_FREE(val_buf);
return 0;
}