Main Page   Modules   Data Structures   File List   Data Fields   Related Pages  

dbus-transport.c

00001 /* -*- mode: C; c-file-style: "gnu" -*- */
00002 /* dbus-transport.c DBusTransport object (internal to D-BUS implementation)
00003  *
00004  * Copyright (C) 2002, 2003  Red Hat Inc.
00005  *
00006  * Licensed under the Academic Free License version 2.0
00007  * 
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  * 
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  */
00023 
00024 #include "dbus-transport-protected.h"
00025 #include "dbus-transport-unix.h"
00026 #include "dbus-connection-internal.h"
00027 #include "dbus-watch.h"
00028 #include "dbus-auth.h"
00029 #include "dbus-address.h"
00030 #ifdef DBUS_BUILD_TESTS
00031 #include "dbus-server-debug-pipe.h"
00032 #endif
00033 
00055 static void
00056 live_messages_size_notify (DBusCounter *counter,
00057                            void        *user_data)
00058 {
00059   DBusTransport *transport = user_data;
00060 
00061   _dbus_transport_ref (transport);
00062 
00063 #if 0
00064   _dbus_verbose ("Counter value is now %d\n",
00065                  (int) _dbus_counter_get_value (counter));
00066 #endif
00067   
00068   /* disable or re-enable the read watch for the transport if
00069    * required.
00070    */
00071   if (* transport->vtable->live_messages_changed)
00072     (* transport->vtable->live_messages_changed) (transport);
00073 
00074   _dbus_transport_unref (transport);
00075 }
00076 
00087 dbus_bool_t
00088 _dbus_transport_init_base (DBusTransport             *transport,
00089                            const DBusTransportVTable *vtable,
00090                            dbus_bool_t                server,
00091                            const DBusString          *address)
00092 {
00093   DBusMessageLoader *loader;
00094   DBusAuth *auth;
00095   DBusCounter *counter;
00096   char *address_copy;
00097   
00098   loader = _dbus_message_loader_new ();
00099   if (loader == NULL)
00100     return FALSE;
00101   
00102   if (server)
00103     auth = _dbus_auth_server_new ();
00104   else
00105     auth = _dbus_auth_client_new ();
00106   if (auth == NULL)
00107     {
00108       _dbus_message_loader_unref (loader);
00109       return FALSE;
00110     }
00111 
00112   counter = _dbus_counter_new ();
00113   if (counter == NULL)
00114     {
00115       _dbus_auth_unref (auth);
00116       _dbus_message_loader_unref (loader);
00117       return FALSE;
00118     }  
00119   
00120   if (server)
00121     {
00122       _dbus_assert (address == NULL);
00123       address_copy = NULL;
00124     }
00125   else
00126     {
00127       _dbus_assert (address != NULL);
00128 
00129       if (!_dbus_string_copy_data (address, &address_copy))
00130         {
00131           _dbus_counter_unref (counter);
00132           _dbus_auth_unref (auth);
00133           _dbus_message_loader_unref (loader);
00134           return FALSE;
00135         }
00136     }
00137   
00138   transport->refcount = 1;
00139   transport->vtable = vtable;
00140   transport->loader = loader;
00141   transport->auth = auth;
00142   transport->live_messages_size = counter;
00143   transport->authenticated = FALSE;
00144   transport->messages_need_sending = FALSE;
00145   transport->disconnected = FALSE;
00146   transport->send_credentials_pending = !server;
00147   transport->receive_credentials_pending = server;
00148   transport->is_server = server;
00149   transport->address = address_copy;
00150   
00151   transport->unix_user_function = NULL;
00152   transport->unix_user_data = NULL;
00153   transport->free_unix_user_data = NULL;
00154   
00155   /* Try to default to something that won't totally hose the system,
00156    * but doesn't impose too much of a limitation.
00157    */
00158   transport->max_live_messages_size = _DBUS_ONE_MEGABYTE * 63;
00159   
00160   transport->credentials.pid = -1;
00161   transport->credentials.uid = -1;
00162   transport->credentials.gid = -1;
00163 
00164   _dbus_counter_set_notify (transport->live_messages_size,
00165                             transport->max_live_messages_size,
00166                             live_messages_size_notify,
00167                             transport);
00168 
00169   if (transport->address)
00170     _dbus_verbose ("Initialized transport on address %s\n", transport->address);
00171   
00172   return TRUE;
00173 }
00174 
00181 void
00182 _dbus_transport_finalize_base (DBusTransport *transport)
00183 {
00184   if (!transport->disconnected)
00185     _dbus_transport_disconnect (transport);
00186 
00187   if (transport->free_unix_user_data != NULL)
00188     (* transport->free_unix_user_data) (transport->unix_user_data);
00189   
00190   _dbus_message_loader_unref (transport->loader);
00191   _dbus_auth_unref (transport->auth);
00192   _dbus_counter_set_notify (transport->live_messages_size,
00193                             0, NULL, NULL);
00194   _dbus_counter_unref (transport->live_messages_size);
00195   dbus_free (transport->address);
00196 }
00197 
00209 DBusTransport*
00210 _dbus_transport_open (const char     *address,
00211                       DBusError      *error)
00212 {
00213   DBusTransport *transport;
00214   DBusAddressEntry **entries;
00215   DBusError tmp_error;
00216   DBusError first_error;
00217   int len, i;
00218   const char *address_problem_type;
00219   const char *address_problem_field;
00220   const char *address_problem_other;
00221 
00222   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
00223   
00224   if (!dbus_parse_address (address, &entries, &len, error))
00225     return NULL;
00226 
00227   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
00228   
00229   transport = NULL;
00230   address_problem_type = NULL;
00231   address_problem_field = NULL;
00232   address_problem_other = NULL;
00233 
00234   dbus_error_init (&tmp_error);
00235   dbus_error_init (&first_error);
00236   for (i = 0; i < len; i++)
00237     {
00238       const char *method;
00239 
00240       method = dbus_address_entry_get_method (entries[i]);
00241       
00242       if (strcmp (method, "unix") == 0)
00243         {
00244           const char *path = dbus_address_entry_get_value (entries[i], "path");
00245           const char *tmpdir = dbus_address_entry_get_value (entries[i], "tmpdir");
00246           const char *abstract = dbus_address_entry_get_value (entries[i], "abstract");
00247           
00248           if (tmpdir != NULL)
00249             {
00250               address_problem_other = "cannot use the \"tmpdir\" option for an address to connect to, only in an address to listen on";
00251               goto bad_address;
00252             }
00253           
00254           if (path == NULL && abstract == NULL)
00255             {
00256               address_problem_type = "unix";
00257               address_problem_field = "path or abstract";  
00258               goto bad_address;
00259             }
00260 
00261           if (path != NULL && abstract != NULL)
00262             {
00263               address_problem_other = "can't specify both \"path\" and \"abstract\" options in an address";
00264               goto bad_address;
00265             }
00266 
00267           if (path)
00268             transport = _dbus_transport_new_for_domain_socket (path, FALSE,
00269                                                                &tmp_error);
00270           else
00271             transport = _dbus_transport_new_for_domain_socket (abstract, TRUE,
00272                                                                &tmp_error);
00273         }
00274       else if (strcmp (method, "tcp") == 0)
00275         {
00276           const char *host = dbus_address_entry_get_value (entries[i], "host");
00277           const char *port = dbus_address_entry_get_value (entries[i], "port");
00278           DBusString  str;
00279           long lport;
00280           dbus_bool_t sresult;
00281           
00282           if (port == NULL)
00283             {
00284               address_problem_type = "tcp";
00285               address_problem_field = "port";
00286               goto bad_address;
00287             }
00288 
00289           _dbus_string_init_const (&str, port);
00290           sresult = _dbus_string_parse_int (&str, 0, &lport, NULL);
00291           _dbus_string_free (&str);
00292           
00293           if (sresult == FALSE || lport <= 0 || lport > 65535)
00294             {
00295               address_problem_other = "Port is not an integer between 0 and 65535";
00296               goto bad_address;
00297             }
00298           
00299           transport = _dbus_transport_new_for_tcp_socket (host, lport, &tmp_error);
00300         }
00301 #ifdef DBUS_BUILD_TESTS
00302       else if (strcmp (method, "debug-pipe") == 0)
00303         {
00304           const char *name = dbus_address_entry_get_value (entries[i], "name");
00305 
00306           if (name == NULL)
00307             {
00308               address_problem_type = "debug-pipe";
00309               address_problem_field = "name";
00310               goto bad_address;
00311             }
00312           
00313           transport = _dbus_transport_debug_pipe_new (name, &tmp_error);
00314         }
00315 #endif
00316       else
00317         {
00318           address_problem_other = "Unknown address type (examples of valid types are \"unix\" and \"tcp\")";
00319           goto bad_address;
00320         }
00321 
00322       if (transport)
00323         break;
00324 
00325       _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
00326       
00327       if (i == 0)
00328         dbus_move_error (&tmp_error, &first_error);
00329       else
00330         dbus_error_free (&tmp_error);
00331     }
00332 
00333   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
00334   _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
00335   
00336   if (transport == NULL)
00337     {
00338       _DBUS_ASSERT_ERROR_IS_SET (&first_error);
00339       dbus_move_error (&first_error, error);
00340     }
00341   else
00342     {
00343       dbus_error_free (&first_error);
00344     }
00345   
00346   dbus_address_entries_free (entries);
00347   return transport;
00348 
00349  bad_address:
00350   dbus_address_entries_free (entries);
00351 
00352   if (address_problem_type != NULL)
00353     dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS,
00354                     "Address of type %s was missing argument %s",
00355                     address_problem_type, address_problem_field);
00356   else
00357     dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS,
00358                     "Could not parse address: %s",
00359                     address_problem_other);
00360 
00361   return NULL;
00362 }
00363 
00370 DBusTransport *
00371 _dbus_transport_ref (DBusTransport *transport)
00372 {
00373   _dbus_assert (transport->refcount > 0);
00374   
00375   transport->refcount += 1;
00376 
00377   return transport;
00378 }
00379 
00387 void
00388 _dbus_transport_unref (DBusTransport *transport)
00389 {
00390   _dbus_assert (transport != NULL);
00391   _dbus_assert (transport->refcount > 0);
00392 
00393   transport->refcount -= 1;
00394   if (transport->refcount == 0)
00395     {
00396       _dbus_assert (transport->vtable->finalize != NULL);
00397       
00398       (* transport->vtable->finalize) (transport);
00399     }
00400 }
00401 
00410 void
00411 _dbus_transport_disconnect (DBusTransport *transport)
00412 {
00413   _dbus_assert (transport->vtable->disconnect != NULL);
00414 
00415   if (transport->disconnected)
00416     return;
00417 
00418   (* transport->vtable->disconnect) (transport);
00419   
00420   transport->disconnected = TRUE;
00421 }
00422 
00431 dbus_bool_t
00432 _dbus_transport_get_is_connected (DBusTransport *transport)
00433 {
00434   return !transport->disconnected;
00435 }
00436 
00446 dbus_bool_t
00447 _dbus_transport_get_is_authenticated (DBusTransport *transport)
00448 {  
00449   if (transport->authenticated)
00450     return TRUE;
00451   else
00452     {
00453       dbus_bool_t maybe_authenticated;
00454       
00455       if (transport->disconnected)
00456         return FALSE;
00457       
00458       maybe_authenticated =
00459         (!(transport->send_credentials_pending ||
00460            transport->receive_credentials_pending));
00461 
00462       if (maybe_authenticated)
00463         {
00464           switch (_dbus_auth_do_work (transport->auth))
00465             {
00466             case DBUS_AUTH_STATE_AUTHENTICATED:
00467               /* leave as maybe_authenticated */
00468               break;
00469             default:
00470               maybe_authenticated = FALSE;
00471             }
00472         }
00473       
00474       /* If we've authenticated as some identity, check that the auth
00475        * identity is the same as our own identity.  In the future, we
00476        * may have API allowing applications to specify how this is
00477        * done, for example they may allow connection as any identity,
00478        * but then impose restrictions on certain identities.
00479        * Or they may give certain identities extra privileges.
00480        */
00481       
00482       if (maybe_authenticated && transport->is_server)
00483         {
00484           DBusCredentials auth_identity;
00485 
00486           _dbus_auth_get_identity (transport->auth, &auth_identity);
00487 
00488           if (transport->unix_user_function != NULL)
00489             {
00490               /* FIXME we hold the connection lock here and should drop it */
00491               if (!(* transport->unix_user_function) (transport->connection,
00492                                                       auth_identity.uid,
00493                                                       transport->unix_user_data))
00494                 {
00495                   _dbus_verbose ("Client UID "DBUS_UID_FORMAT
00496                                  " was rejected, disconnecting\n",
00497                                  auth_identity.uid);
00498                   _dbus_transport_disconnect (transport);
00499                   return FALSE;
00500                 }
00501               else
00502                 {
00503                   _dbus_verbose ("Client UID "DBUS_UID_FORMAT" authorized\n", auth_identity.uid);
00504                 }
00505             }
00506           else
00507             {
00508               DBusCredentials our_identity;
00509               
00510               _dbus_credentials_from_current_process (&our_identity);
00511               
00512               if (!_dbus_credentials_match (&our_identity,
00513                                             &auth_identity))
00514                 {
00515                   _dbus_verbose ("Client authorized as UID "DBUS_UID_FORMAT
00516                                  " but our UID is "DBUS_UID_FORMAT", disconnecting\n",
00517                                  auth_identity.uid, our_identity.uid);
00518                   _dbus_transport_disconnect (transport);
00519                   return FALSE;
00520                 }
00521               else
00522                 {
00523                   _dbus_verbose ("Client authorized as UID "DBUS_UID_FORMAT
00524                                  " matching our UID "DBUS_UID_FORMAT"\n",
00525                                  auth_identity.uid, our_identity.uid);
00526                 }
00527             }
00528         }
00529 
00530       transport->authenticated = maybe_authenticated;
00531       
00532       return transport->authenticated;
00533     }
00534 }
00535 
00543 const char*
00544 _dbus_transport_get_address (DBusTransport *transport)
00545 {
00546   return transport->address;
00547 }
00548 
00558 dbus_bool_t
00559 _dbus_transport_handle_watch (DBusTransport           *transport,
00560                               DBusWatch               *watch,
00561                               unsigned int             condition)
00562 {
00563   dbus_bool_t retval;
00564   
00565   _dbus_assert (transport->vtable->handle_watch != NULL);
00566 
00567   if (transport->disconnected)
00568     return TRUE;
00569 
00570   if (dbus_watch_get_fd (watch) < 0)
00571     {
00572       _dbus_warn ("Tried to handle an invalidated watch; this watch should have been removed\n");
00573       return TRUE;
00574     }
00575   
00576   _dbus_watch_sanitize_condition (watch, &condition);
00577 
00578   _dbus_transport_ref (transport);
00579   _dbus_watch_ref (watch);
00580   retval = (* transport->vtable->handle_watch) (transport, watch, condition);
00581   _dbus_watch_unref (watch);
00582   _dbus_transport_unref (transport);
00583 
00584   return retval;
00585 }
00586 
00596 dbus_bool_t
00597 _dbus_transport_set_connection (DBusTransport  *transport,
00598                                 DBusConnection *connection)
00599 {
00600   _dbus_assert (transport->vtable->connection_set != NULL);
00601   _dbus_assert (transport->connection == NULL);
00602   
00603   transport->connection = connection;
00604 
00605   _dbus_transport_ref (transport);
00606   if (!(* transport->vtable->connection_set) (transport))
00607     transport->connection = NULL;
00608   _dbus_transport_unref (transport);
00609 
00610   return transport->connection != NULL;
00611 }
00612 
00622 void
00623 _dbus_transport_messages_pending (DBusTransport  *transport,
00624                                   int             queue_length)
00625 {
00626   _dbus_assert (transport->vtable->messages_pending != NULL);
00627 
00628   if (transport->disconnected)
00629     return;
00630 
00631   transport->messages_need_sending = queue_length > 0;
00632 
00633   _dbus_transport_ref (transport);
00634   (* transport->vtable->messages_pending) (transport,
00635                                            queue_length);
00636   _dbus_transport_unref (transport);
00637 }
00638 
00650 void
00651 _dbus_transport_do_iteration (DBusTransport  *transport,
00652                               unsigned int    flags,
00653                               int             timeout_milliseconds)
00654 {
00655   _dbus_assert (transport->vtable->do_iteration != NULL);
00656 
00657   _dbus_verbose ("Transport iteration flags 0x%x timeout %d connected = %d\n",
00658                  flags, timeout_milliseconds, !transport->disconnected);
00659   
00660   if ((flags & (DBUS_ITERATION_DO_WRITING |
00661                 DBUS_ITERATION_DO_READING)) == 0)
00662     return; /* Nothing to do */
00663 
00664   if (transport->disconnected)
00665     return;
00666 
00667   _dbus_transport_ref (transport);
00668   (* transport->vtable->do_iteration) (transport, flags,
00669                                        timeout_milliseconds);
00670   _dbus_transport_unref (transport);
00671 }
00672 
00673 static dbus_bool_t
00674 recover_unused_bytes (DBusTransport *transport)
00675 {
00676   if (_dbus_auth_needs_decoding (transport->auth))
00677     {
00678       DBusString plaintext;
00679       const DBusString *encoded;
00680       DBusString *buffer;
00681       int orig_len;
00682       
00683       if (!_dbus_string_init (&plaintext))
00684         goto nomem;
00685       
00686       _dbus_auth_get_unused_bytes (transport->auth,
00687                                    &encoded);
00688 
00689       if (!_dbus_auth_decode_data (transport->auth,
00690                                    encoded, &plaintext))
00691         {
00692           _dbus_string_free (&plaintext);
00693           goto nomem;
00694         }
00695       
00696       _dbus_message_loader_get_buffer (transport->loader,
00697                                        &buffer);
00698       
00699       orig_len = _dbus_string_get_length (buffer);
00700       
00701       if (!_dbus_string_move (&plaintext, 0, buffer,
00702                               orig_len))
00703         {
00704           _dbus_string_free (&plaintext);
00705           goto nomem;
00706         }
00707       
00708       _dbus_verbose (" %d unused bytes sent to message loader\n", 
00709                      _dbus_string_get_length (buffer) -
00710                      orig_len);
00711       
00712       _dbus_message_loader_return_buffer (transport->loader,
00713                                           buffer,
00714                                           _dbus_string_get_length (buffer) -
00715                                           orig_len);
00716 
00717       _dbus_auth_delete_unused_bytes (transport->auth);
00718       
00719       _dbus_string_free (&plaintext);
00720     }
00721   else
00722     {
00723       const DBusString *bytes;
00724       DBusString *buffer;
00725       int orig_len;
00726       dbus_bool_t succeeded;
00727 
00728       _dbus_message_loader_get_buffer (transport->loader,
00729                                        &buffer);
00730                 
00731       orig_len = _dbus_string_get_length (buffer);
00732                 
00733       _dbus_auth_get_unused_bytes (transport->auth,
00734                                    &bytes);
00735 
00736       succeeded = TRUE;
00737       if (!_dbus_string_copy (bytes, 0, buffer, _dbus_string_get_length (buffer)))
00738         succeeded = FALSE;
00739       
00740       _dbus_verbose (" %d unused bytes sent to message loader\n", 
00741                      _dbus_string_get_length (buffer) -
00742                      orig_len);
00743       
00744       _dbus_message_loader_return_buffer (transport->loader,
00745                                           buffer,
00746                                           _dbus_string_get_length (buffer) -
00747                                           orig_len);
00748 
00749       if (succeeded)
00750         _dbus_auth_delete_unused_bytes (transport->auth);
00751       else
00752         goto nomem;
00753     }
00754 
00755   return TRUE;
00756 
00757  nomem:
00758   _dbus_verbose ("Not enough memory to transfer unused bytes from auth conversation\n");
00759   return FALSE;
00760 }
00761 
00769 DBusDispatchStatus
00770 _dbus_transport_get_dispatch_status (DBusTransport *transport)
00771 {
00772   if (_dbus_counter_get_value (transport->live_messages_size) >= transport->max_live_messages_size)
00773     return DBUS_DISPATCH_COMPLETE; /* complete for now */
00774 
00775   if (!_dbus_transport_get_is_authenticated (transport))
00776     {
00777       if (_dbus_auth_do_work (transport->auth) ==
00778           DBUS_AUTH_STATE_WAITING_FOR_MEMORY)
00779         return DBUS_DISPATCH_NEED_MEMORY;
00780       else if (!_dbus_transport_get_is_authenticated (transport))
00781         return DBUS_DISPATCH_COMPLETE;
00782     }
00783 
00784   if (!transport->unused_bytes_recovered &&
00785       !recover_unused_bytes (transport))
00786     return DBUS_DISPATCH_NEED_MEMORY;
00787 
00788   transport->unused_bytes_recovered = TRUE;
00789   
00790   if (!_dbus_message_loader_queue_messages (transport->loader))
00791     return DBUS_DISPATCH_NEED_MEMORY;
00792 
00793   if (_dbus_message_loader_peek_message (transport->loader) != NULL)
00794     return DBUS_DISPATCH_DATA_REMAINS;
00795   else
00796     return DBUS_DISPATCH_COMPLETE;
00797 }
00798 
00807 dbus_bool_t
00808 _dbus_transport_queue_messages (DBusTransport *transport)
00809 {
00810   DBusDispatchStatus status;
00811 
00812 #if 0
00813   _dbus_verbose ("_dbus_transport_queue_messages()\n");
00814 #endif
00815   
00816   /* Queue any messages */
00817   while ((status = _dbus_transport_get_dispatch_status (transport)) == DBUS_DISPATCH_DATA_REMAINS)
00818     {
00819       DBusMessage *message;
00820       DBusList *link;
00821 
00822       link = _dbus_message_loader_pop_message_link (transport->loader);
00823       _dbus_assert (link != NULL);
00824       
00825       message = link->data;
00826       
00827       _dbus_verbose ("queueing received message %p\n", message);
00828 
00829       if (!_dbus_message_add_size_counter (message, transport->live_messages_size))
00830         {
00831           _dbus_message_loader_putback_message_link (transport->loader,
00832                                                      link);
00833           status = DBUS_DISPATCH_NEED_MEMORY;
00834           break;
00835         }
00836       else
00837         {
00838           /* pass ownership of link and message ref to connection */
00839           _dbus_connection_queue_received_message_link (transport->connection,
00840                                                         link);
00841         }
00842     }
00843 
00844   if (_dbus_message_loader_get_is_corrupted (transport->loader))
00845     {
00846       _dbus_verbose ("Corrupted message stream, disconnecting\n");
00847       _dbus_transport_disconnect (transport);
00848     }
00849 
00850   return status != DBUS_DISPATCH_NEED_MEMORY;
00851 }
00852 
00859 void
00860 _dbus_transport_set_max_message_size (DBusTransport  *transport,
00861                                       long            size)
00862 {
00863   _dbus_message_loader_set_max_message_size (transport->loader, size);
00864 }
00865 
00872 long
00873 _dbus_transport_get_max_message_size (DBusTransport  *transport)
00874 {
00875   return _dbus_message_loader_get_max_message_size (transport->loader);
00876 }
00877 
00884 void
00885 _dbus_transport_set_max_received_size (DBusTransport  *transport,
00886                                        long            size)
00887 {
00888   transport->max_live_messages_size = size;
00889   _dbus_counter_set_notify (transport->live_messages_size,
00890                             transport->max_live_messages_size,
00891                             live_messages_size_notify,
00892                             transport);
00893 }
00894 
00895 
00902 long
00903 _dbus_transport_get_max_received_size (DBusTransport  *transport)
00904 {
00905   return transport->max_live_messages_size;
00906 }
00907 
00915 dbus_bool_t
00916 _dbus_transport_get_unix_user (DBusTransport *transport,
00917                                unsigned long *uid)
00918 {
00919   DBusCredentials auth_identity;
00920 
00921   *uid = _DBUS_INT_MAX; /* better than some root or system user in
00922                          * case of bugs in the caller. Caller should
00923                          * never use this value on purpose, however.
00924                          */
00925   
00926   if (!transport->authenticated)
00927     return FALSE;
00928   
00929   _dbus_auth_get_identity (transport->auth, &auth_identity);
00930 
00931   if (auth_identity.uid != DBUS_UID_UNSET)
00932     {
00933       *uid = auth_identity.uid;
00934       return TRUE;
00935     }
00936   else
00937     return FALSE;
00938 }
00939 
00950 void
00951 _dbus_transport_set_unix_user_function (DBusTransport             *transport,
00952                                         DBusAllowUnixUserFunction  function,
00953                                         void                      *data,
00954                                         DBusFreeFunction           free_data_function,
00955                                         void                     **old_data,
00956                                         DBusFreeFunction          *old_free_data_function)
00957 {  
00958   *old_data = transport->unix_user_data;
00959   *old_free_data_function = transport->free_unix_user_data;
00960 
00961   transport->unix_user_function = function;
00962   transport->unix_user_data = data;
00963   transport->free_unix_user_data = free_data_function;
00964 }
00965 
00974 dbus_bool_t
00975 _dbus_transport_set_auth_mechanisms (DBusTransport  *transport,
00976                                      const char    **mechanisms)
00977 {
00978   return _dbus_auth_set_mechanisms (transport->auth, mechanisms);
00979 }
00980 
00981 

Generated on Wed Jun 9 05:01:27 2004 for D-BUS by doxygen1.2.15