UNIX环境高级编程——第六章 系统数据文件和信息

6.1 口令文件

在给出用户登录名或数值用户ID后,这两个函数就能查看相关记录。

#include <sys/types.h>
#include <pwd.h>
struct passwd *getpwuid(uid_t uid);
struct passwd *getpwnam(const char *name);
struct passwd *getpwent(void);
					函数返回:成功则为指针,失败则为NULL
void setpwent(void);
void endpwent(void);

6.3 阴影口令

阴影口令是密码单向加密生成的

6.4 组文件

说明 struct group成员 POSIX.1
组名 char *gr_name .
加密口令 char *gr_passwd
数字组ID int gr_gid .
指向各用户名指针的数组 char &&gr_mem .

查看组名和组ID的函数如下:

#include <sys/types.h>
#include <grp.h>
struct group *getgrgid(gid_t gid);
struct group *getgrnam(const char *name);
					两个函数:成功返回指针,失败返回NULL

搜索整个组文件的函数

#include <sys/types.h>
#include <grp.h>
struct group *getgrent(void);
void setgrent(void);
void endgrent(void);

6.7 登录会计

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

6.8 系统标识

uname函数返回与主机和操作系统相关的信息,可以用uname(1)来打印

#include <sys/uname.h>
int uname(struct utsname *name);
				返回:成功为非负数,出错为-1

gethostname函数返回主机名,该名字通常就是TCP/IP 网络上主机的名字

#include <unistd.h>
int gethostname(char *name, int namelen);

6.9 时间和日期例程

猜你喜欢

转载自blog.csdn.net/u012850592/article/details/103095584