implement kern.arandom properly, instead of lying about it and only filling
the first 4 bytes of the array with random data.
This commit is contained in:
parent
09012c9606
commit
3f78162b5c
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: init_sysctl.c,v 1.90 2006/10/29 22:34:07 christos Exp $ */
|
||||
/* $NetBSD: init_sysctl.c,v 1.91 2006/11/01 22:27:43 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2003 The NetBSD Foundation, Inc.
|
||||
|
@ -37,7 +37,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.90 2006/10/29 22:34:07 christos Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.91 2006/11/01 22:27:43 christos Exp $");
|
||||
|
||||
#include "opt_sysv.h"
|
||||
#include "opt_multiprocessor.h"
|
||||
|
@ -181,6 +181,7 @@ static int sysctl_kern_maxptys(SYSCTLFN_PROTO);
|
|||
#endif /* NPTY > 0 */
|
||||
static int sysctl_kern_sbmax(SYSCTLFN_PROTO);
|
||||
static int sysctl_kern_urnd(SYSCTLFN_PROTO);
|
||||
static int sysctl_kern_arnd(SYSCTLFN_PROTO);
|
||||
static int sysctl_kern_lwp(SYSCTLFN_PROTO);
|
||||
static int sysctl_kern_forkfsleep(SYSCTLFN_PROTO);
|
||||
static int sysctl_kern_root_partition(SYSCTLFN_PROTO);
|
||||
|
@ -682,6 +683,12 @@ SYSCTL_SETUP(sysctl_kern_setup, "sysctl kern subtree setup")
|
|||
SYSCTL_DESCR("Random integer value"),
|
||||
sysctl_kern_urnd, 0, NULL, 0,
|
||||
CTL_KERN, KERN_URND, CTL_EOL);
|
||||
sysctl_createv(clog, 0, NULL, NULL,
|
||||
CTLFLAG_PERMANENT,
|
||||
CTLTYPE_INT, "arandom",
|
||||
SYSCTL_DESCR("n bytes of random data"),
|
||||
sysctl_kern_arnd, 0, NULL, 0,
|
||||
CTL_KERN, KERN_ARND, CTL_EOL);
|
||||
sysctl_createv(clog, 0, NULL, NULL,
|
||||
CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
|
||||
CTLTYPE_INT, "labelsector",
|
||||
|
@ -1852,6 +1859,35 @@ sysctl_kern_urnd(SYSCTLFN_ARGS)
|
|||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* sysctl helper routine for kern.arandom node. picks a random number
|
||||
* for you.
|
||||
*/
|
||||
static int
|
||||
sysctl_kern_arnd(SYSCTLFN_ARGS)
|
||||
{
|
||||
#if NRND > 0
|
||||
int error;
|
||||
void *v;
|
||||
struct sysctlnode node = *rnode;
|
||||
|
||||
if (*oldlenp == 0)
|
||||
return 0;
|
||||
if (*oldlenp > 8192)
|
||||
return E2BIG;
|
||||
|
||||
v = malloc(*oldlenp, M_TEMP, M_WAITOK);
|
||||
|
||||
arc4randbytes(v, *oldlenp);
|
||||
node.sysctl_data = v;
|
||||
node.sysctl_size = *oldlenp;
|
||||
error = sysctl_lookup(SYSCTLFN_CALL(&node));
|
||||
free(v, M_TEMP);
|
||||
return error;
|
||||
#else
|
||||
return (EOPNOTSUPP);
|
||||
#endif
|
||||
}
|
||||
/*
|
||||
* sysctl helper routine to do kern.lwp.* work.
|
||||
*/
|
||||
|
@ -2990,9 +3026,6 @@ fill_kproc2(struct proc *p, struct kinfo_proc2 *ki)
|
|||
strncpy(ki->p_login, p->p_session->s_login,
|
||||
min(sizeof ki->p_login - 1, sizeof p->p_session->s_login));
|
||||
|
||||
strncpy(ki->p_ename, p->p_emul->e_name, sizeof(ki->p_ename));
|
||||
ki->p_ename[sizeof(ki->p_ename) - 1] = '\0';
|
||||
|
||||
ki->p_nlwps = p->p_nlwps;
|
||||
ki->p_nrlwps = p->p_nrlwps;
|
||||
ki->p_realflag = p->p_flag;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: sysctl.h,v 1.161 2006/10/29 22:34:07 christos Exp $ */
|
||||
/* $NetBSD: sysctl.h,v 1.162 2006/11/01 22:27:43 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
|
@ -251,9 +251,6 @@ struct ctlname {
|
|||
#define KERN_TKSTAT 59 /* tty in/out counters */
|
||||
#define KERN_MONOTONIC_CLOCK 60 /* int: POSIX monotonic clock */
|
||||
#define KERN_URND 61 /* int: random integer from urandom */
|
||||
#ifndef _KERNEL
|
||||
#define KERN_ARND KERN_URND /* compat w/ openbsd */
|
||||
#endif
|
||||
#define KERN_LABELSECTOR 62 /* int: disklabel sector */
|
||||
#define KERN_LABELOFFSET 63 /* int: offset of label within sector */
|
||||
#define KERN_LWP 64 /* struct: lwp entries */
|
||||
|
@ -273,7 +270,8 @@ struct ctlname {
|
|||
#define KERN_VERIEXEC 78 /* node: verified exec */
|
||||
#define KERN_CP_ID 79 /* struct: cpu id numbers */
|
||||
#define KERN_HARDCLOCK_TICKS 80 /* int: number of hardclock ticks */
|
||||
#define KERN_MAXID 81 /* number of valid kern ids */
|
||||
#define KERN_ARND 81 /* void *buf, size_t siz random */
|
||||
#define KERN_MAXID 82 /* number of valid kern ids */
|
||||
|
||||
|
||||
#define CTL_KERN_NAMES { \
|
||||
|
@ -358,6 +356,7 @@ struct ctlname {
|
|||
{ "veriexec", CTLTYPE_NODE }, \
|
||||
{ "cp_id", CTLTYPE_STRUCT }, \
|
||||
{ "hardclock_ticks", CTLTYPE_INT }, \
|
||||
{ "arandom", CTLTYPE_STRUCT }, \
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -439,7 +438,6 @@ struct kinfo_proc {
|
|||
#define KI_MAXCOMLEN 24 /* extra for 8 byte alignment */
|
||||
#define KI_WMESGLEN 8
|
||||
#define KI_MAXLOGNAME 24 /* extra for 8 byte alignment */
|
||||
#define KI_MAXEMULLEN 16
|
||||
|
||||
#define KI_NOCPU (~(uint64_t)0)
|
||||
|
||||
|
@ -562,7 +560,6 @@ struct kinfo_proc2 {
|
|||
uint64_t p_realstat; /* LONG: non-LWP process status */
|
||||
uint32_t p_svuid; /* UID_T: saved user id */
|
||||
uint32_t p_svgid; /* GID_T: saved group id */
|
||||
char p_ename[KI_MAXEMULLEN]; /* emulation name */
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue