diff --git a/usr.sbin/eeprom/eeprom.8 b/usr.sbin/eeprom/eeprom.8 index 81cb2d36e930..e132da98b7e6 100644 --- a/usr.sbin/eeprom/eeprom.8 +++ b/usr.sbin/eeprom/eeprom.8 @@ -1,707 +1,700 @@ .\" Copyright (c) 1996 The NetBSD Foundation, Inc. .\" Copyright (c) 2004 Marius Strobl .\" All rights reserved. .\" .\" This code is derived from software contributed to The NetBSD Foundation .\" by Jason R. Thorpe. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the NetBSD -.\" Foundation, Inc. and its contributors. -.\" 4. Neither the name of The NetBSD Foundation nor the names of its -.\" contributors may be used to endorse or promote products derived -.\" from this software without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" .\" from: NetBSD: eeprom.8,v 1.11 2003/03/31 01:31:39 perry Exp .\" $FreeBSD$ .\" .Dd September 1, 2006 .Dt EEPROM 8 sparc64 .Os .Sh NAME .Nm eeprom .Nd "display or modify contents of the EEPROM or NVRAM" .Sh SYNOPSIS .Nm .Fl a .Nm .Op Fl .Ar name Ns Op = Ns Ar value .Ar ... .Sh DESCRIPTION The .Nm utility provides an interface for displaying and changing the system's configuration variables contained in EEPROM or NVRAM. In the first synopsis form, all available configuration variables and their current values are printed. In the second form, only the variable selected by .Ar name and its value is printed or changed if .Ar name is followed by .Ql = and a .Ar value . .Pp The following options are available: .Bl -tag -width indent .It Fl Commands for displaying or changing variables are taken from stdin, allowing one .Ar name or one .Ar name and .Ar value pair per line. The output is printed on stdout. .It Fl a Print all available configuration variables and their current values. .El .Sh VARIABLES AND VALUES Below are variables and values that one is likely to find on a system equipped with OpenBoot 3.x and Open Firmware respectively. .Pp Note: the attempt to set a variable to an illegal value results in the Open Firmware setting it to some legal value instead. The .Nm utility will detect this, try to recover the previous value of the variable and issue a warning telling that the requested value could not be set. .Bl -tag -width ".Va last-hardware-update" .It Va auto-boot? If .Dq Li true , the system will try to boot automatically from the devices listed in .Va boot-device and .Va diag-device respectively, using the command specified in .Va boot-command at power-up. Default: .Dq Li true . .It Va auto-boot-retry? If set to .Dq Li true and .Va auto-boot? is also set to .Dq Li true , the system will try to boot from the specified boot devices forever. Default: .Dq Li false . .It Va ansi-terminal? If .Dq Li false , .Tn ANSI escape sequences are not interpreted by the terminal emulator. Default: .Dq Li true . .It Va boot-command Command executed when .Va auto-boot? is set to .Dq Li true . Default: .Dq Li boot . .It Va boot-device Default device to boot from if .Va diag-switch? is set to .Dq Li false . Takes one or more device aliases or device paths. The boot devices are sequentially tried to boot from, beginning with the first one specified. Default: .Dq Li "net disk" . .It Va cpci-probe-list Digits in the format .Dq Li 0,1,2 specifying in which order to probe the devices on the CompactPCI bus at power-up. Default: system-dependent. .It Va boot-file Default arguments for boot when .Va diag-switch? is set to .Dq Li false . When empty, the secondary boot loader will choose the file to boot. Default: empty string. .It Va diag-device Like .Va boot-device . Used when .Va diag-switch? is set to .Dq Li true . Default: .Dq Li net . .It Va diag-file Like .Va boot-file . Used when .Va diag-switch? is set to .Dq Li true . Default: empty string. .It Va diag-level Level of diagnostics to run when .Va diag-switch? is set to .Dq Li true . Possible values are .Dq Li max , .Dq Li menus , .Dq Li min and .Dq Li off (depending on the system model). When set to .Dq Li off , the Power-On Self Test (POST) is not run. The other values are interpreted by the POST. Default: .Dq Li min or .Dq Li max (system-dependent). .It Va diag-switch? If .Dq Li true , the system will boot and run in diagnostic mode. Default: .Dq Li false or .Dq Li true (system-dependent). .It Va env-monitor Enables or disables the Advanced System Monitoring (ASM). Possible values are .Dq Li enabled and .Dq Li disabled . Default: .Dq Li enabled . .It Va fcode-debug? Used for debugging FCode programs. If set to .Dq Li true , names of additional FCodes are registered in the Forth dictionary. Default: .Dq Li false . .It Va hardware-revision A string describing the system hardware version. Default: system-dependent. .It Va input-device One of the strings .Dq Li keyboard , .Dq Li ttya , or .Dq Li ttyb , specifying the default console input device. Default: .Dq Li keyboard or .Dq Li ttya (system-dependent). .It Va keyboard-click? If set to .Dq Li true , the keys click annoyingly. Default: .Dq Li false . .It Va keymap Keymap for a custom keyboard. Default: empty string. .It Va last-hardware-update Similar to .Va hardware-revision , describing when the hardware was last updated. Default: system-dependent. .It Va last-poweroff-cause Cause of the last power-off. Used internally by the OpenBoot PROM. Default: .Dq Li 0 . .It Va load-base Default address where client programs are loaded to. It is unlikely that this value should ever be changed. Default: .Dq Li 16384 . .It Va local-mac-address? If set to .Dq Li false , all Ethernet devices with FCode will use the system default MAC address. If set to .Dq Li true , Ethernet devices with FCode that contains a unique MAC address will use it rather than the system's default MAC address. Default: .Dq Li false . .Pp Ethernet devices with FCode include those supported by .Xr dc 4 , .Xr gem 4 and .Xr hme 4 . Please see the respective manual page for further information. .It Va mfg-mode Manufacture test mode interpreted by the POST. Possible values are .Dq Li chamber and .Dq Li off . Default: .Dq Li off . .It Va mfg-switch? If set to .Dq Li true , manufacturing tests are repeated until stopped by pressing STOP-A. Default: .Dq Li off . .It Va net-timeout If set to .Dq Li 0 , the system will try to boot forever when the boot device used is a network device. Any non-zero value is interpreted as minutes to try a network boot. Default: .Dq Li 0 . .It Va nvramrc Contents of the NVRAMRC. Default: empty string. .Pp While .Va nvramrc can be set using .Nm , it is preferred to use .Ic nvedit in the boot monitor instead. .It Va oem-banner A string displayed at power-up, rather than the default banner. Used when .Va oem-banner? is set to .Dq Li true . Default: system-dependent. .It Va oem-banner? If set to .Dq Li true , the string stored in .Va oem-banner is displayed at power-up rather than the default banner. Default: system-dependent. .It Va oem-logo A logo displayed at power-up when .Va oem-logo? is set to .Dq Li true , rather than the default logo. The logo has to be 512 bytes in size, containing a 64x64-bit monochrome image in Sun Raster format without the leading 32-byte header. Default: system-dependent. .Pp To set the logo with .Nm , give the pathname of the file containing the image as the .Ar value . Using an empty .Ar value will remove the image. .It Va oem-logo? If set to .Dq Li true , the logo stored in .Va oem-logo is displayed at power-up rather than the default logo. .It Va output-device One of the strings .Dq Li screen , .Dq Li ttya , or .Dq Li ttyb , specifying the default console output device. Default: .Dq Li screen or .Dq Li ttya (system-dependent). .It Va pcia-probe-list Digits in the format .Dq Li 1,2,3 specifying in which order to probe the devices on the PCI bus A. Default: system-dependent. .It Va pcib-probe-list Like .Va pcia-probe-list , but for PCI bus B. Default: system-dependent. .It Va #power-cycles Number of power-cycles. Automatically incremented on each power-cycle. Default: system-dependent. .It Va sbus-probe-list Digits in the format .Dq Li 0123 specifying in which order to probe the SBus slots at power-up. Default: system-dependent. .It Va screen-#columns An integer specifying the screen width in characters per line. Default: .Dq Li 80 . .It Va screen-#rows An integer specifying the screen height in lines. Default: .Dq Li 34 . .It Va scsi-initiator-id The SCSI ID of SCSI controllers in the range of [0-7] or [0-f] (depending on the controller). A SCSI controller may or may not adhere to this setting, depending on its FCode and device driver. Default: .Dq Li 7 . .It Va security-#badlogins Number of incorrect password attempts when .Va security-mode is set to .Dq Li command or .Dq Li full . Default: .Dq Li 0 . .It Va security-mode Boot monitor security level. One of the three possible values .Dq Li full , .Dq Li command , or .Dq Li none . When set to .Dq Li full , all boot monitor commands except for .Ic go require the password. When set to .Dq Li command , all boot monitor commands except for .Ic boot and .Ic go require the password. When set to .Dq Li none , no password is required. Default: .Dq Li none . .Pp When .Nm is used to set .Va security-mode to .Dq Li full or .Dq Li command , you will be prompted for the password. When .Va security-mode is set to .Dq Li none , .Nm will clear the password. .It Va security-password The password used when .Va security-mode is set to .Dq Li full or .Dq Li command . The maximum length for this password is 8 characters. All characters exceeding this length will be ignored. The value displayed for .Va security-password is always an empty string, even when a password is set. Default: empty string. .Pp When .Va security-mode is set to .Dq Li full or .Dq Li command , .Nm can be used to enter a new password using any .Ar value for .Va security-password on the command line. You will be prompted by .Nm to type in the new password in this case. Trying to set .Va security-password when .Va security-mode is set to .Dq Li none using .Nm has no effect. .It Va selftest-#megs An integer specifying the number of megabytes of memory to test upon power-up when .Va diag-switch? is set to .Dq Li false . Default: .Dq Li 1 . .It Va shutdown-temperature Temperature at which the ASM issues an over-temperature shutdown. Default: system-dependent. .It Va silent-mode If set to .Dq Li true , memory test messages will not be displayed at power-up. Default: .Dq Li false . .It Va sunmon-compat? If set to .Dq Li true , the old bootROM interface will be used while in the boot monitor, rather than the OpenBoot PROM interface. Default: .Dq Li false . .It Va system-board-date Manufacturing date of the system board. Default: system-dependent. .It Va system-board-serial# Serial number of the system board. Default: system-dependent. .It Va tpe-link-test? Enable link test on 10baseT and 100baseTX Ethernet devices. Default: .Dq Li true . .It Va ttya-mode A string of five comma separated fields in the format .Dq Li 9600,8,n,1,- . The first field is the baud rate. The second field is the number of data bits. The third field is the parity; acceptable values for parity are .Ql n (none), .Ql e (even), .Ql o (odd), .Ql m (mark), and .Ql s (space). The fourth field is the number of stop bits. The fifth field is the .Dq handshake field; acceptable values are .Ql - (none), .Ql h (RTS/CTS), and .Ql s (Xon/Xoff). Default: .Dq Li 9600,8,n,1,- . .It Va ttya-ignore-cd If set to .Dq Li true , the system will ignore carrier detect. Default: .Dq Li true . .It Va ttya-rts-dtr-off If set to .Dq Li true , the system will ignore RTS/DTR. Default: .Dq Li false . .It Va ttyb-mode Like .Va ttya-mode , but for ttyb. Default: .Dq Li 9600,8,n,1,- . .It Va ttyb-ignore-cd Like .Va ttya-ignore-cd , but for ttyb. Default: .Dq Li true . .It Va ttyb-rts-dtr-off Like .Va ttya-rts-dtr-off , but for ttyb. Default: .Dq Li false . .It Va use-boot-table? Use boot table defined by the OEM. Default: system-dependent. .It Va use-nvramrc? If set to .Dq Li true , the script stored in .Va nvramrc will be executed during start-up. Default: .Dq Li false . .It Va warning-temperature Temperature at which the ASM issues an over-temperature warning. Default: system-dependent. .It Va watchdog-enable? Enables or disables the system watchdog timer. Default: .Dq Li false . .It Va watchdog-reboot? If set to .Dq Li true , the system will reboot upon terminal count of the system watchdog timer. If set to .Dq Li false , the system will fall into the boot monitor. Default: .Dq Li false . .It Va watchdog-timeout Expiry limit for the system watchdog timer. Range and unit depend on the system model. Default: system-dependent. .El .Sh EXAMPLES Print all available configuration variables and their current values: .Pp .Dl "eeprom -a" .Pp Print the current value of the .Va local-mac-address? variable: .Pp .Dl "eeprom local-mac-address\e?" .Pp Set the value of the .Va local-mac-address? variable to .Dq Li true : .Pp .Dl "eeprom local-mac-address\e?=true" .Pp Note that the .Ql \e in the above examples is used to keep the shell from interpreting the .Ql \&? . .Pp Write an image to the .Va oem-logo variable: .Pp .Dl "eeprom oem-logo=/path/to/image.raw" .Pp Remove the image from the .Va oem-logo variable again: .Pp .Dl "eeprom oem-logo=" .Pp Set the value of the .Va security-mode variable to .Dq Li full , and set the password: .Bd -literal -offset indent eeprom security-mode=full New password: Retype new password: .Ed .Pp Remember that the maximum length for the password is 8 characters. All characters exceeding this length will be ignored. .Pp Set a new password when the .Va security-mode variable is set to .Dq Li command or .Dq Li full : .Bd -literal -offset indent eeprom security-password= New password: Retype new password: .Ed .Sh SEE ALSO .Xr dc 4 , .Xr gem 4 , .Xr hme 4 , .Xr ofwdump 8 .Sh HISTORY The .Nm utility first appeared in .Bx 4.4 . It was adopted from there by .Fx 2.0 . The .Nm utility was removed from .Fx again after .Fx 2.1.7 because the utility was unused at that time. The present implementation of the .Nm utility first appeared in .Fx 5.3 . It is inspired by the .Nx .Xr eeprom 8 and SunOS/Solaris .Xr eeprom 1M utilities. .Sh AUTHORS .An -nosplit The .Nm utility uses base code from the .Nx version written by .An "Jason R. Thorpe" . The handlers for the Open Firmware .Pa /options node were written by .An "Marius Strobl" Aq marius@FreeBSD.org . The code for accessing the Open Firmware device tree is shared with the .Xr ofwdump 8 utility written by .An "Thomas Moestl" Aq tmm@FreeBSD.org . .Sh BUGS Currently, .Nm only supports systems equipped with Open Firmware and is only tested on Sun Microsystems sun4u machines. diff --git a/usr.sbin/eeprom/eeprom.c b/usr.sbin/eeprom/eeprom.c index 64018585bc7a..30c1a939567e 100644 --- a/usr.sbin/eeprom/eeprom.c +++ b/usr.sbin/eeprom/eeprom.c @@ -1,153 +1,146 @@ /*- * Copyright (c) 1996 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jason R. Thorpe. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * from: NetBSD: main.c,v 1.15 2001/02/19 23:22:42 cgd Exp */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include "ofw_options.h" static int action(char *); static void dump_config(void); static void usage(void); static void usage(void) { fprintf(stderr, "usage: eeprom -a\n" " eeprom [-] name[=value] ...\n"); exit(EX_USAGE); } int main(int argc, char *argv[]) { int do_stdin, opt; int aflag, rv; char *cp; char line[BUFSIZ]; aflag = do_stdin = 0; rv = EX_OK; while ((opt = getopt(argc, argv, "-a")) != -1) { switch (opt) { case '-': if (aflag) usage(); do_stdin = 1; break; case 'a': if (do_stdin) usage(); aflag = 1; break; case '?': default: usage(); /* NOTREACHED */ } } argc -= optind; argv += optind; if (aflag) { if (argc != 0) usage(); dump_config(); } else { if (do_stdin) { while (fgets(line, BUFSIZ, stdin) != NULL && rv == EX_OK) { if (line[0] == '\n') continue; if ((cp = strrchr(line, '\n')) != NULL) *cp = '\0'; rv = action(line); } if (ferror(stdin)) err(EX_NOINPUT, "stdin"); } else { if (argc == 0) usage(); while (argc && rv == EX_OK) { rv = action(*argv); ++argv; --argc; } } } return (rv); } static int action(char *line) { int rv; char *keyword, *arg; keyword = strdup(line); if (keyword == NULL) err(EX_OSERR, "malloc() failed"); if ((arg = strrchr(keyword, '=')) != NULL) *arg++ = '\0'; switch (rv = ofwo_action(keyword, arg)) { case EX_UNAVAILABLE: warnx("nothing available for '%s'.", keyword); break; case EX_DATAERR: warnx("invalid value '%s' for '%s'.", arg, keyword); break; } free(keyword); return(rv); } static void dump_config(void) { ofwo_dump(); } diff --git a/usr.sbin/makefs/compat/pwcache.c b/usr.sbin/makefs/compat/pwcache.c index 0579d2692ac5..d0c45c22b028 100644 --- a/usr.sbin/makefs/compat/pwcache.c +++ b/usr.sbin/makefs/compat/pwcache.c @@ -1,623 +1,616 @@ /* $NetBSD: pwcache.c,v 1.29 2004/06/20 22:20:14 jmc Exp $ */ /*- * Copyright (c) 1992 Keith Muller. * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Keith Muller of the University of California, San Diego. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #ifdef __weak_alias __weak_alias(user_from_uid,_user_from_uid) __weak_alias(group_from_gid,_group_from_gid) __weak_alias(pwcache_userdb,_pwcache_userdb) __weak_alias(pwcache_groupdb,_pwcache_groupdb) #endif #include "pwcache.h" /* * routines that control user, group, uid and gid caches (for the archive * member print routine). * IMPORTANT: * these routines cache BOTH hits and misses, a major performance improvement */ /* * function pointers to various name lookup routines. * these may be changed as necessary. */ static int (*_pwcache_setgroupent)(int) = setgroupent; static void (*_pwcache_endgrent)(void) = endgrent; static struct group * (*_pwcache_getgrnam)(const char *) = getgrnam; static struct group * (*_pwcache_getgrgid)(gid_t) = getgrgid; static int (*_pwcache_setpassent)(int) = setpassent; static void (*_pwcache_endpwent)(void) = endpwent; static struct passwd * (*_pwcache_getpwnam)(const char *) = getpwnam; static struct passwd * (*_pwcache_getpwuid)(uid_t) = getpwuid; /* * internal state */ static int pwopn; /* is password file open */ static int gropn; /* is group file open */ static UIDC **uidtb; /* uid to name cache */ static GIDC **gidtb; /* gid to name cache */ static UIDC **usrtb; /* user name to uid cache */ static GIDC **grptb; /* group name to gid cache */ static int uidtb_fail; /* uidtb_start() failed ? */ static int gidtb_fail; /* gidtb_start() failed ? */ static int usrtb_fail; /* usrtb_start() failed ? */ static int grptb_fail; /* grptb_start() failed ? */ static u_int st_hash(const char *, size_t, int); static int uidtb_start(void); static int gidtb_start(void); static int usrtb_start(void); static int grptb_start(void); static u_int st_hash(const char *name, size_t len, int tabsz) { u_int key = 0; while (len--) { key += *name++; key = (key << 8) | (key >> 24); } return (key % tabsz); } /* * uidtb_start * creates an an empty uidtb * Return: * 0 if ok, -1 otherwise */ static int uidtb_start(void) { if (uidtb != NULL) return (0); if (uidtb_fail) return (-1); if ((uidtb = (UIDC **)calloc(UID_SZ, sizeof(UIDC *))) == NULL) { ++uidtb_fail; return (-1); } return (0); } /* * gidtb_start * creates an an empty gidtb * Return: * 0 if ok, -1 otherwise */ static int gidtb_start(void) { if (gidtb != NULL) return (0); if (gidtb_fail) return (-1); if ((gidtb = (GIDC **)calloc(GID_SZ, sizeof(GIDC *))) == NULL) { ++gidtb_fail; return (-1); } return (0); } /* * usrtb_start * creates an an empty usrtb * Return: * 0 if ok, -1 otherwise */ static int usrtb_start(void) { if (usrtb != NULL) return (0); if (usrtb_fail) return (-1); if ((usrtb = (UIDC **)calloc(UNM_SZ, sizeof(UIDC *))) == NULL) { ++usrtb_fail; return (-1); } return (0); } /* * grptb_start * creates an an empty grptb * Return: * 0 if ok, -1 otherwise */ static int grptb_start(void) { if (grptb != NULL) return (0); if (grptb_fail) return (-1); if ((grptb = (GIDC **)calloc(GNM_SZ, sizeof(GIDC *))) == NULL) { ++grptb_fail; return (-1); } return (0); } /* * user_from_uid() * caches the name (if any) for the uid. If noname clear, we always * return the stored name (if valid or invalid match). * We use a simple hash table. * Return * Pointer to stored name (or a empty string) */ const char * user_from_uid(uid_t uid, int noname) { struct passwd *pw; UIDC *ptr, **pptr; if ((uidtb == NULL) && (uidtb_start() < 0)) return (NULL); /* * see if we have this uid cached */ pptr = uidtb + (uid % UID_SZ); ptr = *pptr; if ((ptr != NULL) && (ptr->valid > 0) && (ptr->uid == uid)) { /* * have an entry for this uid */ if (!noname || (ptr->valid == VALID)) return (ptr->name); return (NULL); } /* * No entry for this uid, we will add it */ if (!pwopn) { if (_pwcache_setpassent != NULL) (*_pwcache_setpassent)(1); ++pwopn; } if (ptr == NULL) *pptr = ptr = (UIDC *)malloc(sizeof(UIDC)); if ((pw = (*_pwcache_getpwuid)(uid)) == NULL) { /* * no match for this uid in the local password file * a string that is the uid in numeric format */ if (ptr == NULL) return (NULL); ptr->uid = uid; (void)snprintf(ptr->name, UNMLEN, "%lu", (long) uid); ptr->valid = INVALID; if (noname) return (NULL); } else { /* * there is an entry for this uid in the password file */ if (ptr == NULL) return (pw->pw_name); ptr->uid = uid; (void)strlcpy(ptr->name, pw->pw_name, UNMLEN); ptr->valid = VALID; } return (ptr->name); } /* * group_from_gid() * caches the name (if any) for the gid. If noname clear, we always * return the stored name (if valid or invalid match). * We use a simple hash table. * Return * Pointer to stored name (or a empty string) */ const char * group_from_gid(gid_t gid, int noname) { struct group *gr; GIDC *ptr, **pptr; if ((gidtb == NULL) && (gidtb_start() < 0)) return (NULL); /* * see if we have this gid cached */ pptr = gidtb + (gid % GID_SZ); ptr = *pptr; if ((ptr != NULL) && (ptr->valid > 0) && (ptr->gid == gid)) { /* * have an entry for this gid */ if (!noname || (ptr->valid == VALID)) return (ptr->name); return (NULL); } /* * No entry for this gid, we will add it */ if (!gropn) { if (_pwcache_setgroupent != NULL) (*_pwcache_setgroupent)(1); ++gropn; } if (ptr == NULL) *pptr = ptr = (GIDC *)malloc(sizeof(GIDC)); if ((gr = (*_pwcache_getgrgid)(gid)) == NULL) { /* * no match for this gid in the local group file, put in * a string that is the gid in numberic format */ if (ptr == NULL) return (NULL); ptr->gid = gid; (void)snprintf(ptr->name, GNMLEN, "%lu", (long) gid); ptr->valid = INVALID; if (noname) return (NULL); } else { /* * there is an entry for this group in the group file */ if (ptr == NULL) return (gr->gr_name); ptr->gid = gid; (void)strlcpy(ptr->name, gr->gr_name, GNMLEN); ptr->valid = VALID; } return (ptr->name); } /* * uid_from_user() * caches the uid for a given user name. We use a simple hash table. * Return * the uid (if any) for a user name, or a -1 if no match can be found */ int uid_from_user(const char *name, uid_t *uid) { struct passwd *pw; UIDC *ptr, **pptr; size_t namelen; /* * return -1 for mangled names */ if (name == NULL || ((namelen = strlen(name)) == 0)) return (-1); if ((usrtb == NULL) && (usrtb_start() < 0)) return (-1); /* * look up in hash table, if found and valid return the uid, * if found and invalid, return a -1 */ pptr = usrtb + st_hash(name, namelen, UNM_SZ); ptr = *pptr; if ((ptr != NULL) && (ptr->valid > 0) && !strcmp(name, ptr->name)) { if (ptr->valid == INVALID) return (-1); *uid = ptr->uid; return (0); } if (!pwopn) { if (_pwcache_setpassent != NULL) (*_pwcache_setpassent)(1); ++pwopn; } if (ptr == NULL) *pptr = ptr = (UIDC *)malloc(sizeof(UIDC)); /* * no match, look it up, if no match store it as an invalid entry, * or store the matching uid */ if (ptr == NULL) { if ((pw = (*_pwcache_getpwnam)(name)) == NULL) return (-1); *uid = pw->pw_uid; return (0); } (void)strlcpy(ptr->name, name, UNMLEN); if ((pw = (*_pwcache_getpwnam)(name)) == NULL) { ptr->valid = INVALID; return (-1); } ptr->valid = VALID; *uid = ptr->uid = pw->pw_uid; return (0); } /* * gid_from_group() * caches the gid for a given group name. We use a simple hash table. * Return * the gid (if any) for a group name, or a -1 if no match can be found */ int gid_from_group(const char *name, gid_t *gid) { struct group *gr; GIDC *ptr, **pptr; size_t namelen; /* * return -1 for mangled names */ if (name == NULL || ((namelen = strlen(name)) == 0)) return (-1); if ((grptb == NULL) && (grptb_start() < 0)) return (-1); /* * look up in hash table, if found and valid return the uid, * if found and invalid, return a -1 */ pptr = grptb + st_hash(name, namelen, GID_SZ); ptr = *pptr; if ((ptr != NULL) && (ptr->valid > 0) && !strcmp(name, ptr->name)) { if (ptr->valid == INVALID) return (-1); *gid = ptr->gid; return (0); } if (!gropn) { if (_pwcache_setgroupent != NULL) (*_pwcache_setgroupent)(1); ++gropn; } if (ptr == NULL) *pptr = ptr = (GIDC *)malloc(sizeof(GIDC)); /* * no match, look it up, if no match store it as an invalid entry, * or store the matching gid */ if (ptr == NULL) { if ((gr = (*_pwcache_getgrnam)(name)) == NULL) return (-1); *gid = gr->gr_gid; return (0); } (void)strlcpy(ptr->name, name, GNMLEN); if ((gr = (*_pwcache_getgrnam)(name)) == NULL) { ptr->valid = INVALID; return (-1); } ptr->valid = VALID; *gid = ptr->gid = gr->gr_gid; return (0); } #define FLUSHTB(arr, len, fail) \ do { \ if (arr != NULL) { \ for (i = 0; i < len; i++) \ if (arr[i] != NULL) \ free(arr[i]); \ arr = NULL; \ } \ fail = 0; \ } while (/* CONSTCOND */0); int pwcache_userdb( int (*a_setpassent)(int), void (*a_endpwent)(void), struct passwd * (*a_getpwnam)(const char *), struct passwd * (*a_getpwuid)(uid_t)) { int i; /* a_setpassent and a_endpwent may be NULL */ if (a_getpwnam == NULL || a_getpwuid == NULL) return (-1); if (_pwcache_endpwent != NULL) (*_pwcache_endpwent)(); FLUSHTB(uidtb, UID_SZ, uidtb_fail); FLUSHTB(usrtb, UNM_SZ, usrtb_fail); pwopn = 0; _pwcache_setpassent = a_setpassent; _pwcache_endpwent = a_endpwent; _pwcache_getpwnam = a_getpwnam; _pwcache_getpwuid = a_getpwuid; return (0); } int pwcache_groupdb( int (*a_setgroupent)(int), void (*a_endgrent)(void), struct group * (*a_getgrnam)(const char *), struct group * (*a_getgrgid)(gid_t)) { int i; /* a_setgroupent and a_endgrent may be NULL */ if (a_getgrnam == NULL || a_getgrgid == NULL) return (-1); if (_pwcache_endgrent != NULL) (*_pwcache_endgrent)(); FLUSHTB(gidtb, GID_SZ, gidtb_fail); FLUSHTB(grptb, GNM_SZ, grptb_fail); gropn = 0; _pwcache_setgroupent = a_setgroupent; _pwcache_endgrent = a_endgrent; _pwcache_getgrnam = a_getgrnam; _pwcache_getgrgid = a_getgrgid; return (0); } #ifdef TEST_PWCACHE struct passwd * test_getpwnam(const char *name) { static struct passwd foo; memset(&foo, 0, sizeof(foo)); if (strcmp(name, "toor") == 0) { foo.pw_uid = 666; return &foo; } return (getpwnam(name)); } int main(int argc, char *argv[]) { uid_t u; int r, i; printf("pass 1 (default userdb)\n"); for (i = 1; i < argc; i++) { printf("i: %d, pwopn %d usrtb_fail %d usrtb %p\n", i, pwopn, usrtb_fail, usrtb); r = uid_from_user(argv[i], &u); if (r == -1) printf(" uid_from_user %s: failed\n", argv[i]); else printf(" uid_from_user %s: %d\n", argv[i], u); } printf("pass 1 finish: pwopn %d usrtb_fail %d usrtb %p\n", pwopn, usrtb_fail, usrtb); puts(""); printf("pass 2 (replacement userdb)\n"); printf("pwcache_userdb returned %d\n", pwcache_userdb(setpassent, test_getpwnam, getpwuid)); printf("pwopn %d usrtb_fail %d usrtb %p\n", pwopn, usrtb_fail, usrtb); for (i = 1; i < argc; i++) { printf("i: %d, pwopn %d usrtb_fail %d usrtb %p\n", i, pwopn, usrtb_fail, usrtb); u = -1; r = uid_from_user(argv[i], &u); if (r == -1) printf(" uid_from_user %s: failed\n", argv[i]); else printf(" uid_from_user %s: %d\n", argv[i], u); } printf("pass 2 finish: pwopn %d usrtb_fail %d usrtb %p\n", pwopn, usrtb_fail, usrtb); puts(""); printf("pass 3 (null pointers)\n"); printf("pwcache_userdb returned %d\n", pwcache_userdb(NULL, NULL, NULL)); return (0); } #endif /* TEST_PWCACHE */ diff --git a/usr.sbin/makefs/compat/strsuftoll.c b/usr.sbin/makefs/compat/strsuftoll.c index f73e3ad51d23..657e52525fc6 100644 --- a/usr.sbin/makefs/compat/strsuftoll.c +++ b/usr.sbin/makefs/compat/strsuftoll.c @@ -1,229 +1,222 @@ /* $NetBSD: strsuftoll.c,v 1.6 2004/03/05 05:58:29 lukem Exp $ */ /*- * Copyright (c) 2001-2002,2004 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Luke Mewburn. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /*- * Copyright (c) 1991, 1993, 1994 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Keith Muller of the University of California, San Diego and Lance * Visser of Convex Computer Corporation. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #ifdef _LIBC # ifdef __weak_alias __weak_alias(strsuftoll, _strsuftoll) __weak_alias(strsuftollx, _strsuftollx) # endif #endif /* LIBC */ /* * Convert an expression of the following forms to a (u)int64_t. * 1) A positive decimal number. * 2) A positive decimal number followed by a b (mult by 512). * 3) A positive decimal number followed by a k (mult by 1024). * 4) A positive decimal number followed by a m (mult by 1048576). * 5) A positive decimal number followed by a g (mult by 1073741824). * 6) A positive decimal number followed by a t (mult by 1099511627776). * 7) A positive decimal number followed by a w (mult by sizeof int) * 8) Two or more positive decimal numbers (with/without k,b or w). * separated by x (also * for backwards compatibility), specifying * the product of the indicated values. * Returns the result upon successful conversion, or exits with an * appropriate error. * */ /* * As strsuftoll(), but returns the error message into the provided buffer * rather than exiting with it. */ /* LONGLONG */ long long strsuftollx(const char *desc, const char *val, long long min, long long max, char *ebuf, size_t ebuflen) { long long num, t; char *expr; errno = 0; ebuf[0] = '\0'; while (isspace((unsigned char)*val)) /* Skip leading space */ val++; num = strtoll(val, &expr, 10); if (errno == ERANGE) goto erange; /* Overflow */ if (expr == val) /* No digits */ goto badnum; switch (*expr) { case 'b': t = num; num *= 512; /* 1 block */ if (t > num) goto erange; ++expr; break; case 'k': t = num; num *= 1024; /* 1 kilobyte */ if (t > num) goto erange; ++expr; break; case 'm': t = num; num *= 1048576; /* 1 megabyte */ if (t > num) goto erange; ++expr; break; case 'g': t = num; num *= 1073741824; /* 1 gigabyte */ if (t > num) goto erange; ++expr; break; case 't': t = num; num *= 1099511627776LL; /* 1 terabyte */ if (t > num) goto erange; ++expr; break; case 'w': t = num; num *= sizeof(int); /* 1 word */ if (t > num) goto erange; ++expr; break; } switch (*expr) { case '\0': break; case '*': /* Backward compatible */ case 'x': t = num; num *= strsuftollx(desc, expr + 1, min, max, ebuf, ebuflen); if (*ebuf != '\0') return (0); if (t > num) { erange: snprintf(ebuf, ebuflen, "%s: %s", desc, strerror(ERANGE)); return (0); } break; default: badnum: snprintf(ebuf, ebuflen, "%s `%s': illegal number", desc, val); return (0); } if (num < min) { /* LONGLONG */ snprintf(ebuf, ebuflen, "%s %lld is less than %lld.", desc, (long long)num, (long long)min); return (0); } if (num > max) { /* LONGLONG */ snprintf(ebuf, ebuflen, "%s %lld is greater than %lld.", desc, (long long)num, (long long)max); return (0); } *ebuf = '\0'; return (num); } /* LONGLONG */ long long strsuftoll(const char *desc, const char *val, long long min, long long max) { long long result; char errbuf[100]; result = strsuftollx(desc, val, min, max, errbuf, sizeof(errbuf)); if (*errbuf != '\0') errx(1, "%s", errbuf); return (result); } diff --git a/usr.sbin/makefs/getid.c b/usr.sbin/makefs/getid.c index ca52fa39e46f..939d943ab764 100644 --- a/usr.sbin/makefs/getid.c +++ b/usr.sbin/makefs/getid.c @@ -1,436 +1,429 @@ /* $NetBSD: getid.c,v 1.5 2004/06/20 22:20:18 jmc Exp $ */ /* from: NetBSD: getpwent.c,v 1.48 2000/10/03 03:22:26 enami Exp */ /* from: NetBSD: getgrent.c,v 1.41 2002/01/12 23:51:30 lukem Exp */ /* * Copyright (c) 1987, 1988, 1989, 1993, 1994, 1995 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Luke Mewburn of Wasabi Systems. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include "makefs.h" #include "mtree.h" #include "extern.h" static struct group * gi_getgrnam(const char *); static struct group * gi_getgrgid(gid_t); static int gi_setgroupent(int); static void gi_endgrent(void); static int grstart(void); static int grscan(int, gid_t, const char *); static int grmatchline(int, gid_t, const char *); static struct passwd * gi_getpwnam(const char *); static struct passwd * gi_getpwuid(uid_t); static int gi_setpassent(int); static void gi_endpwent(void); static int pwstart(void); static int pwscan(int, uid_t, const char *); static int pwmatchline(int, uid_t, const char *); #define MAXGRP 200 #define MAXLINELENGTH 1024 static FILE *_gr_fp; static struct group _gr_group; static int _gr_stayopen; static int _gr_filesdone; static FILE *_pw_fp; static struct passwd _pw_passwd; /* password structure */ static int _pw_stayopen; /* keep fd's open */ static int _pw_filesdone; static char grfile[MAXPATHLEN]; static char pwfile[MAXPATHLEN]; static char *members[MAXGRP]; static char grline[MAXLINELENGTH]; static char pwline[MAXLINELENGTH]; int setup_getid(const char *dir) { if (dir == NULL) return (0); /* close existing databases */ gi_endgrent(); gi_endpwent(); /* build paths to new databases */ snprintf(grfile, sizeof(grfile), "%s/group", dir); snprintf(pwfile, sizeof(pwfile), "%s/master.passwd", dir); /* try to open new databases */ if (!grstart() || !pwstart()) return (0); /* switch pwcache(3) lookup functions */ if (pwcache_groupdb(gi_setgroupent, gi_endgrent, gi_getgrnam, gi_getgrgid) == -1 || pwcache_userdb(gi_setpassent, gi_endpwent, gi_getpwnam, gi_getpwuid) == -1) return (0); return (1); } /* * group lookup functions */ static struct group * gi_getgrnam(const char *name) { int rval; if (!grstart()) return NULL; rval = grscan(1, 0, name); if (!_gr_stayopen) endgrent(); return (rval) ? &_gr_group : NULL; } static struct group * gi_getgrgid(gid_t gid) { int rval; if (!grstart()) return NULL; rval = grscan(1, gid, NULL); if (!_gr_stayopen) endgrent(); return (rval) ? &_gr_group : NULL; } static int gi_setgroupent(int stayopen) { if (!grstart()) return 0; _gr_stayopen = stayopen; return 1; } static void gi_endgrent(void) { _gr_filesdone = 0; if (_gr_fp) { (void)fclose(_gr_fp); _gr_fp = NULL; } } static int grstart(void) { _gr_filesdone = 0; if (_gr_fp) { rewind(_gr_fp); return 1; } if (grfile[0] == '\0') /* sanity check */ return 0; return (_gr_fp = fopen(grfile, "r")) ? 1 : 0; } static int grscan(int search, gid_t gid, const char *name) { if (_gr_filesdone) return 0; for (;;) { if (!fgets(grline, sizeof(grline), _gr_fp)) { if (!search) _gr_filesdone = 1; return 0; } /* skip lines that are too big */ if (!strchr(grline, '\n')) { int ch; while ((ch = getc(_gr_fp)) != '\n' && ch != EOF) ; continue; } if (grmatchline(search, gid, name)) return 1; } /* NOTREACHED */ } static int grmatchline(int search, gid_t gid, const char *name) { unsigned long id; char **m; char *cp, *bp, *ep; /* name may be NULL if search is nonzero */ bp = grline; memset(&_gr_group, 0, sizeof(_gr_group)); _gr_group.gr_name = strsep(&bp, ":\n"); if (search && name && strcmp(_gr_group.gr_name, name)) return 0; _gr_group.gr_passwd = strsep(&bp, ":\n"); if (!(cp = strsep(&bp, ":\n"))) return 0; id = strtoul(cp, &ep, 10); if (id > GID_MAX || *ep != '\0') return 0; _gr_group.gr_gid = (gid_t)id; if (search && name == NULL && _gr_group.gr_gid != gid) return 0; cp = NULL; if (bp == NULL) return 0; for (_gr_group.gr_mem = m = members;; bp++) { if (m == &members[MAXGRP - 1]) break; if (*bp == ',') { if (cp) { *bp = '\0'; *m++ = cp; cp = NULL; } } else if (*bp == '\0' || *bp == '\n' || *bp == ' ') { if (cp) { *bp = '\0'; *m++ = cp; } break; } else if (cp == NULL) cp = bp; } *m = NULL; return 1; } /* * user lookup functions */ static struct passwd * gi_getpwnam(const char *name) { int rval; if (!pwstart()) return NULL; rval = pwscan(1, 0, name); if (!_pw_stayopen) endpwent(); return (rval) ? &_pw_passwd : NULL; } static struct passwd * gi_getpwuid(uid_t uid) { int rval; if (!pwstart()) return NULL; rval = pwscan(1, uid, NULL); if (!_pw_stayopen) endpwent(); return (rval) ? &_pw_passwd : NULL; } static int gi_setpassent(int stayopen) { if (!pwstart()) return 0; _pw_stayopen = stayopen; return 1; } static void gi_endpwent(void) { _pw_filesdone = 0; if (_pw_fp) { (void)fclose(_pw_fp); _pw_fp = NULL; } } static int pwstart(void) { _pw_filesdone = 0; if (_pw_fp) { rewind(_pw_fp); return 1; } if (pwfile[0] == '\0') /* sanity check */ return 0; return (_pw_fp = fopen(pwfile, "r")) ? 1 : 0; } static int pwscan(int search, uid_t uid, const char *name) { if (_pw_filesdone) return 0; for (;;) { if (!fgets(pwline, sizeof(pwline), _pw_fp)) { if (!search) _pw_filesdone = 1; return 0; } /* skip lines that are too big */ if (!strchr(pwline, '\n')) { int ch; while ((ch = getc(_pw_fp)) != '\n' && ch != EOF) ; continue; } if (pwmatchline(search, uid, name)) return 1; } /* NOTREACHED */ } static int pwmatchline(int search, uid_t uid, const char *name) { unsigned long id; char *cp, *bp, *ep; /* name may be NULL if search is nonzero */ bp = pwline; memset(&_pw_passwd, 0, sizeof(_pw_passwd)); _pw_passwd.pw_name = strsep(&bp, ":\n"); /* name */ if (search && name && strcmp(_pw_passwd.pw_name, name)) return 0; _pw_passwd.pw_passwd = strsep(&bp, ":\n"); /* passwd */ if (!(cp = strsep(&bp, ":\n"))) /* uid */ return 0; id = strtoul(cp, &ep, 10); if (id > UID_MAX || *ep != '\0') return 0; _pw_passwd.pw_uid = (uid_t)id; if (search && name == NULL && _pw_passwd.pw_uid != uid) return 0; if (!(cp = strsep(&bp, ":\n"))) /* gid */ return 0; id = strtoul(cp, &ep, 10); if (id > GID_MAX || *ep != '\0') return 0; _pw_passwd.pw_gid = (gid_t)id; if (!(ep = strsep(&bp, ":"))) /* class */ return 0; if (!(ep = strsep(&bp, ":"))) /* change */ return 0; if (!(ep = strsep(&bp, ":"))) /* expire */ return 0; if (!(_pw_passwd.pw_gecos = strsep(&bp, ":\n"))) /* gecos */ return 0; if (!(_pw_passwd.pw_dir = strsep(&bp, ":\n"))) /* directory */ return 0; if (!(_pw_passwd.pw_shell = strsep(&bp, ":\n"))) /* shell */ return 0; if (strchr(bp, ':') != NULL) return 0; return 1; } diff --git a/usr.sbin/rpcbind/util.c b/usr.sbin/rpcbind/util.c index 9cdfa7054611..aca5236927b8 100644 --- a/usr.sbin/rpcbind/util.c +++ b/usr.sbin/rpcbind/util.c @@ -1,383 +1,378 @@ /* * $NetBSD: util.c,v 1.4 2000/08/03 00:04:30 fvdl Exp $ * $FreeBSD$ */ /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Frank van der Linden. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "rpcbind.h" static struct sockaddr_in *local_in4; #ifdef INET6 static struct sockaddr_in6 *local_in6; #endif static int bitmaskcmp(void *, void *, void *, int); #ifdef INET6 static void in6_fillscopeid(struct sockaddr_in6 *); #endif /* * For all bits set in "mask", compare the corresponding bits in * "dst" and "src", and see if they match. Returns 0 if the addresses * match. */ static int bitmaskcmp(void *dst, void *src, void *mask, int bytelen) { int i; u_int8_t *p1 = dst, *p2 = src, *netmask = mask; for (i = 0; i < bytelen; i++) if ((p1[i] & netmask[i]) != (p2[i] & netmask[i])) return (1); return (0); } /* * Similar to code in ifconfig.c. Fill in the scope ID for link-local * addresses returned by getifaddrs(). */ #ifdef INET6 static void in6_fillscopeid(struct sockaddr_in6 *sin6) { u_int16_t ifindex; if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { ifindex = ntohs(*(u_int16_t *)&sin6->sin6_addr.s6_addr[2]); if (sin6->sin6_scope_id == 0 && ifindex != 0) { sin6->sin6_scope_id = ifindex; *(u_int16_t *)&sin6->sin6_addr.s6_addr[2] = 0; } } } #endif /* * Find a server address that can be used by `caller' to contact * the local service specified by `serv_uaddr'. If `clnt_uaddr' is * non-NULL, it is used instead of `caller' as a hint suggesting * the best address (e.g. the `r_addr' field of an rpc, which * contains the rpcbind server address that the caller used). * * Returns the best server address as a malloc'd "universal address" * string which should be freed by the caller. On error, returns NULL. */ char * addrmerge(struct netbuf *caller, char *serv_uaddr, char *clnt_uaddr, char *netid) { struct ifaddrs *ifap, *ifp = NULL, *bestif; struct netbuf *serv_nbp = NULL, *hint_nbp = NULL, tbuf; struct sockaddr *caller_sa, *hint_sa, *ifsa, *ifmasksa, *serv_sa; struct sockaddr_storage ss; struct netconfig *nconf; char *caller_uaddr = NULL, *hint_uaddr = NULL; char *ret = NULL; #ifdef ND_DEBUG if (debugging) fprintf(stderr, "addrmerge(caller, %s, %s, %s\n", serv_uaddr, clnt_uaddr == NULL ? "NULL" : clnt_uaddr, netid); #endif caller_sa = caller->buf; if ((nconf = rpcbind_get_conf(netid)) == NULL) goto freeit; if ((caller_uaddr = taddr2uaddr(nconf, caller)) == NULL) goto freeit; /* * Use `clnt_uaddr' as the hint if non-NULL, but ignore it if its * address family is different from that of the caller. */ hint_sa = NULL; if (clnt_uaddr != NULL) { hint_uaddr = clnt_uaddr; if ((hint_nbp = uaddr2taddr(nconf, clnt_uaddr)) == NULL) goto freeit; hint_sa = hint_nbp->buf; } if (hint_sa == NULL || hint_sa->sa_family != caller_sa->sa_family) { hint_uaddr = caller_uaddr; hint_sa = caller->buf; } #ifdef ND_DEBUG if (debugging) fprintf(stderr, "addrmerge: hint %s\n", hint_uaddr); #endif /* Local caller, just return the server address. */ if (strncmp(caller_uaddr, "0.0.0.0.", 8) == 0 || strncmp(caller_uaddr, "::.", 3) == 0 || caller_uaddr[0] == '/') { ret = strdup(serv_uaddr); goto freeit; } if (getifaddrs(&ifp) < 0) goto freeit; /* * Loop through all interfaces. For each interface, see if it * is either the loopback interface (which we always listen * on) or is one of the addresses the program bound to (the * wildcard by default, or a subset if -h is specified) and * the network portion of its address is equal to that of the * client. If so, we have found the interface that we want to * use. */ bestif = NULL; for (ifap = ifp; ifap != NULL; ifap = ifap->ifa_next) { ifsa = ifap->ifa_addr; ifmasksa = ifap->ifa_netmask; if (ifsa == NULL || ifsa->sa_family != hint_sa->sa_family || !(ifap->ifa_flags & IFF_UP)) continue; + if (!addr_is_bound(ifsa)) + continue; if (!(ifap->ifa_flags & IFF_LOOPBACK) && !listen_addr(ifsa)) continue; switch (hint_sa->sa_family) { case AF_INET: /* * If the hint address matches this interface * address/netmask, then we're done. */ if (!bitmaskcmp(&SA2SINADDR(ifsa), &SA2SINADDR(hint_sa), &SA2SINADDR(ifmasksa), sizeof(struct in_addr))) { bestif = ifap; goto found; } break; #ifdef INET6 case AF_INET6: /* * For v6 link local addresses, if the caller is on * a link-local address then use the scope id to see * which one. */ in6_fillscopeid(SA2SIN6(ifsa)); if (IN6_IS_ADDR_LINKLOCAL(&SA2SIN6ADDR(ifsa)) && IN6_IS_ADDR_LINKLOCAL(&SA2SIN6ADDR(caller_sa)) && IN6_IS_ADDR_LINKLOCAL(&SA2SIN6ADDR(hint_sa))) { if (SA2SIN6(ifsa)->sin6_scope_id == SA2SIN6(caller_sa)->sin6_scope_id) { bestif = ifap; goto found; } } else if (!bitmaskcmp(&SA2SIN6ADDR(ifsa), &SA2SIN6ADDR(hint_sa), &SA2SIN6ADDR(ifmasksa), sizeof(struct in6_addr))) { bestif = ifap; goto found; } break; #endif default: continue; } /* * Remember the first possibly useful interface, preferring * "normal" to point-to-point and loopback ones. */ if (bestif == NULL || (!(ifap->ifa_flags & (IFF_LOOPBACK | IFF_POINTOPOINT)) && (bestif->ifa_flags & (IFF_LOOPBACK | IFF_POINTOPOINT)))) bestif = ifap; } if (bestif == NULL) goto freeit; found: /* * Construct the new address using the the address from * `bestif', and the port number from `serv_uaddr'. */ serv_nbp = uaddr2taddr(nconf, serv_uaddr); if (serv_nbp == NULL) goto freeit; serv_sa = serv_nbp->buf; memcpy(&ss, bestif->ifa_addr, bestif->ifa_addr->sa_len); switch (ss.ss_family) { case AF_INET: SA2SIN(&ss)->sin_port = SA2SIN(serv_sa)->sin_port; break; #ifdef INET6 case AF_INET6: SA2SIN6(&ss)->sin6_port = SA2SIN6(serv_sa)->sin6_port; break; #endif } tbuf.len = ss.ss_len; tbuf.maxlen = sizeof(ss); tbuf.buf = &ss; ret = taddr2uaddr(nconf, &tbuf); freeit: if (caller_uaddr != NULL) free(caller_uaddr); if (hint_nbp != NULL) { free(hint_nbp->buf); free(hint_nbp); } if (serv_nbp != NULL) { free(serv_nbp->buf); free(serv_nbp); } if (ifp != NULL) freeifaddrs(ifp); #ifdef ND_DEBUG if (debugging) fprintf(stderr, "addrmerge: returning %s\n", ret); #endif return ret; } void network_init() { #ifdef INET6 struct ifaddrs *ifap, *ifp; struct ipv6_mreq mreq6; unsigned int ifindex; int s; #endif int ecode; struct addrinfo hints, *res; memset(&hints, 0, sizeof hints); hints.ai_family = AF_INET; if ((ecode = getaddrinfo(NULL, "sunrpc", &hints, &res))) { if (debugging) fprintf(stderr, "can't get local ip4 address: %s\n", gai_strerror(ecode)); } else { local_in4 = (struct sockaddr_in *)malloc(sizeof *local_in4); if (local_in4 == NULL) { if (debugging) fprintf(stderr, "can't alloc local ip4 addr\n"); } memcpy(local_in4, res->ai_addr, sizeof *local_in4); } #ifdef INET6 hints.ai_family = AF_INET6; if ((ecode = getaddrinfo(NULL, "sunrpc", &hints, &res))) { if (debugging) fprintf(stderr, "can't get local ip6 address: %s\n", gai_strerror(ecode)); } else { local_in6 = (struct sockaddr_in6 *)malloc(sizeof *local_in6); if (local_in6 == NULL) { if (debugging) fprintf(stderr, "can't alloc local ip6 addr\n"); } memcpy(local_in6, res->ai_addr, sizeof *local_in6); } /* * Now join the RPC ipv6 multicast group on all interfaces. */ if (getifaddrs(&ifp) < 0) return; mreq6.ipv6mr_interface = 0; inet_pton(AF_INET6, RPCB_MULTICAST_ADDR, &mreq6.ipv6mr_multiaddr); s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); /* * Loop through all interfaces. For each IPv6 multicast-capable * interface, join the RPC multicast group on that interface. */ for (ifap = ifp; ifap != NULL; ifap = ifap->ifa_next) { if (ifap->ifa_addr->sa_family != AF_INET6 || !(ifap->ifa_flags & IFF_MULTICAST)) continue; ifindex = if_nametoindex(ifap->ifa_name); if (ifindex == mreq6.ipv6mr_interface) /* * Already did this one. */ continue; mreq6.ipv6mr_interface = ifindex; if (setsockopt(s, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq6, sizeof mreq6) < 0) if (debugging) perror("setsockopt v6 multicast"); } #endif /* close(s); */ } struct sockaddr * local_sa(int af) { switch (af) { case AF_INET: return (struct sockaddr *)local_in4; #ifdef INET6 case AF_INET6: return (struct sockaddr *)local_in6; #endif default: return NULL; } } diff --git a/usr.sbin/usbdevs/usbdevs.8 b/usr.sbin/usbdevs/usbdevs.8 index 3226dd5bd658..dd56fc868794 100644 --- a/usr.sbin/usbdevs/usbdevs.8 +++ b/usr.sbin/usbdevs/usbdevs.8 @@ -1,77 +1,70 @@ .\" $NetBSD: usbdevs.8,v 1.5 2000/10/15 12:44:11 bjh21 Exp $ .\" Copyright (c) 1999 The NetBSD Foundation, Inc. .\" All rights reserved. .\" .\" Author: Lennart Augustsson .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the NetBSD -.\" Foundation, Inc. and its contributors. -.\" 4. Neither the name of The NetBSD Foundation nor the names of its -.\" contributors may be used to endorse or promote products derived -.\" from this software without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" .\" $FreeBSD$ .\" .Dd May 24, 2004 .Dt USBDEVS 8 .Os .Sh NAME .Nm usbdevs .Nd show USB devices connected to the system .Sh SYNOPSIS .Nm .Op Fl a Ar addr .Op Fl d .Op Fl f Ar dev .Op Fl o .Op Fl v .Sh DESCRIPTION The .Nm utility prints a listing of all USB devices connected to the system with some information about each device. The indentation of each line indicates its distance from the root. .Pp The options are as follows: .Bl -tag -width ".Fl a Ar addr" .It Fl a Ar addr only print information about the device at the given address. .It Fl d Show the device drivers associated with each device. .It Fl f Ar dev only print information for the given USB controller. .It Fl o One-line output (only useful in combination with .Fl d ) . .It Fl v Be verbose. .El .Sh SEE ALSO .Xr usb 4 .Sh HISTORY The .Nm utility appeared in .Nx 1.4 . diff --git a/usr.sbin/usbdevs/usbdevs.c b/usr.sbin/usbdevs/usbdevs.c index eea8167c55c3..b51e3c5b3dad 100644 --- a/usr.sbin/usbdevs/usbdevs.c +++ b/usr.sbin/usbdevs/usbdevs.c @@ -1,240 +1,233 @@ /* $NetBSD: usbdevs.c,v 1.22 2003/11/12 13:31:08 grant Exp $ */ /* $FreeBSD$ */ /* * Copyright (c) 1998 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Lennart Augustsson (augustss@NetBSD.org). * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include #include #include #include #include #if defined(__FreeBSD__) #include #endif #define USBDEV "/dev/usb" int verbose = 0; int showdevs = 0; int oneline = 0; void usage(void); void usbdev(int f, int a, int rec); void usbdump(int f); void dumpone(char *name, int f, int addr); int main(int, char **); void usage() { fprintf(stderr, "usage: %s [-a addr] [-d] [-f dev] [-o] [-v]\n", getprogname()); exit(1); } char done[USB_MAX_DEVICES]; int indent; void usbdev(int f, int a, int rec) { struct usb_device_info di; int e, p, i; di.udi_addr = a; e = ioctl(f, USB_DEVICEINFO, &di); if (e) { if (errno != ENXIO) printf("addr %d: I/O error\n", a); return; } printf("addr %d: ", a); done[a] = 1; if (verbose) { switch (di.udi_speed) { case USB_SPEED_LOW: printf("low speed, "); break; case USB_SPEED_FULL: printf("full speed, "); break; case USB_SPEED_HIGH: printf("high speed, "); break; default: break; } if (di.udi_power) printf("power %d mA, ", di.udi_power); else printf("self powered, "); if (di.udi_config) printf("config %d, ", di.udi_config); else printf("unconfigured, "); } if (verbose) { printf("%s(0x%04x), %s(0x%04x), rev %s", di.udi_product, di.udi_productNo, di.udi_vendor, di.udi_vendorNo, di.udi_release); } else printf("%s, %s", di.udi_product, di.udi_vendor); if (!oneline) printf("\n"); if (showdevs) { for (i = 0; i < USB_MAX_DEVNAMES; i++) { if (di.udi_devnames[i][0]) { if (oneline) printf(", device %s", di.udi_devnames[i]); else printf("%*s %s\n", indent, "", di.udi_devnames[i]); } } } if (oneline) printf("\n"); if (!rec) return; for (p = 0; p < di.udi_nports; p++) { int s = di.udi_ports[p]; if (s >= USB_MAX_DEVICES) { if (verbose) { printf("%*sport %d %s\n", indent+1, "", p+1, s == USB_PORT_ENABLED ? "enabled" : s == USB_PORT_SUSPENDED ? "suspended" : s == USB_PORT_POWERED ? "powered" : s == USB_PORT_DISABLED ? "disabled" : "???"); } continue; } indent++; printf("%*s", indent, ""); if (verbose) printf("port %d ", p+1); if (s == 0) printf("addr 0 should never happen!\n"); else usbdev(f, s, 1); indent--; } } void usbdump(int f) { int a; for (a = 1; a < USB_MAX_DEVICES; a++) { if (!done[a]) usbdev(f, a, 1); } } void dumpone(char *name, int f, int addr) { if (verbose) printf("Controller %s:\n", name); indent = 0; memset(done, 0, sizeof done); if (addr) usbdev(f, addr, 0); else usbdump(f); } int main(int argc, char **argv) { int ch, i, f; char buf[50]; char *dev = 0; int addr = 0; int ncont; while ((ch = getopt(argc, argv, "a:df:ov?")) != -1) { switch(ch) { case 'a': addr = atoi(optarg); break; case 'd': showdevs++; break; case 'f': dev = optarg; break; case 'o': oneline++; break; case 'v': verbose = 1; break; case '?': default: usage(); } } argc -= optind; argv += optind; if (dev == 0) { for (ncont = 0, i = 0; i < 10; i++) { snprintf(buf, sizeof(buf), "%s%d", USBDEV, i); f = open(buf, O_RDONLY); if (f >= 0) { dumpone(buf, f, addr); close(f); } else { if (errno == ENOENT || errno == ENXIO) continue; warn("%s", buf); } ncont++; } if (verbose && ncont == 0) printf("%s: no USB controllers found\n", getprogname()); } else { f = open(dev, O_RDONLY); if (f >= 0) dumpone(dev, f, addr); else err(1, "%s", dev); } exit(0); } diff --git a/usr.sbin/yppoll/yppoll.8 b/usr.sbin/yppoll/yppoll.8 index ad90d902e146..d466fd3d73fd 100644 --- a/usr.sbin/yppoll/yppoll.8 +++ b/usr.sbin/yppoll/yppoll.8 @@ -1,84 +1,77 @@ .\" Copyright (c) 1996 The NetBSD Foundation, Inc. .\" All rights reserved. .\" .\" This code is derived from software contributed to The NetBSD Foundation .\" by Jason R. Thorpe. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the NetBSD -.\" Foundation, Inc. and its contributors. -.\" 4. Neither the name of The NetBSD Foundation nor the names of its -.\" contributors may be used to endorse or promote products derived -.\" from this software without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" .\" $FreeBSD$ .\" .Dd October 25, 1994 .Dt YPPOLL 8 .Os .Sh NAME .Nm yppoll .Nd ask version of YP map from YP server .Sh SYNOPSIS .Nm .Op Fl h Ar host .Op Fl d Ar domain .Ar mapname .Sh DESCRIPTION The .Nm utility asks a YP server process for the order number and which host is the master server for .Ar mapname . .Pp The options are as follows: .Bl -tag -width indent .It Fl h Ar host Ask the YP server process running on .Ar host for information about .Ar mapname . If .Ar host is not specified, the server polled is the default server returned by .Xr ypwhich 1 . .It Fl d Ar domain Use the YP domain .Ar domain instead of the default domain as returned by .Xr domainname 1 . .El .Sh SEE ALSO .Xr domainname 1 , .Xr ypcat 1 , .Xr ypmatch 1 , .Xr ypwhich 1 , .Xr yp 8 , .Xr ypbind 8 , .Xr ypset 8 .Sh AUTHORS .An Theo De Raadt and .An John Brezak