Monday, March 11, 2013

Format Pen Drive (PD) or USB Drive on Ubuntu from Terminal

To format a Pend drive from terminal use following steps:
1. First of all connect your pen drive to computer and type the below command for know the name of your  USB drive.

$ dmseg  | tail

It will generate output as follows:


[20940.808432]  sdb: sdb1
[20940.811241] sd 7:0:0:0: [sdb] Attached SCSI removable disk

2. Now unmount your pen drive using the following command:

$ sudo umount /dev/sdb1

3. Then enter the following command to format your pen drive with FAT32 partition.

$ sudo mkfs.vfat -n 'Ubuntu' -I /dev/sdb1





Tuesday, February 5, 2013

Ubuntu 12.04 fresh installation failed to install GRUB

Ubuntu 12.04 LTS fresh installation even though completed successfully it might fail to install grub correctly on system.  In such a situation to install grub you can follow following steps using LiveCD or bootable installation disk.

Boot from LiveCD, open terminal and run following commands to note down drive and partition number on which Ubuntu is installed.

$sudo fdisk -l
$sudo blkid   #it gives more information on partition and file system type

Now mount hard disk partition on which Ubuntu is installed.
$sudo  mount  /dev/saXY   /mnt     
Where X is drive letter such as a,b,c,, etc. and
Y is partition number such as 1, 5, 6, 8, etc,

For example:
  sudo mount /dev/sda8 /mnt

Now install grub loader.
$sudo  grub-install  --boot-directory=/mnt/boot    /dev/sdX   
For example:
  sudo grub-install --boot-rectory=/mnt/boot /dev/sda

--boot-directory is folder in which GRUB is located. It is normally /boot. Note that in above command we only provided sdX as input. We didn't use Y i.e. partition number.

Tuesday, December 11, 2012

Being prompted for Password for '(null)' GNOME keyring

You can commit your project using subversion as follows:
svn commit -m “Your comment message goes here ”  - - username <yourusername>
Then the following prompt should be displayed to you for committing your project successfully…
Password for ‘<yourusername>’:
For this password, you should provide your <yourusername> password assigned to you while hosting your project.
First time commit to your project using svn commit will work properly.
However for subsequent commit to your project, you can get the prompt like...

Password for ‘(null)’ GNOME keyring:
The reason for above error message  is multiple keyrings are present on a users system. All users will have a default keyring, and another which is only stored in memory. For each commit, gnome-keyring stores the user details in another keyring. 
To disable keyring, open the config file in the subversion from the home folder as follows:
patilkr@patilkr-desktop:~$ cd .subversion/
patilkr@patilkr-desktop:~$ ls
auth  config  README.txt  servers
Open the ‘config’ file with any text editor,
patilkr@patilkr-desktop:~/.subversion$ gedit config
Inside the text file, look for the line ‘password-stores = no’ under ‘[auth]‘ section and uncomment it & remove the value ‘no’ for it to look like ‘password-stores = ‘. 
Then, save and close config file.
Finally, open another file named ‘servers’ in any text editor,
patilkr@patilkr-desktop:~/.subversion$ gedit servers
Inside the text file, look for the line ‘store-passwords = no’ under ‘[global]‘ section and just uncomment it. 
Then, save and close ‘servers’ file.

Wednesday, September 19, 2012

User Specified Content Security Policy


Content Security Policy is a declarative policy that restricts what content can load on a page.  Its primary purpose is to mitigate Cross-Site Scripting vulnerabilities.  The core issue exploited by Cross-Site Scripting (XSS) attacks is the lack of knowledge in web browsers to distinguish between content that’s intended to be part of web application, and content that’s been maliciously injected into web application.
To address this problem, CSP defines the Content-Security-Policy HTTP header that allows web application developers to create a whitelist of sources of trusted content, and instruct the client browsers to only execute or render resources from those sources.  However, it is often difficult for developers to write a comprehensive Content Security Policy for their website.  They may worry about breaking their page by blocking unanticipated but necessary content.  They may not be able to easily change the CSP header for their site, which makes it challenging for them to experiment with policies until they find one that best protects their page without breaking site functionality.
UserCSP changes this!  A developer can now view the current policy applied to their site and create their own custom policy.  They can choose to apply their custom policy on the site, or even combine their policy with the website’s existing policy.  When combining policies, they have an option to choose from the strictest subset of the two, or the most lax subset.  They can locally test their site with the custom policy applied and tweak the policy until they have one that works.
The coolest feature of UserCSP is the Infer-CSP tab.  This feature can help a developer derive a usable and secure policy for their site.  By looking at the content the website loads, the add-on determines the strictest set of CSP rules it can apply to the site without breaking the current page.  The inferred policy is provided in the proper syntax for the CSP Header, so all a developer needs to do is start serving this policy for their site via the CSP header.
Please visit Tanvi's Blog on Mozilla for more information. 

