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 ------------------------ */ /* ---------------------------- 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 Xorriso_option_chgrpi(struct XorrisO *xorriso, char *gid,
int argc, char **argv, int *idx, int flag) 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); end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 0);
fprintf(stderr, ">>> LIBISOFS : would perform -chgrpi %s ", gid); ret= Xorriso_convert_gidstring(xorriso, gid, &gid_number, 0);
for(i= *idx; i<end_idx; i++) if(ret<=0)
fprintf(stderr, "%s ", argv[i]); goto ex;
fprintf(stderr, "\n");
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; (*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", "-chmodi: Unrecognizable or faulty permission mode %s\n",
Text_shellsafe(mode, sfe, 0)); Text_shellsafe(mode, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
ret= 0; goto ex;
} }
ret= 1; ret= 1;
@ -3532,6 +3592,7 @@ unrecognizable:;
if(ret<=0) if(ret<=0)
break; break;
} }
ex:;
(*idx)= end_idx; (*idx)= end_idx;
return(ret); return(ret);
} }
@ -3541,17 +3602,28 @@ unrecognizable:;
int Xorriso_option_chowni(struct XorrisO *xorriso, char *uid, int Xorriso_option_chowni(struct XorrisO *xorriso, char *uid,
int argc, char **argv, int *idx, int flag) 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); end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 0);
fprintf(stderr, ">>> LIBISOFS : would perform -chowni %s", uid); ret= Xorriso_convert_uidstring(xorriso, uid, &uid_number, 0);
for(i= *idx; i<end_idx; i++) if(ret<=0)
fprintf(stderr, "%s ", argv[i]); goto ex;
fprintf(stderr, "\n");
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; (*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 */ /* Option -gid */
int Xorriso_option_gid(struct XorrisO *xorriso, char *gid, int flag) int Xorriso_option_gid(struct XorrisO *xorriso, char *gid, int flag)
{ {
double num; int ret;
char text[80];
struct group *grp;
xorriso->do_global_gid= 0;
if(gid[0]==0 || strcmp(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); return(1);
} ret= Xorriso_convert_gidstring(xorriso, gid, &(xorriso->global_gid), 0);
grp= getgrnam(gid); if(ret>0)
if(grp==NULL) { xorriso->do_global_gid= 1;
sprintf(xorriso->info_text, "-gid: Not a known group: '%s'", gid); return(ret);
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);
} }
@ -4902,30 +4960,15 @@ int Xorriso_option_toc(struct XorrisO *xorriso, int flag)
/* Option -uid */ /* Option -uid */
int Xorriso_option_uid(struct XorrisO *xorriso, char *uid, int flag) int Xorriso_option_uid(struct XorrisO *xorriso, char *uid, int flag)
{ {
double num; int ret;
char text[80];
struct passwd *pwd;
xorriso->do_global_uid= 0;
if(uid[0]==0 || strcmp(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); return(1);
} ret= Xorriso_convert_uidstring(xorriso, uid, &(xorriso->global_uid), 0);
if(ret>0)
pwd= getpwnam(uid); xorriso->do_global_uid= 1;
if(pwd==NULL) { return(ret);
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);
} }

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); 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, int Xorriso_set_st_mode(struct XorrisO *xorriso, char *path,
mode_t mode_and, mode_t mode_or, int flag); 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 */ #endif /* Xorrisoburn_includeD */