Solved

How do I convert a char * to a struct berval for ldap_sasl_bind_s?

Posted on 2010-09-15
3
894 Views
Last Modified: 2013-12-24
I am new to C so any guidance will be greatly appreciated.  ldap_simple_bind_s is depricated in favor of ldap_sasl_bind_s.  I need to recompile a program that previously used ldap_simple_bind_s.  The password value is passed to the function that is calling ldap_sasl_bind_s as a char *, but sasl_bind_s is wanting a struct berval.  Do I need to convert it, and if so, how?

LDAP_F( int )
ldap_simple_bind_s LDAP_P(( /* deprecated, use ldap_sasl_bind_s */
        LDAP *ld,
        LDAP_CONST char *who,
        LDAP_CONST char *passwd ));

LDAP_F( int )
ldap_sasl_bind_s LDAP_P((
        LDAP                    *ld,
        LDAP_CONST char *dn,
        LDAP_CONST char *mechanism,
        struct berval   *cred,
        LDAPControl             **serverctrls,
        LDAPControl             **clientctrls,
        struct berval   **servercredp ));
0
Comment
Question by:ssbb123
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 33683248
Since a 'strunct berval' is

struct berval {
  unsigned long bv_len;
  char *bv_val;
};

you could use


#include <string.h>

void string_to_berval(const char* pstr, struct berval* pbv) {

  pbv->bv_len = strlen(pstr);
  pbv->bv_val = pstr;
}

//...

char* passwd = "TopSecret";
struct berval bv;

string_to_berval(passwd,&bv);

Open in new window

0
 

Author Comment

by:ssbb123
ID: 33683855
That works! I was trying to make it much more complicated than that =).  Thanks!!!
0
 
LVL 86

Expert Comment

by:jkr
ID: 33684304
Good to know ;o)

BTW, you should close your questions when they're resolved.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some very basic things about SQL Server filegroups.
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question