Wednesday, August 20, 2014

crypt function in Linux

Here is a function provided to encrypt a given key with a provided salt. The signature of the function is as follows:
 
char *crypt(const char *key, const char *salt);

 
If a salt given has a format of "$.$...$..." i.e. normally of the hashed password stored in shadow file (look for my previous blogs on shadow file), then the function will interpret the salt and get the type of hash to be used. A hash type could be of MD5 ($1$), SHA256 ($5$), etc. This way one can hash a password provided by a user (the argument 'key') and match/authenticate with the one stored in the shadow file. This function is highly recommended not to be used for any other purpose except authentication. Readers are recommended to go through its manual page and understand its usage. 
 
Here are some references:
man 3 crypt

gnu_libc_crypt
man7_crypt

Saturday, August 16, 2014

Linux shadow and passwd files - an introduction

A user's credentials and password related information are maintained in shadow file in Linux. The file requires root permission to be read. It has the following construction:

username : hashed passwd with salt and type : last passwd change day : minimun days to change passwd : max passwd lifetime : warning period : grace period : account expire day

Days above are in refernce to last passwd change day (calculated from epoch, 01/01/1970) and max passwd lifetime. They can be changed as required. In grace period, a user is asked to changed the passwd as soon as s/he logs in whereas in warning period, which is calculated from max passwd lifetime, the user is just thrown a warning message saying when the passwd will expire. The account lock day is the day after which the user is not allowed to login. There are several utilities which can be used with appropriate options to manipulate these entries in shadow file.

A passwd file is a file which stores user information. It has the following construction:

username : user id : group id :full name : home dir : shell

The last field, shell, is the default shell given to the user after login and home dir is its home directory.

The above words are used so as to convey the information. More information comes in a follow-up blog with references. 


Functions to get and set shadow and passwd file values

An introduction was given about the shadow and passwd files in linux in my last post. Here are some of the functions with their signatures which are provided to get/set values from/to these files:

struct spwd *getspnam (const char *name);

Following is the structure which gets populated if the user is present:

 struct spwd {
     char *sp_namp;
     char *sp_pwdp;
     long sp_lstchg;
     long sp_min;
     long sp_max;
     long sp_warn;
     long sp_inact;
     long sp_expire;
     unsigned long sp_flag;
};

Following are the functions which may be used to get entries one by one:

void setspent (void);
struct spwd *getspent (void);
void endspent (void);

Following function deals with passwd file entries:

struct passwd *getpwnam (const char *name);

It returns following structure:
 struct passwd {
     char *pw_name;
     char *pw_passwd;
     uid_t pw_uid;
     gid_t pw_gid;
     char *gecos;
     char *pw_dir;
     char *pw_shell;
};

An exhaustive explanation and lists of functions, their return values, header files to include, etc may be found in their manual pages i.e. man 3 getspnam, man 3 getpwnam, etc and the above definitions of structures and functions signatures are taken from these manual pages itself.

Saturday, August 27, 2011

Working with form object in javascript

It took me three days to learn and come up with a solution of how to handle the event of updating a column based on any change in some other corresponding row with some operation being done.
For example,the following function takes the index 'k' of a text field in the first form in the document and handles two successively next text fields.It multiplies the integer entered in the text field at index 'k' with a float at index 'k+1' and writes in the text box at index 'k+2'.This can be done for any number of rows in the table provided the corresponding index is given.The function is as follows:

function total(k){
oForm = document.forms[0];
oText1 = oForm.elements[k];
oText2 = oForm.elements[k+1];
oForm.elements[k+2].value = parseInt(oText1.value) * parseFloat(oText2.value);
}

The radices may be checked according to use.
From html part,the above function can be called from the text box having index 'k'.I used 'onkeyup' to call this function with an index 'k' which had value according to the index of the text box.The reader may work on the probable index according to his/her use which may include the number of columns in the table.
Any other inputs from readers are welcome and appreciated.Thank you all for reading.

Summer school on security and privacy,2011

Many days have passed when I attended summer school on security and privacy conducted by Microsoft this year.But memories are still there based on which I am writing this blog.It has been a great learning experience where I got to listen to eminent speakers from different geographies in an environment of several budding researchers not only from India but also from abroad.I had a chance to talk to several scholars of masters and PhDs from different universities in India.All of them had a fire in them to do something under this umbrella.For the first time I came across the topic called "privacy" in so much of detail.Several topics in security and privacy were taken up which were more than sufficient to light up the same fire in me to go deep into this area.I must say that the researchers from Microsoft are very helpful and whatever I had questions about,were answered by them.I appreciate several activities like panel discussions,question-answers,group picture,etc which were taken up during the school.The readers are suggested to go through the website Summer school on security and privacy, 2011 to have a detailed information about the topics covered,the speakers and for future reference which may be useful for them to apply for the next summer school.At the end I would say that overall the summer school was very much useful for me to decide my career path and to have a knowledge of not only several topics but also what and how different researchers think and work.

