home *** CD-ROM | disk | FTP | other *** search
- /*
- * Name: GOPSRVAU EXEC, authorization function
- * returns TRUE (1) if the file/menu may be retrieved
- * returns FALSE (0) otherwise
- * Date: 1993-Jan-18
- * Author: Rick Troth, Rice University, Information Systems
- *
- * This file is part of CMS Gopher.
- */
-
- /*
- * Copyright 1993 Richard M. Troth. This software was developed
- * with resources provided by Rice University and is intended
- * to serve Rice's user community. Rice has benefitted greatly
- * from the free distribution of software, therefore distribution
- * of unmodified copies of this material is not restricted.
- * You may change your own copy as needed. Neither Rice
- * University nor any of its employees or students shall be held
- * liable for damages resulting from the use of this software.
- */
-
- /* ---------------------------------------------------------- AUTHORIZED
- * Verify that the client is allowed access, based on IP addr or name.
- * (we originally used an internal routine called IPA2C(), but Arty's
- * RXSOCKET provides an Inet_addr() function, which is now preferred)
- */
- AUTHORIZED:
- Parse Upper Arg Client,AuthList
- If AuthList = "" Then Return 1
- ClientAddr = Inet_addr(Client)
-
- rc = Socket('GetHostByAddr', ClientAddr, 'ClientName')
- If rc = "-1" Then ClientName = Client
- Say "Client looks like" ClientName Inet_ntoa(ClientAddr)
- Upper ClientName
-
- allow = 1
- Do While AuthList ^= ""
-
- Parse Var AuthList Auth AuthList
- If Auth = "DENY" Then Do
- allow = 0; Parse Var AuthList Auth AuthList
- End /* If .. Do */
- If Auth = "ALLOW" Then Do
- allow = 1; Parse Var AuthList Auth AuthList
- End /* If .. Do */
- Say "Auth" Auth
- If Auth = '*' Then Return allow
-
- Parse Var Auth Auth "," AuthMask "," .
- AuthAddr = Inet_addr(Auth)
- If AuthAddr = "-1" Then Do /* process as a name spec */
- If Left(Auth,1) = '.' Then Do
- TruncName = Right(ClientName,Length(Auth))
- Say "Truncated ClientName" TruncName
- If TruncName = Auth Then Return allow
- End /* If .. Do */
- Else If ClientName = Auth Then Return allow
- End /* If .. Do */
-
- Else Do /* must be a numeric spec */
- AuthMask = Inet_addr(AuthMask)
- If AuthMask = "-1" Then Do
- AuthMask = bitand(AuthAddr,'C0000000'x)
- Select /* AuthMask */
- When AuthMask = '00000000'x Then AuthMask = 'FF000000'x
- When AuthMask = '80000000'x Then AuthMask = 'FFFF0000'x
- When AuthMask = 'C0000000'x Then AuthMask = 'FFFFFF00'x
- End /* Select AuthMask */
- End /* If .. Do */
- Say "ADDR" c2x(AuthAddr) "MASK" c2x(AuthMask)
- AuthAddr = bitxor(AuthAddr,ClientAddr)
- AuthAddr = bitand(AuthAddr,AuthMask)
- If AuthAddr = '00000000'x Then Return allow
- End /* Else Do */
-
- End /* Do While */
-
- Return 0
-
-