1 //--------------------------------------------------------------------------
2 // Copyright (C) 2015-2021 Cisco and/or its affiliates. All rights reserved.
3 //
4 // This program is free software; you can redistribute it and/or modify it
5 // under the terms of the GNU General Public License Version 2 as published
6 // by the Free Software Foundation.  You may not use, modify or distribute
7 // this program under any other version of the GNU General Public License.
8 //
9 // This program is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License along
15 // with this program; if not, write to the Free Software Foundation, Inc.,
16 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 //--------------------------------------------------------------------------
18 // stream_file.cc author Russ Combs <rucombs@cisco.com>
19 
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23 
24 #include "stream_file.h"
25 
26 #include "log/messages.h"
27 
28 #include "file_module.h"
29 #include "file_session.h"
30 
31 using namespace snort;
32 
33 //-------------------------------------------------------------------------
34 // inspector stuff
35 //-------------------------------------------------------------------------
36 
37 class StreamFile : public Inspector
38 {
39 public:
StreamFile(bool b)40     StreamFile(bool b)
41     { config.upload = b; }
42 
43     NORETURN_ASSERT void eval(Packet*) override;
44     void show(const SnortConfig*) const override;
45 
46     StreamFileConfig config;
47 };
48 
eval(Packet *)49 NORETURN_ASSERT void StreamFile::eval(Packet*)
50 {
51     // session::process() instead
52     assert(false);
53 }
54 
show(const SnortConfig *) const55 void StreamFile::show(const SnortConfig*) const
56 {
57     ConfigLogger::log_flag("upload", config.upload);
58 }
59 
get_file_cfg(Inspector * ins)60 StreamFileConfig* get_file_cfg(Inspector* ins)
61 {
62     assert(ins);
63     return &((StreamFile*)ins)->config;
64 }
65 
66 //-------------------------------------------------------------------------
67 // api stuff
68 //-------------------------------------------------------------------------
69 
mod_ctor()70 static Module* mod_ctor()
71 { return new StreamFileModule; }
72 
mod_dtor(Module * m)73 static void mod_dtor(Module* m)
74 { delete m; }
75 
file_ctor(Module * m)76 static Inspector* file_ctor(Module* m)
77 {
78     StreamFileModule* mod = (StreamFileModule*)m;
79     return new StreamFile(mod->upload);
80 }
81 
file_dtor(Inspector * p)82 static void file_dtor(Inspector* p)
83 {
84     delete p;
85 }
86 
file_ssn(Flow * lws)87 static Session* file_ssn(Flow* lws)
88 {
89     return new FileSession(lws);
90 }
91 
92 static const InspectApi sfile_api =
93 {
94     {
95         PT_INSPECTOR,
96         sizeof(InspectApi),
97         INSAPI_VERSION,
98         0,
99         API_RESERVED,
100         API_OPTIONS,
101         MOD_NAME,
102         MOD_HELP,
103         mod_ctor,
104         mod_dtor
105     },
106     IT_STREAM,
107     PROTO_BIT__FILE,
108     nullptr, // buffers
109     nullptr, // service
110     nullptr, // pinit
111     nullptr, // pterm
112     nullptr, // tinit
113     nullptr, // tterm
114     file_ctor,
115     file_dtor,
116     file_ssn,
117     nullptr  // reset
118 };
119 
120 const BaseApi* nin_stream_file = &sfile_api.base;
121 
122