Sunday, August 14, 2011

Last week experience

So now as I am sitting idle and looking back, I realize that everything was for a reason. Last week was a very learning experience for me when I was working in a team. I never came across learning anything that a manager does but it was the week when I learnt several activities that a program manager does. A very energetic man that I came to know even more was Peter. He has immense energy and working power. Kara, Lucas, Sayanta, Sayan and Jenn were my team members. I learnt various lessons from each one of my team members. Here is a guy named Adam who has the capability to accept even the failures. It was the time when he unknowingly taught me the art of acceptance. A very intelligent pretty girl I came across was Anna who, at least I would say, is by far the fastest note taker that I have seen. Everyone in the group has something to share.
One of the lessons that I got was that even if I had worked on similar projects earlier, I had to struggle hard to learn and then implement the technology I was new to, though the concept remained similar. Overall it was a great week for me for everything I learnt and experienced.
I don't know when and where I will have a chance to work with such a great team.

Wednesday, March 2, 2011

ns installation and configuration.

After a lot of hurdles finally it was possible for me to configure ns and I am now able to successfully run a script.

Following link provided me the necessary setup:

Steps that i followed were :

tar -xzf "package-name-of-ns-without-quotes"
cd "directory-name-of-ns-without-quotes"
./install

gedit ~/.bashrc (appended at the end of this file)

export PATH=$PATH:"path to the directory location of ns with the directory-name of the package without the quotes"/bin:"path to the directory location of ns with the directory-name of the package without the quotes"/tcl8.5.8/unix:"path to the directory location of ns with the directory-name of the package without the quotes"/tk8.5.8/unix

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"path to the directory location of ns with the directory-name of the package without the quotes"/otcl-1.14:"path to the directory location of ns with the directory-name of the package without the quotes"/lib

export TCL_LIBRARY=$TCL_LIBRARY:"path to the directory location of ns with the directory-name of the package without the quotes"/tcl8.5.8/library

and then

cd ns-2.35 (in the ns directory)
./validate (this will take about one hour, atleast it took on my system)

The reader may have to install some other packages like autoconf,automake,libxmu-dev, libxt-dev,libx11-dev,gcc/c++,x11proto-dev.

A tutorial that I followed:

Useful instructions for installing and configuring is also given at:

Tuesday, February 8, 2011

Adding repo in ubuntu

Found "https://help.ubuntu.com/community/Repositories/Ubuntu#Adding Repositories in Ubuntu" and "https://wiki.ubuntu.com/LucidLynx/ReleaseNotes#Sun Java moved to the Partner repository" very much helpful for adding repo and installing java.It solved many problems that i faced earlier.
For configuring the system,following command may help :
sudo update-alternatives --config java

Monday, July 26, 2010

College life and numbers

After a long time I am writing once again. I was thinking about how numbers are present in our everyday life.
So I thought of prime numbers first. It dates back to my first year in college(National Institute of Technology Durgapur). I came here on July 28,2007 with a view to getting a room in the first year hostel(Hall-9).Don't know why I went back to the hotel where I stayed. I came the very next day again and got the room 416.I shared the room with Vinay,Joy and Subhrajit.I quickly felt that how this number '416' is related with its own digit. '16' can be obtained from '4' as: 4^(6-4). First year was quite cool apart from the attendances which I had to make in my seniors' room.

One year passed and I qualified for studying in the second year. I made lots of friends.Seniors were very helpful. I got a room in 206 and later shifted to 202 in hall-2.Here also I began thinking on numbers.202/2=101. This number repeats any two digit number if multiplied. Number count is 3 in 101 and 3 is a prime number.Both 101 and 103(206/2) are also primes.I had a regular wwe kind of fight with my room mates Munna, Abhilash, Rahul, Sanjay. I passed second year also though not with very good marks.

Now was the turn for third year. I stayed in 328 in hall 1. I thought(which I do a lot) again and found out that cubing 2 will result in 8 and these were the only numbers in my room number.This was the year when I again started playing lots of chess.Though i qualified in my hostel's team and went one round forward after it by winning against mca(perhaps, I am not sure of their degree,they may be of mca) which lasted for about one and a half hours, I lost against M.Tech(may be mca, I don't know again about their degree) which lasted about an hour. This was the point when i got to learn some new techniques out of the matches i played.Now was the time when summers were coming and everyone was trying for an internships or projects.I had to stay in my college because i started doing a project in CMERI(nearby). Truly speaking I have never seen such a hot place like Durgapur. But now that time has also passed and I am now in my final year right now preparing for campuses. For quite some time I haven't played chess but I am sure to be in my top form soon. Let's see what happens to me this year. I am staying at the room (which everyone calls as 'deluxe') 201 in hall 5. I am still thinking on these numbers.Mail me if you find anything interesting.
Thanks to Ravi and Pranay who told me to write something and happy mathemagic to all...