Arjun babu
Arjun babu

Reputation: 617

how to set values in attribute of Active directory using C++?

I am using the ldap_modify function to change an attribute value using C++ ...

msgid=ldap_modify_ext_s( ld, dnNameval, ldapmod,NULL,NULL );

The problem is the mod_val argument in that function ...

LDAP *id;
dnNameval ="distinguised name";

In the ldapmod there are three values ...

  1. mod_type="attribute to be changed";
  2. mod_op=LDAP_MOD_REPLACE;
  3. ldapmod struct

The ldapmod struct is:

 typedef struct ldapmod {
      int mod_op;
      char *mod_type;
      union {
        char **modv_strvals;
        struct berval **modv_bvals;
      } mod_vals;
    #define mod_values        mod_vals.modv_strvals
    #define mod_bvalues       mod_vals.modv_bvals

} LDAPMod;

I tried passing the value like this:

mod_vals=(PWCHAR*){"bala",Null};

which resulted in the error

error C2679: binary '=' : no operator found which takes a right-hand operand 
of type 'PWCHAR *' (or there is no acceptable conversion)

I also tried this:

mod_vals.modv_strvals=(PWCHAR*) Password1;
mod_vals.modv_bvals=NULL;

but then the array has a null value...

Can anyone help me work out how to pass the values in that variable? Do I need to include any additional header files? I am already using the winldap.h header.

Thanks in advance.

Upvotes: 0

Views: 754

Answers (1)

Harry Johnston
Harry Johnston

Reputation: 36328

This won't work:

 mod_vals = (PWCHAR*){"bala",Null};

You can't assign a value to a union that way. You have to specify which of the members of the union you want to write to. Also, (PWCHAR *) is the wrong type; you're not dealing with wide characters. Even if you were, you can't convert a string just by casting it.

This won't work either:

mod_vals.modv_strvals=(PWCHAR*) Password1; 
mod_vals.modv_bvals=NULL;

The modv_strvals member is a pointer-to-pointer, not just a pointer, and it doesn't make sense to write to two members of a union; they're mutually exclusive. Depending on context you either use modv_strvals or modv_bvals, never both.

You probably want to do this:

mod_vals.modv_strvals = {"bala", Null};

Upvotes: 1

Related Questions