* dbus/dbus-sysdeps-win.c,dbus/dbus-sysdeps-win.h: removed obsolate DBusUserInfo...
authorRalf Habacker <ralf.habacker@freenet.de>
Sat, 30 Jun 2007 11:38:05 +0000 (11:38 +0000)
committerRalf Habacker <ralf.habacker@freenet.de>
Sat, 30 Jun 2007 11:38:05 +0000 (11:38 +0000)
ChangeLog
dbus/dbus-sysdeps-win.c
dbus/dbus-sysdeps-win.h

index d43c4c9970f241015b0bf77c9c6ab579ce0917d4..4fe8dc19623231b0fa28e0a9bfb391ee82809ecb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-06-30  Ralf Habacker  <ralf.habacker@freenet.de>
+
+       * dbus/dbus-sysdeps-win.c,dbus/dbus-sysdeps-win.h: removed obsolate 
+       DBusUserInfo code
+
 2007-06-30  Ralf Habacker  <ralf.habacker@freenet.de>
 
        * dbus/dbus-sysdeps-win.c (_dbus_daemon_init): reduced compiler warnings
index 5efe2b510c6cc65b0cdfc36ff7a616f1960b7223..7fba2f4539483d9981e0bf15debf703d2306272e 100644 (file)
@@ -26,8 +26,6 @@
  *
  */
 
-/* #define ENABLE_DBUSUSERINFO */
-
 #undef open
 
 #define STRSAFE_NO_DEPRECATE
@@ -71,17 +69,6 @@ _DBUS_DEFINE_GLOBAL_LOCK (win_fds);
 _DBUS_DEFINE_GLOBAL_LOCK (sid_atom_cache);
 #endif
 
-#ifdef ENABLE_DBUSUSERINFO
-typedef struct {
-    int uid;
-    char *username;
-    int n_group_ids;
-    dbus_gid_t *group_ids;
-    int primary_gid;
-    char *homedir;
-} DBusUserInfo;
-#endif
-
 #ifdef ENABLE_DBUSSOCKET
 static
 void 
