enabling xrdp on ubuntu 14.04

As the introduction of Unity Desktop Interface in Ubuntu, you need to tweak the configuration, i.e installing alternate desktop that will be used while remoting into your Ubuntu 14.04 machine.

sudo apt-get install xrdp
sudo apt-get update
sudo apt-get install xfce4
echo xfce4-session >~/.xsession
sudo service xrdp restart


CSS Div tag explained

=======================================<div id="myDIVtagID">hello world</div>
in CSS ->  #myDIVtagID { width:200px; background:#CCC; color:#000; font-size:90%; }
=======================================<div style="width:200px; background:#CCC; color:#000; font-size:90%;">hello world</div>
=======================================<div class="myDIVtagID">hello world</div>
in CSS ->  .myDIVtagID { width:200px; background:#CCC; color:#000; font-size:90%; }

Visual Leak Detector

Visual Leak Detector (VLD) is an open-source alternative to investigate these memory leaks. Using it is very simple and straightforward:

Download and install VLD. The installer will prompt about adding its bin path (C:\…\Visual Leak Detector\bin) to the PATH environment variable. Accept it or add it manually yourself. Either way, you will need to log out and log back in for the addition to the PATH to take effect. vld.dll and dbghelp.dll, from the bin directory need to be available on the system path.
Make sure the Visual C++ project is in Debug mode.
Add the VLD include path (C:\…\Visual Leak Detector\include) to the Include Directories of the project.
Add the VLD lib path (C:\…\Visual Leak Detector\lib) to the Additional Library Directories of the project.
Add #include <vld.h> to any of the C++ source files in the project. This header will bring in vld.lib during the linking stage.
Rebuild the project and execute the compiled program in Debug mode. On program exit, VLD will print out the memory leak information it detected in the Output window.
The memory leak information printed by VLD looks like this:

———- Block 1199 at 0x04BE1058: 136 bytes ———-
Call Stack:
d:\Foobar\FooLog.cpp (26): FooLog::getInstance
d:\Foobar\FooMain.cpp (75): FooMain::init
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (578): __tmainCRTStartup
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (403): WinMainCRTStartup
0x759A3677 (File and line number not available): BaseThreadInitThunk
0x770C9D42 (File and line number not available): RtlInitializeExceptionChain
0x770C9D15 (File and line number not available): RtlInitializeExceptionChain
9C 33 2D 6B 74 2A 2D 6B C8 11 BE 04 00 00 00 00 .3-kt*-k ……..
00 00 00 00 70 14 BB 6C 70 14 BB 6C 00 00 00 00 ….p..l p..l….
00 00 00 00 68 14 BB 6C 68 14 BB 6C 00 00 00 00 ….h..l h..l….
00 00 00 00 6C 14 BB 6C 6C 14 BB 6C 20 12 BE 04 ….l..l l..l….
00 00 00 00 CD 00 CD CD 00 00 00 00 01 CD CD CD …….. ……..
68 14 BB 6C 78 33 2D 6B 00 00 00 00 00 00 00 00 h..lx3-k ……..
00 00 00 00 01 02 00 00 06 00 00 00 00 00 00 00 …….. ……..
00 00 00 00 00 00 00 00 88 11 BE 04 5C 10 BE 04 …….. ….\…
00 00 00 00 20 CD CD CD …….. ……..
We can note the following information from this output:

The block allocation number output by Visual C++ leak detection and by VLD do not necessarily match.
The memory block address and size information of Visual C++ and VLD match. This confirms that this VLD information is about the same memory block as that reported by Visual C++. This is useful when the program has multiple memory leaks. The programmer can then match each of the Visual C++ memory leak to the corresponding VLD memory leak information.
VLD provides a lot of information: the entire call stack trace with function call names, source code filenames and line numbers. It also prints out a lot more data from the memory block.

Valgrind – Dynamic analysis tool

Installing Valgrind

You could install Valgrind with the package manager for your OS, but I want you to learn to install things from source. This involves the following process:

  • Download a source archive file to get the source.
  • Unpack the archive to extract the files onto your computer.
  • Run ./configure to setup build configurations.
  • Run make to make it build, just like you’ve been doing.
  • Run sudo make install to install it onto your computer.

Here’s a script of me doing this very process, which I want you to try to replicate:

# 1) Download it (use wget if you don't have curl)
curl -O http://valgrind.org/downloads/valgrind-3.6.1.tar.bz2

# use md5sum to make sure it matches the one on the site
md5sum valgrind-3.6.1.tar.bz2

# 2) Unpack it.
tar -xjvf valgrind-3.6.1.tar.bz2

# cd into the newly created directory
cd valgrind-3.6.1

# 3) configure it

# 4) make it

# 5) install it (need root)
sudo make install

Follow this, but obviously update it for new Valgrind versions. If it doesn’t build then try digging into why as well.

Using Valgrind

Using Valgrind is easy, you just run valgrind theprogram and it runs your program, then prints out all the errors your program made while it was running. In this exercise we’ll break down one of the error outputs and you can get an instant crash course in “Valgrind hell”. Then we’ll fix the program.

First, here’s a purposefully broken version of the ex3.c code for you to build, now called ex4.c. For practice, type it in again:

#include <stdio.h>

/* Warning: This program is wrong on purpose. */

int main()
    int age = 10;
    int height;

    printf("I am %d years old.\n");
    printf("I am %d inches tall.\n", height);

    return 0;

You’ll see it’s the same except I’ve made two classic mistakes:

  • I’ve failed to initialize the height variable.
  • I’ve forgot to give the first printf the age variable.

What You Should See

Now we will build this just like normal, but instead of running it directly, we’ll run it with Valgrind (see Source: “Building and running ex4.c with Valgrind”):

$ make ex4
cc -Wall -g    ex4.c   -o ex4
ex4.c: In function 'main':
ex4.c:10: warning: too few arguments for format
ex4.c:7: warning: unused variable 'age'
ex4.c:11: warning: 'height' is used uninitialized in this function
$ valgrind ./ex4
==3082== Memcheck, a memory error detector
==3082== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==3082== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info
==3082== Command: ./ex4
I am -16775432 years old.
==3082== Use of uninitialised value of size 8
==3082==    at 0x4E730EB: _itoa_word (_itoa.c:195)
==3082==    by 0x4E743D8: vfprintf (vfprintf.c:1613)
==3082==    by 0x4E7E6F9: printf (printf.c:35)
==3082==    by 0x40052B: main (ex4.c:11)
==3082== Conditional jump or move depends on uninitialised value(s)
==3082==    at 0x4E730F5: _itoa_word (_itoa.c:195)
==3082==    by 0x4E743D8: vfprintf (vfprintf.c:1613)
==3082==    by 0x4E7E6F9: printf (printf.c:35)
==3082==    by 0x40052B: main (ex4.c:11)
==3082== Conditional jump or move depends on uninitialised value(s)
==3082==    at 0x4E7633B: vfprintf (vfprintf.c:1613)
==3082==    by 0x4E7E6F9: printf (printf.c:35)
==3082==    by 0x40052B: main (ex4.c:11)
==3082== Conditional jump or move depends on uninitialised value(s)
==3082==    at 0x4E744C6: vfprintf (vfprintf.c:1613)
==3082==    by 0x4E7E6F9: printf (printf.c:35)
==3082==    by 0x40052B: main (ex4.c:11)
I am 0 inches tall.
==3082== HEAP SUMMARY:
==3082==     in use at exit: 0 bytes in 0 blocks
==3082==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==3082== All heap blocks were freed -- no leaks are possible
==3082== For counts of detected and suppressed errors, rerun with: -v
==3082== Use --track-origins=yes to see where uninitialised values come from
==3082== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 4 from 4)


