#include #include #include // for getpwnam #include // for getpwnam #include // getuid using namespace std; int main() { uid_t id; string name; passwd * theEntry; id = getuid(); cout << "The UID = " << id << endl; theEntry = getpwuid(id); if (theEntry == NULL) { perror("Failed to get password entry"); return 1; } cout << "Hello " << theEntry->pw_name << endl; cout << "\tDid you know your encrypted password is " << theEntry->pw_passwd << endl; cout << "\tYour default group number is " << theEntry->pw_gid << endl; cout << "\tYour gecos field contains " << theEntry->pw_gecos << endl; cout << "\tYour home directory is " << theEntry->pw_dir << endl; cout << "\tYour default shell is " << theEntry->pw_shell << endl; cout << endl; cout << "Enter the user name of someone else=> "; cin >> name; cout << endl; theEntry = getpwnam(name.c_str()); if (theEntry == NULL) { perror("Failed to get password entry "); cerr << "This was for " << name << endl; return 0; } cout << endl; cout << "Information on " << name << endl; cout << "\tuid: " << theEntry->pw_uid << endl; cout << "\tencrypted password: " << theEntry->pw_passwd << endl; cout << "\tdefault group number: " << theEntry->pw_gid << endl; cout << "\tgecos: " << theEntry->pw_gecos << endl; cout << "\thome directory: " << theEntry->pw_dir << endl; cout << "\tdefault shell: " << theEntry->pw_shell << endl; return 0; }