summaryrefslogtreecommitdiff
path: root/src/nu_server.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nu_server.c')
-rwxr-xr-xsrc/nu_server.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/src/nu_server.c b/src/nu_server.c
index d1bb46a..186c2d7 100755
--- a/src/nu_server.c
+++ b/src/nu_server.c
@@ -1,13 +1,5 @@
1#include <time.h>
2#include <fcntl.h>
3#include <signal.h>
4#include <sys/types.h>
5#include <sys/socket.h>
6#include <netinet/in.h>
7#include <stdio.h>
8#include <sys/ioctl.h>
9
10#include "nu_server.h" 1#include "nu_server.h"
2#include "nu_lanman.h"
11 3
12static void bailout( char *reason ); 4static void bailout( char *reason );
13static void sigint( int reason ) { bailout( "User interrupt." ); } 5static void sigint( int reason ) { bailout( "User interrupt." ); }
@@ -89,7 +81,7 @@ static SMB_STATUS handle_SMB_COM_SESSION_SETUP_ANDX( SMB_HEADER *header, SMB_DAT
89 return STATUS_SUCCESS; 81 return STATUS_SUCCESS;
90} 82}
91 83
92static const BYTE SMB_COM_TREE_CONNECT_ANDX_bytes[] = { 8, 0, 'I', 'P', 'C', 0, 'I', 'P', 'C', 0 }; 84static const BYTE SMB_COM_TREE_CONNECT_ANDX_bytes[] = { 9, 0, 'A', ':', 0, 'F', 'A', 'T', '3', '2', 0 };
93static BYTE SMB_COM_TREE_CONNECT_ANDX_params[] = { 3, 255, 0, 0, 0, 0, 0 }; 85static BYTE SMB_COM_TREE_CONNECT_ANDX_params[] = { 3, 255, 0, 0, 0, 0, 0 };
94 86
95static SMB_STATUS handle_SMB_COM_TREE_CONNECT_ANDX( SMB_HEADER *header, SMB_DATA *data ){ 87static SMB_STATUS handle_SMB_COM_TREE_CONNECT_ANDX( SMB_HEADER *header, SMB_DATA *data ){
@@ -99,11 +91,30 @@ static SMB_STATUS handle_SMB_COM_TREE_CONNECT_ANDX( SMB_HEADER *header, SMB_DATA
99 return STATUS_SUCCESS; 91 return STATUS_SUCCESS;
100} 92}
101 93
94static SMB_STATUS handle_SMB_COM_TRANSACTION( SMB_HEADER *header, SMB_DATA *data ) {
95 if( !strcmp( (char*)&data->bytes[1], "\\PIPE\\LANMAN"))
96 {
97 /* TODO: Sanity Check on DataCount vs. ByteCount */
98 SMB_PARAMS_TRANSACTION *params = (SMB_PARAMS_TRANSACTION *)data->params;
99 SMB_TRANSACTION_BYTES bytes;
100
101 bytes.params = ((BYTE*)&header->Protocol) + GETNWORD( params->ParameterOffset );
102 bytes.paramc = GETNWORD( params->ParameterCount );
103 bytes.data = ((BYTE*)&header->Protocol) + GETNWORD( params->DataOffset );
104 bytes.datac = GETNWORD( params->DataCount );
105
106 return handle_LANMAN( header, data, &bytes );
107 }
108 else
109 return 0x00400002;
110}
111
102static int command_handler_match(const void *a, const void *b ) { return *(BYTE*)a - *(BYTE*)b; } 112static int command_handler_match(const void *a, const void *b ) { return *(BYTE*)a - *(BYTE*)b; }
103 113
104/* If you add command handlers, please insert them in the right position, 114/* If you add command handlers, please insert them in the right position,
105 this list is sorted by command, for later bsearch*/ 115 this list is sorted by command, for later bsearch*/
106static SMB_COMMAND_HANDLER command_handler[] = { 116static SMB_COMMAND_HANDLER command_handler[] = {
117 { SMB_COM_TRANSACTION, 0x00, handle_SMB_COM_TRANSACTION },
107 { SMB_COM_NEGOTIATE, 0x00, handle_SMB_COM_NEGOTIATE }, 118 { SMB_COM_NEGOTIATE, 0x00, handle_SMB_COM_NEGOTIATE },
108 { SMB_COM_SESSION_SETUP_ANDX, 0x01, handle_SMB_COM_SESSION_SETUP_ANDX }, 119 { SMB_COM_SESSION_SETUP_ANDX, 0x01, handle_SMB_COM_SESSION_SETUP_ANDX },
109 { SMB_COM_TREE_CONNECT_ANDX, 0x01, handle_SMB_COM_TREE_CONNECT_ANDX } 120 { SMB_COM_TREE_CONNECT_ANDX, 0x01, handle_SMB_COM_TREE_CONNECT_ANDX }
@@ -126,6 +137,7 @@ static void child( ) {
126 SMB_COMMAND cmd; 137 SMB_COMMAND cmd;
127 SMB_DATA requests[ 1 + SMB_MAXREQUESTS ]; 138 SMB_DATA requests[ 1 + SMB_MAXREQUESTS ];
128 SMB_STATUS status = STATUS_SUCCESS; 139 SMB_STATUS status = STATUS_SUCCESS;
140 DWORD null = 0;
129 WORD sizeout = sizeof( SMB_HEADER ) - 4; 141 WORD sizeout = sizeof( SMB_HEADER ) - 4;
130 int num_requests = 0; 142 int num_requests = 0;
131 143
@@ -144,7 +156,7 @@ static void child( ) {
144 sizeof(command_handler)/sizeof(*command_handler), sizeof(*command_handler), command_handler_match); 156 sizeof(command_handler)/sizeof(*command_handler), sizeof(*command_handler), command_handler_match);
145 157
146 requests[ num_requests ].bytes = 158 requests[ num_requests ].bytes =
147 (SMB_BYTES*)(((BYTE*)requests[ num_requests ].params) + *((BYTE*)(requests[ num_requests ].params)) + 2); 159 (SMB_BYTES*)(((BYTE*)requests[ num_requests ].params) + 2 * *((BYTE*)(requests[ num_requests ].params)) + 1);
148 160
149 if( handler ) { 161 if( handler ) {
150 if( handler->flags & SMB_COMMAND_FLAG_ANDX ) { 162 if( handler->flags & SMB_COMMAND_FLAG_ANDX ) {
@@ -163,13 +175,14 @@ static void child( ) {
163 ((BYTE*)requests[ num_requests ].params)[4] = sizeout >> 8; 175 ((BYTE*)requests[ num_requests ].params)[4] = sizeout >> 8;
164 } else 176 } else
165 cmd = 0xff; 177 cmd = 0xff;
166 178 } else { /* no handler - return STATUS_UKCOMMAND*/
167 num_requests++;
168 } else {
169 if( num_requests ) 179 if( num_requests )
170 ((BYTE*)requests[ num_requests-1 ].params)[1] = 0xff; 180 ((BYTE*)requests[ num_requests-1 ].params)[1] = 0xff;
181 requests[ num_requests ].params = (SMB_PARAMS*)&null;
182 requests[ num_requests ].bytes = (SMB_BYTES*) &null;
171 status = 0x00400002; 183 status = 0x00400002;
172 } 184 }
185 num_requests++;
173 } 186 }
174 187
175 memcpy( inpacket->Status, &status, 4 ); /* not aligned, maybe we might do a store DWORD on x86 */ 188 memcpy( inpacket->Status, &status, 4 ); /* not aligned, maybe we might do a store DWORD on x86 */