Directory Client API
modify.c
This is an example of using a modify operation to change an existing entry in the directory.
To compile this example on Unix:
cc -I /opt/isode/include -c modify.c
To compile this example on Windows:
cl /nologo /I C:\Progra~1\Isode\include /c modify.c
To link this example on Unix:
cc -o modify modify.o -L/opt/isode/lib \ -ldua -lisode -libase -lldap -llber \ -lisode_ssl -lisode_crypto -lpthread
To link this example on Windows:
cl /nologo /o modify.exe modify.obj \ C:\Progra~1\Isode\bin\libdua.lib
/*
* Copyright (c) 2008-2009, Isode Limited, London, England.
* All rights reserved.
*
* Acquisition and use of this software and related materials for any
* purpose requires a written licence agreement from Isode Limited,
* or a written licence from an organisation licenced by Isode Limited
* to grant such a licence.
*/
#include <stdio.h>
#include <string.h>
#include <isode/ds/dsapi/dsapi.h>
#define S(a) (a), strlen(a)
int main ( void )
{
DS_Session *ds = NULL;
DS_Indication *di = NULL;
DS_ErrorType t;
DS_DN *dn = NULL;
DS_Attr *sn = NULL;
DS_Attr *mail = NULL;
DS_Attr *description = NULL;
DS_Entry *entry = NULL;
DS_Status status;
int rc = 1;
status = DS_Initialize( );
fprintf( stderr, "Initialization failed\n" );
goto cleanup;
}
if ( status != DS_E_NOERROR ) {
fprintf( stderr, "Bad Manager DN\n" );
goto cleanup;
}
if ( status != DS_E_NOERROR ) {
fprintf( stderr, "Failed to create session\n" );
goto cleanup;
}
t != DS_E_SUCCESS )
status = DS_E_DSOPFAILED;
DS_Indication_Delete( di );
DS_DN_Delete( dn );
dn = NULL;
if ( status != DS_E_NOERROR ) {
fprintf( stderr, "Bind failed\n" );
goto cleanup;
}
/* Build a set of changes */
status = DS_Entry_New( &entry );
status = DS_String2DN( "cn=John Smith,ou=People,dc=example,dc=com", &dn );
status = DS_Entry_SetDN( entry, dn );
status = DS_Entry_AddValues( entry, sn );
status = DS_Attr_New( "mail", &mail );
/* no values means delete entire attribute */
status = DS_Entry_DeleteValues( entry, mail );
status = DS_Attr_New( "description", &description );
status = DS_Attr_AddStringValue( description, S("new surname") );
status = DS_Entry_ReplaceValues( entry, description );
status = DS_ModifySync( ds, entry, NULL, &di );
if ( di != NULL &&
DS_Indication_GetErrorCodes( di, &t, &v ) != DS_E_NOERROR )
fprintf( stderr, "Modify returns error type %d and error value %d\n",
t, v );
if ( status != DS_E_NOERROR ) {
fprintf( stderr, "Modify operation failed\n" );
goto cleanup;
}
rc = 0;
cleanup:
if ( di != NULL ) DS_Indication_Delete( di );
if ( sn != NULL ) DS_Attr_Delete( sn );
if ( description != NULL ) DS_Attr_Delete( description );
return rc;
}