Avoided double attempt to set lfa flag "i" to newly created directory

This commit is contained in:
Thomas Schmitt 2024-09-08 21:26:04 +02:00
parent b2ae46a4cf
commit 1ed76b7bdc
4 changed files with 89 additions and 20 deletions

View File

@ -1046,5 +1046,36 @@ int Permstack_pop(struct PermiteM **o, struct PermiteM *stopper,
} }
/* Look for stack item with disk_path
@return 0= nothing found, 1= *stbuf and *immutable are valid
*/
int Permstack_peek(struct PermiteM **o, struct PermiteM *stopper,
struct XorrisO *xorriso,
char *disk_path, struct stat **stbuf, int *immutable,
int flag)
{
struct PermiteM *m;
if((*o) == stopper)
return(0);
for(m= *o; m != NULL; m= m->next) {
if(strcmp(m->disk_path, disk_path) == 0) {
*stbuf= &(m->stbuf);
*immutable= m->immutable;
return(1);
}
if(m->next == stopper)
break;
}
if(m == NULL) {
sprintf(xorriso->info_text,
"Program error: Permstack_peek() : cannot find stopper");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
return(-1);
}
return(0);
}
/* ---------------------------- End PermstacK ----------------------------- */ /* ---------------------------- End PermstacK ----------------------------- */

View File

