From e952fa42b0c5880f419c399e27e0ef44d50595e5 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Fri, 20 Jun 2008 09:16:34 +0000 Subject: [PATCH] New -osirrox option auto_chmod_on --- libisoburn/trunk/xorriso/xorriso.1 | 59 ++++++++++-------- libisoburn/trunk/xorriso/xorriso.c | 64 ++++++++++++++++++-- libisoburn/trunk/xorriso/xorriso_private.h | 6 ++ libisoburn/trunk/xorriso/xorriso_timestamp.h | 2 +- libisoburn/trunk/xorriso/xorrisoburn.c | 8 +-- 5 files changed, 103 insertions(+), 36 deletions(-) diff --git a/libisoburn/trunk/xorriso/xorriso.1 b/libisoburn/trunk/xorriso/xorriso.1 index 5180a29a..8d41bb9d 100644 --- a/libisoburn/trunk/xorriso/xorriso.1 +++ b/libisoburn/trunk/xorriso/xorriso.1 @@ -2,7 +2,7 @@ .\" First parameter, NAME, should be all caps .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection .\" other parameters are allowed: see man(7), man(1) -.TH XORRISO 1 "Jun, 14, 2008" +.TH XORRISO 1 "Jun, 20, 2008" .\" Please adjust this date whenever revising the manpage. .\" .\" Some roff macros, for reference: @@ -1627,7 +1627,7 @@ If disk file objects already exist then the settings of -overwrite and of -overwrite "nondir". I.e. directories cannot be deleted. .br Access permissions of files in the ISO image do not restrict restoring. -The permissions on disk have to allow writing, of course. +The directory permissions on disk have to allow rwx. .TP \fB\-osirrox\fR "on"|"device_files"|"off"[:option:...] Setting "off" disables disk filesystem manipulations. This is the default @@ -1647,10 +1647,13 @@ restored. .br Option "concat_split_on" is default. It enables restoring of split file directories as data files if the directory contains a complete collection -of -cut_out part files. -.br -With option "concat_split_off" such directories are +of -cut_out part files. With option "concat_split_off" such directories are handled like any other ISO image directory. +.br +Option "auto_chmod_off" is default. If "auto_chmod_on" is set then access +restrictions for disk directories get circumvented if those directories +are owned by the effective user who runs xorriso. This happens by temporarily +granting rwx permission to the owner. It will not work with ACL restrictions. .TP \fB\-extract\fR iso_rr_path disk_path Restore the file objects at and underneath iso_rr_path to their corresponding @@ -1927,6 +1930,8 @@ Adjust thresholds for verbosity, exit value and program abort Examples of input timestrings .br Incremental backup of a few directory trees +.br +Restore directory trees from a particular ISO session to disk .SS .B As superuser learn about available drives Consider to give rw permissions to those users or groups @@ -2152,25 +2157,12 @@ on media and if the expected changes are much smaller than the full backup. An update run will probably save no time but last longer than a full backup. Another good reason may be given if read speed is much higher than write speed. .br -.br With \fBmount\fR option \fB"sbsector="\fR it is possible to access the session trees which represent the older backup versions. With CD media, Linux mount accepts session numbers directly by its option "session=". .br Multi-session media and most overwriteable media written by xorriso can tell the sbsector of a session by xorriso option -toc. -Another way to keep track of incremental sessions is to -set before writing a suitable path for xorriso option -session_log where -the sbsector number gets recorded as the second word in each line. -.br -Independently of mount there is xorriso option \fB-osirrox on\fR which enables -the builtin restore commands -extract, -cpx and others. They operate on the -session eventually selected by option \fB-load\fR. -.br -\fBDo not write more than about 50 sessions\fR to one multi-session media. -Theoretical limits are higher but in practice the media deteriorate more early. -It might also be that your operating system has a session limit with mount. -An overview of sessions is given by option -toc. .br Sessions on multi-session media are separated by several MB of unused blocks. So with small sessions the payload capacity can become substantially lower @@ -2184,15 +2176,32 @@ get endangered by the new write operation, while the newest backup is stored safely on a different media. Always have a blank media ready to perform a full backup in case the update attempt fails due to insufficient remaining capacity. -.br -If you have enough re-useable media for a round-robin scheme then better do -full backups with blank media each time. Blanking can be achieved by -either a separate run: +.SS +.B Restore directory trees from a particular ISO session to disk +This is an alternative to mounting the media and using normal file operations. .br -\fB$\fR xorriso -outdev /dev/sr0 -blank as_needed -eject all +First check which backup sessions are on the media: .br -or in the update run by using option -blank "as_needed" before -option -update_r. +\fB$\fR xorriso -outdev /dev/sr0 -toc +.br +Then load the desired session and copy the file trees to disk. +Avoid to eventually create /home/thomas/restored without rwx-permission. +.br +\fB$\fR xorriso -load volid PROJECTS_MAIL_2008_06_19_205956 \\ +.br + -indev /dev/sr0 \\ +.br + -osirrox on:auto_chmod_on \\ +.br + -chmod u+rwx / \\ +.br + -extract /open_source_projects \\ +.br + /home/thomas/restored/open_source_projects \\ +.br + -extract /personal_mail /home/thomas/restored/personal_mail +.br + -rollback_end .br .SH FILES .SS diff --git a/libisoburn/trunk/xorriso/xorriso.c b/libisoburn/trunk/xorriso/xorriso.c index 10eaf438..fc0889b2 100644 --- a/libisoburn/trunk/xorriso/xorriso.c +++ b/libisoburn/trunk/xorriso/xorriso.c @@ -2835,6 +2835,7 @@ int Xorriso_new(struct XorrisO ** xorriso,char *progname, int flag) m->allow_graft_points= 0; m->allow_restore= 0; m->do_concat_split= 1; + m->do_auto_chmod= 0; m->dialog= 0; m->search_mode= 0; m->structured_search= 1; @@ -3942,11 +3943,14 @@ int Xorriso_status(struct XorrisO *xorriso, char *filter, FILE *fp, int flag) Xorriso_status_result(xorriso,filter,fp,flag&2); } - is_default= (xorriso->allow_restore==0 && xorriso->do_concat_split==1); - sprintf(line,"-osirrox %s:%s\n", + is_default= (xorriso->allow_restore==0 && xorriso->do_concat_split==1 && + xorriso->do_auto_chmod==0); + sprintf(line,"-osirrox %s:%s:%s\n", xorriso->allow_restore ? xorriso->allow_restore==2 ? "device_files" : "on" : "off", - xorriso->do_concat_split ? "concat_split_on" : "concat_split_off"); + xorriso->do_concat_split ? "concat_split_on" : "concat_split_off", + xorriso->do_auto_chmod ? "auto_chmod_on" : "auto_chmod_off" + ); if(!(is_default && no_defaults)) Xorriso_status_result(xorriso,filter,fp,flag&2); @@ -7897,6 +7901,54 @@ int Xorriso_make_tmp_path(struct XorrisO *xorriso, char *orig_path, return(1); } + +int Xorriso_auto_chmod(struct XorrisO *xorriso, char *disk_path, int flag) +{ + int ret, is_link= 0; + char *path_pt, sfe[5*SfileadrL], link_target[SfileadrL]; + mode_t mode, desired= S_IRUSR | S_IWUSR | S_IXUSR; + struct stat stbuf; + + if(!xorriso->do_auto_chmod) + return(0); + + path_pt= disk_path; + ret= lstat(path_pt, &stbuf); + if(ret==-1) + return(0); + if(S_ISLNK(stbuf.st_mode)) { + is_link= 1; + ret= stat(path_pt, &stbuf); + if(ret==-1) + return(0); + } + if(!S_ISDIR(stbuf.st_mode)) + return(0); + if(is_link) { + ret= Xorriso_resolve_link(xorriso, path_pt, link_target, 0); + if(ret<=0) + return(ret); + path_pt= link_target; + } + if(stbuf.st_uid!=geteuid()) + return(0); + if((stbuf.st_mode & desired) == desired) + return(0); + + mode= (stbuf.st_mode | desired) & 07777; + ret= chmod(path_pt, mode); + if(ret==-1) { + sprintf(xorriso->info_text, + "Cannot change access permissions of disk directory: chmod %o %s", + mode & 07777, Text_shellsafe(path_pt, sfe, 0)); + Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "SORRY", 0); + } + ret= Permstack_push(&(xorriso->perm_stack), path_pt, &stbuf, 0); + if(ret<=0) + return(ret); + return(1); +} + /* ---------------------------- Options API ------------------------ */ @@ -10884,6 +10936,10 @@ int Xorriso_option_osirrox(struct XorrisO *xorriso, char *mode, int flag) xorriso->do_concat_split= 1; else if(strncmp(cpt, "concat_split_off", l)==0) xorriso->do_concat_split= 0; + else if(strncmp(cpt, "auto_chmod_on", l)==0) + xorriso->do_auto_chmod= 1; + else if(strncmp(cpt, "auto_chmod_off", l)==0) + xorriso->do_auto_chmod= 0; else { unknown_mode:; sprintf(xorriso->info_text, "-osirrox: unknown mode '%s'", cpt); @@ -10892,7 +10948,7 @@ unknown_mode:; } } sprintf(xorriso->info_text, - "%s copying of file objects from ISO image to disk filesystem\n", + "Copying of file objects from ISO image to disk filesystem is: %s\n", xorriso->allow_restore ? "Enabled" : "Disabled"); Xorriso_info(xorriso, 0); return(1); diff --git a/libisoburn/trunk/xorriso/xorriso_private.h b/libisoburn/trunk/xorriso/xorriso_private.h index 55b3c388..654e62df 100644 --- a/libisoburn/trunk/xorriso/xorriso_private.h +++ b/libisoburn/trunk/xorriso/xorriso_private.h @@ -164,6 +164,9 @@ struct XorrisO { /* the global context of xorriso */ int do_concat_split; /* 1= restore complete split file directories as regular files */ + int do_auto_chmod; /* 1= eventually temporarily open access permissions + of self-owned directories during restore + */ int dialog; @@ -428,6 +431,9 @@ int Xorriso_make_tmp_path(struct XorrisO *xorriso, char *orig_path, int Xorriso_reassure_restore(struct XorrisO *xorriso, char *path, int flag); +int Xorriso_auto_chmod(struct XorrisO *xorriso, char *disk_path, int flag); + + int Sfile_str(char target[SfileadrL], char *source, int flag); double Sfile_microtime(int flag); diff --git a/libisoburn/trunk/xorriso/xorriso_timestamp.h b/libisoburn/trunk/xorriso/xorriso_timestamp.h index 2516b0f0..1ae33585 100644 --- a/libisoburn/trunk/xorriso/xorriso_timestamp.h +++ b/libisoburn/trunk/xorriso/xorriso_timestamp.h @@ -1 +1 @@ -#define Xorriso_timestamP "2008.06.19.092858" +#define Xorriso_timestamP "2008.06.20.091647" diff --git a/libisoburn/trunk/xorriso/xorrisoburn.c b/libisoburn/trunk/xorriso/xorrisoburn.c index a0b2760e..eb479fa3 100644 --- a/libisoburn/trunk/xorriso/xorrisoburn.c +++ b/libisoburn/trunk/xorriso/xorrisoburn.c @@ -3047,9 +3047,7 @@ much_too_long:; goto was_problem; if(stbuf_ret!=-1) { /* (Can only happen with directory) */ - - /* ??? >>> eventually open access to existing directory ? */; - + Xorriso_auto_chmod(xorriso, disk_path, 0); } else { hflag= 4 | (flag & (2|64)); if(source_is_dir && !do_not_dive) @@ -3237,9 +3235,7 @@ int Xorriso_restore(struct XorrisO *xorriso, } new_dir_made= 1; } else if(source_is_dir && !source_is_split) { - - /* >>> If owner: eventually try to obtain rwx-permssions, stack path */; - + Xorriso_auto_chmod(xorriso, disk_path, 0); } if(done) { attach_source:;