home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / dn511.exe / WOBJECT.CPP < prev    next >
C/C++ Source or Header  |  1995-01-12  |  4KB  |  145 lines

  1. /*
  2. ** WOBJECT
  3. **
  4. **    Author: John Buckle, Asia Pacific Support Centre, Novell Australia.
  5. */
  6. # define DSCPP_WINDOWS
  7.  
  8. # include "dslocale.h"
  9. # include "dsobject.h"
  10. # include "dsvchar.h"
  11. # include "dsvint.h"
  12. # include "dsvmulti.h"
  13.  
  14. # include <string.h>
  15. # include <stdio.h>
  16.  
  17. /*
  18. ** dsUserAttrNames[]        Null terminated list of attribute names present
  19. **                in the DSUserObject. The order of these names
  20. **                is important and must be the same as used by
  21. **                the function FindAttribute().
  22. */
  23.  
  24. NWPSTR    dsUserAttrNames[] = { "Surname",
  25.                   "Full Name",
  26.                   "Security Equals",
  27.                   "Language", 0 } ;
  28.  
  29. /*
  30. ** dsUserAttrCount[]        Number of attribute fields in the DSUserObject
  31. **                for each attribute listed in dsUserAttrNames[].
  32. */
  33.  
  34. WORD    dsUserAttrCount[] = { 1, 1, 1, 1, 0 } ;
  35.  
  36. /*
  37. ** Class DSUserObject
  38. **
  39. **    Used to create and read USER objects from the NDS.
  40. */
  41.  
  42. class DSUserObject : public DSObject
  43. {
  44. protected:
  45.     DSValue *        FindAttribute(WORD attrIndex, WORD valueIndex) ;
  46.  
  47.     NWPSTR *        AttributeNames()
  48.                 { return dsUserAttrNames ; }
  49.     WORD *        AttributeCount()
  50.                 { return dsUserAttrCount ; }
  51.     NWPSTR        ClassName()
  52.                 { return "USER" ; }
  53. public:
  54.     DSVString        SurName ;
  55.     DSVString        FullName ;
  56.     DSVMultiValue    Security ;
  57.     DSVStringList    Language ;
  58.  
  59.             DSUserObject() { ; }
  60. } ;
  61.  
  62. /*
  63. ** DSValue * DSUserObject::FindAttribute(WORD attrIndex, WORD)
  64. **
  65. **    Given an attribute index and a value index, return a pointer to the
  66. **    DSValue object responsible for that attribute/value pair.
  67. */
  68.  
  69. DSValue * DSUserObject::FindAttribute(WORD attrIndex, WORD)
  70. {
  71.     switch (attrIndex) {
  72.         case 0:
  73.         return & SurName ;
  74.         case 1:
  75.         return & FullName ;
  76.         case 2:
  77.         return & Security ;
  78.         case 3:
  79.         return & Language ;
  80.         }
  81.     return 0 ;
  82. }
  83.  
  84. /*
  85. ** int ErrorMessage(LPSTR message, NWCCODE ccode)
  86. **
  87. **    Display an error message with NetWare error code.
  88. */
  89.  
  90. int ErrorMessage(LPSTR message, NWDSCCODE ccode = 0)
  91. {
  92. char buffer[256] ;
  93.  
  94.     sprintf(buffer,message,ccode) ;
  95.     MessageBox(0,buffer,"WLOGON error",MB_OK) ;
  96.     return 0 ;
  97. }
  98.  
  99. int PASCAL WinMain(HINSTANCE hInstance,HINSTANCE,LPSTR cmdLine,int)
  100. {
  101.     DSLocale    dsLocale ;
  102.     DSBuffer    dsBuffer ;
  103.     DSUserObject    newUser, oldUser ;
  104.     char        fullname[MAX_DN_BYTES],
  105.             distname[MAX_DN_BYTES],
  106.             context [MAX_DN_BYTES],
  107.             everyone[MAX_DN_BYTES] ;
  108.  
  109.     if (dsLocale.status() || dsBuffer.status()){
  110.         return ErrorMessage("OBJECT: Cannot initialise Unicode\n") ;
  111.         }
  112.  
  113.     dsBuffer.GetContext(context) ;
  114.  
  115.     sprintf(fullname,"%s %s","test","user") ;
  116.     sprintf(distname,".%s.%s","test",context) ;
  117.     sprintf(everyone,"Everyone.%s",context) ;
  118.  
  119.     if (dsBuffer.DoesObjectExist(distname) == 0){
  120.         if (newUser.ReadObject(distname,& dsBuffer)){
  121.             return ErrorMessage("Cannot read user") ;
  122.             }
  123.         oldUser = newUser ;
  124.         newUser.Language.release() ;
  125.         newUser.Language << String("English") << String("C++")
  126.                  << String("Pascal")  << String("Fortran") ;
  127.         if (newUser.WriteObject(distname,& dsBuffer,& oldUser)){
  128.             return ErrorMessage("Cannot modify user") ;
  129.             }
  130.         }
  131.     else {
  132.         newUser.SurName  << String("user")  << Syntax(SYN_CI_STRING) ;
  133.         newUser.FullName << String(fullname) << Syntax(SYN_CI_STRING) ;
  134.         newUser.Security << String(everyone) << Syntax(SYN_DIST_NAME) ;
  135.         newUser.Language << String("English") ;
  136.         if (newUser.WriteObject(distname,& dsBuffer)){
  137.             return ErrorMessage("Cannot create user") ;
  138.             }
  139.         if (dsBuffer.GenerateObjectKeyPair(distname,"")){
  140.             return ErrorMessage("Cannot generate user's RSA keys") ;
  141.             }
  142.         }
  143.  
  144.     return ErrorMessage("OK") ;
  145. }