delete.c

This is an example of using a delete operation to remove an entry from the directory.

To compile this example on Unix:

cc -I /opt/isode/include -c delete.c 

To compile this example on Windows:

cl /nologo /I C:\Progra~1\Isode\include /c delete.c

To link this example on Unix:

cc -o delete delete.o -L/opt/isode/lib \
    -ldua -lisode -libase -lldap -llber \
    -lisode_ssl -lisode_crypto -lpthread

To link this example on Windows:

cl /nologo /o delete.exe delete.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>
int main ( void )
{
DS_Session *ds = NULL;
DS_Indication *di = NULL;
DS_DN *dn = NULL;
DS_Status status;
int rc = 1;
status = DS_Initialize( );
if ( status != DS_E_NOERROR ) {
fprintf( stderr, "Initialization failed\n" );
goto cleanup;
}
status = DS_String2DN( "cn=DSA Manager,cn=dsa,dc=example,dc=com", &dn );
if ( status != DS_E_NOERROR ) {
fprintf( stderr, "Bad Manager DN\n" );
goto cleanup;
}
status = DS_Session_New( "Internet=localhost+19999", 0, &ds );
if ( status != DS_E_NOERROR ) {
fprintf( stderr, "Failed to create session\n" );
goto cleanup;
}
status = DS_BindSimpleSync( ds, dn, "secret", NULL, &di );
if ( DS_Indication_GetErrorCodes( di, &t, &v ) == DS_E_NOERROR &&
t != DS_E_SUCCESS )
status = DS_E_DSOPFAILED;
DS_DN_Delete( dn );
if ( status != DS_E_NOERROR ) {
fprintf( stderr, "Bind failed\n" );
goto cleanup;
}
status = DS_String2DN( "cn=John Smith,ou=People,dc=example,dc=com", &dn );
status = DS_DeleteSync( ds, dn, NULL, &di );
DS_DN_Delete( dn );
if ( di != NULL &&
fprintf( stderr, "Delete returns error type %d and error value %d\n",
t, v );
if ( status != DS_E_NOERROR ) {
fprintf( stderr, "Delete operation failed\n" );
goto cleanup;
}
rc = 0;
cleanup:
if ( di != NULL ) DS_Indication_Delete( di );
if ( ds != NULL ) DS_UnbindSync( &ds );
return rc;
}