If you run valgrind and it says something like by 0x4052112: (below main) (libc-start.c:226) instead of a line number in main.c then add run your valgrind command like this valgrind --track-origins=yes ./ex4 to make it work. For some reason the Debian or Ubuntu version of valgrind does this but not other versions.

This one is huge because Valgrind is telling you exactly where every problem in your program is. Starting at the top here’s what you’re reading, line by line (line numbers are on the left so you can follow):

Ubuntu & Root Password

This is the mystery for most users – you didn’t set a root password, so what is it? The root user (also known as superuser), is a user on Ubuntu Linux and Unix-like systems with full administrative privileges (full access). So using root account for daily work can be very dangerous and you may damage your working system.

Ubuntu and root account

By default root account is locked under Ubuntu Linux. Therefore, you cannot login as root or use ‘su -‘ command to become a superuser. To run all administrative command use sudo command. sudo allows a permitted user to execute a command as the superuser or another user. Ubuntu setup your default account (the one created during installation) to run all administrative commands.

For example create a new user called bar, you need to type sudo command as follows:
$ sudo adduser bar

When sudo asks for a password, you need to supply YOUR OWN password. In other words a root password is not needed. Here are few more examples.

Task: Start / stop / restart services stored in /etc/init.d/ directory

$ sudo /etc/init.d/ssh stop
$ sudo /etc/init.d/networking restart


