From f5cdfb34cd4b92bc6475f6c61f2996ada3a2ad1f Mon Sep 17 00:00:00 2001 From: Jason Molenda Date: Thu, 6 Feb 2020 16:15:03 -0800 Subject: [PATCH] Detect attach fail in debugserver due to non-interactive debug session. --- lldb/tools/debugserver/source/RNBRemote.cpp | 36 +++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/lldb/tools/debugserver/source/RNBRemote.cpp b/lldb/tools/debugserver/source/RNBRemote.cpp index 1f11b2f..b2fe8a1 100644 --- a/lldb/tools/debugserver/source/RNBRemote.cpp +++ b/lldb/tools/debugserver/source/RNBRemote.cpp @@ -12,6 +12,8 @@ #include "RNBRemote.h" +#include +#include #include #include #include @@ -3723,6 +3725,19 @@ static bool process_is_already_being_debugged (nub_process_t pid) { return false; } +// Test if this current login session has a connection to the +// window server (if it does not have that access, it cannot ask +// for debug permission by popping up a dialog box and attach +// may fail outright). +static bool login_session_has_gui_access () { + auditinfo_addr_t info; + getaudit_addr(&info, sizeof(info)); + if (info.ai_flags & AU_SESSION_FLAG_HAS_GRAPHIC_ACCESS) + return true; + else + return false; +} + // Checking for // // { @@ -4013,12 +4028,23 @@ rnb_err_t RNBRemote::HandlePacket_v(const char *p) { return_message += cstring_to_asciihex_string(msg.c_str()); return SendPacket(return_message.c_str()); } - if (!developer_mode_enabled()) { - DNBLogError("Developer mode is not enabled"); + if (!login_session_has_gui_access() && !developer_mode_enabled()) { + DNBLogError("Developer mode is not enabled and this is a " + "non-interactive session"); + std::string return_message = "E96;"; + return_message += cstring_to_asciihex_string("developer mode is " + "not enabled on this machine " + "and this is a non-interactive " + "debug session."); + return SendPacket(return_message.c_str()); + } + if (!login_session_has_gui_access()) { + DNBLogError("This is a non-interactive session"); std::string return_message = "E96;"; - return_message += cstring_to_asciihex_string("developer mode is not " - "enabled on this machine. " - "sudo DevToolsSecurity --enable"); + return_message += cstring_to_asciihex_string("this is a " + "non-interactive debug session, " + "cannot get permission to debug " + "processes."); return SendPacket(return_message.c_str()); } if (attach_failed_due_to_sip (pid_attaching_to)) { -- 2.7.4