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
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <stdio.h>
00011 #include <string.h>
00012
00013 #include <isode/ds/dsapi/dsapi.h>
00014
00020 #define S(a) (a), strlen(a)
00021
00028 int main ( void )
00029 {
00030 DS_Session *ds = NULL;
00031 DS_Indication *di = NULL;
00032 DS_ErrorType t;
00033 DS_ErrorValue v;
00034 DS_DN *dn = NULL;
00035 DS_Attr *sn = NULL;
00036 DS_Attr *mail = NULL;
00037 DS_Attr *description = NULL;
00038 DS_Entry *entry = NULL;
00039 DS_Status status;
00040 int rc = 1;
00041
00042 status = DS_Initialize( );
00043 if ( status != DS_E_NOERROR ) {
00044 fprintf( stderr, "Initialization failed\n" );
00045 goto cleanup;
00046 }
00047
00048 status = DS_String2DN( "cn=DSA Manager,cn=dsa,dc=example,dc=com", &dn );
00049 if ( status != DS_E_NOERROR ) {
00050 fprintf( stderr, "Bad Manager DN\n" );
00051 goto cleanup;
00052 }
00053
00054 status = DS_BindSync_Simple( "Internet=localhost+19999",
00055 dn, "secret",
00056 &ds );
00057 DS_DN_Delete( dn );
00058 dn = NULL;
00059
00060 if ( status != DS_E_NOERROR ) {
00061 fprintf( stderr, "Bind failed\n" );
00062 goto cleanup;
00063 }
00064
00065
00066 status = DS_Entry_New( &entry );
00067
00068 status = DS_String2DN( "cn=John Smith,ou=People,dc=example,dc=com", &dn );
00069 status = DS_Entry_SetDN( entry, dn );
00070
00071 status = DS_Attr_New( "sn", &sn );
00072 status = DS_Attr_AddStringValue( sn, S("Schmidt") );
00073 status = DS_Entry_AddValues( entry, sn );
00074
00075 status = DS_Attr_New( "mail", &mail );
00076
00077 status = DS_Entry_DeleteValues( entry, mail );
00078
00079 status = DS_Attr_New( "description", &description );
00080 status = DS_Attr_AddStringValue( description, S("new surname") );
00081 status = DS_Entry_ReplaceValues( entry, description );
00082
00083 status = DS_ModifySync( ds, entry, NULL, &di );
00084 if ( di != NULL &&
00085 DS_Indication_GetErrorCodes( di, &t, &v ) != DS_E_NOERROR )
00086 fprintf( stderr, "Modify returns error type %d and error value %d\n",
00087 t, v );
00088
00089 if ( status != DS_E_NOERROR ) {
00090 fprintf( stderr, "Modify operation failed\n" );
00091 goto cleanup;
00092 }
00093
00094 rc = 0;
00095
00096 cleanup:
00097 if ( di != NULL ) DS_Indication_Delete( di );
00098 if ( entry != NULL ) DS_Entry_Delete( entry );
00099 if ( mail != NULL ) DS_Attr_Delete( mail );
00100 if ( sn != NULL ) DS_Attr_Delete( sn );
00101 if ( description != NULL ) DS_Attr_Delete( description );
00102 if ( ds != NULL ) DS_UnbindSync( &ds );
00103
00104 return rc;
00105 }