Linux下的系统数据文件和信息

一 口令文件

口令文件保存了系统用户的信息,这些信息的各个字段都包含在<pwd.h>中定义的passwd结构中。口令文件存放在/etc/passwd中,是一个ASCII文件,关于文件内容有几点要注意:
1 有一个用户名为root的登陆项,用户ID为0(超级用户);
2 加密口令字段包含了一个占位字符,在早期的UNIX系统版本中,该字段存放加密口令,现在将加密口令存放在另一个地方(阴影口令文件/etc/shadow);
3 不推荐加密口令字段为空;
4 shell字段为空,则取系统默认值/bin/sh,若为/dev/null,则阻止该用户登陆系统,也可以使用/bin/false或/bin/true以不成功或成功状态终止;
5 使用nobody用户名的目的是,使任何人都可登陆系统,但其用户ID和用户组ID不提供任何特权(该用户和用户组只能访问人人皆可读写的文件)。
#include <pwd.h>
struct passwd *getpwuid( uid_t uid );
struct passwd *getpwnam( const char *name );
这两个函数都返回指向passwd结构的指针,该结构被这两个函数在执行时填入信息,passwd结构通常是相关函数的静态变量,只要调用相关函数,变量内容就会被重写。下面的三个函数用来查看整个口令文件:
#include <pwd.h>
struct passwd *getpwent( void );
void setpwent( void );
void endpwent( void );
调用getpwent时,返回口令文件中的下一个记录项,第一次调用时,打开它所使用的相关文件。函数setpwent反绕它所使用的文件以定位到文件的开始处,endpwent则关闭这些文件。

二 阴影口令
#include <shadow.h>
struct spwd *getspnam( const char *name );
struct spwd *getspent( void );
void setspent( void );
void endspent( void );

三 用户组文件
UNIX组文件的字段包含在<grp.h>中的group结构中。
#include <grp.h>
struct group *getgrgid( gid_t gid );
struct group *getgrnam( const char *name );
这两个函数都返回一个静态变量的指针,每次调用时都重写该静态变量。
#include <grp.h>
struct group *getgrent( void );
void setgrent( void );
void endgrent( void );
getgrent函数从组文件中读取下一个记录,setgrent打开(如果尚未打开)并反绕组文件,endgrent函数关闭组文件。

四 系统标识
#include <sys/utsname.h>
int uname( struct utsname *name );
返回与当前主机和操作系统有关的信息。

五 时间和日期
#include <time.h>
time_t time( time_t *cal_ptr );
time函数返回当前时间和日期,如果cal_ptr不为NULL,则返回值也存放在cal_ptr所指向的单元内。
#include <time.h>
struct tm *gmtime( const time_t *cal_ptr );
struct tm *localtime( const time_t *cal_ptr );
gmtime和localtime将日历时间转换成以年,月,日,时,分,秒,周日表示的时间,并存放在一个tm结构中,两者的区别是:localtime将日历时间转换成本地时间,gmtime将日历时间转换成国际标准时间。
#include <time.h>
time_t mktime( struct tm *tm_ptr );
mktime函数将struct tm结构的时间转换成time_t结构的时间。
#include <time.h>
char *asctime( const struct tm *tm_ptr );
char *ctime( const time_t *cal_ptr );
asctime和ctime函数将时间日期值转换为字符串。

转载于:https://www.cnblogs.com/mahy/archive/2012/01/03/2310965.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值