home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / clipper / nettos11.zip / BINDERY / INGROUP.PRG < prev    next >
Text File  |  1993-02-23  |  3KB  |  119 lines

  1. /*
  2.  * File......: INGROUP.PRG
  3.  * Author....: Glenn Scott
  4.  * CIS ID....: 71620,1521
  5.  * Date......: $Date$
  6.  * Revision..: $Revision$
  7.  * Log file..: $Logfile$
  8.  * 
  9.  * This is an original work by Glenn Scott and is placed in the
  10.  * public domain.
  11.  *
  12.  * Modification history:
  13.  * ---------------------
  14.  *
  15.  * $Log$
  16.  *
  17.  */
  18.  
  19. #include "netto.ch"
  20.  
  21. /*  $DOC$
  22.  *  $FUNCNAME$
  23.  *     FN_INGROUP()
  24.  *  $CATEGORY$
  25.  *     Bindery
  26.  *  $ONELINER$
  27.  *     Determine if user is in a user group
  28.  *  $SYNTAX$
  29.  *     
  30.  *     fn_inGroup( <cGroup> [,<cUser> | <nConn> ] ) -> lInGroup
  31.  *
  32.  *  $ARGUMENTS$
  33.  *     
  34.  *    <cGroup> is the name of the user group that you will test for
  35.  *    the user's membership status.
  36.  *
  37.  *    The second parameter can be either a character or a numeric, 
  38.  *    and is optional.  You can place one of two values in the second
  39.  *    parameter:
  40.  *
  41.  *       <cUser> is the user name to test
  42.  *       <nConn> is the logical connection number to test
  43.  *
  44.  *    If the second parameter is omitted, then the name of the current
  45.  *    user is assumed.
  46.  *
  47.  *  $RETURNS$
  48.  *     
  49.  *    .t. if the user is in the selected group, .f. if the user is not.
  50.  *
  51.  *  $DESCRIPTION$
  52.  *     
  53.  *    fn_inGroup() provides a simple "wrapper" around the fn_bndoins()
  54.  *    function ("Is Bindery Object in Set").  This allows you to test
  55.  *    whether or not a user belongs to  a selected user group, as 
  56.  *    defined in the NetWare operating system's bindery.
  57.  *
  58.  *    This can be useful for partitioned security.  For example, you 
  59.  *    can restrict certain parts of an application to users in 
  60.  *    certain user groups.  See the examples below.
  61.  *
  62.  *  $EXAMPLES$
  63.  *     
  64.  *    *  Test current user's group membership for security reasons:
  65.  *
  66.  *         if fn_inGroup( "PAYROLL" )
  67.  *            doPayroll()
  68.  *         else
  69.  *            qout( "Not authorized" )
  70.  *         endif
  71.  *
  72.  *    *  Test a specific user's membership in the "EVERYONE" group:
  73.  *
  74.  *         qout( fn_inGroup( "EVERYONE", "SUPERVISOR" ) )
  75.  *         
  76.  *
  77.  *    *  Test to see if the user on connection 5 is in "PROGRAMMERS":
  78.  *
  79.  *         qout( fn_inGroup( "PROGRAMMERS", 5 ) )
  80.  *
  81.  *  $SEEALSO$
  82.  *    fn_bndoins() 
  83.  *  $INCLUDE$
  84.  *     
  85.  *  $END$
  86.  */
  87.  
  88.  
  89. #ifdef FT_TEST
  90.   function main( cGroup, cUser )
  91.      default cUser to fn_whoami(),;
  92.              cGroup to "EVERYONE"
  93.  
  94.      qout( cUser + " is " + iif( fn_inGroup( cGroup, cUser ), "", " not " ) + ;
  95.            "a member of group " + cGroup )
  96.      return nil
  97. #endif
  98.  
  99. function fn_inGroup( cGroup, xParm2 )
  100.   local cUser
  101.  
  102.   do case
  103.      case valtype( xParm2 ) == "N"
  104.         cUser := fn_whoami( xParm2 )
  105.      case valtype( xParm2 ) == "C"
  106.         cUser := xParm2
  107.   otherwise
  108.      cUser := fn_whoami()
  109.   endcase
  110.  
  111.   return fn_bndoins( cUser, OT_USER, "GROUPS_I'M_IN",;
  112.                      cGroup, OT_USER_GROUP )
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.