[Date Prev][Date Next] [Chronological] [Thread] [Top]

Is this a bug?


I tried a little c-programming and came across a segmentation fault, I don't
Here is the code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <lber.h>
#include <ldap.h>

void dn2xmlanrede(char *dn, char *ldaphost)
  LDAP *ld;
  LDAPMessage *res;
  char *ldhost, *sn, *base;
  char *attrs[] = {"l", "streetAddress", "postalAddress", "postalCode", "sn", "givenName", "gender"};
  int gender=0, anrlen, ret;

  ld = ldap_open(ldaphost, 389);
  base = strdup(dn);
  ret = ldap_simple_bind_s(ld, "", "");
  if(ret < 0)
    ldap_perror(ld, "simple bind failed");
    ret = ldap_search_s(ld, base, 0, "objectclass=*", attrs, 0, &res);
    if(ldap_count_entries(ld, res) > 0)
      LDAPMessage *entry;
      char **vals;
      entry = ldap_first_entry(ld, res);
      vals = ldap_get_values(ld, entry, "sn");
      sn = strdup(vals[0]);
      vals = ldap_get_values(ld, entry, "gender");
      gender = !strcmp(vals[0], "female");
	printf("<ANREDE>Frau %s</ANREDE>\n", sn);
	sprintf("<ANREDE>Herr %s</ANREDE>\n", sn);
      printf("Nix gefunden\n");
  printf("Nix gefunden");

int main(int argc, char **argv)
  dn2xmlanrede(argv[1], "localhost");
This gives me a segmentation fault in ldap_searc_s. I see the ldap_open, and
ldap_bind working, but than it fails.
I have a similar piece of code working. 
Somebody has a idea?

Dipl-Inf. Konstantin Agouros aka Elwood Blues. Internet: elwood@agouros.de
Otkerstr. 28, 81547 Muenchen, Germany. Tel +49 89 69370185
"Captain, this ship will not sustain the forming of the cosmos." B'Elana Torres