1 /* 2 * Copyright 2016 Alistair Leslie-Hughes 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * This library 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 GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 17 */ 18 #define COBJMACROS 19 #include <stdio.h> 20 21 #include "windows.h" 22 #include "ole2.h" 23 #include "oleauto.h" 24 #include "olectl.h" 25 #include "dispex.h" 26 27 #include "wine/test.h" 28 29 #include "netfw.h" 30 31 static void test_policy2_rules(INetFwPolicy2 *policy2) 32 { 33 HRESULT hr; 34 INetFwRules *rules, *rules2; 35 INetFwServiceRestriction *restriction; 36 37 hr = INetFwPolicy2_QueryInterface(policy2, &IID_INetFwRules, (void**)&rules); 38 ok(hr == E_NOINTERFACE, "got 0x%08x\n", hr); 39 40 hr = INetFwPolicy2_get_Rules(policy2, &rules); 41 ok(hr == S_OK, "got %08x\n", hr); 42 43 hr = INetFwPolicy2_get_Rules(policy2, &rules2); 44 ok(hr == S_OK, "got %08x\n", hr); 45 ok(rules == rules2, "Different pointers\n"); 46 47 hr = INetFwPolicy2_get_ServiceRestriction(policy2, &restriction); 48 todo_wine ok(hr == S_OK, "got %08x\n", hr); 49 if(hr == S_OK) 50 { 51 INetFwRules *rules3; 52 53 hr = INetFwServiceRestriction_get_Rules(restriction, &rules3); 54 ok(hr == S_OK, "got %08x\n", hr); 55 ok(rules != rules3, "same pointers\n"); 56 57 if(rules3) 58 INetFwRules_Release(rules3); 59 INetFwServiceRestriction_Release(restriction); 60 } 61 62 INetFwRules_Release(rules); 63 INetFwRules_Release(rules2); 64 } 65 66 static void test_interfaces(void) 67 { 68 INetFwMgr *manager; 69 INetFwPolicy *policy; 70 INetFwPolicy2 *policy2; 71 HRESULT hr; 72 73 hr = CoCreateInstance(&CLSID_NetFwMgr, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, 74 &IID_INetFwMgr, (void**)&manager); 75 ok(hr == S_OK, "NetFwMgr create failed: %08x\n", hr); 76 77 hr = INetFwMgr_QueryInterface(manager, &IID_INetFwPolicy, (void**)&policy); 78 ok(hr == E_NOINTERFACE, "got 0x%08x\n", hr); 79 80 hr = INetFwMgr_QueryInterface(manager, &IID_INetFwPolicy2, (void**)&policy2); 81 ok(hr == E_NOINTERFACE, "got 0x%08x\n", hr); 82 83 hr = INetFwMgr_get_LocalPolicy(manager, &policy); 84 ok(hr == S_OK, "got 0x%08x\n", hr); 85 86 hr = INetFwPolicy_QueryInterface(policy, &IID_INetFwPolicy2, (void**)&policy2); 87 ok(hr == E_NOINTERFACE, "got 0x%08x\n", hr); 88 89 INetFwPolicy_Release(policy); 90 91 hr = CoCreateInstance(&CLSID_NetFwPolicy2, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, 92 &IID_INetFwPolicy2, (void**)&policy2); 93 if(hr == S_OK) 94 { 95 test_policy2_rules(policy2); 96 97 INetFwPolicy2_Release(policy2); 98 } 99 else 100 win_skip("NetFwPolicy2 object is not supported: %08x\n", hr); 101 102 INetFwMgr_Release(manager); 103 } 104 105 static void test_NetFwAuthorizedApplication(void) 106 { 107 INetFwAuthorizedApplication *app; 108 HRESULT hr; 109 110 hr = CoCreateInstance(&CLSID_NetFwAuthorizedApplication, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, 111 &IID_INetFwAuthorizedApplication, (void**)&app); 112 ok(hr == S_OK, "got: %08x\n", hr); 113 if(hr == S_OK) 114 { 115 BSTR image = SysAllocStringLen( NULL, MAX_PATH ); 116 static WCHAR empty[] = {0}; 117 BSTR bstr; 118 119 if (!GetModuleFileNameW( NULL, image, MAX_PATH )) 120 { 121 ok(0, "Failed to get filename\n"); 122 SysFreeString( image ); 123 return; 124 } 125 126 hr = INetFwAuthorizedApplication_get_ProcessImageFileName(app, NULL); 127 ok(hr == E_POINTER, "got: %08x\n", hr); 128 129 hr = INetFwAuthorizedApplication_get_ProcessImageFileName(app, &bstr); 130 ok(hr == S_OK || hr == HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY), "got: %08x\n", hr); 131 ok(!bstr, "got: %s\n", wine_dbgstr_w(bstr)); 132 133 hr = INetFwAuthorizedApplication_put_ProcessImageFileName(app, NULL); 134 ok(hr == E_INVALIDARG || hr == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "got: %08x\n", hr); 135 136 hr = INetFwAuthorizedApplication_put_ProcessImageFileName(app, empty); 137 ok(hr == E_INVALIDARG || hr == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "got: %08x\n", hr); 138 139 hr = INetFwAuthorizedApplication_put_ProcessImageFileName(app, image); 140 ok(hr == S_OK, "got: %08x\n", hr); 141 142 hr = INetFwAuthorizedApplication_get_ProcessImageFileName(app, &bstr); 143 ok(hr == S_OK, "got: %08x\n", hr); 144 ok(!lstrcmpiW(bstr,image), "got: %s\n", wine_dbgstr_w(bstr)); 145 SysFreeString( bstr ); 146 147 SysFreeString( image ); 148 INetFwAuthorizedApplication_Release(app); 149 } 150 } 151 152 START_TEST(policy) 153 { 154 INetFwMgr *manager; 155 HRESULT hr; 156 157 CoInitialize(NULL); 158 159 hr = CoCreateInstance(&CLSID_NetFwMgr, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, 160 &IID_INetFwMgr, (void**)&manager); 161 if(FAILED(hr)) 162 { 163 win_skip("NetFwMgr object is not supported: %08x\n", hr); 164 CoUninitialize(); 165 return; 166 } 167 168 INetFwMgr_Release(manager); 169 170 test_interfaces(); 171 test_NetFwAuthorizedApplication(); 172 173 CoUninitialize(); 174 } 175