20 using namespace portable;
23 astring
netsh_app() {
return env_string(
"WINDIR") +
"/System32/netsh.exe"; }
26 const astring &exception_name,
const astring &hole_description)
30 known_operating_systems kind = determine_OS();
31 if ( (kind == WIN_SRV2K8) || (kind == WIN_VISTA) ) {
34 cmdline = a_sprintf(
"-c advfirewall firewall add rule name=\"%s\" dir=in "
35 "action=allow program=\"%s\" enable=yes profile=any "
36 "description=\"%s\"", exception_name.s(), program_name.s(),
37 hole_description.s());
41 cmdline = a_sprintf(
"-c firewall add allowedprogram program=\"%s\" "
42 "name=\"%s\" mode=enable scope=all profile=all", program_name.s(),
47 basis::u_int to_return = launch_process::run(
netsh_app(), cmdline,
48 portable::AWAIT_APP_EXIT | portable::HIDE_APP_WINDOW
49 | portable::SHELL_EXECUTE, kid_id);
52 if (!program_name || !exception_name || !hole_description) {}
58 const astring &exception_name)
63 known_operating_systems kind = determine_OS();
64 if ( (kind == WIN_SRV2K8) || (kind == WIN_VISTA) ) {
67 cmdline = a_sprintf(
"-c advfirewall firewall delete rule name=\"%s\" ",
72 cmdline = a_sprintf(
"-c firewall delete allowedprogram program=\"%s\" "
73 "profile=all", program_name.s());
77 basis::u_int to_return = launch_process::run(
netsh_app(), cmdline,
78 portable::AWAIT_APP_EXIT | portable::HIDE_APP_WINDOW
79 | portable::SHELL_EXECUTE, kid_id);
82 if (!program_name || !exception_name) {}
88 const astring &exception_name,
const astring &hole_description,
89 const astring &protocol)
94 known_operating_systems kind = determine_OS();
95 if ( (kind == WIN_SRV2K8) || (kind == WIN_VISTA) ) {
98 cmdline = a_sprintf(
"-c advfirewall firewall add rule name=\"%s\" dir=in "
99 "action=allow protocol=\"%s\" enable=yes profile=any "
100 "description=\"%s\" localport=%d",
101 exception_name.s(), protocol.s(), hole_description.s(), port_number);
105 cmdline = a_sprintf(
"-c firewall add portopening port=%d "
106 "name=\"%s\" protocol=%s mode=enable scope=all profile=all",
107 port_number, exception_name.s(), protocol.s());
111 basis::u_int to_return = launch_process::run(
netsh_app(), cmdline,
112 portable::AWAIT_APP_EXIT | portable::HIDE_APP_WINDOW
113 | portable::SHELL_EXECUTE, kid_id);
116 if (!port_number || !exception_name || !protocol || !hole_description) {}
122 const astring &exception_name,
const astring &protocol)
127 known_operating_systems kind = determine_OS();
128 if ( (kind == WIN_SRV2K8) || (kind == WIN_VISTA) ) {
131 cmdline = a_sprintf(
"-c advfirewall firewall delete rule name=\"%s\" "
132 "localport=%d protocol=%s", exception_name.s(),
133 port_number, protocol.s());
137 cmdline = a_sprintf(
"-c firewall delete portopening protocol=%s "
138 "port=%d profile=all", protocol.s(), port_number);
142 basis::u_int to_return = launch_process::run(
netsh_app(), cmdline,
143 portable::AWAIT_APP_EXIT | portable::HIDE_APP_WINDOW
144 | portable::SHELL_EXECUTE, kid_id);
147 if (!port_number || !exception_name || !protocol) {}
static int remove_firewall_hole(const astring &program_name, const astring &exception_name)
static int poke_firewall_hole(const astring &program_name, const astring &exception_name, const astring &hole_description)