歡迎您光臨本站 註冊首頁

實現Unix用戶在指定的埠和規定的日期和時間內註冊登錄

←手機掃碼閱讀     火星人 @ 2014-03-12 , reply:0
  在某些使用Unix操作系統的銀行,綠卡等應用項目中,出於安全上考慮,往往要求終端用戶只能在指定的埠,指定的日期和時間內註冊登錄。下面提供一種在SCO 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

---- 如果終端是通過終端伺服器或撥入訪問伺服器(例如英國Chase公司生產的iolan pluse通訊伺服器)登錄到系統,此時使用的是偽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< cr > 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(hm1< stime || hm1>etime)
{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_file

---- 3. 拆卸程序/etc/logport/log_port.uninst


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 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

---- 4. 用戶信息配置表/etc/logport/loginfo

---- 在用戶信息配置表中提供下面的例子,在實際應用時可以刪除它們。

laohe tty03 123456 8 25 17 30
laochen tty04 246 8 30 17 30
laowang tty2a 1350 10 00 18 00


[火星人 ] 實現Unix用戶在指定的埠和規定的日期和時間內註冊登錄已經有1592次圍觀

http://coctec.com/docs/unix/show-post-74001.html