From c690ee4351f99ed5e629ffcf5f4a2edcd418d103 Mon Sep 17 00:00:00 2001 From: Chengwei Yang Date: Thu, 6 Jun 2013 16:58:11 +0800 Subject: dbus-send: check usage a bit strictly This commit does several more strictly check for dbus-send as its usage suggested. * now --address is an invalid option but --address=, this just like the others, say --reply-timeout=, --dest=, --type= * --print-reply= only take an optional argument "=literal" * --print-reply= will cause error with missing MSEC and invalid MSEC will cause invalid value error * --dest= will cause error with missing a NAME and also call dbus_validate_bus_name to verify the NAME Signed-off-by: Chengwei Yang Bug: https://bugs.freedesktop.org/show_bug.cgi?id=65424 Reviewed-by: Simon McVittie --- tools/dbus-send.c | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) (limited to 'tools/dbus-send.c') diff --git a/tools/dbus-send.c b/tools/dbus-send.c index e403a587..ca5dd5c6 100644 --- a/tools/dbus-send.c +++ b/tools/dbus-send.c @@ -266,34 +266,52 @@ main (int argc, char *argv[]) type = DBUS_BUS_SESSION; session_or_system = TRUE; } - else if (strstr (arg, "--address") == arg) + else if (strstr (arg, "--address=") == arg) { - address = strchr (arg, '='); - - if (address == NULL) + if (*(strchr (arg, '=') + 1) == '\0') { fprintf (stderr, "\"--address=\" requires an ADDRESS\n"); usage (1); } - else - { - address = address + 1; - } + address = strchr (arg, '=') + 1; } else if (strncmp (arg, "--print-reply", 13) == 0) { print_reply = TRUE; message_type = DBUS_MESSAGE_TYPE_METHOD_CALL; - if (*(arg + 13) != '\0') + if (strcmp (arg + 13, "=literal") == 0) print_reply_literal = TRUE; + else if (*(arg + 13) != '\0') + { + fprintf (stderr, "invalid value (%s) of \"--print-reply\"\n", arg + 13); + usage (1); + } } else if (strstr (arg, "--reply-timeout=") == arg) { + if (*(strchr (arg, '=') + 1) == '\0') + { + fprintf (stderr, "\"--reply-timeout=\" requires an MSEC\n"); + usage (1); + } reply_timeout = strtol (strchr (arg, '=') + 1, NULL, 10); + if (reply_timeout <= 0) + { + fprintf (stderr, "invalid value (%s) of \"--reply-timeout\"\n", + strchr (arg, '=') + 1); + usage (1); + } } else if (strstr (arg, "--dest=") == arg) - dest = strchr (arg, '=') + 1; + { + if (*(strchr (arg, '=') + 1) == '\0') + { + fprintf (stderr, "\"--dest=\" requires an NAME\n"); + usage (1); + } + dest = strchr (arg, '=') + 1; + } else if (strstr (arg, "--type=") == arg) type_str = strchr (arg, '=') + 1; else if (!strcmp(arg, "--help")) @@ -330,6 +348,12 @@ main (int argc, char *argv[]) dbus_error_init (&error); + if (!dbus_validate_bus_name (dest, &error)) + { + fprintf (stderr, "invalid value (%s) of \"--dest\"\n", dest); + usage (1); + } + if (address != NULL) { connection = dbus_connection_open (address, &error); -- cgit v1.2.1 From dd2ca80e3fb0413090136443aa79fe1dba4e6b19 Mon Sep 17 00:00:00 2001 From: Chengwei Yang Date: Wed, 19 Jun 2013 16:35:43 +0800 Subject: dbus-send: Fix fail to run without "--dest" option Bug: https://bugs.freedesktop.org/show_bug.cgi?id=65923 Signed-off-by: Chengwei Yang Reviewed-by: Simon McVittie --- tools/dbus-send.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/dbus-send.c') diff --git a/tools/dbus-send.c b/tools/dbus-send.c index ca5dd5c6..2e37b089 100644 --- a/tools/dbus-send.c +++ b/tools/dbus-send.c @@ -348,7 +348,7 @@ main (int argc, char *argv[]) dbus_error_init (&error); - if (!dbus_validate_bus_name (dest, &error)) + if (dest && !dbus_validate_bus_name (dest, &error)) { fprintf (stderr, "invalid value (%s) of \"--dest\"\n", dest); usage (1); -- cgit v1.2.1 From 5b74af796c8f1d9f3f60594f22c6bfd4c097ad8b Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 8 Oct 2013 15:54:11 +0100 Subject: dbus-send: replace --address with --peer and --bus. --peer is a direct substitute for --address. With --bus dbus-send registers on bus given by ADDRESS, thus allowing messages to be sent to the bus. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=48816 [adjusted to apply to current master -smcv] Reviewed-by: Simon McVittie --- tools/dbus-send.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) (limited to 'tools/dbus-send.c') diff --git a/tools/dbus-send.c b/tools/dbus-send.c index 2e37b089..d3ff2589 100644 --- a/tools/dbus-send.c +++ b/tools/dbus-send.c @@ -51,7 +51,7 @@ static const char *appname; static void usage (int ecode) { - fprintf (stderr, "Usage: %s [--help] [--system | --session | --address=ADDRESS] [--dest=NAME] [--type=TYPE] [--print-reply[=literal]] [--reply-timeout=MSEC] [contents ...]\n", appname); + fprintf (stderr, "Usage: %s [--help] [--system | --session | --bus=ADDRESS | --peer=ADDRESS] [--dest=NAME] [--type=TYPE] [--print-reply[=literal]] [--reply-timeout=MSEC] [contents ...]\n", appname); exit (ecode); } @@ -241,6 +241,7 @@ main (int argc, char *argv[]) int message_type = DBUS_MESSAGE_TYPE_SIGNAL; const char *type_str = NULL; const char *address = NULL; + int is_bus = FALSE; int session_or_system = FALSE; appname = argv[0]; @@ -266,14 +267,28 @@ main (int argc, char *argv[]) type = DBUS_BUS_SESSION; session_or_system = TRUE; } - else if (strstr (arg, "--address=") == arg) + else if ((strstr (arg, "--bus=") == arg) || (strstr (arg, "--peer=") == arg) || (strstr (arg, "--address=") == arg)) { - if (*(strchr (arg, '=') + 1) == '\0') + if (arg[2] == 'b') /* bus */ { - fprintf (stderr, "\"--address=\" requires an ADDRESS\n"); - usage (1); + is_bus = TRUE; + } + else if (arg[2] == 'p') /* peer */ + { + is_bus = FALSE; + } + else /* address; keeping backwards compatibility */ + { + is_bus = FALSE; } + address = strchr (arg, '=') + 1; + + if (address[0] == '\0') + { + fprintf (stderr, "\"--peer=\" and \"--bus=\" require an ADDRESS\n"); + usage (1); + } } else if (strncmp (arg, "--print-reply", 13) == 0) { @@ -330,7 +345,7 @@ main (int argc, char *argv[]) if (session_or_system && (address != NULL)) { - fprintf (stderr, "\"--address\" may not be used with \"--system\" or \"--session\"\n"); + fprintf (stderr, "\"--peer\" and \"--bus\" may not be used with \"--system\" or \"--session\"\n"); usage (1); } @@ -372,6 +387,16 @@ main (int argc, char *argv[]) dbus_error_free (&error); exit (1); } + else if ((address != NULL) && is_bus) + { + if (!dbus_bus_register (connection, &error)) + { + fprintf (stderr, "Failed to register on connection to \"%s\" message bus: %s\n", + address, error.message); + dbus_error_free (&error); + exit (1); + } + } if (message_type == DBUS_MESSAGE_TYPE_METHOD_CALL) { -- cgit v1.2.1 From 39673b945ca809d24797d237d1e2abc6f59ebe77 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 9 Oct 2013 11:17:20 +0100 Subject: Revert "dbus-send: replace --address"... to fix attribution This reverts commit 5b74af796c8f1d9f3f60594f22c6bfd4c097ad8b. --- tools/dbus-send.c | 37 ++++++------------------------------- 1 file changed, 6 insertions(+), 31 deletions(-) (limited to 'tools/dbus-send.c') diff --git a/tools/dbus-send.c b/tools/dbus-send.c index d3ff2589..2e37b089 100644 --- a/tools/dbus-send.c +++ b/tools/dbus-send.c @@ -51,7 +51,7 @@ static const char *appname; static void usage (int ecode) { - fprintf (stderr, "Usage: %s [--help] [--system | --session | --bus=ADDRESS | --peer=ADDRESS] [--dest=NAME] [--type=TYPE] [--print-reply[=literal]] [--reply-timeout=MSEC] [contents ...]\n", appname); + fprintf (stderr, "Usage: %s [--help] [--system | --session | --address=ADDRESS] [--dest=NAME] [--type=TYPE] [--print-reply[=literal]] [--reply-timeout=MSEC] [contents ...]\n", appname); exit (ecode); } @@ -241,7 +241,6 @@ main (int argc, char *argv[]) int message_type = DBUS_MESSAGE_TYPE_SIGNAL; const char *type_str = NULL; const char *address = NULL; - int is_bus = FALSE; int session_or_system = FALSE; appname = argv[0]; @@ -267,28 +266,14 @@ main (int argc, char *argv[]) type = DBUS_BUS_SESSION; session_or_system = TRUE; } - else if ((strstr (arg, "--bus=") == arg) || (strstr (arg, "--peer=") == arg) || (strstr (arg, "--address=") == arg)) + else if (strstr (arg, "--address=") == arg) { - if (arg[2] == 'b') /* bus */ + if (*(strchr (arg, '=') + 1) == '\0') { - is_bus = TRUE; - } - else if (arg[2] == 'p') /* peer */ - { - is_bus = FALSE; - } - else /* address; keeping backwards compatibility */ - { - is_bus = FALSE; - } - - address = strchr (arg, '=') + 1; - - if (address[0] == '\0') - { - fprintf (stderr, "\"--peer=\" and \"--bus=\" require an ADDRESS\n"); + fprintf (stderr, "\"--address=\" requires an ADDRESS\n"); usage (1); } + address = strchr (arg, '=') + 1; } else if (strncmp (arg, "--print-reply", 13) == 0) { @@ -345,7 +330,7 @@ main (int argc, char *argv[]) if (session_or_system && (address != NULL)) { - fprintf (stderr, "\"--peer\" and \"--bus\" may not be used with \"--system\" or \"--session\"\n"); + fprintf (stderr, "\"--address\" may not be used with \"--system\" or \"--session\"\n"); usage (1); } @@ -387,16 +372,6 @@ main (int argc, char *argv[]) dbus_error_free (&error); exit (1); } - else if ((address != NULL) && is_bus) - { - if (!dbus_bus_register (connection, &error)) - { - fprintf (stderr, "Failed to register on connection to \"%s\" message bus: %s\n", - address, error.message); - dbus_error_free (&error); - exit (1); - } - } if (message_type == DBUS_MESSAGE_TYPE_METHOD_CALL) { -- cgit v1.2.1 From b994830c7f6e201e8e8c3e6d8eaeb67191b9338a Mon Sep 17 00:00:00 2001 From: Andrey Mazo Date: Tue, 8 Oct 2013 15:54:11 +0100 Subject: dbus-send: replace --address with --peer and --bus. --peer is a direct substitute for --address. With --bus dbus-send registers on bus given by ADDRESS, thus allowing messages to be sent to the bus. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=48816 [adjusted to apply to current master -smcv] Reviewed-by: Simon McVittie --- tools/dbus-send.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) (limited to 'tools/dbus-send.c') diff --git a/tools/dbus-send.c b/tools/dbus-send.c index 2e37b089..d3ff2589 100644 --- a/tools/dbus-send.c +++ b/tools/dbus-send.c @@ -51,7 +51,7 @@ static const char *appname; static void usage (int ecode) { - fprintf (stderr, "Usage: %s [--help] [--system | --session | --address=ADDRESS] [--dest=NAME] [--type=TYPE] [--print-reply[=literal]] [--reply-timeout=MSEC] [contents ...]\n", appname); + fprintf (stderr, "Usage: %s [--help] [--system | --session | --bus=ADDRESS | --peer=ADDRESS] [--dest=NAME] [--type=TYPE] [--print-reply[=literal]] [--reply-timeout=MSEC] [contents ...]\n", appname); exit (ecode); } @@ -241,6 +241,7 @@ main (int argc, char *argv[]) int message_type = DBUS_MESSAGE_TYPE_SIGNAL; const char *type_str = NULL; const char *address = NULL; + int is_bus = FALSE; int session_or_system = FALSE; appname = argv[0]; @@ -266,14 +267,28 @@ main (int argc, char *argv[]) type = DBUS_BUS_SESSION; session_or_system = TRUE; } - else if (strstr (arg, "--address=") == arg) + else if ((strstr (arg, "--bus=") == arg) || (strstr (arg, "--peer=") == arg) || (strstr (arg, "--address=") == arg)) { - if (*(strchr (arg, '=') + 1) == '\0') + if (arg[2] == 'b') /* bus */ { - fprintf (stderr, "\"--address=\" requires an ADDRESS\n"); - usage (1); + is_bus = TRUE; + } + else if (arg[2] == 'p') /* peer */ + { + is_bus = FALSE; + } + else /* address; keeping backwards compatibility */ + { + is_bus = FALSE; } + address = strchr (arg, '=') + 1; + + if (address[0] == '\0') + { + fprintf (stderr, "\"--peer=\" and \"--bus=\" require an ADDRESS\n"); + usage (1); + } } else if (strncmp (arg, "--print-reply", 13) == 0) { @@ -330,7 +345,7 @@ main (int argc, char *argv[]) if (session_or_system && (address != NULL)) { - fprintf (stderr, "\"--address\" may not be used with \"--system\" or \"--session\"\n"); + fprintf (stderr, "\"--peer\" and \"--bus\" may not be used with \"--system\" or \"--session\"\n"); usage (1); } @@ -372,6 +387,16 @@ main (int argc, char *argv[]) dbus_error_free (&error); exit (1); } + else if ((address != NULL) && is_bus) + { + if (!dbus_bus_register (connection, &error)) + { + fprintf (stderr, "Failed to register on connection to \"%s\" message bus: %s\n", + address, error.message); + dbus_error_free (&error); + exit (1); + } + } if (message_type == DBUS_MESSAGE_TYPE_METHOD_CALL) { -- cgit v1.2.1