免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1136 | 回复: 0
打印 上一主题 下一主题

System data files and information APUE阅读笔记(4) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-08-06 13:38 |只看该作者 |倒序浏览
System data files and information
Password File:结构体passwd 在<pwd.h>中定义,包含如下字段
char * pw_name 用户名
char* pw_passwd 密码
uid_t pw_uid 用户id
gid_t pw_gid 组id
char *pw_gecos 备注
char *pw_dir home目录
char *pw_shell 初始shell
char *pw_class 用户访问类
time_t pw_change 下一次改变密码时间
time_t pw_expire 账户终止时间
password file 通常保存在/etc/passwd文件。每个字段由:分隔。
通常有一个记录包含用户名root,userid为0;
密码字段中只包含以个字母,密码被保存在其他地方;
Shell字段包含了用作用户登录shell的可执行程序;
#include <pwd.h>
struct passwd *getpwuid(uid_t uid);
struct passwd *getpwnam(const char *name);
getpwuid函数被ls程序调用去匹配i-node中的userid和用户登录名。
getpwnam函数被login函数调用。
Struct passwd *getpwent(void);
void setpwent(void);
void endpwent(void);
getpwent用于返回password file中的下一条记录,setpwent用于回绕,endpwent用于关闭文件。
Shadow password:
struct spwd{
char *sp_namp  用户登录名
char *sp_pwdp 密码
int sp_lstchg 距离上次密码修改时间
int sp_min days until change allowed
int sp_max days before change required
int sp_warn days warning for expriation
int sp_inact days before account inactive
int sp_expire
unsigned int sp_flag reserved
#include <shadow.h>
struct spwd *getspnam(const char *name);
struct spwd *getspent(void);
void setspent(void);
void endspent(void);
组文件:group结构体在<grp.h>中定义
char *gr_name 组名
char *gr_passwd 密码
int gr_gid 组id
char **gr_men组员数组
#include <grp.h>
struct group *getgrgid(gid_t gid);
struct group *getgrnam(const char *name);
struct group *getgrent(void);
void setgrent(void);
void endgrent(void);
System Identification:#include <sys/utsname.h>
int uname(struct utsname *name);返回当前Host和操作系统信息
struct utsname{
char sysname[]; 操作系统名
char nodename[]; 结点名
char release[]; 操作系统的发布号
char version[]; 版本
char machine[]; 硬件类型名
}
#include <unistd.h> int gethostname(char *name , int namelen);返回host
Time函数:
#include <time.h>
time_t time(time_t *calptr);
#include <sys/time.h>
int gettimeofday(struct timeval *restrict tp, void *restrict tzp);
struct timeval{ time_t tv_sec; long tv_usec;}
#include <time.h>
struct tm *gmtime(const time_t *calptr);
struct tm *localtime(const time_t *calptr);
函数将time_t时间转化成tm时间
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP