unix-fd: add basic marshalling code for unix fds

This is actually pretty boring since we store our fds as indexes that
are stored as uint32_t's.
This commit is contained in:
Lennart Poettering 2009-04-22 03:31:20 +02:00
parent faac66e3ea
commit ba7daa606c
6 changed files with 25 additions and 2 deletions

View file

@ -414,6 +414,7 @@ _dbus_marshal_set_basic (DBusString *str,
case DBUS_TYPE_BOOLEAN:
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT32:
case DBUS_TYPE_UNIX_FD:
pos = _DBUS_ALIGN_VALUE (pos, 4);
set_4_octets (str, pos, vp->u32, byte_order);
if (old_end_pos)
@ -540,6 +541,7 @@ _dbus_marshal_read_basic (const DBusString *str,
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT32:
case DBUS_TYPE_BOOLEAN:
case DBUS_TYPE_UNIX_FD:
{
volatile dbus_uint32_t *vp = value;
pos = _DBUS_ALIGN_VALUE (pos, 4);
@ -839,6 +841,7 @@ _dbus_marshal_write_basic (DBusString *str,
break;
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT32:
case DBUS_TYPE_UNIX_FD:
return marshal_4_octets (str, insert_at, vp->u32,
byte_order, pos_after);
break;
@ -1066,6 +1069,7 @@ _dbus_marshal_write_fixed_multi (DBusString *str,
case DBUS_TYPE_BOOLEAN:
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT32:
case DBUS_TYPE_UNIX_FD:
return marshal_fixed_multi (str, insert_at, vp, n_elements, byte_order, 4, pos_after);
break;
case DBUS_TYPE_INT64:
@ -1114,6 +1118,7 @@ _dbus_marshal_skip_basic (const DBusString *str,
case DBUS_TYPE_BOOLEAN:
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT32:
case DBUS_TYPE_UNIX_FD:
*pos = _DBUS_ALIGN_VALUE (*pos, 4);
*pos += 4;
break;
@ -1202,6 +1207,7 @@ _dbus_type_get_alignment (int typecode)
case DBUS_TYPE_BOOLEAN:
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT32:
case DBUS_TYPE_UNIX_FD:
/* this stuff is 4 since it starts with a length */
case DBUS_TYPE_STRING:
case DBUS_TYPE_OBJECT_PATH:
@ -1256,6 +1262,7 @@ _dbus_type_is_valid (int typecode)
case DBUS_TYPE_STRUCT:
case DBUS_TYPE_DICT_ENTRY:
case DBUS_TYPE_VARIANT:
case DBUS_TYPE_UNIX_FD:
return TRUE;
default:
@ -1316,6 +1323,8 @@ _dbus_type_to_string (int typecode)
return "begin_dict_entry";
case DBUS_DICT_ENTRY_END_CHAR:
return "end_dict_entry";
case DBUS_TYPE_UNIX_FD:
return "unix_fd";
default:
return "unknown";
}

View file

@ -191,6 +191,11 @@ byteswap_body_helper (DBusTypeReader *reader,
}
break;
case DBUS_TYPE_UNIX_FD:
/* fds can only be passed on a local machine, so byte order must always match */
_dbus_assert_not_reached("attempted to byteswap unix fds which makes no sense");
break;
default:
_dbus_assert_not_reached ("invalid typecode in supposedly-validated signature");
break;

View file

@ -81,7 +81,8 @@ _dbus_header_field_types[DBUS_HEADER_FIELD_LAST+1] = {
{ DBUS_HEADER_FIELD_REPLY_SERIAL, DBUS_TYPE_UINT32 },
{ DBUS_HEADER_FIELD_DESTINATION, DBUS_TYPE_STRING },
{ DBUS_HEADER_FIELD_SENDER, DBUS_TYPE_STRING },
{ DBUS_HEADER_FIELD_SIGNATURE, DBUS_TYPE_SIGNATURE }
{ DBUS_HEADER_FIELD_SIGNATURE, DBUS_TYPE_SIGNATURE },
{ DBUS_HEADER_FIELD_UNIX_FDS, DBUS_TYPE_UINT32 }
};
/** Macro to look up the correct type for a field */
@ -888,6 +889,10 @@ load_and_validate_field (DBusHeader *header,
}
break;
case DBUS_HEADER_FIELD_UNIX_FDS:
/* Every value makes sense */
break;
case DBUS_HEADER_FIELD_SIGNATURE:
/* SIGNATURE validated generically due to its type */
string_validation_func = NULL;

View file

@ -100,6 +100,7 @@ _dbus_validate_signature_with_reason (const DBusString *type_str,
case DBUS_TYPE_UINT16:
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT32:
case DBUS_TYPE_UNIX_FD:
case DBUS_TYPE_INT64:
case DBUS_TYPE_UINT64:
case DBUS_TYPE_DOUBLE:
@ -319,12 +320,13 @@ validate_body_helper (DBusTypeReader *reader,
case DBUS_TYPE_BYTE:
++p;
break;
case DBUS_TYPE_BOOLEAN:
case DBUS_TYPE_INT16:
case DBUS_TYPE_UINT16:
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT32:
case DBUS_TYPE_UNIX_FD:
case DBUS_TYPE_INT64:
case DBUS_TYPE_UINT64:
case DBUS_TYPE_DOUBLE:

View file

@ -949,6 +949,7 @@ static const int typecodes[] = {
DBUS_STRUCT_END_CHAR,
DBUS_DICT_ENTRY_BEGIN_CHAR,
DBUS_DICT_ENTRY_END_CHAR,
DBUS_TYPE_UNIX_FD,
255 /* random invalid typecode */
};

View file

@ -355,6 +355,7 @@ dbus_type_is_fixed (int typecode)
case DBUS_TYPE_INT64:
case DBUS_TYPE_UINT64:
case DBUS_TYPE_DOUBLE:
case DBUS_TYPE_UNIX_FD:
return TRUE;
default:
return FALSE;