6.1 如果系统使用阴影文件,那么如何取得加密口令
获取超级用户权限,并与加密口令文件中对应用户的加密口令字段来比较。
6.2 假设你由超级用户权限,并且系统使用了阴影口令,重新考虑上一道习题。
/*************************************************************************
> File Name: test6_2.c
> Author: Elliot
************************************************************************/
#include <shadow.h>
#include "apue.h"
int
main(void)
{
struct spwd *spwdp;
if ((spwdp = getspnam("samba")) == NULL)
err_sys("getspnam error!");
printf("password: %s\n", spwdp->sp_pwdp == NULL ||
spwdp->sp_pwdp[0] == 0 ? "(null)" : spwdp->sp_pwdp);
exit(0);
}
6.3 编写一程序,它调用uname病输出utsname结构中的所有字段,将该输出uname命令的输出结果进行比较
/*************************************************************************
> File Name: test6_3.c
> Author: Elliot
************************************************************************/
#include <sys/utsname.h>
#include "apue.h"
int
main(void)
{
struct utsname utsnamebuf;
if (uname(&utsnamebuf) < 0)
err_sys("uname error!");
printf("sysname = %s\n", utsnamebuf.sysname);
printf("nodename = %s\n", utsnamebuf.nodename);
printf("release = %s\n", utsnamebuf.release);
printf("version = %s\n", utsnamebuf.version);
printf("machine = %s\n", utsnamebuf.machine);
exit (0);
}
6.5 编写一程序,获取当前时间,并使用strftime将输出结果转换为类似于date(1)命令的默认输出。将环境变量TZ设置为不同值,观察输出结果。
/*************************************************************************
> File Name: test6_5.c
> Author: Elliot
************************************************************************/
#include "apue.h"
#include <time.h>
#define BUFFERSIZE 256
int
main(void)
{
time_t t;
char buf[BUFFERSIZE];
struct tm *tmp;
if (time(&t) < 0)
err_sys("time error!");
if ((tmp = localtime(&t)) == NULL)
err_sys("localtime error!");
if (strftime(buf, BUFFERSIZE,
"%Y年 %m月 %d日 %A %H:%M:%S %Z",
tmp) == 0)
err_sys("strftime error!");
else
printf("%s\n", buf);
exit (0);
}