home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / dbsamp.exe / DBUNINST / DBUNINST.C next >
Text File  |  1995-01-04  |  8KB  |  273 lines

  1. /****************************************************************************
  2. **    File:    DBUNINST.C
  3. **
  4. **    Desc:    Removes the following classes from the tree:
  5. **                    DBServer -     a class that is used for a Database Server
  6. **                                            to authenticate to the tree.
  7. **                    Database -     a class that is used as an object to represent
  8. **                                            a database in a Database Server.
  9. **        Removes the following Attributes from the tree:
  10. **                    DBAdmin -        an attribute that is used to hold the name of
  11. **                                            a NDS group.  This will be used to hold the
  12. **                                            administrators of the Database.
  13. **                    DBOperator- an attribute that is used to hold the name of
  14. **                                            a NDS group.  This will be used to hold the
  15. **                                            operators of the Database.
  16. **                NOTE -  Because none of the classes or attributes above effect the
  17. **                the base classes, they can be removed from the schema
  18. **                                provided there are no objects that exists of these types.
  19. **                                If objects do exist, the removal of the classes and attributes
  20. **                                will fail.
  21. **
  22. **        DISCLAIMER
  23. **
  24. **    Novell, Inc. makes no representations or warranties with respect to
  25. **    any NetWare software, and specifically disclaims any express or
  26. **    implied warranties of merchantability, title, or fitness for a
  27. **    particular purpose.
  28. **
  29. **    Distribution of any NetWare software is forbidden without the
  30. **    express written consent of Novell, Inc.  Further, Novell reserves
  31. **    the right to discontinue distribution of any NetWare software.
  32. **
  33. **    Novell is not responsible for lost profits or revenue, loss of use
  34. **    of the software, loss of data, costs of re-creating lost data, the
  35. **    cost of any substitute equipment or program, or claims by any party
  36. **    other than you.  Novell strongly recommends a backup be made before
  37. **    any software is installed.   Technical support for this software
  38. **    may be provided at the discretion of Novell.
  39. **
  40. **    Programmers:
  41. **
  42. **        Ini    Who                                Firm
  43. **        --- ----------------- ------------------------------------------------
  44. **        CRG    Calvin Gaisford        Novell Developer Support.
  45. **
  46. **    History:
  47. **
  48. **        When         Who What
  49. **        -------- --- ---------------------------------------------------------
  50. **        10-21-94 CRG First code.
  51. **         1-04-95 CRG Modified to be generic as an example.
  52. */
  53.  
  54.  
  55.  
  56. /***************************************************************************
  57. **  Libraries Linked in for .exe
  58. **
  59. **  NWCALLS.LIB
  60. **  NWLOCALE.LIB
  61. **  NWNET.LIB
  62. **
  63. */
  64.  
  65.  
  66.  
  67. /***************************************************************************
  68. **  #defines
  69. */
  70. #define FAILURE  0xFF
  71. #define SUCCESS  0x00
  72.  
  73.  
  74.  
  75. /****************************************************************************
  76. **    Include headers, macros, etc.
  77. */
  78.  
  79.     /*-----------------------------------------------------------------------
  80.     **    ANSI
  81.     */
  82.     #include <stdio.h>
  83.     #include <stdlib.h>
  84.     #include <string.h>
  85.     #include <conio.h>
  86.  
  87.     /*-----------------------------------------------------------------------
  88.     **    NetWare
  89.     */
  90.     #include <nwnet.h>
  91.     #include <nwcalls.h>
  92.     #include <nwlocale.h>
  93.  
  94.     /*-----------------------------------------------------------------------
  95.     **    Program Global storage
  96.     */
  97.     struct
  98.     {
  99.         NWDSContextHandle context;
  100.     }gs;
  101.     extern unsigned _stklen=8000;
  102.  
  103.  
  104. /***************************************************************************
  105. **    Function Prototypes
  106. */
  107. void processCode(NWDSCCODE ccode);
  108. void removeDB(void);
  109. void removeDBS(void);
  110. void removeAttr(void);
  111. void FatalError(int errorCode);
  112. void InitDS(void);
  113. int  UninitDS(void);
  114.  
  115. /***************************************************************************
  116. **    Main Program
  117. */
  118. void main(void)
  119. {
  120.     InitDS();
  121.     removeDB();
  122.     removeDBS();
  123.     removeAttr();
  124.     UninitDS();
  125. }
  126.  
  127.  
  128.  
  129. /***************************************************************************
  130. **    Processes the return codes from DS calls.
  131. */
  132. void processCode(NWDSCCODE ccode)
  133. {
  134.     switch(ccode)
  135.     {
  136.         case    0        :    printf("Successfully Removed\n");
  137.                             break;
  138.         case    -644    :  printf("Failed -- Schema in Use\n");
  139.                             break;
  140.         default        :  printf("Failed -- Returned Error: %d\n", ccode);
  141.                             break;
  142.     }
  143. }
  144.  
  145. /***************************************************************************
  146. **    Removes the following Attributes from the Schema: DBAdmin, DBOperator.
  147. */
  148. void removeAttr(void)
  149. {
  150.     Attr_Info_T       attrInfo;
  151.     char              attrName[MAX_SCHEMA_NAME_CHARS+2];
  152.     NWDSCCODE            ccode;
  153.  
  154.  
  155.     /*---------------------------------------------------------------
  156.     ** Removing the attributes DBAdmin and DBOperator.
  157.     */
  158.     strcpy(attrName, "DBAdmin");
  159.     printf("Removing attribute \"%s\" from Schema...",attrName);
  160.     ccode = NWDSRemoveAttrDef(gs.context, attrName);
  161.     processCode(ccode);
  162.  
  163.     strcpy(attrName, "DBOperator");
  164.     printf("Removing attribute \"%s\" from Schema...",attrName);
  165.     ccode = NWDSRemoveAttrDef(gs.context, attrName);
  166.     processCode(ccode);
  167.  
  168. }
  169.  
  170.  
  171. /***************************************************************************
  172. **    Removes the new DBServer Class
  173. **        This class is based on the "Top" class.  It is defined so that it
  174. **        can be contained by Organization or Organizational Unit.  It is
  175. **        defined as an object for a Database
  176. **        Server to authenticate to the Tree. (therefore the public and private
  177. **        keys)  Also, the Network Address Attribute was added so clients could
  178. **        find the server through DS and no have to look for SAPs.
  179. */
  180. void removeDBS(void)
  181. {
  182.     NWDSCCODE            ccode;
  183.     char                    *className="DBServer";
  184.  
  185.     printf("Removing Class \"%s\" from Schema...",className);
  186.     ccode = NWDSRemoveClassDef(gs.context, className);
  187.     processCode(ccode);
  188. }
  189.  
  190.  
  191.  
  192. /***************************************************************************
  193. **    Removes the new Database Class.  This class is defined to represent
  194. ** an an object that represents a database.  It can only
  195. ** be contained by a Organization or Organizational Unit.
  196. */
  197. void removeDB(void)
  198. {
  199.     NWDSCCODE                ccode;
  200.     char                        *className="Database";
  201.  
  202.     printf("Removing Class \"%s\" from Schema...",className);
  203.     ccode = NWDSRemoveClassDef(gs.context, className);
  204.     processCode(ccode);
  205. }
  206.  
  207.  
  208.  
  209. /***************************************************************************
  210. **    FatalError is the common exit point for errors.
  211. */
  212. void FatalError(int errorCode)
  213. {
  214.         exit(errorCode);
  215. }
  216.  
  217.  
  218.  
  219. /***************************************************************************
  220. **    Establish context.  These are the standard initializations for DS calls
  221. */
  222. void InitDS(void)
  223. {
  224.     NWDSCCODE dsCcode;
  225.     LCONV            lconvInfo;
  226.  
  227.     dsCcode=NWCallsInit(NULL,NULL);
  228.     if(dsCcode)          /* initialize allowing to call nwcalls functions */
  229.     {
  230.         printf("FatalError during NWCallsInit %X\n",dsCcode);
  231.         FatalError(FAILURE);
  232.     }
  233.     NWLlocaleconv(&lconvInfo);
  234.     dsCcode = NWInitUnicodeTables(lconvInfo.country_id, lconvInfo.code_page);
  235.     if(dsCcode)
  236.     {
  237.         printf("NWInitUnicodeTables() returned: %04X\n", dsCcode);
  238.         FatalError(FAILURE);
  239.     }
  240.     gs.context=NWDSCreateContext();
  241.     if(gs.context)
  242.     {
  243.         printf("FatalError during NWDSCreateContext %X\n",gs.context);
  244.         FatalError(FAILURE);
  245.     }
  246. }
  247.  
  248.  
  249.  
  250. /***************************************************************************
  251. **    Release context and clean up.
  252. */
  253. int UninitDS()
  254. {
  255.     NWDSCCODE dsCcode;
  256.  
  257.     dsCcode=NWDSFreeContext(gs.context);
  258.     if(dsCcode)
  259.     {
  260.         printf("FatalError during NWDSFreeContext %X\n",dsCcode);
  261.         FatalError (FAILURE);
  262.     }
  263.     dsCcode=NWFreeUnicodeTables();
  264.     if(dsCcode)
  265.     {
  266.         printf("Error during NWFreeUnicodeTables()\n");
  267.         FatalError (FAILURE);
  268.     }
  269.     return(0);
  270. }
  271.  
  272.  
  273.