2N/A/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2N/A/*
2N/A * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#include <string.h>
2N/A#include <time.h>
2N/A#include "kdb_ldap.h"
2N/A#include "ldap_misc.h"
2N/A#include "ldap_main.h"
2N/A#include "ldap_handle.h"
2N/A#include "ldap_err.h"
2N/A#include "ldap_principal.h"
2N/A#include "princ_xdr.h"
2N/A#include "ldap_pwd_policy.h"
2N/A
2N/A/*
2N/A * Solaris libldap does not provide the following functions which are in
2N/A * OpenLDAP. Note, Solaris Kerberos added the use_SSL to do a SSL init. Also
2N/A * added errstr to return specific error if it isn't NULL. Yes, this is ugly
2N/A * and no, the errstr should not be free()'ed.
2N/A */
2N/A#ifndef HAVE_LDAP_INITIALIZE
2N/Aint
2N/Aldap_initialize(LDAP **ldp, char *url, int use_SSL, char **errstr)
2N/A{
2N/A int rc = LDAP_SUCCESS;
2N/A LDAP *ld = NULL;
2N/A LDAPURLDesc *ludp = NULL;
2N/A
2N/A /* For now, we don't use any DN that may be provided. And on
2N/A Solaris (based on Mozilla's LDAP client code), we need the
2N/A _nodn form to parse "ldap://host" without a trailing slash.
2N/A
2N/A Also, this version won't handle an input string which contains
2N/A multiple URLs, unlike the OpenLDAP ldap_initialize. See
2N/A https://bugzilla.mozilla.org/show_bug.cgi?id=353336#c1 . */
2N/A
2N/A /* to avoid reinit and leaking handles, *ldp must be NULL */
2N/A if (*ldp != NULL)
2N/A return LDAP_SUCCESS;
2N/A
2N/A#ifdef HAVE_LDAP_URL_PARSE_NODN
2N/A rc = ldap_url_parse_nodn(url, &ludp);
2N/A#else
2N/A rc = ldap_url_parse(url, &ludp);
2N/A#endif
2N/A if (rc == 0) {
2N/A if (use_SSL == SSL_ON)
2N/A ld = ldapssl_init(ludp->lud_host, ludp->lud_port, 1);
2N/A else
2N/A ld = ldap_init(ludp->lud_host, ludp->lud_port);
2N/A
2N/A if (ld != NULL)
2N/A *ldp = ld;
2N/A else {
2N/A if (errstr != NULL)
2N/A *errstr = strerror(errno);
2N/A rc = LDAP_OPERATIONS_ERROR;
2N/A }
2N/A
2N/A ldap_free_urldesc(ludp);
2N/A } else {
2N/A /* report error from ldap url parsing */
2N/A if (errstr != NULL)
2N/A *errstr = ldap_err2string(rc);
2N/A /* convert to generic LDAP error */
2N/A rc = LDAP_OPERATIONS_ERROR;
2N/A }
2N/A return rc;
2N/A}
2N/A#endif /* HAVE_LDAP_INITIALIZE */