home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / dschgp.exe / DSCHGPAS.C < prev    next >
C/C++ Source or Header  |  1995-01-19  |  6KB  |  217 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: DSCHGPSS.C  
  22. **
  23. **   Desc: Allows the user to change the password on a user in the DS tree.  
  24. **
  25. **        
  26. **   Programmers:
  27. **   Ini   Who                Firm
  28. **   ------------------------------------------------------------------
  29. **   ARM   A. Ray Maxwell     Novell Developer Support.
  30. **
  31. **   History:
  32. **       
  33. **   ------------------------------------------------------------------
  34. **   01-18-95   ARM   First code.
  35. */
  36.  
  37. /****************************************************************************
  38. **   Include headers, macros, function prototypes, etc.
  39. */
  40.  
  41.    /*------------------------------------------------------------------------
  42.    **   Macros
  43.    */
  44.    #define NWDOS
  45.  
  46.    /*------------------------------------------------------------------------
  47.    **   ANSI
  48.    */
  49.    #include <stdio.h>
  50.    #include <string.h>
  51.    #include <stdlib.h>
  52.    #include <conio.h>   /* getch()    */
  53.  
  54.    /*------------------------------------------------------------------------
  55.    **   NetWare
  56.    */
  57.    #include <nwnet.h>
  58.    #include <nwcalls.h>
  59.    #include <nwlocale.h>
  60.  
  61.    extern unsigned _stklen = (1024 * 8);
  62.  
  63. /****************************************************************************
  64. **   Function main() contains the entire program. 
  65. **   
  66. */
  67.  
  68.  
  69. void main(int argc, char *argv[])
  70. {
  71.   NWDSContextHandle  dContext;
  72.   NWDSCCODE          ccode;
  73.   NWCONN_HANDLE      connHandle;
  74.   char               *ptr,*ptr1;
  75.   char               objectName[MAX_DN_CHARS],
  76.                      originalPassword[128],
  77.                      newPassword[128];
  78.   char               ch;
  79.   LCONV              lconvInfo;
  80.  
  81.  
  82.    ccode = NWCallsInit(NULL,NULL);
  83.    printf("NWCallsInit() = %04X\n",ccode);
  84.    if(ccode)
  85.       exit(1);
  86.  
  87.    NWLsetlocale(LC_ALL, "");
  88.    printf("\nNWLsetl.. OK");
  89.  
  90.    NWLlocaleconv(&lconvInfo);
  91.    printf("\nCountry ID = %03d, Code Page = %04d\n",
  92.             lconvInfo.country_id, lconvInfo.code_page);
  93.  
  94.    ccode = NWInitUnicodeTables(lconvInfo.country_id, lconvInfo.code_page);
  95.  
  96.    printf("NWInitUnicodeTables() = %04X\n",ccode);
  97.    if(ccode){
  98.       NWFreeUnicodeTables();
  99.       exit(1);
  100.    }
  101.  
  102.  
  103.       dContext = NWDSCreateContext();
  104.       printf("NWDSCreateContext() = %04X\n",dContext);
  105.  
  106.    if(dContext == ERR_CONTEXT_CREATION){
  107.       NWFreeUnicodeTables();
  108.       NWDSFreeContext(dContext);
  109.       exit(1);
  110.    }
  111.  
  112.  
  113.    originalPassword[0] = '\0';
  114.    printf("\nOriginal Password: ");
  115.  
  116.    ptr = originalPassword;
  117.  
  118.    do
  119.       {
  120.       ch = getch();                         // get password without echo!
  121.       *ptr = ch;
  122.          ptr++;
  123.       } while (ch != '\r');
  124.  
  125.    ptr = ptr - 1;
  126.    *ptr = '\0';
  127.  
  128.    printf("\nAttempting Change User password... \n");
  129.  
  130.       ccode = NWDSWhoAmI(
  131.               /* > Context       */ dContext,
  132.               /* < Obj name*     */ objectName);
  133.    
  134.    if (ccode){
  135.       printf("\nNWDSWhoAmI returned: %04X", ccode);
  136.       NWFreeUnicodeTables();
  137.       NWDSFreeContext(dContext);
  138.       exit(1);
  139.    }
  140.  
  141.    ccode=NWDSVerifyObjectPassword(
  142.          /* > contextHandle             */ dContext,
  143.          /* > reserved                  */ 0,
  144.          /* > object name               */ objectName,
  145.             /* > password clear text       */ originalPassword);
  146.    
  147.    if (ccode){
  148.       printf("\nNWDSVerifyObjectPassword returned: %04X", ccode);
  149.       NWFreeUnicodeTables();
  150.       NWDSFreeContext(dContext);
  151.       exit(1);
  152.    }
  153.  
  154.  
  155.    newPassword[0] = '\0';
  156.    printf("\nNew Password: ");
  157.  
  158.    ptr1 = newPassword;
  159.  
  160.    do
  161.       {
  162.       ch = getch();                         // get password without echo!
  163.       *ptr1 = ch;
  164.       ptr1 = ptr1 + 1;
  165.       } while (ch != '\r');
  166.  
  167.    ptr1 = ptr1 - 1;
  168.    *ptr1 = '\0';
  169.  
  170.  
  171.    ccode=NWDSChangeObjectPassword(
  172.          /* > contextHandle             */ dContext,
  173.          /* > reserved                  */ NULL,
  174.          /* > object name               */ objectName,
  175.          /* > currentpassword           */ originalPassword,
  176.          /* > new password              */ newPassword);
  177.  
  178.    if(ccode){
  179.       printf("\nNWDSChangeObjectPassword returned: %04X", ccode);
  180.       NWFreeUnicodeTables(); 
  181.       NWDSFreeContext(dContext);
  182.       exit(1);
  183.    }
  184.    NWFreeUnicodeTables(); 
  185.    NWDSFreeContext(dContext);
  186.  
  187.  
  188. }
  189.  
  190.  
  191.                                                                                                     
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
  217.