diff --git a/NT/init_nt b/NT/init_nt index 6d50c7467b85ae33719773ae75994e410b3b07b0..9a5f6bc456f00a38d9e16fcd9ee3873facb620db 100755 --- a/NT/init_nt +++ b/NT/init_nt @@ -1,15 +1,27 @@ #!/bin/sh # Edit -NTHOST=kheleyr +NTHOST=10.0.4.10 NTDRIVE='j:' # What dir on the UNIX machine is on $NTDRIVE ? # This variable MUST NOT end with a slash. NTMOUNT= +# Use Simple Pike Remote SHell? +USE_SPRSH=yes + +# Port for sprsh +NTPORT=4711 + # Don't edit -PATH=`pwd`/tools:$PATH + +NP=`pwd`/tools + +case :$PATH: in + *:$NP:*) ;; + *) PATH=$NP:$PATH ;; +esac CC=rntcc NTTOOLS=`pwd`/tools/lib if [ "x$NTMOUNT" = x ]; then @@ -19,5 +31,5 @@ else " fi -export NTHOST NTDRIVE NTCC CC PATH NTTOOLS MNTREPLACE MNTREPLACE +export NTHOST NTDRIVE NTCC CC PATH NTTOOLS MNTREPLACE MNTREPLACE NTPORT USE_SPRSH diff --git a/NT/tools/lib b/NT/tools/lib index 214ecd6df46b66bb8b7d0a2517e5780a568b6a1b..ddcaf35a3636f5df18cab1e76f4106934123060c 100644 --- a/NT/tools/lib +++ b/NT/tools/lib @@ -14,25 +14,33 @@ fixabspath() { } getntenv() { - rsh $NTHOST set $1 | egrep "^$1=" | sed 's/^.*=// + if [ $USE_SPRSH = yes ]; then + sprsh getenv $1 + else + rsh $NTHOST set $1 | egrep "^$1=" | sed 's/^.*=// s/ //g' + fi } silent_do_cmd() { - BATFILE=TMP$$.bat - PWD=`pwd` - RPWD=`fixabspath $PWD` - if [ x$NT_DEBUG != xyes ]; then - echo >$BATFILE "@echo off " + if [ $USE_SPRSH = yes ]; then + sprsh "$*" else - echo >$BATFILE - fi - echo >>$BATFILE "$NTDRIVE " - echo >>$BATFILE "cd $RPWD " - echo >>$BATFILE "$* " - rsh $NTHOST $NTDRIVE$RPWD\\$BATFILE - if [ x$CLEANUP = xyes ]; then - rm $BATFILE || : + BATFILE=TMP$$.bat + PWD=`pwd` + RPWD=`fixabspath $PWD` + if [ x$NT_DEBUG != xyes ]; then + echo >$BATFILE "@echo off " + else + echo >$BATFILE + fi + echo >>$BATFILE "$NTDRIVE " + echo >>$BATFILE "cd $RPWD " + echo >>$BATFILE "$* " + rsh $NTHOST $NTDRIVE$RPWD\\$BATFILE + if [ x$CLEANUP = xyes ]; then + rm $BATFILE || : + fi fi } diff --git a/NT/tools/rntcc b/NT/tools/rntcc index 15e8340342138f0b2b0173902ce63bf8d7b5b9d7..3bc8a062e3ceb8ecf812842e5fe06a20c21e8c53 100755 --- a/NT/tools/rntcc +++ b/NT/tools/rntcc @@ -2,8 +2,6 @@ . $NTTOOLS -set -e - OPTS="" CFLAGS="" SOURCES="" @@ -212,5 +210,6 @@ if [ $OPERATION = linking ]; then echo >>$OUTPUT ". \$NTTOOLS" echo >>$OUTPUT "set -e" echo >>$OUTPUT "silent_do_cmd '`fixpath $NTDRIVE$PWD/$TARGET`' \"\$@\"" + echo >>$OUTPUT "exit \$?" chmod +x $OUTPUT fi diff --git a/NT/tools/sprsh b/NT/tools/sprsh new file mode 100755 index 0000000000000000000000000000000000000000..cb463c2ce0dec5ceea09c8ab23a9828d08ac0413 --- /dev/null +++ b/NT/tools/sprsh @@ -0,0 +1,42 @@ +#!/usr/local/bin/pike + +inherit Stdio.File; + +string handle_input() +{ + object stdin=Stdio.File("stdin"); + while(string s=stdin->read(1000,1)) + write(s); +} + + +#if !constant(strerror) +#define strerror(X) X +#endif + +int main(int argc, string *cmd) +{ + if(!connect(getenv("NTHOST"),(int)getenv("NTPORT"))) + { + werror("Failed to connect "+strerror(errno())+".\n"); + exit(1); + } + + string tmp=getcwd(); + string mnt=getenv("NTMOUNT"); + if(mnt && strlen(mnt)) tmp=replace(tmp,mnt,""); + cmd[0]=getenv("NTDRIVE")+replace(tmp,"/","\\"); + write(sprintf("%4c",sizeof(cmd))); + for(int e=0;e<sizeof(cmd);e++) + write(sprintf("%4c%s",strlen(cmd[e]),cmd[e])); + + thread_create(handle_input); + while(1) + { + sscanf(read(4),"%4c",int len); + if(!len) break; + predef::write(read(len)); + } + sscanf(read(4),"%4c",int code); + exit(code); +} diff --git a/NT/tools/sprshd b/NT/tools/sprshd new file mode 100755 index 0000000000000000000000000000000000000000..ae6a177c9d27932b78e09e3c493119783741c759 --- /dev/null +++ b/NT/tools/sprshd @@ -0,0 +1,95 @@ +#!/usr/local/bin/pike + +inherit Stdio.Port; + +void handle_incoming_connection(object(Stdio.File) io) +{ + object p; + sscanf(io->read(4),"%4c",int args); + string *cmd=allocate(args); + for(int e=0;e<args;e++) + { + sscanf(io->read(4),"%4c",int len); + cmd[e]=io->read(len); + } + + object pi=Stdio.File(); + object p2=pi->pipe(); + string dir=cmd[0]; + cmd=cmd[1..]; + + switch(cmd[0]) + { + case "getenv": + { + string s=getenv(cmd[1])+"\n"; + io->write(sprintf("%4c%s",strlen(s),s)); + io->write(sprintf("%4c",0)); + io->write(sprintf("%4c",0)); + break; + } + + default: + mixed err=catch { + p=Process.create_process(cmd, + ([ + "stdin":io, + "stdout":p2, + "stderr":p2, + "cwd":dir, + ])); }; + + destruct(p2); + + if(!err) + { + while(1) + { + string s=pi->read(1000,1); + if(!s || !strlen(s)) break; + io->write(sprintf("%4c%s",strlen(s),s)); + } + + io->write(sprintf("%4c",0)); + io->write(sprintf("%4c",p->wait())); + }else{ + io->write(sprintf("%4c",0)); + io->write(sprintf("%4c",69)); + } + } + io->close("w"); + destruct(io); +} + + +int main(int argc, string *argv) +{ + if(c<2) + { + werror("Usage: sprshd <port> <host to accept connections from>\n"); + exit(1); + } + if(!bind((int)argv[1])) + { + werror("Failed to bind port.\n"); + exit(1); + } + + string *hosts=gethostbyname(argv[2])[1]; + + while(1) + { + if(object io=accept()) + { + sscanf(io->query_address(),"%s ",string ip); + if(search(hosts, ip)==-1) + { + destruct(io); + continue; + } + thread_create(handle_incoming_connection,io); + }else{ + werror("Accept failed "+errno()+"\n"); + } + } +} diff --git a/NT/tools/uname b/NT/tools/uname index ff699aae43ac1e28c138a8d06154f83f000ade6f..aa9c693546e0a7564d2229b9bb9105ed859380eb 100755 --- a/NT/tools/uname +++ b/NT/tools/uname @@ -57,7 +57,8 @@ fi OUTPUT= if [ $S = yes ]; then - OUTPUT="$OUTPUT `getntenv OS`" + OUTPUT="$OUTPUT Windows_NT" +# OUTPUT="$OUTPUT `getntenv OS`" fi if [ $N = yes ]; then diff --git a/src/modules/files/socket.c b/src/modules/files/socket.c index dda702639651c642ce978c0679de7e24bc84ef6a..fc7300d6f649aa3ed71ccf8a3b0c5b4c011693b2 100644 --- a/src/modules/files/socket.c +++ b/src/modules/files/socket.c @@ -295,6 +295,7 @@ extern struct program *file_program; static void port_accept(INT32 args) { + struct sockaddr_in addr; struct port *this=THIS; int fd,tmp; int len=0; @@ -305,7 +306,8 @@ static void port_accept(INT32 args) THREADS_ALLOW(); - fd=fd_accept(this->fd, 0, &len); + len=sizeof(addr); + fd=fd_accept(this->fd, (struct sockaddr *)&addr, &len); THREADS_DISALLOW(); if(fd < 0)