System Data Files and Information

Password File
The password file contains the important information of all the users the system knows.
The format of the password file is described in /etc/passwd.
Let's take a look at the /etc/passwd and /etc/shadow.
A typical line is as follows. 
msql:x:36:36:Mini SQL Database Manager:/var/lib/msql:/bin/sh
The entries in the /etc/passwd contains the following.  The fields are separated by colon ':'.
symbolic user name
optional encrypted passwd
This is a 13-char string converted from the actual user password
user id
group id
comment
user home directory
user login in shell
Programming interface
We now write a program to read the information in the /etc/passwd file. 
This program uses getpwuid to access the passwd structure by uid.
We can also uses getpwnam to access the same data structure by name.
We now write a program to access the passwd information of all users.
This program will be based on the implementation of getpwnam in the textbook. 
There are three functions to use. They are much like open, read and close a file.
 setpwent
Start reading of the passwd structures.
getpwent
Sequentially read the he passwd structures.
endpwent
Ends the reading.
Group File
The /etc/group file contains all the information about the groups in a UNIX system.
The format of the password file is described in /etc/group.
A typical group line is like.
audio:x:29:
The group file contains the following information.
Symbolic name of the group.
The group password
The group is.
Comments.
The programming interface
getgrgid
Get the group structure by id.
getgrnam
Get the group structure by name.
The following three functions are the counterpart of group processing.
setgrent
getgrent
endgrent
Now we extend our ls to print user id and group id in symbolic form.
First we use stat to obtain the user id and group id of the file.
Then we use getpwuid to obtain the symbolic form of the user name.
Then we use getgrgid to obtain the symbolic form of the group name.
Login Accounting File
The file /var/run/utmp contains the information of current login users.
The file /var/log/wtmp contains the information of all login records.
These two files share a common data structure that describes the login information.
TTY line
From where the connection was made.
The user login name
The login in/out time.
During login a record is append to both record files, and during logout the same entry is erased from utmp, but a new record is appended to wtmp to indicate the logout event.
The command who reads utmp and reports the information.
System Information
uname
Obtain the system information, including the following.
The name of the system
The name of this node
The release number
The version number
The hardware type
gethostname
The name of this machine.
File System Table File
/etc/fstab
Time and Date
The time time routine reports the time of the system. 
The time is measured as the elapsed number of second since January 1st, 1970.
The time is kept in UTC.
One can also provide storage for the time routine to place the retuen value,
The tm structure is a more useful form to represent the date and the time.
gmtime
Convert the return value of time into tm structure according to UTC.
localtime
Convert the return value of time into tm structure according to local time.
asctime
Convert a tm into an ASCII string.
ctime
Convert the return value of time directly into a ASCII string.
strftime
Convert a tm structure into a formatted string.