Get Fat Emacs working in Windows Console

This commit is contained in:
Justine Tunney 2023-08-18 04:55:57 -07:00
parent bf835de612
commit 7100b1cf91
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
34 changed files with 479 additions and 168 deletions

View file

@ -39,13 +39,11 @@
#include "libc/sysv/consts/ok.h"
#include "libc/sysv/errfuns.h"
// TODO: what does this code do with symlinks?
/**
* Asks Microsoft if we're authorized to use a folder or file.
*
* Implementation Details: MSDN documentation imposes no limit on the
* internal size of SECURITY_DESCRIPTOR, which we are responsible for
* allocating. We've selected 1024 which shall hopefully be adequate.
*
* @param flags can have R_OK, W_OK, X_OK, etc.
* @return 0 if authorized, or -1 w/ errno
* @see https://blog.aaronballman.com/2011/08/how-to-check-access-rights/
@ -86,25 +84,28 @@ TryAgain:
&hToken)) {
if (DuplicateToken(hToken, kNtSecurityImpersonation,
&hImpersonatedToken)) {
if (flags == kNtGenericExecute) { // X_OK
flags |= kNtGenericRead; // R_OK
}
if (AccessCheck(s, hImpersonatedToken, flags, &mapping, &privileges,
&privsize, &granted, &result)) {
if (result || flags == F_OK) {
rc = 0;
} else {
STRACE("ntaccesscheck finale failed %d %d", result, flags);
NTTRACE("ntaccesscheck finale failed %d %x", result, flags);
rc = eacces();
}
} else {
rc = __winerr();
STRACE("%s(%#hs) failed: %m", "AccessCheck", pathname);
NTTRACE("%s(%#hs) failed: %m", "AccessCheck", pathname);
}
} else {
rc = __winerr();
STRACE("%s(%#hs) failed: %m", "DuplicateToken", pathname);
NTTRACE("%s(%#hs) failed: %m", "DuplicateToken", pathname);
}
} else {
rc = __winerr();
STRACE("%s(%#hs) failed: %m", "OpenProcessToken", pathname);
NTTRACE("%s(%#hs) failed: %m", "OpenProcessToken", pathname);
}
} else {
e = GetLastError();
@ -114,11 +115,11 @@ TryAgain:
goto TryAgain;
} else {
rc = enomem();
STRACE("%s(%#hs) failed: %m", "GetFileSecurity", pathname);
NTTRACE("%s(%#hs) failed: %m", "GetFileSecurity", pathname);
}
} else {
errno = e;
STRACE("%s(%#hs) failed: %m", "GetFileSecurity", pathname);
NTTRACE("%s(%#hs) failed: %m", "GetFileSecurity", pathname);
rc = -1;
}
}