summaryrefslogtreecommitdiff
path: root/src/nu_server.h
blob: 89fe2e964317ea9788a4846c4d1c4e4acea7c29c (plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef _NU_SERVER_H_
#define _NU_SERVER_H_

#include <time.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <sys/ioctl.h>

typedef unsigned char  BYTE;
typedef unsigned short WORD;
typedef unsigned long  DWORD;
typedef int64_t        QWORD;

#define SKIPSTRING( str ) ((BYTE*)(str)) + 1 + strlen( (str) )
#define GETNWORD(addr) (*((BYTE*)(addr)) | 256 * ((BYTE*)(addr))[1] )

#include "nu_defines.h"
#define SMB_MAXREQUESTS 16

typedef struct {
  BYTE       netbios_command;
  BYTE       netbios_flags;
  WORD       netbios_size;
  DWORD      Protocol;     /* Protocol identifier 0xFF,"SMB" */
  BYTE       Command;      /* Command Code, look below */
  BYTE       Status[4];
  BYTE       Flags;
  WORD       Flags2;
  WORD       Pad[6];       /* Ensure 12 bytes len */
  WORD       TreeID;
  WORD       ProcessID;
  WORD       UserID;
  WORD       MultiplexID;
} SMB_HEADER;

typedef struct {
  BYTE       WordCount;
  WORD       Buffer[0];
} SMB_PARAMS;

typedef struct {
  WORD       ByteCount;
  BYTE       Buffer[0];
} SMB_BYTES;

typedef struct {
  SMB_PARAMS *params;
  SMB_BYTES  *bytes;
} SMB_DATA;

typedef struct {
  BYTE       WordCount;             /* 19 + SetupCount */
  BYTE       TotalParameterCount [2];
  BYTE       TotalDataCount [2];
  BYTE       MaxParameterCount [2]; /* For now we only support packets */
  BYTE       MaxDataCount [2];      /* with TotalXXCount == MaxXXCount */
  BYTE       MaxSetupCount;
  BYTE       Reserved;
  BYTE       Flags [2];
  BYTE       Timeout [4];
  BYTE       Reserved2 [2];

  BYTE       ParameterCount [2];
  BYTE       ParameterOffset [2];
  BYTE       DataCount [2];
  BYTE       DataOffset [2];
  BYTE       SetupCount;
  BYTE       Reserved3;
  BYTE       Setup[0];
} SMB_PARAMS_TRANSACTION;

typedef struct {
  BYTE      *params;
  DWORD      paramc;
  BYTE      *data;
  DWORD      datac;
} SMB_TRANSACTION_BYTES;

typedef struct {
  BYTE             cmd;
  SMB_COMMAND_FLAG flags;
  SMB_STATUS     (*handler)(SMB_HEADER *header, SMB_DATA *data);
} SMB_COMMAND_HANDLER;

#endif