Of Pseudo-Seculars and xenophobes…

The below rant contains some very strong words and is not for the faint hearted! Lets start by clearing the definitions of certain words that I am going to use in my article.

– Xenophobe: Xenophobia is a dislike or fear of people from other countries or of that which is perceived to be foreign or strange (http://en.wikipedia.org/wiki/Xenophobia). Xenophobes are the people suffering from Xenophobia.

– Pseudo-Seculars: Pseudo-secularism is the state of implicit non-secular trends in the face of pledged secularism (http://en.wikipedia.org/wiki/Pseudo-secularism). Pseudo-seculars are the people who either implicitly or explicitly support pseudo-secularism.

– Secularism: Secularism is the principle of separation of government institutions, and the persons mandated to represent the State, from religious institutions and religious dignitaries (http://en.wikipedia.org/wiki/Secularism).

Now with the above three words clear and out of our way, I will start on how pseudo-seculars turn into xenophobes and how xenophobes reinforce pseudo-seculars. India is a rich culture, not just the indigenous type but the one which has assimilated a mix of other cultures, customs and people as and when it got a chance to do so. If you are an acute reader of history, it is quite easy to understand how India survived and is surviving against the onslaught of invasions, be it economic, social or cultural. But after the Indian Independence, a new age of Nehruvian teaching has threatened to destabilize and destroy the assimilation achieved over the past thousands of years. The new age teaching of denouncing indigenous culture (read Hindu customs and traditions) even while explicitly encouraging foreign cultures and traditions and create an environment of distrust against native Indians is quite striking!

An environment is created where talking about Hinduism/Hindu values is considered alien, an attack on secularism, out of fashion and can frame one as a fundamentalist. At the same time, talking about other cultures and values, showing support for such cultures even when no one knows shit about them and denigrating Hindu values and customs is encouraged and is seen as a sign of progressive thinking! The environment in turn creates xenophobes who are afraid of their own values and culture, find them to be foreign and strange and strive in the pool of pseudo-secular values. These xenophobes are the reinforcements for the brains which have developed in a social degrading, self-injuring and poisonous environment which finally attains the goals of inferiority complex in a manner such that every indigenous person has 2 faces: 1. A private face where he follows his faith, culture and customs and loves all and 2. A public face where he publicly distances himself from the very things he is doing privately.

The worst part is that such a public face also looses all moral values such as empathy, love, non-violence, equality, forbearance, etc. The person instead turns into a mechanical zombie whose only job is to disgrace and distance himself from his own self and show utter humility to violent, rejective and immoral behavior in the name of human rights and/or secularism giving birth to pseudo-secularism. Such a person will accept when a Muslim says he is a Muslim, when a Christian says that he is Christian, but when a Hindu asserts his Hinduism, suddenly such a pseudo-secular person becomes quite hostile.

And I personally have experienced it at many places. Not to go through all such incidents, I will just write about an incident that happened yesterday (11th Feb 2013). Besides my job, I am also involved with Indians in Malmö and helping out the IAIM organization. ISKCON in Malmö is organizing Rath Yatra every year as a part of Festival of India celebrations in Scandinavia. My humble request was to send out an email to all Indian members to spread the information of the Rath Yatra and where/when it was happening. Instantly I received a lot of opposition from people who were following the same faith as mine! In other words, the pseudo-seculars and xenophobes made a hue and cry about it. One person went up to the option of saying that Eid and Christmas should also be celebrated if we want to send out such information! Now that is what I call height of xenophobia.

But not all is lost. I have my utmost respect to the one and only truly secular person in the whole forum yesterday who (in-spite of following a different faith) understood the value of Indian-ness and India and its socio-cultural diversity. I do applause and respect you for that my dear friend. And hopefully we together can bring an end to the xenophobes and pseudo-seculars and bring/pass-on the true Indian values across the globe.

End to my rant. Hare Krishna, Jai Sri Krishna…

Gain local root access on an encrypted HDD (FDE) in Linux

Disclaimer: The following information is to be used for educational purposes only. I am not responsible if you do something weird with your encrypted drive and it fails to boot! And doing this stuff on other’s computers (i.e. computers, HDD, etc. which are not owned by you) might land you into legal troubles and no pointing fingers to me.

Now with all that bla bla out of the way, we can start with the real meat. Running Linux on your local machine is fun. Running Linux on a machine connected to the network is more fun (and not funnier!). And getting Linux installed on your work machine and doing everything with it (and not looking back to WinBlows anymore) is much more fun (and not funniest!). Anyways, after having such loads of fun, of course we run into people known as system admins. And these people are real bottlenecks for productivity. If you are a sysadmin reading this, then yes it is you who is hampering productivity and utility on our Linux systems because of your stupid decisions and mis-configurations.

Anyways, now, if you have a laptop running Linux, why in the name of "<insert whoever you love/hate>" will you not get root privileges on the local machine? I mean you are the owner of the system and you don’t want to call support (read sysadmins) for every little thing that you need to do! In my case, my local installation had a Thunderbird version 3.xx something. And the latest was 16.xx. I asked the sysadmins to update my Thunderbird and the usual answer was that they would look into the possibility. Of course the possibility probability is always 0.01. So the next best thing is to do it yourself but then of course you are not allowed to do that because of the restrictive access rights. And it seriously destroys my productivity working with older versions and trying to solve bugs which are already solved in newer versions.

And for the sysadmins, what better way to defer people from rooting then by encrypting the whole hard drive! Any noob can be stopped from doing such devious acts right. Well, wrong! Now, I am not exactly a noob but I do not consider myself a guru as well. So below is how you get root access on your encrypted HDD. Now with my rant out of the way, we start with the real thing.

Follow the procedure below and ask questions in the comments if you have doubts. First of all, boot the machine through a live CD. I used the Ubuntu live CD but you can use anything. If the bios settings do not allow to boot from the CD, use another machine to boot into a Linux machine (on which you have root access or from which you can boot a live CD), remove the HDD from the current machine and attach it as a secondary HDD on the machine with root access. Now if you do a fdisk or use the partition viewer, you should basically see 2 partitions. One is an ext3/ext4 based partition which will contain a minimal kernel and secret keys for the Luks encrypted partition. This partition will be very small (close to 200MB). Another partition will be an unrecognized file system and it will be the big partition spanning the entire disk.

Now go to the command line and install lvm2. i.e. execute sudo apt-get install lvm2. In the ubuntu live CD, lvm2 is not a part of the default install. Hence you need to install it. On others, it might be included. Use the package manager as provided by your live CD to install lvm2. Don’t worry, all the changes are happening in RAM, so there is no way you will write to the encrypted HDD or mess with the partition schemes. Now you should run a command known as vgs. This command will read information about the volume groups and provide you with the needed information like volume group name (quite important to remember/write down). You should also run a sudo vgscan if needed which will scan the HDD for LVM encrypted volumes and rebuild the caches. Now run lvs to report the information about the logical volumes if needed (i.e. if vgscan does not show proper information). Also do a modprobe dm-mod if the device manager module is not loaded in the kernel. For the live CD I was using, I had to it. Now that you have got the group name, change the attributes of the volume to allow changes and modifications. Use the command: sudo vgchange -ay <volume group name>.

If you reached here, the rest is a piece of cake. Mount the volume now and make the changes. But before mounting, you need to decrypt it. Use the following command. Please make sure you are using the proper mount point (look into the kernel logs dmesg if you need information on what block device is the volume pointing to).

sudo cryptsetup luksOpen /dev/<sda1> <any_name_for_recognition>

It will now ask for the password. And of course you have one since you are able to login. If not, you will have to get the keys from the root volume. That is a thing for another article! Once you give the correct password, it will show something along the lines that the volume is decrypted successfully. Now it is just a matter of mounting the volume as a normal volume.

sudo mkdir /media/<mount_point>
sudo mount /dev/mapper/<any_name_for_recognition> /media/<mount_point>

Remember that in the above command, the decrypted volume is available at /dev/mapper. If you want to know why, google for LVM and full disk encryption using Luks. There are detailed explanations available on how Full Disk Encryption (FDE) works under Linux.

Okay, now you have achieved what you wanted to. The root account in most such cases is disabled. You can enable it and change the root password to anything you like. You can also add your normal account/user id to the local root group. That will give you local root access. Now all you need to do is flush the changes back to the encrypted HDD. For that, you unmount the device using sudo umount /media/<mount_point>. And then we close and lock the container. Use the command: sudo cryptsetup luksClose <any_name_for_recognition>.

Thats it, now shutdown the system and boot it normally. Enter your encryption password and go into the system. Open a terminal window and do su -l. It asks you for a password, enter the same one that you have given above while enabling/changing password for the root account. You should be in with root access to local system. This is much useful to fix your system instead of making calls to the admins/help and wait for them to fix stuff for you. You can also install printers and do everything that makes you more productive. On networked computers, usually the access is monitored using /etc/sudoers. It might happen that the file is being reset every now and then. So if you find a message that your normal user account cannot execute certain functions, make sure you log in as local root and change the sudoers file. Then it won’t cause any problems.

Last and not the least, if you don’t know what to do with root access, please don’t enable it. You can mess with your system. ENJOY and help people find peace and liberation!

Ubuntu 12.04 updates on an external HDD–Grub recovery fight

Okay, I know what you guys will tell me now. That there are tons of tutorials on the internet on various sites on how to install Ubuntu on an external HDD. The knowledge level will vary between using UNetBoot to burning a CD and booting from it. As with all my articles, I will write my experiences here so that I can refer to the same in future if needed and also spread the information on various aspects of upgrades of Ubuntu on external HDD. And by external HDD, I mean the external HDD with rotating platters. Not a huge USB stick or any other MMC but an external HDD.

Ubuntu as well know comes with Grub2 in its latest incarnation. And I don’t know if it is a problem with Ubuntu (I am pretty sure it would be) or with Grub but whatever external HDD you install to, the MBR of your primary disk will always be replaced with a Grub2. So before trying any heroics and to have a truly portable Linux installation, burn the Ubuntu ISO to either a CD/DVD or better still, use a USB stick and make it bootable using the many methods you read on the internet.

Once done, shutdown and disconnect your mail HDD. Now start with booting your computer and install Ubuntu as you normally do. During installation Ubuntu writes to the proper external HDD and also installs Grub2 on the HDD. In my case, the external HDD was mounted on /dev/sde (my PC has a list of attached USB drivers including MMC readers and stuff so I got the e number there). In any case, I reboot the PC and everything goes fine.

Now comes the time for an upgrade. Again at upgrade/update time, I recommend to remove the primary HDD and just do the boot from USB HDD and then upgrade/update. And you already know why. Because Ubuntu screws up here. Again, if you primary HDD is attached, it will write the Grub updates to that HDD. And the best part comes now. Even if your primary is not attached, it will in the Grub config try to mount /dev/sda for vmlinuz and initrd images!

Hola, I am not joking. Even though the drive GUID is used, Grub will have problems finding the kernel and initrd images after the update. While booting after update, you will instantly end up in Grub recovery. For someone inexperienced with Grub, the only option would be to use a liveCD to put the proper MBR back and fix the Grub config. But instead below, I will show you how you go about navigating yourselves to sanity.

So when you land up in Grub recovery, execute ls (i.e. ELL ESS not III ESS). You should see something like hd0, (hd0,msdos1) depending on the USB HDD and the number of partitions you have created while installing Ubuntu. To keep things simple, I had just asked Ubuntu to use the whole disk, so I got only those 2 partitions. Anyways, the first one is the disk which starts with 0 and the next one is the partition which starts with a 1. Yep, I know it is confusing but that is how it is.

Now type in find / and press tab. You should see your root FS and find the kernel and initrd images. So now all you need to do is point Grub to the proper files and off you go. For me the commands look like below:

set root=(hd0, msdos1)
linux /vmlinuz root=/dev/sde1
initrd /initrd.img
boot

In the above code segment, you can also use (hd0,msdos1)/vmlinuz instead of /vmlinuz and same with initrd.img. Also notice that in the second line, I have specified my root partition to mount at /dev/sde1 since my original installation was at /dev/sde. You can also check your boot logs by specifying a random entry like /dev/sda. The onscreen logs will show you a root mount error and show a list of possible devices. Now you select one more and proceed. Once that is done, Ubuntu should boot up. Now before doing anything, fire up terminal and issue a sudo update-grub that writes the proper stuff to your grub config. Pretty easy to keep handy when stuff goes wrong because of a small, simple update right?

If you want to read more look at the below links:

https://help.ubuntu.com/community/Grub2#Using%20CLI%20to%20Boot
http://ubuntuforums.org/showthread.php?t=1195275
http://askubuntu.com/questions/21342/how-can-i-load-ubuntu-when-all-i-have-is-grub

So, there you have it lads. Now enjoy your portable installation with any machine. Just take precaution while upgrading/updating.

VBA Script to Change IE Settings Quickly!

If you are a regular reader of my site, you will know the problems I had been facing with HTTP Authentication and related problems associated with it that I was facing. I solved it using a local forwarding proxy named Delegate. I also have put the script to get Delegate to work properly. All and more you can read in my previous articles. Everything is working fine. But at times, I need to change from my local proxy to the office proxy since some of the internal websites require the connections to be forwarded from the office proxy. So I had to go to IE settings and turn off local proxy and turn on office proxy and vice-versa. Now IE being the most optimal browser (sarcasm) and my disdain for clicking made me write the below script. All it does is change the IE settings like I intend to. But you as a vivid reader can do a lot more with IE/System settings as you would like to (you know what I mean!).

Check it out, extend it and ENJOY!


dim oShell, regValue

set oShell = Wscript.CreateObject("Wscript.Shell")
regValue = oShell.RegRead ("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable")

if regValue=1 then
	oShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 0, "REG_DWORD"
	oShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\AutoConfigURL", "http://myoffice-proxy.com/", "REG_SZ"
  msgbox "Local Proxy - OFF, Office Proxy - ON"
else
	oShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 1, "REG_DWORD"
  oShell.RegDelete "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\AutoConfigURL"  
  msgbox "Local Proxy - ON, Office Proxy - OFF"
end if

set oShell = nothing
set regValue = nothing

Programming Discipline!

I was reading the article “Destructors Considered Harmful” on DrDobbs by Andrew Koenig. Generally I agree with Andrew’s views on various programming topics but I thought I should just write down my thoughts on this particular article. I have a number of agreements and disagreements on certain points. One point that specifically sticks out especially with the new generation of dumb-down languages is that it looses the traditional power of kind of raw functionality that you can churn out from a piece of code. Of course we can all be happy with a walled garden approach if we are only implementing some business logic which does not need to actually utilize the full power of the underlying HW but instead rely on language/OS supported runtimes to do the required optimizations for them. But what happens when we start arguing against a programming concept/construct just because it requires some basic programming discipline and understanding of basic principles before one actually needs to start using it?

One such typical argumentation occurs with GoTo statements. And as mentioned in Dijkstra’s paper as well as that article, GoTo’s definitely create a branching pattern which will be hard to follow, and now comes the important part “If they are used haphazardly and just as a means of executing particular lines of code without taking into consideration what the state of the program might be!”. A structured language definitely has no place for GoTo. But what about assembly language? Just rejecting GoTo as a general programming construct is not a sensible way going forward. Instead, the programming discipline should be taught on how to understand the program state and use proper branching constructs. GoTo’s are essentially a boon when I am writing boot loaders or doing POST routine implementation. A failed device initialization or return code will not stop the POST from executing.

The article goes forward stating that GoTo affects our ability to think about programs! I really don’t agree there. Before I compile program or even before I add a variable, I follow certain strict rules. I will try to jot them down below which falls into the discipline category. If people follow that, everything will fall in order more or less.

Checklist for declaring/using variables:

– Why is the variable needed?

– What kind of variable is needed?

– Does it have to be on the stack or heap?

– What is the lifetime of the variable?

– What is the typical memory allocated on a particular architecture for that variable?

– Will that variable need more memory than it would be allocated?

– Is it necessary to consider endian-ness while evaluating the variable?

– What are the bounds for the data being help by variable?

– Does the variable need validation before evaluation?

– Is it an alias for holding other variables or memory addresses (in other words, is it a pointer)?

Once you answer the above questions, one very well understands why the variable is needed and how it should be used. Why am I talking about variables now? Because branching very much depends on the state of a variable or memory location (register, etc.). The author in the article also talks against pointers. Yes, pointers create problems when you don’t follow certain rules. I will try to put down my points using simple statements with the below C examples.

Prog1: Prog2:
#define CONST_SIZE 10
…
int n=5;
char ptr[CONST_SIZE];
…
while(n>0) {
… // Do some logic implementation here // …
n-=1;
}
…
#define CONST_SIZE 10
…
int n=5;
char *ptr = (char *) malloc(sizeof(char)*CONST_SIZE);
…
while(n>0) {
memset(ptr, 0, CONST_SIZE);
…// Do some logic implementation here // …
n-=1;
}
free(ptr);
ptr=null;

Most of the newbies that I see would use the programming construct on the left and not on the right. And believe me, even professionals do it simply because we don’t follow certain programming guidelines. Prog1 has advantages but is limiting in terms of scalability. Since the memory is allocated on stack, your code will simply be a bottleneck if you increase the CONST_SIZE. On the other hand, if this particular function is called multiple times or is recursive, it will lead to stack overflow and even end-up fragmenting the stack. Prog2 is much more dynamic and scalable. Increase in CONST_SIZE will not be an issue and it can even be passed as a dynamic parameter to a function in future versions if needed. The best part is that we reduce the stack usage and re-use the same memory locations during the whole run of the function.

Of course if some programmer ends up messing with ptr without storing the initial location in another variable, he will end up with the problems that Andrew is pointing to especially “pointer exceptions pointing to invalid memory locations”. But instead of saying pointers are bad, why not say that pointer manipulations are bad without storing the initial memory address location. All the reasons he has mentioned in the article happens just because a programmer is inefficient in his use of pointers.

The rest of the article than goes on comparing pointers to labels in GoTos. That I would say is absolute BS. First of all, labels in GoTo statements are “labels” or entry points to code fragments. i.e. they are addresses. Secondly, pointers are variables pointing to memory locations. i.e. they are not entry points to code fragments. Andrew philosophically tries to confuse basic constructs to prove his case.

A look at page 2 in the article, one immediately notices the fallacy of his arguments. Now he moves into C++ domains but let me try to prove why I disagree with him. Firstly he is not following the rules for using pointers. i.e. pointer validation before assignment is an important aspects. Most of the bugs arise because of no/improper pointer validation. Ownership of variable is an important aspect. Even in C++, the scope, extent and evaluation of the variable needs to be thought of. One important rule to remember is, “If your code is not owning the memory i.e. your variable has only been assigned the value and has not been passed the ownership, then you don’t own the memory!

The code that he has written will not even pass my basic code review test. In the constructor for ThingHandle, he is simply assigning the variable to the pointer tp. i.e. he is simply assigning the value but not passing the ownership. And in the destructor, he is assuming ownership of memory location and trying to free it. Of course it would fail but not because pointers are bad in nature or destructor are stupid, it is only because some guy didn’t follow the proper coding discipline. He writes that he is encapsulating “memory allocation” but in the code fragment he shows, he is not encapsulating “memory allocation”!

All the other statements after that falls down as a pack of cards. The errors he points out only happens because somebody has messed up with the concept of ownership and data encapsulation. And then he goes on to state the analogy behind GoTo and destructors! And I say again, labels have to be unique and pointers can point to the same memory location. So his last paragraph is nothing but pure BS. And on page 3, he advises to use shared_ptr which I agree we should but I don’t agree with the case that has been build up by Andrew to push for shared_ptr. I would have more approved the statements if he had made it WRT inheritance (especially multiple) and tried to base the facts on relationship between objects.

In any case, programming disciple is a must and people should be made about possible pitfalls of using certain programming constructs instead of just telling them that it is bad to use. Programming guidelines, checklist and deep knowledge of the language constructs as well as knowledge about how a compiler will work will not only help us get better code but will also help us write code with lesser bugs. I have seen many c#/java programmers who lack understanding of basic concepts simply because they are not present in the language and they haven’t been taught to deal with it. I personally feel that the rise in bloat is because of programmers not understanding a few simple and basic constructs.

In my next article, I will point out to some coding mistakes that I have seen in professional real-time code!