Samstag, 23. Februar 2013

Editing the context menu

When you right-click onto your Linux desktop you get a context menu like this:


I took this screenshot using Knoppix 7.0. My goal for today is to configure this menu.First step is to open a console and call

pcmanfm --desktop-pref

and select Advanced -> "Show menus provided by window managers when desktop is clicked":



Now you will not see a desktop menu when you right-click onto your desktop. But we will change this now. First install the window manager openbox:

sudo apt-get update
sudo apt-get install openbox

And run it

openbox --replace

You find that the menu has changed. You want to know which configuration files are used to build this menu so you run

cd
strace -e open openbox --replace 2>strace.txt

Now looking at strace.txt I find a line

open("/etc/xdg/openbox/menu.xml", O_RDONLY|O_LARGEFILE) = 6

ok, so it seems like openbox is using /etc/xdg/openbox/menu.xml for its menu structure. And indeed, we find there exactly the entries we see in the context menu. Once I changed it and re-ran

openbox --replace

my dream-menu for right-clicks was there:


The interesting thing is that I had no idea how to call the file manager (for "open files") from the command line. So I clicked on it and used the command xprop to find out its program name. I found it is pcmanfm.

So here is my /etc/xdg/openbox/menu.xml:

<?xml version="1.0" encoding="UTF-8"?>

<openbox_menu xmlns="http://openbox.org/"

        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://openbox.org/
                file:///usr/share/openbox/menu.xsd">

<menu id="root-menu" label="Openbox 3">

  <item label="Open a console">
    <action name="Execute"><execute>x-terminal-emulator</execute></action>
  </item>
  <item label="Browse the web">
    <action name="Execute"><execute>x-www-browser</execute></action>
  </item>
  <item label="Open files">
    <action name="Execute"><execute>pcmanfm</execute></action>
  </item>
  <item label="Take a screenshot...">
    <action name="Execute"><execute>ksnapshot</execute></action>
  </item>
  <separator />
  <item label="Configure desktop...">
    <action name="Execute"><execute>pcmanfm --desktop-pref</execute></action>
  </item>
  <item label="Restart">
    <action name="Restart" />
  </item>
  <separator />
  <item label="Exit">
    <action name="Exit" />
  </item>
</menu>

</openbox_menu>


Samstag, 16. Februar 2013

4 ways to try Linux

So you want to try out Linux but you aren't really sure how to do it? I want to show you four ways:

Ditch Windows, install Linux

Take your computer, format C: and install Linux. Frankly, I don't see any advantage in doing this. You give up all the Windows-specific know-how you already have for something you don't know.

Dual-Boot Windows and Linux

Many distributions, e.g. Ubuntu and SUSE allow you to install them onto a separate partition. When starting your computer you can select if you want to work under Windows or under Linux. Even better, if you install Linux on a USB disk you can take this disk anywhere and boot any computer with it - provided the computer is modern enough to boot from USB.

Use a virtual machine

You don't have a spare computer around? Just install VirtualBox (available for Windows and Linux) and create a virtual machine on your computer. There you can install Linux and experiment without the danger to break anything out of your virtual machine.
VirtualBox hosting 4 virtual Linux machines
And the best thing is - you can run Windows and Linux simultaneously. You do not have to decide when booting which one you want to use. When both operating systems are running it is also easy to copy files between Linux and Windows. VirtualBox also allows you to access USB devices that are attached to the physical machine as if they were attached to the virtual machine.

Use a remote desktop over the internet

The easiest way to try Linux is via a Linux desktop on a remote computer via the network. Here it depends if you are behind a corporate firewall or not. If you are (or if you don't know) GuacaMole will work and give you a Linux desktop in a browser.
FireFox accessing a Linux desktop shared via GuacaMole

If you are directly in the public internet, you can also use NoMachine's NX. In both cases be aware - you will not be able to access your local hardware like USB sticks or hard drives. The easiest way to get access to such a shared Linux desktop is to rent a server and install the needed software.

Freitag, 1. Februar 2013

run vlc as root

The best video player in the world is VLC. But when I try to run it I get the following error message:

VLC is not supposed to be run as root. Sorry.
If you need to use real-time priorities and/or privileged TCP ports
you can use vlc-wrapper (make sure it is Set-UID root and
cannot be run by non-trusted users first).


That's nonsense to my opinion so I want to remove it. Re-compiling takes time and knowledge about video codex so I want a shorter way. Just editing the executable file /usr/bin/vlc will work:

cp /usr/bin/vlc /usr/bin/vlc-backup
needle=$(objdump -d /usr/bin/vlc | grep euid | tail -1 | awk '{print "\\x"$2"\\x"$3"\\x"$4"\\x"$5"\\x"$6;}')
sed -ir "s/$needle/\xb8\x01\x00\x00\x00/" /usr/bin/vlc

and it works, vlc runs as root now.

How did I do this

Glad you asked this question - it will take us through a journey of the gnu debugger, disassembling programs and editing hex files that is actually very interesting.

Let's look at the functions that are contained in vlc. Open a console and type:

# which vlc
/usr/bin/vlc
# gdb /usr/bin/vlc
[...]
(gdb) info functions
All defined functions:

Non-debugging symbols:
[...]
0x0000000000400f40  geteuid
[...]
 
Ok so there is a function geteuid to find out the effective User ID. Let's disassemble vlc to find out when this is called:

objdump -d -M intel /usr/bin/vlc
[...]
40118e:       e8 6d fe ff ff          call   401000 <geteuid@plt>
401193:       85 c0                   test   eax,eax
401195:       0f 84 20 05 00 00       je     4016bb <dlerror@plt+0x57b>
[...] 

Wow, in line 40118, the function geteuid is called. Obviously it sets the processor register eax to 0 if the user is root. Because in line 401193, eax is checked to be 0 or not. Line 401195 contains the command je, "jump if equal". So if eax is 0, the processor will continue at address
<dlerror@plt+0x57b>. There will be code to end the program I assume.
So let's replace line 401195 by some code that just does nothing. "Do nothing" in assembly is NOP, "no operation". In machine code it is 90h. That means if we replace the bytes in line 401195 by 90 90 90 90 90 90, it will no longer exit.

No problem, let's call this hex editor okteta using the command

okteta /usr/bin/vlc

and search for the bytes 0f8420:
The hex editor okteta showing /usr/bin/vlc
Now there is only one occurrence in the file. Replace it (and the following 3 bytes) by 90's:
Then click on File -> Save and the problem from the beginning will not bug you any longer.

See also

http://www.linuxintro.org/wiki/Run_vlc_as_root

Raspberry Pi, test my internet connection

Since start of Corona times, I use my internet at home also for work. So its reliability and performance has become crucial. Performance see...