follow lib naming convention working implementation for user and group
authorHans Breuer <hans@breuer.org>
Sun, 9 Dec 2007 22:10:40 +0000 (22:10 +0000)
committerHans Breuer <hans@src.gnome.org>
Sun, 9 Dec 2007 22:10:40 +0000 (22:10 +0000)
2007-12-09  Hans Breuer  <hans@breuer.org>

* makefile.msc : follow lib naming convention
* glocalfileinfo.c(win32_get_file_user_info) : working implementation
for user and group name, tested with ../tests/gio-ls

svn path=/trunk/; revision=6080

gio/ChangeLog
gio/glocalfileinfo.c
gio/makefile.msc

index 0d42765..fee454d 100644 (file)
@@ -1,3 +1,9 @@
+2007-12-09  Hans Breuer  <hans@breuer.org>
+
+       * makefile.msc : follow lib naming convention
+       * glocalfileinfo.c(win32_get_file_user_info) : working implementation
+       for user and group name, tested with ../tests/gio-ls
+
 2007-12-09  A. Walton  <awalton@svn.gnome.org>
 
        * gdesktopappinfo.c:
index dac9f93..33d7727 100644 (file)
@@ -1266,14 +1266,14 @@ get_thumbnail_attributes (const char *path,
 }
 
 #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, 
@@ -1283,32 +1283,75 @@ win32_get_file_user_info (const gchar* filename,
                        &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);
 }
index d4e7b8d..8f546c4 100644 (file)
@@ -251,7 +251,8 @@ libgio-$(PKG_VER).dll : $(OBJECTS) $(PACKAGE).def
        $(CC) $(CFLAGS) -LD -Felibgio-$(PKG_VER).dll $(OBJECTS) \
        ..\glib\glib-2.0.lib ..\gobject\gobject-2.0.lib ..\gmodule\gmodule-2.0.lib \
        $(INTL_LIBS) \
-       user32.lib advapi32.lib shell32.lib wsock32.lib $(LDFLAGS) /def:$(PACKAGE).def
+       user32.lib advapi32.lib shell32.lib wsock32.lib $(LDFLAGS) \
+       /implib:gio-2.0.lib /def:$(PACKAGE).def
 
 .c.obj :
        $(CC) $(CFLAGS) -c $(PKG_CFLAGS) $<