MOON
Server: Apache/2.2.31 (Unix) mod_ssl/2.2.31 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4
System: Linux csr818.wilogic.com 2.6.18-419.el5xen #1 SMP Fri Feb 24 22:50:37 UTC 2017 x86_64
User: digitals (531)
PHP: 5.4.45
Disabled: NONE
Upload Files
File: //usr/share/devhelp/books/dbus/api/dbus-sysdeps-util-unix_8c-source.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>D-Bus: dbus-sysdeps-util-unix.c Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.7 -->
<div class="tabs">
  <ul>
    <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
    <li><a href="modules.html"><span>Modules</span></a></li>
    <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
    <li id="current"><a href="files.html"><span>Files</span></a></li>
    <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
  </ul></div>
<h1>dbus-sysdeps-util-unix.c</h1><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-sysdeps-util-unix.c Would be in dbus-sysdeps-unix.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) 2002, 2003, 2004, 2005  Red Hat, Inc.</span>
<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2003 CodeFactory AB</span>
<a name="l00006"></a>00006 <span class="comment"> *</span>
<a name="l00007"></a>00007 <span class="comment"> * Licensed under the Academic Free License version 2.1</span>
<a name="l00008"></a>00008 <span class="comment"> * </span>
<a name="l00009"></a>00009 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
<a name="l00010"></a>00010 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
<a name="l00011"></a>00011 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
<a name="l00012"></a>00012 <span class="comment"> * (at your option) any later version.</span>
<a name="l00013"></a>00013 <span class="comment"> *</span>
<a name="l00014"></a>00014 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
<a name="l00015"></a>00015 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00016"></a>00016 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<a name="l00017"></a>00017 <span class="comment"> * GNU General Public License for more details.</span>
<a name="l00018"></a>00018 <span class="comment"> * </span>
<a name="l00019"></a>00019 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
<a name="l00020"></a>00020 <span class="comment"> * along with this program; if not, write to the Free Software</span>
<a name="l00021"></a>00021 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
<a name="l00022"></a>00022 <span class="comment"> *</span>
<a name="l00023"></a>00023 <span class="comment"> */</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include "dbus-sysdeps.h"</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include "dbus-sysdeps-unix.h"</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include "dbus-internals.h"</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include "dbus-protocol.h"</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include "dbus-string.h"</span>
<a name="l00029"></a>00029 <span class="preprocessor">#define DBUS_USERDB_INCLUDES_PRIVATE 1</span>
<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#include "dbus-userdb.h"</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include "dbus-test.h"</span>
<a name="l00032"></a>00032 
<a name="l00033"></a>00033 <span class="preprocessor">#include &lt;sys/types.h&gt;</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00036"></a>00036 <span class="preprocessor">#include &lt;signal.h&gt;</span>
<a name="l00037"></a>00037 <span class="preprocessor">#include &lt;unistd.h&gt;</span>
<a name="l00038"></a>00038 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00039"></a>00039 <span class="preprocessor">#include &lt;errno.h&gt;</span>
<a name="l00040"></a>00040 <span class="preprocessor">#include &lt;fcntl.h&gt;</span>
<a name="l00041"></a>00041 <span class="preprocessor">#include &lt;sys/stat.h&gt;</span>
<a name="l00042"></a>00042 <span class="preprocessor">#include &lt;grp.h&gt;</span>
<a name="l00043"></a>00043 <span class="preprocessor">#include &lt;sys/socket.h&gt;</span>
<a name="l00044"></a>00044 <span class="preprocessor">#include &lt;dirent.h&gt;</span>
<a name="l00045"></a>00045 <span class="preprocessor">#include &lt;sys/un.h&gt;</span>
<a name="l00046"></a>00046 <span class="preprocessor">#ifdef HAVE_LIBAUDIT</span>
<a name="l00047"></a>00047 <span class="preprocessor"></span><span class="preprocessor">#include &lt;sys/prctl.h&gt;</span>
<a name="l00048"></a>00048 <span class="preprocessor">#include &lt;sys/capability.h&gt;</span>
<a name="l00049"></a>00049 <span class="preprocessor">#include &lt;libaudit.h&gt;</span>
<a name="l00050"></a>00050 <span class="preprocessor">#endif </span><span class="comment">/* HAVE_LIBAUDIT */</span>
<a name="l00051"></a>00051 
<a name="l00052"></a>00052 <span class="preprocessor">#ifdef HAVE_SYS_SYSLIMITS_H</span>
<a name="l00053"></a>00053 <span class="preprocessor"></span><span class="preprocessor">#include &lt;sys/syslimits.h&gt;</span>
<a name="l00054"></a>00054 <span class="preprocessor">#endif</span>
<a name="l00055"></a>00055 <span class="preprocessor"></span>
<a name="l00056"></a>00056 <span class="preprocessor">#ifndef O_BINARY</span>
<a name="l00057"></a>00057 <span class="preprocessor"></span><span class="preprocessor">#define O_BINARY 0</span>
<a name="l00058"></a>00058 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00059"></a>00059 <span class="preprocessor"></span>
<a name="l00073"></a>00073 <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00074"></a><a class="code" href="group__DBusSysdeps.html#g4d4f9b1d4e78ba017ada75a6982ac173">00074</a> <a class="code" href="group__DBusInternalsUtils.html#g4d4f9b1d4e78ba017ada75a6982ac173">_dbus_become_daemon</a> (<span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *pidfile,
<a name="l00075"></a>00075                      <a class="code" href="structDBusPipe.html">DBusPipe</a>         *print_pid_pipe,
<a name="l00076"></a>00076                      <a class="code" href="structDBusError.html">DBusError</a>        *error)
<a name="l00077"></a>00077 {
<a name="l00078"></a>00078   <span class="keyword">const</span> <span class="keywordtype">char</span> *s;
<a name="l00079"></a>00079   pid_t child_pid;
<a name="l00080"></a>00080   <span class="keywordtype">int</span> dev_null_fd;
<a name="l00081"></a>00081 
<a name="l00082"></a>00082   _dbus_verbose (<span class="stringliteral">"Becoming a daemon...\n"</span>);
<a name="l00083"></a>00083 
<a name="l00084"></a>00084   _dbus_verbose (<span class="stringliteral">"chdir to /\n"</span>);
<a name="l00085"></a>00085   <span class="keywordflow">if</span> (chdir (<span class="stringliteral">"/"</span>) &lt; 0)
<a name="l00086"></a>00086     {
<a name="l00087"></a>00087       <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gbb62fd6340d0787fbd56ff8dd2f326c7">DBUS_ERROR_FAILED</a>,
<a name="l00088"></a>00088                       <span class="stringliteral">"Could not chdir() to root directory"</span>);
<a name="l00089"></a>00089       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00090"></a>00090     }
<a name="l00091"></a>00091 
<a name="l00092"></a>00092   _dbus_verbose (<span class="stringliteral">"forking...\n"</span>);
<a name="l00093"></a>00093   <span class="keywordflow">switch</span> ((child_pid = fork ()))
<a name="l00094"></a>00094     {
<a name="l00095"></a>00095     <span class="keywordflow">case</span> -1:
<a name="l00096"></a>00096       _dbus_verbose (<span class="stringliteral">"fork failed\n"</span>);
<a name="l00097"></a>00097       <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#g2212aa0e5732257598a6597748c658e4">_dbus_error_from_errno</a> (errno),
<a name="l00098"></a>00098                       <span class="stringliteral">"Failed to fork daemon: %s"</span>, _dbus_strerror (errno));
<a name="l00099"></a>00099       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00100"></a>00100       <span class="keywordflow">break</span>;
<a name="l00101"></a>00101 
<a name="l00102"></a>00102     <span class="keywordflow">case</span> 0:
<a name="l00103"></a>00103       _dbus_verbose (<span class="stringliteral">"in child, closing std file descriptors\n"</span>);
<a name="l00104"></a>00104 
<a name="l00105"></a>00105       <span class="comment">/* silently ignore failures here, if someone</span>
<a name="l00106"></a>00106 <span class="comment">       * doesn't have /dev/null we may as well try</span>
<a name="l00107"></a>00107 <span class="comment">       * to continue anyhow</span>
<a name="l00108"></a>00108 <span class="comment">       */</span>
<a name="l00109"></a>00109       
<a name="l00110"></a>00110       dev_null_fd = open (<span class="stringliteral">"/dev/null"</span>, O_RDWR);
<a name="l00111"></a>00111       <span class="keywordflow">if</span> (dev_null_fd &gt;= 0)
<a name="l00112"></a>00112         {
<a name="l00113"></a>00113           dup2 (dev_null_fd, 0);
<a name="l00114"></a>00114           dup2 (dev_null_fd, 1);
<a name="l00115"></a>00115           
<a name="l00116"></a>00116           s = <a class="code" href="group__DBusSysdeps.html#gb846071a4de54cb7e518654f9375313a">_dbus_getenv</a> (<span class="stringliteral">"DBUS_DEBUG_OUTPUT"</span>);
<a name="l00117"></a>00117           <span class="keywordflow">if</span> (s == <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> || *s == <span class="charliteral">'\0'</span>)
<a name="l00118"></a>00118             dup2 (dev_null_fd, 2);
<a name="l00119"></a>00119           <span class="keywordflow">else</span>
<a name="l00120"></a>00120             _dbus_verbose (<span class="stringliteral">"keeping stderr open due to DBUS_DEBUG_OUTPUT\n"</span>);
<a name="l00121"></a>00121         }
<a name="l00122"></a>00122 
<a name="l00123"></a>00123       <span class="comment">/* Get a predictable umask */</span>
<a name="l00124"></a>00124       _dbus_verbose (<span class="stringliteral">"setting umask\n"</span>);
<a name="l00125"></a>00125       umask (022);
<a name="l00126"></a>00126       <span class="keywordflow">break</span>;
<a name="l00127"></a>00127 
<a name="l00128"></a>00128     <span class="keywordflow">default</span>:
<a name="l00129"></a>00129       <span class="keywordflow">if</span> (pidfile)
<a name="l00130"></a>00130         {
<a name="l00131"></a>00131           _dbus_verbose (<span class="stringliteral">"parent writing pid file\n"</span>);
<a name="l00132"></a>00132           <span class="keywordflow">if</span> (!<a class="code" href="group__DBusInternalsUtils.html#g7461c6fa553c30f4eb8482675e86668c">_dbus_write_pid_file</a> (pidfile,
<a name="l00133"></a>00133                                      child_pid,
<a name="l00134"></a>00134                                      error))
<a name="l00135"></a>00135             {
<a name="l00136"></a>00136               _dbus_verbose (<span class="stringliteral">"pid file write failed, killing child\n"</span>);
<a name="l00137"></a>00137               kill (child_pid, SIGTERM);
<a name="l00138"></a>00138               <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00139"></a>00139             }
<a name="l00140"></a>00140         }
<a name="l00141"></a>00141 
<a name="l00142"></a>00142       <span class="comment">/* Write PID if requested */</span>
<a name="l00143"></a>00143       <span class="keywordflow">if</span> (print_pid_pipe != <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> &amp;&amp; <a class="code" href="group__DBusSysdeps.html#gb49c65d02349d01ee291a5c49f7a1ed9">_dbus_pipe_is_valid</a> (print_pid_pipe))
<a name="l00144"></a>00144         {
<a name="l00145"></a>00145           <a class="code" href="structDBusString.html">DBusString</a> pid;
<a name="l00146"></a>00146           <span class="keywordtype">int</span> bytes;
<a name="l00147"></a>00147           
<a name="l00148"></a>00148           <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#g348252317f7bb8ac43529972945830ae">_dbus_string_init</a> (&amp;pid))
<a name="l00149"></a>00149             {
<a name="l00150"></a>00150               _DBUS_SET_OOM (error);
<a name="l00151"></a>00151               kill (child_pid, SIGTERM);
<a name="l00152"></a>00152               <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00153"></a>00153             }
<a name="l00154"></a>00154           
<a name="l00155"></a>00155           <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#g41141ca36c361f92b6029530ff83fa66">_dbus_string_append_int</a> (&amp;pid, child_pid) ||
<a name="l00156"></a>00156               !<a class="code" href="group__DBusString.html#g100c5ce0696822c5a4cfbdfaba674d96">_dbus_string_append</a> (&amp;pid, <span class="stringliteral">"\n"</span>))
<a name="l00157"></a>00157             {
<a name="l00158"></a>00158               <a class="code" href="group__DBusString.html#g781ca91acda49a834dce7d0ed0eef212">_dbus_string_free</a> (&amp;pid);
<a name="l00159"></a>00159               _DBUS_SET_OOM (error);
<a name="l00160"></a>00160               kill (child_pid, SIGTERM);
<a name="l00161"></a>00161               <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00162"></a>00162             }
<a name="l00163"></a>00163           
<a name="l00164"></a>00164           bytes = _dbus_string_get_length (&amp;pid);
<a name="l00165"></a>00165           <span class="keywordflow">if</span> (<a class="code" href="group__DBusSysdeps.html#g95ab99cceeaa29082a02f0b971d9e9e5">_dbus_pipe_write</a> (print_pid_pipe, &amp;pid, 0, bytes, error) != bytes)
<a name="l00166"></a>00166             {
<a name="l00167"></a>00167               <span class="comment">/* _dbus_pipe_write sets error only on failure, not short write */</span>
<a name="l00168"></a>00168               <span class="keywordflow">if</span> (error != <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> &amp;&amp; !<a class="code" href="group__DBusErrors.html#g49c2509c79ae0fa01f5004b17e2ec6be">dbus_error_is_set</a>(error))
<a name="l00169"></a>00169                 {
<a name="l00170"></a>00170                   <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gbb62fd6340d0787fbd56ff8dd2f326c7">DBUS_ERROR_FAILED</a>,
<a name="l00171"></a>00171                                   <span class="stringliteral">"Printing message bus PID: did not write enough bytes\n"</span>);
<a name="l00172"></a>00172                 }
<a name="l00173"></a>00173               <a class="code" href="group__DBusString.html#g781ca91acda49a834dce7d0ed0eef212">_dbus_string_free</a> (&amp;pid);
<a name="l00174"></a>00174               kill (child_pid, SIGTERM);
<a name="l00175"></a>00175               <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00176"></a>00176             }
<a name="l00177"></a>00177           
<a name="l00178"></a>00178           <a class="code" href="group__DBusString.html#g781ca91acda49a834dce7d0ed0eef212">_dbus_string_free</a> (&amp;pid);
<a name="l00179"></a>00179         }
<a name="l00180"></a>00180       _dbus_verbose (<span class="stringliteral">"parent exiting\n"</span>);
<a name="l00181"></a>00181       _exit (0);
<a name="l00182"></a>00182       <span class="keywordflow">break</span>;
<a name="l00183"></a>00183     }
<a name="l00184"></a>00184 
<a name="l00185"></a>00185   _dbus_verbose (<span class="stringliteral">"calling setsid()\n"</span>);
<a name="l00186"></a>00186   <span class="keywordflow">if</span> (setsid () == -1)
<a name="l00187"></a>00187     <a class="code" href="group__DBusInternalsUtils.html#g0c4961ec784874f1b1f3aeccea8d3da1">_dbus_assert_not_reached</a> (<span class="stringliteral">"setsid() failed"</span>);
<a name="l00188"></a>00188   
<a name="l00189"></a>00189   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga8cecfc5c5c054d2875c03e77b7be15d">TRUE</a>;
<a name="l00190"></a>00190 }
<a name="l00191"></a>00191 
<a name="l00192"></a>00192 
<a name="l00201"></a>00201 <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00202"></a><a class="code" href="group__DBusSysdeps.html#g7461c6fa553c30f4eb8482675e86668c">00202</a> <a class="code" href="group__DBusInternalsUtils.html#g7461c6fa553c30f4eb8482675e86668c">_dbus_write_pid_file</a> (<span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *filename,
<a name="l00203"></a>00203                       <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>     pid,
<a name="l00204"></a>00204                       <a class="code" href="structDBusError.html">DBusError</a>        *error)
<a name="l00205"></a>00205 {
<a name="l00206"></a>00206   <span class="keyword">const</span> <span class="keywordtype">char</span> *cfilename;
<a name="l00207"></a>00207   <span class="keywordtype">int</span> fd;
<a name="l00208"></a>00208   FILE *f;
<a name="l00209"></a>00209 
<a name="l00210"></a>00210   cfilename = _dbus_string_get_const_data (filename);
<a name="l00211"></a>00211   
<a name="l00212"></a>00212   fd = open (cfilename, O_WRONLY|O_CREAT|O_EXCL|O_BINARY, 0644);
<a name="l00213"></a>00213   
<a name="l00214"></a>00214   <span class="keywordflow">if</span> (fd &lt; 0)
<a name="l00215"></a>00215     {
<a name="l00216"></a>00216       <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#g2212aa0e5732257598a6597748c658e4">_dbus_error_from_errno</a> (errno),
<a name="l00217"></a>00217                       <span class="stringliteral">"Failed to open \"%s\": %s"</span>, cfilename,
<a name="l00218"></a>00218                       _dbus_strerror (errno));
<a name="l00219"></a>00219       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00220"></a>00220     }
<a name="l00221"></a>00221 
<a name="l00222"></a>00222   <span class="keywordflow">if</span> ((f = fdopen (fd, <span class="stringliteral">"w"</span>)) == <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>)
<a name="l00223"></a>00223     {
<a name="l00224"></a>00224       <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#g2212aa0e5732257598a6597748c658e4">_dbus_error_from_errno</a> (errno),
<a name="l00225"></a>00225                       <span class="stringliteral">"Failed to fdopen fd %d: %s"</span>, fd, _dbus_strerror (errno));
<a name="l00226"></a>00226       <a class="code" href="group__DBusSysdepsUnix.html#gc448479a1674e3b86cee9a4bdc7eba03">_dbus_close</a> (fd, <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>);
<a name="l00227"></a>00227       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00228"></a>00228     }
<a name="l00229"></a>00229   
<a name="l00230"></a>00230   <span class="keywordflow">if</span> (fprintf (f, <span class="stringliteral">"%lu\n"</span>, pid) &lt; 0)
<a name="l00231"></a>00231     {
<a name="l00232"></a>00232       <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#g2212aa0e5732257598a6597748c658e4">_dbus_error_from_errno</a> (errno),
<a name="l00233"></a>00233                       <span class="stringliteral">"Failed to write to \"%s\": %s"</span>, cfilename,
<a name="l00234"></a>00234                       _dbus_strerror (errno));
<a name="l00235"></a>00235       
<a name="l00236"></a>00236       fclose (f);
<a name="l00237"></a>00237       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00238"></a>00238     }
<a name="l00239"></a>00239 
<a name="l00240"></a>00240   <span class="keywordflow">if</span> (fclose (f) == EOF)
<a name="l00241"></a>00241     {
<a name="l00242"></a>00242       <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#g2212aa0e5732257598a6597748c658e4">_dbus_error_from_errno</a> (errno),
<a name="l00243"></a>00243                       <span class="stringliteral">"Failed to close \"%s\": %s"</span>, cfilename,
<a name="l00244"></a>00244                       _dbus_strerror (errno));
<a name="l00245"></a>00245       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00246"></a>00246     }
<a name="l00247"></a>00247   
<a name="l00248"></a>00248   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga8cecfc5c5c054d2875c03e77b7be15d">TRUE</a>;
<a name="l00249"></a>00249 }
<a name="l00250"></a>00250 
<a name="l00257"></a>00257 <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00258"></a><a class="code" href="group__DBusSysdeps.html#g45f661c5a089ed45233a1acabaf31964">00258</a> <a class="code" href="group__DBusInternalsUtils.html#g45f661c5a089ed45233a1acabaf31964">_dbus_verify_daemon_user</a> (<span class="keyword">const</span> <span class="keywordtype">char</span> *user)
<a name="l00259"></a>00259 {
<a name="l00260"></a>00260   <a class="code" href="structDBusString.html">DBusString</a> u;
<a name="l00261"></a>00261 
<a name="l00262"></a>00262   <a class="code" href="group__DBusString.html#g374640ddfa2f0b27a8356e2379ba8043">_dbus_string_init_const</a> (&amp;u, user);
<a name="l00263"></a>00263 
<a name="l00264"></a>00264   <span class="keywordflow">return</span> <a class="code" href="group__DBusInternalsUtils.html#gc82f42ff83fabbde717cc08569265e6e">_dbus_get_user_id_and_primary_group</a> (&amp;u, <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>, <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>);
<a name="l00265"></a>00265 }
<a name="l00266"></a>00266 
<a name="l00274"></a>00274 <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00275"></a><a class="code" href="group__DBusSysdeps.html#g82c920a8c3b5958ba1ecf8e5f5d6373b">00275</a> <a class="code" href="group__DBusInternalsUtils.html#g82c920a8c3b5958ba1ecf8e5f5d6373b">_dbus_change_to_daemon_user</a>  (<span class="keyword">const</span> <span class="keywordtype">char</span>    *user,
<a name="l00276"></a>00276                               <a class="code" href="structDBusError.html">DBusError</a>     *error)
<a name="l00277"></a>00277 {
<a name="l00278"></a>00278   <a class="code" href="group__DBusSysdeps.html#g186e987b700f9ddc6cea8aa0db82b151">dbus_uid_t</a> uid;
<a name="l00279"></a>00279   <a class="code" href="group__DBusSysdeps.html#g2f5c2e418b81ec2a86594f56ec6d7627">dbus_gid_t</a> gid;
<a name="l00280"></a>00280   <a class="code" href="structDBusString.html">DBusString</a> u;
<a name="l00281"></a>00281 <span class="preprocessor">#ifdef HAVE_LIBAUDIT</span>
<a name="l00282"></a>00282 <span class="preprocessor"></span>  <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a> we_were_root;
<a name="l00283"></a>00283   cap_t new_caps;
<a name="l00284"></a>00284 <span class="preprocessor">#endif</span>
<a name="l00285"></a>00285 <span class="preprocessor"></span>  
<a name="l00286"></a>00286   <a class="code" href="group__DBusString.html#g374640ddfa2f0b27a8356e2379ba8043">_dbus_string_init_const</a> (&amp;u, user);
<a name="l00287"></a>00287   
<a name="l00288"></a>00288   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusInternalsUtils.html#gc82f42ff83fabbde717cc08569265e6e">_dbus_get_user_id_and_primary_group</a> (&amp;u, &amp;uid, &amp;gid))
<a name="l00289"></a>00289     {
<a name="l00290"></a>00290       <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gbb62fd6340d0787fbd56ff8dd2f326c7">DBUS_ERROR_FAILED</a>,
<a name="l00291"></a>00291                       <span class="stringliteral">"User '%s' does not appear to exist?"</span>,
<a name="l00292"></a>00292                       user);
<a name="l00293"></a>00293       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00294"></a>00294     }
<a name="l00295"></a>00295   
<a name="l00296"></a>00296 <span class="preprocessor">#ifdef HAVE_LIBAUDIT</span>
<a name="l00297"></a>00297 <span class="preprocessor"></span>  we_were_root = <a class="code" href="group__DBusSysdepsUnix.html#ge7701063932951bdd8a7df0dcacb3bab">_dbus_getuid</a> () == 0;
<a name="l00298"></a>00298   new_caps = <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00299"></a>00299   <span class="comment">/* have a tmp set of caps that we use to transition to the usr/grp dbus should</span>
<a name="l00300"></a>00300 <span class="comment">   * run as ... doesn't really help. But keeps people happy.</span>
<a name="l00301"></a>00301 <span class="comment">   */</span>
<a name="l00302"></a>00302     
<a name="l00303"></a>00303   <span class="keywordflow">if</span> (we_were_root)
<a name="l00304"></a>00304     {
<a name="l00305"></a>00305       cap_value_t new_cap_list[] = { CAP_AUDIT_WRITE };
<a name="l00306"></a>00306       cap_value_t tmp_cap_list[] = { CAP_AUDIT_WRITE, CAP_SETUID, CAP_SETGID };
<a name="l00307"></a>00307       cap_t tmp_caps = cap_init();
<a name="l00308"></a>00308         
<a name="l00309"></a>00309       <span class="keywordflow">if</span> (!tmp_caps || !(new_caps = cap_init ()))
<a name="l00310"></a>00310         {
<a name="l00311"></a>00311           <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gbb62fd6340d0787fbd56ff8dd2f326c7">DBUS_ERROR_FAILED</a>,
<a name="l00312"></a>00312                           <span class="stringliteral">"Failed to initialize drop of capabilities: %s\n"</span>,
<a name="l00313"></a>00313                           _dbus_strerror (errno));
<a name="l00314"></a>00314 
<a name="l00315"></a>00315           <span class="keywordflow">if</span> (tmp_caps)
<a name="l00316"></a>00316             cap_free (tmp_caps);
<a name="l00317"></a>00317 
<a name="l00318"></a>00318           <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00319"></a>00319         }
<a name="l00320"></a>00320 
<a name="l00321"></a>00321       <span class="comment">/* assume these work... */</span>
<a name="l00322"></a>00322       cap_set_flag (new_caps, CAP_PERMITTED, 1, new_cap_list, CAP_SET);
<a name="l00323"></a>00323       cap_set_flag (new_caps, CAP_EFFECTIVE, 1, new_cap_list, CAP_SET);
<a name="l00324"></a>00324       cap_set_flag (tmp_caps, CAP_PERMITTED, 3, tmp_cap_list, CAP_SET);
<a name="l00325"></a>00325       cap_set_flag (tmp_caps, CAP_EFFECTIVE, 3, tmp_cap_list, CAP_SET);
<a name="l00326"></a>00326       
<a name="l00327"></a>00327       <span class="keywordflow">if</span> (prctl (PR_SET_KEEPCAPS, 1, 0, 0, 0) == -1)
<a name="l00328"></a>00328         {
<a name="l00329"></a>00329           <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#g2212aa0e5732257598a6597748c658e4">_dbus_error_from_errno</a> (errno),
<a name="l00330"></a>00330                           <span class="stringliteral">"Failed to set keep-capabilities: %s\n"</span>,
<a name="l00331"></a>00331                           _dbus_strerror (errno));
<a name="l00332"></a>00332           cap_free (tmp_caps);
<a name="l00333"></a>00333           <span class="keywordflow">goto</span> fail;
<a name="l00334"></a>00334         }
<a name="l00335"></a>00335         
<a name="l00336"></a>00336       <span class="keywordflow">if</span> (cap_set_proc (tmp_caps) == -1)
<a name="l00337"></a>00337         {
<a name="l00338"></a>00338           <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gbb62fd6340d0787fbd56ff8dd2f326c7">DBUS_ERROR_FAILED</a>,
<a name="l00339"></a>00339                           <span class="stringliteral">"Failed to drop capabilities: %s\n"</span>,
<a name="l00340"></a>00340                           _dbus_strerror (errno));
<a name="l00341"></a>00341           cap_free (tmp_caps);
<a name="l00342"></a>00342           <span class="keywordflow">goto</span> fail;
<a name="l00343"></a>00343         }
<a name="l00344"></a>00344       cap_free (tmp_caps);
<a name="l00345"></a>00345     }
<a name="l00346"></a>00346 <span class="preprocessor">#endif </span><span class="comment">/* HAVE_LIBAUDIT */</span>
<a name="l00347"></a>00347   
<a name="l00348"></a>00348   <span class="comment">/* setgroups() only works if we are a privileged process,</span>
<a name="l00349"></a>00349 <span class="comment">   * so we don't return error on failure; the only possible</span>
<a name="l00350"></a>00350 <span class="comment">   * failure is that we don't have perms to do it.</span>
<a name="l00351"></a>00351 <span class="comment">   *</span>
<a name="l00352"></a>00352 <span class="comment">   * not sure this is right, maybe if setuid()</span>
<a name="l00353"></a>00353 <span class="comment">   * is going to work then setgroups() should also work.</span>
<a name="l00354"></a>00354 <span class="comment">   */</span>
<a name="l00355"></a>00355   <span class="keywordflow">if</span> (setgroups (0, <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>) &lt; 0)
<a name="l00356"></a>00356     <a class="code" href="group__DBusInternalsUtils.html#gbea2c16d6d3fe7c4eb5b9496fc877f84">_dbus_warn</a> (<span class="stringliteral">"Failed to drop supplementary groups: %s\n"</span>,
<a name="l00357"></a>00357                 _dbus_strerror (errno));
<a name="l00358"></a>00358   
<a name="l00359"></a>00359   <span class="comment">/* Set GID first, or the setuid may remove our permission</span>
<a name="l00360"></a>00360 <span class="comment">   * to change the GID</span>
<a name="l00361"></a>00361 <span class="comment">   */</span>
<a name="l00362"></a>00362   <span class="keywordflow">if</span> (setgid (gid) &lt; 0)
<a name="l00363"></a>00363     {
<a name="l00364"></a>00364       <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#g2212aa0e5732257598a6597748c658e4">_dbus_error_from_errno</a> (errno),
<a name="l00365"></a>00365                       <span class="stringliteral">"Failed to set GID to %lu: %s"</span>, gid,
<a name="l00366"></a>00366                       _dbus_strerror (errno));
<a name="l00367"></a>00367       <span class="keywordflow">goto</span> fail;
<a name="l00368"></a>00368     }
<a name="l00369"></a>00369   
<a name="l00370"></a>00370   <span class="keywordflow">if</span> (setuid (uid) &lt; 0)
<a name="l00371"></a>00371     {
<a name="l00372"></a>00372       <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#g2212aa0e5732257598a6597748c658e4">_dbus_error_from_errno</a> (errno),
<a name="l00373"></a>00373                       <span class="stringliteral">"Failed to set UID to %lu: %s"</span>, uid,
<a name="l00374"></a>00374                       _dbus_strerror (errno));
<a name="l00375"></a>00375       <span class="keywordflow">goto</span> fail;
<a name="l00376"></a>00376     }
<a name="l00377"></a>00377   
<a name="l00378"></a>00378 <span class="preprocessor">#ifdef HAVE_LIBAUDIT</span>
<a name="l00379"></a>00379 <span class="preprocessor"></span>  <span class="keywordflow">if</span> (we_were_root)
<a name="l00380"></a>00380     {
<a name="l00381"></a>00381       <span class="keywordflow">if</span> (cap_set_proc (new_caps))
<a name="l00382"></a>00382         {
<a name="l00383"></a>00383           <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gbb62fd6340d0787fbd56ff8dd2f326c7">DBUS_ERROR_FAILED</a>,
<a name="l00384"></a>00384                           <span class="stringliteral">"Failed to drop capabilities: %s\n"</span>,
<a name="l00385"></a>00385                           _dbus_strerror (errno));
<a name="l00386"></a>00386           <span class="keywordflow">goto</span> fail;
<a name="l00387"></a>00387         }
<a name="l00388"></a>00388       cap_free (new_caps);
<a name="l00389"></a>00389 
<a name="l00390"></a>00390       <span class="comment">/* should always work, if it did above */</span>      
<a name="l00391"></a>00391       <span class="keywordflow">if</span> (prctl (PR_SET_KEEPCAPS, 0, 0, 0, 0) == -1)
<a name="l00392"></a>00392         {
<a name="l00393"></a>00393           <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#g2212aa0e5732257598a6597748c658e4">_dbus_error_from_errno</a> (errno),
<a name="l00394"></a>00394                           <span class="stringliteral">"Failed to unset keep-capabilities: %s\n"</span>,
<a name="l00395"></a>00395                           _dbus_strerror (errno));
<a name="l00396"></a>00396           <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00397"></a>00397         }
<a name="l00398"></a>00398     }
<a name="l00399"></a>00399 <span class="preprocessor">#endif</span>
<a name="l00400"></a>00400 <span class="preprocessor"></span>
<a name="l00401"></a>00401  <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga8cecfc5c5c054d2875c03e77b7be15d">TRUE</a>;
<a name="l00402"></a>00402 
<a name="l00403"></a>00403  fail:
<a name="l00404"></a>00404 <span class="preprocessor">#ifdef HAVE_LIBAUDIT</span>
<a name="l00405"></a>00405 <span class="preprocessor"></span> <span class="keywordflow">if</span> (!we_were_root)
<a name="l00406"></a>00406    {
<a name="l00407"></a>00407      <span class="comment">/* should always work, if it did above */</span>
<a name="l00408"></a>00408      prctl (PR_SET_KEEPCAPS, 0, 0, 0, 0);
<a name="l00409"></a>00409      cap_free (new_caps);
<a name="l00410"></a>00410    }
<a name="l00411"></a>00411 <span class="preprocessor">#endif</span>
<a name="l00412"></a>00412 <span class="preprocessor"></span>
<a name="l00413"></a>00413  <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00414"></a>00414 }
<a name="l00415"></a>00415 
<a name="l00421"></a>00421 <span class="keywordtype">void</span>
<a name="l00422"></a><a class="code" href="group__DBusSysdeps.html#g4aa7500366dad2dd6d3fa97b3aa7165b">00422</a> <a class="code" href="group__DBusInternalsUtils.html#g4aa7500366dad2dd6d3fa97b3aa7165b">_dbus_set_signal_handler</a> (<span class="keywordtype">int</span>               sig,
<a name="l00423"></a>00423                           <a class="code" href="group__DBusSysdeps.html#gdd0067ae8ae20e747b818697395d420f">DBusSignalHandler</a> handler)
<a name="l00424"></a>00424 {
<a name="l00425"></a>00425   <span class="keyword">struct </span>sigaction act;
<a name="l00426"></a>00426   sigset_t empty_mask;
<a name="l00427"></a>00427   
<a name="l00428"></a>00428   sigemptyset (&amp;empty_mask);
<a name="l00429"></a>00429   act.sa_handler = handler;
<a name="l00430"></a>00430   act.sa_mask    = empty_mask;
<a name="l00431"></a>00431   act.sa_flags   = 0;
<a name="l00432"></a>00432   sigaction (sig,  &amp;act, <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>);
<a name="l00433"></a>00433 }
<a name="l00434"></a>00434 
<a name="l00435"></a>00435 
<a name="l00443"></a>00443 <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00444"></a><a class="code" href="group__DBusSysdeps.html#g3bc1512aef42cea17a2aaacc7d8e7211">00444</a> <a class="code" href="group__DBusInternalsUtils.html#g3bc1512aef42cea17a2aaacc7d8e7211">_dbus_delete_directory</a> (<span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *filename,
<a name="l00445"></a>00445                         <a class="code" href="structDBusError.html">DBusError</a>        *error)
<a name="l00446"></a>00446 {
<a name="l00447"></a>00447   <span class="keyword">const</span> <span class="keywordtype">char</span> *filename_c;
<a name="l00448"></a>00448   
<a name="l00449"></a>00449   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l00450"></a>00450 
<a name="l00451"></a>00451   filename_c = _dbus_string_get_const_data (filename);
<a name="l00452"></a>00452 
<a name="l00453"></a>00453   <span class="keywordflow">if</span> (rmdir (filename_c) != 0)
<a name="l00454"></a>00454     {
<a name="l00455"></a>00455       <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gbb62fd6340d0787fbd56ff8dd2f326c7">DBUS_ERROR_FAILED</a>,
<a name="l00456"></a>00456                       <span class="stringliteral">"Failed to remove directory %s: %s\n"</span>,
<a name="l00457"></a>00457                       filename_c, _dbus_strerror (errno));
<a name="l00458"></a>00458       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00459"></a>00459     }
<a name="l00460"></a>00460   
<a name="l00461"></a>00461   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga8cecfc5c5c054d2875c03e77b7be15d">TRUE</a>;
<a name="l00462"></a>00462 }
<a name="l00463"></a>00463 
<a name="l00469"></a>00469 <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a> 
<a name="l00470"></a><a class="code" href="group__DBusSysdeps.html#g13a527e32c05b63e8b32a63d728e20e8">00470</a> <a class="code" href="group__DBusInternalsUtils.html#g13a527e32c05b63e8b32a63d728e20e8">_dbus_file_exists</a> (<span class="keyword">const</span> <span class="keywordtype">char</span> *file)
<a name="l00471"></a>00471 {
<a name="l00472"></a>00472   <span class="keywordflow">return</span> (access (file, F_OK) == 0);
<a name="l00473"></a>00473 }
<a name="l00474"></a>00474 
<a name="l00481"></a>00481 <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a> 
<a name="l00482"></a><a class="code" href="group__DBusSysdeps.html#g31ec42cef2d15ca358e737bb5f19c5cf">00482</a> <a class="code" href="group__DBusInternalsUtils.html#g31ec42cef2d15ca358e737bb5f19c5cf">_dbus_user_at_console</a> (<span class="keyword">const</span> <span class="keywordtype">char</span> *username,
<a name="l00483"></a>00483                        <a class="code" href="structDBusError.html">DBusError</a>  *error)
<a name="l00484"></a>00484 {
<a name="l00485"></a>00485 
<a name="l00486"></a>00486   <a class="code" href="structDBusString.html">DBusString</a> f;
<a name="l00487"></a>00487   <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a> result;
<a name="l00488"></a>00488 
<a name="l00489"></a>00489   result = <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00490"></a>00490   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#g348252317f7bb8ac43529972945830ae">_dbus_string_init</a> (&amp;f))
<a name="l00491"></a>00491     {
<a name="l00492"></a>00492       _DBUS_SET_OOM (error);
<a name="l00493"></a>00493       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00494"></a>00494     }
<a name="l00495"></a>00495 
<a name="l00496"></a>00496   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#g100c5ce0696822c5a4cfbdfaba674d96">_dbus_string_append</a> (&amp;f, DBUS_CONSOLE_AUTH_DIR))
<a name="l00497"></a>00497     {
<a name="l00498"></a>00498       _DBUS_SET_OOM (error);
<a name="l00499"></a>00499       <span class="keywordflow">goto</span> out;
<a name="l00500"></a>00500     }
<a name="l00501"></a>00501 
<a name="l00502"></a>00502 
<a name="l00503"></a>00503   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#g100c5ce0696822c5a4cfbdfaba674d96">_dbus_string_append</a> (&amp;f, username))
<a name="l00504"></a>00504     {
<a name="l00505"></a>00505       _DBUS_SET_OOM (error);
<a name="l00506"></a>00506       <span class="keywordflow">goto</span> out;
<a name="l00507"></a>00507     }
<a name="l00508"></a>00508 
<a name="l00509"></a>00509   result = <a class="code" href="group__DBusInternalsUtils.html#g13a527e32c05b63e8b32a63d728e20e8">_dbus_file_exists</a> (_dbus_string_get_const_data (&amp;f));
<a name="l00510"></a>00510 
<a name="l00511"></a>00511  out:
<a name="l00512"></a>00512   <a class="code" href="group__DBusString.html#g781ca91acda49a834dce7d0ed0eef212">_dbus_string_free</a> (&amp;f);
<a name="l00513"></a>00513 
<a name="l00514"></a>00514   <span class="keywordflow">return</span> result;
<a name="l00515"></a>00515 }
<a name="l00516"></a>00516 
<a name="l00517"></a>00517 
<a name="l00524"></a>00524 <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00525"></a><a class="code" href="group__DBusSysdeps.html#g6d80876bcae54f47cde79d0bce20321d">00525</a> <a class="code" href="group__DBusInternalsUtils.html#g6d80876bcae54f47cde79d0bce20321d">_dbus_path_is_absolute</a> (<span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *filename)
<a name="l00526"></a>00526 {
<a name="l00527"></a>00527   <span class="keywordflow">if</span> (_dbus_string_get_length (filename) &gt; 0)
<a name="l00528"></a>00528     <span class="keywordflow">return</span> _dbus_string_get_byte (filename, 0) == <span class="charliteral">'/'</span>;
<a name="l00529"></a>00529   <span class="keywordflow">else</span>
<a name="l00530"></a>00530     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00531"></a>00531 }
<a name="l00532"></a>00532 
<a name="l00541"></a>00541 <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00542"></a><a class="code" href="group__DBusSysdeps.html#g04e98ad0e3a181f0a5921a4cbc49cf08">00542</a> <a class="code" href="group__DBusInternalsUtils.html#g04e98ad0e3a181f0a5921a4cbc49cf08">_dbus_stat</a> (<span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *filename,
<a name="l00543"></a>00543             <a class="code" href="structDBusStat.html">DBusStat</a>         *statbuf,
<a name="l00544"></a>00544             <a class="code" href="structDBusError.html">DBusError</a>        *error)
<a name="l00545"></a>00545 {
<a name="l00546"></a>00546   <span class="keyword">const</span> <span class="keywordtype">char</span> *filename_c;
<a name="l00547"></a>00547   <span class="keyword">struct </span>stat sb;
<a name="l00548"></a>00548 
<a name="l00549"></a>00549   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l00550"></a>00550   
<a name="l00551"></a>00551   filename_c = _dbus_string_get_const_data (filename);
<a name="l00552"></a>00552 
<a name="l00553"></a>00553   <span class="keywordflow">if</span> (stat (filename_c, &amp;sb) &lt; 0)
<a name="l00554"></a>00554     {
<a name="l00555"></a>00555       <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#g2212aa0e5732257598a6597748c658e4">_dbus_error_from_errno</a> (errno),
<a name="l00556"></a>00556                       <span class="stringliteral">"%s"</span>, _dbus_strerror (errno));
<a name="l00557"></a>00557       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00558"></a>00558     }
<a name="l00559"></a>00559 
<a name="l00560"></a>00560   statbuf-&gt;<a class="code" href="structDBusStat.html#722ec64f90cf29e0b8bafaea55b90d27">mode</a> = sb.st_mode;
<a name="l00561"></a>00561   statbuf-&gt;<a class="code" href="structDBusStat.html#1b5ef4ce7f46c798d4b222c61f8912f7">nlink</a> = sb.st_nlink;
<a name="l00562"></a>00562   statbuf-&gt;<a class="code" href="structDBusStat.html#300fac914534803bcfacdd87b15e1a8d">uid</a> = sb.st_uid;
<a name="l00563"></a>00563   statbuf-&gt;<a class="code" href="structDBusStat.html#98dd4c45ffc8488b399cb3feb57ef48c">gid</a> = sb.st_gid;
<a name="l00564"></a>00564   statbuf-&gt;<a class="code" href="structDBusStat.html#1b8b518248d41601766ae955bdca0de2">size</a> = sb.st_size;
<a name="l00565"></a>00565   statbuf-&gt;<a class="code" href="structDBusStat.html#9c68f29816af750a47d80177a23d6cf1">atime</a> = sb.st_atime;
<a name="l00566"></a>00566   statbuf-&gt;<a class="code" href="structDBusStat.html#cf4750b66ccb06b49c7eaf2405d8c417">mtime</a> = sb.st_mtime;
<a name="l00567"></a>00567   statbuf-&gt;<a class="code" href="structDBusStat.html#ceb3c4a3230d1a9063baee27c140fbb3">ctime</a> = sb.st_ctime;
<a name="l00568"></a>00568 
<a name="l00569"></a>00569   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga8cecfc5c5c054d2875c03e77b7be15d">TRUE</a>;
<a name="l00570"></a>00570 }
<a name="l00571"></a>00571 
<a name="l00572"></a>00572 
<a name="l00576"></a><a class="code" href="structDBusDirIter.html">00576</a> <span class="keyword">struct </span><a class="code" href="structDBusDirIter.html">DBusDirIter</a>
<a name="l00577"></a>00577 {
<a name="l00578"></a><a class="code" href="structDBusDirIter.html#9b713ab1d8b9b0b621e7555a33def70f">00578</a>   DIR *<a class="code" href="structDBusDirIter.html#9b713ab1d8b9b0b621e7555a33def70f">d</a>; 
<a name="l00580"></a>00580 };
<a name="l00581"></a>00581 
<a name="l00589"></a>00589 <a class="code" href="structDBusDirIter.html">DBusDirIter</a>*
<a name="l00590"></a><a class="code" href="group__DBusSysdeps.html#gaf6eb8179fb6ea2175ed9742a0c8be68">00590</a> <a class="code" href="group__DBusInternalsUtils.html#gaf6eb8179fb6ea2175ed9742a0c8be68">_dbus_directory_open</a> (<span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *filename,
<a name="l00591"></a>00591                       <a class="code" href="structDBusError.html">DBusError</a>        *error)
<a name="l00592"></a>00592 {
<a name="l00593"></a>00593   DIR *d;
<a name="l00594"></a>00594   <a class="code" href="structDBusDirIter.html">DBusDirIter</a> *iter;
<a name="l00595"></a>00595   <span class="keyword">const</span> <span class="keywordtype">char</span> *filename_c;
<a name="l00596"></a>00596 
<a name="l00597"></a>00597   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l00598"></a>00598   
<a name="l00599"></a>00599   filename_c = _dbus_string_get_const_data (filename);
<a name="l00600"></a>00600 
<a name="l00601"></a>00601   d = opendir (filename_c);
<a name="l00602"></a>00602   <span class="keywordflow">if</span> (d == <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>)
<a name="l00603"></a>00603     {
<a name="l00604"></a>00604       <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#g2212aa0e5732257598a6597748c658e4">_dbus_error_from_errno</a> (errno),
<a name="l00605"></a>00605                       <span class="stringliteral">"Failed to read directory \"%s\": %s"</span>,
<a name="l00606"></a>00606                       filename_c,
<a name="l00607"></a>00607                       _dbus_strerror (errno));
<a name="l00608"></a>00608       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00609"></a>00609     }
<a name="l00610"></a>00610   iter = <a class="code" href="group__DBusMemory.html#gba9d823abda7f4cadbaf5177d3b8b793">dbus_new0</a> (<a class="code" href="structDBusDirIter.html">DBusDirIter</a>, 1);
<a name="l00611"></a>00611   <span class="keywordflow">if</span> (iter == <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>)
<a name="l00612"></a>00612     {
<a name="l00613"></a>00613       closedir (d);
<a name="l00614"></a>00614       <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gc32eaf0b92f798307853cd4fe0cf11c2">DBUS_ERROR_NO_MEMORY</a>,
<a name="l00615"></a>00615                       <span class="stringliteral">"Could not allocate memory for directory iterator"</span>);
<a name="l00616"></a>00616       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00617"></a>00617     }
<a name="l00618"></a>00618 
<a name="l00619"></a>00619   iter-&gt;<a class="code" href="structDBusDirIter.html#9b713ab1d8b9b0b621e7555a33def70f">d</a> = d;
<a name="l00620"></a>00620 
<a name="l00621"></a>00621   <span class="keywordflow">return</span> iter;
<a name="l00622"></a>00622 }
<a name="l00623"></a>00623 
<a name="l00624"></a>00624 <span class="comment">/* Calculate the required buffer size (in bytes) for directory</span>
<a name="l00625"></a>00625 <span class="comment"> * entries read from the given directory handle.  Return -1 if this</span>
<a name="l00626"></a>00626 <span class="comment"> * this cannot be done. </span>
<a name="l00627"></a>00627 <span class="comment"> *</span>
<a name="l00628"></a>00628 <span class="comment"> * If you use autoconf, include fpathconf and dirfd in your</span>
<a name="l00629"></a>00629 <span class="comment"> * AC_CHECK_FUNCS list.  Otherwise use some other method to detect</span>
<a name="l00630"></a>00630 <span class="comment"> * and use them where available.</span>
<a name="l00631"></a>00631 <span class="comment"> */</span>
<a name="l00632"></a>00632 <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00633"></a>00633 dirent_buf_size(DIR * dirp, size_t *size)
<a name="l00634"></a>00634 {
<a name="l00635"></a>00635  <span class="keywordtype">long</span> name_max;
<a name="l00636"></a>00636 <span class="preprocessor">#   if defined(HAVE_FPATHCONF) &amp;&amp; defined(_PC_NAME_MAX)</span>
<a name="l00637"></a>00637 <span class="preprocessor"></span><span class="preprocessor">#      if defined(HAVE_DIRFD)</span>
<a name="l00638"></a>00638 <span class="preprocessor"></span>          name_max = fpathconf(dirfd(dirp), _PC_NAME_MAX);
<a name="l00639"></a>00639 <span class="preprocessor">#      elif defined(HAVE_DDFD)</span>
<a name="l00640"></a>00640 <span class="preprocessor"></span>          name_max = fpathconf(dirp-&gt;dd_fd, _PC_NAME_MAX);
<a name="l00641"></a>00641 <span class="preprocessor">#      else</span>
<a name="l00642"></a>00642 <span class="preprocessor"></span>          name_max = fpathconf(dirp-&gt;__dd_fd, _PC_NAME_MAX);
<a name="l00643"></a>00643 <span class="preprocessor">#      endif </span><span class="comment">/* HAVE_DIRFD */</span>
<a name="l00644"></a>00644      <span class="keywordflow">if</span> (name_max == -1)
<a name="l00645"></a>00645 <span class="preprocessor">#           if defined(NAME_MAX)</span>
<a name="l00646"></a>00646 <span class="preprocessor"></span>             name_max = NAME_MAX;
<a name="l00647"></a>00647 <span class="preprocessor">#           else</span>
<a name="l00648"></a>00648 <span class="preprocessor"></span>             <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00649"></a>00649 <span class="preprocessor">#           endif</span>
<a name="l00650"></a>00650 <span class="preprocessor"></span><span class="preprocessor">#   elif defined(MAXNAMELEN)</span>
<a name="l00651"></a>00651 <span class="preprocessor"></span>     name_max = MAXNAMELEN;
<a name="l00652"></a>00652 <span class="preprocessor">#   else</span>
<a name="l00653"></a>00653 <span class="preprocessor"></span><span class="preprocessor">#       if defined(NAME_MAX)</span>
<a name="l00654"></a>00654 <span class="preprocessor"></span>         name_max = NAME_MAX;
<a name="l00655"></a>00655 <span class="preprocessor">#       else</span>
<a name="l00656"></a>00656 <span class="preprocessor"></span><span class="preprocessor">#           error "buffer size for readdir_r cannot be determined"</span>
<a name="l00657"></a>00657 <span class="preprocessor"></span><span class="preprocessor">#       endif</span>
<a name="l00658"></a>00658 <span class="preprocessor"></span><span class="preprocessor">#   endif</span>
<a name="l00659"></a>00659 <span class="preprocessor"></span>  <span class="keywordflow">if</span> (size)
<a name="l00660"></a>00660     *size = (size_t)offsetof(<span class="keyword">struct</span> dirent, d_name) + name_max + 1;
<a name="l00661"></a>00661   <span class="keywordflow">else</span>
<a name="l00662"></a>00662     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00663"></a>00663 
<a name="l00664"></a>00664   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga8cecfc5c5c054d2875c03e77b7be15d">TRUE</a>;
<a name="l00665"></a>00665 }
<a name="l00666"></a>00666 
<a name="l00677"></a>00677 <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00678"></a><a class="code" href="group__DBusSysdeps.html#gb9a2ddb130da035d6186f2d96bf37cb4">00678</a> <a class="code" href="group__DBusInternalsUtils.html#gb9a2ddb130da035d6186f2d96bf37cb4">_dbus_directory_get_next_file</a> (<a class="code" href="structDBusDirIter.html">DBusDirIter</a>      *iter,
<a name="l00679"></a>00679                                <a class="code" href="structDBusString.html">DBusString</a>       *filename,
<a name="l00680"></a>00680                                <a class="code" href="structDBusError.html">DBusError</a>        *error)
<a name="l00681"></a>00681 {
<a name="l00682"></a>00682   <span class="keyword">struct </span>dirent *d, *ent;
<a name="l00683"></a>00683   size_t buf_size;
<a name="l00684"></a>00684   <span class="keywordtype">int</span> err;
<a name="l00685"></a>00685 
<a name="l00686"></a>00686   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l00687"></a>00687  
<a name="l00688"></a>00688   <span class="keywordflow">if</span> (!dirent_buf_size (iter-&gt;<a class="code" href="structDBusDirIter.html#9b713ab1d8b9b0b621e7555a33def70f">d</a>, &amp;buf_size))
<a name="l00689"></a>00689     {
<a name="l00690"></a>00690       <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gbb62fd6340d0787fbd56ff8dd2f326c7">DBUS_ERROR_FAILED</a>,
<a name="l00691"></a>00691                       <span class="stringliteral">"Can't calculate buffer size when reading directory"</span>);
<a name="l00692"></a>00692       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00693"></a>00693     }
<a name="l00694"></a>00694 
<a name="l00695"></a>00695   d = (<span class="keyword">struct </span>dirent *)<a class="code" href="group__DBusMemory.html#g0fff22bd7f055f5581a9898116a744b1">dbus_malloc</a> (buf_size);
<a name="l00696"></a>00696   <span class="keywordflow">if</span> (!d)
<a name="l00697"></a>00697     {
<a name="l00698"></a>00698       <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gc32eaf0b92f798307853cd4fe0cf11c2">DBUS_ERROR_NO_MEMORY</a>,
<a name="l00699"></a>00699                       <span class="stringliteral">"No memory to read directory entry"</span>);
<a name="l00700"></a>00700       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00701"></a>00701     }
<a name="l00702"></a>00702 
<a name="l00703"></a>00703  again:
<a name="l00704"></a>00704   err = readdir_r (iter-&gt;<a class="code" href="structDBusDirIter.html#9b713ab1d8b9b0b621e7555a33def70f">d</a>, d, &amp;ent);
<a name="l00705"></a>00705   <span class="keywordflow">if</span> (err || !ent)
<a name="l00706"></a>00706     {
<a name="l00707"></a>00707       <span class="keywordflow">if</span> (err != 0)
<a name="l00708"></a>00708         <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error,
<a name="l00709"></a>00709                         <a class="code" href="group__DBusInternalsUtils.html#g2212aa0e5732257598a6597748c658e4">_dbus_error_from_errno</a> (err),
<a name="l00710"></a>00710                         <span class="stringliteral">"%s"</span>, _dbus_strerror (err));
<a name="l00711"></a>00711 
<a name="l00712"></a>00712       <a class="code" href="group__DBusMemory.html#g488c6b08cc8c1ddf0203243c4b27a13c">dbus_free</a> (d);
<a name="l00713"></a>00713       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00714"></a>00714     }
<a name="l00715"></a>00715   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ent-&gt;d_name[0] == <span class="charliteral">'.'</span> &amp;&amp;
<a name="l00716"></a>00716            (ent-&gt;d_name[1] == <span class="charliteral">'\0'</span> ||
<a name="l00717"></a>00717             (ent-&gt;d_name[1] == <span class="charliteral">'.'</span> &amp;&amp; ent-&gt;d_name[2] == <span class="charliteral">'\0'</span>)))
<a name="l00718"></a>00718     <span class="keywordflow">goto</span> again;
<a name="l00719"></a>00719   <span class="keywordflow">else</span>
<a name="l00720"></a>00720     {
<a name="l00721"></a>00721       <a class="code" href="group__DBusString.html#g08c423b93c28dd746dcb93e0461ab95c">_dbus_string_set_length</a> (filename, 0);
<a name="l00722"></a>00722       <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#g100c5ce0696822c5a4cfbdfaba674d96">_dbus_string_append</a> (filename, ent-&gt;d_name))
<a name="l00723"></a>00723         {
<a name="l00724"></a>00724           <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gc32eaf0b92f798307853cd4fe0cf11c2">DBUS_ERROR_NO_MEMORY</a>,
<a name="l00725"></a>00725                           <span class="stringliteral">"No memory to read directory entry"</span>);
<a name="l00726"></a>00726           <a class="code" href="group__DBusMemory.html#g488c6b08cc8c1ddf0203243c4b27a13c">dbus_free</a> (d);
<a name="l00727"></a>00727           <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00728"></a>00728         }
<a name="l00729"></a>00729       <span class="keywordflow">else</span>
<a name="l00730"></a>00730         {
<a name="l00731"></a>00731           <a class="code" href="group__DBusMemory.html#g488c6b08cc8c1ddf0203243c4b27a13c">dbus_free</a> (d);
<a name="l00732"></a>00732           <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga8cecfc5c5c054d2875c03e77b7be15d">TRUE</a>;
<a name="l00733"></a>00733         }
<a name="l00734"></a>00734     }
<a name="l00735"></a>00735 }
<a name="l00736"></a>00736 
<a name="l00740"></a>00740 <span class="keywordtype">void</span>
<a name="l00741"></a><a class="code" href="group__DBusSysdeps.html#g1821b64302fe8e12278fa227eb11d393">00741</a> <a class="code" href="group__DBusInternalsUtils.html#g1821b64302fe8e12278fa227eb11d393">_dbus_directory_close</a> (<a class="code" href="structDBusDirIter.html">DBusDirIter</a> *iter)
<a name="l00742"></a>00742 {
<a name="l00743"></a>00743   closedir (iter-&gt;<a class="code" href="structDBusDirIter.html#9b713ab1d8b9b0b621e7555a33def70f">d</a>);
<a name="l00744"></a>00744   <a class="code" href="group__DBusMemory.html#g488c6b08cc8c1ddf0203243c4b27a13c">dbus_free</a> (iter);
<a name="l00745"></a>00745 }
<a name="l00746"></a>00746 
<a name="l00747"></a>00747 <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00748"></a>00748 fill_user_info_from_group (<span class="keyword">struct</span> group  *g,
<a name="l00749"></a>00749                            <a class="code" href="structDBusGroupInfo.html">DBusGroupInfo</a> *info,
<a name="l00750"></a>00750                            <a class="code" href="structDBusError.html">DBusError</a>     *error)
<a name="l00751"></a>00751 {
<a name="l00752"></a>00752   <a class="code" href="group__DBusInternalsUtils.html#g129c6c03f011cdc171934d5d386cc797">_dbus_assert</a> (g-&gt;gr_name != <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>);
<a name="l00753"></a>00753   
<a name="l00754"></a>00754   info-&gt;<a class="code" href="structDBusGroupInfo.html#583e8d6d421fa85fb1d43789efae4b75">gid</a> = g-&gt;gr_gid;
<a name="l00755"></a>00755   info-&gt;<a class="code" href="structDBusGroupInfo.html#f1a4b925663336f64c62cfcab40571c6">groupname</a> = <a class="code" href="group__DBusInternalsUtils.html#g9d00d77f6595b9d7ac1baf59d44bf58c">_dbus_strdup</a> (g-&gt;gr_name);
<a name="l00756"></a>00756 
<a name="l00757"></a>00757   <span class="comment">/* info-&gt;members = dbus_strdupv (g-&gt;gr_mem) */</span>
<a name="l00758"></a>00758   
<a name="l00759"></a>00759   <span class="keywordflow">if</span> (info-&gt;<a class="code" href="structDBusGroupInfo.html#f1a4b925663336f64c62cfcab40571c6">groupname</a> == <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>)
<a name="l00760"></a>00760     {
<a name="l00761"></a>00761       <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gc32eaf0b92f798307853cd4fe0cf11c2">DBUS_ERROR_NO_MEMORY</a>, <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>);
<a name="l00762"></a>00762       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00763"></a>00763     }
<a name="l00764"></a>00764 
<a name="l00765"></a>00765   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga8cecfc5c5c054d2875c03e77b7be15d">TRUE</a>;
<a name="l00766"></a>00766 }
<a name="l00767"></a>00767 
<a name="l00768"></a>00768 <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00769"></a>00769 fill_group_info (<a class="code" href="structDBusGroupInfo.html">DBusGroupInfo</a>    *info,
<a name="l00770"></a>00770                  <a class="code" href="group__DBusSysdeps.html#g2f5c2e418b81ec2a86594f56ec6d7627">dbus_gid_t</a>        gid,
<a name="l00771"></a>00771                  <span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *groupname,
<a name="l00772"></a>00772                  <a class="code" href="structDBusError.html">DBusError</a>        *error)
<a name="l00773"></a>00773 {
<a name="l00774"></a>00774   <span class="keyword">const</span> <span class="keywordtype">char</span> *group_c_str;
<a name="l00775"></a>00775 
<a name="l00776"></a>00776   <a class="code" href="group__DBusInternalsUtils.html#g129c6c03f011cdc171934d5d386cc797">_dbus_assert</a> (groupname != <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> || gid != <a class="code" href="group__DBusSysdeps.html#g768a080926a119a6131083facc0bd42b">DBUS_GID_UNSET</a>);
<a name="l00777"></a>00777   <a class="code" href="group__DBusInternalsUtils.html#g129c6c03f011cdc171934d5d386cc797">_dbus_assert</a> (groupname == <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> || gid == <a class="code" href="group__DBusSysdeps.html#g768a080926a119a6131083facc0bd42b">DBUS_GID_UNSET</a>);
<a name="l00778"></a>00778 
<a name="l00779"></a>00779   <span class="keywordflow">if</span> (groupname)
<a name="l00780"></a>00780     group_c_str = _dbus_string_get_const_data (groupname);
<a name="l00781"></a>00781   <span class="keywordflow">else</span>
<a name="l00782"></a>00782     group_c_str = <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00783"></a>00783   
<a name="l00784"></a>00784   <span class="comment">/* For now assuming that the getgrnam() and getgrgid() flavors</span>
<a name="l00785"></a>00785 <span class="comment">   * always correspond to the pwnam flavors, if not we have</span>
<a name="l00786"></a>00786 <span class="comment">   * to add more configure checks.</span>
<a name="l00787"></a>00787 <span class="comment">   */</span>
<a name="l00788"></a>00788   
<a name="l00789"></a>00789 <span class="preprocessor">#if defined (HAVE_POSIX_GETPWNAM_R) || defined (HAVE_NONPOSIX_GETPWNAM_R)</span>
<a name="l00790"></a>00790 <span class="preprocessor"></span>  {
<a name="l00791"></a>00791     <span class="keyword">struct </span>group *g;
<a name="l00792"></a>00792     <span class="keywordtype">int</span> result;
<a name="l00793"></a>00793     <span class="keywordtype">char</span> buf[1024];
<a name="l00794"></a>00794     <span class="keyword">struct </span>group g_str;
<a name="l00795"></a>00795 
<a name="l00796"></a>00796     g = <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00797"></a>00797 <span class="preprocessor">#ifdef HAVE_POSIX_GETPWNAM_R</span>
<a name="l00798"></a>00798 <span class="preprocessor"></span>
<a name="l00799"></a>00799     <span class="keywordflow">if</span> (group_c_str)
<a name="l00800"></a>00800       result = getgrnam_r (group_c_str, &amp;g_str, buf, <span class="keyword">sizeof</span> (buf),
<a name="l00801"></a>00801                            &amp;g);
<a name="l00802"></a>00802     <span class="keywordflow">else</span>
<a name="l00803"></a>00803       result = getgrgid_r (gid, &amp;g_str, buf, <span class="keyword">sizeof</span> (buf),
<a name="l00804"></a>00804                            &amp;g);
<a name="l00805"></a>00805 <span class="preprocessor">#else</span>
<a name="l00806"></a>00806 <span class="preprocessor"></span>    g = getgrnam_r (group_c_str, &amp;g_str, buf, <span class="keyword">sizeof</span> (buf));
<a name="l00807"></a>00807     result = 0;
<a name="l00808"></a>00808 <span class="preprocessor">#endif </span><span class="comment">/* !HAVE_POSIX_GETPWNAM_R */</span>
<a name="l00809"></a>00809     <span class="keywordflow">if</span> (result == 0 &amp;&amp; g == &amp;g_str)
<a name="l00810"></a>00810       {
<a name="l00811"></a>00811         <span class="keywordflow">return</span> fill_user_info_from_group (g, info, error);
<a name="l00812"></a>00812       }
<a name="l00813"></a>00813     <span class="keywordflow">else</span>
<a name="l00814"></a>00814       {
<a name="l00815"></a>00815         <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#g2212aa0e5732257598a6597748c658e4">_dbus_error_from_errno</a> (errno),
<a name="l00816"></a>00816                         <span class="stringliteral">"Group %s unknown or failed to look it up\n"</span>,
<a name="l00817"></a>00817                         group_c_str ? group_c_str : <span class="stringliteral">"???"</span>);
<a name="l00818"></a>00818         <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00819"></a>00819       }
<a name="l00820"></a>00820   }
<a name="l00821"></a>00821 <span class="preprocessor">#else </span><span class="comment">/* ! HAVE_GETPWNAM_R */</span>
<a name="l00822"></a>00822   {
<a name="l00823"></a>00823     <span class="comment">/* I guess we're screwed on thread safety here */</span>
<a name="l00824"></a>00824     <span class="keyword">struct </span>group *g;
<a name="l00825"></a>00825 
<a name="l00826"></a>00826     g = getgrnam (group_c_str);
<a name="l00827"></a>00827 
<a name="l00828"></a>00828     <span class="keywordflow">if</span> (g != <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>)
<a name="l00829"></a>00829       {
<a name="l00830"></a>00830         <span class="keywordflow">return</span> fill_user_info_from_group (g, info, error);
<a name="l00831"></a>00831       }
<a name="l00832"></a>00832     <span class="keywordflow">else</span>
<a name="l00833"></a>00833       {
<a name="l00834"></a>00834         <a class="code" href="group__DBusErrors.html#g4e1b4b297468006781a957129ad9cf00">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#g2212aa0e5732257598a6597748c658e4">_dbus_error_from_errno</a> (errno),
<a name="l00835"></a>00835                         <span class="stringliteral">"Group %s unknown or failed to look it up\n"</span>,
<a name="l00836"></a>00836                         group_c_str ? group_c_str : <span class="stringliteral">"???"</span>);
<a name="l00837"></a>00837         <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00838"></a>00838       }
<a name="l00839"></a>00839   }
<a name="l00840"></a>00840 <span class="preprocessor">#endif  </span><span class="comment">/* ! HAVE_GETPWNAM_R */</span>
<a name="l00841"></a>00841 }
<a name="l00842"></a>00842 
<a name="l00852"></a>00852 <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00853"></a><a class="code" href="group__DBusInternalsUtils.html#g23814bdf1859c6aa52da1feab8f1aed4">00853</a> <a class="code" href="group__DBusSysdepsUnix.html#g23814bdf1859c6aa52da1feab8f1aed4">_dbus_group_info_fill</a> (<a class="code" href="structDBusGroupInfo.html">DBusGroupInfo</a>    *info,
<a name="l00854"></a>00854                        <span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *groupname,
<a name="l00855"></a>00855                        <a class="code" href="structDBusError.html">DBusError</a>        *error)
<a name="l00856"></a>00856 {
<a name="l00857"></a>00857   <span class="keywordflow">return</span> fill_group_info (info, <a class="code" href="group__DBusSysdeps.html#g768a080926a119a6131083facc0bd42b">DBUS_GID_UNSET</a>,
<a name="l00858"></a>00858                           groupname, error);
<a name="l00859"></a>00859 
<a name="l00860"></a>00860 }
<a name="l00861"></a>00861 
<a name="l00871"></a>00871 <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00872"></a><a class="code" href="group__DBusInternalsUtils.html#gd235e373b223982b7d3aba8a2b602b58">00872</a> <a class="code" href="group__DBusSysdepsUnix.html#gd235e373b223982b7d3aba8a2b602b58">_dbus_group_info_fill_gid</a> (<a class="code" href="structDBusGroupInfo.html">DBusGroupInfo</a> *info,
<a name="l00873"></a>00873                            <a class="code" href="group__DBusSysdeps.html#g2f5c2e418b81ec2a86594f56ec6d7627">dbus_gid_t</a>     gid,
<a name="l00874"></a>00874                            <a class="code" href="structDBusError.html">DBusError</a>     *error)
<a name="l00875"></a>00875 {
<a name="l00876"></a>00876   <span class="keywordflow">return</span> fill_group_info (info, gid, <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>, error);
<a name="l00877"></a>00877 }
<a name="l00878"></a>00878 
<a name="l00887"></a>00887 <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00888"></a><a class="code" href="group__DBusSysdeps.html#g437470fc327b0169fc14a0b66a6e5278">00888</a> <a class="code" href="group__DBusInternalsUtils.html#g437470fc327b0169fc14a0b66a6e5278">_dbus_parse_unix_user_from_config</a> (<span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a>  *username,
<a name="l00889"></a>00889                                    <a class="code" href="group__DBusSysdeps.html#g186e987b700f9ddc6cea8aa0db82b151">dbus_uid_t</a>        *uid_p)
<a name="l00890"></a>00890 {
<a name="l00891"></a>00891   <span class="keywordflow">return</span> <a class="code" href="group__DBusInternalsUtils.html#gf07ee24eddcb3b0f85fa54196bc44fe1">_dbus_get_user_id</a> (username, uid_p);
<a name="l00892"></a>00892 
<a name="l00893"></a>00893 }
<a name="l00894"></a>00894 
<a name="l00903"></a>00903 <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00904"></a><a class="code" href="group__DBusSysdeps.html#g96da816095ec7fec07136a6019745bcb">00904</a> <a class="code" href="group__DBusInternalsUtils.html#g96da816095ec7fec07136a6019745bcb">_dbus_parse_unix_group_from_config</a> (<span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a>  *groupname,
<a name="l00905"></a>00905                                     <a class="code" href="group__DBusSysdeps.html#g2f5c2e418b81ec2a86594f56ec6d7627">dbus_gid_t</a>        *gid_p)
<a name="l00906"></a>00906 {
<a name="l00907"></a>00907   <span class="keywordflow">return</span> <a class="code" href="group__DBusInternalsUtils.html#g90657adefa9bbac9b35eee63dd46a854">_dbus_get_group_id</a> (groupname, gid_p);
<a name="l00908"></a>00908 }
<a name="l00909"></a>00909 
<a name="l00920"></a>00920 <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00921"></a><a class="code" href="group__DBusSysdeps.html#g79647ec21c7edccd1510808ea0ca3779">00921</a> <a class="code" href="group__DBusInternalsUtils.html#g79647ec21c7edccd1510808ea0ca3779">_dbus_unix_groups_from_uid</a> (<a class="code" href="group__DBusSysdeps.html#g186e987b700f9ddc6cea8aa0db82b151">dbus_uid_t</a>            uid,
<a name="l00922"></a>00922                             <a class="code" href="group__DBusSysdeps.html#g2f5c2e418b81ec2a86594f56ec6d7627">dbus_gid_t</a>          **group_ids,
<a name="l00923"></a>00923                             <span class="keywordtype">int</span>                  *n_group_ids)
<a name="l00924"></a>00924 {
<a name="l00925"></a>00925   <span class="keywordflow">return</span> <a class="code" href="group__DBusInternalsUtils.html#ge9408936869314101f8ea13dfa5ba968">_dbus_groups_from_uid</a> (uid, group_ids, n_group_ids);
<a name="l00926"></a>00926 }
<a name="l00927"></a>00927 
<a name="l00937"></a>00937 <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00938"></a><a class="code" href="group__DBusSysdeps.html#ged2e025454364fbe31cd9b6538c9a936">00938</a> <a class="code" href="group__DBusInternalsUtils.html#ged2e025454364fbe31cd9b6538c9a936">_dbus_unix_user_is_at_console</a> (<a class="code" href="group__DBusSysdeps.html#g186e987b700f9ddc6cea8aa0db82b151">dbus_uid_t</a>         uid,
<a name="l00939"></a>00939                                <a class="code" href="structDBusError.html">DBusError</a>         *error)
<a name="l00940"></a>00940 {
<a name="l00941"></a>00941   <span class="keywordflow">return</span> <a class="code" href="group__DBusInternalsUtils.html#ga504db352a939909051a494d06c5b607">_dbus_is_console_user</a> (uid, error);
<a name="l00942"></a>00942 
<a name="l00943"></a>00943 }
<a name="l00944"></a>00944 
<a name="l00952"></a>00952 <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00953"></a><a class="code" href="group__DBusSysdeps.html#g849177164bc5e73435104f57c631ed7e">00953</a> <a class="code" href="group__DBusInternalsUtils.html#g849177164bc5e73435104f57c631ed7e">_dbus_unix_user_is_process_owner</a> (<a class="code" href="group__DBusSysdeps.html#g186e987b700f9ddc6cea8aa0db82b151">dbus_uid_t</a> uid)
<a name="l00954"></a>00954 {
<a name="l00955"></a>00955   <span class="keywordflow">return</span> uid == <a class="code" href="group__DBusSysdepsUnix.html#ge7701063932951bdd8a7df0dcacb3bab">_dbus_getuid</a> ();
<a name="l00956"></a>00956 }
<a name="l00957"></a>00957 
<a name="l00965"></a>00965 <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00966"></a><a class="code" href="group__DBusSysdeps.html#g912d34a7e40b3a57864972e6d6ab65ba">00966</a> <a class="code" href="group__DBusInternalsUtils.html#g912d34a7e40b3a57864972e6d6ab65ba">_dbus_windows_user_is_process_owner</a> (<span class="keyword">const</span> <span class="keywordtype">char</span> *windows_sid)
<a name="l00967"></a>00967 {
<a name="l00968"></a>00968   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00969"></a>00969 }
<a name="l00970"></a>00970  <span class="comment">/* End of DBusInternalsUtils functions */</span>
<a name="l00972"></a>00972 
<a name="l00984"></a>00984 <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00985"></a><a class="code" href="group__DBusSysdeps.html#gfa79c1113fa75419dcc5ee4290e06608">00985</a> <a class="code" href="group__DBusString.html#gfa79c1113fa75419dcc5ee4290e06608">_dbus_string_get_dirname</a>  (<span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *filename,
<a name="l00986"></a>00986                            <a class="code" href="structDBusString.html">DBusString</a>       *dirname)
<a name="l00987"></a>00987 {
<a name="l00988"></a>00988   <span class="keywordtype">int</span> sep;
<a name="l00989"></a>00989   
<a name="l00990"></a>00990   <a class="code" href="group__DBusInternalsUtils.html#g129c6c03f011cdc171934d5d386cc797">_dbus_assert</a> (filename != dirname);
<a name="l00991"></a>00991   <a class="code" href="group__DBusInternalsUtils.html#g129c6c03f011cdc171934d5d386cc797">_dbus_assert</a> (filename != <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>);
<a name="l00992"></a>00992   <a class="code" href="group__DBusInternalsUtils.html#g129c6c03f011cdc171934d5d386cc797">_dbus_assert</a> (dirname != <a class="code" href="group__DBusMacros.html#g070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>);
<a name="l00993"></a>00993 
<a name="l00994"></a>00994   <span class="comment">/* Ignore any separators on the end */</span>
<a name="l00995"></a>00995   sep = _dbus_string_get_length (filename);
<a name="l00996"></a>00996   <span class="keywordflow">if</span> (sep == 0)
<a name="l00997"></a>00997     <span class="keywordflow">return</span> <a class="code" href="group__DBusString.html#g100c5ce0696822c5a4cfbdfaba674d96">_dbus_string_append</a> (dirname, <span class="stringliteral">"."</span>); <span class="comment">/* empty string passed in */</span>
<a name="l00998"></a>00998     
<a name="l00999"></a>00999   <span class="keywordflow">while</span> (sep &gt; 0 &amp;&amp; _dbus_string_get_byte (filename, sep - 1) == <span class="charliteral">'/'</span>)
<a name="l01000"></a>01000     --sep;
<a name="l01001"></a>01001 
<a name="l01002"></a>01002   <a class="code" href="group__DBusInternalsUtils.html#g129c6c03f011cdc171934d5d386cc797">_dbus_assert</a> (sep &gt;= 0);
<a name="l01003"></a>01003   
<a name="l01004"></a>01004   <span class="keywordflow">if</span> (sep == 0)
<a name="l01005"></a>01005     <span class="keywordflow">return</span> <a class="code" href="group__DBusString.html#g100c5ce0696822c5a4cfbdfaba674d96">_dbus_string_append</a> (dirname, <span class="stringliteral">"/"</span>);
<a name="l01006"></a>01006   
<a name="l01007"></a>01007   <span class="comment">/* Now find the previous separator */</span>
<a name="l01008"></a>01008   <a class="code" href="group__DBusString.html#g89d458f4f530ee82dbb45f9dcbc9c637">_dbus_string_find_byte_backward</a> (filename, sep, <span class="charliteral">'/'</span>, &amp;sep);
<a name="l01009"></a>01009   <span class="keywordflow">if</span> (sep &lt; 0)
<a name="l01010"></a>01010     <span class="keywordflow">return</span> <a class="code" href="group__DBusString.html#g100c5ce0696822c5a4cfbdfaba674d96">_dbus_string_append</a> (dirname, <span class="stringliteral">"."</span>);
<a name="l01011"></a>01011   
<a name="l01012"></a>01012   <span class="comment">/* skip multiple separators */</span>
<a name="l01013"></a>01013   <span class="keywordflow">while</span> (sep &gt; 0 &amp;&amp; _dbus_string_get_byte (filename, sep - 1) == <span class="charliteral">'/'</span>)
<a name="l01014"></a>01014     --sep;
<a name="l01015"></a>01015 
<a name="l01016"></a>01016   <a class="code" href="group__DBusInternalsUtils.html#g129c6c03f011cdc171934d5d386cc797">_dbus_assert</a> (sep &gt;= 0);
<a name="l01017"></a>01017   
<a name="l01018"></a>01018   <span class="keywordflow">if</span> (sep == 0 &amp;&amp;
<a name="l01019"></a>01019       _dbus_string_get_byte (filename, 0) == <span class="charliteral">'/'</span>)
<a name="l01020"></a>01020     <span class="keywordflow">return</span> <a class="code" href="group__DBusString.html#g100c5ce0696822c5a4cfbdfaba674d96">_dbus_string_append</a> (dirname, <span class="stringliteral">"/"</span>);
<a name="l01021"></a>01021   <span class="keywordflow">else</span>
<a name="l01022"></a>01022     <span class="keywordflow">return</span> <a class="code" href="group__DBusString.html#gf5f13bc7ac7a623516930d26ae2589bf">_dbus_string_copy_len</a> (filename, 0, sep - 0,
<a name="l01023"></a>01023                                   dirname, _dbus_string_get_length (dirname));
<a name="l01024"></a>01024 } <span class="comment">/* DBusString stuff */</span>
<a name="l01026"></a>01026 
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Dec 14 22:26:12 2009 for D-Bus by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.7 </small></address>
</body>
</html>