All about programming in GNU/LINUX

PROGRAM TO GET THE COMPLETE INFORMATION OF THE USER USING “getpwuid” system call in gnu/LINUX

/*DOWNLOAD LINK OF THE FILE:http://www.slideshare.net/hackintoshrao/usrinfogetpwuid*/
/*HACKINTOSH RAO \m/ , codes for GNU/LINUX
  PROGRAM TO GET THE COMPLETE INFORMATION OF THE USER USING “getpwuid” system call in gnu/LINUX
  SYSImageTEM CALLS USED: 1) struct passwd *getpwuid(int uid);
  DESCRIPTION: “getpwuid” system call takes uid of the a user as parameter and then fills in the entries of the built in structure
              ‘passwd'( check out the header pwd.h under /usr/include to get the details of the passwd structure) and returns a
               pointer to it .Using the pointer the members of the structure are accessed to get the user info
                     2)uid_t/int getuid()
  DESCRIPTION:’getuid’ system call returns UID of a user who runs the executable of the code*/
#include<pwd.h> //header for getpwuid system call
#include<unistd.h>//header for getuid system call
#include<stdlib.h>
int main()
{
    struct passwd *usrinfo;
    usrinfo=getpwuid(getuid());
    printf(“\nUser name: %s”,usrinfo->pw_name);
    printf(“\n\nUserID:%d”,usrinfo->pw_uid);
    printf(“\n\nEncrypted password of the user:%s”,usrinfo->pw_passwd);
    printf(“\n\nGroup ID:%d”,usrinfo->pw_gid);
    printf(“\n\nReal name:%s”,usrinfo->pw_gecos);
    printf(“\n\nHOME DIRECTORY OF THE USER:%s”,usrinfo->pw_dir);
    printf(“\n\nDefault login shell:%s\n\n\n\n”,usrinfo->pw_shell);

    return 0;

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s