KNF, WARNS == 3. Reported by John Nemeth
This commit is contained in:
parent
bc0c808b3b
commit
6e498d006d
@ -1,8 +1,9 @@
|
|||||||
# $NetBSD: Makefile,v 1.16 2005/03/04 20:41:09 he Exp $
|
# $NetBSD: Makefile,v 1.17 2005/03/27 21:00:58 christos Exp $
|
||||||
# from: @(#)Makefile 8.1 (Berkeley) 6/4/93
|
# from: @(#)Makefile 8.1 (Berkeley) 6/4/93
|
||||||
|
|
||||||
.include <bsd.own.mk>
|
.include <bsd.own.mk>
|
||||||
|
|
||||||
|
WARNS= 3
|
||||||
PROG= rshd
|
PROG= rshd
|
||||||
MAN= rshd.8
|
MAN= rshd.8
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: rshd.c,v 1.40 2005/03/13 01:48:54 christos Exp $ */
|
/* $NetBSD: rshd.c,v 1.41 2005/03/27 21:00:58 christos Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 1998 WIDE Project.
|
* Copyright (C) 1998 WIDE Project.
|
||||||
@ -69,7 +69,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1992, 1993, 1994\n\
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)rshd.c 8.2 (Berkeley) 4/6/94";
|
static char sccsid[] = "@(#)rshd.c 8.2 (Berkeley) 4/6/94";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: rshd.c,v 1.40 2005/03/13 01:48:54 christos Exp $");
|
__RCSID("$NetBSD: rshd.c,v 1.41 2005/03/27 21:00:58 christos Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
@ -137,10 +137,10 @@ int check_all;
|
|||||||
int log_success; /* If TRUE, log all successful accesses */
|
int log_success; /* If TRUE, log all successful accesses */
|
||||||
int sent_null;
|
int sent_null;
|
||||||
|
|
||||||
void doit(struct sockaddr *);
|
void doit(struct sockaddr *) __attribute__((__noreturn__));
|
||||||
void rshd_errx(int, const char *, ...)
|
void rshd_errx(int, const char *, ...)
|
||||||
__attribute__((__noreturn__, __format__(__printf__, 2, 3)));
|
__attribute__((__noreturn__, __format__(__printf__, 2, 3)));
|
||||||
void getstr(char *, int, char *);
|
void getstr(char *, int, const char *);
|
||||||
int local_domain(char *);
|
int local_domain(char *);
|
||||||
char *topdomain(char *);
|
char *topdomain(char *);
|
||||||
void usage(void);
|
void usage(void);
|
||||||
@ -186,9 +186,9 @@ main(int argc, char *argv[])
|
|||||||
argv += optind;
|
argv += optind;
|
||||||
|
|
||||||
fromlen = sizeof(from); /* xxx */
|
fromlen = sizeof(from); /* xxx */
|
||||||
if (getpeername(0, (struct sockaddr *)&from, &fromlen) < 0) {
|
if (getpeername(STDIN_FILENO, (struct sockaddr *)&from, &fromlen) < 0) {
|
||||||
syslog(LOG_ERR, "getpeername: %m");
|
syslog(LOG_ERR, "getpeername: %m");
|
||||||
exit(1);
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
if (((struct sockaddr *)&from)->sa_family == AF_INET6 &&
|
if (((struct sockaddr *)&from)->sa_family == AF_INET6 &&
|
||||||
@ -200,12 +200,12 @@ main(int argc, char *argv[])
|
|||||||
sizeof(struct sockaddr_in);
|
sizeof(struct sockaddr_in);
|
||||||
|
|
||||||
sin6 = (struct sockaddr_in6 *)&from;
|
sin6 = (struct sockaddr_in6 *)&from;
|
||||||
memset(&sin, 0, sizeof(sin));
|
(void)memset(&sin, 0, sizeof(sin));
|
||||||
sin.sin_family = AF_INET;
|
sin.sin_family = AF_INET;
|
||||||
sin.sin_len = sizeof(struct sockaddr_in);
|
sin.sin_len = sizeof(struct sockaddr_in);
|
||||||
memcpy(&sin.sin_addr, &sin6->sin6_addr.s6_addr[off],
|
(void)memcpy(&sin.sin_addr, &sin6->sin6_addr.s6_addr[off],
|
||||||
sizeof(sin.sin_addr));
|
sizeof(sin.sin_addr));
|
||||||
memcpy(&from, &sin, sizeof(sin));
|
(void)memcpy(&from, &sin, sizeof(sin));
|
||||||
fromlen = sin.sin_len;
|
fromlen = sin.sin_len;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -218,25 +218,22 @@ main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
syslog(LOG_ERR, "malformed \"from\" address (v4 mapped, %s)",
|
syslog(LOG_ERR, "malformed \"from\" address (v4 mapped, %s)",
|
||||||
hbuf);
|
hbuf);
|
||||||
exit(1);
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (keepalive &&
|
if (keepalive &&
|
||||||
setsockopt(0, SOL_SOCKET, SO_KEEPALIVE, (char *)&on,
|
setsockopt(STDIN_FILENO, SOL_SOCKET, SO_KEEPALIVE, (char *)&on,
|
||||||
sizeof(on)) < 0)
|
sizeof(on)) < 0)
|
||||||
syslog(LOG_WARNING, "setsockopt (SO_KEEPALIVE): %m");
|
syslog(LOG_WARNING, "setsockopt (SO_KEEPALIVE): %m");
|
||||||
linger.l_onoff = 1;
|
linger.l_onoff = 1;
|
||||||
linger.l_linger = 60; /* XXX */
|
linger.l_linger = 60; /* XXX */
|
||||||
if (setsockopt(0, SOL_SOCKET, SO_LINGER, (char *)&linger,
|
if (setsockopt(STDIN_FILENO, SOL_SOCKET, SO_LINGER, (char *)&linger,
|
||||||
sizeof (linger)) < 0)
|
sizeof (linger)) < 0)
|
||||||
syslog(LOG_WARNING, "setsockopt (SO_LINGER): %m");
|
syslog(LOG_WARNING, "setsockopt (SO_LINGER): %m");
|
||||||
proto = getprotobyname("tcp");
|
proto = getprotobyname("tcp");
|
||||||
setsockopt(0, proto->p_proto, TCP_NODELAY, &on, sizeof(on));
|
(void)setsockopt(STDIN_FILENO, proto->p_proto, TCP_NODELAY, &on,
|
||||||
|
sizeof(on));
|
||||||
doit((struct sockaddr *)&from);
|
doit((struct sockaddr *)&from);
|
||||||
/* NOTREACHED */
|
|
||||||
#ifdef __GNUC__
|
|
||||||
exit(0);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char username[20] = "USER=";
|
char username[20] = "USER=";
|
||||||
@ -280,9 +277,9 @@ doit(struct sockaddr *fromp)
|
|||||||
(void)signal(SIGTERM, SIG_DFL);
|
(void)signal(SIGTERM, SIG_DFL);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
{
|
{
|
||||||
int t = open(_PATH_TTY, 2);
|
int t = open(_PATH_TTY, O_RDWR);
|
||||||
if (t >= 0) {
|
if (t >= 0) {
|
||||||
ioctl(t, TIOCNOTTY, (char *)0);
|
ioctl(t, TIOCNOTTY, NULL);
|
||||||
(void)close(t);
|
(void)close(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -298,12 +295,12 @@ doit(struct sockaddr *fromp)
|
|||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
syslog(LOG_ERR, "malformed \"from\" address (af %d)", af);
|
syslog(LOG_ERR, "malformed \"from\" address (af %d)", af);
|
||||||
exit(1);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
if (getnameinfo(fromp, fromp->sa_len, naddr, sizeof(naddr),
|
if (getnameinfo(fromp, fromp->sa_len, naddr, sizeof(naddr),
|
||||||
pbuf, sizeof(pbuf), niflags) != 0) {
|
pbuf, sizeof(pbuf), niflags) != 0) {
|
||||||
syslog(LOG_ERR, "malformed \"from\" address (af %d)", af);
|
syslog(LOG_ERR, "malformed \"from\" address (af %d)", af);
|
||||||
exit(1);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
#ifdef IP_OPTIONS
|
#ifdef IP_OPTIONS
|
||||||
if (af == AF_INET) {
|
if (af == AF_INET) {
|
||||||
@ -327,7 +324,7 @@ doit(struct sockaddr *fromp)
|
|||||||
inet_ntoa((
|
inet_ntoa((
|
||||||
(struct sockaddr_in *)fromp)->sin_addr),
|
(struct sockaddr_in *)fromp)->sin_addr),
|
||||||
c == IPOPT_LSRR ? "LSRR" : "SSRR");
|
c == IPOPT_LSRR ? "LSRR" : "SSRR");
|
||||||
exit(1);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
if (c == IPOPT_EOL)
|
if (c == IPOPT_EOL)
|
||||||
break;
|
break;
|
||||||
@ -341,7 +338,7 @@ doit(struct sockaddr *fromp)
|
|||||||
syslog(LOG_NOTICE|LOG_AUTH,
|
syslog(LOG_NOTICE|LOG_AUTH,
|
||||||
"Connection from %s on illegal port %u",
|
"Connection from %s on illegal port %u",
|
||||||
naddr, ntohs(*portp));
|
naddr, ntohs(*portp));
|
||||||
exit(1);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
(void) alarm(60);
|
(void) alarm(60);
|
||||||
@ -352,8 +349,8 @@ doit(struct sockaddr *fromp)
|
|||||||
if ((cc = read(STDIN_FILENO, &c, 1)) != 1) {
|
if ((cc = read(STDIN_FILENO, &c, 1)) != 1) {
|
||||||
if (cc < 0)
|
if (cc < 0)
|
||||||
syslog(LOG_ERR, "read: %m");
|
syslog(LOG_ERR, "read: %m");
|
||||||
shutdown(0, SHUT_RDWR);
|
(void)shutdown(0, SHUT_RDWR);
|
||||||
exit(1);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
if (c == 0)
|
if (c == 0)
|
||||||
break;
|
break;
|
||||||
@ -366,25 +363,25 @@ doit(struct sockaddr *fromp)
|
|||||||
s = rresvport_af(&lport, af);
|
s = rresvport_af(&lport, af);
|
||||||
if (s < 0) {
|
if (s < 0) {
|
||||||
syslog(LOG_ERR, "can't get stderr port: %m");
|
syslog(LOG_ERR, "can't get stderr port: %m");
|
||||||
exit(1);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
if (port >= IPPORT_RESERVED) {
|
if (port >= IPPORT_RESERVED) {
|
||||||
syslog(LOG_ERR, "2nd port not reserved");
|
syslog(LOG_ERR, "2nd port not reserved");
|
||||||
exit(1);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
*portp = htons(port);
|
*portp = htons(port);
|
||||||
if (connect(s, fromp, fromp->sa_len) < 0) {
|
if (connect(s, fromp, fromp->sa_len) < 0) {
|
||||||
syslog(LOG_ERR, "connect second port %d: %m", port);
|
syslog(LOG_ERR, "connect second port %d: %m", port);
|
||||||
exit(1);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef notdef
|
#ifdef notdef
|
||||||
/* from inetd, socket is already on 0, 1, 2 */
|
/* from inetd, socket is already on 0, 1, 2 */
|
||||||
dup2(f, 0);
|
(void)dup2(f, STDIN_FILENO);
|
||||||
dup2(f, 1);
|
(void)dup2(f, STDOUT_FILENO);
|
||||||
dup2(f, 2);
|
(void)dup2(f, STDERR_FILENO);
|
||||||
#endif
|
#endif
|
||||||
if (getnameinfo(fromp, fromp->sa_len, saddr, sizeof(saddr),
|
if (getnameinfo(fromp, fromp->sa_len, saddr, sizeof(saddr),
|
||||||
NULL, 0, NI_NAMEREQD) == 0) {
|
NULL, 0, NI_NAMEREQD) == 0) {
|
||||||
@ -397,9 +394,9 @@ doit(struct sockaddr *fromp)
|
|||||||
hostname = saddr;
|
hostname = saddr;
|
||||||
res0 = NULL;
|
res0 = NULL;
|
||||||
if (check_all || local_domain(saddr)) {
|
if (check_all || local_domain(saddr)) {
|
||||||
strlcpy(remotehost, saddr, sizeof(remotehost));
|
(void)strlcpy(remotehost, saddr, sizeof(remotehost));
|
||||||
errorhost = remotehost;
|
errorhost = remotehost;
|
||||||
memset(&hints, 0, sizeof(hints));
|
(void)memset(&hints, 0, sizeof(hints));
|
||||||
hints.ai_family = fromp->sa_family;
|
hints.ai_family = fromp->sa_family;
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
hints.ai_flags = AI_CANONNAME;
|
hints.ai_flags = AI_CANONNAME;
|
||||||
@ -440,12 +437,12 @@ doit(struct sockaddr *fromp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
strlcpy(hostnamebuf, hostname, sizeof(hostnamebuf));
|
(void)strlcpy(hostnamebuf, hostname, sizeof(hostnamebuf));
|
||||||
hostname = hostnamebuf;
|
hostname = hostnamebuf;
|
||||||
if (res0)
|
if (res0)
|
||||||
freeaddrinfo(res0);
|
freeaddrinfo(res0);
|
||||||
} else {
|
} else {
|
||||||
strlcpy(hostnamebuf, naddr, sizeof(hostnamebuf));
|
(void)strlcpy(hostnamebuf, naddr, sizeof(hostnamebuf));
|
||||||
errorhost = hostname = hostnamebuf;
|
errorhost = hostname = hostnamebuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -460,20 +457,20 @@ doit(struct sockaddr *fromp)
|
|||||||
if (pam_err != PAM_SUCCESS) {
|
if (pam_err != PAM_SUCCESS) {
|
||||||
syslog(LOG_ERR|LOG_AUTH, "pam_start(): %s",
|
syslog(LOG_ERR|LOG_AUTH, "pam_start(): %s",
|
||||||
pam_strerror(pamh, pam_err));
|
pam_strerror(pamh, pam_err));
|
||||||
rshd_errx(1, incorrect);
|
rshd_errx(EXIT_FAILURE, incorrect);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pam_err = pam_set_item(pamh, PAM_RUSER, remuser)) != PAM_SUCCESS ||
|
if ((pam_err = pam_set_item(pamh, PAM_RUSER, remuser)) != PAM_SUCCESS ||
|
||||||
(pam_err = pam_set_item(pamh, PAM_RHOST, hostname) != PAM_SUCCESS)){
|
(pam_err = pam_set_item(pamh, PAM_RHOST, hostname) != PAM_SUCCESS)){
|
||||||
syslog(LOG_ERR|LOG_AUTH, "pam_set_item(): %s",
|
syslog(LOG_ERR|LOG_AUTH, "pam_set_item(): %s",
|
||||||
pam_strerror(pamh, pam_err));
|
pam_strerror(pamh, pam_err));
|
||||||
rshd_errx(1, incorrect);
|
rshd_errx(EXIT_FAILURE, incorrect);
|
||||||
}
|
}
|
||||||
|
|
||||||
pam_err = pam_authenticate(pamh, 0);
|
pam_err = pam_authenticate(pamh, 0);
|
||||||
if (pam_err == PAM_SUCCESS) {
|
if (pam_err == PAM_SUCCESS) {
|
||||||
if ((pam_err = pam_get_user(pamh, &cp, NULL)) == PAM_SUCCESS) {
|
if ((pam_err = pam_get_user(pamh, &cp, NULL)) == PAM_SUCCESS) {
|
||||||
strlcpy(locuser, cp, sizeof(locuser));
|
(void)strlcpy(locuser, cp, sizeof(locuser));
|
||||||
/* XXX truncation! */
|
/* XXX truncation! */
|
||||||
}
|
}
|
||||||
pam_err = pam_acct_mgmt(pamh, 0);
|
pam_err = pam_acct_mgmt(pamh, 0);
|
||||||
@ -492,7 +489,7 @@ doit(struct sockaddr *fromp)
|
|||||||
remuser, hostname, locuser, cmdbuf);
|
remuser, hostname, locuser, cmdbuf);
|
||||||
if (errorstr == NULL)
|
if (errorstr == NULL)
|
||||||
errorstr = "Permission denied.";
|
errorstr = "Permission denied.";
|
||||||
rshd_errx(1, errorstr, errorhost);
|
rshd_errx(EXIT_FAILURE, errorstr, errorhost);
|
||||||
}
|
}
|
||||||
#ifdef LOGIN_CAP
|
#ifdef LOGIN_CAP
|
||||||
lc = login_getclass(pwd ? pwd->pw_class : NULL);
|
lc = login_getclass(pwd ? pwd->pw_class : NULL);
|
||||||
@ -507,7 +504,7 @@ doit(struct sockaddr *fromp)
|
|||||||
syslog(LOG_INFO|LOG_AUTH,
|
syslog(LOG_INFO|LOG_AUTH,
|
||||||
"%s@%s as %s: no home directory. cmd='%.80s'",
|
"%s@%s as %s: no home directory. cmd='%.80s'",
|
||||||
remuser, hostname, locuser, cmdbuf);
|
remuser, hostname, locuser, cmdbuf);
|
||||||
rshd_errx(0, "No remote home directory.");
|
rshd_errx(EXIT_SUCCESS, "No remote home directory.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -523,7 +520,7 @@ doit(struct sockaddr *fromp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pwd->pw_uid && !access(_PATH_NOLOGIN, F_OK))
|
if (pwd->pw_uid && !access(_PATH_NOLOGIN, F_OK))
|
||||||
rshd_errx(1, "Logins currently disabled.");
|
rshd_errx(EXIT_FAILURE, "Logins currently disabled.");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LOGIN_CAP
|
#ifdef LOGIN_CAP
|
||||||
@ -534,7 +531,7 @@ doit(struct sockaddr *fromp)
|
|||||||
*/
|
*/
|
||||||
if (setusercontext(lc, pwd, pwd->pw_uid, LOGIN_SETGROUP) != 0) {
|
if (setusercontext(lc, pwd, pwd->pw_uid, LOGIN_SETGROUP) != 0) {
|
||||||
syslog(LOG_ERR, "setusercontext: %m");
|
syslog(LOG_ERR, "setusercontext: %m");
|
||||||
exit(1);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
initgroups(pwd->pw_name, pwd->pw_gid);
|
initgroups(pwd->pw_name, pwd->pw_gid);
|
||||||
@ -555,16 +552,16 @@ doit(struct sockaddr *fromp)
|
|||||||
|
|
||||||
if (port) {
|
if (port) {
|
||||||
if (pipe(pv) < 0)
|
if (pipe(pv) < 0)
|
||||||
rshd_errx(1, "Can't make pipe. (%s)", strerror(errno));
|
rshd_errx(EXIT_FAILURE, "Can't make pipe. (%s)",
|
||||||
|
strerror(errno));
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid == -1)
|
if (pid == -1)
|
||||||
rshd_errx(1, "Can't fork. (%s)", strerror(errno));
|
rshd_errx(EXIT_FAILURE, "Can't fork. (%s)",
|
||||||
|
strerror(errno));
|
||||||
if (pid) {
|
if (pid) {
|
||||||
{
|
(void)close(STDIN_FILENO);
|
||||||
(void) close(0);
|
(void)close(STDOUT_FILENO);
|
||||||
(void) close(1);
|
(void)close(STDERR_FILENO);
|
||||||
}
|
|
||||||
(void) close(2);
|
|
||||||
(void)close(pv[1]);
|
(void)close(pv[1]);
|
||||||
|
|
||||||
set[0].fd = s;
|
set[0].fd = s;
|
||||||
@ -599,18 +596,19 @@ doit(struct sockaddr *fromp)
|
|||||||
|
|
||||||
} while ((set[0].revents | set[1].revents) & POLLIN);
|
} while ((set[0].revents | set[1].revents) & POLLIN);
|
||||||
PAM_END;
|
PAM_END;
|
||||||
exit(0);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
(void)close(s);
|
(void)close(s);
|
||||||
(void)close(pv[0]);
|
(void)close(pv[0]);
|
||||||
dup2(pv[1], 2);
|
(void)dup2(pv[1], STDERR_FILENO);
|
||||||
close(pv[1]);
|
close(pv[1]);
|
||||||
}
|
}
|
||||||
#ifdef USE_PAM
|
#ifdef USE_PAM
|
||||||
else {
|
else {
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid == -1)
|
if (pid == -1)
|
||||||
rshd_errx(1, "Can't fork. (%s)", strerror(errno));
|
rshd_errx(EXIT_FAILURE, "Can't fork. (%s)",
|
||||||
|
strerror(errno));
|
||||||
if (pid) {
|
if (pid) {
|
||||||
pid_t xpid;
|
pid_t xpid;
|
||||||
int status;
|
int status;
|
||||||
@ -628,17 +626,17 @@ doit(struct sockaddr *fromp)
|
|||||||
else
|
else
|
||||||
syslog(LOG_WARNING,
|
syslog(LOG_WARNING,
|
||||||
"wait pid=%d failed %m", pid);
|
"wait pid=%d failed %m", pid);
|
||||||
exit(1);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
exit(0);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef F_CLOSEM
|
#ifdef F_CLOSEM
|
||||||
(void)fcntl(3, F_CLOSEM, 0);
|
(void)fcntl(STDERR_FILENO + 1, F_CLOSEM, 0);
|
||||||
#else
|
#else
|
||||||
for (fd = getdtablesize(); fd > 2; fd--)
|
for (fd = getdtablesize(); fd > STDERR_FILENO; fd--)
|
||||||
(void)close(fd);
|
(void)close(fd);
|
||||||
#endif
|
#endif
|
||||||
if (setsid() == -1)
|
if (setsid() == -1)
|
||||||
@ -648,7 +646,7 @@ doit(struct sockaddr *fromp)
|
|||||||
syslog(LOG_ERR, "setlogin() failed: %m");
|
syslog(LOG_ERR, "setlogin() failed: %m");
|
||||||
|
|
||||||
if (*pwd->pw_shell == '\0')
|
if (*pwd->pw_shell == '\0')
|
||||||
pwd->pw_shell = _PATH_BSHELL;
|
pwd->pw_shell = __UNCONST(_PATH_BSHELL);
|
||||||
|
|
||||||
(void)pam_setenv(pamh, "HOME", pwd->pw_dir, 1);
|
(void)pam_setenv(pamh, "HOME", pwd->pw_dir, 1);
|
||||||
(void)pam_setenv(pamh, "SHELL", pwd->pw_shell, 1);
|
(void)pam_setenv(pamh, "SHELL", pwd->pw_shell, 1);
|
||||||
@ -663,17 +661,17 @@ doit(struct sockaddr *fromp)
|
|||||||
if ((sh = login_getcapstr(lc, "shell", NULL, NULL))) {
|
if ((sh = login_getcapstr(lc, "shell", NULL, NULL))) {
|
||||||
if(!(sh = strdup(sh))) {
|
if(!(sh = strdup(sh))) {
|
||||||
syslog(LOG_ERR, "Cannot alloc mem");
|
syslog(LOG_ERR, "Cannot alloc mem");
|
||||||
exit(1);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
pwd->pw_shell = sh;
|
pwd->pw_shell = sh;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
environ = envinit;
|
environ = envinit;
|
||||||
strlcat(homedir, pwd->pw_dir, sizeof(homedir));
|
(void)strlcat(homedir, pwd->pw_dir, sizeof(homedir));
|
||||||
strlcat(path, _PATH_DEFPATH, sizeof(path));
|
(void)strlcat(path, _PATH_DEFPATH, sizeof(path));
|
||||||
strlcat(shell, pwd->pw_shell, sizeof(shell));
|
(void)strlcat(shell, pwd->pw_shell, sizeof(shell));
|
||||||
strlcat(username, pwd->pw_name, sizeof(username));
|
(void)strlcat(username, pwd->pw_name, sizeof(username));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cp = strrchr(pwd->pw_shell, '/');
|
cp = strrchr(pwd->pw_shell, '/');
|
||||||
@ -686,7 +684,7 @@ doit(struct sockaddr *fromp)
|
|||||||
if (setusercontext(lc, pwd, pwd->pw_uid,
|
if (setusercontext(lc, pwd, pwd->pw_uid,
|
||||||
LOGIN_SETALL & ~LOGIN_SETGROUP) < 0) {
|
LOGIN_SETALL & ~LOGIN_SETGROUP) < 0) {
|
||||||
syslog(LOG_ERR, "setusercontext(): %m");
|
syslog(LOG_ERR, "setusercontext(): %m");
|
||||||
exit(1);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
login_close(lc);
|
login_close(lc);
|
||||||
#else
|
#else
|
||||||
@ -698,13 +696,13 @@ doit(struct sockaddr *fromp)
|
|||||||
syslog(LOG_INFO|LOG_AUTH, "%s@%s as %s: cmd='%.80s'",
|
syslog(LOG_INFO|LOG_AUTH, "%s@%s as %s: cmd='%.80s'",
|
||||||
remuser, hostname, locuser, cmdbuf);
|
remuser, hostname, locuser, cmdbuf);
|
||||||
}
|
}
|
||||||
execl(pwd->pw_shell, cp, "-c", cmdbuf, NULL);
|
(void)execl(pwd->pw_shell, cp, "-c", cmdbuf, NULL);
|
||||||
rshd_errx(1, "%s: %s", pwd->pw_shell, strerror(errno));
|
rshd_errx(EXIT_FAILURE, "%s: %s", pwd->pw_shell, strerror(errno));
|
||||||
badlogin:
|
badlogin:
|
||||||
syslog(LOG_INFO|LOG_AUTH,
|
syslog(LOG_INFO|LOG_AUTH,
|
||||||
"%s@%s as %s: permission denied (%s). cmd='%.80s'",
|
"%s@%s as %s: permission denied (%s). cmd='%.80s'",
|
||||||
remuser, hostname, locuser, errormsg, cmdbuf);
|
remuser, hostname, locuser, errormsg, cmdbuf);
|
||||||
rshd_errx(1, errorstr, errorhost);
|
rshd_errx(EXIT_FAILURE, errorstr, errorhost);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -736,16 +734,16 @@ rshd_errx(int error, const char *fmt, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
getstr(char *buf, int cnt, char *err)
|
getstr(char *buf, int cnt, const char *err)
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (read(STDIN_FILENO, &c, 1) != 1)
|
if (read(STDIN_FILENO, &c, 1) != 1)
|
||||||
exit(1);
|
exit(EXIT_FAILURE);
|
||||||
*buf++ = c;
|
*buf++ = c;
|
||||||
if (--cnt == 0)
|
if (--cnt == 0)
|
||||||
rshd_errx(1, "%s too long", err);
|
rshd_errx(EXIT_FAILURE, "%s too long", err);
|
||||||
} while (c != 0);
|
} while (c != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -793,6 +791,6 @@ void
|
|||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
syslog(LOG_ERR, "usage: rshd [-%s]", OPTIONS);
|
syslog(LOG_ERR, "Usage: %s [-%s]", getprogname(), OPTIONS);
|
||||||
exit(2);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user