home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / nfsrc21.zip / NWUID.PRG < prev    next >
Text File  |  1991-08-16  |  4KB  |  131 lines

  1. /*
  2.  * File......: NWUID.PRG
  3.  * Author....: Glenn Scott
  4.  * CIS ID....: 71620,1521
  5.  * Date......: $Date:   15 Aug 1991 23:04:10  $
  6.  * Revision..: $Revision:   1.4  $
  7.  * Log file..: $Logfile:   E:/nanfor/src/nwuid.prv  $
  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:   E:/nanfor/src/nwuid.prv  $
  16.  * 
  17.  *    Rev 1.4   15 Aug 1991 23:04:10   GLENN
  18.  * Forest Belt proofread/edited/cleaned up doc
  19.  * 
  20.  *    Rev 1.3   14 Jun 1991 19:52:34   GLENN
  21.  * Minor edit to file header
  22.  * 
  23.  *    Rev 1.2   14 Jun 1991 04:31:30   GLENN
  24.  * Return value still needs to have nulls (chr(0)) removed.  Put that back
  25.  * in.
  26.  * 
  27.  *    Rev 1.1   12 Jun 1991 02:25:22   GLENN
  28.  * Documentation correction and revision of ft_int86() call to account
  29.  * for Ted's new string passing conventions.
  30.  * 
  31.  *    Rev 1.0   01 Apr 1991 01:01:56   GLENN
  32.  * Nanforum Toolkit
  33.  *
  34.  */
  35.  
  36.  
  37. /*  $DOC$
  38.  *  $FUNCNAME$
  39.  *     FT_NWUID()
  40.  *  $CATEGORY$
  41.  *     NetWare
  42.  *  $ONELINER$
  43.  *     Return the current Novell NetWare User ID
  44.  *  $SYNTAX$
  45.  *     FT_NWUID( [ <nConnection> ] ) -> cUid
  46.  *  $ARGUMENTS$
  47.  *     <nConnection> is a connection number, or logical station number,
  48.  *     to find a userid for.  Under NetWare 286, this number can be from
  49.  *     1 to 100.  Under NetWare 386, 1-250.  If not supplied, FT_NWUID()
  50.  *     defaults to the current connection (i.e., the connection running
  51.  *     the application).
  52.  *  $RETURNS$
  53.  *     A string containing the userid, or "login name."
  54.  *     The maximum length of this string, as defined by current
  55.  *     versions of Novell NetWare, is 48 characters.
  56.  *  $DESCRIPTION$
  57.  *     FT_NWUID() returns the current NetWare userid, or "login
  58.  *     name."  This is useful for implementing security or audit
  59.  *     trail procedures within your programs.
  60.  *
  61.  *     There is no simple way a user can "fool" this function into 
  62.  *     retrieving an incorrect value, provided a NetWare shell is loaded.
  63.  *
  64.  *     This function requires FT_INT86() and FT_NWLSTAT()
  65.  *
  66.  *     This function does NOT test for the existence of the NetWare shell.  
  67.  *     The behavior is undefined if no shell is loaded. You'll usually get
  68.  *     garbage.  This function has not been tested on NetWare 386.
  69.  *  $EXAMPLES$
  70.  *     QOut( "I am: " + FT_NWUID() )
  71.  *
  72.  *     FOR x := 1 TO 100
  73.  *       cUid := FT_NWUID( x )
  74.  *       IF .NOT Empty( cUid )
  75.  *         QOut( Str( x, 3 ) + Space(3) + cUid )
  76.  *       ENDIF
  77.  *     NEXT
  78.  *  $END$
  79.  */
  80.  
  81. #include "FTINT86.CH"
  82.  
  83. #define DOS         33
  84. #define NW_LOG     227
  85.  
  86. #ifdef FT_TEST
  87.   FUNCTION MAIN()
  88.      local x, cUid
  89.      QOut( "I am: [" + FT_NWUID() + "]" )
  90.      QOut( "---------------------" )
  91.  
  92.       for x:= 1 to 100
  93.         cUid := FT_NWUID( x )
  94.         if .not. empty( cUid )
  95.           QOut( str( x, 3 ) + space(3) + cUid )
  96.         endif
  97.       next
  98.  
  99.   return ( nil )
  100. #endif
  101.  
  102. FUNCTION FT_NWUID( nConn )
  103.   LOCAL aRegs[ INT86_MAX_REGS ], ;
  104.         cReqPkt,                 ;
  105.         cRepPkt
  106.  
  107.   nConn := IIF( nConn == nil, FT_NWLSTAT(), nConn )
  108.  
  109.   // Set up request packet
  110.  
  111.   cReqPkt  :=  chr( 22    )          // Function 22: Get Connection Information
  112.   cReqPkt  +=  chr( nConn )        
  113.   cReqPkt  :=  i2bin( len( cReqPkt ) ) + cReqPkt
  114.  
  115.   // Set up reply packet
  116.  
  117.   cRepPkt  :=  space(63)
  118.  
  119.   // Assign registers
  120.  
  121.   aRegs[ AX ]        :=  MAKEHI( NW_LOG )
  122.   aRegs[ DS ]        :=  cReqPkt
  123.   aRegs[ SI ]        :=  REG_DS
  124.   aRegs[ ES ]        :=  cRepPkt
  125.   aRegs[ DI ]        :=  REG_ES
  126.  
  127.   FT_INT86( DOS, aRegs )
  128.   RETURN alltrim( strtran( substr( aRegs[ ES ], 9, 48 ), chr(0) )  )
  129.  
  130.  
  131.