aboutsummaryrefslogtreecommitdiff
path: root/src/util/winproc.c
diff options
context:
space:
mode:
authorNils Durner <durner@gnunet.org>2009-06-10 22:24:54 +0000
committerNils Durner <durner@gnunet.org>2009-06-10 22:24:54 +0000
commit9cf5b99404c1f3694417b2e4900771398022fd23 (patch)
treee6e8f99d21a6ae94894c774b7505b95ae370ccff /src/util/winproc.c
parent812138f1d6cbd39d2ec623f2201bb034ab4ac3d2 (diff)
downloadgnunet-9cf5b99404c1f3694417b2e4900771398022fd23.tar.gz
gnunet-9cf5b99404c1f3694417b2e4900771398022fd23.zip
MinGW
Diffstat (limited to 'src/util/winproc.c')
-rw-r--r--src/util/winproc.c254
1 files changed, 254 insertions, 0 deletions
diff --git a/src/util/winproc.c b/src/util/winproc.c
new file mode 100644
index 000000000..469e1fb41
--- /dev/null
+++ b/src/util/winproc.c
@@ -0,0 +1,254 @@
1/*
2 This file is part of GNUnet.
3 (C) 2001, 2002, 2003, 2004, 2005, 2006 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file util/win/winproc.c
23 * @brief Functions for MS Windows
24 * @author Nils Durner
25 */
26
27#include "platform.h"
28#include "gnunet_common.h"
29
30#define DEBUG_WINPROC 0
31
32#ifdef MINGW
33
34static HINSTANCE hNTDLL, hIphlpapi, hAdvapi, hNetapi;
35
36TNtQuerySystemInformation GNNtQuerySystemInformation;
37TGetIfEntry GNGetIfEntry;
38TGetIpAddrTable GNGetIpAddrTable;
39TGetIfTable GNGetIfTable;
40TOpenSCManager GNOpenSCManager;
41TCreateService GNCreateService;
42TCloseServiceHandle GNCloseServiceHandle;
43TDeleteService GNDeleteService;
44TRegisterServiceCtrlHandler GNRegisterServiceCtrlHandler;
45TSetServiceStatus GNSetServiceStatus;
46TStartServiceCtrlDispatcher GNStartServiceCtrlDispatcher;
47TControlService GNControlService;
48TOpenService GNOpenService;
49TGetBestInterface GNGetBestInterface;
50TGetAdaptersInfo GGetAdaptersInfo;
51TNetUserAdd GNNetUserAdd;
52TNetUserSetInfo GNNetUserSetInfo;
53TLsaOpenPolicy GNLsaOpenPolicy;
54TLsaAddAccountRights GNLsaAddAccountRights;
55TLsaRemoveAccountRights GNLsaRemoveAccountRights;
56TLsaClose GNLsaClose;
57TLookupAccountName GNLookupAccountName;
58TGetFileSecurity GNGetFileSecurity;
59TInitializeSecurityDescriptor GNInitializeSecurityDescriptor;
60TGetSecurityDescriptorDacl GNGetSecurityDescriptorDacl;
61TGetAclInformation GNGetAclInformation;
62TInitializeAcl GNInitializeAcl;
63TGetAce GNGetAce;
64TEqualSid GNEqualSid;
65TAddAce GNAddAce;
66TAddAccessAllowedAce GNAddAccessAllowedAce;
67TSetNamedSecurityInfo GNSetNamedSecurityInfo;
68
69/**
70 * Log (panic) messages from PlibC
71 */
72void
73plibc_panic (int err, char *msg)
74{
75 GNUNET_log (((err ==
76 INT_MAX) ? GNUNET_ERROR_TYPE_DEBUG : GNUNET_ERROR_TYPE_ERROR),
77 "%s", msg);
78}
79
80/**
81 * @brief Initialize PlibC and set up Windows environment
82 * @param logging context, NULL means stderr
83 * @return Error code from winerror.h, ERROR_SUCCESS on success
84*/
85int
86InitWinEnv ()
87{
88 int ret;
89
90 plibc_initialized ();
91 plibc_set_panic_proc (plibc_panic);
92 ret = plibc_init ("GNU", PACKAGE);
93
94 /* don't load other DLLs twice */
95 if (hNTDLL)
96 return ret;
97
98 hNTDLL = LoadLibrary ("ntdll.dll");
99
100 /* Function to get CPU usage under Win NT */
101 if (hNTDLL)
102 {
103 GNNtQuerySystemInformation = (TNtQuerySystemInformation)
104 GetProcAddress (hNTDLL, "NtQuerySystemInformation");
105 }
106 else
107 {
108 GNNtQuerySystemInformation = NULL;
109 }
110
111 /* Functions to get information about a network adapter */
112 hIphlpapi = LoadLibrary ("iphlpapi.dll");
113 if (hIphlpapi)
114 {
115 GNGetIfEntry = (TGetIfEntry) GetProcAddress (hIphlpapi, "GetIfEntry");
116 GNGetIpAddrTable = (TGetIpAddrTable) GetProcAddress (hIphlpapi,
117 "GetIpAddrTable");
118 GNGetIfTable = (TGetIfTable) GetProcAddress (hIphlpapi, "GetIfTable");
119 GNGetBestInterface = (TGetBestInterface) GetProcAddress (hIphlpapi,
120 "GetBestInterface");
121 GGetAdaptersInfo = (TGetAdaptersInfo) GetProcAddress (hIphlpapi,
122 "GetAdaptersInfo");
123 }
124 else
125 {
126 GNGetIfEntry = NULL;
127 GNGetIpAddrTable = NULL;
128 GNGetIfTable = NULL;
129 GNGetBestInterface = NULL;
130 GGetAdaptersInfo = NULL;
131 }
132
133 /* Service & Account functions */
134 hAdvapi = LoadLibrary ("advapi32.dll");
135 if (hAdvapi)
136 {
137 GNOpenSCManager = (TOpenSCManager)
138 GetProcAddress (hAdvapi, "OpenSCManagerA");
139 GNCreateService = (TCreateService)
140 GetProcAddress (hAdvapi, "CreateServiceA");
141 GNCloseServiceHandle = (TCloseServiceHandle)
142 GetProcAddress (hAdvapi, "CloseServiceHandle");
143 GNDeleteService = (TDeleteService)
144 GetProcAddress (hAdvapi, "DeleteService");
145 GNRegisterServiceCtrlHandler = (TRegisterServiceCtrlHandler)
146 GetProcAddress (hAdvapi, "RegisterServiceCtrlHandlerA");
147 GNSetServiceStatus = (TSetServiceStatus)
148 GetProcAddress (hAdvapi, "SetServiceStatus");
149 GNStartServiceCtrlDispatcher = (TStartServiceCtrlDispatcher)
150 GetProcAddress (hAdvapi, "StartServiceCtrlDispatcherA");
151 GNControlService = (TControlService)
152 GetProcAddress (hAdvapi, "ControlService");
153 GNOpenService = (TOpenService) GetProcAddress (hAdvapi, "OpenServiceA");
154
155 GNLsaOpenPolicy = (TLsaOpenPolicy)
156 GetProcAddress (hAdvapi, "LsaOpenPolicy");
157 GNLsaAddAccountRights = (TLsaAddAccountRights)
158 GetProcAddress (hAdvapi, "LsaAddAccountRights");
159 GNLsaRemoveAccountRights = (TLsaRemoveAccountRights)
160 GetProcAddress (hAdvapi, "LsaRemoveAccountRights");
161 GNLsaClose = (TLsaClose) GetProcAddress (hAdvapi, "LsaClose");
162 GNLookupAccountName = (TLookupAccountName)
163 GetProcAddress (hAdvapi, "LookupAccountNameA");
164
165 GNGetFileSecurity = (TGetFileSecurity)
166 GetProcAddress (hAdvapi, "GetFileSecurityA");
167 GNInitializeSecurityDescriptor = (TInitializeSecurityDescriptor)
168 GetProcAddress (hAdvapi, "InitializeSecurityDescriptor");
169 GNGetSecurityDescriptorDacl = (TGetSecurityDescriptorDacl)
170 GetProcAddress (hAdvapi, "GetSecurityDescriptorDacl");
171 GNGetAclInformation = (TGetAclInformation)
172 GetProcAddress (hAdvapi, "GetAclInformation");
173 GNInitializeAcl = (TInitializeAcl)
174 GetProcAddress (hAdvapi, "InitializeAcl");
175 GNGetAce = (TGetAce) GetProcAddress (hAdvapi, "GetAce");
176 GNEqualSid = (TEqualSid) GetProcAddress (hAdvapi, "EqualSid");
177 GNAddAce = (TAddAce) GetProcAddress (hAdvapi, "AddAce");
178 GNAddAccessAllowedAce = (TAddAccessAllowedAce)
179 GetProcAddress (hAdvapi, "AddAccessAllowedAce");
180 GNSetNamedSecurityInfo = (TSetNamedSecurityInfo)
181 GetProcAddress (hAdvapi, "SetNamedSecurityInfoA");
182 }
183 else
184 {
185 GNOpenSCManager = NULL;
186 GNCreateService = NULL;
187 GNCloseServiceHandle = NULL;
188 GNDeleteService = NULL;
189 GNRegisterServiceCtrlHandler = NULL;
190 GNSetServiceStatus = NULL;
191 GNStartServiceCtrlDispatcher = NULL;
192 GNControlService = NULL;
193 GNOpenService = NULL;
194
195 GNLsaOpenPolicy = NULL;
196 GNLsaAddAccountRights = NULL;
197 GNLsaRemoveAccountRights = NULL;
198 GNLsaClose = NULL;
199 GNLookupAccountName = NULL;
200
201 GNGetFileSecurity = NULL;
202 GNInitializeSecurityDescriptor = NULL;
203 GNGetSecurityDescriptorDacl = NULL;
204 GNGetAclInformation = NULL;
205 GNInitializeAcl = NULL;
206 GNGetAce = NULL;
207 GNEqualSid = NULL;
208 GNAddAce = NULL;
209 GNAddAccessAllowedAce = NULL;
210 GNSetNamedSecurityInfo = NULL;
211 }
212
213 /* Account function */
214 hNetapi = LoadLibrary ("netapi32.dll");
215 if (hNetapi)
216 {
217 GNNetUserAdd = (TNetUserAdd) GetProcAddress (hNetapi, "NetUserAdd");
218 GNNetUserSetInfo = (TNetUserSetInfo)
219 GetProcAddress (hNetapi, "NetUserSetInfo");
220 }
221 else
222 {
223 GNNetUserAdd = NULL;
224 GNNetUserSetInfo = NULL;
225 }
226
227 return ret;
228}
229
230/**
231 * Clean up Windows environment
232 */
233void
234ShutdownWinEnv ()
235{
236 plibc_shutdown ();
237
238 FreeLibrary (hNTDLL);
239 FreeLibrary (hIphlpapi);
240 FreeLibrary (hAdvapi);
241 FreeLibrary (hNetapi);
242
243 CoUninitialize ();
244}
245
246#endif /* MINGW */
247
248#if !HAVE_ATOLL
249long long
250atoll (const char *nptr)
251{
252 return atol (nptr);
253}
254#endif