From: tateishi@... (Takaaki.Tateishi) Date: 1997-12-18T02:01:03+09:00 Subject: [ruby-list:5712] script to rewrite a pap-secrets 立石です。 度々、失礼致します。 rubyを久々に使い始めました。 それでTCPsocketを使用したスクリプトを 作成中なのですが、セキュリティの面での アドバイスを頂きたいと思いこのメーリング リストにスクリプトを流します。 スクリプトはPAPで使用されるpap-secretsの パスワードを変更するもので、root以外の ユーザからパスワード変更ができるようにするためで、 rootで以下のスクリプトを走らせておき、 ユーザは telnet localhost 16016 としてパスワード変更を行なうものです。 実際には、pap-secrets,pap-hosts,pap-logと 3つのファイルも必要となります。 ------------[ pap-hosts ]--------------------------- localhost 127.0.0.1 ---------------------------------------------------- ------------[ pap-secrets ]------------------------ tate tatespass ???.???.???.?0 hoge hoge ???.???.???.?1 fuge fuge ???.???.???.?2 --------------------------------------------------- ------------[ pappasswd ]-------------------------- #!/usr/local/bin/ruby # pappasswd server require "socket" PROTOCOL = 16016; PAP_FILE = "/home/tateishi/work/pappasswd/pap-secrets"; CERT_FILE = "/home/tateishi/work/pappasswd/pap-hosts"; LOG_FILE = "/home/tateishi/work/pappasswd/pap-log"; def certify?(client,file=CERT_FILE) addr = client.peeraddr(); # get client info address = addr[3]; host = addr[2]; log = open(LOG_FILE,"a"); log.print(host + "\t" + address + "\t" + `date`); log.close(); f = open(file,"r"); while line = f.gets() line.chop!(); line_list = line.split(/[ \t]+/); if (line_list[0] == host)&&(line_list[1] == address) then f.close(); return TRUE; end; end; f.close(); return FALSE; end; serv = TCPserver.open(PROTOCOL); while TRUE ns = serv.accept(); # open client socket if ( ! certify?(ns)) then ns.close(); continue; end; ns.write("user name: "); user_name = ns.gets().chop(); # get a user name ns.write("old password: "); old_passwd = ns.gets().chop(); # get a old password ns.write("new password: "); new_passwd = ns.gets().chop(); # get a new password file = open(PAP_FILE,"r") i = 0; entry = Array.new(); while line = file.gets() line.chop!(); entry << line.split(/[ \t]+/); end; file.close(); file = open(PAP_FILE,"w"); for line_entry in entry if (line_entry[0]==user_name)&&(line_entry[1]==old_passwd) then line_entry[1] = new_passwd; ns.write("--------------------------\n"); ns.write("password is changed.\n"); ns.write("--------------------------\n"); end; file.print(line_entry.join("\t")); file.print("\n"); end; file.close(); ns.close(); # close a client end; ------------------------------------------------------------