encode_attr_2(
    Slapi_PBlock *pb,
    BerElement *ber,
    Slapi_Entry *e,
    Slapi_ValueSet *vs,
    int attrsonly,
    const char *attribute_type,
    const char *returned_type)
{

    char *attrs[2] = {NULL, NULL};
    Slapi_Value *v;
    int i = slapi_valueset_first_value(vs, &v);

    if (i == -1) {
        return (0);
    }

    attrs[0] = (char *)attribute_type;

#if !defined(DISABLE_ACL_CHECK)
    if (plugin_call_acl_plugin(pb, e, attrs, NULL, SLAPI_ACL_READ,
                               ACLPLUGIN_ACCESS_READ_ON_ATTR, NULL) != LDAP_SUCCESS) {
        return (0);
    }
#endif

    if (ber_printf(ber, "{s[", returned_type ? returned_type : attribute_type) == -1) {
        slapi_log_err(SLAPI_LOG_ERR, "encode_attr_2", "ber_printf failed 4\n");
        ber_free(ber, 1);
        send_ldap_result(pb, LDAP_OPERATIONS_ERROR, NULL,
                         "ber_printf type", 0, NULL);
        return (-1);
    }

    if (!attrsonly) {
        while (i != -1) {
            if (ber_printf(ber, "o", v->bv.bv_val, v->bv.bv_len) == -1) {
                slapi_log_err(SLAPI_LOG_ERR,
                              "encode_attr_2", "ber_printf failed 5\n");
                ber_free(ber, 1);
                send_ldap_result(pb, LDAP_OPERATIONS_ERROR,
                                 NULL, "ber_printf value", 0, NULL);
                return (-1);
            }
            i = slapi_valueset_next_value(vs, i, &v);
        }
    }

    if (ber_printf(ber, "]}") == -1) {
        slapi_log_err(SLAPI_LOG_ERR, "encode_attr_2", "ber_printf failed 6\n");
        ber_free(ber, 1);
        send_ldap_result(pb, LDAP_OPERATIONS_ERROR, NULL,
                         "ber_printf type end", 0, NULL);
        return (-1);
    }

    return (0);
}
encode_attr_2(
    Slapi_PBlock *pb,
    BerElement *ber,
    Slapi_Entry *e,
    Slapi_ValueSet *vs,
    int attrsonly,
    const char *attribute_type,
    const char *returned_type)
{

    char *attrs[2] = {NULL, NULL};
    Slapi_Value *v;
    int i = slapi_valueset_first_value(vs, &v);

    if (i == -1) {
        return (0);
    }

    attrs[0] = (char *)attribute_type;

#if !defined(DISABLE_ACL_CHECK)
    if (plugin_call_acl_plugin(pb, e, attrs, NULL, SLAPI_ACL_READ,
                               ACLPLUGIN_ACCESS_READ_ON_ATTR, NULL) != LDAP_SUCCESS) {
        return (0);
    }
#endif

    if (ber_printf(ber, "{s[", returned_type ? returned_type : attribute_type) == -1) {
        slapi_log_err(SLAPI_LOG_ERR, "encode_attr_2", "ber_printf failed 4\n");
        ber_free(ber, 1);
        send_ldap_result(pb, LDAP_OPERATIONS_ERROR, NULL,
                         "ber_printf type", 0, NULL);
        return (-1);
    }

    if (!attrsonly) {
        while (i != -1) {
            if (ber_printf(ber, "o", v->bv.bv_val, v->bv.bv_len) == -1) {
                slapi_log_err(SLAPI_LOG_ERR,
                              "encode_attr_2", "ber_printf failed 5\n");
                ber_free(ber, 1);
                send_ldap_result(pb, LDAP_OPERATIONS_ERROR,
                                 NULL, "ber_printf value", 0, NULL);
                return (-1);
            }
            i = slapi_valueset_next_value(vs, i, &v);
        }
    }

    if (ber_printf(ber, "]}") == -1) {
        slapi_log_err(SLAPI_LOG_ERR, "encode_attr_2", "ber_printf failed 6\n");
        ber_free(ber, 1);
        send_ldap_result(pb, LDAP_OPERATIONS_ERROR, NULL,
                         "ber_printf type end", 0, NULL);
        return (-1);
    }

    return (0);
}