@@ -1036,450 +1023,6 @@ _dbus_connect_named_pipe (const char     *path,
 #endif
 
 
-#ifdef ENABLE_DBUSUSERINFO
-dbus_bool_t
-_dbus_account_to_win_sid (const wchar_t  *waccount,
-                          void          **ppsid,
-                          DBusError      *error)
-{
-  dbus_bool_t retval = FALSE;
-  DWORD sid_length, wdomain_length;
-  SID_NAME_USE use;
-  wchar_t *wdomain;
-
-  *ppsid = NULL;
-
-  sid_length = 0;
-  wdomain_length = 0;
-  if (!LookupAccountNameW (NULL, waccount, NULL, &sid_length,
-                           NULL, &wdomain_length, &use)
-      && GetLastError () != ERROR_INSUFFICIENT_BUFFER)
-    {
-      _dbus_win_set_error_from_win_error (error, GetLastError ());
-      return FALSE;
-    }
-
-  *ppsid = dbus_malloc (sid_length);
-  if (!*ppsid)
-    {
-      _DBUS_SET_OOM (error);
-      return FALSE;
-    }
-
-  wdomain = dbus_new (wchar_t, wdomain_length);
-  if (!wdomain)
-    {
-      _DBUS_SET_OOM (error);
-      goto out1;
-    }
-
-  if (!LookupAccountNameW (NULL, waccount, (PSID) *ppsid, &sid_length,
-                           wdomain, &wdomain_length, &use))
-    {
-      _dbus_win_set_error_from_win_error (error, GetLastError ());
-      goto out2;
-    }
-
-  if (!IsValidSid ((PSID) *ppsid))
-    {
-      dbus_set_error_const (error, DBUS_ERROR_FAILED, "Invalid SID");
-      goto out2;
-    }
-
-  retval = TRUE;
-
-out2:
-  dbus_free (wdomain);
-out1:
-  if (!retval)
-    {
-      dbus_free (*ppsid);
-      *ppsid = NULL;
-    }
-
-  return retval;
-}
-
-dbus_bool_t
-fill_win_user_info_name_and_groups (wchar_t      *wname,
-                                    wchar_t      *wdomain,
-                                    DBusUserInfo *info,
-                                    DBusError    *error)
-{
-#ifdef DBUS_WINCE
-       return TRUE;
-#else
-  dbus_bool_t retval = FALSE;
-  char *name, *domain;
-  LPLOCALGROUP_USERS_INFO_0 local_groups = NULL;
-  LPGROUP_USERS_INFO_0 global_groups = NULL;
-  DWORD nread, ntotal;
-
-  name = _dbus_win_utf16_to_utf8 (wname, error);
-  if (!name)
-    return FALSE;
-
-  domain = _dbus_win_utf16_to_utf8 (wdomain, error);
-  if (!domain)
-    goto out0;
-
-  info->username = dbus_malloc (strlen (domain) + 1 + strlen (name) + 1);
-  if (!info->username)
-    {
-      _DBUS_SET_OOM (error);
-      goto out1;
-    }
-
-  strcpy (info->username, domain);
-  strcat (info->username, "\\");
-  strcat (info->username, name);
-
-  info->n_group_ids = 0;
-  if (NetUserGetLocalGroups (NULL, wname, 0, LG_INCLUDE_INDIRECT,
-                             (LPBYTE *) &local_groups, MAX_PREFERRED_LENGTH,
-                             &nread, &ntotal) == NERR_Success)
-    {
-      DWORD i;
-      int n;
-
-      info->group_ids = dbus_new (dbus_gid_t, nread);
-      if (!info->group_ids)
-        {
-          _DBUS_SET_OOM (error);
-          goto out3;
-        }
-
-      for (i = n = 0; i < nread; i++)
-        {
-          PSID group_sid;
-          if (_dbus_account_to_win_sid (local_groups[i].lgrui0_name,
-                                        &group_sid, error))
-            {
-              info->group_ids[n++] = _dbus_win_sid_to_uid_t (group_sid);
-              dbus_free (group_sid);
-            }
-        }
-      info->n_group_ids = n;
-    }
-
-  if (NetUserGetGroups (NULL, wname, 0,
-                        (LPBYTE *) &global_groups, MAX_PREFERRED_LENGTH,
-                        &nread, &ntotal) == NERR_Success)
-    {
-      DWORD i;
-      int n = info->n_group_ids;
-
-      info->group_ids = dbus_realloc (info->group_ids, (n + nread) * sizeof (dbus_gid_t));
-      if (!info->group_ids)
-        {
-          _DBUS_SET_OOM (error);
-          goto out4;
-        }
-
-      for (i = 0; i < nread; i++)
-        {
-          PSID group_sid;
-          if (_dbus_account_to_win_sid (global_groups[i].grui0_name,
-                                        &group_sid, error))
-            {
-              info->group_ids[n++] = _dbus_win_sid_to_uid_t (group_sid);
-              dbus_free (group_sid);
-            }
-        }
-      info->n_group_ids = n;
-    }
-
-  if (info->n_group_ids > 0)
-    {
-      /* FIXME: find out actual primary group */
-      info->primary_gid = info->group_ids[0];
-    }
-  else
-    {
-      info->group_ids = dbus_new (dbus_gid_t, 1);
-      info->n_group_ids = 1;
-      info->group_ids[0] = DBUS_GID_UNSET;
-      info->primary_gid = DBUS_GID_UNSET;
-    }
-
-  retval = TRUE;
-
-out4:
-  if (global_groups != NULL)
-    NetApiBufferFree (global_groups);
-out3:
-  if (local_groups != NULL)
-    NetApiBufferFree (local_groups);
-out1:
-  dbus_free (domain);
-out0:
-  dbus_free (name);
-
-  return retval;
-#endif //DBUS_WINCE
-}
-
-dbus_bool_t
-fill_win_user_info_homedir (wchar_t     *wname,
-                            wchar_t     *wdomain,
-                            DBusUserInfo *info,
-                            DBusError    *error)
-{
-#ifdef DBUS_WINCE
-       //TODO
-       return TRUE;
-#else
-  dbus_bool_t retval = FALSE;
-  USER_INFO_1 *user_info = NULL;
-  wchar_t wcomputername[MAX_COMPUTERNAME_LENGTH + 1];
-  DWORD wcomputername_length = MAX_COMPUTERNAME_LENGTH + 1;
-  dbus_bool_t local_computer;
-  wchar_t *dc = NULL;
-  NET_API_STATUS ret = 0;
-
-  /* If the domain is this computer's name, assume it's a local user.
-   * Otherwise look up a DC for the domain, and ask it.
-   */
-
-  GetComputerNameW (wcomputername, &wcomputername_length);
-  local_computer = (wcsicmp (wcomputername, wdomain) == 0);
-
-  if (!local_computer)
-    {
-      ret = NetGetAnyDCName (NULL, wdomain, (LPBYTE *) &dc);
-      if (ret != NERR_Success)
-        {
-          info->homedir = _dbus_strdup ("\\");
-          _dbus_verbose("NetGetAnyDCName() failed with errorcode %d '%s'\n",ret,_dbus_lm_strerror(ret));
-          return TRUE;
-        }
-    }
-
-  /* No way to find out the profile of another user, let's try the
-   * "home directory" from NetUserGetInfo's USER_INFO_1.
-   */
-  ret = NetUserGetInfo (dc, wname, 1, (LPBYTE *) &user_info);
-  if (ret == NERR_Success )
-    if(user_info->usri1_home_dir != NULL &&
-        user_info->usri1_home_dir != (LPWSTR)0xfeeefeee &&  /* freed memory http://www.gamedev.net/community/forums/topic.asp?topic_id=158402 */
-        user_info->usri1_home_dir[0] != '\0')
-      {
-        info->homedir = _dbus_win_utf16_to_utf8 (user_info->usri1_home_dir, error);
-        if (!info->homedir)
-          goto out1;
-      }
-    else
-      {
-        _dbus_verbose("NetUserGetInfo() returned no home dir entry\n");
-        /* Not set, so use something random. */
-        info->homedir = _dbus_strdup ("\\");
-      }
-  else
-    {
-      char *dc_string = _dbus_win_utf16_to_utf8(dc,error);
-         char *user_name = _dbus_win_utf16_to_utf8(wname,error);
-      _dbus_verbose("NetUserGetInfo() for user '%s' failed with errorcode %d '%s', %s\n",user_name, ret,_dbus_lm_strerror(ret),dc_string);
-      dbus_free(user_name);
-      dbus_free(dc_string);
-      /* Not set, so use something random. */
-      info->homedir = _dbus_strdup ("\\");
-    }
-
-  retval = TRUE;
-
-out1:
-  if (dc != NULL)
-    NetApiBufferFree (dc);
-  if (user_info != NULL)
-    NetApiBufferFree (user_info);
-
-  return retval;
-#endif //DBUS_WINCE
-}
-
-dbus_bool_t
-fill_win_user_info_from_name (wchar_t      *wname,
-                              DBusUserInfo *info,
-                              DBusError    *error)
-{
-#ifdef DBUS_WINCE
-       return TRUE;
-       //TODO
-#else
-  dbus_bool_t retval = FALSE;
-  PSID sid;
-  wchar_t *wdomain;
-  DWORD sid_length, wdomain_length;
-  SID_NAME_USE use;
-
-  sid_length = 0;
-  wdomain_length = 0;
-  if (!LookupAccountNameW (NULL, wname, NULL, &sid_length,
-                           NULL, &wdomain_length, &use) &&
-      GetLastError () != ERROR_INSUFFICIENT_BUFFER)
-    {
-      _dbus_win_set_error_from_win_error (error, GetLastError ());
-      return FALSE;
-    }
-
-  sid = dbus_malloc (sid_length);
-  if (!sid)
-    {
-      _DBUS_SET_OOM (error);
-      return FALSE;
-    }
-
-  wdomain = dbus_new (wchar_t, wdomain_length);
-  if (!wdomain)
-    {
-      _DBUS_SET_OOM (error);
-      goto out0;
-    }
-
-  if (!LookupAccountNameW (NULL, wname, sid, &sid_length,
-                           wdomain, &wdomain_length, &use))
-    {
-      _dbus_win_set_error_from_win_error (error, GetLastError ());
-      goto out1;
-    }
-
-  if (!IsValidSid (sid))
-    {
-      dbus_set_error_const (error, DBUS_ERROR_FAILED, "Invalid SID");
-      goto out1;
-    }
-
-  info->uid = _dbus_win_sid_to_uid_t (sid);
-
-  if (!fill_win_user_info_name_and_groups (wname, wdomain, info, error))
-    goto out1;
-
-  if (!fill_win_user_info_homedir (wname, wdomain, info, error))
-    goto out1;
-
-  retval = TRUE;
-
-out1:
-  dbus_free (wdomain);
-out0:
-  dbus_free (sid);
-
-  return retval;
-#endif //DBUS_WINCE
-}
-
-dbus_bool_t
-_dbus_win_sid_to_name_and_domain (dbus_uid_t uid,
-                                  wchar_t  **wname,
-                                  wchar_t  **wdomain,
-                                  DBusError *error)
-{
-#ifdef DBUS_WINCE
-       return TRUE;
-       //TODO
-#else
-  PSID sid;
-  DWORD wname_length, wdomain_length;
-  SID_NAME_USE use;
-
-  if (!_dbus_uid_t_to_win_sid (uid, &sid))
-    {
-      _dbus_win_set_error_from_win_error (error, GetLastError ());
-      return FALSE;
-    }
-
-  wname_length = 0;
-  wdomain_length = 0;
-  if (!LookupAccountSidW (NULL, sid, NULL, &wname_length,
-                          NULL, &wdomain_length, &use) &&
-      GetLastError () != ERROR_INSUFFICIENT_BUFFER)
-    {
-      _dbus_win_set_error_from_win_error (error, GetLastError ());
-      goto out0;
-    }
-
-  *wname = dbus_new (wchar_t, wname_length);
-  if (!*wname)
-    {
-      _DBUS_SET_OOM (error);
-      goto out0;
-    }
-
-  *wdomain = dbus_new (wchar_t, wdomain_length);
-  if (!*wdomain)
-    {
-      _DBUS_SET_OOM (error);
-      goto out1;
-    }
-
-  if (!LookupAccountSidW (NULL, sid, *wname, &wname_length,
-                          *wdomain, &wdomain_length, &use))
-    {
-      _dbus_win_set_error_from_win_error (error, GetLastError ());
-      goto out2;
-    }
-
-  return TRUE;
-
-out2:
-  dbus_free (*wdomain);
-  *wdomain = NULL;
-out1:
-  dbus_free (*wname);
-  *wname = NULL;
-out0:
-  LocalFree (sid);
-
-  return FALSE;
-#endif //DBUS_WINCE
-}
-
-dbus_bool_t
-fill_win_user_info_from_uid (dbus_uid_t    uid,
-                             DBusUserInfo *info,
-                             DBusError    *error)
-{
-#ifdef DBUS_WINCE
-       return TRUE;
-       //TODO
-#else
-  PSID sid;
-  dbus_bool_t retval = FALSE;
-  wchar_t *wname, *wdomain;
-
-  info->uid = uid;
-
-  if (!_dbus_win_sid_to_name_and_domain (uid, &wname, &wdomain, error))
-    {
-      _dbus_verbose("%s after _dbus_win_sid_to_name_and_domain\n",__FUNCTION__);
-      return FALSE;
-    }
-
-  if (!fill_win_user_info_name_and_groups (wname, wdomain, info, error))
-    {
-      _dbus_verbose("%s after fill_win_user_info_name_and_groups\n",__FUNCTION__);
-      goto out0;
-    }
-
-
-  if (!fill_win_user_info_homedir (wname, wdomain, info, error))
-    {
-      _dbus_verbose("%s after fill_win_user_info_homedir\n",__FUNCTION__);
-      goto out0;
-    }
-
-  retval = TRUE;
-
-out0:
-  dbus_free (wdomain);
-  dbus_free (wname);
-
-  return retval;
-#endif //DBUS_WINCE
-}
-
-#endif
-
 
 void
 _dbus_win_startup_winsock (void)
@@ -4087,91 +3630,6 @@ _dbus_check_dir_is_private_to_user (DBusString *dir, DBusError *error)
   return TRUE;
 }
 
