commit.msg
[platform/upstream/dbus.git] / dbus / dbus-userdb.h
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-userdb.h User database abstraction
3  * 
4  * Copyright (C) 2003  Red Hat, Inc.
5  *
6  * Licensed under the Academic Free License version 2.1
7  * 
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  * 
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  */
23
24 #ifndef DBUS_USERDB_H
25 #define DBUS_USERDB_H
26
27 #include <dbus/dbus-sysdeps.h>
28
29 DBUS_BEGIN_DECLS
30
31 typedef struct DBusUserDatabase DBusUserDatabase;
32
33 #ifdef DBUS_USERDB_INCLUDES_PRIVATE
34 #include <dbus/dbus-hash.h>
35
36 /**
37  * Internals of DBusUserDatabase
38  */
39 struct DBusUserDatabase
40 {
41   int refcount; /**< Reference count */
42
43   DBusHashTable *users; /**< Users in the database by UID */
44   DBusHashTable *groups; /**< Groups in the database by GID */
45   DBusHashTable *users_by_name; /**< Users in the database by name */
46   DBusHashTable *groups_by_name; /**< Groups in the database by name */
47
48 };
49
50
51 DBusUserDatabase* _dbus_user_database_new           (void);
52 DBusUserDatabase* _dbus_user_database_ref           (DBusUserDatabase     *db);
53 void              _dbus_user_database_flush         (DBusUserDatabase     *db);
54 void              _dbus_user_database_unref         (DBusUserDatabase     *db);
55 dbus_bool_t       _dbus_user_database_get_uid       (DBusUserDatabase     *db,
56                                                      dbus_uid_t            uid,
57                                                      const DBusUserInfo  **info,
58                                                      DBusError            *error);
59 dbus_bool_t       _dbus_user_database_get_gid       (DBusUserDatabase     *db,
60                                                      dbus_gid_t            gid,
61                                                      const DBusGroupInfo **info,
62                                                      DBusError            *error);
63 dbus_bool_t       _dbus_user_database_get_username  (DBusUserDatabase     *db,
64                                                      const DBusString     *username,
65                                                      const DBusUserInfo  **info,
66                                                      DBusError            *error);
67 dbus_bool_t       _dbus_user_database_get_groupname (DBusUserDatabase     *db,
68                                                      const DBusString     *groupname,
69                                                      const DBusGroupInfo **info,
70                                                      DBusError            *error);
71
72 DBusUserInfo*  _dbus_user_database_lookup       (DBusUserDatabase *db,
73                                                  dbus_uid_t        uid,
74                                                  const DBusString *username,
75                                                  DBusError        *error);
76 DBusGroupInfo* _dbus_user_database_lookup_group (DBusUserDatabase *db,
77                                                  dbus_gid_t        gid,
78                                                  const DBusString *groupname,
79                                                  DBusError        *error);
80 void           _dbus_user_info_free_allocated   (DBusUserInfo     *info);
81 void           _dbus_group_info_free_allocated  (DBusGroupInfo    *info);
82 #endif /* DBUS_USERDB_INCLUDES_PRIVATE */
83
84 DBusUserDatabase* _dbus_user_database_get_system    (void);
85 void              _dbus_user_database_lock_system   (void);
86 void              _dbus_user_database_unlock_system (void);
87 void              _dbus_user_database_flush_system  (void);
88
89 dbus_bool_t _dbus_username_from_current_process (const DBusString **username);
90 dbus_bool_t _dbus_homedir_from_current_process  (const DBusString **homedir);
91 dbus_bool_t _dbus_homedir_from_username         (const DBusString  *username,
92                                                  DBusString        *homedir);
93 dbus_bool_t _dbus_get_user_id                   (const DBusString  *username,
94                                                  dbus_uid_t        *uid);
95 dbus_bool_t _dbus_get_group_id                  (const DBusString  *group_name,
96                                                  dbus_gid_t        *gid);
97 dbus_bool_t _dbus_credentials_from_username     (const DBusString  *username,
98                                                  DBusCredentials   *credentials);
99 dbus_bool_t _dbus_credentials_from_uid          (dbus_uid_t         user_id,
100                                                  DBusCredentials   *credentials);
101 dbus_bool_t _dbus_groups_from_uid               (dbus_uid_t            uid,
102                                                  dbus_gid_t          **group_ids,
103                                                  int                  *n_group_ids);
104 dbus_bool_t _dbus_is_console_user               (dbus_uid_t         uid,
105                                                  DBusError         *error);
106
107 dbus_bool_t _dbus_is_a_number                   (const DBusString *str, 
108                                                  unsigned long    *num);
109
110
111 DBUS_END_DECLS
112
113 #endif /* DBUS_USERDB_H */