home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / xflg1.exe / FLAG.C next >
Text File  |  1995-08-30  |  9KB  |  319 lines

  1. /****************************************************************************
  2. **    File:    FLAG.C
  3. **
  4. **    Desc:    Sample code showing how to use ChangeDirectoryEntry().
  5. **
  6. **    Disclaimer:
  7. **
  8. **        Novell, Inc. makes no representations or warranties with respect to
  9. **        any NetWare software, and specifically disclaims any express or
  10. **        implied warranties of merchantability, title, or fitness for a
  11. **        particular purpose.  
  12. **
  13. **        Distribution of any NetWare software is forbidden without the
  14. **        express written consent of Novell, Inc.  Further, Novell reserves
  15. **        the right to discontinue distribution of any NetWare software.
  16. **
  17. **        Novell is not responsible for lost profits or revenue, loss of use
  18. **        of the software, loss of data, costs of re-creating lost data, the
  19. **        cost of any substitute equipment or program, or claims by any party
  20. **        other than you.  Novell strongly recommends a backup be made before
  21. **        any software is installed.   Developer support for this software
  22. **        may be provided at the discretion of Novell.
  23. **
  24. **    QMK386 options used:
  25. **
  26. **        None
  27. **
  28. **    Programmers:
  29. **
  30. **        Ini    Who                    Firm
  31. **        -----------------------------------------------------------------------
  32. **        ABJ    Adam B. Jerome        Novell Developer Support.
  33. **
  34. **    History:
  35. **
  36. **        When        Who    What
  37. **        -----------------------------------------------------------------------
  38. **        08-29-95    ABJ    First code.
  39. */
  40.  
  41. /****************************************************************************
  42. **    Compiler setup
  43. */
  44.     /*------------------------------------------------------------------------
  45.     **    ANSI
  46.     */
  47.     #include <stdio.h>         /* printf() */
  48.     #include <string.h>         /* memset() */
  49.     #include <errno.h>       /* ESUCCESS    */
  50.     #include <sys\stat.h>    /* stat(), stat */
  51.  
  52.     /*------------------------------------------------------------------------
  53.     **    NetWare
  54.     */
  55.     #include <nwdir.h>      /* ChangeDirectoryEntry(), MFileAttributesBit, direct.h */
  56.  
  57. /****************************************************************************
  58. **    Program help
  59. */
  60. void NLM_Help(void)
  61.     {
  62.    printf("\n");
  63.    printf("Usage: LOAD FLAG {path}filename {flag{+|-}\n");
  64.     printf("\n");
  65.     printf("Flags:\n");
  66.     printf("\n");
  67.     printf("     R    Read-Only\n");
  68.     printf("     H    Hidden\n");
  69.     printf("     Y    System\n");
  70.     printf("     E    Execute-Only\n");
  71.     printf("     A    Archive\n");
  72.     printf("     S    Sharable\n");
  73.     printf("     XT   Transactional\n");
  74.     printf("     XR   Read-Audit\n");
  75.     printf("     XW   Write-Audit\n");
  76.     printf("     XI   Purge-Immediate\n");
  77.     printf("     XN   MAC No-Rename\n");
  78.     printf("     XD   MAC No-Delete\n");
  79.     printf("     XC   MAC No-Copy\n");
  80.     printf("\n");
  81.     printf("Example: LOAD FLAG sys:system\\autoexec.ncf S+ XI- \n");
  82.     printf("\n");
  83.  
  84.     return;
  85.     }
  86.  
  87. /****************************************************************************
  88. **    Set one bit of mask & attr as specified.
  89. */
  90. void NLM_SetAttrAndMask(LONG *attr, LONG *mask, LONG bit, char value)
  91.     {
  92.     *mask |= bit;
  93.     if(value == '+')
  94.         *attr |= bit;
  95.     else
  96.         *attr = *attr & !(bit);
  97.  
  98.     return;
  99.     }
  100.  
  101. /****************************************************************************
  102. **    Program start
  103. */
  104. void main(int argC, char *argV[])
  105.    {
  106.     char                 *path             = NULL;
  107.     int                  nCnt;
  108.     int                 cCode;
  109.     struct ModifyStructure des;
  110.     struct stat ss;
  111.  
  112.    /*------------------------------------------------------------------------
  113.    ** Initialize storage.
  114.    */
  115.     memset(&des, 0x00, sizeof(struct ModifyStructure));
  116.  
  117.    /*------------------------------------------------------------------------
  118.    ** Parse command line.
  119.     */
  120.     if(argC < 2)
  121.         {
  122.         NLM_Help();
  123.         goto END_ERR;
  124.         }
  125.  
  126.    path=argV[1];
  127.     for(nCnt=2; nCnt < argC; ++nCnt)
  128.         {
  129.         switch(argV[nCnt][1])
  130.             {
  131.             case '-':
  132.             case '+':
  133.                 break;
  134.             
  135.             default:
  136.                 switch(argV[nCnt][2])
  137.                     {
  138.                     case '-':
  139.                     case '+':
  140.                         break;
  141.  
  142.                     default:
  143.                         NLM_Help();
  144.                         goto END_ERR;
  145.                     }          
  146.             }
  147.         switch(argV[nCnt][0])
  148.             {
  149.             case 'R':
  150.             case 'r':
  151.                 NLM_SetAttrAndMask(&des.MFileAttributes, &des.MFileAttributesMask, _A_RDONLY, argV[nCnt][1]);
  152.                 break;
  153.  
  154.             case 'H':
  155.             case 'h':
  156.                 NLM_SetAttrAndMask(&des.MFileAttributes, &des.MFileAttributesMask, _A_HIDDEN, argV[nCnt][1]);
  157.                 break;
  158.  
  159.             case 'Y':
  160.             case 'y':
  161.                 NLM_SetAttrAndMask(&des.MFileAttributes, &des.MFileAttributesMask, _A_SYSTEM, argV[nCnt][1]);
  162.                 break;
  163.  
  164.             case 'E':
  165.             case 'e':
  166.                 NLM_SetAttrAndMask(&des.MFileAttributes, &des.MFileAttributesMask, _A_EXECUTE, argV[nCnt][1]);
  167.                 break;
  168.  
  169.             case 'A':
  170.             case 'a':
  171.                 NLM_SetAttrAndMask(&des.MFileAttributes, &des.MFileAttributesMask, _A_ARCH, argV[nCnt][1]);
  172.                 break;
  173.  
  174.             case 'S':
  175.             case 's':
  176.                 NLM_SetAttrAndMask(&des.MFileAttributes, &des.MFileAttributesMask, _A_SHARE, argV[nCnt][1]);
  177.                 break;
  178.  
  179.             case 'X':
  180.             case 'x':
  181.                 switch(argV[nCnt][1])
  182.                     {
  183.                     case 'T':
  184.                     case 't':
  185.                         NLM_SetAttrAndMask(&des.MFileAttributes, &des.MFileAttributesMask, _A_TRANS, argV[nCnt][2]);
  186.                         break;
  187.  
  188.                     case 'R':
  189.                     case 'r':
  190.                         NLM_SetAttrAndMask(&des.MFileAttributes, &des.MFileAttributesMask, _A_READAUD, argV[nCnt][2]);
  191.                         break;
  192.  
  193.                     case 'W':
  194.                     case 'w':
  195.                         NLM_SetAttrAndMask(&des.MFileAttributes, &des.MFileAttributesMask, _A_WRITAUD, argV[nCnt][2]);
  196.                         break;
  197.                 
  198.                     case 'I':
  199.                     case 'i':
  200.                         NLM_SetAttrAndMask(&des.MFileAttributes, &des.MFileAttributesMask, _A_IMMPURG, argV[nCnt][2]);
  201.                         break;
  202.                 
  203.                     case 'N':
  204.                     case 'n':
  205.                         NLM_SetAttrAndMask(&des.MFileAttributes, &des.MFileAttributesMask, _A_NORENAM, argV[nCnt][2]);
  206.                         break;
  207.                 
  208.                     case 'D':
  209.                     case 'd':
  210.                         NLM_SetAttrAndMask(&des.MFileAttributes, &des.MFileAttributesMask, _A_NODELET, argV[nCnt][2]);
  211.                         break;
  212.                 
  213.                     case 'C':
  214.                     case 'c':
  215.                         NLM_SetAttrAndMask(&des.MFileAttributes, &des.MFileAttributesMask, _A_NOCOPY, argV[nCnt][2]);
  216.                         break;
  217.                 
  218.                     default:
  219.                         NLM_Help();
  220.                         goto END_ERR;
  221.                     }
  222.  
  223.                 break;
  224.  
  225.             default:
  226.                 NLM_Help();
  227.                 goto END_ERR;
  228.             }
  229.         }
  230.  
  231.     /*------------------------------------------------------------------------
  232.     **    If the user has specfied any flags, set them.
  233.     */
  234.     if(des.MFileAttributesMask != 0L)
  235.         {
  236.         cCode=ChangeDirectoryEntry(
  237.             /*    I-    pathName                    */    path,
  238.             /*    I-    modifyVector            */    &des,
  239.             /* I-    modifyBits                */    MFileAttributesBit,
  240.             /* I- allowWildCardsFlag    */    0     /* 0=No wildcards allowed */
  241.             );
  242.         if(cCode != ESUCCESS)
  243.             {
  244.             switch(cCode)
  245.                 {
  246.                 case 0x01:
  247.                     printf("ERROR: ChangeDirectoryEntry() reports any one of the following:\n");
  248.                     printf("\n");
  249.                     printf("            Invalid MOwnerID in modify structure.\n");
  250.                     printf("            Invalid MLastUpdateID in modify structure.\n");
  251.                     printf("            Invalid MLastArchiveID in modify structure.\n");
  252.                     printf("            Invalid MMaximumSpace in modify structure.\n");
  253.                     printf("\n");
  254.                     break;
  255.                 
  256.                 case 0xFF:
  257.                     printf("ERROR: ChangeDirectoryEntry() reports 255 (Invalid path).\n");
  258.                     break;
  259.  
  260.                 default:
  261.                     printf("ERROR: ChangeDirectoryEntry() reports %d:\n", cCode);
  262.                     break;
  263.                 }
  264.  
  265.             goto END_ERR;
  266.             }
  267.  
  268.         }
  269.  
  270.     /*------------------------------------------------------------------------
  271.     **    Display files flags.
  272.     */
  273.     cCode=stat(
  274.         /*    I-    path        */ path,
  275.         /*    I-    statblk    */    &ss
  276.         );
  277.     if(cCode != 0)
  278.         {
  279.         printf("ERROR: stat() reports %d, errno=%d\n", cCode, errno);
  280.         goto END_ERR;
  281.         }
  282.     printf("File: %s\n", path);
  283.     printf("\n");
  284.     printf("Attributes:  %s\n", (ss.st_attr & _A_RDONLY) ? "Read-Only" : "Read-Write");
  285.     printf("             %s\n", (ss.st_attr & _A_HIDDEN) ? "Hidden" : "Not-Hidden");
  286.     printf("             %s\n", (ss.st_attr & _A_SYSTEM) ? "System" : "Not-System");
  287.     printf("             %s\n", (ss.st_attr & _A_EXECUTE) ? "Execute-Only or VolumeID" : "Not Execute-Only");
  288.     printf("             %s\n", (ss.st_attr & _A_SUBDIR) ? "Directory" : "File");
  289.     printf("             %s\n", (ss.st_attr & _A_ARCH) ? "Archive" : "Not-Archive");
  290.     printf("             %s\n", (ss.st_attr & _A_SHARE) ? "Shareable" : "Non-Sharable");
  291.     printf("             %s\n", (ss.st_attr & _A_TRANS) ? "Transactional" : "Not-Transactional");
  292.     printf("             %s\n", (ss.st_attr & _A_READAUD) ? "Read-Audit" : "Non Read-Audit");
  293.     printf("             %s\n", (ss.st_attr & _A_WRITAUD) ? "Write-Audit" : "Non Write-Audit");
  294.     printf("             %s\n", (ss.st_attr & _A_IMMPURG) ? "Purge-Immediate" : "Non Purge-Immediate");
  295.     printf("             %s\n", (ss.st_attr & _A_NORENAM) ? "(MAC) No-Rename" : "(MAC) Rename");
  296.     printf("             %s\n", (ss.st_attr & _A_NODELET) ? "(MAC) No-Delete" : "(MAC) Delete");
  297.     printf("             %s\n", (ss.st_attr & _A_NOCOPY) ? "(MAC) No-Copy" : "(MAC) Copy");
  298.     printf("\n");
  299.  
  300.  
  301. END_ERR:
  302.  
  303.  
  304.     return;
  305.     }
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.