[PATCH] Prevent unintentionally running as root

Dirk Hohndel dirk at hohndel.org
Fri Mar 25 07:50:43 PDT 2016


Why would we use the verbose option to allow running as root? That seems odd
to me. So someone testing a USB permission problem who runs as root to see
all warnings (and runs with -v) then doesn't get warned?

I think this needs a separate option, Robert.

/D

> On Mar 25, 2016, at 1:27 AM, Robert C. Helling > <helling at atdotde.de> wrote:
> 
> From: "Robert C. Helling" <helling at atdotde.de>
> 
> Some users try to run Subsurface as root for example to get around
> permission problems with dive computer devices. This is a bad idea
> since config files get touched as root and then cannot be read
> as normal user anymore.
> 
> This patch allows running as root only with verbose option on. We can
> assume if somebody manages to start subsurface as root this happens
> from the command line.
> 
> For some reason, I couldn't get translation working at this stage.
> 
> Signed-off-by: Robert C. Helling <helling at atdotde.de>
> ---
> subsurface-desktop-main.cpp | 6 ++++++
> 1 file changed, 6 insertions(+)
> 
> diff --git a/subsurface-desktop-main.cpp b/subsurface-desktop-main.cpp
> index 2b7bf89..d02e90a 100644
> --- a/subsurface-desktop-main.cpp
> +++ b/subsurface-desktop-main.cpp
> @@ -20,6 +20,7 @@
> #include <QApplication>
> #include <QLoggingCategory>
> #include <git2.h>
> +#include <unistd.h>
> 
> QTranslator *qtTranslator, *ssrfTranslator;
> 
> @@ -59,6 +60,11 @@ int main(int argc, char **argv)
> 			files.push_back(a);
> 		}
> 	}
> +	if ((getegid() == 0) && !verbose) {
> +		printf("You are running Subsurface as root. This is not recommended.\n");
> +		printf("If you insist to do so, run with option -v.\n");
> +		exit(0);
> +	}
> #if !LIBGIT2_VER_MAJOR && LIBGIT2_VER_MINOR < 22
> 	git_threads_init();
> #else
> -- 
> 2.5.4 (Apple Git-61)
> 
> _______________________________________________
> subsurface mailing list
> subsurface at subsurface-divelog.org
> http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface



More information about the subsurface mailing list