Bug fixes and enhancements about "default" ACL

This commit is contained in:
Thomas Schmitt 2009-01-28 07:49:56 +00:00
parent b09a2101cd
commit 0b4e59ee1e
2 changed files with 115 additions and 48 deletions

View File

@ -1 +1 @@
#define Xorriso_timestamP "2009.01.27.121417"
#define Xorriso_timestamP "2009.01.28.074917"

View File

@ -2014,11 +2014,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
*/
int Xorriso_transfer_properties(struct XorrisO *xorriso, struct stat *stbuf,
IsoNode *node, int flag)
char *disk_path, IsoNode *node, int flag)
{
mode_t mode;
int a_ret= 0, d_ret= 0;
char *default_text= NULL, *access_text= NULL;
mode= stbuf->st_mode;
if((flag&1) && S_ISDIR(mode)) {
@ -2035,7 +2039,21 @@ int Xorriso_transfer_properties(struct XorrisO *xorriso, struct stat *stbuf,
iso_node_set_atime(node, stbuf->st_atime);
iso_node_set_mtime(node, stbuf->st_mtime);
iso_node_set_ctime(node, stbuf->st_ctime);
return(1);
if((xorriso->do_aaip & 1) && !(flag & 2)) {
a_ret= iso_local_get_acl_text(disk_path, &access_text, 16);
if(a_ret > 0 && (access_text != NULL || (flag & 4)))
a_ret= iso_node_set_acl_text(node, access_text, 0);
if(access_text != NULL)
iso_local_get_acl_text(disk_path, &access_text, 1 << 15);
if(S_ISDIR(stbuf->st_mode) && a_ret >= 0)
d_ret= iso_local_get_acl_text(disk_path, &default_text, 1);
if(d_ret > 0 && (default_text != NULL || (flag & 4)))
d_ret= iso_node_set_acl_text(node, default_text, 1);
if(default_text != NULL)
iso_local_get_acl_text(disk_path, &default_text, 1 << 15);
}
return(a_ret >= 0 && d_ret >= 0);
}
@ -2336,7 +2354,7 @@ cannot_lstat:;
ret= iso_tree_add_new_symlink(dir, img_name, link_target, &iso_symlink);
node= (IsoNode *) iso_symlink;
if(ret>0) {
ret= Xorriso_transfer_properties(xorriso, &stbuf, node, 0);
ret= Xorriso_transfer_properties(xorriso, &stbuf, srcpt, node, 2);
if(ret<=0)
goto was_problem;
} else {
@ -2446,7 +2464,7 @@ int Xorriso_copy_implicit_properties(struct XorrisO *xorriso, IsoDir *dir,
strcpy(nfd, "/");
if(stat(nfd, &stbuf)==-1)
return(0);
Xorriso_transfer_properties(xorriso, &stbuf, (IsoNode *) dir,
Xorriso_transfer_properties(xorriso, &stbuf, nfd, (IsoNode *) dir,
((flag&1) && d==0));
sprintf(xorriso->info_text,
"Copied properties for %s", Text_shellsafe(ni, sfe, 0));
@ -2471,9 +2489,15 @@ int Xorriso_copy_properties(struct XorrisO *xorriso,
ret= Xorriso_get_node_by_path(xorriso, img_path, NULL, &node, 0);
if(ret<=0)
return(ret);
if(lstat(disk_path, &stbuf)==-1)
return(0);
Xorriso_transfer_properties(xorriso, &stbuf, node, (flag&2)>>1);
if(flag & 1) {
if(stat(disk_path, &stbuf)==-1)
return(0);
} else {
if(lstat(disk_path, &stbuf)==-1)
return(0);
}
Xorriso_transfer_properties(xorriso, &stbuf, disk_path, node,
4 | ((flag & 2) >> 1) | (((stbuf.st_mode & S_IFMT) == S_IFLNK) << 1));
xorriso->volset_change_pending= 1;
return(1);
}
@ -2670,7 +2694,8 @@ attach_source:;
/* directory node was created above */;
} else if(is_dir) {
Xorriso_transfer_properties(xorriso, &stbuf, (IsoNode *) dir, 0);
Xorriso_transfer_properties(xorriso, &stbuf, disk_path,
(IsoNode *) dir, ((stbuf.st_mode & S_IFMT) == S_IFLNK) << 1);
if(!(flag&32)) {
ret= Xorriso_add_tree(xorriso, dir, img_path, disk_path, NULL,
flag&2);
@ -8790,9 +8815,9 @@ ok:;
int Xorriso_getfacl(struct XorrisO *xorriso, void *in_node, char *path,
char **acl_text, int flag)
{
int ret, path_offset= 0;
int ret, d_ret, path_offset= 0, result_len= 0, pass;
IsoNode *node;
char *text= NULL, *cpt, *npt;
char *text= NULL, *d_text= NULL, *cpt, *npt;
uid_t uid;
gid_t gid;
struct passwd *pwd;
@ -8808,11 +8833,14 @@ int Xorriso_getfacl(struct XorrisO *xorriso, void *in_node, char *path,
#ifdef Xorriso_with_aaiP
ret= iso_node_get_acl_text(node, &text, 0);
if(ret > 0 && LIBISO_ISDIR(node)) {
d_ret= iso_node_get_acl_text(node, &d_text, 1 | 16);
}
#else
ret= 0;
ret= d_ret= 0;
#endif
if(ret < 0) {
if(ret < 0 || d_ret < 0) {
if(path != NULL && path[0] != 0) {
strcpy(xorriso->info_text, "Error with obtaining ACL of ");
Text_shellsafe(path, xorriso->info_text, 1);
@ -8824,11 +8852,11 @@ int Xorriso_getfacl(struct XorrisO *xorriso, void *in_node, char *path,
ret= 1 + (ret != 1);
goto ex;
}
if(flag & 1) {
ret= 1 + (ret == 0);
goto ex;
}
if(ret == 0 || ret == 2) {
if(flag & 1) {
ret= 1 + (ret == 0);
goto ex;
}
#ifdef Xorriso_with_aaiP
strcpy(xorriso->info_text, "No ACL associated with ");
Text_shellsafe(path, xorriso->info_text, 1);
@ -8841,43 +8869,82 @@ int Xorriso_getfacl(struct XorrisO *xorriso, void *in_node, char *path,
{ret= 2; goto ex;}
}
if(path[0] == '/' && !(flag & 2))
path_offset= 1;
strcpy(xorriso->result_line, "# file: ");
Text_shellsafe(path + path_offset, xorriso->result_line, 1);
strcat(xorriso->result_line, "\n");
Xorriso_result(xorriso, 0);
uid= iso_node_get_uid(node);
pwd= getpwuid(uid);
if(pwd == NULL)
sprintf(xorriso->result_line, "# owner: %.f\n", (double) uid);
else
sprintf(xorriso->result_line, "# owner: %s\n", pwd->pw_name);
Xorriso_result(xorriso, 0);
gid= iso_node_get_gid(node);
grp= getgrgid(gid);
if(grp == NULL)
sprintf(xorriso->result_line, "# group: %.f\n", (double) gid);
else
sprintf(xorriso->result_line, "# group: %s\n", grp->gr_name);
Xorriso_result(xorriso, 0);
for(npt= cpt= text; npt != NULL; cpt= npt + 1) {
npt= strchr(cpt, '\n');
if(npt != NULL)
*npt= 0;
Sfile_str(xorriso->result_line, cpt, 0);
if(!(flag & 1)) {
if(path[0] == '/' && !(flag & 2))
path_offset= 1;
strcpy(xorriso->result_line, "# file: ");
Text_shellsafe(path + path_offset, xorriso->result_line, 1);
strcat(xorriso->result_line, "\n");
Xorriso_result(xorriso, 0);
uid= iso_node_get_uid(node);
pwd= getpwuid(uid);
if(pwd == NULL)
sprintf(xorriso->result_line, "# owner: %.f\n", (double) uid);
else
sprintf(xorriso->result_line, "# owner: %s\n", pwd->pw_name);
Xorriso_result(xorriso, 0);
gid= iso_node_get_gid(node);
grp= getgrgid(gid);
if(grp == NULL)
sprintf(xorriso->result_line, "# group: %.f\n", (double) gid);
else
sprintf(xorriso->result_line, "# group: %s\n", grp->gr_name);
Xorriso_result(xorriso, 0);
}
for(pass= 0; pass < 1 + (acl_text != NULL && !(flag & 2)); pass++) {
if(pass) {
*acl_text= calloc(result_len + 1, 1);
if(*acl_text == NULL) {
Xorriso_no_malloc_memory(xorriso, NULL, 0);
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(d_text != NULL) {
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);
} else {
Sfile_str(xorriso->result_line, "default:", 0);
Sfile_str(xorriso->result_line, cpt, 1);
result_len+= strlen(cpt) + 9;
}
} else
xorriso->result_line[0]= 0;
if(pass== 0 && !(flag & 1)) {
strcat(xorriso->result_line, "\n");
Xorriso_result(xorriso, 0);
}
}
}
}
ret= 1;
ex:;
if(acl_text != NULL && !(flag & 2))
*acl_text= text;
else if(text != NULL)
if(d_text != NULL)
free(d_text);
if(text != NULL)
free(text);
return(ret);
}