Solved

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

Posted on 2010-09-15
3
883 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

785 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