Register::Register(PCWSTR path, HKEY hkey, ACCESS_MASK acc): m_hndl(nullptr), m_access(acc) { // LogDebug(L"path: '%s'\n", path); if (acc & KEY_READ) CheckApiError(::RegOpenKeyExW(hkey, path, 0, acc, &m_hndl)); else CheckApiError(::RegCreateKeyExW(hkey, path, 0, nullptr, 0, acc, 0, &m_hndl, 0)); }
ustring ExpAccess::get_name() const { TRUSTEE_FORM tf = ::GetTrusteeFormW((PTRUSTEEW)&Trustee); if (tf == TRUSTEE_IS_NAME) return ustring(::GetTrusteeNameW((PTRUSTEEW)&Trustee)); else if (tf != TRUSTEE_IS_SID) CheckApiError(ERROR_INVALID_PARAMETER); return Sid((PSID)Trustee.ptstrName).get_name(); }
///====================================================================================== Method Method::Method(const Lib & arc_lib, size_t idx) { Com::PropVariant prop; CheckApiError(arc_lib.GetMethodProperty(idx, 0, prop.ref())); id = prop.as_uint(); CheckApiError(arc_lib.GetMethodProperty(idx, 1, prop.ref())); name = prop.as_str(); arc_lib.GetMethodProperty(idx, 2, prop.ref()); if (prop.vt == VT_BSTR) { size_t len = ::SysStringByteLen(prop.bstrVal); BYTE* data = reinterpret_cast<BYTE*>(prop.bstrVal); start_sign.assign(&data[0], &data[len]); }; arc_lib.GetMethodProperty(idx, 3, prop.ref()); if (prop.vt == VT_BSTR) { size_t len = ::SysStringByteLen(prop.bstrVal); BYTE* data = reinterpret_cast<BYTE*>(prop.bstrVal); finish_sign.assign(&data[0], &data[len]); }; }
void User::add(const ustring & name, const ustring & pass, const ustring & dom) { DWORD dwLevel = 1; USER_INFO_1 info = {0}; info.usri1_name = const_cast<wchar_t*>(name.c_str()); info.usri1_password = const_cast<wchar_t*>(pass.c_str()); info.usri1_priv = USER_PRIV_USER; info.usri1_flags = UF_SCRIPT | UF_NORMAL_ACCOUNT | UF_DONT_EXPIRE_PASSWD; if (pass.empty()) info.usri1_flags |= UF_PASSWD_NOTREQD; CheckApiError(::NetUserAdd(dom.c_str(), dwLevel, (PBYTE)&info, nullptr)); }
ShellLink::ShellLink(PCWSTR path, bool write) : m_path(path) { Object<IPersistFile> ppf; CheckApiError(::CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_IPersistFile, (PVOID* )&ppf)); CheckCom(ppf->Load(m_path.c_str(), write ? STGM_READWRITE : STGM_READ)); CheckCom(ppf->QueryInterface(IID_IShellLink, (PVOID*)&m_lnk)); CheckCom(m_lnk->Resolve(NULL, SLR_ANY_MATCH | SLR_NO_UI)); }
void set_dacl(PCWSTR path, PSECURITY_DESCRIPTOR sd, SE_OBJECT_TYPE type) { WORD control = WinSD::get_control(sd); if (bits::Flags::check(control, (WORD)SE_DACL_PRESENT)) { DWORD flag = (bits::Flags::check(control, (WORD)SE_DACL_PROTECTED)) ? PROTECTED_DACL_SECURITY_INFORMATION : UNPROTECTED_DACL_SECURITY_INFORMATION; CheckApiError(::SetNamedSecurityInfoW((PWSTR)path, type, DACL_SECURITY_INFORMATION | flag, nullptr, nullptr, WinSD::get_dacl(sd), nullptr)); } }
Item::this_type& Item::wait_state(State state, DWORD dwTimeout) { DWORD dwStartTime = ::GetTickCount(); while (true) { Status ssp(get_status()); if (ssp.dwCurrentState == (DWORD)state) break; if (::GetTickCount() - dwStartTime > dwTimeout) CheckApiError(WAIT_TIMEOUT); ::Sleep(500); }; return *this; }
void Archive::open_archive(const Lib & lib, const ustring & path) { LogNoise(L"%p, '%s'\n", &lib, path.c_str()); Com::Object<IInStream> stream(new FileReadStream(path)); Com::Object<IArchiveOpenCallback> openCallback(new OpenCallback); for (auto it = lib.codecs().begin(); it != lib.codecs().end(); ++it) { LogNoise(L"codec: '%s'\n", it->name.c_str()); CheckCom(stream->Seek(0, STREAM_SEEK_SET, nullptr)); CheckCom(lib.CreateObject(&it->guid, &IID_IInArchive, (PVOID*)&m_arc)); if (m_arc->Open(stream, &max_check_size, openCallback) == S_OK) { m_codec = it; return; } } CheckApiError(ERROR_INVALID_DATA); }
WinSD::WinSD(const trustee_t & owner, const trustee_t & group, const ExpAccessArray * dacl, const ExpAccessArray * sacl) { ULONG size = 0; LogTrace(); CheckApiError( ::BuildSecurityDescriptorW( (PTRUSTEEW)&owner, (PTRUSTEEW)&group, dacl ? dacl->size() : 0, (PEXPLICIT_ACCESS_W)dacl ? &(*dacl)[0] : nullptr, sacl ? sacl->size() : 0, (PEXPLICIT_ACCESS_W)sacl ? &(*sacl)[0] : nullptr, nullptr, &size, &m_sd )); }
void set_security(HANDLE hnd, PSECURITY_DESCRIPTOR sd, SE_OBJECT_TYPE type) { DWORD flag = 0; PSID owner = WinSD::get_owner(sd); if (owner) flag |= OWNER_SECURITY_INFORMATION; PSID group = WinSD::get_group(sd); if (group) flag |= GROUP_SECURITY_INFORMATION; WORD control = WinSD::get_control(sd); PACL dacl = nullptr; if (bits::Flags::check(control, (WORD)SE_DACL_PRESENT)) { dacl = WinSD::get_dacl(sd); flag |= DACL_SECURITY_INFORMATION; flag |= (bits::Flags::check(control, (WORD)SE_DACL_PROTECTED)) ? PROTECTED_DACL_SECURITY_INFORMATION : UNPROTECTED_DACL_SECURITY_INFORMATION; } PACL sacl = nullptr; // if (WinFlag::Check(control, (WORD)SE_SACL_PRESENT)) { // sacl = WinSD::get_sacl(sd); // flag |= SACL_SECURITY_INFORMATION; // flag |= (WinFlag::Check(control, (WORD)SE_SACL_PROTECTED)) ? // PROTECTED_SACL_SECURITY_INFORMATION : UNPROTECTED_SACL_SECURITY_INFORMATION; // } DWORD err = ::SetSecurityInfo(hnd, type, flag, owner, group, dacl, sacl); if (err == ERROR_INVALID_OWNER) { WinPriv::modify(SE_TAKE_OWNERSHIP_NAME, true); WinPriv::modify(SE_RESTORE_NAME, true); err = ::SetSecurityInfo(hnd, type, flag, owner, group, dacl, sacl); } CheckApiError(err); }
void set_pass_age(size_t age, PCWSTR srv) { USER_MODALS_INFO_1002 info = {(DWORD)age}; CheckApiError(::NetUserModalsSet(srv, 1002, (PBYTE)&info, nullptr)); }
void set_pass_length(size_t len, PCWSTR srv) { USER_MODALS_INFO_1001 info = {(DWORD)len}; CheckApiError(::NetUserModalsSet(srv, 1001, (PBYTE)&info, nullptr)); }
static void set_info(const ustring& name, const ustring& dom, DWORD level, PVOID info) { CheckApiError(::NetUserSetInfo(dom.c_str(), name.c_str(), level, (PBYTE)info, nullptr)); }
void User::del(const ustring& name, const ustring& dom) { CheckApiError(::NetUserDel(dom.c_str(), name.c_str())); }
Sid ExpAccess::get_sid() const { if (::GetTrusteeFormW((PTRUSTEEW)&Trustee) != TRUSTEE_IS_SID) CheckApiError(ERROR_INVALID_PARAMETER); return Sid((PSID)Trustee.ptstrName); }
void Group::add(const ustring& name, const ustring& comm, const ustring& dom) { const DWORD level = 1; LOCALGROUP_INFO_1 info = {const_cast<PWSTR>(name.c_str()), const_cast<PWSTR>(comm.c_str())}; CheckApiError(::NetLocalGroupAdd(dom.c_str(), level, (PBYTE )&info, nullptr)); }
void WinSDW::Get() { free(m_sd); CheckApiError(::GetNamedSecurityInfoW((PWSTR)m_name.c_str(), m_type, ALL_SD_INFO, nullptr, nullptr, nullptr, nullptr, &m_sd)); }
void Archive::init_props() { LogTrace(); CheckApiError(m_arc->GetNumberOfItems(&m_size)); m_props.cache(m_arc); }
GroupBuf(const ustring& name, const ustring& dom = ustring()) : info(nullptr) { CheckApiError(::NetLocalGroupGetInfo(dom.c_str(), name.c_str(), level, (PBYTE* )&info)); }
void Register::set(PCWSTR name, uint64_t value) { CheckApiError(::RegSetValueExW(m_hndl, name, 0, REG_QWORD, (PBYTE)&value, sizeof(value))); }
void Register::set(PCWSTR name, PCWSTR value) { CheckApiError(::RegSetValueExW(m_hndl, name, 0, REG_SZ, (PBYTE)&value, (cstr::length(value) + 1) * sizeof(wchar_t))); }
void Register::set(PCWSTR name, const void* value, size_t size) { CheckApiError(::RegSetValueExW(m_hndl, name, 0, REG_BINARY, (PBYTE)&value, size)); }
UserBuf(const ustring& name, const ustring& dom = ustring()) { CheckApiError(::NetUserGetInfo(dom.c_str(), name.c_str(), 3, (PBYTE*)&info)); }
void Group::del_member(const ustring& name, const Sid & user, const ustring& dom) { const DWORD level = 0; LOCALGROUP_MEMBERS_INFO_0 info = {user}; CheckApiError(::NetLocalGroupDelMembers(dom.c_str(), name.c_str(), level, (PBYTE )&info, 1)); }
void set(const ustring& name, const ustring& dom = ustring()) { CheckApiError(::NetUserSetInfo(dom.c_str(), name.c_str(), 3, (PBYTE)info, nullptr)); }
void Group::set_name(const ustring& name, const ustring& in, const ustring& dom) { const DWORD level = 0; LOCALGROUP_INFO_0 info = {const_cast<PWSTR>(in.c_str())}; CheckApiError(::NetLocalGroupSetInfo(dom.c_str(), name.c_str(), level, (PBYTE )&info, nullptr)); }
void WinSDH::Get() { free(m_sd); CheckApiError(::GetSecurityInfo(m_hnd, m_type, ALL_SD_INFO, nullptr, nullptr, nullptr, nullptr, &m_sd)); }
void Group::del(const ustring& name, const ustring& dom) { CheckApiError(::NetLocalGroupDel(dom.c_str(), name.c_str())); }