As a general rule, libraries should not emit error messages of any kind. A library should depend on its consumer to present errors to users.
Remove log messages for invalid function parameters. Signed-off-by: Chuck Lever <[email protected]> --- src/libnsdb/administrator.c | 124 +++++++++++-------------------------------- src/libnsdb/fileserver.c | 84 +++++++---------------------- src/libnsdb/ldap.c | 16 +----- src/libnsdb/path.c | 16 +----- 4 files changed, 60 insertions(+), 180 deletions(-) diff --git a/src/libnsdb/administrator.c b/src/libnsdb/administrator.c index 86d85cf..29a7a92 100644 --- a/src/libnsdb/administrator.c +++ b/src/libnsdb/administrator.c @@ -273,20 +273,14 @@ FedFsStatus nsdb_create_fsn_s(nsdb_t host, const char *nce, const char *fsn_uuid, const unsigned int ttl) { - if (host == NULL) { - xlog(L_ERROR, "%s: Invalid host parameter", __func__); + if (host == NULL) return FEDFS_ERR_INVAL; - } - if (host->fn_ldap == NULL) { - xlog(L_ERROR, "%s: NSDB not open", __func__); + if (host->fn_ldap == NULL) return FEDFS_ERR_INVAL; - } - if (nce == NULL || fsn_uuid == NULL) { - xlog(L_ERROR, "%s: Invalid parameter", __func__); + if (nce == NULL || fsn_uuid == NULL) return FEDFS_ERR_INVAL; - } return nsdb_create_fsn_add_entry(host, nce, fsn_uuid, ttl); } @@ -540,20 +534,14 @@ nsdb_delete_fsn_s(nsdb_t host, const char *nce, const char *fsn_uuid, FedFsStatus retval; char *dn; - if (host == NULL) { - xlog(L_ERROR, "%s: Invalid host parameter", __func__); + if (host == NULL) return FEDFS_ERR_INVAL; - } - if (host->fn_ldap == NULL) { - xlog(L_ERROR, "%s: NSDB not open", __func__); + if (host->fn_ldap == NULL) return FEDFS_ERR_INVAL; - } - if (nce == NULL || fsn_uuid == NULL) { - xlog(L_ERROR, "%s: Invalid parameter", __func__); + if (nce == NULL || fsn_uuid == NULL) return FEDFS_ERR_INVAL; - } retval = nsdb_search_fsn_dn_s(host, nce, fsn_uuid, &dn); if (retval != FEDFS_OK) @@ -883,20 +871,14 @@ nsdb_create_fsls_s(nsdb_t host, const char *nce, struct fedfs_fsl *fsls) struct fedfs_fsl *fsl, *progress; FedFsStatus retval; - if (host == NULL) { - xlog(L_ERROR, "%s: Invalid host parameter", __func__); + if (host == NULL) return FEDFS_ERR_INVAL; - } - if (host->fn_ldap == NULL) { - xlog(D_GENERAL, "%s: NSDB not open", __func__); + if (host->fn_ldap == NULL) return FEDFS_ERR_INVAL; - } - if (nce == NULL || fsls == NULL) { - xlog(D_GENERAL, "%s: Invalid parameter", __func__); + if (nce == NULL || fsls == NULL) return FEDFS_ERR_INVAL; - } for (fsl = fsls, progress = NULL; fsl != NULL; @@ -1058,20 +1040,14 @@ nsdb_delete_fsl_s(nsdb_t host, const char *nce, const char *fsl_uuid) FedFsStatus retval; char *dn; - if (host == NULL) { - xlog(L_ERROR, "%s: Invalid host parameter", __func__); + if (host == NULL) return FEDFS_ERR_INVAL; - } - if (host->fn_ldap == NULL) { - xlog(L_ERROR, "%s: NSDB not open", __func__); + if (host->fn_ldap == NULL) return FEDFS_ERR_INVAL; - } - if (nce == NULL || fsl_uuid == NULL) { - xlog(L_ERROR, "%s: Invalid parameter", __func__); + if (nce == NULL || fsl_uuid == NULL) return FEDFS_ERR_INVAL; - } retval = nsdb_search_fsl_dn_s(host, nce, fsl_uuid, &dn); if (retval != FEDFS_OK) @@ -1184,20 +1160,14 @@ nsdb_update_fsl_s(nsdb_t host, const char *nce, const char *fsl_uuid, FedFsStatus retval; char *dn; - if (host == NULL) { - xlog(L_ERROR, "%s: Invalid host parameter", __func__); + if (host == NULL) return FEDFS_ERR_INVAL; - } - if (host->fn_ldap == NULL) { - xlog(L_ERROR, "%s: NSDB not open", __func__); + if (host->fn_ldap == NULL) return FEDFS_ERR_INVAL; - } - if (nce == NULL || fsl_uuid == NULL || attribute == NULL) { - xlog(L_ERROR, "%s: Invalid parameter", __func__); + if (nce == NULL || fsl_uuid == NULL || attribute == NULL) return FEDFS_ERR_INVAL; - } retval = nsdb_search_fsl_dn_s(host, nce, fsl_uuid, &dn); if (retval != FEDFS_OK) @@ -1367,20 +1337,14 @@ nsdb_create_simple_nce_s(nsdb_t host, const char *parent, char **dn) FedFsStatus retval; char *nce; - if (host == NULL) { - xlog(L_ERROR, "%s: Invalid host parameter", __func__); + if (host == NULL) return FEDFS_ERR_INVAL; - } - if (host->fn_ldap == NULL) { - xlog(L_ERROR, "%s: NSDB not open", __func__); + if (host->fn_ldap == NULL) return FEDFS_ERR_INVAL; - } - if (parent == NULL) { - xlog(L_ERROR, "%s: Invalid parameter", __func__); + if (parent == NULL) return FEDFS_ERR_INVAL; - } if (parent[0] == '\0') retval = nsdb_create_nce_add_top_entry(host, &nce); @@ -1457,20 +1421,14 @@ nsdb_update_nci_s(nsdb_t host, const char *nce) FedFsStatus retval; char *context; - if (host == NULL) { - xlog(L_ERROR, "%s: Invalid host parameter", __func__); + if (host == NULL) return FEDFS_ERR_INVAL; - } - if (host->fn_ldap == NULL) { - xlog(L_ERROR, "%s: NSDB not open", __func__); + if (host->fn_ldap == NULL) return FEDFS_ERR_INVAL; - } - if (nce == NULL) { - xlog(L_ERROR, "%s: Invalid parameter", __func__); + if (nce == NULL) return FEDFS_ERR_INVAL; - } retval = nsdb_find_naming_context_s(host, nce, &context); if (retval != FEDFS_OK) @@ -1571,20 +1529,14 @@ nsdb_remove_nci_s(nsdb_t host, const char *nce) FedFsStatus retval; char *context; - if (host == NULL) { - xlog(L_ERROR, "%s: Invalid host parameter", __func__); + if (host == NULL) return FEDFS_ERR_INVAL; - } - if (host->fn_ldap == NULL) { - xlog(L_ERROR, "%s: NSDB not open", __func__); + if (host->fn_ldap == NULL) return FEDFS_ERR_INVAL; - } - if (nce == NULL) { - xlog(L_ERROR, "%s: Invalid parameter", __func__); + if (nce == NULL) return FEDFS_ERR_INVAL; - } retval = nsdb_find_naming_context_s(host, nce, &context); if (retval != FEDFS_OK) @@ -1720,20 +1672,14 @@ nsdb_delete_nsdb_s(nsdb_t host, const char *nce) { FedFsStatus retval; - if (host == NULL) { - xlog(L_ERROR, "%s: Invalid host parameter", __func__); + if (host == NULL) return FEDFS_ERR_INVAL; - } - if (host->fn_ldap == NULL) { - xlog(L_ERROR, "%s: NSDB not open", __func__); + if (host->fn_ldap == NULL) return FEDFS_ERR_INVAL; - } - if (nce == NULL) { - xlog(L_ERROR, "%s: Invalid parameter", __func__); + if (nce == NULL) return FEDFS_ERR_INVAL; - } retval = nsdb_remove_nci_s(host, nce); if (retval != FEDFS_OK) @@ -1767,15 +1713,11 @@ nsdb_attr_add_s(nsdb_t host, const char *dn, const char *attr, { struct berval bval; - if (host == NULL) { - xlog(L_ERROR, "%s: Invalid host parameter", __func__); + if (host == NULL) return FEDFS_ERR_INVAL; - } - if (host->fn_ldap == NULL) { - xlog(L_ERROR, "%s: NSDB not open", __func__); + if (host->fn_ldap == NULL) return FEDFS_ERR_INVAL; - } if (value == NULL) return FEDFS_ERR_INVAL; @@ -1815,15 +1757,11 @@ nsdb_attr_delete_s(nsdb_t host, const char *dn, const char *attr, { struct berval bval; - if (host == NULL) { - xlog(L_ERROR, "%s: Invalid host parameter", __func__); + if (host == NULL) return FEDFS_ERR_INVAL; - } - if (host->fn_ldap == NULL) { - xlog(L_ERROR, "%s: NSDB not open", __func__); + if (host->fn_ldap == NULL) return FEDFS_ERR_INVAL; - } if (value == NULL) return nsdb_delete_attribute_all_s(host->fn_ldap, dn, diff --git a/src/libnsdb/fileserver.c b/src/libnsdb/fileserver.c index db443a6..7c96c4e 100644 --- a/src/libnsdb/fileserver.c +++ b/src/libnsdb/fileserver.c @@ -601,20 +601,14 @@ nsdb_get_ncedn_s(nsdb_t host, const char *naming_context, char **dn) { FedFsStatus retval; - if (host == NULL) { - xlog(L_ERROR, "%s: Invalid host parameter", __func__); + if (host == NULL) return FEDFS_ERR_INVAL; - } - if (host->fn_ldap == NULL) { - xlog(L_ERROR, "%s: NSDB not open", __func__); + if (host->fn_ldap == NULL) return FEDFS_ERR_INVAL; - } - if (dn == NULL) { - xlog(L_ERROR, "%s: Invalid parameter", __func__); + if (dn == NULL) return FEDFS_ERR_INVAL; - } retval = nsdb_new_get_ncedn_s(host, naming_context, dn); if (retval != FEDFS_OK) @@ -723,20 +717,14 @@ nsdb_get_naming_contexts_s(nsdb_t host, char ***contexts) int entries; char **tmp; - if (host == NULL) { - xlog(L_ERROR, "%s: Invalid host parameter", __func__); + if (host == NULL) return FEDFS_ERR_INVAL; - } - if (host->fn_ldap == NULL) { - xlog(L_ERROR, "%s: NSDB not open", __func__); + if (host->fn_ldap == NULL) return FEDFS_ERR_INVAL; - } - if (contexts == NULL) { - xlog(L_ERROR, "%s: Invalid parameter", __func__); + if (contexts == NULL) return FEDFS_ERR_INVAL; - } host->fn_ldaperr = nsdb_search_nsdb_attr_s(ld, LDAP_ROOT_DSE, "(objectClass=*)", @@ -1287,20 +1275,14 @@ nsdb_resolve_fsn_s(nsdb_t host, const char *nce, const char *fsn_uuid, FedFsStatus retval; int i, j; - if (host == NULL) { - xlog(L_ERROR, "%s: Invalid host parameter", __func__); + if (host == NULL) return FEDFS_ERR_INVAL; - } - if (host->fn_ldap == NULL) { - xlog(L_ERROR, "%s: NSDB not open", __func__); + if (host->fn_ldap == NULL) return FEDFS_ERR_INVAL; - } - if (fsls == NULL) { - xlog(L_ERROR, "%s: Invalid parameter", __func__); + if (fsls == NULL) return FEDFS_ERR_INVAL; - } if (nce != NULL) return nsdb_resolve_fsn_find_entry_s(host, nce, @@ -1599,20 +1581,14 @@ nsdb_get_fsn_s(nsdb_t host, const char *nce, const char *fsn_uuid, FedFsStatus retval; int i, j; - if (host == NULL) { - xlog(L_ERROR, "%s: Invalid host parameter", __func__); + if (host == NULL) return FEDFS_ERR_INVAL; - } - if (host->fn_ldap == NULL) { - xlog(L_ERROR, "%s: NSDB not open", __func__); + if (host->fn_ldap == NULL) return FEDFS_ERR_INVAL; - } - if (fsn == NULL) { - xlog(L_ERROR, "%s: Invalid parameter", __func__); + if (fsn == NULL) return FEDFS_ERR_INVAL; - } if (nce != NULL) return nsdb_get_fsn_find_entry_s(host, nce, fsn_uuid, fsn); @@ -1852,20 +1828,14 @@ nsdb_list_s(nsdb_t host, const char *nce, char ***fsns) FedFsStatus retval; int i, j; - if (host == NULL) { - xlog(L_ERROR, "%s: Invalid host parameter", __func__); + if (host == NULL) return FEDFS_ERR_INVAL; - } - if (host->fn_ldap == NULL) { - xlog(L_ERROR, "%s: NSDB not open", __func__); + if (host->fn_ldap == NULL) return FEDFS_ERR_INVAL; - } - if (fsns == NULL) { - xlog(L_ERROR, "%s: Invalid parameter", __func__); + if (fsns == NULL) return FEDFS_ERR_INVAL; - } if (nce != NULL) return nsdb_list_find_entries_s(host, nce, fsns); @@ -1960,15 +1930,11 @@ nsdb_ping_nsdb_s(nsdb_t host) FedFsStatus retval; char **contexts = NULL; - if (host == NULL) { - xlog(L_ERROR, "%s: Invalid host parameter", __func__); + if (host == NULL) return FEDFS_ERR_INVAL; - } - if (host->fn_ldap == NULL) { - xlog(L_ERROR, "%s: NSDB not open", __func__); + if (host->fn_ldap == NULL) return FEDFS_ERR_INVAL; - } retval = nsdb_get_naming_contexts_s(host, &contexts); if (retval != FEDFS_OK) @@ -1999,10 +1965,8 @@ nsdb_ping_s(const char *hostname, const unsigned short port, FedFsStatus retval; nsdb_t host; - if (ldap_err == NULL) { - xlog(L_ERROR, "%s: Invalid parameter", __func__); + if (ldap_err == NULL) return FEDFS_ERR_INVAL; - } retval = nsdb_new_nsdb(hostname, port, &host); if (retval != FEDFS_OK) @@ -2083,20 +2047,14 @@ nsdb_find_naming_context_s(nsdb_t host, const char *entry, char **context) char **contexts = NULL; FedFsStatus retval; - if (host == NULL) { - xlog(L_ERROR, "%s: Invalid host parameter", __func__); + if (host == NULL) return FEDFS_ERR_INVAL; - } - if (host->fn_ldap == NULL) { - xlog(L_ERROR, "%s: NSDB not open", __func__); + if (host->fn_ldap == NULL) return FEDFS_ERR_INVAL; - } - if (context == NULL) { - xlog(L_ERROR, "%s: Invalid parameter", __func__); + if (context == NULL) return FEDFS_ERR_INVAL; - } retval = nsdb_get_naming_contexts_s(host, &contexts); if (retval != FEDFS_OK) diff --git a/src/libnsdb/ldap.c b/src/libnsdb/ldap.c index 57fbf4a..84a641c 100644 --- a/src/libnsdb/ldap.c +++ b/src/libnsdb/ldap.c @@ -963,10 +963,8 @@ nsdb_compare_dns(LDAPDN dn1, LDAPDN dn2) { int count1, count2; - if (dn1 == NULL || dn2 == NULL) { - xlog(L_ERROR, "%s: Invalid parameter", __func__); + if (dn1 == NULL || dn2 == NULL) return false; - } for (count1 = 0; dn1[count1] != NULL; count1++); for (count2 = 0; dn2[count2] != NULL; count2++); @@ -1002,10 +1000,8 @@ nsdb_compare_dn_string(LDAPDN dn1, const char *dn2_in, result = false; - if (dn1 == NULL || dn2_in == NULL || ldap_err == NULL) { - xlog(L_ERROR, "%s: Invalid parameter", __func__); + if (dn1 == NULL || dn2_in == NULL || ldap_err == NULL) goto out; - } rc = ldap_str2dn(dn2_in, &dn2, LDAP_DN_FORMAT_LDAPV3); if (rc != LDAP_SUCCESS) { @@ -1043,10 +1039,8 @@ nsdb_compare_dn_strings(const char *dn1_in, const char *dn2_in, result = false; - if (dn1_in == NULL || dn2_in == NULL || ldap_err == NULL) { - xlog(L_ERROR, "%s: Invalid parameter", __func__); + if (dn1_in == NULL || dn2_in == NULL || ldap_err == NULL) goto out; - } rc = ldap_str2dn(dn1_in, &dn1, LDAP_DN_FORMAT_LDAPV3); if (rc != LDAP_SUCCESS) { @@ -1115,10 +1109,8 @@ nsdb_dn_ends_with(const char *dn_in, const char *suffix_in, result = false; - if (dn_in == NULL || suffix_in == NULL || ldap_err == NULL) { - xlog(L_ERROR, "%s: Invalid parameter", __func__); + if (dn_in == NULL || suffix_in == NULL || ldap_err == NULL) goto out; - } rc = ldap_str2dn(dn_in, &dn, LDAP_DN_FORMAT_LDAPV3); if (rc != LDAP_SUCCESS) { diff --git a/src/libnsdb/path.c b/src/libnsdb/path.c index 11bf73b..a7cb524 100644 --- a/src/libnsdb/path.c +++ b/src/libnsdb/path.c @@ -273,10 +273,8 @@ nsdb_path_array_to_posix(char * const *path_array, char **pathname) unsigned int i, count; size_t length, len; - if (path_array == NULL || pathname == NULL) { - xlog(L_ERROR, "%s: Invalid argument", __func__); + if (path_array == NULL || pathname == NULL) return FEDFS_ERR_INVAL; - } if (path_array[0] == NULL) { xlog(D_GENERAL, "%s: Zero-component pathname", __func__); @@ -357,10 +355,8 @@ nsdb_posix_to_path_array(const char *pathname, char ***path_array) unsigned int i, count; size_t length; - if (pathname == NULL || path_array == NULL) { - xlog(L_ERROR, "%s: Invalid argument", __func__); + if (pathname == NULL || path_array == NULL) return FEDFS_ERR_INVAL; - } if (!nsdb_pathname_is_utf8(pathname)) { xlog(D_GENERAL, "%s: Bad character in pathname", __func__); @@ -433,10 +429,8 @@ nsdb_path_array_to_fedfspathname(char * const *path_array, FedFsPathName *fpath) size_t length, len; char *component; - if (path_array == NULL || fpath == NULL) { - xlog(L_ERROR, "%s: Invalid argument", __func__); + if (path_array == NULL || fpath == NULL) return FEDFS_ERR_INVAL; - } /* The path "/" MUST be encoded as an array with zero components. */ if (path_array[0] == NULL) { @@ -522,10 +516,8 @@ nsdb_fedfspathname_to_path_array(FedFsPathName fpath, char ***path_array) unsigned int i, len; size_t length; - if (path_array == NULL) { - xlog(L_ERROR, "%s: Invalid argument", __func__); + if (path_array == NULL) return FEDFS_ERR_INVAL; - } if (fpath.FedFsPathName_len == 0) return nsdb_alloc_zero_component_pathname(path_array); _______________________________________________ fedfs-utils-devel mailing list [email protected] https://oss.oracle.com/mailman/listinfo/fedfs-utils-devel
