diff --git a/NEWS b/NEWS index 231ea4b5..8e1eb377 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,8 @@ User visible changes for UPX ================================================================== Changes in 3.01 (XX XXX 2007): + * new options --no-mode, --no-owner and --no-time to disable preservation + of mode (file permissions), file ownership and timestamps. * dos/exe: fixed an incorrect error message caused by a bug in relocation handling * new format linux/mipsel supports ELF on [32-bit] R3000 diff --git a/src/main.cpp b/src/main.cpp index b3770828..01a3194f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -56,6 +56,9 @@ void options_t::reset() o->backup = -1; o->overlay = -1; + o->preserve_mode = true; + o->preserve_ownership = true; + o->preserve_timestamp = true; o->console = CON_FILE; #if defined(__DJGPP__) @@ -646,6 +649,15 @@ static int do_option(int optc, const char *arg) case 519: opt->no_env = true; break; + case 526: + opt->preserve_mode = false; + break; + case 527: + opt->preserve_ownership = false; + break; + case 528: + opt->preserve_timestamp = false; + break; // compression settings case 520: // --small if (opt->small < 0) @@ -900,7 +912,10 @@ static const struct mfx_option longopts[] = {"force-compress", 0, 0, 'f'}, // and compression of suspicious files {"info", 0, 0, 'i'}, // info mode {"no-env", 0x10, 0, 519}, // no environment var + {"no-mode", 0x10, 0, 526}, // do not preserve mode (permissions) + {"no-owner", 0x10, 0, 527}, // do not preserve ownership {"no-progress", 0, 0, 516}, // no progress bar + {"no-time", 0x10, 0, 528}, // do not preserve timestamp {"output", 0x21, 0, 'o'}, {"quiet", 0, 0, 'q'}, // quiet mode {"silent", 0, 0, 'q'}, // quiet mode diff --git a/src/options.h b/src/options.h index 94cd9e80..efcd79f4 100644 --- a/src/options.h +++ b/src/options.h @@ -69,6 +69,9 @@ struct options_t { bool no_env; bool no_progress; const char *output_name; + bool preserve_mode; + bool preserve_ownership; + bool preserve_timestamp; int small; int verbose; bool to_stdout; diff --git a/src/work.cpp b/src/work.cpp index d7281650..1dc2ed9d 100644 --- a/src/work.cpp +++ b/src/work.cpp @@ -141,6 +141,8 @@ void do_one_file(const char *iname, char *oname) // cannot rely on open() because of umask //int omode = st.st_mode | 0600; int omode = 0600; + if (!opt->preserve_mode) + omode = 0666; fo.sopen(tname,flags,shmode,omode); // open succeeded - now set oname[] strcpy(oname,tname); @@ -209,21 +211,30 @@ void do_one_file(const char *iname, char *oname) UNUSED(name); #if defined(USE_UTIME) // copy time stamp - struct utimbuf u; - u.actime = st.st_atime; - u.modtime = st.st_mtime; - r = utime(name, &u); - UNUSED(r); + if (opt->preserve_timestamp) + { + struct utimbuf u; + u.actime = st.st_atime; + u.modtime = st.st_mtime; + r = utime(name, &u); + UNUSED(r); + } #endif #if defined(HAVE_CHMOD) // copy permissions - r = chmod(name, st.st_mode); - UNUSED(r); + if (opt->preserve_mode) + { + r = chmod(name, st.st_mode); + UNUSED(r); + } #endif #if defined(HAVE_CHOWN) // copy the ownership - r = chown(name, st.st_uid, st.st_gid); - UNUSED(r); + if (opt->preserve_ownership) + { + r = chown(name, st.st_uid, st.st_gid); + UNUSED(r); + } #endif }