projects
/
platform
/
upstream
/
dbus.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
[daemon-dev][lib-opt] Fix in freeing memory, cleanup, comments, renames
[platform/upstream/dbus.git]
/
dbus
/
dbus-userdb.c
diff --git
a/dbus/dbus-userdb.c
b/dbus/dbus-userdb.c
index
0e430b2
..
b792cbe
100644
(file)
--- a/
dbus/dbus-userdb.c
+++ b/
dbus/dbus-userdb.c
@@
-17,9
+17,10
@@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 5
9 Temple Place, Suite 330, Boston, MA 02111-1307
USA
+ * Foundation, Inc., 5
1 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*
*/
*
*/
+#include <config.h>
#define DBUS_USERDB_INCLUDES_PRIVATE 1
#include "dbus-userdb.h"
#include "dbus-hash.h"
#define DBUS_USERDB_INCLUDES_PRIVATE 1
#include "dbus-userdb.h"
#include "dbus-hash.h"
@@
-143,9
+144,9
@@
_dbus_user_database_lookup (DBusUserDatabase *db,
uid = n;
}
uid = n;
}
-#ifdef DBUS_ENABLE_USER_CACHE
+#ifdef DBUS_ENABLE_USER
DB
_CACHE
if (uid != DBUS_UID_UNSET)
if (uid != DBUS_UID_UNSET)
- info = _dbus_hash_table_lookup_u
long
(db->users, uid);
+ info = _dbus_hash_table_lookup_u
intptr
(db->users, uid);
else
info = _dbus_hash_table_lookup_string (db->users_by_name, _dbus_string_get_const_data (username));
else
info = _dbus_hash_table_lookup_string (db->users_by_name, _dbus_string_get_const_data (username));
@@
-198,7
+199,7
@@
_dbus_user_database_lookup (DBusUserDatabase *db,
username = NULL;
/* insert into hash */
username = NULL;
/* insert into hash */
- if (!_dbus_hash_table_insert_u
long
(db->users, info->uid, info))
+ if (!_dbus_hash_table_insert_u
intptr
(db->users, info->uid, info))
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
_dbus_user_info_free_allocated (info);
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
_dbus_user_info_free_allocated (info);
@@
-209,7
+210,7
@@
_dbus_user_database_lookup (DBusUserDatabase *db,
info->username,
info))
{
info->username,
info))
{
- _dbus_hash_table_remove_u
long
(db->users, info->uid);
+ _dbus_hash_table_remove_u
intptr
(db->users, info->uid);
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
return NULL;
}
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
return NULL;
}
@@
-226,7
+227,8
@@
static DBusString process_homedir;
static void
shutdown_system_db (void *data)
{
static void
shutdown_system_db (void *data)
{
- _dbus_user_database_unref (system_db);
+ if (system_db != NULL)
+ _dbus_user_database_unref (system_db);
system_db = NULL;
_dbus_string_free (&process_username);
_dbus_string_free (&process_homedir);
system_db = NULL;
_dbus_string_free (&process_username);
_dbus_string_free (&process_homedir);
@@
-304,11
+306,18
@@
init_system_db (void)
/**
* Locks global system user database.
*/
/**
* Locks global system user database.
*/
-void
+dbus_bool_t
_dbus_user_database_lock_system (void)
{
_dbus_user_database_lock_system (void)
{
- _DBUS_LOCK (system_users);
- database_locked = TRUE;
+ if (_DBUS_LOCK (system_users))
+ {
+ database_locked = TRUE;
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
}
/**
}
/**
@@
-343,9
+352,14
@@
_dbus_user_database_get_system (void)
void
_dbus_user_database_flush_system (void)
{
void
_dbus_user_database_flush_system (void)
{
- _dbus_user_database_lock_system ();
-
- _dbus_user_database_flush (system_db);
+ if (!_dbus_user_database_lock_system ())
+ {
+ /* nothing to flush */
+ return;
+ }
+
+ if (system_db != NULL)
+ _dbus_user_database_flush (system_db);
_dbus_user_database_unlock_system ();
}
_dbus_user_database_unlock_system ();
}
@@
-360,7
+374,9
@@
_dbus_user_database_flush_system (void)
dbus_bool_t
_dbus_username_from_current_process (const DBusString **username)
{
dbus_bool_t
_dbus_username_from_current_process (const DBusString **username)
{
- _dbus_user_database_lock_system ();
+ if (!_dbus_user_database_lock_system ())
+ return FALSE;
+
if (!init_system_db ())
{
_dbus_user_database_unlock_system ();
if (!init_system_db ())
{
_dbus_user_database_unlock_system ();
@@
-382,7
+398,9
@@
_dbus_username_from_current_process (const DBusString **username)
dbus_bool_t
_dbus_homedir_from_current_process (const DBusString **homedir)
{
dbus_bool_t
_dbus_homedir_from_current_process (const DBusString **homedir)
{
- _dbus_user_database_lock_system ();
+ if (!_dbus_user_database_lock_system ())
+ return FALSE;
+
if (!init_system_db ())
{
_dbus_user_database_unlock_system ();
if (!init_system_db ())
{
_dbus_user_database_unlock_system ();
@@
-407,7
+425,10
@@
_dbus_homedir_from_username (const DBusString *username,
{
DBusUserDatabase *db;
const DBusUserInfo *info;
{
DBusUserDatabase *db;
const DBusUserInfo *info;
- _dbus_user_database_lock_system ();
+
+ /* FIXME: this can't distinguish ENOMEM from other errors */
+ if (!_dbus_user_database_lock_system ())
+ return FALSE;
db = _dbus_user_database_get_system ();
if (db == NULL)
db = _dbus_user_database_get_system ();
if (db == NULL)
@@
-446,7
+467,10
@@
_dbus_homedir_from_uid (dbus_uid_t uid,
{
DBusUserDatabase *db;
const DBusUserInfo *info;
{
DBusUserDatabase *db;
const DBusUserInfo *info;
- _dbus_user_database_lock_system ();
+
+ /* FIXME: this can't distinguish ENOMEM from other errors */
+ if (!_dbus_user_database_lock_system ())
+ return FALSE;
db = _dbus_user_database_get_system ();
if (db == NULL)
db = _dbus_user_database_get_system ();
if (db == NULL)
@@
-493,7
+517,9
@@
_dbus_credentials_add_from_user (DBusCredentials *credentials,
DBusUserDatabase *db;
const DBusUserInfo *info;
DBusUserDatabase *db;
const DBusUserInfo *info;
- _dbus_user_database_lock_system ();
+ /* FIXME: this can't distinguish ENOMEM from other errors */
+ if (!_dbus_user_database_lock_system ())
+ return FALSE;
db = _dbus_user_database_get_system ();
if (db == NULL)
db = _dbus_user_database_get_system ();
if (db == NULL)
@@
-535,13
+561,13
@@
_dbus_user_database_new (void)
db->refcount = 1;
db->refcount = 1;
- db->users = _dbus_hash_table_new (DBUS_HASH_U
LONG
,
+ db->users = _dbus_hash_table_new (DBUS_HASH_U
INTPTR
,
NULL, (DBusFreeFunction) _dbus_user_info_free_allocated);
if (db->users == NULL)
goto failed;
NULL, (DBusFreeFunction) _dbus_user_info_free_allocated);
if (db->users == NULL)
goto failed;
- db->groups = _dbus_hash_table_new (DBUS_HASH_U
LONG
,
+ db->groups = _dbus_hash_table_new (DBUS_HASH_U
INTPTR
,
NULL, (DBusFreeFunction) _dbus_group_info_free_allocated);
if (db->groups == NULL)
NULL, (DBusFreeFunction) _dbus_group_info_free_allocated);
if (db->groups == NULL)
@@
-576,7
+602,7
@@
_dbus_user_database_flush (DBusUserDatabase *db)
_dbus_hash_table_remove_all(db->groups);
}
_dbus_hash_table_remove_all(db->groups);
}
-#ifdef DBUS_
BUIL
D_TESTS
+#ifdef DBUS_
ENABLE_EMBEDDE
D_TESTS
/**
* Increments refcount of user database.
* @param db the database
/**
* Increments refcount of user database.
* @param db the database
@@
-591,7
+617,7
@@
_dbus_user_database_ref (DBusUserDatabase *db)
return db;
}
return db;
}
-#endif /* DBUS_
BUIL
D_TESTS */
+#endif /* DBUS_
ENABLE_EMBEDDE
D_TESTS */
/**
* Decrements refcount of user database.
/**
* Decrements refcount of user database.