priv_adjtime.c revision 162271
185213Sdarrenr/*- 285213Sdarrenr * Copyright (c) 2006 nCircle Network Security, Inc. 385310Sru * All rights reserved. 485213Sdarrenr * 585213Sdarrenr * This software was developed by Robert N. M. Watson for the TrustedBSD 685213Sdarrenr * Project under contract to nCircle Network Security, Inc. 785213Sdarrenr * 888055Sru * Redistribution and use in source and binary forms, with or without 988055Sru * modification, are permitted provided that the following conditions 1085213Sdarrenr * are met: 1185213Sdarrenr * 1. Redistributions of source code must retain the above copyright 1285213Sdarrenr * notice, this list of conditions and the following disclaimer. 1385213Sdarrenr * 2. Redistributions in binary form must reproduce the above copyright 1485213Sdarrenr * notice, this list of conditions and the following disclaimer in the 1585213Sdarrenr * documentation and/or other materials provided with the distribution. 1685213Sdarrenr * 1785213Sdarrenr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1885213Sdarrenr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1985213Sdarrenr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2085213Sdarrenr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR, NCIRCLE NETWORK SECURITY, 2185213Sdarrenr * INC., OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2285213Sdarrenr * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 2385213Sdarrenr * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 2485213Sdarrenr * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 2585213Sdarrenr * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 2688055Sru * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 2785213Sdarrenr * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2885213Sdarrenr * 29 * $FreeBSD: head/tools/regression/priv/priv_adjtime.c 162271 2006-09-13 09:05:39Z rwatson $ 30 */ 31 32/* 33 * Confirm that privilege is required to invoke adjtime(); first query, then 34 * try setting first with, and then without privilege. 35 */ 36 37#include <sys/time.h> 38 39#include <err.h> 40#include <errno.h> 41#include <unistd.h> 42 43#include "main.h" 44 45void 46priv_adjtime(void) 47{ 48 struct timeval tv; 49 int error; 50 51 assert_root(); 52 53 /* 54 * Query time adjustment. 55 */ 56 if (adjtime(NULL, &tv) < 0) 57 err(-1, "adjtime"); 58 59 /* 60 * Set with privilege. 61 */ 62 if (adjtime(&tv, NULL) < 0) 63 err(-1, "adjtime as root"); 64 65 /* 66 * Set without privilege. 67 */ 68 set_euid(UID_OTHER); 69 70 error = adjtime(&tv, NULL); 71 if (error == 0) 72 errx(-1, "adjtime succeeded as !root"); 73 if (errno != EPERM) 74 errx(-1, "adjtime wrong errno %d as !root", errno); 75} 76