e system - spew out unique exit codes we can then show dialogs for

tell the user all the possible exit reason we know about for
enlightenment_system.
This commit is contained in:
Carsten Haitzler 2020-04-29 22:10:10 +01:00
parent a999bdcdf3
commit 2ae006cfbd
3 changed files with 123 additions and 29 deletions

View File

@ -24,20 +24,102 @@ static double _last_spawn = 0.0;
static int _respawn_count = 0; static int _respawn_count = 0;
static Eina_Bool static Eina_Bool
_cb_dialog_timer(void *data EINA_UNUSED) _cb_dialog_timer(void *data)
{ {
int exit_code = (int)(long)data;
_error_dialog_timer = NULL; _error_dialog_timer = NULL;
e_util_dialog_show(_("Error in Enlightenment System Service"),
_("Enlightenment cannot successfully start<br>" if (exit_code == 0) // can't even do ecore_exe_run...
"the enlightenment_system service.")); e_util_dialog_show(_("Error in Enlightenment System Service"),
_("Enlightenment cannot successfully start<br>"
"the enlightenment_system service<br>"
"because ecore_exe_run() failed."));
else if (exit_code == 31) // can't get passwd entry for user
e_util_dialog_show(_("Error in Enlightenment System Service"),
_("Enlightenment cannot successfully start<br>"
"the enlightenment_system service<br>"
"because your user has no passwd file entry."));
else if (exit_code == 32) // username is blank in passwd entry
e_util_dialog_show(_("Error in Enlightenment System Service"),
_("Enlightenment cannot successfully start<br>"
"the enlightenment_system service<br>"
"because your username is blank in the passwd file."));
else if (exit_code == 33) // can't alloc mem for username
e_util_dialog_show(_("Error in Enlightenment System Service"),
_("Enlightenment cannot successfully start<br>"
"the enlightenment_system service<br>"
"because it could not allocate memory."));
else if (exit_code == 34) // can't get group entry for user's group
e_util_dialog_show(_("Error in Enlightenment System Service"),
_("Enlightenment cannot successfully start<br>"
"the enlightenment_system service<br>"
"because it can't find your user group entry."));
else if (exit_code == 35) // group name is blank
e_util_dialog_show(_("Error in Enlightenment System Service"),
_("Enlightenment cannot successfully start<br>"
"the enlightenment_system service<br>"
"because your user group entry is blank."));
else if (exit_code == 36) // can't setuid to 0
e_util_dialog_show(_("Error in Enlightenment System Service"),
_("Enlightenment cannot successfully start<br>"
"the enlightenment_system service<br>"
"since it can't become root. Missing setuid bit?"));
else if (exit_code == 37) // can't setgid to 0
e_util_dialog_show(_("Error in Enlightenment System Service"),
_("Enlightenment cannot successfully start<br>"
"the enlightenment_system service<br>"
"since it can't become group root. Missing setuid bit?"));
else if (exit_code == 38) // can't get passwd entry for uid 0
e_util_dialog_show(_("Error in Enlightenment System Service"),
_("Enlightenment cannot successfully start<br>"
"the enlightenment_system service<br>"
"because the passwd file entry for root isn't found."));
else if (exit_code == 39) // root has no homedir
e_util_dialog_show(_("Error in Enlightenment System Service"),
_("Enlightenment cannot successfully start<br>"
"the enlightenment_system service<br>"
"because the root home directory is blank."));
else if (exit_code == 40) // root homedir is not a full path
e_util_dialog_show(_("Error in Enlightenment System Service"),
_("Enlightenment cannot successfully start<br>"
"the enlightenment_system service<br>"
"because the root home directory is not a full path."));
else if (exit_code == 41) // root homedir does not resolve to a path
e_util_dialog_show(_("Error in Enlightenment System Service"),
_("Enlightenment cannot successfully start<br>"
"the enlightenment_system service<br>"
"because the root home directory can't be found."));
else if (exit_code == 42) // can't change HOME to root homedir
e_util_dialog_show(_("Error in Enlightenment System Service"),
_("Enlightenment cannot successfully start<br>"
"the enlightenment_system service<br>"
"because it can't change the HOME environment."));
else if (exit_code == 43) // can't change dir to root homedir
e_util_dialog_show(_("Error in Enlightenment System Service"),
_("Enlightenment cannot successfully start<br>"
"the enlightenment_system service<br>"
"because it cannot change working directory to root's home."));
else if (exit_code == 46) // user denied to all subsystems
e_util_dialog_show(_("Error in Enlightenment System Service"),
_("Enlightenment cannot successfully start<br>"
"the enlightenment_system service<br>"
"because your user is denied access to all services.<br>"
"Please see /etc/enlightenment/system.conf."));
else
e_util_dialog_show(_("Error in Enlightenment System Service"),
_("Enlightenment cannot successfully start<br>"
"the enlightenment_system service for<br>"
"some unknown reason."));
return EINA_FALSE; return EINA_FALSE;
} }
static void static void
_system_spawn_error(void) _system_spawn_error(int exit_code)
{ {
if (_error_dialog_timer) ecore_timer_del(_error_dialog_timer); if (_error_dialog_timer) ecore_timer_del(_error_dialog_timer);
_error_dialog_timer = ecore_timer_add(5.0, _cb_dialog_timer, NULL); _error_dialog_timer = ecore_timer_add(5.0, _cb_dialog_timer,
(void *)(long)exit_code);
} }
static void static void
@ -54,7 +136,7 @@ _system_spawn(void)
_system_exe = ecore_exe_pipe_run _system_exe = ecore_exe_pipe_run
(buf, ECORE_EXE_NOT_LEADER | ECORE_EXE_TERM_WITH_PARENT | (buf, ECORE_EXE_NOT_LEADER | ECORE_EXE_TERM_WITH_PARENT |
ECORE_EXE_PIPE_READ | ECORE_EXE_PIPE_WRITE, NULL); ECORE_EXE_PIPE_READ | ECORE_EXE_PIPE_WRITE, NULL);
if (!_system_exe) _system_spawn_error(); if (!_system_exe) _system_spawn_error(0);
} }
static Eina_Bool static Eina_Bool
@ -131,12 +213,24 @@ _cb_exe_del(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *event)
Ecore_Exe_Event_Del *ev = event; Ecore_Exe_Event_Del *ev = event;
if (ev->exe != _system_exe) return ECORE_CALLBACK_PASS_ON; if (ev->exe != _system_exe) return ECORE_CALLBACK_PASS_ON;
if ((ev->exit_code == 3) || (ev->exit_code == 5) || if ((ev->exit_code == 31) || // can't get passwd entry for user
(ev->exit_code == 7) || (ev->exit_code == 9) || (ev->exit_code == 32) || // username is blank in passwd entry
(ev->exit_code == 11)) (ev->exit_code == 33) || // can't alloc mem for username
(ev->exit_code == 34) || // can't get group entry for user's group
(ev->exit_code == 35) || // group name is blank
(ev->exit_code == 36) || // can't setuid to 0
(ev->exit_code == 37) || // can't setgid to 0
(ev->exit_code == 38) || // can't get passwd entry for uid 0
(ev->exit_code == 39) || // root has no homedir
(ev->exit_code == 40) || // root homedir is not a full path
(ev->exit_code == 41) || // root homedir does not resolve to a path
(ev->exit_code == 42) || // can't change HOME to root homedir
(ev->exit_code == 43) || // can't change dir to root homedir
(ev->exit_code == 46) // user denied to all subsystems
)
{ {
// didn't run because it literally refused.... // didn't run because it literally refused....
_system_spawn_error(); _system_spawn_error(ev->exit_code);
} }
else else
{ {

View File

@ -5,12 +5,12 @@
#define E_UTILS_H #define E_UTILS_H
#define e_util_dialog_show(title, args...) \ #define e_util_dialog_show(title, args...) \
{ \ do { \
char __tmpbuf[4096]; \ char __tmpbuf[4096]; \
\ \
snprintf(__tmpbuf, sizeof(__tmpbuf), ##args); \ snprintf(__tmpbuf, sizeof(__tmpbuf), ##args); \
e_util_dialog_internal(title, __tmpbuf); \ e_util_dialog_internal(title, __tmpbuf); \
} } while (0)
E_API void e_util_wakeup(void); E_API void e_util_wakeup(void);
E_API void e_util_env_set(const char *var, const char *val); E_API void e_util_env_set(const char *var, const char *val);

View File

@ -128,86 +128,86 @@ setuid_setup(void)
if (!pwent) if (!pwent)
{ {
ERR("Unable to obtain passwd entry for calling user\n"); ERR("Unable to obtain passwd entry for calling user\n");
exit(1); exit(31);
} }
if (!pwent->pw_name) if (!pwent->pw_name)
{ {
ERR("Blank username for user\n"); ERR("Blank username for user\n");
exit(1); exit(32);
} }
user_name = strdup(pwent->pw_name); user_name = strdup(pwent->pw_name);
if (!user_name) if (!user_name)
{ {
ERR("Unable to allocate memory for username\n"); ERR("Unable to allocate memory for username\n");
exit(1); exit(33);
} }
grent = getgrgid(gid); grent = getgrgid(gid);
if (!grent) if (!grent)
{ {
ERR("Unable to obtain group entry for calling group\n"); ERR("Unable to obtain group entry for calling group\n");
exit(1); exit(34);
} }
if (!grent->gr_name) if (!grent->gr_name)
{ {
ERR("Blank groupname for group\n"); ERR("Blank groupname for group\n");
exit(1); exit(35);
} }
group_name = strdup(grent->gr_name); group_name = strdup(grent->gr_name);
if (!group_name) if (!group_name)
{ {
ERR("Unable to allocate memory for groupname\n"); ERR("Unable to allocate memory for groupname\n");
exit(1); exit(36);
} }
if (setuid(0) != 0) if (setuid(0) != 0)
{ {
ERR("Unable to assume root user privileges\n"); ERR("Unable to assume root user privileges\n");
exit(5); exit(37);
} }
if (setgid(0) != 0) if (setgid(0) != 0)
{ {
ERR("Unable to assume root group privileges\n"); ERR("Unable to assume root group privileges\n");
exit(7); exit(38);
} }
pwent = getpwuid(getuid()); pwent = getpwuid(getuid());
if (!pwent) if (!pwent)
{ {
ERR("Unable to obtain passwd entry\n"); ERR("Unable to obtain passwd entry\n");
exit(1); exit(39);
} }
if (!pwent->pw_dir) if (!pwent->pw_dir)
{ {
ERR("No home dir for root\n"); ERR("No home dir for root\n");
exit(1); exit(40);
} }
if (strlen(pwent->pw_dir) > (sizeof(buf) - 8)) if (strlen(pwent->pw_dir) > (sizeof(buf) - 8))
{ {
ERR("Root homedir too long\n"); ERR("Root homedir too long\n");
exit(1); exit(41);
} }
if (pwent->pw_dir[0] != '/') if (pwent->pw_dir[0] != '/')
{ {
ERR("Root homedir %s is not a full path\n", pwent->pw_dir); ERR("Root homedir %s is not a full path\n", pwent->pw_dir);
exit(1); exit(42);
} }
if (!realpath(pwent->pw_dir, buf)) if (!realpath(pwent->pw_dir, buf))
{ {
ERR("Root homedir %s does not resolve\n", pwent->pw_dir); ERR("Root homedir %s does not resolve\n", pwent->pw_dir);
exit(1); exit(43);
} }
snprintf(buf, sizeof(buf), "HOME=%s", pwent->pw_dir); snprintf(buf, sizeof(buf), "HOME=%s", pwent->pw_dir);
if (putenv(buf) == -1) if (putenv(buf) == -1)
{ {
ERR("Unable to set $HOME environment\n"); ERR("Unable to set $HOME environment\n");
exit(1); exit(44);
} }
// change CWD to / to avoid path search dlopens finding libs in ./ // change CWD to / to avoid path search dlopens finding libs in ./
if (chdir("/") != 0) if (chdir("/") != 0)
{ {
ERR("Unable to change working dir to /\n"); ERR("Unable to change working dir to /\n");
exit(1); exit(45);
} }
// die with parent - special as this is setuid // die with parent - special as this is setuid
@ -425,7 +425,7 @@ main(int argc EINA_UNUSED, const char **argv EINA_UNUSED)
if (systems == 0) if (systems == 0)
{ {
ERR("Permission denied to use this tool\n"); ERR("Permission denied to use this tool\n");
exit(11); exit(46);
} }
ecore_idle_enterer_add(_cb_idle_enterer, NULL); ecore_idle_enterer_add(_cb_idle_enterer, NULL);