New -xattr mode "any" to process all xattr namespaces of local filesystem

This commit is contained in:
2017-10-23 12:08:16 +02:00
parent 25e24911d9
commit cbc5dbf496
14 changed files with 264 additions and 114 deletions

View File

@ -309,14 +309,15 @@ ex:;
int Xorriso_restore_properties(struct XorrisO *xorriso, char *disk_path,
IsoNode *node, int flag)
{
int ret, is_dir= 0, errno_copy= 0;
int ret, is_dir= 0, errno_copy= 0, local_attrs_set= 0, i, err_count;
mode_t mode;
uid_t uid;
gid_t gid;
uid_t uid, disk_uid;
gid_t gid, disk_gid;
struct utimbuf utime_buffer;
struct stat stbuf;
size_t num_attrs= 0, *value_lengths= NULL;
char **names= NULL, **values= NULL;
int *errnos= NULL;
ret= lstat(disk_path, &stbuf);
if(ret==-1) {
@ -326,7 +327,8 @@ int Xorriso_restore_properties(struct XorrisO *xorriso, char *disk_path,
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
{ret= 0; goto ex;}
}
uid= stbuf.st_uid;
disk_uid= uid= stbuf.st_uid;
disk_gid= stbuf.st_gid;
is_dir= S_ISDIR(stbuf.st_mode);
@ -342,22 +344,46 @@ int Xorriso_restore_properties(struct XorrisO *xorriso, char *disk_path,
{ret= 0; goto ex;}
}
if(num_attrs > 0) {
ret= iso_local_set_attrs(disk_path, num_attrs, names, value_lengths,
values, (!(xorriso->do_strict_acl & 1)) << 6);
Xorriso_alloc_meM(errnos, int, num_attrs);
ret= iso_local_set_attrs_errno(disk_path, num_attrs, names, value_lengths,
values, errnos,
((!(xorriso->do_strict_acl & 1)) << 6) |
((!!(xorriso->do_aaip & 1024)) << 3) );
if(ret < 0) {
cannot_set_xattr:;
errno_copy= errno;
if(ret != (int) ISO_AAIP_NO_SET_LOCAL)
errno_copy= 0;
Xorriso_report_iso_error(xorriso, "", ret,
"Error on iso_local_set_attrs",
0, "FAILURE", 1 | ((ret == -1)<<2) );
sprintf(xorriso->info_text,
"Cannot change ACL or xattr of disk file ");
sprintf(xorriso->info_text, "Disk file ");
Text_shellsafe(disk_path, xorriso->info_text, 1);
err_count= 0;
for(i= 0; (unsigned int) i < num_attrs; i++) {
if(errnos[i] == 0)
continue;
if(err_count >= 3) {
strcat(xorriso->info_text, " , and more");
break;
}
err_count++;
errno_copy= 0; /* Detail errno overrides final errno */
if(names[i][0] == 0)
sprintf(xorriso->info_text + strlen(xorriso->info_text), " , ACL ");
else
sprintf(xorriso->info_text + strlen(xorriso->info_text),
" , xattr %s ", names[i]);
if(errnos[i] < 0)
Text_shellsafe("Unknown error", xorriso->info_text, 1);
else
Text_shellsafe(strerror(errnos[i]), xorriso->info_text, 1);
}
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno_copy,
"FAILURE",0);
{ret= 0; goto ex;}
}
local_attrs_set= 1;
}
Xorriso_process_msg_queues(xorriso,0);
}
@ -381,6 +407,7 @@ int Xorriso_restore_properties(struct XorrisO *xorriso, char *disk_path,
}
ret= chmod(disk_path, mode);
if(ret==-1) {
cannot_set_perm:;
sprintf(xorriso->info_text,
"Cannot change access permissions of disk file ");
Text_shellsafe(disk_path, xorriso->info_text, 1);
@ -391,10 +418,6 @@ int Xorriso_restore_properties(struct XorrisO *xorriso, char *disk_path,
if(flag&1)
{ret= 1; goto ex;}
gid= iso_node_get_gid(node);
if(!(S_ISDIR(stbuf.st_mode) && (flag&2)))
uid= iso_node_get_uid(node);
ret= chown(disk_path, uid, gid); /* don't complain if it fails */
utime_buffer.actime= iso_node_get_atime(node);
utime_buffer.modtime= iso_node_get_mtime(node);
ret= utime(disk_path,&utime_buffer);
@ -405,9 +428,43 @@ int Xorriso_restore_properties(struct XorrisO *xorriso, char *disk_path,
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
{ret= 0; goto ex;}
}
gid= iso_node_get_gid(node);
if(!(S_ISDIR(stbuf.st_mode) && (flag&2)))
uid= iso_node_get_uid(node);
if(uid != disk_uid || gid != disk_gid) {
ret= chown(disk_path, uid, gid); /* don't complain if it fails */
/* Check whether xattr are still set and try to set them again if needed.
E.g. Linux 3.16 removes security.capability on chown(2).
*/
if(local_attrs_set && (xorriso->do_aaip & 1024)) {
ret= iso_local_set_attrs_errno(disk_path, num_attrs, names, value_lengths,
values, errnos,
1 | ((!!(xorriso->do_aaip & 1024)) << 3) |
128);
if(ret < 0)
goto cannot_set_xattr;
}
/* Check whether setuid or setgid bits got reset */
ret= lstat(disk_path, &stbuf);
if(ret != -1) {
if((mode ^ stbuf.st_mode) & (S_ISUID | S_ISGID)) {
ret= chmod(disk_path, mode);
if(ret==-1)
goto cannot_set_perm;
}
}
}
ret= 1;
ex:;
iso_node_get_attrs(node, &num_attrs, &names, &value_lengths, &values,1 << 15);
if(errnos != NULL)
free(errnos);
return(ret);
}