home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Spezial
/
SPEZIAL2_97.zip
/
SPEZIAL2_97.iso
/
ANWEND
/
ONLINE
/
SREFPRC1
/
ADDPRIVS.SRF
< prev
next >
Wrap
Text File
|
1997-06-30
|
5KB
|
152 lines
/* add an entry to the dynamic privlieges list, and remove expired ones.
call as: status=sref_add_priv(privlist,expire_minutes,verbose,port,host_nickname,user,enmadd)
privlist is REQUIRED. It is the list of privileges to add
expire_minutes is recommented. It is how long these privileges should
be active for. If not specified, 15 minutes will be used
verbose is optional, it controls extent of pmprintf output
port is optional. It is the http port. If not specified, it is extracted from goserve
host_nickname is optional, but recommended in multi-host environments.
It is the host nickname. If not specified, the "generic"
(no host nickname) host is used. NOTE THAT "GENERIC" ENTRIES ONLY
APPLY TO REQUEST TO THE "GENERIC" IP name.
user is optiona. It is the client's ip address. If not specified, it is extracted from goserve.
enmadd is optional. It is used to lookup environment strings. If not specified, it is constructed.
Return:
status=0 if a problem, otherwise returns # of entries
Entries are kept in a file named _dynpriv.nnn, where nnn is the port number,
and the file is located in the Goserve working directory.
Entries have the form:
ip.address expire host_nickname , privs_list
ip.address = numeric ip address
expire = time of expiration (in nnnnn.mmmmmm format)
host_nickname = which host_nickname does this correpond to
(or blank, if not host specific)
privs_list = list of privileges (at least one)
*/
sref_add_privs:
parse upper arg privlist,expire_minutes,verbose,port,host_nickname,user,enmadd
numeric digits 11
crlf = '0d0a'x
d1=date('b')
t1=time('m')/(24*60)
nowtime=d1+t1
if port=" " then port=extract('serverport')
if user=" " then user=extract('clientaddr')
if verbose=" " then verbose=0
if enmadd=" " then enmadd="SREF_"||port||"_"
if expire_minutes=' ' then expire_minutes=15
if datatype(expire_minutes)<>"NUM" then expire_minutes=15
/* check for file. If not there, give up */
wdir=value(enmadd||"TEMPDATA_DIR",,'os2environment')
wdir=strip(wdir,'t','\')||'\'
dafile=wdir||"_ADDPRIV."||port
aa=stream(dafile,'c','query exists')
if aa="" then do
if verbose>0 then call pmprintf_sref(' Creating add-privileges file: 'dafile)
call lineout dafile,' ; the add-privileges file. DO NOT EDIT! '
call lineout dafile
end
/* got it, read it in */
filelines.0=0
nlines=file_lines2(dafile)
if nlines<0 then do
if verbose>0 then call pmprintf_sref(' Problem reading add-privileges file: 'dafile)
foo=stream(dafile,'c','close')
return 0
end
newlist=""
ndone=0
/* delete expired or identical entries */
do mm=1 to nlines
eeo=filelines.mm
if eeo=" " | abbrev(eeo,';')=1 then iterate
parse var filelines.mm ipaddress expires thehost ',' privs
thehost=strip(thehost); privs=strip(privs)
ipaddress=strip(ipaddress);expires=strip(expires)
/* drop if expired, or if identical to current entry */
if expires<nowtime then do
iterate
end
if ipaddress=user & thehost=host_nickname & privs=privlist then do
iterate
end
newlist=newlist||filelines.mm||crlf
ndone=ndone+1
end
nowdate=nowtime+ (expire_minutes/(24*60))
newlist=newlist||user||' '||nowdate||' '||host_nickname||' , '||privlist
foo=stream(dafile,'c','close')
chewtoy=sysfiledelete(dafile)
if chewtoy<>0 then do
if verbose>0 then call pmprintf_sref(' Warning: could not delete old add-privileges file: ' chewtoy)
return 0
end
wow=charout(dafile,newlist,1)
if wow>0 then do
if verbose>0 then call pmprintf_sref(' Warning: could not completely write add-privileges file: ' foo)
end
foo=stream(dafile,'c','close')
return ndone
/* -------------------------------------------------------------- */
/* FILE_LINES: Get a file, parse into a "lines" stem variable
. Read in a file, but first check to see if openable, and if
. so, open and read. After reading, split into logical lines,
. using the eol character ('0d0a'x by default), and return
. each of these lines in the filelines. stem variable.
. Note: filelines.0 holds # of lines; also, the number of lines
. is returned (so if 0 returned, failure probably caused by no such file)
. Usage:
. filelines.0= 0 ; nlines=grab_file_lines(afile,30,optional_eol_delimiter)
. (filelines.1 to filelines.(filelines.0) contain afile)
*/
/* ------------------------------------------------------------- */
file_lines2:procedure expose filelines. verbose
parse arg dofile
crlf = '0d0a'x
aneol=crlf
ause=sref_open_read(dofile,30,'OPEN')
if ause<0 then do /* couldn't get it */
if verbose>1 then say " Error opening file: " ause
return -1
end
lily=chars(dofile)
ause=charin(dofile,1,lily)
ause=translate(ause,' ','001a'x)
ause=upper(ause)
/* got a file, let's parse it */
if filelines.0<>0 then say " Warning: overwriting filelines stem variable "
filelines.0=0
iz=0
do until ause=""
parse var ause eeo (aneol) ause
eeo=strip(eeo)
iz=iz+1
filelines.iz=strip(eeo)
end
filelines.0=iz
return filelines.0