X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Flist.c;h=0c1e886c4b04a612d6c2d5bce757f717796fb723;hb=1f27dca9765c886a72629a655d538c36c6cb0fea;hp=a3b38304c9368a430515f8f1050d2ed9bbbb76fc;hpb=545ec1a3fae8b395a82ccc0840f313e0b4f16bf1;p=chaz%2Ftar diff --git a/src/list.c b/src/list.c index a3b3830..0c1e886 100644 --- a/src/list.c +++ b/src/list.c @@ -14,20 +14,16 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., - 59 Place - Suite 330, Boston, MA 02111-1307, USA. */ + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Define to non-zero for forcing old ctime() instead of isotime(). */ #undef USE_OLD_CTIME #include "system.h" +#include -#include #include -#define ISODIGIT(Char) \ - ((unsigned char) (Char) >= '0' && (unsigned char) (Char) <= '7') -#define ISSPACE(Char) (ISASCII (Char) && isspace (Char)) - #ifndef FNM_LEADING_DIR # include #endif @@ -38,6 +34,9 @@ union block *current_header; /* points to current archive header */ struct stat current_stat; /* stat struct corresponding */ enum archive_format current_format; /* recognized format */ +static uintmax_t from_oct PARAMS ((const char *, size_t, const char *, uintmax_t)); + + /*-----------------------------------. | Main loop for reading an archive. | `-----------------------------------*/ @@ -66,18 +65,12 @@ read_and (void (*do_something) ()) /* Valid header. We should decode next field (mode) first. Ensure incoming names are null terminated. */ - if (ending_file_option && - fnmatch (ending_file_option, current_file_name, - FNM_LEADING_DIR) == 0) { - goto all_done; - } - /* FIXME: This is a quick kludge before 1.12 goes out. */ current_stat.st_mtime = TIME_FROM_OCT (current_header->header.mtime); if (!name_match (current_file_name) || current_stat.st_mtime < newer_mtime_option - || (exclude_option && check_exclude (current_file_name))) + || excluded_pathname (excluded, current_file_name)) { int isextended = 0; @@ -174,7 +167,6 @@ read_and (void (*do_something) ()) } break; } - all_done: ; apply_delayed_set_stat (); close_archive (); @@ -319,6 +311,7 @@ read_header (void) long unsigned_sum; /* the POSIX one :-) */ long signed_sum; /* the Sun one :-( */ long recorded_sum; + uintmax_t parsed_sum; char *p; union block *header; char **longp; @@ -334,8 +327,13 @@ read_header (void) if (!header) return HEADER_END_OF_FILE; - recorded_sum = UINTMAX_FROM_OCT (header->header.chksum); + parsed_sum = from_oct (header->header.chksum, + sizeof header->header.chksum, + (char *) 0, TYPE_MAXIMUM (long)); + if (parsed_sum == (uintmax_t) -1) + return HEADER_FAILURE; + recorded_sum = parsed_sum; unsigned_sum = 0; signed_sum = 0; p = header->buffer; @@ -477,7 +475,6 @@ decode_header (union block *header, struct stat *stat_info, *format_pointer = format; stat_info->st_mode = MODE_FROM_OCT (header->header.mode); - stat_info->st_mode &= 07777; stat_info->st_mtime = TIME_FROM_OCT (header->header.mtime); if (format == OLDGNU_FORMAT && incremental_option) @@ -510,21 +507,17 @@ decode_header (union block *header, struct stat *stat_info, } switch (header->header.typeflag) { -#ifdef S_IFBLK case BLKTYPE: stat_info->st_rdev = makedev (MAJOR_FROM_OCT (header->header.devmajor), MINOR_FROM_OCT (header->header.devminor)); break; -#endif -#ifdef S_IFCHR case CHRTYPE: stat_info->st_rdev = makedev (MAJOR_FROM_OCT (header->header.devmajor), MINOR_FROM_OCT (header->header.devminor)); break; -#endif default: stat_info->st_rdev = 0; @@ -548,11 +541,12 @@ from_oct (const char *where0, size_t digs0, const char *type, uintmax_t maxval) { if (digs == 0) { - ERROR ((0, 0, _("Blanks in header where octal %s value expected"), - type)); + if (type) + ERROR ((0, 0, _("Blanks in header where octal %s value expected"), + type)); return -1; } - if (!ISSPACE (*where)) + if (!ISSPACE ((unsigned char) *where)) break; where++; digs--; @@ -569,10 +563,27 @@ from_oct (const char *where0, size_t digs0, const char *type, uintmax_t maxval) --digs; } - if (digs != 0 && *where && !ISSPACE (*where)) + if (digs != 0 && *where && !ISSPACE ((unsigned char) *where)) { - ERROR ((0, 0, _("Header contains `%.*s' where octal %s value expected"), - (int) digs0, where0, type)); + if (type) + { + char buf[1000]; /* Big enough to represent any header. */ + static struct quoting_options *o; + + if (!o) + { + o = clone_quoting_options ((struct quoting_options *) 0); + set_quoting_style (o, c_quoting_style); + } + + for (digs = digs0; digs && ! where0[digs - 1]; digs--) + continue; + quotearg_buffer (buf, sizeof buf, where0, digs, o); + ERROR ((0, 0, + _("Header contains %.*s where octal %s value expected"), + (int) sizeof buf, buf, type)); + } + return -1; } @@ -580,8 +591,9 @@ from_oct (const char *where0, size_t digs0, const char *type, uintmax_t maxval) return value; out_of_range: - ERROR ((0, 0, _("Octal value `%.*s' is out of range for %s"), - (int) digs0, where0, type)); + if (type) + ERROR ((0, 0, _("Octal value `%.*s' is out of range for %s"), + (int) digs0, where0, type)); return -1; } gid_t @@ -602,7 +614,20 @@ minor_from_oct (const char *p, size_t s) mode_t mode_from_oct (const char *p, size_t s) { - return from_oct (p, s, "mode_t", (uintmax_t) TYPE_MAXIMUM (mode_t)); + /* Do not complain about unrecognized mode bits. */ + unsigned u = from_oct (p, s, "mode_t", TYPE_MAXIMUM (uintmax_t)); + return ((u & TSUID ? S_ISUID : 0) + | (u & TSGID ? S_ISGID : 0) + | (u & TSVTX ? S_ISVTX : 0) + | (u & TUREAD ? S_IRUSR : 0) + | (u & TUWRITE ? S_IWUSR : 0) + | (u & TUEXEC ? S_IXUSR : 0) + | (u & TGREAD ? S_IRGRP : 0) + | (u & TGWRITE ? S_IWGRP : 0) + | (u & TGEXEC ? S_IXGRP : 0) + | (u & TOREAD ? S_IROTH : 0) + | (u & TOWRITE ? S_IWOTH : 0) + | (u & TOEXEC ? S_IXOTH : 0)); } off_t off_from_oct (const char *p, size_t s) @@ -677,25 +702,21 @@ isotime (const time_t *time) static void decode_mode (mode_t mode, char *string) { - mode_t mask; - const char *rwx = "rwxrwxrwx"; - - for (mask = 0400; mask != 0; mask >>= 1) - if (mode & mask) - *string++ = *rwx++; - else - { - *string++ = '-'; - rwx++; - } - - if (mode & S_ISUID) - string[-7] = string[-7] == 'x' ? 's' : 'S'; - if (mode & S_ISGID) - string[-4] = string[-4] == 'x' ? 's' : 'S'; - if (mode & S_ISVTX) - string[-1] = string[-1] == 'x' ? 't' : 'T'; - + *string++ = mode & S_IRUSR ? 'r' : '-'; + *string++ = mode & S_IWUSR ? 'w' : '-'; + *string++ = (mode & S_ISUID + ? (mode & S_IXUSR ? 's' : 'S') + : (mode & S_IXUSR ? 'x' : '-')); + *string++ = mode & S_IRGRP ? 'r' : '-'; + *string++ = mode & S_IWGRP ? 'w' : '-'; + *string++ = (mode & S_ISGID + ? (mode & S_IXGRP ? 's' : 'S') + : (mode & S_IXGRP ? 'x' : '-')); + *string++ = mode & S_IROTH ? 'r' : '-'; + *string++ = mode & S_IWOTH ? 'w' : '-'; + *string++ = (mode & S_ISVTX + ? (mode & S_IXOTH ? 't' : 'T') + : (mode & S_IXOTH ? 'x' : '-')); *string = '\0'; } @@ -730,7 +751,8 @@ print_header (void) { char modes[11]; char *timestamp; - char uform[11], gform[11]; /* these hold formatted ints */ + /* These hold formatted ints. */ + char uform[UINTMAX_STRSIZE_BOUND], gform[UINTMAX_STRSIZE_BOUND]; char *user, *group; char size[2 * UINTMAX_STRSIZE_BOUND]; /* holds formatted size or major,minor */ @@ -848,14 +870,12 @@ print_header (void) switch (current_header->header.typeflag) { -#if defined(S_IFBLK) || defined(S_IFCHR) case CHRTYPE: case BLKTYPE: sprintf (size, "%lu,%lu", (unsigned long) major (current_stat.st_rdev), (unsigned long) minor (current_stat.st_rdev)); break; -#endif case GNUTYPE_SPARSE: strcpy (size, STRINGIFY_BIGINT