}
#ifdef G_OS_WIN32
-void
+static void
win32_get_file_user_info (const gchar* filename,
gchar **group_name,
gchar **user_name,
gchar **real_name)
{
PSECURITY_DESCRIPTOR psd = NULL;
- DWORD sd_size = 0; /* first call calculates the size rewuired */
+ DWORD sd_size = 0; /* first call calculates the size required */
wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
if ((GetFileSecurityW (wfilename,
&sd_size) || (ERROR_INSUFFICIENT_BUFFER == GetLastError())) &&
(psd = g_try_malloc (sd_size)) != NULL &&
GetFileSecurityW (wfilename,
- GROUP_SECURITY_INFORMATION | OWNER_SECURITY_INFORMATION,
- psd,
- sd_size,
- &sd_size))
- {
- PSID psid = 0;
- SID_NAME_USE name_use; /* don't care? */
- char *name = NULL;
- DWORD name_len = 0;
- if (user_name &&
- GetSecurityDescriptorOwner (psd, &psid, NULL) &&
- (LookupAccountSid (NULL, /* local machine */
- psid,
- name, &name_len,
- NULL, NULL, /* no domain info yet */
- &name_use) || (ERROR_INSUFFICIENT_BUFFER == GetLastError())) &&
- (name = g_try_malloc (name_len)) != NULL &&
- LookupAccountSid (NULL, /* local machine */
- psid,
- name, &name_len,
- NULL, NULL, /* no domain info yet */
- &name_use))
- {
- *user_name = name;
- }
- g_free (psd);
+ GROUP_SECURITY_INFORMATION | OWNER_SECURITY_INFORMATION,
+ psd,
+ sd_size,
+ &sd_size))
+ {
+ PSID psid = 0;\r
+ BOOL defaulted;
+ SID_NAME_USE name_use = 0; /* don't care? */
+ wchar_t *name = NULL;\r
+ wchar_t *domain = NULL;\r
+ DWORD name_len = 0;\r
+ DWORD domain_len = 0;\r
+ /* get the user name */\r
+ do {\r
+ if (!user_name)\r
+ break;\r
+ if (!GetSecurityDescriptorOwner (psd, &psid, &defaulted))\r
+ break;\r
+ if (!LookupAccountSidW (NULL, /* local machine */\r
+ psid, \r
+ name, &name_len,\r
+ domain, &domain_len, /* no domain info yet */\r
+ &name_use) && (ERROR_INSUFFICIENT_BUFFER != GetLastError()))\r
+ break;\r
+ name = g_try_malloc (name_len*sizeof(wchar_t));\r
+ domain = g_try_malloc (domain_len*sizeof(wchar_t));\r
+ if (name && domain &&\r
+ LookupAccountSidW (NULL, /* local machine */\r
+ psid, \r
+ name, &name_len,\r
+ domain, &domain_len, /* no domain info yet */\r
+ &name_use))\r
+ {\r
+ *user_name = g_utf16_to_utf8 (name, -1, NULL, NULL, NULL);\r
+ }\r
+ g_free (name);\r
+ g_free (domain);\r
+ } while (FALSE);\r
+\r
+ /* get the group name */\r
+ do {\r
+ if (!group_name)\r
+ break;\r
+ if (!GetSecurityDescriptorGroup (psd, &psid, &defaulted))\r
+ break;\r
+ if (!LookupAccountSidW (NULL, /* local machine */\r
+ psid, \r
+ name, &name_len,\r
+ domain, &domain_len, /* no domain info yet */\r
+ &name_use) && (ERROR_INSUFFICIENT_BUFFER != GetLastError()))\r
+ break;\r
+ name = g_try_malloc (name_len*sizeof(wchar_t));\r
+ domain = g_try_malloc (domain_len*sizeof(wchar_t));\r
+ if (name && domain &&\r
+ LookupAccountSidW (NULL, /* local machine */\r
+ psid, \r
+ name, &name_len,\r
+ domain, &domain_len, /* no domain info yet */\r
+ &name_use))\r
+ {\r
+ *group_name = g_utf16_to_utf8 (name, -1, NULL, NULL, NULL);\r
+ }\r
+ g_free (name);\r
+ g_free (domain);\r
+ } while (FALSE);\r
+\r
+ /* TODO: get real name */\r
+\r
+ g_free (psd);\r
}
g_free (wfilename);
}