name_size =
sizeof(name) /
sizeof(name[0]) - 1;
69name[name_size] =
_TX(
'\0');
83 DWORDdomain_size = 0;
89 if( !::LookupAccountName(
NULL, name.c_str(), sid, &sid_size, domain, &domain_size, &use) ) {
90 DWORDerr = ::GetLastError();
91 if(err != ERROR_INSUFFICIENT_BUFFER) {
98sid = (PSID) LocalAlloc(LMEM_FIXED, sid_size);
100 if( !sid || !domain ) {
104 if( !LookupAccountName(
NULL, name.c_str(), sid, &sid_size, domain, &domain_size, &use) ) {
119 if( domain )
free(domain);
138 DWORDaccount_size =
sizeof(account_name)/
sizeof(account_name[0]) - 1;
139 DWORDdomain_size =
sizeof(domain_name)/
sizeof(domain_name[0]) - 1;
145 if( !::LookupAccountSid(
NULL, sid,
146account_name, &account_size,
147domain_name, &domain_size, &use) ) {
154account_name[account_size] =
_TX(
'\0');
159 if(*domatch !=
int(use)) {
162domain_name[domain_size] =
_TX(
'\0');
179 string* owner_name,
string* group_name,
180 unsigned int* uid,
unsigned int* gid)
182 boolsuccess =
true;
186 int match= SidTypeUser;
195*uid += *::GetSidSubAuthority(owner_sid, *::GetSidSubAuthorityCount(owner_sid) - 1);
199 int match= SidTypeGroup;
206*gid += *::GetSidSubAuthority(group_sid, *::GetSidSubAuthorityCount(group_sid) - 1);
228SE_OBJECT_TYPE obj_type,
229 string* owner,
string* group,
230 unsigned int* uid,
unsigned int* gid)
234PSECURITY_DESCRIPTOR sd;
237&sid_owner, &sid_group,
NULL,
NULL, &sd);
238 if( res != ERROR_SUCCESS ) {
249SE_OBJECT_TYPE obj_type,
250 string* owner,
string* group,
251 unsigned int* uid,
unsigned int* gid)
255PSECURITY_DESCRIPTOR sd;
259&sid_owner, &sid_group,
NULL,
NULL, &sd);
260 if( res != ERROR_SUCCESS ) {
275 if( !::OpenThreadToken(GetCurrentThread(), access,
FALSE, &token) ) {
276 DWORDres = GetLastError();
277 if( res == ERROR_NO_TOKEN ) {
278 if( !::ImpersonateSelf(SecurityImpersonation) ) {
283 if( !::OpenThreadToken(GetCurrentThread(), access,
FALSE, &token) ) {
300 const string& owner,
const string& group,
301 unsigned int* uid,
unsigned int* gid)
303 _ASSERT(!owner.empty() || !group.empty());
306PSID owner_sid =
NULL;
307PSID group_sid =
NULL;
308 boolsuccess =
false;
309SECURITY_INFORMATION security_info = 0;
312 if( !owner.empty() ) {
318 if( !group.empty() ) {
331security_info |= OWNER_SECURITY_INFORMATION;
334security_info |= GROUP_SECURITY_INFORMATION;
339SE_FILE_OBJECT, security_info,
340owner_sid, group_sid,
NULL,
NULL) == ERROR_SUCCESS ) {
351 boolprev_ownership_name;
352 boolprev_restore_name;
354 if( !
SetTokenPrivilege(token, SE_TAKE_OWNERSHIP_NAME,
true, &prev_ownership_name) ) {
361SE_FILE_OBJECT, security_info,
362owner_sid, group_sid,
NULL,
NULL) == ERROR_SUCCESS ) {
372 if( group_sid ) ::LocalFree(group_sid);
373 if( owner_sid ) ::LocalFree(owner_sid);
380 boolenable,
bool*
prev)
384 if( !::LookupPrivilegeValue(
NULL, privilege, &luid) ) {
392TOKEN_PRIVILEGES tp_prev;
393 DWORDtp_size =
sizeof(tp);
395tp.PrivilegeCount = 1;
396tp.Privileges[0].Luid = luid;
397tp.Privileges[0].Attributes = 0;
399::AdjustTokenPrivileges(token,
FALSE, &tp, tp_size, &tp_prev, &tp_size);
400 DWORDres = GetLastError();
401 if( res != ERROR_SUCCESS ) {
409tp.PrivilegeCount = 1;
410tp.Privileges[0].Luid = luid;
412*
prev= ((tp_prev.Privileges[0].Attributes & SE_PRIVILEGE_ENABLED) == SE_PRIVILEGE_ENABLED);
414tp.Privileges[0].Attributes = enable ? SE_PRIVILEGE_ENABLED : 0;
416::AdjustTokenPrivileges(token,
FALSE, &tp, tp_size,
NULL,
NULL);
417res = GetLastError();
418 if( res != ERROR_SUCCESS ) {
444 if( path.empty() ) {
448PSECURITY_DESCRIPTOR sd =
NULL;
453 DWORDerr = ::GetLastError();
454 if(err != ERROR_INSUFFICIENT_BUFFER) {
459sd = (PSECURITY_DESCRIPTOR) ::LocalAlloc(LMEM_FIXED, size_need);
467::LocalFree((HLOCAL) sd);
481 if( !permissions ) {
497 boolsuccess =
true;
505GENERIC_MAPPING mapping;
506memset(&mapping, 0,
sizeof(mapping));
508PRIVILEGE_SET privileges;
509 DWORDprivileges_size =
sizeof(privileges);
512 if( !::AccessCheck(sd, token, MAXIMUM_ALLOWED, &mapping,
513&privileges, &privileges_size, permissions,
514&status) || !status ) {
524::CloseHandle(token);
534 HANDLE constsnapshot = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
537entry.dwSize =
sizeof(PROCESSENTRY32);
538 BOOLret = ::Process32First(snapshot, &entry);
539 while(ret && entry.th32ProcessID !=
id) {
540ret = ::Process32Next(snapshot, &entry);
542::CloseHandle(snapshot);
static bool FindProcessEntry(DWORD id, PROCESSENTRY32 &entry)
Find process entry information by process identifier (pid).
static bool GetFilePermissions(const string &path, ACCESS_MASK *permissions)
Get file access permissions.
static string GetUserName(void)
Get name of the current user.
static bool SetTokenPrivilege(HANDLE token, LPCTSTR privilege, bool enable, bool *prev=0)
Enables or disables privileges in the specified access token.
static bool SetFileOwner(const string &filename, const string &owner, const string &group=kEmptyStr, unsigned int *uid=0, unsigned int *gid=0)
Set file object owner.
static bool GetObjectOwner(const string &obj_name, SE_OBJECT_TYPE obj_type, string *owner, string *group, unsigned int *uid=0, unsigned int *gid=0)
Get owner name of specified system object.
static bool SetThreadPrivilege(LPCTSTR privilege, bool enable, bool *prev=0)
Enables or disables privileges for the current thread.
The NCBI C++ standard methods for dealing with std::string.
static void cleanup(void)
static DLIST_TYPE *DLIST_NAME() prev(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
static void SetFromWindowsError(void)
Set last error on MS Windows using GetLastError()
static void Set(ECode code)
Set last error using native error code enum.
static const CNcbiError & GetLast(void)
Get the error that was last set (in the current thread)
static void SetWindowsError(int native_err_code)
Set last error using Windows-specific error code.
@ eUnknown
Unknown error.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
static SIZE_TYPE FindNoCase(const CTempString str, const CTempString pattern, SIZE_TYPE start, SIZE_TYPE end, EOccurrence which=eFirst)
Find the pattern in the specified range of a string using a case insensitive search.
static bool EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
#define INVALID_HANDLE_VALUE
A value for an invalid file handle.
#define HANDLE
An abstraction for a file handle.
const struct ncbi::grid::netcache::search::fields::SIZE size
#define FILE_SECURITY_INFO
static PSID x_GetAccountSidByName(const string &account, SID_NAME_USE type=(SID_NAME_USE) 0)
#define CYGWIN_PRIMARY_ID_OFFSET
static bool x_GetAccountNameBySid(PSID sid, string *account, int *domatch=0)
static bool s_GetOwnerGroupFromSIDs(PSID owner_sid, PSID group_sid, string *owner_name, string *group_name, unsigned int *uid, unsigned int *gid)
static HANDLE s_GetCurrentThreadToken(DWORD access)
static PSECURITY_DESCRIPTOR s_GetFileSecurityDescriptor(const string &path)
#define ACCOUNT_SECURITY_INFO
Defines MS Windows specific private functions and classes.
#define FALSE
bool replacment for C indicating false.
Defines NCBI C++ diagnostic APIs, classes, and macros.
Defines NCBI C++ Toolkit portable error codes.
static int match(PCRE2_SPTR start_eptr, PCRE2_SPTR start_ecode, uint16_t top_bracket, PCRE2_SIZE frame_size, pcre2_match_data *match_data, match_block *mb)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4