1系统数据文件
说明 | 数据文件 | 头文件 | 结构 | 附加的关键字查找函数 |
口令 组 阴影 主机 网络 协议 服务 | /etc/passwd /etc/group /etc/shadow /etc/hosts /etc/networks /etc/protocols /etc/services | <pwd.h> <grp.h> <shadow.h> <netdb.h> <netdb.h> <netdb.h> <netdb.h> | passwd group spwd hostent netent protoent servent | getpwnam、getpwuid getgrnam、getgrgid getspnam gethostbyname、gethostbyaddr getnetbyname、getnetbyaddr getprotobyname、..bynumber getservbyname、getservbyport |
2数据文件函数
一般情况下,对每个数据文件至少有三个函数:
(1)get函数:读下一个记录,如果需要,还可打开该文件。
(2)set函数:打开相应数据文件(如果尚未打开),然后反绕该文件。如果希望在相应文件起始处开始处理,则调用此函数。
(3)end函数:关闭相应数据文件。
查看口令文件的三个函数:
#include<pwd.h> struct passwd *getpwent(void);/*成功返回指针,出错或到达文件结尾则返回NULL*/ void setpwent(void); void endpwent(void); |
查看组文件的三个函数:
#include<grp.h> struct group *getgrent(void);/*成功返回指针,出错或到达文件结尾则返回NULL*/ void setgrent(void); void endgrent(void); |