@ -180,6 +180,15 @@ int Permstack_push(struct PermiteM **o, char *disk_path, struct stat *stbuf,
int Permstack_pop(struct PermiteM **o, struct PermiteM *stopper, int Permstack_pop(struct PermiteM **o, struct PermiteM *stopper,
struct XorrisO *xorriso, int flag); struct XorrisO *xorriso, int flag);
/* Look for stack item with disk_path
@param immutable bit0= when popping: set chattr immutable bit
bit1= when popping: only set immutable bit
@return 0= nothing found, 1= *stbuf and *immutable are valid
*/
int Permstack_peek(struct PermiteM **o, struct PermiteM *stopper,
struct XorrisO *xorriso,
char *disk_path, struct stat **stbuf, int *immutable,
int flag);
#endif /* ! Xorriso_pvt_auxobj_includeD */ #endif /* ! Xorriso_pvt_auxobj_includeD */

View File

@ -529,18 +529,39 @@ int Xorriso_early_chattr_CF(struct XorrisO *xorriso, IsoNode *node,
} }
int Xorriso_restore_timestamps(struct XorrisO *xorriso, char *disk_path,
IsoNode *node, int flag)
{
int ret;
struct utimbuf utime_buffer;
utime_buffer.actime= iso_node_get_atime(node);
utime_buffer.modtime= iso_node_get_mtime(node);
ret= utime(disk_path, &utime_buffer);
if(ret == -1) {
sprintf(xorriso->info_text,
"Cannot change atime, mtime of disk file ");
Text_shellsafe(disk_path, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
return(0);
}
return(1);
}
/* @param flag bit0= minimal transfer: access permissions only /* @param flag bit0= minimal transfer: access permissions only
bit1= keep directory open: keep owner, allow rwx for owner bit1= keep directory open: keep owner, allow rwx for owner
and push directory onto xorriso->perm_stack and push directory onto xorriso->perm_stack
@return 1=ok , 2=ok, lfa "i" pushed to permstack, <=0 error
*/ */
int Xorriso_restore_properties(struct XorrisO *xorriso, char *disk_path, int Xorriso_restore_properties(struct XorrisO *xorriso, char *disk_path,
IsoNode *node, int flag) IsoNode *node, int flag)
{ {
int ret, is_dir= 0, errno_copy= 0, local_attrs_set= 0, i, err_count; int ret, is_dir= 0, errno_copy= 0, local_attrs_set= 0, i, err_count;
int lfa_i_pushed= 0;
mode_t mode; mode_t mode;
uid_t uid, disk_uid; uid_t uid, disk_uid;
gid_t gid, disk_gid; gid_t gid, disk_gid;
struct utimbuf utime_buffer;
struct stat stbuf; struct stat stbuf;
size_t num_attrs= 0, *value_lengths= NULL; size_t num_attrs= 0, *value_lengths= NULL;
char **names= NULL, **values= NULL; char **names= NULL, **values= NULL;
@ -669,6 +690,7 @@ cannot_set_xattr:;
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
{ret= -1; goto ex;} {ret= -1; goto ex;}
} }
lfa_i_pushed= !!(lfa_flags & push_mask & lfa_i);
mode|= S_IRUSR|S_IWUSR|S_IXUSR; mode|= S_IRUSR|S_IWUSR|S_IXUSR;
} }
ret= chmod(disk_path, mode); ret= chmod(disk_path, mode);
@ -684,16 +706,9 @@ cannot_set_perm:;
if(flag&1) if(flag&1)
{ret= 1; goto ex;} {ret= 1; goto ex;}
utime_buffer.actime= iso_node_get_atime(node); ret= Xorriso_restore_timestamps(xorriso, disk_path, node, 0);
utime_buffer.modtime= iso_node_get_mtime(node); if(ret <= 0)
ret= utime(disk_path,&utime_buffer); goto ex;
if(ret==-1) {
sprintf(xorriso->info_text,
"Cannot change atime, mtime of disk file ");
Text_shellsafe(disk_path, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
{ret= 0; goto ex;}
}
gid= iso_node_get_gid(node); gid= iso_node_get_gid(node);
if(!(S_ISDIR(stbuf.st_mode) && (flag&2))) if(!(S_ISDIR(stbuf.st_mode) && (flag&2)))
@ -736,7 +751,7 @@ cannot_set_perm:;
} }
} }
ret= 1; ret= 1 + !!lfa_i_pushed;
ex:; ex:;
iso_node_get_attrs(node, &num_attrs, &names, &value_lengths, &values,1 << 15); iso_node_get_attrs(node, &num_attrs, &names, &value_lengths, &values,1 << 15);
if(errnos != NULL) if(errnos != NULL)
@ -1938,6 +1953,8 @@ int Xorriso_restore_tree(struct XorrisO *xorriso, IsoDir *dir,
struct stat stbuf, disk_stbuf; struct stat stbuf, disk_stbuf;
int dir_create= 0, node_register= 0, do_node_count= 0, normal_mode= 0; int dir_create= 0, node_register= 0, do_node_count= 0, normal_mode= 0;
int target_was_no_dir, dir_is_new; int target_was_no_dir, dir_is_new;
struct stat *stack_stbufpt;
int lfa_i_pushed= 0, stack_immutable;
perm_stack_mem= xorriso->perm_stack; perm_stack_mem= xorriso->perm_stack;
switch((flag >> 7) & 3) { switch((flag >> 7) & 3) {
@ -2164,11 +2181,15 @@ much_too_long:;
} }
if(source_is_dir) { if(source_is_dir) {
/* Restore exact access permissions of directory */ /* Restore exact access permissions of directory */
hret= Permstack_peek(&(xorriso->perm_stack), perm_stack_mem, xorriso,
disk_path, &stack_stbufpt, &stack_immutable, 0);
if(hret == 1 && (stack_immutable & 1))
lfa_i_pushed= 1;
hret= Permstack_pop(&(xorriso->perm_stack), perm_stack_mem, xorriso, hret= Permstack_pop(&(xorriso->perm_stack), perm_stack_mem, xorriso,
!!(flag&64)); !!(flag&64));
if(hret<=0 && hret<ret) if(hret<=0 && hret<ret)
ret= hret; ret= hret;
if(dir_is_new && !dir_create) { if(dir_is_new && !(dir_create || lfa_i_pushed)) {
hret= Xorriso_restore_chattr_i(xorriso, node, disk_path, 0); hret= Xorriso_restore_chattr_i(xorriso, node, disk_path, 0);
if(hret <= 0 && hret < ret) if(hret <= 0 && hret < ret)
ret= hret; ret= hret;
@ -2250,6 +2271,8 @@ int Xorriso_restore(struct XorrisO *xorriso,
int leaf_is_split= 0, source_is_split= 0, new_dir_made= 0, no_props; int leaf_is_split= 0, source_is_split= 0, new_dir_made= 0, no_props;
struct stat stbuf; struct stat stbuf;
struct PermiteM *perm_stack_mem; struct PermiteM *perm_stack_mem;
struct stat *stack_stbufpt;
int lfa_i_pushed= 0, stack_immutable;
perm_stack_mem= xorriso->perm_stack; perm_stack_mem= xorriso->perm_stack;
@ -2420,7 +2443,7 @@ attach_source:;
} }
if(new_dir_made && !(flag&64)) { if(new_dir_made && !(flag&64)) {
/* set timestamps which Permstack_pop() will not set */ /* set timestamps which Permstack_pop() will not set */
ret= Xorriso_restore_properties(xorriso, disk_path, node, 2); ret= Xorriso_restore_timestamps(xorriso, disk_path, node, 0);
if(ret <= 0) { if(ret <= 0) {
hret= Xorriso_eval_problem_status(xorriso, ret, 1 | 2); hret= Xorriso_eval_problem_status(xorriso, ret, 1 | 2);
if(hret < 0) if(hret < 0)
@ -2455,16 +2478,22 @@ attach_source:;
/* Need to set any properties before possibly setting immutable bit. /* Need to set any properties before possibly setting immutable bit.
So pop earlier than normal. So pop earlier than normal.
*/ */
hret= Permstack_peek(&(xorriso->perm_stack), perm_stack_mem, xorriso,
disk_path, &stack_stbufpt, &stack_immutable, 0);
if(hret == 1 && (stack_immutable & 1))
lfa_i_pushed= 1;
hret= Permstack_pop(&(xorriso->perm_stack), perm_stack_mem, xorriso, hret= Permstack_pop(&(xorriso->perm_stack), perm_stack_mem, xorriso,
2 | !!(flag&64)); 2 | !!(flag&64));
if(hret <= 0 && hret < ret) if(hret <= 0 && hret < ret)
ret= hret; ret= hret;
if(!lfa_i_pushed) {
hret= Xorriso_restore_chattr_i(xorriso, node, disk_path, 0); hret= Xorriso_restore_chattr_i(xorriso, node, disk_path, 0);
if(hret <= 0 && hret < ret) if(hret <= 0 && hret < ret)
ret= hret; ret= hret;
if(ret <= 0) if(ret <= 0)
goto ex; goto ex;
} }
}
Xorriso_process_msg_queues(xorriso,0); Xorriso_process_msg_queues(xorriso,0);
ret= 1 + (is_dir && !leaf_is_split); ret= 1 + (is_dir && !leaf_is_split);

View File

@ -1 +1 @@
#define Xorriso_timestamP "2024.09.08.102135" #define Xorriso_timestamP "2024.09.08.192526"