home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Spezial
/
SPEZIAL2_97.zip
/
SPEZIAL2_97.iso
/
ANWEND
/
ONLINE
/
SREFV12J
/
USERCHK.RXX
< prev
next >
Wrap
Text File
|
1997-06-30
|
8KB
|
285 lines
/* Check users/password module for SRE-FILTER. Uses contents of USERfile */
/* Initializae with userfile,usequeue,usesem
call (via queues and semaphore) -- return q, return sem ,USERNAME PASSWORD
returns: no match : 0
match: N priv_list
where N is the "# in list of match", and priv_list is space delimited
*/
parse upper arg userfile, usequeue , USESEM , max_semwait,logon_limit
call pmprintf_sref(' SRE-FILTER Users Thread: Userfile='||userfile)
call pmprintf_sref(' SRE-FILTER Users Thread: queue='||usequeue)
call pmprintf_sref(' SRE-FILTER Users Thread: semaphore='||usesem)
call pmprintf_sref(' SRE-FILTER Users Thread: logon limit='||logon_limit)
mytid=dostid()
call pmprintf_sref(' SRE-FILTER Users thread: thread id='||mytid)
resetit:
if usequeue="" | USESEM="" then do
call pmprintf_sref('SRE-FILTER Users thread: initialization ERROR: '||usequeue)
exit
end
logfailb=1
logfaile=0
call set_users(userfile)
if nusers+nwilds=0 then do
call pmprintf_sref(' SRE-FILTER Users thread: Warning: No valid entries in users file:'||userfile)
end
else do
call pmprintf_sref(' SRE-FILTER Users thread: #users='||nusers||', #wildcards= '||nwilds)
end
/* Initialization now done == start waiting for requests for user info */
signal on error name iserror
signal on syntax name iserror
bakme:
a=rxqueue('s',usequeue)
aq=queued()
if aq=0 then do
WOW=EVENTSEM_WAIT(USESEM,max_semwait)
aq=-1
if wow=640 then do
signal bakme
end
IF WOW<>0 THEN do /* FATAL ERROR */
call pmprintf_sref(' Fatal semaphore error in User thread ')
EXIT
end
end
wow=EVENTSEM_RESET(usesem)
if aq=-1 then
if queued()=0 then signal bakme
pull isit0
goobs:
isit0=translate(isit0,' ','000d0a09'x)
if isit0=" " then signal bakme
parse var isit0 idnum ',' newq ',' newsem ',' ISIT
parse var idnum idnum host_nickname
if newq="" | newsem="" then do
call pmprintf_sref(' SRE-FILTER Users Thread: missing queue or semaphore ')
signal bakme
end
newq=strip(newq); newsem=strip(newsem) ;ISIT=STRIP(ISIT)
if abbrev(strip(translate(isit)),'*DIE*') then
exit
if abbrev(strip(translate(isit)),'*RESET*') then do
parse var isit foo newfile .
if newfile<>' ' then userfile=newfile
call set_users(userfile)
call pmprintf_sref('SRE-Filter Users Thread: Reread user file: 'userfile)
end
else do
dog1=fig_User(isit,host_nickname)
a=rxqueue('s',newq)
dog1=idnum','dog1
push dog1
wow=eventsem_post(newsem)
end
signal bakme
serror:
signal off error ; signal off syntax
call pmprintf_sref('SRE-Filter: error in Users thread ')
a=rxqueue('d',usequeue)
a=rxqueue('c',usequeue)
a=eventsem_close(usesem)
a=eventsem_create(usesem)
a=rxqueue('s',newq)
push idnum ', 0 '
wow=eventsem_post(newsem)
call pmprintf_sref('SRE-Filter: done resetting Users thread ')
signal on error name iserror
signal on syntax name iserror
signal bakme
exit
/* ---------- */
fig_User:procedure expose names. pwds. orig. privs. wildorig. wildpwds. wildprivs. ,
hostids. wildhosts. logfailb logfaile logfail. logon_limit
parse arg inline, host_nickname
host_nickname=upper(strip(host_nickname))
acum=0
inline=translate(inline,' ','000d0a09'x)
parse upper var inline username password who .
who=strip(who)
/* got a request -- look for a match */
issec=time('s')
/* see if logon_limit has been exceeded for this ip address */
if logon_limit>0 & logfailb <= logfaile & who<>' ' then do
if issec<logfail.logfaile.istime then do /* reset at midnite */
drop logfail.
logfailb=0; logfaile=1
end
newb=0
do ikk=logfailb to logfaile
if logfail.ikk.istime < (issec-60) then do
newb=ikk ; iterate
end
if logfail.ikk.isip=who then acum=acum+1
if acum>logon_limit then leave
end
if newb>0 then do
do oo=logfailb to newb
drop logfail.oo.
end
logfailb=newb+1
end
if acum>logon_Limit then do
return -(acum+1)
end
end
if username=' ' | password=' ' then do
return -acum
end
oo=arraysearch('names','reslines',username,'SF')
/* probably,there will be only 1 match. But in case there isn't,
check out several possible passwords */
ok=0
thematch=0
do mm=1 to oo
m1=reslines.mm
if hostids.m1<>host_nickname & hostids.m1<>"" then
iterate
if m1=" " then iterate
if password=pwds.m1 then do /* name and password match ! */
ok=m1
leave
end
if pwds.m1='*' & ok=0 then do /*note if it's a wild card match (first one only */
ok=-m1
end
end
/* if ok<>0, then got a match. So return results */
if ok <> 0 then do /* ok<0 means "wildcarded password */
ok=abs(ok)
thematch=orig.ok
theprivs=privs.ok
end
/* no exact match -- try wildcard list */
if ok=0 then do
do mm=1 to wildpwds.0
if wildhosts.m1<>host_nickname & wildhosts.m1<>"" then
iterate
if password=wildpwds.mm then do /* name and password match ! */
theprivs=wildprivs.mm
thematch=wildorig.mm
leave
END
end
end
/* crlf='0d0a'x*/
if thematch=0 then do
amess=-(acum+1)
if logon_limit>0 & who<>' ' then do
logfaile=logfaile+1
logfail.logfaile.isip=who
logfail.logfaile.istime=issec
end
end
else do
amess=thematch||' '||theprivs
end
amess=translate(amess,' ','000d0a09'x)
return amess
/* ---------------- */
/* read and set up users/pwds */
set_users:
parse arg afile
nwilds=0 ; nusers=0 ; got1=0
names.0=0 ; wildpwds.0=0
a=sref_fileread(afile,'ulist',,'E') /* read it to a stem variable */
foo=do_extends(1)
if a=0 then do
call pmprintf_sref(' SRE-FILTER Users thread: ERROR reading user-file: '||afile)
return 0
end
ause2=arraysort('ulist',,,,,,'I')
do mm=1 to ulist.0
t1=translate(strip(ulist.mm))
if t1=" " then iterate
if abbrev(t1,';')=1 then iterate
foo=upper(strip(word(t1,1)))
ahost=' '
if right(foo,2)='//' then do
ahost=left(foo,length(foo)-2)
parse upper var t1 ffo aname apwd aprivs
end
else
parse upper var t1 aname apwd aprivs
got1=got1+1
if aname='*' then do
nwilds=nwilds+1
wildpwds.nwilds=strip(apwd) ; wildprivs.nwilds=strip(aprivs)
wildorig.nwilds=got1
wildhosts.nwilds=ahost
end
else do
nusers=nusers+1
names.nusers=strip(aname)
pwds.nusers=strip(apwd) ; privs.nusers=strip(aprivs)
orig.nusers=got1
hostids.nusers=ahost
end
end
names.0=nusers
wildpwds.0=nwilds
return 0
/************/
/* Redo ulist, by treating lines starting with , as continuation lines */
do_extends:procedure expose ulist.
if ulist.0=0 then return
isnew=1
tmps.1=ulist.1
do mm=2 to ulist.0
ali=strip(ulist.mm)
if abbrev(ali,',')=0 then do
isnew=isnew+1
tmps.isnew=ulist.mm
end
else do
tmps.isnew=tmps.isnew||substr(ali,2)
end
end
do mm=1 to isnew
ulist.mm=tmps.mm
end
ulist.0=isnew
return 0