Wednesday, April 25, 2007

[Tip 0.3] ln: do you like it soft or hard?

ln is a linux command to create a symbolic link to a file. The link could be hard or soft.

Hard Link:
- create another file (or entry to directory file) that reference to the same inode number (or disk block/s).
- attributes/permissions are carried out when the file has been changed/removed
- apply for files only (not directory)
- can not span hard drives (ie. hard link in /dev/hda/ that points to a file from /dev/hdb)

Example:
How to create a hard link 'tlink' that points to test (must be file only, NOT directory):
rex@rexubuntu:~$ ln test tlink

How to create another hard link 'tlink'2 that points to test (must be file only, NOT directory):
rex@rexubuntu:~$ ln test tlink2

How to identify hard links? Issue the command below and check for the same inode numbers:
rex@rexubuntu:~$ ls -il
8437999 -rw-r--r-- 2 rex rex 0 2007-04-25 15:02 test
8437999 -rw-r--r-- 2 rex rex 0 2007-04-25 15:02 tlink
8437999 -rw-r--r-- 2 rex rex 0 2007-04-25 15:02 tlink2

Having the same inode numbers means that the files: test, tlink and tlink2 are three files pointing to the same inode/s or disk blocks. Just think of them as 2 copies of test.

Soft Link:
- analogous to Windows shortcut file. It contains the path of the target file, and when the target file has been removed/deleted, the soft link is broken.
- file that contains the path of another file

Example:
How to create a soft symbolic link named 'slink' that points to file 'test' (could be a file or directory):
rex@rexubuntu:~$ ln -s test slink
rex@rexubuntu:~$ ls -il
8438031 lrwxrwxrwx 1 rex rex 4 2007-04-25 15:18 slink -> test

Note: test file should be existing

How to display soft links? Symlinks end with @ when you use the command:
$ ls -F
slink@

or

$ ls -l
lrwxrwxrwx 1 rex rex 4 2007-04-25 15:18 slink -> test

What if..a malicious software (malware) creates multiple (random) hard links to itself to avoid being completely deleted from the system. How would you completely clean the infection? Ok, lets say you were able to spot the file and terminate the process and delete the file. Then the next morning, you see another instance/copy of the malware. You suspect that there could be more other copies of itself that are still lurking in your system. So in order to remove all the copied files of the malware in your system you gotta be able to find all of its copies. So the next question would be: how would you know all of its instances or copies when you got one of its hard links or copies manually?

Well, first lets define inode. inode is the data structure that stores information about a file in Unix file system. Its number uniquely identifies the file. Its a basic building block of the file. So a file must have atleast one inode that also contains info about the data, permission,etc of the file. A file contains the (a) data and (b) filename parts. The data part is associated with inode structure and the filename is associated to name of the file and the inode number.

How to identify all hard links pointing to the same inode? There's no single command that would do this. It requires a little scripting and filtering. So its your choice. But basically, you have to search from the root directory and checking their inode number with the inode you identified as your input. I've found a simple solution from googling and it worked:

find <location> -samefile foobar
where foobar is a found link(whether original or not) and <location> is where you want to search. (ie. / to get all of them).

Another approach is:

find <location> -inum nnnnnn
where nnnnnn is the inode number of the known file that you established with "ls -li".

How to remove a link:
$ rm <linkname>
Remember that in *NIX world, everything is a file or directory. So rm would work.


Friday, April 20, 2007

pcap owl unleashed!