-#ifdef ENABLE_DBUSUSERINFO
-dbus_bool_t
-fill_user_info (DBusUserInfo       *info,
-                dbus_uid_t          uid,
-                const DBusString   *username,
-                DBusError          *error)
-{
-  const char *username_c;
-
-  /* exactly one of username/uid provided */
-  _dbus_assert (username != NULL || uid != DBUS_UID_UNSET);
-  _dbus_assert (username == NULL || uid == DBUS_UID_UNSET);
-
-  info->uid = DBUS_UID_UNSET;
-  info->primary_gid = DBUS_GID_UNSET;
-  info->group_ids = NULL;
-  info->n_group_ids = 0;
-  info->username = NULL;
-  info->homedir = NULL;
-
-  if (username != NULL)
-    username_c = _dbus_string_get_const_data (username);
-  else
-    username_c = NULL;
-
-  if (uid != DBUS_UID_UNSET)
-    {
-      if (!fill_win_user_info_from_uid (uid, info, error))
-        {
-          _dbus_verbose("%s after fill_win_user_info_from_uid\n",__FUNCTION__);
-          return FALSE;
-        }
-    }
-  else
-    {
-      wchar_t *wname = _dbus_win_utf8_to_utf16 (username_c, error);
-
-      if (!wname)
-        return FALSE;
-
-      if (!fill_win_user_info_from_name (wname, info, error))
-        {
-          dbus_free (wname);
-          return FALSE;
-        }
-      dbus_free (wname);
-    }
-
-  return TRUE;
-}
-/**
- * Gets user info for the given user ID.
- *
- * @param info user info object to initialize
- * @param uid the user ID
- * @param error error return
- * @returns #TRUE on success
- */
-dbus_bool_t
-_dbus_user_info_fill_uid (DBusUserInfo *info,
-                          dbus_uid_t    uid,
-                          DBusError    *error)
-{
-  return fill_user_info (info, uid,
-                         NULL, error);
-}
-
-
-/**
- * Gets user info for the given username.
- *
- * @param info user info object to initialize
- * @param username the username
- * @param error error return
- * @returns #TRUE on success
- */
-dbus_bool_t
-_dbus_user_info_fill (DBusUserInfo     *info,
-                      const DBusString *username,
-                      DBusError        *error)
-{
-  return fill_user_info (info, DBUS_UID_UNSET,
-                         username, error);
-}
-#endif
 
 /**
  * Appends the given filename to the given directory.
index 2572fd3aad2e409250079399a0f41f6a02c0d06f..7aed6ce0923b6d1c1bea70551053cbe12217f89b 100644 (file)
@@ -83,23 +83,6 @@ void _dbus_win_warn_win_error  (const char *message,
                                 int         code);
 extern const char* _dbus_lm_strerror  (int error_number);
 
-#ifdef ENABLE_DBUSUSERINFO
-dbus_bool_t
-fill_win_user_info_from_uid (dbus_uid_t    uid,
-                             DBusUserInfo *info,
-                             DBusError    *error);
-dbus_bool_t
-fill_win_user_info_from_name (wchar_t      *wname,
-                              DBusUserInfo *info,
-                              DBusError    *error);
-
-dbus_bool_t
-fill_user_info (DBusUserInfo       *info,
-                dbus_uid_t          uid,
-                const DBusString   *username,
-                DBusError          *error);
-#endif
-
 dbus_bool_t _dbus_win_account_to_sid (const wchar_t *waccount,
                                       void         **ppsid,
                                       DBusError     *error);