Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
SystemFirewall.h
1/*
2* Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3*/
4#ifndef _Stroika_Foundation_IO_Network_SystemFirewall_h_
5#define _Stroika_Foundation_IO_Network_SystemFirewall_h_ 1
6
7#include "Stroika/Frameworks/StroikaPreComp.h"
8
9#include <compare>
10#include <filesystem>
11
12#if qStroika_Foundation_Common_Platform_Windows
13#include <netfw.h>
14#endif
15
18
19/**
20*/
21
22namespace Stroika::Foundation::IO::Network::SystemFirewall {
23
24 using namespace Stroika::Foundation;
25
27
28 /**
29 * \note <a href="Design-Overview.md#Comparisons">Comparisons</a>:
30 * o static_assert (totally_ordered<Rule>);
31 */
32 struct Rule {
33 String fName;
34 String fDescription;
35 String fGroup;
36 filesystem::path fApplication;
37#if qStroika_Foundation_Common_Platform_Windows
38 NET_FW_PROFILE_TYPE2 fProfileMask;
39 NET_FW_RULE_DIRECTION fDirection;
40 NET_FW_IP_PROTOCOL_ fProtocol;
41#endif
42 String fLocalPorts;
43 String fRemotePorts;
44#if qStroika_Foundation_Common_Platform_Windows
45 NET_FW_ACTION fAction;
46#endif
47 bool fEnabled;
48
49 public:
50 /**
51 * @see Characters::ToString ()
52 */
53 nonvirtual String ToString () const;
54
55 public:
56 /**
57 */
58 nonvirtual strong_ordering operator<=> (const Rule&) const = default;
59 };
60 static_assert (totally_ordered<Rule>);
61
62 /**
63 * Configure the OS/system firewall on the system where the application is being run.
64 *
65 * Many apps must augment the system firewall in order to operate properly. Often (e.g. on windows)
66 * this requires admin access (running as root or administrator). These functions will often fail
67 * (exceptions) due to inadequate access permissions.
68 *
69 * \note - this class contains no data, and is not copyable, and is just a proxy to talk to the OS
70 * storage of firewall rules.
71 */
72 class Manager {
73 public:
74 Manager () = default;
75
76 public:
77 /**
78 * Return true if created, and false if already there and no change needed. Throw if
79 * any errors (besides no work todo), such as not running 'access denined'.
80 */
81 nonvirtual bool Register (const Rule& rule);
82
83 public:
84 /**
85 */
86 nonvirtual optional<Rule> Lookup (const String& ruleName) const;
87
88 public:
89 /**
90 */
91 nonvirtual Traversal::Iterable<Rule> LookupByGroup (const String& groupName) const;
92
93 public:
94 /**
95 */
96 nonvirtual Traversal::Iterable<Rule> LookupAll () const;
97 };
98
99}
100
101/*
102********************************************************************************
103***************************** Implementation Details ***************************
104********************************************************************************
105*/
106#include "SystemFirewall.inl"
107
108#endif /*_Stroika_Foundation_IO_Network_SystemFirewall_h_*/
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
Iterable<T> is a base class for containers which easily produce an Iterator<T> to traverse them.
Definition Iterable.h:237