home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / scntst.exe / SCANTRST.C next >
C/C++ Source or Header  |  1995-02-01  |  7KB  |  190 lines

  1. /****************************************************************************
  2. **      DISCLAIMER  
  3. **  
  4. **   Novell, Inc. makes no representations or warranties with respect to
  5. **   any NetWare software, and specifically disclaims any express or
  6. **   implied warranties of merchantability, title, or fitness for a
  7. **   particular purpose.  
  8. **
  9. **   Distribution of any NetWare software is forbidden without the
  10. **   express written consent of Novell, Inc.  Further, Novell reserves
  11. **   the right to discontinue distribution of any NetWare software.
  12. **   
  13. **   Novell is not responsible for lost profits or revenue, loss of use
  14. **   of the software, loss of data, costs of re-creating lost data, the
  15. **   cost of any substitute equipment or program, or claims by any party
  16. **   other than you.  Novell strongly recommends a backup be made before
  17. **   any software is installed.   Technical support for this software
  18. **   may be provided at the discretion of Novell.
  19. ****************************************************************************
  20. **
  21. **   File: SCANTRST.C   
  22. **
  23. **   Desc: Scans a specified directory and shows the trustee assignments for
  24. **         that directory.  
  25. **
  26. **        
  27. **   Programmers:
  28. **   Ini   Who                Firm
  29. **   ------------------------------------------------------------------
  30. **   ARM   A. Ray Maxwell     Novell Developer Support.
  31. **
  32. **   History:
  33. **       
  34. **   ------------------------------------------------------------------
  35. **   01-31-95   ARM   First code.
  36. */
  37.  
  38. /***************************************************************************
  39. **   Include headers, macros, function prototypes, etc.
  40. */
  41.  
  42.    /*------------------------------------------------------------------
  43.    **   ANSI
  44.    */
  45.    #include <stdlib.h>      /* exit(), atol()        */
  46.    #include <stdio.h>       /* sprintf()             */
  47.    #include <string.h>      /* strupr()              */
  48.    #include <conio.h>       /* clrscr()              */
  49.    /*------------------------------------------------------------------
  50.    **   NetWare
  51.    */
  52.    #include <nwcalls.h>
  53.  
  54.  
  55.  
  56. /***************************************************************************
  57. **   Program Start
  58. */
  59. void main(int argc, char *argv[])
  60. {
  61.  
  62.    NWSEQUENCE           sequence;
  63.    NWNUM_ENTRIES        numberOfEntries;
  64.    char                 dirPath[255+1];
  65.    char                 serverName[47+1];
  66.    NWET_INFO            entryTrusteeInfo;
  67.    NWCCODE              ccode;
  68.    NWCONN_HANDLE        connHandle;
  69.    NWDIR_HANDLE         dirHandle;
  70.    NWACCESS_RIGHTS      rightsMask;
  71.    char                 objectName[48];
  72.    int                  count;
  73.    int                  objCount=0;
  74.  
  75.    switch(argc){
  76.       case  3:
  77.          strcpy(serverName,strupr(argv[1]));
  78.          strcpy(dirPath,strupr(argv[2]));
  79.          break;
  80.       default:
  81.          clrscr();
  82.          printf("USAGE: scantrst <server name> <directory>\n");
  83.          printf("\n       Trustee information EXAMPLE:\n");
  84.          printf("            scantrst server1 sys:users\\jsmith\n");
  85.          exit(1);
  86.    }
  87.  
  88.    ccode=NWCallsInit(NULL,NULL);
  89.    if (ccode)
  90.       exit(1);
  91.  
  92.    ccode = NWGetConnectionHandle(
  93.            /* > servername        */ serverName,
  94.            /*   Novell Reserved1  */ 0,
  95.            /* < connection Handle */ &connHandle,
  96.            /*   Novell Reserved2  */ NULL);
  97.  
  98.    //ccode= NWGetDefaultConnectionID(&connHandle);
  99. /*--------------------------------------------------------------------------
  100. ** check for validity of the directory path.
  101. */
  102.    ccode = NWAllocTemporaryDirectoryHandle(
  103.            /* Connection Handle            */ connHandle,
  104.            /* Directory Handle             */ NULL,
  105.            /* Pointer to Absolute dir path */ dirPath,
  106.            /* Pointer to New dir Handle    */ &dirHandle,
  107.            /* Pointer to trustee rights    */ &rightsMask);
  108.    if(ccode){
  109.       printf("NWAllocTemporaryDirectoryHandle failed %X\n",ccode);
  110.       printf("Check for input of valid path\n");
  111.       exit(1);
  112.    }
  113.  
  114.    if (ccode)
  115.       exit(1);
  116.  
  117.    sequence=0L;
  118. /*--------------------------------------------------------------------------
  119. ** Get all the trustee assignments for the specified directory
  120. */
  121.    while((ccode!=0x899C)&&(ccode==0)){
  122.       ccode=NWScanForTrustees(
  123.             /* connection Handle          */ connHandle,
  124.             /* NWDIR_HANDLE               */ 0,
  125.             /* NWDIR_PATH                 */ dirPath,
  126.             /* sequence number            */ &sequence,
  127.             /* NWNUM number of entries    */ &numberOfEntries,
  128.             /* trustee info stuct pointer */ &entryTrusteeInfo);
  129.  
  130.       if(ccode==0){
  131.          printf("\nTrustees of %s\n", dirPath);
  132.  
  133.          if (numberOfEntries == 0){
  134.             printf("\nNo trustee entries found!\n");
  135.             exit(1);
  136.          }
  137.  
  138.          for (count=0; count<numberOfEntries; ++count){
  139.              ccode = NWGetObjectName(
  140.                      /* > conn Hand   */ connHandle,
  141.                      /* > Object ID   */ entryTrusteeInfo.trusteeList[count].objectID,
  142.                      /* < Obj name    */ objectName,
  143.                      /*   Obj Type    */ NULL);
  144.              if (ccode){
  145.                 printf("NWGetObjectName returned %X \n",ccode);
  146.                 exit(1);
  147.              }
  148.  
  149.                  if ((entryTrusteeInfo.trusteeList[count].objectID !=0)
  150.                   && (ccode == 0)){
  151.                 objCount = objCount + 1;
  152.                 
  153.                 /*----------------------------------------------------------
  154.                 ** The TR_READ etc. are found defined in the nwdentry.h.
  155.                 */
  156.                 printf("\n\t%-08s\t [%c%c%c%c%c%c%c%c]",objectName,
  157.                 (entryTrusteeInfo.trusteeList[count].objectRights & TR_SUPERVISOR)  ? 'S' : ' ',
  158.                    (entryTrusteeInfo.trusteeList[count].objectRights & TR_READ)        ? 'R' : ' ',
  159.                    (entryTrusteeInfo.trusteeList[count].objectRights & TR_WRITE)       ? 'W' : ' ',
  160.                    (entryTrusteeInfo.trusteeList[count].objectRights & TR_CREATE)      ? 'C' : ' ',
  161.                    (entryTrusteeInfo.trusteeList[count].objectRights & TR_DELETE)      ? 'E' : ' ',
  162.                    (entryTrusteeInfo.trusteeList[count].objectRights & TR_ACCESS_CTRL) ? 'A' : ' ',
  163.                    (entryTrusteeInfo.trusteeList[count].objectRights & TR_FILE_SCAN)   ? 'F' : ' ',
  164.                    (entryTrusteeInfo.trusteeList[count].objectRights & TR_MODIFY)      ? 'M' : ' ');
  165.  
  166.              }
  167.  
  168.              if (objCount == 0){
  169.                 printf("\nNo trustee entries found!\n");
  170.                 exit(1);
  171.              }
  172.  
  173.          } /* end for */
  174.       } /* end if */
  175.       else
  176.          switch (ccode){
  177.             case 0x899c : printf("All trustees found\n");
  178.                           break;
  179.             case 0x8801  :printf("Invalid connection\n");
  180.                           break;
  181.             case 0x8998  :printf("Volume does not exist\n");
  182.                           break;
  183.             case 0x899B  :printf("Bad Directory Handle\n");
  184.             default      :printf("Unknown error on find of Trustees\n");
  185.                           break;
  186.          }
  187.    }
  188. }
  189.  
  190.