Sie befinden sich hier: Krischer.org » Code » Ansi C » Snipplet Overview » Get User Details

Get User Details

/* 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);
}
 
Nach oben
code/ansi_c/snipplets/user_details.txt · Zuletzt geändert: 2009/01/14 23:48 (Externe Bearbeitung)
edv-krischer.de Valid CSS Driven by DokuWiki Recent changes RSS feed Valid XHTML 1.0