I need to run Z:/usr/bin/sudo init 0 within wine without changing sudo to a shellscript

Questions about Wine on Linux
Locked
fernandomngl
Level 1
Level 1
Posts: 6
Joined: Sat Jul 27, 2019 8:48 am

I need to run Z:/usr/bin/sudo init 0 within wine without changing sudo to a shellscript

Post by fernandomngl »

Hello,

I have one software which I cannot modify and it tries to execute Z:/usr/bin/sudo init 0 to poweroff from within Wine.

The solution I have found to make this working, seeming that Wine won't run elf binaries and would exec shell scripts, was to add user to sudoers permitting poweroff and reboot, move sudo to sudobkp, chmoding this and new sudo shellscript to 4755 and write sudo shellscript like that:

Code: Select all

#!/bin/sh
if [ "$1" = "init" ]
	then
		if [ "$2" = "0" ]
		then
			( sudo poweroff )
		
		elif [ "$2" = "6" ]
		then
			( sudo reboot )
		fi
else 
	( /usr/bin/sudobkp $@ )
fi
exit
Thing is sudo just got updated because of "Baron Samedit" and overwrites the shell script. I believe each time sudo updates it will break the script again.

Is there a cleaner way to do this? I tried taking advantage of precedence of $PATH and writing this script into /usr/local/sbin which comes first (Ubuntu 20.04), it worked from shell but from the software within Wine it doesn't work. I believe it always go executing Z:/usr/bin/sudo directly .

The best "clean" solution I have thought so far is to recreate symlinks to / somewhere with Z: letter mapped there, recreate symlinks from /usr/ after then from /usr/bin/ and changing just sudo not linked there. That really looks a lot of work which I don't know would break another thing (and probably those links would need to be recreated each time bin folder changes).

Do you know a better way to do this?

Thank you!
jkfloris
Level 12
Level 12
Posts: 3141
Joined: Thu Aug 14, 2014 10:10 am

Re: I need to run Z:/usr/bin/sudo init 0 within wine without changing sudo to a shellscript

Post by jkfloris »

I have one software which I cannot modify and it tries to execute Z:/usr/bin/sudo init 0 to poweroff from within Wine.
Do you 100% trust the maker of the software? I have never come across a Windows program that tries to shut down the computer via Wine.
Wine (if used correctly) cannot change system files, so restarting or shutting down shouldn't be necessary.
fernandomngl
Level 1
Level 1
Posts: 6
Joined: Sat Jul 27, 2019 8:48 am

Re: I need to run Z:/usr/bin/sudo init 0 within wine without changing sudo to a shellscript

Post by fernandomngl »

Yes, I trust the software.

To explain a little background on why I want to do it, the software is a point-of-sale software which runs at all times while computer is powered on. The operators can type numbers and hit some buttons in their limited keyboards which execute functions based on options at screen. They don't use mouse and force closing or shutting down would be bad for the software data/files.

Truth is, it's working years the way I said before but the point-of-sale developers don't help much as their focus isn't Linux.

To have a little more security I use Ubuntu Unattended Updates and let machines auto update by themselves, some more frequently to know what is gonna happen, and whenever I can I fix those problems and learn the best way I can to make those fixes easier and seamless.

Only problem is every now and then apt overwrites the sudo script with the correct sudo and I'm not sure if there is a better option for what I'm doing
jkfloris
Level 12
Level 12
Posts: 3141
Joined: Thu Aug 14, 2014 10:10 am

Re: I need to run Z:/usr/bin/sudo init 0 within wine without changing sudo to a shellscript

Post by jkfloris »

The fact that the software somehow detects that it is running under Wine is bad.
(https://wiki.winehq.org/Developer_FAQ#H ... ct_Wine.3F)

How does the software behave if you remove or modify the z: symlink in ~/.wine/dosdevices?
For example, does it work if you link z: to your user home directory and place your sudo wrapper script in ~/usr/bin/?
fernandomngl
Level 1
Level 1
Posts: 6
Joined: Sat Jul 27, 2019 8:48 am

Re: I need to run Z:/usr/bin/sudo init 0 within wine without changing sudo to a shellscript

Post by fernandomngl »

Yes, it works.

I think before executing Windows shutdown it executes Z:/usr/bin/sudo and it doesn't really detect it is running under Wine.

Not sure if symlinking Z: to another place is safe enough instead of '/' , all that I find is that it will probably break something, but after reboot everything is working and the link persists.

I will let it run for more time to see what happens
madewokherd
Level 4
Level 4
Posts: 144
Joined: Mon Jun 02, 2008 5:03 pm

Re: I need to run Z:/usr/bin/sudo init 0 within wine without changing sudo to a shellscript

Post by madewokherd »

As long as a drive mapping for '/' still exists it shouldn't break anything in Wine. Of course, if a Windows program makes assumptions about the contents of z:, those assumptions could be broken.
fernandomngl
Level 1
Level 1
Posts: 6
Joined: Sat Jul 27, 2019 8:48 am

Re: I need to run Z:/usr/bin/sudo init 0 within wine without changing sudo to a shellscript

Post by fernandomngl »

I think everything is working perfectly, I will map another letter to '/' as suggested to be safe too.

Thank you all!
Locked