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
  

00001 /* 
00002  * Copyright (c) 2008, Isode Limited, London, England.
00003  * All rights reserved.
00004  * 
00005  * Acquisition and use of this software and related materials for any
00006  * purpose requires a written licence agreement from Isode Limited,
00007  * or a written licence from an organisation licenced by Isode Limited
00008  * to grant such a licence.
00009  */
00010 #include <stdio.h>
00011 
00012 #include <isode/ds/dsapi/dsapi.h>
00013 
00023 int main ( void )
00024 {
00025     DS_Session    *ds = NULL;
00026     DS_Indication *di = NULL;
00027     DS_ErrorType   t;
00028     DS_ErrorValue  v;
00029     DS_DN         *dn = NULL;
00030     DS_Status      status;
00031     int            rc = 1;
00032 
00033     status = DS_Initialize( );
00034     if ( status != DS_E_NOERROR ) {
00035         fprintf( stderr, "Initialization failed\n" );
00036         goto cleanup;
00037     }
00038 
00039     status = DS_String2DN( "cn=DSA Manager,cn=dsa,dc=example,dc=com", &dn );
00040     if ( status != DS_E_NOERROR ) {
00041         fprintf( stderr, "Bad Manager DN\n" );
00042         goto cleanup;
00043     }
00044     
00045     status = DS_BindSync_Simple( "Internet=localhost+19999",
00046                                  dn, "secret",
00047                                  &ds );
00048     DS_DN_Delete( dn );
00049 
00050     if ( status != DS_E_NOERROR ) {
00051         fprintf( stderr, "Bind failed\n" );
00052         goto cleanup;
00053     }
00054 
00055     status = DS_String2DN( "cn=John Smith,ou=People,dc=example,dc=com", &dn );
00056 
00057     status = DS_DeleteSync( ds, dn, NULL, &di );
00058     DS_DN_Delete( dn );
00059     
00060     if ( di != NULL &&
00061          DS_Indication_GetErrorCodes( di, &t, &v ) != DS_E_NOERROR )
00062         fprintf( stderr, "Delete returns error type %d and error value %d\n",
00063                  t, v );
00064     
00065     if ( status != DS_E_NOERROR ) {
00066         fprintf( stderr, "Delete operation failed\n" );
00067         goto cleanup;
00068     }
00069 
00070     rc = 0;
00071     
00072 cleanup:
00073     if ( di != NULL ) DS_Indication_Delete( di );
00074     if ( ds != NULL ) DS_UnbindSync( &ds );
00075 
00076     return rc;
00077 }
Copyright © 2008 Isode privacy   feedback Subscribe to our rss newsfeed