index.html
Main Page
|
modules.html
Modules
|
namespaces.html
Namespace List
|
hierarchy.html
Class Hierarchy
|
annotated.html
Data Structures
|
dirs.html
Directories
|
files.html
File List
|
namespacemembers.html
Namespace Members
|
functions.html
Data Fields
|
pages.html
Related Pages
dir_000004.html
dbus
dbus-userdb-util.c
00001
/* -*- mode: C; c-file-style: "gnu" -*- */
00002
/* dbus-userdb-util.c Would be in dbus-userdb.c, but not used in libdbus
00003
*
00004
* Copyright (C) 2003, 2004, 2005  Red Hat, Inc.
00005
*
00006
* Licensed under the Academic Free License version 2.1
00007
*
00008
* This program is free software; you can redistribute it and/or modify
00009
* it under the terms of the GNU General Public License as published by
00010
* the Free Software Foundation; either version 2 of the License, or
00011
* (at your option) any later version.
00012
*
00013
* This program is distributed in the hope that it will be useful,
00014
* but WITHOUT ANY WARRANTY; without even the implied warranty of
00015
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016
* GNU General Public License for more details.
00017
*
00018
* You should have received a copy of the GNU General Public License
00019
* along with this program; if not, write to the Free Software
00020
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021
*
00022
*/
00023
#define DBUS_USERDB_INCLUDES_PRIVATE 1
00024
#include "dbus-userdb.h"
00025
#include "dbus-test.h"
00026
#include "dbus-internals.h"
00027
#include "dbus-protocol.h"
00028
#include <string.h>
00029
00042
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusInternalsUtils.html#ga105
00043
group__DBusInternalsUtils.html#ga105
_dbus_is_console_user
(dbus_uid_t uid,
00044
structDBusError.html
DBusError
*error)
00045 {
00046
00047   DBusUserDatabase *db;
00048
const
structDBusUserInfo.html
DBusUserInfo
*info;
00049
group__DBusTypes.html#ga2
dbus_bool_t
result =
group__DBusMacros.html#ga3
FALSE
;
00050
00051
group__DBusInternalsUtils.html#ga119
_dbus_user_database_lock_system
();
00052
00053   db =
group__DBusInternalsUtils.html#ga121
_dbus_user_database_get_system
();
00054
if
(db ==
group__DBusMacros.html#ga4
NULL
)
00055     {
00056
group__DBusErrors.html#ga6
dbus_set_error
(error, DBUS_ERROR_FAILED,
"Could not get system database."
);
00057
group__DBusInternalsUtils.html#ga120
_dbus_user_database_unlock_system
();
00058
return
group__DBusMacros.html#ga3
FALSE
;
00059     }
00060
00061   info =
group__DBusInternalsUtils.html#ga116
_dbus_user_database_lookup
(db, uid,
group__DBusMacros.html#ga4
NULL
, error);
00062
00063
if
(info ==
group__DBusMacros.html#ga4
NULL
)
00064     {
00065
group__DBusInternalsUtils.html#ga120
_dbus_user_database_unlock_system
();
00066
return
group__DBusMacros.html#ga3
FALSE
;
00067     }
00068
00069   result =
group__DBusInternalsUtils.html#ga45
_dbus_user_at_console
(info->
structDBusUserInfo.html#o4
username
, error);
00070
00071
group__DBusInternalsUtils.html#ga120
_dbus_user_database_unlock_system
();
00072
00073
return
result;
00074 }
00075
00076
00084
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusInternalsUtils.html#ga106
00085
group__DBusInternalsUtils.html#ga106
_dbus_credentials_from_uid
(dbus_uid_t        uid,
00086
structDBusCredentials.html
DBusCredentials
*
structDBusTransport.html#o5
credentials
)
00087 {
00088   DBusUserDatabase *db;
00089
const
structDBusUserInfo.html
DBusUserInfo
*info;
00090
group__DBusInternalsUtils.html#ga119
_dbus_user_database_lock_system
();
00091
00092   db =
group__DBusInternalsUtils.html#ga121
_dbus_user_database_get_system
();
00093
if
(db ==
group__DBusMacros.html#ga4
NULL
)
00094     {
00095
group__DBusInternalsUtils.html#ga120
_dbus_user_database_unlock_system
();
00096
return
group__DBusMacros.html#ga3
FALSE
;
00097     }
00098
00099
if
(!
group__DBusInternalsUtils.html#ga128
_dbus_user_database_get_uid
(db, uid,
00100                                     &info,
group__DBusMacros.html#ga4
NULL
))
00101     {
00102
group__DBusInternalsUtils.html#ga120
_dbus_user_database_unlock_system
();
00103
return
group__DBusMacros.html#ga3
FALSE
;
00104     }
00105
00106
group__DBusInternalsUtils.html#ga130
_dbus_assert
(info->
structDBusUserInfo.html#o0
uid
== uid);
00107
00108   credentials->
structDBusCredentials.html#o0
pid
= DBUS_PID_UNSET;
00109   credentials->
structDBusCredentials.html#o1
uid
= info->
structDBusUserInfo.html#o0
uid
;
00110   credentials->
structDBusCredentials.html#o2
gid
= info->
structDBusUserInfo.html#o1
primary_gid
;
00111
00112
group__DBusInternalsUtils.html#ga120
_dbus_user_database_unlock_system
();
00113
return
group__DBusMacros.html#ga2
TRUE
;
00114 }
00115
00116
00124
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusInternalsUtils.html#ga107
00125
group__DBusInternalsUtils.html#ga107
_dbus_get_user_id
(
const
structDBusString.html
DBusString
*username,
00126                    dbus_uid_t        *uid)
00127 {
00128
structDBusCredentials.html
DBusCredentials
creds;
00129
00130
if
(!
group__DBusInternalsUtils.html#ga125
_dbus_credentials_from_username
(username, &creds))
00131
return
group__DBusMacros.html#ga3
FALSE
;
00132
00133
if
(creds.
structDBusCredentials.html#o1
uid
== DBUS_UID_UNSET)
00134
return
group__DBusMacros.html#ga3
FALSE
;
00135
00136   *uid = creds.
structDBusCredentials.html#o1
uid
;
00137
00138
return
group__DBusMacros.html#ga2
TRUE
;
00139 }
00140
00148
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusInternalsUtils.html#ga108
00149
group__DBusInternalsUtils.html#ga108
_dbus_get_group_id
(
const
structDBusString.html
DBusString
*groupname,
00150                     dbus_gid_t        *gid)
00151 {
00152   DBusUserDatabase *db;
00153
const
structDBusGroupInfo.html
DBusGroupInfo
*info;
00154
group__DBusInternalsUtils.html#ga119
_dbus_user_database_lock_system
();
00155
00156   db =
group__DBusInternalsUtils.html#ga121
_dbus_user_database_get_system
();
00157
if
(db ==
group__DBusMacros.html#ga4
NULL
)
00158     {
00159
group__DBusInternalsUtils.html#ga120
_dbus_user_database_unlock_system
();
00160
return
group__DBusMacros.html#ga3
FALSE
;
00161     }
00162
00163
if
(!
group__DBusInternalsUtils.html#ga110
_dbus_user_database_get_groupname
(db, groupname,
00164                                           &info,
group__DBusMacros.html#ga4
NULL
))
00165     {
00166
group__DBusInternalsUtils.html#ga120
_dbus_user_database_unlock_system
();
00167
return
group__DBusMacros.html#ga3
FALSE
;
00168     }
00169
00170   *gid = info->
structDBusGroupInfo.html#o0
gid
;
00171
00172
group__DBusInternalsUtils.html#ga120
_dbus_user_database_unlock_system
();
00173
return
group__DBusMacros.html#ga2
TRUE
;
00174 }
00175
00188
structDBusGroupInfo.html
DBusGroupInfo
*
group__DBusInternalsUtils.html#ga109
00189
group__DBusInternalsUtils.html#ga109
_dbus_user_database_lookup_group
(DBusUserDatabase *db,
00190                                   dbus_gid_t        gid,
00191
const
structDBusString.html
DBusString
*groupname,
00192
structDBusError.html
DBusError
*error)
00193 {
00194
structDBusGroupInfo.html
DBusGroupInfo
*info;
00195
00196   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
00197
00198
/* See if the group is really a number */
00199
if
(gid == DBUS_UID_UNSET)
00200     {
00201
unsigned
long
n;
00202
00203
if
(
group__DBusInternalsUtils.html#ga115
_dbus_is_a_number
(groupname, &n))
00204         gid = n;
00205     }
00206
00207
00208
if
(gid != DBUS_GID_UNSET)
00209     info =
group__DBusHashTable.html#ga18
_dbus_hash_table_lookup_ulong
(db->groups, gid);
00210
else
00211     info =
group__DBusHashTable.html#ga16
_dbus_hash_table_lookup_string
(db->groups_by_name,
00212                                            _dbus_string_get_const_data (groupname));
00213
if
(info)
00214     {
00215       _dbus_verbose (
"Using cache for GID "
DBUS_GID_FORMAT
" information\n"
,
00216                      info->
structDBusGroupInfo.html#o0
gid
);
00217
return
info;
00218     }
00219
else
00220     {
00221
if
(gid != DBUS_GID_UNSET)
00222         _dbus_verbose (
"No cache for GID "
DBUS_GID_FORMAT
"\n"
,
00223                        gid);
00224
else
00225         _dbus_verbose (
"No cache for groupname \"%s\"\n"
,
00226                        _dbus_string_get_const_data (groupname));
00227
00228       info =
group__DBusMemory.html#ga7
dbus_new0
(
structDBusGroupInfo.html
DBusGroupInfo
, 1);
00229
if
(info ==
group__DBusMacros.html#ga4
NULL
)
00230         {
00231
group__DBusErrors.html#ga6
dbus_set_error
(error, DBUS_ERROR_NO_MEMORY,
group__DBusMacros.html#ga4
NULL
);
00232
return
group__DBusMacros.html#ga4
NULL
;
00233         }
00234
00235
if
(gid != DBUS_GID_UNSET)
00236         {
00237
if
(!
group__DBusInternalsUtils.html#ga54
_dbus_group_info_fill_gid
(info, gid, error))
00238             {
00239               _DBUS_ASSERT_ERROR_IS_SET (error);
00240
group__DBusInternalsUtils.html#ga114
_dbus_group_info_free_allocated
(info);
00241
return
group__DBusMacros.html#ga4
NULL
;
00242             }
00243         }
00244
else
00245         {
00246
if
(!
group__DBusInternalsUtils.html#ga53
_dbus_group_info_fill
(info, groupname, error))
00247             {
00248               _DBUS_ASSERT_ERROR_IS_SET (error);
00249
group__DBusInternalsUtils.html#ga114
_dbus_group_info_free_allocated
(info);
00250
return
group__DBusMacros.html#ga4
NULL
;
00251             }
00252         }
00253
00254
/* don't use these past here */
00255       gid = DBUS_GID_UNSET;
00256       groupname =
group__DBusMacros.html#ga4
NULL
;
00257
00258
if
(!
group__DBusHashTable.html#ga24
_dbus_hash_table_insert_ulong
(db->groups, info->
structDBusGroupInfo.html#o0
gid
, info))
00259         {
00260
group__DBusErrors.html#ga6
dbus_set_error
(error, DBUS_ERROR_NO_MEMORY,
group__DBusMacros.html#ga4
NULL
);
00261
group__DBusInternalsUtils.html#ga114
_dbus_group_info_free_allocated
(info);
00262
return
group__DBusMacros.html#ga4
NULL
;
00263         }
00264
00265
00266
if
(!
group__DBusHashTable.html#ga22
_dbus_hash_table_insert_string
(db->groups_by_name,
00267                                            info->
structDBusGroupInfo.html#o1
groupname
,
00268                                            info))
00269         {
00270
group__DBusHashTable.html#ga21
_dbus_hash_table_remove_ulong
(db->groups, info->
structDBusGroupInfo.html#o0
gid
);
00271
group__DBusErrors.html#ga6
dbus_set_error
(error, DBUS_ERROR_NO_MEMORY,
group__DBusMacros.html#ga4
NULL
);
00272
return
group__DBusMacros.html#ga4
NULL
;
00273         }
00274
00275
return
info;
00276     }
00277 }
00278
00279
00290
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusInternalsUtils.html#ga110
00291
group__DBusInternalsUtils.html#ga110
_dbus_user_database_get_groupname
(DBusUserDatabase     *db,
00292
const
structDBusString.html
DBusString
*groupname,
00293
const
structDBusGroupInfo.html
DBusGroupInfo
**info,
00294
structDBusError.html
DBusError
*error)
00295 {
00296   *info =
group__DBusInternalsUtils.html#ga109
_dbus_user_database_lookup_group
(db, DBUS_GID_UNSET, groupname, error);
00297
return
*info !=
group__DBusMacros.html#ga4
NULL
;
00298 }
00299
00310
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusInternalsUtils.html#ga111
00311
group__DBusInternalsUtils.html#ga111
_dbus_user_database_get_gid
(DBusUserDatabase     *db,
00312                              dbus_gid_t            gid,
00313
const
structDBusGroupInfo.html
DBusGroupInfo
**info,
00314
structDBusError.html
DBusError
*error)
00315 {
00316   *info =
group__DBusInternalsUtils.html#ga109
_dbus_user_database_lookup_group
(db, gid,
group__DBusMacros.html#ga4
NULL
, error);
00317
return
*info !=
group__DBusMacros.html#ga4
NULL
;
00318 }
00319
00320
00334
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusInternalsUtils.html#ga112
00335
group__DBusInternalsUtils.html#ga112
_dbus_user_database_get_groups
(DBusUserDatabase  *db,
00336                                 dbus_uid_t         uid,
00337                                 dbus_gid_t       **group_ids,
00338
int
*n_group_ids,
00339
structDBusError.html
DBusError
*error)
00340 {
00341
structDBusUserInfo.html
DBusUserInfo
*info;
00342
00343   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
00344
00345   *group_ids =
group__DBusMacros.html#ga4
NULL
;
00346   *n_group_ids = 0;
00347
00348   info =
group__DBusInternalsUtils.html#ga116
_dbus_user_database_lookup
(db, uid,
group__DBusMacros.html#ga4
NULL
, error);
00349
if
(info ==
group__DBusMacros.html#ga4
NULL
)
00350     {
00351       _DBUS_ASSERT_ERROR_IS_SET (error);
00352
return
group__DBusMacros.html#ga3
FALSE
;
00353     }
00354
00355
if
(info->
structDBusUserInfo.html#o3
n_group_ids
> 0)
00356     {
00357       *group_ids =
group__DBusMemory.html#ga6
dbus_new
(dbus_gid_t, info->
structDBusUserInfo.html#o3
n_group_ids
);
00358
if
(*group_ids ==
group__DBusMacros.html#ga4
NULL
)
00359         {
00360
group__DBusErrors.html#ga6
dbus_set_error
(error, DBUS_ERROR_NO_MEMORY,
group__DBusMacros.html#ga4
NULL
);
00361
return
group__DBusMacros.html#ga3
FALSE
;
00362         }
00363
00364       *n_group_ids = info->
structDBusUserInfo.html#o3
n_group_ids
;
00365
00366       memcpy (*group_ids, info->
structDBusUserInfo.html#o2
group_ids
, info->
structDBusUserInfo.html#o3
n_group_ids
* sizeof (dbus_gid_t));
00367     }
00368
00369
return
group__DBusMacros.html#ga2
TRUE
;
00370 }
00371
00374
#ifdef DBUS_BUILD_TESTS
00375
#include <stdio.h>
00376
00382
group__DBusTypes.html#ga2
dbus_bool_t
00383 _dbus_userdb_test (
const
char
*test_data_dir)
00384 {
00385
const
structDBusString.html
DBusString
*username;
00386
const
structDBusString.html
DBusString
*homedir;
00387
00388
if
(!
group__DBusInternalsUtils.html#ga122
_dbus_username_from_current_process
(&username))
00389
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"didn't get username"
);
00390
00391
if
(!
group__DBusInternalsUtils.html#ga123
_dbus_homedir_from_current_process
(&homedir))
00392
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"didn't get homedir"
);
00393
00394   printf (
"    Current user: %s homedir: %s\n"
,
00395           _dbus_string_get_const_data (username),
00396           _dbus_string_get_const_data (homedir));
00397
00398
return
group__DBusMacros.html#ga2
TRUE
;
00399 }
00400
#endif
/* DBUS_BUILD_TESTS */
Generated on Tue Sep 13 01:28:08 2005 for D-BUS by
http://www.doxygen.org/index.html
doxygen
1.4.4
