6.1 Password file
Given a user login name or numeric user ID, these two functions view the associated records.
#include <sys/types.h>
#include <pwd.h>
struct passwd *getpwuid(uid_t uid);
struct passwd *getpwnam(const char *name);
struct passwd *getpwent(void);
函数返回:成功则为指针,失败则为NULL
void setpwent(void);
void endpwent(void);
6.3 Shadow passwords
Shadow password is generated by password one-way encryption
6.4 Group files
illustrate | struct group members | POSIX.1 |
---|---|---|
group name | char *gr_name | . |
encrypted password | char *gr_passwd | |
Numeric Group ID | int gr_gid | . |
array of pointers to individual usernames | char &&gr_mem | . |
The function to view the group name and group ID is as follows:
#include <sys/types.h>
#include <grp.h>
struct group *getgrgid(gid_t gid);
struct group *getgrnam(const char *name);
两个函数:成功返回指针,失败返回NULL
Function to search entire group files
#include <sys/types.h>
#include <grp.h>
struct group *getgrent(void);
void setgrent(void);
void endgrent(void);
6.7 Login Accounting
Most UNIX systems provide the following two data files: utmp file, which records each user currently logged into the system; wtmp file, which tracks each login and logout event;
6.8 System identification
The uname function returns information related to the host and operating system, which can be printed with uname(1)
#include <sys/uname.h>
int uname(struct utsname *name);
返回:成功为非负数,出错为-1
The gethostname function returns the hostname, which is usually the name of the host on the TCP/IP network
#include <unistd.h>
int gethostname(char *name, int namelen);