summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xMakefile1
-rwxr-xr-xsrc/nu_server.c66
2 files changed, 34 insertions, 33 deletions
diff --git a/Makefile b/Makefile
index d52be6b..61cb62c 100755
--- a/Makefile
+++ b/Makefile
@@ -1,2 +1,3 @@
1nudossi: 1nudossi:
2 gcc -O -o bin/nudossi src/nu_server.c 2 gcc -O -o bin/nudossi src/nu_server.c
3 strip bin/nudossi
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) {
22 DWORD bytes; 22 DWORD bytes;
23 ssize_t bytestoread; 23 ssize_t bytestoread;
24 24
25 if( read( childsock, bytes, 4) < 4 ) 25 if( read( childsock, &bytes, 4) < 4 )
26 bailout( "Short read." ); 26 bailout( "Short read." );
27 bytestoread = htons(((WORD*)bytes)[1]); 27 bytestoread = htons(bytes>>16);
28 if( (*buf = (SMB_HEADER*)realloc( *buf, 4 + bytestoread )) == NULL) 28 if( (*buf = (SMB_HEADER*)realloc( *buf, 4 + bytestoread )) == NULL)
29 bailout( "Out of memory."); 29 bailout( "Out of memory.");
30 *(DWORD*)*buf = bytes; 30 *(DWORD*)*buf = bytes;
@@ -39,40 +39,34 @@ static void netbios_write( SMB_COMMAND cmd,
39 BYTE buf_[4] = { 0, 0, 0, 0 }; 39 BYTE buf_[4] = { 0, 0, 0, 0 };
40 if(!buf2 ) buf2 = (SMB_PARAMS*)buf_; 40 if(!buf2 ) buf2 = (SMB_PARAMS*)buf_;
41 if(!buf3 ) buf3 = (SMB_BYTES*)buf_; 41 if(!buf3 ) buf3 = (SMB_BYTES*)buf_;
42 if( buf ) { 42
43 struct iovec iov[3] = { {buf , sizeof(SMB_HEADER) }, 43 struct iovec iov[16] = { {buf , sizeof(SMB_HEADER) },
44 {buf2, 1 + buf2->WordCount * 2}, 44 {buf2, 1 + buf2->WordCount * 2},
45 {buf3, 2 + buf3->ByteCount } }; 45 {buf3, 2 + buf3->ByteCount } };
46 46
47 buf->netbios_command = cmd; 47 buf->netbios_command = cmd;
48 buf->netbios_flags = 0; 48 buf->netbios_flags = 0;
49 buf->netbios_size = htons( sizeof(SMB_HEADER) - 4 + 49 buf->netbios_size = htons( sizeof(SMB_HEADER) - 4 +
50 1 + buf2->WordCount * 2 + 50 1 + buf2->WordCount * 2 +
51 2 + buf3->ByteCount ); 51 2 + buf3->ByteCount );
52 buf->Flags = 0x88; 52 buf->Flags = 0x88;
53 buf->Flags2 = 0x4001; 53 buf->Flags2 = 0x4001;
54 54
55 if( writev( childsock, iov, 3 ) < htons( buf->netbios_size ) + 4 ) 55 if( writev( childsock, iov, 3 ) < htons( buf->netbios_size ) + 4 )
56 bailout( "Write failed." ); 56 bailout( "Write failed." );
57 } else {
58 *buf_ = cmd;
59 if( write( childsock, buf_, 4 ) < 4)
60 bailout( "Write failed." );
61 }
62} 57}
63 58
64static void child( ) { 59static void child( ) {
65 SMB_HEADER *inpacket = NULL; 60 SMB_HEADER *inpacket = NULL;
66 DWORD bytesread;
67 61
68 /* I should spare that code... */ 62 /* I should spare that code... */
69 if( mainsock != -1 ) { close( mainsock ); mainsock = -1; } 63 if( mainsock != -1 ) { close( mainsock ); mainsock = -1; }
70 64
71 /* Try to answer first netbios packet */ 65 /* Try to answer first netbios packet */
72 netbios_read( &inpacket ); 66 netbios_read( &inpacket );
73 if( inpacket->netbios_command != 0x81 ) 67 if( inpacket->netbios_command++ != 0x81 )
74 bailout( "No session request"); 68 bailout( "No session request");
75 netbios_write( 0x82, NULL, NULL, NULL ); 69 write( childsock, inpacket, 4);
76 70
77 while( 1 ) { 71 while( 1 ) {
78 netbios_read( &inpacket ); 72 netbios_read( &inpacket );
@@ -86,19 +80,25 @@ static void child( ) {
86 case SMB_COM_NEGOTIATE: 80 case SMB_COM_NEGOTIATE:
87 { 81 {
88 const BYTE bytes[] = { 8,0,0x67,0x61,0x74,0x6c,0x69,0x6e,0x67,0 }; 82 const BYTE bytes[] = { 8,0,0x67,0x61,0x74,0x6c,0x69,0x6e,0x67,0 };
89 WORD params[] = { 0x0511, 0x0000, 0x0001, 0x0001, 83 WORD params[] = { 0x0511, 0x0000, 0x0001, 0x0001, 0x0000, 0x0100,
90 0x0000, 0x0100, 0x0000, 0x0100, 84 0x0000, 0x0100, 0x0000, 0x0000, 0xC049, 0x0000,
91 0x0000, 0x0000, 0x0000, 0x0000, 85 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 };
92 0x0000, 0x0000, 0x0000, 0x0000,
93 0x0000, 0x0000 };
94 struct timeval t; gettimeofday( &t, NULL ); 86 struct timeval t; gettimeofday( &t, NULL );
95 87
96 *(DWORD*)&inpacket->Status = STATUS_SUCCESS; 88 *(DWORD*)&inpacket->Status = STATUS_SUCCESS;
97 params[8] = getpid(); params[9] = getppid(); 89 params[8] = getpid(); params[9] = getppid();
98 *(QWORD*)&params[12] = getnttime( &t ); 90 *(QWORD*)&params[12] = getnttime( &t );
99 netbios_write( 0, inpacket, (SMB_PARAMS*)params ,(SMB_BYTES*)bytes); 91 netbios_write( 0, inpacket, (SMB_PARAMS*)params, (SMB_BYTES*)bytes);
100 break; 92 break;
101 } 93 }
94/* case SMB_COM_SESSION_SETUP_ANDX:
95 {
96 const BYTE bytes[] = { 19, 0, 'O', 'S', 0, 'g', 'a', 't', 'l',
97 'i', 'n', 'g', 0, 'g', 'a', 't', 'l', 'i',
98 'n', 'g', 0};
99 BYTE params[] = { 4, 0, 0, 23, 0, 1, 0, 0, 0 };
100
101 } */
102 default: 102 default:
103 { 103 {
104 fprintf( stderr, "Got message: %02X\n", inpacket->Command ); 104 fprintf( stderr, "Got message: %02X\n", inpacket->Command );