实现 Unix 用户在指定端口和规定时间内登录注册Windows系统 -电脑资料

电脑资料 时间:2019-01-01 我要投稿
【www.unjs.com - 电脑资料】

    实现 Unix 用户在指定端口和规定时间内登录注册 北京中软同和公司何绍德 某些使用Unix操作系统的 银行 ,在绿卡等应用项目中,出于 安全 上的考虑,往往要求终端用户只能在指定的端口、指定的日期和时间内注册登录,

实现 Unix 用户在指定端口和规定时间内登录注册Windows系统

。下面提供一种实现这种功能的方法。 工作原理

    实现Unix用户在指定端口和规定时间内登录注册

    北京中软同和公司   何绍德

    某些使用 Unix 操作系统的银行, 在绿卡等应用项目中 , 出于安全上的考虑 , 往往要求终端用户只能在指定的端口、指定的日期和时间内注册登录。下面提供一种实现这种功能的方法。

    工作原理

    当用户注册登录到 Unix 系统时 , 首先执行系统文件 /etc/profile , 然后执行文件 $HOME/.profile 。我们在文件 /etc/profile 中增加一段程序 , 判断一下当前注册用户的登录端口、当前的登录日期和时间是否和用户信息配置表 /etc/logport/loginfo 中预先设定的数据相一致 , 若不一致 , 则拒绝用户注册登录。之所以修改文件 /etc/profile 而没有使用文件 $HOME/.profile, 是因为使用文件 /etc/profile 更便于控制和处理。

    文件 /etc/logport/loginfo 是一个文本文件 , 每个用户占用一行 , 每行中有七个字段 , 字段间由制表符相隔。七个字段分别表示注册用户名、登录端口设备名、每周工作的日期 ( 星期日到星期六分别用 0 ~ 6 七个数字表示 ) 、每天上班的时间 ( 时和分各占一个字段 ) 以及每天下班的时间 ( 时和分各占一个字段 ) 。下面是文件 /etc/logport/loginfo 的一个例子 :

    laohe   tty03 123456 8 25  17 30

    laochen tty04 246  8 30  17 30

    laowang tty2a 1350   10 00 18 00

    如果终端是通过终端服务器或拨入访问服务器登录到系统 , 此时使用的是伪 tty 设备文件 , 通常登录的端口是不固定的。因此必须先执行固定通讯服务器端口设置程序 , 此程序由通讯服务器生产厂家随产品一起提供。

    安装软件

    在软盘上提供了四个程序 :

    /etc/logport/log_port.inst

    安装程序

    /etc/logport/log_port.uninst

    拆卸程序

    /etc/logport/log_port

    主体程序

    /etc/logport/loginfo

    用户信息配置表

    1.  以 root 身份登录 , 把所提供软盘上的文件装入系统。

    # tar xv6

    此时在 /etc/logport 目录下有下面四个文件 , 请检查一下它们的权限和属性 :

    rw-r — r-- 1 bin bin 603 log_port

    rwx------ 1 bin bin 461 log_port.inst

    rwx------ 1 bin bin 325 log_port.uninst

    rw-r — r-- 1

    bin bin 116

    loginfo

    2.  执行安装程序。

    # /etc/logport/log_port.inst

    安装程序主要完成三个功能 :

    ·   如果文件 /etc/profile 在此之前还没有被修改过 , 则产生文件 /etc/profile 的副本 /etc/profile.old.sco 。

    ·   修改文件 /etc/profile, 把主体程序 log_port 插入到文件 /etc/profile 中。

    ·   修改新文件 /etc/profile 和 /etc/profile.old.sco 的权限和属性。

    3.  编辑 /etc/logport/loginfo 文件。

    文件 /etc/logport/loginfo 中存放着有关注册用户的用户名 (name), 允许登录的端口设备文件名 (port), 每周允许工作的日期 (date) 以及上下班时间的时值和分值 (onduty(hh), onduty(mm), offduty(hh), offduty(mm)) 等七个字段的信息 , 字段间用制表符相隔。其结构如下所示 :

    Name port date onduty(hh) onduty(mm)

    offduty(hh) offduty(mm)

    # vi /etc/logport/loginfo

    laohe   tty03 123456 8  25 17 30

    laochen tty04 246  8  30 17 30

    laowang tty2a 1350   10 00 18 00

    # 注意在编辑时不要改变文件 /etc/logport/loginfo 的权限和属性。

    经过上述操作后 , 现在用户登录注册时系统就要检查用户的登录端口和时间是否在规定的范围内 , 对于所有不符合规定的用户都将被拒绝登录到系统中。

    执行拆卸程序

    当你不需要对用户登录进行检查时 , 可以执行拆卸程序 /etc/logport/log_port.uninst 恢复原来的系统文件 /etc/profile 。如果以后你需要再次使用该功能时 , 可以再次执行安装程序 /etc/logport/log_port.inst 。

    拆卸程序 /etc/logport/log_port.uninst 主要完成下述功能 :

    * 从副本文件 /etc/profile.old.sco 恢复文件 /etc/profile 。

    * 删除副本文件 /etc/profile.old.sco 。

    * 修改文件 /etc/profile 的权限和属性。

    源文件

    1.  主体程序 /etc/logport/log_port

    lab=0

    name= ‘ who am I | awk  ‘ {print $1}' ’  #  得到注册用户名

    dev= ‘ who am I | awk  ‘ {print $2}' ’  #  得到注册端口名

    awk -v name1="$name" -v dev1="$dev"

    ‘ $1 == name1 && $2 != dev1 {exit 1} ’  /etc/logport/loginfo || lab=1

    if [$lab -eq 1 ] #  和信息配置表中相应字段对比

    then

    echo "\n\tThe user $name can not login on this port"

    exit 1

    fi

    ww= ‘ date +%w ’  #  得到当前星期几

    aa= ‘ date +%H ’  #  得到当前时间的时值

    bb= ‘ date +%M ’  #  得到当前时间的分值

    hm= ‘ expr $aa \*60+ $bb ’ #  把当前时间化成分值

    lab=0

    awk -v hm1="$hm" -v ww1="$ww"

    ‘ $3 ! ~  ww1 {exit 1}

    {stime=$4*60+$5; etime=$6*60+$7}

    {if(hm1etime) {exit 1}}'

    /etc/logport/loginfo || lab=1

    if[$lab -eq 1] #  如果不在工作时间内登录则退出

    then

    echo "\n\tYou must login in working time"

    exit 1

    fi

    trap 1 2 3

    2.  安装程序 /etc/logport/log_port.inst

    tmp_file=/etc/hsd$$

    copy_file=/etc/profile.old.sco

    if  ‘ logname ’  != "root"  〗  # 必须以超级用户 root 登录

    then echo"n\tPlease become supperuser root first"

    exit 1

    fi

    if[-r $copy_file ] #  如果副本 profile.old.sco 存在 , 则认为已经安装过

    then echo "\n\tThe software has been installed"

    exit 1

    fi

    copy /etc/profile $copy_file #  建立系统文件 /etc/profile 的副本

    sed "/^trap 1 2 3$/{

    r /etc/logport/log_port

    d

    }" /etc/profile > $tmp_file #  把主体程序 log_port 插入到 /etc/profile

    mv $tmp_file /etc/profile

    chown bin /etc/profile $copy_file #  修改 /etc/profile 和它的副本的属性

    chgrp bin /etc/profile $copy_file #  性和权限

    chmod 664 /etc/profile $copy_file3.  拆卸程序 /etc/logport/log_port.unins

    copy_file=/etc/profile.old.sco

    if[ ‘ logname ’  != "root" ] #  必须以超级用户 root 登录

    then echo "\n\t]Please become supperuser root first"

    exit 1

    fi

    if [!-r $copy-file] # 如果副本 profile.old.sco 不存在

    then echo"\n\tThe software has been uninstalled"

    exit 1

    fi

    copy $copy-file/etc/profile #  恢复系统的 /etc/profile

    rm $copy_file #  删除副本文件 profile.old.sco

    chown bin /etc/profile #  修改 /etc/profile 的属性和权限

    chgrp bin /etc/profile

    chmod 664 /etc/profile

    3.  用户信息配置表 /etc/logport/loginfo

    在用户信息配置表中提供下面的例子 , 在实际应用时可以删除它们,

电脑资料

实现 Unix 用户在指定端口和规定时间内登录注册Windows系统》(https://www.unjs.com)。

    laohe  tty03 123456 8 25 17 30

    laochen tty04 246   8 30 17 30

    laowang tty2a 1350 10 00 18 00

    【发表回复】【查看CU论坛原帖】【添加到收藏夹】【关闭】

    原文转自:http://www.ltesting.net

最新文章