diff options
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/fstat/fstat.c | 60 | ||||
-rw-r--r-- | usr.bin/fstat/fstat.h | 2 | ||||
-rw-r--r-- | usr.bin/fstat/fuser.c | 8 | ||||
-rw-r--r-- | usr.bin/netstat/main.c | 17 | ||||
-rw-r--r-- | usr.bin/netstat/netstat.h | 6 | ||||
-rw-r--r-- | usr.bin/netstat/unix.c | 78 |
6 files changed, 77 insertions, 94 deletions
diff --git a/usr.bin/fstat/fstat.c b/usr.bin/fstat/fstat.c index 1a07124cd5d..b670af9e343 100644 --- a/usr.bin/fstat/fstat.c +++ b/usr.bin/fstat/fstat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fstat.c,v 1.75 2013/03/31 01:42:28 bluhm Exp $ */ +/* $OpenBSD: fstat.c,v 1.76 2013/10/22 16:40:27 guenther Exp $ */ /* * Copyright (c) 2009 Todd C. Miller <Todd.Miller@courtesan.com> @@ -102,25 +102,25 @@ int signo; /* signal to send (fuser only) */ kvm_t *kd; uid_t uid; -void fstat_dofile(struct kinfo_file2 *); +void fstat_dofile(struct kinfo_file *); void fstat_header(void); void getinetproto(int); void usage(void); int getfname(char *); -void cryptotrans(struct kinfo_file2 *); -void kqueuetrans(struct kinfo_file2 *); -void pipetrans(struct kinfo_file2 *); -struct kinfo_file2 *splice_find(char, u_int64_t); -void splice_insert(char, u_int64_t, struct kinfo_file2 *); -void find_splices(struct kinfo_file2 *, int); -void print_inet_details(struct kinfo_file2 *); +void cryptotrans(struct kinfo_file *); +void kqueuetrans(struct kinfo_file *); +void pipetrans(struct kinfo_file *); +struct kinfo_file *splice_find(char, u_int64_t); +void splice_insert(char, u_int64_t, struct kinfo_file *); +void find_splices(struct kinfo_file *, int); +void print_inet_details(struct kinfo_file *); #ifdef INET6 -void print_inet6_details(struct kinfo_file2 *); +void print_inet6_details(struct kinfo_file *); #endif -void print_sock_details(struct kinfo_file2 *); -void socktrans(struct kinfo_file2 *); -void systracetrans(struct kinfo_file2 *); -void vtrans(struct kinfo_file2 *); +void print_sock_details(struct kinfo_file *); +void socktrans(struct kinfo_file *); +void systracetrans(struct kinfo_file *); +void vtrans(struct kinfo_file *); const char *inet6_addrstr(struct in6_addr *); int signame_to_signum(char *); void hide(void *p); @@ -137,7 +137,7 @@ int main(int argc, char *argv[]) { struct passwd *passwd; - struct kinfo_file2 *kf, *kflast; + struct kinfo_file *kf, *kflast; int arg, ch, what; char *memf, *nlistf, *optstr; char buf[_POSIX2_LINE_MAX]; @@ -271,7 +271,7 @@ main(int argc, char *argv[]) checkfile = 1; } - if ((kf = kvm_getfile2(kd, what, arg, sizeof(*kf), &cnt)) == NULL) + if ((kf = kvm_getfiles(kd, what, arg, sizeof(*kf), &cnt)) == NULL) errx(1, "%s", kvm_geterr(kd)); find_splices(kf, cnt); @@ -336,7 +336,7 @@ pid_t Pid; * print open files attributed to this process */ void -fstat_dofile(struct kinfo_file2 *kf) +fstat_dofile(struct kinfo_file *kf) { Uname = user_from_uid(kf->p_uid, 0); @@ -378,7 +378,7 @@ fstat_dofile(struct kinfo_file2 *kf) } void -vtrans(struct kinfo_file2 *kf) +vtrans(struct kinfo_file *kf) { const char *badtype = NULL; char rw[3], mode[12]; @@ -471,7 +471,7 @@ vtrans(struct kinfo_file2 *kf) } void -pipetrans(struct kinfo_file2 *kf) +pipetrans(struct kinfo_file *kf) { void *maxaddr; @@ -502,7 +502,7 @@ pipetrans(struct kinfo_file2 *kf) } void -kqueuetrans(struct kinfo_file2 *kf) +kqueuetrans(struct kinfo_file *kf) { PREFIX(kf->fd_fd); @@ -518,7 +518,7 @@ kqueuetrans(struct kinfo_file2 *kf) } void -cryptotrans(struct kinfo_file2 *kf) +cryptotrans(struct kinfo_file *kf) { PREFIX(kf->fd_fd); @@ -530,7 +530,7 @@ cryptotrans(struct kinfo_file2 *kf) } void -systracetrans(struct kinfo_file2 *kf) +systracetrans(struct kinfo_file *kf) { PREFIX(kf->fd_fd); @@ -570,7 +570,7 @@ inet6_addrstr(struct in6_addr *p) #endif void -splice_insert(char type, u_int64_t ptr, struct kinfo_file2 *data) +splice_insert(char type, u_int64_t ptr, struct kinfo_file *data) { ENTRY entry, *found; @@ -584,7 +584,7 @@ splice_insert(char type, u_int64_t ptr, struct kinfo_file2 *data) found->data = NULL; } -struct kinfo_file2 * +struct kinfo_file * splice_find(char type, u_int64_t ptr) { ENTRY entry, *found; @@ -597,7 +597,7 @@ splice_find(char type, u_int64_t ptr) } void -find_splices(struct kinfo_file2 *kf, int cnt) +find_splices(struct kinfo_file *kf, int cnt) { int i, created; @@ -617,7 +617,7 @@ find_splices(struct kinfo_file2 *kf, int cnt) } void -print_inet_details(struct kinfo_file2 *kf) +print_inet_details(struct kinfo_file *kf) { struct in_addr laddr, faddr; @@ -653,7 +653,7 @@ print_inet_details(struct kinfo_file2 *kf) #ifdef INET6 void -print_inet6_details(struct kinfo_file2 *kf) +print_inet6_details(struct kinfo_file *kf) { char xaddrbuf[NI_MAXHOST + 2]; struct in6_addr laddr6, faddr6; @@ -700,7 +700,7 @@ print_inet6_details(struct kinfo_file2 *kf) #endif void -print_sock_details(struct kinfo_file2 *kf) +print_sock_details(struct kinfo_file *kf) { if (kf->so_family == AF_INET) print_inet_details(kf); @@ -711,7 +711,7 @@ print_sock_details(struct kinfo_file2 *kf) } void -socktrans(struct kinfo_file2 *kf) +socktrans(struct kinfo_file *kf) { static char *stypename[] = { "unused", /* 0 */ @@ -809,7 +809,7 @@ socktrans(struct kinfo_file2 *kf) hide((void *)(uintptr_t)kf->f_data); } if (kf->so_splice != 0 || kf->so_splicelen == -1) { - struct kinfo_file2 *from, *to; + struct kinfo_file *from, *to; from = splice_find('<', kf->f_data); to = NULL; diff --git a/usr.bin/fstat/fstat.h b/usr.bin/fstat/fstat.h index 6e2b230261f..573ee7a9a20 100644 --- a/usr.bin/fstat/fstat.h +++ b/usr.bin/fstat/fstat.h @@ -45,6 +45,6 @@ extern struct fileargs fileargs; extern char *__progname; -void fuser_check(struct kinfo_file2 *); +void fuser_check(struct kinfo_file *); void fuser_run(void); void usage(void); diff --git a/usr.bin/fstat/fuser.c b/usr.bin/fstat/fuser.c index 8486d33ac89..6713055c1db 100644 --- a/usr.bin/fstat/fuser.c +++ b/usr.bin/fstat/fuser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fuser.c,v 1.2 2009/07/19 12:56:19 millert Exp $ */ +/* $OpenBSD: fuser.c,v 1.3 2013/10/22 16:40:28 guenther Exp $ */ /* * Copyright (c) 2009 Todd C. Miller <Todd.Miller@courtesan.com> @@ -65,7 +65,7 @@ * to a file held by a process (kf), else 0. */ static int -match(struct filearg *fa, struct kinfo_file2 *kf) +match(struct filearg *fa, struct kinfo_file *kf) { if (fa->dev == kf->va_fsid) { if (cflg) @@ -77,11 +77,11 @@ match(struct filearg *fa, struct kinfo_file2 *kf) } /* - * Examine kinfo_file2 struct and record the details if they + * Examine kinfo_file struct and record the details if they * match a watched file. */ void -fuser_check(struct kinfo_file2 *kf) +fuser_check(struct kinfo_file *kf) { struct filearg *fa; struct fuser *fu; diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index 88c0c694a64..9b2b62e4310 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.95 2013/03/20 15:23:37 deraadt Exp $ */ +/* $OpenBSD: main.c,v 1.96 2013/10/22 16:40:28 guenther Exp $ */ /* $NetBSD: main.c,v 1.9 1996/05/07 02:55:02 thorpej Exp $ */ /* @@ -31,7 +31,6 @@ */ #include <sys/param.h> -#include <sys/file.h> #include <sys/protosw.h> #include <sys/socket.h> #include <sys/sysctl.h> @@ -42,6 +41,7 @@ #include <ctype.h> #include <err.h> #include <errno.h> +#include <fcntl.h> #include <kvm.h> #include <limits.h> #include <netdb.h> @@ -162,6 +162,7 @@ main(int argc, char *argv[]) u_int tableid; int Tflag = 0; int repeatcount = 0; + int need_nlist; hideroot = getuid(); @@ -331,6 +332,10 @@ main(int argc, char *argv[]) } #endif + need_nlist = !mflag && (pflag || nlistf != NULL || memf != NULL || + (!iflag && !sflag && (rflag ? Aflag : + (gflag || af != AF_UNIX || Pflag)))); + /* * Discard setgid privileges if not the running kernel so that bad * guys can't print interesting stuff from kernel memory. @@ -341,8 +346,8 @@ main(int argc, char *argv[]) if (setresgid(gid, gid, gid) == -1) err(1, "setresgid"); - if ((kvmd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, - buf)) == NULL) { + if ((kvmd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY | + (need_nlist ? 0 : KVM_NO_FILES), buf)) == NULL) { fprintf(stderr, "%s: kvm_openfiles: %s\n", __progname, buf); exit(1); } @@ -351,7 +356,7 @@ main(int argc, char *argv[]) if (setresgid(gid, gid, gid) == -1) err(1, "setresgid"); - if (kvm_nlist(kvmd, nl) < 0 || nl[0].n_type == 0) { + if (need_nlist && (kvm_nlist(kvmd, nl) < 0 || nl[0].n_type == 0)) { if (nlistf) fprintf(stderr, "%s: %s: no namelist\n", __progname, nlistf); @@ -429,7 +434,7 @@ main(int argc, char *argv[]) printproto(tp, tp->pr_name, AF_INET6, tableid, pcbaddr); if ((af == AF_UNIX || af == AF_UNSPEC) && !sflag) - unixpr(nl[N_UNIXSW].n_value, pcbaddr); + unixpr(kvmd, pcbaddr); exit(0); } diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h index bad8b97e271..539d9775d00 100644 --- a/usr.bin/netstat/netstat.h +++ b/usr.bin/netstat/netstat.h @@ -1,4 +1,4 @@ -/* $OpenBSD: netstat.h,v 1.65 2013/03/20 15:23:37 deraadt Exp $ */ +/* $OpenBSD: netstat.h,v 1.66 2013/10/22 16:40:28 guenther Exp $ */ /* $NetBSD: netstat.h,v 1.6 1996/05/07 02:55:05 thorpej Exp $ */ /* @@ -32,6 +32,8 @@ * from: @(#)netstat.h 8.2 (Berkeley) 1/4/94 */ +#include <kvm.h> + /* What is the max length of a pointer printed with %p (including 0x)? */ #define PLEN (LONG_BIT / 4 + 2) @@ -132,7 +134,7 @@ void nsprotopr(u_long, char *); void intpr(int, int); -void unixpr(u_long, u_long); +void unixpr(kvm_t *, u_long); void mroutepr(u_long, u_long, u_long); void mrt_stats(void); diff --git a/usr.bin/netstat/unix.c b/usr.bin/netstat/unix.c index 2a95b272499..01454785a60 100644 --- a/usr.bin/netstat/unix.c +++ b/usr.bin/netstat/unix.c @@ -1,4 +1,4 @@ -/* $OpenBSD: unix.c,v 1.20 2013/08/18 16:32:24 guenther Exp $ */ +/* $OpenBSD: unix.c,v 1.21 2013/10/22 16:40:28 guenther Exp $ */ /* $NetBSD: unix.c,v 1.13 1995/10/03 21:42:48 thorpej Exp $ */ /*- @@ -42,9 +42,8 @@ #include <sys/un.h> #include <sys/unpcb.h> #define _KERNEL -struct uio; -struct proc; #include <sys/file.h> +#undef _KERNEL #include <netinet/in.h> @@ -54,65 +53,42 @@ struct proc; #include <kvm.h> #include "netstat.h" -static void unixdomainpr(struct socket *, caddr_t, u_long); - -static struct file *file, *fileNFILE; -static int fcnt; -extern kvm_t *kvmd; +static void unixdomainpr(const struct kinfo_file *, u_long); void -unixpr(u_long off, u_long pcbaddr) +unixpr(kvm_t *kvmd, u_long pcbaddr) { - struct file *fp; + struct kinfo_file *kf; struct socket sock, *so = &sock; - char *filebuf; - struct protosw *unixsw = (struct protosw *)off; + int i, fcnt; - filebuf = kvm_getfiles(kvmd, KERN_FILE, 0, &fcnt); - if (filebuf == NULL) { + kf = kvm_getfiles(kvmd, KERN_FILE_BYFILE, 0, sizeof(*kf), &fcnt); + if (kf == NULL) { printf("Out of memory (file table).\n"); return; } - file = (struct file *)(filebuf + sizeof(fp)); - fileNFILE = file + fcnt; - for (fp = file; fp < fileNFILE; fp++) { - if (fp->f_count == 0 || fp->f_type != DTYPE_SOCKET) - continue; - if (kread((u_long)fp->f_data, so, sizeof (*so))) - continue; - /* kludge */ - if (so->so_proto >= unixsw && so->so_proto <= unixsw + 2) - if (so->so_pcb) - unixdomainpr(so, fp->f_data, pcbaddr); + for (i = 0; i < fcnt; i++) { + if (kf[i].f_count != 0 && kf[i].f_type == DTYPE_SOCKET && + kf[i].so_family == AF_LOCAL && (kf[i].so_pcb != 0 || + kf[i].unp_path[0] != '\0')) + unixdomainpr(&kf[i], pcbaddr); } } -static char *socktype[] = +static const char *socktype[] = { "#0", "stream", "dgram", "raw", "rdm", "seqpacket" }; static void -unixdomainpr(struct socket *so, caddr_t soaddr, u_long pcbaddr) +unixdomainpr(const struct kinfo_file *kf, u_long pcbaddr) { - struct unpcb unpcb, *unp = &unpcb; - struct mbuf mbuf, *m; - struct sockaddr_un *sa = NULL; static int first = 1; if (Pflag) { - if (pcbaddr == (u_long)soaddr) + if (pcbaddr == kf->f_data) socket_dump(pcbaddr); return; } - if (kread((u_long)so->so_pcb, unp, sizeof (*unp))) - return; - if (unp->unp_addr) { - m = &mbuf; - if (kread((u_long)unp->unp_addr, m, sizeof (*m))) - m = NULL; - sa = (struct sockaddr_un *)(m->m_dat); - } else - m = NULL; if (first) { printf("Active UNIX domain sockets\n"); printf("%-*.*s %-6.6s %-6.6s %-6.6s %*.*s %*.*s %*.*s %*.*s Addr\n", @@ -121,17 +97,17 @@ unixdomainpr(struct socket *so, caddr_t soaddr, u_long pcbaddr) PLEN, PLEN, "Refs", PLEN, PLEN, "Nextref"); first = 0; } - printf("%*p %-6.6s %6ld %6ld %*p %*p %*p %*p", - PLEN, hideroot ? 0 : soaddr, - socktype[so->so_type], so->so_rcv.sb_cc, so->so_snd.sb_cc, - PLEN, hideroot ? 0 : unp->unp_vnode, - PLEN, hideroot ? 0 : unp->unp_conn, - PLEN, hideroot ? 0 : unp->unp_refs, - PLEN, hideroot ? 0 : unp->unp_nextref); - if (m) - printf(" %.*s", - (int)(m->m_len - (int)(sizeof(*sa) - sizeof(sa->sun_path))), - sa->sun_path); + +#define FAKE_PTR(p) (PLEN - ((p) ? 0 : 2)), p, ((p) ? "" : "x0") + printf("%#*llx%s %-6.6s %6ld %6ld %#*llx%s %#*llx%s %#*llx%s %#*llx%s", + FAKE_PTR(kf->f_data), socktype[kf->so_type], + kf->so_rcv_cc, kf->so_snd_cc, + FAKE_PTR(kf->v_un), + FAKE_PTR(kf->unp_conn), + FAKE_PTR(kf->unp_refs), + FAKE_PTR(kf->unp_nextref)); + if (kf->unp_path[0] != '\0') + printf(" %.*s", KI_UNPPATHLEN, kf->unp_path); putchar('\n'); } |