coming very soon...abangan!
,_,
)v(
\_/
="=

Thursday, April 19, 2007

Linux here is everywhere

My company doesnt love Windows, or maybe they just love free software thats why they dont use Windows that much. Its evident with the desktop and application they're using. I think 90% are using non-windows systems here. Meaning time for me to learn and migrate to *nix desktop too! Its kind of hard for someone using the Windows systems for more than 6 years. Have to re-learn how to install, rebuild from source, vi/vim editor, setup/install/upgrade via command shell, remote access using ssh, forget about Visual Studio and use GEdit/KDevelop/etc instead, and many more things. Its cool, but it takes a little time..hehe!

But I wanna try Gentoo..of the most powerful and yet trickiest distros on earth!

Ubuntu 7.04 (Fiesty Fawn) released!

Yes, today is the scheduled released of the much awaited Fiesty Fawn!

More info below:

http://www.debianadmin.com/ubuntu-704-feisty-fawn-release-dates.html

http://distrowatch.com/?newsid=04178


Now, its time to update my Ubuntu 6.10 (Edgy Eft) to Fiesty Fawn!!
Note: Ubuntu requires an incremental upgrade. If you're using Ubuntu 5.10, upgrade to 6.10 first before you can go to 7.04.

But its as easy as running the System->Administration->Package Manager. It should prompt you to install any available updates including upgrades.


If not, you can manually click the Check update button to check and get the updates! If you click the Install Updates button, it first will install some application updates. Clicking the Upgrade button will start the upgrade process. Then the release note is displayed. Click Upgrade button and you're on your way to upgrade your Edgy to Fiesty.

You'll be asked for the password since its a system-wide change.

Then it will prepare the distribution upgrade before prompting to proceed the real upgrade.

Depends on your internet speed, the upgrade could take hours or even days to complete. After the upgrade you can check if it indeed has been upgraded. Some of ways to check your Ubuntu version are like:

cat /etc/issue

or

lsb_release -a


or

cat /etc/lsb_release

That's how you upgrade using the GUI. Smooth. :)

If you're a CLI guru, then you can upgade using apt-get command (not advisable). If you want some pain in the ass, try it the hard way, check how here or there .

So whats up with this upgrade foo??!

Shuttleworth said “the main themes for development in this release will be improvements to hardware support in the laptop, desktop and high-end server market, and an aggressive adoption of emerging desktop technologies.”Ubuntu’s Feisty release will put the spotlight on multimedia enablement and desktop effects. We expect this to be a very gratifying release for both users and developers”.

“Edgy has been a wild ride, with some remarkable achievements (nothing like re-inventing and substantially improving on init!). Feisty will be a little more focused on features that are very visible to end-users,”

Tip 0.2: /usr/include/net/bpf.h header doesnt exist

BPF (Berkeley Packet Filter) is not supported by default by non-BSD systems, (ie. Ubuntu and other Linux).
So whenever you'll code something (especially libpcap -based ones) on these platforms, all you can do is to install libpcap library because it has the compatible header file bpf.h. Just copy the pcap-bpf.h from libpcap and rename it as bpf.h , and your good to go:

It is useful when you get progy written from BSD systems that includes the header /usr/include/net/bpf.h file and build it in a non-BSD system that doesnt support bpf by default.

Solution:
1. Install the libpcap library
Download the latest libpcap from here and extract to your own folder.
Note: Read the INSTALL.txt for instruction:
a) ./configure
By default, there is no flex/bison installed, so use the Synaptic Manager (easier way) to get and install flex/bison. They're required in building the libpcap.

Or by using the apt-get:
sudo apt-get install flex
sudo apt-get install bison

b) make
c) make install

2. copy the file: cp /usr/include/pcap-bpf.h /usr/include/net/bpf.h
Change the path accordingly if needed.

3. you can now build your libpcap progy.

Note: If this is the first time you would compile/build libpcap or any C/C++ program in Ubuntu, you probably need to setup/install most of the needed stuff in development, like include files, compiler,etc. Heres how:

Install Linux source:
~$ sudo apt-get install linux-tree

Install Linux headers:
~$ sudo apt-get install linux-headers-'uname -r'

Install C/C++ builder:
~$ sudo apt-get install build-essential

Install Kernel source:
~$ sudo apt-get install linux-source

You can also install your favorite IDE, like GEdit,KDevelop, or the old school vi/vim.

Cheers!

Saturday, April 07, 2007

Canada - a new destination!

Im here at last! New page of another chapter in my life..Hopefully, I would like it here and stay for good. The place looks very nice and exciting.

Zandro and Gilou picked me up from the Vancouver airport going to Rodel's house at New Westminster, BC, where I would be staying temporarily. After unloading all my luggages, we headed to Thai's restaurant near the office place to lunch. Then, Gilou left us and I asked help from bud Zandro to pick some grocery enough for the weekend. Then I went home (Rodel's flat) and fixed my internet connection to check mails and contact my family and friends in the Philippines.
I've watched the LA Lakers and SuperSonics game at 7:30PM, while eating my left over from Thai's restaurant when my eyes started to fall. I even cant remember if I was able to finish the game lolz! So I went up, with my eyes about to give up, I rested my exhausted body and drained eyes.
I woke up around 3AM and felt a little bit hungry. My body clock is still adjusting, and I couldnt sleep after the snacks. So I just surfed the net and started blogging. Its now 6:30 AM and I want to go back to bed to rest again =) Bye for now and see you around!