[UNIX环境高级编程第二版]读书笔记6章
2013-08-05 17:05
267 查看
6.1 由于历史原因,大量系统有关的数据文件都是ASCII文本文件。
6.2 口令文件中shell如果为/dev/null表示阻止任何人以该用户名义登陆。
finger -p username可以显示用户相关信息。
有些系统提供了vipw命令,允许管理员编辑口令文件。
获取口令文件项的函数。
struct passwd *getpwuid(uid_t uid);
struct passwd *getpwnam(const char *name);
查看整个口令文件
struct passwd *getpwent(void);
void setpwent(void); void endpwent(void);
在程序开始处调用setpwent是自我保护性措施,以便调用者在此之前已经调用getpwent打开有关文件的情况下,反绕有关文件使他们定位到文件开始处。使用完之后应该调用endpwent关闭文件。
6.3 加密口令是单向算法处理过的用户口令副本。为使有所企图的人难以获得加密口令,系统将加密口令存放在阴影口令中(shadow password)的文件中。/etc/shadow文件
下列函数可以访问阴影口令文件。
struct spwd *getspnam(const char *name);
struct spwd *getspent(void);
void setspent(void);
void endspent(void);
6.4 查看组名或组ID。
struct group *getgrgid(gid_t gid);
struct group *getgrnam(const char *name);
搜索整个组文件。
struct *getgrent(void);
void setgrent(void);
void endgrent(void);
6.5 早期用户的组经常改动,后引入附加组,可以有多个。
获取和设置附加组。
int getgroups(int gidsetsize, gid_t grouplist[]);返回组。
int setgroups(int ngroups, const gid_t grouplist[]);由超级用户调用为进程设置附加组ID表。
int initgroups(const char *username, gid_t basegid);读取整个组文件,然后对username确定其组的成员关系,并调用setgroups为该用户初始化附加组ID表。
6.6 查看不同系统的实现的区别
6.7 /etc/services记录各网络服务器所提供的服务的数据文件。
/etc/protocols记录协议信息的数据文件。
/etc/networks记录网络信息的数据文件。
对于每个数据文件,一般都有至少三个函数。
1)get函数:读下一个记录,如果需要,还可以打开该文件。通常返回结构的指针。大多数get返回指向静态结构的指针,要保存内容,需复制它。
2)set函数:打开数据文件,然后反绕该文件。如果希望在文件起始处开始处理,使用此函数。
3)end函数:关闭相应数据文件。
6.8 登陆账户记录
大多数UNIX提供下列数据文件:
utmp文件:记录当前登陆进系统的各个用户;/var/run/utmp
wtmp文件:跟踪各个登录和注销事件;/var/log/wtmp
6.9 获取当前主机和操作系统有关信息。
int uname(struct utsname *name);操作系统名字,节点名字,当前release,当前版本,硬件类型。
int gethostname(char *name, int namelen);只返回主机名,通常是TCP/IP网络上的主机的名字。对应hostname命令。
6.10 UNIX内核提供的时间是自UTC公元1970年1月1日00:00:00以来的秒数。
time_t time(time_t *calptr);返回当前时间和日期。
int gettimeofday(struct timeval *restrict tp, void *restrict tzp);提供最高位微妙级的时间分辨率。
struct tm *gmtime(const time_t *calptr);将日历时间转换成国际标准时间。
struct tm *localtime(const time_t *calptr); 将日历时间转换为本地时间。
time_t mktime(struct tm *tmptr);以本地时间年月日做参数,将其转换成time_t值。
char *asctime(const struct tm *tmptr);
char *ctime(const time_t *calptr);产生大家熟悉的26字节的字符串,与date命令输出类型。
最后一个函数,格式化输出时间。
size_t strftime(char *restrict buf, size_t maxsize, const char *restrict format, const struct tm *restrict tmptr);
6.11 null
6.2 口令文件中shell如果为/dev/null表示阻止任何人以该用户名义登陆。
finger -p username可以显示用户相关信息。
有些系统提供了vipw命令,允许管理员编辑口令文件。
获取口令文件项的函数。
struct passwd *getpwuid(uid_t uid);
struct passwd *getpwnam(const char *name);
查看整个口令文件
struct passwd *getpwent(void);
void setpwent(void); void endpwent(void);
在程序开始处调用setpwent是自我保护性措施,以便调用者在此之前已经调用getpwent打开有关文件的情况下,反绕有关文件使他们定位到文件开始处。使用完之后应该调用endpwent关闭文件。
6.3 加密口令是单向算法处理过的用户口令副本。为使有所企图的人难以获得加密口令,系统将加密口令存放在阴影口令中(shadow password)的文件中。/etc/shadow文件
下列函数可以访问阴影口令文件。
struct spwd *getspnam(const char *name);
struct spwd *getspent(void);
void setspent(void);
void endspent(void);
6.4 查看组名或组ID。
struct group *getgrgid(gid_t gid);
struct group *getgrnam(const char *name);
搜索整个组文件。
struct *getgrent(void);
void setgrent(void);
void endgrent(void);
6.5 早期用户的组经常改动,后引入附加组,可以有多个。
获取和设置附加组。
int getgroups(int gidsetsize, gid_t grouplist[]);返回组。
int setgroups(int ngroups, const gid_t grouplist[]);由超级用户调用为进程设置附加组ID表。
int initgroups(const char *username, gid_t basegid);读取整个组文件,然后对username确定其组的成员关系,并调用setgroups为该用户初始化附加组ID表。
6.6 查看不同系统的实现的区别
6.7 /etc/services记录各网络服务器所提供的服务的数据文件。
/etc/protocols记录协议信息的数据文件。
/etc/networks记录网络信息的数据文件。
对于每个数据文件,一般都有至少三个函数。
1)get函数:读下一个记录,如果需要,还可以打开该文件。通常返回结构的指针。大多数get返回指向静态结构的指针,要保存内容,需复制它。
2)set函数:打开数据文件,然后反绕该文件。如果希望在文件起始处开始处理,使用此函数。
3)end函数:关闭相应数据文件。
6.8 登陆账户记录
大多数UNIX提供下列数据文件:
utmp文件:记录当前登陆进系统的各个用户;/var/run/utmp
wtmp文件:跟踪各个登录和注销事件;/var/log/wtmp
6.9 获取当前主机和操作系统有关信息。
int uname(struct utsname *name);操作系统名字,节点名字,当前release,当前版本,硬件类型。
int gethostname(char *name, int namelen);只返回主机名,通常是TCP/IP网络上的主机的名字。对应hostname命令。
6.10 UNIX内核提供的时间是自UTC公元1970年1月1日00:00:00以来的秒数。
time_t time(time_t *calptr);返回当前时间和日期。
int gettimeofday(struct timeval *restrict tp, void *restrict tzp);提供最高位微妙级的时间分辨率。
struct tm *gmtime(const time_t *calptr);将日历时间转换成国际标准时间。
struct tm *localtime(const time_t *calptr); 将日历时间转换为本地时间。
time_t mktime(struct tm *tmptr);以本地时间年月日做参数,将其转换成time_t值。
char *asctime(const struct tm *tmptr);
char *ctime(const time_t *calptr);产生大家熟悉的26字节的字符串,与date命令输出类型。
最后一个函数,格式化输出时间。
size_t strftime(char *restrict buf, size_t maxsize, const char *restrict format, const struct tm *restrict tmptr);
6.11 null
相关文章推荐
- [UNIX环境高级编程第二版]读书笔记8章[TBD]
- [UNIX环境高级编程第二版]读书笔记5章
- [UNIX环境高级编程第二版]读书笔记7章
- [UNIX环境高级编程第二版]读书笔记3章
- [UNIX环境高级编程第二版]读书笔记4章
- [UNIX环境高级编程第二版]读书笔记1~2章
- 进程编程1 – Unix环境高级编程7章读书笔记
- 进程编程1 – Unix环境高级编程7章读书笔记
- 进程编程1 – Unix环境高级编程7章读书笔记
- Unix 环境高级编程-读书笔记
- 进程编程3 - UNIX高级环境编程第9章读书笔记
- 进程编程1 – Unix环境高级编程7章读书笔记
- UNIX环境高级编程(第二版)/ APUE 源码编译与使用
- 进程编程1 – Unix环境高级编程7章读书笔记
- unix环境高级编程 APUE.H最简单编译方法(第二版) Linux和Ubuntu
- 进程编程3 - UNIX高级环境编程第9章读书笔记
- 使用pthread库进行多线程编程1 - UNIX环境高级编程第11章读书笔记
- 进程编程2 – Unix环境高级编程8章读书笔记
- 进程编程3 - UNIX高级环境编程第9章读书笔记
- 进程编程3 - UNIX高级环境编程第9章读书笔记