Deleted Added
full compact
priv_clock_settime.c (162271) priv_clock_settime.c (172106)
1/*-
2 * Copyright (c) 2006 nCircle Network Security, Inc.
1/*-
2 * Copyright (c) 2006 nCircle Network Security, Inc.
3 * Copyright (c) 2007 Robert N. M. Watson
3 * All rights reserved.
4 *
5 * This software was developed by Robert N. M. Watson for the TrustedBSD
6 * Project under contract to nCircle Network Security, Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:

--- 10 unchanged lines hidden (view full) ---

21 * INC., OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
23 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
4 * All rights reserved.
5 *
6 * This software was developed by Robert N. M. Watson for the TrustedBSD
7 * Project under contract to nCircle Network Security, Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:

--- 10 unchanged lines hidden (view full) ---

22 * INC., OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
29 * $FreeBSD: head/tools/regression/priv/priv_clock_settime.c 162271 2006-09-13 09:05:39Z rwatson $
30 * $FreeBSD: head/tools/regression/priv/priv_clock_settime.c 172106 2007-09-09 23:08:39Z rwatson $
30 */
31
32/*
33 * Confirm that privilege is required to invoke clock_settime(). So as not
34 * to mess up the clock too much, first query the time, then immediately set
35 * it. Test only CLOCK_REALTIME.
36 */
37
38#include <sys/time.h>
39
40#include <err.h>
41#include <errno.h>
42#include <unistd.h>
43
44#include "main.h"
45
31 */
32
33/*
34 * Confirm that privilege is required to invoke clock_settime(). So as not
35 * to mess up the clock too much, first query the time, then immediately set
36 * it. Test only CLOCK_REALTIME.
37 */
38
39#include <sys/time.h>
40
41#include <err.h>
42#include <errno.h>
43#include <unistd.h>
44
45#include "main.h"
46
47static struct timespec the_time;
48
49int
50priv_clock_settime_setup(int asroot, int injail, struct test *test)
51{
52
53 if (clock_gettime(CLOCK_REALTIME, &the_time) < 0) {
54 warn("priv_clock_settime_setup: "
55 "clock_gettime(CLOCK_REALTIME)");
56 return (-1);
57 }
58 return (0);
59}
60
46void
61void
47priv_clock_settime(void)
62priv_clock_settime(int asroot, int injail, struct test *test)
48{
63{
49 struct timespec ts;
50 int error;
51
64 int error;
65
52 assert_root();
66 error = clock_settime(CLOCK_REALTIME, &the_time);
67 if (asroot && injail)
68 expect("priv_clock_settime(asroot, injail)", error, -1,
69 EPERM);
70 if (asroot && !injail)
71 expect("priv_clock_settime(asroot, !injail)", error, 0, 0);
72 if (!asroot && injail)
73 expect("priv_clock_settime(!asroot, injail)", error, -1,
74 EPERM);
75 if (!asroot && !injail)
76 expect("priv_clock_settime(!asroot, !injail", error, -1,
77 EPERM);
78}
53
79
54 /*
55 * Query time.
56 */
57 if (clock_gettime(CLOCK_REALTIME, &ts) < 0)
58 err(-1, "clock_gettime");
80void
81priv_clock_settime_cleanup(int asroot, int injail, struct test *test)
82{
59
83
60 /*
61 * Set with privilege.
62 */
63 if (clock_settime(CLOCK_REALTIME, &ts) < 0)
64 err(-1, "clock_settime as root");
65
66 /*
67 * Set without privilege.
68 */
69 set_euid(UID_OTHER);
70
71 error = clock_settime(CLOCK_REALTIME, &ts);
72 if (error == 0)
73 errx(-1, "clock_settime succeeded as !root");
74 if (errno != EPERM)
75 errx(-1, "clock_settime wrong errno %d as !root", errno);
76}
84}