Unix环境高级编程-系统数据文件和信息

登录名
用户在登录UNIX系统时,先键入登录名,然后键入口令。系统在其口令文件(通常是/etc/passwd文件)中查看登录名。口令文件中的登录项由7个以冒号分隔的字段组成,依次是:登录名、加密口令、数字用户ID (205)、数字组ID (105)、注释字段、起始目录(/home/sar) 以及shell程序( /bin/ksh)
目前,所有的系统已将加密口令移到另-一个文件中。
口令文件
unix系统口令文件,也有称其为用户数据库的,一般有以下各字段,这些字段包含在<pwd.h>中的passwd结构体中。

#include <sys/types.h>
#include <pwd.h>
struct passwd
{
  char *pw_name;                /* 用户登录名 */
  char *pw_passwd;              /* 加密口令 */
  __uid_t pw_uid;               /* 用户ID */
  __gid_t pw_gid;               /* 组ID */
  char *pw_gecos;               /* 详细用户名 */
  char *pw_dir;                 /* 用户目录 */
  char *pw_shell;               /* Shell程序名 */
};

以下是两个获取口令文件项的函数。在给出用户登录名或数值用户ID后,可以查看相关项。

#include <sys/types.h>
#include <pwd.h>
struct passwd *getpwnam(const char *name);
struct passwd *getpwuid(uid_t uid);
//两个函数返回值,若成功,返回指针,出错,返回NULL

阴影口令
阴影口令还可以叫做加密口令。该文件至少包含用户名和加密口令。

struct spwd {
   char *sp_namp;     /* Login name */
   char *sp_pwdp;     /* Encrypted password */
   long  sp_lstchg;   /* Date of last change (measured
                         in days since 1970-01-01 00:00:00 +0000 (UTC)) */
   long  sp_min;      /* Min # of days between changes */
   long  sp_max;      /* Max # of days between changes */
   long  sp_warn;     /* # of days before password expires
                         to warn user to change it */
   long  sp_inact;    /* # of days after password expires
                         until account is disabled */
   long  sp_expire;   /* Date when account expires (measured
                         in days since 1970-01-01 00:00:00 +0000 (UTC)) */
   unsigned long sp_flag;  /* Reserved */
};

与访问口令文件一样,也有一组函数可用于访问阴影口令文件。

#include <shadow.h>
struct spwd *getspnam(const char *name);
struct spwd *getspent(void);
//成功返回指针,出错返回NULL
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值