- Fix bug in port parsing code; s_port must be in network byte order.
- Factor out port parsing code and add error checking to it. - WARNS=3
This commit is contained in:
parent
226c6eda62
commit
d9d5b79249
@ -1,9 +1,12 @@
|
||||
# $NetBSD: Makefile,v 1.18 2004/09/05 08:38:23 manu Exp $
|
||||
# $NetBSD: Makefile,v 1.19 2004/10/16 02:03:54 christos Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 7/19/93
|
||||
|
||||
PROG= rlogin
|
||||
SRCS= rlogin.c
|
||||
WARNS= 2
|
||||
SRCS= rlogin.c getport.c
|
||||
WARNS= 3
|
||||
|
||||
.PATH.c: ${.CURDIR}/../rsh
|
||||
CPPFLAGS+=-I${.CURDIR}/../rsh
|
||||
|
||||
BINOWN= root
|
||||
BINMODE=4555
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: rlogin.c,v 1.30 2004/03/31 13:01:00 jmmv Exp $ */
|
||||
/* $NetBSD: rlogin.c,v 1.31 2004/10/16 02:03:54 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1990, 1993
|
||||
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1990, 1993\n\
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)rlogin.c 8.4 (Berkeley) 4/29/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: rlogin.c,v 1.30 2004/03/31 13:01:00 jmmv Exp $");
|
||||
__RCSID("$NetBSD: rlogin.c,v 1.31 2004/10/16 02:03:54 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -72,6 +72,8 @@ __RCSID("$NetBSD: rlogin.c,v 1.30 2004/03/31 13:01:00 jmmv Exp $");
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "getport.h"
|
||||
|
||||
#ifdef KERBEROS
|
||||
#include <kerberosIV/des.h>
|
||||
#include <kerberosIV/krb.h>
|
||||
@ -125,7 +127,7 @@ u_int getescape(char *);
|
||||
void lostpeer(int);
|
||||
int main(int, char **);
|
||||
void mode(int);
|
||||
void msg(char *);
|
||||
void msg(const char *);
|
||||
void oob(int);
|
||||
int reader(sigset_t *);
|
||||
void sendwindow(void);
|
||||
@ -156,7 +158,7 @@ main(int argc, char *argv[])
|
||||
char *host, *p, *user, *name, term[1024] = "network";
|
||||
speed_t ospeed;
|
||||
struct sigaction sa;
|
||||
char *service=NULL;
|
||||
char *service = NULL;
|
||||
struct rlimit rlim;
|
||||
#ifdef KERBEROS
|
||||
KTEXT_ST ticket;
|
||||
@ -221,17 +223,7 @@ main(int argc, char *argv[])
|
||||
user = optarg;
|
||||
break;
|
||||
case 'p':
|
||||
/*HF*/
|
||||
service = optarg;
|
||||
sp = getservbyname(service, "tcp");
|
||||
if (sp == NULL) { /* number given, no name */
|
||||
sp = malloc(sizeof(*sp));
|
||||
memset(sp, 0, sizeof(*sp));
|
||||
sp->s_name = service;
|
||||
sp->s_port = atoi(service);
|
||||
if (sp->s_port <= 0 || sp->s_port > IPPORT_ANONMAX)
|
||||
errx(1,"port must be between 1 and %d", IPPORT_ANONMAX);
|
||||
}
|
||||
sp = getport(service = optarg, "tcp");
|
||||
break;
|
||||
#ifdef CRYPT
|
||||
#ifdef KERBEROS
|
||||
@ -947,7 +939,7 @@ copytochild(int signo)
|
||||
}
|
||||
|
||||
void
|
||||
msg(char *str)
|
||||
msg(const char *str)
|
||||
{
|
||||
|
||||
(void)fprintf(stderr, "rlogin: %s\r\n", str);
|
||||
|
@ -1,10 +1,12 @@
|
||||
# $NetBSD: Makefile,v 1.16 2004/09/05 08:38:23 manu Exp $
|
||||
# $NetBSD: Makefile,v 1.17 2004/10/16 02:03:54 christos Exp $
|
||||
# from: @(#)Makefile 8.1 (Berkeley) 7/19/93
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
WARNS= 3
|
||||
PROG= rsh
|
||||
WARNS= 2
|
||||
SRCS= rsh.c getport.c
|
||||
|
||||
# XXX Kerberos support broken right now.
|
||||
# XXX Unsupported Kerberos options were removed from man page
|
||||
# XXX Don't forget to update the man page if you fix Kerberos
|
||||
|
73
usr.bin/rsh/getport.c
Normal file
73
usr.bin/rsh/getport.c
Normal file
@ -0,0 +1,73 @@
|
||||
/* $NetBSD: getport.c,v 1.1 2004/10/16 02:03:54 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2004 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Christos Zoulas.
|
||||
*
|
||||
* 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``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 FOUNDATION OR CONTRIBUTORS
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: getport.c,v 1.1 2004/10/16 02:03:54 christos Exp $");
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <err.h>
|
||||
#include <netdb.h>
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include "getport.h"
|
||||
|
||||
struct servent *
|
||||
getport(const char *service, const char *protocol)
|
||||
{
|
||||
long port;
|
||||
char *ep;
|
||||
struct servent *sp = getservbyname(service, protocol);
|
||||
if (sp != NULL)
|
||||
return sp;
|
||||
|
||||
if ((sp = calloc(1, sizeof(*sp))) == NULL)
|
||||
err(1, "malloc");
|
||||
sp->s_name = __UNCONST(service);
|
||||
sp->s_proto = __UNCONST(protocol);
|
||||
port = strtol(service, &ep, 0);
|
||||
if ((service[0] != '\0' && *ep != '\0') ||
|
||||
(errno == ERANGE &&
|
||||
(port == LONG_MAX || port == LONG_MIN)) ||
|
||||
(port <= 0 || port >= IPPORT_ANONMAX))
|
||||
errx(1,"port must be between 1 and %d",
|
||||
IPPORT_ANONMAX);
|
||||
sp->s_port = htons((uint16_t)port);
|
||||
return sp;
|
||||
}
|
36
usr.bin/rsh/getport.h
Normal file
36
usr.bin/rsh/getport.h
Normal file
@ -0,0 +1,36 @@
|
||||
/*-
|
||||
* Copyright (c) 2004 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Christos Zoulas.
|
||||
*
|
||||
* 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``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 FOUNDATION OR CONTRIBUTORS
|
||||
* 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.
|
||||
*/
|
||||
extern struct servent *getport(const char *, const char *);
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: rsh.c,v 1.22 2003/08/07 11:15:43 agc Exp $ */
|
||||
/* $NetBSD: rsh.c,v 1.23 2004/10/16 02:03:54 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1983, 1990, 1993, 1994
|
||||
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1990, 1993, 1994\n\
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)rsh.c 8.4 (Berkeley) 4/29/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: rsh.c,v 1.22 2003/08/07 11:15:43 agc Exp $");
|
||||
__RCSID("$NetBSD: rsh.c,v 1.23 2004/10/16 02:03:54 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -55,6 +55,7 @@ __RCSID("$NetBSD: rsh.c,v 1.22 2003/08/07 11:15:43 agc Exp $");
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <pwd.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
@ -64,6 +65,7 @@ __RCSID("$NetBSD: rsh.c,v 1.22 2003/08/07 11:15:43 agc Exp $");
|
||||
#include <unistd.h>
|
||||
|
||||
#include "pathnames.h"
|
||||
#include "getport.h"
|
||||
|
||||
#ifdef KERBEROS
|
||||
#include <des.h>
|
||||
@ -112,7 +114,7 @@ main(int argc, char **argv)
|
||||
pid_t pid;
|
||||
uid_t uid;
|
||||
char *args, *host, *p, *user, *name;
|
||||
char *service=NULL;
|
||||
char *service = NULL;
|
||||
|
||||
argoff = asrsh = dflag = nflag = 0;
|
||||
one = 1;
|
||||
@ -202,17 +204,7 @@ main(int argc, char **argv)
|
||||
nflag = 1;
|
||||
break;
|
||||
case 'p':
|
||||
service = optarg;
|
||||
sp = getservbyname(service, "tcp");
|
||||
if (sp == NULL) { /* number given, no name */
|
||||
sp = malloc(sizeof(*sp));
|
||||
memset(sp, 0, sizeof(*sp));
|
||||
sp->s_name = service;
|
||||
sp->s_proto = "tcp";
|
||||
sp->s_port = atoi(service);
|
||||
if (sp->s_port <= 0 || sp->s_port > IPPORT_ANONMAX)
|
||||
errx(1,"port must be between 1 and %d", IPPORT_ANONMAX);
|
||||
}
|
||||
sp = getport(optarg, "tcp");
|
||||
break;
|
||||
#ifdef IN_RCMD
|
||||
case 'u':
|
||||
@ -246,7 +238,7 @@ main(int argc, char **argv)
|
||||
usage();
|
||||
#else
|
||||
if (asrsh)
|
||||
*argv = "rlogin";
|
||||
*argv = __UNCONST("rlogin");
|
||||
execv(_PATH_RLOGIN, argv);
|
||||
err(1, "can't exec %s", _PATH_RLOGIN);
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user