home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / rlogin.exe / LOG.C next >
Text File  |  1995-01-07  |  5KB  |  150 lines

  1.  
  2. /****************************************************************************
  3. **      DISCLAIMER  
  4. **  
  5. **   Novell, Inc. makes no representations or warranties with respect to
  6. **   any NetWare software, and specifically disclaims any express or
  7. **   implied warranties of merchantability, title, or fitness for a
  8. **   particular purpose.  
  9. **
  10. **   Distribution of any NetWare software is forbidden without the
  11. **   express written consent of Novell, Inc.  Further, Novell reserves
  12. **   the right to discontinue distribution of any NetWare software.
  13. **   
  14. **   Novell is not responsible for lost profits or revenue, loss of use
  15. **   of the software, loss of data, costs of re-creating lost data, the
  16. **   cost of any substitute equipment or program, or claims by any party
  17. **   other than you.  Novell strongly recommends a backup be made before
  18. **   any software is installed.   Technical support for this software
  19. **   may be provided at the discretion of Novell.
  20. ****************************************************************************
  21. **
  22. **   File:   log.c
  23. **
  24. **   Desc: Program that allows a user to login to a specified file server.
  25. **         This code comes from the v1.0e manuals and has corrections that
  26. **         allow the code to actually work! It should be noted that you 
  27. **         login and are automatically map rooted to the login subdirectory.
  28. **         Code would have to be written to map you to other directories or
  29. **         for testing copy the map.exe file to the login subdirectory so you
  30. **         can map elswhere.
  31. **        
  32. **   Parameter descriptions:    > input
  33. **                              < output
  34. **
  35. **   Programmers:
  36. **   Ini   Who                Firm
  37. **   ------------------------------------------------------------------
  38. **   ARM   A. Ray Maxwell     Novell Developer Support.
  39. **
  40. **   History:
  41. **       
  42. **   ------------------------------------------------------------------
  43. **   06-28-94   ARM   First code.
  44. */
  45.  
  46. /****************************************************************************
  47. ** Include Headers, Macros & function Prototypes.
  48. */
  49.    /*-------------------------------------------------------------------
  50.    ** Borland C.
  51.    */
  52.    #include <stdio.h>
  53.    #include <stdlib.h>
  54.    #include <string.h>
  55.    #include <conio.h>
  56.  
  57.    #define RETURN '\r'
  58.  
  59.    /*-------------------------------------------------------------------
  60.    ** NetWare API's
  61.    */
  62.    #include <nwcalls.h>
  63.       
  64. /****************************************************************************
  65. ** Program start.
  66. */
  67. void main(int argc, char *argv[ ])
  68. {
  69.    NWCONN_HANDLE   connHandle;
  70.    CONNECT_INFO    connInfo;
  71.    NWCCODE         ccode;
  72.    char            *ptr;
  73.    char            server[50],
  74.                    objName[50],
  75.                    password[128];
  76.  
  77.    if(argc != 3) {
  78.       printf("Usage: LOGIN <servername> <username>\n");
  79.       exit(1);
  80.    }
  81.  
  82.    strcpy(server,  strupr(argv[1]));
  83.    strcpy(objName, strupr(argv[2]));
  84.  
  85.    ccode = NWCallsInit(NULL, NULL);
  86.  
  87.    if(ccode)
  88.       exit(1);
  89.  
  90.    ccode = NWGetConnectionHandle(
  91.            /* > servername        */ server,
  92.            /*   Novell Reserved1  */ 0,
  93.            /* < connection Handle */ &connHandle,
  94.            /*   Novell Reserved2  */ NULL);
  95.  
  96.    if(ccode){
  97.       ccode = NWAttachToFileServer(
  98.               /* > servername       */ server,
  99.               /*   Novell Reserved1 */ 0,
  100.               /* < Now conn Handle  */ &connHandle);
  101.       if(ccode)
  102.     exit(1);
  103.    }
  104.    else{
  105.       ccode = NWGetConnectionStatus(
  106.               /* > conn Handle             */ connHandle,
  107.               /* < pointer to CONNECT_INFO */ &connInfo,
  108.               /* > size of structure       */ sizeof(CONNECT_INFO));
  109.       if(ccode)
  110.          exit(1);
  111.       if(connInfo.connectFlags & CONNECTION_NDS){
  112.          printf("An NDS connection is already established to %s.\n",server);
  113.          exit(0);
  114.       }
  115.       if(connInfo.connectFlags & CONNECTION_LOGGED_IN){
  116.          printf("Already logged in: %s as %s.\n", server,connInfo.clientName);
  117.          exit(0);
  118.       }
  119.    }
  120.    memset(password,'\0',sizeof(password));
  121.    printf("Password: ");
  122.   
  123.    
  124.   /*------------------------------------------------------------------------
  125.   **  Get the Password
  126.   */
  127.    ptr = password;
  128.  
  129.     while(*(--ptr) != RETURN){
  130.         *ptr=getch();
  131.         ptr++;
  132.     }
  133.     *ptr=='\0';
  134.  
  135.    strupr(password);
  136.    
  137.    ccode = NWLoginToFileServer(
  138.            /* > conn Handle             */ connHandle,
  139.            /* > pointer to login object */ objName,
  140.            /* > object type             */ OT_USER,
  141.            /* > pointer to password     */ password);
  142.  
  143.    if(ccode)
  144.       printf("Unable to log into %s error code is %X.\n",server, ccode);
  145.    else
  146.       printf("You are logged into %s.\n", server);
  147.  
  148. }
  149.                                                                                                                                                             
  150.