Monday, August 27, 2012

Configure NFS on Ubuntu

Network File System (NFS) is useful to share space on other computers.

In this scenario we are going to configure NFS server on 10.1.1.15 host and NFS client on 10.1.1.17 machine.

1. Prerequisites
    Install nfs-common package on both NFS client and NFS server using following command.

     $ sudo apt-get install nfs-common

Additionally we need to install extra package on NFS server (10.1.1.15)

    $ sudo apt-get install nfs-kernel-server

This package is the actual NFS daemon listenning on both UDP and TCP 2049 ports. And portmap should be waiting for instructions on a port 111.

2. Create NFS Share on NFS Server (10.1.1.15)
Create a directory to share on NFS server(10.1.1.15).

Run following command on NFS server.

   $ mkdir /home/kailas

3. Apply Access Control Rules

In our scenario we want only 10.1.1.17 to access the nfs share.

Therefore, open /etc/exports file in any text editor (such as vi, gedit, or emacs) on NFS server (10.1.1.15).

Add following line in (/etc/exports) file.

A. Read/Write Permissions

    /home/kailas/     10.1.1.17(rw,sync)

Above line specifies that export /home/kailas directory for host with IP 10.1.1.17 with read, write permissions, synchronized mode.


B. Only Read Permissions

If you don't want to give write permission and only want to give read permission to client (10.1.1.17) then instead of above line use following line.

    /home/kailas/     10.1.1.17(ro,sync)

C. Read/Write + Root privileges

  /home/kailas/    10.1.1.17(rw,sync,no_root_squash)

Above line in "/etc/exports" file will export /home/kailas directory for host with an IP address 10.1.1.17 with read, write permissions, synchronized mode and the remote root user will be treated as a root and will be able to change any file and directory.

D. Read/Write Privilege to all computers on network

 /home/kailas/     *(rw,sync)

Above line indicates, export /home/kailas directory for any host with read, write permissions and synchronized mode.


E. Read Privilege to All computers on network

   /home/kailas/     *(ro,sync)

Above line indicates, export /home/kailas directory for any host with read only permissions and synchronized mode.


3. Restart NFS daemon

Use following command on Ubuntu to restart NFS service.

$ sudo /etc/init.d/nfs-kernel-server restart 

Note: After any modification you will made  in "/etc/exports" file please restart NFS service to reflect your changes. 


4. Mount NFS directory on client (10.1.1.17) machine

NFS client needs portmap service, simply install nfs-comman package on client (10.1.1.17)

   $ sudo apt-get install nfs-common


Make sure portmap service is running:
  $ sudo service portmap status

Sample outputs:
  portmap start/running, process 4193

If not just start it:
    $ sudo service portmap start

Create a mount directory on Client (10.1.1.17)
  $ sudo mkdir /nfs

$ sudo  mount  10.1.1.15:/home/kailas   /nfs/

To see the content of the directory use following command.
 $ ls /nfs


5. Configure automount

To make this completely transparent to end users, you can automount the NFS file system every time a user boots a Linux system. Simply edit "/etc/fstab" to mount system automatically during a system boot. You can use your favorite editor and create new line like this within /etc/fstab:

10.1.1.15:/home/kailas   /nfs/  nfs  defaults  0  0


 6. Appendix

If above steps doesn't work then please try to stop iptables or configure iptable rules to allow nfs communication.

# service iptables stop








Friday, April 27, 2012

IRC command help

The goal of this post is to play with some IRC commands.

To Register your nickname:
/msg nickserv register [password] [your@email.address.com]
You should substitute an actual password for [password] and actual email address for [your@email.address.com].  You don't need the "["brackets"]".

To identify yourself to IRC nickserv:
/msg nickserv identify [password]
You should substitute an actual password for [password].

