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 >
Wrap
Text File
|
1995-08-29
|
11KB
|
295 lines
/****************************************************************************
** DISCLAIMER
**
** Novell, Inc. makes no representations or warranties with respect to
** any NetWare software, and specifically disclaims any express or
** implied warranties of merchantability, title, or fitness for a
** particular purpose.
**
** Distribution of any NetWare software is forbidden without the
** express written consent of Novell, Inc. Further, Novell reserves
** the right to discontinue distribution of any NetWare software.
**
** Novell is not responsible for lost profits or revenue, loss of use
** of the software, loss of data, costs of re-creating lost data, the
** cost of any substitute equipment or program, or claims by any party
** other than you. Novell strongly recommends a backup be made before
** any software is installed. Technical support for this software
** may be provided at the discretion of Novell.
****************************************************************************
**
** File: USERMK.C
**
** Desc: Adds a bindery user to the bindery on a 3.x server.
**
**
** Programmers:
** Ini Who Firm
** ------------------------------------------------------------------
** ARM A. Ray Maxwell Novell Developer Support.
**
** History:
**
** ------------------------------------------------------------------
** 04-03-95 ARM First code.
*/
/***************************************************************************
** Include headers, macros, function prototypes, etc.
*/
/*------------------------------------------------------------------
** ANSI
*/
#include <stdlib.h> /* exit() */
#include <stdio.h> /* printf() */
#include <string.h> /* strcpy() */
/*------------------------------------------------------------------
** NetWare
*/
#include <nwcalls.h>
#define NWDOS
/*------------------------------------------------------------------
** Global
** The LOGIN_CONTROL structure is an 86 byte structure that contains
** account and password information. Following is the structure of
** the LOGIN_CONTROL property.
*/
typedef struct{
BYTE accountExpiresYear;
BYTE accountExpiresMonth;
BYTE accountExpiresDay;
BYTE accountExpired;
BYTE passwordExpiresYear;
BYTE passwordExpiresMonth;
BYTE passwordExpiresDay;
BYTE passwordGraceLogins;
WORD expirationInterval;
BYTE graceReset;
BYTE minimumPasswordLength;
WORD maxConcurrentConnections;
BYTE timeBitMap[42];
BYTE lastLoginDate[6];
BYTE restrictionFlags;
BYTE filler;
LONG maxDiskBlocks;
WORD badLoginCount;
LONG nextResetTime;
BYTE badStationAddress[12];
} LOGIN_CONTROL;
/****************************************************************************
** Program Start
*/
void main(int argc, char *argv[])
{
LOGIN_CONTROL log;
NWCCODE ccode;
NWCONN_HANDLE connHandle;
NWOBJ_ID objectID;
char server[48];
char name[48];
char password[48];
if(argc != 4)
{
printf("Usage: USERMK <server> <object Name> <password>\n\n");
exit(1);
}
strcpy(server,strupr(argv[1]));
strcpy(name,strupr(argv[2]));
strcpy(password,strupr(argv[3]));
ccode = NWCallsInit(NULL, NULL);
if(ccode)
exit(1);
ccode=NWGetConnectionHandle(
/* > Server name */ server,
/* Reserved */ 0,
/* < Connection handle */ &connHandle,
/* Reserved */ NULL);
if(ccode)
{
printf("NWGetConnectionHandle failed: %X\n",ccode);
exit(1);
}
/*----------------------------------------------------------------------_
** create the user in the bindery
*/
ccode=NWCreateObject(
/* > Connection handle */ connHandle,
/* > Object to create */ name,
/* > Object type */ OT_USER,
/* > Is Dynamic or Static ? */ BF_STATIC,
/* > New objects access rights */ BS_OBJECT_WRITE |BS_ANY_READ);
switch(ccode)
{
case 0x89EE : printf("This object already exists.\n");
exit(1);
case 0x00 : break;
default : printf("NWCreateObject failed: %X\n",ccode);
exit(1);
}
/*-----------------------------------------------------------------------
** Create the SECURITY_EQUALS property.
*/
ccode=NWCreateProperty(
/* > Connection Handle */ connHandle,
/* > Object name */ name,
/* > Object type */ OT_USER,
/* > name of property to create */ "SECURITY_EQUALS",
/* > Bindery flags */ BF_STATIC|BF_SET,
/* > New property access mask */ BS_SUPER_WRITE|BS_OBJECT_READ);
if(ccode)
{
printf("NWCreatePropery failed: %X\n",ccode);
exit(1);
}
/*-----------------------------------------------------------------------
** Create the GROUPS_I'M_IN property under the user
*/
ccode=NWCreateProperty(
/* > Connection Handle */ connHandle,
/* > Object name */ name,
/* > Object type */ OT_USER,
/* > name of property to create */ "GROUPS_I'M_IN",
/* > Bindery flags */ BF_STATIC|BF_SET,
/* > New property access mask */ BS_SUPER_WRITE|BS_LOGGED_READ);
if(ccode)
{
printf("NWCreatePropery failed: %X\n",ccode);
exit(1);
}
/*-----------------------------------------------------------------------
** create the LOGIN_CONTROL property in the bindery for the user.
*/
ccode=NWCreateProperty(
/* > Connection Handle */ connHandle,
/* > Object name */ name,
/* > Object type */ OT_USER,
/* > name of property to create */ "LOGIN_CONTROL",
/* > Bindery flags */ BF_STATIC|BF_ITEM,
/* > New property access mask */ BS_SUPER_WRITE|BS_OBJECT_READ);
if(ccode)
{
printf("NWCreatePropery failed: %X\n",ccode);
exit(1);
}
/*-----------------------------------------------------------------------
** create MISC_LOGIN_INFO stores the last login time and date.
*/
ccode=NWCreateProperty(
/* > Connection Handle */ connHandle,
/* > Object name */ name,
/* > Object type */ OT_USER,
/* > name of property to create */ "MISC_LOGIN_INFO",
/* > Bindery flags */ BF_STATIC|BF_ITEM,
/* > New property access mask */ BS_OBJECT_WRITE|BS_OBJECT_READ);
if(ccode)
{
printf("NWCreatePropery failed: %X\n",ccode);
exit(1);
}
ccode=NWChangeObjectPassword(
/* > Connection handle */ connHandle,
/* > Object name */ name,
/* > Object Type */ OT_USER,
/* > Old password */ "",
/* > New password */ password);
if(ccode)
{
printf("NWChangeObjectPassword failed: %X\n",ccode);
exit(1);
}
memset(&log,0,sizeof(LOGIN_CONTROL));
memset(log.timeBitMap, 0XFF, sizeof(log.timeBitMap));
/*-----------------------------------------------------------------------
** example of how the LOGIN_CONTROL can be modified
*/
log.minimumPasswordLength=5;
log.maxConcurrentConnections=NWWordSwap(2);
/*-----------------------------------------------------------------------
** Write property values to the LOGIN_CONTROL property.
*/
ccode=NWWritePropertyValue(
/* > Connection handle */ connHandle,
/* > Object name */ name,
/* > Object type */ OT_USER,
/* > Objects property name */ "LOGIN_CONTROL",
/* > segment number or written data */ 1,
/* > 128 byte buffer containing data */ (NWSEGMENT_DATA)&log,
/* > if 0x00 no more segments written */ 0x00);
if(ccode)
{
printf("NWWritePropertyValue failed: %X\n",ccode);
exit(1);
}
/*-----------------------------------------------------------------------
** added the user to the group EVERYONE's GROUP_MEMBERS list
*/
ccode=NWAddObjectToSet(
/* > connection Handle */ connHandle,
/* > New SET object name */ "EVERYONE",
/* > New SET object type */ OT_USER_GROUP,
/* > SETS property name */ "GROUP_MEMBERS",
/* > name of object being added to SET */ name,
/* > type of object being added to SET */ OT_USER);
if(ccode)
{
printf("NWAddObjectToSet failed: %X\n",ccode);
exit(1);
}
/*-----------------------------------------------------------------------
** Add object EVERYONE to the GROUPS_I'M_IN property in the user SET.
*/
ccode=NWAddObjectToSet(
/* > connection Handle */ connHandle,
/* > New SET object name */ name,
/* > New SET object type */ OT_USER,
/* > SETS property name */ "GROUPS_I'M_IN",
/* > name of object being added to SET */ "EVERYONE",
/* > type of object being added to SET */ OT_USER_GROUP);
if(ccode)
{
printf("NWAddObjectToSet failed: %X\n",ccode);
exit(1);
}
/*-----------------------------------------------------------------------
** Add object EVERYONE to the SECURITY_EQUALS property in the user SET.
** If this is not done then the user has no security rights and syscon
** will give an error 251.
*/
ccode=NWAddObjectToSet(
/* > connection Handle */ connHandle,
/* > New SET object name */ name,
/* > New SET object type */ OT_USER,
/* > SETS property name */ "SECURITY_EQUALS",
/* > name of object being added to SET */ "EVERYONE",
/* > type of object being added to SET */ OT_USER_GROUP);
if(ccode)
{
printf("NWAddObjectToSet failed: %X\n",ccode);
exit(1);
}
}