comparison src/nt.c @ 4990:8f0cf4fd3d2c

Automatic merge
author Ben Wing <ben@xemacs.org>
date Sat, 06 Feb 2010 04:01:46 -0600
parents 3c3c1d139863
children 44d7bde26046
comparison
equal deleted inserted replaced
4989:d2ec55325515 4990:8f0cf4fd3d2c
156 && GetTokenInformation (token, TokenUser, &sidinfo, sizeof (sidinfo), 156 && GetTokenInformation (token, TokenUser, &sidinfo, sizeof (sidinfo),
157 &trash) 157 &trash)
158 && qxeLookupAccountSid (NULL, sidinfo.User.Sid, name, &length, 158 && qxeLookupAccountSid (NULL, sidinfo.User.Sid, name, &length,
159 domain, &dlength, &user_type)) 159 domain, &dlength, &user_type))
160 { 160 {
161 TSTR_TO_C_STRING_MALLOC (name, the_passwd.pw_name); 161 the_passwd.pw_name = TSTR_TO_ITEXT_MALLOC (name);
162 /* Determine a reasonable uid value. */ 162 /* Determine a reasonable uid value. */
163 if (qxestrcasecmp ("administrator", the_passwd.pw_name) == 0) 163 if (qxestrcasecmp ("administrator", the_passwd.pw_name) == 0)
164 { 164 {
165 the_passwd.pw_uid = 0; 165 the_passwd.pw_uid = 0;
166 the_passwd.pw_gid = 0; 166 the_passwd.pw_gid = 0;
200 } 200 }
201 /* If security calls are not supported (presumably because we 201 /* If security calls are not supported (presumably because we
202 are running under Windows 95), fallback to this. */ 202 are running under Windows 95), fallback to this. */
203 else if (qxeGetUserName (name, &length)) 203 else if (qxeGetUserName (name, &length))
204 { 204 {
205 TSTR_TO_C_STRING_MALLOC (name, the_passwd.pw_name); 205 the_passwd.pw_name = TSTR_TO_ITEXT_MALLOC (name);
206 if (qxestrcasecmp ("administrator", the_passwd.pw_name) == 0) 206 if (qxestrcasecmp ("administrator", the_passwd.pw_name) == 0)
207 the_passwd.pw_uid = 0; 207 the_passwd.pw_uid = 0;
208 else 208 else
209 the_passwd.pw_uid = 123; 209 the_passwd.pw_uid = 123;
210 the_passwd.pw_gid = the_passwd.pw_uid; 210 the_passwd.pw_gid = the_passwd.pw_uid;
221 #else 221 #else
222 /* Obtain only logon id here, uid part is moved to getuid */ 222 /* Obtain only logon id here, uid part is moved to getuid */
223 DWORD length = UNLEN + 1; 223 DWORD length = UNLEN + 1;
224 Extbyte name[MAX_XETCHAR_SIZE * (UNLEN + 1)]; 224 Extbyte name[MAX_XETCHAR_SIZE * (UNLEN + 1)];
225 if (qxeGetUserName (name, &length)) 225 if (qxeGetUserName (name, &length))
226 TSTR_TO_C_STRING_MALLOC (name, the_passwd.pw_name); 226 the_passwd.pw_name = TSTR_TO_ITEXT_MALLOC (name);
227 else 227 else
228 the_passwd.pw_name = "unknown"; 228 the_passwd.pw_name = "unknown";
229 #endif 229 #endif
230 230
231 #if 0 231 #if 0
299 dir_handle = qxeFindFirstFile (nameext, &find_data); 299 dir_handle = qxeFindFirstFile (nameext, &find_data);
300 if (dir_handle != INVALID_HANDLE_VALUE) 300 if (dir_handle != INVALID_HANDLE_VALUE)
301 { 301 {
302 Ibyte *fileint; 302 Ibyte *fileint;
303 303
304 TSTR_TO_C_STRING_MALLOC (find_data.cFileName, fileint); 304 fileint = TSTR_TO_ITEXT_MALLOC (find_data.cFileName);
305 FindClose (dir_handle); 305 FindClose (dir_handle);
306 return fileint; 306 return fileint;
307 } 307 }
308 return 0; 308 return 0;
309 } 309 }
336 if (p != NULL) 336 if (p != NULL)
337 { 337 {
338 *p++ = '\\'; 338 *p++ = '\\';
339 eicat_ch (o, '\\'); 339 eicat_ch (o, '\\');
340 } 340 }
341 xfree (component, Ibyte *); 341 xfree (component);
342 } 342 }
343 else 343 else
344 { 344 {
345 xfree (full, Ibyte *); 345 xfree (full);
346 return 0; 346 return 0;
347 } 347 }
348 } 348 }
349 349
350 xfree (full, Ibyte *); 350 xfree (full);
351 return eicpyout_malloc (o, 0); 351 return eicpyout_malloc (o, 0);
352 } 352 }
353 353
354 static int 354 static int
355 is_unc_volume (const Ibyte *filename) 355 is_unc_volume (const Ibyte *filename)
375 LPBYTE lpvalue; 375 LPBYTE lpvalue;
376 HKEY hrootkey = NULL; 376 HKEY hrootkey = NULL;
377 DWORD cbData; 377 DWORD cbData;
378 Extbyte *keyext; 378 Extbyte *keyext;
379 379
380 C_STRING_TO_TSTR (key, keyext); 380 keyext = ITEXT_TO_TSTR (key);
381 381
382 /* Check both the current user and the local machine to see if 382 /* Check both the current user and the local machine to see if
383 we have any resources. */ 383 we have any resources. */
384 384
385 if (qxeRegOpenKeyEx (HKEY_CURRENT_USER, XETEXT (REG_ROOT), 0, KEY_READ, 385 if (qxeRegOpenKeyEx (HKEY_CURRENT_USER, XETEXT (REG_ROOT), 0, KEY_READ,
393 && qxeRegQueryValueEx (hrootkey, keyext, NULL, lpdwtype, lpvalue, 393 && qxeRegQueryValueEx (hrootkey, keyext, NULL, lpdwtype, lpvalue,
394 &cbData) == ERROR_SUCCESS) 394 &cbData) == ERROR_SUCCESS)
395 return (lpvalue); 395 return (lpvalue);
396 396
397 if (lpvalue) 397 if (lpvalue)
398 xfree (lpvalue, LPBYTE); 398 xfree (lpvalue);
399 399
400 RegCloseKey (hrootkey); 400 RegCloseKey (hrootkey);
401 } 401 }
402 402
403 if (qxeRegOpenKeyEx (HKEY_LOCAL_MACHINE, XETEXT (REG_ROOT), 0, KEY_READ, 403 if (qxeRegOpenKeyEx (HKEY_LOCAL_MACHINE, XETEXT (REG_ROOT), 0, KEY_READ,
411 qxeRegQueryValueEx (hrootkey, keyext, NULL, lpdwtype, lpvalue, 411 qxeRegQueryValueEx (hrootkey, keyext, NULL, lpdwtype, lpvalue,
412 &cbData) == ERROR_SUCCESS) 412 &cbData) == ERROR_SUCCESS)
413 return (lpvalue); 413 return (lpvalue);
414 414
415 if (lpvalue) 415 if (lpvalue)
416 xfree (lpvalue, LPBYTE); 416 xfree (lpvalue);
417 417
418 RegCloseKey (hrootkey); 418 RegCloseKey (hrootkey);
419 } 419 }
420 420
421 return (NULL); 421 return (NULL);
486 Charcount cch; 486 Charcount cch;
487 487
488 cch = qxeExpandEnvironmentStrings ((Extbyte *) lpval, buf, 0); 488 cch = qxeExpandEnvironmentStrings ((Extbyte *) lpval, buf, 0);
489 buf = alloca_extbytes (cch * XETCHAR_SIZE); 489 buf = alloca_extbytes (cch * XETCHAR_SIZE);
490 qxeExpandEnvironmentStrings ((Extbyte *) lpval, buf, cch); 490 qxeExpandEnvironmentStrings ((Extbyte *) lpval, buf, cch);
491 TSTR_TO_C_STRING (buf, envval); 491 envval = TSTR_TO_ITEXT (buf);
492 eputenv (env_vars[i], (CIbyte *) envval); 492 eputenv (env_vars[i], (CIbyte *) envval);
493 } 493 }
494 else if (dwType == REG_SZ) 494 else if (dwType == REG_SZ)
495 { 495 {
496 Ibyte *envval; 496 Ibyte *envval;
497 497
498 TSTR_TO_C_STRING (lpval, envval); 498 envval = TSTR_TO_ITEXT (lpval);
499 eputenv (env_vars[i], (CIbyte *) envval); 499 eputenv (env_vars[i], (CIbyte *) envval);
500 } 500 }
501 501
502 xfree (lpval, LPBYTE); 502 xfree (lpval);
503 } 503 }
504 } 504 }
505 } 505 }
506 506
507 /* Another special case: on NT, the PATH variable is actually named 507 /* Another special case: on NT, the PATH variable is actually named
633 if (!nchars) 633 if (!nchars)
634 return NULL; 634 return NULL;
635 rootext = alloca_extbytes (nchars * XETCHAR_SIZE); 635 rootext = alloca_extbytes (nchars * XETCHAR_SIZE);
636 if (!qxeGetCurrentDirectory (nchars, rootext)) 636 if (!qxeGetCurrentDirectory (nchars, rootext))
637 return NULL; 637 return NULL;
638 TSTR_TO_C_STRING (rootext, default_root); 638 default_root = TSTR_TO_ITEXT (rootext);
639 parse_root (default_root, &root_dir); 639 parse_root (default_root, &root_dir);
640 *root_dir = 0; 640 *root_dir = 0;
641 root_dir = default_root; 641 root_dir = default_root;
642 } 642 }
643 643
703 info = xnew (volume_info_data); 703 info = xnew (volume_info_data);
704 add_volume_info (root_dir, info); 704 add_volume_info (root_dir, info);
705 } 705 }
706 else 706 else
707 { 707 {
708 xfree (info->name, Ibyte *); 708 xfree (info->name);
709 xfree (info->type, Ibyte *); 709 xfree (info->type);
710 } 710 }
711 711
712 TSTR_TO_C_STRING_MALLOC (name, info->name); 712 info->name = TSTR_TO_ITEXT_MALLOC (name);
713 info->serialnum = serialnum; 713 info->serialnum = serialnum;
714 info->maxcomp = maxcomp; 714 info->maxcomp = maxcomp;
715 info->flags = flags; 715 info->flags = flags;
716 TSTR_TO_C_STRING_MALLOC (type, info->type); 716 info->type = TSTR_TO_ITEXT_MALLOC (type);
717 info->timestamp = GetTickCount (); 717 info->timestamp = GetTickCount ();
718 } 718 }
719 719
720 return info; 720 return info;
721 } 721 }
826 826
827 if (!(dirp = xnew_and_zero (DIR))) 827 if (!(dirp = xnew_and_zero (DIR)))
828 return NULL; 828 return NULL;
829 829
830 if (dir_pathname) 830 if (dir_pathname)
831 xfree (dir_pathname, Ibyte *); 831 xfree (dir_pathname);
832 dir_pathname = qxestrdup (filename); 832 dir_pathname = qxestrdup (filename);
833 833
834 return dirp; 834 return dirp;
835 } 835 }
836 836
848 else if (wnet_enum_handle != INVALID_HANDLE_VALUE) 848 else if (wnet_enum_handle != INVALID_HANDLE_VALUE)
849 { 849 {
850 retval = close_unc_volume (wnet_enum_handle); 850 retval = close_unc_volume (wnet_enum_handle);
851 wnet_enum_handle = INVALID_HANDLE_VALUE; 851 wnet_enum_handle = INVALID_HANDLE_VALUE;
852 } 852 }
853 xfree (dirp, DIR *); 853 xfree (dirp);
854 854
855 return retval; 855 return retval;
856 } 856 }
857 857
858 struct direct * 858 struct direct *
883 883
884 dir_find_handle = qxeFindFirstFile (fileext, &dir_find_data); 884 dir_find_handle = qxeFindFirstFile (fileext, &dir_find_data);
885 885
886 if (dir_find_handle == INVALID_HANDLE_VALUE) 886 if (dir_find_handle == INVALID_HANDLE_VALUE)
887 return NULL; 887 return NULL;
888 TSTR_TO_C_STRING (dir_find_data.cFileName, val); 888 val = TSTR_TO_ITEXT (dir_find_data.cFileName);
889 } 889 }
890 else 890 else
891 { 891 {
892 if (!qxeFindNextFile (dir_find_handle, &dir_find_data)) 892 if (!qxeFindNextFile (dir_find_handle, &dir_find_data))
893 return NULL; 893 return NULL;
894 TSTR_TO_C_STRING (dir_find_data.cFileName, val); 894 val = TSTR_TO_ITEXT (dir_find_data.cFileName);
895 } 895 }
896 896
897 /* XEmacs never uses this value, so don't bother making it match 897 /* XEmacs never uses this value, so don't bother making it match
898 value returned by qxe_stat(). */ 898 value returned by qxe_stat(). */
899 dir_static.d_ino = 1; 899 dir_static.d_ino = 1;
923 eicat_ch (linkname, '\\'); 923 eicat_ch (linkname, '\\');
924 eicat_rawz (linkname, val); 924 eicat_rawz (linkname, val);
925 resolved = mswindows_read_link (eidata (linkname)); 925 resolved = mswindows_read_link (eidata (linkname));
926 if (resolved) 926 if (resolved)
927 { 927 {
928 xfree (resolved, Ibyte *); 928 xfree (resolved);
929 len -= 4; 929 len -= 4;
930 val[len] = '\0'; 930 val[len] = '\0';
931 } 931 }
932 } 932 }
933 } 933 }
934 934
935 eicpy_rawz (found, val); 935 eicpy_rawz (found, val);
936 if (need_to_free) 936 if (need_to_free)
937 xfree (val, Ibyte *); 937 xfree (val);
938 938
939 if (!NILP (Vmswindows_downcase_file_names)) 939 if (!NILP (Vmswindows_downcase_file_names))
940 eilwr (found); 940 eilwr (found);
941 941
942 namlen = min (eilen (found), sizeof (dir_static.d_name) - 1); 942 namlen = min (eilen (found), sizeof (dir_static.d_name) - 1);
996 result = qxeWNetEnumResource (wnet_enum_handle, &count, buf, &bufsize); 996 result = qxeWNetEnumResource (wnet_enum_handle, &count, buf, &bufsize);
997 if (result != NO_ERROR) 997 if (result != NO_ERROR)
998 return NULL; 998 return NULL;
999 999
1000 /* WNetEnumResource returns \\resource\share...skip forward to "share". */ 1000 /* WNetEnumResource returns \\resource\share...skip forward to "share". */
1001 TSTR_TO_C_STRING (((LPNETRESOURCEW) buf)->lpRemoteName, ptr); 1001 ptr = TSTR_TO_ITEXT (((LPNETRESOURCEW) buf)->lpRemoteName);
1002 INC_IBYTEPTR (ptr); 1002 INC_IBYTEPTR (ptr);
1003 INC_IBYTEPTR (ptr); 1003 INC_IBYTEPTR (ptr);
1004 while (*ptr && !IS_DIRECTORY_SEP (itext_ichar (ptr))) 1004 while (*ptr && !IS_DIRECTORY_SEP (itext_ichar (ptr)))
1005 INC_IBYTEPTR (ptr); 1005 INC_IBYTEPTR (ptr);
1006 INC_IBYTEPTR (ptr); 1006 INC_IBYTEPTR (ptr);
1562 { 1562 {
1563 if (!IS_DIRECTORY_SEP (name[len-1])) 1563 if (!IS_DIRECTORY_SEP (name[len-1]))
1564 qxestrcat (name, (Ibyte *) "\\"); 1564 qxestrcat (name, (Ibyte *) "\\");
1565 /* File has already been resolved and we don't want to do it again 1565 /* File has already been resolved and we don't want to do it again
1566 in case of lstat() */ 1566 in case of lstat() */
1567 C_STRING_TO_TSTR (name, nameext); 1567 nameext = ITEXT_TO_TSTR (name);
1568 if (qxeGetDriveType (nameext) < 2) 1568 if (qxeGetDriveType (nameext) < 2)
1569 { 1569 {
1570 SetErrorMode (errm); 1570 SetErrorMode (errm);
1571 errno = ENOENT; 1571 errno = ENOENT;
1572 return -1; 1572 return -1;
1603 /* This was the last entry returned by readdir. */ 1603 /* This was the last entry returned by readdir. */
1604 wfd = dir_find_data; 1604 wfd = dir_find_data;
1605 } 1605 }
1606 else 1606 else
1607 { 1607 {
1608 C_STRING_TO_TSTR (name, nameext); 1608 nameext = ITEXT_TO_TSTR (name);
1609 fh = qxeFindFirstFile (nameext, &wfd); 1609 fh = qxeFindFirstFile (nameext, &wfd);
1610 if (fh == INVALID_HANDLE_VALUE) 1610 if (fh == INVALID_HANDLE_VALUE)
1611 { 1611 {
1612 SetErrorMode (errm); 1612 SetErrorMode (errm);
1613 errno = ENOENT; 1613 errno = ENOENT;
1628 else 1628 else
1629 { 1629 {
1630 if (!NILP (Vmswindows_get_true_file_attributes)) 1630 if (!NILP (Vmswindows_get_true_file_attributes))
1631 /* File has already been resolved and we don't want to do it again 1631 /* File has already been resolved and we don't want to do it again
1632 in case of lstat() */ 1632 in case of lstat() */
1633 C_STRING_TO_TSTR (name, nameext); 1633 nameext = ITEXT_TO_TSTR (name);
1634 if (!NILP (Vmswindows_get_true_file_attributes) 1634 if (!NILP (Vmswindows_get_true_file_attributes)
1635 /* No access rights required to get info. */ 1635 /* No access rights required to get info. */
1636 && (fh = qxeCreateFile (nameext, 0, 0, NULL, OPEN_EXISTING, 0, NULL)) 1636 && (fh = qxeCreateFile (nameext, 0, 0, NULL, OPEN_EXISTING, 0, NULL))
1637 != INVALID_HANDLE_VALUE) 1637 != INVALID_HANDLE_VALUE)
1638 { 1638 {
1688 { 1688 {
1689 /* check if link is valid */ 1689 /* check if link is valid */
1690 Ibyte *resolved = mswindows_read_link (name); 1690 Ibyte *resolved = mswindows_read_link (name);
1691 if (resolved) 1691 if (resolved)
1692 { 1692 {
1693 xfree (resolved, Ibyte *); 1693 xfree (resolved);
1694 buf->st_mode = S_IFLNK; 1694 buf->st_mode = S_IFLNK;
1695 } 1695 }
1696 } 1696 }
1697 } 1697 }
1698 } 1698 }
1839 if (XEUNICODE_P) 1839 if (XEUNICODE_P)
1840 cwdext = (Extbyte *) _wgetdcwd (drivelet, NULL, 0); 1840 cwdext = (Extbyte *) _wgetdcwd (drivelet, NULL, 0);
1841 else 1841 else
1842 cwdext = _getdcwd (drivelet, NULL, 0); 1842 cwdext = _getdcwd (drivelet, NULL, 0);
1843 if (cwdext == NULL) return NULL; 1843 if (cwdext == NULL) return NULL;
1844 TSTR_TO_C_STRING_MALLOC (cwdext, cwd); 1844 cwd = TSTR_TO_ITEXT_MALLOC (cwdext);
1845 xfree (cwdext, Extbyte *); 1845 xfree (cwdext);
1846 return cwd; 1846 return cwd;
1847 } 1847 }
1848 1848
1849 1849
1850 /*--------------------------------------------------------------------*/ 1850 /*--------------------------------------------------------------------*/
2050 { 2050 {
2051 Extbyte *dllname_ext = 2051 Extbyte *dllname_ext =
2052 (Extbyte *) RVA_TO_PTR (imports->Name, section, executable); 2052 (Extbyte *) RVA_TO_PTR (imports->Name, section, executable);
2053 Ibyte *dllname; 2053 Ibyte *dllname;
2054 2054
2055 EXTERNAL_TO_C_STRING (dllname_ext, dllname, Qbinary); 2055 dllname = EXTERNAL_TO_ITEXT (dllname_ext, Qbinary);
2056 2056
2057 /* The exact name of the cygwin dll has changed with 2057 /* The exact name of the cygwin dll has changed with
2058 various releases, but hopefully this will be reasonably 2058 various releases, but hopefully this will be reasonably
2059 future proof. */ 2059 future proof. */
2060 if (qxestrncasecmp (dllname, (Ibyte *) "cygwin", 6) == 0) 2060 if (qxestrncasecmp (dllname, (Ibyte *) "cygwin", 6) == 0)
2104 /* luckily, this returns the short version of each element in the path. */ 2104 /* luckily, this returns the short version of each element in the path. */
2105 if (qxeGetShortPathName (fileext, shortname, 2105 if (qxeGetShortPathName (fileext, shortname,
2106 sizeof (shortname) / XETCHAR_SIZE) == 0) 2106 sizeof (shortname) / XETCHAR_SIZE) == 0)
2107 return Qnil; 2107 return Qnil;
2108 2108
2109 TSTR_TO_C_STRING (shortname, shortint); 2109 shortint = TSTR_TO_ITEXT (shortname);
2110 MSWINDOWS_NORMALIZE_FILENAME (shortint); 2110 MSWINDOWS_NORMALIZE_FILENAME (shortint);
2111 2111
2112 return build_intstring (shortint); 2112 return build_istring (shortint);
2113 } 2113 }
2114 2114
2115 2115
2116 DEFUN ("mswindows-long-file-name", Fmswindows_long_file_name, 1, 1, 0, /* 2116 DEFUN ("mswindows-long-file-name", Fmswindows_long_file_name, 1, 1, 0, /*
2117 Return the long file name version of the full path of FILENAME. 2117 Return the long file name version of the full path of FILENAME.
2130 2130
2131 if (!(longname = mswindows_get_long_filename (XSTRING_DATA (filename)))) 2131 if (!(longname = mswindows_get_long_filename (XSTRING_DATA (filename))))
2132 return Qnil; 2132 return Qnil;
2133 2133
2134 canon = mswindows_canonicalize_filename (longname); 2134 canon = mswindows_canonicalize_filename (longname);
2135 ret = build_intstring (canon); 2135 ret = build_istring (canon);
2136 xfree (canon, Ibyte *); 2136 xfree (canon);
2137 xfree (longname, Ibyte *); 2137 xfree (longname);
2138 return ret; 2138 return ret;
2139 } 2139 }
2140 2140
2141 2141
2142 void 2142 void