/* Passwd Server - DMS - march 98 - by Sylvain HUET */ /* Modified - feb 99 - by Patrice FAVRE */ defcom Cquizz=quizz S I I;; defcom Cedit=edit S;; struct Qz=[cliQz:CLIENT,txtQz:S,passQz:S,numQz:I,kQz:I]mkQz;; typeof quizz=[[S S] r1];; typeof qu=[Qz r1];; typeof edit=[CLIENT r1];; typeof dmifile=S;; fun chgbanner(l,q)= if l==nil then q else let l->[a n] in if strcmp hd a "passwd" then a::chgbanner n q else chgbanner n q;; fun getps(l)= if l==nil then nil else let l->[[a b] n] in ("passwd"::a::b::nil)::getps n;; fun gettexts(l)= if l==nil then nil else let l->[[t _] n] in ("*"::t::nil)::gettexts n;; fun byboth(a,z)=let z->[c i] in c==a.cliQz && i==a.numQz;; fun sndevt(i,res,cli)= _DMSevent this cli "log" strcatn "passwd "::(itoa i)::" by ":: (_DMSgetLogin cli)::" : "::res::nil nil; _DMSevent this cli strcat res itoa i nil nil;; fun __answer(i,ps)= let search_in_list qu @byboth [DMSsender i ] -> x in if x==nil then nil else let if ps!=nil && !strcmp ps x.passQz then "true" else "false" -> res in (set qu=remove_from_list qu x; sndevt i res DMSsender);; fun removecli(l,c)= if l==nil then nil else let l->[a n] in if a.cliQz==c then removecli n c else a::removecli n c;; fun logout(cli)= set qu=removecli qu cli; set edit=remove_from_list edit cli; 0;; fun calcpasswd(i,param)= let if i==nil then let hd strextr param -> l in [hd l hd tl l] else nth_list quizz i ->[tx ps] in let rand -> k in [tx ps _getlongname strcat ps itoa k "" "#" k];; fun activate(from,cli,action,param,rep)= if !_DMSclientAlive cli then nil else if !strcmp substr action 0 6 "passwd" then let if !strcmp action "passwd" then nil else atoi substr action 6 100 -> i in let calcpasswd i param -> [txt ps psk k] in if ps==nil || !strlen ps then sndevt i "true" cli else (_DMScreateClientDMI this cli nil; _DMSsend this cli Cquizz [txt i k]; set qu=(mkQz[cli txt psk i k])::qu; 0) else if !strcmp action "edit" then (_DMScreateClientDMI this cli nil; _DMSsend this cli Cedit [strbuild gettexts quizz]; set edit=cli::remove_from_list edit cli; 0) else nil;; fun getQuizz(l)= if l==nil then nil else let l->[q n] in if !strcmp hd q "passwd" then ([hd tl q hd tl tl q])::getQuizz n else getQuizz n;; fun IniDMI(file)= set dmifile=file; let strextr _getpack _checkpack file ->l in (set quizz=getQuizz l); srand time; _DMSregisterDMI this @activate nil @logout nil;; fun updatepsw(l,q)= if l==nil then nil else let l->[a n] in let hd q ->[_[t[p _]]] in (if t==nil then nil else mutate a<-[t _]; if p==nil then nil else mutate a<-[_ p]; a::updatepsw n tl q);; fun __setpsw(s)= if !findList edit DMSsender then nil else (set quizz=updatepsw quizz strextr s; _storepack strbuild chgbanner strextr _getpack _checkpack dmifile getps quizz dmifile; _DMSevent this nil "log" strcatn "passwd_changed_by "::(_DMSgetLogin DMSsender)::nil nil);;