home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / bindsr.exe / BINDSERV.C next >
C/C++ Source or Header  |  1995-07-28  |  8KB  |  226 lines

  1. /****************************************************************************
  2. **        DISCLAIMER
  3. **
  4. **  This program is provided as is and carries no warranty       
  5. **  whatsoever.  Novell disclaims and excludes any and all implied    
  6. **  warranties of merchantability, title and fitness for a particular 
  7. **  purpose.  Novell does not warrant that the software will satisfy  
  8. **  your requirements or that the software is without defect or error 
  9. **  or that operation of the software will be uninterrupted.  You are 
  10. **  using the software at your risk.  The software is not a product   
  11. **  of Novell, Inc. or any of subsidiaries.
  12. **
  13. ****************************************************************************
  14. **
  15. **    File:     bindserv.c 
  16. **
  17. **    Desc:  Bindery Services -- sample code
  18. **
  19. **        Create a user object in the bindery and gives this new user
  20. **        a password.   The new user object is added to the group
  21. **        EVERYONE and given supervisor equivalent access.
  22. **
  23. **   API Calls:
  24. **         NWCallsInit()
  25. **         NWGetDefaultConnectionID()
  26. **         NWCreateObject()
  27. **         NWChangeObjectPassword()
  28. **         NWCreateProperty()
  29. **         NWWritePropertyValue()
  30. **         NWAddObjectToSet()
  31. **         
  32. **    History:
  33. **       
  34. **      ------------------------------------------------------------------
  35. **      10/94    BBA    Original.
  36. */
  37.  
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. #include <mem.h>
  41.  
  42. #define NWDOS
  43.  
  44. #include <nwcalls.h>
  45.  
  46. NWCCODE        cCode;
  47. NWCONN_HANDLE  connHandle;
  48.  
  49. extern unsigned _stklen = (1024 * 8);
  50.  
  51. struct {                                 /* loginControl structure */
  52.     BYTE accountExpirationDate[3] ;
  53.     BYTE accountDisabledFlag ;
  54.     BYTE passwordExpirationDate[3] ;
  55.     BYTE graceLogin ;
  56.     WORD passwordExpirationIntervals ;
  57.     BYTE graceLoginResetValue ;
  58.     BYTE minPasswordLength ;
  59.     WORD maxConcurrentConnections ;
  60.     BYTE allowedLoginTimeBitmap[42] ;
  61.     BYTE lastLoginDateTime[6] ;
  62.     BYTE restrictionFlags ;
  63.     BYTE unused ;
  64.     DWORD maxDiskUsageInBlocks ;
  65.     WORD badLoginCount ;
  66.     DWORD nextResetTime ;
  67.     BYTE badLoginAddr[12] ;
  68.     BYTE paddingToMakeStruct128Long[42] ;
  69. } loginControl ;
  70.  
  71. void main(void)
  72. { /* start of main */
  73.  
  74. /* Initialize NWCalls  */
  75.  
  76.    cCode = NWCallsInit( NULL, NULL );
  77.    if (cCode)
  78.    {
  79.       printf( "\nNWCallsInit: failed %04x", cCode );
  80.       exit(1);
  81.    }
  82.  
  83. /* Retrieve the connection handle of the server that you wish to issue all
  84.    requests. Note: You can use NWGetDefaultConnectionID or
  85.    NWGetConnectionHandle */
  86.  
  87.    cCode = NWGetDefaultConnectionID(&connHandle);
  88.    if (cCode)
  89.    {
  90.       printf( "\nNWGetDefaultConnectionID: failed %04x", cCode );
  91.       exit(1);
  92.    }
  93.  
  94. /* Creates user TESTUSER and gives security rights of BS_OBJECT_WRITE and
  95.    BS_ANY_READ */
  96.  
  97.    cCode = NWCreateObject( connHandle,
  98.                            "TESTUSER",
  99.                            OT_USER,
  100.                            BF_STATIC,
  101.                            BS_OBJECT_WRITE | BS_ANY_READ );
  102.    if (cCode)
  103.    {
  104.       printf( "\nNWCreateObject: failed %04x", cCode );
  105.       exit(1);
  106.    }
  107.  
  108. /* Assign a password of XXXXXXXX for TESTUSER */
  109.  
  110.    cCode = NWChangeObjectPassword( connHandle,
  111.                                    "TESTUSER",
  112.                                    OT_USER,
  113.                                    "",
  114.                                    "XXXXXXXX" );
  115.    if (cCode)
  116.       printf( "\nNWChangeObjectPassword: failed %04x", cCode );
  117.  
  118. /* Create the property "LOGIN_CONTROL"  */
  119.  
  120.    cCode = NWCreateProperty( connHandle,
  121.                              "TESTUSER",
  122.                              OT_USER,
  123.                              "LOGIN_CONTROL",
  124.                              BF_STATIC | BF_ITEM,
  125.                              BS_SUPER_WRITE | BS_OBJECT_READ );
  126.    if (cCode)
  127.       printf( "\nNWCreateProperty: failed %04x", cCode );
  128.  
  129. /* Manipulates the loginControl structure to allow TESTUSER to have a
  130.    minimum password length of 5 characters and allows TESTUSER to login
  131.    at any time. */
  132.  
  133.    loginControl.minPasswordLength = 5;
  134.    memset(loginControl.allowedLoginTimeBitmap, 0xFF,
  135.           sizeof(loginControl.allowedLoginTimeBitmap) );
  136.  
  137. /* Write the loginControl structure to the "LOGIN_CONTROL" property.   */
  138.  
  139.    cCode = NWWritePropertyValue( connHandle,
  140.                                  "TESTUSER",
  141.                                  OT_USER,
  142.                                  "LOGIN_CONTROL",
  143.                                  1,
  144.                                  (BYTE *)&loginControl,
  145.                                  0x00 );
  146.    if (cCode)
  147.       printf( "\nNWWritePropertyValue: failed %04x", cCode );
  148.  
  149. /*  This code creates the group EVERYONE with a property
  150.     GROUP_MEMBERS.  This is not needed if group EVERYONE already exists. */
  151.  
  152.    cCode = NWCreateObject( connHandle,
  153.                            "EVERYONE",
  154.                            OT_USER_GROUP,
  155.                            BF_STATIC,
  156.                            BS_OBJECT_WRITE | BS_ANY_READ );
  157.    if (cCode)
  158.       printf( "\nNWCreateObject: failed %04x", cCode );
  159.  
  160.    cCode = NWCreateProperty( connHandle,
  161.                              "EVERYONE",
  162.                              OT_USER_GROUP,
  163.                              "GROUP_MEMBERS",
  164.                              BF_STATIC | BF_SET,
  165.                              BS_SUPER_WRITE | BS_LOGGED_READ );
  166.    if (cCode)
  167.       printf( "\nNWCreateProperty: failed %04x", cCode );
  168.  
  169. /* Make TESTUSER a member of the group EVERYONE. There are three steps:
  170.    1. Adds TESTUSER to the "GROUP_MEMBERS" property of the object EVERYONE
  171.    2. Creates the property "GROUPS_I'M_IN"
  172.    3. Adds the group EVERYONE to the newly created "GROUPS_I'M_IN" property
  173. */
  174.  
  175.    cCode = NWAddObjectToSet( connHandle,
  176.                              "EVERYONE",
  177.                              OT_USER_GROUP,
  178.                              "GROUP_MEMBERS",
  179.                              "TESTUSER",
  180.                              OT_USER );
  181.    if (cCode)
  182.       printf( "\nNWAddObjectToSet: failed %04x", cCode );
  183.  
  184.    cCode = NWCreateProperty( connHandle,
  185.                              "TESTUSER",
  186.                              OT_USER,
  187.                              "GROUPS_I'M_IN",
  188.                              BF_STATIC | BF_SET,
  189.                              BS_SUPER_WRITE | BS_LOGGED_READ );
  190.    if (cCode)
  191.       printf( "\nNWCreateProperty: failed %04x", cCode );
  192.  
  193.    cCode = NWAddObjectToSet( connHandle,
  194.                              "TESTUSER",
  195.                              OT_USER,
  196.                              "GROUPS_I'M_IN",
  197.                              "EVERYONE",
  198.                              OT_USER_GROUP);
  199.    if (cCode)
  200.       printf( "\nNWAddObjectToSet: failed %04x", cCode );
  201.  
  202.  
  203. /* Makes TESTUSER a supervisor equivalent by creating the property
  204.    "SECURITY_EQUALS" and adding the user SUPERVISOR to this property. */
  205.  
  206.    cCode = NWCreateProperty( connHandle,
  207.                              "TESTUSER",
  208.                              OT_USER,
  209.                              "SECURITY_EQUALS",
  210.                              BF_STATIC | BF_SET,
  211.                              BS_SUPER_WRITE | BS_OBJECT_READ );
  212.    if (cCode)
  213.       printf( "\nNWCreateProperty: failed %04x", cCode );
  214.  
  215.    cCode = NWAddObjectToSet( connHandle,
  216.                              "TESTUSER",
  217.                              OT_USER,
  218.                              "SECURITY_EQUALS",
  219.                              "SUPERVISOR",
  220.                              OT_USER );
  221.    if (cCode)
  222.       printf( "\nNWAddObjectToSet: failed %04x", cCode );
  223.  
  224. }
  225.  
  226.