Took into respect ACL and xattr with -compare and -update
This commit is contained in:
@ -6506,7 +6506,7 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
|
||||
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);
|
||||
ret= Xorriso_getfattr(xorriso, (void *) node, show_path, NULL, 0);
|
||||
} else if(action == 27) {
|
||||
ret= Xorriso_path_setfattr(xorriso, (void *) node, show_path,
|
||||
target, strlen(text_2), text_2, 0);
|
||||
@ -6581,7 +6581,7 @@ int Xorriso_findi_test(struct XorrisO *xorriso, struct FindjoB *job,
|
||||
}
|
||||
Findjob_get_xattr_filter(job, &a_filter, 0);
|
||||
if(a_filter) {
|
||||
ret = Xorriso_getfattr(xorriso, (void *) node, "", 2);
|
||||
ret = Xorriso_getfattr(xorriso, (void *) node, "", NULL, 64);
|
||||
if(ret < 0) {
|
||||
Xorriso_process_msg_queues(xorriso, 0);
|
||||
goto ex;
|
||||
@ -8841,6 +8841,11 @@ int Xorriso_getfname(struct XorrisO *xorriso, char *path, int flag)
|
||||
@param flag bit0= do not report to result but only retrieve ACL text
|
||||
bit1= check for existence of true ACL (not fabricated),
|
||||
do not allocate and set acl_text but return 1 or 2
|
||||
bit2-3: what ALC to retrieve:
|
||||
0= "access" and "default", mark "default:"
|
||||
1= "access" only
|
||||
2= "default" only, do not mark "default:"
|
||||
bit4= get "access" ACL only if not trivial
|
||||
@return 2 ok, no ACL available, eventual *acl_text will be NULL
|
||||
1 ok, ACL available, eventual *acl_text stems from malloc()
|
||||
<=0 error
|
||||
@ -8848,7 +8853,7 @@ int Xorriso_getfname(struct XorrisO *xorriso, char *path, int flag)
|
||||
int Xorriso_getfacl(struct XorrisO *xorriso, void *in_node, char *path,
|
||||
char **acl_text, int flag)
|
||||
{
|
||||
int ret, d_ret, result_len= 0, pass;
|
||||
int ret, d_ret, result_len= 0, pass, what;
|
||||
IsoNode *node;
|
||||
char *text= NULL, *d_text= NULL, *cpt, *npt;
|
||||
uid_t uid;
|
||||
@ -8856,6 +8861,10 @@ int Xorriso_getfacl(struct XorrisO *xorriso, void *in_node, char *path,
|
||||
struct passwd *pwd;
|
||||
struct group *grp;
|
||||
|
||||
what= (flag >> 2) & 3;
|
||||
if(acl_text != NULL)
|
||||
*acl_text= NULL;
|
||||
|
||||
node= (IsoNode *) in_node;
|
||||
if(node == NULL) {
|
||||
ret= Xorriso_get_node_by_path(xorriso, path, NULL, &node, 0);
|
||||
@ -8864,7 +8873,7 @@ int Xorriso_getfacl(struct XorrisO *xorriso, void *in_node, char *path,
|
||||
}
|
||||
|
||||
#ifdef Xorriso_with_aaiP
|
||||
ret= iso_node_get_acl_text(node, &text, &d_text, 0);
|
||||
ret= iso_node_get_acl_text(node, &text, &d_text, flag & 16);
|
||||
d_ret= (d_text != NULL);
|
||||
#else
|
||||
ret= d_ret= 0;
|
||||
@ -8927,33 +8936,45 @@ int Xorriso_getfacl(struct XorrisO *xorriso, void *in_node, char *path,
|
||||
ret= -1; goto ex;
|
||||
}
|
||||
}
|
||||
for(npt= cpt= text; npt != NULL; cpt= npt + 1) {
|
||||
npt= strchr(cpt, '\n');
|
||||
if(npt != NULL)
|
||||
*npt= 0;
|
||||
if(*cpt == 0) {
|
||||
if(d_text != NULL || pass)
|
||||
continue;
|
||||
} else
|
||||
result_len+= strlen(cpt) + 1;
|
||||
if(pass) {
|
||||
sprintf(*acl_text + strlen(*acl_text), "%s\n", cpt);
|
||||
} else if(!(flag & 1)) {
|
||||
Sfile_str(xorriso->result_line, cpt, 0);
|
||||
strcat(xorriso->result_line, "\n");
|
||||
Xorriso_result(xorriso, 0);
|
||||
if(text != NULL && what <= 1) {
|
||||
for(npt= cpt= text; npt != NULL; cpt= npt + 1) {
|
||||
npt= strchr(cpt, '\n');
|
||||
if(npt != NULL)
|
||||
*npt= 0;
|
||||
if(*cpt == 0) {
|
||||
if(d_text != NULL || pass) {
|
||||
if(npt != NULL)
|
||||
*npt= '\n';
|
||||
continue;
|
||||
}
|
||||
} else
|
||||
result_len+= strlen(cpt) + 1;
|
||||
if(pass) {
|
||||
sprintf(*acl_text + strlen(*acl_text), "%s\n", cpt);
|
||||
} else if(!(flag & 1)) {
|
||||
Sfile_str(xorriso->result_line, cpt, 0);
|
||||
strcat(xorriso->result_line, "\n");
|
||||
Xorriso_result(xorriso, 0);
|
||||
}
|
||||
if(npt != NULL)
|
||||
*npt= '\n';
|
||||
}
|
||||
}
|
||||
if(d_text != NULL) {
|
||||
if(d_text != NULL && (what == 0 || what == 2)) {
|
||||
for(npt= cpt= d_text; npt != NULL; cpt= npt + 1) {
|
||||
npt= strchr(cpt, '\n');
|
||||
if(npt != NULL)
|
||||
*npt= 0;
|
||||
if(*cpt != 0) {
|
||||
if(pass) {
|
||||
sprintf(*acl_text + strlen(*acl_text), "default:%s\n", cpt);
|
||||
if(what == 0)
|
||||
sprintf(*acl_text + strlen(*acl_text), "default:%s\n", cpt);
|
||||
else
|
||||
sprintf(*acl_text + strlen(*acl_text), "%s\n", cpt);
|
||||
} else {
|
||||
Sfile_str(xorriso->result_line, "default:", 0);
|
||||
xorriso->result_line[0]= 0;
|
||||
if(what == 0)
|
||||
Sfile_str(xorriso->result_line, "default:", 0);
|
||||
Sfile_str(xorriso->result_line, cpt, 1);
|
||||
result_len+= strlen(cpt) + 9;
|
||||
}
|
||||
@ -8963,6 +8984,8 @@ int Xorriso_getfacl(struct XorrisO *xorriso, void *in_node, char *path,
|
||||
strcat(xorriso->result_line, "\n");
|
||||
Xorriso_result(xorriso, 0);
|
||||
}
|
||||
if(npt != NULL)
|
||||
*npt= '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -9029,78 +9052,91 @@ ex:;
|
||||
return(ret);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@param flag
|
||||
bit1= check for existence of non-ACL xattr,
|
||||
@param flag bit0= do not report to result but only retrieve attr text
|
||||
bit1= path is disk_path
|
||||
bit5= in case of symbolic link on disk: inquire link target
|
||||
bit6= check for existence of non-ACL xattr,
|
||||
return 0 or 1
|
||||
*/
|
||||
int Xorriso_getfattr(struct XorrisO *xorriso, void *in_node, char *path,
|
||||
int flag)
|
||||
char **attr_text, int flag)
|
||||
{
|
||||
int ret= 1, i, bsl_mem;
|
||||
int ret= 1, i, bsl_mem, result_len= 0, pass;
|
||||
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) {
|
||||
if(attr_text != NULL)
|
||||
*attr_text= NULL;
|
||||
ret= Xorriso_get_attrs(xorriso, in_node, path, &num_attrs, &names,
|
||||
&value_lengths, &values, flag & (2 | 32));
|
||||
if(ret <= 0)
|
||||
goto ex;
|
||||
if(flag & 64) {
|
||||
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;
|
||||
if(!(flag & 1)) {
|
||||
ret= Xorriso_getfname(xorriso, path, 0);
|
||||
if(ret <= 0)
|
||||
goto ex;
|
||||
}
|
||||
for(pass= 0; pass < 1 + (attr_text != NULL); pass++) {
|
||||
if(pass) {
|
||||
*attr_text= calloc(result_len + 1, 1);
|
||||
if(*attr_text == NULL) {
|
||||
Xorriso_no_malloc_memory(xorriso, NULL, 0);
|
||||
ret= -1; 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 */
|
||||
result_len+= strlen(xorriso->result_line);
|
||||
if(pass) {
|
||||
strcat(*attr_text, xorriso->result_line);
|
||||
} else if(!(flag & 1)) {
|
||||
bsl_mem= xorriso->bsl_interpretation;
|
||||
xorriso->bsl_interpretation= 0;
|
||||
Xorriso_result(xorriso, 0);
|
||||
xorriso->bsl_interpretation= bsl_mem;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!(flag & 1)) {
|
||||
strcpy(xorriso->result_line, "\n");
|
||||
Xorriso_result(xorriso, 0);
|
||||
}
|
||||
strcpy(xorriso->result_line, "\n");
|
||||
Xorriso_result(xorriso, 0);
|
||||
ret= 1;
|
||||
ex:;
|
||||
|
||||
#ifndef NIX
|
||||
Xorriso_get_attrs(xorriso, in_node, path, &num_attrs, &names,
|
||||
&value_lengths, &values, 1 << 15);
|
||||
#else /* NIX */
|
||||
iso_node_get_attrs(node, &num_attrs, &names, &value_lengths,
|
||||
&values, 1 << 15); /* free memory */
|
||||
#endif /* NIX */
|
||||
|
||||
return(ret);
|
||||
}
|
||||
|
||||
@ -9177,17 +9213,151 @@ ex:;
|
||||
int Xorriso_local_getfacl(struct XorrisO *xorriso, char *disk_path,
|
||||
char **text, int flag)
|
||||
{
|
||||
int ret;
|
||||
|
||||
#ifdef Xorriso_with_aaiP
|
||||
ret= iso_local_get_acl_text(disk_path, text,
|
||||
flag & (1 | 16 | 32 | (1 << 15)));
|
||||
Xorriso_process_msg_queues(xorriso,0);
|
||||
#else
|
||||
ret= 0;
|
||||
#endif
|
||||
|
||||
return(ret);
|
||||
int ret, skip= 0, colons= 0, countdown= 0;
|
||||
char *acl= NULL, *cpt, *wpt;
|
||||
|
||||
if(flag & (1 << 15)) {
|
||||
if(*text != NULL)
|
||||
free(*text);
|
||||
*text= NULL;
|
||||
return(1);
|
||||
}
|
||||
*text= NULL;
|
||||
ret= iso_local_get_acl_text(disk_path, &acl, flag & (1 | 16 | 32));
|
||||
Xorriso_process_msg_queues(xorriso,0);
|
||||
if(ret < 0 || ret == 2)
|
||||
return(ret);
|
||||
if(acl == NULL)
|
||||
return(0);
|
||||
*text= strdup(acl);
|
||||
iso_local_get_acl_text(disk_path, &acl, 1 << 15);
|
||||
if(*text == NULL) {
|
||||
Xorriso_no_malloc_memory(xorriso, NULL, 0);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/* Garbage collection about trailing remarks after 3 permission chars */
|
||||
wpt= *text;
|
||||
for(cpt= *text; *cpt; cpt++) {
|
||||
if(skip) {
|
||||
if(*cpt == '\n')
|
||||
skip= 0;
|
||||
else
|
||||
continue;
|
||||
}
|
||||
if(*cpt == ':' && !countdown) {
|
||||
colons++;
|
||||
if(colons == 2) {
|
||||
countdown= 4;
|
||||
colons= 0;
|
||||
}
|
||||
}
|
||||
if(countdown > 0) {
|
||||
countdown--;
|
||||
if(countdown == 0)
|
||||
skip= 1;
|
||||
}
|
||||
*wpt= *cpt;
|
||||
wpt++;
|
||||
}
|
||||
*wpt= 0;
|
||||
|
||||
return(1);
|
||||
#else
|
||||
|
||||
*text= NULL;
|
||||
return(0);
|
||||
|
||||
#endif /* ! Xorriso_with_aaiP */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@param flag
|
||||
bit1= path is disk_path
|
||||
bit5= in case of symbolic link on disk: inquire link target
|
||||
bit15= free memory
|
||||
*/
|
||||
int Xorriso_get_attrs(struct XorrisO *xorriso, void *in_node, char *path,
|
||||
size_t *num_attrs, char ***names,
|
||||
size_t **value_lengths, char ***values, int flag)
|
||||
{
|
||||
int ret, i, widx;
|
||||
IsoNode *node;
|
||||
|
||||
if(flag & (1 << 15)) {
|
||||
#ifdef Xorriso_with_aaiP
|
||||
if(flag & 2) {
|
||||
iso_local_get_attrs(NULL, num_attrs, names, value_lengths, values,
|
||||
1 << 15);
|
||||
} else {
|
||||
iso_node_get_attrs(NULL, num_attrs, names, value_lengths, values,
|
||||
1 << 15);
|
||||
}
|
||||
#endif /* Xorriso_with_aaiP */
|
||||
return(1);
|
||||
}
|
||||
|
||||
*num_attrs= 0;
|
||||
if(flag & 2) {
|
||||
|
||||
#ifdef Xorriso_with_aaiP
|
||||
ret= iso_local_get_attrs(path, num_attrs, names, value_lengths, values,
|
||||
flag & 32);
|
||||
if(ret < 0) {
|
||||
strcpy(xorriso->info_text, "Error with reading xattr of disk file ");
|
||||
Text_shellsafe(path, xorriso->info_text, 1);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
|
||||
}
|
||||
#endif /* Xorriso_with_aaiP */
|
||||
;
|
||||
|
||||
} else {
|
||||
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);
|
||||
if(ret < 0) {
|
||||
Xorriso_report_iso_error(xorriso, "", ret,
|
||||
"Error when obtaining xattr of ISO node", 0, "FAILURE", 1);
|
||||
goto ex;
|
||||
}
|
||||
#endif /* Xorriso_with_aaiP */
|
||||
|
||||
/* Filter away any non-userspace xattr */;
|
||||
widx= 0;
|
||||
for(i= 0; i < *num_attrs; i++) {
|
||||
if(strncmp((*names)[i], "user.", 5) != 0) {
|
||||
free((*names)[i]);
|
||||
(*names)[i]= NULL;
|
||||
if((*values)[i] != NULL) {
|
||||
free((*values)[i]);
|
||||
(*values)[i]= NULL;
|
||||
}
|
||||
} else {
|
||||
if(widx != i) {
|
||||
(*names)[widx]= (*names)[i];
|
||||
(*value_lengths)[widx]= (*value_lengths)[i];
|
||||
(*values)[widx]= (*values)[i];
|
||||
(*names)[i]= NULL;
|
||||
(*value_lengths)[i]= 0;
|
||||
(*values)[i]= NULL;
|
||||
}
|
||||
widx++;
|
||||
}
|
||||
}
|
||||
*num_attrs= widx;
|
||||
}
|
||||
ret= 1;
|
||||
ex:;
|
||||
Xorriso_process_msg_queues(xorriso,0);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user