ITeye博客

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

brxonline · 2011-06-28 16:35 · C · 操作系统 · Markdown

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);

日期间的转换和格式化

#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);

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。