summaryrefslogtreecommitdiffstats
path: root/tools/regression/priv/priv_clock_settime.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/regression/priv/priv_clock_settime.c')
-rw-r--r--tools/regression/priv/priv_clock_settime.c56
1 files changed, 32 insertions, 24 deletions
diff --git a/tools/regression/priv/priv_clock_settime.c b/tools/regression/priv/priv_clock_settime.c
index e3d1089..84b8beb 100644
--- a/tools/regression/priv/priv_clock_settime.c
+++ b/tools/regression/priv/priv_clock_settime.c
@@ -1,5 +1,6 @@
/*-
* Copyright (c) 2006 nCircle Network Security, Inc.
+ * Copyright (c) 2007 Robert N. M. Watson
* All rights reserved.
*
* This software was developed by Robert N. M. Watson for the TrustedBSD
@@ -43,34 +44,41 @@
#include "main.h"
-void
-priv_clock_settime(void)
+static struct timespec the_time;
+
+int
+priv_clock_settime_setup(int asroot, int injail, struct test *test)
{
- struct timespec ts;
- int error;
- assert_root();
+ if (clock_gettime(CLOCK_REALTIME, &the_time) < 0) {
+ warn("priv_clock_settime_setup: "
+ "clock_gettime(CLOCK_REALTIME)");
+ return (-1);
+ }
+ return (0);
+}
- /*
- * Query time.
- */
- if (clock_gettime(CLOCK_REALTIME, &ts) < 0)
- err(-1, "clock_gettime");
+void
+priv_clock_settime(int asroot, int injail, struct test *test)
+{
+ int error;
- /*
- * Set with privilege.
- */
- if (clock_settime(CLOCK_REALTIME, &ts) < 0)
- err(-1, "clock_settime as root");
+ error = clock_settime(CLOCK_REALTIME, &the_time);
+ if (asroot && injail)
+ expect("priv_clock_settime(asroot, injail)", error, -1,
+ EPERM);
+ if (asroot && !injail)
+ expect("priv_clock_settime(asroot, !injail)", error, 0, 0);
+ if (!asroot && injail)
+ expect("priv_clock_settime(!asroot, injail)", error, -1,
+ EPERM);
+ if (!asroot && !injail)
+ expect("priv_clock_settime(!asroot, !injail", error, -1,
+ EPERM);
+}
- /*
- * Set without privilege.
- */
- set_euid(UID_OTHER);
+void
+priv_clock_settime_cleanup(int asroot, int injail, struct test *test)
+{
- error = clock_settime(CLOCK_REALTIME, &ts);
- if (error == 0)
- errx(-1, "clock_settime succeeded as !root");
- if (errno != EPERM)
- errx(-1, "clock_settime wrong errno %d as !root", errno);
}
OpenPOWER on IntegriCloud