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 1.2
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 
00369 void
00370 _dbus_transport_ref (DBusTransport *transport)
00371 {
00372   _dbus_assert (transport->refcount > 0);
00373   
00374   transport->refcount += 1;
00375 }
00376 
00384 void
00385 _dbus_transport_unref (DBusTransport *transport)
00386 {
00387   _dbus_assert (transport != NULL);
00388   _dbus_assert (transport->refcount > 0);
00389 
00390   transport->refcount -= 1;
00391   if (transport->refcount == 0)
00392     {
00393       _dbus_assert (transport->vtable->finalize != NULL);
00394       
00395       (* transport->vtable->finalize) (transport);
00396     }
00397 }
00398 
00407 void
00408 _dbus_transport_disconnect (DBusTransport *transport)
00409 {
00410   _dbus_assert (transport->vtable->disconnect != NULL);
00411 
00412   if (transport->disconnected)
00413     return;
00414 
00415   (* transport->vtable->disconnect) (transport);
00416   
00417   transport->disconnected = TRUE;
00418 
00419   if (transport->connection)
00420     _dbus_connection_notify_disconnected (transport->connection);
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             case DBUS_AUTH_STATE_AUTHENTICATED_WITH_UNUSED_BYTES:
00468               /* leave as maybe_authenticated */
00469               break;
00470             default:
00471               maybe_authenticated = FALSE;
00472             }
00473         }
00474       
00475       /* If we've authenticated as some identity, check that the auth
00476        * identity is the same as our own identity.  In the future, we
00477        * may have API allowing applications to specify how this is
00478        * done, for example they may allow connection as any identity,
00479        * but then impose restrictions on certain identities.
00480        * Or they may give certain identities extra privileges.
00481        */
00482       
00483       if (maybe_authenticated && transport->is_server)
00484         {
00485           DBusCredentials auth_identity;
00486 
00487           _dbus_auth_get_identity (transport->auth, &auth_identity);
00488 
00489           if (transport->unix_user_function != NULL)
00490             {
00491               /* FIXME we hold the connection lock here and should drop it */
00492               if (!(* transport->unix_user_function) (transport->connection,
00493                                                       auth_identity.uid,
00494                                                       transport->unix_user_data))
00495                 {
00496                   _dbus_verbose ("Client UID "DBUS_UID_FORMAT
00497                                  " was rejected, disconnecting\n",
00498                                  auth_identity.uid);
00499                   _dbus_transport_disconnect (transport);
00500                   return FALSE;
00501                 }
00502               else
00503                 {
00504                   _dbus_verbose ("Client UID "DBUS_UID_FORMAT" authorized\n", auth_identity.uid);
00505                 }
00506             }
00507           else
00508             {
00509               DBusCredentials our_identity;
00510               
00511               _dbus_credentials_from_current_process (&our_identity);
00512               
00513               if (!_dbus_credentials_match (&our_identity,
00514                                             &auth_identity))
00515                 {
00516                   _dbus_verbose ("Client authorized as UID "DBUS_UID_FORMAT
00517                                  " but our UID is "DBUS_UID_FORMAT", disconnecting\n",
00518                                  auth_identity.uid, our_identity.uid);
00519                   _dbus_transport_disconnect (transport);
00520                   return FALSE;
00521                 }
00522               else
00523                 {
00524                   _dbus_verbose ("Client authorized as UID "DBUS_UID_FORMAT
00525                                  " matching our UID "DBUS_UID_FORMAT"\n",
00526                                  auth_identity.uid, our_identity.uid);
00527                 }
00528             }
00529         }
00530 
00531       transport->authenticated = maybe_authenticated;
00532       
00533       return transport->authenticated;
00534     }
00535 }
00536 
00544 const char*
00545 _dbus_transport_get_address (DBusTransport *transport)
00546 {
00547   return transport->address;
00548 }
00549 
00559 dbus_bool_t
00560 _dbus_transport_handle_watch (DBusTransport           *transport,
00561                               DBusWatch               *watch,
00562                               unsigned int             condition)
00563 {
00564   dbus_bool_t retval;
00565   
00566   _dbus_assert (transport->vtable->handle_watch != NULL);
00567 
00568   if (transport->disconnected)
00569     return TRUE;
00570 
00571   if (dbus_watch_get_fd (watch) < 0)
00572     {
00573       _dbus_warn ("Tried to handle an invalidated watch; this watch should have been removed\n");
00574       return TRUE;
00575     }
00576   
00577   _dbus_watch_sanitize_condition (watch, &condition);
00578 
00579   _dbus_transport_ref (transport);
00580   _dbus_watch_ref (watch);
00581   retval = (* transport->vtable->handle_watch) (transport, watch, condition);
00582   _dbus_watch_unref (watch);
00583   _dbus_transport_unref (transport);
00584 
00585   return retval;
00586 }
00587 
00597 dbus_bool_t
00598 _dbus_transport_set_connection (DBusTransport  *transport,
00599                                 DBusConnection *connection)
00600 {
00601   _dbus_assert (transport->vtable->connection_set != NULL);
00602   _dbus_assert (transport->connection == NULL);
00603   
00604   transport->connection = connection;
00605 
00606   _dbus_transport_ref (transport);
00607   if (!(* transport->vtable->connection_set) (transport))
00608     transport->connection = NULL;
00609   _dbus_transport_unref (transport);
00610 
00611   return transport->connection != NULL;
00612 }
00613 
00623 void
00624 _dbus_transport_messages_pending (DBusTransport  *transport,
00625                                   int             queue_length)
00626 {
00627   _dbus_assert (transport->vtable->messages_pending != NULL);
00628 
00629   if (transport->disconnected)
00630     return;
00631 
00632   transport->messages_need_sending = queue_length > 0;
00633 
00634   _dbus_transport_ref (transport);
00635   (* transport->vtable->messages_pending) (transport,
00636                                            queue_length);
00637   _dbus_transport_unref (transport);
00638 }
00639 
00651 void
00652 _dbus_transport_do_iteration (DBusTransport  *transport,
00653                               unsigned int    flags,
00654                               int             timeout_milliseconds)
00655 {
00656   _dbus_assert (transport->vtable->do_iteration != NULL);
00657 
00658   _dbus_verbose ("Transport iteration flags 0x%x timeout %d connected = %d\n",
00659                  flags, timeout_milliseconds, !transport->disconnected);
00660   
00661   if ((flags & (DBUS_ITERATION_DO_WRITING |
00662                 DBUS_ITERATION_DO_READING)) == 0)
00663     return; /* Nothing to do */
00664 
00665   if (transport->disconnected)
00666     return;
00667 
00668   _dbus_transport_ref (transport);
00669   (* transport->vtable->do_iteration) (transport, flags,
00670                                        timeout_milliseconds);
00671   _dbus_transport_unref (transport);
00672 }
00673 
00674 static dbus_bool_t
00675 recover_unused_bytes (DBusTransport *transport)
00676 {
00677   if (_dbus_auth_do_work (transport->auth) != DBUS_AUTH_STATE_AUTHENTICATED_WITH_UNUSED_BYTES)
00678     return TRUE;
00679   
00680   if (_dbus_auth_needs_decoding (transport->auth))
00681     {
00682       DBusString plaintext;
00683       const DBusString *encoded;
00684       DBusString *buffer;
00685       int orig_len;
00686       
00687       if (!_dbus_string_init (&plaintext))
00688         goto nomem;
00689       
00690       _dbus_auth_get_unused_bytes (transport->auth,
00691                                    &encoded);
00692 
00693       if (!_dbus_auth_decode_data (transport->auth,
00694                                    encoded, &plaintext))
00695         {
00696           _dbus_string_free (&plaintext);
00697           goto nomem;
00698         }
00699       
00700       _dbus_message_loader_get_buffer (transport->loader,
00701                                        &buffer);
00702       
00703       orig_len = _dbus_string_get_length (buffer);
00704       
00705       if (!_dbus_string_move (&plaintext, 0, buffer,
00706                               orig_len))
00707         {
00708           _dbus_string_free (&plaintext);
00709           goto nomem;
00710         }
00711       
00712       _dbus_verbose (" %d unused bytes sent to message loader\n", 
00713                      _dbus_string_get_length (buffer) -
00714                      orig_len);
00715       
00716       _dbus_message_loader_return_buffer (transport->loader,
00717                                           buffer,
00718                                           _dbus_string_get_length (buffer) -
00719                                           orig_len);
00720 
00721       _dbus_auth_delete_unused_bytes (transport->auth);
00722       
00723       _dbus_string_free (&plaintext);
00724     }
00725   else
00726     {
00727       const DBusString *bytes;
00728       DBusString *buffer;
00729       int orig_len;
00730       dbus_bool_t succeeded;
00731 
00732       _dbus_message_loader_get_buffer (transport->loader,
00733                                        &buffer);
00734                 
00735       orig_len = _dbus_string_get_length (buffer);
00736                 
00737       _dbus_auth_get_unused_bytes (transport->auth,
00738                                    &bytes);
00739 
00740       succeeded = TRUE;
00741       if (!_dbus_string_copy (bytes, 0, buffer, _dbus_string_get_length (buffer)))
00742         succeeded = FALSE;
00743       
00744       _dbus_verbose (" %d unused bytes sent to message loader\n", 
00745                      _dbus_string_get_length (buffer) -
00746                      orig_len);
00747       
00748       _dbus_message_loader_return_buffer (transport->loader,
00749                                           buffer,
00750                                           _dbus_string_get_length (buffer) -
00751                                           orig_len);
00752 
00753       if (succeeded)
00754         _dbus_auth_delete_unused_bytes (transport->auth);
00755       else
00756         goto nomem;
00757     }
00758 
00759   return TRUE;
00760 
00761  nomem:
00762   _dbus_verbose ("Not enough memory to transfer unused bytes from auth conversation\n");
00763   return FALSE;
00764 }
00765 
00773 DBusDispatchStatus
00774 _dbus_transport_get_dispatch_status (DBusTransport *transport)
00775 {
00776   if (_dbus_counter_get_value (transport->live_messages_size) >= transport->max_live_messages_size)
00777     return DBUS_DISPATCH_COMPLETE; /* complete for now */
00778 
00779   if (!_dbus_transport_get_is_authenticated (transport))
00780     {
00781       if (_dbus_auth_do_work (transport->auth) ==
00782           DBUS_AUTH_STATE_WAITING_FOR_MEMORY)
00783         return DBUS_DISPATCH_NEED_MEMORY;
00784       else if (!_dbus_transport_get_is_authenticated (transport))
00785         return DBUS_DISPATCH_COMPLETE;
00786     }
00787 
00788   if (!transport->unused_bytes_recovered &&
00789       !recover_unused_bytes (transport))
00790     return DBUS_DISPATCH_NEED_MEMORY;
00791 
00792   transport->unused_bytes_recovered = TRUE;
00793   
00794   if (!_dbus_message_loader_queue_messages (transport->loader))
00795     return DBUS_DISPATCH_NEED_MEMORY;
00796 
00797   if (_dbus_message_loader_peek_message (transport->loader) != NULL)
00798     return DBUS_DISPATCH_DATA_REMAINS;
00799   else
00800     return DBUS_DISPATCH_COMPLETE;
00801 }
00802 
00811 dbus_bool_t
00812 _dbus_transport_queue_messages (DBusTransport *transport)
00813 {
00814   DBusDispatchStatus status;
00815 
00816   _dbus_verbose ("_dbus_transport_queue_messages()\n");
00817   
00818   /* Queue any messages */
00819   while ((status = _dbus_transport_get_dispatch_status (transport)) == DBUS_DISPATCH_DATA_REMAINS)
00820     {
00821       DBusMessage *message;
00822       DBusList *link;
00823 
00824       link = _dbus_message_loader_pop_message_link (transport->loader);
00825       _dbus_assert (link != NULL);
00826       
00827       message = link->data;
00828       
00829       _dbus_verbose ("queueing received message %p\n", message);
00830 
00831       if (!_dbus_message_add_size_counter (message, transport->live_messages_size))
00832         {
00833           _dbus_message_loader_putback_message_link (transport->loader,
00834                                                      link);
00835           status = DBUS_DISPATCH_NEED_MEMORY;
00836           break;
00837         }
00838       else
00839         {
00840           /* pass ownership of link and message ref to connection */
00841           _dbus_connection_queue_received_message_link (transport->connection,
00842                                                         link);
00843         }
00844     }
00845 
00846   if (_dbus_message_loader_get_is_corrupted (transport->loader))
00847     {
00848       _dbus_verbose ("Corrupted message stream, disconnecting\n");
00849       _dbus_transport_disconnect (transport);
00850     }
00851 
00852   return status != DBUS_DISPATCH_NEED_MEMORY;
00853 }
00854 
00861 void
00862 _dbus_transport_set_max_message_size (DBusTransport  *transport,
00863                                       long            size)
00864 {
00865   _dbus_message_loader_set_max_message_size (transport->loader, size);
00866 }
00867 
00874 long
00875 _dbus_transport_get_max_message_size (DBusTransport  *transport)
00876 {
00877   return _dbus_message_loader_get_max_message_size (transport->loader);
00878 }
00879 
00886 void
00887 _dbus_transport_set_max_received_size (DBusTransport  *transport,
00888                                        long            size)
00889 {
00890   transport->max_live_messages_size = size;
00891   _dbus_counter_set_notify (transport->live_messages_size,
00892                             transport->max_live_messages_size,
00893                             live_messages_size_notify,
00894                             transport);
00895 }
00896 
00897 
00904 long
00905 _dbus_transport_get_max_received_size (DBusTransport  *transport)
00906 {
00907   return transport->max_live_messages_size;
00908 }
00909 
00917 dbus_bool_t
00918 _dbus_transport_get_unix_user (DBusTransport *transport,
00919                                unsigned long *uid)
00920 {
00921   DBusCredentials auth_identity;
00922 
00923   *uid = _DBUS_INT_MAX; /* better than some root or system user in
00924                          * case of bugs in the caller. Caller should
00925                          * never use this value on purpose, however.
00926                          */
00927   
00928   if (!transport->authenticated)
00929     return FALSE;
00930   
00931   _dbus_auth_get_identity (transport->auth, &auth_identity);
00932 
00933   if (auth_identity.uid != DBUS_UID_UNSET)
00934     {
00935       *uid = auth_identity.uid;
00936       return TRUE;
00937     }
00938   else
00939     return FALSE;
00940 }
00941 
00952 void
00953 _dbus_transport_set_unix_user_function (DBusTransport             *transport,
00954                                         DBusAllowUnixUserFunction  function,
00955                                         void                      *data,
00956                                         DBusFreeFunction           free_data_function,
00957                                         void                     **old_data,
00958                                         DBusFreeFunction          *old_free_data_function)
00959 {  
00960   *old_data = transport->unix_user_data;
00961   *old_free_data_function = transport->free_unix_user_data;
00962 
00963   transport->unix_user_function = function;
00964   transport->unix_user_data = data;
00965   transport->free_unix_user_data = free_data_function;
00966 }
00967 
00976 dbus_bool_t
00977 _dbus_transport_set_auth_mechanisms (DBusTransport  *transport,
00978                                      const char    **mechanisms)
00979 {
00980   return _dbus_auth_set_mechanisms (transport->auth, mechanisms);
00981 }
00982 
00983 

Generated on Wed Oct 22 14:05:05 2003 for D-BUS by doxygen1.3-rc3