달력

07

« 2010/07 »

  •  
  •  
  •  
  •  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
2008/09/21 21:52

rlogin, rsh 사용 시 에러 메세지 (RHEL5) Linux2008/09/21 21:52

RHEL5 에서 rlogin 할 때 아래와 같은 메세지가 발생할 경우...

n.rlogind: network.c:130: find_hostname: Assertion `error == 0' failed. network.c 130:

해결은 간단하다. 

/etc/hosts 파일에 접속을 시도하는 시스템의 ip, hostname 이 등록되어 있지 않아서 발생하는 메세지 이므로 등록하면 된다.
TAG rhel5, rlogin, rsh
Posted by shsch
가장 많이 물어보는 질문 중 하나여서 간단한 Tip 정도로 정리해 둔다.

.rhosts 파일에 등록된 시스템으로 접속할 경우에는 패스워드 인증 없이 바로 접속이 되어야 하는데 그렇지 않고 매번 패스워드를 물어볼 경우 확인해야 할 사항.


1. /etc/hosts 파일에 각각의 서버가  등록되어 있어야 한다.

2. .rhosts 파일의 쓰기 권한은 소유자만 가지고 있어야 한다.


Posted by shsch
2007/06/03 11:35

rsh timeout patch Linux2007/06/03 11:35

아래의 패치는 RHEL 4.0 기준으로 작성되었고 테스트시 이상없었습니다.

패치 적용 후 rsh 실행시 -t 옵션을 주어 사용하면 됩니다.


diff -uNr netkit-rsh-0.17.org/rsh/rsh.c netkit-rsh-0.17/rsh/rsh.c
--- netkit-rsh-0.17.org/rsh/rsh.c 2006-09-20 10:40:30.732583250 +0900
+++ netkit-rsh-0.17/rsh/rsh.c 2006-09-20 09:55:11.000000000 +0900
@@ -65,8 +65,9 @@
 static int rfd2;
 static char *copyargs(char **);
 static void sendsig(int);
-static void talk(int nflag, long omask, int pid, int rem);
+static void talk(int nflag, long omask, int pid, int rem, int timeout);
 static void usage(void);
+void connect_timeout( int );
 
 int
 main(int argc, char *argv[])
@@ -75,6 +76,7 @@
  struct servent *sp;
  long omask;
  int argoff, asrsh, ch, dflag, nflag, one, pid=0, rem, uid;
+ int timeout=0;
  char *p;
  char *args, *host, *user;
  char *null = NULL;
@@ -101,7 +103,7 @@
   argoff = 1;
  }
 
-#define OPTIONS "+8KLdel:nw"
+#define OPTIONS "+8KLdelt:nw"
  while ((ch = getopt(argc - argoff, argv + argoff, OPTIONS)) != EOF)
   switch(ch) {
   case 'K':
@@ -120,6 +122,9 @@
   case 'n':
    nflag = 1;
    break;
+  case 't':
+   timeout = atoi(optarg);
+   break;
   case '?':
   default:
    usage();
@@ -162,9 +167,20 @@
   fprintf(stderr, "rsh: shell/tcp: unknown service.\n");
   exit(1);
  }
+ if( timeout ) {
+  signal( SIGALRM, connect_timeout);
+  alarm( timeout );
+ }
+
 
  rem = rcmd(&host, sp->s_port, pw->pw_name, user, args, &rfd2);
 
+ if( timeout ) {
+  signal(SIGALRM, SIG_DFL);
+  alarm(0);
+ }
+
+
  if (rem < 0)
   exit(1);
 
@@ -211,7 +227,7 @@
   ioctl(rem, FIONBIO, &one);
  }
 
- talk(nflag, omask, pid, rem);
+ talk(nflag, omask, pid, rem, timeout);
 
  if (!nflag)
   kill(pid, SIGKILL);
@@ -219,13 +235,15 @@
 }
 
 static void
-talk(int nflag, long omask, int pid, int rem)
+talk(int nflag, long omask, int pid, int rem, int timeout)
 {
  register int cc, wc;
  register char *bp;
  fd_set readfrom, rembits;
  int rfd2_ok, rem_ok;
  char buf[BUFSIZ];
+ struct timeval tvtimeout;
+ int srval ;
 
  FD_ZERO(&rembits);
 
@@ -265,6 +283,9 @@
   exit(0);
  }
 
+ tvtimeout.tv_sec = timeout;
+ tvtimeout.tv_usec = 0;
+
  rfd2_ok = rem_ok = 1;
  sigsetmask(omask);
  while (rfd2_ok || rem_ok) {
@@ -273,8 +294,13 @@
    FD_SET(rfd2, &readfrom);
   if (rem_ok)
    FD_SET(rem, &readfrom);
-  if (select(rfd2 > rem ? rfd2+1 : rem+1,
-      &readfrom, 0, 0, 0) < 0) {
+  if( timeout ) {
+   srval = select(rfd2 > rem ? rfd2+1 : rem+1, &readfrom, 0, 0, &tvtimeout );
+  } else {
+   srval = select(rfd2 > rem ? rfd2+1 : rem+1, &readfrom, 0, 0, 0);
+  }
+
+  if ( srval < 0) {
    if (errno != EINTR) {
     fprintf(stderr,
         "rsh: select: %s.\n", strerror(errno));
@@ -282,6 +308,11 @@
    }
    continue;
   }
+
+  if( srval == 0 )  {
+   fprintf(stderr, "timeout reached (%d seconds)", timeout);
+  }
+
   if (FD_ISSET(rfd2, &readfrom)) {
    errno = 0;
     cc = read(rfd2, buf, sizeof buf);
@@ -301,6 +332,14 @@
  }
 }
 
+
+/*
+void
+sendsig2(int signo)
+{
+ abort();
+}
+*/
 void
 sendsig(int signo)
 {
@@ -332,11 +371,21 @@
  return(args);
 }
 
+void
+connect_timeout( int sig)
+{
+ char message[] = "timeout reached before connection completed.\n";
+ write(STDERR_FILENO, message, sizeof(message) - 1);
+ abort();
+ //_exit(1);
+}
+
+
 void
 usage(void)
 {
  fprintf(stderr,
-     "usage: rsh [-nd%s]%s[-l login] host [command]\n",
+     "usage: rsh [-nd%s]%s -t timeout [-l login] host [command]\n",
      "", " ");
  exit(1);
 }
TAG rsh, timeout
Posted by shsch
2007/06/03 11:17

rsh 사용 시 timeout 스크립트 사용 Linux2007/06/03 11:17

rsh, rlogin 서비스 작동 유무를 점검시 직접 시스템으로의 rlogin을 하는 방법으로 하려고 하는데 리눅스에서 제공되는 rsh 에는 timeout 설정이 없어 아래의 스크립트를 구글에서 구하여 사용함.

#Newsgroups: comp.unix.admin,comp.unix.solaris,comp.unix.shell
#From: gwc@root.co.uk (Geoff Clare)
#Subject: Re: timeout -t (Re: How to give rsh a shorter timeout?)
#Message-ID:
#Date: Fri, 13 Feb 1998 18:23:52 GMT

#
# Conversion to bash v2 syntax done by Chet Ramey # UNTESTED
#

prog=${0##*/}
usage="usage: $prog [-signal] [timeout] [:interval] [+delay] [--] "

SIG=-TERM # default signal sent to the process when the timer expires
timeout=60 # default timeout
interval=15 # default interval between checks if the process is still alive
delay=2 # default delay between posting the given signal and
# destroying the process (kill -KILL)

while :
do
case $1 in
--) shift; break ;;
-*) SIG=$1 ;;
[0-9]*) timeout=$1 ;;
:*) EXPR='..\(.*\)' ; interval=`expr x"$1" : "$EXPR"` ;;
+*) EXPR='..\(.*\)' ; delay=`expr x"$1" : "$EXPR"` ;;
*) break ;;
esac
shift
done

case $# in
0) echo "$prog: $usage" >&2 ; exit 2 ;;
esac

(
for t in $timeout $delay
do
while (( $t > $interval ))
do
sleep $interval
kill -0 $$ || exit
t=$(( $t - $interval ))
done
sleep $t
kill $SIG $$ && kill -0 $$ || exit
SIG=-KILL
done
) 2> /dev/null &

exec "$@"
Posted by shsch
2007/06/03 11:07

rlogin 시 '++' 을 사용하려면... Linux2007/06/03 11:07

참고로 보안을 고려한다면 rlogin, rsh 보다는 ssh 를 사용하는 것이 바람직하다.

Linux 와 Solaris 로 구성된 Computing Parm 에서 rlogin, rsh 을 사용 시 Solaris 에서는 .rhosts 파일에 '++' 를 사용할 수 있으나 Linux 에서는 사용이 불가능하다.

사용가능하게 하려면,

/etc/pam.d/login 파일의 다음 항목 끝에 아래와 같이 옵션을 추가하면 된다.

auth  sufficient     /lib/security/pam_rhosts_auth.so  'promiscuous'


(Update)
RHEL4, 5 버전에서는 /etc/pam.d/rsh, /etc/pam.d/rlogin 파일에 promiscuous 옵션만 추가해 주면 된다.

TAG ++, rhosts, rlogin, rsh
Posted by shsch