winDBus authentication stage

Ralf Habacker ralf.habacker at freenet.de
Tue Mar 13 15:22:45 PDT 2007


Havoc Pennington schrieb:
> Peter Kümmel wrote:
>>
>> I thought all non unix files are platform-independent, therefore the
>> hack.
>>
>
> They are *supposed* to be - except where necessary, e.g. even if we
> had a DBusUser internal abstraction, we'd need
> "_dbus_user_get_unix_uid(DBusUser*)" which would be called inside
> dbus_connection_get_unix_user(), because as I've explained it is
> necessary to have platform-specific public API in some spots in order
> to interoperate with other frameworks and application code. If we had
> a DBusUser that could not be converted to a normal unix or windows
> user representation, it would be 100% completely useless to app
> programmers.
>
> Aside from these interoperability and public API needs, the code
> should be as platform-independent as possible. It is not always
> already as platform-independent as possible, and where it isn't, there
> is work to do when porting. That's the work that needs doing in order
> to port to Windows. I have no objection to increasing the
> platform-independence of the code, as long as it's done in the way
> that I've asked (avoiding ifdefs, avoiding leakage into public
> API/protocol, following the usual dbus code conventions, not
> implementing inherently single-platform stuff on all platforms, and so
> forth). Please, make the code better.
Nice statement, I agree with you, the problem is that there may be
multiple views how to reach this aim. The main discussion we had - and
may be will have - looks to me as a try to find a common base where we
can go together on the road. Let me explain this with the following
example:

I found split_paths_and_append() in dbus-sysdeps-win.c (see below) and
the comment says: 

// @TODO: this function is duplicated from dbus-sysdeps-unix.c
//        and differs only in the path separator, may be we should
//        use a dbus path separator variable

It is a long function and for my opinion there is no reason to duplicate
it as it is. I would add a constant DBUS_PATH_SEPARATOR to
config.h.cmake for cmake (and configure.in for autools) and place this
function into dbus-sysdeps.c. Ready. Someone else may think in another
and we can discuss over this detail until death, which isn't wanted by
anyone and the real important stuff is undone. The important question
is: Where is the limit ?

Ralf


#define _dbus_path_seperator ";"

static dbus_bool_t
split_paths_and_append (DBusString *dirs,
                        const char *suffix,
                        DBusList **dir_list)
{
   int start;
   int i;
   int len;
   char *cpath;
   const DBusString file_suffix;

   start = 0;
   i = 0;

   _dbus_string_init_const (&file_suffix, suffix);

   len = _dbus_string_get_length (dirs);

   while (_dbus_string_find (dirs, start, _dbus_path_seperator, &i))
     {
       DBusString path;

       if (!_dbus_string_init (&path))
          goto oom;

       if (!_dbus_string_copy_len (dirs,
                                   start,
                                   i - start,
                                   &path,
                                   0))
          {
            _dbus_string_free (&path);
            goto oom;
          }

        _dbus_string_chop_white (&path);

        /* check for an empty path */
        if (_dbus_string_get_length (&path) == 0)
          goto next;

        if (!_dbus_concat_dir_and_file (&path,
                                        &file_suffix))
          {
            _dbus_string_free (&path);
            goto oom;
          }

        if (!_dbus_string_copy_data(&path, &cpath))
          {
            _dbus_string_free (&path);
            goto oom;
          }

        if (!_dbus_list_append (dir_list, cpath))
          {
            _dbus_string_free (&path);             
            dbus_free (cpath);
            goto oom;
          }

       next:
        _dbus_string_free (&path);
        start = i + 1;
    }
     
  if (start != len)
    {
      DBusString path;

      if (!_dbus_string_init (&path))
        goto oom;

      if (!_dbus_string_copy_len (dirs,
                                  start,
                                  len - start,
                                  &path,
                                  0))
        {
          _dbus_string_free (&path);
          goto oom;
        }

      if (!_dbus_concat_dir_and_file (&path,
                                      &file_suffix))
        {
          _dbus_string_free (&path);
          goto oom;
        }

      if (!_dbus_string_copy_data(&path, &cpath))
        {
          _dbus_string_free (&path);
          goto oom;
        }

      if (!_dbus_list_append (dir_list, cpath))
        {
          _dbus_string_free (&path);             
          dbus_free (cpath);
          goto oom;
        }

      _dbus_string_free (&path);
    }

  return TRUE;

 oom:
  _dbus_list_foreach (dir_list, (DBusForeachFunction)dbus_free, NULL);
  _dbus_list_clear (dir_list);
  return FALSE;
}



More information about the dbus mailing list