summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2009-04-22 03:31:20 +0200
committerLennart Poettering <lennart@poettering.net>2009-05-20 01:36:44 +0200
commitba7daa606cf20ff3b5e992907f380a425feaef01 (patch)
tree540ece84c50a5b8724a7e38189f7ee1638cc06ae
parentfaac66e3ea52644a5efa2f69ea2f6825a15b31a6 (diff)
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.
-rw-r--r--dbus/dbus-marshal-basic.c9
-rw-r--r--dbus/dbus-marshal-byteswap.c5
-rw-r--r--dbus/dbus-marshal-header.c7
-rw-r--r--dbus/dbus-marshal-validate.c4
-rw-r--r--dbus/dbus-message-factory.c1
-rw-r--r--dbus/dbus-signature.c1
6 files changed, 25 insertions, 2 deletions
diff --git a/dbus/dbus-marshal-basic.c b/dbus/dbus-marshal-basic.c
index 38fbe2d6..d396b6db 100644
--- a/dbus/dbus-marshal-basic.c
+++ b/dbus/dbus-marshal-basic.c
@@ -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";
}
diff --git a/dbus/dbus-marshal-byteswap.c b/dbus/dbus-marshal-byteswap.c
index 6c9fff5d..5f0945b9 100644
--- a/dbus/dbus-marshal-byteswap.c
+++ b/dbus/dbus-marshal-byteswap.c
@@ -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;
diff --git a/dbus/dbus-marshal-header.c b/dbus/dbus-marshal-header.c
index 8aba6a94..50b5f73c 100644
--- a/dbus/dbus-marshal-header.c
+++ b/dbus/dbus-marshal-header.c
@@ -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;
diff --git a/dbus/dbus-marshal-validate.c b/dbus/dbus-marshal-validate.c
index 78d55941..fbfb1c31 100644
--- a/dbus/dbus-marshal-validate.c
+++ b/dbus/dbus-marshal-validate.c
@@ -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:
diff --git a/dbus/dbus-message-factory.c b/dbus/dbus-message-factory.c
index 8550ee86..bd86dab9 100644
--- a/dbus/dbus-message-factory.c
+++ b/dbus/dbus-message-factory.c
@@ -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 */
};
diff --git a/dbus/dbus-signature.c b/dbus/dbus-signature.c
index c7f8d0e3..b1e69315 100644
--- a/dbus/dbus-signature.c
+++ b/dbus/dbus-signature.c
@@ -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;