rshd.c revision 59748
1/*-
2 * Copyright (c) 1988, 1989, 1992, 1993, 1994
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 *    must display the following acknowledgement:
15 *	This product includes software developed by the University of
16 *	California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 *    may be used to endorse or promote products derived from this software
19 *    without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35static const char copyright[] =
36"@(#) Copyright (c) 1988, 1989, 1992, 1993, 1994\n\
37	The Regents of the University of California.  All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41#if 0
42static const char sccsid[] = "@(#)rshd.c	8.2 (Berkeley) 4/6/94";
43#endif
44static const char rcsid[] =
45  "$FreeBSD: head/libexec/rshd/rshd.c 59748 2000-04-29 12:02:00Z asmodai $";
46#endif /* not lint */
47
48/*
49 * remote shell server:
50 *	[port]\0
51 *	remuser\0
52 *	locuser\0
53 *	command\0
54 *	data
55 */
56#include <sys/param.h>
57#include <sys/ioctl.h>
58#include <sys/time.h>
59#include <sys/socket.h>
60
61#include <netinet/in_systm.h>
62#include <netinet/in.h>
63#include <netinet/ip.h>
64#include <netinet/tcp.h>
65#include <arpa/inet.h>
66#include <netdb.h>
67
68#include <errno.h>
69#include <fcntl.h>
70#include <libutil.h>
71#include <paths.h>
72#include <pwd.h>
73#include <signal.h>
74#include <stdio.h>
75#include <stdlib.h>
76#include <string.h>
77#include <syslog.h>
78#include <unistd.h>
79#ifdef	LOGIN_CAP
80#include <login_cap.h>
81#endif
82
83/* wrapper for KAME-special getnameinfo() */
84#ifndef NI_WITHSCOPEID
85#define	NI_WITHSCOPEID	0
86#endif
87
88int	keepalive = 1;
89int	log_success;		/* If TRUE, log all successful accesses */
90int	sent_null;
91int	no_delay;
92#ifdef CRYPT
93int	doencrypt = 0;
94#endif
95
96union sockunion {
97	struct sockinet {
98		u_char si_len;
99		u_char si_family;
100		u_short si_port;
101	} su_si;
102	struct sockaddr_in  su_sin;
103	struct sockaddr_in6 su_sin6;
104};
105#define su_len		su_si.si_len
106#define su_family	su_si.si_family
107#define su_port		su_si.si_port
108
109void	 doit __P((union sockunion *));
110void	 error __P((const char *, ...));
111void	 getstr __P((char *, int, char *));
112int	 local_domain __P((char *));
113char	*topdomain __P((char *));
114void	 usage __P((void));
115
116#ifndef NO_PAM
117extern int auth_pam __P((char *));
118#endif
119
120#define	OPTIONS	"alnDL"
121
122int
123main(argc, argv)
124	int argc;
125	char *argv[];
126{
127	extern int __check_rhosts_file;
128	struct linger linger;
129	int ch, on = 1, fromlen;
130	struct sockaddr_storage from;
131
132	openlog("rshd", LOG_PID | LOG_ODELAY, LOG_DAEMON);
133
134	opterr = 0;
135	while ((ch = getopt(argc, argv, OPTIONS)) != -1)
136		switch (ch) {
137		case 'a':
138			/* ignored for compatability */
139			break;
140		case 'l':
141			__check_rhosts_file = 0;
142			break;
143		case 'n':
144			keepalive = 0;
145			break;
146#ifdef CRYPT
147		case 'x':
148			doencrypt = 1;
149			break;
150#endif
151		case 'D':
152			no_delay = 1;
153			break;
154		case 'L':
155			log_success = 1;
156			break;
157		case '?':
158		default:
159			usage();
160			break;
161		}
162
163	argc -= optind;
164	argv += optind;
165
166#ifdef CRYPT
167	if (doencrypt) {
168		syslog(LOG_ERR, "-k is required for -x");
169		exit(2);
170	}
171#endif
172
173	fromlen = sizeof (from);
174	if (getpeername(0, (struct sockaddr *)&from, &fromlen) < 0) {
175		syslog(LOG_ERR, "getpeername: %m");
176		exit(1);
177	}
178	if (keepalive &&
179	    setsockopt(0, SOL_SOCKET, SO_KEEPALIVE, (char *)&on,
180	    sizeof(on)) < 0)
181		syslog(LOG_WARNING, "setsockopt (SO_KEEPALIVE): %m");
182	linger.l_onoff = 1;
183	linger.l_linger = 60;			/* XXX */
184	if (setsockopt(0, SOL_SOCKET, SO_LINGER, (char *)&linger,
185	    sizeof (linger)) < 0)
186		syslog(LOG_WARNING, "setsockopt (SO_LINGER): %m");
187	if (no_delay &&
188	    setsockopt(0, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)) < 0)
189		syslog(LOG_WARNING, "setsockopt (TCP_NODELAY): %m");
190	doit((union sockunion *)&from);
191	/* NOTREACHED */
192	return(0);
193}
194
195char	username[20] = "USER=";
196char	homedir[64] = "HOME=";
197char	shell[64] = "SHELL=";
198char	path[100] = "PATH=";
199char	*envinit[] =
200	    {homedir, shell, path, username, 0};
201char	**environ;
202
203void
204doit(fromp)
205	union sockunion *fromp;
206{
207	extern char *__rcmd_errstr;	/* syslog hook from libc/net/rcmd.c. */
208	struct passwd *pwd;
209	u_short port;
210	fd_set ready, readfrom;
211	int cc, nfd, pv[2], pid, s;
212	int one = 1;
213	char *errorstr;
214	char *cp, sig, buf[BUFSIZ];
215	char cmdbuf[NCARGS+1], locuser[16], remuser[16];
216	char fromhost[2 * MAXHOSTNAMELEN + 1];
217	char numericname[INET6_ADDRSTRLEN];
218	int af = fromp->su_family, err;
219	int retval;
220#ifdef	CRYPT
221	int rc;
222	int pv1[2], pv2[2];
223#endif
224#ifdef	LOGIN_CAP
225	login_cap_t *lc;
226#endif
227
228	(void) signal(SIGINT, SIG_DFL);
229	(void) signal(SIGQUIT, SIG_DFL);
230	(void) signal(SIGTERM, SIG_DFL);
231	fromp->su_port = ntohs((u_short)fromp->su_port);
232	if (af != AF_INET
233#ifdef INET6
234	    && af != AF_INET6
235#endif
236	    ) {
237		syslog(LOG_ERR, "malformed \"from\" address (af %d)\n", af);
238		exit(1);
239	}
240	err = getnameinfo((struct sockaddr *)fromp, fromp->su_len, numericname,
241			  sizeof(numericname), NULL, 0,
242			  NI_NUMERICHOST|NI_WITHSCOPEID);
243	/* XXX: do 'err' check */
244#ifdef IP_OPTIONS
245      if (af == AF_INET) {
246	u_char optbuf[BUFSIZ/3];
247	int optsize = sizeof(optbuf), ipproto, i;
248	struct protoent *ip;
249
250	if ((ip = getprotobyname("ip")) != NULL)
251		ipproto = ip->p_proto;
252	else
253		ipproto = IPPROTO_IP;
254	if (!getsockopt(0, ipproto, IP_OPTIONS, (char *)optbuf, &optsize) &&
255	    optsize != 0) {
256		for (i = 0; i < optsize; ) {
257			u_char c = optbuf[i];
258			if (c == IPOPT_LSRR || c == IPOPT_SSRR) {
259				syslog(LOG_NOTICE,
260					"connection refused from %s with IP option %s",
261					numericname,
262					c == IPOPT_LSRR ? "LSRR" : "SSRR");
263				exit(1);
264			}
265			if (c == IPOPT_EOL)
266				break;
267			i += (c == IPOPT_NOP) ? 1 : optbuf[i+1];
268		}
269	}
270      }
271#endif
272
273	if (fromp->su_port >= IPPORT_RESERVED ||
274	    fromp->su_port < IPPORT_RESERVED/2) {
275		syslog(LOG_NOTICE|LOG_AUTH,
276		    "connection from %s on illegal port %u",
277		    numericname,
278		    fromp->su_port);
279		exit(1);
280	}
281
282	(void) alarm(60);
283	port = 0;
284	s = 0;		/* not set or used if port == 0 */
285	for (;;) {
286		char c;
287		if ((cc = read(STDIN_FILENO, &c, 1)) != 1) {
288			if (cc < 0)
289				syslog(LOG_NOTICE, "read: %m");
290			shutdown(0, 1+1);
291			exit(1);
292		}
293		if (c == 0)
294			break;
295		port = port * 10 + c - '0';
296	}
297
298	(void) alarm(0);
299	if (port != 0) {
300		int lport = IPPORT_RESERVED - 1;
301		s = rresvport_af(&lport, af);
302		if (s < 0) {
303			syslog(LOG_ERR, "can't get stderr port: %m");
304			exit(1);
305		}
306		if (port >= IPPORT_RESERVED ||
307		    port < IPPORT_RESERVED/2) {
308			syslog(LOG_NOTICE|LOG_AUTH,
309			    "2nd socket from %s on unreserved port %u",
310			    numericname,
311			    port);
312			exit(1);
313		}
314		fromp->su_port = htons(port);
315		if (connect(s, (struct sockaddr *)fromp, fromp->su_len) < 0) {
316			syslog(LOG_INFO, "connect second port %d: %m", port);
317			exit(1);
318		}
319	}
320
321	errorstr = NULL;
322	realhostname_sa(fromhost, sizeof(fromhost) - 1,
323			(struct sockaddr *)fromp,
324			fromp->su_len);
325	fromhost[sizeof(fromhost) - 1] = '\0';
326
327#ifdef CRYPT
328	if (doencrypt && af == AF_INET) {
329		struct sockaddr_in local_addr;
330		rc = sizeof(local_addr);
331		if (getsockname(0, (struct sockaddr *)&local_addr,
332		    &rc) < 0) {
333			syslog(LOG_ERR, "getsockname: %m");
334			error("rlogind: getsockname: %m");
335			exit(1);
336		}
337		authopts = KOPT_DO_MUTUAL;
338		rc = krb_recvauth(authopts, 0, ticket,
339			"rcmd", instance, &fromaddr,
340			&local_addr, kdata, "", schedule,
341			version);
342		des_set_key(&kdata->session, schedule);
343	}
344#endif
345	getstr(remuser, sizeof(remuser), "remuser");
346
347	getstr(locuser, sizeof(locuser), "locuser");
348	getstr(cmdbuf, sizeof(cmdbuf), "command");
349	setpwent();
350	pwd = getpwnam(locuser);
351	if (pwd == NULL) {
352		syslog(LOG_INFO|LOG_AUTH,
353		    "%s@%s as %s: unknown login. cmd='%.80s'",
354		    remuser, fromhost, locuser, cmdbuf);
355		if (errorstr == NULL)
356			errorstr = "Login incorrect.\n";
357		goto fail;
358	}
359#ifdef	LOGIN_CAP
360	lc = login_getpwclass(pwd);
361#endif
362	if (chdir(pwd->pw_dir) < 0) {
363#ifdef	LOGIN_CAP
364		if (chdir("/") < 0 ||
365		    login_getcapbool(lc, "requirehome", !!pwd->pw_uid)) {
366			syslog(LOG_INFO|LOG_AUTH,
367			"%s@%s as %s: no home directory. cmd='%.80s'",
368			remuser, fromhost, locuser, cmdbuf);
369			error("No remote home directory.\n");
370			exit(0);
371		}
372#else
373		(void) chdir("/");
374#ifdef notdef
375		syslog(LOG_INFO|LOG_AUTH,
376		    "%s@%s as %s: no home directory. cmd='%.80s'",
377		    remuser, fromhost, locuser, cmdbuf);
378		error("No remote directory.\n");
379		exit(1);
380#endif
381#endif
382		pwd->pw_dir = "/";
383	}
384
385#ifndef  NO_PAM
386	retval = auth_pam(locuser);
387
388	if (retval) {
389		if (retval == -1) {
390			syslog(LOG_ERR,"PAM authentication failed");
391		}
392		else {
393			syslog(LOG_ERR,
394				"User %s failed PAM authentication", locuser);
395			exit(1);
396		}
397	}
398#endif
399
400		if (errorstr ||
401		    (pwd->pw_expire && time(NULL) >= pwd->pw_expire) ||
402		    (pwd->pw_passwd != 0 && *pwd->pw_passwd != '\0' &&
403		     iruserok_sa(fromp, fromp->su_len, pwd->pw_uid == 0,
404				 remuser, locuser) < 0)) {
405			if (__rcmd_errstr)
406				syslog(LOG_INFO|LOG_AUTH,
407			    "%s@%s as %s: permission denied (%s). cmd='%.80s'",
408				    remuser, fromhost, locuser, __rcmd_errstr,
409				    cmdbuf);
410			else
411				syslog(LOG_INFO|LOG_AUTH,
412			    "%s@%s as %s: permission denied. cmd='%.80s'",
413				    remuser, fromhost, locuser, cmdbuf);
414fail:
415			if (errorstr == NULL)
416				errorstr = "Login incorrect.\n";
417			error(errorstr, fromhost);
418			exit(1);
419		}
420
421	if (pwd->pw_uid && !access(_PATH_NOLOGIN, F_OK)) {
422		error("Logins currently disabled.\n");
423		exit(1);
424	}
425#ifdef	LOGIN_CAP
426	if (lc != NULL && fromp->su_family == AF_INET) {	/*XXX*/
427		char	remote_ip[MAXHOSTNAMELEN];
428
429		strncpy(remote_ip, numericname,
430			sizeof(remote_ip) - 1);
431		remote_ip[sizeof(remote_ip) - 1] = 0;
432		if (!auth_hostok(lc, fromhost, remote_ip)) {
433			syslog(LOG_INFO|LOG_AUTH,
434			    "%s@%s as %s: permission denied (%s). cmd='%.80s'",
435			    remuser, fromhost, locuser, __rcmd_errstr,
436			    cmdbuf);
437			error("Login incorrect.\n");
438			exit(1);
439		}
440		if (!auth_timeok(lc, time(NULL))) {
441			error("Logins not available right now\n");
442			exit(1);
443		}
444	}
445#endif	/* !LOGIN_CAP */
446#if	BSD > 43
447	/* before fork, while we're session leader */
448	if (setlogin(pwd->pw_name) < 0)
449		syslog(LOG_ERR, "setlogin() failed: %m");
450#endif
451
452	(void) write(STDERR_FILENO, "\0", 1);
453	sent_null = 1;
454
455	if (port) {
456		if (pipe(pv) < 0) {
457			error("Can't make pipe.\n");
458			exit(1);
459		}
460#ifdef CRYPT
461		if (doencrypt) {
462			if (pipe(pv1) < 0) {
463				error("Can't make 2nd pipe.\n");
464				exit(1);
465			}
466			if (pipe(pv2) < 0) {
467				error("Can't make 3rd pipe.\n");
468				exit(1);
469			}
470		}
471#endif
472		pid = fork();
473		if (pid == -1)  {
474			error("Can't fork; try again.\n");
475			exit(1);
476		}
477		if (pid) {
478#ifdef CRYPT
479			if (doencrypt) {
480				static char msg[] = SECURE_MESSAGE;
481				(void) close(pv1[1]);
482				(void) close(pv2[1]);
483				des_enc_write(s, msg, sizeof(msg) - 1,
484					schedule, &kdata->session);
485
486			} else
487#endif
488			{
489				(void) close(0);
490				(void) close(1);
491			}
492			(void) close(2);
493			(void) close(pv[1]);
494
495			FD_ZERO(&readfrom);
496			FD_SET(s, &readfrom);
497			FD_SET(pv[0], &readfrom);
498			if (pv[0] > s)
499				nfd = pv[0];
500			else
501				nfd = s;
502#ifdef CRYPT
503			if (doencrypt) {
504				FD_ZERO(&writeto);
505				FD_SET(pv2[0], &writeto);
506				FD_SET(pv1[0], &readfrom);
507
508				nfd = MAX(nfd, pv2[0]);
509				nfd = MAX(nfd, pv1[0]);
510			} else
511#endif
512				ioctl(pv[0], FIONBIO, (char *)&one);
513
514			/* should set s nbio! */
515			nfd++;
516			do {
517				ready = readfrom;
518#ifdef CRYPT
519				if (doencrypt) {
520					wready = writeto;
521					if (select(nfd, &ready,
522					    &wready, (fd_set *) 0,
523					    (struct timeval *) 0) < 0)
524						break;
525				} else
526#endif
527					if (select(nfd, &ready, (fd_set *)0,
528					  (fd_set *)0, (struct timeval *)0) < 0)
529						break;
530				if (FD_ISSET(s, &ready)) {
531					int	ret;
532#ifdef CRYPT
533					if (doencrypt)
534						ret = des_enc_read(s, &sig, 1,
535						schedule, &kdata->session);
536					else
537#endif
538						ret = read(s, &sig, 1);
539					if (ret <= 0)
540						FD_CLR(s, &readfrom);
541					else
542						killpg(pid, sig);
543				}
544				if (FD_ISSET(pv[0], &ready)) {
545					errno = 0;
546					cc = read(pv[0], buf, sizeof(buf));
547					if (cc <= 0) {
548						shutdown(s, 1+1);
549						FD_CLR(pv[0], &readfrom);
550					} else {
551#ifdef CRYPT
552						if (doencrypt)
553							(void)
554							  des_enc_write(s, buf, cc,
555								schedule, &kdata->session);
556						else
557#endif
558							(void)
559							  write(s, buf, cc);
560					}
561				}
562#ifdef CRYPT
563				if (doencrypt && FD_ISSET(pv1[0], &ready)) {
564					errno = 0;
565					cc = read(pv1[0], buf, sizeof(buf));
566					if (cc <= 0) {
567						shutdown(pv1[0], 1+1);
568						FD_CLR(pv1[0], &readfrom);
569					} else
570						(void) des_enc_write(STDOUT_FILENO,
571						    buf, cc,
572							schedule, &kdata->session);
573				}
574
575				if (doencrypt && FD_ISSET(pv2[0], &wready)) {
576					errno = 0;
577					cc = des_enc_read(STDIN_FILENO,
578					    buf, sizeof(buf),
579						schedule, &kdata->session);
580					if (cc <= 0) {
581						shutdown(pv2[0], 1+1);
582						FD_CLR(pv2[0], &writeto);
583					} else
584						(void) write(pv2[0], buf, cc);
585				}
586#endif
587
588			} while (FD_ISSET(s, &readfrom) ||
589#ifdef CRYPT
590			    (doencrypt && FD_ISSET(pv1[0], &readfrom)) ||
591#endif
592			    FD_ISSET(pv[0], &readfrom));
593			exit(0);
594		}
595		setpgrp(0, getpid());
596		(void) close(s);
597		(void) close(pv[0]);
598#ifdef CRYPT
599		if (doencrypt) {
600			close(pv1[0]); close(pv2[0]);
601			dup2(pv1[1], 1);
602			dup2(pv2[1], 0);
603			close(pv1[1]);
604			close(pv2[1]);
605		}
606#endif
607		dup2(pv[1], 2);
608		close(pv[1]);
609	}
610	if (*pwd->pw_shell == '\0')
611		pwd->pw_shell = _PATH_BSHELL;
612	environ = envinit;
613	strncat(homedir, pwd->pw_dir, sizeof(homedir)-6);
614	strcat(path, _PATH_DEFPATH);
615	strncat(shell, pwd->pw_shell, sizeof(shell)-7);
616	strncat(username, pwd->pw_name, sizeof(username)-6);
617	cp = strrchr(pwd->pw_shell, '/');
618	if (cp)
619		cp++;
620	else
621		cp = pwd->pw_shell;
622#ifdef	LOGIN_CAP
623	if (setusercontext(lc, pwd, pwd->pw_uid, LOGIN_SETALL) != 0) {
624                syslog(LOG_ERR, "setusercontext: %m");
625		exit(1);
626	}
627	login_close(lc);
628#else
629	(void) setgid((gid_t)pwd->pw_gid);
630	initgroups(pwd->pw_name, pwd->pw_gid);
631	(void) setuid((uid_t)pwd->pw_uid);
632#endif
633	endpwent();
634	if (log_success || pwd->pw_uid == 0) {
635		    syslog(LOG_INFO|LOG_AUTH, "%s@%s as %s: cmd='%.80s'",
636			remuser, fromhost, locuser, cmdbuf);
637	}
638	execl(pwd->pw_shell, cp, "-c", cmdbuf, 0);
639	perror(pwd->pw_shell);
640	exit(1);
641}
642
643/*
644 * Report error to client.  Note: can't be used until second socket has
645 * connected to client, or older clients will hang waiting for that
646 * connection first.
647 */
648#if __STDC__
649#include <stdarg.h>
650#else
651#include <varargs.h>
652#endif
653
654void
655#if __STDC__
656error(const char *fmt, ...)
657#else
658error(fmt, va_alist)
659	char *fmt;
660        va_dcl
661#endif
662{
663	va_list ap;
664	int len;
665	char *bp, buf[BUFSIZ];
666#if __STDC__
667	va_start(ap, fmt);
668#else
669	va_start(ap);
670#endif
671	bp = buf;
672	if (sent_null == 0) {
673		*bp++ = 1;
674		len = 1;
675	} else
676		len = 0;
677	(void)vsnprintf(bp, sizeof(buf) - 1, fmt, ap);
678	(void)write(STDERR_FILENO, buf, len + strlen(bp));
679}
680
681void
682getstr(buf, cnt, err)
683	char *buf, *err;
684	int cnt;
685{
686	char c;
687
688	do {
689		if (read(STDIN_FILENO, &c, 1) != 1)
690			exit(1);
691		*buf++ = c;
692		if (--cnt == 0) {
693			error("%s too long\n", err);
694			exit(1);
695		}
696	} while (c != 0);
697}
698
699/*
700 * Check whether host h is in our local domain,
701 * defined as sharing the last two components of the domain part,
702 * or the entire domain part if the local domain has only one component.
703 * If either name is unqualified (contains no '.'),
704 * assume that the host is local, as it will be
705 * interpreted as such.
706 */
707int
708local_domain(h)
709	char *h;
710{
711	char localhost[MAXHOSTNAMELEN];
712	char *p1, *p2;
713
714	localhost[0] = 0;
715	(void) gethostname(localhost, sizeof(localhost) - 1);
716	localhost[sizeof(localhost) - 1] = '\0';
717	p1 = topdomain(localhost);
718	p2 = topdomain(h);
719	if (p1 == NULL || p2 == NULL || !strcasecmp(p1, p2))
720		return (1);
721	return (0);
722}
723
724char *
725topdomain(h)
726	char *h;
727{
728	char *p, *maybe = NULL;
729	int dots = 0;
730
731	for (p = h + strlen(h); p >= h; p--) {
732		if (*p == '.') {
733			if (++dots == 2)
734				return (p);
735			maybe = p;
736		}
737	}
738	return (maybe);
739}
740
741void
742usage()
743{
744
745	syslog(LOG_ERR, "usage: rshd [-%s]", OPTIONS);
746	exit(2);
747}
748