APUE系统文件和信息

pag133
这里的各类ID都是针对用户的
口令文件
/etc/passwd文件中的字段(linux)(struct passwd的成员)
用户名---------------------------char *pw_name
加密口令------------------------char *pw_passwd
数值用户ID---------------------uid_t pw_uid
数值组ID------------------------gid_t pw_gid
注释字段------------------------char *pw_gecos
初始工作目录-------------------char *pw_dir
初始shell------------------------char *pw_shell
如:
root:x:0:0:root:/root:/bin/bash                                                
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync

shell字段包含了一个可执行程序名,他被用做该用户的登录shell(ubuntu下用adduser时,发现切换至创建的用户时登录shell不对(显示为只有一个$)这是因为新创建的用户默认登录shell为/bin/sh,进入/etc/passwd将/bin/sh改为/bin/bash即可)

获取口令文件项
struct passwd *getpwuid(uid_t uid); //将i节点中的数值用户ID映射为用户登录名
struct passwd *getpwnam(const char *name);//用户登录名

struct passwd *getpwent(void);//返回口令文件的下个记录项,返回由他填好的password结构指针(get password entry)
void setpwent(void);//反绕文件,我的理解:从头开始
void endpwent(void);//关闭文件(getpwent后调用)

阴影口令
struct spwd *getspnam(const char *name);
struct spwd *getspent(void);
void setspent(void);
void endspent(void);

组文件
struct group中的gr_mem是一个指针数组,其中每个指针指向一个属于该组的用户名,该数组以空指针结尾。

struct group *getgrgid(gid_t gid);//返回gid组的group结构
struct group *getgrnam(const char *name);//返回name组的group结构

struct group *getgrent(void);
void setgrent(void);
void endgrent(void);

附加组ID:
一个用户可以参加多个项目,因此也就要同时属于多个组。

int getgroup(int gidsetsize, gid_t grouplist[]);//将各附加组ID填写到数组grouplist中
int setgroup(int ngroups, const gid_t grouplist[]);//设置附加组ID
int initgroups(const char *username, gid_t basegid);//在组文件中找到username是成员的所有组,,并将参数basegid组识别码加入此数据中。

一般情况,对于每个数据文件至少有三个函数:
1、get:读下一个记录,如果需要还可打开文件。通常返回一个指向一个结构的指针
2、set:从相应文件的起始处处理
3、end:关闭数据文件

口令 -------------------------/etc/passwd
组    -------------------------/etc/group
阴影 -------------------------/etc/shadow
主机 -------------------------/etc/hosts
网络 -------------------------/etc/networks
协议 -------------------------/etc/protocols
服务 -------------------------/etc/services

int uname(struct utsname *name);//返回当前主机和操作系统有关的信息 (uname命令)
int gethostname(char *name, int namelen);//获取主机名(TCP/IP网络上主机名)(hostname命令)

time_t time(time_t *calptr);//返回当前时间和日期
int gettimeofday(struct timeval *restrict tp, void *restrict tzp);//tzp唯一合法值是NULL
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);//返回指向日历时间的指针
size_t strftime(char *restrict buf, size_t maxsize, const char *restrict format, const struct tm *restrict tmptr);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值