home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / effrht.exe / RIGHTS.C < prev    next >
Text File  |  1995-06-02  |  7KB  |  175 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: Rights.c   
  22. **
  23. **   Desc: Finds a users effective rights for a directory or a file.  
  24. **   NOTE: This code works with a 4.X server but fails with a 3.x server
  25. **         this is being fixed and once fixed will allow this call to work
  26. **         in the 3.x environment also.
  27. **        
  28. **   Programmers:
  29. **   Ini   Who         Firm
  30. **   ------------------------------------------------------------------
  31. **   ARM   A. Ray Maxwell     Novell Developer Support.
  32. **
  33. **   History:
  34. **       
  35. **   ------------------------------------------------------------------
  36. **   04-01-95   ARM   First code.
  37. */
  38.  
  39. /***************************************************************************
  40. **   Include headers, macros, function prototypes, etc.
  41. */
  42.  
  43.    /*------------------------------------------------------------------
  44.    **   ANSI
  45.    */
  46.    #include <stdlib.h>          /* exit(), atol()        */
  47.    #include <stdio.h>           /* printf()              */
  48.    #include <string.h>           /* strcpy()              */
  49.  
  50.    /*------------------------------------------------------------------
  51.    **   NetWare
  52.    */
  53.    #include <nwcalls.h>
  54.  
  55.  
  56.  
  57. /****************************************************************************
  58. **   Program Start
  59. */
  60. void main(int argc, char *argv[])
  61. {
  62.    NWCONN_HANDLE   connHandle;
  63.    NWOBJ_ID        objectID;
  64.    NWCCODE         ccode;
  65.    NWACCESS_RIGHTS mask;
  66.    NWRIGHTS_MASK   rightsMask;
  67.    NWDIR_HANDLE    dirHandle=-1;
  68.    char            server[50];
  69.    char            objectName[48];
  70.    char            path[256];
  71.    char            directory[128];
  72.    char            dirPath[128];
  73.  
  74.    if(argc <= 3) {
  75.       printf("Usage: rights <server> <object Name> <path> <directory>\n\n");
  76.       printf("       NOTE:If directory is not given then dirHandle=0.\n");
  77.       printf("       so path is the full path.  Otherwise the path is\n");
  78.       printf("       relative to the directory given.\n");
  79.       printf("EXAMPLE rights servername johndoe sys:johndoe testdir\n");
  80.       exit(1);
  81.    }
  82.    if (argc==4)
  83.       dirHandle=0;
  84.  
  85.    strcpy(server,    strupr(argv[1]));
  86.    strcpy(objectName,strupr(argv[2]));
  87.    strcpy(path,strupr(argv[3]));
  88.    strcpy(directory,      strupr(argv[4]));
  89.  
  90.    ccode = NWCallsInit(NULL, NULL);
  91.  
  92.    if(ccode)
  93.       exit(1);
  94.  
  95.    ccode = NWGetConnectionHandle(
  96.            /* > servername        */ server,
  97.            /*   Novell Reserved1  */ 0,
  98.            /* < connection Handle */ &connHandle,
  99.            /*   Novell Reserved2  */ NULL);
  100.    if(ccode){
  101.       printf("NWGetConnectionHandle failed %X\n",ccode);
  102.       exit(1);
  103.    }
  104.  
  105.    ccode=NWGetObjectID(
  106.          /* > connection Handle        */ connHandle,
  107.          /* > object Name              */ objectName,
  108.          /* > objectType               */ OT_USER,
  109.          /* < object ID                */ &objectID);
  110.    if(ccode){
  111.       printf("NWGetObjectID failed %X\n",ccode);
  112.       exit(1);
  113.    }
  114.  
  115.    /*----------------------------------------------------------------
  116.    **  The following code will allocate a temporary directory handle
  117.    **  for use in the NWGetObjectEffectiveRights() function
  118.    */
  119.    if(dirHandle!=0){
  120.       ccode = NWAllocTemporaryDirectoryHandle(
  121.               /* > Connection Handle            */ connHandle,
  122.               /* > Directory Handle             */ NULL,
  123.               /* > Pointer to Absolute dir path */ directory,
  124.               /* < Pointer to New dir Handle    */ &dirHandle,
  125.               /* < Pointer to trustee rights    */ &mask);
  126.       if (ccode){
  127.          printf("NWAllocTemproaryDirectoryHandle failed error code= %X\n",
  128.                   ccode);
  129.          exit(1);
  130.       }
  131.    }
  132.    ccode=NWGetObjectEffectiveRights(
  133.          /* > connection Handle        */ connHandle,
  134.          /* > object ID                */ objectID,
  135.          /* > directory Handle         */ dirHandle,
  136.          /* > path                     */ path,
  137.          /* < rights mask              */ &rightsMask);
  138.    if(ccode){
  139.       printf("NWGetObjectEffectiveRights failed %X\n",ccode);
  140.    }
  141.    else{
  142.       printf("NWGetObjectEffectiveRights for\n");
  143.       printf("\n\t%-08s\t [%c%c%c%c%c%c%c%c]\n\n",objectName,
  144.                (rightsMask & TR_SUPERVISOR)  ? 'S' : ' ',
  145.                (rightsMask & TR_READ)        ? 'R' : ' ',
  146.                (rightsMask & TR_WRITE)       ? 'W' : ' ',
  147.                (rightsMask & TR_CREATE)      ? 'C' : ' ',
  148.                (rightsMask & TR_DELETE)      ? 'E' : ' ',
  149.                (rightsMask & TR_ACCESS_CTRL) ? 'A' : ' ',
  150.                (rightsMask & TR_FILE_SCAN)   ? 'F' : ' ',
  151.                (rightsMask & TR_MODIFY)      ? 'M' : ' ');
  152.  
  153.    }
  154.    ccode=NWGetEffectiveRights(connHandle,
  155.                               dirHandle,
  156.                               path,
  157.                               &rightsMask);
  158.    if(ccode){
  159.       printf("NWGetEffectiveRights failed %X\n",ccode);
  160.    }
  161.  
  162.    else
  163.       printf("NWGetEffectiveRights for:\n");
  164.       printf("%-08s\t\t [%c%c%c%c%c%c%c%c]",objectName,
  165.                (rightsMask & TR_SUPERVISOR)  ? 'S' : ' ',
  166.                (rightsMask & TR_READ)        ? 'R' : ' ',
  167.                (rightsMask & TR_WRITE)       ? 'W' : ' ',
  168.                (rightsMask & TR_CREATE)      ? 'C' : ' ',
  169.                (rightsMask & TR_DELETE)      ? 'E' : ' ',
  170.                (rightsMask & TR_ACCESS_CTRL) ? 'A' : ' ',
  171.                (rightsMask & TR_FILE_SCAN)   ? 'F' : ' ',
  172.                (rightsMask & TR_MODIFY)      ? 'M' : ' ');
  173.  
  174. }
  175.