Deleted Added
full compact
rlogind.c (81991) rlogind.c (90377)
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[] =
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
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
129
130
131int
132main(argc, argv)
133 int argc;
134 char *argv[];
132main(int argc, char *argv[])
135{
136 extern int __check_rhosts_file;
137 union sockunion from;
138 int ch, fromlen, on;
139
140 openlog("rlogind", LOG_PID | LOG_CONS, LOG_AUTH);
141
142 opterr = 0;

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

194int netf;
195char line[MAXPATHLEN];
196int confirmed;
197
198struct winsize win = { 0, 0, 0, 0 };
199
200
201void
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)
205{
206 int master, pid, on = 1;
207 int authenticated = 0;
208 char hostname[2 * MAXHOSTNAMELEN + 1];
209 char nameinfo[2 * INET6_ADDRSTRLEN + 1];
210 char c;
211
212 alarm(60);

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

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

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

430 fcc = des_enc_read(f, fibuf, sizeof(fibuf),
431 schedule, &kdata->session);
432 else
433#endif
434 fcc = read(f, fibuf, sizeof(fibuf));
435 if (fcc < 0 && errno == EWOULDBLOCK)
436 fcc = 0;
437 else {
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;
439 int left, n;
440
441 if (fcc <= 0)
442 break;
443 fbp = fibuf;
444
445 top:
446 for (cp = fibuf; cp < fibuf+fcc-1; cp++)

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

511 pcc -= cc;
512 pbp += cc;
513 }
514 }
515 }
516}
517
518void
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)
521{
522 char *p;
523
524 p = line + sizeof(_PATH_DEV) - 1;
525 if (logout(p))
526 logwtmp(p, "", "");
527 (void)chflags(line, 0);
528 (void)chmod(line, 0666);
529 (void)chown(line, 0, 0);
530 *p = 'p';
531 (void)chflags(line, 0);
532 (void)chmod(line, 0666);
533 (void)chown(line, 0, 0);
534 shutdown(netf, 2);
535 exit(1);
536}
537
538void
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)
543{
544 int len;
545 char buf[BUFSIZ], *bp = buf;
546
547 /*
548 * Prepend binary one to message if we haven't sent
549 * the magic null as confirmation.
550 */

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

557 len = snprintf(bp, sizeof(buf), "rlogind: %s.\r\n", msg);
558 if (len < 0)
559 len = 0;
560 (void) write(f, buf, bp + len - buf);
561 exit(1);
562}
563
564int
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)
567{
568
569 getstr(rusername, sizeof(rusername), "remuser too long");
570 getstr(lusername, sizeof(lusername), "locuser too long");
571 getstr(term+ENVSIZE, sizeof(term)-ENVSIZE, "Terminal type too long");
572
573 pwd = getpwnam(lusername);
574 if (pwd == NULL)
575 return (-1);
576 /* XXX why don't we syslog() failure? */
577
578 return (iruserok_sa(dest, dest->su_len, pwd->pw_uid == 0, rusername,
579 lusername));
580}
581
582void
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)
587{
588 char c;
589
590 do {
591 if (read(STDIN_FILENO, &c, 1) != 1)
592 exit(1);
593 if (--cnt < 0)
594 fatal(STDOUT_FILENO, errmsg, 0);
595 *buf++ = c;
596 } while (c != 0);
597}
598
599extern char **environ;
600
601void
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)
604{
587{
605 register char *cp = index(term+ENVSIZE, '/');
588 char *cp = index(term+ENVSIZE, '/');
606 char *speed;
607 struct termios tt;
608
609#ifndef notyet
610 tcgetattr(fd, &tt);
611 if (cp) {
612 *cp++ = '\0';
613 speed = cp;

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

635#endif
636
637 env[0] = term;
638 env[1] = 0;
639 environ = env;
640}
641
642void
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)
644{
645 syslog(LOG_ERR, "usage: rlogind [-" ARGSTR "]");
646}
627{
628 syslog(LOG_ERR, "usage: rlogind [-" ARGSTR "]");
629}