Make get/setuid prog ops (so that i can do rump.ping -f regardless

of host privs).
This commit is contained in:
pooka 2011-03-11 09:59:56 +00:00
parent a6893ed075
commit 3e81f0bf9e
4 changed files with 22 additions and 11 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ping.c,v 1.92 2010/12/13 17:42:17 pooka Exp $ */
/* $NetBSD: ping.c,v 1.93 2011/03/11 09:59:56 pooka Exp $ */
/*
* Copyright (c) 1989, 1993
@ -58,7 +58,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: ping.c,v 1.92 2010/12/13 17:42:17 pooka Exp $");
__RCSID("$NetBSD: ping.c,v 1.93 2011/03/11 09:59:56 pooka Exp $");
#endif
#include <stdio.h>
@ -261,7 +261,7 @@ main(int argc, char *argv[])
if (prog_shutdown(sloop, SHUT_RD) == -1)
warn("Cannot shutdown for read");
if (setuid(getuid()) == -1)
if (prog_setuid(prog_getuid()) == -1)
err(1, "setuid");
setprogname(argv[0]);
@ -410,11 +410,11 @@ main(int argc, char *argv[])
if (interval == 0)
interval = (pingflags & F_FLOOD) ? FLOOD_INTVL : 1.0;
#ifndef sgi
if (pingflags & F_FLOOD && getuid())
if (pingflags & F_FLOOD && prog_getuid())
errx(1, "Must be superuser to use -f");
if (interval < 1.0 && getuid())
if (interval < 1.0 && prog_getuid())
errx(1, "Must be superuser to use < 1 sec ping interval");
if (preload > 0 && getuid())
if (preload > 0 && prog_getuid())
errx(1, "Must be superuser to use -l");
#endif
sec_to_timeval(interval, &interval_tv);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ping_hostops.c,v 1.1 2010/12/13 17:42:17 pooka Exp $ */
/* $NetBSD: ping_hostops.c,v 1.2 2011/03/11 09:59:56 pooka Exp $ */
/*
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: ping_hostops.c,v 1.1 2010/12/13 17:42:17 pooka Exp $");
__RCSID("$NetBSD: ping_hostops.c,v 1.2 2011/03/11 09:59:56 pooka Exp $");
#endif /* !lint */
#include <sys/types.h>
@ -48,4 +48,6 @@ const struct prog_ops prog_ops = {
.op_recvfrom = recvfrom,
.op_sendto = sendto,
.op_close = close,
.op_getuid = getuid,
.op_setuid = setuid,
};

View File

@ -1,4 +1,4 @@
/* $NetBSD: ping_rumpops.c,v 1.1 2010/12/13 17:42:17 pooka Exp $ */
/* $NetBSD: ping_rumpops.c,v 1.2 2011/03/11 09:59:56 pooka Exp $ */
/*
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: ping_rumpops.c,v 1.1 2010/12/13 17:42:17 pooka Exp $");
__RCSID("$NetBSD: ping_rumpops.c,v 1.2 2011/03/11 09:59:56 pooka Exp $");
#endif /* !lint */
#include <sys/types.h>
@ -53,4 +53,6 @@ const struct prog_ops prog_ops = {
.op_sendto = rump_sys_sendto,
.op_recvfrom = rump_sys_recvfrom,
.op_close = rump_sys_close,
.op_getuid = rump_sys_getuid,
.op_setuid = rump_sys_setuid,
};

View File

@ -1,4 +1,4 @@
/* $NetBSD: prog_ops.h,v 1.2 2010/12/13 19:19:10 pooka Exp $ */
/* $NetBSD: prog_ops.h,v 1.3 2011/03/11 09:59:56 pooka Exp $ */
/*
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@ -47,6 +47,9 @@ struct prog_ops {
const struct sockaddr *, socklen_t);
int (*op_close)(int);
uid_t (*op_getuid)(void);
int (*op_setuid)(uid_t);
};
extern const struct prog_ops prog_ops;
@ -58,6 +61,8 @@ extern const struct prog_ops prog_ops;
#define prog_recvfrom prog_ops.op_recvfrom
#define prog_sendto prog_ops.op_sendto
#define prog_close prog_ops.op_close
#define prog_getuid prog_ops.op_getuid
#define prog_setuid prog_ops.op_setuid
#else
#define prog_init ((int (*)(void))NULL)
#define prog_socket socket
@ -67,6 +72,8 @@ extern const struct prog_ops prog_ops;
#define prog_recvfrom recvfrom
#define prog_sendto sendto
#define prog_close close
#define prog_getuid getuid
#define prog_setuid setuid
#endif
#endif /* _PROG_OPS_H_ */