summaryrefslogtreecommitdiffstats
path: root/sys/kern
diff options
context:
space:
mode:
authorjamie <jamie@FreeBSD.org>2009-05-29 21:27:12 +0000
committerjamie <jamie@FreeBSD.org>2009-05-29 21:27:12 +0000
commit572db1408a55640213faa331981d20cda01f68d8 (patch)
tree36c53629863ffb1eb32354e9a24549059dd6273f /sys/kern
parent64785ac65985d6800df1bacd80b5a3ba30b36b27 (diff)
downloadFreeBSD-src-572db1408a55640213faa331981d20cda01f68d8.zip
FreeBSD-src-572db1408a55640213faa331981d20cda01f68d8.tar.gz
Place hostnames and similar information fully under the prison system.
The system hostname is now stored in prison0, and the global variable "hostname" has been removed, as has the hostname_mtx mutex. Jails may have their own host information, or they may inherit it from the parent/system. The proper way to read the hostname is via getcredhostname(), which will copy either the hostname associated with the passed cred, or the system hostname if you pass NULL. The system hostname can still be accessed directly (and without locking) at prison0.pr_host, but that should be avoided where possible. The "similar information" referred to is domainname, hostid, and hostuuid, which have also become prison parameters and had their associated global variables removed. Approved by: bz (mentor)
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_jail.c171
-rw-r--r--sys/kern/kern_mib.c156
-rw-r--r--sys/kern/kern_shutdown.c4
-rw-r--r--sys/kern/kern_xxx.c22
4 files changed, 247 insertions, 106 deletions
diff --git a/sys/kern/kern_jail.c b/sys/kern/kern_jail.c
index b12a478..b6a6d56 100644
--- a/sys/kern/kern_jail.c
+++ b/sys/kern/kern_jail.c
@@ -29,6 +29,7 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include "opt_compat.h"
#include "opt_ddb.h"
#include "opt_inet.h"
#include "opt_inet6.h"
@@ -50,6 +51,7 @@ __FBSDID("$FreeBSD$");
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/sx.h>
+#include <sys/sysent.h>
#include <sys/namei.h>
#include <sys/mount.h>
#include <sys/queue.h>
@@ -79,7 +81,9 @@ struct prison prison0 = {
.pr_uref = 1,
.pr_path = "/",
.pr_securelevel = -1,
+ .pr_uuid = "00000000-0000-0000-0000-000000000000",
.pr_children = LIST_HEAD_INITIALIZER(&prison0.pr_children),
+ .pr_flags = PR_HOST,
.pr_allow = PR_ALLOW_ALL,
};
MTX_SYSINIT(prison0, &prison0.pr_mtx, "jail mutex", MTX_DEF);
@@ -116,8 +120,9 @@ static int prison_restrict_ip6(struct prison *pr, struct in6_addr *newip6);
*/
static char *pr_flag_names[] = {
[0] = "persist",
+ "host",
#ifdef INET
- [2] = "ip4",
+ "ip4",
#endif
#ifdef INET6
[3] = "ip6",
@@ -126,8 +131,9 @@ static char *pr_flag_names[] = {
static char *pr_flag_nonames[] = {
[0] = "nopersist",
+ "nohost",
#ifdef INET
- [2] = "noip4",
+ "noip4",
#endif
#ifdef INET6
[3] = "noip6",
@@ -453,13 +459,14 @@ kern_jail_set(struct thread *td, struct uio *optuio, int flags)
struct vfsoptlist *opts;
struct prison *pr, *deadpr, *mypr, *ppr, *tpr;
struct vnode *root;
- char *errmsg, *host, *name, *p, *path;
+ char *domain, *errmsg, *host, *name, *p, *path, *uuid;
#if defined(INET) || defined(INET6)
void *op;
#endif
+ unsigned long hid;
size_t namelen, onamelen;
int created, cuflags, descend, enforce, error, errmsg_len, errmsg_pos;
- int gotenforce, gotslevel, fi, jid, len;
+ int gotenforce, gothid, gotslevel, fi, jid, len;
int slevel, vfslocked;
#if defined(INET) || defined(INET6)
int ii, ij;
@@ -578,6 +585,8 @@ kern_jail_set(struct thread *td, struct uio *optuio, int flags)
else if (error != 0)
goto done_free;
else {
+ ch_flags |= PR_HOST;
+ pr_flags |= PR_HOST;
if (len == 0 || host[len - 1] != '\0') {
error = EINVAL;
goto done_free;
@@ -588,6 +597,61 @@ kern_jail_set(struct thread *td, struct uio *optuio, int flags)
}
}
+ error = vfs_getopt(opts, "host.domainname", (void **)&domain, &len);
+ if (error == ENOENT)
+ domain = NULL;
+ else if (error != 0)
+ goto done_free;
+ else {
+ ch_flags |= PR_HOST;
+ pr_flags |= PR_HOST;
+ if (len == 0 || domain[len - 1] != '\0') {
+ error = EINVAL;
+ goto done_free;
+ }
+ if (len > MAXHOSTNAMELEN) {
+ error = ENAMETOOLONG;
+ goto done_free;
+ }
+ }
+
+ error = vfs_getopt(opts, "host.hostuuid", (void **)&uuid, &len);
+ if (error == ENOENT)
+ uuid = NULL;
+ else if (error != 0)
+ goto done_free;
+ else {
+ ch_flags |= PR_HOST;
+ pr_flags |= PR_HOST;
+ if (len == 0 || uuid[len - 1] != '\0') {
+ error = EINVAL;
+ goto done_free;
+ }
+ if (len > HOSTUUIDLEN) {
+ error = ENAMETOOLONG;
+ goto done_free;
+ }
+ }
+
+#ifdef COMPAT_IA32
+ if (td->td_proc->p_sysent->sv_flags & SV_IA32) {
+ uint32_t hid32;
+
+ error = vfs_copyopt(opts, "host.hostid", &hid32, sizeof(hid32));
+ hid = hid32;
+ } else
+#endif
+ error = vfs_copyopt(opts, "host.hostid", &hid, sizeof(hid));
+ if (error == ENOENT)
+ gothid = 0;
+ else if (error != 0)
+ goto done_free;
+ else {
+ gothid = 1;
+ ch_flags |= PR_HOST;
+ pr_flags |= PR_HOST;
+ }
+
/* This might be the second time around for this option. */
#ifdef INET
error = vfs_getopt(opts, "ip4.addr", &op, &ip4s);
@@ -1000,6 +1064,16 @@ kern_jail_set(struct thread *td, struct uio *optuio, int flags)
/* Set some default values, and inherit some from the parent. */
if (name == NULL)
name = "";
+ if (host != NULL || domain != NULL || uuid != NULL || gothid) {
+ if (host == NULL)
+ host = ppr->pr_host;
+ if (domain == NULL)
+ domain = ppr->pr_domain;
+ if (uuid == NULL)
+ uuid = ppr->pr_uuid;
+ if (!gothid)
+ hid = ppr->pr_hostid;
+ }
if (path == NULL) {
path = "/";
root = mypr->pr_root;
@@ -1436,8 +1510,50 @@ kern_jail_set(struct thread *td, struct uio *optuio, int flags)
strlcpy(pr->pr_path, path, sizeof(pr->pr_path));
pr->pr_root = root;
}
- if (host != NULL)
- strlcpy(pr->pr_host, host, sizeof(pr->pr_host));
+ if (PR_HOST & ch_flags & ~pr_flags) {
+ if (pr->pr_flags & PR_HOST) {
+ /*
+ * Copy the parent's host info. As with pr_ip4 above,
+ * the lack of a lock on the parent is not a problem;
+ * it is always set with allprison_lock at least
+ * shared, and is held exclusively here.
+ */
+ strlcpy(pr->pr_host, pr->pr_parent->pr_host,
+ sizeof(pr->pr_host));
+ strlcpy(pr->pr_domain, pr->pr_parent->pr_domain,
+ sizeof(pr->pr_domain));
+ strlcpy(pr->pr_uuid, pr->pr_parent->pr_uuid,
+ sizeof(pr->pr_uuid));
+ pr->pr_hostid = pr->pr_parent->pr_hostid;
+ }
+ } else if (host != NULL || domain != NULL || uuid != NULL || gothid) {
+ /* Set this prison, and any descendants without PR_HOST. */
+ if (host != NULL)
+ strlcpy(pr->pr_host, host, sizeof(pr->pr_host));
+ if (domain != NULL)
+ strlcpy(pr->pr_domain, domain, sizeof(pr->pr_domain));
+ if (uuid != NULL)
+ strlcpy(pr->pr_uuid, uuid, sizeof(pr->pr_uuid));
+ if (gothid)
+ pr->pr_hostid = hid;
+ FOREACH_PRISON_DESCENDANT_LOCKED(pr, tpr, descend) {
+ if (tpr->pr_flags & PR_HOST)
+ descend = 0;
+ else {
+ if (host != NULL)
+ strlcpy(tpr->pr_host, pr->pr_host,
+ sizeof(tpr->pr_host));
+ if (domain != NULL)
+ strlcpy(tpr->pr_domain, pr->pr_domain,
+ sizeof(tpr->pr_domain));
+ if (uuid != NULL)
+ strlcpy(tpr->pr_uuid, pr->pr_uuid,
+ sizeof(tpr->pr_uuid));
+ if (gothid)
+ tpr->pr_hostid = hid;
+ }
+ }
+ }
if ((tallow = ch_allow & ~pr_allow)) {
/* Clear allow bits in all children. */
FOREACH_PRISON_DESCENDANT_LOCKED(pr, tpr, descend)
@@ -1753,6 +1869,23 @@ kern_jail_get(struct thread *td, struct uio *optuio, int flags)
error = vfs_setopts(opts, "host.hostname", pr->pr_host);
if (error != 0 && error != ENOENT)
goto done_deref;
+ error = vfs_setopts(opts, "host.domainname", pr->pr_domain);
+ if (error != 0 && error != ENOENT)
+ goto done_deref;
+ error = vfs_setopts(opts, "host.hostuuid", pr->pr_uuid);
+ if (error != 0 && error != ENOENT)
+ goto done_deref;
+#ifdef COMPAT_IA32
+ if (td->td_proc->p_sysent->sv_flags & SV_IA32) {
+ uint32_t hid32 = pr->pr_hostid;
+
+ error = vfs_setopt(opts, "host.hostid", &hid32, sizeof(hid32));
+ } else
+#endif
+ error = vfs_setopt(opts, "host.hostid", &pr->pr_hostid,
+ sizeof(pr->pr_hostid));
+ if (error != 0 && error != ENOENT)
+ goto done_deref;
error = vfs_setopt(opts, "enforce_statfs", &pr->pr_enforce_statfs,
sizeof(pr->pr_enforce_statfs));
if (error != 0 && error != ENOENT)
@@ -3072,17 +3205,12 @@ jailed(struct ucred *cred)
void
getcredhostname(struct ucred *cred, char *buf, size_t size)
{
- INIT_VPROCG(cred->cr_vimage->v_procg);
+ struct prison *pr;
- if (jailed(cred)) {
- mtx_lock(&cred->cr_prison->pr_mtx);
- strlcpy(buf, cred->cr_prison->pr_host, size);
- mtx_unlock(&cred->cr_prison->pr_mtx);
- } else {
- mtx_lock(&hostname_mtx);
- strlcpy(buf, V_hostname, size);
- mtx_unlock(&hostname_mtx);
- }
+ pr = (cred != NULL) ? cred->cr_prison : &prison0;
+ mtx_lock(&pr->pr_mtx);
+ strlcpy(buf, pr->pr_host, size);
+ mtx_unlock(&pr->pr_mtx);
}
/*
@@ -3683,8 +3811,16 @@ SYSCTL_JAIL_PARAM(, dying, CTLTYPE_INT | CTLFLAG_RD,
"B", "Jail is in the process of shutting down");
SYSCTL_JAIL_PARAM_NODE(host, "Jail host info");
+SYSCTL_JAIL_PARAM(, nohost, CTLTYPE_INT | CTLFLAG_RW,
+ "BN", "Jail w/ no host info");
SYSCTL_JAIL_PARAM_STRING(_host, hostname, CTLFLAG_RW, MAXHOSTNAMELEN,
"Jail hostname");
+SYSCTL_JAIL_PARAM_STRING(_host, domainname, CTLFLAG_RW, MAXHOSTNAMELEN,
+ "Jail NIS domainname");
+SYSCTL_JAIL_PARAM_STRING(_host, hostuuid, CTLFLAG_RW, HOSTUUIDLEN,
+ "Jail host UUID");
+SYSCTL_JAIL_PARAM(_host, hostid, CTLTYPE_ULONG | CTLFLAG_RW,
+ "LU", "Jail host ID");
SYSCTL_JAIL_PARAM_NODE(cpuset, "Jail cpuset");
SYSCTL_JAIL_PARAM(_cpuset, id, CTLTYPE_INT | CTLFLAG_RD, "I", "Jail cpuset ID");
@@ -3762,6 +3898,9 @@ db_show_prison(struct prison *pr)
db_printf("\n");
db_printf(" enforce_statfs = %d\n", pr->pr_enforce_statfs);
db_printf(" host.hostname = %s\n", pr->pr_host);
+ db_printf(" host.domainname = %s\n", pr->pr_domain);
+ db_printf(" host.hostuuid = %s\n", pr->pr_uuid);
+ db_printf(" host.hostid = %lu\n", pr->pr_hostid);
#ifdef INET
db_printf(" ip4s = %d\n", pr->pr_ip4s);
for (ii = 0; ii < pr->pr_ip4s; ii++)
diff --git a/sys/kern/kern_mib.c b/sys/kern/kern_mib.c
index 38116d5..823df6b 100644
--- a/sys/kern/kern_mib.c
+++ b/sys/kern/kern_mib.c
@@ -54,7 +54,6 @@ __FBSDID("$FreeBSD$");
#include <sys/smp.h>
#include <sys/sx.h>
#include <sys/unistd.h>
-#include <sys/vimage.h>
SYSCTL_NODE(, 0, sysctl, CTLFLAG_RW, 0,
"Sysctl internal magic");
@@ -209,71 +208,69 @@ static char machine_arch[] = MACHINE_ARCH;
SYSCTL_STRING(_hw, HW_MACHINE_ARCH, machine_arch, CTLFLAG_RD,
machine_arch, 0, "System architecture");
-#ifdef VIMAGE_GLOBALS
-char hostname[MAXHOSTNAMELEN];
-#endif
-
-/*
- * This mutex is used to protect the hostname and domainname variables, and
- * perhaps in the future should also protect hostid, hostuid, and others.
- */
-struct mtx hostname_mtx;
-MTX_SYSINIT(hostname_mtx, &hostname_mtx, "hostname", MTX_DEF);
-
static int
sysctl_hostname(SYSCTL_HANDLER_ARGS)
{
- INIT_VPROCG(TD_TO_VPROCG(req->td));
- struct prison *pr;
- char tmphostname[MAXHOSTNAMELEN];
- int error;
+ struct prison *pr, *cpr;
+ size_t pr_offset;
+ char tmpname[MAXHOSTNAMELEN];
+ int descend, error, len;
+
+ /*
+ * This function can set: hostname domainname hostuuid.
+ * Keep that in mind when comments say "hostname".
+ */
+ pr_offset = (size_t)arg1;
+ len = arg2;
+ KASSERT(len <= sizeof(tmpname),
+ ("length %d too long for %s", len, __func__));
pr = req->td->td_ucred->cr_prison;
- if (pr != &prison0) {
- if (!(pr->pr_allow & PR_ALLOW_SET_HOSTNAME) && req->newptr)
- return (EPERM);
+ if (!(pr->pr_allow & PR_ALLOW_SET_HOSTNAME) && req->newptr)
+ return (EPERM);
+ /*
+ * Make a local copy of hostname to get/set so we don't have to hold
+ * the jail mutex during the sysctl copyin/copyout activities.
+ */
+ mtx_lock(&pr->pr_mtx);
+ bcopy((char *)pr + pr_offset, tmpname, len);
+ mtx_unlock(&pr->pr_mtx);
+
+ error = sysctl_handle_string(oidp, tmpname, len, req);
+
+ if (req->newptr != NULL && error == 0) {
/*
- * Process is in jail, so make a local copy of jail
- * hostname to get/set so we don't have to hold the jail
- * mutex during the sysctl copyin/copyout activities.
+ * Copy the locally set hostname to all jails that share
+ * this host info.
*/
+ sx_slock(&allprison_lock);
+ while (!(pr->pr_flags & PR_HOST))
+ pr = pr->pr_parent;
mtx_lock(&pr->pr_mtx);
- bcopy(pr->pr_host, tmphostname, MAXHOSTNAMELEN);
+ bcopy(tmpname, (char *)pr + pr_offset, len);
+ FOREACH_PRISON_DESCENDANT_LOCKED(pr, cpr, descend)
+ if (cpr->pr_flags & PR_HOST)
+ descend = 0;
+ else
+ bcopy(tmpname, (char *)cpr + pr_offset, len);
mtx_unlock(&pr->pr_mtx);
-
- error = sysctl_handle_string(oidp, tmphostname,
- sizeof pr->pr_host, req);
-
- if (req->newptr != NULL && error == 0) {
- /*
- * Copy the locally set hostname to the jail, if
- * appropriate.
- */
- mtx_lock(&pr->pr_mtx);
- bcopy(tmphostname, pr->pr_host, MAXHOSTNAMELEN);
- mtx_unlock(&pr->pr_mtx);
- }
- } else {
- mtx_lock(&hostname_mtx);
- bcopy(V_hostname, tmphostname, MAXHOSTNAMELEN);
- mtx_unlock(&hostname_mtx);
- error = sysctl_handle_string(oidp, tmphostname,
- sizeof tmphostname, req);
- if (req->newptr != NULL && error == 0) {
- mtx_lock(&prison0.pr_mtx);
- mtx_lock(&hostname_mtx);
- bcopy(tmphostname, prison0.pr_host, MAXHOSTNAMELEN);
- bcopy(tmphostname, V_hostname, MAXHOSTNAMELEN);
- mtx_unlock(&hostname_mtx);
- mtx_unlock(&prison0.pr_mtx);
- }
+ sx_sunlock(&allprison_lock);
}
return (error);
}
SYSCTL_PROC(_kern, KERN_HOSTNAME, hostname,
- CTLTYPE_STRING|CTLFLAG_RW|CTLFLAG_PRISON|CTLFLAG_MPSAFE,
- 0, 0, sysctl_hostname, "A", "Hostname");
+ CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
+ (void *)(offsetof(struct prison, pr_host)), MAXHOSTNAMELEN,
+ sysctl_hostname, "A", "Hostname");
+SYSCTL_PROC(_kern, KERN_NISDOMAINNAME, domainname,
+ CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
+ (void *)(offsetof(struct prison, pr_domain)), MAXHOSTNAMELEN,
+ sysctl_hostname, "A", "Name of the current YP/NIS domain");
+SYSCTL_PROC(_kern, KERN_HOSTUUID, hostuuid,
+ CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
+ (void *)(offsetof(struct prison, pr_uuid)), HOSTUUIDLEN,
+ sysctl_hostname, "A", "Host UUID");
static int regression_securelevel_nonmonotonic = 0;
@@ -341,38 +338,43 @@ SYSCTL_PROC(_kern, OID_AUTO, conftxt, CTLTYPE_STRING|CTLFLAG_RW,
0, 0, sysctl_kern_config, "", "Kernel configuration file");
#endif
-#ifdef VIMAGE_GLOBALS
-char domainname[MAXHOSTNAMELEN]; /* Protected by hostname_mtx. */
-#endif
-
static int
-sysctl_domainname(SYSCTL_HANDLER_ARGS)
+sysctl_hostid(SYSCTL_HANDLER_ARGS)
{
- INIT_VPROCG(TD_TO_VPROCG(req->td));
- char tmpdomainname[MAXHOSTNAMELEN];
- int error;
-
- mtx_lock(&hostname_mtx);
- bcopy(V_domainname, tmpdomainname, MAXHOSTNAMELEN);
- mtx_unlock(&hostname_mtx);
- error = sysctl_handle_string(oidp, tmpdomainname,
- sizeof tmpdomainname, req);
+ struct prison *pr, *cpr;
+ u_long tmpid;
+ int descend, error;
+
+ /*
+ * Like sysctl_hostname, except it operates on a u_long
+ * instead of a string, and is used only for hostid.
+ */
+ pr = req->td->td_ucred->cr_prison;
+ if (!(pr->pr_allow & PR_ALLOW_SET_HOSTNAME) && req->newptr)
+ return (EPERM);
+ tmpid = pr->pr_hostid;
+ error = sysctl_handle_long(oidp, &tmpid, 0, req);
+
if (req->newptr != NULL && error == 0) {
- mtx_lock(&hostname_mtx);
- bcopy(tmpdomainname, V_domainname, MAXHOSTNAMELEN);
- mtx_unlock(&hostname_mtx);
+ sx_slock(&allprison_lock);
+ while (!(pr->pr_flags & PR_HOST))
+ pr = pr->pr_parent;
+ mtx_lock(&pr->pr_mtx);
+ pr->pr_hostid = tmpid;
+ FOREACH_PRISON_DESCENDANT_LOCKED(pr, cpr, descend)
+ if (cpr->pr_flags & PR_HOST)
+ descend = 0;
+ else
+ cpr->pr_hostid = tmpid;
+ mtx_unlock(&pr->pr_mtx);
+ sx_sunlock(&allprison_lock);
}
return (error);
}
-SYSCTL_PROC(_kern, KERN_NISDOMAINNAME, domainname, CTLTYPE_STRING|CTLFLAG_RW,
- 0, 0, sysctl_domainname, "A", "Name of the current YP/NIS domain");
-
-u_long hostid;
-SYSCTL_ULONG(_kern, KERN_HOSTID, hostid, CTLFLAG_RW, &hostid, 0, "Host ID");
-char hostuuid[64] = "00000000-0000-0000-0000-000000000000";
-SYSCTL_STRING(_kern, KERN_HOSTUUID, hostuuid, CTLFLAG_RW, hostuuid,
- sizeof(hostuuid), "Host UUID");
+SYSCTL_PROC(_kern, KERN_HOSTID, hostid,
+ CTLTYPE_ULONG | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
+ NULL, 0, sysctl_hostid, "LU", "Host ID");
SYSCTL_NODE(_kern, OID_AUTO, features, CTLFLAG_RD, 0, "Kernel Features");
diff --git a/sys/kern/kern_shutdown.c b/sys/kern/kern_shutdown.c
index 7702ad8..3fc2e72 100644
--- a/sys/kern/kern_shutdown.c
+++ b/sys/kern/kern_shutdown.c
@@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$");
#include <sys/conf.h>
#include <sys/cons.h>
#include <sys/eventhandler.h>
+#include <sys/jail.h>
#include <sys/kdb.h>
#include <sys/kernel.h>
#include <sys/kerneldump.h>
@@ -65,7 +66,6 @@ __FBSDID("$FreeBSD$");
#include <sys/smp.h> /* smp_active */
#include <sys/sysctl.h>
#include <sys/sysproto.h>
-#include <sys/vimage.h>
#include <ddb/ddb.h>
@@ -693,7 +693,7 @@ mkdumpheader(struct kerneldumpheader *kdh, char *magic, uint32_t archver,
kdh->dumplength = htod64(dumplen);
kdh->dumptime = htod64(time_second);
kdh->blocksize = htod32(blksz);
- strncpy(kdh->hostname, G_hostname, sizeof(kdh->hostname));
+ strncpy(kdh->hostname, prison0.pr_host, sizeof(kdh->hostname));
strncpy(kdh->versionstring, version, sizeof(kdh->versionstring));
if (panicstr != NULL)
strncpy(kdh->panicstring, panicstr, sizeof(kdh->panicstring));
diff --git a/sys/kern/kern_xxx.c b/sys/kern/kern_xxx.c
index e60d05e..095e3ff 100644
--- a/sys/kern/kern_xxx.c
+++ b/sys/kern/kern_xxx.c
@@ -45,7 +45,6 @@ __FBSDID("$FreeBSD$");
#include <sys/socket.h>
#include <sys/sysctl.h>
#include <sys/utsname.h>
-#include <sys/vimage.h>
#include <vm/vm_param.h>
@@ -103,9 +102,13 @@ ogethostid(td, uap)
struct thread *td;
struct ogethostid_args *uap;
{
+ size_t len = sizeof(long);
+ int name[2];
- *(long *)(td->td_retval) = hostid;
- return (0);
+ name[0] = CTL_KERN;
+ name[1] = KERN_HOSTID;
+ return (kernel_sysctl(td, name, 2, (long *)td->td_retval, &len,
+ NULL, 0, NULL, 0));
}
#endif /* COMPAT_43 */
@@ -121,15 +124,12 @@ osethostid(td, uap)
struct thread *td;
struct osethostid_args *uap;
{
- int error;
+ int name[2];
- error = priv_check(td, PRIV_SETHOSTID);
- if (error)
- return (error);
- mtx_lock(&Giant);
- hostid = uap->hostid;
- mtx_unlock(&Giant);
- return (0);
+ name[0] = CTL_KERN;
+ name[1] = KERN_HOSTID;
+ return (kernel_sysctl(td, name, 2, NULL, NULL, &uap->hostid,
+ sizeof(uap->hostid), NULL, 0));
}
int
OpenPOWER on IntegriCloud