mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
Some hacks to do with unsupported file ownership detection in mingw
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@13620 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
58d0257a97
commit
3f1f110b1a
2 changed files with 138 additions and 0 deletions
|
@ -64,6 +64,8 @@
|
|||
#endif
|
||||
|
||||
#if defined(__MINGW__)
|
||||
#include <stdio.h>
|
||||
#include <tchar.h>
|
||||
#define WIN32ERR ((DWORD)0xFFFFFFFF)
|
||||
#endif
|
||||
|
||||
|
@ -2223,6 +2225,139 @@ static int sparc_warn = 0;
|
|||
|
||||
if (copy == NO)
|
||||
{
|
||||
#ifdef __MINGW_NOT_AVAILABLE_YET
|
||||
|
||||
|
||||
{
|
||||
DWORD dwRtnCode = 0;
|
||||
PSID pSidOwner;
|
||||
BOOL bRtnBool = TRUE;
|
||||
LPTSTR AcctName, DomainName;
|
||||
DWORD dwAcctName = 1, dwDomainName = 1;
|
||||
SID_NAME_USE eUse = SidTypeUnknown;
|
||||
HANDLE hFile;
|
||||
PSECURITY_DESCRIPTOR pSD;
|
||||
|
||||
// Get the handle of the file object.
|
||||
hFile = CreateFile(
|
||||
"myfile.txt",
|
||||
GENERIC_READ,
|
||||
FILE_SHARE_READ,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
NULL);
|
||||
|
||||
// Check GetLastError for CreateFile error code.
|
||||
if (hFile == INVALID_HANDLE_VALUE) {
|
||||
DWORD dwErrorCode = 0;
|
||||
|
||||
dwErrorCode = GetLastError();
|
||||
_tprintf(TEXT("CreateFile error = %d\n"), dwErrorCode);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Allocate memory for the SID structure.
|
||||
pSidOwner = (PSID)GlobalAlloc(
|
||||
GMEM_FIXED,
|
||||
sizeof(PSID));
|
||||
|
||||
// Allocate memory for the security descriptor structure.
|
||||
pSD = (PSECURITY_DESCRIPTOR)GlobalAlloc(
|
||||
GMEM_FIXED,
|
||||
sizeof(PSECURITY_DESCRIPTOR));
|
||||
|
||||
// Get the owner SID of the file.
|
||||
dwRtnCode = GetSecurityInfo(
|
||||
hFile,
|
||||
SE_FILE_OBJECT,
|
||||
OWNER_SECURITY_INFORMATION,
|
||||
&pSidOwner,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
&pSD);
|
||||
|
||||
// Check GetLastError for GetSecurityInfo error condition.
|
||||
if (dwRtnCode != ERROR_SUCCESS) {
|
||||
DWORD dwErrorCode = 0;
|
||||
|
||||
dwErrorCode = GetLastError();
|
||||
_tprintf(TEXT("GetSecurityInfo error = %d\n"), dwErrorCode);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// First call to LookupAccountSid to get the buffer sizes.
|
||||
bRtnBool = LookupAccountSid(
|
||||
NULL, // local computer
|
||||
pSidOwner,
|
||||
AcctName,
|
||||
(LPDWORD)&dwAcctName,
|
||||
DomainName,
|
||||
(LPDWORD)&dwDomainName,
|
||||
&eUse);
|
||||
|
||||
// Reallocate memory for the buffers.
|
||||
AcctName = (char *)GlobalAlloc(
|
||||
GMEM_FIXED,
|
||||
dwAcctName);
|
||||
|
||||
// Check GetLastError for GlobalAlloc error condition.
|
||||
if (AcctName == NULL) {
|
||||
DWORD dwErrorCode = 0;
|
||||
|
||||
dwErrorCode = GetLastError();
|
||||
_tprintf(TEXT("GlobalAlloc error = %d\n"), dwErrorCode);
|
||||
return -1;
|
||||
}
|
||||
|
||||
DomainName = (char *)GlobalAlloc(
|
||||
GMEM_FIXED,
|
||||
dwDomainName);
|
||||
|
||||
// Check GetLastError for GlobalAlloc error condition.
|
||||
if (DomainName == NULL) {
|
||||
DWORD dwErrorCode = 0;
|
||||
|
||||
dwErrorCode = GetLastError();
|
||||
_tprintf(TEXT("GlobalAlloc error = %d\n"), dwErrorCode);
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
// Second call to LookupAccountSid to get the account name.
|
||||
bRtnBool = LookupAccountSid(
|
||||
NULL, // name of local or remote computer
|
||||
pSidOwner, // security identifier
|
||||
AcctName, // account name buffer
|
||||
(LPDWORD)&dwAcctName, // size of account name buffer
|
||||
DomainName, // domain name
|
||||
(LPDWORD)&dwDomainName, // size of domain name buffer
|
||||
&eUse); // SID type
|
||||
|
||||
// Check GetLastError for LookupAccountSid error condition.
|
||||
if (bRtnBool == FALSE) {
|
||||
DWORD dwErrorCode = 0;
|
||||
|
||||
dwErrorCode = GetLastError();
|
||||
|
||||
if (dwErrorCode == ERROR_NONE_MAPPED)
|
||||
_tprintf(TEXT("Account owner not found for specified SID.\n"));
|
||||
else
|
||||
_tprintf(TEXT("Error in LookupAccountSid.\n"));
|
||||
return -1;
|
||||
|
||||
} else if (bRtnBool == TRUE)
|
||||
|
||||
// Print the account name.
|
||||
_tprintf(TEXT("Account owner = %s\n"), AcctName);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
#ifdef HAVE_PWD_H
|
||||
{
|
||||
struct passwd *pw;
|
||||
|
|
|
@ -587,11 +587,14 @@ userDirectory(NSString *name, BOOL defaults)
|
|||
fprintf(stderr, "The file '%s' is writable by someone other than"
|
||||
" its owner.\nIgnoring it.\n", [file fileSystemRepresentation]);
|
||||
}
|
||||
#ifndef __MINGW__
|
||||
/* FIXME ... need to get mingw working */
|
||||
else if ([[attributes fileOwnerAccountName] isEqual: NSUserName()] == NO)
|
||||
{
|
||||
fprintf(stderr, "The file '%s' is not owned by the current user."
|
||||
"\nIgnoring it.\n", [file fileSystemRepresentation]);
|
||||
}
|
||||
#endif
|
||||
else if ([manager isReadableFileAtPath: file] == YES)
|
||||
{
|
||||
NSArray *lines;
|
||||
|
|
Loading…
Reference in a new issue