diff options
Diffstat (limited to 'bin/pax/sel_subs.c')
-rw-r--r-- | bin/pax/sel_subs.c | 134 |
1 files changed, 64 insertions, 70 deletions
diff --git a/bin/pax/sel_subs.c b/bin/pax/sel_subs.c index 4c0d09e4eb7f..ccbb77ccbb5c 100644 --- a/bin/pax/sel_subs.c +++ b/bin/pax/sel_subs.c @@ -33,28 +33,23 @@ * SUCH DAMAGE. */ -#ifndef lint -#if 0 -static char sccsid[] = "@(#)sel_subs.c 8.1 (Berkeley) 5/31/93"; -#endif -#endif /* not lint */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/types.h> #include <sys/time.h> #include <sys/stat.h> -#include <pwd.h> + +#include <ctype.h> #include <grp.h> +#include <pwd.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <strings.h> -#include <stdlib.h> + #include "pax.h" #include "sel_subs.h" #include "extern.h" -static int str_sec(char *, time_t *); +static int str_sec(const char *, time_t *); static int usr_match(ARCHD *); static int grp_match(ARCHD *); static int trng_match(ARCHD *); @@ -89,7 +84,7 @@ sel_chk(ARCHD *arcn) * User/group selection routines * * Routines to handle user selection of files based on the file uid/gid. To - * add an entry, the user supplies either then name or the uid/gid starting with + * add an entry, the user supplies either the name or the uid/gid starting with * a # on the command line. A \# will escape the #. */ @@ -134,11 +129,7 @@ usr_add(char *str) } uid = (uid_t)pw->pw_uid; } else -# ifdef NET2_STAT - uid = (uid_t)atoi(str+1); -# else uid = (uid_t)strtoul(str+1, NULL, 10); -# endif endpwent(); /* @@ -235,11 +226,7 @@ grp_add(char *str) } gid = gr->gr_gid; } else -# ifdef NET2_STAT - gid = (gid_t)atoi(str+1); -# else gid = (gid_t)strtoul(str+1, NULL, 10); -# endif endgrent(); /* @@ -317,7 +304,7 @@ grp_match(ARCHD *arcn) * trng_add() * add a time range match to the time range list. * This is a non-standard pax option. Lower and upper ranges are in the - * format: [yy[mm[dd[hh]]]]mm[.ss] and are comma separated. + * format: [[[[[cc]yy]mm]dd]HH]MM[.SS] and are comma separated. * Time ranges are based on current time, so 1234 would specify a time of * 12:34 today. * Return: @@ -454,7 +441,7 @@ trng_add(char *str) return(0); out: - paxwarn(1, "Time range format is: [yy[mm[dd[hh]]]]mm[.ss][/[c][m]]"); + paxwarn(1, "Time range format is: [[[[[cc]yy]mm]dd]HH]MM[.SS][/[c][m]]"); return(-1); } @@ -528,80 +515,87 @@ trng_match(ARCHD *arcn) /* * str_sec() - * Convert a time string in the format of [yy[mm[dd[hh]]]]mm[.ss] to gmt - * seconds. Tval already has current time loaded into it at entry. + * Convert a time string in the format of [[[[[cc]yy]mm]dd]HH]MM[.SS] to + * seconds UTC. Tval already has current time loaded into it at entry. * Return: * 0 if converted ok, -1 otherwise */ static int -str_sec(char *str, time_t *tval) +str_sec(const char *p, time_t *tval) { struct tm *lt; - char *dot = NULL; + const char *dot, *t; + size_t len; + int bigyear; + int yearset; + + yearset = 0; + len = strlen(p); + + for (t = p, dot = NULL; *t; ++t) { + if (isdigit((unsigned char)*t)) + continue; + if (*t == '.' && dot == NULL) { + dot = t; + continue; + } + return(-1); + } lt = localtime(tval); - if ((dot = strchr(str, '.')) != NULL) { - /* - * seconds (.ss) - */ - *dot++ = '\0'; - if (strlen(dot) != 2) + + if (dot != NULL) { /* .SS */ + if (strlen(++dot) != 2) return(-1); - if ((lt->tm_sec = ATOI2(dot)) > 61) + lt->tm_sec = ATOI2(dot); + if (lt->tm_sec > 61) return(-1); + len -= 3; } else lt->tm_sec = 0; - switch (strlen(str)) { - case 10: - /* - * year (yy) - * watch out for year 2000 - */ - if ((lt->tm_year = ATOI2(str)) < 69) - lt->tm_year += 100; - str += 2; + switch (len) { + case 12: /* cc */ + bigyear = ATOI2(p); + lt->tm_year = (bigyear * 100) - 1900; + yearset = 1; /* FALLTHROUGH */ - case 8: - /* - * month (mm) - * watch out months are from 0 - 11 internally - */ - if ((lt->tm_mon = ATOI2(str)) > 12) + case 10: /* yy */ + if (yearset) { + lt->tm_year += ATOI2(p); + } else { + lt->tm_year = ATOI2(p); + if (lt->tm_year < 69) /* hack for 2000 ;-} */ + lt->tm_year += (2000 - 1900); + } + /* FALLTHROUGH */ + case 8: /* mm */ + lt->tm_mon = ATOI2(p); + if ((lt->tm_mon > 12) || !lt->tm_mon) return(-1); - --lt->tm_mon; - str += 2; + --lt->tm_mon; /* time struct is 0 - 11 */ /* FALLTHROUGH */ - case 6: - /* - * day (dd) - */ - if ((lt->tm_mday = ATOI2(str)) > 31) + case 6: /* dd */ + lt->tm_mday = ATOI2(p); + if ((lt->tm_mday > 31) || !lt->tm_mday) return(-1); - str += 2; /* FALLTHROUGH */ - case 4: - /* - * hour (hh) - */ - if ((lt->tm_hour = ATOI2(str)) > 23) + case 4: /* HH */ + lt->tm_hour = ATOI2(p); + if (lt->tm_hour > 23) return(-1); - str += 2; /* FALLTHROUGH */ - case 2: - /* - * minute (mm) - */ - if ((lt->tm_min = ATOI2(str)) > 59) + case 2: /* MM */ + lt->tm_min = ATOI2(p); + if (lt->tm_min > 59) return(-1); break; default: return(-1); } - /* - * convert broken-down time to GMT clock time seconds - */ + + /* convert broken-down time to UTC clock time seconds */ if ((*tval = mktime(lt)) == -1) return(-1); return(0); |