2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-22 01:49:11 +00:00

Trivial test for process start time. We don't try to check the

resulting timespec as it differs by platform.  On most it is wallclock
time, on others it is relative to boot time (Linux).
This commit is contained in:
Todd C. Miller 2017-12-18 10:35:37 -07:00
parent d93559e9c0
commit 6ce85b1746
3 changed files with 82 additions and 1 deletions

View File

@ -388,6 +388,7 @@ plugins/sudoers/regress/parser/check_digest.out.ok
plugins/sudoers/regress/parser/check_fill.c
plugins/sudoers/regress/parser/check_gentime.c
plugins/sudoers/regress/parser/check_hexchar.c
plugins/sudoers/regress/starttime/check_starttime.c
plugins/sudoers/regress/sudoers/test1.in
plugins/sudoers/regress/sudoers/test1.json.ok
plugins/sudoers/regress/sudoers/test1.out.ok

View File

@ -147,7 +147,7 @@ PROGS = sudoers.la visudo sudoreplay testsudoers
TEST_PROGS = check_addr check_base64 check_digest check_env_pattern \
check_fill check_gentime check_hexchar check_iolog_path \
check_wrap @SUDOERS_TEST_PROGS@
check_wrap check_starttime @SUDOERS_TEST_PROGS@
AUTH_OBJS = sudo_auth.lo @AUTH_OBJS@
@ -192,6 +192,8 @@ CHECK_IOLOG_PATH_OBJS = check_iolog_path.o iolog_path.o locale.o \
CHECK_SYMBOLS_OBJS = check_symbols.o
CHECK_STARTTIME_OBJS = check_starttime.o starttime.o sudoers_debug.o
CHECK_WRAP_OBJS = check_wrap.o logwrap.o sudoers_debug.o
VERSION = @PACKAGE_VERSION@
@ -267,6 +269,9 @@ check_hexchar: $(CHECK_HEXCHAR_OBJS) $(LT_LIBS)
check_iolog_path: $(CHECK_IOLOG_PATH_OBJS) $(LT_LIBS)
$(LIBTOOL) $(LTFLAGS) --mode=link $(CC) -o $@ $(CHECK_IOLOG_PATH_OBJS) $(LDFLAGS) $(ASAN_LDFLAGS) $(PIE_LDFLAGS) $(SSP_LDFLAGS) $(LIBS)
check_starttime: $(CHECK_STARTTIME_OBJS) $(LT_LIBS)
$(LIBTOOL) $(LTFLAGS) --mode=link $(CC) -o $@ $(CHECK_STARTTIME_OBJS) $(LDFLAGS) $(ASAN_LDFLAGS) $(PIE_LDFLAGS) $(SSP_LDFLAGS) $(LIBS)
# We need to link check_symbols with -lpthread on HP-UX since LDAP uses threads
check_symbols: $(CHECK_SYMBOLS_OBJS) $(LT_LIBS)
$(LIBTOOL) $(LTFLAGS) --mode=link $(CC) -o $@ $(CHECK_SYMBOLS_OBJS) $(LDFLAGS) $(ASAN_LDFLAGS) $(PIE_LDFLAGS) $(SSP_LDFLAGS) $(LIBS) @SUDO_LIBS@
@ -395,6 +400,7 @@ check: $(TEST_PROGS) visudo testsudoers
./check_gentime || rval=`expr $$rval + $$?`; \
./check_hexchar || rval=`expr $$rval + $$?`; \
./check_iolog_path $(srcdir)/regress/iolog_path/data || rval=`expr $$rval + $$?`; \
./check_starttime || rval=`expr $$rval + $$?`; \
if test -f check_symbols; then \
./check_symbols .libs/sudoers.so $(shlib_exp) || rval=`expr $$rval + $$?`; \
fi; \
@ -654,6 +660,17 @@ check_iolog_path.o: $(srcdir)/regress/iolog_path/check_iolog_path.c \
$(srcdir)/sudoers.h $(srcdir)/sudoers_debug.h \
$(top_builddir)/config.h $(top_builddir)/pathnames.h
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(ASAN_CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(srcdir)/regress/iolog_path/check_iolog_path.c
check_starttime.o: $(srcdir)/regress/starttime/check_starttime.c \
$(devdir)/def_data.h $(incdir)/compat/stdbool.h \
$(incdir)/sudo_compat.h $(incdir)/sudo_conf.h \
$(incdir)/sudo_debug.h $(incdir)/sudo_fatal.h \
$(incdir)/sudo_gettext.h $(incdir)/sudo_plugin.h \
$(incdir)/sudo_queue.h $(incdir)/sudo_util.h \
$(srcdir)/check.h $(srcdir)/defaults.h $(srcdir)/logging.h \
$(srcdir)/sudo_nss.h $(srcdir)/sudoers.h \
$(srcdir)/sudoers_debug.h $(top_builddir)/config.h \
$(top_builddir)/pathnames.h
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(ASAN_CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(srcdir)/regress/starttime/check_starttime.c
check_symbols.o: $(srcdir)/regress/check_symbols/check_symbols.c \
$(incdir)/compat/stdbool.h $(incdir)/sudo_compat.h \
$(incdir)/sudo_dso.h $(incdir)/sudo_fatal.h \
@ -1124,6 +1141,7 @@ starttime.lo: $(srcdir)/starttime.c $(devdir)/def_data.h \
$(srcdir)/sudoers_debug.h $(top_builddir)/config.h \
$(top_builddir)/pathnames.h
$(LIBTOOL) $(LTFLAGS) --mode=compile $(CC) -c $(CPPFLAGS) $(CFLAGS) $(ASAN_CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(srcdir)/starttime.c
starttime.o: starttime.lo
sudo_auth.lo: $(authdir)/sudo_auth.c $(devdir)/def_data.h \
$(incdir)/compat/stdbool.h $(incdir)/sudo_compat.h \
$(incdir)/sudo_conf.h $(incdir)/sudo_debug.h \

View File

@ -0,0 +1,62 @@
/*
* Copyright (c) 2017 Todd C. Miller <Todd.Miller@sudo.ws>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <config.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include "sudo_compat.h"
#include "sudo_util.h"
#include "check.h"
__dso_public int main(int argc, char *argv[]);
int
main(int argc, char *argv[])
{
int ntests = 0, errors = 0;
struct timespec ts;
pid_t pids[2];
int i;
initprogname(argc > 0 ? argv[0] : "check_starttime");
pids[0] = getpid();
pids[1] = getppid();
/*
* We don't try to check the resulting timespec as it differs
* by platform. On some it is wallclock time, on others it
* is relative to boot time.
*/
for (i = 0; i < 2; i++) {
ntests++;
if (get_starttime(pids[i], &ts) == -1) {
printf("%s: test %d: unable to get start time for pid %d\n",
getprogname(), ntests, (int)pids[i]);
errors++;
}
}
printf("%s: %d tests run, %d errors, %d%% success rate\n", getprogname(),
ntests, errors, (ntests - errors) * 100 / ntests);
exit(errors);
}