UNIX环境高级编程之第6章:系统数据文件和信息
6.1 引言
6.2 口令文件(Password File)
#Include <pwd.h>
struct passwd *getpwuid(uid_t uid);
struct passwd *getpwnam(const char *name);
getpwuid函数由ls(1)程序使用,在输入登录名是,getpwnam函数由login(1)程序使用
#include<pwd.h>
struct passwdd *getpwent(void);
void setpwent(void);
void endpwent(void);
调用getpwent时,它返回口令文件中的下一个纪录项
getpwnam函数的一个实现
#include <pwd.h>
#include <stddef.h>
#include <string.h>
struct passwd *getpwnam(const char *name)
{struct passwd *ptr;setpwent();whlie((ptr = getpwent())!=NULL)if(strcmp(name,ptr->pw_name)==0)break;endpwent(); return(ptr);
}
setpwent反绕有关文件使它们定位到文件开始处(自我保护措施)。getpwnam和getpwuid完成后不应使文件处于打开状态,所以调用endpwent关闭它们。
6.3 阴影口令(Shadow Passwords)
#include <shadow.h>
struct spwd *getspnam(const char *name);
struct spwd *getspent(void);
void setpent(void);
void endspent(void);
6.4 组文件
#include <grp.h>
struct group *getgrgid(gid_t gid);
struct group *gergrnam(const char *name);
如同对口令文件进行操作的函数一样
#include <grp.h>
struct group *getgrent(void);
void setgrent(void);
void endgrent(void);
6.5 附属组ID
6.6 实现区别
6.7 其他数据文件
6.8 登录账户记录
6.9 系统标识
#include <sys/utname.h>
int uname (struct utsname *name);
utsname的结构
6.10 时间和日期例程(Time and Date Routines)
#include <time.h>
time_t time(time_t *calptr);
clock_gettime函数可用于获取指定时钟的时间,把时间保存再timespec结构中
#include <sys/time.h>
int clock_gettime(clockid_t clock_id, struct timespec *tsp);
当时钟ID设置为CLOCK_REALTIME时,clock_gettinng函数提供了与time函数类似的功能,clock_getting可能比time函数提供更高的精度的时间
#include<sys/time.h>
int clock_getres(clockid_t clock_id, struct timespec *tsp);
clock_getres函数把参数tsp指向的timespec结构初始化为与clock_id参数相对应的时钟精度
对特定的时钟设置时间
#include<sys/time.h>
int clock_settime(clockid_t clock_id, const struct timespec *tsp);
#include <time.h>
struct tm *gmtime(const time_t *calptr);
struct tm *localtime(const time_t *calptr);
两个函数localtime 和gmtime将日历时间转化成分解的时间,并将其存放再一个tm结构中
#include<time.h>
time_t mktime(struct tm *tmptr);
函数strftime是一个类似printf的时间值函数,可以通过可用的多个参数指定产生的字符串。
#include <time.h>
size_t strftime(char *restrict buf, size_t maxsize, const char *restrict format, const struct tm *restrict tmptr);
size_t strftime_l(char *restrict buf, size_t maxsize, const char *restrict format, const struct tm *restrict tmptr, locale_t locale);
ISO C规定的转换说明(conversion specifiers)
6.11 小结
UNIX环境高级编程之第6章:系统数据文件和信息相关推荐
- UNIX环境高级编程之第4章:文件和文件夹-习题
4.1 stat函数是尾随符号链接的,所以用stat替换lstat不会显示符号链接的信息 4.2 在一个目录下先再shell中输入umask shell进程再进行创建文件的操作.其权限抖都会被屏蔽 4 ...
- unix环境高级编程之 read与write 函数详解
学习记录:unix环境高级编程之 read 与write 函数详解 备注:本博文非本人所写,本人觉得此文讲的非常地道通俗易懂,所以摘录在此以方便以后再次查看 read函数从打开的设备或文件中读取数据 ...
- APUE第6章 系统数据文件和信息
6.1 引言 UNIX系统的正常运作需要使用大量与系统有关的数据文件,例 如,口令文件/etc/passwd和组文件/etc/group就是经常被多个程序频繁 使用的两个文件.用户每次登录UNIX系统 ...
- 第6章 系统数据文件和信息
口令文件 用户: 基础密码文件:/etc/passwd 密码文件:/etc/shadow 组: 基础密码文件:/etc/group 密码文件:/etc/gshadow /etc/passwd 内容:用 ...
- 第6章系统数据文件和信息总结
1 口令文件的shell字段 如果是空,则使用系统默认的shell,一般是/bin/sh /dev/null:阻止对应的用户名登陆系统 /bin/false:同样是阻止特定用户登录,以不成功状态终止 ...
- UNIX环境高级编程源码
UNIX环境高级编程源码 一.下载源码 利用wget命令下载源码,源码地址http://apuebook.com/src.3e.tar.gz 可以在服务器的根目录下创建文件夹,mkdir 1.mkdi ...
- 《unix环境高级编程》笔记4——系统数据文件和信息
文章目录 系统数据文件和信息 口令文件 获取口令文件 getwpuid getpwnam 阴影口令 组文件 附属组ID 查看附属组ID 其他文件 登录账户记录: 系统标识 uname gethostn ...
- Unix环境高级编程-系统数据文件和信息
unix口令文件/etc/passwd 包含了下表所示的字段: 系统定义了两个获取口令文件项的函数,在给出用户登录名或数值用户ID后,这两个函数能够查看相关项. struct passwd *getp ...
- UNIX环境高级编程——系统数据文件和信息
6.1 引言 UNIX系统的正常运行需要使用大量与系统有关的数据文件,这些文件都是ASCII文本文件,并且使用标准I/O库读这些文件. 6.2 口令文件 UNIX口令文件是/etc/passwd,每一 ...
- linux系统数据文件和信息--unix环境高级编程读书笔记
linux系统中的数据文件有很多,在这一章里介绍的主要内容是和系统有关的一系列文件,包括passwd,shadow,group,utmp,wtmp以及一些系统的相关信息和时间的相关操作. 1.pass ...
最新文章
- 超级详细的 Python 数据分析指南
- 一个c/c++分布式框架ZMQ或者ZeroMQ, 介绍和win下安装使用方法
- JavaScript window.location物
- 通过js让页面中的元素上下居中的写法
- 天津大学计算机学院院长及副院长,李晓红 教授
- python中的面向对象
- Windows中命令提示符被禁用的解决方法
- HashSet、LinkedHashSet、TreeSet 简明解释
- HTTP 之 HTTPD介绍
- Google 开源 iOS 应用测试工具:EarlGrey
- unity3d ppsspp模拟器中的post processing shader在unity中使用
- 人工智能在生活中的应用都有哪些?
- 锋利的jQuery(汇总)
- [转载]MTK入门教程
- 面试必背 Java 多线程面试题
- 推荐一个项目管理工具:TAPD
- cad横断面图转文本
- HTML5+CSS3新特性
- WordPress 5.0的重要问题,答案已有
- Excel怎么在数据中间隔插入指定行