return 0;
}
+/* Lexicographically sorted representation for a 32-bit integer */
+static int ldif_index_format_int32(struct ldb_context *ldb,
+ void *mem_ctx,
+ const struct ldb_val *in,
+ struct ldb_val *out)
+{
+ int32_t i;
+ int ret;
+ char prefix;
+ size_t len;
+
+ ret = val_to_int32(in, &i);
+ if (ret != LDB_SUCCESS) {
+ return ret;
+ }
+
+ if (i < 0) {
+ prefix = 'n';
+ i = INT32_MAX + i + 1;
+ } else if (i > 0) {
+ prefix = 'p';
+ } else {
+ prefix = 'o';
+ }
+
+ out->data = (uint8_t *) talloc_asprintf(mem_ctx, "%c%010ld", prefix, (long)i);
+ if (out->data == NULL) {
+ ldb_oom(ldb);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ len = talloc_array_length(out->data) - 1;
+ if (len != 11) {
+ ldb_debug(ldb, LDB_DEBUG_ERROR,
+ __location__ ": expected index format str %s to"
+ " have length 11 but got %zu",
+ (char*)out->data, len);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ out->length = 11;
+ return 0;
+}
+
/* Comparison of two 32-bit integers */
static int ldif_comparison_int32(struct ldb_context *ldb, void *mem_ctx,
const struct ldb_val *v1, const struct ldb_val *v2)
.ldif_read_fn = ldb_handler_copy,
.ldif_write_fn = ldb_handler_copy,
.canonicalise_fn = ldif_canonicalise_int32,
+ .index_format_fn = ldif_index_format_int32,
.comparison_fn = ldif_comparison_int32,
.operator_fn = samba_syntax_operator_fn
},{
return 0;
}
+/*
+ * Lexicographically ordered format for a ldap Integer
+ */
+static int ldb_index_format_Integer(struct ldb_context *ldb,
+ void *mem_ctx,
+ const struct ldb_val *in,
+ struct ldb_val *out)
+{
+ int64_t i;
+ int ret;
+ char prefix;
+ size_t len;
+
+ ret = val_to_int64(in, &i);
+ if (ret != LDB_SUCCESS) {
+ return ret;
+ }
+
+ if (i < 0) {
+ prefix = 'n';
+ i = INT64_MAX + i + 1;
+ } else if (i > 0) {
+ prefix = 'p';
+ } else {
+ prefix = 'o';
+ }
+
+ out->data = (uint8_t *) talloc_asprintf(mem_ctx, "%c%019lld", prefix, (long long)i);
+ if (out->data == NULL) {
+ ldb_oom(ldb);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ len = talloc_array_length(out->data) - 1;
+ if (len != 20) {
+ ldb_debug(ldb, LDB_DEBUG_ERROR,
+ __location__ ": expected index format str %s to"
+ " have length 20 but got %zu",
+ (char*)out->data, len);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ out->length = 20;
+ return 0;
+}
+
/*
compare two Integers
*/
.canonicalise_fn = ldb_canonicalise_Integer,
.comparison_fn = ldb_comparison_Integer
},
- {
+ {
+ .name = LDB_SYNTAX_ORDERED_INTEGER,
+ .ldif_read_fn = ldb_handler_copy,
+ .ldif_write_fn = ldb_handler_copy,
+ .canonicalise_fn = ldb_canonicalise_Integer,
+ .index_format_fn = ldb_index_format_Integer,
+ .comparison_fn = ldb_comparison_Integer
+ },
+ {
.name = LDB_SYNTAX_OCTET_STRING,
.ldif_read_fn = ldb_handler_copy,
.ldif_write_fn = ldb_handler_copy,
*/
#define LDB_SYNTAX_INTEGER "1.3.6.1.4.1.1466.115.121.1.27"
+/**
+ Custom attribute syntax for an integer whose index is lexicographically
+ ordered by attribute value in the database.
+*/
+#define LDB_SYNTAX_ORDERED_INTEGER "LDB_SYNTAX_ORDERED_INTEGER"
+
/**
LDAP attribute syntax for a boolean
ADD_LDB_STRING(SYNTAX_DN);
ADD_LDB_STRING(SYNTAX_DIRECTORY_STRING);
ADD_LDB_STRING(SYNTAX_INTEGER);
+ ADD_LDB_STRING(SYNTAX_ORDERED_INTEGER);
ADD_LDB_STRING(SYNTAX_BOOLEAN);
ADD_LDB_STRING(SYNTAX_OCTET_STRING);
ADD_LDB_STRING(SYNTAX_UTC_TIME);
/* change this when we change something in our schema code that
* requires a re-index of the database
*/
-#define SAMDB_INDEXING_VERSION "2"
+#define SAMDB_INDEXING_VERSION "3"
/*
override the name to attribute handler function
.validate_ldb = dsdb_syntax_INT64_validate_ldb,
.equality = "integerMatch",
.comment = "Large Integer",
- .ldb_syntax = LDB_SYNTAX_INTEGER,
+ .ldb_syntax = LDB_SYNTAX_ORDERED_INTEGER,
.auto_normalise = true
},{
.name = "String(NT-Sec-Desc)",