home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 35 Internet
/
35-Internet.zip
/
srev13h.zip
/
ACCESCHK.RXX
< prev
next >
Wrap
Text File
|
1999-11-11
|
12KB
|
438 lines
/* Check acesss privs module for SRE-http. Uses contents of accessfile
Standard arguments on initialization: access_file, queue, semaphore
Caller places on queue: newq,newsem,AURL
This put on newq: amatch,privs,options,realm
amatch= entry number of match (0 if NOt match)
privs = entry privileges
options = CACHE NOSSI NOSSP
realm = realm to use for "ask client for id stuff"
Options and realm are often not available.
*/
parse upper arg accessfile, usequeue , USESEM, max_semwait,sport
mytid=dostid()
fo=pmprintf_sref(' SRE-http Access: thread, file, queue='||mytid', 'accessfile', 'usequeue,,sport)
cfgs_dir=value('SRE_CFGS_DIR',,'os2environment')
cfglist_file=cfgs_dir||'\CFGLIST.CFG'
defrealm=value('SREF_DEFREALM_FILE_TEMP',,'os2environment')
resetit:
if usequeue="" | USESEM="" then do
call pmprintf('SRE-http Access ERROR: initialization ERROR: '||usequeue)
exit
end
call set_access(accessfile)
foo=pmprintf_sref(' SRE-http Access: #entries='||naccess,,sport)
/* Initialization now done == start waiting for requests for access 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 error in access thread 'wow)
EXIT
end
end
wow=EVENTSEM_RESET(usesem)
if aq=-1 then
if queued()=0 then signal bakme
pull isit0
isit0=upper(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 Access ERROR: 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(isit,'*LIST*') then do
dog1=''
do mm=1 to urls.0
dog1=dog1||hosturls.mm '// ' urls.mm' , 'privs.mm' , 'realms.mm' ; 'opts.mm||'0d0a'x
end
a=rxqueue('s',newq)
push idnum ',' dog1
wow=eventsem_post(newsem)
signal bakme
end
if abbrev(strip(translate(isit)),'*RESET*') then do
parse var isit foo newfile .
if newfile<>' ' then accessfile=newfile
call set_access(accessfile)
foo=pmprintf_sref(' SRE-http Access: thread reset, #acesss entries='||naccess)
end
else do
if naccess=0 then do
dog1=' 0 '
end
else do
dog1=fig_access(isit,host_nickname)
end
a=rxqueue('s',newq)
push idnum ',' dog1
wow=eventsem_post(newsem)
end
signal bakme
iserror: /* jump here on an error */
signal off error ; signal off syntax
call pmprintf_sref(' Error in daemon ('usequeue'), exiting: 'sigl','rc)
a=rxqueue('d',usequeue)
call pmprintf(" Status= "a " shutting down "usequeue)
a=eventsem_close(usesem)
call pmprintf(" Status= "a " shutting down "usesem)
foo=value('SREF_REDO',1,'os2environment')
badt=value('SREF_ACCESS_BAD',1,'os2environment')
exit
/* ---------- */
fig_access:procedure expose urls. privs. opts. realms. nrealms realm_names. realm_privs. hosturls. usesem usequeue
parse arg inline,host_nickname
/*call pmprintf(' aceess for 'inline)*/
isdebug=0
if abbrev(inline,'++:') then do /* special code used by checksel utility */
inline=substr(inline,4)
isdebug=1
end
inline=strip(translate(inline,' ','000d0a09'x))
inline=translate(inline,'/','\')
inline=strip(inline,'l','/')
host_nickname=strip(upper(host_nickname))
/* got a request -- look for a POSSIBLY multiple wild-card match */
gotit=0 ; RESU=' '; gotit2=''
/* if superceding host, then first check host-specific entries */
if abbrev(host_nickname,'_!')<>0 then do
do mm=1 to urls.0
if hosturls.mm<>host_nickname then iterate
aresu=sref_wild_match(inline,urls.mm,resu)
if aresu=0 then iterate /* no match */
if aresu=-1 then do /* exact match */
gotit=mm
gotit2=urls.mm
leave
end
resu=aresu
GOTIT=MM
gotit2=urls.mm
end
end
/* no host specfic match, and not strict-superceding host? try defaults */
if gotit=0 & abbrev(host_nickname,'_!!')=0 then do
do mm=1 to urls.0
if abbrev(host_nickname,'_!')=1 & hosturls.mm<>'' then iterate /* don't check superceding host entries */
if hosturls.mm<>host_nickname & hosturls.mm<>'' then iterate
aresu=sref_wild_match(inline,urls.mm,resu)
/*call pmprintf(inline' 'mm' chk 'urls.mm'='aresu)*/
if aresu=0 then iterate /* no match */
if aresu=-1 then do /* exact match */
gotit=mm
gotit2=urls.mm
leave
end
resu=aresu
GOTIT=MM
gotit2=urls.mm
end
end
if gotit=0 then return gotit
pgot=privs.gotit
/*call pmprintf(' gotit 'gotit', 'pgot)*/
if realms.gotit<>"" then do /* find realm privs? */
do nn1=1 to nrealms
if realms.gotit=realm_names.nn1 then do
pgot=pgot||' '||realm_privs.nn1
leave
end
end
end
gotitx=gotit
if isdebug=1 then gotitx=gotitx' 'gotit2
return gotitx ' , ' pgot ',' opts.gotit ', ' realms.gotit
/* ---------------- */
/* read and set up access privs */
set_access:
parse arg afile
naccess=0
nrealms=0
urls.0=0
a=sref_fileread(afile,'ULINES',,'E') /* read it to a stem variable */
foo=do_extends(0)
if a=0 then do
foo=pmprintf_sref(' SRE-http Access ERROR: ERROR reading access-file: '||afile,,sport)
return 0
end
foo=add_cfglist('ACCESS','ACCESS.IN') /*augment the ULINES stem variable, using CFGLIST.CFG files */
foo=add_defrealm('ACCESS')
do mm=1 to ULINES.0
t1=strip(translate(ULINES.mm,' ','0d0a09'x))
if abbrev(t1,';')=1 | t1=' 'then
iterate
ahost=' '
t1w=strip(upper(word(t1,1)))
if right(t1w,2)='//' then do
ahost=left(t1w,length(t1w)-2)
t1=strip(delword(t1,1,1))
end
if upper(word(t1,1))='!REALM' then do
nrealms=nrealms+1
parse upper var t1 foo1 realm_names.nrealms realm_privs.nrealms
iterate
end
/* parse var t1 aurl privs ',' options ',' realm */
parse var t1 aurl privs ',' options ',' realm
naccess=naccess+1
aurl=strip(aurl)
aurl=translate(aurl,'/','\')
aurl=strip(aurl,'l','/')
urls.naccess=translate(aurl)
privs.naccess=translate(strip(privs))
opts.naccess=translate(strip(options))
realms.naccess=strip(realm)
hosturls.naccess=translate(strip(ahost))
end
urls.0=naccess
return 0
/************/
/* Redo ULINES, by treating lines starting with , as continuation lines */
do_extends:procedure expose ULINES.
if ULINES.0=0 then return 0
isnew=1
tmps.1=ULINES.1
do mm=2 to ULINES.0
ali=strip(ULINES.mm)
if abbrev(ali,',')=0 then do
isnew=isnew+1
tmps.isnew=ULINES.mm
end
else do
tmps.isnew=tmps.isnew||substr(ali,2)
end
end
do mm=1 to isnew
ULINES.mm=tmps.mm
end
ULINES.0=isnew
return 0
/**********************************/
/* Add entries to ulines. variable, from the defrealm_temp file.
Note that this file only has the appropriate port entries
in it */
add_defrealm:procedure expose defrealm ulines.
parse upper arg atype
atype=strip(atype)
crlf='0d0a'x
/*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=ulines.0+1
ulines.ii=aline
ulines.0=ii
end
/**********************************/
/* Add entries to ULINES. variable, from the ATYPE files listed in the CFGLIST.CFG file
(but only for port SPORT)
*/
add_cfglist:procedure expose ULINES. cfglist_file sport cfgs_dir
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')
crlf='0d0a'x
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 ULINES.0 /* retain old ULINES */
ULINEStmp.mm=ULINES.mm
end
ULINEStmp.0=ULINES.0
do mm=1 to ufiles.0
afile=ufiles.mm.!file
ahost=ufiles.mm.!host
a=sref_fileread(afile,'ULINES',,'E') /* read it to a stem variable */
if a=0 | ULINES.0=0 then do
call pmprintf(' SRE-http 'atype': WARNING**: bad auxillary file: '||afile)
iterate
end
foo=do_extends(1) /* fixup ULINES. */
call pmprintf(' SRE-http '||lower(atype)||': adding from 'AHOST ' specific file 'afile ',' ULINES.0)
do ii=1 to ULINES.0
aline=strip(ULINES.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=ULINEStmp.0+1
ULINEStmp.ii2=aline
ULINEStmp.0=ii2
end
end
do mm=1 to ULINEStmp.0
ULINES.mm=ULINEStmp.mm
end
ULINES.0=ULINEStmp.0
drop ULINEStmp.
return 1