To change your password:
/msg nickserv set password [YourNewPassword]

To enforce users to identify your nickname with password to protect from identity theft:
/msg nickserv set enforce on

To remove nickname currently in use:
If somehow you close your IRC but didn't get a chance to disconnect from server then server believes you are still online and you cannot use it until server recognizes it. Use following command to resolve this problem.
/nickserv ghost [nickname] [password]
For example, if your nickname is "abc123" and password is "xyz123", then command to use is as follows:

/nickserv ghost abc123 xyz123








Monday, March 26, 2012

Unable to ping Guest VM in VirtualBox

Suppose you have installed guest OS (such as Windows, Ubuntu, etc) in VirtualBox and want to ping it from host OS then you might not be able to ping it,  if Network adapter is configured as NAT mode adapter in VirtualBox for the VM.

To solve this problem. First shutdown your gust VM. Second, change the Guest VM's network adapter settings of "Attached to" from "NAT" to "Bridged Adapter".  Also change "Name" to "vmnet1" or  any other similar name.

The cause of this problem is, in NAT mode the IP headers of any packets that are going out the guest VM are re-written to match the hosts network settings. But VirtualBox does not do any kind of reverse NAT, not even for packets originating from the host machine.  It only does it for established connections.

Hope this helps!


Monday, November 14, 2011

Email Address verification using Perl script

Checking correctness of one email address is easy and can be done manually, however, if you want to validate a bunch of email addresses then automated script plays a very handy role. 
I would like to thank my colleague and friend "Sai Sathyanarayam" for giving me this script. I think this might be useful for others therefore, I am posting it here. 

