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_Session_New( "Internet=localhost+19999", 0, &ds );
00055 if ( status != DS_E_NOERROR ) {
00056 fprintf( stderr, "Failed to create session\n" );
00057 goto cleanup;
00058 }
00059
00060 status = DS_BindSimpleSync( ds, dn, "secret", NULL, &di );
00061
00062 if ( DS_Indication_GetErrorCodes( di, &t, &v ) == DS_E_NOERROR &&
00063 t != DS_E_SUCCESS )
00064 status = DS_E_DSOPFAILED;
00065
00066 DS_Indication_Delete( di );
00067 DS_DN_Delete( dn );
00068 dn = NULL;
00069
00070 if ( status != DS_E_NOERROR ) {
00071 fprintf( stderr, "Bind failed\n" );
00072 goto cleanup;
00073 }
00074
00075
00076 status = DS_Entry_New( &entry );
00077
00078 status = DS_String2DN( "cn=John Smith,ou=People,dc=example,dc=com", &dn );
00079 status = DS_Entry_SetDN( entry, dn );
00080
00081 status = DS_Attr_New( "sn", &sn );
00082 status = DS_Attr_AddStringValue( sn, S("Schmidt") );
00083 status = DS_Entry_AddValues( entry, sn );
00084
00085 status = DS_Attr_New( "mail", &mail );
00086
00087 status = DS_Entry_DeleteValues( entry, mail );
00088
00089 status = DS_Attr_New( "description", &description );
00090 status = DS_Attr_AddStringValue( description, S("new surname") );
00091 status = DS_Entry_ReplaceValues( entry, description );
00092
00093 status = DS_ModifySync( ds, entry, NULL, &di );
00094 if ( di != NULL &&
00095 DS_Indication_GetErrorCodes( di, &t, &v ) != DS_E_NOERROR )
00096 fprintf( stderr, "Modify returns error type %d and error value %d\n",
00097 t, v );
00098
00099 if ( status != DS_E_NOERROR ) {
00100 fprintf( stderr, "Modify operation failed\n" );
00101 goto cleanup;
00102 }
00103
00104 rc = 0;
00105
00106 cleanup:
00107 if ( di != NULL ) DS_Indication_Delete( di );
00108 if ( entry != NULL ) DS_Entry_Delete( entry );
00109 if ( mail != NULL ) DS_Attr_Delete( mail );
00110 if ( sn != NULL ) DS_Attr_Delete( sn );
00111 if ( description != NULL ) DS_Attr_Delete( description );
00112 if ( ds != NULL ) DS_UnbindSync( &ds );
00113
00114 return rc;
00115 }