$NetBSD: patch-aw,v 1.1 2005/11/02 03:11:36 aolcarton Exp $ --- scepd/dn2xid.c.orig 2001-03-26 05:36:47.000000000 -0500 +++ scepd/dn2xid.c @@ -22,8 +22,7 @@ int debug = 0; extern int optind; extern char *optarg; -char *ldaphost = "localhost"; -int ldapport = LDAP_PORT; +char *ldapuri = NULL; char *binddn = NULL; char *bindpw = NULL; @@ -38,9 +37,10 @@ int main(int argc, char *argv[]) { BIO *bio; X509 *x509; unsigned char *data; + int version3 = 3, rc; /* parse command line */ - while (EOF != (c = getopt(argc, argv, "dD:w:h:p:"))) + while (EOF != (c = getopt(argc, argv, "dD:w:H:"))) switch (c) { case 'd': debug++; @@ -51,13 +51,8 @@ int main(int argc, char *argv[]) { case 'w': bindpw = optarg; break; - case 'h': - ldaphost = optarg; - break; - case 'p': - ldapport = atoi(optarg); - if ((ldapport < 0) || (ldapport > 65535)) - ldapport = LDAP_PORT; + case 'H': + ldapuri = optarg; break; } @@ -71,10 +66,16 @@ int main(int argc, char *argv[]) { dn = argv[optind]; /* create an ldap session */ - ldap = ldap_init(ldaphost, ldapport); - if (ldap == NULL) { - fprintf(stderr, "%s:%d: cannot connect to LDAP\n", __FILE__, - __LINE__); + rc = ldap_initialize(&ldap, ldapuri); + if (rc || ldap == NULL) { + fprintf(stderr, "%s:%d: cannot initialize LDAP connection to %s: %s (%d)\n", + __FILE__, __LINE__, ldapuri != NULL ? ldapuri : "", ldap_err2string(rc), rc); + exit(EXIT_FAILURE); + } + if (ldap_set_option(ldap, LDAP_OPT_PROTOCOL_VERSION, &version3) + != LDAP_OPT_SUCCESS ) { + fprintf(stderr, "%s:%d: couldn't set LDAP protocol version 3\n", + __FILE__, __LINE__); exit(EXIT_FAILURE); } if (LDAP_SUCCESS != ldap_simple_bind_s(ldap, binddn, bindpw)) {