1/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 *
22 */
23
24#ifndef DBUS_USERDB_H
25#define DBUS_USERDB_H
26
27#include <dbus/dbus-sysdeps-unix.h>
28
29#ifdef DBUS_WIN
30#error "Don't include this on Windows"
31#endif
32
33DBUS_BEGIN_DECLS
34
35typedef struct DBusUserDatabase DBusUserDatabase;
36
37#ifdef DBUS_USERDB_INCLUDES_PRIVATE
38#include <dbus/dbus-hash.h>
39
40/**
41 * Internals of DBusUserDatabase
42 */
43struct DBusUserDatabase
44{
45  int refcount; /**< Reference count */
46
47  DBusHashTable *users; /**< Users in the database by UID */
48  DBusHashTable *groups; /**< Groups in the database by GID */
49  DBusHashTable *users_by_name; /**< Users in the database by name */
50  DBusHashTable *groups_by_name; /**< Groups in the database by name */
51
52};
53
54
55DBusUserDatabase* _dbus_user_database_new           (void);
56DBusUserDatabase* _dbus_user_database_ref           (DBusUserDatabase     *db);
57void              _dbus_user_database_flush         (DBusUserDatabase     *db);
58void              _dbus_user_database_unref         (DBusUserDatabase     *db);
59dbus_bool_t       _dbus_user_database_get_uid       (DBusUserDatabase     *db,
60                                                     dbus_uid_t            uid,
61                                                     const DBusUserInfo  **info,
62                                                     DBusError            *error);
63dbus_bool_t       _dbus_user_database_get_gid       (DBusUserDatabase     *db,
64                                                     dbus_gid_t            gid,
65                                                     const DBusGroupInfo **info,
66                                                     DBusError            *error);
67dbus_bool_t       _dbus_user_database_get_username  (DBusUserDatabase     *db,
68                                                     const DBusString     *username,
69                                                     const DBusUserInfo  **info,
70                                                     DBusError            *error);
71dbus_bool_t       _dbus_user_database_get_groupname (DBusUserDatabase     *db,
72                                                     const DBusString     *groupname,
73                                                     const DBusGroupInfo **info,
74                                                     DBusError            *error);
75
76DBusUserInfo*  _dbus_user_database_lookup       (DBusUserDatabase *db,
77                                                 dbus_uid_t        uid,
78                                                 const DBusString *username,
79                                                 DBusError        *error);
80DBusGroupInfo* _dbus_user_database_lookup_group (DBusUserDatabase *db,
81                                                 dbus_gid_t        gid,
82                                                 const DBusString *groupname,
83                                                 DBusError        *error);
84void           _dbus_user_info_free_allocated   (DBusUserInfo     *info);
85void           _dbus_group_info_free_allocated  (DBusGroupInfo    *info);
86#endif /* DBUS_USERDB_INCLUDES_PRIVATE */
87
88DBusUserDatabase* _dbus_user_database_get_system    (void);
89void              _dbus_user_database_lock_system   (void);
90void              _dbus_user_database_unlock_system (void);
91void              _dbus_user_database_flush_system  (void);
92
93dbus_bool_t _dbus_get_user_id                   (const DBusString  *username,
94                                                 dbus_uid_t        *uid);
95dbus_bool_t _dbus_get_group_id                  (const DBusString  *group_name,
96                                                 dbus_gid_t        *gid);
97dbus_bool_t _dbus_get_user_id_and_primary_group (const DBusString  *username,
98                                                 dbus_uid_t        *uid_p,
99                                                 dbus_gid_t        *gid_p);
100dbus_bool_t _dbus_credentials_from_uid          (dbus_uid_t         user_id,
101                                                 DBusCredentials   *credentials);
102dbus_bool_t _dbus_groups_from_uid		(dbus_uid_t            uid,
103                                                 dbus_gid_t          **group_ids,
104                                                 int                  *n_group_ids);
105dbus_bool_t _dbus_is_console_user               (dbus_uid_t         uid,
106                                                 DBusError         *error);
107
108dbus_bool_t _dbus_is_a_number                   (const DBusString *str,
109                                                 unsigned long    *num);
110
111dbus_bool_t _dbus_username_from_current_process (const DBusString **username);
112dbus_bool_t _dbus_homedir_from_current_process  (const DBusString **homedir);
113dbus_bool_t _dbus_homedir_from_username         (const DBusString  *username,
114                                                 DBusString        *homedir);
115
116dbus_bool_t _dbus_homedir_from_uid              (dbus_uid_t         uid,
117                                                 DBusString        *homedir);
118
119DBUS_END_DECLS
120
121#endif /* DBUS_USERDB_H */
122