diff options
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/luna88k/stand/boot/Makefile | 4 | ||||
-rw-r--r-- | sys/arch/luna88k/stand/boot/boot.c | 60 | ||||
-rw-r--r-- | sys/arch/luna88k/stand/boot/init_main.c | 4 |
3 files changed, 60 insertions, 8 deletions
diff --git a/sys/arch/luna88k/stand/boot/Makefile b/sys/arch/luna88k/stand/boot/Makefile index 4504605e875..03eca50eb65 100644 --- a/sys/arch/luna88k/stand/boot/Makefile +++ b/sys/arch/luna88k/stand/boot/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.5 2013/11/12 14:04:15 aoyama Exp $ +# $OpenBSD: Makefile,v 1.6 2014/02/23 20:01:04 miod Exp $ # $NetBSD: Makefile,v 1.9 2013/01/22 15:48:40 tsutsui Exp $ # @(#)Makefile 8.2 (Berkeley) 8/15/93 @@ -43,7 +43,7 @@ PROG= boot ### find out what to use for libkern .PATH: ${S}/lib/libkern -SRCS+= memcpy.c strlen.c +SRCS+= memcpy.c strlcat.c strlcpy.c strlen.c SRCS+= muldi3.c negdi2.c ashrdi3.c ### find out what to use for libsa diff --git a/sys/arch/luna88k/stand/boot/boot.c b/sys/arch/luna88k/stand/boot/boot.c index 4cc8cade039..51567f45694 100644 --- a/sys/arch/luna88k/stand/boot/boot.c +++ b/sys/arch/luna88k/stand/boot/boot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: boot.c,v 1.3 2014/01/29 11:22:13 aoyama Exp $ */ +/* $OpenBSD: boot.c,v 1.4 2014/02/23 20:01:04 miod Exp $ */ /* $NetBSD: boot.c,v 1.3 2013/03/05 15:34:53 tsutsui Exp $ */ /* @@ -78,13 +78,19 @@ #include <sys/param.h> #include <sys/reboot.h> -#include <sys/exec.h> +#include <sys/stat.h> +#define _KERNEL +#include <sys/fcntl.h> +#undef _KERNEL + +#include <lib/libkern/libkern.h> #include <luna88k/stand/boot/samachdep.h> #include <luna88k/stand/boot/status.h> #include <lib/libsa/loadfile.h> int howto; +int loadrandom(const char *, char *, size_t); #if 0 static int get_boot_device(const char *, int *, int *, int *); #endif @@ -93,7 +99,7 @@ void (*cpu_boot)(uint32_t, uint32_t); uint32_t cpu_bootarg1; uint32_t cpu_bootarg2; -char rnddata[BOOTRANDOM_MAX]; /* XXX dummy */ +char rnddata[BOOTRANDOM_MAX]; #if 0 int @@ -139,7 +145,9 @@ error: int boot(int argc, char *argv[]) { - char *line; + char *line, *lparen, *rparen; + char rndpath[MAXPATHLEN]; + static int rnd_loaded = 0; if (argc < 2) line = default_file; @@ -148,6 +156,27 @@ boot(int argc, char *argv[]) printf("Booting %s\n", line); + /* + * Try and load randomness from the boot device. + */ + if (rnd_loaded == 0) { + lparen = strchr(line, '('); + if (lparen != NULL) + rparen = strchr(line, ')'); + else + rparen = NULL; + if (rparen != NULL && + rparen + 1 - line < sizeof rndpath) { + rparen++; + memcpy(rndpath, line, rparen - line); + rndpath[rparen - line] = '\0'; + strlcat(rndpath, BOOTRANDOM, sizeof rndpath); + } else + strlcpy(rndpath, BOOTRANDOM, sizeof rndpath); + + rnd_loaded = loadrandom(rndpath, rnddata, sizeof(rnddata)); + } + return bootunix(line); } @@ -187,3 +216,26 @@ bootunix(char *line) return ST_ERROR; } + +int +loadrandom(const char *name, char *buf, size_t buflen) +{ + struct stat sb; + int fd; + int rc = 0; + + fd = open(name, O_RDONLY); + if (fd == -1) { + if (errno != EPERM) + printf("cannot open %s: %s\n", name, strerror(errno)); + return 0; + } + if (fstat(fd, &sb) == -1 || sb.st_uid != 0 || !S_ISREG(sb.st_mode) || + (sb.st_mode & (S_IWOTH|S_IROTH))) + goto fail; + (void) read(fd, buf, buflen); + rc = 1; +fail: + close(fd); + return rc; +} diff --git a/sys/arch/luna88k/stand/boot/init_main.c b/sys/arch/luna88k/stand/boot/init_main.c index c5fff01ea82..f3d0a79793e 100644 --- a/sys/arch/luna88k/stand/boot/init_main.c +++ b/sys/arch/luna88k/stand/boot/init_main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init_main.c,v 1.5 2013/11/01 07:43:09 miod Exp $ */ +/* $OpenBSD: init_main.c,v 1.6 2014/02/23 20:01:04 miod Exp $ */ /* $NetBSD: init_main.c,v 1.6 2013/03/05 15:34:53 tsutsui Exp $ */ /* @@ -181,7 +181,7 @@ main(void) nplane = get_plane_numbers(); cninit(); - printf("\nOpenBSD/" MACHINE " (%s) boot 0.3\n\n", machstr); + printf("\nOpenBSD/" MACHINE " (%s) boot 0.4\n\n", machstr); #ifdef SUPPORT_ETHERNET try_bootp = 1; |