Let configure detect availability of libacl and of Linux listxattr call

and aaip-os work around eventual missing functionality
This commit is contained in:
Thomas Schmitt 2009-01-23 18:28:51 +01:00
parent aae339fe49
commit bd9b49714f
4 changed files with 171 additions and 71 deletions

View File

@ -10,7 +10,11 @@ lib_LTLIBRARIES = libisofs/libisofs.la
libisofs_libisofs_la_LDFLAGS = \
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
# ts A80114 : added aaip_0_2.*
# ts A90123 : Eventually enabling system adapters for ACL and EA
libisofs_libisofs_la_CFLAGS = $(LIBACL_DEF) $(XATTR_DEF)
# ts A90114 : added aaip_0_2.*
libisofs_libisofs_la_SOURCES = \
libisofs/builder.h \
@ -64,8 +68,7 @@ libisofs_libisofs_la_SOURCES = \
libisofs/aaip_0_2.h \
libisofs/aaip_0_2.c
libisofs_libisofs_la_LIBADD= \
$(THREAD_LIBS) \
-lacl
$(THREAD_LIBS)
libinclude_HEADERS = \
libisofs/libisofs.h

View File

@ -146,6 +146,37 @@ AC_ARG_ENABLE(verbose-debug,
AC_DEFINE(LIBISOFS_VERBOSE_DEBUG, 1))
dnl ts A90123
AC_ARG_ENABLE(libacl,
[ --enable-libacl Enable use of libacl by libisofs, default=yes],
, enable_libacl=yes)
if test x$enable_libacl = xyes; then
dnl Check whether there is libacl-devel and libacl-runtime.
dnl If not, erase this macro which would enable use of acl_to_text and others
LIBACL_DEF="-DLibisofs_with_aaip_acL"
dnl The empty yes case obviously causes -lacl to be linked
AC_CHECK_HEADER(sys/acl.h, AC_CHECK_LIB(acl, acl_to_text, , LIBACL_DEF= ), LIBACL_DEF= )
else
LIBACL_DEF=
fi
AC_SUBST(LIBACL_DEF)
dnl ts A90123
AC_ARG_ENABLE(xattr,
[ --enable-xattr Enable use of xattr by libisofs, default=yes],
, enable_xattr=yes)
if test x$enable_xattr = xyes; then
dnl Check whether there is the header for Linux xattr.
dnl If not, erase this macro which would enable use of listxattr and others
XATTR_DEF="-DLibisofs_with_aaip_xattR"
AC_CHECK_HEADER(attr/xattr.h, AC_CHECK_LIB(c, listxattr, X= , XATTR_DEF= ), XATTR_DEF= )
else
XATTR_DEF=
fi
AC_SUBST(XATTR_DEF)
AC_CONFIG_FILES([
Makefile
doc/doxygen.conf

View File

@ -16,7 +16,9 @@
#include <stdio.h>
#include <sys/stat.h>
#ifdef Libisofs_with_aaip_acL
#include <sys/acl.h>
#endif
/* ------------------------------ Getters --------------------------------- */
@ -33,16 +35,23 @@
bit15= free text and return 1
@return > 0 ok
-1 failure of system ACL service (see errno)
-2 ACL support not enabled at compile time
*/
int aaip_get_acl_text(char *path, char **text, int flag)
{
#ifdef Libisofs_with_aaip_acL
acl_t acl= NULL;
#endif
struct stat stbuf;
int ret;
if(flag & (1 << 15)) {
if(*text != NULL)
#ifdef Libisofs_with_aaip_acL
acl_free(text);
#else
free(text);
#endif
*text= NULL;
return(1);
}
@ -52,12 +61,23 @@ int aaip_get_acl_text(char *path, char **text, int flag)
if(flag & 1)
return(0);
#ifdef Libisofs_with_aaip_acL
acl= acl_get_file(path, ACL_TYPE_ACCESS);
if(acl == NULL)
return(-1);
*text= acl_to_text(acl, NULL);
acl_free(acl);
#else /* Libisofs_with_aaip_acL */
/* ??? >>> Fake ACL */;
return(-2);
#endif /* ! Libisofs_with_aaip_acL */
if(*text == NULL)
return(-1);
if(flag & 16) {
@ -68,7 +88,11 @@ int aaip_get_acl_text(char *path, char **text, int flag)
(*text)[0]= 0;
}
if((*text)[0] == 0 || strcmp(*text, "\n") == 0) {
#ifdef Libisofs_with_aaip_acL
acl_free(text);
#else
free(text);
#endif
*text= NULL;
return(2);
}
@ -136,6 +160,8 @@ int aaip_get_attr_list(char *path, size_t *num_attrs, char ***names,
(*value_lengths)[i]= 0;
}
#ifdef Libisofs_with_aaip_acL
if(flag & 1) { /* Obtain ACL */
/* access-ACL */
ret= aaip_get_acl_text(path, &acl_text, flag & 16);
@ -159,6 +185,8 @@ int aaip_get_attr_list(char *path, size_t *num_attrs, char ***names,
(*num_attrs)++;
}
#endif /* Libisofs_with_aaip_acL */
ret= 1;
ex:;
if(a_acl != NULL)
@ -201,9 +229,13 @@ ex:;
bit0= set default ACL rather than access ACL
@return > 0 ok
-1 failure of system ACL service (see errno)
-2 ACL support not enabled at compile time
*/
int aaip_set_acl_text(char *path, char *text, int flag)
{
#ifdef Libisofs_with_aaip_acL
int ret;
acl_t acl= NULL;
@ -225,6 +257,13 @@ ex:
if(acl != NULL)
acl_free(acl);
return(ret);
#else /* Libisofs_with_aaip_acL */
return(-2);
#endif /* ! Libisofs_with_aaip_acL */
}
@ -242,12 +281,13 @@ ex:
-3 error with setting ACL
( -4 error with setting attribute )
( -5 error with deleting attribute )
-6 support of xattr not enabled at compile time
-7 support of ACL not enabled at compile time
*/
int aaip_set_attr_list(char *path, size_t num_attrs, char **names,
size_t *value_lengths, char **values, int flag)
{
int ret, has_default_acl= 0;
int ret, has_default_acl= 0, was_xattr= 0;
size_t i, consumed, acl_text_fill, list_size= 0;
char *acl_text= NULL, *list= NULL;
@ -268,9 +308,15 @@ int aaip_set_attr_list(char *path, size_t num_attrs, char **names,
if(ret <= 0)
{ret= -2; goto ex;}
has_default_acl= (ret == 2);
#ifdef Libisofs_with_aaip_acL
ret= aaip_set_acl_text(path, acl_text, 0);
if(ret <= 0)
{ret= -3; goto ex;}
#else
{ret= -7; goto ex;}
#endif
/* "default" ACL */
if(has_default_acl) {
free(acl_text);
acl_text= NULL;
@ -291,9 +337,12 @@ int aaip_set_attr_list(char *path, size_t num_attrs, char **names,
if(ret <= 0)
{ret= -3; goto ex;}
}
}
} else
was_xattr= 1;
}
ret= 1;
if(was_xattr)
ret= -6;
ex:;
if(acl_text != NULL)
free(acl_text);

View File

@ -16,8 +16,13 @@
#include <stdio.h>
#include <sys/stat.h>
#ifdef Libisofs_with_aaip_acL
#include <sys/acl.h>
#endif
#ifdef Libisofs_with_aaip_xattR
#include <attr/xattr.h>
#endif
#define Aaip_acl_attrnamE "system.posix_acl_access"
@ -39,25 +44,44 @@
2 only st_mode permissions exist and bit 4 is set
or empty ACL and bit0 is set
-1 failure of system ACL service (see errno)
-2 ACL support not enabled at compile time
*/
int aaip_get_acl_text(char *path, char **text, int flag)
{
#ifdef Libisofs_with_aaip_acL
acl_t acl= NULL;
#endif
struct stat stbuf;
int ret;
if(flag & (1 << 15)) {
if(*text != NULL)
#ifdef Libisofs_with_aaip_acL
acl_free(text);
#else
free(text);
#endif
*text= NULL;
return(1);
}
*text= NULL;
#ifdef Libisofs_with_aaip_acL
acl= acl_get_file(path, (flag & 1) ? ACL_TYPE_DEFAULT : ACL_TYPE_ACCESS);
if(acl == NULL)
return(-1);
*text= acl_to_text(acl, NULL);
acl_free(acl);
#else /* Libisofs_with_aaip_acL */
/* ??? >>> Fake ACL */;
return(-2);
#endif /* ! Libisofs_with_aaip_acL */
if(*text == NULL)
return(-1);
if(flag & 16) {
@ -70,7 +94,11 @@ int aaip_get_acl_text(char *path, char **text, int flag)
}
if(flag & (1 | 16)) {
if((*text)[0] == 0 || strcmp(*text, "\n") == 0) {
#ifdef Libisofs_with_aaip_acL
acl_free(text);
#else
free(text);
#endif
*text= NULL;
return(2);
}
@ -105,16 +133,7 @@ int aaip_get_attr_list(char *path, size_t *num_attrs, char ***names,
ssize_t list_size= 0, i, num_names= 0, value_ret;
size_t acl_len= 0;
unsigned char *acl= NULL;
#define Aaip_os_linux_use_both_acL yes
#ifdef Aaip_os_linux_use_both_acL
char *a_acl_text= NULL, *d_acl_text= NULL;
#else
char *acl_text= NULL;
size_t a_acl_len= 0, d_acl_len= 0;
unsigned char *a_acl= NULL, *d_acl= NULL;
#endif
if(flag & (1 << 15)) { /* Free memory */
if(*names != NULL)
@ -129,6 +148,9 @@ int aaip_get_attr_list(char *path, size_t *num_attrs, char ***names,
/* Set up arrays */
if(!(flag & 4)) { /* Get xattr names */
#ifdef Libisofs_with_aaip_xattR
list_size= listxattr(path, list, 0);
if(list_size == -1)
{ret= -1; goto ex;}
@ -138,11 +160,22 @@ int aaip_get_attr_list(char *path, size_t *num_attrs, char ***names,
list_size= listxattr(path, list, list_size);
if(list_size == -1)
{ret= -1; goto ex;}
#else /* Libisofs_with_aaip_xattR */
list= strdup("");
#endif /* ! Libisofs_with_aaip_xattR */
for(i= 0; i < list_size; i+= strlen(list + i) + 1)
num_names++;
}
#ifdef Libisofs_with_aaip_acL
if(flag & 1)
num_names++;
#endif
if(num_names == 0)
{ret= 1; goto ex;}
(*names)= calloc(num_names, sizeof(char *));
@ -166,6 +199,8 @@ int aaip_get_attr_list(char *path, size_t *num_attrs, char ***names,
(*value_lengths)[i]= 0;
}
#ifdef Libisofs_with_aaip_xattR
if(!(flag & 4)) { /* Get xattr values */
for(i= 0; i < *num_attrs; i++) {
if(!(flag & 8))
@ -189,11 +224,12 @@ int aaip_get_attr_list(char *path, size_t *num_attrs, char ***names,
}
}
#endif /* Libisofs_with_aaip_xattR */
#ifdef Libisofs_with_aaip_acL
if(flag & 1) { /* Obtain ACL */
#ifdef Aaip_os_linux_use_both_acL
/* access-ACL */
aaip_get_acl_text(path, &a_acl_text, flag & 16);
aaip_get_acl_text(path, &d_acl_text, 1);
if(a_acl_text == NULL && d_acl_text == NULL)
@ -203,42 +239,6 @@ int aaip_get_attr_list(char *path, size_t *num_attrs, char ***names,
if(ret <= 0)
goto ex;
#else /* Aaip_os_linux_use_both_acL */
/* access-ACL */
ret= aaip_get_acl_text(path, &acl_text, flag & 16);
if(ret <= 0)
goto ex;
if(ret == 2)
{ret= 1; goto ex;} /* empty ACL / only st_mode info was found in ACL */
ret= aaip_encode_acl(acl_text, &a_acl_len, &a_acl, flag & 2);
if(ret <= 0)
goto ex;
aaip_get_acl_text("", &acl_text, 1 << 15); /* free */
/* eventually default-ACL */
ret= aaip_get_acl_text(path, &acl_text, 1);
if(ret > 0) {
/* encode and append to a_acl */;
ret= aaip_encode_acl(acl_text, &d_acl_len, &d_acl, (flag & 2) | 4);
if(ret <= 0)
goto ex;
acl= calloc(a_acl_len + d_acl_len + 1, 1);
if(acl == NULL)
{ret= -1; goto ex;}
if(a_acl_len)
memcpy(acl, a_acl, a_acl_len);
if(d_acl_len)
memcpy(acl + a_acl_len, d_acl, d_acl_len);
acl_len= a_acl_len + d_acl_len;
} else {
acl= a_acl;
a_acl= NULL;
acl_len= a_acl_len;
}
#endif /* ! Aaip_os_linux_use_both_acL */
/* Set as attribute with empty name */;
(*names)[*num_attrs]= strdup("");
if((*names)[*num_attrs] == NULL)
@ -249,28 +249,14 @@ int aaip_get_attr_list(char *path, size_t *num_attrs, char ***names,
(*num_attrs)++;
}
#endif /* Libisofs_with_aaip_acL */
ret= 1;
ex:;
#ifdef Aaip_os_linux_use_both_acL
if(a_acl_text != NULL)
aaip_get_acl_text("", &a_acl_text, 1 << 15); /* free */
if(d_acl_text != NULL)
aaip_get_acl_text("", &d_acl_text, 1 << 15); /* free */
#else /* Aaip_os_linux_use_both_acL */
if(a_acl != NULL)
free(a_acl);
if(d_acl != NULL)
free(d_acl);
if(acl != NULL)
free(acl);
if(acl_text != NULL)
aaip_get_acl_text("", &acl_text, 1 << 15); /* free */
#endif /* ! Aaip_os_linux_use_both_acL */
if(ret <= 0 || (flag & (1 << 15))) {
if(list != NULL)
free(list);
@ -304,9 +290,13 @@ ex:;
bit0= set default ACL rather than access ACL
@return > 0 ok
-1 failure of system ACL service (see errno)
-2 ACL support not enabled at compile time
*/
int aaip_set_acl_text(char *path, char *text, int flag)
{
#ifdef Libisofs_with_aaip_acL
int ret;
acl_t acl= NULL;
@ -322,6 +312,13 @@ ex:
if(acl != NULL)
acl_free(acl);
return(ret);
#else /* Libisofs_with_aaip_acL */
return(-2);
#endif /* ! Libisofs_with_aaip_acL */
}
@ -338,7 +335,8 @@ ex:
-3 error with setting ACL
-4 error with setting attribute
-5 error with deleting attributes
-6 support of xattr not enabled at compile time
-7 support of ACL not enabled at compile time
*/
int aaip_set_attr_list(char *path, size_t num_attrs, char **names,
size_t *value_lengths, char **values, int flag)
@ -347,6 +345,8 @@ int aaip_set_attr_list(char *path, size_t num_attrs, char **names,
size_t i, consumed, acl_text_fill, list_size= 0, acl_idx= 0;
char *acl_text= NULL, *list= NULL;
#ifdef Libisofs_with_aaip_xattR
if(flag & 2) /* Delete all file attributes */
list_size= listxattr(path, list, 0);
if(list_size > 0) { /* Delete all file attributes */
@ -367,6 +367,8 @@ int aaip_set_attr_list(char *path, size_t num_attrs, char **names,
free(list); list= NULL;
}
#endif /* Libisofs_with_aaip_xattR */
for(i= 0; i < num_attrs; i++) {
if(names[i] == NULL || values[i] == NULL)
continue;
@ -379,9 +381,19 @@ int aaip_set_attr_list(char *path, size_t num_attrs, char **names,
if((flag & 1) && !(flag & 8))
if(strcmp(names[i], Aaip_acl_attrnamE) == 0)
continue;
#ifdef Libisofs_with_aaip_xattR
ret= setxattr(path, names[i], values[i], value_lengths[i], 0);
if(ret == -1)
{ret= -4; goto ex;}
#else
{ret= -6; goto ex;}
#endif /* Libisofs_with_aaip_xattR */
}
/* Decode ACLs */
@ -401,9 +413,14 @@ int aaip_set_attr_list(char *path, size_t num_attrs, char **names,
if(ret <= 0)
{ret= -2; goto ex;}
has_default_acl= (ret == 2);
#ifdef Libisofs_with_aaip_acL
ret= aaip_set_acl_text(path, acl_text, 0);
if(ret <= 0)
{ret= -3; goto ex;}
#else
{ret= -7; goto ex;}
#endif
/* "default" ACL */
if(has_default_acl) {
free(acl_text);