From 9906751f3cc0e6a2acd8912a85b325fe6cf7bf8d Mon Sep 17 00:00:00 2001 From: "David P. Reese, Jr." Date: Fri, 14 Nov 2003 01:53:55 +0000 Subject: [PATCH] Move ogethostname(), osethostname(), ogethostid(), osethostid(), and oquota() to the 43bsd emulation subtree. Change o{get,set}hostname() to use kernel_sysctl() instead of userland_sysctl(). --- sys/conf/files | 3 +- sys/emulation/43bsd/43bsd_hostinfo.c | 126 +++++++++++++++++++++++++++ sys/kern/kern_xxx.c | 67 +------------- 3 files changed, 129 insertions(+), 67 deletions(-) create mode 100644 sys/emulation/43bsd/43bsd_hostinfo.c diff --git a/sys/conf/files b/sys/conf/files index 5792da5acf..1905cf41c4 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1,5 +1,5 @@ # $FreeBSD: src/sys/conf/files,v 1.340.2.137 2003/06/04 17:10:30 sam Exp $ -# $DragonFly: src/sys/conf/files,v 1.26 2003/11/08 07:57:40 dillon Exp $ +# $DragonFly: src/sys/conf/files,v 1.27 2003/11/14 01:53:54 daver Exp $ # # The long compile-with and dependency lines are required because of # limitations in config: backslash-newline doesn't work in strings, and @@ -1591,3 +1591,4 @@ emulation/43bsd/43bsd_file.c optional compat_43 emulation/43bsd/43bsd_signal.c optional compat_43 emulation/43bsd/43bsd_exit.c optional compat_43 emulation/43bsd/43bsd_resource.c optional compat_43 +emulation/43bsd/43bsd_hostinfo.c optional compat_43 diff --git a/sys/emulation/43bsd/43bsd_hostinfo.c b/sys/emulation/43bsd/43bsd_hostinfo.c new file mode 100644 index 0000000000..210f567763 --- /dev/null +++ b/sys/emulation/43bsd/43bsd_hostinfo.c @@ -0,0 +1,126 @@ +/* + * 43BSD_HOSTINFO.C - 4.3BSD compatibility host info syscalls + * + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $DragonFly: src/sys/emulation/43bsd/43bsd_hostinfo.c,v 1.1 2003/11/14 01:53:54 daver Exp $ + * from: DragonFly kern/kern_xxx.c,v 1.7 + * + * These syscalls used to live in kern/kern_xxx.c. + */ + +#include "opt_compat.h" + +#include +#include +#include +#include +#include +#include + +int +ogethostname(struct gethostname_args *uap) +{ + size_t len; + char *hostname; + int error, name[2]; + + name[0] = CTL_KERN; + name[1] = KERN_HOSTNAME; + len = MIN(uap->len, MAXHOSTNAMELEN); + hostname = malloc(MAXHOSTNAMELEN, M_TEMP, M_WAITOK); + + error = kernel_sysctl(name, 2, hostname, &len, NULL, 0, NULL); + + if (error == 0) + error = copyout(hostname, uap->hostname, len); + + free(hostname, M_TEMP); + return (error); +} + +int +osethostname(struct sethostname_args *uap) +{ + struct thread *td = curthread; + struct proc *p = td->td_proc; + size_t len; + char *hostname; + int name[2]; + int error; + + KKASSERT(p); + name[0] = CTL_KERN; + name[1] = KERN_HOSTNAME; + error = suser_cred(p->p_ucred, PRISON_ROOT); + if (error) + return (error); + len = MIN(uap->len, MAXHOSTNAMELEN); + hostname = malloc(MAXHOSTNAMELEN, M_TEMP, M_WAITOK); + + error = copyin(uap->hostname, hostname, len); + if (error) { + free(hostname, M_TEMP); + return (error); + } + + error = kernel_sysctl(name, 2, NULL, 0, hostname, len, NULL); + + free(hostname, M_TEMP); + return (error); +} + +int +ogethostid(struct ogethostid_args *uap) +{ + uap->sysmsg_lresult = hostid; + return (0); +} + +int +osethostid(struct osethostid_args *uap) +{ + struct thread *td = curthread; + int error; + + error = suser(td); + if (error) + return (error); + hostid = uap->hostid; + return (0); +} + +int +oquota(struct oquota_args *uap) +{ + return (ENOSYS); +} diff --git a/sys/kern/kern_xxx.c b/sys/kern/kern_xxx.c index 04946639f3..9b68d669fa 100644 --- a/sys/kern/kern_xxx.c +++ b/sys/kern/kern_xxx.c @@ -32,11 +32,9 @@ * * @(#)kern_xxx.c 8.2 (Berkeley) 11/14/93 * $FreeBSD: src/sys/kern/kern_xxx.c,v 1.31 1999/08/28 00:46:15 peter Exp $ - * $DragonFly: src/sys/kern/kern_xxx.c,v 1.7 2003/07/30 00:19:14 dillon Exp $ + * $DragonFly: src/sys/kern/kern_xxx.c,v 1.8 2003/11/14 01:53:55 daver Exp $ */ -#include "opt_compat.h" - #include #include #include @@ -45,69 +43,6 @@ #include #include - -#if defined(COMPAT_43) || defined(COMPAT_SUNOS) - -/* ARGSUSED */ -int -ogethostname(struct gethostname_args *uap) -{ - int name[2]; - size_t len = uap->len; - - name[0] = CTL_KERN; - name[1] = KERN_HOSTNAME; - return (userland_sysctl(name, 2, uap->hostname, &len, - 1, 0, 0, 0)); -} - -/* ARGSUSED */ -int -osethostname(struct sethostname_args *uap) -{ - struct thread *td = curthread; - struct proc *p = td->td_proc; - int name[2]; - int error; - - KKASSERT(p); - name[0] = CTL_KERN; - name[1] = KERN_HOSTNAME; - if ((error = suser_cred(p->p_ucred, PRISON_ROOT))) - return (error); - return (userland_sysctl(name, 2, 0, 0, 0, uap->hostname, uap->len, 0)); -} - -/* ARGSUSED */ -int -ogethostid(struct ogethostid_args *uap) -{ - uap->sysmsg_lresult = hostid; - return (0); -} -#endif /* COMPAT_43 || COMPAT_SUNOS */ - -#ifdef COMPAT_43 -/* ARGSUSED */ -int -osethostid(struct osethostid_args *uap) -{ - struct thread *td = curthread; - int error; - - if ((error = suser(td))) - return (error); - hostid = uap->hostid; - return (0); -} - -int -oquota(struct oquota_args *uap) -{ - return (ENOSYS); -} -#endif /* COMPAT_43 */ - /* ARGSUSED */ int uname(struct uname_args *uap) -- 2.41.0