diff options
author | Rob Crittenden <rcritten@redhat.com> | 2009-10-07 16:48:57 -0400 |
---|---|---|
committer | Rob Crittenden <rcritten@redhat.com> | 2009-10-12 09:37:12 -0400 |
commit | 416c2a894f6563284ac146745390f98763487f0a (patch) | |
tree | e42b884c936077c7b33c6560c9e65787a58af14e /ipa-client/ipa-join.c | |
parent | 03731660020425879607e7acf4a57e84f757ca0a (diff) | |
download | freeipa-416c2a894f6563284ac146745390f98763487f0a.tar.gz freeipa-416c2a894f6563284ac146745390f98763487f0a.tar.xz freeipa-416c2a894f6563284ac146745390f98763487f0a.zip |
Improve debugging, general output, initialize xmlrpc-c properly
Diffstat (limited to 'ipa-client/ipa-join.c')
-rw-r--r-- | ipa-client/ipa-join.c | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/ipa-client/ipa-join.c b/ipa-client/ipa-join.c index d08d3b578..68af1ea4a 100644 --- a/ipa-client/ipa-join.c +++ b/ipa-client/ipa-join.c @@ -173,6 +173,11 @@ connect_ldap(const char *hostname, const char *binddn, const char *bindpw) { int ssl = LDAP_OPT_X_TLS_HARD; int version = LDAP_VERSION3; int ret; + int ldapdebug = 0; + if (debug) { + ldapdebug=2; + ret = ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, &ldapdebug); + } if (ldap_set_option(NULL, LDAP_OPT_X_TLS_CACERTFILE, CAFILE) != LDAP_OPT_SUCCESS) goto fail; @@ -191,15 +196,20 @@ connect_ldap(const char *hostname, const char *binddn, const char *bindpw) { ret = ldap_bind_s(ld, binddn, bindpw, LDAP_AUTH_SIMPLE); if (ret != LDAP_SUCCESS) { + int err; + + ldap_get_option(ld, LDAP_OPT_RESULT_CODE, &err); if (debug) - fprintf(stderr, "Bind failed\n"); + fprintf(stderr, "Bind failed: %s\n", ldap_err2string(err)); goto fail; } return ld; fail: - ldap_unbind_ext(ld, NULL, NULL); + if (ld != NULL) { + ldap_unbind_ext(ld, NULL, NULL); + } return NULL; } @@ -210,7 +220,7 @@ get_root_dn(const char *ipaserver, char **ldap_base) char *root_attrs[] = {"namingContexts", NULL}; LDAPMessage *entry, *res = NULL; struct berval **ncvals; - int ret, rval; + int ret, rval = 0; ld = connect_ldap(ipaserver, NULL, NULL); if (!ld) { @@ -225,6 +235,7 @@ get_root_dn(const char *ipaserver, char **ldap_base) if (ret != LDAP_SUCCESS) { fprintf(stderr, "Search for %s on rootdse failed with error %d", root_attrs[0], ret); + rval = 1; goto done; } @@ -232,8 +243,9 @@ get_root_dn(const char *ipaserver, char **ldap_base) entry = ldap_first_entry(ld, res); ncvals = ldap_get_values_len(ld, entry, root_attrs[0]); if (!ncvals) { - fprintf(stderr, "No values for %s", root_attrs[0]); - goto done; + fprintf(stderr, "No values for %s", root_attrs[0]); + rval = 1; + goto done; } *ldap_base = strdup(ncvals[0]->bv_val); @@ -242,7 +254,9 @@ get_root_dn(const char *ipaserver, char **ldap_base) done: if (res) ldap_msgfree(res); - ldap_unbind_ext(ld, NULL, NULL); + if (ld != NULL) { + ldap_unbind_ext(ld, NULL, NULL); + } return rval; } @@ -284,10 +298,15 @@ join_ldap(const char *ipaserver, const char *hostname, const char ** binddn, con *binddn = NULL; - get_root_dn(ipaserver, &ldap_base); + if (get_root_dn(ipaserver, &ldap_base) != 0) { + fprintf(stderr, "Unable to determine root DN of %s\n", ipaserver); + rval = 1; + goto done; + } ld = connect_ldap(ipaserver, NULL, NULL); if (!ld) { + fprintf(stderr, "Unable to make an LDAP connection to %s\n", ipaserver); rval = 1; goto done; } @@ -328,7 +347,9 @@ join_ldap(const char *ipaserver, const char *hostname, const char ** binddn, con ldap_value_free_len(ncvals); ldap_msgfree(result); - ldap_unbind_ext(ld, NULL, NULL); + if (ld != NULL) { + ldap_unbind_ext(ld, NULL, NULL); + } /* Now rebind as the host */ ld = connect_ldap(ipaserver, *binddn, bindpw); @@ -359,7 +380,9 @@ ldap_done: free(filter); free(search_base); free(ldap_base); - ldap_unbind_ext(ld, NULL, NULL); + if (ld != NULL) { + ldap_unbind_ext(ld, NULL, NULL); + } done: if (valresult) ber_bvfree(valresult); @@ -390,6 +413,8 @@ join_krb5(const char *ipaserver, const char *hostname, const char **hostdn, cons xmlrpc_env_init(&env); + xmlrpc_client_setup_global_const(&env); + #if 1 asprintf(&url, "https://%s:443/ipa/xml", ipaserver); #else |