Skip to content

Commit

Permalink
Frontend.XF.GTK: exit with one when user is root
Browse files Browse the repository at this point in the history
An error occurs when geewallet is run with root permissions,
thus it’s necessary to restrict users from running it as root:

```
update.go:85: cannot change mount namespace according to change mount (/snap/gtk-common-themes/1534/share/gtk2/Materia-compact /snap/geewallet/x1/data-dir/themes/Materia-compact none bind,ro 0 0): cannot write to "/snap/gtk-common-themes/1534/share/gtk2/Materia-compact" because it would affect the host in "/snap"
update.go:85: cannot change mount namespace according to change mount (/snap/gtk-common-themes/1534/share/gtk2/Materia-dark-compact /snap/geewallet/x1/data-dir/themes/Materia-dark-compact none bind,ro 0 0): cannot write to "/snap/gtk-common-themes/1534/share/gtk2/Materia-dark-compact" because it would affect the host in "/snap"
update.go:85: cannot change mount namespace according to change mount (/snap/gtk-common-themes/1534/share/gtk2/Yaru-MATE-dark /snap/geewallet/x1/data-dir/themes/Yaru-MATE-dark none bind,ro 0 0): cannot use "/snap/gtk-common-themes/1534/share/gtk2/Yaru-MATE-dark" as bind-mount source: not a directory
update.go:85: cannot change mount namespace according to change mount (/snap/gtk-common-themes/1534/share/gtk2/Yaru-MATE-light /snap/geewallet/x1/data-dir/themes/Yaru-MATE-light none bind,ro 0 0): cannot use "/snap/gtk-common-themes/1534/share/gtk2/Yaru-MATE-light" as bind-mount source: not a directory
mkdir: cannot create directory ‘/run/user/0’: Permission denied
realpath: '': No such file or directory
realpath: '': No such file or directory
realpath: '': No such file or directory
realpath: '': No such file or directory
realpath: '': No such file or directory
realpath: '': No such file or directory
realpath: '': No such file or directory
realpath: '': No such file or directory
Authorization required, but no authorization protocol specified

(geewallet:5797): Gtk-WARNING **: 09:01:13.760: cannot open display: :0
```
  • Loading branch information
Mersho committed Feb 27, 2024
1 parent 3114fc3 commit 274f445
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/GWallet.Backend/Config.fs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ module Config =
let IsMacPlatform() =
RuntimeInformation.IsOSPlatform OSPlatform.OSX

let IsLinuxPlatform() =
RuntimeInformation.IsOSPlatform OSPlatform.Linux

let GetMonoVersion(): Option<Version> =
FSharpUtil.option {
// this gives None on MS.NET (e.g. UWP/WPF)
Expand Down
20 changes: 12 additions & 8 deletions src/GWallet.Frontend.XF.Gtk/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ module Main =
[<EntryPoint>]
[<STAThread>]
let main argv =
match argv.Length with
| 0 ->
NormalStartWithNoParameters()
| 1 when argv.[0] = "--version" ->
Console.WriteLine (SPrintF1 "geewallet v%s" VersionHelper.CURRENT_VERSION)
0
| _ ->
failwith "Arguments not recognized"
if GWallet.Backend.Config.IsLinuxPlatform() && Environment.UserName = "root" then
Console.Error.WriteLine "Running as root user is not supported"
1

This comment has been minimized.

Copy link
@knocte

knocte Feb 27, 2024

Member

@Mersho this diff is utterly unacceptable because you're changing lines that DONT need to be changed. Use Environment.Exit 1, and then you don't need the else block

else
match argv.Length with
| 0 ->
NormalStartWithNoParameters()
| 1 when argv.[0] = "--version" ->
Console.WriteLine (SPrintF1 "geewallet v%s" VersionHelper.CURRENT_VERSION)
0
| _ ->
failwith "Arguments not recognized"

0 comments on commit 274f445

Please sign in to comment.