APUE学习笔记——6 系统数据文件与信息
1、用户口令:/etc/passwd文件
struct passwd
{
char * pw_name; /* 用户名e, POSIX.1 */
char * pw_passwd; /* 密码*/
uid_t pw_uid; /* 数值化用户ID, POSIX.1 */
gid_t pw_gid; /* 数值化组ID, POSIX.1 */
char * pw_gecos; /* 注释 */
char * pw_dir; /* 用户根目录, POSIX.1 */
char * pw_shell; /* 默认shell, POSIX.1 */
char *pw_class; /* 用户访问类 */
time_t pw_change; /* 下次更改密码时间 */
time_t pw_expire; /* 账户到期时间 */
};
#include <pwd.h>
struct passwd *getpwuid(uid_tuid);
struct passwd *getpwnam(const char *name);
Both return: pointer if OK,NULLon erro
#include <pwd.h>
struct passwd *getpwent(void);
Returns: pointer if OK,NULLon error or end of file
void setpwent(void);
void endpwent(void);
#include <pwd.h>
#include <stddef.h>
#include <string.h>
struct passwd *
getpwnam(const char *name)
{
struct passwd *ptr;
setpwent();
while ((ptr = getpwent()) != NULL)
if (strcmp(name, ptr->pw_name) == 0)
break; /* found a match */
endpwent();
return(ptr); /* ptr is NULL if no match found */
}
2、阴影口令/etc/shadow
struct passwd
{
char *sp_namp; //用户名
char *sp_pwdp; //加密口令
int sp_lstchg; //上次更改口令到现在的时间
int sp_min; //还需多久才能更改口令
int sp_max; //离要求更改的时间
int sp_warn; //到期警告天数
int sp_inact; //账户不活动前剩余天数
int sp_expire; //账户到期天数
unsigned int sp_flag; //保留
}
#include <shadow.h>
struct spwd *getspnam(const char *name);
struct spwd *getspent(void);
Both return: pointer if OK,NULLon error
void setspent(void);
void endspent(void);
3、组文件/etc/group
struct group
{
char *gr_name;
char *gr_passwd;
int gr_gid;
char **gr_mem;
}
</pre></div><div><div>相关函数:</div></div><div><pre name="code" class="cpp">#include <grp.h>
struct group *getgrent(void);
Returns: pointer if OK,NULLon error or end of file
void setgrent(void);
void endgrent(void);
4、附加组
#include <unistd.h>
int getgroups(intgidsetsize,gid_tgrouplist[]);
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(intngroups,const gid_tgrouplist[]);
#include <grp.h> /* on Linux and Solaris */
#include <unistd.h> /* on FreeBSD and Mac OS X */
int initgroups(const char *username,gid_tbasegid);
Both return: 0 if OK,−1 on error
APUE学习笔记——6 系统数据文件与信息的更多相关文章
- 《UNIX环境高级编程》读书笔记之系统数据文件和信息(1)
1.UNIX系统口令文件包括了下图所看到的的各字段,这些字段包括在<pwd.h>中定义的passwd结构体中 POSIX定义了两个获取口令文件项的函数. 在给出用户登录名或用户ID后.这两 ...
- apue 第6章 系统数据文件和信息
在给出用户登录名或数值用户ID后,这两个函数就能查看相关项. #include <sys/types.h> #include <pwd.h> struct passwd *ge ...
- (四) 一起学 Unix 环境高级编程(APUE) 之 系统数据文件和信息
. . . . . 目录 (一) 一起学 Unix 环境高级编程 (APUE) 之 标准IO (二) 一起学 Unix 环境高级编程 (APUE) 之 文件 IO (三) 一起学 Unix 环境高级编 ...
- apue学习笔记(第六章 系统数据文件和信息)
UNIX系统的正常运作需要使用大量与系统有关的数据文件,例如,口令文件/etc/passwd和组文件/etc/group就是经常被多个程序频繁使用的两个文件. 口令文件 UNIX系统口令文件包含如下字 ...
- [APUE]系统数据文件与信息
一.口令文件 UNIX口令文件包含下表中的各个字段,这些字段包含在 由于历史原因,口令文件是/bin/passwd,而且是一个文本文件,每一行都包括了上表中的七个字段,字段之间用":&quo ...
- UNIX环境高级编程 第6章 系统数据文件和信息
UNIX系统的正常运作需要用到大量与系统有关的数据文件,例如系统用户账号.用户密码.用户组等文件.出于历史原因,这些数据文件都是ASCII文本文件,并且使用标准I/O库函数来读取. 口令文件 /etc ...
- UNIX系统高级编程——第六章-系统数据文件和信息-总结
口令文件: /* The passwd structure. */ struct passwd { char *pw_name; /* Username. */ char *pw_passwd; /* ...
- [06]APUE:系统数据文件和信息
[a] getpwent / setpwent / endpwent #include <pwd.h> struct passwd *getpwent(void) //成功返回指针,出错或 ...
- #Linux学习笔记# Linux系统查看文件内容的命令
1.cat 连结多个文件的内容并显示在屏幕上:如果没有指定文件或文件名为“-”,则读取标准输入.语法如下: cat [option] ... [file] ... 常用的选项有: 选项-n:编号所有行 ...
随机推荐
- Python中正则模块re.compile、re.match及re.search函数用法
import rehelp(re.compile)'''输出结果为:Help on function compile in module re: compile(pattern, flags=0) C ...
- myeclipse 方法上加上@Override就报错的处理方法
在有@Override方法上面会报错如下: The method oncreate(Bundle) of type HelloWorld must override or implement a su ...
- 【c++ primer, 5e】函数声明 & 分离式编译
p186~p188: 函数声明1.函数只能定义一次,但是可以声明多次. 2.函数的接口:返回类型 + 函数名 + 形参类型 3.为什么要在头文件中进行函数声明???在源文件中定义?暂时理解到,这么做可 ...
- Phred-scale quality scores的相关内容
phred-scale quality score起源于人类基因组计划,最初是用来评估碱基质量分数,后来,被广泛的推广到基因领域的其他内容. phred-scalequality score表示这件事 ...
- 20145329《Java程序设计》第八周学习总结
教材学习内容总结 日志 1.java.util.logging包提供了日志功能相关类与接口. 2.使用日志的起点是Logger类,Longer类的构造函数标示为protected,不同包的类药取得Lo ...
- Oh My Fish! 让你的 Shell 漂亮起来
安装 Oh My Fish 安装 omf 很简单.你要做的只是在你的 Fish shell 中运行下面的命令. curl -L https://get.oh-my.fish | fish 一旦安装完成 ...
- 4.9版本的linux内核中eeprom存储芯片at24c512的驱动源码在哪里
答:drivers/misc/eeprom/at24.c,内核配置项为CONFIG_EEPROM_AT24 Location: -> Device Drivers -> Misc devi ...
- 拓扑排序(dfs)
int c[N];//c[u]=0表示从来没有访问过:c[u]=1表示已经访问过,并且还递归访问过它的所有子:c[u]=-1表示正在访问. int topo[N],t; int G[N][N]; bo ...
- mysql中一张(居民)表按年龄段查询数据
知识点: 用mysql,按年龄段查询一张居民的数据(各年龄段居民的个数) 1.如:查询resident(居民表),按照各年龄段,统计人数 2.mysql语句如下: select ageproporti ...
- SpringMVC封装表单数据
1.domain类 package com.xiaostudy.domain; public class User { private int id; private String username; ...