home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rxlan.zip / rxlan.c < prev    next >
Text File  |  1993-05-25  |  5KB  |  139 lines

  1. /*
  2.     REXX-Utils for retrieving LAN-requester information
  3.     Copyright RZplus GmbH 1993
  4.     dedicated to public domain
  5. */
  6. #define  INCL_DOS
  7. #include <os2.h>
  8.  
  9. #include <netcons.h>
  10. #include <wksta.h>
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <rexxsaa.h>
  16.  
  17. SHORT APIENTRY RxNetInfo(
  18.          PSZ       function_name,      /* Function invocation name.*/
  19.          SHORT     argc,               /* Number of arguments.     */
  20.          PRXSTRING argv,               /* Function arguments.      */
  21.          PSZ       queue_name,         /* Current queue name.      */
  22.          PRXSTRING retval ) ;          /* Value returned by funct. */
  23.  
  24. char *UserID();
  25. char *DomainController();
  26.  
  27.  
  28. /*******************************************************************/
  29. /* Function:            RxNetInfo()                                */
  30. /* Description:         Return requester information;              */
  31. /* Input:               Name of desired information.               */
  32. /* Output:              Desired information.  Please see notes.    */
  33. /*                      Returns 0 if the function executed OK,     */
  34. /*                      -1 otherwise.  The interpreter will fail   */
  35. /*                      if the function returns a negative result. */
  36. /*                                                                 */
  37. /*   This routine takes one parameter.  The form of the call is:   */
  38. /*                                                                 */
  39. /*   Information = RxNetInfo( request )                            */
  40. /*                                                                 */
  41. /*   The value of the request parameter determines the information */
  42. /*   returned.  Valid values are:                                  */
  43. /*                                                                 */
  44. /*   request            value returned                             */
  45. /*   -------            --------------                             */
  46. /*   USERID             Name of logged on user.                    */
  47. /*   DOMAIN             Name of domain controller.                 */
  48. /*                                                                 */
  49. /*   The routine ignores the case of the request parameter.  If    */
  50. /*   the parameter is invalid or the argument count is not one,    */
  51. /*   the function returns an empty string.                         */
  52. /*                                                                 */
  53. /*******************************************************************/
  54.  
  55. SHORT APIENTRY RxNetInfo(
  56.          PSZ       function_name,      /* Function invocation name.*/
  57.          SHORT     argc,               /* Number of arguments.     */
  58.          PRXSTRING argv,               /* Function arguments.      */
  59.          PSZ       queue_name,         /* Current queue name.      */
  60.          PRXSTRING retval )            /* Value returned by funct. */
  61. {
  62.     char request[ 64 ];
  63.     char *sResult;
  64.     SHORT rc = -1;
  65.  
  66.     ( void ) memset( retval -> strptr,
  67.                      0,
  68.                      ( size_t ) retval -> strlength ) ;
  69.     retval -> strlength = 0 ;
  70.  
  71.  
  72.     if( ( argc == 1 ) &&                /* Arg count valid?          */
  73.         ( argv -> strlength <           /* Request name not too      */
  74.               sizeof( request )))       /* long?                     */
  75.     {
  76.         ( void ) memset( request,        /* zero the destination      */
  77.                          0,              /* buffer.                   */
  78.                          sizeof( request ) ) ;
  79.         ( void ) memmove( request,       /* Move request from the     */
  80.                           argv ->        /* argument into the null    */
  81.                                strptr,   /* terminated buffer.        */
  82.                           ( size_t ) argv -> strlength ) ;
  83.  
  84.         /* Which Information is needed */
  85.         if( !stricmp( request, "USERID" ))
  86.         {
  87.             sResult = UserID();
  88.         }
  89.  
  90.         if( !stricmp( request, "DOMAIN" ))
  91.         {
  92.             sResult = DomainController();
  93.         }
  94.  
  95.         if( strlen( sResult ))
  96.         {
  97.             ( void ) strcpy( retval -> strptr,
  98.                              sResult ) ;
  99.  
  100.             retval -> strlength = strlen( sResult );
  101.             rc = 0;
  102.         }
  103.         else
  104.         {
  105.             rc = 1;
  106.         }
  107.  
  108.     }
  109.     return( rc );
  110. }
  111.  
  112.  
  113. char *
  114. UserID()
  115. {
  116.     static char buffer[ 256 ];
  117.     USHORT netRet;
  118.     USHORT totalAvail = 0;
  119.  
  120.     netRet = NetWkstaGetInfo( NULL, 0, buffer, sizeof( buffer ),
  121.                               &totalAvail );
  122.  
  123.     return( ( netRet ? "" : (( struct wksta_info_0 *)buffer)->wki0_username ));
  124. }
  125.  
  126. char *
  127. DomainController()
  128. {
  129.     static char buffer[ 256 ];
  130.     USHORT netRet;
  131.     USHORT totalAvail = 0;
  132.  
  133.     netRet = NetWkstaGetInfo( NULL, 0, buffer, sizeof( buffer ),
  134.                               &totalAvail );
  135.  
  136.     return( ( netRet ? "" : (( struct wksta_info_0 *)buffer)->wki0_logon_server ));
  137. }
  138.  
  139.