Mercurial > hg > xemacs-beta
comparison src/nt.c @ 440:8de8e3f6228a r21-2-28
Import from CVS: tag r21-2-28
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:33:38 +0200 |
parents | 080151679be2 |
children | abe6d1db359e |
comparison
equal
deleted
inserted
replaced
439:357dd071b03c | 440:8de8e3f6228a |
---|---|
72 #if 0 | 72 #if 0 |
73 extern Lisp_Object Vwin32_generate_fake_inodes; | 73 extern Lisp_Object Vwin32_generate_fake_inodes; |
74 #endif | 74 #endif |
75 extern Lisp_Object Vmswindows_get_true_file_attributes; | 75 extern Lisp_Object Vmswindows_get_true_file_attributes; |
76 | 76 |
77 extern char *get_home_directory(void); | 77 int nt_fake_unix_uid; |
78 | 78 |
79 static char startup_dir[ MAXPATHLEN ]; | 79 static char startup_dir[ MAXPATHLEN ]; |
80 | 80 |
81 /* Get the current working directory. */ | 81 /* Get the current working directory. */ |
82 char * | 82 char * |
131 the_passwd_shell, | 131 the_passwd_shell, |
132 }; | 132 }; |
133 | 133 |
134 uid_t | 134 uid_t |
135 getuid () | 135 getuid () |
136 { | 136 { |
137 return the_passwd.pw_uid; | 137 return nt_fake_unix_uid; |
138 } | 138 } |
139 | 139 |
140 uid_t | 140 uid_t |
141 geteuid () | 141 geteuid () |
142 { | 142 { |
143 /* I could imagine arguing for checking to see whether the user is | 143 return nt_fake_unix_uid; |
144 in the Administrators group and returning a UID of 0 for that | |
145 case, but I don't know how wise that would be in the long run. */ | |
146 return getuid (); | |
147 } | 144 } |
148 | 145 |
149 gid_t | 146 gid_t |
150 getgid () | 147 getgid () |
151 { | 148 { |
159 } | 156 } |
160 | 157 |
161 struct passwd * | 158 struct passwd * |
162 getpwuid (uid_t uid) | 159 getpwuid (uid_t uid) |
163 { | 160 { |
164 if (uid == the_passwd.pw_uid) | 161 if (uid == nt_fake_unix_uid) |
165 return &the_passwd; | 162 { |
166 return NULL; | 163 the_passwd.pw_gid = the_passwd.pw_uid = uid; |
164 return &the_passwd; | |
165 } | |
166 else | |
167 return NULL; | |
167 } | 168 } |
168 | 169 |
169 struct passwd * | 170 struct passwd * |
170 getpwnam (const char *name) | 171 getpwnam (const char *name) |
171 { | 172 { |
182 } | 183 } |
183 | 184 |
184 void | 185 void |
185 init_user_info () | 186 init_user_info () |
186 { | 187 { |
188 /* This code is pretty much of ad hoc nature. There is no unix-like | |
189 UIDs under Windows NT. There is no concept of root user, because | |
190 all security is ACL-based. Instead, let's use a simple variable, | |
191 nt-fake-unix-uid, which would allow the user to have a uid of | |
192 choice. --kkm, 02/03/2000 */ | |
193 #if 0 | |
187 /* Find the user's real name by opening the process token and | 194 /* Find the user's real name by opening the process token and |
188 looking up the name associated with the user-sid in that token. | 195 looking up the name associated with the user-sid in that token. |
189 | 196 |
190 Use the relative portion of the identifier authority value from | 197 Use the relative portion of the identifier authority value from |
191 the user-sid as the user id value (same for group id using the | 198 the user-sid as the user id value (same for group id using the |
257 strcpy (the_passwd.pw_name, "unknown"); | 264 strcpy (the_passwd.pw_name, "unknown"); |
258 the_passwd.pw_uid = 123; | 265 the_passwd.pw_uid = 123; |
259 the_passwd.pw_gid = 123; | 266 the_passwd.pw_gid = 123; |
260 } | 267 } |
261 | 268 |
269 if (token) | |
270 CloseHandle (token); | |
271 #else | |
272 /* Obtain only logon id here, uid part is moved to getuid */ | |
273 char name[256]; | |
274 DWORD length = sizeof (name); | |
275 if (GetUserName (name, &length)) | |
276 strcpy (the_passwd.pw_name, name); | |
277 else | |
278 strcpy (the_passwd.pw_name, "unknown"); | |
279 #endif | |
280 | |
262 /* Ensure HOME and SHELL are defined. */ | 281 /* Ensure HOME and SHELL are defined. */ |
263 #if 0 | 282 #if 0 |
264 /* | 283 /* |
265 * With XEmacs, setting $HOME is deprecated. | 284 * With XEmacs, setting $HOME is deprecated. |
266 */ | 285 */ |
271 putenv ((GetVersion () & 0x80000000) ? "SHELL=command" : "SHELL=cmd"); | 290 putenv ((GetVersion () & 0x80000000) ? "SHELL=command" : "SHELL=cmd"); |
272 | 291 |
273 /* Set dir and shell from environment variables. */ | 292 /* Set dir and shell from environment variables. */ |
274 strcpy (the_passwd.pw_dir, get_home_directory()); | 293 strcpy (the_passwd.pw_dir, get_home_directory()); |
275 strcpy (the_passwd.pw_shell, getenv ("SHELL")); | 294 strcpy (the_passwd.pw_shell, getenv ("SHELL")); |
276 | |
277 if (token) | |
278 CloseHandle (token); | |
279 } | 295 } |
280 | 296 |
281 /* Normalize filename by converting all path separators to | 297 /* Normalize filename by converting all path separators to |
282 the specified separator. Also conditionally convert upper | 298 the specified separator. Also conditionally convert upper |
283 case path name components to lower case. */ | 299 case path name components to lower case. */ |
1202 return rename (temp, newname); | 1218 return rename (temp, newname); |
1203 } | 1219 } |
1204 #endif /* 0 */ | 1220 #endif /* 0 */ |
1205 | 1221 |
1206 static FILETIME utc_base_ft; | 1222 static FILETIME utc_base_ft; |
1223 static int init = 0; | |
1224 | |
1225 #if 0 | |
1226 | |
1207 static long double utc_base; | 1227 static long double utc_base; |
1208 static int init = 0; | |
1209 | 1228 |
1210 time_t | 1229 time_t |
1211 convert_time (FILETIME ft) | 1230 convert_time (FILETIME ft) |
1212 { | 1231 { |
1213 long double ret; | 1232 long double ret; |
1236 | 1255 |
1237 ret = (long double) ft.dwHighDateTime * 4096 * 1024 * 1024 + ft.dwLowDateTime; | 1256 ret = (long double) ft.dwHighDateTime * 4096 * 1024 * 1024 + ft.dwLowDateTime; |
1238 ret -= utc_base; | 1257 ret -= utc_base; |
1239 return (time_t) (ret * 1e-7); | 1258 return (time_t) (ret * 1e-7); |
1240 } | 1259 } |
1241 | 1260 #else |
1242 #if 0 | 1261 |
1243 /* in case we ever have need of this */ | 1262 static LARGE_INTEGER utc_base_li; |
1244 void | 1263 |
1245 convert_from_time_t (time_t time, FILETIME * pft) | 1264 time_t |
1246 { | 1265 convert_time (FILETIME uft) |
1247 long double tmp; | 1266 { |
1267 time_t ret; | |
1268 #ifndef MAXLONGLONG | |
1269 SYSTEMTIME st; | |
1270 struct tm t; | |
1271 FILETIME ft; | |
1272 TIME_ZONE_INFORMATION tzi; | |
1273 DWORD tzid; | |
1274 #else | |
1275 LARGE_INTEGER lft; | |
1276 #endif | |
1248 | 1277 |
1249 if (!init) | 1278 if (!init) |
1250 { | 1279 { |
1251 /* Determine the delta between 1-Jan-1601 and 1-Jan-1970. */ | 1280 /* Determine the delta between 1-Jan-1601 and 1-Jan-1970. */ |
1252 SYSTEMTIME st; | 1281 SYSTEMTIME st; |
1258 st.wMinute = 0; | 1287 st.wMinute = 0; |
1259 st.wSecond = 0; | 1288 st.wSecond = 0; |
1260 st.wMilliseconds = 0; | 1289 st.wMilliseconds = 0; |
1261 | 1290 |
1262 SystemTimeToFileTime (&st, &utc_base_ft); | 1291 SystemTimeToFileTime (&st, &utc_base_ft); |
1292 | |
1293 utc_base_li.LowPart = utc_base_ft.dwLowDateTime; | |
1294 utc_base_li.HighPart = utc_base_ft.dwHighDateTime; | |
1295 | |
1296 init = 1; | |
1297 } | |
1298 | |
1299 #ifdef MAXLONGLONG | |
1300 | |
1301 /* On a compiler that supports long integers, do it the easy way */ | |
1302 lft.LowPart = uft.dwLowDateTime; | |
1303 lft.HighPart = uft.dwHighDateTime; | |
1304 ret = (time_t) ((lft.QuadPart - utc_base_li.QuadPart) / 10000000); | |
1305 | |
1306 #else | |
1307 | |
1308 /* Do it the hard way using mktime. */ | |
1309 FileTimeToLocalFileTime(&uft, &ft); | |
1310 FileTimeToSystemTime (&ft, &st); | |
1311 tzid = GetTimeZoneInformation (&tzi); | |
1312 t.tm_year = st.wYear - 1900; | |
1313 t.tm_mon = st.wMonth - 1; | |
1314 t.tm_mday = st.wDay; | |
1315 t.tm_hour = st.wHour; | |
1316 t.tm_min = st.wMinute; | |
1317 t.tm_sec = st.wSecond; | |
1318 t.tm_isdst = (tzid == TIME_ZONE_ID_DAYLIGHT); | |
1319 /* st.wMilliseconds not applicable */ | |
1320 ret = mktime(&t); | |
1321 if (ret == -1) | |
1322 { | |
1323 ret = 0; | |
1324 } | |
1325 | |
1326 #endif | |
1327 | |
1328 return ret; | |
1329 } | |
1330 #endif | |
1331 | |
1332 #if 0 | |
1333 /* in case we ever have need of this */ | |
1334 void | |
1335 convert_from_time_t (time_t time, FILETIME * pft) | |
1336 { | |
1337 long double tmp; | |
1338 | |
1339 if (!init) | |
1340 { | |
1341 /* Determine the delta between 1-Jan-1601 and 1-Jan-1970. */ | |
1342 SYSTEMTIME st; | |
1343 | |
1344 st.wYear = 1970; | |
1345 st.wMonth = 1; | |
1346 st.wDay = 1; | |
1347 st.wHour = 0; | |
1348 st.wMinute = 0; | |
1349 st.wSecond = 0; | |
1350 st.wMilliseconds = 0; | |
1351 | |
1352 SystemTimeToFileTime (&st, &utc_base_ft); | |
1263 utc_base = (long double) utc_base_ft.dwHighDateTime | 1353 utc_base = (long double) utc_base_ft.dwHighDateTime |
1264 * 4096 * 1024 * 1024 + utc_base_ft.dwLowDateTime; | 1354 * 4096 * 1024 * 1024 + utc_base_ft.dwLowDateTime; |
1265 init = 1; | 1355 init = 1; |
1266 } | 1356 } |
1267 | 1357 |
1313 return hashval (p); | 1403 return hashval (p); |
1314 } | 1404 } |
1315 | 1405 |
1316 #endif | 1406 #endif |
1317 | 1407 |
1408 /* stat has been fixed since MSVC 5.0. | |
1409 Oh, and do not encapsulater stat for non-MS compilers, too */ | |
1410 /* #### popineau@ese-metz.fr says they still might be broken. | |
1411 Oh well... Let's add that `1 ||' condition.... --kkm */ | |
1412 #if 1 || defined(_MSC_VER) && _MSC_VER < 1100 | |
1413 | |
1318 /* Since stat is encapsulated on Windows NT, we need to encapsulate | 1414 /* Since stat is encapsulated on Windows NT, we need to encapsulate |
1319 the equally broken fstat as well. */ | 1415 the equally broken fstat as well. */ |
1320 int | 1416 int _cdecl |
1321 fstat (int handle, struct stat *buffer) | 1417 fstat (int handle, struct stat *buffer) |
1322 { | 1418 { |
1323 int ret; | 1419 int ret; |
1324 BY_HANDLE_FILE_INFORMATION lpFileInfo; | 1420 BY_HANDLE_FILE_INFORMATION lpFileInfo; |
1325 /* Initialize values */ | 1421 /* Initialize values */ |
1499 | 1595 |
1500 /* #### MSVC defines _ino_t to be short; other libc's might not. */ | 1596 /* #### MSVC defines _ino_t to be short; other libc's might not. */ |
1501 buf->st_ino = (unsigned short) (fake_inode ^ (fake_inode >> 16)); | 1597 buf->st_ino = (unsigned short) (fake_inode ^ (fake_inode >> 16)); |
1502 | 1598 |
1503 /* consider files to belong to current user */ | 1599 /* consider files to belong to current user */ |
1504 buf->st_uid = the_passwd.pw_uid; | 1600 buf->st_uid = buf->st_gid = nt_fake_unix_uid; |
1505 buf->st_gid = the_passwd.pw_gid; | |
1506 | 1601 |
1507 /* volume_info is set indirectly by map_win32_filename */ | 1602 /* volume_info is set indirectly by map_win32_filename */ |
1508 buf->st_dev = volume_info.serialnum; | 1603 buf->st_dev = volume_info.serialnum; |
1509 buf->st_rdev = volume_info.serialnum; | 1604 buf->st_rdev = volume_info.serialnum; |
1510 | |
1511 | 1605 |
1512 buf->st_size = wfd.nFileSizeLow; | 1606 buf->st_size = wfd.nFileSizeLow; |
1513 | 1607 |
1514 /* Convert timestamps to Unix format. */ | 1608 /* Convert timestamps to Unix format. */ |
1515 buf->st_mtime = convert_time (wfd.ftLastWriteTime); | 1609 buf->st_mtime = convert_time (wfd.ftLastWriteTime); |
1539 | 1633 |
1540 buf->st_mode |= permission | (permission >> 3) | (permission >> 6); | 1634 buf->st_mode |= permission | (permission >> 3) | (permission >> 6); |
1541 | 1635 |
1542 return 0; | 1636 return 0; |
1543 } | 1637 } |
1638 #endif /* defined(_MSC_VER) && _MSC_VER < 1100 */ | |
1544 | 1639 |
1545 /* From callproc.c */ | 1640 /* From callproc.c */ |
1546 extern Lisp_Object Vbinary_process_input; | 1641 extern Lisp_Object Vbinary_process_input; |
1547 extern Lisp_Object Vbinary_process_output; | 1642 extern Lisp_Object Vbinary_process_output; |
1548 | 1643 |
1955 UnmapViewOfFile (p_file->file_base); | 2050 UnmapViewOfFile (p_file->file_base); |
1956 CloseHandle (p_file->file_mapping); | 2051 CloseHandle (p_file->file_mapping); |
1957 CloseHandle (p_file->file); | 2052 CloseHandle (p_file->file); |
1958 } | 2053 } |
1959 | 2054 |
2055 void | |
2056 vars_of_nt (void) | |
2057 { | |
2058 DEFVAR_INT ("nt-fake-unix-uid", &nt_fake_unix_uid /* | |
2059 *Set uid returned by `user-uid' and `user-real-uid'. | |
2060 Under NT and 9x, there is no uids, and even no almighty user called root. | |
2061 By setting this variable, you can have any uid of choice. Default is 0. | |
2062 Changes to this variable take effect immediately. | |
2063 */ ); | |
2064 nt_fake_unix_uid = 0; | |
2065 } | |
2066 | |
1960 /* end of nt.c */ | 2067 /* end of nt.c */ |