Improved error messages in case of failing Linux-specific ACL or xattr functions

This commit is contained in:
Thomas Schmitt 2022-09-20 09:28:06 +02:00
parent c6cb7dfa3e
commit 9b7ccc9727
2 changed files with 70 additions and 8 deletions

View File

@ -7,7 +7,7 @@
To be included by aaip_0_2.c for Linux To be included by aaip_0_2.c for Linux
Copyright (c) 2009 - 2018 Thomas Schmitt Copyright (c) 2009 - 2022 Thomas Schmitt
This file is part of the libisofs project; you can redistribute it and/or This file is part of the libisofs project; you can redistribute it and/or
modify it under the terms of the GNU General Public License version 2 modify it under the terms of the GNU General Public License version 2
@ -77,6 +77,44 @@ int aaip_local_attr_support(int flag)
} }
/* -------------------------- Error reporting ----------------------------- */
/* Report an error with local ACL or xattr calls.
@param flag bit0-7: mode 0=NO_GET_LOCAL , 1=NO_SET_LOCAL
*/
static
void aaip_local_error(char *function_name, char *path, int err, int flag)
{
int mode, err_code;
mode= (flag & 255);
if(mode == 1)
err_code= ISO_AAIP_NO_SET_LOCAL_S;
else
err_code= ISO_AAIP_NO_GET_LOCAL_S;
if(err > 0) {
if(path[0])
iso_msg_submit(-1, err_code, 0,
"Function %s(\"%s\") failed with errno %d '%s'",
function_name, path, err, strerror(err));
else
iso_msg_submit(-1, err_code, 0, "Function %s() failed with %d '%s'",
function_name, err, strerror(err));
} else {
if(path[0])
iso_msg_submit(-1, err_code, 0,
"Function %s(\"%s\") failed without error code",
function_name, path);
else
iso_msg_submit(-1, err_code, 0,
"Function %s() failed without error code",
function_name);
}
}
/* ------------------------------ Getters --------------------------------- */ /* ------------------------------ Getters --------------------------------- */
/* Obtain the ACL of the given file in long text form. /* Obtain the ACL of the given file in long text form.
@ -181,8 +219,10 @@ static int get_single_attr(char *path, char *name, size_t *value_length,
value_ret= getxattr(path, name, NULL, 0); value_ret= getxattr(path, name, NULL, 0);
else else
value_ret= lgetxattr(path, name, NULL, 0); value_ret= lgetxattr(path, name, NULL, 0);
if(value_ret == -1) if(value_ret == -1) {
aaip_local_error((flag & 32) ? "getxattr" : "lgetxattr", path, errno, 0);
return(0); return(0);
}
*value_bytes= calloc(value_ret + 1, 1); *value_bytes= calloc(value_ret + 1, 1);
if(*value_bytes == NULL) if(*value_bytes == NULL)
return(-1); return(-1);
@ -191,6 +231,7 @@ static int get_single_attr(char *path, char *name, size_t *value_length,
else else
value_ret= lgetxattr(path, name, *value_bytes, value_ret); value_ret= lgetxattr(path, name, *value_bytes, value_ret);
if(value_ret == -1) { if(value_ret == -1) {
aaip_local_error((flag & 32) ? "getxattr" : "lgetxattr", path, errno, 0);
free(*value_bytes); free(*value_bytes);
*value_bytes= NULL; *value_bytes= NULL;
*value_length= 0; *value_length= 0;
@ -275,11 +316,14 @@ ex:;
else else
list_size= llistxattr(path, list, 0); list_size= llistxattr(path, list, 0);
if(list_size == -1) { if(list_size == -1) {
if(errno == ENOSYS) /* Function not implemented */ if(errno == ENOSYS) { /* Function not implemented */
list_size= 0; /* Handle as if xattr was disabled at compile time */ list_size= 0; /* Handle as if xattr was disabled at compile time */
else } else {
aaip_local_error((flag & 32) ? "listxattr" : "llistxattr", path, errno,
0);
{ret= -1; goto ex;} {ret= -1; goto ex;}
} }
}
if(list_size > 0) { if(list_size > 0) {
list= calloc(list_size, 1); list= calloc(list_size, 1);
if(list == NULL) if(list == NULL)
@ -288,9 +332,12 @@ ex:;
list_size= listxattr(path, list, list_size); list_size= listxattr(path, list, list_size);
else else
list_size= llistxattr(path, list, list_size); list_size= llistxattr(path, list, list_size);
if(list_size == -1) if(list_size == -1) {
aaip_local_error((flag & 32) ? "listxattr" : "llistxattr", path, errno,
0);
{ret= -1; goto ex;} {ret= -1; goto ex;}
} }
}
for(i= 0; i < list_size; i+= strlen(list + i) + 1) for(i= 0; i < list_size; i+= strlen(list + i) + 1)
num_names++; num_names++;
} }
@ -443,11 +490,14 @@ int aaip_set_acl_text(char *path, char *text, int flag)
acl= acl_from_text(text); acl= acl_from_text(text);
if(acl == NULL) { if(acl == NULL) {
aaip_local_error("acl_from_text", "", errno, 1);
ret= -1; goto ex; ret= -1; goto ex;
} }
ret= acl_set_file(path, (flag & 1) ? ACL_TYPE_DEFAULT : ACL_TYPE_ACCESS, acl); ret= acl_set_file(path, (flag & 1) ? ACL_TYPE_DEFAULT : ACL_TYPE_ACCESS, acl);
if(ret == -1) if(ret == -1) {
aaip_local_error("acl_set_file", path, errno, 1);
goto ex; goto ex;
}
ret= 1; ret= 1;
ex: ex:
if(acl != NULL) if(acl != NULL)
@ -533,8 +583,11 @@ int aaip_set_attr_list(char *path, size_t num_attrs, char **names,
list_size= listxattr(path, list, list_size); list_size= listxattr(path, list, list_size);
else else
list_size= llistxattr(path, list, list_size); list_size= llistxattr(path, list, list_size);
if(list_size == -1) if(list_size == -1) {
aaip_local_error((flag & 32) ? "listxattr" : "llistxattr", path, errno,
1);
{ret= -5; goto ex;} {ret= -5; goto ex;}
}
for(i= 0; i < (size_t) list_size; i+= strlen(list + i) + 1) { for(i= 0; i < (size_t) list_size; i+= strlen(list + i) + 1) {
if(!(flag & 8)) if(!(flag & 8))
if(strncmp(list + i, "user.", 5)) if(strncmp(list + i, "user.", 5))
@ -543,9 +596,12 @@ int aaip_set_attr_list(char *path, size_t num_attrs, char **names,
ret= removexattr(path, list + i); ret= removexattr(path, list + i);
else else
ret= lremovexattr(path, list + i); ret= lremovexattr(path, list + i);
if(ret == -1) if(ret == -1) {
aaip_local_error((flag & 32) ? "removexattr" : "lremovexattr", path,
errno, 1);
{ret= -5; goto ex;} {ret= -5; goto ex;}
} }
}
free(list); list= NULL; free(list); list= NULL;
} }
@ -587,6 +643,8 @@ int aaip_set_attr_list(char *path, size_t num_attrs, char **names,
else else
ret= lsetxattr(path, names[i], values[i], value_lengths[i], 0); ret= lsetxattr(path, names[i], values[i], value_lengths[i], 0);
if(ret == -1) { if(ret == -1) {
aaip_local_error((flag & 32) ? "setxattr" : "lsetxattr", path, errno,
1);
register_errno(errnos, i); register_errno(errnos, i);
end_ret= -4; end_ret= -4;
continue; continue;

View File

@ -8954,9 +8954,13 @@ int iso_conv_name_chars(IsoWriteOpts *opts, char *name, size_t name_len,
/** Error with reading ACL or xattr from local file (FAILURE, HIGH, -341) */ /** Error with reading ACL or xattr from local file (FAILURE, HIGH, -341) */
#define ISO_AAIP_NO_GET_LOCAL 0xE830FEAB #define ISO_AAIP_NO_GET_LOCAL 0xE830FEAB
/** Error with reading ACL or xattr from local file (SORRY, HIGH, -341) */
#define ISO_AAIP_NO_GET_LOCAL_S 0xE030FEAB
/** Error with attaching ACL or xattr to local file (FAILURE, HIGH, -342) */ /** Error with attaching ACL or xattr to local file (FAILURE, HIGH, -342) */
#define ISO_AAIP_NO_SET_LOCAL 0xE830FEAA #define ISO_AAIP_NO_SET_LOCAL 0xE830FEAA
/** Error with attaching ACL or xattr to local file (SORRY, HIGH, -342) */
#define ISO_AAIP_NO_SET_LOCAL_S 0xE030FEAA
/** Unallowed attempt to set an xattr with non-userspace name /** Unallowed attempt to set an xattr with non-userspace name
(FAILURE, HIGH, -343) */ (FAILURE, HIGH, -343) */