- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

configuration.cpp
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2013 Graeme Walker <graeme_walker@users.sourceforge.net>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
17 //
18 // configuration.cpp
19 //
20
21 #include "gdef.h"
22 #include "gsmtp.h"
23 #include "gstr.h"
24 #include "configuration.h"
25 #include "commandline.h"
26 #include "gmessagestore.h"
27 #include "gpopsecrets.h"
28 #include "gstrings.h"
29 #include "gdebug.h"
30
31 Main::Configuration::Configuration( const CommandLine & cl ) :
32 m_cl(cl)
33 {
34 }
35
36 bool Main::Configuration::log() const
37 {
38 return
39 contains( "log" ) ||
40 contains( "as-client" ) ||
41 contains( "as-proxy" ) ||
42 contains( "as-server" ) ;
43 }
44
45 bool Main::Configuration::verbose() const
46 {
47 return contains( "verbose" ) ;
48 }
49
50 bool Main::Configuration::debug() const
51 {
52 return contains( "debug" ) ;
53 }
54
55 bool Main::Configuration::useSyslog() const
56 {
57 bool basic = !contains("no-syslog") && !contains("as-client") ;
58 bool override = contains( "syslog" ) ;
59 return override || basic ;
60 }
61
62 bool Main::Configuration::logTimestamp() const
63 {
64 return contains( "log-time" ) ;
65 }
66
67 std::string Main::Configuration::logFile() const
68 {
69 return contains("log-file") ? value("log-file") : std::string() ;
70 }
71
72 unsigned int Main::Configuration::port() const
73 {
74 return value( "port" , 25U ) ;
75 }
76
77 G::Strings Main::Configuration::listeningInterfaces( const std::string & protocol ) const
78 {
79 // allow eg. "127.0.0.1,smtp=192.168.1.1,admin=10.0.0.1"
80
81 // prepare the naive result by splitting the user's string by comma or slash separators
82 G::Strings result = m_cl.value( "interface" , ",/" ) ;
83
84 // then weed out the ones that have an explicit protocol name that doesnt match the
85 // required protocol, removing the "protocol=" prefix at the same time to leave just
86 // the required list of addresses
87 for( G::Strings::iterator p = result.begin() ; p != result.end() ; )
88 {
89 if( protocol.empty() || protocol == G::Str::head( *p , (*p).find('=') , protocol ) )
90 *p++ = G::Str::tail( *p , (*p).find('=') , *p ) ;
91 else
92 p = result.erase( p ) ;
93 }
94
95 return result ;
96 }
97
98 std::string Main::Configuration::clientInterface() const
99 {
100 G::Strings result = m_cl.value( "interface" , ",/" ) ;
101 // look for first "client=" value
102 {
103 for( G::Strings::iterator p = result.begin() ; p != result.end() ; ++p )
104 {
105 if( (*p).find("client=") == 0U )
106 return G::Str::tail( *p , (*p).find('=') , *p ) ;
107 }
108 }
109 // or use the first unqalified value
110 {
111 for( G::Strings::iterator p = result.begin() ; p != result.end() ; ++p )
112 {
113 if( (*p).find('=') == std::string::npos )
114 return *p ;
115 }
116 }
117 return std::string() ;
118 }
119
120 unsigned int Main::Configuration::adminPort() const
121 {
122 return value( "admin" , 0U ) ;
123 }
124
125 bool Main::Configuration::closeStderr() const
126 {
127 return
128 contains("close-stderr") ||
129 contains("as-proxy") ||
130 contains("as-server") ;
131 }
132
133 bool Main::Configuration::daemon() const
134 {
135 return !contains("no-daemon") && !contains("as-client") ;
136 }
137
138 G::Path Main::Configuration::spoolDir() const
139 {
140 return contains("spool-dir") ?
141 G::Path(value("spool-dir")) :
142 GSmtp::MessageStore::defaultDirectory() ;
143 }
144
145 std::string Main::Configuration::serverAddress() const
146 {
147 const char * key = "forward-to" ;
148 if( contains("as-client") )
149 key = "as-client" ;
150 else if( contains("as-proxy") )
151 key = "as-proxy" ;
152 return contains(key) ? value(key) : std::string() ;
153 }
154
155 bool Main::Configuration::doForwardingOnStartup() const
156 {
157 return contains("forward") || contains("as-client") ;
158 }
159
160 bool Main::Configuration::doServing() const
161 {
162 return !contains("dont-serve") && !contains("as-client") ;
163 }
164
165 bool Main::Configuration::immediate() const
166 {
167 return contains("immediate") ;
168 }
169
170 bool Main::Configuration::doPolling() const
171 {
172 return contains("poll") && pollingTimeout() > 0U ;
173 }
174
175 unsigned int Main::Configuration::pollingTimeout() const
176 {
177 return value( "poll" , 0U ) ;
178 }
179
180 bool Main::Configuration::pollingLog() const
181 {
182 // dont log if polling very frequently
183 return doPolling() && pollingTimeout() > 60U ;
184 }
185
186 bool Main::Configuration::forwardingOnStore() const
187 {
188 // this is not settable for now -- the 103 exit
189 // code has a similar effect -- see also comments below
190 return false ;
191 }
192
193 bool Main::Configuration::forwardingOnDisconnect() const
194 {
195 // TODO -- it not completely logical to tie forwarding-on-disconnect
196 // in with polling, but it avoids the situation where messages can
197 // get missed if a polling run is already in progress when a
198 // forwarding-on-disconnect event occurs -- the scan of the spool
199 // directory is done at the start of the polling run -- the fix
200 // could be to allow clients to run in parallel in the Run class,
201 // or have a method to force the client to rescan the directory
202 // before finishing
203
204 return
205 ( contains("poll") && pollingTimeout() == 0U ) ||
206 contains("as-proxy") ;
207 }
208
209 unsigned int Main::Configuration::promptTimeout() const
210 {
211 return value( "prompt-timeout" , 20U ) ;
212 }
213
214 bool Main::Configuration::doSmtp() const
215 {
216 return ! contains( "no-smtp" ) ;
217 }
218
219 bool Main::Configuration::doPop() const
220 {
221 return contains( "pop" ) ;
222 }
223
224 bool Main::Configuration::popByName() const
225 {
226 return contains( "pop-by-name" ) ;
227 }
228
229 bool Main::Configuration::popNoDelete() const
230 {
231 return contains( "pop-no-delete" ) ;
232 }
233
234 unsigned int Main::Configuration::popPort() const
235 {
236 return value( "pop-port" , 110U ) ;
237 }
238
239 bool Main::Configuration::allowRemoteClients() const
240 {
241 return contains( "remote-clients" ) ;
242 }
243
244 bool Main::Configuration::doAdmin() const
245 {
246 return contains( "admin" ) ;
247 }
248
249 bool Main::Configuration::usePidFile() const
250 {
251 return contains( "pid-file" ) ;
252 }
253
254 std::string Main::Configuration::pidFile() const
255 {
256 return value( "pid-file" ) ;
257 }
258
259 bool Main::Configuration::useFilter() const
260 {
261 return contains( "filter" ) ;
262 }
263
264 std::string Main::Configuration::filter() const
265 {
266 return contains("filter") ? value("filter") : std::string() ;
267 }
268
269 std::string Main::Configuration::clientFilter() const
270 {
271 return contains("client-filter") ? value("client-filter") : std::string() ;
272 }
273
274 unsigned int Main::Configuration::icon() const
275 {
276 return 0U ; // no longer used
277 }
278
279 bool Main::Configuration::hidden() const
280 {
281 return contains( "hidden" ) ;
282 }
283
284 std::string Main::Configuration::clientSecretsFile() const
285 {
286 return contains("client-auth") ? value("client-auth") : std::string() ;
287 }
288
289 bool Main::Configuration::clientTls() const
290 {
291 return contains( "client-tls" ) ;
292 }
293
294 bool Main::Configuration::clientOverTls() const
295 {
296 return contains( "client-tls-connection" ) ;
297 }
298
299 unsigned int Main::Configuration::tlsConfig() const
300 {
301 return value( "tls-config" , 0U ) ;
302 }
303
304 std::string Main::Configuration::serverTlsFile() const
305 {
306 return contains("server-tls") ? value("server-tls") : std::string() ;
307 }
308
309 std::string Main::Configuration::popSecretsFile() const
310 {
311 return contains("pop-auth") ? value("pop-auth") : GPop::Secrets::defaultPath() ;
312 }
313
314 std::string Main::Configuration::serverSecretsFile() const
315 {
316 return contains("server-auth") ? value("server-auth") : std::string() ;
317 }
318
319 unsigned int Main::Configuration::responseTimeout() const
320 {
321 return value( "response-timeout" , 30U * 60U ) ;
322 }
323
324 unsigned int Main::Configuration::connectionTimeout() const
325 {
326 return value( "connection-timeout" , 40U ) ;
327 }
328
329 unsigned int Main::Configuration::secureConnectionTimeout() const
330 {
331 return connectionTimeout() ;
332 }
333
334 std::string Main::Configuration::fqdn( std::string default_ ) const
335 {
336 return contains("domain") ? value("domain") : default_ ;
337 }
338
339 std::string Main::Configuration::nobody() const
340 {
341 return contains("user") ? value("user") : std::string("daemon") ;
342 }
343
344 std::string Main::Configuration::verifier() const
345 {
346 return contains("verifier") ? value("verifier") : std::string() ;
347 }
348
349 bool Main::Configuration::withTerminate() const
350 {
351 return contains( "admin-terminate" ) ;
352 }
353
354 unsigned int Main::Configuration::maxSize() const
355 {
356 return value( "size" , 0U ) ;
357 }
358
359 std::string Main::Configuration::scannerAddress() const
360 {
361 return contains("scanner") ? value("scanner") : std::string() ;
362 }
363
364 unsigned int Main::Configuration::scannerConnectionTimeout() const
365 {
366 return 10U ; // for now
367 }
368
369 unsigned int Main::Configuration::scannerResponseTimeout() const
370 {
371 return 90U ; // for now
372 }
373
374 bool Main::Configuration::anonymous() const
375 {
376 return contains( "anonymous" ) ;
377 }
378
379 unsigned int Main::Configuration::filterTimeout() const
380 {
381 return value( "filter-timeout" , 5U * 60U ) ;
382 }
383
384 bool Main::Configuration::peerLookup() const
385 {
386 return contains( "peer-lookup" ) ;
387 }
388
389 bool Main::Configuration::contains( const char * s ) const
390 {
391 return m_cl.contains( s ) ;
392 }
393
394 std::string Main::Configuration::value( const char * s ) const
395 {
396 return m_cl.value( s ) ;
397 }
398
399 unsigned int Main::Configuration::value( const char * s , unsigned int d ) const
400 {
401 return m_cl.value( s , d ) ;
402 }
403
Main::Configuration::peerLookup
bool peerLookup() const
Returns true if there should be some attempt to look up the userid of SMTP peers connected from the t...
Definition: configuration.cpp:384
Main::Configuration::doSmtp
bool doSmtp() const
Returns true if listening for smtp connections.
Definition: configuration.cpp:214
Main::Configuration::immediate
bool immediate() const
Returns true if forwarding should occur as soon as each message body is received and before receipt i...
Definition: configuration.cpp:165
Main::Configuration::clientOverTls
bool clientOverTls() const
Returns true if using the SMTP over TLS (vs.
Definition: configuration.cpp:294
Main::Configuration::verifier
std::string verifier() const
Returns the path of an external address verifier program.
Definition: configuration.cpp:344
Main::Configuration::serverAddress
std::string serverAddress() const
Returns the downstream server's address string.
Definition: configuration.cpp:145
Main::Configuration::pollingLog
bool pollingLog() const
Returns true if polling activity should be logged.
Definition: configuration.cpp:180
gstrings.h
Main::Configuration::filter
std::string filter() const
Returns the path to a server-side pre-processor.
Definition: configuration.cpp:264
Main::Configuration::doServing
bool doServing() const
Returns true if running as a server (SMTP, POP, admin or COM).
Definition: configuration.cpp:160
Main::Configuration::daemon
bool daemon() const
Returns true if running as a daemon.
Definition: configuration.cpp:133
G::Strings
std::list< std::string > Strings
A std::list of std::strings.
Definition: gstrings.h:39
Main::Configuration::anonymous
bool anonymous() const
Returns true if the server protocol should be slightly more anonymous.
Definition: configuration.cpp:374
Main::Configuration::popNoDelete
bool popNoDelete() const
Returns true if pop deletion is to be disabled.
Definition: configuration.cpp:229
Main::Configuration::popPort
unsigned int popPort() const
Returns the pop port number.
Definition: configuration.cpp:234
Main::Configuration::allowRemoteClients
bool allowRemoteClients() const
Returns true if allowing remote clients to connect.
Definition: configuration.cpp:239
Main::Configuration::closeStderr
bool closeStderr() const
Returns true if stderr should be closed.
Definition: configuration.cpp:125
Main::Configuration::spoolDir
G::Path spoolDir() const
Returns the spool directory.
Definition: configuration.cpp:138
Main::Configuration::doAdmin
bool doAdmin() const
Returns true if listening for admin connections.
Definition: configuration.cpp:244
Main::Configuration::listeningInterfaces
G::Strings listeningInterfaces(const std::string &protocol=std::string()) const
Returns the listening interface(s).
Definition: configuration.cpp:77
G::Str::tail
static std::string tail(const std::string &in, std::string::size_type pos, const std::string &default_=std::string())
Returns the last part of the string after the given position.
Definition: gstr.cpp:842
Main::Configuration::useSyslog
bool useSyslog() const
Returns true if generating syslog events.
Definition: configuration.cpp:55
Main::Configuration::forwardingOnStore
bool forwardingOnStore() const
Returns true if forwarding should occur as each message is stored, after it is acknowledged.
Definition: configuration.cpp:186
Main::Configuration::secureConnectionTimeout
unsigned int secureConnectionTimeout() const
Returns the timeout for establishing a secure connection.
Definition: configuration.cpp:329
Main::Configuration::verbose
bool verbose() const
Returns true if doing verbose logging.
Definition: configuration.cpp:45
Main::Configuration::serverTlsFile
std::string serverTlsFile() const
Returns the tls certificate file if the server should support tls.
Definition: configuration.cpp:304
Main::Configuration::debug
bool debug() const
Returns true if doing debug-level logging.
Definition: configuration.cpp:50
Main::Configuration::scannerConnectionTimeout
unsigned int scannerConnectionTimeout() const
Returns a timeout for connecting to the scanner process.
Definition: configuration.cpp:364
configuration.h
gstr.h
Main::Configuration::serverSecretsFile
std::string serverSecretsFile() const
Returns the server-side autentication secrets (password) file.
Definition: configuration.cpp:314
Main::Configuration::promptTimeout
unsigned int promptTimeout() const
Returns the timeout for getting a prompt from the SMTP server.
Definition: configuration.cpp:209
G::Str::head
static std::string head(const std::string &in, std::string::size_type pos, const std::string &default_=std::string())
Returns the first part of the string up to just before the given position.
Definition: gstr.cpp:834
commandline.h
gpopsecrets.h
Main::Configuration::nobody
std::string nobody() const
Returns the name of an unprivileged user.
Definition: configuration.cpp:339
Main::CommandLine
A class which deals with the command-line interface to the process, both input and output...
Definition: commandline.h:44
Main::Configuration::log
bool log() const
Returns true if doing logging.
Definition: configuration.cpp:36
Main::Configuration::connectionTimeout
unsigned int connectionTimeout() const
Returns the client-side connection timeout value.
Definition: configuration.cpp:324
gmessagestore.h
GSmtp::MessageStore::defaultDirectory
static G::Path defaultDirectory()
Returns a default spool directory, such as "/usr/local/var/spool/emailrelay".
Definition: gmessagestore_unix.cpp:30
Main::Configuration::fqdn
std::string fqdn(std::string default_=std::string()) const
Returns the fully-qualified-domain-name override.
Definition: configuration.cpp:334
Main::Configuration::pollingTimeout
unsigned int pollingTimeout() const
Returns the timeout for periodic polling.
Definition: configuration.cpp:175
Main::Configuration::logFile
std::string logFile() const
Returns the path of a stderr replacement for logging.
Definition: configuration.cpp:67
Main::Configuration::maxSize
unsigned int maxSize() const
Returns the maximum size of submitted messages, or zero.
Definition: configuration.cpp:354
Main::Configuration::clientFilter
std::string clientFilter() const
Returns the path to a client-side pre-processor.
Definition: configuration.cpp:269
Main::Configuration::pidFile
std::string pidFile() const
Returns the pid file's path.
Definition: configuration.cpp:254
Main::Configuration::useFilter
bool useFilter() const
Returns true if pre-processing.
Definition: configuration.cpp:259
Main::Configuration::Configuration
Configuration(const CommandLine &cl)
Constructor. The reference is kept.
Definition: configuration.cpp:31
Main::Configuration::icon
unsigned int icon() const
Returns the icon selector (win32).
Definition: configuration.cpp:274
Main::Configuration::withTerminate
bool withTerminate() const
Returns true if the admin interface should support the terminate command.
Definition: configuration.cpp:349
Main::Configuration::logTimestamp
bool logTimestamp() const
Returns true if logging output should be timestamped.
Definition: configuration.cpp:62
Main::Configuration::clientInterface
std::string clientInterface() const
Returns the sending interface.
Definition: configuration.cpp:98
Main::Configuration::popByName
bool popByName() const
Returns true if the pop spool directory is modified according to the client name. ...
Definition: configuration.cpp:224
Main::Configuration::port
unsigned int port() const
Returns the main listening port number.
Definition: configuration.cpp:72
Main::Configuration::forwardingOnDisconnect
bool forwardingOnDisconnect() const
Returns true if forwarding should occur when the submitter's network connection disconnects.
Definition: configuration.cpp:193
Main::Configuration::doForwardingOnStartup
bool doForwardingOnStartup() const
Returns true if running as a client.
Definition: configuration.cpp:155
gsmtp.h
Main::Configuration::adminPort
unsigned int adminPort() const
Returns the admin port number.
Definition: configuration.cpp:120
Main::Configuration::hidden
bool hidden() const
Returns true if the main window is hidden (win32).
Definition: configuration.cpp:279
Main::Configuration::tlsConfig
unsigned int tlsConfig() const
Returns TLS configuration flags.
Definition: configuration.cpp:299
Main::Configuration::scannerAddress
std::string scannerAddress() const
Returns the address of a scanner process.
Definition: configuration.cpp:359
Main::Configuration::clientSecretsFile
std::string clientSecretsFile() const
Returns the client-side autentication secrets (password) file.
Definition: configuration.cpp:284
Main::Configuration::usePidFile
bool usePidFile() const
Returns true if writing a pid file.
Definition: configuration.cpp:249
GPop::Secrets::defaultPath
static std::string defaultPath()
Returns the default path.
Definition: gpopsecrets_unix.cpp:26
G::Path
A Path object represents a file system path.
Definition: gpath.h:44
Main::Configuration::doPolling
bool doPolling() const
Returns true if doing poll-based forwarding.
Definition: configuration.cpp:170
Main::Configuration::doPop
bool doPop() const
Returns true if listening for pop connections.
Definition: configuration.cpp:219
Main::Configuration::scannerResponseTimeout
unsigned int scannerResponseTimeout() const
Returns a timeout for talking to the scanner process.
Definition: configuration.cpp:369
Main::Configuration::responseTimeout
unsigned int responseTimeout() const
Returns the client-side protocol timeout value.
Definition: configuration.cpp:319
gdebug.h
Main::Configuration::filterTimeout
unsigned int filterTimeout() const
Returns the timeout for executing an ansynchronous filter() or clientFilter() program.
Definition: configuration.cpp:379
Main::Configuration::clientTls
bool clientTls() const
Returns true if the client protocol should take account of the server's tls capability.
Definition: configuration.cpp:289
Main::Configuration::popSecretsFile
std::string popSecretsFile() const
Returns the pop-server autentication secrets (password) file.
Definition: configuration.cpp:309