PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
27 #ifndef PTLIB_IPACL_H
28 #define PTLIB_IPACL_H
29 
30 
31 #include <ptlib/sockets.h>
32 
33 
37 {
39 
40  public:
46  PIPSocket::Address addr,
48  PBoolean allow
49  );
51  const PString & description
52  );
53 
59  const PString & pstr
60  );
62  const char * cstr
63  );
64 
71  virtual Comparison Compare(
72  const PObject & obj
73  ) const;
74 
78  virtual void PrintOn(
79  ostream &strm
80  ) const;
81 
86  virtual void ReadFrom(
87  istream &strm
88  );
89 
96  PString AsString() const;
97 
103  PBoolean IsValid();
104 
124  PBoolean Parse(
125  const PString & description
126  );
127 
128 
135  PBoolean Match(
137  );
138 
141  const PString & GetDomain() const { return domain; }
142 
145  const PIPSocket::Address & GetAddress() const { return address; }
146 
149  const PIPSocket::Address & GetMask() const { return mask; }
150 
153  PBoolean IsAllowed() const { return allowed; }
154 
157  PBoolean IsHidden() const { return hidden; }
158 
159  protected:
165 };
166 
167 PSORTED_LIST(PIpAccessControlList_base, PIpAccessControlEntry);
168 
169 
183 class PIpAccessControlList : public PIpAccessControlList_base
184 {
185 
186  PCLASSINFO(PIpAccessControlList, PIpAccessControlList_base)
187 
188  public:
193  );
194 
210  const char * daemonName = NULL
211  );
212 
213 #ifdef P_CONFIG_FILE
214 
222  PBoolean Load(
223  PConfig & cfg
224  );
225 
235  PBoolean Load(
236  PConfig & cfg,
237  const PString & baseName
238  );
239 
243  void Save(
244  PConfig & cfg
245  );
246 
252  void Save(
253  PConfig & cfg,
254  const PString & baseName
255  );
256 
257 #endif // P_CONFIG_FILE
258 
266  PBoolean Add(
267  PIpAccessControlEntry * entry
268  );
269  PBoolean Add(
270  const PString & description
271  );
272  PBoolean Add(
273  PIPSocket::Address address,
274  PIPSocket::Address mask,
275  PBoolean allow
276  );
277 
286  const PString & description
287  );
289  PIPSocket::Address address,
290  PIPSocket::Address mask
291  );
292 
293 
301  const PString & description
302  );
303 
307  PIPSocket::Address address
308  ) const;
309 
323  PTCPSocket & socket
324  ) const;
326  PIPSocket::Address address
327  ) const;
328 
329 
333 
336  void SetDefaultAllowance(PBoolean defAllow) { defaultAllowance = defAllow; }
337 
338  private:
339  PBoolean InternalLoadHostsAccess(const PString & daemon, const char * file, PBoolean allow);
340  PBoolean InternalRemoveEntry(PIpAccessControlEntry & entry);
341 
342  protected:
344 };
345 
346 
347 #endif // PTLIB_IPACL_H
348 
349 
350 // End of File ///////////////////////////////////////////////////////////////
void SetDefaultAllowance(PBoolean defAllow)
Set the default state for allowed access if the list is empty.
Definition: ipacl.h:336
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:2164
PBoolean IsAllowed() const
Get the allowed flag of entry.
Definition: ipacl.h:153
PBoolean allowed
Definition: ipacl.h:163
PIPSocket::Address address
Definition: ipacl.h:161
virtual Comparison Compare(const PObject &obj) const
Compare the two objects and return their relative rank.
PIPSocket::Address mask
Definition: ipacl.h:162
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:62
Comparison
Result of the comparison operation performed by the Compare() function.
Definition: object.h:2251
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:145
PBoolean Remove(const PString &description)
Remove the specified entry into the list.
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:157
bool PBoolean
Definition: object.h:174
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:40
This class is a single IP access control specification.
Definition: ipacl.h:36
This class is a list of IP address mask specifications used to validate if an address may or may not ...
Definition: ipacl.h:183
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:149
A class describing an IP address.
Definition: ipsock.h:59
PString domain
Definition: ipacl.h:160
PBoolean defaultAllowance
Definition: ipacl.h:343
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:141
#define PSORTED_LIST(cls, T)
Declare a sorted list class.
Definition: lists.h:1116
Ultimate parent class for all objects in the class library.
Definition: object.h:2204
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:332
PBoolean hidden
Definition: ipacl.h:164