From patchwork Thu Nov 29 01:49:59 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 202638 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from aserp1040.oracle.com (aserp1040.oracle.com [141.146.126.69]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "aserp1040.oracle.com", Issuer "VeriSign Class 3 International Server CA - G3" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 9E4772C0085 for ; Thu, 29 Nov 2012 12:50:11 +1100 (EST) Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by aserp1040.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id qAT1o8tJ008433 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 29 Nov 2012 01:50:09 GMT Received: from oss.oracle.com (oss-external.oracle.com [137.254.96.51]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id qAT1o8VY029767 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 29 Nov 2012 01:50:08 GMT Received: from localhost ([127.0.0.1] helo=oss.oracle.com) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1TdtGR-000813-U5; Wed, 28 Nov 2012 17:50:07 -0800 Received: from ucsinet21.oracle.com ([156.151.31.93]) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1TdtGM-00080a-IF for fedfs-utils-devel@oss.oracle.com; Wed, 28 Nov 2012 17:50:02 -0800 Received: from acsinet13.oracle.com (acsinet13.oracle.com [141.146.126.235]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id qAT1o1Fg029274 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 29 Nov 2012 01:50:02 GMT Received: from mail-ia0-f171.google.com (mail-ia0-f171.google.com [209.85.210.171]) by acsinet13.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id qAT1nQXB002765 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Thu, 29 Nov 2012 01:50:01 GMT Received: by mail-ia0-f171.google.com with SMTP id b35so8185184iac.2 for ; Wed, 28 Nov 2012 17:50:00 -0800 (PST) Received: by 10.50.190.161 with SMTP id gr1mr24169030igc.14.1354153800890; Wed, 28 Nov 2012 17:50:00 -0800 (PST) Received: from seurat.1015granger.net (adsl-99-26-161-222.dsl.sfldmi.sbcglobal.net. [99.26.161.222]) by mx.google.com with ESMTPS id i10sm5987197igb.12.2012.11.28.17.50.00 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 28 Nov 2012 17:50:00 -0800 (PST) From: Chuck Lever To: fedfs-utils-devel@oss.oracle.com Date: Wed, 28 Nov 2012 20:49:59 -0500 Message-ID: <20121129014959.2497.69600.stgit@seurat.1015granger.net> In-Reply-To: <20121129014751.2497.93909.stgit@seurat.1015granger.net> References: <20121129014751.2497.93909.stgit@seurat.1015granger.net> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 X-Flow-Control-Info: class=Default reputation=ipRepBelow100 ip=209.85.210.171 ct-class=R5 ct-vol1=-97 ct-vol2=8 ct-vol3=7 ct-risk=49 ct-spam1=78 ct-spam2=8 ct-bulk=5 rcpts=1 size=13718 X-MM-CT-Classification: not spam X-MM-CT-RefID: str=0001.0A090202.50B6BF49.0040,ss=1,re=-2.300,fgs=0 Subject: [fedfs-utils] [PATCH 4/8] libnsdb: Add debugging message near ldap_search_ext_s(3) call sites X-BeenThere: fedfs-utils-devel@oss.oracle.com X-Mailman-Version: 2.1.9 Precedence: list Reply-To: fedfs-utils Developers List-Id: fedfs-utils Developers List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: fedfs-utils-devel-bounces@oss.oracle.com Errors-To: fedfs-utils-devel-bounces@oss.oracle.com X-Source-IP: acsinet22.oracle.com [141.146.126.238] Enhance observability when NSDB tools use the "-d" command line switch. Signed-off-by: Chuck Lever --- src/libnsdb/administrator.c | 96 +++++++++++++++++++++++++++++----- src/libnsdb/fileserver.c | 122 +++++++++++++++++++++++++++++++++---------- src/libnsdb/ldap.c | 22 ++++++++ src/libnsdb/nsdb-internal.h | 2 + 4 files changed, 201 insertions(+), 41 deletions(-) diff --git a/src/libnsdb/administrator.c b/src/libnsdb/administrator.c index 050e2b0..5f0c574 100644 --- a/src/libnsdb/administrator.c +++ b/src/libnsdb/administrator.c @@ -47,6 +47,82 @@ #include "xlog.h" /** + * Invoke ldap_search_ext_s(3), requesting no attributes + * + * @param func NUL-terminated C string containing name of calling function + * @param ld an initialized LDAP server descriptor + * @param base NUL-terminated C string containing search base + * @param scope LDAP scope + * @param filter NUL-terminated C string containing search filter + * @param response OUT: list of LDAP responses + * @return an LDAP result code + * + */ +static int +__nsdb_search_nsdb_none_s(const char *func, LDAP *ld, const char *base, + int scope, char *filter, LDAPMessage **response) +{ + static char *attrs[] = { LDAP_NO_ATTRS, NULL }; + char *uri; + + if (ldap_get_option(ld, LDAP_OPT_URI, &uri) == LDAP_OPT_SUCCESS) { + xlog(D_CALL, "%s:\n ldapsearch -H %s -b \"%s\" -s %s '%s'", + func, uri, base, nsdb_printable_scope(scope), filter); + ldap_memfree(uri); + } else { + xlog(D_CALL, "%s:\n ldapsearch -b \"%s\" -s %s '%s'", + func, base, nsdb_printable_scope(scope), filter); + } + + return ldap_search_ext_s(ld, (char *)base, scope, filter, attrs, + 0, NULL, NULL, NULL, + LDAP_NO_LIMIT, response); +} + +/** + * Hide the __func__ argument at call sites + */ +#define nsdb_search_nsdb_none_s(ld, base, scope, filter, response) \ + __nsdb_search_nsdb_none_s(__func__, ld, base, scope, filter, response) + +/** + * Invoke ldap_search_ext_s(3), requesting no attributes, no filter + * + * @param func NUL-terminated C string containing name of calling function + * @param ld an initialized LDAP server descriptor + * @param base NUL-terminated C string containing search base + * @param response OUT: list of LDAP responses + * @return an LDAP result code + * + */ +static int +__nsdb_search_nsdb_nofilter_s(const char *func, LDAP *ld, const char *base, + LDAPMessage **response) +{ + static char *attrs[] = { LDAP_NO_ATTRS, NULL }; + char *uri; + + if (ldap_get_option(ld, LDAP_OPT_URI, &uri) == LDAP_OPT_SUCCESS) { + xlog(D_CALL, "%s:\n ldapsearch -H %s -b \"%s\" -s one", + func, uri, base); + ldap_memfree(uri); + } else { + xlog(D_CALL, "%s:\n ldapsearch -b \"%s\" -s one", + func, base); + } + + return ldap_search_ext_s(ld, (char *)base, LDAP_SCOPE_ONELEVEL, NULL, + attrs, 0, NULL, NULL, NULL, + LDAP_NO_LIMIT, response); +} + +/** + * Hide the __func__ argument at call sites + */ +#define nsdb_search_nsdb_nofilter_s(ld, base, response) \ + __nsdb_search_nsdb_nofilter_s(__func__, ld, base, response) + +/** * Construct the DN of an FSN entry * * @param nce NUL-terminated C string containing DN of NSDB container entry @@ -187,7 +263,6 @@ static FedFsStatus nsdb_search_fsn_dn_s(LDAP *ld, const char *nce, const char *fsn_uuid, char **dn, unsigned int *ldap_err) { - static char *attrs[] = { LDAP_NO_ATTRS, NULL }; LDAPMessage *response; FedFsStatus retval; char filter[128]; @@ -201,9 +276,8 @@ nsdb_search_fsn_dn_s(LDAP *ld, const char *nce, const char *fsn_uuid, return FEDFS_ERR_INVAL; } - rc = ldap_search_ext_s(ld, nce, LDAP_SCOPE_ONELEVEL, - filter, attrs, 0, NULL, NULL, - NULL, LDAP_NO_LIMIT, &response); + rc = nsdb_search_nsdb_none_s(ld, nce, LDAP_SCOPE_ONELEVEL, + filter, &response); switch (rc) { case LDAP_SUCCESS: break; @@ -310,7 +384,6 @@ nsdb_parse_delete_fsn_fsls_entry_s(LDAP *ld, LDAPMessage *entry, static FedFsStatus nsdb_delete_fsn_fsls_s(LDAP *ld, const char *dn, unsigned int *ldap_err) { - static char *attrs[] = { LDAP_NO_ATTRS, NULL }; LDAPMessage *message, *response; FedFsStatus retval; int entries, rc; @@ -318,8 +391,7 @@ nsdb_delete_fsn_fsls_s(LDAP *ld, const char *dn, unsigned int *ldap_err) xlog(D_CALL, "%s: searching for children of %s", __func__, dn); again: - rc = ldap_search_ext_s(ld, dn, LDAP_SCOPE_ONELEVEL, NULL, attrs, 0, - NULL, NULL, NULL, LDAP_NO_LIMIT, &response); + rc = nsdb_search_nsdb_nofilter_s(ld, dn, &response); switch (rc) { case LDAP_SUCCESS: case LDAP_SIZELIMIT_EXCEEDED: @@ -773,7 +845,6 @@ static FedFsStatus nsdb_search_fsl_dn_s(LDAP *ld, const char *nce, const char *fsl_uuid, char **dn, unsigned int *ldap_err) { - static char *attrs[] = { LDAP_NO_ATTRS, NULL }; LDAPMessage *response; FedFsStatus retval; char filter[128]; @@ -787,9 +858,8 @@ nsdb_search_fsl_dn_s(LDAP *ld, const char *nce, const char *fsl_uuid, return FEDFS_ERR_INVAL; } - rc = ldap_search_ext_s(ld, nce, LDAP_SCOPE_SUBTREE, - filter, attrs, 0, NULL, NULL, - NULL, LDAP_NO_LIMIT, &response); + rc = nsdb_search_nsdb_none_s(ld, nce, LDAP_SCOPE_SUBTREE, + filter, &response); switch (rc) { case LDAP_SUCCESS: break; @@ -1275,7 +1345,6 @@ out: static FedFsStatus nsdb_delete_nsdb_fsns_s(LDAP *ld, const char *nce, unsigned int *ldap_err) { - static char *attrs[] = { LDAP_NO_ATTRS, NULL }; LDAPMessage *message, *response; FedFsStatus retval; int entries, rc; @@ -1283,8 +1352,7 @@ nsdb_delete_nsdb_fsns_s(LDAP *ld, const char *nce, unsigned int *ldap_err) xlog(D_CALL, "%s: searching for children of %s", __func__, nce); again: - rc = ldap_search_ext_s(ld, nce, LDAP_SCOPE_ONELEVEL, NULL, attrs, 0, - NULL, NULL, NULL, LDAP_NO_LIMIT, &response); + rc = nsdb_search_nsdb_nofilter_s(ld, nce, &response); switch (rc) { case LDAP_SUCCESS: case LDAP_SIZELIMIT_EXCEEDED: diff --git a/src/libnsdb/fileserver.c b/src/libnsdb/fileserver.c index a047aba..28107c7 100644 --- a/src/libnsdb/fileserver.c +++ b/src/libnsdb/fileserver.c @@ -44,9 +44,88 @@ #include "xlog.h" /** - * Default 5 second time out for LDAP requests + * Invoke ldap_search_ext_s(3), requesting all attributes + * + * @param func NUL-terminated C string containing name of calling function + * @param ld an initialized LDAP server descriptor + * @param base NUL-terminated C string containing search base + * @param scope LDAP scope + * @param filter NUL-terminated C string containing search filter + * @param response OUT: list of LDAP responses + * @return an LDAP result code + * + * A fast timeout is used to prevent hanging the caller. + */ +static int +__nsdb_search_nsdb_all_s(const char *func, LDAP *ld, const char *base, + int scope, char *filter, LDAPMessage **response) +{ + static char *attrs[] = { LDAP_ALL_USER_ATTRIBUTES, NULL }; + static struct timeval timeout = { 5, 0 }; + char *uri; + + if (ldap_get_option(ld, LDAP_OPT_URI, &uri) == LDAP_OPT_SUCCESS) { + xlog(D_CALL, "%s:\n ldapsearch -H %s -b \"%s\" -s %s '%s' *", + func, uri, base, nsdb_printable_scope(scope), filter); + ldap_memfree(uri); + } else { + xlog(D_CALL, "%s:\n ldapsearch -b \"%s\" -s %s '%s' *", + func, base, nsdb_printable_scope(scope), filter); + } + + return ldap_search_ext_s(ld, (char *)base, LDAP_SCOPE_SUBTREE, filter, + attrs, 0, NULL, NULL, &timeout, + LDAP_NO_LIMIT, response); +} + +/** + * Hide the __func__ argument at call sites + */ +#define nsdb_search_nsdb_all_s(ld, base, scope, filter, response) \ + __nsdb_search_nsdb_all_s(__func__, ld, base, scope, filter, response) + +/** + * Invoke ldap_search_ext_s(3), requesting a specific attribute + * + * @param func NUL-terminated C string containing name of calling function + * @param ld an initialized LDAP server descriptor + * @param base NUL-terminated C string containing search base + * @param filter NUL-terminated C string containing search filter + * @param attr NUL-terminated C string containing attribute name + * @param response OUT: list of LDAP responses + * @return an LDAP result code + * + * A fast timeout is used to prevent hanging the caller. */ -static struct timeval nsdb_ldap_timeout = { 5, 0 }; +static int +__nsdb_search_nsdb_attr_s(const char *func, LDAP *ld, const char *base, + char *filter, char *attr, LDAPMessage **response) +{ + static struct timeval timeout = { 5, 0 }; + char *uri, *attrs[2]; + + attrs[0] = attr; + attrs[1] = NULL; + + if (ldap_get_option(ld, LDAP_OPT_URI, &uri) == LDAP_OPT_SUCCESS) { + xlog(D_CALL, "%s:\n ldapsearch -H %s -b \"%s\" -s base '%s' %s", + func, uri, filter, attr); + ldap_memfree(uri); + } else { + xlog(D_CALL, "%s:\n ldapsearch -b \"%s\" -s base '%s' %s", + func, filter, attr); + } + + return ldap_search_ext_s(ld, (char *)base, LDAP_SCOPE_BASE, filter, + attrs, 0, NULL, NULL, &timeout, + LDAP_NO_LIMIT, response); +} + +/** + * Hide the __func__ argument at call sites + */ +#define nsdb_search_nsdb_attr_s(ld, base, filter, attr, response) \ + __nsdb_search_nsdb_attr_s(__func__, ld, base, filter, attr, response) /** * Free a single struct fedfs_fsn @@ -297,9 +376,9 @@ nsdb_get_ncedn_s(nsdb_t host, const char *naming_context, char **dn, unsigned int *ldap_err) { LDAPMessage *response, *message; - char *attrs[2], *tmp = NULL; LDAP *ld = host->fn_ldap; FedFsStatus retval; + char *tmp = NULL; int rc; if (host->fn_ldap == NULL) { @@ -312,12 +391,8 @@ nsdb_get_ncedn_s(nsdb_t host, const char *naming_context, char **dn, return FEDFS_ERR_INVAL; } - attrs[0] = "fedfsNceDN"; - attrs[1] = NULL; - rc = ldap_search_ext_s(ld, naming_context, LDAP_SCOPE_BASE, - "(objectClass=*)", attrs, 0, NULL, - NULL, &nsdb_ldap_timeout, - LDAP_NO_LIMIT, &response); + rc = nsdb_search_nsdb_attr_s(ld, naming_context, "(objectClass=*)", + "fedfsNceDN", &response); switch (rc) { case LDAP_SUCCESS: break; @@ -492,8 +567,8 @@ nsdb_get_naming_contexts_s(nsdb_t host, char ***contexts, { LDAPMessage *response, *message; LDAP *ld = host->fn_ldap; - char *attrs[2], **tmp; FedFsStatus retval; + char **tmp; int rc; if (host->fn_ldap == NULL) { @@ -506,12 +581,8 @@ nsdb_get_naming_contexts_s(nsdb_t host, char ***contexts, return FEDFS_ERR_INVAL; } - attrs[0] = "namingContexts"; - attrs[1] = NULL; - rc = ldap_search_ext_s(ld, "", LDAP_SCOPE_BASE, - "(objectClass=*)", attrs, 0, NULL, - NULL, &nsdb_ldap_timeout, - LDAP_NO_LIMIT, &response); + rc = nsdb_search_nsdb_attr_s(ld, LDAP_ROOT_DSE, "(objectClass=*)", + "namingContexts", &response); switch (rc) { case LDAP_SUCCESS: break; @@ -853,9 +924,8 @@ nsdb_resolve_fsn_find_entry_s(LDAP *ld, const char *nce, const char *fsn_uuid, return FEDFS_ERR_INVAL; } - rc = ldap_search_ext_s(ld, nce, LDAP_SCOPE_SUBTREE, - filter, NULL, 0, NULL, NULL, - NULL, LDAP_NO_LIMIT, &response); + rc = nsdb_search_nsdb_all_s(ld, nce, LDAP_SCOPE_SUBTREE, + filter, &response); switch (rc) { case LDAP_SUCCESS: break; @@ -1168,9 +1238,8 @@ nsdb_get_fsn_find_entry_s(LDAP *ld, const char *nce, const char *fsn_uuid, return FEDFS_ERR_INVAL; } - rc = ldap_search_ext_s(ld, nce, LDAP_SCOPE_ONE, - filter, NULL, 0, NULL, NULL, - NULL, LDAP_NO_LIMIT, &response); + rc = nsdb_search_nsdb_all_s(ld, nce, LDAP_SCOPE_ONE, + filter, &response); switch (rc) { case LDAP_SUCCESS: break; @@ -1420,9 +1489,8 @@ nsdb_list_find_entries_s(LDAP *ld, const char *nce, char ***fsns, char **tmp; int rc; - rc = ldap_search_ext_s(ld, nce, LDAP_SCOPE_SUBTREE, - "(objectClass=fedfsFsn)", NULL, 0, NULL, - NULL, NULL, LDAP_NO_LIMIT, &response); + rc = nsdb_search_nsdb_all_s(ld, nce, LDAP_SCOPE_ONE, + "(objectClass=fedfsFsn)", &response); switch (rc) { case LDAP_SUCCESS: break; @@ -1560,8 +1628,8 @@ nsdb_list_s(nsdb_t host, const char *nce, char ***fsns, unsigned int *ldap_err) for (j = 0; nce_list[j] != NULL; j++) { retval = nsdb_list_find_entries_s(host->fn_ldap, - nce_list[j], - fsns, ldap_err); + nce_list[j], + fsns, ldap_err); if (retval == FEDFS_OK) break; } diff --git a/src/libnsdb/ldap.c b/src/libnsdb/ldap.c index 404f6d1..f2a47c4 100644 --- a/src/libnsdb/ldap.c +++ b/src/libnsdb/ldap.c @@ -44,6 +44,28 @@ #include "xlog.h" /** + * Map scope to a printable string + * + * @param scope LDAP scope + * @return static NUL-terminated C string containing scope name + */ +const char * +nsdb_printable_scope(int scope) +{ + switch (scope) { + case LDAP_SCOPE_BASE: + return "base"; + case LDAP_SCOPE_ONE: + return "one"; + case LDAP_SCOPE_SUB: + return "sub"; + case LDAP_SCOPE_CHILDREN: + return "children"; + } + return "default"; +} + +/** * Read a password from stdin, disabling character echo * * @return a NUL-terminated C string containing the typed-in password. Caller must free the string with free(3) diff --git a/src/libnsdb/nsdb-internal.h b/src/libnsdb/nsdb-internal.h index 7defe6d..09c3d03 100644 --- a/src/libnsdb/nsdb-internal.h +++ b/src/libnsdb/nsdb-internal.h @@ -51,6 +51,8 @@ struct fedfs_nsdb { ** Private LDAP-related APIs (ldap.c) **/ +const char * nsdb_printable_scope(int scope); + void nsdb_init_add_attribute(LDAPMod *mod, const char *attribute, char **bv, const char *value);