Linux/UNIX数据文件和信息系统

数据文件和信息系统

密码文件

在存储/etc/passwd在。以下功能可以用来获得密码文件条目。

#include <sys/types.h>

#include <pwd.h>

struct passwd *getpwnam(const char *name);

struct passwd *getpwuid(uid_t uid);

假设要查看的仅仅是登录名或用户ID,上述两个函数能满足要求,但有些程序要查看整个口令文件。

以下三个函数可用于此种目的。

#include <sys/types.h>

#include <pwd.h>

struct passwd *getpwent(void);

void setpwent(void);

void endpwent(void);

阴影口令

阴影口令文件:存放加密口令

下面函数用于訪问阴影口令文件:

#include <shadow.h>

struct spwd *getspnam(const char *name);

struct spwd *getspent(void);

void setspent(void);

void endspent(void);

组文件

下面函数用来查看组名或数值组ID

#include <sys/types.h>

#include <grp.h>

struct group *getgrnam(const char *name);

struct group *getgrgid(gid_t gid);

如需搜索整个组文件。可用下面是三个函数:

#include <sys/types.h>

#include <grp.h>

struct group *getgrent(void);

void setgrent(void);

 

void endgrent(void);

附加组ID

为获取和设置附加组ID,可用例如以下三个函数

#include <sys/types.h>

#include <unistd.h>

int getgroups(int size, gid_t list[]);

#include <grp.h>

#include <unistd.h>

int setgroups(size_t size, const gid_t*list);

#include <sys/types.h>

#include <grp.h>

int initgroups(const char *user, gid_tgroup);

时间和日期例程

#include <time.h>

time_t time(time_t *t);

该函数用于返回当前时间和日期。

#include <sys/time.h>

int gettimeofday(struct timeval *tv, structtimezone *tz);

上述函数也用于获取当前时间和日期。只是其分辨率更高(最高为微秒级)。

 

#include <time.h>

double difftime(time_t time1, time_ttime0);

该函数用于计算两个时间值之间的差。和time1-time2的值作为一个浮点回报。

版权声明:本文博客原创文章,博客,未经同意,不得转载。

posted @ 2015-07-03 08:38  blfshiye  阅读(122)  评论(0编辑  收藏  举报