several clean ups:

- don't include eeprom support on sparc64.
	- work out if we are eeprom or openprom from the results of open()
	and/or ioctl(), rather than grovelling the kernel.
	- move all eeprom specific code to eehandlers.c
	- update manpage for sparc64 usage, remove delete -N switch

with these changes, eeprom(8) no longer needs to be setgid.
This commit is contained in:
mrg 2000-11-28 22:31:37 +00:00
parent aa77dea4c2
commit 6ce96c999f
6 changed files with 143 additions and 155 deletions

View File

@ -1,5 +1,5 @@
# from: @(#)Makefile 5.8 (Berkeley) 7/28/90 # from: @(#)Makefile 5.8 (Berkeley) 7/28/90
# $NetBSD: Makefile,v 1.8 1999/01/17 20:02:29 eeh Exp $ # $NetBSD: Makefile,v 1.9 2000/11/28 22:31:37 mrg Exp $
.if ${MACHINE} == "sun3" || ${MACHINE} == "sun3x" || ${MACHINE} == "sparc" \ .if ${MACHINE} == "sun3" || ${MACHINE} == "sun3x" || ${MACHINE} == "sparc" \
|| ${MACHINE} == "sparc64" || ${MACHINE} == "sparc64"
@ -7,16 +7,15 @@ PROG= eeprom
YPREFIX=getdate_ YPREFIX=getdate_
BINGRP= kmem SRCS= getdate.y main.c
BINMODE=2555
SRCS= eehandlers.c getdate.y main.c
.if ${MACHINE} == "sparc" || ${MACHINE} == "sparc64" .if ${MACHINE} == "sparc" || ${MACHINE} == "sparc64"
SRCS+= ophandlers.c SRCS+= ophandlers.c
DPADD= ${LIBKVM}
LDADD= -lkvm
.endif .endif
.if ${MACHINE} != "sparc64"
SRCS+= eehandlers.c
.endif
.endif .endif
MAN= eeprom.8 MAN= eeprom.8

View File

