home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / mapdr.exe / MAPDRIVE.C < prev    next >
C/C++ Source or Header  |  1994-09-29  |  5KB  |  203 lines

  1. /*
  2.        This program is provided as is and carries no warranty      
  3.   whatsoever.  Novell disclaims and excludes any and all implied    
  4.   warranties of merchantability, title and fitness for a particular 
  5.   purpose.  Novell does not warrant that the software will satisfy  
  6.   your requirements or that the software is without defect or error 
  7.   or that operation of the software will be uninterrupted.  You are 
  8.   using the software at your risk.  The software is not a product   
  9.   of Novell, Inc. or any of subsidiaries.                           
  10. */
  11.  
  12. /* Programmer : Belinda Adams */
  13. /* Program to map and reset a drive.       */
  14.  
  15. #define NWDOS
  16.  
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <ctype.h>
  21. #include <conio.h>
  22. #include <nwcalls.h>
  23.  
  24. static void display_all_mappings(void);
  25. static void display_mapping(int);
  26. static void change_mappings(void);
  27. static void reset_mapping( char, NWCONN_HANDLE, char *);
  28.  
  29. /*************************************************************************/
  30.  
  31. void main(void)
  32.  
  33. {
  34.    int rtn_code;
  35.    char drive;
  36.    char ans = 'n';
  37.  
  38.    if ( rtn_code = NWCallsInit( NULL, NULL ) )
  39.    {
  40.       printf( "\nNWCallsInit: failed %04x", rtn_code );
  41.       exit(1);
  42.    }
  43.    system( "cls" );
  44.    display_all_mappings();
  45.    puts("\n\nChange current mappings (y/n)? ");
  46.    ans = getche();
  47.    puts("\n");
  48.    if ( ans == 'y' || ans == 'Y' )
  49.       change_mappings();
  50. }
  51.  
  52. /*************************************************************************/
  53. void display_all_mappings(void)
  54.  
  55. {
  56.    int   drive_num;
  57.  
  58.    puts( "Current drive mapping:\n" );
  59.    for (drive_num = 1; drive_num <= 26; drive_num++)
  60.       display_mapping(drive_num);
  61. }
  62.  
  63. /*************************************************************************/
  64. void display_mapping
  65. (
  66.    int drive_num
  67. )
  68.  
  69. {
  70.    int   rtn_code;
  71.    char  rootPath[304], relativePath[304];
  72.    int   status;
  73.  
  74.    rtn_code = NWGetDriveStatus( drive_num, NW_FORMAT_SERVER_VOLUME, &status,
  75.                                   NULL, rootPath, relativePath, NULL );
  76.    if ( rtn_code == NW_INVALID_DRIVE )
  77.       printf( "\nNWGetDriveStatus: Invalid Drive Number %d", drive_num );
  78.    else
  79.    {
  80.       if ( rtn_code )
  81.       {
  82.            printf( "\nNWGetDriveStatus: failed %04x", rtn_code );
  83.           exit(1);
  84.       }
  85.       if ( status & NW_NETWARE_DRIVE )
  86.       {
  87.           printf("Drive %c: = %s", drive_num + '@', rootPath);
  88.           puts( relativePath );
  89.       }
  90.    }
  91. }
  92. /*************************************************************************/
  93.  
  94. void change_mappings(void)
  95.  
  96. {
  97.    char         drive_ltr, drive_num;
  98.    int          rtn_code, status;
  99.    NWCONN_HANDLE conn;
  100.    char         ans, ans_str[100];
  101.    char         *upr_ans;
  102.    char         server[50], rootPath[304], relativePath[304], *volumePath;
  103.  
  104.    puts( "Enter drive letter to change " );
  105.    drive_ltr = getche();
  106.    if (drive_ltr >= 'a' && drive_ltr <= 'z')
  107.       drive_ltr = _toupper(drive_ltr);
  108.    puts("\n");
  109.    if (drive_ltr >= 'A' && drive_ltr <= 'Z')
  110.       drive_num = drive_ltr - '@';
  111.    else
  112.    {
  113.       printf("Drive letter %c is an invalid drive letter", drive_ltr);
  114.       exit(1);
  115.    }
  116.  
  117.    /* Read current info */
  118.    rtn_code = NWGetDriveStatus( drive_num, NW_FORMAT_SERVER_VOLUME, &status,
  119.                 &conn, rootPath, relativePath, NULL);
  120.    if ( rtn_code )
  121.    {
  122.       printf( "\nNWGetDriveStatus: failed %04x", rtn_code );
  123.       exit(1);
  124.    }
  125.  
  126.    /* delete the drive's current mapping */
  127.    if ( status != NW_UNMAPPED_DRIVE )
  128.       if ( rtn_code = NWDeleteDriveBase( drive_num, 0 ) )
  129.       {
  130.           printf( "\nNWGetDriveStatus: failed %04x", rtn_code );
  131.           exit(1);
  132.       }
  133.  
  134.    puts("Enter new mapping (server\\volume:path): ");
  135.    gets(ans_str);
  136.    upr_ans = strupr(ans_str);
  137.  
  138.    rtn_code = NWParsePath( upr_ans, server, &conn, NULL, NULL );
  139.    if (rtn_code == NO_CONNECTION_TO_SERVER )
  140.    {
  141.       if ( rtn_code = NWAttachToFileServer( server, 0, &conn ) )
  142.       {
  143.           printf( "\nNWAttachToFileServer: failed %04x", rtn_code );
  144.           exit(1);
  145.       }
  146.    }
  147.    else if (rtn_code)
  148.    {
  149.        printf( "\nNWParsePath: failed %04x", rtn_code );
  150.        exit(1);
  151.    }
  152.  
  153.    volumePath = NWStripServerOffPath( upr_ans, NULL );
  154.  
  155.    if ( rtn_code = NWSetDriveBase( drive_num, conn, 0, volumePath, 0) )
  156.    {
  157.       printf( "\nNWSetDriveBase: failed %04x", rtn_code );
  158.       exit(1);
  159.    }
  160.  
  161.    system( "cls" );
  162.    puts("Drive mappings updated.\n");
  163.    display_mapping(drive_num);
  164.  
  165.    puts("\n\nReset to original mappings (y/n)? ");
  166.    ans = getche();
  167.    puts("\n");
  168.    if ( ans == 'y' || ans == 'Y' )
  169.    {
  170.       strcat(rootPath, relativePath);
  171.       reset_mapping(drive_num, conn, rootPath);
  172.       system( "cls" );
  173.       puts("Drive mappings reset.");
  174.    }
  175.    display_all_mappings();
  176. }
  177. /*************************************************************************/
  178.  
  179. void reset_mapping
  180. (
  181.    char drive_num,
  182.    NWCONN_HANDLE conn,
  183.    char *rootPath
  184. )
  185.  
  186. {
  187.    int          rtn_code;
  188.    char         *volumePath;
  189.  
  190.    if ( rtn_code = NWDeleteDriveBase( drive_num, 0 ) )
  191.    {
  192.       printf( "\nNWGetDriveStatus: failed %04x", rtn_code );
  193.       exit(1);
  194.    }
  195.    volumePath = NWStripServerOffPath( rootPath, NULL );
  196.  
  197.    if ( rtn_code = NWSetDriveBase( drive_num, conn, 0, volumePath, 0) )
  198.    {
  199.       printf( "\nNWSetDriveBase: failed %04x", rtn_code );
  200.       exit(1);
  201.    }
  202. }
  203.