From 227651131a61db937d4fec01e8e4e318889f6ad9 Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Wed, 3 Dec 2003 21:34:33 +0000 Subject: Starting SETUP_ANDX --- src/nu_server.c | 66 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/nu_server.c b/src/nu_server.c index 64eecfe..ddd555e 100755 --- a/src/nu_server.c +++ b/src/nu_server.c @@ -22,9 +22,9 @@ static void netbios_read( SMB_HEADER **buf) { DWORD bytes; ssize_t bytestoread; - if( read( childsock, bytes, 4) < 4 ) + if( read( childsock, &bytes, 4) < 4 ) bailout( "Short read." ); - bytestoread = htons(((WORD*)bytes)[1]); + bytestoread = htons(bytes>>16); if( (*buf = (SMB_HEADER*)realloc( *buf, 4 + bytestoread )) == NULL) bailout( "Out of memory."); *(DWORD*)*buf = bytes; @@ -39,40 +39,34 @@ static void netbios_write( SMB_COMMAND cmd, BYTE buf_[4] = { 0, 0, 0, 0 }; if(!buf2 ) buf2 = (SMB_PARAMS*)buf_; if(!buf3 ) buf3 = (SMB_BYTES*)buf_; - if( buf ) { - struct iovec iov[3] = { {buf , sizeof(SMB_HEADER) }, - {buf2, 1 + buf2->WordCount * 2}, - {buf3, 2 + buf3->ByteCount } }; - - buf->netbios_command = cmd; - buf->netbios_flags = 0; - buf->netbios_size = htons( sizeof(SMB_HEADER) - 4 + - 1 + buf2->WordCount * 2 + - 2 + buf3->ByteCount ); - buf->Flags = 0x88; - buf->Flags2 = 0x4001; - - if( writev( childsock, iov, 3 ) < htons( buf->netbios_size ) + 4 ) - bailout( "Write failed." ); - } else { - *buf_ = cmd; - if( write( childsock, buf_, 4 ) < 4) - bailout( "Write failed." ); - } + + struct iovec iov[16] = { {buf , sizeof(SMB_HEADER) }, + {buf2, 1 + buf2->WordCount * 2}, + {buf3, 2 + buf3->ByteCount } }; + + buf->netbios_command = cmd; + buf->netbios_flags = 0; + buf->netbios_size = htons( sizeof(SMB_HEADER) - 4 + + 1 + buf2->WordCount * 2 + + 2 + buf3->ByteCount ); + buf->Flags = 0x88; + buf->Flags2 = 0x4001; + + if( writev( childsock, iov, 3 ) < htons( buf->netbios_size ) + 4 ) + bailout( "Write failed." ); } static void child( ) { SMB_HEADER *inpacket = NULL; - DWORD bytesread; /* I should spare that code... */ if( mainsock != -1 ) { close( mainsock ); mainsock = -1; } /* Try to answer first netbios packet */ netbios_read( &inpacket ); - if( inpacket->netbios_command != 0x81 ) + if( inpacket->netbios_command++ != 0x81 ) bailout( "No session request"); - netbios_write( 0x82, NULL, NULL, NULL ); + write( childsock, inpacket, 4); while( 1 ) { netbios_read( &inpacket ); @@ -86,19 +80,25 @@ static void child( ) { case SMB_COM_NEGOTIATE: { const BYTE bytes[] = { 8,0,0x67,0x61,0x74,0x6c,0x69,0x6e,0x67,0 }; - WORD params[] = { 0x0511, 0x0000, 0x0001, 0x0001, - 0x0000, 0x0100, 0x0000, 0x0100, - 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000 }; + WORD params[] = { 0x0511, 0x0000, 0x0001, 0x0001, 0x0000, 0x0100, + 0x0000, 0x0100, 0x0000, 0x0000, 0xC049, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 }; struct timeval t; gettimeofday( &t, NULL ); *(DWORD*)&inpacket->Status = STATUS_SUCCESS; - params[8] = getpid(); params[9] = getppid(); - *(QWORD*)¶ms[12] = getnttime( &t ); - netbios_write( 0, inpacket, (SMB_PARAMS*)params ,(SMB_BYTES*)bytes); + params[8] = getpid(); params[9] = getppid(); + *(QWORD*)¶ms[12] = getnttime( &t ); + netbios_write( 0, inpacket, (SMB_PARAMS*)params, (SMB_BYTES*)bytes); break; } +/* case SMB_COM_SESSION_SETUP_ANDX: + { + const BYTE bytes[] = { 19, 0, 'O', 'S', 0, 'g', 'a', 't', 'l', + 'i', 'n', 'g', 0, 'g', 'a', 't', 'l', 'i', + 'n', 'g', 0}; + BYTE params[] = { 4, 0, 0, 23, 0, 1, 0, 0, 0 }; + + } */ default: { fprintf( stderr, "Got message: %02X\n", inpacket->Command ); -- cgit v1.2.3