UNIX编程(6)-系统数据文件和信息

1.口令文件
口令文件存储在/etc/passwd中,是一个ASCII文件
用用户名或UID获取passwd结构体信息的函数
#include <pwd.h>

struct passwd *getpwuid(uid_t uid);

struct passwd *getpwnam(const char *name);
获取口令文件中所有内容

#include <pwd.h>

struct passwd *getpwent(void);

Returns: pointer if OK, NULL on error or end of file


void setpwent(void);

void endpwent(void);

2.阴影口令
某些系统将加密口令存放在一个通常称为阴影的文件里面
访问阴影口令文件的函数
#include <shadow.h>

struct spwd *getspnam(const char *name);

struct spwd *getspent(void);



Both return: pointer if OK, NULL on error


void setspent(void);

void endspent(void);
3.组文件
组的信息存放在/etc/group文件中
查看组信息的函数
#include <grp.h>

struct group *getgrgid(gid_t gid);

struct group *getgrnam(const char *name);


查看整个组文件的函数


#include <grp.h>

struct group *getgrent(void);

Returns: pointer if OK, NULL on error or end of file


void setgrent(void);

void endgrent(void);

获取和设置附加组函数

#include <unistd.h>

int getgroups(int gidsetsize, gid_t grouplist[]);

Returns: number of supplementary group IDs if OK, 1 on error


#include <grp.h> /* on Linux */
#include <unistd.h> /* on FreeBSD, Mac OS X, and
Solaris */

int setgroups(int ngroups, const gid_t grouplist[]);

#include <grp.h> /* on Linux and Solaris */
#include <unistd.h> /* on FreeBSD and Mac OS X */

int initgroups(const char *username, gid_t basegid);

4.登录账号记录

系统都提供下列两个数据文件:utmp文件,它记录当前登录进系统的各个用户
wtmp文件,它跟踪各个登录和注销事件

5.系统标识

获取当前主机和操作系统相关的信息的函数

#include <sys/utsname.h>

int uname(struct utsname *name);


7.时间和日期

UNIX内核提供的时间是从1970年1月1日00:00:00以来经过的秒数
#include <time.h>

time_t time(time_t *calptr);


#include <sys/time.h>

int gettimeofday(struct timeval *restrict tp, void
*restrict tzp);


日期间的转换和格式化

[img]http://dl.iteye.com/upload/attachment/506268/98d890e0-7268-3f6c-b5aa-22d5ce16faac.png[/img]
#include <time.h>

struct tm *gmtime(const time_t *calptr);

struct tm *localtime(const time_t *calptr);


#include <time.h>

time_t mktime(struct tm *tmptr);


#include <time.h>

char *asctime(const struct tm *tmptr);

char *ctime(const time_t *calptr);


#include <time.h>

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、付费专栏及课程。

余额充值