diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2018-09-22 16:50:36 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2018-09-22 16:50:36 +0000 |
commit | 415eaace606e3303643870ec174fbcba6e55a047 (patch) | |
tree | 3207316811b43b0b8287f09e22418399391944b0 /usr.bin/top | |
parent | dc02f123aa694cf034c65dd662567cca548d81c6 (diff) |
Use user_from_uid() and uid_from_user() directly. The wrappers
in username.c are now so simple there is no longer a good reason
to use them. OK deraadt@
Diffstat (limited to 'usr.bin/top')
-rw-r--r-- | usr.bin/top/Makefile | 4 | ||||
-rw-r--r-- | usr.bin/top/machine.c | 8 | ||||
-rw-r--r-- | usr.bin/top/machine.h | 4 | ||||
-rw-r--r-- | usr.bin/top/top.c | 20 | ||||
-rw-r--r-- | usr.bin/top/top.h | 6 | ||||
-rw-r--r-- | usr.bin/top/username.c | 58 | ||||
-rw-r--r-- | usr.bin/top/utils.c | 4 | ||||
-rw-r--r-- | usr.bin/top/utils.h | 4 |
8 files changed, 22 insertions, 86 deletions
diff --git a/usr.bin/top/Makefile b/usr.bin/top/Makefile index 060b1af32ae..44b33b17650 100644 --- a/usr.bin/top/Makefile +++ b/usr.bin/top/Makefile @@ -1,11 +1,11 @@ -# $OpenBSD: Makefile,v 1.16 2014/07/16 20:06:27 okan Exp $ +# $OpenBSD: Makefile,v 1.17 2018/09/22 16:50:35 millert Exp $ # # Makefile for OpenBSD top-3.4. PROG= top CFLAGS+=-I. -Wall -Wmissing-prototypes -SRCS= commands.c display.c machine.c screen.c top.c username.c utils.c +SRCS= commands.c display.c machine.c screen.c top.c utils.c DPADD= ${LIBCURSES} LDADD= -lcurses diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c index 2926ec2133b..10cf0b4a2bb 100644 --- a/usr.bin/top/machine.c +++ b/usr.bin/top/machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machine.c,v 1.91 2018/09/13 15:23:32 millert Exp $ */ +/* $OpenBSD: machine.c,v 1.92 2018/09/22 16:50:35 millert Exp $ */ /*- * Copyright (c) 1994 Thorsten Lockert <tholo@sigmasoft.com> @@ -545,8 +545,8 @@ format_comm(struct kinfo_proc *kp) } char * -format_next_process(caddr_t hndl, const char *(*get_userid)(uid_t), pid_t *pid, - int show_threads) +format_next_process(caddr_t hndl, const char *(*get_userid)(uid_t, int), + pid_t *pid, int show_threads) { char *p_wait; struct kinfo_proc *pp; @@ -573,7 +573,7 @@ format_next_process(caddr_t hndl, const char *(*get_userid)(uid_t), pid_t *pid, if (show_threads) snprintf(buf, sizeof(buf), "%8d", pp->p_tid); else - snprintf(buf, sizeof(buf), "%s", (*get_userid)(pp->p_ruid)); + snprintf(buf, sizeof(buf), "%s", (*get_userid)(pp->p_ruid, 0)); /* format this entry */ snprintf(fmt, sizeof(fmt), Proc_format, pp->p_pid, buf, diff --git a/usr.bin/top/machine.h b/usr.bin/top/machine.h index 4c7c62b78dc..55a6b8572c2 100644 --- a/usr.bin/top/machine.h +++ b/usr.bin/top/machine.h @@ -1,4 +1,4 @@ -/* $OpenBSD: machine.h,v 1.21 2018/09/13 15:23:32 millert Exp $ */ +/* $OpenBSD: machine.h,v 1.22 2018/09/22 16:50:35 millert Exp $ */ /* * Top users/processes display for Unix @@ -89,7 +89,7 @@ extern void get_system_info(struct system_info *); extern caddr_t get_process_info(struct system_info *, struct process_select *, int (*) (const void *, const void *)); -extern char *format_next_process(caddr_t, const char *(*)(uid_t), pid_t *, int); +extern char *format_next_process(caddr_t, const char *(*)(uid_t, int), pid_t *, int); extern uid_t proc_owner(pid_t); extern struct kinfo_proc *getprocs(int, int, int *); diff --git a/usr.bin/top/top.c b/usr.bin/top/top.c index 178696ba792..3a45cdb44b6 100644 --- a/usr.bin/top/top.c +++ b/usr.bin/top/top.c @@ -1,4 +1,4 @@ -/* $OpenBSD: top.c,v 1.91 2018/09/13 15:23:32 millert Exp $ */ +/* $OpenBSD: top.c,v 1.92 2018/09/22 16:50:35 millert Exp $ */ /* * Top users/processes display for Unix @@ -36,6 +36,7 @@ #include <signal.h> #include <string.h> #include <poll.h> +#include <pwd.h> #include <stdlib.h> #include <limits.h> #include <unistd.h> @@ -150,12 +151,12 @@ parseargs(int ac, char **av) case 'U': /* display only username's processes */ if (optarg[0] == '-') { - if ((ps.huid = userid(optarg+1)) == (uid_t)-1) - new_message(MT_delayed, "%s: unknown user", - optarg); + if (uid_from_user(optarg+1, &ps.huid) == -1) + new_message(MT_delayed, + "%s: unknown user", optarg); else ps.uid = (uid_t)-1; - } else if ((ps.uid = userid(optarg)) == (uid_t)-1) + } else if (uid_from_user(optarg, &ps.uid) == -1) new_message(MT_delayed, "%s: unknown user", optarg); else @@ -279,7 +280,7 @@ int main(int argc, char *argv[]) { char *uname_field = "USERNAME", *header_text, *env_top; - const char *(*get_userid)(uid_t) = username; + const char *(*get_userid)(uid_t, int) = user_from_uid; char **preset_argv = NULL, **av = argv; int preset_argc = 0, ac = argc, active_procs, i; sigset_t mask, oldmask; @@ -562,7 +563,6 @@ rundisplay(void) char ch, *iptr; int change, i; struct pollfd pfd[1]; - uid_t uid, huid; static char command_chars[] = "\f qh?en#sdkriIuSopCHg+P1"; /* @@ -803,20 +803,18 @@ rundisplay(void) ps.uid = (uid_t)-1; ps.huid = (uid_t)-1; } else if (tempbuf[0] == '-') { - if ((huid = userid(tempbuf+1)) == (uid_t)-1) { + if (uid_from_user(tempbuf+1, &ps.huid) == -1) { new_message(MT_standout, " %s: unknown user", tempbuf+1); no_command = Yes; } else { - ps.huid = huid; ps.uid = (uid_t)-1; } - } else if ((uid = userid(tempbuf)) == (uid_t)-1) { + } else if (uid_from_user(tempbuf, &ps.uid) == -1) { new_message(MT_standout, " %s: unknown user", tempbuf); no_command = Yes; } else { - ps.uid = uid; ps.huid = (uid_t)-1; } putr(); diff --git a/usr.bin/top/top.h b/usr.bin/top/top.h index f19952eee7c..2a7e9f64f93 100644 --- a/usr.bin/top/top.h +++ b/usr.bin/top/top.h @@ -1,4 +1,4 @@ -/* $OpenBSD: top.h,v 1.17 2018/09/16 17:37:11 krw Exp $ */ +/* $OpenBSD: top.h,v 1.18 2018/09/22 16:50:35 millert Exp $ */ /* * Top users/processes display for Unix @@ -76,7 +76,3 @@ extern char *renice_procs(char *); /* top.c */ extern void quit(int); - -/* username.c */ -extern const char *username(uid_t); -extern uid_t userid(const char *); diff --git a/usr.bin/top/username.c b/usr.bin/top/username.c deleted file mode 100644 index 326ce593ee9..00000000000 --- a/usr.bin/top/username.c +++ /dev/null @@ -1,58 +0,0 @@ -/* $OpenBSD: username.c,v 1.20 2018/09/22 02:18:19 procter Exp $ */ - -/* - * Top users/processes display for Unix - * Version 3 - * - * Copyright (c) 1984, 1989, William LeFebvre, Rice University - * Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University - * - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR OR HIS EMPLOYER 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. - */ - -/* - * Username translation code for top. - */ - -#include <sys/types.h> -#include <stdio.h> -#include <string.h> -#include <pwd.h> - -#include "top.local.h" -#include "top.h" -#include "utils.h" - -const char * -username(uid_t uid) -{ - return user_from_uid(uid, 0); -} - -uid_t -userid(const char *username) -{ - uid_t uid; - if (uid_from_user(username, &uid) == -1) { - uid = (uid_t)-1; - } - return uid; -} diff --git a/usr.bin/top/utils.c b/usr.bin/top/utils.c index 9e7f9cce41b..29fb3d84abe 100644 --- a/usr.bin/top/utils.c +++ b/usr.bin/top/utils.c @@ -1,4 +1,4 @@ -/* $OpenBSD: utils.c,v 1.27 2018/09/13 15:23:32 millert Exp $ */ +/* $OpenBSD: utils.c,v 1.28 2018/09/22 16:50:35 millert Exp $ */ /* * Top users/processes display for Unix @@ -89,7 +89,7 @@ itoa(int val) * justified in a 6 character field to match uname_field in top.c. */ const char * -format_uid(uid_t uid) +format_uid(uid_t uid, int nouser) { static char buffer[16]; /* result is built here */ diff --git a/usr.bin/top/utils.h b/usr.bin/top/utils.h index 034d2f62c60..09fd9a3cef0 100644 --- a/usr.bin/top/utils.h +++ b/usr.bin/top/utils.h @@ -1,4 +1,4 @@ -/* $OpenBSD: utils.h,v 1.9 2018/09/13 15:23:32 millert Exp $ */ +/* $OpenBSD: utils.h,v 1.10 2018/09/22 16:50:35 millert Exp $ */ /* * Top users/processes display for Unix @@ -32,7 +32,7 @@ int atoiwi(char *); char *itoa(int); -const char *format_uid(uid_t); +const char *format_uid(uid_t, int); int digits(int); int string_index(char *, char **); char **argparse(char *, int *); |