home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / gopher / Rice_CMS / gopher24 / gopsrvau.$exec < prev    next >
Encoding:
Text File  |  1993-01-25  |  6.3 KB  |  81 lines

  1. /*                                                                      00010000
  2.  *        Name: GOPSRVAU EXEC, authorization function                   00020000
  3.  *              returns TRUE (1) if the file/menu may be retrieved      00030000
  4.  *              returns FALSE (0) otherwise                             00040000
  5.  *        Date: 1993-Jan-18                                             00050000
  6.  *      Author: Rick Troth, Rice University, Information Systems        00060000
  7.  *                                                                      00070000
  8.  *              This file is part of CMS Gopher.                        00080000
  9.  */                                                                     00090000
  10.                                                                         00100000
  11. /*                                                                      00110000
  12.  *      Copyright 1993 Richard M. Troth.   This software was developed  00120000
  13.  *      with resources provided by Rice University and is intended      00130000
  14.  *      to serve Rice's user community.   Rice has benefitted greatly   00140000
  15.  *      from the free distribution of software,  therefore distribution 00150000
  16.  *      of unmodified copies of this material is not restricted.        00160000
  17.  *      You may change your own copy as needed.   Neither Rice          00170000
  18.  *      University nor any of its employees or students shall be held   00180000
  19.  *      liable for damages resulting from the use of this software.     00190000
  20.  */                                                                     00200000
  21.                                                                         00210000
  22. /* ---------------------------------------------------------- AUTHORIZED00220000
  23.  * Verify that the client is allowed access, based on IP addr or name.  00230000
  24.  * (we originally used an internal routine called IPA2C(),  but Arty's  00240000
  25.  * RXSOCKET provides an Inet_addr() function,  which is now preferred)  00250000
  26.  */                                                                     00260000
  27. AUTHORIZED:                                                             00270000
  28. Parse Upper Arg Client,AuthList                                         00280000
  29. If AuthList = "" Then Return 1                                          00290000
  30. ClientAddr = Inet_addr(Client)                                          00300000
  31.                                                                         00310000
  32. rc = Socket('GetHostByAddr', ClientAddr, 'ClientName')                  00320000
  33. If rc = "-1" Then ClientName = Client                                   00330000
  34. Say "Client looks like" ClientName Inet_ntoa(ClientAddr)                00340000
  35. Upper ClientName                                                        00350000
  36.                                                                         00360000
  37. allow = 1                                                               00370000
  38. Do While AuthList ^= ""                                                 00380000
  39.                                                                         00390000
  40.     Parse Var AuthList Auth AuthList                                    00400000
  41.     If Auth = "DENY" Then Do                                            00410000
  42.         allow = 0; Parse Var AuthList Auth AuthList                     00420000
  43.         End  /*  If  ..  Do  */                                         00430000
  44.     If Auth = "ALLOW" Then Do                                           00440000
  45.         allow = 1; Parse Var AuthList Auth AuthList                     00450000
  46.         End  /*  If  ..  Do  */                                         00460000
  47.     Say "Auth" Auth                                                     00470000
  48.     If Auth = '*' Then Return allow                                     00480000
  49.                                                                         00490000
  50.     Parse Var Auth Auth "," AuthMask "," .                              00500000
  51.     AuthAddr = Inet_addr(Auth)                                          00510000
  52.     If AuthAddr = "-1" Then Do              /* process as a name spec */00520000
  53.         If Left(Auth,1) = '.' Then Do                                   00530000
  54.             TruncName = Right(ClientName,Length(Auth))                  00540000
  55.             Say "Truncated ClientName" TruncName                        00550000
  56.             If TruncName = Auth Then Return allow                       00560000
  57.             End  /*  If  ..  Do  */                                     00570000
  58.         Else If ClientName = Auth Then Return allow                     00580000
  59.         End  /*  If  ..  Do  */                                         00590000
  60.                                                                         00600000
  61.     Else Do                                 /* must be a numeric spec */00610000
  62.         AuthMask = Inet_addr(AuthMask)                                  00620000
  63.         If AuthMask = "-1" Then Do                                      00630000
  64.             AuthMask = bitand(AuthAddr,'C0000000'x)                     00640000
  65.             Select  /*  AuthMask  */                                    00650000
  66.                 When AuthMask = '00000000'x Then AuthMask = 'FF000000'x 00660000
  67.                 When AuthMask = '80000000'x Then AuthMask = 'FFFF0000'x 00670000
  68.                 When AuthMask = 'C0000000'x Then AuthMask = 'FFFFFF00'x 00680000
  69.                 End  /*  Select  AuthMask  */                           00690000
  70.             End  /*  If  ..  Do  */                                     00700000
  71.         Say "ADDR" c2x(AuthAddr) "MASK" c2x(AuthMask)                   00710000
  72.         AuthAddr = bitxor(AuthAddr,ClientAddr)                          00720000
  73.         AuthAddr = bitand(AuthAddr,AuthMask)                            00730000
  74.         If AuthAddr = '00000000'x Then Return allow                     00740000
  75.         End  /*  Else  Do  */                                           00750000
  76.                                                                         00760000
  77.     End  /*  Do  While  */                                              00770000
  78.                                                                         00780000
  79. Return 0                                                                00790000
  80.                                                                         00800000
  81.