home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / xdsa4.exe / DSLIST.C next >
C/C++ Source or Header  |  1995-11-03  |  5KB  |  167 lines

  1. /**************************************************************************
  2. ** File: dslist.c
  3. **
  4. ** Desc: Lists users on a server and displays their full NDS name
  5. **
  6. **
  7. **   DISCLAIMER  
  8. **  
  9. **   Novell, Inc. makes no representations or warranties with respect to
  10. **   any NetWare software, and specifically disclaims any express or
  11. **   implied warranties of merchantability, title, or fitness for a
  12. **   particular purpose.  
  13. **
  14. **   Distribution of any NetWare software is forbidden without the
  15. **   express written consent of Novell, Inc.  Further, Novell reserves
  16. **   the right to discontinue distribution of any NetWare software.
  17. **   
  18. **   Novell is not responsible for lost profits or revenue, loss of use
  19. **   of the software, loss of data, costs of re-creating lost data, the
  20. **   cost of any substitute equipment or program, or claims by any party
  21. **   other than you.  Novell strongly recommends a backup be made before
  22. **   any software is installed.   Technical support for this software
  23. **   may be provided at the discretion of Novell.
  24. **
  25. **
  26. ** Programmers:
  27. **
  28. **    Ini   Who                  Firm
  29. **    ---------------------------------------------------------------------
  30. **    DWH   Dirk W. Howard       Novell Developer Support
  31. **
  32. **
  33. ** History:
  34. **
  35. **    When        Who      What
  36. **    ---------------------------------------------------------------------
  37. **    11-3-1995    DWH      First code.
  38. **
  39. */
  40.  
  41. /**************************************************************************
  42. ** Function prototypes and macro definitions
  43. */
  44.  
  45.    /*------------------------------------------------
  46.    ** Include headers
  47.    */
  48.    #include <stdio.h>
  49.    #include <nwconn.h>
  50.    #include <nwcntask.h>
  51.    #include <nwdsapi.h>
  52.    #include <nwmisc.h>
  53.    #include <nwbindry.h>
  54.    #include <conio.h>
  55.  
  56.  
  57. /**************************************************************************
  58. ** Main procedure
  59. */
  60.  
  61. void main( void )
  62. {
  63.    WORD                 wConnection;
  64.    char                 objectName[48];
  65.    WORD                 objectType;
  66.    long                 objectID;
  67.    BYTE                 loginTime[7];
  68.    NWDSContextHandle    cx;
  69.    NWCONN_HANDLE        connID;
  70.    char                 name[MAX_DN_CHARS+1];
  71.    NWDSCCODE            ccode;
  72.    uint32               flags;
  73.    BYTE                 net[4], node[6];
  74.    char                 netBuff[9], nodeBuff[13];
  75.    int                  i;
  76.  
  77.    /*------------------------------------------------
  78.    ** Create a DS context to work with
  79.    */
  80.    cx = NWDSCreateContext();
  81.  
  82.    /*------------------------------------------------
  83.    ** Get and set the context flags so we can display the names
  84.    ** in a typeless naming convention and the full name is used.
  85.    */
  86.    ccode = NWDSGetContext( cx, DCK_FLAGS, &flags );
  87.    if ( ccode )
  88.       printf( "Error getting context flags\r\n" );
  89.    else
  90.    {
  91.       flags |= DCV_TYPELESS_NAMES;        /* Set the Typeless names flag */
  92.       flags &= ~DCV_CANONICALIZE_NAMES;   /* Clear the Canonicalize 
  93.                                              names flag                  */
  94.  
  95.       ccode = NWDSSetContext( cx, DCK_FLAGS, &flags );
  96.       if ( ccode )
  97.          printf( "Error setting context flags.\r\n" );
  98.    }
  99.  
  100.    /*------------------------------------------------
  101.    ** Get a connection other than connection 0 to work on
  102.    */
  103.    connID = SetCurrentConnection( -1 );
  104.    connID = GetCurrentConnection();
  105.  
  106.    /*------------------------------------------------
  107.    ** Process each connection
  108.    */
  109.    printf( "\r\nUser information\r\n"
  110.       "Connection  Network    Node Address    User Name\r\n"
  111.       "----------  --------   -------------   -------------------------"
  112.       "-------\r\n" );
  113.    for ( wConnection=1; wConnection<250; wConnection++ )
  114.    {
  115.       if ( GetConnectionInformation( wConnection, objectName, &objectType, 
  116.                                      &objectID, loginTime ) )
  117.          continue;               /* on error skip the rest of the loop */
  118.  
  119.       if ( objectID == 0 )
  120.          continue;               /* if no objectID skip the rest */
  121.  
  122.       if ( objectType != OT_USER )
  123.          continue;               /* if not a user type skip the rest */
  124.  
  125.       GetInternetAddress( wConnection, net, node );
  126.       sprintf( netBuff, "%02X%02X%02X%02X",
  127.                net[0], net[1], net[2], net[3] );
  128.  
  129.       /*------------------------------------------------
  130.       ** Remove leading zeros
  131.       */
  132.       for( i = 0; i < 7; i++ )
  133.          if (netBuff[i] == '0')
  134.             netBuff[i] = ' ';
  135.          else
  136.             break;
  137.  
  138.       sprintf( nodeBuff, "%02X%02X%02X%02X%02X%02X",
  139.                node[0], node[1], node[2], node[3], node[4], node[5] );
  140.  
  141.       /*------------------------------------------------
  142.       ** Remove leading zeros
  143.       */
  144.       for( i = 0; i < 11; i++ )
  145.          if (nodeBuff[i] == '0')
  146.             nodeBuff[i] = ' ';
  147.          else
  148.             break;
  149.  
  150.       NWDSMapIDToName( cx, connID, LongSwap(objectID), name );
  151.  
  152.       printf( "%6u     [%8.8s]  [%12.12s]  %s\r\n", wConnection, netBuff, 
  153.               nodeBuff, name );
  154.    }
  155.    printf( "\r\n" );
  156.  
  157.    /*------------------------------------------------
  158.    ** Return connection
  159.    */
  160.    ReturnConnection( SetCurrentConnection( 0 ) );
  161.  
  162.    /*------------------------------------------------
  163.    ** Return the context
  164.    */
  165.    NWDSFreeContext( cx );
  166. }
  167.