Ubuntu 14.04: Add ‘Open As Root/Administrator’ to Context Menu

This simple tutorial will show you how to add ‘Open As Root’ or ‘Open As Administrator’ option to context menu so that you can easily edit / open file folders as super user privilege within Nautilus file browser.

Open as Administrator ubuntu 14.04

To get started:

1. Open Ubuntu Software Center. Search for and make sure the package gksu is installed. gksu allows graphical programs to ask a user’s password to run program as root / administrator.

gksu ubuntu 14.04

2. Open Nautilus file browser, press Ctrl+H to view hidden files & folders. Navigate to USER Home -> .local -> share -> nautilus -> scripts.

Create an empty document under this directory named ‘open-as-administrator’ or ‘open-as-root’

open as administtrator ubuntu 14.04

3. Edit and paste following lines into the file

# this code will determine exactly the path and the type of object,
# then it will decide use gedit or nautilus to open it by ROOT permission
# Determine the path
if [ -e -n $1 ]; then
base="`echo $NAUTILUS_SCRIPT_CURRENT_URI | cut -d'/' -f3- | sed 's/%20/ /g'`"
# Determine the type and run as ROOT
if [ -f "$obj" ]; then
gksu gedit "$obj"
elif [ -d "$obj" ]; then
gksu nautilus "$obj"

exit 0

4. Press Ctrl+Alt+T to open the terminal. When it opens, run the command below to make executable:

cd .local/share/nautilus/scripts/ && chmod 0755 open-as-administrator

5. Finally restart Nautilus via command nautilus -q, or just log out and back in.

courtesy – http://ubuntuhandbook.org/index.php/2014/04/ubuntu-14-04-add-open-as-rootadministrator-to-context-menu/

Installing TFTPD FTP server on Ubuntu Linux Distro

  1. tftpd is a server for the Trivial File Transfer Protocol. The TFTP protocol is extensively used to support remote booting of diskless devices or loading operating systems. Debian or Ubuntu can use any one of the following tftpd server:
    • atftpd – Advanced TFTP server.
    • tftpd – Trivial file transfer protocol server.
    • tftpd-hpa – HPA’s tftp server.
    • dnsmasq – Lightweight DNS, TFTP and DHCP server.
  2. Install following packages.
    sudo apt-get install xinetd tftpd tftp
  3. Create /etc/xinetd.d/tftp and put this entry
    service tftp
    protocol        = udp
    port            = 69
    socket_type     = dgram
    wait            = yes
    user            = nobody
    server          = /usr/sbin/in.tftpd
    server_args     = /tftpboot
    disable         = no
  4. Create a folder /tftpboot this should match whatever you gave in server_args. mostly it will be tftpboot
    sudo mkdir /tftpboot
    sudo chmod -R 777 /tftpboot
    sudo chown -R nobody /tftpboot
  5. Restart the xinetd service.
    sudo /etc/init.d/xinetd restart

    Now our tftp server is up and running.

Testing our tftp server

  1. Create a file named test with some content in /tftpboot path of the tftp serverObtain the ip address of the tftp server using ifconfig command
  2. Now in some other system follow the following steps.
    tftp> get test
    Sent 159 bytes in 0.0 seconds
    tftp> quit
    cat test