ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/SambaPermissionify/SambaPermissionify.cpp
Revision: 449
Committed: 2005-05-17T20:06:45-07:00 (20 years, 1 month ago) by douglas
File size: 1942 byte(s)
Log Message:
Whatever!

File Contents

# Content
1 // Douglas Thrift
2 //
3 // Samba Permissionify
4 //
5 // $Id$
6
7 #include <iostream>
8 #include <string>
9
10 #include <aclapi.h>
11 #include <sddl.h>
12
13 int main(int argc, char* argv[])
14 {
15 std::wstring file(L"\\\\daemon\\douglas\\Music\\Sugarcult\\Five\\05 Bruises.wma");
16 PSID owner, group;
17 PSECURITY_DESCRIPTOR descriptor;
18
19 if (unsigned long code = GetNamedSecurityInfo(const_cast<LPTSTR>(file.c_str()), SE_FILE_OBJECT, GROUP_SECURITY_INFORMATION | OWNER_SECURITY_INFORMATION, &owner, &group, NULL, NULL, &descriptor) != ERROR_SUCCESS)
20 {
21 std::cout << code << std::endl;
22
23 return 1;
24 }
25
26 unsigned long sizeName(32), sizeDomain(32);
27 std::wstring ownerName(sizeName, L'\0'), ownerDomain(sizeDomain, L'\0');
28 SID_NAME_USE ownerType;
29
30 if (!LookupAccountSid(const_cast<LPWSTR>(file.substr(2, 6).data()), owner, const_cast<LPWSTR>(ownerName.data()), &sizeName, const_cast<LPWSTR>(ownerDomain.data()), &sizeDomain, &ownerType))
31 {
32 std::cout << GetLastError() << std::endl;
33
34 return 1;
35 }
36
37 ownerName.resize(sizeName);
38 ownerDomain.resize(sizeDomain);
39
40 wchar_t* ownerPermission;
41
42 if (!ConvertSecurityDescriptorToStringSecurityDescriptor(descriptor, SDDL_REVISION_1, OWNER_SECURITY_INFORMATION, &ownerPermission, NULL))
43 {
44 std::cout << GetLastError() << std::endl;
45
46 return 1;
47 }
48
49 std::wcout << ownerDomain << '\\' << ownerName << ' ' << ownerPermission << std::endl;
50
51 LocalFree(ownerPermission);
52
53 sizeName = 32;
54 sizeDomain = 32;
55
56 std::wstring groupName(sizeName, L'\0'), groupDomain(sizeDomain, L'\0');
57 SID_NAME_USE groupType;
58
59 if (!LookupAccountSid(const_cast<LPWSTR>(file.substr(2, 6).data()), group, const_cast<LPWSTR>(groupName.data()), &sizeName, const_cast<LPWSTR>(groupDomain.data()), &sizeDomain, &groupType))
60 {
61 std::cout << GetLastError() << std::endl;
62
63 return 1;
64 }
65
66 groupName.resize(sizeName);
67 groupDomain.resize(sizeDomain);
68
69 std::wcout << groupDomain << '\\' << groupName << std::endl;
70
71 LocalFree(descriptor);
72
73 return 0;
74 }

Properties

Name Value
svn:eol-style native
svn:keywords Id