Mercurial > emacs
comparison src/w32.c @ 48375:4d7b83cc03aa
Added a partial implementation of play-sound-internal for Windows. Fixed the following entry in etc/PROBLEMS: Emacs built on Windows 9x/ME crashes at startup on Windows XP, or Emacs built on XP crashes at startup on Windows 9x/ME.
author | Ben Key <bkey1@tampabay.rr.com> |
---|---|
date | Sun, 17 Nov 2002 22:35:26 +0000 |
parents | 40db0673e6f0 |
children | 538af265a4a7 |
comparison
equal
deleted
inserted
replaced
48374:a6f9803f174f | 48375:4d7b83cc03aa |
---|---|
103 extern Lisp_Object Vw32_generate_fake_inodes; | 103 extern Lisp_Object Vw32_generate_fake_inodes; |
104 extern Lisp_Object Vw32_get_true_file_attributes; | 104 extern Lisp_Object Vw32_get_true_file_attributes; |
105 extern Lisp_Object Vw32_num_mouse_buttons; | 105 extern Lisp_Object Vw32_num_mouse_buttons; |
106 | 106 |
107 | 107 |
108 /* | |
109 BEGIN: Wrapper functions around OpenProcessToken | |
110 and other functions in advapi32.dll that are only | |
111 supported in Windows NT / 2k / XP | |
112 */ | |
113 /* ** Function pointer typedefs ** */ | |
114 typedef BOOL (WINAPI * OpenProcessToken_Proc) ( | |
115 HANDLE ProcessHandle, | |
116 DWORD DesiredAccess, | |
117 PHANDLE TokenHandle); | |
118 typedef BOOL (WINAPI * GetTokenInformation_Proc) ( | |
119 HANDLE TokenHandle, | |
120 TOKEN_INFORMATION_CLASS TokenInformationClass, | |
121 LPVOID TokenInformation, | |
122 DWORD TokenInformationLength, | |
123 PDWORD ReturnLength); | |
124 #ifdef _UNICODE | |
125 const char * const LookupAccountSid_Name = "LookupAccountSidW"; | |
126 #else | |
127 const char * const LookupAccountSid_Name = "LookupAccountSidA"; | |
128 #endif | |
129 typedef BOOL (WINAPI * LookupAccountSid_Proc) ( | |
130 LPCTSTR lpSystemName, | |
131 PSID Sid, | |
132 LPTSTR Name, | |
133 LPDWORD cbName, | |
134 LPTSTR DomainName, | |
135 LPDWORD cbDomainName, | |
136 PSID_NAME_USE peUse); | |
137 typedef PSID_IDENTIFIER_AUTHORITY (WINAPI * GetSidIdentifierAuthority_Proc) ( | |
138 PSID pSid); | |
139 | |
140 /* ** A utility function ** */ | |
141 static BOOL is_windows_9x () | |
142 { | |
143 BOOL b_ret=0; | |
144 OSVERSIONINFO os_ver; | |
145 ZeroMemory(&os_ver, sizeof(OSVERSIONINFO)); | |
146 os_ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); | |
147 if (GetVersionEx (&os_ver)) | |
148 { | |
149 b_ret = (os_ver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS); | |
150 } | |
151 return b_ret; | |
152 } | |
153 | |
154 /* ** The wrapper functions ** */ | |
155 | |
156 BOOL WINAPI open_process_token ( | |
157 HANDLE ProcessHandle, | |
158 DWORD DesiredAccess, | |
159 PHANDLE TokenHandle) | |
160 { | |
161 OpenProcessToken_Proc pfn_Open_Process_Token = NULL; | |
162 HMODULE hm_advapi32 = NULL; | |
163 if (is_windows_9x () == TRUE) | |
164 { | |
165 return FALSE; | |
166 } | |
167 hm_advapi32 = LoadLibrary ("Advapi32.dll"); | |
168 pfn_Open_Process_Token = | |
169 (OpenProcessToken_Proc) GetProcAddress (hm_advapi32, "OpenProcessToken"); | |
170 if (pfn_Open_Process_Token == NULL) | |
171 { | |
172 return FALSE; | |
173 } | |
174 return ( | |
175 pfn_Open_Process_Token ( | |
176 ProcessHandle, | |
177 DesiredAccess, | |
178 TokenHandle) | |
179 ); | |
180 } | |
181 | |
182 BOOL WINAPI get_token_information ( | |
183 HANDLE TokenHandle, | |
184 TOKEN_INFORMATION_CLASS TokenInformationClass, | |
185 LPVOID TokenInformation, | |
186 DWORD TokenInformationLength, | |
187 PDWORD ReturnLength) | |
188 { | |
189 GetTokenInformation_Proc pfn_Get_Token_Information = NULL; | |
190 HMODULE hm_advapi32 = NULL; | |
191 if (is_windows_9x () == TRUE) | |
192 { | |
193 return FALSE; | |
194 } | |
195 hm_advapi32 = LoadLibrary ("Advapi32.dll"); | |
196 pfn_Get_Token_Information = | |
197 (GetTokenInformation_Proc) GetProcAddress (hm_advapi32, "GetTokenInformation"); | |
198 if (pfn_Get_Token_Information == NULL) | |
199 { | |
200 return FALSE; | |
201 } | |
202 return ( | |
203 pfn_Get_Token_Information ( | |
204 TokenHandle, | |
205 TokenInformationClass, | |
206 TokenInformation, | |
207 TokenInformationLength, | |
208 ReturnLength) | |
209 ); | |
210 } | |
211 | |
212 BOOL WINAPI lookup_account_sid ( | |
213 LPCTSTR lpSystemName, | |
214 PSID Sid, | |
215 LPTSTR Name, | |
216 LPDWORD cbName, | |
217 LPTSTR DomainName, | |
218 LPDWORD cbDomainName, | |
219 PSID_NAME_USE peUse) | |
220 { | |
221 LookupAccountSid_Proc pfn_Lookup_Account_Sid = NULL; | |
222 HMODULE hm_advapi32 = NULL; | |
223 if (is_windows_9x () == TRUE) | |
224 { | |
225 return FALSE; | |
226 } | |
227 hm_advapi32 = LoadLibrary ("Advapi32.dll"); | |
228 pfn_Lookup_Account_Sid = | |
229 (LookupAccountSid_Proc) GetProcAddress (hm_advapi32, LookupAccountSid_Name); | |
230 if (pfn_Lookup_Account_Sid == NULL) | |
231 { | |
232 return FALSE; | |
233 } | |
234 return ( | |
235 pfn_Lookup_Account_Sid ( | |
236 lpSystemName, | |
237 Sid, | |
238 Name, | |
239 cbName, | |
240 DomainName, | |
241 cbDomainName, | |
242 peUse) | |
243 ); | |
244 } | |
245 | |
246 PSID_IDENTIFIER_AUTHORITY WINAPI get_sid_identifier_authority ( | |
247 PSID pSid) | |
248 { | |
249 GetSidIdentifierAuthority_Proc pfn_Get_Sid_Identifier_Authority = NULL; | |
250 HMODULE hm_advapi32 = NULL; | |
251 if (is_windows_9x () == TRUE) | |
252 { | |
253 return NULL; | |
254 } | |
255 hm_advapi32 = LoadLibrary ("Advapi32.dll"); | |
256 pfn_Get_Sid_Identifier_Authority = | |
257 (GetSidIdentifierAuthority_Proc) GetProcAddress ( | |
258 hm_advapi32, "GetSidIdentifierAuthority"); | |
259 if (pfn_Get_Sid_Identifier_Authority == NULL) | |
260 { | |
261 return NULL; | |
262 } | |
263 return (pfn_Get_Sid_Identifier_Authority (pSid)); | |
264 } | |
265 | |
266 /* | |
267 END: Wrapper functions around OpenProcessToken | |
268 and other functions in advapi32.dll that are only | |
269 supported in Windows NT / 2k / XP | |
270 */ | |
271 | |
272 | |
108 /* Equivalent of strerror for W32 error codes. */ | 273 /* Equivalent of strerror for W32 error codes. */ |
109 char * | 274 char * |
110 w32_strerror (int error_no) | 275 w32_strerror (int error_no) |
111 { | 276 { |
112 static char buf[500]; | 277 static char buf[500]; |
252 char user_sid[256], name[256], domain[256]; | 417 char user_sid[256], name[256], domain[256]; |
253 DWORD length = sizeof (name), dlength = sizeof (domain), trash; | 418 DWORD length = sizeof (name), dlength = sizeof (domain), trash; |
254 HANDLE token = NULL; | 419 HANDLE token = NULL; |
255 SID_NAME_USE user_type; | 420 SID_NAME_USE user_type; |
256 | 421 |
257 if (OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &token) | 422 if ( |
258 && GetTokenInformation (token, TokenUser, | 423 open_process_token (GetCurrentProcess (), TOKEN_QUERY, &token) |
424 && get_token_information ( | |
425 token, TokenUser, | |
259 (PVOID) user_sid, sizeof (user_sid), &trash) | 426 (PVOID) user_sid, sizeof (user_sid), &trash) |
260 && LookupAccountSid (NULL, *((PSID *) user_sid), name, &length, | 427 && lookup_account_sid ( |
261 domain, &dlength, &user_type)) | 428 NULL, *((PSID *) user_sid), name, &length, |
429 domain, &dlength, &user_type) | |
430 ) | |
262 { | 431 { |
263 strcpy (the_passwd.pw_name, name); | 432 strcpy (the_passwd.pw_name, name); |
264 /* Determine a reasonable uid value. */ | 433 /* Determine a reasonable uid value. */ |
265 if (stricmp ("administrator", name) == 0) | 434 if (stricmp ("administrator", name) == 0) |
266 { | 435 { |
269 } | 438 } |
270 else | 439 else |
271 { | 440 { |
272 SID_IDENTIFIER_AUTHORITY * pSIA; | 441 SID_IDENTIFIER_AUTHORITY * pSIA; |
273 | 442 |
274 pSIA = GetSidIdentifierAuthority (*((PSID *) user_sid)); | 443 pSIA = get_sid_identifier_authority (*((PSID *) user_sid)); |
275 /* I believe the relative portion is the last 4 bytes (of 6) | 444 /* I believe the relative portion is the last 4 bytes (of 6) |
276 with msb first. */ | 445 with msb first. */ |
277 the_passwd.pw_uid = ((pSIA->Value[2] << 24) + | 446 the_passwd.pw_uid = ((pSIA->Value[2] << 24) + |
278 (pSIA->Value[3] << 16) + | 447 (pSIA->Value[3] << 16) + |
279 (pSIA->Value[4] << 8) + | 448 (pSIA->Value[4] << 8) + |
280 (pSIA->Value[5] << 0)); | 449 (pSIA->Value[5] << 0)); |
281 /* restrict to conventional uid range for normal users */ | 450 /* restrict to conventional uid range for normal users */ |
282 the_passwd.pw_uid = the_passwd.pw_uid % 60001; | 451 the_passwd.pw_uid = the_passwd.pw_uid % 60001; |
283 | 452 |
284 /* Get group id */ | 453 /* Get group id */ |
285 if (GetTokenInformation (token, TokenPrimaryGroup, | 454 if (get_token_information (token, TokenPrimaryGroup, |
286 (PVOID) user_sid, sizeof (user_sid), &trash)) | 455 (PVOID) user_sid, sizeof (user_sid), &trash)) |
287 { | 456 { |
288 SID_IDENTIFIER_AUTHORITY * pSIA; | 457 SID_IDENTIFIER_AUTHORITY * pSIA; |
289 | 458 |
290 pSIA = GetSidIdentifierAuthority (*((PSID *) user_sid)); | 459 pSIA = get_sid_identifier_authority (*((PSID *) user_sid)); |
291 the_passwd.pw_gid = ((pSIA->Value[2] << 24) + | 460 the_passwd.pw_gid = ((pSIA->Value[2] << 24) + |
292 (pSIA->Value[3] << 16) + | 461 (pSIA->Value[3] << 16) + |
293 (pSIA->Value[4] << 8) + | 462 (pSIA->Value[4] << 8) + |
294 (pSIA->Value[5] << 0)); | 463 (pSIA->Value[5] << 0)); |
295 /* I don't know if this is necessary, but for safety... */ | 464 /* I don't know if this is necessary, but for safety... */ |