Implemented option -chmod (does not get written into image, though)

This commit is contained in:
Thomas Schmitt 2007-11-07 19:18:31 +00:00
parent f46827aa62
commit aa0f876723
5 changed files with 200 additions and 45 deletions

View File

@ -1306,6 +1306,8 @@ char *Text_shellsafe(char *in_text, char *out_text, int flag)
out_text[w++]= '\'';
for(i=0;i<l;i++){
if(in_text[i]=='\''){
if(w+7>4*SfileadrL)
goto overflow;
/* escape hard quote within the text */
out_text[w++]= '\'';
out_text[w++]= '"';
@ -1313,6 +1315,11 @@ char *Text_shellsafe(char *in_text, char *out_text, int flag)
out_text[w++]= '"';
out_text[w++]= '\'';
} else {
if(w+3>4*SfileadrL) {
overflow:;
strncpy(out_text, "'xorriso: TEXT MUCH TOO LONG ... ",33);
break;
}
out_text[w++]= in_text[i];
}
}
@ -3415,14 +3422,14 @@ int Xorriso_option_cdx(struct XorrisO *xorriso, char *disk_path, int flag)
/* Option -chgrp alias -chgrpi */
int Xorriso_option_chgrpi(struct XorrisO *xorriso, char *gid, char *path,
int Xorriso_option_chgrpi(struct XorrisO *xorriso, char *gid,
int argc, char **argv, int *idx, int flag)
{
int i, end_idx;
end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 0);
fprintf(stderr, ">>> LIBISOFS : would perform -chgrpi %s %s ", gid, path);
fprintf(stderr, ">>> LIBISOFS : would perform -chgrpi %s ", gid);
for(i= *idx; i<end_idx; i++)
fprintf(stderr, "%s ", argv[i]);
fprintf(stderr, "\n");
@ -3433,32 +3440,112 @@ int Xorriso_option_chgrpi(struct XorrisO *xorriso, char *gid, char *path,
/* Option -chmod alias -chmodi */
int Xorriso_option_chmodi(struct XorrisO *xorriso, char *mode, char *path,
int Xorriso_option_chmodi(struct XorrisO *xorriso, char *mode,
int argc, char **argv, int *idx, int flag)
{
int i, end_idx;
int i, end_idx, ret, who_val= 0;
unsigned int num;
mode_t mode_and= ~0, mode_or= 0, mode_val;
char sfe[4*SfileadrL], *mpt, *opt, *vpt;
end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 0);
fprintf(stderr, ">>> LIBISOFS : would perform -chmodi %s %s ", mode, path);
for(i= *idx; i<end_idx; i++)
fprintf(stderr, "%s ", argv[i]);
fprintf(stderr, "\n");
if(mode[0]=='0') {
mode_and= 0;
sscanf(mode,"%o",&num);
mode_or= num;
} else if(strchr(mode,'+')!=NULL || strchr(mode,'-')!=NULL) {
/* [ugoa][+-][rwxst] */;
for(mpt= mode; mpt!=NULL; mpt= strchr(mpt, ',')) {
if(*mpt==',')
mpt++;
if(strlen(mpt)<3)
goto unrecognizable;
who_val= 0;
for(vpt= mpt; *vpt!='+' && *vpt!='-' && *vpt!='='; vpt++) {
if(*vpt=='u')
who_val|= 4;
else if(*vpt=='g')
who_val|= 2;
else if(*vpt=='o')
who_val|= 1;
else if(*vpt=='a')
who_val|= 7;
else
goto unrecognizable;
}
opt= vpt;
mode_val= 0;
for(vpt= opt+1; *vpt!=0 && *vpt!=','; vpt++) {
if(*vpt=='r') {
if(who_val&4)
mode_val|= S_IRUSR;
if(who_val&2)
mode_val|= S_IRGRP;
if(who_val&1)
mode_val|= S_IROTH;
} else if(*vpt=='w') {
if(who_val&4)
mode_val|= S_IWUSR;
if(who_val&2)
mode_val|= S_IWGRP;
if(who_val&1)
mode_val|= S_IWOTH;
} else if(*vpt=='x') {
if(who_val&4)
mode_val|= S_IXUSR;
if(who_val&2)
mode_val|= S_IXGRP;
if(who_val&1)
mode_val|= S_IXOTH;
} else if(*vpt=='s') {
if(who_val&4)
mode_val|= S_ISUID;
if(who_val&2)
mode_val|= S_ISGID;
} else if(*vpt=='t') {
mode_val|= S_ISVTX;
} else
goto unrecognizable;
}
if(*opt=='+') {
mode_or|= mode_val;
} else if(*opt=='=') {
mode_and= 0;
mode_or= mode_val;
} else if(*opt=='-') {
mode_or&= ~mode_val;
mode_and&= ~mode_val;
}
}
} else {
unrecognizable:;
sprintf(xorriso->info_text,
"-chmodi: Unrecognizable or faulty permission mode %s\n",
Text_shellsafe(mode, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
}
ret= 1;
for(i= *idx; i<end_idx; i++) {
ret= Xorriso_set_st_mode(xorriso, argv[i], mode_and, mode_or, 0);
if(ret<=0)
break;
}
(*idx)= end_idx;
return(1);
return(ret);
}
/* Option -chown alias -chowni */
int Xorriso_option_chowni(struct XorrisO *xorriso, char *uid, char *path,
int Xorriso_option_chowni(struct XorrisO *xorriso, char *uid,
int argc, char **argv, int *idx, int flag)
{
int i, end_idx;
end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 0);
fprintf(stderr, ">>> LIBISOFS : would perform -chowni %s %s ", uid, path);
fprintf(stderr, ">>> LIBISOFS : would perform -chowni %s", uid);
for(i= *idx; i<end_idx; i++)
fprintf(stderr, "%s ", argv[i]);
fprintf(stderr, "\n");
@ -4952,16 +5039,16 @@ next_command:;
ret= Xorriso_option_cdx(xorriso, arg1, 0);
} else if(strcmp(cmd,"-chgrp")==0 || strcmp(cmd,"-chgrpi")==0) {
(*idx)+= 2;
ret= Xorriso_option_chgrpi(xorriso, arg1, arg2, argc, argv, idx, 0);
(*idx)+= 1;
ret= Xorriso_option_chgrpi(xorriso, arg1, argc, argv, idx, 0);
} else if(strcmp(cmd,"-chmod")==0 || strcmp(cmd,"-chmodi")==0) {
(*idx)+= 2;
ret= Xorriso_option_chmodi(xorriso, arg1, arg2, argc, argv, idx, 0);
(*idx)+= 1;
ret= Xorriso_option_chmodi(xorriso, arg1, argc, argv, idx, 0);
} else if(strcmp(cmd,"-chown")==0 || strcmp(cmd,"-chowni")==0) {
(*idx)+= 2;
ret= Xorriso_option_chowni(xorriso, arg1, arg2, argc, argv, idx, 0);
(*idx)+= 1;
ret= Xorriso_option_chowni(xorriso, arg1, argc, argv, idx, 0);
} else if(strcmp(cmd,"-close")==0) {
(*idx)++;

View File

@ -127,9 +127,9 @@ int Xorriso_option_add(struct XorrisO *xorriso, int argc, char **argv,
int *idx, int flag);
/* Option -alter_date */
int Xorriso_option_slater_date(struct XorrisO *xorriso,
char *time_type, char *timestring,
int argc, char **argv, int *idx, int flag);
int Xorriso_option_alter_date(struct XorrisO *xorriso,
char *time_type, char *timestring,
int argc, char **argv, int *idx, int flag);
/* Option -ban_stdio_write */
int Xorriso_option_ban_stdio_write(struct XorrisO *xorriso, int flag);
@ -145,15 +145,15 @@ int Xorriso_option_cdi(struct XorrisO *xorriso, char *iso_rr_path, int flag);
int Xorriso_option_cdx(struct XorrisO *xorriso, char *disk_path, int flag);
/* Option -chgrp alias -chgrpi */
int Xorriso_option_chgrpi(struct XorrisO *xorriso, char *gid, char *path,
int Xorriso_option_chgrpi(struct XorrisO *xorriso, char *gid,
int argc, char **argv, int *idx, int flag);
/* Option -chmod alias -chmodi */
int Xorriso_option_chmodi(struct XorrisO *xorriso, char *mode, char *path,
int Xorriso_option_chmodi(struct XorrisO *xorriso, char *mode,
int argc, char **argv, int *idx, int flag);
/* Option -chown alias -chowni */
int Xorriso_option_chowni(struct XorrisO *xorriso, char *uid, char *path,
int Xorriso_option_chowni(struct XorrisO *xorriso, char *uid,
int argc, char **argv, int *idx, int flag);
/* Option -close "on"|"off" */

View File

@ -1 +1 @@
#define Xorriso_timestamP "2007.11.07.150157"
#define Xorriso_timestamP "2007.11.07.191915"

View File

@ -580,6 +580,33 @@ much_too_long:;
}
int Xorriso_get_node_by_path(struct XorrisO *xorriso,
char *in_path, char *eff_path,
struct iso_tree_node **node, int flag)
{
int ret;
char sfe[4*SfileadrL], path[SfileadrL];
struct iso_volume *volume;
ret= Xorriso_normalize_img_path(xorriso, in_path, path, 0);
if(ret<=0)
return(ret);
if(eff_path!=NULL)
strcpy(eff_path, path);
ret= Xorriso_get_volume(xorriso, &volume, 0);
if(ret<=0)
return(ret);
*node= iso_tree_volume_path_to_node(volume,path);
if(*node==NULL) {
sprintf(xorriso->info_text, "Not found in ISO image: %s",
Text_shellsafe(path, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
return(1);
}
/* @param flag bit0= recursion is active */
int Xorriso_add_tree(struct XorrisO *xorriso, struct iso_tree_node_dir *dir,
char *img_dir_path, char *disk_dir_path, int flag)
@ -1740,6 +1767,40 @@ ex:;
}
int Xorriso__mode_to_perms(mode_t st_mode, char perms[10], int flag)
{
strcpy(perms,"---------");
if(st_mode&S_IRUSR) perms[0]= 'r';
if(st_mode&S_IWUSR) perms[1]= 'w';
if(st_mode&S_IXUSR) perms[2]= 'x';
if(st_mode&S_ISUID) {
if(st_mode&S_IXUSR)
perms[2]= 's';
else
perms[2]= 'S';
}
if(st_mode&S_IRGRP) perms[3]= 'r';
if(st_mode&S_IWGRP) perms[4]= 'w';
if(st_mode&S_IXGRP) perms[5]= 'x';
if(st_mode&S_ISGID) {
if(st_mode&S_IXGRP)
perms[5]= 's';
else
perms[5]= 'S';
}
if(st_mode&S_IROTH) perms[6]= 'r';
if(st_mode&S_IWOTH) perms[7]= 'w';
if(st_mode&S_IXOTH) perms[8]= 'x';
if(st_mode&S_ISVTX) {
if(st_mode&S_IXOTH)
perms[8]= 't';
else
perms[8]= 'T';
}
return(1);
}
/* @param flag bit0= long format
bit1= do not print count of nodes
bit2= du format
@ -1824,16 +1885,7 @@ much_too_long:;
strcat(rpt, "?");
st_mode= iso_tree_node_get_permissions(node);
strcpy(perms,"---------");
if(st_mode&S_IRUSR) perms[0]= 'r';
if(st_mode&S_IWUSR) perms[1]= 'w';
if(st_mode&S_IXUSR) perms[2]= 'x';
if(st_mode&S_IRGRP) perms[3]= 'r';
if(st_mode&S_IWGRP) perms[4]= 'w';
if(st_mode&S_IXGRP) perms[5]= 'x';
if(st_mode&S_IROTH) perms[6]= 'r';
if(st_mode&S_IWOTH) perms[7]= 'w';
if(st_mode&S_IXOTH) perms[8]= 'x';
Xorriso__mode_to_perms(st_mode, perms, 0);
strcat(rpt, perms);
/* >>> With directories this should be : number of subdirs + 2 */
@ -1976,16 +2028,7 @@ wdi_is_not_a_dir:;
strcat(rpt, "?");
st_mode= iso_tree_node_get_permissions(node);
strcpy(perms,"---------");
if(st_mode&S_IRUSR) perms[0]= 'r';
if(st_mode&S_IWUSR) perms[1]= 'w';
if(st_mode&S_IXUSR) perms[2]= 'x';
if(st_mode&S_IRGRP) perms[3]= 'r';
if(st_mode&S_IWGRP) perms[4]= 'w';
if(st_mode&S_IXGRP) perms[5]= 'x';
if(st_mode&S_IROTH) perms[6]= 'r';
if(st_mode&S_IWOTH) perms[7]= 'w';
if(st_mode&S_IXOTH) perms[8]= 'x';
Xorriso__mode_to_perms(st_mode, perms, 0);
strcat(rpt, perms);
/* >>> With directories this should be : number of subdirs + 2 */
@ -2422,3 +2465,24 @@ ex:;
}
int Xorriso_set_st_mode(struct XorrisO *xorriso, char *in_path,
mode_t mode_and, mode_t mode_or, int flag)
{
mode_t mode= 0;
int ret;
struct iso_tree_node *node;
char sfe[4*SfileadrL], path[SfileadrL];
ret= Xorriso_get_node_by_path(xorriso, in_path, path, &node, 0);
if(ret<=0)
return(ret);
mode= iso_tree_node_get_permissions(node);
mode= (mode & mode_and) | mode_or;
iso_tree_node_set_permissions(node, mode);
sprintf(xorriso->info_text,"Permissions now: %-5.5o %s",
mode, Text_shellsafe(path, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
xorriso->volset_change_pending= 1;
return(1);
}

View File

@ -95,5 +95,9 @@ int Xorriso_expand_pattern(struct XorrisO *xorriso,
int num_patterns, char **patterns,
int *filec, char ***filev, off_t *mem, int flag);
int Xorriso_set_st_mode(struct XorrisO *xorriso, char *path,
mode_t mode_and, mode_t mode_or, int flag);
#endif /* Xorrisoburn_includeD */