From: Todd C. Miller Date: Fri, 2 Nov 2001 20:56:20 +0000 (+0000) Subject: Add new T_UINT type that most things use instead of T_INT X-Git-Tag: SUDO_1_6_4~171 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3550d52a904cf93ec56f0ae5096d2219d2c041c5;p=sudo Add new T_UINT type that most things use instead of T_INT If timestamp_timeout is < 0 then treat the ticket as never expiring (to be expired manually by the user). --- diff --git a/check.c b/check.c index b28cb524f..fc6864921 100644 --- a/check.c +++ b/check.c @@ -424,24 +424,29 @@ timestamp_status(timestampdir, timestampfile, user, make_dirs) * If the file/dir exists, check its mtime. */ if (status == TS_OLD) { - now = time(NULL); - if (def_ival(I_TIMESTAMP_TIMEOUT) && - now - sb.st_mtime < 60 * def_ival(I_TIMESTAMP_TIMEOUT)) { - /* - * Check for bogus time on the stampfile. The clock may - * have been set back or someone could be trying to spoof us. - */ - if (sb.st_mtime > now + 60 * def_ival(I_TIMESTAMP_TIMEOUT) * 2) { - log_error(NO_EXIT, - "timestamp too far in the future: %20.20s", - 4 + ctime(&sb.st_mtime)); - if (timestampfile) - (void) unlink(timestampfile); - else - (void) rmdir(timestampdir); - status = TS_MISSING; - } else - status = TS_CURRENT; + /* Negative timeouts only expire manually (sudo -k). */ + if (def_ival(I_TS_TIMEOUT) < 0 && sb.st_mtime != 0) + status = TS_CURRENT; + else { + now = time(NULL); + if (def_ival(I_TIMESTAMP_TIMEOUT) && + now - sb.st_mtime < 60 * def_ival(I_TIMESTAMP_TIMEOUT)) { + /* + * Check for bogus time on the stampfile. The clock may + * have been set back or someone could be trying to spoof us. + */ + if (sb.st_mtime > now + 60 * def_ival(I_TIMESTAMP_TIMEOUT) * 2) { + log_error(NO_EXIT, + "timestamp too far in the future: %20.20s", + 4 + ctime(&sb.st_mtime)); + if (timestampfile) + (void) unlink(timestampfile); + else + (void) rmdir(timestampdir); + status = TS_MISSING; + } else + status = TS_CURRENT; + } } } diff --git a/defaults.c b/defaults.c index 30fd6040c..7d2f6cace 100644 --- a/defaults.c +++ b/defaults.c @@ -102,6 +102,7 @@ extern int sudolineno; * Local prototypes. */ static int store_int __P((char *, struct sudo_defs_types *, int)); +static int store_uint __P((char *, struct sudo_defs_types *, int)); static int store_str __P((char *, struct sudo_defs_types *, int)); static int store_syslogfac __P((char *, struct sudo_defs_types *, int)); static int store_syslogpri __P((char *, struct sudo_defs_types *, int)); @@ -137,6 +138,7 @@ dump_defaults() putchar('\n'); } break; + case T_UINT: case T_INT: (void) printf(cur->desc, cur->sd_un.ival); putchar('\n'); @@ -286,6 +288,23 @@ set_default(var, val, op) return(FALSE); } break; + case T_UINT: + if (!val) { + /* Check for bogus boolean usage or lack of a value. */ + if (!(cur->type & T_BOOL) || op != FALSE) { + (void) fprintf(stderr, + "%s: no value specified for `%s' on line %d\n", Argv[0], + var, sudolineno); + return(FALSE); + } + } + if (!store_uint(val, cur, op)) { + (void) fprintf(stderr, + "%s: value '%s' is invalid for option '%s'\n", Argv[0], + val, var); + return(FALSE); + } + break; case T_MODE: if (!val) { /* Check for bogus boolean usage or lack of a value. */ @@ -467,6 +486,27 @@ store_int(val, def, op) char *endp; long l; + if (op == FALSE) { + def->sd_un.ival = 0; + } else { + l = strtol(val, &endp, 10); + if (*endp != '\0') + return(FALSE); + /* XXX - should check against INT_MAX */ + def->sd_un.ival = (unsigned int)l; + } + return(TRUE); +} + +static int +store_uint(val, def, op) + char *val; + struct sudo_defs_types *def; + int op; +{ + char *endp; + long l; + if (op == FALSE) { def->sd_un.ival = 0; } else { diff --git a/defaults.h b/defaults.h index 5fe0f6b7e..dbbe89a93 100644 --- a/defaults.h +++ b/defaults.h @@ -46,8 +46,8 @@ struct sudo_defs_types { char *desc; union { int flag; + int ival; char *str; - unsigned int ival; mode_t mode; } sd_un; }; @@ -59,18 +59,20 @@ struct sudo_defs_types { */ #undef T_INT #define T_INT 0x001 +#undef T_UINT +#define T_UINT 0x002 #undef T_STR -#define T_STR 0x002 +#define T_STR 0x003 #undef T_FLAG -#define T_FLAG 0x003 +#define T_FLAG 0x004 #undef T_MODE -#define T_MODE 0x004 +#define T_MODE 0x005 #undef T_LOGFAC -#define T_LOGFAC 0x005 +#define T_LOGFAC 0x006 #undef T_LOGPRI -#define T_LOGPRI 0x006 +#define T_LOGPRI 0x007 #undef T_PWFLAG -#define T_PWFLAG 0x007 +#define T_PWFLAG 0x008 #undef T_MASK #define T_MASK 0x0FF #undef T_BOOL