@ -1,4 +1,4 @@
/* $NetBSD: defs.h,v 1.5 2000/11/19 11:15:01 mrg Exp $ */ /* $NetBSD: defs.h,v 1.6 2000/11/28 22:31:37 mrg Exp $ */
/*- /*-
* Copyright (c) 1996 The NetBSD Foundation, Inc. * Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -94,6 +94,8 @@ struct timeb;
time_t get_date (char *, struct timeb *); time_t get_date (char *, struct timeb *);
/* Sun 3/4 EEPROM handlers. */ /* Sun 3/4 EEPROM handlers. */
void ee_action (char *, char *);
void ee_dump (void);
void ee_hwupdate (struct keytabent *, char *); void ee_hwupdate (struct keytabent *, char *);
void ee_num8 (struct keytabent *, char *); void ee_num8 (struct keytabent *, char *);
void ee_num16 (struct keytabent *, char *); void ee_num16 (struct keytabent *, char *);
@ -114,5 +116,7 @@ void ee_verifychecksums (void);
#ifdef __sparc__ #ifdef __sparc__
/* Sparc Openprom handlers. */ /* Sparc Openprom handlers. */
char *op_handler (char *, char *); char *op_handler (char *, char *);
void op_action (char *, char *);
void op_dump (void); void op_dump (void);
int check_for_openprom (void);
#endif /* __sparc__ */ #endif /* __sparc__ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: eehandlers.c,v 1.8 2000/11/19 11:15:01 mrg Exp $ */ /* $NetBSD: eehandlers.c,v 1.9 2000/11/28 22:31:37 mrg Exp $ */
/*- /*-
* Copyright (c) 1996 The NetBSD Foundation, Inc. * Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -71,6 +71,34 @@ static char err_str[BUFSIZE];
static void badval (struct keytabent *, char *); static void badval (struct keytabent *, char *);
static int doio (struct keytabent *, u_char *, ssize_t, int); static int doio (struct keytabent *, u_char *, ssize_t, int);
struct keytabent eekeytab[] = {
{ "hwupdate", 0x10, ee_hwupdate },
{ "memsize", 0x14, ee_num8 },
{ "memtest", 0x15, ee_num8 },
{ "scrsize", 0x16, ee_screensize },
{ "watchdog_reboot", 0x17, ee_truefalse },
{ "default_boot", 0x18, ee_truefalse },
{ "bootdev", 0x19, ee_bootdev },
{ "kbdtype", 0x1e, ee_kbdtype },
{ "console", 0x1f, ee_constype },
{ "keyclick", 0x21, ee_truefalse },
{ "diagdev", 0x22, ee_bootdev },
{ "diagpath", 0x28, ee_diagpath },
{ "columns", 0x50, ee_num8 },
{ "rows", 0x51, ee_num8 },
{ "ttya_use_baud", 0x58, ee_truefalse },
{ "ttya_baud", 0x59, ee_num16 },
{ "ttya_no_rtsdtr", 0x5b, ee_truefalse },
{ "ttyb_use_baud", 0x60, ee_truefalse },
{ "ttyb_baud", 0x61, ee_num16 },
{ "ttyb_no_rtsdtr", 0x63, ee_truefalse },
{ "banner", 0x68, ee_banner },
{ "secure", 0, ee_notsupp },
{ "bad_login", 0, ee_notsupp },
{ "password", 0, ee_notsupp },
{ NULL, 0, ee_notsupp },
};
#define BARF(kt) { \ #define BARF(kt) { \
badval((kt), arg); \ badval((kt), arg); \
++eval; \ ++eval; \
@ -91,6 +119,32 @@ static int doio (struct keytabent *, u_char *, ssize_t, int);
return; \ return; \
} }
void
ee_action(keyword, arg)
char *keyword, *arg;
{
struct keytabent *ktent;
for (ktent = eekeytab; ktent->kt_keyword != NULL; ++ktent) {
if (strcmp(ktent->kt_keyword, keyword) == 0) {
(*ktent->kt_handler)(ktent, arg);
return;
}
}
warnx("unknown keyword %s", keyword);
++eval;
}
void
ee_dump()
{
struct keytabent *ktent;
for (ktent = eekeytab; ktent->kt_keyword != NULL; ++ktent)
(*ktent->kt_handler)(ktent, NULL);
}
void void
ee_hwupdate(ktent, arg) ee_hwupdate(ktent, arg)
struct keytabent *ktent; struct keytabent *ktent;

View File

@ -1,4 +1,4 @@
.\" $NetBSD: eeprom.8,v 1.4 2000/11/07 06:43:36 lukem Exp $ .\" $NetBSD: eeprom.8,v 1.5 2000/11/28 22:31:37 mrg Exp $
.\" .\"
.\" Copyright (c) 1996 The NetBSD Foundation, Inc. .\" Copyright (c) 1996 The NetBSD Foundation, Inc.
.\" All rights reserved. .\" All rights reserved.
@ -34,7 +34,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE. .\" POSSIBILITY OF SUCH DAMAGE.
.\" .\"
.Dd May 25, 1995 .Dd November 19, 2000
.Dt EEPROM 8 .Dt EEPROM 8
.Os .Os
.Sh NAME .Sh NAME
@ -51,14 +51,13 @@
.Li = Ns Ar value .Li = Ns Ar value
.Oc ... .Oc ...
.Oc .Oc
.Sh SPARC SYNOPSIS .Sh SPARC and SPARC64 SYNOPSIS
.Nm "" .Nm ""
.Op Fl .Op Fl
.Op Fl c .Op Fl c
.Op Fl f Ar device .Op Fl f Ar device
.Op Fl i .Op Fl i
.Op Fl v .Op Fl v
.Op Fl N Ar system
.Oo .Oo
.Ar field Ns Oo .Ar field Ns Oo
.Li = Ns Ar value .Li = Ns Ar value
@ -107,12 +106,11 @@ error when used on a Sun 3:
.It Fl v .It Fl v
On systems with an OpenProm, be verbose when setting a value. Systems On systems with an OpenProm, be verbose when setting a value. Systems
with an EEPROM are always verbose. with an EEPROM are always verbose.
.It Fl N Ar system
Use the system image
.Ar system
instead of the default
.Pa /netbsd .
.El .El
.Pp
The
.Fl v
option is also present on sparc64 systems.
.Sh FIELDS AND VALUES .Sh FIELDS AND VALUES
The following fields and values are for systems with an EEPROM: The following fields and values are for systems with an EEPROM:
.Bl -tag -width "watchdog_reboot " .Bl -tag -width "watchdog_reboot "

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.11 2000/11/19 11:15:01 mrg Exp $ */ /* $NetBSD: main.c,v 1.12 2000/11/28 22:31:37 mrg Exp $ */
/*- /*-
* Copyright (c) 1996 The NetBSD Foundation, Inc. * Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -40,7 +40,7 @@
#ifndef lint #ifndef lint
__COPYRIGHT( __COPYRIGHT(
"@(#) Copyright (c) 1996 The NetBSD Foundation, Inc. All rights reserved."); "@(#) Copyright (c) 1996 The NetBSD Foundation, Inc. All rights reserved.");
__RCSID("$NetBSD: main.c,v 1.11 2000/11/19 11:15:01 mrg Exp $"); __RCSID("$NetBSD: main.c,v 1.12 2000/11/28 22:31:37 mrg Exp $");
#endif #endif
#include <sys/param.h> #include <sys/param.h>
@ -49,63 +49,25 @@ __RCSID("$NetBSD: main.c,v 1.11 2000/11/19 11:15:01 mrg Exp $");
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#ifdef __sparc__
#include <fcntl.h>
#include <kvm.h>
#include <limits.h>
#include <nlist.h>
#include <machine/openpromio.h>
struct nlist nl[] = {
{ "_cputyp" },
#define SYM_CPUTYP 0
{ NULL },
};
static char *system = NULL;
#endif /* __sparc__ */
#include <machine/eeprom.h> #include <machine/eeprom.h>
#include "defs.h" #include "defs.h"
#include "pathnames.h" #include "pathnames.h"
struct keytabent eekeytab[] = { #if defined(__sparc__)
{ "hwupdate", 0x10, ee_hwupdate }, # define USE_OPENPROM
{ "memsize", 0x14, ee_num8 }, # if defined(__arch64__)
{ "memtest", 0x15, ee_num8 }, # define ee_action(a,b)
{ "scrsize", 0x16, ee_screensize }, # define ee_dump()
{ "watchdog_reboot", 0x17, ee_truefalse }, # define ee_updatechecksums() (void)0
{ "default_boot", 0x18, ee_truefalse }, # define check_for_openprom() 1
{ "bootdev", 0x19, ee_bootdev }, # endif
{ "kbdtype", 0x1e, ee_kbdtype }, #endif
{ "console", 0x1f, ee_constype },
{ "keyclick", 0x21, ee_truefalse },
{ "diagdev", 0x22, ee_bootdev },
{ "diagpath", 0x28, ee_diagpath },
{ "columns", 0x50, ee_num8 },
{ "rows", 0x51, ee_num8 },
{ "ttya_use_baud", 0x58, ee_truefalse },
{ "ttya_baud", 0x59, ee_num16 },
{ "ttya_no_rtsdtr", 0x5b, ee_truefalse },
{ "ttyb_use_baud", 0x60, ee_truefalse },
{ "ttyb_baud", 0x61, ee_num16 },
{ "ttyb_no_rtsdtr", 0x63, ee_truefalse },
{ "banner", 0x68, ee_banner },
{ "secure", 0, ee_notsupp },
{ "bad_login", 0, ee_notsupp },
{ "password", 0, ee_notsupp },
{ NULL, 0, ee_notsupp },
};
int main (int, char *[]); int main (int, char *[]);
static void action (char *); static void action (char *);
static void dump_prom (void); static void dump_prom (void);
static void usage (void); static void usage (void);
#ifdef __sparc__
static int getcputype (void);
#endif /* __sparc__ */
char *path_eeprom = _PATH_EEPROM; char *path_eeprom = _PATH_EEPROM;
char *path_openprom = _PATH_OPENPROM; char *path_openprom = _PATH_OPENPROM;
@ -115,8 +77,10 @@ int update_checksums = 0;
int cksumfail = 0; int cksumfail = 0;
u_short writecount; u_short writecount;
int eval = 0; int eval = 0;
int use_openprom = 0; #ifdef USE_OPENPROM
int verbose = 0; int verbose = 0;
int use_openprom;
#endif
extern char *__progname; extern char *__progname;
@ -127,11 +91,11 @@ main(argc, argv)
{ {
int ch, do_stdin = 0; int ch, do_stdin = 0;
char *cp, line[BUFSIZE]; char *cp, line[BUFSIZE];
#ifdef __sparc__ #ifdef USE_OPENPROM
char *optstring = "-cf:ivN:"; char *optstring = "-cf:iv";
#else #else
char *optstring = "-cf:i"; char *optstring = "-cf:i";
#endif /* __sparc__ */ #endif /* USE_OPENPROM */
while ((ch = getopt(argc, argv, optstring)) != -1) while ((ch = getopt(argc, argv, optstring)) != -1)
switch (ch) { switch (ch) {
@ -150,16 +114,12 @@ main(argc, argv)
case 'i': case 'i':
ignore_checksum = 1; ignore_checksum = 1;
break; break;
#ifdef __sparc__
#ifdef USE_OPENPROM
case 'v': case 'v':
verbose = 1; verbose = 1;
break; break;
#endif /* USE_OPENPROM */
case 'N':
system = optarg;
break;
#endif /* __sparc__ */
case '?': case '?':
default: default:
@ -168,16 +128,9 @@ main(argc, argv)
argc -= optind; argc -= optind;
argv += optind; argv += optind;
#ifdef __sparc__ #ifdef USE_OPENPROM
/* use_openprom = check_for_openprom();
* Discard setgid setgid privileges if not the running kernel so #endif /* USE_OPENPROM */
* that bad guys can't print interesting stuff from kernel memory.
*/
if (system != NULL)
setgid(getgid());
if (getcputype() != CPU_SUN4)
use_openprom = 1;
#endif /* __sparc__ */
if (use_openprom == 0) { if (use_openprom == 0) {
ee_verifychecksums(); ee_verifychecksums();
@ -208,7 +161,9 @@ main(argc, argv)
} }
} }
#ifdef USE_OPENPROM
if (use_openprom == 0) if (use_openprom == 0)
#endif /* USE_OPENPROM */
if (update_checksums) { if (update_checksums) {
++writecount; ++writecount;
ee_updatechecksums(); ee_updatechecksums();
@ -217,36 +172,6 @@ main(argc, argv)
exit(eval + cksumfail); exit(eval + cksumfail);
} }
#ifdef __sparc__
#define KVM_ABORT(kd, str) { \
(void)kvm_close((kd)); \
errx(1, "%s: %s", (str), kvm_geterr((kd))); \
}
static int
getcputype()
{
char errbuf[_POSIX2_LINE_MAX];
int cputype;
kvm_t *kd;
memset(errbuf, 0, sizeof(errbuf));
if ((kd = kvm_openfiles(system, NULL, NULL, O_RDONLY, errbuf)) == NULL)
errx(1, "can't open kvm: %s", errbuf);
if (kvm_nlist(kd, nl))
KVM_ABORT(kd, "can't read symbol table");
if (kvm_read(kd, nl[SYM_CPUTYP].n_value, (char *)&cputype,
sizeof(cputype)) != sizeof(cputype))
KVM_ABORT(kd, "can't determine cpu type");
(void)kvm_close(kd);
return (cputype);
}
#endif /* __sparc__ */
/* /*
* Separate the keyword from the argument (if any), find the keyword in * Separate the keyword from the argument (if any), find the keyword in
* the table, and call the corresponding handler function. * the table, and call the corresponding handler function.
@ -256,35 +181,17 @@ action(line)
char *line; char *line;
{ {
char *keyword, *arg; char *keyword, *arg;
struct keytabent *ktent;
keyword = strdup(line); keyword = strdup(line);
if ((arg = strrchr(keyword, '=')) != NULL) if ((arg = strrchr(keyword, '=')) != NULL)
*arg++ = '\0'; *arg++ = '\0';
#ifdef __sparc__ #ifdef USE_OPENPROM
if (use_openprom) { if (use_openprom)
char *cp; op_action(keyword, arg);
/* else
* The whole point of the Openprom is that one #endif /* USE_OPENPROM */
* isn't required to know the keywords. With this ee_action(keyword, arg);
* in mind, we just dump the whole thing off to
* the generic op_handler.
*/
if ((cp = op_handler(keyword, arg)) != NULL)
warnx("%s", cp);
return;
} else
#endif /* __sparc__ */
for (ktent = eekeytab; ktent->kt_keyword != NULL; ++ktent) {
if (strcmp(ktent->kt_keyword, keyword) == 0) {
(*ktent->kt_handler)(ktent, arg);
return;
}
}
warnx("unknown keyword %s", keyword);
++eval;
} }
/* /*
@ -293,31 +200,28 @@ action(line)
static void static void
dump_prom() dump_prom()
{ {
struct keytabent *ktent;
#ifdef __sparc__ #ifdef USE_OPENPROM
if (use_openprom) { if (use_openprom)
/* /*
* We have a special dump routine for this. * We have a special dump routine for this.
*/ */
op_dump(); op_dump();
} else else
#endif /* __sparc__ */ #endif /* USE_OPENPROM */
for (ktent = eekeytab; ktent->kt_keyword != NULL; ++ktent) ee_dump();
(*ktent->kt_handler)(ktent, NULL);
} }
static void static void
usage() usage()
{ {
#ifdef __sparc__ #ifdef USE_OPENPROM
fprintf(stderr, "usage: %s %s %s\n", __progname, fprintf(stderr, "usage: %s %s\n", __progname,
"[-] [-c] [-f device] [-i] [-v]", "[-] [-c] [-f device] [-i] [-v] [field[=value] ...]");
"[-N system] [field[=value] ...]");
#else #else
fprintf(stderr, "usage: %s %s\n", __progname, fprintf(stderr, "usage: %s %s\n", __progname,
"[-] [-c] [-f device] [-i] [field[=value] ...]"); "[-] [-c] [-f device] [-i] [field[=value] ...]");
#endif /* __sparc__ */ #endif /* __us */
exit(1); exit(1);
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: ophandlers.c,v 1.7 2000/11/19 11:15:01 mrg Exp $ */ /* $NetBSD: ophandlers.c,v 1.8 2000/11/28 22:31:37 mrg Exp $ */
/*- /*-
* Copyright (c) 1996 The NetBSD Foundation, Inc. * Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -76,6 +76,35 @@ static struct extabent opextab[] = {
return (err_str); \ return (err_str); \
}; };
void
op_action(keyword, arg)
char *keyword, *arg;
{
char *cp;
if ((cp = op_handler(keyword, arg)) != NULL)
warnx("%s", cp);
return;
}
#if defined(__sparc__) && !defined(__arch64__)
int
check_for_openprom()
{
int fd, rv, optnode;
/* if we can't open it, obviously we can't use it. */
if ((fd = open(path_openprom, O_RDONLY)) < 0)
return (0);
/* check for the presence of OpenFirmware with OPIOCGETOPTNODE */
rv = ioctl(fd, OPIOCGETOPTNODE, (char *)&optnode);
close (fd);
return (rv == 0);
}
#endif
char * char *
op_handler(keyword, arg) op_handler(keyword, arg)
char *keyword, *arg; char *keyword, *arg;