home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / usermk.exe / USERMK.C next >
Text File  |  1995-08-29  |  11KB  |  295 lines

  1. /****************************************************************************
  2. **      DISCLAIMER  
  3. **  
  4. **   Novell, Inc. makes no representations or warranties with respect to
  5. **   any NetWare software, and specifically disclaims any express or
  6. **   implied warranties of merchantability, title, or fitness for a
  7. **   particular purpose.  
  8. **
  9. **   Distribution of any NetWare software is forbidden without the
  10. **   express written consent of Novell, Inc.  Further, Novell reserves
  11. **   the right to discontinue distribution of any NetWare software.
  12. **   
  13. **   Novell is not responsible for lost profits or revenue, loss of use
  14. **   of the software, loss of data, costs of re-creating lost data, the
  15. **   cost of any substitute equipment or program, or claims by any party
  16. **   other than you.  Novell strongly recommends a backup be made before
  17. **   any software is installed.   Technical support for this software
  18. **   may be provided at the discretion of Novell.
  19. ****************************************************************************
  20. **
  21. **   File: USERMK.C   
  22. **
  23. **   Desc: Adds a bindery user to the bindery on a 3.x server.  
  24. **
  25. **        
  26. **   Programmers:
  27. **   Ini   Who         Firm
  28. **   ------------------------------------------------------------------
  29. **   ARM   A. Ray Maxwell     Novell Developer Support.
  30. **
  31. **   History:
  32. **       
  33. **   ------------------------------------------------------------------
  34. **   04-03-95   ARM   First code.
  35. */
  36.  
  37. /***************************************************************************
  38. **   Include headers, macros, function prototypes, etc.
  39. */
  40.  
  41.    /*------------------------------------------------------------------
  42.    **   ANSI
  43.    */
  44.    #include <stdlib.h>          /* exit()   */
  45.    #include <stdio.h>           /* printf() */
  46.    #include <string.h>          /* strcpy() */
  47.  
  48.    /*------------------------------------------------------------------
  49.    **   NetWare
  50.    */
  51.    #include <nwcalls.h>
  52.    #define NWDOS
  53.    /*------------------------------------------------------------------
  54.    ** Global 
  55.    ** The LOGIN_CONTROL structure is an 86 byte structure that contains
  56.    ** account and password information.  Following is the structure of
  57.    ** the LOGIN_CONTROL property.
  58.    */
  59.  
  60.    typedef struct{
  61.       BYTE accountExpiresYear;
  62.       BYTE accountExpiresMonth;
  63.       BYTE accountExpiresDay;
  64.       BYTE accountExpired;
  65.       BYTE passwordExpiresYear;
  66.       BYTE passwordExpiresMonth;
  67.       BYTE passwordExpiresDay;
  68.       BYTE passwordGraceLogins;
  69.       WORD expirationInterval;
  70.       BYTE graceReset;
  71.       BYTE minimumPasswordLength;
  72.       WORD maxConcurrentConnections;
  73.       BYTE timeBitMap[42];
  74.       BYTE lastLoginDate[6];
  75.       BYTE restrictionFlags;
  76.       BYTE filler;
  77.       LONG maxDiskBlocks;
  78.       WORD badLoginCount;
  79.       LONG nextResetTime;
  80.       BYTE badStationAddress[12];
  81.    } LOGIN_CONTROL;
  82.  
  83.  
  84.  
  85.  
  86. /****************************************************************************
  87. **   Program Start
  88. */
  89. void main(int argc, char *argv[])
  90. {
  91.    LOGIN_CONTROL  log;
  92.    NWCCODE        ccode;
  93.    NWCONN_HANDLE  connHandle;
  94.    NWOBJ_ID       objectID;
  95.    char           server[48];
  96.    char           name[48];
  97.    char           password[48];
  98.  
  99.     if(argc != 4)
  100.     {
  101.         printf("Usage: USERMK <server> <object Name> <password>\n\n");
  102.         exit(1);
  103.     }
  104.    strcpy(server,strupr(argv[1]));
  105.    strcpy(name,strupr(argv[2]));
  106.    strcpy(password,strupr(argv[3]));
  107.  
  108.    
  109.    
  110.    ccode = NWCallsInit(NULL, NULL);
  111.  
  112.    if(ccode)
  113.       exit(1);
  114.    
  115.    ccode=NWGetConnectionHandle(
  116.          /* > Server name       */ server,
  117.          /*   Reserved          */ 0,
  118.          /* < Connection handle */ &connHandle,
  119.          /*   Reserved          */ NULL);
  120.    if(ccode)
  121.    {
  122.       printf("NWGetConnectionHandle failed: %X\n",ccode);
  123.       exit(1);
  124.    }
  125.  
  126.    /*----------------------------------------------------------------------_
  127.    ** create the user in the bindery
  128.    */
  129.    ccode=NWCreateObject(
  130.          /* > Connection handle           */ connHandle,
  131.          /* > Object to create            */ name,
  132.          /* > Object type                 */ OT_USER,
  133.          /* > Is Dynamic or Static ?      */ BF_STATIC,
  134.          /* > New objects access rights   */ BS_OBJECT_WRITE |BS_ANY_READ);
  135.  
  136.     switch(ccode)
  137.     {
  138.         case 0x89EE : printf("This object already exists.\n");
  139.                           exit(1);
  140.         case 0x00   : break;
  141.         default     : printf("NWCreateObject failed: %X\n",ccode);
  142.                           exit(1);
  143.     }
  144.  
  145.    /*-----------------------------------------------------------------------
  146.    ** Create the SECURITY_EQUALS property.
  147.    */
  148.    ccode=NWCreateProperty(
  149.          /* > Connection Handle           */ connHandle,
  150.          /* > Object name                 */   name,
  151.          /* > Object type                 */   OT_USER,
  152.          /* > name of property to create  */   "SECURITY_EQUALS",
  153.          /* > Bindery flags               */   BF_STATIC|BF_SET,
  154.          /* > New property access mask    */   BS_SUPER_WRITE|BS_OBJECT_READ);
  155.    if(ccode)
  156.    {
  157.       printf("NWCreatePropery failed: %X\n",ccode);
  158.       exit(1);
  159.    }
  160.    /*-----------------------------------------------------------------------
  161.    ** Create the GROUPS_I'M_IN property under the user
  162.    */
  163.    ccode=NWCreateProperty(
  164.          /* > Connection Handle           */ connHandle,
  165.          /* > Object name                 */   name,
  166.          /* > Object type                 */   OT_USER,
  167.          /* > name of property to create  */   "GROUPS_I'M_IN",
  168.          /* > Bindery flags               */   BF_STATIC|BF_SET,
  169.          /* > New property access mask    */   BS_SUPER_WRITE|BS_LOGGED_READ);
  170.    if(ccode)
  171.    {
  172.       printf("NWCreatePropery failed: %X\n",ccode);
  173.       exit(1);
  174.    }
  175.  
  176.    /*-----------------------------------------------------------------------
  177.    ** create the LOGIN_CONTROL property in the bindery for the user.
  178.    */
  179.    ccode=NWCreateProperty(
  180.          /* > Connection Handle           */ connHandle,
  181.          /* > Object name                 */ name,
  182.          /* > Object type                 */ OT_USER,
  183.          /* > name of property to create  */ "LOGIN_CONTROL",
  184.          /* > Bindery flags               */ BF_STATIC|BF_ITEM,
  185.          /* > New property access mask    */ BS_SUPER_WRITE|BS_OBJECT_READ);
  186.    if(ccode)
  187.    {
  188.       printf("NWCreatePropery failed: %X\n",ccode);
  189.       exit(1);
  190.    }
  191.    /*-----------------------------------------------------------------------
  192.    ** create MISC_LOGIN_INFO stores the last login time and date.
  193.    */
  194.    ccode=NWCreateProperty(
  195.          /* > Connection Handle           */ connHandle,
  196.          /* > Object name                 */ name,
  197.          /* > Object type                 */ OT_USER,
  198.          /* > name of property to create  */ "MISC_LOGIN_INFO",
  199.          /* > Bindery flags               */ BF_STATIC|BF_ITEM,
  200.          /* > New property access mask    */ BS_OBJECT_WRITE|BS_OBJECT_READ);
  201.    if(ccode)
  202.    {
  203.       printf("NWCreatePropery failed: %X\n",ccode);
  204.       exit(1);
  205.    }
  206.  
  207.    ccode=NWChangeObjectPassword(
  208.             /* > Connection handle     */   connHandle,
  209.             /* > Object name           */   name,
  210.             /* > Object Type           */ OT_USER,
  211.          /* > Old password          */   "",
  212.          /* > New password          */   password);
  213.    if(ccode)
  214.    {
  215.       printf("NWChangeObjectPassword failed: %X\n",ccode);
  216.       exit(1);
  217.    }
  218.  
  219.    memset(&log,0,sizeof(LOGIN_CONTROL));
  220.    memset(log.timeBitMap, 0XFF, sizeof(log.timeBitMap));
  221.    
  222.    /*-----------------------------------------------------------------------
  223.    ** example of how the LOGIN_CONTROL can be modified
  224.    */
  225.    log.minimumPasswordLength=5;
  226.    log.maxConcurrentConnections=NWWordSwap(2);
  227.  
  228.    /*-----------------------------------------------------------------------
  229.    ** Write property values to the LOGIN_CONTROL property.
  230.    */
  231.    ccode=NWWritePropertyValue(
  232.          /* > Connection handle                 */ connHandle,
  233.          /* > Object name                       */ name,
  234.          /* > Object type                       */ OT_USER,
  235.          /* > Objects property name             */ "LOGIN_CONTROL",
  236.          /* > segment number or written data    */   1,
  237.          /* > 128 byte buffer containing data   */   (NWSEGMENT_DATA)&log,
  238.          /* > if 0x00 no more segments written  */   0x00);
  239.    if(ccode)
  240.    {
  241.       printf("NWWritePropertyValue failed: %X\n",ccode);
  242.       exit(1);
  243.    }
  244.  
  245.    /*-----------------------------------------------------------------------
  246.    ** added the user to the group EVERYONE's GROUP_MEMBERS list
  247.    */
  248.    ccode=NWAddObjectToSet(
  249.          /* > connection Handle                 */ connHandle,
  250.          /* > New SET object name               */ "EVERYONE",
  251.          /* > New SET object type               */ OT_USER_GROUP,
  252.          /* > SETS property name                */ "GROUP_MEMBERS",
  253.          /* > name of object being added to SET */ name,
  254.          /* > type of object being added to SET */ OT_USER);
  255.    if(ccode)
  256.    {
  257.       printf("NWAddObjectToSet failed: %X\n",ccode);
  258.       exit(1);
  259.    }
  260.    /*-----------------------------------------------------------------------
  261.    ** Add object EVERYONE  to the GROUPS_I'M_IN property in the user SET.
  262.    */
  263.    ccode=NWAddObjectToSet(
  264.          /* > connection Handle                 */ connHandle,
  265.          /* > New SET object name               */ name,
  266.          /* > New SET object type               */ OT_USER,
  267.          /* > SETS property name                */ "GROUPS_I'M_IN",
  268.          /* > name of object being added to SET */ "EVERYONE",
  269.          /* > type of object being added to SET */ OT_USER_GROUP);
  270.    if(ccode)
  271.    {
  272.       printf("NWAddObjectToSet failed: %X\n",ccode);
  273.       exit(1);
  274.    }
  275.    
  276.    /*-----------------------------------------------------------------------
  277.    ** Add object EVERYONE  to the SECURITY_EQUALS property in the user SET.
  278.    ** If this is not done then the user has no security rights and syscon
  279.    ** will give an error 251.
  280.    */
  281.    ccode=NWAddObjectToSet(
  282.          /* > connection Handle                 */ connHandle,
  283.          /* > New SET object name               */   name,
  284.          /* > New SET object type               */   OT_USER,
  285.          /* > SETS property name                */   "SECURITY_EQUALS",
  286.          /* > name of object being added to SET */   "EVERYONE",
  287.          /* > type of object being added to SET */   OT_USER_GROUP);
  288.    if(ccode)
  289.    {
  290.       printf("NWAddObjectToSet failed: %X\n",ccode);
  291.       exit(1);
  292.    }
  293.  
  294. }
  295.