summaryrefslogtreecommitdiffstats
path: root/src/CLI
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-03-04 16:19:31 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-03-04 16:19:31 +0100
commitafb30fe1502e9c45b722da3b5c09e292d589aa7f (patch)
tree8f0429ccc50987a34e73899c0a724ff6e0205c93 /src/CLI
parent892b7fde75cafca50a18dcb8620ddc22b2e74688 (diff)
downloadabrt-afb30fe1502e9c45b722da3b5c09e292d589aa7f.tar.gz
abrt-afb30fe1502e9c45b722da3b5c09e292d589aa7f.tar.xz
abrt-afb30fe1502e9c45b722da3b5c09e292d589aa7f.zip
*: UID:UUID -> crash_id conversion
This fixes at least three instances where we did not check whether user is even allowed to report or delete a crash. Also fixes a few cases when root might inadvertently act on (e.g. delete) mote than one crash. Renamed FILENAME_UID to CD_UID - makes more sense this way. Added COL_INFORMALL and CD_INFORMALL. Nuked UID == -1 hacks. Renamed getReport() to start_job on Python side. Dropped a few unused parameters from server -> client dbus signals. Fixed CLI's way of reverencing crashes (see updated help text). Run-tested (GUI and CLI). Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> Acked-by: Nikola Pajkovsky <npajkovs@redhat.com>
Diffstat (limited to 'src/CLI')
-rw-r--r--src/CLI/CLI.cpp99
-rw-r--r--src/CLI/dbus.cpp8
-rw-r--r--src/CLI/dbus.h4
-rw-r--r--src/CLI/report.cpp6
4 files changed, 70 insertions, 47 deletions
diff --git a/src/CLI/CLI.cpp b/src/CLI/CLI.cpp
index ef88732f..fcf1f0cd 100644
--- a/src/CLI/CLI.cpp
+++ b/src/CLI/CLI.cpp
@@ -73,7 +73,7 @@ static void print_crash_infos(vector_map_crash_data_t& pCrashInfos, int pMode)
"\tCrash Time : %s\n"
"\tCrash Count: %s\n"),
ii,
- get_crash_data_item_content(info, FILENAME_UID).c_str(),
+ get_crash_data_item_content(info, CD_UID).c_str(),
get_crash_data_item_content(info, CD_UUID).c_str(),
get_crash_data_item_content(info, FILENAME_PACKAGE).c_str(),
get_crash_data_item_content(info, FILENAME_EXECUTABLE).c_str(),
@@ -84,6 +84,39 @@ static void print_crash_infos(vector_map_crash_data_t& pCrashInfos, int pMode)
}
}
+static char *guess_crash_id(const char *str)
+{
+ vector_map_crash_data_t ci = call_GetCrashInfos();
+ unsigned num_crashinfos = ci.size();
+ if (str[0] == '@') /* "--report @N" syntax */
+ {
+ unsigned position = xatoi_u(str + 1);
+ if (position >= num_crashinfos)
+ error_msg_and_die("There are only %u crash infos", num_crashinfos);
+ map_crash_data_t& info = ci[position];
+ return xasprintf("%s:%s",
+ get_crash_data_item_content(info, CD_UID).c_str(),
+ get_crash_data_item_content(info, CD_UUID).c_str()
+ );
+ }
+
+ unsigned len = strlen(str);
+ unsigned ii;
+ for (ii = 0; ii < num_crashinfos; ii++)
+ {
+ map_crash_data_t& info = ci[ii];
+ const char *this_uuid = get_crash_data_item_content(info, CD_UUID).c_str();
+ if (strncmp(str, this_uuid, len) == 0)
+ {
+ return xasprintf("%s:%s",
+ get_crash_data_item_content(info, CD_UID).c_str(),
+ this_uuid
+ );
+ }
+ }
+ error_msg_and_die("Crash '%s' not found", str);
+}
+
static const struct option longopts[] =
{
/* name, has_arg, flag, val */
@@ -120,15 +153,20 @@ static void usage(char *argv0)
"Actions:\n"
" --get-list print list of crashes which are not reported yet\n"
" --get-list-full print list of all crashes\n"
- " --report UUID create and send a report\n"
- " --report-always UUID create and send a report without asking\n"
- " --delete UUID remove crash\n"),
+ " --report CRASH_ID create and send a report\n"
+ " --report-always CRASH_ID create and send a report without asking\n"
+ " --delete CRASH_ID remove crash\n"
+ "CRASH_ID may be:\n"
+ " an UID:UUID pair,\n"
+ " an UUID prefix - the first crash with matching UUID will be acted upon\n"
+ " @N - N'th crash (as displayed by --get-list-full) will be acted upon\n"
+ ),
name, name);
}
int main(int argc, char** argv)
{
- const char* uuid = NULL;
+ const char* crash_id = NULL;
int op = -1;
setlocale(LC_ALL, "");
@@ -146,7 +184,7 @@ int main(int argc, char** argv)
case OPT_REPORT:
case OPT_REPORT_ALWAYS:
case OPT_DELETE:
- uuid = optarg;
+ crash_id = optarg;
/* fall through */
case OPT_GET_LIST:
case OPT_GET_LIST_FULL:
@@ -195,45 +233,30 @@ int main(int argc, char** argv)
}
case OPT_REPORT:
case OPT_REPORT_ALWAYS:
- exitcode = report(uuid, op == OPT_REPORT_ALWAYS);
- if (exitcode == -1) /* no such UUID */
+ exitcode = report(crash_id, op == OPT_REPORT_ALWAYS);
+ if (exitcode == -1) /* no such crash_id */
{
- vector_map_crash_data_t ci = call_GetCrashInfos();
- unsigned num_crashinfos = ci.size();
- if (uuid[0] == '@') /* "--report @N" syntax */
- {
- unsigned position = xatoi_u(uuid + 1);
- if (position >= num_crashinfos)
- error_msg_and_die("There are only %u crash infos", num_crashinfos);
- map_crash_data_t& info = ci[position];
- uuid = get_crash_data_item_content(info, CD_UUID).c_str();
- } else {
- unsigned uuid_len = strlen(uuid);
- unsigned ii;
- for (ii = 0; ii < num_crashinfos; ii++)
- {
- map_crash_data_t& info = ci[ii];
- const char *this_uuid = get_crash_data_item_content(info, CD_UUID).c_str();
- if (strncmp(uuid, this_uuid, uuid_len) == 0)
- {
- uuid = this_uuid;
- goto do_report;
- }
- }
- error_msg_and_die("Crash '%s' not found", uuid);
- }
- do_report:
- exitcode = report(uuid, op == OPT_REPORT_ALWAYS);
+ crash_id = guess_crash_id(crash_id);
+ exitcode = report(crash_id, op == OPT_REPORT_ALWAYS);
if (exitcode == -1)
- error_msg_and_die("Crash '%s' not found", uuid);
+ error_msg_and_die("Crash '%s' not found", crash_id);
}
break;
case OPT_DELETE:
{
- if (call_DeleteDebugDump(uuid) != 0)
+ exitcode = call_DeleteDebugDump(crash_id);
+ if (exitcode == ENOENT)
+ {
+ crash_id = guess_crash_id(crash_id);
+ exitcode = call_DeleteDebugDump(crash_id);
+ if (exitcode == ENOENT)
+ {
+ error_msg_and_die("Crash '%s' not found", crash_id);
+ }
+ }
+ if (exitcode != 0)
{
- log("Can't delete debug dump with UUID '%s'", uuid);
- exitcode = 1;
+ error_msg_and_die("Can't delete debug dump '%s'", crash_id);
}
break;
}
diff --git a/src/CLI/dbus.cpp b/src/CLI/dbus.cpp
index db45cd8b..b251c6f0 100644
--- a/src/CLI/dbus.cpp
+++ b/src/CLI/dbus.cpp
@@ -121,11 +121,11 @@ vector_map_crash_data_t call_GetCrashInfos()
return argout;
}
-map_crash_data_t call_CreateReport(const char* uuid)
+map_crash_data_t call_CreateReport(const char* crash_id)
{
DBusMessage* msg = new_call_msg(__func__ + 5);
dbus_message_append_args(msg,
- DBUS_TYPE_STRING, &uuid,
+ DBUS_TYPE_STRING, &crash_id,
DBUS_TYPE_INVALID);
DBusMessage *reply = send_get_reply_and_unref(msg);
@@ -166,11 +166,11 @@ report_status_t call_Report(const map_crash_data_t& report,
return result;
}
-int32_t call_DeleteDebugDump(const char* uuid)
+int32_t call_DeleteDebugDump(const char* crash_id)
{
DBusMessage* msg = new_call_msg(__func__ + 5);
dbus_message_append_args(msg,
- DBUS_TYPE_STRING, &uuid,
+ DBUS_TYPE_STRING, &crash_id,
DBUS_TYPE_INVALID);
DBusMessage *reply = send_get_reply_and_unref(msg);
diff --git a/src/CLI/dbus.h b/src/CLI/dbus.h
index c5eebbd7..be6b9615 100644
--- a/src/CLI/dbus.h
+++ b/src/CLI/dbus.h
@@ -24,7 +24,7 @@
extern DBusConnection* s_dbus_conn;
vector_map_crash_data_t call_GetCrashInfos();
-map_crash_data_t call_CreateReport(const char *uuid);
+map_crash_data_t call_CreateReport(const char *crash_id);
/** Sends report using enabled Reporter plugins.
* @param plugins
@@ -36,7 +36,7 @@ map_crash_data_t call_CreateReport(const char *uuid);
*/
report_status_t call_Report(const map_crash_data_t& report,
const map_map_string_t &plugins);
-int32_t call_DeleteDebugDump(const char* uuid);
+int32_t call_DeleteDebugDump(const char* crash_id);
/* Gets basic data about all installed plugins.
*/
diff --git a/src/CLI/report.cpp b/src/CLI/report.cpp
index 41ac6c2c..68df2d7d 100644
--- a/src/CLI/report.cpp
+++ b/src/CLI/report.cpp
@@ -523,11 +523,11 @@ static void get_reporter_plugin_settings(map_map_string_t &settings, bool ask_us
}
}
-/* Reports the crash with corresponding uuid over DBus. */
-int report(const char *uuid, bool always)
+/* Reports the crash with corresponding crash_id over DBus. */
+int report(const char *crash_id, bool always)
{
// Ask for an initial report.
- map_crash_data_t cr = call_CreateReport(uuid);
+ map_crash_data_t cr = call_CreateReport(crash_id);
if (cr.size() == 0)
{
return -1;