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 >
Wrap
C/C++ Source or Header
|
1995-07-28
|
8KB
|
226 lines
/****************************************************************************
** DISCLAIMER
**
** This program is provided as is and carries no warranty
** whatsoever. Novell disclaims and excludes any and all implied
** warranties of merchantability, title and fitness for a particular
** purpose. Novell does not warrant that the software will satisfy
** your requirements or that the software is without defect or error
** or that operation of the software will be uninterrupted. You are
** using the software at your risk. The software is not a product
** of Novell, Inc. or any of subsidiaries.
**
****************************************************************************
**
** File: bindserv.c
**
** Desc: Bindery Services -- sample code
**
** Create a user object in the bindery and gives this new user
** a password. The new user object is added to the group
** EVERYONE and given supervisor equivalent access.
**
** API Calls:
** NWCallsInit()
** NWGetDefaultConnectionID()
** NWCreateObject()
** NWChangeObjectPassword()
** NWCreateProperty()
** NWWritePropertyValue()
** NWAddObjectToSet()
**
** History:
**
** ------------------------------------------------------------------
** 10/94 BBA Original.
*/
#include <stdio.h>
#include <stdlib.h>
#include <mem.h>
#define NWDOS
#include <nwcalls.h>
NWCCODE cCode;
NWCONN_HANDLE connHandle;
extern unsigned _stklen = (1024 * 8);
struct { /* loginControl structure */
BYTE accountExpirationDate[3] ;
BYTE accountDisabledFlag ;
BYTE passwordExpirationDate[3] ;
BYTE graceLogin ;
WORD passwordExpirationIntervals ;
BYTE graceLoginResetValue ;
BYTE minPasswordLength ;
WORD maxConcurrentConnections ;
BYTE allowedLoginTimeBitmap[42] ;
BYTE lastLoginDateTime[6] ;
BYTE restrictionFlags ;
BYTE unused ;
DWORD maxDiskUsageInBlocks ;
WORD badLoginCount ;
DWORD nextResetTime ;
BYTE badLoginAddr[12] ;
BYTE paddingToMakeStruct128Long[42] ;
} loginControl ;
void main(void)
{ /* start of main */
/* Initialize NWCalls */
cCode = NWCallsInit( NULL, NULL );
if (cCode)
{
printf( "\nNWCallsInit: failed %04x", cCode );
exit(1);
}
/* Retrieve the connection handle of the server that you wish to issue all
requests. Note: You can use NWGetDefaultConnectionID or
NWGetConnectionHandle */
cCode = NWGetDefaultConnectionID(&connHandle);
if (cCode)
{
printf( "\nNWGetDefaultConnectionID: failed %04x", cCode );
exit(1);
}
/* Creates user TESTUSER and gives security rights of BS_OBJECT_WRITE and
BS_ANY_READ */
cCode = NWCreateObject( connHandle,
"TESTUSER",
OT_USER,
BF_STATIC,
BS_OBJECT_WRITE | BS_ANY_READ );
if (cCode)
{
printf( "\nNWCreateObject: failed %04x", cCode );
exit(1);
}
/* Assign a password of XXXXXXXX for TESTUSER */
cCode = NWChangeObjectPassword( connHandle,
"TESTUSER",
OT_USER,
"",
"XXXXXXXX" );
if (cCode)
printf( "\nNWChangeObjectPassword: failed %04x", cCode );
/* Create the property "LOGIN_CONTROL" */
cCode = NWCreateProperty( connHandle,
"TESTUSER",
OT_USER,
"LOGIN_CONTROL",
BF_STATIC | BF_ITEM,
BS_SUPER_WRITE | BS_OBJECT_READ );
if (cCode)
printf( "\nNWCreateProperty: failed %04x", cCode );
/* Manipulates the loginControl structure to allow TESTUSER to have a
minimum password length of 5 characters and allows TESTUSER to login
at any time. */
loginControl.minPasswordLength = 5;
memset(loginControl.allowedLoginTimeBitmap, 0xFF,
sizeof(loginControl.allowedLoginTimeBitmap) );
/* Write the loginControl structure to the "LOGIN_CONTROL" property. */
cCode = NWWritePropertyValue( connHandle,
"TESTUSER",
OT_USER,
"LOGIN_CONTROL",
1,
(BYTE *)&loginControl,
0x00 );
if (cCode)
printf( "\nNWWritePropertyValue: failed %04x", cCode );
/* This code creates the group EVERYONE with a property
GROUP_MEMBERS. This is not needed if group EVERYONE already exists. */
cCode = NWCreateObject( connHandle,
"EVERYONE",
OT_USER_GROUP,
BF_STATIC,
BS_OBJECT_WRITE | BS_ANY_READ );
if (cCode)
printf( "\nNWCreateObject: failed %04x", cCode );
cCode = NWCreateProperty( connHandle,
"EVERYONE",
OT_USER_GROUP,
"GROUP_MEMBERS",
BF_STATIC | BF_SET,
BS_SUPER_WRITE | BS_LOGGED_READ );
if (cCode)
printf( "\nNWCreateProperty: failed %04x", cCode );
/* Make TESTUSER a member of the group EVERYONE. There are three steps:
1. Adds TESTUSER to the "GROUP_MEMBERS" property of the object EVERYONE
2. Creates the property "GROUPS_I'M_IN"
3. Adds the group EVERYONE to the newly created "GROUPS_I'M_IN" property
*/
cCode = NWAddObjectToSet( connHandle,
"EVERYONE",
OT_USER_GROUP,
"GROUP_MEMBERS",
"TESTUSER",
OT_USER );
if (cCode)
printf( "\nNWAddObjectToSet: failed %04x", cCode );
cCode = NWCreateProperty( connHandle,
"TESTUSER",
OT_USER,
"GROUPS_I'M_IN",
BF_STATIC | BF_SET,
BS_SUPER_WRITE | BS_LOGGED_READ );
if (cCode)
printf( "\nNWCreateProperty: failed %04x", cCode );
cCode = NWAddObjectToSet( connHandle,
"TESTUSER",
OT_USER,
"GROUPS_I'M_IN",
"EVERYONE",
OT_USER_GROUP);
if (cCode)
printf( "\nNWAddObjectToSet: failed %04x", cCode );
/* Makes TESTUSER a supervisor equivalent by creating the property
"SECURITY_EQUALS" and adding the user SUPERVISOR to this property. */
cCode = NWCreateProperty( connHandle,
"TESTUSER",
OT_USER,
"SECURITY_EQUALS",
BF_STATIC | BF_SET,
BS_SUPER_WRITE | BS_OBJECT_READ );
if (cCode)
printf( "\nNWCreateProperty: failed %04x", cCode );
cCode = NWAddObjectToSet( connHandle,
"TESTUSER",
OT_USER,
"SECURITY_EQUALS",
"SUPERVISOR",
OT_USER );
if (cCode)
printf( "\nNWAddObjectToSet: failed %04x", cCode );
}