口令文件
#include <pwd.h>
查看登入名或者用户ID
struct passwd *getpwuid(uid_t uid);
struct passwd *getpwnam(const char *name);
macos
struct passwd {
char *pw_name; /* user name */
char *pw_passwd; /* encrypted password */
uid_t pw_uid; /* user uid */
gid_t pw_gid; /* user gid */
__darwin_time_t pw_change; /* password change time */
char *pw_class; /* user access class */
char *pw_gecos; /* Honeywell login info */
char *pw_dir; /* home directory */
char *pw_shell; /* default shell */
__darwin_time_t pw_expire; /* account expiration */
};
查看整个口令文件
struct passwd *getpwent(void);
//清理读取的缓存和关闭文件
void setpwent(void);
void endpwent(void);
阴影口令
访问阴影口令函数
#include <shadow.h>
struct spwd *getspnam(const char *name);
struct spwd *getspent(void);
void setepent(void);
void endspent(void);
组文件
#include <grp.h>
struct group *getgrgid(gid_t gid);
struct group *getgrnam(const char *name);
一行一行获取
struct group *getgrent(void);
void setgrent(void);
void endgrent(void);
macos
struct group {
char *gr_name; /* [XBD] group name */
char *gr_passwd; /* [???] group password */
gid_t gr_gid; /* [XBD] group id */
char **gr_mem; /* [XBD] group members */
};
附属组ID
POSIX.1 要求的
实现区别
其他数据文件
pwd /etc/passwd
grp /etc/group
shadow /etc/shadow
/etc/hosts
/etc/networks
/etc/protocols
/etc/services
登入账号记录
utmp文件:记录当前登入系统的用户
struct utmp{
char ut_line[8];
char ut_name[8];
long ut_time;
}
wtmp文件:记录登入,注销事件
linux中/var/run/utmp,/var/log/wtmp
系统标识
#include <sys/utsname.h>
int uname(struct utsname *name);
int gethostname(char *name,int namelen);//获取主机名,sethostname超管用户可设置
struct utsname{
char sysname[];//
char nodename[];
char release[];
char version[];
char machine[];
}
时间和日期例程
#include <time.h>
time_t time(time_t *calptr);//返回日历时间
#include <sys/time.h>
int clock_gettime(clockid_t clock_id,struct timespec *tsp);//获取指定时钟的时间
int clock_getres(clock_id_t clock_id,struct timespec *tsp);//
int clock_settime(clockid_t clock_id,const struct timespec *tsp);
int gettimeofday(struct timeval *restrict tp,void *restrict tzp);//获得微妙级别时间,虽然弃用
#include <time.h>
struct tm *gmtime(cosnt time_t *calptr);
struct tm *localtime(const time_t *calptr);
time_t mktime(struct tm *tmptr);
size_t strftime();//转字符串
size_t strftime_l();//较上多个指定区域
localtime:日历时间转本地时间
gmtime:日历时间转协调统一时间的分解结构
mktime:本地时间转time_t
strftime:转字符串
用法
time(&t) t是日历时间
localtime(&t) 转换位本地时间
strftime() 本地时间格式成字符串
网友评论