Giving access to AAIP xattr by new API functions iso_node_get_attrs() and

iso_node_set_attrs. Giving access to local filesystem xattr by new API
functions iso_local_get_attrs(), iso_local_set_attrs().
This commit is contained in:
Thomas Schmitt 2009-02-02 11:49:28 +01:00
parent c226491f18
commit 4950f869cb
4 changed files with 351 additions and 77 deletions

View File

@ -126,15 +126,12 @@ int aaip_get_attr_list(char *path, size_t *num_attrs, char ***names,
size_t **value_lengths, char ***values, int flag) size_t **value_lengths, char ***values, int flag)
{ {
int ret; int ret;
char *list= NULL;
ssize_t i, num_names; ssize_t i, num_names;
size_t a_acl_len= 0, acl_len= 0; size_t a_acl_len= 0, acl_len= 0;
unsigned char *a_acl= NULL, *d_acl= NULL, *acl= NULL; unsigned char *a_acl= NULL, *d_acl= NULL, *acl= NULL;
char *acl_text= NULL; char *acl_text= NULL;
if(flag & (1 << 15)) { /* Free memory */ if(flag & (1 << 15)) { /* Free memory */
if(*names != NULL)
list= (*names)[0];
{ret= 1; goto ex;} {ret= 1; goto ex;}
} }
@ -153,9 +150,8 @@ int aaip_get_attr_list(char *path, size_t *num_attrs, char ***names,
if(*names == NULL || *value_lengths == NULL || *values == NULL) if(*names == NULL || *value_lengths == NULL || *values == NULL)
{ret= -1; goto ex;} {ret= -1; goto ex;}
for(i= *num_attrs; i < num_names; i++)
(*names)[i]= NULL;
for(i= 0; i < num_names; i++) { for(i= 0; i < num_names; i++) {
(*names)[i]= NULL;
(*values)[i]= NULL; (*values)[i]= NULL;
(*value_lengths)[i]= 0; (*value_lengths)[i]= 0;
} }
@ -197,10 +193,11 @@ ex:;
aaip_get_acl_text("", &acl_text, 1 << 15); /* free */ aaip_get_acl_text("", &acl_text, 1 << 15); /* free */
if(ret <= 0 || (flag & (1 << 15))) { if(ret <= 0 || (flag & (1 << 15))) {
if(list != NULL) if(*names != NULL) {
free(list); for(i= 0; i < *num_attrs; i++)
if(*names != NULL) free((*names)[i]);
free(*names); free(*names);
}
*names= NULL; *names= NULL;
if(*value_lengths != NULL) if(*value_lengths != NULL)
free(*value_lengths); free(*value_lengths);

View File

@ -24,7 +24,8 @@
#include <attr/xattr.h> #include <attr/xattr.h>
#endif #endif
#define Aaip_acl_attrnamE "system.posix_acl_access" #define Aaip_a_acl_attrnamE "system.posix_acl_access"
#define Aaip_d_acl_attrnamE "system.posix_acl_default"
/* ------------------------------ Getters --------------------------------- */ /* ------------------------------ Getters --------------------------------- */
@ -124,8 +125,6 @@ int aaip_get_attr_list(char *path, size_t *num_attrs, char ***names,
char *a_acl_text= NULL, *d_acl_text= NULL; char *a_acl_text= NULL, *d_acl_text= NULL;
if(flag & (1 << 15)) { /* Free memory */ if(flag & (1 << 15)) { /* Free memory */
if(*names != NULL)
list= (*names)[0];
{ret= 1; goto ex;} {ret= 1; goto ex;}
} }
@ -172,19 +171,22 @@ int aaip_get_attr_list(char *path, size_t *num_attrs, char ***names,
if(*names == NULL || *value_lengths == NULL || *values == NULL) if(*names == NULL || *value_lengths == NULL || *values == NULL)
{ret= -1; goto ex;} {ret= -1; goto ex;}
if(!(flag & 4)) for(i= 0; i < num_names; i++) {
(*names)[i]= NULL;
(*values)[i]= NULL;
(*value_lengths)[i]= 0;
}
if(!(flag & 4)) {
for(i= 0; i < list_size && num_names > *num_attrs; for(i= 0; i < list_size && num_names > *num_attrs;
i+= strlen(list + i) + 1) { i+= strlen(list + i) + 1) {
if(!(flag & 8)) if(!(flag & 8))
if(strcmp(list + i, Aaip_acl_attrnamE) == 0) if(strcmp(list + i, Aaip_a_acl_attrnamE) == 0 ||
strcmp(list + i, Aaip_d_acl_attrnamE) == 0)
continue; continue;
(*names)[(*num_attrs)++]= list + i; (*names)[(*num_attrs)++]= strdup(list + i);
if((*names)[(*num_attrs) - 1] == NULL)
{ret= -1; goto ex;}
} }
for(i= *num_attrs; i < num_names; i++)
(*names)[i]= NULL;
for(i= 0; i < num_names; i++) {
(*values)[i]= NULL;
(*value_lengths)[i]= 0;
} }
#ifdef Libisofs_with_aaip_xattR #ifdef Libisofs_with_aaip_xattR
@ -192,7 +194,8 @@ int aaip_get_attr_list(char *path, size_t *num_attrs, char ***names,
if(!(flag & 4)) { /* Get xattr values */ if(!(flag & 4)) { /* Get xattr values */
for(i= 0; i < *num_attrs; i++) { for(i= 0; i < *num_attrs; i++) {
if(!(flag & 8)) if(!(flag & 8))
if(strcmp((*names)[i], Aaip_acl_attrnamE) == 0) if(strcmp((*names)[i], Aaip_a_acl_attrnamE) == 0 ||
strcmp((*names)[i], Aaip_d_acl_attrnamE) == 0)
continue; continue;
value_ret= getxattr(path, (*names)[i], NULL, 0); value_ret= getxattr(path, (*names)[i], NULL, 0);
if(value_ret == -1) if(value_ret == -1)
@ -200,7 +203,7 @@ int aaip_get_attr_list(char *path, size_t *num_attrs, char ***names,
(*values)[i]= calloc(value_ret + 1, 1); (*values)[i]= calloc(value_ret + 1, 1);
if((*values)[i] == NULL) if((*values)[i] == NULL)
{ret= -1; goto ex;} {ret= -1; goto ex;}
(*value_lengths)[i]= getxattr(path, (*names)[i], (*values)[i], value_ret); value_ret= getxattr(path, (*names)[i], (*values)[i], value_ret);
if(value_ret == -1) { /* there could be a race condition */ if(value_ret == -1) { /* there could be a race condition */
if(retry++ > 5) if(retry++ > 5)
{ret= -1; goto ex;} {ret= -1; goto ex;}
@ -248,8 +251,11 @@ ex:;
if(ret <= 0 || (flag & (1 << 15))) { if(ret <= 0 || (flag & (1 << 15))) {
if(list != NULL) if(list != NULL)
free(list); free(list);
if(*names != NULL) if(*names != NULL) {
for(i= 0; i < *num_attrs; i++)
free((*names)[i]);
free(*names); free(*names);
}
*names= NULL; *names= NULL;
if(*value_lengths != NULL) if(*value_lengths != NULL)
free(*value_lengths); free(*value_lengths);
@ -346,7 +352,8 @@ int aaip_set_attr_list(char *path, size_t num_attrs, char **names,
{ret= -5; goto ex;} {ret= -5; goto ex;}
for(i= 0; i < list_size; i+= strlen(list + i) + 1) { for(i= 0; i < list_size; i+= strlen(list + i) + 1) {
if(!(flag & 8)) if(!(flag & 8))
if(strcmp(list + i, Aaip_acl_attrnamE) == 0) if(strcmp(list + i, Aaip_a_acl_attrnamE) == 0 ||
strcmp(list + i, Aaip_d_acl_attrnamE) == 0)
continue; continue;
ret= removexattr(path, list + i); ret= removexattr(path, list + i);
if(ret == -1) if(ret == -1)
@ -367,7 +374,8 @@ int aaip_set_attr_list(char *path, size_t num_attrs, char **names,
} }
/* Extended Attribute */ /* Extended Attribute */
if((flag & 1) && !(flag & 8)) if((flag & 1) && !(flag & 8))
if(strcmp(names[i], Aaip_acl_attrnamE) == 0) if(strcmp(names[i], Aaip_a_acl_attrnamE) == 0 ||
strcmp(names[i], Aaip_d_acl_attrnamE) == 0)
continue; continue;
#ifdef Libisofs_with_aaip_xattR #ifdef Libisofs_with_aaip_xattR

View File

@ -686,12 +686,12 @@ struct IsoFileSource_Iface
/* ts A90114 */ /* ts A90114 */
/** /**
* Valid only if .version is > 0. See above. * Valid only if .version is > 0. See above.
* Get the AA string with encoded ACL and/or XFS-style Extended Attributes. * Get the AA string with encoded ACL and XFS-style Extended Attributes
* (Not to be confused with ECMA-119 Extended Attributes). * xattr. (Not to be confused with ECMA-119 Extended Attributes).
* *
* bit1 and bit2 of flag should be implemented so that freshly fetched * bit1 and bit2 of flag should be implemented so that freshly fetched
* info does not include the undesired ACL or EAs. Nevertheless if the * info does not include the undesired ACL or xattr. Nevertheless if the
* aa_string is cached, then it is permissible that ACL and EA are still * aa_string is cached, then it is permissible that ACL and xattr are still
* delivered. * delivered.
* *
* @param flag Bitfield for control purposes * @param flag Bitfield for control purposes
@ -699,7 +699,7 @@ struct IsoFileSource_Iface
* src will free the eventual cached data and might * src will free the eventual cached data and might
* not be able to produce it again. * not be able to produce it again.
* bit1= No need to get ACL (no guarantee of exclusion) * bit1= No need to get ACL (no guarantee of exclusion)
* bit2= No need to get EA (no guarantee of exclusion) * bit2= No need to get xattr (no guarantee of exclusion)
* @param aa_string Returns a pointer to the AA string data. If no AA * @param aa_string Returns a pointer to the AA string data. If no AA
* string is available, *aa_string becomes NULL. * string is available, *aa_string becomes NULL.
* (See doc/susp_aaip_0_2.txt for the meaning of AA and * (See doc/susp_aaip_0_2.txt for the meaning of AA and
@ -937,13 +937,13 @@ int iso_image_new(const char *name, IsoImage **image);
/* ts A90121 */ /* ts A90121 */
/** /**
* Control whether ACL and XFS-style Extended Attributes will be imported from * Control whether ACL and XFS-style Extended Attributes xattr will be
* external filesystems (typically the local POSIX filesystem) when new * imported from external filesystems (typically the local POSIX filesystem)
* nodes get inserted. If enabled by iso_write_opts_set_aaip() they will later * when new nodes get inserted. If enabled by iso_write_opts_set_aaip() they
* be written into the image as AAIP extension fields. * will later be written into the image as AAIP extension fields.
* *
* A change of this setting does neither affect existing IsoNode objects * A change of this setting does neither affect existing IsoNode objects
* nor the way how ACL and EA are handled when loading an ISO image. * nor the way how ACL and xattr are handled when loading an ISO image.
* The latter is controlled by iso_read_opts_set_no_aaip(). * The latter is controlled by iso_read_opts_set_no_aaip().
* *
* @param image * @param image
@ -951,7 +951,7 @@ int iso_image_new(const char *name, IsoImage **image);
* @param what * @param what
* A bit field which sets the behavior: * A bit field which sets the behavior:
* bit0= ignore ACLs if the external file object bears some * bit0= ignore ACLs if the external file object bears some
* bit1= ignore EAs if the external file object bears some * bit1= ignore xattr if the external file object bears some
* all other bits are reserved * all other bits are reserved
* *
* @since 0.6.14 * @since 0.6.14
@ -1061,7 +1061,7 @@ int iso_lib_is_compatible(int major, int minor, int micro);
* ---> 1 [BACKUP] * ---> 1 [BACKUP]
* POSIX compatibility for backup. Simple settings, ISO level is set to * POSIX compatibility for backup. Simple settings, ISO level is set to
* 3 and RR extensions are enabled. Useful for backup purposes. * 3 and RR extensions are enabled. Useful for backup purposes.
* Note that ACL and XFS-style EA are not enabled by default. * Note that ACL and XFS-style xattr are not enabled by default.
* If you enable them, expect them not to show up in the mounted image. * If you enable them, expect them not to show up in the mounted image.
* They will have to be retrieved by libisofs applications like xorriso. * They will have to be retrieved by libisofs applications like xorriso.
* ---> 2 [DISTRIBUTION] * ---> 2 [DISTRIBUTION]
@ -1148,8 +1148,8 @@ int iso_write_opts_set_iso1999(IsoWriteOpts *opts, int enable);
/* ts A90122 */ /* ts A90122 */
/** /**
* Control writing of AAIP informations for ACL and XFS-style Extended * Control writing of AAIP informations for ACL and XFS-style Extended
* Attributes. * Attributes xattr.
* For importing ACL and EA when inserting nodes from external filesystems * For importing ACL and xattr when inserting nodes from external filesystems
* (e.g. the local POSIX filesystem) see iso_image_set_ignore_aclea(). * (e.g. the local POSIX filesystem) see iso_image_set_ignore_aclea().
* For loading of this information from images see iso_read_opts_set_no_aaip(). * For loading of this information from images see iso_read_opts_set_no_aaip().
* *
@ -1539,7 +1539,7 @@ int iso_image_update_sizes(IsoImage *image);
* ---> 0 [STANDARD] * ---> 0 [STANDARD]
* Suitable for most situations. Most extension are read. When both * Suitable for most situations. Most extension are read. When both
* Joliet and RR extension are present, RR is used. * Joliet and RR extension are present, RR is used.
* AAIP for ACL and Extended Attributes is not enabled by default. * AAIP for ACL and xattr is not enabled by default.
* @return * @return
* 1 success, < 0 error * 1 success, < 0 error
* *
@ -1587,8 +1587,8 @@ int iso_read_opts_set_no_iso1999(IsoReadOpts *opts, int noiso1999);
/** /**
* Control reading of AAIP informations about ACL and XFS-style Extended * Control reading of AAIP informations about ACL and XFS-style Extended
* Attributes when loading existing images. * Attributes xattr when loading existing images.
* For importing ACL and EA when inserting nodes from external filesystems * For importing ACL and xattr when inserting nodes from external filesystems
* (e.g. the local POSIX filesystem) see iso_image_set_ignore_aclea(). * (e.g. the local POSIX filesystem) see iso_image_set_ignore_aclea().
* For eventual writing of this information see iso_write_opts_set_aaip(). * For eventual writing of this information see iso_write_opts_set_aaip().
* *
@ -2123,8 +2123,9 @@ typedef int (*iso_node_xinfo_func)(void *data, int flag);
/** /**
* Add extended information to the given node. Extended info allows * Add extended information to the given node. Extended info allows
* applications (and libisofs itself) to add more information to an IsoNode. * applications (and libisofs itself) to add more information to an IsoNode.
* You can use this facilities to associate new information with a given * You can use this facilities to associate temporary information with a given
* node. * node. This information is not written into the ISO 9660 image on media
* and thus does not persist longer than the node memory object.
* *
* Each node keeps a list of added extended info, meaning you can add several * Each node keeps a list of added extended info, meaning you can add several
* extended info data to each node. Each extended info you add is identified * extended info data to each node. Each extended info you add is identified
@ -3751,7 +3752,7 @@ int iso_file_source_readlink(IsoFileSource *src, char *buf, size_t bufsiz);
/** /**
* Get the AA string with encoded ACL and/or XFS-style Extended Attributes. * Get the AA string with encoded ACL and XFS-style Extended Attributes xattr.
* (Not to be confused with ECMA-119 Extended Attributes). * (Not to be confused with ECMA-119 Extended Attributes).
* @param src The file source object to be inquired. * @param src The file source object to be inquired.
* @param aa_string Returns a pointer to the AA string data. If no AA * @param aa_string Returns a pointer to the AA string data. If no AA
@ -3765,7 +3766,7 @@ int iso_file_source_readlink(IsoFileSource *src, char *buf, size_t bufsiz);
* src will free the eventual cached data and might * src will free the eventual cached data and might
* not be able to produce it again. * not be able to produce it again.
* bit1= No need to get ACL (but no guarantee of exclusion) * bit1= No need to get ACL (but no guarantee of exclusion)
* bit2= No need to get EA (but no guarantee of exclusion) * bit2= No need to get xattr (but no guarantee of exclusion)
* @return 1 means success (*aa_string == NULL is possible) * @return 1 means success (*aa_string == NULL is possible)
* <0 means failure and must b a valid libisofs error code * <0 means failure and must b a valid libisofs error code
* (e.g. ISO_FILE_ERROR if no better one can be found). * (e.g. ISO_FILE_ERROR if no better one can be found).
@ -4223,10 +4224,19 @@ void iso_stream_get_id(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id,
/** Error with decoding attribute list AAIP info (FAILURE, HIGH, -340) */ /** Error with decoding attribute list AAIP info (FAILURE, HIGH, -340) */
#define ISO_AAIP_BAD_AASTRING 0xE830FEAC #define ISO_AAIP_BAD_AASTRING 0xE830FEAC
/* ts A90131 */
/** Error with reading ACL or xattr from local file (FAILURE, HIGH, -341) */
#define ISO_AAIP_NO_GET_LOCAL 0xE830FEAB
/* ts A90131 */
/** Error with attaching ACL or xattr to local file (FAILURE, HIGH, -342) */
#define ISO_AAIP_NO_SET_LOCAL 0xE830FEAA
/* --------------------------------- AAIP --------------------------------- */ /* --------------------------------- AAIP --------------------------------- */
/* ts A90112 : Enable experiments about EA and ACL /* ts A90112 : Enable experiments about xattr and ACL
*/ */
#define Libisofs_with_aaiP yes #define Libisofs_with_aaiP yes
@ -4240,14 +4250,22 @@ void iso_stream_get_id(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id,
/** /**
* Function to identify and manage AA strings as xinfo of IsoNode. * Function to identify and manage AA strings as xinfo of IsoNode.
* *
* An AA string contains all EA (aka xattr) and ACL of a node in the image * An AA string contains the Attribute List with the xattr and ACL of a node
* tree. It is formatted according to libisofs specification AAIP-0.2 and * in the image tree. It is formatted according to libisofs specification
* ready to be written into the System Use Area resp. Continuation Area * AAIP-0.2 and ready to be written into the System Use Area resp. Continuation
* of a directory entry in an ISO image. * Area of a directory entry in an ISO image.
* *
* Applications are not supposed to manipulate AA strings directly. They should * Applications are not supposed to manipulate AA strings directly. They should
* rather make use of the appropriate iso_node_get_* and iso_node_set_* calls. * rather make use of the appropriate iso_node_get_* and iso_node_set_* calls.
* *
* AAIP represents ACLs as xattr with empty name and AAIP-specific binary
* content. Local filesystems may represent ACLs as xattr with names like
* "system.posix_acl_access". libisofs does not interpret those local
* xattr representations of ACL directly but rather uses the ACL interface of
* the local system. By default the local xattr representations of ACL will
* not become part of the AAIP Attribute List via iso_local_get_attrs() and
* not be attached to local files via iso_local_set_attrs().
*
* @since 0.6.14 * @since 0.6.14
*/ */
int aaip_xinfo_func(void *data, int flag); int aaip_xinfo_func(void *data, int flag);
@ -4257,14 +4275,14 @@ int aaip_xinfo_func(void *data, int flag);
/** /**
* Get the eventual ACLs which are associated with the node. * Get the eventual ACLs which are associated with the node.
* The result will be in "long" text form as of man acl resp. acl_to_text(). * The result will be in "long" text form as of man acl resp. acl_to_text().
* Call this function with flag bit15 to finally release the memory
* occupied by an ACL inquiry.
* *
* @param node * @param node
* The node that is to be inquired. * The node that is to be inquired.
* @param access_text * @param access_text
* Will return a pointer to the eventual "access" ACL text or NULL if it * Will return a pointer to the eventual "access" ACL text or NULL if it
* is not available and flag bit 4 is set. * is not available and flag bit 4 is set.
* Call this function with flag bit15 to finally release the memory
* occupied by an ACL inquiry.
* @param default_text * @param default_text
* Will return a pointer to the eventual "default" ACL or NULL if it * Will return a pointer to the eventual "default" ACL or NULL if it
* is not available. * is not available.
@ -4292,7 +4310,7 @@ int iso_node_get_acl_text(IsoNode *node,
* Set the ACLs of the given node to the lists in parameters access_text and * Set the ACLs of the given node to the lists in parameters access_text and
* default_text or delete them. * default_text or delete them.
* *
* The POSIX permission bits get updated according to the new "access" ACL if * The stat(2) permission bits get updated according to the new "access" ACL if
* neither bit1 of parameter flag is set nor parameter access_text is NULL. * neither bit1 of parameter flag is set nor parameter access_text is NULL.
* Note that S_IRWXG permission bits correspond to ACL mask permissions * Note that S_IRWXG permission bits correspond to ACL mask permissions
* if a "mask::" entry exists in the ACL. Only if there is no "mask::" then * if a "mask::" entry exists in the ACL. Only if there is no "mask::" then
@ -4316,10 +4334,87 @@ int iso_node_get_acl_text(IsoNode *node,
* @return * @return
* > 0 success * > 0 success
* < 0 failure * < 0 failure
*
* @since 0.6.14
*/ */
int iso_node_set_acl_text(IsoNode *node, int iso_node_set_acl_text(IsoNode *node,
char *access_text, char *default_text, int flag); char *access_text, char *default_text, int flag);
/* ts A90131 */
/**
* Get the list of XFS-style Extended Attributes xattr which is associated
* with the node.
* The resulting data may finally be disposed by a call to this function
* with flag bit15 set, or its components may be freed one-by-one.
* The following values are either NULL or malloc() memory:
* *names, *value_lengths, *values, (*names)[i], (*values)[i]
* with 0 <= i < *num_attrs.
* It is allowed to replace or reallocate those memory items in order to
* to manipulate the attribute list before submitting it to other calls.
*
* If enabled by flag bit0, this list possibly includes the ACLs of the node.
* They are eventually encoded in a pair with empty name. It is not advisable
* to alter the value or name of that pair. One may decide to erase both ACLs
* by deleting this pair or to copy both ACLs by copying the content of this
* pair to an empty named pair of another node.
* For all other ACL purposes use iso_node_get_acl_text().
*
* @param node
* The node that is to be manipulated.
* @param num_attrs
* Will return the number of name-value pairs
* @param names
* Will return an array of pointers to 0-terminated names
* @param value_lengths
* Will return an arry with the lenghts of values
* @param values
* Will return an array of pointers to 8-bit values
* @param flag
* Bitfield for control purposes
* bit0= obtain eventual ACLs as attribute with empty name
* bit15= free memory
* @return
* 1 = ok (but *num_attrs may be 0)
* < 0 = error
*
* @since 0.6.14
*/
int iso_node_get_attrs(IsoNode *node, size_t *num_attrs,
char ***names, size_t **value_lengths, char ***values, int flag);
/* ts A90131 */
/**
* Set the list of XFS-style Extended Attributes xattr which is associated
* with the node.
* The data get copied so that you may dispose your input data afterwards.
*
* If enabled by flag bit0 then the submitted list of attributes will not only
* overwrite xattr but also both eventual ACLs of the node. Eventual ACL in
* the submitted list have to reside in an attribute with empty name.
*
* @param node
* The node that is to be manipulated.
* @param num_attrs
* Number of attributes
* @param names
* Array of pointers to 0 terminated name strings
* @param value_lengths
* Array of byte lengths for each value
* @param values
* Array of pointers to the value bytes
* @param flag
* Bitfield for control purposes
* bit0= Do not maintain eventual existing ACL of the node.
* Set eventual new ACL from value of empty name.
* @return
* 1 = ok
* < 0 = error
*
* @since 0.6.14
*/
int iso_node_set_attrs(IsoNode *node, size_t num_attrs, char **names,
size_t *value_lengths, char **values, int flag);
/* -------- This is an interface to the ACL of the local filesystem -------- */ /* -------- This is an interface to the ACL of the local filesystem -------- */
/** /**
@ -4377,4 +4472,72 @@ int iso_local_get_acl_text(char *disk_path, char **text, int flag);
int iso_local_set_acl_text(char *disk_path, char *text, int flag); int iso_local_set_acl_text(char *disk_path, char *text, int flag);
/* ts A90131 */
/**
* Get xattr and non-trivial ACLs of the given file in the local filesystem.
* The resulting data has finally to be disposed by a call to this function
* with flag bit15 set.
*
* Eventual ACLs will get encoded as attribute pair with empty name if this is
* enabled by flag bit0. An ACL which simply replects stat(2) permissions
* will not be put into the result.
*
* @param disk_path
* Path to the file
* @param num_attrs
* Will return the number of name-value pairs
* @param names
* Will return an array of pointers to 0-terminated names
* @param value_lengths
* Will return an arry with the lenghts of values
* @param values
* Will return an array of pointers to 8-bit values
* @param flag
* Bitfield for control purposes
* bit0= obtain eventual ACLs as attribute with empty name
* bit2= do not obtain attributes other than ACLs
* bit3= do not ignore eventual xattr representing ACL in local format
* (e.g. name "system.posix_acl_access")
* bit15= free memory
* @return
* 1 ok
* < 0 failure
*
* @since 0.6.14
*/
int iso_local_get_attrs(char *disk_path, size_t *num_attrs, char ***names,
size_t **value_lengths, char ***values, int flag);
/* ts A90131 */
/**
* Attach a list of xattr and ACLs to the given file in the local filesystem.
*
* Eventual ACLs have to be encoded as attribute pair with empty name.
*
* @param disk_path
* Path to the file
* @param num_attrs
* Number of attributes
* @param names
* Array of pointers to 0 terminated name strings
* @param value_lengths
* Array of byte lengths for each attribute payload
* @param values
* Array of pointers to the attribute payload bytes
* @param flag
* Bitfield for control purposes
* bit0= do not attach ACLs from an eventual attribute with empty name
* bit3= do not ignore eventual xattr representing ACL in local format
* (e.g. name "system.posix_acl_access")
* @return
* 1 = ok
* < 0 = error
*
* @since 0.6.14
*/
int iso_local_set_attrs(char *disk_path, size_t num_attrs, char **names,
size_t *value_lengths, char **values, int flag);
#endif /*LIBISO_LIBISOFS_H_*/ #endif /*LIBISO_LIBISOFS_H_*/

View File

@ -1352,11 +1352,33 @@ int iso_node_new_special(char *name, mode_t mode, dev_t dev,
} }
/* ts A90116 */ /* ts A90202 */
/* >>> describe static
int attrs_cleanout_name(char *del_name, size_t *num_attrs, char **names,
size_t *value_lengths, char **values, int flag)
{
size_t i, w;
@param flag bit15 = free memory for (w = i = 0; i < *num_attrs; i++) {
*/ if (strcmp(names[i], del_name) == 0)
continue;
if (w == i) {
w++;
continue;
}
names[w] = names[i];
value_lengths[w] = value_lengths[i];
values[w] = values[i];
names[i] = values[i] = NULL;
value_lengths[i] = 0;
w++;
}
*num_attrs = w;
return 1;
}
/* ts A90116 */
int iso_node_get_attrs(IsoNode *node, size_t *num_attrs, int iso_node_get_attrs(IsoNode *node, size_t *num_attrs,
char ***names, size_t **value_lengths, char ***values, int flag) char ***names, size_t **value_lengths, char ***values, int flag)
{ {
@ -1407,17 +1429,22 @@ int iso_node_get_attrs(IsoNode *node, size_t *num_attrs,
return ISO_AAIP_BAD_AASTRING; return ISO_AAIP_BAD_AASTRING;
} }
if(rpt - aa_string != len) { if (rpt - aa_string != len) {
/* aaip_decode_attrs() returns 2 but still bytes are left */ /* aaip_decode_attrs() returns 2 but still bytes are left */
return ISO_AAIP_BAD_AASTRING; return ISO_AAIP_BAD_AASTRING;
} }
ret = aaip_get_decoded_attrs(&aaip, num_attrs, names, ret = aaip_get_decoded_attrs(&aaip, num_attrs, names,
value_lengths, values, 0); value_lengths, values, 0);
if(ret != 1) { if (ret != 1) {
/* aaip_get_decoded_attrs() failed */ /* aaip_get_decoded_attrs() failed */
return ISO_AAIP_BAD_AASTRING; return ISO_AAIP_BAD_AASTRING;
} }
if (!(flag & 1)) {
/* Clean out eventual ACL attribute */
attrs_cleanout_name("", num_attrs, *names, *value_lengths, *values, 0);
}
#else /* Libisofs_with_aaiP */ #else /* Libisofs_with_aaiP */
@ -1442,11 +1469,20 @@ int iso_node_set_attrs(IsoNode *node, size_t num_attrs, char **names,
int ret; int ret;
size_t sret, result_len; size_t sret, result_len;
unsigned char *result; unsigned char *result;
char *a_acl= NULL, *d_acl= NULL;
if (!(flag & 1))
iso_node_get_acl_text(node, &a_acl, &d_acl, 16);
if (num_attrs == 0) { if (num_attrs == 0) {
ret = iso_node_remove_xinfo(node, aaip_xinfo_func); ret = iso_node_remove_xinfo(node, aaip_xinfo_func);
if (ret < 0) if (ret < 0)
return ret; return ret;
if (!(flag & 1)) {
ret = iso_node_set_acl_text(node, a_acl, d_acl, 0);
if (ret < 0)
return ret;
}
return 1; return 1;
} }
sret = aaip_encode(num_attrs, names, value_lengths, values, sret = aaip_encode(num_attrs, names, value_lengths, values,
@ -1466,6 +1502,11 @@ int iso_node_set_attrs(IsoNode *node, size_t num_attrs, char **names,
return ISO_ERROR; return ISO_ERROR;
} }
if (!(flag & 1)) {
ret = iso_node_set_acl_text(node, a_acl, d_acl, 0);
if (ret < 0)
return ret;
}
return 1; return 1;
#else /* Libisofs_with_aaiP */ #else /* Libisofs_with_aaiP */
@ -1786,33 +1827,98 @@ bad_decode:;
} }
/* ts A90118 */
int iso_local_set_acl_text(char *disk_path, char *text, int flag)
{
#ifdef Libisofs_with_aaiP
return aaip_set_acl_text(disk_path, text, flag & 1);
#else /* Libisofs_with_aaiP */
return 0;
#endif /* ! Libisofs_with_aaiP */
}
/* ts A90127 */ /* ts A90127 */
int iso_local_get_acl_text(char *disk_path, char **text, int flag) int iso_local_get_acl_text(char *disk_path, char **text, int flag)
{ {
#ifdef Libisofs_with_aaiP #ifdef Libisofs_with_aaiP
return aaip_get_acl_text(disk_path, text, flag & (1 | 16 | (1 << 15))); int ret;
ret = aaip_get_acl_text(disk_path, text, flag & (1 | 16 | (1 << 15)));
if (ret < 0)
return ISO_AAIP_NO_GET_LOCAL;
return ret;
#else /* Libisofs_with_aaiP */ #else /* Libisofs_with_aaiP */
return 0; return 0;
#endif /* ! Libisofs_with_aaiP */
}
/* ts A90118 */
int iso_local_set_acl_text(char *disk_path, char *text, int flag)
{
#ifdef Libisofs_with_aaiP
int ret;
ret = aaip_set_acl_text(disk_path, text, flag & 1);
if (ret < 0)
return ISO_AAIP_NO_SET_LOCAL;
return ret;
#else /* Libisofs_with_aaiP */
return 0;
#endif /* ! Libisofs_with_aaiP */
}
/* ts A90131 */
int iso_local_get_attrs(char *disk_path, size_t *num_attrs, char ***names,
size_t **value_lengths, char ***values, int flag)
{
#ifdef Libisofs_with_aaiP
int ret;
ret = aaip_get_attr_list(disk_path,
num_attrs, names, value_lengths, values,
(flag & (1 | 4 | 8 | (1 << 15))) | 2 | 16);
if (ret <= 0)
return ISO_AAIP_NO_GET_LOCAL;
return 1;
#else /* Libisofs_with_aaiP */
*num_attrs = 0;
*names = NULL;
*value_lengths = NULL;
*values = NULL;
return 1;
#endif /* ! Libisofs_with_aaiP */
}
/* ts A90131 */
int iso_local_set_attrs(char *disk_path, size_t num_attrs, char **names,
size_t *value_lengths, char **values, int flag)
{
#ifdef Libisofs_with_aaiP
int ret;
ret = aaip_set_attr_list(disk_path, num_attrs, names, value_lengths,
values, (flag & 8) | !(flag & 1));
if (ret <= 0)
return ISO_AAIP_NO_SET_LOCAL;
return 1;
#else /* Libisofs_with_aaiP */
if (num_attrs > 0)
return ISO_AAIP_NOT_ENABLED;
return 1;
#endif /* ! Libisofs_with_aaiP */ #endif /* ! Libisofs_with_aaiP */