Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys provide KERN_URND, which extracts sizeof(int) random num...
details: https://anonhg.NetBSD.org/src/rev/53d3137ba94b
branches: trunk
changeset: 533506:53d3137ba94b
user: itojun <itojun%NetBSD.org@localhost>
date: Tue Jul 02 17:06:17 2002 +0000
description:
provide KERN_URND, which extracts sizeof(int) random number from the kernel
(similar to /dev/urandom, for use within chroot jail).
diffstat:
sys/kern/kern_sysctl.c | 22 ++++++++++++++++++++--
sys/sys/sysctl.h | 9 +++++++--
2 files changed, 27 insertions(+), 4 deletions(-)
diffs (94 lines):
diff -r 53bf2ed335b6 -r 53d3137ba94b sys/kern/kern_sysctl.c
--- a/sys/kern/kern_sysctl.c Tue Jul 02 16:22:28 2002 +0000
+++ b/sys/kern/kern_sysctl.c Tue Jul 02 17:06:17 2002 +0000
@@ -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 @@
#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 @@
#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 @@
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 @@
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);
}
diff -r 53bf2ed335b6 -r 53d3137ba94b sys/sys/sysctl.h
--- a/sys/sys/sysctl.h Tue Jul 02 16:22:28 2002 +0000
+++ b/sys/sys/sysctl.h Tue Jul 02 17:06:17 2002 +0000
@@ -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 @@
#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 @@
{ "sbmax", CTLTYPE_INT }, \
{ "tkstat", CTLTYPE_NODE }, \
{ "monotonic_clock", CTLTYPE_INT }, \
+ { "urandom", CTLTYPE_INT }, \
}
/*
Home |
Main Index |
Thread Index |
Old Index