provide KERN_URND, which extracts sizeof(int) random number from the kernel

(similar to /dev/urandom, for use within chroot jail).
This commit is contained in:
itojun 2002-07-02 17:06:17 +00:00
parent 11bb3d047b
commit 0a9d2ad2d7
2 changed files with 27 additions and 4 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_sysctl.c,v 1.108 2002/05/14 02:58:32 matt Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.109 2002/07/02 17:06:17 itojun Exp $ */
/*-
* Copyright (c) 1982, 1986, 1989, 1993
@ -43,7 +43,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_sysctl.c,v 1.108 2002/05/14 02:58:32 matt Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_sysctl.c,v 1.109 2002/07/02 17:06:17 itojun Exp $");
#include "opt_ddb.h"
#include "opt_insecure.h"
@ -51,6 +51,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_sysctl.c,v 1.108 2002/05/14 02:58:32 matt Exp $
#include "opt_pipe.h"
#include "opt_sysv.h"
#include "pty.h"
#include "rnd.h"
#include <sys/param.h>
#include <sys/systm.h>
@ -102,6 +103,10 @@ __KERNEL_RCSID(0, "$NetBSD: kern_sysctl.c,v 1.108 2002/05/14 02:58:32 matt Exp $
#include <sys/pipe.h>
#endif
#if NRND > 0
#include <sys/rnd.h>
#endif
#define PTRTOINT64(foo) ((u_int64_t)(uintptr_t)(foo))
static int sysctl_file(void *, size_t *);
@ -327,6 +332,9 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
int old_autonicetime;
int old_vnodes;
dev_t consdev;
#if NRND > 0
int v;
#endif
/* All sysctl names at this level, except for a few, are terminal. */
switch (name[0]) {
@ -568,6 +576,16 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
newp));
case KERN_MONOTONIC_CLOCK: /* XXX _POSIX_VERSION */
return (sysctl_rdint(oldp, oldlenp, newp, 200112));
case KERN_URND:
#if NRND > 0
if (rnd_extract_data(&v, sizeof(v), RND_EXTRACT_ANY) ==
sizeof(v))
return (sysctl_rdint(oldp, oldlenp, newp, v));
else
return (EIO); /*XXX*/
#else
return (EOPNOTSUPP);
#endif
default:
return (EOPNOTSUPP);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: sysctl.h,v 1.74 2002/03/20 00:23:46 christos Exp $ */
/* $NetBSD: sysctl.h,v 1.75 2002/07/02 17:06:19 itojun Exp $ */
/*
* Copyright (c) 1989, 1993
@ -180,7 +180,11 @@ struct ctlname {
#define KERN_SBMAX 58 /* int: max socket buffer size */
#define KERN_TKSTAT 59 /* tty in/out counters */
#define KERN_MONOTONIC_CLOCK 60 /* int: POSIX monotonic clock */
#define KERN_MAXID 61 /* number of valid kern ids */
#define KERN_URND 61 /* int: random integer from urandom */
#ifndef _KERNEL
#define KERN_ARND KERN_URND /* compat w/ openbsd */
#endif
#define KERN_MAXID 62 /* number of valid kern ids */
#define CTL_KERN_NAMES { \
{ 0, 0 }, \
@ -244,6 +248,7 @@ struct ctlname {
{ "sbmax", CTLTYPE_INT }, \
{ "tkstat", CTLTYPE_NODE }, \
{ "monotonic_clock", CTLTYPE_INT }, \
{ "urandom", CTLTYPE_INT }, \
}
/*