PTLib  Version 2.10.10
ipacl.h
Go to the documentation of this file.
1 /*
2  * ipacl.h
3  *
4  * IP Access Control Lists
5  *
6  * Portable Windows Library
7  *
8  * Copyright (c) 1998-2002 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Contributor(s): ______________________________________.
25  *
26  * $Revision: 24177 $
27  * $Author: rjongbloed $
28  * $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
29  */
30 
31 #ifndef PTLIB_IPACL_H
32 #define PTLIB_IPACL_H
33 
34 
35 #include <ptlib/sockets.h>
36 
37 
41 {
43 
44  public:
50  PIPSocket::Address addr,
52  PBoolean allow
53  );
55  const PString & description
56  );
57 
63  const PString & pstr
64  );
66  const char * cstr
67  );
68 
75  virtual Comparison Compare(
76  const PObject & obj
77  ) const;
78 
82  virtual void PrintOn(
83  ostream &strm
84  ) const;
85 
90  virtual void ReadFrom(
91  istream &strm
92  );
93 
100  PString AsString() const;
101 
107  PBoolean IsValid();
108 
128  PBoolean Parse(
129  const PString & description
130  );
131 
132 
139  PBoolean Match(
141  );
142 
145  const PString & GetDomain() const { return domain; }
146 
149  const PIPSocket::Address & GetAddress() const { return address; }
150 
153  const PIPSocket::Address & GetMask() const { return mask; }
154 
157  PBoolean IsAllowed() const { return allowed; }
158 
161  PBoolean IsHidden() const { return hidden; }
162 
163  protected:
169 };
170 
171 PSORTED_LIST(PIpAccessControlList_base, PIpAccessControlEntry);
172 
173 
187 class PIpAccessControlList : public PIpAccessControlList_base
188 {
189 
190  PCLASSINFO(PIpAccessControlList, PIpAccessControlList_base)
191 
192  public:
197  );
198 
214  const char * daemonName = NULL
215  );
216 
217 #ifdef P_CONFIG_FILE
218 
226  PBoolean Load(
227  PConfig & cfg
228  );
229 
239  PBoolean Load(
240  PConfig & cfg,
241  const PString & baseName
242  );
243 
247  void Save(
248  PConfig & cfg
249  );
250 
256  void Save(
257  PConfig & cfg,
258  const PString & baseName
259  );
260 
261 #endif // P_CONFIG_FILE
262 
270  PBoolean Add(
271  PIpAccessControlEntry * entry
272  );
273  PBoolean Add(
274  const PString & description
275  );
276  PBoolean Add(
277  PIPSocket::Address address,
278  PIPSocket::Address mask,
279  PBoolean allow
280  );
281 
290  const PString & description
291  );
293  PIPSocket::Address address,
294  PIPSocket::Address mask
295  );
296 
297 
305  const PString & description
306  );
307 
311  PIPSocket::Address address
312  ) const;
313 
327  PTCPSocket & socket
328  ) const;
330  PIPSocket::Address address
331  ) const;
332 
333 
337 
340  void SetDefaultAllowance(PBoolean defAllow) { defaultAllowance = defAllow; }
341 
342  private:
343  PBoolean InternalLoadHostsAccess(const PString & daemon, const char * file, PBoolean allow);
344  PBoolean InternalRemoveEntry(PIpAccessControlEntry & entry);
345 
346  protected:
348 };
349 
350 
351 #endif // PTLIB_IPACL_H
352 
353 
354 // End of File ///////////////////////////////////////////////////////////////
void SetDefaultAllowance(PBoolean defAllow)
Set the default state for allowed access if the list is empty.
Definition: ipacl.h:340
virtual void ReadFrom(istream &strm)
Input the contents of the object from the stream.
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:1049
PBoolean IsAllowed() const
Get the allowed flag of entry.
Definition: ipacl.h:157
PBoolean allowed
Definition: ipacl.h:167
PIPSocket::Address address
Definition: ipacl.h:165
virtual Comparison Compare(const PObject &obj) const
Compare the two objects and return their relative rank.
PIPSocket::Address mask
Definition: ipacl.h:166
PBoolean IsAllowed(PTCPSocket &socket) const
Test the address/connection for if it is allowed within this access control list. ...
A class representing a configuration for the application.
Definition: config.h:67
Comparison
Result of the comparison operation performed by the Compare() function.
Definition: object.h:1184
PBoolean Parse(const PString &description)
Parse the description string into this IP access control specification.
PIpAccessControlEntry * Find(PIPSocket::Address address) const
Find the PIpAccessControl specification for the address.
PBoolean LoadHostsAccess(const char *daemonName=NULL)
Load the system wide files commonly use under Linux (hosts.allow and hosts.deny file) for IP access...
virtual void PrintOn(ostream &strm) const
Output the contents of the object to the stream.
virtual PIpAccessControlEntry * CreateControlEntry(const PString &description)
Create a new PIpAccessControl specification entry object.
const PIPSocket::Address & GetAddress() const
Get the address part of entry.
Definition: ipacl.h:149
PBoolean Remove(const PString &description)
Remove the specified entry into the list.
BOOL PBoolean
Definition: object.h:102
PBoolean Add(PIpAccessControlEntry *entry)
Add the specified entry into the list.
PIpAccessControlList(PBoolean defaultAllowance=true)
Create a new, empty, access control list.
void Save(PConfig &cfg)
Save entries in the list to the configuration file specified.
PBoolean IsHidden() const
Get the hidden flag of entry.
Definition: ipacl.h:161
PString AsString() const
Convert the specification to a string, that can be processed by the Parse() function.
The character string class.
Definition: pstring.h:108
A socket that uses the TCP transport on the Internet Protocol.
Definition: tcpsock.h:44
This class is a single IP access control specification.
Definition: ipacl.h:40
This class is a list of IP address mask specifications used to validate if an address may or may not ...
Definition: ipacl.h:187
PIpAccessControlEntry(PIPSocket::Address addr, PIPSocket::Address msk, PBoolean allow)
Create a new IP access control specification.
const PIPSocket::Address & GetMask() const
Get the mask part of entry.
Definition: ipacl.h:153
A class describing an IP address.
Definition: ipsock.h:75
PString domain
Definition: ipacl.h:164
PBoolean defaultAllowance
Definition: ipacl.h:347
PBoolean Match(PIPSocket::Address &address)
Check to see if the specified IP address match any of the conditions specifed in the Parse() function...
PBoolean IsValid()
Check the internal fields of the specification for validity.
const PString & GetDomain() const
Get the domain part of entry.
Definition: ipacl.h:145
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
PBoolean Load(PConfig &cfg)
Load entries in the list from the configuration file specified.
PIpAccessControlEntry & operator=(const PString &pstr)
Set a new IP access control specification.
PBoolean GetDefaultAllowance() const
Get the default state for allowed access if the list is empty.
Definition: ipacl.h:336
PBoolean hidden
Definition: ipacl.h:168
PSORTED_LIST(PIpAccessControlList_base, PIpAccessControlEntry)