New options -xattr, -getfattr, find -has_xattr, -has_aaip, -exec getfattr

This commit is contained in:
2009-02-02 13:44:00 +00:00
parent 4ceee394f7
commit f861321c45
6 changed files with 329 additions and 205 deletions

View File

@ -173,11 +173,6 @@ LIBISOBURN_MISCONFIGURATION_ = 0;
/* End of ugly compile time test (scroll up for explanation) */
#ifdef NIX
sprintf(xorriso->info_text, "Starting up libraries ...\n");
Xorriso_info(xorriso, 0);
#endif
handler_prefix= calloc(strlen(xorriso->progname)+3+1, 1);
if(handler_prefix==NULL) {
sprintf(xorriso->info_text,
@ -236,12 +231,6 @@ LIBISOBURN_MISCONFIGURATION_ = 0;
sprintf(xorriso->info_text, "%s", reason);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
}
#ifdef NIX
sprintf(xorriso->info_text, "Library startup done.\n");
Xorriso_info(xorriso, 0);
#endif
free(handler_prefix);
return(1);
}
@ -1151,11 +1140,7 @@ int Xorriso_write_session(struct XorrisO *xorriso, int flag)
Xorriso_process_msg_queues(xorriso, 0);
return(ret);
}
#ifdef NIX
relax= isoburn_igopt_allow_deep_paths;
#else
relax= xorriso->relax_compliance;
#endif
xorriso->alignment= 0;
image= isoburn_get_attached_image(source_drive);
@ -1202,19 +1187,6 @@ int Xorriso_write_session(struct XorrisO *xorriso, int flag)
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
{ret= 0; goto ex;}
}
#ifdef NIX
#ifdef Xorriso_with_make_isohybrid_mbR
/* ??? must the boot image have a low LBA to boot from MBR ? */
/* A81110: Does not look so. The proplems were caused by wrong
self-LBA in isolinux.bin at byte 12 to 15 */
isoburn_igopt_set_sort_files(sopts, isoburn_igopt_sort_files_by_weight);
iso_node_set_sort_weight(node, 0x7fffffff);
#endif
#endif /* NIX */
ret= Xorriso_node_from_path(xorriso, image, xorriso->boot_image_cat_path,
&node, 1);
if(ret > 0) {
@ -1458,17 +1430,8 @@ ex:;
Xorriso_set_abort_severity(xorriso, 0);
if(ret<=0) {
/* >>> ??? revive discarded boot image */;
#ifdef NIX
/* <<< this was probably not a good idea */
} else if(xorriso->boot_image_bin_path[0]) {
xorriso->keep_boot_image= 1;
xorriso->patch_isolinux_image= 1;
xorriso->boot_image_bin_path[0]= 0;
sprintf(xorriso->info_text, "Switched to -boot_image isolinux patch");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
#endif /* NIX */
/* >>> ??? revive discarded boot image */;
}
if(disc!=NULL)
@ -2014,15 +1977,15 @@ int Xorriso_iso_lstat(struct XorrisO *xorriso, char *path, struct stat *stbuf,
/* @param flag bit0= give directory x-permission where is r-permission
bit1= do not transfer ACL
bit2= transfer ACL even if NULL
bit1= do not transfer ACL or xattr
*/
int Xorriso_transfer_properties(struct XorrisO *xorriso, struct stat *stbuf,
char *disk_path, IsoNode *node, int flag)
{
mode_t mode;
int a_ret= 0, d_ret= 0;
char *default_text= NULL, *access_text= NULL;
int ret= 1;
size_t num_attrs= 0, *value_lengths= NULL;
char **names= NULL, **values= NULL;
mode= stbuf->st_mode;
if((flag&1) && S_ISDIR(mode)) {
@ -2040,18 +2003,34 @@ int Xorriso_transfer_properties(struct XorrisO *xorriso, struct stat *stbuf,
iso_node_set_mtime(node, stbuf->st_mtime);
iso_node_set_ctime(node, stbuf->st_ctime);
if((xorriso->do_aaip & 1) && !(flag & 2)) {
a_ret= iso_local_get_acl_text(disk_path, &access_text, 16);
if(S_ISDIR(stbuf->st_mode) && a_ret >= 0)
d_ret= iso_local_get_acl_text(disk_path, &default_text, 1);
if(access_text != NULL || default_text != NULL || (flag & 4))
a_ret= iso_node_set_acl_text(node, access_text, default_text, 0);
if(access_text != NULL)
iso_local_get_acl_text(disk_path, &access_text, 1 << 15);
if(default_text != NULL)
iso_local_get_acl_text(disk_path, &default_text, 1 << 15);
if(flag & 2)
{ret= 1; goto ex;}
if(xorriso->do_aaip & 5) {
ret= iso_local_get_attrs(disk_path, &num_attrs, &names, &value_lengths,
&values, ((xorriso->do_aaip & 1) && !(flag & 2))
| (!(xorriso->do_aaip & 4)) << 4);
if(ret < 0) {
Xorriso_process_msg_queues(xorriso,0);
Xorriso_report_iso_error(xorriso, disk_path, ret,
"Error when obtaining local ACL and xattr", 0,
"FAILURE", 1 | 2);
ret= 0; goto ex;
}
ret= iso_node_set_attrs(node, num_attrs, names, value_lengths, values, 0);
if(ret < 0) {
Xorriso_process_msg_queues(xorriso,0);
Xorriso_report_iso_error(xorriso, "", ret,
"Error when obtaining local ACL and xattr", 0,
"FAILURE", 1);
ret= 0; goto ex;
}
ret= 1;
}
return(a_ret >= 0 && d_ret >= 0);
ex:;
iso_local_get_attrs(disk_path, &num_attrs, &names, &value_lengths,
&values, 1 << 15); /* free memory */
return(ret);
}
@ -2495,7 +2474,7 @@ int Xorriso_copy_properties(struct XorrisO *xorriso,
return(0);
}
Xorriso_transfer_properties(xorriso, &stbuf, disk_path, node,
4 | ((flag & 2) >> 1) | (((stbuf.st_mode & S_IFMT) == S_IFLNK) << 1));
((flag & 2) >> 1) | (((stbuf.st_mode & S_IFMT) == S_IFLNK) << 1));
xorriso->volset_change_pending= 1;
return(1);
}
@ -2924,6 +2903,9 @@ int Xorriso_restore_properties(struct XorrisO *xorriso, char *disk_path,
#ifdef Xorriso_with_aaiP
if(xorriso->do_aaip & 2) {
/* >>> change to iso_node_get_attrs */;
ret= iso_node_get_acl_text(node, &access_text, &default_text, 16);
if(ret < 0) {
strcpy(xorriso->info_text, "Error with obtaining ACL for ");
@ -2931,6 +2913,9 @@ int Xorriso_restore_properties(struct XorrisO *xorriso, char *disk_path,
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
{ret= 0; goto ex;}
}
/* >>> change to iso_node_set_attrs */;
if(access_text != NULL) {
ret= iso_local_set_acl_text(disk_path, access_text, 0);
if(ret == -1) {
@ -6499,6 +6484,8 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
} else if(action == 25) {
if(target == NULL || target[0] || text_2 == NULL || text_2[0])
ret= Xorriso_setfacl(xorriso, (void *) node, show_path, target, text_2,0);
} else if(action == 26) {
ret= Xorriso_getfattr(xorriso, (void *) node, show_path, 0);
} else { /* includes : 15 in_iso */
sprintf(xorriso->result_line, "%s\n", Text_shellsafe(show_path, sfe, 0));
Xorriso_result(xorriso, 0);
@ -6519,7 +6506,7 @@ int Xorriso_findi_test(struct XorrisO *xorriso, struct FindjoB *job,
struct stat *boss_stbuf, struct stat *stbuf,
int depth, int flag)
{
int ret, start_lba, end_lba, damage_filter, commit_filter, lba, acl_filter;
int ret, start_lba, end_lba, damage_filter, commit_filter, lba, a_filter;
off_t damage_start, damage_end, size;
int lba_count, *file_end_lbas= NULL, *file_start_lbas= NULL, i;
void *wanted_node;
@ -6556,18 +6543,49 @@ int Xorriso_findi_test(struct XorrisO *xorriso, struct FindjoB *job,
if(ret > 0 && lba >= 0)
{ret= 0; goto ex;}
}
Findjob_get_acl_filter(job, &acl_filter, 0);
if(acl_filter) {
Findjob_get_acl_filter(job, &a_filter, 0);
if(a_filter) {
ret = Xorriso_getfacl(xorriso, (void *) node, "", NULL, 2);
if(ret <= 0) {
Xorriso_process_msg_queues(xorriso, 0);
goto ex;
}
if(acl_filter < 0 && ret != 2)
if(a_filter < 0 && ret != 2)
{ret= 0; goto ex;}
if(acl_filter > 0 && ret == 2)
if(a_filter > 0 && ret == 2)
{ret= 0; goto ex;}
}
Findjob_get_xattr_filter(job, &a_filter, 0);
if(a_filter) {
ret = Xorriso_getfattr(xorriso, (void *) node, "", 2);
if(ret < 0) {
Xorriso_process_msg_queues(xorriso, 0);
goto ex;
}
if(a_filter < 0 && ret > 0)
{ret= 0; goto ex;}
if(a_filter > 0 && ret == 0)
{ret= 0; goto ex;}
}
Findjob_get_aaip_filter(job, &a_filter, 0);
if(a_filter) {
#ifdef Xorriso_with_aaiP
{ void *xinfo_dummy;
ret= iso_node_get_xinfo(node, aaip_xinfo_func, &xinfo_dummy);
}
#else
ret= 0;
#endif
if(ret < 0) {
Xorriso_process_msg_queues(xorriso, 0);
goto ex;
}
if(a_filter < 0 && ret == 1)
{ret= 0; goto ex;}
if(a_filter > 0 && ret != 1)
{ret= 0; goto ex;}
}
Findjob_get_wanted_node(job, &wanted_node, 0);
if(wanted_node != NULL && ((IsoNode *) wanted_node) != node)
{ret= 0; goto ex;}
@ -6851,56 +6869,6 @@ int Xorriso_get_volid(struct XorrisO *xorriso, char volid[33], int flag)
}
#ifdef NIX
/* @param flag bit0= do not mark image as changed */
int Xorriso_set_publisher(struct XorrisO *xorriso, char *name, int flag)
{
int ret;
IsoImage *volume;
if(xorriso->in_volset_handle == NULL)
return(2);
ret= Xorriso_get_volume(xorriso, &volume, 0);
if(ret<=0)
return(ret);
iso_image_set_publisher_id(volume, name);
if(!(flag&1))
xorriso->volset_change_pending= 1;
Xorriso_process_msg_queues(xorriso,0);
sprintf(xorriso->info_text,"Publisher: '%s'",
iso_image_get_publisher_id(volume));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
return(1);
}
/* @param flag bit0= do not mark image as changed */
int Xorriso_set_application_id(struct XorrisO *xorriso, char *name, int flag)
{
int ret;
IsoImage *volume;
if(xorriso->in_volset_handle == NULL)
return(2);
ret= Xorriso_get_volume(xorriso, &volume, 0);
if(ret<=0)
return(ret);
iso_image_set_application_id(volume, name);
if(!(flag&1))
xorriso->volset_change_pending= 1;
Xorriso_process_msg_queues(xorriso,0);
sprintf(xorriso->info_text,"Application id: '%s'",
iso_image_get_application_id(volume));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
return(1);
}
#endif /* NIX */
/* @param flag bit0=prepare for a burn run */
int Xorriso_set_abort_severity(struct XorrisO *xorriso, int flag)
{
@ -8813,6 +8781,34 @@ ok:;
}
/*
@param flag bit0= do not remove leading slash
*/
int Xorriso_getfname(struct XorrisO *xorriso, char *path, int flag)
{
int ret, path_offset= 0, bsl_mem;
char *bsl_path= NULL;
if(path[0] == '/' && !(flag & 1))
path_offset= 1;
/* backslash escaped path rather than shellsafe path */
ret= Sfile_bsl_encoder(&bsl_path, path + path_offset,
strlen(path + path_offset), 8);
if(ret <= 0)
return(-1);
sprintf(xorriso->result_line, "# file: %s\n", bsl_path);
free(bsl_path);
bsl_path= NULL;
/* temporarily disable -backslash_codes with result output */
bsl_mem= xorriso->bsl_interpretation;
xorriso->bsl_interpretation= 0;
Xorriso_result(xorriso, 0);
xorriso->bsl_interpretation= bsl_mem;
return(1);
}
/* @param node Opaque handle to IsoNode which is to be inquired instead of path if it is not NULL.
@param path is used as address if node is NULL.
@param acl_text if acl_text is not NULL, then *acl_text will be set to the
@ -8828,15 +8824,14 @@ ok:;
int Xorriso_getfacl(struct XorrisO *xorriso, void *in_node, char *path,
char **acl_text, int flag)
{
int ret, d_ret, path_offset= 0, result_len= 0, pass, bsl_mem;
int ret, d_ret, result_len= 0, pass;
IsoNode *node;
char *text= NULL, *d_text= NULL, *cpt, *npt, *bsl_path= NULL;
char *text= NULL, *d_text= NULL, *cpt, *npt;
uid_t uid;
gid_t gid;
struct passwd *pwd;
struct group *grp;
node= (IsoNode *) in_node;
if(node == NULL) {
ret= Xorriso_get_node_by_path(xorriso, path, NULL, &node, 0);
@ -8881,22 +8876,9 @@ int Xorriso_getfacl(struct XorrisO *xorriso, void *in_node, char *path,
}
if(!(flag & 1)) {
if(path[0] == '/' && !(flag & 2))
path_offset= 1;
/* backslash escaped path rather than shellsafe path */
ret= Sfile_bsl_encoder(&bsl_path, path + path_offset, 8);
ret= Xorriso_getfname(xorriso, path, 0);
if(ret <= 0)
{ret= -1; goto ex;}
sprintf(xorriso->result_line, "# file: %s\n", bsl_path);
free(bsl_path);
bsl_path= NULL;
/* temporarily disable -backslash_codes with result output */
bsl_mem= xorriso->bsl_interpretation;
xorriso->bsl_interpretation= 0;
Xorriso_result(xorriso, 0);
xorriso->bsl_interpretation= bsl_mem;
goto ex;
uid= iso_node_get_uid(node);
pwd= getpwuid(uid);
if(pwd == NULL)
@ -8963,8 +8945,6 @@ int Xorriso_getfacl(struct XorrisO *xorriso, void *in_node, char *path,
ret= 1;
ex:;
iso_node_get_acl_text(node, &text, &d_text, 1 << 15);
if(bsl_path != NULL)
free(bsl_path);
return(ret);
}
@ -9025,3 +9005,77 @@ ex:;
return(ret);
}
/*
@param flag
>>> bit1= check for existence of non-ACL xattr,
return 0 or 1
*/
int Xorriso_getfattr(struct XorrisO *xorriso, void *in_node, char *path,
int flag)
{
int ret= 1, i, bsl_mem;
size_t num_attrs= 0, *value_lengths= NULL;
char **names= NULL, **values= NULL, *bsl;
IsoNode *node;
node= (IsoNode *) in_node;
if(node == NULL) {
ret= Xorriso_get_node_by_path(xorriso, path, NULL, &node, 0);
if(ret<=0)
goto ex;
}
#ifdef Xorriso_with_aaiP
ret= iso_node_get_attrs(node, &num_attrs, &names, &value_lengths,
&values, 0);
#else
ret= 1;
#endif
if(ret < 0) {
strcpy(xorriso->info_text, "Error with obtaining xattr of ");
Text_shellsafe(path, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
}
if(flag & 2) {
ret= (num_attrs > 0);
goto ex;
}
if(num_attrs == 0)
{ret= 2; goto ex;}
ret= Xorriso_getfname(xorriso, path, 0);
if(ret <= 0)
goto ex;
for(i= 0; i < num_attrs; i++) {
if(strlen(names[i]) + value_lengths[i] >= SfileadrL) {
sprintf(xorriso->result_line, "# oversized: name %d , value %d bytes\n",
(int) strlen(names[i]), (int) value_lengths[i]);
} else {
ret= Sfile_bsl_encoder(&bsl, names[i], strlen(names[i]), 8);
if(ret <= 0)
{ret= -1; goto ex;}
strcpy(xorriso->result_line, bsl);
free(bsl);
ret= Sfile_bsl_encoder(&bsl, values[i], value_lengths[i], 8);
if(ret <= 0)
{ret= -1; goto ex;}
sprintf(xorriso->result_line + strlen(xorriso->result_line),
"=\"%s\"\n", bsl);
free(bsl);
}
/* temporarily disable -backslash_codes with result output */
bsl_mem= xorriso->bsl_interpretation;
xorriso->bsl_interpretation= 0;
Xorriso_result(xorriso, 0);
xorriso->bsl_interpretation= bsl_mem;
}
strcpy(xorriso->result_line, "\n");
Xorriso_result(xorriso, 0);
ret= 1;
ex:;
iso_node_get_attrs(node, &num_attrs, &names, &value_lengths,
&values, 1 << 15); /* free memory */
return(ret);
}