Deleted Added
full compact
1/*-
2 * Copyright (c) 1983, 1988, 1989, 1993
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

--- 28 unchanged lines hidden (view full) ---

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[] = "@(#)rlogind.c 8.1 (Berkeley) 6/4/93";
43#endif
44static const char rcsid[] =
45 "$FreeBSD: head/libexec/rlogind/rlogind.c 81991 2001-08-20 18:13:50Z brian $";
45 "$FreeBSD: head/libexec/rlogind/rlogind.c 90377 2002-02-07 23:57:01Z imp $";
46#endif /* not lint */
47
48/*
49 * remote login server:
50 * \0
51 * remuser\0
52 * locuser\0
53 * terminal_type/speed\0

--- 57 unchanged lines hidden (view full) ---

111 } su_si;
112 struct sockaddr_in su_sin;
113 struct sockaddr_in6 su_sin6;
114};
115#define su_len su_si.si_len
116#define su_family su_si.si_family
117#define su_port su_si.si_port
118
119void doit __P((int, union sockunion *));
120int control __P((int, char *, int));
121void protocol __P((int, int));
122void cleanup __P((int));
123void fatal __P((int, char *, int));
124int do_rlogin __P((union sockunion *));
125void getstr __P((char *, int, char *));
126void setup_term __P((int));
127int do_krb_login __P((struct sockaddr_in *));
128void usage __P((void));
119void doit(int, union sockunion *);
120int control(int, char *, int);
121void protocol(int, int);
122void cleanup(int);
123void fatal(int, char *, int);
124int do_rlogin(union sockunion *);
125void getstr(char *, int, char *);
126void setup_term(int);
127int do_krb_login(struct sockaddr_in *);
128void usage(void);
129
130
131int
132main(argc, argv)
133 int argc;
134 char *argv[];
132main(int argc, char *argv[])
133{
134 extern int __check_rhosts_file;
135 union sockunion from;
136 int ch, fromlen, on;
137
138 openlog("rlogind", LOG_PID | LOG_CONS, LOG_AUTH);
139
140 opterr = 0;

--- 51 unchanged lines hidden (view full) ---

192int netf;
193char line[MAXPATHLEN];
194int confirmed;
195
196struct winsize win = { 0, 0, 0, 0 };
197
198
199void
202doit(f, fromp)
203 int f;
204 union sockunion *fromp;
200doit(int f, union sockunion *fromp)
201{
202 int master, pid, on = 1;
203 int authenticated = 0;
204 char hostname[2 * MAXHOSTNAMELEN + 1];
205 char nameinfo[2 * INET6_ADDRSTRLEN + 1];
206 char c;
207
208 alarm(60);

--- 118 unchanged lines hidden (view full) ---

327char oobdata[] = {TIOCPKT_WINDOW};
328
329/*
330 * Handle a "control" request (signaled by magic being present)
331 * in the data stream. For now, we are only willing to handle
332 * window size changes.
333 */
334int
339control(pty, cp, n)
340 int pty;
341 char *cp;
342 int n;
335control(int pty, char *cp, int n)
336{
337 struct winsize w;
338
339 if (n < 4+sizeof (w) || cp[2] != 's' || cp[3] != 's')
340 return (0);
341 oobdata[0] &= ~TIOCPKT_WINDOW; /* we know he heard */
342 bcopy(cp+4, (char *)&w, sizeof(w));
343 w.ws_row = ntohs(w.ws_row);
344 w.ws_col = ntohs(w.ws_col);
345 w.ws_xpixel = ntohs(w.ws_xpixel);
346 w.ws_ypixel = ntohs(w.ws_ypixel);
347 (void)ioctl(pty, TIOCSWINSZ, &w);
348 return (4+sizeof (w));
349}
350
351/*
352 * rlogin "protocol" machine.
353 */
354void
362protocol(f, p)
363 register int f, p;
355protocol(int f, int p)
356{
357 char pibuf[1024+1], fibuf[1024], *pbp = NULL, *fbp = NULL;
358 int pcc = 0, fcc = 0;
359 int cc, nfd, n;
360 char cntl;
361
362 /*
363 * Must ignore SIGTTOU, otherwise we'll stop

--- 58 unchanged lines hidden (view full) ---

422 fcc = des_enc_read(f, fibuf, sizeof(fibuf),
423 schedule, &kdata->session);
424 else
425#endif
426 fcc = read(f, fibuf, sizeof(fibuf));
427 if (fcc < 0 && errno == EWOULDBLOCK)
428 fcc = 0;
429 else {
438 register char *cp;
430 char *cp;
431 int left, n;
432
433 if (fcc <= 0)
434 break;
435 fbp = fibuf;
436
437 top:
438 for (cp = fibuf; cp < fibuf+fcc-1; cp++)

--- 64 unchanged lines hidden (view full) ---

503 pcc -= cc;
504 pbp += cc;
505 }
506 }
507 }
508}
509
510void
519cleanup(signo)
520 int signo;
511cleanup(int signo)
512{
513 char *p;
514
515 p = line + sizeof(_PATH_DEV) - 1;
516 if (logout(p))
517 logwtmp(p, "", "");
518 (void)chflags(line, 0);
519 (void)chmod(line, 0666);
520 (void)chown(line, 0, 0);
521 *p = 'p';
522 (void)chflags(line, 0);
523 (void)chmod(line, 0666);
524 (void)chown(line, 0, 0);
525 shutdown(netf, 2);
526 exit(1);
527}
528
529void
539fatal(f, msg, syserr)
540 int f;
541 char *msg;
542 int syserr;
530fatal(int f, char *msg, int syserr)
531{
532 int len;
533 char buf[BUFSIZ], *bp = buf;
534
535 /*
536 * Prepend binary one to message if we haven't sent
537 * the magic null as confirmation.
538 */

--- 6 unchanged lines hidden (view full) ---

545 len = snprintf(bp, sizeof(buf), "rlogind: %s.\r\n", msg);
546 if (len < 0)
547 len = 0;
548 (void) write(f, buf, bp + len - buf);
549 exit(1);
550}
551
552int
565do_rlogin(dest)
566 union sockunion *dest;
553do_rlogin(union sockunion *dest)
554{
555
556 getstr(rusername, sizeof(rusername), "remuser too long");
557 getstr(lusername, sizeof(lusername), "locuser too long");
558 getstr(term+ENVSIZE, sizeof(term)-ENVSIZE, "Terminal type too long");
559
560 pwd = getpwnam(lusername);
561 if (pwd == NULL)
562 return (-1);
563 /* XXX why don't we syslog() failure? */
564
565 return (iruserok_sa(dest, dest->su_len, pwd->pw_uid == 0, rusername,
566 lusername));
567}
568
569void
583getstr(buf, cnt, errmsg)
584 char *buf;
585 int cnt;
586 char *errmsg;
570getstr(char *buf, int cnt, char *errmsg)
571{
572 char c;
573
574 do {
575 if (read(STDIN_FILENO, &c, 1) != 1)
576 exit(1);
577 if (--cnt < 0)
578 fatal(STDOUT_FILENO, errmsg, 0);
579 *buf++ = c;
580 } while (c != 0);
581}
582
583extern char **environ;
584
585void
602setup_term(fd)
603 int fd;
586setup_term(int fd)
587{
605 register char *cp = index(term+ENVSIZE, '/');
588 char *cp = index(term+ENVSIZE, '/');
589 char *speed;
590 struct termios tt;
591
592#ifndef notyet
593 tcgetattr(fd, &tt);
594 if (cp) {
595 *cp++ = '\0';
596 speed = cp;

--- 21 unchanged lines hidden (view full) ---

618#endif
619
620 env[0] = term;
621 env[1] = 0;
622 environ = env;
623}
624
625void
643usage()
626usage(void)
627{
628 syslog(LOG_ERR, "usage: rlogind [-" ARGSTR "]");
629}