•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 397,698 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,500 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser:
This Program gives the UserDetails of the logged in User.
a) The RealName
b) Login Name ( Why do we need this?)
c) Home Directory
d) Default Login Shell
Additional Purpose of this code would be to invoke/ learn at man getpwuid and about struct passswd
a) The RealName
b) Login Name ( Why do we need this?)
c) Home Directory
d) Default Login Shell
Additional Purpose of this code would be to invoke/ learn at man getpwuid and about struct passswd
/* Program to get the Details of the user like User's Real Name, Username and Shell */ #include <pwd.h> /* getpwdid */ #include <sys/types.h> #include <unistd.h> #include <stdio.h> void user_details(void); int main(void) { user_details(); return 0; } void user_details(void) { struct passwd *passwd; /* man getpwuid */ passwd = getpwuid ( getuid()); /* Get the uid of the running processand use it to get a record from /etc/passwd */ printf("\n The Real User Name is %s ", passwd->pw_gecos); printf("\n The Login Name is %s ", passwd->pw_name); printf("\n The Home Directory is %s", passwd->pw_dir); printf("\n The Login Shell is %s ", passwd->pw_shell); printf("\n The Passwd is %s ", getpwuid(getuid()) >pw_passwd); printf("\n The uid is %lu ", (unsigned long) getpwuid(getuid())->pw_uid); printf("\n The gid is %lu \n\n", (unsigned long) getpwuid(getuid())->pw_gid); } /* Program to get the Details of the user like User's Real Name, Username and Shell */ #include <pwd.h> /* getpwdid */ #include <sys/types.h> #include <unistd.h> #include <stdio.h> void user_details(void); int main(void) { user_details(); return 0; } void user_details(void) { struct passwd *passwd; /* man getpwuid */ passwd = getpwuid ( getuid()); /* Get the uid of the running processand use it to get a record from /etc/passwd */ printf("\n The Real User Name is %s ", passwd->pw_gecos); printf("\n The Login Name is %s ", passwd->pw_name); printf("\n The Home Directory is %s", passwd->pw_dir); printf("\n The Login Shell is %s ", passwd->pw_shell); printf("\n The Passwd is %s ", getpwuid(getuid())->pw_passwd); printf("\n The uid is %lu ", (unsigned long) getpwuid(getuid())->pw_uid); printf("\n The gid is %lu \n\n", (unsigned long) getpwuid(getuid())->pw_gid); }
Comments (Newest First)
Post Comment
•
•
•
•
DaniWeb Marketplace (Sponsored Links)