# email.pl file
#open "email.txt" file from current directory, 
# email.txt file contains email addresses separated by , (comma) and each address is on new line
open(FILE,"email.txt");
while($line = <FILE> ) {
 
   chomp($line);
    if($line =~ /,/) { $line = $`; }else { print $line." is invalid\n";}
    if ($line =~ /^(\w|\-|\_|\.)+\@((\w|\-|\_)+\.)+[a-zA-Z]{2,}$/)
   {
       print "$line is valid\n"; 
   }
   else {
     print "$line is invalid\n";
   }
}

Sample email.txt file is as follows:
xyz@abc.com,
pqr@mnr.ac.in,

To perform validation test run following command:
$ perl email.pl


Friday, August 26, 2011

JaegerMonkey Architecture

JaegerMonkey is a JavaScript engine used in Firefox 4.0 and later versions. The SpiderMonkey JavaScript engine was used by Firefox for version 3.0 or earlier. TraceMonkey is a tracing engine which is an improvement to SpiderMonkey. Trace Monkey was used in Firefox 3.5 and above versions.  Before we will look into architecture of JaegerMonkey, lets first have a glance at TraceMonkey JavaScript engine who is a predecessor of JaegerMonkey.

TraceMonkey Overview
TraceMonkey uses a trace monitor called jstracer. The jstracer monitors a script as interpreted by SpiderMonkey. Whenever jstracer sees a code that would benefit from the native compilation, it activates it recorder. The recorder records the execution of the IR and creates NanoJIT Low Level Intermediate Representation, which is then compiled into native code. NanoJIT produces optimized code. More information on TraceMonkey and its architecture diagram is available  here.

JaegerMonkey Architecture
JaegerMonkey used in Fireox 4.0 and above version is Just-in-Time (JIT) JavaScript execution engine.  JaegerMonkey JIT engine produces native code for JavaScripts. Usually JIT engines take an intermediate representation (IR) from a compiler and produce native (machine) code and execute it on the fly.  Therefore, JIT engines do not parse the code or check its syntax, or create intermediate representation (IR) of code.
Hence, JavaScript engine in Mozilla Firefox we divide into two parts: front-end and back-end. The front-end is responsible to parse the script, check its syntax and generate intermediate representation (IR) of script required for native code generation.  The back-end is responsible for generating native code and memory management.

In Mozilla Firefox front-end is SpiderMonkey which parses script syntax and generates an intermediate representation (IR) of the script. In SpiderMonkey intermediate representation of script is bytecode of the script.  This generated bytecode is then fed to JaegerMonkey JIT engine to be compiled into machine code. JaegerMonkey is a method-base JIT JavaScript engine which compiles script into non-optimized machine code.  JaegerMoneky uses Nitro (borrowed from the WebKit project) as its back-end assembler.  
Nitro does memory management and code generation in JaegerMonkey.

Nitro contains two parts assembler and memory unit. Assembler handles the code assembly and memory unit handles allocation and deallocation of memory for native code. The bulk of the bytecode to native code translation is performed in the mjit::compiler class and it can be found in js/src/methodjit/Compiler.cpp.  This compiler class translates SpiderMonkey bytecode instructions to their native code block equivalents using the AssemblerBuffer and LinkBuffer helper classes.

JaegerMonkey uses inline cache to improve the performance. Inline cache is used to perform faster object type lookups.  JavaScript supports dynamic typing during runtime. To support this feature, in SpiderMonkey JSOP_GETPROP bytecode is responsible to return the value of a specific property by looking up its type first. SpiderMonkey uses property cache which stores the Shape of existing objects.  Shape is a structure in SpiderMonkey that defines how the object can be accessed.

Inline Caching for good locality
When JIT compiles a property access bytecode, emitted machine code look like as follows:


type                     <- load addressof(object) + offsetof(JSObject, type)
shapeIsKnown    <- type equals IMPOSSIBLE_TYPE
None                   <- goto slowLookupCode if shapeIsKnown is False
property              <- load addressof(object) + IMPOSSIBLE_SLOT

JagerMonkey uses self modifying code to inline cache the Shape of the object. Self modifying code is a code that modifies code that currently exists in memory.  When first time JaegerMonkey performs a property access on object its shape is unknown therefore shapeIsKnow will be false.  Hence slowLookupCode will be executed.  After slowLookupCode resolves the property it fills the appropriate value for IMPOSSIBLE_TYPE and IMPOSSIBLE_SLOT.  Hence, next time when this piece of code is executed, if the type of object is not change then shapeIsKnown return true and there is no need to go into slowLookupCode.  This technique of modifying JIT-compiled code to reflect a probable value is called as inline caching: inline, as in "in the emitted code";  caching, as in "cache a probable value".

However, JavaScript supports dynamic typing. This is handles by polymorphic inline caching (PIC).  Lets consider an example of PIC code:

var vals = {1, "hello", [1, 2, 3]};
for (var i in vals) {
   document.write(vals[i].toString());
}

In above code vals array contains different data types such as a Number, a String and a array. For each object in the array, the interpreter has to perform an expressive type lookup and determine the correct toString method to call.  JaegerMonkey uses PIC slots to colve this problem, that is make a chain of cache entries. It creates several blocks of native code that perform property lookups for types the object has already been seen as. It the first type does not match, then a branch is taken to the next code block to perform a lookup. If type is match then it performs a fast slot lookup.  According to our example, first time it recognizes Number object and fills cache entry for it. Second time its a String. So a new piece of code memory is created for type String and modify the jump of first lookup (that is, Number type mismatch in our example) to go to this newly created piece of code memory instead of slowLookupCode.  and so on.

References:

Friday, April 1, 2011

How to Merge Multiple PDF files into single PDF file on Ubuntu


Multiple PDF files can be merged into single PDF using two different ways: ghostscript or pdftk

A. Use Ghostscript to merge PDF files
Steps:
1. Install two pacakeges GhostScript and PDFtk tools.
 $ sudo apt-get install gs pdftk

2. Use following command to combine multiple files into single PDF file. The output file name is "singleCombinedPdfFile.pdf". The input file names are all files in the current directory, bcoz we used "*.pdf".

$ gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=singleCombinedPdfFile.pdf -dBATCH *.pdf

If you want to join PDF files in specific order then you can also use file names.
$ gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=singleCombinedPdfFile.pdf -dBATCH 1.pdf 2.pdf 3.pdf

B. Use pdftk (PDF toolkit) to merge multiple PDF files into Single PDF file
1.  To merge PDF files by using names of the source PDF files:
$ pdftk one.pdf  two.pdf  three.pdf  cat  output  123-combined.pdf

2. To merge PDF files using wildcard when number of files are large and its not feasible to input filenames of all files:
pdftk *.pdf cat output combined.pdf


3. Select specific pages from Multiple PDFs and create new PDF document:
$ pdftk A=one.pdf B=two.pdf cat A1-7 B1-5 A8 output combined.pdf