diff options
author | Matthew Bauer <mjbauer95@gmail.com> | 2018-04-12 00:14:15 -0500 |
---|---|---|
committer | Matthew Bauer <mjbauer95@gmail.com> | 2018-04-24 14:16:35 -0500 |
commit | 31ef995e37ad4291afdaebb2c6480280fd058858 (patch) | |
tree | eab612604693b4f8263c1d71c9dc37c59621ac67 /pkgs/os-specific/bsd/netbsd | |
parent | 0dc26d0e7edfd6849643147b8e6c2d21ea7f5d5d (diff) | |
download | nixpkgs-31ef995e37ad4291afdaebb2c6480280fd058858.tar nixpkgs-31ef995e37ad4291afdaebb2c6480280fd058858.tar.gz nixpkgs-31ef995e37ad4291afdaebb2c6480280fd058858.tar.bz2 nixpkgs-31ef995e37ad4291afdaebb2c6480280fd058858.tar.lz nixpkgs-31ef995e37ad4291afdaebb2c6480280fd058858.tar.xz nixpkgs-31ef995e37ad4291afdaebb2c6480280fd058858.tar.zst nixpkgs-31ef995e37ad4291afdaebb2c6480280fd058858.zip |
bsd: init netbsd & openbsd userland
Adds a couple of useful NetBSD and OpenBSD derivations. Some of these will be integrated into Nixpkgs later. Noncomprehensive list: - netbsd.getent - netbsd.getconf - netbsd.fts - openbsd.mg - netbsd.compat (can replace libbsd)
Diffstat (limited to 'pkgs/os-specific/bsd/netbsd')
-rw-r--r-- | pkgs/os-specific/bsd/netbsd/compat-setup-hook.sh | 18 | ||||
-rw-r--r-- | pkgs/os-specific/bsd/netbsd/default.nix | 404 | ||||
-rw-r--r-- | pkgs/os-specific/bsd/netbsd/fts-setup-hook.sh | 16 | ||||
-rw-r--r-- | pkgs/os-specific/bsd/netbsd/getent.patch | 455 |
4 files changed, 893 insertions, 0 deletions
diff --git a/pkgs/os-specific/bsd/netbsd/compat-setup-hook.sh b/pkgs/os-specific/bsd/netbsd/compat-setup-hook.sh new file mode 100644 index 00000000000..d47d602e2ed --- /dev/null +++ b/pkgs/os-specific/bsd/netbsd/compat-setup-hook.sh @@ -0,0 +1,18 @@ +setupCompatFlags() { + # The `depHostOffset` describes how the host platform of the dependencies + # are slid relative to the depending package. It is brought into scope of + # the environment hook defined as the role of the dependency being applied. + case $depHostOffset in + -1) local role='BUILD_' ;; + 0) local role='' ;; + 1) local role='TARGET_' ;; + *) echo "cc-wrapper: Error: Cannot be used with $depHostOffset-offset deps" >2; + return 1 ;; + esac + + export NIX_${role}LDFLAGS+=" -lnbcompat" + export NIX_${role}CFLAGS_COMPILE+=" -DHAVE_NBTOOL_CONFIG_H" + export NIX_${role}CFLAGS_COMPILE+=" -include nbtool_config.h" +} + +addEnvHooks "$hostOffset" setupCompatFlags diff --git a/pkgs/os-specific/bsd/netbsd/default.nix b/pkgs/os-specific/bsd/netbsd/default.nix new file mode 100644 index 00000000000..8cbc765ec9e --- /dev/null +++ b/pkgs/os-specific/bsd/netbsd/default.nix @@ -0,0 +1,404 @@ +{ stdenv, hostPlatform, fetchcvs, lib, groff, mandoc, zlib, coreutils +, yacc, flex, libressl, bash }: + +let + fetchNetBSD = path: version: sha256: fetchcvs { + cvsRoot = ":pserver:anoncvs@anoncvs.NetBSD.org:/cvsroot"; + module = "src/${path}"; + inherit sha256; + tag = "netbsd-${builtins.replaceStrings ["."] ["-"] version}-RELEASE"; + }; + + netBSDDerivation = attrs: stdenv.mkDerivation ((rec { + name = "${attrs.pname or (baseNameOf attrs.path)}-netbsd-${attrs.version}"; + src = fetchNetBSD attrs.path attrs.version attrs.sha256; + + extraPaths = [ ]; + + nativeBuildInputs = [ makeMinimal mandoc groff install yacc flex ]; + buildInputs = [ compat ]; + installFlags = [ "includes" ]; + + # These should be coverd in nbcompat, but are missing, sadly + NIX_CFLAGS_COMPILE = [ + "-D__noinline=" + "-D__warn_references(a,b)=" + "-D__strong_alias(a,b)=" + "-D__va_list=va_list" + ]; + + # Definitions passed to share/mk/*.mk. Should be pretty simple - + # eventually maybe move it to a configure script. + DESTDIR = "$(out)"; + TOOLDIR = "$(out)"; + USETOOLS = "never"; + NOCLANGERROR="yes"; + NOGCCERROR="yes"; + LEX = "flex"; + + # libs will be provided by cc-wrapper + LIBCRT0=""; + LIBCRTI=""; + LIBCRTEND=""; + LIBCRTBEGIN=""; + LIBC=""; + LIBUTIL=""; + LIBSSL = ""; + LIBCRYPTO = ""; + LIBCURSES = ""; + "LIBDO.terminfo" = "_external"; + _GCC_CRTBEGIN = ""; + _GCC_CRTBEGINS = ""; + _GCC_CRTEND = ""; + _GCC_CRTENDS = ""; + _GCC_LIBGCCDIR = ""; + _GCC_CRTI = ""; + _GCC_CRTDIR = ""; + _GCC_CRTN = ""; + + # all dirs will be prefixed with DESTDIR + BINDIR = "/bin"; + LIBDIR = "/lib"; + SHLIBDIR = "/lib"; + MANDIR = "/share/man"; + INFODIR = "/share/info"; + DOCDIR = "/share/doc"; + LOCALEDIR = "/share/locale"; + X11BINDIR = "/bin"; + X11USRLIBDIR = "/lib"; + X11MANDIR = "/share/man"; + SHLINKDIR = "/usr/libexec"; + + HOST_SH = "${bash}/bin/sh"; + + # not using bsd binutils + SHLIB_WARNTEXTREL = "no"; + SHLIB_MKMAP = "no"; + OBJCOPY = "true"; + PRESERVE = "-p"; + + MACHINE_ARCH = hostPlatform.parsed.cpu.name; + MACHINE_CPU = hostPlatform.parsed.cpu.name; + + # NetBSD makefiles should be able to detect this + # but without they end up using gcc on Darwin stdenv + preConfigure = '' + export HAVE_${if stdenv.cc.isGNU then "GCC" else "LLVM"}=${lib.head (lib.splitString "." (lib.getVersion stdenv.cc.cc))} + '' + lib.optionalString (!builtins.hasAttr "nativeBuildInputs" attrs) '' + # hack until #38657 is fixed + export PATH=${install}/bin:$PATH + ''; + + postUnpack = '' + # merge together all extra paths + # there should be a better way to do this + sourceRoot=$PWD/$sourceRoot + export NETBSDSRCDIR=$sourceRoot + export BSDSRCDIR=$NETBSDSRCDIR + chmod -R u+w $sourceRoot + for path in $extraPaths; do + cd $path + find . -type d -exec mkdir -p $sourceRoot/\{} \; + find . -type f -exec cp -pr \{} $sourceRoot/\{} \; + chmod -R u+w $sourceRoot + done + + cd $sourceRoot + if [ -d ${attrs.path} ] + then sourceRoot=$sourceRoot/${attrs.path} + fi + ''; + + # need to create directories for xinstall to work + preInstall = '' + mkdir -p $out$BINDIR $out$LIBDIR $out$INFODIR \ + $out$DOCDIR $out$LOCALEDIR + for i in 1 2 3 4 5 6 7 8 9; do + mkdir -p $out$MANDIR/man$i $out$MANDIR/html$i + done + mkdir -p $out/usr/include + ''; + + postInstall = '' + # Remove lingering /usr references + if [ -d $out/usr ]; then + cd $out/usr + find . -type d -exec mkdir -p $out/\{} \; + find . -type f -exec mv \{} $out/\{} \; + find . -type d -delete + fi + + find $out -type d -empty -delete + ''; + + meta = with lib; { + maintainers = with maintainers; [matthewbauer]; + platforms = platforms.unix; + license = licenses.bsd2; + }; + }) // attrs); + + # BOOTSTRAPPING + makeMinimal = netBSDDerivation rec { + path = "tools/make"; + sha256 = "0l4794zwj2haark3azf9xwcwqlkbrifhb2glaa9iba4dkg2mklsb"; + version = "7.1.2"; + + buildInputs = []; + nativeBuildInputs = []; + NIX_CFLAGS_COMPILE = ""; + NIX_LDFLAGS = ""; + + patchPhase = '' + patchShebangs configure + ${make.patchPhase} + ''; + buildPhase = "sh ./buildmake.sh"; + installPhase = '' + install -D nbmake $out/bin/nbmake + ln -s $out/bin/nbmake $out/bin/make + mkdir -p $out/share + cp -r ../../share/mk $out/share/mk + ''; + extraPaths = [ make.src ] ++ make.extraPaths; + }; + + compat = netBSDDerivation { + path = "tools/compat"; + sha256 = "17phkfafybxwhzng44k5bhmag6i55br53ky1nwcmw583kg2fa86z"; + version = "7.1.2"; + + setupHook = ./compat-setup-hook.sh; + + # override defaults to prevent infinite recursion + nativeBuildInputs = [ makeMinimal ]; + buildInputs = [ zlib ]; + NIX_CFLAGS_COMPILE = ""; + NIX_LDFLAGS = ""; + + # temporarily use gnuinstall for bootstrapping + # bsdinstall will be built later + makeFlags = "INSTALL=${coreutils}/bin/install"; + RENAME = "-D"; + + postInstall = '' + mv $out/include/compat/* $out/include + rmdir $out/include/compat + + # why aren't these installed by netbsd? + install -D compat_defs.h $out/include/compat_defs.h + install -D $NETBSDSRCDIR/include/cdbw.h $out/include/cdbw.h + install -D $NETBSDSRCDIR/sys/sys/cdbr.h $out/include/cdbr.h + install -D $NETBSDSRCDIR/sys/sys/featuretest.h \ + $out/include/sys/featuretest.h + install -D $NETBSDSRCDIR/sys/sys/md5.h $out/include/md5.h + install -D $NETBSDSRCDIR/sys/sys/rmd160.h $out/include/rmd160.h + install -D $NETBSDSRCDIR/sys/sys/sha1.h $out/include/sha1.h + install -D $NETBSDSRCDIR/sys/sys/sha2.h $out/include/sha2.h + ''; + extraPaths = [ libc.src libutil.src + (fetchNetBSD "include" "7.1.2" "1vc58xrhrp202biiv1chhlh0jwnjr7k3qq91pm46k6v5j95j0qwp") + (fetchNetBSD "external/bsd/flex" "7.1.2" "0m0m72r3zzc9gi432h3xkqdzspr4n0hj4m8h7j74pwbvpfg9d9qq") + (fetchNetBSD "sys/sys" "7.1.2" "1vwnv5nk7rlgn5w9nkdqj9652hmwmfwqxj3ymcz0zk10abbaib93") + ] ++ libutil.extraPaths ++ libc.extraPaths; + }; + + install = netBSDDerivation { + path = "usr.bin/xinstall"; + version = "7.1.2"; + sha256 = "0nzhyh714m19h61m45gzc5dszkbafp5iaphbp5mza6w020fzf2y8"; + extraPaths = [ mtree.src make.src ]; + nativeBuildInputs = [ makeMinimal mandoc groff compat ]; + RENAME = "-D"; + }; + # END BOOTSTRAPPING + + libutil = netBSDDerivation { + path = "lib/libutil"; + version = "7.1.2"; + sha256 = "12848ynizz13mvn2kndrkq482xhkw323b7c8fg0zli1nhfsmwsm8"; + extraPaths = [ + (fetchNetBSD "common/lib/libutil" "7.1.2" "0q3ixrf36lip1dx0gafs0a03qfs5cs7n0myqq7af4jpjd6kh1831") + ]; + }; + + libc = netBSDDerivation { + path = "lib/libc"; + version = "7.1.2"; + sha256 = "13rcx3mbx2644z01zgk9gggdfr0hqdbsvd7zrsm2l13yf9aix6pg"; + extraPaths = [ + (fetchNetBSD "common/lib/libc" "7.1.2" "1va8zd4lqyrc1d0c9q04r8y88cfxpkhwcxasggxxvhksd3khkpha") + ]; + }; + + make = netBSDDerivation { + path = "usr.bin/make"; + sha256 = "0srkkg6qdzqlccfi4xh19gl766ks6hpss76bnfvwmd0zg4q4zdar"; + version = "7.1.2"; + patchPhase = '' + # make needs this to pick up our sys make files + NIX_CFLAGS_COMPILE+=" -D_PATH_DEFSYSPATH=\"$out/share/mk\"" + + # can't set owner or group in Nix build + # maybe there is a better way to trick it? + substituteInPlace $NETBSDSRCDIR/share/mk/bsd.prog.mk \ + --replace '-o ''${SCRIPTSOWN_''${.ALLSRC:T}:U''${SCRIPTSOWN}}' "" \ + --replace '-g ''${SCRIPTSGRP_''${.ALLSRC:T}:U''${SCRIPTSGRP}}' "" \ + --replace '-o ''${RUMPBINOWN} -g ''${RUMPBINGRP}' "" \ + --replace '-o ''${BINOWN} -g ''${BINGRP}' "" \ + --replace '-o ''${RUMPBINOWN} -g ''${RUMPBINGRP}' "" \ + --replace '-o ''${DEBUGOWN} -g ''${DEBUGGRP}' "" + substituteInPlace $NETBSDSRCDIR/share/mk/bsd.doc.mk \ + --replace '-o ''${DOCOWN} -g ''${DOCGRP}' "" + substituteInPlace $NETBSDSRCDIR/share/mk/bsd.man.mk \ + --replace '-o ''${MANOWN} -g ''${MANGRP}' "" + substituteInPlace $NETBSDSRCDIR/share/mk/bsd.files.mk \ + --replace '-o ''${FILESOWN_''${.ALLSRC:T}:U''${FILESOWN}}' "" \ + --replace '-g ''${FILESGRP_''${.ALLSRC:T}:U''${FILESGRP}}' "" + substituteInPlace $NETBSDSRCDIR/share/mk/bsd.inc.mk \ + --replace '-o ''${BINOWN} -g ''${BINGRP}' "" + substituteInPlace $NETBSDSRCDIR/share/mk/bsd.lib.mk \ + --replace '-o ''${DEBUGOWN} -g ''${DEBUGGRP}' "" \ + --replace '-o ''${LIBOWN} -g ''${LIBGRP}' "" + + substituteInPlace $NETBSDSRCDIR/share/mk/Makefile \ + --replace /usr/share/mk /share/mk + substituteInPlace $NETBSDSRCDIR/share/mk/bsd.sys.mk \ + --replace '-Wl,--fatal-warnings' "" + substituteInPlace $NETBSDSRCDIR/share/mk/bsd.lib.mk \ + --replace ' ''${_ARFL} ''${.TARGET} `NM=''${NM} ''${LORDER} ''${.ALLSRC:M*o} | ''${TSORT}`' ' ''${_ARFL} ''${.TARGET} ''${.ALLSRC:M*o}' \ + --replace '-Wl,-soname,''${_LIB}.so.''${SHLIB_SOVERSION}' "" \ + --replace '-Wl,--whole-archive' "" \ + --replace '-Wl,--no-whole-archive' "" + ''; + postInstall = '' + (cd $NETBSDSRCDIR/share/mk && make install) + ''; + extraPaths = [ + (fetchNetBSD "share/mk" "7.1.2" "0570v0siv0wygn8ygs1yy9pgk9xjw9x1axr5qg4xrddv3lskf9xa") + ]; + }; + + mtree = netBSDDerivation { + path = "usr.sbin/mtree"; + version = "7.1.2"; + sha256 = "1dhsyfvcm67kf5zdbg5dmx5y8fimnbll6qxwp3gjfmbxqigmc52m"; + }; + +in rec { + inherit compat libc libutil install make mtree netBSDDerivation; + + getent = netBSDDerivation { + path = "usr.bin/getent"; + sha256 = "1ylhw4dnpyrmcy8n5kjcxywm8qc9p124dqnm17x4magiqx1kh9iz"; + version = "7.1.2"; + patches = [ ./getent.patch ]; + }; + + getconf = netBSDDerivation { + path = "usr.bin/getconf"; + sha256 = "122vslz4j3h2mfs921nr2s6m078zcj697yrb75rwp2hnw3qz4s8q"; + version = "7.1.2"; + }; + + fts = netBSDDerivation { + pname = "fts"; + path = "include/fts.h"; + sha256 = "01d4fpxvz1pgzfk5xznz5dcm0x0gdzwcsfm1h3d0xc9kc6hj2q77"; + version = "7.1.2"; + nativeBuildInputs = [ ]; + extraPaths = [ + (fetchNetBSD "lib/libc/gen/fts.c" "7.1.2" "1yfd2liypj6xky2h0mgxi5lgpflmkkg4zf3ii3apz5cf8jq9gmn9") + (fetchNetBSD "lib/libc/include/namespace.h" "7.1.2" "0kwd4v8y0mfjhmwplsk52pvzbcpvpp2qy2g8c0jmfraam63q6q1y") + (fetchNetBSD "lib/libc/gen/fts.3" "7.1.2" "1asxw0n3fhjdadwkkq3xplfgqgl3q32w1lyrvbakfa3gs0wz5zc1") + ]; + buildPhase = '' + cc -c -Iinclude -Ilib/libc/include lib/libc/gen/fts.c \ + -o lib/libc/gen/fts.o + ar -rsc libfts.a lib/libc/gen/fts.o + ''; + installPhase = '' + install -D lib/libc/gen/fts.3 $out/share/man/man3/fts.3 + install -D include/fts.h $out/include/fts.h + install -D lib/libc/include/namespace.h $out/include/namespace.h + install -D libfts.a $out/lib/libfts.a + ''; + setupHook = ./fts-setup-hook.sh; + }; + + games = netBSDDerivation { + path = "games"; + sha256 = "04wjsang8f8kxsifiayklbxaaxmm3vx9rfr91hfbxj4hk8gkqzy1"; + version = "7.1.2"; + patchPhase = '' + sed -i '1i #include <time.h>' adventure/save.c + ''; + }; + + who = netBSDDerivation { + path = "usr.bin/who"; + version = "7.1.2"; + sha256 = "17ffwww957m3qw0b6fkgjpp12pd5ydg2hs9dxkkw0qpv11j00d88"; + }; + + finger = netBSDDerivation { + path = "usr.bin/finger"; + sha256 = "0jl672z50f2yf7ikp682b3xrarm6bnrrx9vi94xnp2fav8m8zfyi"; + version = "7.1.2"; + extraPaths = [ who.src ]; + }; + + fingerd = netBSDDerivation { + path = "usr.bin/fingerd"; + sha256 = "04wjsang8f8kxsifiayklbxaaxmm3vx9rfr91hfbxj4hk8gkqz00"; + version = "7.1.2"; + }; + + libedit = netBSDDerivation { + path = "lib/libedit"; + buildInputs = [ compat libterminfo ]; + patchPhase = '' + sed -i '1i #undef bool_t' el.h + ''; + version = "7.1.2"; + sha256 = "0qvr52j4qih10m7fa8nddn1psyjy9l0pa4ix02acyssjvgbz2kca"; + }; + + libterminfo = netBSDDerivation { + path = "lib/libterminfo"; + version = "7.1.2"; + sha256 = "06plg0bjqgbb0aghpb9qlk8wkp1l2izdlr64vbr5laqyw8jg84zq"; + buildInputs = [ compat tic nbperf ]; + extraPaths = [ + (fetchNetBSD "share/terminfo" "7.1.2" "1z5vzq8cw24j05r6df4vd6r57cvdbv7vbm4h962kplp14xrbg2h3") + ]; + }; + + libcurses = netBSDDerivation { + path = "lib/libcurses"; + version = "7.1.2"; + sha256 = "04djah9dadzw74nswn0xydkxn900kav8xdvxlxdl50nbrynxg9yf"; + buildInputs = [ compat libterminfo ]; + MKDOC = "no"; # missing vfontedpr + }; + + nbperf = netBSDDerivation { + path = "usr.bin/nbperf"; + version = "7.1.2"; + sha256 = "0gzm0zv2400lasnsswnjw9bwzyizhxzdbrcjwcl1k65aj86aqyqb"; + }; + + tic = netBSDDerivation { + path = "tools/tic"; + version = "7.1.2"; + sha256 = "092y7db7k4kh2jq8qc55126r5qqvlb8lq8mhmy5ipbi36hwb4zrz"; + HOSTPROG = "tic"; + buildInputs = [ compat nbperf ]; + extraPaths = [ + libterminfo.src + (fetchNetBSD "usr.bin/tic" "7.1.2" "1ghwsaag4gbwvgp3lfxscnh8hn27n8cscwmgjwp3bkx5vl85nfsa") + (fetchNetBSD "tools/Makefile.host" "7.1.2" "076r3amivb6xranpvqjmg7x5ibj4cbxaa3z2w1fh47h7d55dw9w8") + ]; + }; + +} diff --git a/pkgs/os-specific/bsd/netbsd/fts-setup-hook.sh b/pkgs/os-specific/bsd/netbsd/fts-setup-hook.sh new file mode 100644 index 00000000000..6b706417493 --- /dev/null +++ b/pkgs/os-specific/bsd/netbsd/fts-setup-hook.sh @@ -0,0 +1,16 @@ +ftsLdflags() { + # The `depHostOffset` describes how the host platform of the dependencies + # are slid relative to the depending package. It is brought into scope of + # the environment hook defined as the role of the dependency being applied. + case $depHostOffset in + -1) local role='BUILD_' ;; + 0) local role='' ;; + 1) local role='TARGET_' ;; + *) echo "cc-wrapper: Error: Cannot be used with $depHostOffset-offset deps" >2; + return 1 ;; + esac + + export NIX_${role}LDFLAGS+=" -lfts" +} + +addEnvHooks "$hostOffset" ftsLdflags diff --git a/pkgs/os-specific/bsd/netbsd/getent.patch b/pkgs/os-specific/bsd/netbsd/getent.patch new file mode 100644 index 00000000000..e9e34d19a31 --- /dev/null +++ b/pkgs/os-specific/bsd/netbsd/getent.patch @@ -0,0 +1,455 @@ +Author: Matthew Bauer +Description: Remove unavailable getent databases +Version: 7.1.2 +--- a/getent.c 2018-04-16 13:33:49.000000000 -0500 ++++ b/getent.c 2018-04-16 13:29:30.000000000 -0500 +@@ -42,7 +42,6 @@ + #include <grp.h> + #include <limits.h> + #include <netdb.h> +-#include <netgroup.h> + #include <pwd.h> + #include <stdio.h> + #include <stdarg.h> +@@ -57,27 +56,16 @@ + #include <arpa/nameser.h> + + #include <net/if.h> +-#include <net/if_ether.h> + + #include <netinet/in.h> /* for INET6_ADDRSTRLEN */ + +-#include <rpc/rpcent.h> +- +-#include <disktab.h> +- + static int usage(void) __attribute__((__noreturn__)); + static int parsenum(const char *, unsigned long *); +-static int disktab(int, char *[]); +-static int gettytab(int, char *[]); +-static int ethers(int, char *[]); + static int group(int, char *[]); + static int hosts(int, char *[]); +-static int netgroup(int, char *[]); + static int networks(int, char *[]); + static int passwd(int, char *[]); +-static int printcap(int, char *[]); + static int protocols(int, char *[]); +-static int rpc(int, char *[]); + static int services(int, char *[]); + static int shells(int, char *[]); + +@@ -92,17 +80,11 @@ + const char *name; + int (*callback)(int, char *[]); + } databases[] = { +- { "disktab", disktab, }, +- { "ethers", ethers, }, +- { "gettytab", gettytab, }, + { "group", group, }, + { "hosts", hosts, }, +- { "netgroup", netgroup, }, + { "networks", networks, }, + { "passwd", passwd, }, +- { "printcap", printcap, }, + { "protocols", protocols, }, +- { "rpc", rpc, }, + { "services", services, }, + { "shells", shells, }, + +@@ -195,49 +177,6 @@ + (void)printf("\n"); + } + +- +- /* +- * ethers +- */ +- +-static int +-ethers(int argc, char *argv[]) +-{ +- char hostname[MAXHOSTNAMELEN + 1], *hp; +- struct ether_addr ea, *eap; +- int i, rv; +- +- assert(argc > 1); +- assert(argv != NULL); +- +-#define ETHERSPRINT (void)printf("%-17s %s\n", ether_ntoa(eap), hp) +- +- rv = RV_OK; +- if (argc == 2) { +- warnx("Enumeration not supported on ethers"); +- rv = RV_NOENUM; +- } else { +- for (i = 2; i < argc; i++) { +- if ((eap = ether_aton(argv[i])) == NULL) { +- eap = &ea; +- hp = argv[i]; +- if (ether_hostton(hp, eap) != 0) { +- rv = RV_NOTFOUND; +- break; +- } +- } else { +- hp = hostname; +- if (ether_ntohost(hp, eap) != 0) { +- rv = RV_NOTFOUND; +- break; +- } +- } +- ETHERSPRINT; +- } +- } +- return rv; +-} +- + /* + * group + */ +@@ -298,7 +237,7 @@ + hosts(int argc, char *argv[]) + { + struct hostent *he; +- char addr[IN6ADDRSZ]; ++ char addr[NS_IN6ADDRSZ]; + int i, rv; + + assert(argc > 1); +@@ -312,9 +251,9 @@ + } else { + for (i = 2; i < argc; i++) { + if (inet_pton(AF_INET6, argv[i], (void *)addr) > 0) +- he = gethostbyaddr(addr, IN6ADDRSZ, AF_INET6); ++ he = gethostbyaddr(addr, NS_IN6ADDRSZ, AF_INET6); + else if (inet_pton(AF_INET, argv[i], (void *)addr) > 0) +- he = gethostbyaddr(addr, INADDRSZ, AF_INET); ++ he = gethostbyaddr(addr, NS_INADDRSZ, AF_INET); + else + he = gethostbyname(argv[i]); + if (he != NULL) +@@ -330,48 +269,6 @@ + } + + /* +- * netgroup +- */ +-static int +-netgroup(int argc, char *argv[]) +-{ +- int rv, i; +- bool first; +- const char *host, *user, *domain; +- +- assert(argc > 1); +- assert(argv != NULL); +- +-#define NETGROUPPRINT(s) (((s) != NULL) ? (s) : "") +- +- rv = RV_OK; +- if (argc == 2) { +- warnx("Enumeration not supported on netgroup"); +- rv = RV_NOENUM; +- } else { +- for (i = 2; i < argc; i++) { +- setnetgrent(argv[i]); +- first = true; +- while (getnetgrent(&host, &user, &domain) != 0) { +- if (first) { +- first = false; +- (void)fputs(argv[i], stdout); +- } +- (void)printf(" (%s,%s,%s)", +- NETGROUPPRINT(host), +- NETGROUPPRINT(user), +- NETGROUPPRINT(domain)); +- } +- if (!first) +- (void)putchar('\n'); +- endnetgrent(); +- } +- } +- +- return rv; +-} +- +- /* + * networks + */ + +@@ -464,227 +361,6 @@ + return rv; + } + +-static char * +-mygetent(const char * const * db_array, const char *name) +-{ +- char *buf = NULL; +- int error; +- +- switch (error = cgetent(&buf, db_array, name)) { +- case -3: +- warnx("tc= loop in record `%s' in `%s'", name, db_array[0]); +- break; +- case -2: +- warn("system error fetching record `%s' in `%s'", name, +- db_array[0]); +- break; +- case -1: +- case 0: +- break; +- case 1: +- warnx("tc= reference not found in record for `%s' in `%s'", +- name, db_array[0]); +- break; +- default: +- warnx("unknown error %d in record `%s' in `%s'", error, name, +- db_array[0]); +- break; +- } +- return buf; +-} +- +-static char * +-mygetone(const char * const * db_array, int first) +-{ +- char *buf = NULL; +- int error; +- +- switch (error = (first ? cgetfirst : cgetnext)(&buf, db_array)) { +- case -2: +- warnx("tc= loop in `%s'", db_array[0]); +- break; +- case -1: +- warn("system error fetching record in `%s'", db_array[0]); +- break; +- case 0: +- case 1: +- break; +- case 2: +- warnx("tc= reference not found in `%s'", db_array[0]); +- break; +- default: +- warnx("unknown error %d in `%s'", error, db_array[0]); +- break; +- } +- return buf; +-} +- +-static void +-capprint(const char *cap) +-{ +- char *c = strchr(cap, ':'); +- if (c) +- if (c == cap) +- (void)printf("true\n"); +- else { +- int l = (int)(c - cap); +- (void)printf("%*.*s\n", l, l, cap); +- } +- else +- (void)printf("%s\n", cap); +-} +- +-static void +-prettyprint(char *b) +-{ +-#define TERMWIDTH 65 +- int did = 0; +- size_t len; +- char *s, c; +- +- for (;;) { +- len = strlen(b); +- if (len <= TERMWIDTH) { +-done: +- if (did) +- printf("\t:"); +- printf("%s\n", b); +- return; +- } +- for (s = b + TERMWIDTH; s > b && *s != ':'; s--) +- continue; +- if (*s++ != ':') +- goto done; +- c = *s; +- *s = '\0'; +- if (did) +- printf("\t:"); +- did++; +- printf("%s\\\n", b); +- *s = c; +- b = s; +- } +-} +- +-static void +-handleone(const char * const *db_array, char *b, int recurse, int pretty, +- int level) +-{ +- char *tc; +- +- if (level && pretty) +- printf("\n"); +- if (pretty) +- prettyprint(b); +- else +- printf("%s\n", b); +- if (!recurse || cgetstr(b, "tc", &tc) <= 0) +- return; +- +- b = mygetent(db_array, tc); +- free(tc); +- +- if (b == NULL) +- return; +- +- handleone(db_array, b, recurse, pretty, ++level); +- free(b); +-} +- +-static int +-handlecap(const char *db, int argc, char *argv[]) +-{ +- static const char sfx[] = "=#:"; +- const char *db_array[] = { db, NULL }; +- char *b, *cap; +- int i, rv, c; +- size_t j; +- int expand = 1, recurse = 0, pretty = 0; +- +- assert(argc > 1); +- assert(argv != NULL); +- +- argc--; +- argv++; +- while ((c = getopt(argc, argv, "pnr")) != -1) +- switch (c) { +- case 'n': +- expand = 0; +- break; +- case 'r': +- expand = 0; +- recurse = 1; +- break; +- case 'p': +- pretty = 1; +- break; +- default: +- usage(); +- break; +- } +- +- argc -= optind; +- argv += optind; +- csetexpandtc(expand); +- rv = RV_OK; +- if (argc == 0) { +- for (b = mygetone(db_array, 1); b; b = mygetone(db_array, 0)) { +- handleone(db_array, b, recurse, pretty, 0); +- free(b); +- } +- } else { +- if ((b = mygetent(db_array, argv[0])) == NULL) +- return RV_NOTFOUND; +- if (argc == 1) +- handleone(db_array, b, recurse, pretty, 0); +- else { +- for (i = 2; i < argc; i++) { +- for (j = 0; j < sizeof(sfx) - 1; j++) { +- cap = cgetcap(b, argv[i], sfx[j]); +- if (cap) { +- capprint(cap); +- break; +- } +- } +- if (j == sizeof(sfx) - 1) +- printf("false\n"); +- } +- } +- free(b); +- } +- return rv; +-} +- +- /* +- * gettytab +- */ +- +-static int +-gettytab(int argc, char *argv[]) +-{ +- return handlecap(_PATH_GETTYTAB, argc, argv); +-} +- +- /* +- * printcap +- */ +- +-static int +-printcap(int argc, char *argv[]) +-{ +- return handlecap(_PATH_PRINTCAP, argc, argv); +-} +- +- /* +- * disktab +- */ +- +-static int +-disktab(int argc, char *argv[]) +-{ +- return handlecap(_PATH_DISKTAB, argc, argv); +-} +- + /* + * protocols + */ +@@ -726,47 +402,6 @@ + } + + /* +- * rpc +- */ +- +-static int +-rpc(int argc, char *argv[]) +-{ +- struct rpcent *re; +- unsigned long id; +- int i, rv; +- +- assert(argc > 1); +- assert(argv != NULL); +- +-#define RPCPRINT printfmtstrings(re->r_aliases, " ", " ", \ +- "%-16s %6d", \ +- re->r_name, re->r_number) +- +- setrpcent(1); +- rv = RV_OK; +- if (argc == 2) { +- while ((re = getrpcent()) != NULL) +- RPCPRINT; +- } else { +- for (i = 2; i < argc; i++) { +- if (parsenum(argv[i], &id)) +- re = getrpcbynumber((int)id); +- else +- re = getrpcbyname(argv[i]); +- if (re != NULL) +- RPCPRINT; +- else { +- rv = RV_NOTFOUND; +- break; +- } +- } +- } +- endrpcent(); +- return rv; +-} +- +- /* + * services + */ + |