77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
struct {
UCHAR DataBuffer[1];
} GenericReparseBuffer;
} DUMMYUNIONNAME;
} REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER;
#define LINK_BUFFER_SIZE 1024
/*
** Fill stat buf with information received from GetFileAttributesExW().
** Does not follow symbolic links, returning instead information about
** the link itself.
** Returns 0 on success, 1 on failure.
*/
int win32_lstat(const wchar_t *zFilename, struct fossilStat *buf){
WIN32_FILE_ATTRIBUTE_DATA attr;
int rc = GetFileAttributesExW(zFilename, GetFileExInfoStandard, &attr);
if( rc ){
ssize_t tlen = 0; /* assume it is not a symbolic link */
/* if it is a reparse point it *might* be a symbolic link */
/* so defer to win32_readlink to actually check */
if (attr.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT){
char *tname = fossil_filename_to_utf8(zFilename);
char tlink[LINK_BUFFER_SIZE];
tlen = win32_readlink(tname, tlink, sizeof(tlink));
fossil_filename_free(tname);
}
ULARGE_INTEGER ull;
/* if a link was retrieved, it is a symlink, otherwise a dir or file */
if (tlen == 0){
buf->st_mode = ((attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ?
S_IFDIR : S_IFREG);
buf->st_size = (((i64)attr.nFileSizeHigh)<<32) | attr.nFileSizeLow;
}else{
buf->st_mode = S_IFLNK;
buf->st_size = tlen;
}
ull.LowPart = attr.ftLastWriteTime.dwLowDateTime;
ull.HighPart = attr.ftLastWriteTime.dwHighDateTime;
buf->st_mtime = ull.QuadPart / 10000000ULL - 11644473600ULL;
}
return !rc;
}
/*
** Fill stat buf with information received from win32_lstat().
** If a symbolic link is found, follow it and return information about
** the target, repeating until an actual target is found.
** Limit the number of loop iterations so as to avoid an infinite loop
** due to circular links. This should never happen because
** GetFinalPathNameByHandleW() should always preclude that need, but being
** prepared to loop seems prudent, or at least not harmful.
** Returns 0 on success, 1 on failure.
*/
int win32_stat(const wchar_t *zFilename, struct fossilStat *buf){
int rc;
HANDLE file;
wchar_t nextFilename[LINK_BUFFER_SIZE];
DWORD len;
int iterationsRemaining = 8; /* 8 is arbitrary, can be modified as needed */
while (iterationsRemaining-- > 0){
rc = win32_lstat(zFilename, buf);
/* exit on error or not link */
if ((rc != 0) || (buf->st_mode != S_IFLNK))
break;
/* it is a link, so open the linked file */
file = CreateFileW(zFilename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
if ((file == NULL) || (file == INVALID_HANDLE_VALUE)){
rc = 1;
break;
}
/* get the final path name and close the handle */
len = GetFinalPathNameByHandleW(file, nextFilename, LINK_BUFFER_SIZE - 1, 0);
CloseHandle(file);
/* if any problems getting the final path name error so exit */
if ((len <= 0) || (len > LINK_BUFFER_SIZE - 1)){
rc = 1;
break;
}
/* prepare to try again just in case we have a chain to follow */
/* this shouldn't happen, but just trying to be safe */
zFilename = nextFilename;
}
return rc;
}
/*
** An implementation of a posix-like readlink function for win32.
** Copies the target of a symbolic link to buf if possible.
** Returns the length of the link copied to buf on success, -1 on failure.
*/
ssize_t win32_readlink(const char *path, char *buf, size_t bufsiz){
/* assume we're going to fail */
ssize_t rv = -1;
/* does path reference a reparse point? */
WIN32_FILE_ATTRIBUTE_DATA attr;
int rc = GetFileAttributesEx(path, GetFileExInfoStandard, &attr);
if (rc && (attr.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)){
/* since it is a reparse point, open it */
HANDLE file = CreateFile(path, FILE_READ_EA, 0, NULL, OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL);
if ((file != NULL) && (file != INVALID_HANDLE_VALUE)){
/* use DeviceIoControl to get the reparse point data */
int data_size = sizeof(REPARSE_DATA_BUFFER) + LINK_BUFFER_SIZE * sizeof(wchar_t);
REPARSE_DATA_BUFFER* data = fossil_malloc(data_size);
DWORD data_used;
data->ReparseTag = IO_REPARSE_TAG_SYMLINK;
data->ReparseDataLength = 0;
data->Reserved = 0;
int rc = DeviceIoControl(file, FSCTL_GET_REPARSE_POINT, NULL, 0,
data, data_size, &data_used, NULL);
/* did the reparse point data fit into the desired buffer? */
if (rc && (data_used < data_size)){
/* it fit, so setup the print name for further processing */
USHORT
offset = data->SymbolicLinkReparseBuffer.PrintNameOffset / sizeof(wchar_t),
length = data->SymbolicLinkReparseBuffer.PrintNameLength / sizeof(wchar_t);
char *temp;
data->SymbolicLinkReparseBuffer.PathBuffer[offset + length] = 0;
/* convert the filename to utf8, copy it, and discard the converted copy */
temp = fossil_filename_to_utf8(data->SymbolicLinkReparseBuffer.PathBuffer + offset);
rv = strlen(temp);
if (rv >= bufsiz)
rv = bufsiz;
memcpy(buf, temp, rv);
fossil_filename_free(temp);
}
fossil_free(data);
/* all done, close the reparse point */
CloseHandle(file);
}
}
return rv;
}
/*
** Either unlink a file or remove a directory on win32 systems.
** To delete a symlink on a posix system, you simply unlink the entry.
** Unfortunately for our purposes, win32 differentiates between symlinks for
** files and for directories. Thus you must unlink a file symlink or rmdir a
** directory symlink. This is a convenience function used when we know we're
** deleting a symlink of some type.
** Returns 0 on success, 1 on failure.
*/
int win32_unlink_rmdir(const wchar_t *zFilename){
int rc = 0;
WIN32_FILE_ATTRIBUTE_DATA attr;
if (GetFileAttributesExW(zFilename, GetFileExInfoStandard, &attr)){
if ((attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)
rc = RemoveDirectoryW(zFilename);
else
rc = DeleteFileW(zFilename);
}
return !rc;
}
|
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
|
|
|
|
>
|
>
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
struct {
UCHAR DataBuffer[1];
} GenericReparseBuffer;
} DUMMYUNIONNAME;
} REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER;
#define LINK_BUFFER_SIZE 1024
static int isVistaOrLater(){
if( !dllhandle ){
HANDLE h = LoadLibraryW(L"KERNEL32");
createSymbolicLinkW = (BOOLEAN APIENTRY (*) (LPCWSTR, LPCWSTR, DWORD)) GetProcAddress(h, "CreateSymbolicLinkW");
getFinalPathNameByHandleW = (DWORD WINAPI (*) (HANDLE, LPWSTR, DWORD, DWORD)) GetProcAddress(h, "GetFinalPathNameByHandleW");
dllhandle = h;
}
return createSymbolicLinkW != NULL;
}
/*
** Fill stat buf with information received from GetFileAttributesExW().
** Does not follow symbolic links, returning instead information about
** the link itself.
** Returns 0 on success, 1 on failure.
*/
int win32_lstat(const wchar_t *zFilename, struct fossilStat *buf){
WIN32_FILE_ATTRIBUTE_DATA attr;
int rc = GetFileAttributesExW(zFilename, GetFileExInfoStandard, &attr);
if( rc ){
ssize_t tlen = 0; /* assume it is not a symbolic link */
/* if it is a reparse point it *might* be a symbolic link */
/* so defer to win32_readlink to actually check */
if( attr.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT ){
char *tname = fossil_filename_to_utf8(zFilename);
char tlink[LINK_BUFFER_SIZE];
tlen = win32_readlink(tname, tlink, sizeof(tlink));
fossil_filename_free(tname);
}
ULARGE_INTEGER ull;
/* if a link was retrieved, it is a symlink, otherwise a dir or file */
if( tlen == 0 ){
buf->st_mode = ((attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ?
S_IFDIR : S_IFREG);
buf->st_size = (((i64)attr.nFileSizeHigh)<<32) | attr.nFileSizeLow;
}else{
buf->st_mode = S_IFLNK;
buf->st_size = tlen;
}
ull.LowPart = attr.ftLastWriteTime.dwLowDateTime;
ull.HighPart = attr.ftLastWriteTime.dwHighDateTime;
buf->st_mtime = ull.QuadPart / 10000000ULL - 11644473600ULL;
}
return !rc;
}
/*
** Fill stat buf with information received from win32_lstat().
** If a symbolic link is found, follow it and return information about
** the target, repeating until an actual target is found.
** Limit the number of loop iterations so as to avoid an infinite loop
** due to circular links. This should never happen because
** GetFinalPathNameByHandleW() should always preclude that need, but being
** prepared to loop seems prudent, or at least not harmful.
** Returns 0 on success, 1 on failure.
*/
int win32_stat(const wchar_t *zFilename, struct fossilStat *buf){
int rc;
HANDLE file;
wchar_t nextFilename[LINK_BUFFER_SIZE];
DWORD len;
int iterationsRemaining = 8; /* 8 is arbitrary, can be modified as needed */
while (iterationsRemaining-- > 0){
rc = win32_lstat(zFilename, buf);
/* exit on error or not link */
if( (rc != 0) || (buf->st_mode != S_IFLNK) )
break;
/* it is a link, so open the linked file */
file = CreateFileW(zFilename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
if( (file == NULL) || (file == INVALID_HANDLE_VALUE) ){
rc = 1;
break;
}
/* get the final path name and close the handle */
if( isVistaOrLater() ){
len = getFinalPathNameByHandleW(file, nextFilename, LINK_BUFFER_SIZE - 1, 0);
}else{
len = -1;
}
CloseHandle(file);
/* if any problems getting the final path name error so exit */
if( (len <= 0) || (len > LINK_BUFFER_SIZE - 1) ){
rc = 1;
break;
}
/* prepare to try again just in case we have a chain to follow */
/* this shouldn't happen, but just trying to be safe */
zFilename = nextFilename;
}
return rc;
}
/*
** An implementation of a posix-like readlink function for win32.
** Copies the target of a symbolic link to buf if possible.
** Returns the length of the link copied to buf on success, -1 on failure.
*/
ssize_t win32_readlink(const char *path, char *buf, size_t bufsiz){
/* assume we're going to fail */
ssize_t rv = -1;
/* does path reference a reparse point? */
WIN32_FILE_ATTRIBUTE_DATA attr;
int rc = GetFileAttributesEx(path, GetFileExInfoStandard, &attr);
if( rc && (attr.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) ){
/* since it is a reparse point, open it */
HANDLE file = CreateFile(path, FILE_READ_EA, 0, NULL, OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL);
if( (file != NULL) && (file != INVALID_HANDLE_VALUE) ){
/* use DeviceIoControl to get the reparse point data */
int data_size = sizeof(REPARSE_DATA_BUFFER) + LINK_BUFFER_SIZE * sizeof(wchar_t);
REPARSE_DATA_BUFFER* data = fossil_malloc(data_size);
DWORD data_used;
data->ReparseTag = IO_REPARSE_TAG_SYMLINK;
data->ReparseDataLength = 0;
data->Reserved = 0;
int rc = DeviceIoControl(file, FSCTL_GET_REPARSE_POINT, NULL, 0,
data, data_size, &data_used, NULL);
/* did the reparse point data fit into the desired buffer? */
if( rc && (data_used < data_size) ){
/* it fit, so setup the print name for further processing */
USHORT
offset = data->SymbolicLinkReparseBuffer.PrintNameOffset / sizeof(wchar_t),
length = data->SymbolicLinkReparseBuffer.PrintNameLength / sizeof(wchar_t);
char *temp;
data->SymbolicLinkReparseBuffer.PathBuffer[offset + length] = 0;
/* convert the filename to utf8, copy it, and discard the converted copy */
temp = fossil_filename_to_utf8(data->SymbolicLinkReparseBuffer.PathBuffer + offset);
rv = strlen(temp);
if( rv >= bufsiz )
rv = bufsiz;
memcpy(buf, temp, rv);
fossil_filename_free(temp);
}
fossil_free(data);
/* all done, close the reparse point */
CloseHandle(file);
}
}
return rv;
}
/*
** Either unlink a file or remove a directory on win32 systems.
** To delete a symlink on a posix system, you simply unlink the entry.
** Unfortunately for our purposes, win32 differentiates between symlinks for
** files and for directories. Thus you must unlink a file symlink or rmdir a
** directory symlink. This is a convenience function used when we know we're
** deleting a symlink of some type.
** Returns 0 on success, 1 on failure.
*/
int win32_unlink_rmdir(const wchar_t *zFilename){
int rc = 0;
WIN32_FILE_ATTRIBUTE_DATA attr;
if( GetFileAttributesExW(zFilename, GetFileExInfoStandard, &attr) ){
if( (attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY )
rc = RemoveDirectoryW(zFilename);
else
rc = DeleteFileW(zFilename);
}
return !rc;
}
|
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
*/
int win32_symlink(const char *oldpath, const char *newpath){
fossilStat stat;
int created = 0;
DWORD flags = 0;
wchar_t *zMbcs, *zMbcsOld;
/* does oldpath exist? is it a dir or a file? */
zMbcsOld = fossil_utf8_to_filename(oldpath);
if (win32_stat(zMbcsOld, &stat) == 0){
if (stat.st_mode == S_IFDIR)
flags = SYMBOLIC_LINK_FLAG_DIRECTORY;
}
/* remove newpath before creating the symlink */
zMbcs = fossil_utf8_to_filename(newpath);
win32_unlink_rmdir(zMbcs);
created = CreateSymbolicLinkW(zMbcs, zMbcsOld, flags);
fossil_filename_free(zMbcs);
fossil_filename_free(zMbcsOld);
/* if the symlink was not created, create a plain text file */
if (!created){
Blob content;
blob_set(&content, oldpath);
blob_write_to_file(&content, newpath);
blob_reset(&content);
created = 1;
}
return !created;
}
/*
** Given a pathname to a file, return true if:
** 1. the file exists
** 2. the file is a symbolic link
** 3. the symbolic link's attributes can be acquired
** 4. the symbolic link type is different than the target type
*/
int win32_check_symlink_type_changed(const char* zName){
int changed = 0;
wchar_t* zMbcs;
fossilStat lstat_buf, stat_buf;
WIN32_FILE_ATTRIBUTE_DATA lstat_attr;
zMbcs = fossil_utf8_to_filename(zName);
if (win32_stat(zMbcs, &stat_buf) != 0)
stat_buf.st_mode = S_IFREG;
changed =
(win32_lstat(zMbcs, &lstat_buf) == 0) &&
(lstat_buf.st_mode == S_IFLNK) &&
GetFileAttributesExW(zMbcs, GetFileExInfoStandard, &lstat_attr) &&
((stat_buf.st_mode == S_IFDIR) != ((lstat_attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY));
fossil_filename_free(zMbcs);
return changed;
|
|
|
|
>
>
|
>
|
|
|
>
|
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
*/
int win32_symlink(const char *oldpath, const char *newpath){
fossilStat stat;
int created = 0;
DWORD flags = 0;
wchar_t *zMbcs, *zMbcsOld;
/* does oldpath exist? is it a dir or a file? */
zMbcsOld = fossil_utf8_to_filename(oldpath);
if( win32_stat(zMbcsOld, &stat) == 0 ){
if( stat.st_mode == S_IFDIR ){
flags = SYMBOLIC_LINK_FLAG_DIRECTORY;
}
}
/* remove newpath before creating the symlink */
zMbcs = fossil_utf8_to_filename(newpath);
win32_unlink_rmdir(zMbcs);
if( isVistaOrLater() ){
created = createSymbolicLinkW(zMbcs, zMbcsOld, flags);
}
fossil_filename_free(zMbcs);
fossil_filename_free(zMbcsOld);
/* if the symlink was not created, create a plain text file */
if( !created ){
Blob content;
blob_set(&content, oldpath);
blob_write_to_file(&content, newpath);
blob_reset(&content);
created = 1;
}
return !created;
}
/*
** Given a pathname to a file, return true if:
** 1. the file exists
** 2. the file is a symbolic link
** 3. the symbolic link's attributes can be acquired
** 4. the symbolic link type is different than the target type
*/
int win32_check_symlink_type_changed(const char* zName){
int changed = 0;
wchar_t* zMbcs;
fossilStat lstat_buf, stat_buf;
WIN32_FILE_ATTRIBUTE_DATA lstat_attr;
zMbcs = fossil_utf8_to_filename(zName);
if( win32_stat(zMbcs, &stat_buf) != 0 ){
stat_buf.st_mode = S_IFREG;
}
changed =
(win32_lstat(zMbcs, &lstat_buf) == 0) &&
(lstat_buf.st_mode == S_IFLNK) &&
GetFileAttributesExW(zMbcs, GetFileExInfoStandard, &lstat_attr) &&
((stat_buf.st_mode == S_IFDIR) != ((lstat_attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY));
fossil_filename_free(zMbcs);
return changed;
|
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
|
wchar_t *pFilename;
wchar_t fullName[MAX_PATH+1];
DWORD fullLength;
wchar_t volName[MAX_PATH+1];
DWORD fsFlags;
/* symlinks only supported on vista or greater */
/* if (!IsWindowsVistaOrGreater()) // TODO: make it work on MinGW
return 0; */
/* next we need to check to see if the privilege is available */
/* can't check privilege if we can't lookup its value */
if (!LookupPrivilegeValue(NULL, SE_CREATE_SYMBOLIC_LINK_NAME, &luid))
return 0;
/* can't check privilege if we can't open the process token */
process = GetCurrentProcess();
if (!OpenProcessToken(process, TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &token))
return 0;
/* by this point, we have a process token and the privilege value */
/* try to enable the privilege then close the token */
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(token, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL);
status = GetLastError();
CloseHandle(token);
/* any error means we failed to enable the privilege, symlinks not supported */
if (status != ERROR_SUCCESS)
return 0;
/* assume no support for symlinks */
success = 0;
pFilename = fossil_utf8_to_filename(zFilename);
/* given the filename we're interested in, symlinks are supported if */
/* 1. we can get the full name of the path from the given path */
fullLength = GetFullPathNameW(pFilename, sizeof(fullName), fullName, NULL);
if ((fullLength > 0) && (fullLength < sizeof(fullName))){
/* 2. we can get the volume path name from the full name */
if (GetVolumePathNameW(fullName, volName, sizeof(volName))){
/* 3. we can get volume information from the volume path name */
if (GetVolumeInformationW(volName, NULL, 0, NULL, NULL, &fsFlags, NULL, 0)){
/* 4. the given volume support reparse points */
if (fsFlags & FILE_SUPPORTS_REPARSE_POINTS){
/* all four conditions were true, so we support symlinks; success! */
success = 1;
}
}
}
}
fossil_filename_free(pFilename);
return success;
}
/*
** Wrapper around the access() system call. This code was copied from Tcl
** 8.6 and then modified.
*/
int win32_access(const wchar_t *zFilename, int flags){
|
|
|
|
>
|
|
|
>
|
|
>
|
|
|
|
>
|
|
|
|
|
|
|
|
|
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
|
wchar_t *pFilename;
wchar_t fullName[MAX_PATH+1];
DWORD fullLength;
wchar_t volName[MAX_PATH+1];
DWORD fsFlags;
/* symlinks only supported on vista or greater */
if( !isVistaOrLater() ){
return 0;
}
/* next we need to check to see if the privilege is available */
/* can't check privilege if we can't lookup its value */
if( !LookupPrivilegeValue(NULL, SE_CREATE_SYMBOLIC_LINK_NAME, &luid) ){
return 0;
}
/* can't check privilege if we can't open the process token */
process = GetCurrentProcess();
if( !OpenProcessToken(process, TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &token) ){
return 0;
}
/* by this point, we have a process token and the privilege value */
/* try to enable the privilege then close the token */
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(token, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL);
status = GetLastError();
CloseHandle(token);
/* any error means we failed to enable the privilege, symlinks not supported */
if( status != ERROR_SUCCESS ){
return 0;
}
/* assume no support for symlinks */
success = 0;
pFilename = fossil_utf8_to_filename(zFilename);
/* given the filename we're interested in, symlinks are supported if */
/* 1. we can get the full name of the path from the given path */
fullLength = GetFullPathNameW(pFilename, sizeof(fullName), fullName, NULL);
if( (fullLength > 0) && (fullLength < sizeof(fullName)) ){
/* 2. we can get the volume path name from the full name */
if( GetVolumePathNameW(fullName, volName, sizeof(volName)) ){
/* 3. we can get volume information from the volume path name */
if( GetVolumeInformationW(volName, NULL, 0, NULL, NULL, &fsFlags, NULL, 0) ){
/* 4. the given volume support reparse points */
if( fsFlags & FILE_SUPPORTS_REPARSE_POINTS ){
/* all four conditions were true, so we support symlinks; success! */
success = 1;
}
}
}
}
fossil_filename_free(pFilename);
return success;
}
/*
** Wrapper around the access() system call. This code was copied from Tcl
** 8.6 and then modified.
*/
int win32_access(const wchar_t *zFilename, int flags){
|