don't check timestamp mtime if we are just going to remove it
This commit is contained in:
24
check.c
24
check.c
@@ -68,6 +68,10 @@ __unused static const char rcsid[] = "$Sudo$";
|
|||||||
#define TS_NOFILE 3
|
#define TS_NOFILE 3
|
||||||
#define TS_ERROR 4
|
#define TS_ERROR 4
|
||||||
|
|
||||||
|
/* Flags for timestamp_status() */
|
||||||
|
#define TS_MAKE_DIRS 1
|
||||||
|
#define TS_REMOVE 2
|
||||||
|
|
||||||
static void build_timestamp __P((char **, char **));
|
static void build_timestamp __P((char **, char **));
|
||||||
static int timestamp_status __P((char *, char *, char *, int));
|
static int timestamp_status __P((char *, char *, char *, int));
|
||||||
static char *expand_prompt __P((char *, char *, char *));
|
static char *expand_prompt __P((char *, char *, char *));
|
||||||
@@ -91,7 +95,8 @@ check_user(override)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
build_timestamp(×tampdir, ×tampfile);
|
build_timestamp(×tampdir, ×tampfile);
|
||||||
status = timestamp_status(timestampdir, timestampfile, user_name, TRUE);
|
status = timestamp_status(timestampdir, timestampfile, user_name,
|
||||||
|
TS_MAKE_DIRS);
|
||||||
if (override || status != TS_CURRENT) {
|
if (override || status != TS_CURRENT) {
|
||||||
lecture(status);
|
lecture(status);
|
||||||
|
|
||||||
@@ -347,11 +352,11 @@ build_timestamp(timestampdir, timestampfile)
|
|||||||
* Check the timestamp file and directory and return their status.
|
* Check the timestamp file and directory and return their status.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
timestamp_status(timestampdir, timestampfile, user, make_dirs)
|
timestamp_status(timestampdir, timestampfile, user, flags)
|
||||||
char *timestampdir;
|
char *timestampdir;
|
||||||
char *timestampfile;
|
char *timestampfile;
|
||||||
char *user;
|
char *user;
|
||||||
int make_dirs;
|
int flags;
|
||||||
{
|
{
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
time_t now;
|
time_t now;
|
||||||
@@ -389,7 +394,7 @@ timestamp_status(timestampdir, timestampfile, user, make_dirs)
|
|||||||
log_error(NO_EXIT|USE_ERRNO, "can't stat %s", dirparent);
|
log_error(NO_EXIT|USE_ERRNO, "can't stat %s", dirparent);
|
||||||
} else {
|
} else {
|
||||||
/* No dirparent, try to make one. */
|
/* No dirparent, try to make one. */
|
||||||
if (make_dirs) {
|
if (ISSET(flags, TS_MAKE_DIRS)) {
|
||||||
if (mkdir(dirparent, S_IRWXU))
|
if (mkdir(dirparent, S_IRWXU))
|
||||||
log_error(NO_EXIT|USE_ERRNO, "can't mkdir %s",
|
log_error(NO_EXIT|USE_ERRNO, "can't mkdir %s",
|
||||||
dirparent);
|
dirparent);
|
||||||
@@ -439,9 +444,9 @@ timestamp_status(timestampdir, timestampfile, user, make_dirs)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* If there is no user ticket dir, AND we are in tty ticket mode,
|
* If there is no user ticket dir, AND we are in tty ticket mode,
|
||||||
* AND the make_dirs flag is set, create the user ticket dir.
|
* AND the TS_MAKE_DIRS flag is set, create the user ticket dir.
|
||||||
*/
|
*/
|
||||||
if (status == TS_MISSING && timestampfile && make_dirs) {
|
if (status == TS_MISSING && timestampfile && ISSET(flags, TS_MAKE_DIRS)) {
|
||||||
if (mkdir(timestampdir, S_IRWXU) == -1) {
|
if (mkdir(timestampdir, S_IRWXU) == -1) {
|
||||||
status = TS_ERROR;
|
status = TS_ERROR;
|
||||||
log_error(NO_EXIT|USE_ERRNO, "can't mkdir %s", timestampdir);
|
log_error(NO_EXIT|USE_ERRNO, "can't mkdir %s", timestampdir);
|
||||||
@@ -487,9 +492,9 @@ timestamp_status(timestampdir, timestampfile, user, make_dirs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the file/dir exists, check its mtime.
|
* If the file/dir exists and we are not removing it, check its mtime.
|
||||||
*/
|
*/
|
||||||
if (status == TS_OLD) {
|
if (status == TS_OLD && !ISSET(flags, TS_REMOVE)) {
|
||||||
/* Negative timeouts only expire manually (sudo -k). */
|
/* Negative timeouts only expire manually (sudo -k). */
|
||||||
if (def_timestamp_timeout < 0 && sb.st_mtime != 0)
|
if (def_timestamp_timeout < 0 && sb.st_mtime != 0)
|
||||||
status = TS_CURRENT;
|
status = TS_CURRENT;
|
||||||
@@ -534,7 +539,8 @@ remove_timestamp(remove)
|
|||||||
int status;
|
int status;
|
||||||
|
|
||||||
build_timestamp(×tampdir, ×tampfile);
|
build_timestamp(×tampdir, ×tampfile);
|
||||||
status = timestamp_status(timestampdir, timestampfile, user_name, FALSE);
|
status = timestamp_status(timestampdir, timestampfile, user_name,
|
||||||
|
TS_REMOVE);
|
||||||
if (status == TS_OLD || status == TS_CURRENT) {
|
if (status == TS_OLD || status == TS_CURRENT) {
|
||||||
path = timestampfile ? timestampfile : timestampdir;
|
path = timestampfile ? timestampfile : timestampdir;
|
||||||
if (remove) {
|
if (remove) {
|
||||||
|
Reference in New Issue
Block a user