diff options
| author | lukem <lukem@NetBSD.org> | 1997-07-07 02:27:05 +0000 |
|---|---|---|
| committer | lukem <lukem@NetBSD.org> | 1997-07-07 02:27:05 +0000 |
| commit | d65e85e261fd4e31a07baa511ec50b51e14cf95e (patch) | |
| tree | 9c7e76b8779375b942a87d604fc662087eef3ce6 /usr.sbin/ypbind | |
| parent | 42736edb4defdabbfbf16d76a8fb016c83285a7c (diff) | |
* use _yp_invalid_domain() (from libc) to validate the domainnames
* cleanup for -Wall
* use __RCSID
the following were inspired by openbsd:
* only allow connections from reserved ports
* implement -insecure, which turns off the above restriction (required
for sunos 3.x and ultrix)
* prevent more than 100 domains from being bound at once, preventing
a denial of service attacks
Diffstat (limited to 'usr.sbin/ypbind')
| -rw-r--r-- | usr.sbin/ypbind/Makefile | 4 | ||||
| -rw-r--r-- | usr.sbin/ypbind/ypbind.8 | 28 | ||||
| -rw-r--r-- | usr.sbin/ypbind/ypbind.c | 55 |
3 files changed, 58 insertions, 29 deletions
diff --git a/usr.sbin/ypbind/Makefile b/usr.sbin/ypbind/Makefile index 9cf10198c11..a39f78172a4 100644 --- a/usr.sbin/ypbind/Makefile +++ b/usr.sbin/ypbind/Makefile @@ -1,8 +1,8 @@ -# $NetBSD: Makefile,v 1.9 1996/07/09 06:36:31 thorpej Exp $ +# $NetBSD: Makefile,v 1.10 1997/07/07 02:27:05 lukem Exp $ # from: @(#)Makefile 5.8 (Berkeley) 7/28/90 PROG= ypbind MAN= ypbind.8 -CFLAGS+=-DHEURISTIC +CFLAGS+=-DHEURISTIC -Wall .include <bsd.prog.mk> diff --git a/usr.sbin/ypbind/ypbind.8 b/usr.sbin/ypbind/ypbind.8 index f2a65ec418d..367d8401f97 100644 --- a/usr.sbin/ypbind/ypbind.8 +++ b/usr.sbin/ypbind/ypbind.8 @@ -1,4 +1,4 @@ -.\" $NetBSD: ypbind.8,v 1.5 1996/10/02 05:55:05 thorpej Exp $ +.\" $NetBSD: ypbind.8,v 1.6 1997/07/07 02:27:06 lukem Exp $ .\" .\" Copyright (c) 1996 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -34,19 +34,18 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd October 25, 1994 +.Dd July 7, 1997 .Dt YPBIND 8 .Os .Sh NAME .Nm ypbind .Nd create and maintain a binding to a YP server .Sh SYNOPSIS -.Nm ypbind +.Nm +.Op Fl broadcast +.Op Fl insecure .Op Fl ypset -.Nm ypbind .Op Fl ypsetme -.Nm ypbind -.Op Fl broadcast .Sh DESCRIPTION .Nm finds the server for a particular YP domain and stores information about it @@ -97,6 +96,15 @@ marks the domain as bound and resumes its periodic check. .Pp The options are as follows: .Bl -tag -width "-broadcast" +.It Fl broadcast +sends a broadcast requesting a YP server to which to bind. +.It Fl insecure +do not require that clients make requests from reserved ports. +This may be necessary for +.Tn SunOS 3.x +or +.Tn ULTRIX +clients. .It Fl ypset .Xr ypset 8 may be used to change the server to which a domain is bound. @@ -104,15 +112,13 @@ may be used to change the server to which a domain is bound. .Xr ypset 8 may be used only from this machine to change the server to which a domain is bound. -.It Fl broadcast -sends a broadcast requesting a YP server to which to bind. .El .Pp The +.Fl broadcast .Fl ypset , -.Fl ypsetme , and -.Fl broadcast +.Fl ypsetme , options are inherently insecure and should be avoided. .Sh FILES .Pa /var/yp/binding/domainname.version @@ -129,6 +135,6 @@ options are inherently insecure and should be avoided. .Xr yp 8 .Sh AUTHOR This version of -.Nm ypbind +.Nm was originally implemented by Theo de Raadt. The ypservers support was implemented by Luke Mewburn. diff --git a/usr.sbin/ypbind/ypbind.c b/usr.sbin/ypbind/ypbind.c index cd9c014d5d1..ac1d85f9c8b 100644 --- a/usr.sbin/ypbind/ypbind.c +++ b/usr.sbin/ypbind/ypbind.c @@ -1,4 +1,4 @@ -/* $NetBSD: ypbind.c,v 1.29 1996/10/02 05:55:06 thorpej Exp $ */ +/* $NetBSD: ypbind.c,v 1.30 1997/07/07 02:27:08 lukem Exp $ */ /* * Copyright (c) 1992, 1993 Theo de Raadt <deraadt@fsa.ca> @@ -32,8 +32,9 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> #ifndef LINT -static char rcsid[] = "$NetBSD: ypbind.c,v 1.29 1996/10/02 05:55:06 thorpej Exp $"; +__RCSID("$NetBSD: ypbind.c,v 1.30 1997/07/07 02:27:08 lukem Exp $"); #endif #include <sys/param.h> @@ -84,12 +85,12 @@ struct _dom_binding { unsigned short int dom_server_port; int dom_socket; CLIENT *dom_client; - long int dom_vers; + long dom_vers; time_t dom_check_t; time_t dom_ask_t; int dom_lockfd; int dom_alive; - int dom_xid; + u_int32_t dom_xid; }; static char *domainname; @@ -114,6 +115,7 @@ int been_ypset; static int debug; #endif +static int insecure; static int rpcsock, pingsock; static struct rmtcallargs rmtca; static struct rmtcallres rmtcr; @@ -121,6 +123,7 @@ static bool_t rmtcr_outval; static u_long rmtcr_port; static SVCXPRT *udptransp, *tcptransp; +int _yp_invalid_domain __P((const char *)); /* from libc */ static void usage __P((void)); static struct _dom_binding *makebinding __P((const char *)); @@ -136,10 +139,8 @@ static int nag_servers __P((struct _dom_binding *)); static enum clnt_stat handle_replies __P((void)); static enum clnt_stat handle_ping __P((void)); static void rpc_received __P((char *, struct sockaddr_in *, int)); -static struct _dom_binding *xid2ypdb __P((int)); -static int unique_xid __P((struct _dom_binding *)); -static struct _dom_binding *xid2ypdb __P((int xid)); -static int unique_xid __P((struct _dom_binding *ypdb)); +static struct _dom_binding *xid2ypdb __P((u_int32_t)); +static u_int32_t unique_xid __P((struct _dom_binding *)); static int broadcast __P((char *, int)); static int direct __P((char *, int)); static int direct_set __P((char *, int, struct _dom_binding *)); @@ -152,7 +153,8 @@ usage() #ifdef DEBUG opt = " [-d]"; #endif - (void) fprintf(stderr, "Usage: %s [-ypset|-ypsetme]%s\n", + (void) fprintf(stderr, + "Usage: %s [-broadcast] [-insecure] [-ypset] [-ypsetme] %s\n", __progname, opt); exit(1); } @@ -229,17 +231,26 @@ ypbindproc_domain_2(transp, argp) struct _dom_binding *ypdb; char *arg = *(char **) argp; time_t now; + int count; #ifdef DEBUG if (debug) printf("ypbindproc_domain_2 %s\n", arg); #endif + if (_yp_invalid_domain(arg)) + return NULL; + (void) memset(&res, 0, sizeof res); res.ypbind_status = YPBIND_FAIL_VAL; - for (ypdb = ypbindlist; ypdb; ypdb = ypdb->dom_pnext) + for (count = 0, ypdb = ypbindlist; + ypdb != NULL; + ypdb = ypdb->dom_pnext, count++) { + if (count > 100) + return NULL; /* prevent denial of service */ if (!strcmp(ypdb->dom_domain, arg)) break; + } if (ypdb == NULL) { ypdb = makebinding(arg); @@ -470,7 +481,9 @@ main(argc, argv) while (--argc) { ++argv; - if (!strcmp("-ypset", *argv)) + if (!strcmp("-insecure", *argv)) + insecure = 1; + else if (!strcmp("-ypset", *argv)) ypbindmode = YPBIND_SETALL; else if (!strcmp("-ypsetme", *argv)) ypbindmode = YPBIND_SETLOCAL; @@ -532,6 +545,9 @@ main(argc, argv) rmtcr.xdr_results = xdr_bool; rmtcr.results_ptr = (caddr_t)&rmtcr_outval; + if (_yp_invalid_domain(domainname)) + errx(1, "bad domainname: %s", domainname); + /* build initial domain binding, make it "unsuccessful" */ ypbindlist = makebinding(domainname); ypbindlist->dom_vers = YPVERS; @@ -931,7 +947,7 @@ direct_set(buf, outlen, ypdb) * "been_set" if this happens, otherwise we'll never * bind again. */ - snprintf(path, sizeof(path), "%s/%s.%d", BINDINGDIR, + snprintf(path, sizeof(path), "%s/%s.%ld", BINDINGDIR, ypdb->dom_domain, ypdb->dom_vers); if ((fd = open(path, O_SHLOCK|O_RDONLY, 0644)) == -1) { @@ -1093,6 +1109,13 @@ rpc_received(dom, raddrp, force) if (dom == NULL) return; + if (_yp_invalid_domain(dom)) + return; + + /* don't support insecure servers by default */ + if (!insecure && ntohs(raddrp->sin_port) >= IPPORT_RESERVED) + return; + for (ypdb = ypbindlist; ypdb; ypdb = ypdb->dom_pnext) if (!strcmp(ypdb->dom_domain, dom)) break; @@ -1159,7 +1182,7 @@ rpc_received(dom, raddrp, force) static struct _dom_binding * xid2ypdb(xid) - int xid; + u_int32_t xid; { struct _dom_binding *ypdb; @@ -1169,13 +1192,13 @@ xid2ypdb(xid) return (ypdb); } -static int +static u_int32_t unique_xid(ypdb) struct _dom_binding *ypdb; { - int tmp_xid; + u_int32_t tmp_xid; - tmp_xid = (long)ypdb & 0xffffffff; + tmp_xid = (u_int32_t)ypdb & 0xffffffff; while (xid2ypdb(tmp_xid) != NULL) tmp_xid++; |
