From patchwork Tue Nov 6 17:34:12 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 197524 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from userp1040.oracle.com (userp1040.oracle.com [156.151.31.81]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "userp1040.oracle.com", Issuer "VeriSign Class 3 International Server CA - G3" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 910CF2C008A for ; Wed, 7 Nov 2012 04:37:40 +1100 (EST) Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by userp1040.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id qA6HbZ1P026996 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 6 Nov 2012 17:37:36 GMT Received: from oss.oracle.com (oss-external.oracle.com [137.254.96.51]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id qA6HbZOt027061 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 6 Nov 2012 17:37:35 GMT Received: from localhost ([127.0.0.1] helo=oss.oracle.com) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1TVn2g-0007LU-4u; Tue, 06 Nov 2012 09:34:26 -0800 Received: from acsinet22.oracle.com ([141.146.126.238]) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1TVn2X-0007L7-TR for fedfs-utils-devel@oss.oracle.com; Tue, 06 Nov 2012 09:34:17 -0800 Received: from acsinet13.oracle.com (acsinet13.oracle.com [141.146.126.235]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id qA6HYHCO027679 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 6 Nov 2012 17:34:17 GMT Received: from mail-pb0-f43.google.com (mail-pb0-f43.google.com [209.85.160.43]) by acsinet13.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id qA6HYGgs015365 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Tue, 6 Nov 2012 17:34:17 GMT Received: by mail-pb0-f43.google.com with SMTP id jt11so539965pbb.2 for ; Tue, 06 Nov 2012 09:34:16 -0800 (PST) Received: by 10.66.85.67 with SMTP id f3mr4680749paz.0.1352223255839; Tue, 06 Nov 2012 09:34:15 -0800 (PST) Received: from seurat.1015granger.net ([2001:df8:0:64:20c:29ff:fe93:815b]) by mx.google.com with ESMTPS id zv10sm12631650pbc.76.2012.11.06.09.34.13 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 06 Nov 2012 09:34:13 -0800 (PST) From: Chuck Lever To: fedfs-utils-devel@oss.oracle.com Date: Tue, 06 Nov 2012 12:34:12 -0500 Message-ID: <20121106173412.26310.54033.stgit@seurat.1015granger.net> In-Reply-To: <20121106172934.26310.10982.stgit@seurat.1015granger.net> References: <20121106172934.26310.10982.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.160.43 ct-class=R6 ct-vol1=0 ct-vol2=0 ct-vol3=0 ct-risk=68 ct-spam1=0 ct-spam2=0 ct-bulk=0 rcpts=1 size=8777 X-MM-CT-Classification: not spam X-MM-CT-RefID: str=0001.0A090204.50994A19.0062,ss=1,re=-2.300,fgs=0 Subject: [fedfs-utils] [PATCH 08/11] libnsdb: Remove nsdb_get_nceprefix_s() 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: acsinet21.oracle.com [141.146.126.237] Since we no longer store a DN prefix in the naming context, nsdb_get_nceprefix_s() is no longer used. Signed-off-by: Chuck Lever --- src/include/nsdb.h | 2 src/libnsdb/fileserver.c | 272 ---------------------------------------------- 2 files changed, 0 insertions(+), 274 deletions(-) diff --git a/src/include/nsdb.h b/src/include/nsdb.h index 14ad8ed..196ef0f 100644 --- a/src/include/nsdb.h +++ b/src/include/nsdb.h @@ -321,8 +321,6 @@ FedFsStatus nsdb_annotation_delete_s(nsdb_t host, const char *dn, */ FedFsStatus nsdb_get_ncedn_s(nsdb_t host, const char *naming_context, char **dn, unsigned int *ldap_err); -FedFsStatus nsdb_get_nceprefix_s(nsdb_t host, const char *naming_context, - char **dn, unsigned int *ldap_err); FedFsStatus nsdb_get_naming_contexts_s(nsdb_t host, char ***contexts, unsigned int *ldap_err); FedFsStatus nsdb_find_naming_context_s(nsdb_t host, const char *entry, diff --git a/src/libnsdb/fileserver.c b/src/libnsdb/fileserver.c index 52bb991..01bbe11 100644 --- a/src/libnsdb/fileserver.c +++ b/src/libnsdb/fileserver.c @@ -169,278 +169,6 @@ nsdb_new_fedfs_fsl(FedFsFslType type) } /** - * Parse DN for an LDAP server's NSDB container info - * - * @param ld an initialized LDAP descriptor - * @param message an LDAP_RES_SEARCH_ENTRY message - * @param nceprefix a NUL-terminated C string containing an NCE prefix received from server - * @param tmp OUT: pointer to a NUL-terminated C string containing resulting DN - * @return true if successful - * - * Caller must free "tmp" with free(3) - */ -static _Bool -nsdb_parse_nce_dn(LDAP *ld, LDAPMessage *message, - const char *nceprefix, char **tmp) -{ - char *dn, *result; - size_t size; - int rc, len; - - dn = ldap_get_dn(ld, message); - if (dn == NULL) { - ldap_get_option(ld, LDAP_OPT_RESULT_CODE, &rc); - xlog(D_GENERAL, "%s: Failed to parse DN: %s", - __func__, ldap_err2string(rc)); - return false; - } - - /* - * If the fedfsNcePrefix value is empty, - * the NCE DN is the namingContext. - */ - if (*nceprefix == '\0') { - result = strdup(dn); - if (result == NULL) { - xlog(D_GENERAL, "%s: No memory", __func__); - goto out_err; - } - goto out; - } - - /* - * Otherwise, the NCE DN is the concatenation - * of the two strings - */ - size = strlen(nceprefix) + strlen(",") + strlen(dn) + 1; - result = malloc(size); - if (result == NULL) { - xlog(D_GENERAL, "%s: No memory", __func__); - goto out_err; - } - - len = snprintf(result, size, "%s,%s", nceprefix, dn); - if (len < 0 || (size_t)len > size) { - xlog(D_GENERAL, "%s: Buffer overflow", __func__); - free(result); - goto out_err; - } - -out: - ldap_memfree(dn); - *tmp = result; - return true; - -out_err: - ldap_memfree(dn); - return false; -} - -/** - * Parse NCE prefix attribute - * - * @param ld an initialized LDAP descriptor - * @param entry an LDAP_RES_SEARCH_ENTRY message - * @param attr a NUL-terminated C string containing the name of an attribute - * @param dn OUT: pointer to a NUL-terminated C string containing resulting DN - * @return a FedFsStatus code - * - * Caller must free "dn" with free(3) - */ -static FedFsStatus -nsdb_parse_nceprefix_attribute(LDAP *ld, LDAPMessage *entry, char *attr, - char **dn) -{ - struct berval **values; - FedFsStatus retval; - char *tmp; - - xlog(D_CALL, "%s: parsing attribute %s", __func__, attr); - if (strcasecmp(attr, "fedfsNcePrefix") != 0) - return FEDFS_OK; - - values = ldap_get_values_len(ld, entry, attr); - if (values == NULL) { - xlog(D_GENERAL, "%s: No values found for attribute %s", - __func__, attr); - return FEDFS_ERR_NSDB_RESPONSE; - } - if (values[1] != NULL) { - xlog(L_ERROR, "%s: Expecting only one value for attribute %s", - __func__, attr); - retval = FEDFS_ERR_NSDB_RESPONSE; - goto out_free; - } - - if (!nsdb_parse_nce_dn(ld, entry, values[0]->bv_val, &tmp)) { - retval = FEDFS_ERR_SVRFAULT; - goto out_free; - } - - retval = FEDFS_OK; - *dn = tmp; - -out_free: - ldap_value_free_len(values); - return retval; -} - -/** - * Construct DN for an LDAP server's NSDB container - * - * @param ld an initialized LDAP descriptor - * @param entry an LDAP_RES_SEARCH_ENTRY message - * @param dn OUT: pointer to a NUL-terminated C string containing resulting DN - * @return a FedFsStatus code - * - * Caller must free "dn" with free(3) - */ -static FedFsStatus -nsdb_parse_nceprefix_entry(LDAP *ld, LDAPMessage *entry, char **dn) -{ - BerElement *field = NULL; - FedFsStatus retval; - char *attr; - - for (attr = ldap_first_attribute(ld, entry, &field), retval = FEDFS_OK; - attr != NULL && retval == FEDFS_OK; - attr = ldap_next_attribute(ld, entry, field)) { - retval = nsdb_parse_nceprefix_attribute(ld, entry, - attr, dn); - ldap_memfree(attr); - } - - if (field != NULL) - ber_free(field, 0); - return retval; -} - -/** - * Get the naming context's NSDB DN, if it has one - * - * @param host an initialized and bound nsdb_t object - * @param naming_context NUL-terminated C string containing one naming context - * @param dn OUT: pointer to a NUL-terminated C string containing full DN of NSDB container - * @param ldap_err OUT: possibly an LDAP error code - * @return a FedFsStatus code - * - * Caller must free "dn" with free(3) - * - * ldapsearch equivalent: - * - * @verbatim - - ldapsearch -b "naming_context" -s base (objectClass=*) fedfsNcePrefix - @endverbatim - * - * The full DN for the NSDB container is constructed and returned in "dn." - * That is, if the requested naming context is "dc=example,dc=com" and - * the fedfsNcePrefix attribute in the server's "dc=example,dc=com" - * entry contains "ou=fedfs", then the string that is returned in "dn" - * is "ou=fedfs,dc=example,dc=com". - */ -FedFsStatus -nsdb_get_nceprefix_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; - int rc; - - if (host->fn_ldap == NULL) { - xlog(L_ERROR, "%s: NSDB not open", __func__); - return FEDFS_ERR_INVAL; - } - - if (dn == NULL || ldap_err == NULL) { - xlog(L_ERROR, "%s: Invalid parameter", __func__); - return FEDFS_ERR_INVAL; - } - - attrs[0] = "fedfsNcePrefix"; - 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); - switch (rc) { - case LDAP_SUCCESS: - break; - case LDAP_NO_SUCH_OBJECT: - xlog(D_GENERAL, "%s: %s is not an NSDB container entry", - __func__, naming_context); - return FEDFS_ERR_NSDB_NONCE; - default: - xlog(D_GENERAL, "%s: Failed to retrieve naming_context " - "entry %s: %s", __func__, naming_context, - ldap_err2string(rc)); - *ldap_err = rc; - return FEDFS_ERR_NSDB_LDAP_VAL; - } - if (response == NULL) { - xlog(D_GENERAL, "%s: Empty LDAP response\n", __func__); - return FEDFS_ERR_NSDB_FAULT; - } - - rc = ldap_count_messages(ld, response); - switch (rc) { - case -1: - xlog(D_GENERAL, "%s: Empty LDAP response\n", __func__); - retval = FEDFS_ERR_NSDB_FAULT; - goto out; - case 1: - xlog(L_ERROR, "Naming context entry %s is inaccessible", - naming_context); - retval = FEDFS_ERR_NSDB_NONCE; - goto out; - default: - xlog(D_CALL, "%s: received %d messages", __func__, rc); - break; - } - - tmp = NULL; - retval = FEDFS_OK; - for (message = ldap_first_message(ld, response); - message != NULL && retval == FEDFS_OK; - message = ldap_next_message(ld, message)) { - switch (ldap_msgtype(message)) { - case LDAP_RES_SEARCH_ENTRY: - retval = nsdb_parse_nceprefix_entry(ld, message, &tmp); - break; - case LDAP_RES_SEARCH_REFERENCE: - retval = nsdb_parse_reference(ld, message, ldap_err); - break; - case LDAP_RES_SEARCH_RESULT: - retval = nsdb_parse_result(ld, message, ldap_err); - break; - default: - xlog(L_ERROR, "%s: Unrecognized LDAP message type", - __func__); - retval = FEDFS_ERR_NSDB_FAULT; - } - } - - if (retval == FEDFS_OK) { - if (tmp == NULL) { - xlog(D_GENERAL, "%s: %s is not an NCE", - __func__, naming_context); - retval = FEDFS_ERR_NSDB_NONCE; - } else { - xlog(D_CALL, "%s: %s contains NCE prefix %s", - __func__, naming_context, tmp); - *dn = tmp; - } - } else - free(tmp); - -out: - ldap_msgfree(response); - return retval; -} - -/** * Parse fedfsNceDN attribute * * @param ld an initialized LDAP descriptor