| Current File : //usr/share/doc/dbus/api/dbus-userdb-util_8c_source.html |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>D-Bus: dbus-userdb-util.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td style="padding-left: 0.5em;">
<div id="projectname">D-Bus
 <span id="projectnumber">1.8.20</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- Generated by Doxygen 1.7.6.1 -->
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main Page</span></a></li>
<li><a href="pages.html"><span>Related Pages</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="annotated.html"><span>Data Structures</span></a></li>
<li class="current"><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<div id="navrow2" class="tabs2">
<ul class="tablist">
<li><a href="files.html"><span>File List</span></a></li>
</ul>
</div>
</div>
<div class="header">
<div class="headertitle">
<div class="title">dbus-userdb-util.c</div> </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */</span>
<a name="l00002"></a>00002 <span class="comment">/* dbus-userdb-util.c Would be in dbus-userdb.c, but not used in libdbus</span>
<a name="l00003"></a>00003 <span class="comment"> * </span>
<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2003, 2004, 2005 Red Hat, Inc.</span>
<a name="l00005"></a>00005 <span class="comment"> *</span>
<a name="l00006"></a>00006 <span class="comment"> * Licensed under the Academic Free License version 2.1</span>
<a name="l00007"></a>00007 <span class="comment"> * </span>
<a name="l00008"></a>00008 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
<a name="l00009"></a>00009 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
<a name="l00010"></a>00010 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
<a name="l00011"></a>00011 <span class="comment"> * (at your option) any later version.</span>
<a name="l00012"></a>00012 <span class="comment"> *</span>
<a name="l00013"></a>00013 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
<a name="l00014"></a>00014 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00015"></a>00015 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<a name="l00016"></a>00016 <span class="comment"> * GNU General Public License for more details.</span>
<a name="l00017"></a>00017 <span class="comment"> * </span>
<a name="l00018"></a>00018 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
<a name="l00019"></a>00019 <span class="comment"> * along with this program; if not, write to the Free Software</span>
<a name="l00020"></a>00020 <span class="comment"> * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA</span>
<a name="l00021"></a>00021 <span class="comment"> *</span>
<a name="l00022"></a>00022 <span class="comment"> */</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include <config.h></span>
<a name="l00024"></a>00024 <span class="preprocessor">#include <unistd.h></span>
<a name="l00025"></a>00025 <span class="preprocessor">#define DBUS_USERDB_INCLUDES_PRIVATE 1</span>
<a name="l00026"></a>00026 <span class="preprocessor"></span><span class="preprocessor">#include "dbus-userdb.h"</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include "dbus-test.h"</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include "dbus-internals.h"</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include "dbus-protocol.h"</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include <string.h></span>
<a name="l00031"></a>00031
<a name="l00032"></a>00032 <span class="preprocessor">#if HAVE_SYSTEMD</span>
<a name="l00033"></a>00033 <span class="preprocessor"></span><span class="preprocessor">#include <systemd/sd-login.h></span>
<a name="l00034"></a>00034 <span class="preprocessor">#endif</span>
<a name="l00035"></a>00035 <span class="preprocessor"></span>
<a name="l00048"></a>00048 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l00049"></a><a class="code" href="group__DBusInternalsUtils.html#gaa504db352a939909051a494d06c5b607">00049</a> <a class="code" href="group__DBusInternalsUtils.html#gaa504db352a939909051a494d06c5b607" title="Checks to see if the UID sent in is the console user.">_dbus_is_console_user</a> (<a class="code" href="group__DBusSysdeps.html#ga186e987b700f9ddc6cea8aa0db82b151" title="A user ID.">dbus_uid_t</a> uid,
<a name="l00050"></a>00050 <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a> *error)
<a name="l00051"></a>00051 {
<a name="l00052"></a>00052
<a name="l00053"></a>00053 DBusUserDatabase *db;
<a name="l00054"></a>00054 <span class="keyword">const</span> <a class="code" href="structDBusUserInfo.html" title="Information about a UNIX user.">DBusUserInfo</a> *info;
<a name="l00055"></a>00055 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> result = <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to "0".">FALSE</a>;
<a name="l00056"></a>00056
<a name="l00057"></a>00057 <span class="preprocessor">#ifdef HAVE_SYSTEMD</span>
<a name="l00058"></a>00058 <span class="preprocessor"></span> <span class="comment">/* check if we have logind */</span>
<a name="l00059"></a>00059 <span class="keywordflow">if</span> (access (<span class="stringliteral">"/run/systemd/seats/"</span>, F_OK) >= 0)
<a name="l00060"></a>00060 {
<a name="l00061"></a>00061 <span class="keywordtype">int</span> r;
<a name="l00062"></a>00062
<a name="l00063"></a>00063 <span class="comment">/* Check whether this user is logged in on at least one physical</span>
<a name="l00064"></a>00064 <span class="comment"> seat */</span>
<a name="l00065"></a>00065 r = sd_uid_get_seats (uid, 0, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l00066"></a>00066 <span class="keywordflow">if</span> (r < 0)
<a name="l00067"></a>00067 {
<a name="l00068"></a>00068 <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (-r),
<a name="l00069"></a>00069 <span class="stringliteral">"Failed to determine seats of user \""</span> <a class="code" href="group__DBusSysdeps.html#gab657f0434f01b463891942f373f7b4a1" title="an appropriate printf format for dbus_uid_t">DBUS_UID_FORMAT</a> <span class="stringliteral">"\": %s"</span>,
<a name="l00070"></a>00070 uid,
<a name="l00071"></a>00071 _dbus_strerror (-r));
<a name="l00072"></a>00072 <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to "0".">FALSE</a>;
<a name="l00073"></a>00073 }
<a name="l00074"></a>00074
<a name="l00075"></a>00075 <span class="keywordflow">return</span> (r > 0);
<a name="l00076"></a>00076 }
<a name="l00077"></a>00077 <span class="preprocessor">#endif</span>
<a name="l00078"></a>00078 <span class="preprocessor"></span>
<a name="l00079"></a>00079 <span class="preprocessor">#ifdef HAVE_CONSOLE_OWNER_FILE</span>
<a name="l00080"></a>00080 <span class="preprocessor"></span>
<a name="l00081"></a>00081 <a class="code" href="structDBusString.html">DBusString</a> f;
<a name="l00082"></a>00082 <a class="code" href="structDBusStat.html" title="Portable struct with stat() results.">DBusStat</a> st;
<a name="l00083"></a>00083
<a name="l00084"></a>00084 <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga348252317f7bb8ac43529972945830ae" title="Initializes a string.">_dbus_string_init</a> (&f))
<a name="l00085"></a>00085 {
<a name="l00086"></a>00086 _DBUS_SET_OOM (error);
<a name="l00087"></a>00087 <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to "0".">FALSE</a>;
<a name="l00088"></a>00088 }
<a name="l00089"></a>00089
<a name="l00090"></a>00090 <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga100c5ce0696822c5a4cfbdfaba674d96" title="Appends a nul-terminated C-style string to a DBusString.">_dbus_string_append</a>(&f, DBUS_CONSOLE_OWNER_FILE))
<a name="l00091"></a>00091 {
<a name="l00092"></a>00092 <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a>(&f);
<a name="l00093"></a>00093 _DBUS_SET_OOM (error);
<a name="l00094"></a>00094 <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to "0".">FALSE</a>;
<a name="l00095"></a>00095 }
<a name="l00096"></a>00096
<a name="l00097"></a>00097 <span class="keywordflow">if</span> (<a class="code" href="group__DBusInternalsUtils.html#ga04e98ad0e3a181f0a5921a4cbc49cf08" title="stat() wrapper.">_dbus_stat</a>(&f, &st, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>) && (st.<a class="code" href="structDBusStat.html#a300fac914534803bcfacdd87b15e1a8d" title="User owning file.">uid</a> == uid))
<a name="l00098"></a>00098 {
<a name="l00099"></a>00099 <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a>(&f);
<a name="l00100"></a>00100 <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to "1".">TRUE</a>;
<a name="l00101"></a>00101 }
<a name="l00102"></a>00102
<a name="l00103"></a>00103 <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a>(&f);
<a name="l00104"></a>00104
<a name="l00105"></a>00105 <span class="preprocessor">#endif </span><span class="comment">/* HAVE_CONSOLE_OWNER_FILE */</span>
<a name="l00106"></a>00106
<a name="l00107"></a>00107 <span class="keywordflow">if</span> (!<a class="code" href="group__DBusInternalsUtils.html#ga15df3b3fdaa4946f69ff87f3a9a03fe7" title="Locks global system user database.">_dbus_user_database_lock_system</a> ())
<a name="l00108"></a>00108 {
<a name="l00109"></a>00109 _DBUS_SET_OOM (error);
<a name="l00110"></a>00110 <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to "0".">FALSE</a>;
<a name="l00111"></a>00111 }
<a name="l00112"></a>00112
<a name="l00113"></a>00113 db = <a class="code" href="group__DBusInternalsUtils.html#ga79b6c3cf0d735622b6af2795840f9d21" title="Gets the system global user database; must be called with lock held (_dbus_user_database_lock_system(...">_dbus_user_database_get_system</a> ();
<a name="l00114"></a>00114 <span class="keywordflow">if</span> (db == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l00115"></a>00115 {
<a name="l00116"></a>00116 <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gabb62fd6340d0787fbd56ff8dd2f326c7" title="A generic error; "something went wrong" - see the error message for more.">DBUS_ERROR_FAILED</a>, <span class="stringliteral">"Could not get system database."</span>);
<a name="l00117"></a>00117 <a class="code" href="group__DBusInternalsUtils.html#ga468e1d62e1df24bb699c4a37fdfa274c" title="Unlocks global system user database.">_dbus_user_database_unlock_system</a> ();
<a name="l00118"></a>00118 <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to "0".">FALSE</a>;
<a name="l00119"></a>00119 }
<a name="l00120"></a>00120
<a name="l00121"></a>00121 <span class="comment">/* TPTD: this should be cache-safe, we've locked the DB and</span>
<a name="l00122"></a>00122 <span class="comment"> _dbus_user_at_console doesn't pass it on. */</span>
<a name="l00123"></a>00123 info = <a class="code" href="group__DBusInternalsUtils.html#ga959372f7d7cdea35ffbac3b78e29a1b0" title="Looks up a uid or username in the user database.">_dbus_user_database_lookup</a> (db, uid, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, error);
<a name="l00124"></a>00124
<a name="l00125"></a>00125 <span class="keywordflow">if</span> (info == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l00126"></a>00126 {
<a name="l00127"></a>00127 <a class="code" href="group__DBusInternalsUtils.html#ga468e1d62e1df24bb699c4a37fdfa274c" title="Unlocks global system user database.">_dbus_user_database_unlock_system</a> ();
<a name="l00128"></a>00128 <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to "0".">FALSE</a>;
<a name="l00129"></a>00129 }
<a name="l00130"></a>00130
<a name="l00131"></a>00131 result = <a class="code" href="group__DBusInternalsUtils.html#ga31ec42cef2d15ca358e737bb5f19c5cf" title="Checks if user is at the console.">_dbus_user_at_console</a> (info-><a class="code" href="structDBusUserInfo.html#ac6b57db1dc8315eee3f532f4e77912d1" title="Username.">username</a>, error);
<a name="l00132"></a>00132
<a name="l00133"></a>00133 <a class="code" href="group__DBusInternalsUtils.html#ga468e1d62e1df24bb699c4a37fdfa274c" title="Unlocks global system user database.">_dbus_user_database_unlock_system</a> ();
<a name="l00134"></a>00134
<a name="l00135"></a>00135 <span class="keywordflow">return</span> result;
<a name="l00136"></a>00136 }
<a name="l00137"></a>00137
<a name="l00145"></a>00145 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l00146"></a><a class="code" href="group__DBusInternalsUtils.html#gaf07ee24eddcb3b0f85fa54196bc44fe1">00146</a> <a class="code" href="group__DBusInternalsUtils.html#gaf07ee24eddcb3b0f85fa54196bc44fe1" title="Gets user ID given username.">_dbus_get_user_id</a> (<span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *username,
<a name="l00147"></a>00147 <a class="code" href="group__DBusSysdeps.html#ga186e987b700f9ddc6cea8aa0db82b151" title="A user ID.">dbus_uid_t</a> *uid)
<a name="l00148"></a>00148 {
<a name="l00149"></a>00149 <span class="keywordflow">return</span> <a class="code" href="group__DBusInternalsUtils.html#gac82f42ff83fabbde717cc08569265e6e" title="Gets user ID and primary group given username.">_dbus_get_user_id_and_primary_group</a> (username, uid, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l00150"></a>00150 }
<a name="l00151"></a>00151
<a name="l00159"></a>00159 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l00160"></a><a class="code" href="group__DBusInternalsUtils.html#ga90657adefa9bbac9b35eee63dd46a854">00160</a> <a class="code" href="group__DBusInternalsUtils.html#ga90657adefa9bbac9b35eee63dd46a854" title="Gets group ID given groupname.">_dbus_get_group_id</a> (<span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *groupname,
<a name="l00161"></a>00161 <a class="code" href="group__DBusSysdeps.html#ga2f5c2e418b81ec2a86594f56ec6d7627" title="A group ID.">dbus_gid_t</a> *gid)
<a name="l00162"></a>00162 {
<a name="l00163"></a>00163 DBusUserDatabase *db;
<a name="l00164"></a>00164 <span class="keyword">const</span> <a class="code" href="structDBusGroupInfo.html" title="Information about a UNIX group.">DBusGroupInfo</a> *info;
<a name="l00165"></a>00165
<a name="l00166"></a>00166 <span class="comment">/* FIXME: this can't distinguish ENOMEM from other errors */</span>
<a name="l00167"></a>00167 <span class="keywordflow">if</span> (!<a class="code" href="group__DBusInternalsUtils.html#ga15df3b3fdaa4946f69ff87f3a9a03fe7" title="Locks global system user database.">_dbus_user_database_lock_system</a> ())
<a name="l00168"></a>00168 <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to "0".">FALSE</a>;
<a name="l00169"></a>00169
<a name="l00170"></a>00170 db = <a class="code" href="group__DBusInternalsUtils.html#ga79b6c3cf0d735622b6af2795840f9d21" title="Gets the system global user database; must be called with lock held (_dbus_user_database_lock_system(...">_dbus_user_database_get_system</a> ();
<a name="l00171"></a>00171 <span class="keywordflow">if</span> (db == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l00172"></a>00172 {
<a name="l00173"></a>00173 <a class="code" href="group__DBusInternalsUtils.html#ga468e1d62e1df24bb699c4a37fdfa274c" title="Unlocks global system user database.">_dbus_user_database_unlock_system</a> ();
<a name="l00174"></a>00174 <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to "0".">FALSE</a>;
<a name="l00175"></a>00175 }
<a name="l00176"></a>00176
<a name="l00177"></a>00177 <span class="keywordflow">if</span> (!<a class="code" href="group__DBusInternalsUtils.html#gad370299b907799440331c47e8d2357e0" title="Gets the user information for the given group name, returned group info should not be freed...">_dbus_user_database_get_groupname</a> (db, groupname,
<a name="l00178"></a>00178 &info, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>))
<a name="l00179"></a>00179 {
<a name="l00180"></a>00180 <a class="code" href="group__DBusInternalsUtils.html#ga468e1d62e1df24bb699c4a37fdfa274c" title="Unlocks global system user database.">_dbus_user_database_unlock_system</a> ();
<a name="l00181"></a>00181 <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to "0".">FALSE</a>;
<a name="l00182"></a>00182 }
<a name="l00183"></a>00183
<a name="l00184"></a>00184 *gid = info-><a class="code" href="structDBusGroupInfo.html#a583e8d6d421fa85fb1d43789efae4b75" title="GID.">gid</a>;
<a name="l00185"></a>00185
<a name="l00186"></a>00186 <a class="code" href="group__DBusInternalsUtils.html#ga468e1d62e1df24bb699c4a37fdfa274c" title="Unlocks global system user database.">_dbus_user_database_unlock_system</a> ();
<a name="l00187"></a>00187 <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to "1".">TRUE</a>;
<a name="l00188"></a>00188 }
<a name="l00189"></a>00189
<a name="l00198"></a>00198 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l00199"></a><a class="code" href="group__DBusInternalsUtils.html#gac82f42ff83fabbde717cc08569265e6e">00199</a> <a class="code" href="group__DBusInternalsUtils.html#gac82f42ff83fabbde717cc08569265e6e" title="Gets user ID and primary group given username.">_dbus_get_user_id_and_primary_group</a> (<span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *username,
<a name="l00200"></a>00200 <a class="code" href="group__DBusSysdeps.html#ga186e987b700f9ddc6cea8aa0db82b151" title="A user ID.">dbus_uid_t</a> *uid_p,
<a name="l00201"></a>00201 <a class="code" href="group__DBusSysdeps.html#ga2f5c2e418b81ec2a86594f56ec6d7627" title="A group ID.">dbus_gid_t</a> *gid_p)
<a name="l00202"></a>00202 {
<a name="l00203"></a>00203 DBusUserDatabase *db;
<a name="l00204"></a>00204 <span class="keyword">const</span> <a class="code" href="structDBusUserInfo.html" title="Information about a UNIX user.">DBusUserInfo</a> *info;
<a name="l00205"></a>00205
<a name="l00206"></a>00206 <span class="comment">/* FIXME: this can't distinguish ENOMEM from other errors */</span>
<a name="l00207"></a>00207 <span class="keywordflow">if</span> (!<a class="code" href="group__DBusInternalsUtils.html#ga15df3b3fdaa4946f69ff87f3a9a03fe7" title="Locks global system user database.">_dbus_user_database_lock_system</a> ())
<a name="l00208"></a>00208 <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to "0".">FALSE</a>;
<a name="l00209"></a>00209
<a name="l00210"></a>00210 db = <a class="code" href="group__DBusInternalsUtils.html#ga79b6c3cf0d735622b6af2795840f9d21" title="Gets the system global user database; must be called with lock held (_dbus_user_database_lock_system(...">_dbus_user_database_get_system</a> ();
<a name="l00211"></a>00211 <span class="keywordflow">if</span> (db == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l00212"></a>00212 {
<a name="l00213"></a>00213 <a class="code" href="group__DBusInternalsUtils.html#ga468e1d62e1df24bb699c4a37fdfa274c" title="Unlocks global system user database.">_dbus_user_database_unlock_system</a> ();
<a name="l00214"></a>00214 <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to "0".">FALSE</a>;
<a name="l00215"></a>00215 }
<a name="l00216"></a>00216
<a name="l00217"></a>00217 <span class="keywordflow">if</span> (!<a class="code" href="group__DBusInternalsUtils.html#gaccf1d5b330707a1835dcf4ce49a29c8c" title="Gets the user information for the given username.">_dbus_user_database_get_username</a> (db, username,
<a name="l00218"></a>00218 &info, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>))
<a name="l00219"></a>00219 {
<a name="l00220"></a>00220 <a class="code" href="group__DBusInternalsUtils.html#ga468e1d62e1df24bb699c4a37fdfa274c" title="Unlocks global system user database.">_dbus_user_database_unlock_system</a> ();
<a name="l00221"></a>00221 <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to "0".">FALSE</a>;
<a name="l00222"></a>00222 }
<a name="l00223"></a>00223
<a name="l00224"></a>00224 <span class="keywordflow">if</span> (uid_p)
<a name="l00225"></a>00225 *uid_p = info-><a class="code" href="structDBusUserInfo.html#a2d9c74d29f371e391a79b81162050b2e" title="UID.">uid</a>;
<a name="l00226"></a>00226 <span class="keywordflow">if</span> (gid_p)
<a name="l00227"></a>00227 *gid_p = info-><a class="code" href="structDBusUserInfo.html#ac970de2fac9ea4ba91485e6c37c3bf93" title="GID.">primary_gid</a>;
<a name="l00228"></a>00228
<a name="l00229"></a>00229 <a class="code" href="group__DBusInternalsUtils.html#ga468e1d62e1df24bb699c4a37fdfa274c" title="Unlocks global system user database.">_dbus_user_database_unlock_system</a> ();
<a name="l00230"></a>00230 <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to "1".">TRUE</a>;
<a name="l00231"></a>00231 }
<a name="l00232"></a>00232
<a name="l00245"></a>00245 <a class="code" href="structDBusGroupInfo.html" title="Information about a UNIX group.">DBusGroupInfo</a>*
<a name="l00246"></a><a class="code" href="group__DBusInternalsUtils.html#gaf6b7452691c0c7d11fec4b9214137052">00246</a> <a class="code" href="group__DBusInternalsUtils.html#gaf6b7452691c0c7d11fec4b9214137052" title="Looks up a gid or group name in the user database.">_dbus_user_database_lookup_group</a> (DBusUserDatabase *db,
<a name="l00247"></a>00247 <a class="code" href="group__DBusSysdeps.html#ga2f5c2e418b81ec2a86594f56ec6d7627" title="A group ID.">dbus_gid_t</a> gid,
<a name="l00248"></a>00248 <span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *groupname,
<a name="l00249"></a>00249 <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a> *error)
<a name="l00250"></a>00250 {
<a name="l00251"></a>00251 <a class="code" href="structDBusGroupInfo.html" title="Information about a UNIX group.">DBusGroupInfo</a> *info;
<a name="l00252"></a>00252
<a name="l00253"></a>00253 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l00254"></a>00254
<a name="l00255"></a>00255 <span class="comment">/* See if the group is really a number */</span>
<a name="l00256"></a>00256 <span class="keywordflow">if</span> (gid == <a class="code" href="group__DBusSysdeps.html#ga3d2f3fb32bb759cabe362ca2de383f7d" title="an invalid UID used to represent an uninitialized dbus_uid_t field">DBUS_UID_UNSET</a>)
<a name="l00257"></a>00257 {
<a name="l00258"></a>00258 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> n;
<a name="l00259"></a>00259
<a name="l00260"></a>00260 <span class="keywordflow">if</span> (<a class="code" href="group__DBusInternalsUtils.html#gad1c3538c544df91f438a13c9fb4d3a1b" title="Checks if a given string is actually a number and converts it if it is.">_dbus_is_a_number</a> (groupname, &n))
<a name="l00261"></a>00261 gid = n;
<a name="l00262"></a>00262 }
<a name="l00263"></a>00263
<a name="l00264"></a>00264 <span class="keywordflow">if</span> (gid != <a class="code" href="group__DBusSysdeps.html#ga768a080926a119a6131083facc0bd42b" title="an invalid GID used to represent an uninitialized dbus_gid_t field">DBUS_GID_UNSET</a>)
<a name="l00265"></a>00265 info = <a class="code" href="group__DBusHashTable.html#gae0ac411f87a797767f36c6e64fd807b3" title="Looks up the value for a given integer in a hash table of type DBUS_HASH_UINTPTR.">_dbus_hash_table_lookup_uintptr</a> (db->groups, gid);
<a name="l00266"></a>00266 <span class="keywordflow">else</span>
<a name="l00267"></a>00267 info = <a class="code" href="group__DBusHashTable.html#gad51eb3fe682721dd4f6a920ca87cb730" title="Looks up the value for a given string in a hash table of type DBUS_HASH_STRING.">_dbus_hash_table_lookup_string</a> (db->groups_by_name,
<a name="l00268"></a>00268 <a class="code" href="group__DBusString.html#ga33e20241ae7d784624f97d89b1a0539e" title="Gets the raw character buffer from a const string.">_dbus_string_get_const_data</a> (groupname));
<a name="l00269"></a>00269 <span class="keywordflow">if</span> (info)
<a name="l00270"></a>00270 {
<a name="l00271"></a>00271 _dbus_verbose (<span class="stringliteral">"Using cache for GID "</span><a class="code" href="group__DBusSysdeps.html#gaaab5918b2ae57886d9783df09bd61c7e" title="an appropriate printf format for dbus_gid_t">DBUS_GID_FORMAT</a><span class="stringliteral">" information\n"</span>,
<a name="l00272"></a>00272 info-><a class="code" href="structDBusGroupInfo.html#a583e8d6d421fa85fb1d43789efae4b75" title="GID.">gid</a>);
<a name="l00273"></a>00273 <span class="keywordflow">return</span> info;
<a name="l00274"></a>00274 }
<a name="l00275"></a>00275 <span class="keywordflow">else</span>
<a name="l00276"></a>00276 {
<a name="l00277"></a>00277 <span class="keywordflow">if</span> (gid != <a class="code" href="group__DBusSysdeps.html#ga768a080926a119a6131083facc0bd42b" title="an invalid GID used to represent an uninitialized dbus_gid_t field">DBUS_GID_UNSET</a>)
<a name="l00278"></a>00278 _dbus_verbose (<span class="stringliteral">"No cache for GID "</span><a class="code" href="group__DBusSysdeps.html#gaaab5918b2ae57886d9783df09bd61c7e" title="an appropriate printf format for dbus_gid_t">DBUS_GID_FORMAT</a><span class="stringliteral">"\n"</span>,
<a name="l00279"></a>00279 gid);
<a name="l00280"></a>00280 <span class="keywordflow">else</span>
<a name="l00281"></a>00281 _dbus_verbose (<span class="stringliteral">"No cache for groupname \"%s\"\n"</span>,
<a name="l00282"></a>00282 <a class="code" href="group__DBusString.html#ga33e20241ae7d784624f97d89b1a0539e" title="Gets the raw character buffer from a const string.">_dbus_string_get_const_data</a> (groupname));
<a name="l00283"></a>00283
<a name="l00284"></a>00284 info = <a class="code" href="group__DBusMemory.html#gaba9d823abda7f4cadbaf5177d3b8b793" title="Safe macro for using dbus_malloc0().">dbus_new0</a> (<a class="code" href="structDBusGroupInfo.html" title="Information about a UNIX group.">DBusGroupInfo</a>, 1);
<a name="l00285"></a>00285 <span class="keywordflow">if</span> (info == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l00286"></a>00286 {
<a name="l00287"></a>00287 <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gac32eaf0b92f798307853cd4fe0cf11c2" title="There was not enough memory to complete an operation.">DBUS_ERROR_NO_MEMORY</a>, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l00288"></a>00288 <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00289"></a>00289 }
<a name="l00290"></a>00290
<a name="l00291"></a>00291 <span class="keywordflow">if</span> (gid != <a class="code" href="group__DBusSysdeps.html#ga768a080926a119a6131083facc0bd42b" title="an invalid GID used to represent an uninitialized dbus_gid_t field">DBUS_GID_UNSET</a>)
<a name="l00292"></a>00292 {
<a name="l00293"></a>00293 <span class="keywordflow">if</span> (!<a class="code" href="group__DBusSysdepsUnix.html#gad235e373b223982b7d3aba8a2b602b58" title="Initializes the given DBusGroupInfo struct with information about the given group ID...">_dbus_group_info_fill_gid</a> (info, gid, error))
<a name="l00294"></a>00294 {
<a name="l00295"></a>00295 _DBUS_ASSERT_ERROR_IS_SET (error);
<a name="l00296"></a>00296 <a class="code" href="group__DBusInternalsUtils.html#gab9420d7a4a31329a00fd5709f8cf08ba" title="Frees the given DBusGroupInfo's members with _dbus_group_info_free() and also calls dbus_free() on th...">_dbus_group_info_free_allocated</a> (info);
<a name="l00297"></a>00297 <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00298"></a>00298 }
<a name="l00299"></a>00299 }
<a name="l00300"></a>00300 <span class="keywordflow">else</span>
<a name="l00301"></a>00301 {
<a name="l00302"></a>00302 <span class="keywordflow">if</span> (!<a class="code" href="group__DBusSysdepsUnix.html#ga23814bdf1859c6aa52da1feab8f1aed4" title="Initializes the given DBusGroupInfo struct with information about the given group name...">_dbus_group_info_fill</a> (info, groupname, error))
<a name="l00303"></a>00303 {
<a name="l00304"></a>00304 _DBUS_ASSERT_ERROR_IS_SET (error);
<a name="l00305"></a>00305 <a class="code" href="group__DBusInternalsUtils.html#gab9420d7a4a31329a00fd5709f8cf08ba" title="Frees the given DBusGroupInfo's members with _dbus_group_info_free() and also calls dbus_free() on th...">_dbus_group_info_free_allocated</a> (info);
<a name="l00306"></a>00306 <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00307"></a>00307 }
<a name="l00308"></a>00308 }
<a name="l00309"></a>00309
<a name="l00310"></a>00310 <span class="comment">/* don't use these past here */</span>
<a name="l00311"></a>00311 gid = <a class="code" href="group__DBusSysdeps.html#ga768a080926a119a6131083facc0bd42b" title="an invalid GID used to represent an uninitialized dbus_gid_t field">DBUS_GID_UNSET</a>;
<a name="l00312"></a>00312 groupname = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00313"></a>00313
<a name="l00314"></a>00314 <span class="keywordflow">if</span> (!<a class="code" href="group__DBusHashTable.html#ga811d833032ca919a9063ca835482d01a" title="Creates a hash entry with the given key and value.">_dbus_hash_table_insert_uintptr</a> (db->groups, info-><a class="code" href="structDBusGroupInfo.html#a583e8d6d421fa85fb1d43789efae4b75" title="GID.">gid</a>, info))
<a name="l00315"></a>00315 {
<a name="l00316"></a>00316 <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gac32eaf0b92f798307853cd4fe0cf11c2" title="There was not enough memory to complete an operation.">DBUS_ERROR_NO_MEMORY</a>, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l00317"></a>00317 <a class="code" href="group__DBusInternalsUtils.html#gab9420d7a4a31329a00fd5709f8cf08ba" title="Frees the given DBusGroupInfo's members with _dbus_group_info_free() and also calls dbus_free() on th...">_dbus_group_info_free_allocated</a> (info);
<a name="l00318"></a>00318 <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00319"></a>00319 }
<a name="l00320"></a>00320
<a name="l00321"></a>00321
<a name="l00322"></a>00322 <span class="keywordflow">if</span> (!<a class="code" href="group__DBusHashTable.html#ga43e98a91a11952824c544330e19f6c22" title="Creates a hash entry with the given key and value.">_dbus_hash_table_insert_string</a> (db->groups_by_name,
<a name="l00323"></a>00323 info-><a class="code" href="structDBusGroupInfo.html#af1a4b925663336f64c62cfcab40571c6" title="Group name.">groupname</a>,
<a name="l00324"></a>00324 info))
<a name="l00325"></a>00325 {
<a name="l00326"></a>00326 <a class="code" href="group__DBusHashTable.html#ga0ad8fa1108bad2b4bd5b4ce539d32d64" title="Removes the hash entry for the given key.">_dbus_hash_table_remove_uintptr</a> (db->groups, info-><a class="code" href="structDBusGroupInfo.html#a583e8d6d421fa85fb1d43789efae4b75" title="GID.">gid</a>);
<a name="l00327"></a>00327 <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gac32eaf0b92f798307853cd4fe0cf11c2" title="There was not enough memory to complete an operation.">DBUS_ERROR_NO_MEMORY</a>, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l00328"></a>00328 <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00329"></a>00329 }
<a name="l00330"></a>00330
<a name="l00331"></a>00331 <span class="keywordflow">return</span> info;
<a name="l00332"></a>00332 }
<a name="l00333"></a>00333 }
<a name="l00334"></a>00334
<a name="l00335"></a>00335
<a name="l00346"></a>00346 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l00347"></a><a class="code" href="group__DBusInternalsUtils.html#gad370299b907799440331c47e8d2357e0">00347</a> <a class="code" href="group__DBusInternalsUtils.html#gad370299b907799440331c47e8d2357e0" title="Gets the user information for the given group name, returned group info should not be freed...">_dbus_user_database_get_groupname</a> (DBusUserDatabase *db,
<a name="l00348"></a>00348 <span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *groupname,
<a name="l00349"></a>00349 <span class="keyword">const</span> <a class="code" href="structDBusGroupInfo.html" title="Information about a UNIX group.">DBusGroupInfo</a> **info,
<a name="l00350"></a>00350 <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a> *error)
<a name="l00351"></a>00351 {
<a name="l00352"></a>00352 *info = <a class="code" href="group__DBusInternalsUtils.html#gaf6b7452691c0c7d11fec4b9214137052" title="Looks up a gid or group name in the user database.">_dbus_user_database_lookup_group</a> (db, <a class="code" href="group__DBusSysdeps.html#ga768a080926a119a6131083facc0bd42b" title="an invalid GID used to represent an uninitialized dbus_gid_t field">DBUS_GID_UNSET</a>, groupname, error);
<a name="l00353"></a>00353 <span class="keywordflow">return</span> *info != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00354"></a>00354 }
<a name="l00355"></a>00355
<a name="l00366"></a>00366 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l00367"></a><a class="code" href="group__DBusInternalsUtils.html#ga70d3fd2edd61c69edc6f7fe1d5cfa6ea">00367</a> <a class="code" href="group__DBusInternalsUtils.html#ga70d3fd2edd61c69edc6f7fe1d5cfa6ea" title="Gets the user information for the given GID, returned group info should not be freed.">_dbus_user_database_get_gid</a> (DBusUserDatabase *db,
<a name="l00368"></a>00368 <a class="code" href="group__DBusSysdeps.html#ga2f5c2e418b81ec2a86594f56ec6d7627" title="A group ID.">dbus_gid_t</a> gid,
<a name="l00369"></a>00369 <span class="keyword">const</span> <a class="code" href="structDBusGroupInfo.html" title="Information about a UNIX group.">DBusGroupInfo</a> **info,
<a name="l00370"></a>00370 <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a> *error)
<a name="l00371"></a>00371 {
<a name="l00372"></a>00372 *info = <a class="code" href="group__DBusInternalsUtils.html#gaf6b7452691c0c7d11fec4b9214137052" title="Looks up a gid or group name in the user database.">_dbus_user_database_lookup_group</a> (db, gid, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, error);
<a name="l00373"></a>00373 <span class="keywordflow">return</span> *info != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00374"></a>00374 }
<a name="l00375"></a>00375
<a name="l00376"></a>00376
<a name="l00387"></a>00387 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l00388"></a><a class="code" href="group__DBusInternalsUtils.html#gae9408936869314101f8ea13dfa5ba968">00388</a> <a class="code" href="group__DBusInternalsUtils.html#gae9408936869314101f8ea13dfa5ba968" title="Gets all groups corresponding to the given UID.">_dbus_groups_from_uid</a> (<a class="code" href="group__DBusSysdeps.html#ga186e987b700f9ddc6cea8aa0db82b151" title="A user ID.">dbus_uid_t</a> uid,
<a name="l00389"></a>00389 <a class="code" href="group__DBusSysdeps.html#ga2f5c2e418b81ec2a86594f56ec6d7627" title="A group ID.">dbus_gid_t</a> **group_ids,
<a name="l00390"></a>00390 <span class="keywordtype">int</span> *n_group_ids)
<a name="l00391"></a>00391 {
<a name="l00392"></a>00392 DBusUserDatabase *db;
<a name="l00393"></a>00393 <span class="keyword">const</span> <a class="code" href="structDBusUserInfo.html" title="Information about a UNIX user.">DBusUserInfo</a> *info;
<a name="l00394"></a>00394 *group_ids = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00395"></a>00395 *n_group_ids = 0;
<a name="l00396"></a>00396
<a name="l00397"></a>00397 <span class="comment">/* FIXME: this can't distinguish ENOMEM from other errors */</span>
<a name="l00398"></a>00398 <span class="keywordflow">if</span> (!<a class="code" href="group__DBusInternalsUtils.html#ga15df3b3fdaa4946f69ff87f3a9a03fe7" title="Locks global system user database.">_dbus_user_database_lock_system</a> ())
<a name="l00399"></a>00399 <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to "0".">FALSE</a>;
<a name="l00400"></a>00400
<a name="l00401"></a>00401 db = <a class="code" href="group__DBusInternalsUtils.html#ga79b6c3cf0d735622b6af2795840f9d21" title="Gets the system global user database; must be called with lock held (_dbus_user_database_lock_system(...">_dbus_user_database_get_system</a> ();
<a name="l00402"></a>00402 <span class="keywordflow">if</span> (db == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l00403"></a>00403 {
<a name="l00404"></a>00404 <a class="code" href="group__DBusInternalsUtils.html#ga468e1d62e1df24bb699c4a37fdfa274c" title="Unlocks global system user database.">_dbus_user_database_unlock_system</a> ();
<a name="l00405"></a>00405 <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to "0".">FALSE</a>;
<a name="l00406"></a>00406 }
<a name="l00407"></a>00407
<a name="l00408"></a>00408 <span class="keywordflow">if</span> (!<a class="code" href="group__DBusInternalsUtils.html#ga6a7e8b8cf3a6968972e9a49726022638" title="Gets the user information for the given UID, returned user info should not be freed.">_dbus_user_database_get_uid</a> (db, uid,
<a name="l00409"></a>00409 &info, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>))
<a name="l00410"></a>00410 {
<a name="l00411"></a>00411 <a class="code" href="group__DBusInternalsUtils.html#ga468e1d62e1df24bb699c4a37fdfa274c" title="Unlocks global system user database.">_dbus_user_database_unlock_system</a> ();
<a name="l00412"></a>00412 <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to "0".">FALSE</a>;
<a name="l00413"></a>00413 }
<a name="l00414"></a>00414
<a name="l00415"></a>00415 _dbus_assert (info-><a class="code" href="structDBusUserInfo.html#a2d9c74d29f371e391a79b81162050b2e" title="UID.">uid</a> == uid);
<a name="l00416"></a>00416
<a name="l00417"></a>00417 <span class="keywordflow">if</span> (info-><a class="code" href="structDBusUserInfo.html#a21c07867fbffb1854a97aed265d87c89" title="Size of group IDs array.">n_group_ids</a> > 0)
<a name="l00418"></a>00418 {
<a name="l00419"></a>00419 *group_ids = <a class="code" href="group__DBusMemory.html#ga54ccb556e7964112a825a7f46c156ca0" title="Safe macro for using dbus_malloc().">dbus_new</a> (<a class="code" href="group__DBusSysdeps.html#ga2f5c2e418b81ec2a86594f56ec6d7627" title="A group ID.">dbus_gid_t</a>, info-><a class="code" href="structDBusUserInfo.html#a21c07867fbffb1854a97aed265d87c89" title="Size of group IDs array.">n_group_ids</a>);
<a name="l00420"></a>00420 <span class="keywordflow">if</span> (*group_ids == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l00421"></a>00421 {
<a name="l00422"></a>00422 <a class="code" href="group__DBusInternalsUtils.html#ga468e1d62e1df24bb699c4a37fdfa274c" title="Unlocks global system user database.">_dbus_user_database_unlock_system</a> ();
<a name="l00423"></a>00423 <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to "0".">FALSE</a>;
<a name="l00424"></a>00424 }
<a name="l00425"></a>00425
<a name="l00426"></a>00426 *n_group_ids = info-><a class="code" href="structDBusUserInfo.html#a21c07867fbffb1854a97aed265d87c89" title="Size of group IDs array.">n_group_ids</a>;
<a name="l00427"></a>00427
<a name="l00428"></a>00428 memcpy (*group_ids, info-><a class="code" href="structDBusUserInfo.html#a902af9e0fb7d37c14eefb7d2b016ab11" title="Groups IDs, *including* above primary group.">group_ids</a>, info-><a class="code" href="structDBusUserInfo.html#a21c07867fbffb1854a97aed265d87c89" title="Size of group IDs array.">n_group_ids</a> * sizeof (<a class="code" href="group__DBusSysdeps.html#ga2f5c2e418b81ec2a86594f56ec6d7627" title="A group ID.">dbus_gid_t</a>));
<a name="l00429"></a>00429 }
<a name="l00430"></a>00430
<a name="l00431"></a>00431 <a class="code" href="group__DBusInternalsUtils.html#ga468e1d62e1df24bb699c4a37fdfa274c" title="Unlocks global system user database.">_dbus_user_database_unlock_system</a> ();
<a name="l00432"></a>00432 <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to "1".">TRUE</a>;
<a name="l00433"></a>00433 }
<a name="l00436"></a>00436 <span class="preprocessor">#ifdef DBUS_ENABLE_EMBEDDED_TESTS</span>
<a name="l00437"></a>00437 <span class="preprocessor"></span><span class="preprocessor">#include <stdio.h></span>
<a name="l00438"></a>00438
<a name="l00444"></a>00444 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l00445"></a>00445 _dbus_userdb_test (<span class="keyword">const</span> <span class="keywordtype">char</span> *test_data_dir)
<a name="l00446"></a>00446 {
<a name="l00447"></a>00447 <span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *username;
<a name="l00448"></a>00448 <span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *homedir;
<a name="l00449"></a>00449 <a class="code" href="group__DBusSysdeps.html#ga186e987b700f9ddc6cea8aa0db82b151" title="A user ID.">dbus_uid_t</a> uid;
<a name="l00450"></a>00450 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> *group_ids;
<a name="l00451"></a>00451 <span class="keywordtype">int</span> n_group_ids, i;
<a name="l00452"></a>00452 <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a> error;
<a name="l00453"></a>00453
<a name="l00454"></a>00454 <span class="keywordflow">if</span> (!<a class="code" href="group__DBusInternalsUtils.html#ga9c4c1850787bfd457107b95fa1878869" title="Gets username of user owning current process.">_dbus_username_from_current_process</a> (&username))
<a name="l00455"></a>00455 _dbus_assert_not_reached (<span class="stringliteral">"didn't get username"</span>);
<a name="l00456"></a>00456
<a name="l00457"></a>00457 <span class="keywordflow">if</span> (!<a class="code" href="group__DBusInternalsUtils.html#ga17ce3ab061a3ae2441cd33ece34f5e7a" title="Gets homedir of user owning current process.">_dbus_homedir_from_current_process</a> (&homedir))
<a name="l00458"></a>00458 _dbus_assert_not_reached (<span class="stringliteral">"didn't get homedir"</span>);
<a name="l00459"></a>00459
<a name="l00460"></a>00460 <span class="keywordflow">if</span> (!<a class="code" href="group__DBusInternalsUtils.html#gaf07ee24eddcb3b0f85fa54196bc44fe1" title="Gets user ID given username.">_dbus_get_user_id</a> (username, &uid))
<a name="l00461"></a>00461 _dbus_assert_not_reached (<span class="stringliteral">"didn't get uid"</span>);
<a name="l00462"></a>00462
<a name="l00463"></a>00463 <span class="keywordflow">if</span> (!<a class="code" href="group__DBusInternalsUtils.html#gae9408936869314101f8ea13dfa5ba968" title="Gets all groups corresponding to the given UID.">_dbus_groups_from_uid</a> (uid, &group_ids, &n_group_ids))
<a name="l00464"></a>00464 _dbus_assert_not_reached (<span class="stringliteral">"didn't get groups"</span>);
<a name="l00465"></a>00465
<a name="l00466"></a>00466 printf (<span class="stringliteral">" Current user: %s homedir: %s gids:"</span>,
<a name="l00467"></a>00467 <a class="code" href="group__DBusString.html#ga33e20241ae7d784624f97d89b1a0539e" title="Gets the raw character buffer from a const string.">_dbus_string_get_const_data</a> (username),
<a name="l00468"></a>00468 <a class="code" href="group__DBusString.html#ga33e20241ae7d784624f97d89b1a0539e" title="Gets the raw character buffer from a const string.">_dbus_string_get_const_data</a> (homedir));
<a name="l00469"></a>00469
<a name="l00470"></a>00470 <span class="keywordflow">for</span> (i=0; i<n_group_ids; i++)
<a name="l00471"></a>00471 printf(<span class="stringliteral">" %ld"</span>, group_ids[i]);
<a name="l00472"></a>00472
<a name="l00473"></a>00473 printf (<span class="stringliteral">"\n"</span>);
<a name="l00474"></a>00474
<a name="l00475"></a>00475 <a class="code" href="group__DBusErrors.html#ga8937f0b7cdf8554fa6305158ce453fbe" title="Initializes a DBusError structure.">dbus_error_init</a> (&error);
<a name="l00476"></a>00476 printf (<span class="stringliteral">"Is Console user: %i\n"</span>,
<a name="l00477"></a>00477 <a class="code" href="group__DBusInternalsUtils.html#gaa504db352a939909051a494d06c5b607" title="Checks to see if the UID sent in is the console user.">_dbus_is_console_user</a> (uid, &error));
<a name="l00478"></a>00478 printf (<span class="stringliteral">"Invocation was OK: %s\n"</span>, error.<a class="code" href="structDBusError.html#afb559175326de5b6b340e26204e92d72" title="public error message field">message</a> ? error.<a class="code" href="structDBusError.html#afb559175326de5b6b340e26204e92d72" title="public error message field">message</a> : <span class="stringliteral">"yes"</span>);
<a name="l00479"></a>00479 <a class="code" href="group__DBusErrors.html#gaac6c14ead14829ee4e090f39de6a7568" title="Frees an error that's been set (or just initialized), then reinitializes the error as in dbus_error_i...">dbus_error_free</a> (&error);
<a name="l00480"></a>00480 printf (<span class="stringliteral">"Is Console user 4711: %i\n"</span>,
<a name="l00481"></a>00481 <a class="code" href="group__DBusInternalsUtils.html#gaa504db352a939909051a494d06c5b607" title="Checks to see if the UID sent in is the console user.">_dbus_is_console_user</a> (4711, &error));
<a name="l00482"></a>00482 printf (<span class="stringliteral">"Invocation was OK: %s\n"</span>, error.<a class="code" href="structDBusError.html#afb559175326de5b6b340e26204e92d72" title="public error message field">message</a> ? error.<a class="code" href="structDBusError.html#afb559175326de5b6b340e26204e92d72" title="public error message field">message</a> : <span class="stringliteral">"yes"</span>);
<a name="l00483"></a>00483 <a class="code" href="group__DBusErrors.html#gaac6c14ead14829ee4e090f39de6a7568" title="Frees an error that's been set (or just initialized), then reinitializes the error as in dbus_error_i...">dbus_error_free</a> (&error);
<a name="l00484"></a>00484
<a name="l00485"></a>00485 <a class="code" href="group__DBusMemory.html#ga34e666b19b015035a9a31e53da84b39a" title="Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().">dbus_free</a> (group_ids);
<a name="l00486"></a>00486
<a name="l00487"></a>00487 <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to "1".">TRUE</a>;
<a name="l00488"></a>00488 }
<a name="l00489"></a>00489 <span class="preprocessor">#endif </span><span class="comment">/* DBUS_ENABLE_EMBEDDED_TESTS */</span>
</pre></div></div><!-- contents -->
<hr class="footer"/><address class="footer"><small>
Generated on Thu Mar 3 2016 17:50:32 for D-Bus by  <a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>
</body>
</html>