home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / snapx2.exe / SNAPX1.EXE / DSMODOBJ.C next >
Text File  |  1994-10-19  |  5KB  |  169 lines

  1. /****************************************************************************
  2. **    File:    DSMODOBJ.C
  3. **
  4. **    Desc:    This application adds an attribute called "Pets" to the 
  5. **           user object. This sample code demonstrates to proper steps
  6. **            to create an attribute class and how to add this attribute
  7. **            to an existing class. This code was intended to be used with
  8. **            the SNAPPETS.C example. This must be run before any changes in
  9. **            the PETS.DLL Snapin example will be saved to the DS Database.
  10. **        
  11. **
  12. **        DISCLAIMER  
  13. **  
  14. **    Novell, Inc. makes no representations or warranties with respect to
  15. **    any NetWare software, and specifically disclaims any express or
  16. **    implied warranties of merchantability, title, or fitness for a
  17. **    particular purpose.  
  18. **
  19. **    Distribution of any NetWare software is forbidden without the
  20. **    express written consent of Novell, Inc.  Further, Novell reserves
  21. **    the right to discontinue distribution of any NetWare software.
  22. **    
  23. **    Novell is not responsible for lost profits or revenue, loss of use
  24. **    of the software, loss of data, costs of re-creating lost data, the
  25. **    cost of any substitute equipment or program, or claims by any party
  26. **    other than you.  Novell strongly recommends a backup be made before
  27. **    any software is installed.   Technical support for this software
  28. **    may be provided at the discretion of Novell.
  29. **
  30. **    Programmers:
  31. **
  32. **        Ini    Who                        Firm
  33. **        -----------------------------------------------------------------------
  34. **        KLB    Karl Bunnell                Novell Developer Support.
  35. **
  36. **    History:
  37. **
  38. **        When        Who    What
  39. **        -----------------------------------------------------------------------
  40. **        09-19-94    klb    First code.
  41. */
  42.  
  43. /****************************************************************************
  44. **    Include headers, macros, function prototypes, etc.
  45. */
  46.  
  47.     /*------------------------------------------------------------------------
  48.     **    MACROS
  49.     */
  50.     #define NWDOS
  51.  
  52.     /*------------------------------------------------------------------------
  53.     **    ANSI
  54.     */
  55.     #include <stdio.h>
  56.     #include <conio.h>
  57.     #include <stdlib.h>
  58.         #include <string.h>
  59.  
  60.  
  61.     /*------------------------------------------------------------------------
  62.     **    NetWare
  63.     */
  64.     #include <nwnet.h>
  65.     #include <nwcalls.h>
  66.     #include <nwlocale.h>
  67.  
  68.  
  69. void main(void)
  70. {
  71.       NWDSContextHandle dContext;
  72.       NWDSCCODE         cCode=0;
  73.       Attr_Info_T       attrInfo;
  74.       Buf_T             *classBuf;
  75.       char              attrName[MAX_SCHEMA_NAME_CHARS+2];   
  76.       char              className[MAX_SCHEMA_NAME_CHARS+2];
  77.       char              optAttr[MAX_SCHEMA_NAME_CHARS+2];
  78.       char far             *countryPtr;
  79.       LCONV                lconvInfo;
  80.  
  81.  
  82.     cCode = NWCallsInit(NULL, NULL);
  83.     if (cCode)
  84.         {
  85.         printf("\nCall to NWCallsInit returned: %04X", cCode);
  86.         exit(1);
  87.         }
  88.  
  89.       countryPtr = NWLsetlocale(LC_ALL, "");
  90.  
  91.       NWLlocaleconv(&lconvInfo);
  92.  
  93.       cCode = NWInitUnicodeTables(lconvInfo.country_id, lconvInfo.code_page);
  94.  
  95.       if(cCode)
  96.         {
  97.           printf("NWInitUnicodeTables() returned: %04X\n", cCode);
  98.         NWFreeUnicodeTables();
  99.         exit(1);
  100.         }
  101.  
  102.     dContext = NWDSCreateContext();
  103.  
  104.     if (dContext == ERR_CONTEXT_CREATION)
  105.         {
  106.           printf("NWDSCreateContext returned: %04X\n", cCode);
  107.         NWFreeUnicodeTables();
  108.         exit(1);
  109.         }
  110.  
  111.     /*---------------------------------------------------------------
  112.     ** Create the attribute Pets.
  113.     */
  114.     memset(&attrInfo, (int) '\0', sizeof(Attr_Info_T));
  115.     attrInfo.asn1ID.length = 0;
  116.     memset(attrInfo.asn1ID.data, 0, MAX_ASN1_NAME);
  117.  
  118.     attrInfo.attrFlags = 0;
  119.     attrInfo.attrSyntaxID = SYN_PR_STRING;
  120.     strcpy(attrName, "Pets");
  121.  
  122.     cCode = NWDSDefineAttr(dContext, attrName, &attrInfo);
  123.         if( cCode < 0 )
  124.         {
  125.         printf("\nNWDSDefineAttr returned %04X\n", cCode);
  126.         exit ((NWCCODE) cCode );
  127.         }
  128.  
  129.  
  130.     strcpy(className, "User");
  131.  
  132.     cCode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &classBuf);
  133.     if( cCode < 0 )
  134.         {
  135.          printf("\nNWDSAllocBuf returned %04X\n", cCode);
  136.           exit( ( NWCCODE ) cCode );
  137.         }
  138.  
  139.     cCode = NWDSInitBuf(dContext, DSV_MODIFY_CLASS_DEF, classBuf);
  140.     if( cCode < 0 )
  141.         {
  142.          printf("\nNWDSInitBuf returned %04X\n", cCode);
  143.          exit( ( NWCCODE ) cCode );
  144.         }
  145.  
  146.     /*---------------------------------------------------------------
  147.     ** Add Pets as optional attribute
  148.     */
  149.     strcpy(optAttr, "Pets");
  150.     cCode = NWDSPutClassItem(dContext, classBuf, optAttr);
  151.     if( cCode < 0 )
  152.         {
  153.          printf("\nNWDSPutClassItem returned %04X\n", cCode);
  154.           exit ( ( NWCCODE ) cCode );
  155.         }
  156.  
  157.  
  158.     cCode = NWDSModifyClassDef(dContext, className, classBuf);
  159.     if( cCode < 0 )
  160.         {
  161.          printf("\nNWDSModifyClassDef returned %04X\n", cCode);
  162.           exit ( ( NWCCODE ) cCode );
  163.         }
  164.  
  165.     NWDSFreeBuf(classBuf);
  166.     NWDSFreeContext(dContext);
  167. }
  168.  
  169.