home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / dscrea.exe / DSCREATE.C < prev    next >
C/C++ Source or Header  |  1995-06-23  |  5KB  |  169 lines

  1. /****************************************************************************
  2. ** File:DSCREATE.C
  3. **
  4. **    Description:
  5. **              The file DSCREATE.C sets up a buffer and creates a DS user
  6. **              named Joe Smith in the default context then logs the user
  7. **              Joe Smith into the tree.
  8. **
  9. **
  10. **    Disclaimer:
  11. **
  12. **        Novell, Inc. makes no representations or warranties with respect to
  13. **        any NetWare software, and specifically disclaims any express or
  14. **        implied warranties of merchantability, title, or fitness for a
  15. **        particular purpose.
  16. **
  17. **        Distribution of any NetWare software is forbidden without the
  18. **        express written consent of Novell, Inc.  Further, Novell reserves
  19. **        the right to discontinue distribution of any NetWare software.
  20. **
  21. **        Novell is not responsible for lost profits or revenue, loss of use
  22. **        of the software, loss of data, costs of re-creating lost data, the
  23. **        cost of any substitute equipment or program, or claims by any party
  24. **        other than you.  Novell strongly recommends a backup be made before
  25. **        any software is installed.   Technical support for this software
  26. **        may be provided at the discretion of Novell.
  27. **
  28. **
  29. **
  30. **    Programmers:
  31. **
  32. **        Ini    Who                    Firm
  33. **        -----------------------------------------------------------------------
  34. **        MDP    Marina D Pimentel        Novell Developer Support
  35. **
  36. **    History:
  37. **
  38. **        When        Who    What
  39. **        -----------------------------------------------------------------------
  40. **        06-21-95    MDP    First code.
  41. **
  42. */
  43.  
  44. /*---------------------------------------------------------------------------
  45. ** Include headers, macros, structures, typedefs, etc.
  46. */
  47.  
  48. #define NWDOS
  49.  
  50. #include <stdio.h>
  51. #include <string.h>
  52. #include <nwcalls.h>
  53. #include <nwnet.h>
  54. #include <nwpsrv.h>
  55. #include <stdlib.h>
  56.  
  57. extern _stklen = (8 * 1024U);
  58.  
  59.  
  60. /*---------------------------------------------------------------------------
  61. **    Program start.
  62. */
  63.  
  64. void main(int argc, char *argv[ ])
  65. {
  66.   NWDSContextHandle   dContext;
  67.   NWDSCCODE           ccode;
  68.   NWDS_FLAGS optionsFlag=0;
  69.   NWCONN_HANDLE connID;
  70.   NWDS_BUFFER *inBuf;
  71.  
  72. /*---------------------------------------------------------------------------
  73. ** Include headers, macros, structures, typedefs, etc.
  74. */
  75.   ccode=NWCallsInit(NULL,NULL);
  76.   ccode = NWInitUnicodeTables(001, 437);
  77.   if(ccode)
  78.   {
  79.     printf("NWInitUnicodeTables returned [%x]\n",ccode);
  80.     goto cleanup;
  81.   }
  82.   ccode=NWGetPrimaryConnectionID(&connID);
  83.   if(ccode)
  84.   {
  85.     printf("NWGetPrimaryConnectionID returned [%x]\n",ccode);
  86.     goto cleanup;
  87.   }
  88.   dContext = NWDSCreateContext( );
  89.   if(dContext == ERR_CONTEXT_CREATION)
  90.   {
  91.     printf("Could not create context\n");
  92.     goto cleanup;
  93.   }
  94.  
  95. /*---------------------------------------------------------------------------
  96. ** Setting up buffer to add user.
  97. */
  98.   ccode=NWDSAllocBuf(DEFAULT_MESSAGE_LEN,&inBuf);
  99.   if (ccode)
  100.   {
  101.     printf("NWDSAllocBuf failed with [%x]\n",ccode);
  102.     goto cleanup;
  103.   }
  104.   ccode=NWDSInitBuf(dContext,DSV_ADD_ENTRY,inBuf);
  105.   if (ccode)
  106.   {
  107.     printf("NWDSInitBuf failed with [%x]\n",ccode);
  108.     goto cleanup;
  109.   }
  110.   ccode=NWDSPutAttrName(dContext,inBuf,"Object Class");
  111.   if (ccode)
  112.   {
  113.     printf("NWDSPutAttrName failed with [%x]\n",ccode);
  114.     goto cleanup;
  115.   }
  116.   ccode=NWDSPutAttrVal(dContext,inBuf,SYN_DIST_NAME,"User");
  117.   if (ccode)
  118.   {
  119.     printf("NWDSPutAttrValue failed with [%x]\n",ccode);
  120.     goto cleanup;
  121.   }
  122.   ccode=NWDSPutAttrName(dContext,inBuf,"Surname");
  123.   if (ccode)
  124.   {
  125.     printf("NWDSPutAttrName failed with [%x]\n",ccode);
  126.     goto cleanup;
  127.   }
  128.   ccode=NWDSPutAttrVal(dContext,inBuf,SYN_CI_STRING,"Smith");
  129.   if (ccode)
  130.   {
  131.     printf("NWDSPutAttrVal failed with [%x]\n",ccode);
  132.     goto cleanup;
  133.   }
  134.   ccode=NWDSAddObject(dContext,"Joe",NULL,0,inBuf);
  135.   if (ccode)
  136.   {
  137.     printf("NWDSAddObject failed with [%x]\n",ccode);
  138.     goto cleanup;
  139.   }
  140.  
  141. /*---------------------------------------------------------------------------
  142. ** Generating object key pair then logging in as the new user.
  143. */
  144.   ccode=NWDSGenerateObjectKeyPair(dContext,"Joe","MYPASS",optionsFlag);
  145.   if (ccode)
  146.   {
  147.     printf("NWDSGenerateObjectKeyPair failed with [%x]\n",ccode);
  148.     goto cleanup;
  149.   }
  150.   ccode=NWDSLogin(dContext,optionsFlag,"Joe","MYPASS",0);
  151.   if (ccode)
  152.     printf("NWDSLogin failed with [%x]\n",ccode);
  153.   ccode=NWDSAuthenticate(connID,optionsFlag,NULL);
  154.   if (ccode)
  155.     printf("NWDSAuthenticate returned a [%x]\n",ccode);
  156.  
  157. /*---------------------------------------------------------------------------
  158. ** Freeing memory.
  159. */
  160.   cleanup:
  161.   NWDSFreeBuf(inBuf);
  162.   NWFreeUnicodeTables();
  163.   NWDSFreeContext(dContext);
  164. }
  165.  
  166.  
  167.  
  168.  
  169.