Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

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

Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

808 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