11573Srgrimes/*- 21573Srgrimes * Copyright (c) 1993 31573Srgrimes * The Regents of the University of California. All rights reserved. 41573Srgrimes * 51573Srgrimes * Redistribution and use in source and binary forms, with or without 61573Srgrimes * modification, are permitted provided that the following conditions 71573Srgrimes * are met: 81573Srgrimes * 1. Redistributions of source code must retain the above copyright 91573Srgrimes * notice, this list of conditions and the following disclaimer. 101573Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111573Srgrimes * notice, this list of conditions and the following disclaimer in the 121573Srgrimes * documentation and/or other materials provided with the distribution. 131573Srgrimes * 4. Neither the name of the University nor the names of its contributors 141573Srgrimes * may be used to endorse or promote products derived from this software 151573Srgrimes * without specific prior written permission. 161573Srgrimes * 171573Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181573Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191573Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201573Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211573Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221573Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231573Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241573Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251573Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261573Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271573Srgrimes * SUCH DAMAGE. 281573Srgrimes */ 291573Srgrimes 301573Srgrimes#if defined(LIBC_SCCS) && !defined(lint) 311573Srgrimesstatic char sccsid[] = "@(#)sysctl.c 8.2 (Berkeley) 1/4/94"; 321573Srgrimes#endif /* LIBC_SCCS and not lint */ 3392986Sobrien#include <sys/cdefs.h> 3492986Sobrien__FBSDID("$FreeBSD$"); 351573Srgrimes 361573Srgrimes#include <sys/param.h> 371573Srgrimes#include <sys/sysctl.h> 381573Srgrimes 391573Srgrimes#include <errno.h> 401573Srgrimes#include <limits.h> 411573Srgrimes#include <paths.h> 421573Srgrimes#include <stdio.h> 431573Srgrimes#include <unistd.h> 4411659Sphk#include <string.h> 451573Srgrimes 46204170Sedextern int __sysctl(const int *name, u_int namelen, void *oldp, 47204170Sed size_t *oldlenp, const void *newp, size_t newlen); 48111010Snectar 491573Srgrimesint 50204170Sedsysctl(const int *name, u_int namelen, void *oldp, size_t *oldlenp, 51204170Sed const void *newp, size_t newlen) 521573Srgrimes{ 53240176Strhodes int retval; 541573Srgrimes 55240176Strhodes retval = __sysctl(name, namelen, oldp, oldlenp, newp, newlen); 56240176Strhodes if (retval != -1 || errno != ENOENT || name[0] != CTL_USER) 57240176Strhodes return (retval); 58240176Strhodes 591573Srgrimes if (newp != NULL) { 601573Srgrimes errno = EPERM; 611573Srgrimes return (-1); 621573Srgrimes } 631573Srgrimes if (namelen != 2) { 641573Srgrimes errno = EINVAL; 651573Srgrimes return (-1); 661573Srgrimes } 671573Srgrimes 681573Srgrimes switch (name[1]) { 691573Srgrimes case USER_CS_PATH: 7042353Sdes if (oldp && *oldlenp < sizeof(_PATH_STDPATH)) { 7142353Sdes errno = ENOMEM; 7242353Sdes return -1; 7342353Sdes } 741573Srgrimes *oldlenp = sizeof(_PATH_STDPATH); 751573Srgrimes if (oldp != NULL) 761573Srgrimes memmove(oldp, _PATH_STDPATH, sizeof(_PATH_STDPATH)); 771573Srgrimes return (0); 781573Srgrimes } 791573Srgrimes 8042353Sdes if (oldp && *oldlenp < sizeof(int)) { 8142353Sdes errno = ENOMEM; 8242353Sdes return (-1); 8342353Sdes } 841573Srgrimes *oldlenp = sizeof(int); 851573Srgrimes if (oldp == NULL) 861573Srgrimes return (0); 871573Srgrimes 881573Srgrimes switch (name[1]) { 891573Srgrimes case USER_BC_BASE_MAX: 901573Srgrimes *(int *)oldp = BC_BASE_MAX; 911573Srgrimes return (0); 921573Srgrimes case USER_BC_DIM_MAX: 931573Srgrimes *(int *)oldp = BC_DIM_MAX; 941573Srgrimes return (0); 951573Srgrimes case USER_BC_SCALE_MAX: 961573Srgrimes *(int *)oldp = BC_SCALE_MAX; 971573Srgrimes return (0); 981573Srgrimes case USER_BC_STRING_MAX: 991573Srgrimes *(int *)oldp = BC_STRING_MAX; 1001573Srgrimes return (0); 1011573Srgrimes case USER_COLL_WEIGHTS_MAX: 1021573Srgrimes *(int *)oldp = COLL_WEIGHTS_MAX; 1031573Srgrimes return (0); 1041573Srgrimes case USER_EXPR_NEST_MAX: 1051573Srgrimes *(int *)oldp = EXPR_NEST_MAX; 1061573Srgrimes return (0); 1071573Srgrimes case USER_LINE_MAX: 1081573Srgrimes *(int *)oldp = LINE_MAX; 1091573Srgrimes return (0); 1101573Srgrimes case USER_RE_DUP_MAX: 1111573Srgrimes *(int *)oldp = RE_DUP_MAX; 1121573Srgrimes return (0); 1131573Srgrimes case USER_POSIX2_VERSION: 1141573Srgrimes *(int *)oldp = _POSIX2_VERSION; 1151573Srgrimes return (0); 1161573Srgrimes case USER_POSIX2_C_BIND: 1171573Srgrimes#ifdef POSIX2_C_BIND 1181573Srgrimes *(int *)oldp = 1; 1191573Srgrimes#else 1201573Srgrimes *(int *)oldp = 0; 1211573Srgrimes#endif 1221573Srgrimes return (0); 1231573Srgrimes case USER_POSIX2_C_DEV: 1241573Srgrimes#ifdef POSIX2_C_DEV 1251573Srgrimes *(int *)oldp = 1; 1261573Srgrimes#else 1271573Srgrimes *(int *)oldp = 0; 1281573Srgrimes#endif 1291573Srgrimes return (0); 1301573Srgrimes case USER_POSIX2_CHAR_TERM: 1311573Srgrimes#ifdef POSIX2_CHAR_TERM 1321573Srgrimes *(int *)oldp = 1; 1331573Srgrimes#else 1341573Srgrimes *(int *)oldp = 0; 1351573Srgrimes#endif 1361573Srgrimes return (0); 1371573Srgrimes case USER_POSIX2_FORT_DEV: 1381573Srgrimes#ifdef POSIX2_FORT_DEV 1391573Srgrimes *(int *)oldp = 1; 1401573Srgrimes#else 1411573Srgrimes *(int *)oldp = 0; 1421573Srgrimes#endif 1431573Srgrimes return (0); 1441573Srgrimes case USER_POSIX2_FORT_RUN: 1451573Srgrimes#ifdef POSIX2_FORT_RUN 1461573Srgrimes *(int *)oldp = 1; 1471573Srgrimes#else 1481573Srgrimes *(int *)oldp = 0; 1491573Srgrimes#endif 1501573Srgrimes return (0); 1511573Srgrimes case USER_POSIX2_LOCALEDEF: 1521573Srgrimes#ifdef POSIX2_LOCALEDEF 1531573Srgrimes *(int *)oldp = 1; 1541573Srgrimes#else 1551573Srgrimes *(int *)oldp = 0; 1561573Srgrimes#endif 1571573Srgrimes return (0); 1581573Srgrimes case USER_POSIX2_SW_DEV: 1591573Srgrimes#ifdef POSIX2_SW_DEV 1601573Srgrimes *(int *)oldp = 1; 1611573Srgrimes#else 1621573Srgrimes *(int *)oldp = 0; 1631573Srgrimes#endif 1641573Srgrimes return (0); 1651573Srgrimes case USER_POSIX2_UPE: 1661573Srgrimes#ifdef POSIX2_UPE 1671573Srgrimes *(int *)oldp = 1; 1681573Srgrimes#else 1691573Srgrimes *(int *)oldp = 0; 1701573Srgrimes#endif 1711573Srgrimes return (0); 1721573Srgrimes case USER_STREAM_MAX: 1731573Srgrimes *(int *)oldp = FOPEN_MAX; 1741573Srgrimes return (0); 1751573Srgrimes case USER_TZNAME_MAX: 1761573Srgrimes *(int *)oldp = NAME_MAX; 1771573Srgrimes return (0); 1781573Srgrimes default: 1791573Srgrimes errno = EINVAL; 1801573Srgrimes return (-1); 1811573Srgrimes } 1821573Srgrimes /* NOTREACHED */ 1831573Srgrimes} 184