home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / chgrht.exe / CHGRGHTS.C next >
C/C++ Source or Header  |  1995-06-08  |  8KB  |  266 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: chgrghts.c  
  22. **
  23. **   Desc: This program will change the Inherited rights mask of a specified
  24. **         directory then show you the IRM for that directory or if only the
  25. **         path is specified it will return the current IRM for that directory.  
  26. **
  27. **        
  28. **   Programmers:
  29. **   Ini   Who         Firm
  30. **   ------------------------------------------------------------------
  31. **   ARM   A. Ray Maxwell     Novell Developer Support.
  32. **
  33. **   History:
  34. **       
  35. **   ------------------------------------------------------------------
  36. **   06-08-95   ARM   First code.
  37. */
  38.  
  39. /***************************************************************************
  40. **   Include headers, macros, function prototypes, etc.
  41. */
  42.  
  43.    /*------------------------------------------------------------------
  44.    **   ANSI
  45.    */
  46.    #include <stdio.h>  
  47.     #include <string.h> /* printf() */
  48.     #include <stdlib.h> /* exit()   */
  49.    
  50.    extern unsigned _stklen=8000;
  51.  
  52.    /*------------------------------------------------------------------
  53.    **   NetWare
  54.    */
  55.    #include <nwcalls.h>      
  56.  
  57.  
  58.  
  59. /****************************************************************************
  60. **   Program Start
  61. */
  62. void main (int argc, char *argv[])
  63. {
  64.     NWCCODE                  ccode;
  65.     NWCONN_HANDLE          conn;
  66.     NWCONN_NUM                connNumber;
  67.     NWDIR_HANDLE          dirHandle;
  68.     NWDIR_HANDLE          newDirHandle;
  69.     NWFLAGS                  attrib;
  70.     NWSEQUENCE              sequence;
  71.     NWCHANGE_BITS          bits;
  72.     NWENTRY_INFO          entryInfo;
  73.     NWACCESS_RIGHTS        maxRightsMask;
  74.     NWOBJ_ID                    objectID;
  75.     DWORD                        currDateTime;
  76.     char                      dir[100];
  77.     char                       newPath[100];
  78.     int            i;
  79.  
  80.     if (argc == 1)
  81.     {
  82.         printf("\nUsage: DINFO <PATH> {OPTIONS}\n");
  83.         printf("Where options can be zero or more of the following:\n");
  84.         printf("__________________________________________________\n");
  85.         printf("\nR\t\tREAD\n");
  86.         printf("W\t\tWRITE\n");
  87.         printf("C\t\tCREATE\n");
  88.         printf("D\t\tDELETE\n");
  89.         printf("A\t\tACCESS CONTROL\n");
  90.         printf("F\t\tFILE SCAN\n");
  91.         printf("M\t\tMODIFY\n");
  92.         printf("S\t\tSUPERVISOR\n");
  93.         printf("If no options given program returns current IRM.\n");
  94.         printf("\n\n?\t\tBrings up this help screen\n");
  95.         exit(0);
  96.  
  97.     }
  98.  
  99.     ccode=NWCallsInit (NULL,NULL);
  100.     if (ccode)
  101.     {
  102.         printf("NWCallsInit failed: %X\n",ccode);
  103.         exit(1);
  104.     }
  105.  
  106.     strcpy (dir, strupr(argv[1]));
  107.  
  108.    ccode=NWParseNetWarePath(
  109.          /* > path to parse                        */ dir,
  110.          /* < server connection Handle             */ &conn,
  111.             /* < directory Handle                     */ &dirHandle,
  112.          /* < new path relative to directory Handle*/ newPath);
  113.  
  114.     if (ccode)
  115.     {
  116.         printf("NWParseNetWarePath failed: %X\n",ccode);
  117.         exit(1);
  118.     }
  119.  
  120.    /*-----------------------------------------------------------------------
  121.    ** Get a temporary directory handle
  122.    */
  123.    ccode = NWAllocTemporaryDirectoryHandle(
  124.            /* > connection Handle            */ conn,
  125.            /* > Directory Handle             */ dirHandle,
  126.            /* > pointer to absolute dir path */ newPath,
  127.            /* < pointer to new dir handle    */ &newDirHandle, 
  128.            /* <pointer to trustee rights     */ NULL);
  129.     if (ccode)
  130.     {
  131.         printf("NWAllocTemporarydirectoryHandle failed: %X\n",ccode);
  132.         exit(1);
  133.     }
  134.  
  135.  
  136.     if (argc >= 3)
  137.     {
  138.         sequence = -1;
  139.  
  140.         ccode=NWScanDirEntryInfo(
  141.                 /* > Connection Handle  */ conn,
  142.                 /* > directory Handle   */ newDirHandle,
  143.                 /* > Search attrib      */ FA_DIRECTORY,
  144.                 /* > Sequence number    */ &sequence,
  145.                 /* > Search Pattern     */ NULL,
  146.                 /* < Entry info         */ &entryInfo);
  147.         if (ccode == INVALID_PATH)
  148.             printf("\nInvalid Path Specification. Directory does not exist!\n");
  149.         else if(ccode)
  150.         {
  151.             printf("NWScanDirEntryInfo failed: %X\n",ccode);
  152.             exit(1);
  153.         }
  154.  
  155.         maxRightsMask = 0x00;
  156.  
  157.         for (i=2; i<argc; i++)
  158.         {
  159.             switch(argv[i][0])
  160.             {
  161.                 case 'S':
  162.                 case 's':
  163.                         maxRightsMask = (maxRightsMask | TR_SUPERVISOR);
  164.                         break;
  165.  
  166.                 case 'R':
  167.                 case 'r':
  168.                         maxRightsMask = (maxRightsMask | TR_READ);
  169.                         break;
  170.  
  171.                 case 'W':
  172.                 case 'w':
  173.                         maxRightsMask = (maxRightsMask | TR_WRITE);
  174.                         break;
  175.  
  176.                 case 'C':
  177.                 case 'c':
  178.                         maxRightsMask = (maxRightsMask | TR_CREATE);
  179.                         break;
  180.  
  181.                 case 'D':
  182.                 case 'd':
  183.                         maxRightsMask = (maxRightsMask | TR_DELETE);
  184.                         break;
  185.  
  186.                 case 'A':
  187.                 case 'a':
  188.                         maxRightsMask = (maxRightsMask | TR_ACCESS_CTRL);
  189.                         break;
  190.  
  191.                 case 'F':
  192.                 case 'f':
  193.                         maxRightsMask = (maxRightsMask | TR_FILE_SCAN);
  194.                         break;
  195.  
  196.                 case 'M':
  197.                 case 'm':
  198.                         maxRightsMask = (maxRightsMask | TR_MODIFY);
  199.                         break;
  200.             }
  201.         }
  202.  
  203.         ccode=NWGetConnectionNumber(
  204.                 /* > Connection handle */ conn,
  205.                 /* > Connect. number   */ &connNumber
  206.                 );
  207.         if (ccode)
  208.         {
  209.             printf("NWGetConnectionNumber failed: %X\n",ccode);
  210.             exit(1);
  211.         }
  212.  
  213.         ccode=NWGetConnectionInformation(
  214.                 /* > connection handle     */ conn,
  215.                 /* > connection Number     */ connNumber,
  216.                 /* < Object Name           */ NULL,
  217.                 /* < Object Type           */ NULL,
  218.                 /* < Object ID             */ &objectID,
  219.                 /* < Login Time            */ NULL
  220.                 );
  221.         if (ccode)
  222.         {
  223.             printf("NWGetConnectionInformation failed: %X\n",ccode);
  224.             exit(1);
  225.         }
  226.  
  227.         ccode=NWSetDirectoryInformation(
  228.                 /* > connection Handle     */ conn,
  229.                 /* > dirHandle             */ 0,
  230.                 /* > dir Path              */ newPath,
  231.                 /* > Packed date and time  */ currDateTime,
  232.                 /* > Object ID             */ objectID,
  233.                 /* > Rights mask           */ maxRightsMask
  234.                 );
  235.         if (ccode)
  236.         {
  237.             printf("NWSetDirectoryInformation failed: %X\n",ccode);
  238.             exit(1);
  239.         }
  240.     }
  241.  
  242.     ccode=NWScanDirEntryInfo(
  243.             /* > Connection Handle  */ conn,
  244.             /* > directory Handle   */ newDirHandle,
  245.             /* > Search attrib      */ FA_DIRECTORY,
  246.             /* > Sequence number    */ &sequence,
  247.             /* > Search Pattern     */ NULL,
  248.             /* < Entry info         */ &entryInfo);
  249.     if (ccode)
  250.     {
  251.         printf("NWScanDirEntryInfo failed: %X\n",ccode);
  252.         exit(1);
  253.     }
  254.  
  255.     printf("\nDirectory Name: %s", newPath);
  256.     printf("\nInherited Rights Mask: [%c%c%c%c%c%c%c%c]\n",
  257.         (entryInfo.info.dir.inheritedRightsMask & TR_SUPERVISOR)  ? 'S' : ' ',
  258.         (entryInfo.info.dir.inheritedRightsMask & TR_READ)        ? 'R' : ' ',
  259.         (entryInfo.info.dir.inheritedRightsMask & TR_WRITE)       ? 'W' : ' ',
  260.         (entryInfo.info.dir.inheritedRightsMask & TR_CREATE)      ? 'C' : ' ',
  261.         (entryInfo.info.dir.inheritedRightsMask & TR_DELETE)      ? 'D' : ' ',
  262.         (entryInfo.info.dir.inheritedRightsMask & TR_ACCESS_CTRL) ? 'A' : ' ',
  263.         (entryInfo.info.dir.inheritedRightsMask & TR_FILE_SCAN)   ? 'F' : ' ',
  264.         (entryInfo.info.dir.inheritedRightsMask & TR_MODIFY)      ? 'M' : ' ');
  265. }
  266.