// Douglas Thrift // // Samba Permissionify // // $Id$ #include #include #include #include int main(int argc, char* argv[]) { std::wstring file(L"\\\\daemon\\douglas\\Music\\Sugarcult\\Five\\05 Bruises.wma"); PSID owner, group; PSECURITY_DESCRIPTOR descriptor; if (unsigned long code = GetNamedSecurityInfo(const_cast(file.c_str()), SE_FILE_OBJECT, GROUP_SECURITY_INFORMATION | OWNER_SECURITY_INFORMATION, &owner, &group, NULL, NULL, &descriptor) != ERROR_SUCCESS) { std::cout << code << std::endl; return 1; } unsigned long sizeName(32), sizeDomain(32); std::wstring ownerName(sizeName, L'\0'), ownerDomain(sizeDomain, L'\0'); SID_NAME_USE ownerType; if (!LookupAccountSid(const_cast(file.substr(2, 6).data()), owner, const_cast(ownerName.data()), &sizeName, const_cast(ownerDomain.data()), &sizeDomain, &ownerType)) { std::cout << GetLastError() << std::endl; return 1; } ownerName.resize(sizeName); ownerDomain.resize(sizeDomain); wchar_t* ownerPermission; if (!ConvertSecurityDescriptorToStringSecurityDescriptor(descriptor, SDDL_REVISION_1, OWNER_SECURITY_INFORMATION, &ownerPermission, NULL)) { std::cout << GetLastError() << std::endl; return 1; } std::wcout << ownerDomain << '\\' << ownerName << ' ' << ownerPermission << std::endl; LocalFree(ownerPermission); sizeName = 32; sizeDomain = 32; std::wstring groupName(sizeName, L'\0'), groupDomain(sizeDomain, L'\0'); SID_NAME_USE groupType; if (!LookupAccountSid(const_cast(file.substr(2, 6).data()), group, const_cast(groupName.data()), &sizeName, const_cast(groupDomain.data()), &sizeDomain, &groupType)) { std::cout << GetLastError() << std::endl; return 1; } groupName.resize(sizeName); groupDomain.resize(sizeDomain); std::wcout << groupDomain << '\\' << groupName << std::endl; LocalFree(descriptor); return 0; }