rlogind.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. void getstr(int, char*, int);
  12. void
  13. main(void)
  14. {
  15. char luser[128], ruser[128], term[128], err[128];
  16. getstr(0, err, sizeof(err));
  17. getstr(0, ruser, sizeof(ruser));
  18. getstr(0, luser, sizeof(luser));
  19. getstr(0, term, sizeof(term));
  20. write(0, "", 1);
  21. if(luser[0] == '\0')
  22. strncpy(luser, ruser, sizeof luser);
  23. luser[sizeof luser-1] = '\0';
  24. syslog(0, "telnet", "rlogind %s", luser);
  25. execl("/bin/ip/telnetd", "telnetd", "-n", "-u", luser, nil);
  26. fprint(2, "can't exec con service: %r\n");
  27. exits("can't exec");
  28. }
  29. void
  30. getstr(int fd, char *str, int len)
  31. {
  32. char c;
  33. int n;
  34. while(--len > 0){
  35. n = read(fd, &c, 1);
  36. if(n < 0)
  37. return;
  38. if(n == 0)
  39. continue;
  40. *str++ = c;
  41. if(c == 0)
  42. break;
  43. }
  44. *str = '\0';
  45. }