home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 35 Internet
/
35-Internet.zip
/
srev13g.zip
/
USERCHK.RXX
< prev
next >
Wrap
Text File
|
1999-06-19
|
14KB
|
486 lines
/* Check users/password module for SRE-http. 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
Note: no longer supports "USERFILES.". Instead, read files from
the CFGLIST.CFG file (in the CFGS\ subdirectory)
*/
/******************* END OF USER CONFIGURABLE PARAMETERS ******************/
parse upper arg userfile, usequeue , USESEM , max_semwait,logon_limit,sport
mytid=dostid()
foo=pmprintf_sref(' SRE-http Users: thread, file, queue='||mytid', 'userfile', 'usequeue,,sport)
foo=pmprintf_sref(' SRE-http Users: logon limit='||logon_limit,,sport)
resetit:
if usequeue="" | USESEM="" then do
call pmprintf('SRE-http Users ERROR: initialization ERROR: '||usequeue)
exit
end
crlf='0d0a'x
logfailb=1
logfaile=0
cfgs_dir=value('SRE_CFGS_DIR',,'os2environment')
cfglist_file=cfgs_dir||'\CFGLIST.CFG'
defrealm=value('SREF_DEFREALM_FILE_TEMP',,'os2environment')
call set_users(userfile) /* see if anything in CFGLIST.CFG */
foo=pmprintf_sref(' SRE-http Users: #users='||nusers||', #wildcards= '||nwilds,,sport)
/* 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(' 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(' SRE-http Users: missing queue or semaphore ')
signal bakme
end
newq=strip(newq); newsem=strip(newsem) ;ISIT=STRIP(ISIT)
if abbrev(strip(translate(isit)),'*LIST*') then do
dog1=''
do mm=1 to names.0
raa=hostids.mm' // 'names.mm ',' pwds.mm ',' privs.mm
dog1=dog1||raa||crlf
end
do mm=1 to wildpwds.0
raa=wildhosts.mm' // * ,' wildpwds.mm ',' wildprivs.mm
dog1=dog1||raa||crlf
end
a=rxqueue('s',newq)
dog1=idnum','dog1
push dog1
wow=eventsem_post(newsem)
signal bakme
end
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)
foo=pmprintf_sref(' SRE-http Users: reset: #users='||nusers||', #wildcards= '||nwilds,,sport)
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
iserror:
signal off error ; signal off syntax
call pmprintf('SRE-http: 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('SRE-http: 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 crlf
parse arg inline, host_nickname
host_nickname=upper(strip(host_nickname))
acum=0
inline=translate(inline,' ','000d0a09'x)
parse upper var inline atype 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 atype='DIGEST' & username=' ' then return -acum
if atype='BASIC' & (username=' ' | password=' ') then return -acum
oo=arraysearch('names','reslines',username,'X')
/* probably,there will be only 1 match. But in case there isn't,
check out several possible passwords. OR, if no password,
return the first password (along with the privset) */
ok=0
thematch=0
do mm=1 to oo /* check the username matches */
m1=reslines.mm
if hostids.m1<>host_nickname & hostids.m1<>"" then
iterate
if m1=" " then iterate
if password=UPPER(pwds.m1) | atype='DIGEST' then do /* name and password match ! */
ok=m1 /* or let DIGEST do it */
if hostids.m1<>"" then leave /* if not, allow host specific to overwrite */
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)
if atype='DIGEST' then
thematch=pwds.ok
else
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.mm<>host_nickname & wildhosts.mm<>"" then
iterate
if password=wildpwds.mm | wildpwds.mm='*' then do /* name and password match ! */
theprivs=wildprivs.mm
thematch=wildorig.mm
if wildhosts.mm<>"" then leave /* if not, allow host specific to overwrite */
END
end
end
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 -- from generic list, and from cfglist.cfg list */
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 */
if a=0 then do
call pmprintf(' SRE-http Users ERROR: ERROR reading user-file: '||afile)
return 0
end
foo=do_extends(1)
if ulist.0>0 then do /* convert tabs to spaces */
do ir=1 to ulist.0
ulist.ir=translate(ulist.ir,' ','0009'x)
end
end
foo=add_cfglist('USERS','USERS.IN') /*augment the ulist stem variable, using CFGLIST.CFG files */
foo=add_defrealm('USER')
MKK=0
DO KK=1 TO ULIST.0
AAA=STRIP(ULIST.KK)
IF ABBREV(AAA,';')=1 | AAA='' THEN ITERATE
MKK=MKK+1
ULIST.MKK=AAA
END
ULIST.0=MKK
ause2=arraysort('ulist',,,,,,'I')
do zmm=1 to ulist.0
t1=strip(ulist.zmm)
if t1=" " then iterate
if abbrev(t1,';')=1 then iterate
foo=upper(strip(word(t1,1)))
ahost=' '
if right(foo,2)='//' then do
ahost=upper(left(foo,length(foo)-2))
parse var t1 ffo aname apwd aprivs
parse UPPER var t1 ffo aname aFOO aprivs
end
else DO
parse var t1 aname apwd aprivs
parse upper var t1 aname aFOO aprivs
END
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. crlf
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
/**********************************/
/* Add entries to ULIST. variable, from the ATYPE files listed in the CFGLIST.CFG file
(but only for port SPORT)
*/
add_cfglist:procedure expose ulist. cfglist_file sport cfgs_dir crlf
parse upper arg atype,defname
atype=strip(atype)
if cfglist_file='' then return /* nothing to do */
/* look for files */
foo=translate(stream(cfglist_file,'c','open read'))
if abbrev(foo,'READY')<>1 then do
call pmprintf('SRE-http: ' atype ' Warning: Unable to open cfglist.cfg ')
return 0 /* unable to open */
end
inj=stream(cfglist_file,'c','query size')
if inj=0 | inj='' then return 0 /* empty file */
astuff=charin(cfglist_file,1,inj)
foo=stream(cfglist_file,'c','close')
astuff=astuff||crlf||' ' /* place an elephant in cairo */
/* determine which files apply to this atype and port, by readling CFGLIST.CFG */
mm=0
/* note: file is organized in blocks */
curport=80 /* defaults port and host */
curhost=''
curfile=''
do forever /* for all blocks in file */
if astuff='' then leave /* all done (note we always put an elephant in cairo */
parse var astuff aline (crlf) astuff
if abbrev(aline,';')=1 then iterate /* ignore comments */
if aline='' then do /* block end */
if curport<>sport | curfile='' then do /* different port, or this atype file not specified */
nop
end
else do /* otherwise, add this entry to filelist */
mm=mm+1
ufiles.mm.!host=curhost
ufiles.mm.!file=curfile
end
curport=80 ; curhost='' ; curfile='' /* clear block */
iterate
end
/* process an entry in this block */
parse upper var aline ltype ':' lstuff ;ltype=strip(ltype) ; lstuff=strip(lstuff)
select
when ltype='PORT' then curport=lstuff
when ltype='HOST' then curhost=lstuff
when abbrev(ltype,atype)=1 then do
curfile=strip(translate(lstuff,'\','/'),'l','\')
if pos(':',curfile)=0 then curfile=cfgs_dir||'\'||curfile
end
when ltype='*' then do
curfile=strip(translate(lstuff,'\','/'),,'\')
if pos(':',curfile)=0 then curfile=cfgs_dir||'\'||curfile
curfile=stream(curfile'\'defname,'c','query exists')
end
otherwise nop
end
end
/* done reading cfglist; add entries from appropriate files */
if mm=0 then return 1 /* no auxillary files of this type */
ufiles.0=mm
do mm=1 to ulist.0 /* retain old ulist */
ulisttmp.mm=ulist.mm
end
ulisttmp.0=ulist.0
do mm=1 to ufiles.0
afile=ufiles.mm.!file
ahost=ufiles.mm.!host
a=sref_fileread(afile,'ulist',,'E') /* read it to a stem variable */
if a=0 | ulist.0=0 then do
call pmprintf(' SRE-http 'atype': WARNING**: bad auxillary file: '||afile)
iterate
end
foo=do_extends(1) /* fixup ulist. */
call pmprintf('SRE-http 'atype': adding from 'AHOST ' specific file 'afile ',' ulist.0)
do ii=1 to ulist.0
aline=strip(ulist.ii)
if ALINE=' ' then iterate
aline=translate(aline,' ','0009'x)
if abbrev(strip(aline),';')=1 then iterate
parse var aline aw1 .
if pos('//',aw1)>0 then do
call pmprintf('SRE-http: 'atype 'warning: disallowed auxillary entry: 'aline)
iterate
end
if ahost<>'' then aline=ahost||'// '||aline
ii2=ulisttmp.0+1
ulisttmp.ii2=aline
ulisttmp.0=ii2
end
end
do mm=1 to ulisttmp.0
ulist.mm=ulisttmp.mm
end
ulist.0=ulisttmp.0
drop ulisttmp.
return 1
/**********************************/
/* Add entries to ulist. variable, from the defrealm_temp file.
Note that this file only has the appropriate port entries
in it */
add_defrealm:procedure expose defrealm ulist. crlf
parse upper arg atype
atype=strip(atype)
/*call pmprintf(' xxx 'atype' 'defrealm) */
if defrealm='' then return 0
aa=sref_open_read(defrealm,15,'READ')
if aa<=0 then return 0
ii=stream(defrealm,'c','query size')
if ii=0 | ii='' then return 0
stuff=charin(defrealm,1,ii)
foo=stream(defrealm,'c','close')
do forever
if stuff="" then return 1
parse var stuff aline (crlf) stuff
if abbrev(aline,';')=1 then iterate
parse var aline btype ':' aline
if btype<>atype then iterate
ii=ulist.0+1
ulist.ii=aline
ulist.0=ii
end