home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / ONLINE / SREFPRC1 / ADDPRIVS.SRF < prev    next >
Text File  |  1997-06-30  |  5KB  |  152 lines

  1. /* add an entry to the dynamic privlieges list, and remove expired ones.
  2.  
  3. call as: status=sref_add_priv(privlist,expire_minutes,verbose,port,host_nickname,user,enmadd)
  4.     privlist is REQUIRED. It is the list of privileges to add
  5.     expire_minutes is recommented. It is how long these privileges should 
  6.        be active for. If not specified, 15 minutes will be used
  7.     verbose is optional, it controls extent of pmprintf output
  8.     port is optional. It is the http port. If not specified, it is extracted from goserve
  9.     host_nickname is optional, but recommended in multi-host environments. 
  10.        It is the host nickname. If not specified, the "generic"
  11.        (no host nickname) host is used. NOTE THAT "GENERIC" ENTRIES ONLY
  12.        APPLY TO REQUEST TO THE "GENERIC" IP name.
  13.     user is optiona. It is the client's ip address. If not specified, it is extracted from goserve.
  14.     enmadd is optional. It is used to lookup environment strings. If not specified, it is constructed.
  15.  
  16. Return:
  17.    status=0 if a problem, otherwise returns # of entries
  18.  
  19.   Entries are kept in a file named _dynpriv.nnn, where nnn is the port number,
  20.   and the file is located in the Goserve working directory.
  21.  
  22.    Entries have the form:
  23.    ip.address  expire  host_nickname , privs_list
  24.       ip.address =  numeric ip address
  25.       expire =  time of expiration (in nnnnn.mmmmmm format)
  26.       host_nickname = which host_nickname does this correpond to
  27.                 (or blank, if not host specific)
  28.       privs_list = list of privileges (at least one)
  29.  
  30. */
  31.  
  32. sref_add_privs:
  33. parse upper arg privlist,expire_minutes,verbose,port,host_nickname,user,enmadd
  34.  
  35. numeric digits 11
  36. crlf = '0d0a'x
  37.  
  38. d1=date('b')
  39. t1=time('m')/(24*60)
  40. nowtime=d1+t1
  41.  
  42. if port=" " then port=extract('serverport')
  43. if user=" " then user=extract('clientaddr')
  44. if verbose=" " then verbose=0
  45. if enmadd=" " then enmadd="SREF_"||port||"_"
  46. if expire_minutes=' ' then expire_minutes=15
  47. if datatype(expire_minutes)<>"NUM" then expire_minutes=15
  48.  
  49. /* check for file. If not there, give up */
  50. wdir=value(enmadd||"TEMPDATA_DIR",,'os2environment')
  51. wdir=strip(wdir,'t','\')||'\'
  52. dafile=wdir||"_ADDPRIV."||port
  53.  
  54. aa=stream(dafile,'c','query exists')
  55. if aa="" then do
  56.   if verbose>0 then call pmprintf_sref(' Creating add-privileges file: 'dafile)
  57.   call lineout dafile,' ; the add-privileges file. DO NOT EDIT!  '
  58.   call lineout dafile
  59. end
  60.  
  61. /* got it, read it in */
  62. filelines.0=0
  63. nlines=file_lines2(dafile)
  64. if nlines<0 then do
  65.   if verbose>0 then call pmprintf_sref(' Problem reading add-privileges file: 'dafile)
  66.   foo=stream(dafile,'c','close')
  67.   return 0
  68. end
  69.  
  70. newlist=""
  71. ndone=0
  72. /* delete expired or identical  entries */
  73. do mm=1 to nlines
  74.    eeo=filelines.mm
  75.   if eeo=" " | abbrev(eeo,';')=1 then iterate
  76.  
  77.    parse  var filelines.mm ipaddress expires thehost ',' privs
  78.    thehost=strip(thehost); privs=strip(privs)
  79.    ipaddress=strip(ipaddress);expires=strip(expires)
  80.  
  81. /* drop if expired, or if identical to current entry */
  82.    if expires<nowtime then do
  83.        iterate
  84.    end
  85.    if ipaddress=user & thehost=host_nickname  & privs=privlist then do
  86.        iterate
  87.    end
  88.  
  89.    newlist=newlist||filelines.mm||crlf
  90.    ndone=ndone+1
  91. end
  92.  
  93. nowdate=nowtime+ (expire_minutes/(24*60))
  94. newlist=newlist||user||' '||nowdate||' '||host_nickname||' , '||privlist
  95. foo=stream(dafile,'c','close')
  96. chewtoy=sysfiledelete(dafile)
  97. if chewtoy<>0 then do
  98.   if verbose>0 then call pmprintf_sref(' Warning: could not delete old add-privileges file: ' chewtoy)
  99.   return 0
  100. end
  101. wow=charout(dafile,newlist,1)     
  102. if wow>0 then do
  103.   if verbose>0 then call pmprintf_sref(' Warning: could not completely write add-privileges file: ' foo)
  104. end
  105. foo=stream(dafile,'c','close')
  106. return ndone
  107.  
  108. /* -------------------------------------------------------------- */
  109. /* FILE_LINES:  Get a file, parse into a "lines" stem variable
  110. .  Read in a file, but first check to see if openable, and if
  111. .  so, open and  read.  After reading, split into logical lines,
  112. .  using the eol character ('0d0a'x  by default), and return
  113. .  each of these lines in the filelines. stem variable.
  114. .  Note: filelines.0 holds # of lines; also, the number of lines
  115. .  is returned (so if 0 returned, failure probably caused by no such file)
  116. .  Usage:
  117. .   filelines.0= 0 ;  nlines=grab_file_lines(afile,30,optional_eol_delimiter)
  118. .   (filelines.1 to filelines.(filelines.0) contain afile)
  119. */
  120. /* ------------------------------------------------------------- */
  121.  
  122. file_lines2:procedure expose filelines. verbose
  123. parse arg dofile
  124.  
  125. crlf = '0d0a'x
  126.  
  127. aneol=crlf
  128.  
  129. ause=sref_open_read(dofile,30,'OPEN')
  130. if ause<0 then  do                /* couldn't get it */
  131.   if verbose>1 then say " Error opening  file: " ause
  132.   return -1
  133. end
  134. lily=chars(dofile)
  135. ause=charin(dofile,1,lily)
  136. ause=translate(ause,' ','001a'x)
  137. ause=upper(ause)
  138. /* got a file, let's parse it */
  139. if filelines.0<>0 then say " Warning: overwriting filelines stem variable "
  140. filelines.0=0
  141. iz=0
  142. do until ause=""
  143.   parse  var ause eeo (aneol) ause
  144.   eeo=strip(eeo)
  145.   iz=iz+1
  146.   filelines.iz=strip(eeo)
  147. end
  148. filelines.0=iz
  149. return filelines.0
  150.  
  151.  
  152.