Implemented options -chown and -chgrp (not written into image, though)

This commit is contained in:
Thomas Schmitt 2007-11-07 22:55:37 +00:00
parent aa0f876723
commit 8d480b1b91
4 changed files with 134 additions and 54 deletions

View File

@ -3132,6 +3132,54 @@ int Xorriso_eval_problem_status(struct XorrisO *xorriso, int ret, int flag)
}
int Xorriso_convert_uidstring(struct XorrisO *xorriso, char *uid_string,
uid_t *uid, int flag)
{
double num;
char text[80];
struct passwd *pwd;
sscanf(uid_string, "%lf", &num);
sprintf(text,"%.f",num);
if(strcmp(text,uid_string)==0) {
*uid= num;
return(1);
}
pwd= getpwnam(uid_string);
if(pwd==NULL) {
sprintf(xorriso->info_text, "-uid: Not a known user: '%s'", uid_string);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
*uid= pwd->pw_uid;
return(1);
}
int Xorriso_convert_gidstring(struct XorrisO *xorriso, char *gid_string,
gid_t *gid, int flag)
{
double num;
char text[80];
struct group *grp;
sscanf(gid_string, "%lf", &num);
sprintf(text,"%.f",num);
if(strcmp(text,gid_string)==0) {
*gid= num;
return(1);
}
grp= getgrnam(gid_string);
if(grp==NULL) {
sprintf(xorriso->info_text, "-gid: Not a known group: '%s'", gid_string);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
*gid= grp->gr_gid;
return(1);
}
/* ---------------------------- Options API ------------------------ */
@ -3425,17 +3473,28 @@ int Xorriso_option_cdx(struct XorrisO *xorriso, char *disk_path, int flag)
int Xorriso_option_chgrpi(struct XorrisO *xorriso, char *gid,
int argc, char **argv, int *idx, int flag)
{
int i, end_idx;
int i, end_idx, ret, was_failure= 0;
gid_t gid_number;
end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 0);
fprintf(stderr, ">>> LIBISOFS : would perform -chgrpi %s ", gid);
for(i= *idx; i<end_idx; i++)
fprintf(stderr, "%s ", argv[i]);
fprintf(stderr, "\n");
ret= Xorriso_convert_gidstring(xorriso, gid, &gid_number, 0);
if(ret<=0)
goto ex;
for(i= *idx; i<end_idx; i++) {
ret= Xorriso_set_gid(xorriso, argv[i], gid_number, 0);
if(ret<0)
goto ex;
if(ret==0)
was_failure= 1;
}
ret= 1;
ex:;
(*idx)= end_idx;
return(1);
if(ret<=0)
return(ret);
return(!was_failure);
}
@ -3524,6 +3583,7 @@ unrecognizable:;
"-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= 0; goto ex;
}
ret= 1;
@ -3532,6 +3592,7 @@ unrecognizable:;
if(ret<=0)
break;
}
ex:;
(*idx)= end_idx;
return(ret);
}
@ -3541,17 +3602,28 @@ unrecognizable:;
int Xorriso_option_chowni(struct XorrisO *xorriso, char *uid,
int argc, char **argv, int *idx, int flag)
{
int i, end_idx;
int i, end_idx, ret, was_failure= 0;
uid_t uid_number;
end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 0);
fprintf(stderr, ">>> LIBISOFS : would perform -chowni %s", uid);
for(i= *idx; i<end_idx; i++)
fprintf(stderr, "%s ", argv[i]);
fprintf(stderr, "\n");
ret= Xorriso_convert_uidstring(xorriso, uid, &uid_number, 0);
if(ret<=0)
goto ex;
for(i= *idx; i<end_idx; i++) {
ret= Xorriso_set_uid(xorriso, argv[i], uid_number, 0);
if(ret<0)
goto ex;
if(ret==0)
was_failure= 1;
}
ret= 1;
ex:;
(*idx)= end_idx;
return(1);
if(ret<=0)
return(ret);
return(!was_failure);
}
@ -3834,29 +3906,15 @@ int Xorriso_option_fs(struct XorrisO *xorriso, char *size, int flag)
/* Option -gid */
int Xorriso_option_gid(struct XorrisO *xorriso, char *gid, int flag)
{
double num;
char text[80];
struct group *grp;
int ret;
xorriso->do_global_gid= 0;
if(gid[0]==0 || strcmp(gid,"-")==0)
xorriso->do_global_gid= 0;
sscanf(gid, "%lf", &num);
sprintf(text,"%.f",num);
if(strcmp(text,gid)==0) {
xorriso->global_gid= num;
xorriso->do_global_gid= 1;
return(1);
}
grp= getgrnam(gid);
if(grp==NULL) {
sprintf(xorriso->info_text, "-gid: Not a known group: '%s'", gid);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
xorriso->global_gid= grp->gr_gid;
xorriso->do_global_gid= 1;
return(1);
ret= Xorriso_convert_gidstring(xorriso, gid, &(xorriso->global_gid), 0);
if(ret>0)
xorriso->do_global_gid= 1;
return(ret);
}
@ -4902,30 +4960,15 @@ int Xorriso_option_toc(struct XorrisO *xorriso, int flag)
/* Option -uid */
int Xorriso_option_uid(struct XorrisO *xorriso, char *uid, int flag)
{
double num;
char text[80];
struct passwd *pwd;
int ret;
xorriso->do_global_uid= 0;
if(uid[0]==0 || strcmp(uid,"-")==0)
xorriso->do_global_uid= 0;
sscanf(uid, "%lf", &num);
sprintf(text,"%.f",num);
if(strcmp(text,uid)==0) {
xorriso->global_uid= num;
xorriso->do_global_uid= 1;
return(1);
}
pwd= getpwnam(uid);
if(pwd==NULL) {
sprintf(xorriso->info_text, "-gid: Not a known user: '%s'", uid);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
xorriso->global_uid= pwd->pw_uid;
xorriso->do_global_uid= 1;
return(1);
ret= Xorriso_convert_uidstring(xorriso, uid, &(xorriso->global_uid), 0);
if(ret>0)
xorriso->do_global_uid= 1;
return(ret);
}

View File

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

View File

@ -2486,3 +2486,34 @@ int Xorriso_set_st_mode(struct XorrisO *xorriso, char *in_path,
return(1);
}
int Xorriso_set_uid(struct XorrisO *xorriso, char *in_path, uid_t uid,
int flag)
{
int ret;
struct iso_tree_node *node;
ret= Xorriso_get_node_by_path(xorriso, in_path, NULL, &node, 0);
if(ret<=0)
return(ret);
iso_tree_node_set_uid(node, uid);
xorriso->volset_change_pending= 1;
return(1);
}
int Xorriso_set_gid(struct XorrisO *xorriso, char *in_path, gid_t gid,
int flag)
{
int ret;
struct iso_tree_node *node;
ret= Xorriso_get_node_by_path(xorriso, in_path, NULL, &node, 0);
if(ret<=0)
return(ret);
iso_tree_node_set_gid(node, gid);
xorriso->volset_change_pending= 1;
return(1);
}

View File

@ -98,6 +98,12 @@ int Xorriso_expand_pattern(struct XorrisO *xorriso,
int Xorriso_set_st_mode(struct XorrisO *xorriso, char *path,
mode_t mode_and, mode_t mode_or, int flag);
int Xorriso_set_uid(struct XorrisO *xorriso, char *in_path, uid_t uid,
int flag);
int Xorriso_set_gid(struct XorrisO *xorriso, char *in_path, gid_t gid,
int flag);
#endif /* Xorrisoburn_includeD */