04数据文件

系统数据文件和信息

  • /etc/passwd (不一定所有系统都有)
    • getpwuid();用uid得到passwd结构体指针
      struct passwd *getpwuid(uid_t uid);
      
    • getpwnam();用用户名得到passwd结构体
      struct passwd *getpwnam(const char *name);
      
    • struct passwd {
        char   *pw_name;       /* username */
        char   *pw_passwd;     /* user password */
        uid_t   pw_uid;        /* user ID */
        gid_t   pw_gid;        /* group ID */
        char   *pw_gecos;      /* user information */
        char   *pw_dir;        /* home directory */
        char   *pw_shell;      /* shell program */
        };
      
  • /etc/group
    • getgrgid();
      struct group *getgrgid(gid_t gid);
      
    • getgrgrnam();
      struct group *getgrnam(const char *name);
      
    • struct group {
        char   *gr_name;        /* group name */
        char   *gr_passwd;      /* group password */
        gid_t   gr_gid;         /* group ID */
        char  **gr_mem;         /* NULL-terminated array of pointers to names of group members */
      };
      
  • /etc/shadow
    • getspnam(); 用用户名得到spwd结构体
      struct spwd *getspnam(const char *name);
      
      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 ntil 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 */
      };
      
    • crypt();加密 Crypt Library (libcrypt, -lcrypt)
      char * crypt(const char *phrase, const char *setting);
      
    • getpass();安全地获得密码(关闭终端的回显)
      char *getpass(const char *prompt);
      
    • /etc/shadow语法格式: zhang:$加密方式$杂质$口令
  1. 时间戳 (man 2):①time-t②char *③struct tm
  • time(); 两种用法①返回值②参数传指针
    time_t time(time_t *tloc);
    
  • gmtime();秒数转化为格林尼治时间
    struct tm *gmtime(const time_t *timep);
    
    struct tm {
      int tm_sec;    /* Seconds (0-60) */
      int tm_min;    /* Minutes (0-59) */
      int tm_hour;   /* Hours (0-23) */
      int tm_mday;   /* Day of the month (1-31) */
      int tm_mon;    /* Month (0-11) */
      int tm_year;   /* Year - 1900 */
      int tm_wday;   /* Day of the week (0-6, Sunday = 0) */
      int tm_yday;   /* Day in the year (0-365, 1 Jan = 0) */
      int tm_isdst;  /* Daylight saving time */
    };
    
  • localtime();秒数转化为本地时间(指向静态区)
    struct tm *localtime(const time_t *timep);
    
  • mktime();把结构体转化为秒数
    time_t mktime(struct tm *tm);
    
  • strftime(); 按照模式来获取字符串
    size_t strftime(char *s, size_t max, const char *format, const struct tm *tm);
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值