diff options
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/charcnv.c | 61 | ||||
-rw-r--r-- | source3/lib/ldb/common/ldb.c | 6 | ||||
-rw-r--r-- | source3/lib/ldb/common/ldb_dn.c | 53 | ||||
-rw-r--r-- | source3/lib/ldb/include/ldb.h | 9 | ||||
-rw-r--r-- | source3/lib/ldb/tools/ldbadd.c | 2 | ||||
-rw-r--r-- | source3/lib/ldb/tools/ldbdel.c | 2 | ||||
-rw-r--r-- | source3/lib/ldb/tools/ldbedit.c | 2 | ||||
-rw-r--r-- | source3/lib/ldb/tools/ldbmodify.c | 2 | ||||
-rw-r--r-- | source3/lib/ldb/tools/ldbrename.c | 2 | ||||
-rw-r--r-- | source3/lib/ldb/tools/ldbsearch.c | 2 |
10 files changed, 115 insertions, 26 deletions
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 374079c8ae..eb794d8347 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -1861,3 +1861,64 @@ codepoint_t next_codepoint(const char *str, size_t *size) /* no other length is valid */ return INVALID_CODEPOINT; } + +/* + push a single codepoint into a CH_UNIX string the target string must + be able to hold the full character, which is guaranteed if it is at + least 5 bytes in size. The caller may pass less than 5 bytes if they + are sure the character will fit (for example, you can assume that + uppercase/lowercase of a character will not add more than 1 byte) + + return the number of bytes occupied by the CH_UNIX character, or + -1 on failure +*/ +_PUBLIC_ ssize_t push_codepoint(char *str, codepoint_t c) +{ + smb_iconv_t descriptor; + uint8_t buf[4]; + size_t ilen, olen; + const char *inbuf; + + if (c < 128) { + *str = c; + return 1; + } + + lazy_initialize_conv(); + + descriptor = conv_handles[CH_UNIX][CH_UTF16LE]; + if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) { + return -1; + } + + if (c < 0x10000) { + ilen = 2; + olen = 5; + inbuf = (char *)buf; + SSVAL(buf, 0, c); + smb_iconv(descriptor, &inbuf, &ilen, &str, &olen); + if (ilen != 0) { + return -1; + } + return 5 - olen; + } + + c -= 0x10000; + + buf[0] = (c>>10) & 0xFF; + buf[1] = (c>>18) | 0xd8; + buf[2] = c & 0xFF; + buf[3] = ((c>>8) & 0x3) | 0xdc; + + ilen = 4; + olen = 5; + inbuf = (char *)buf; + + smb_iconv(descriptor, &inbuf, &ilen, &str, &olen); + if (ilen != 0) { + return -1; + } + return 5 - olen; +} + + diff --git a/source3/lib/ldb/common/ldb.c b/source3/lib/ldb/common/ldb.c index cef7373c26..791c1863d7 100644 --- a/source3/lib/ldb/common/ldb.c +++ b/source3/lib/ldb/common/ldb.c @@ -39,7 +39,7 @@ initialise a ldb context The mem_ctx is optional */ -struct ldb_context *ldb_init(void *mem_ctx) +struct ldb_context *ldb_init(void *mem_ctx, struct tevent_context *tev_ctx) { struct ldb_context *ldb = talloc_zero(mem_ctx, struct ldb_context); int ret; @@ -166,7 +166,7 @@ static const struct ldb_dn *ldb_set_default_basedn(struct ldb_context *ldb) } tmp_ctx = talloc_new(ldb); - ret = ldb_search(ldb, ldb, &res, ldb_dn_new(tmp_ctx), LDB_SCOPE_BASE, + ret = ldb_search(ldb, ldb, &res, ldb_dn_new(tmp_ctx, ldb, NULL), LDB_SCOPE_BASE, attrs, "(objectClass=*)"); if (ret == LDB_SUCCESS) { if (res->count == 1) { @@ -601,7 +601,7 @@ int ldb_build_search_req(struct ldb_request **ret_req, req->operation = LDB_SEARCH; if (base == NULL) { - req->op.search.base = ldb_dn_new(req); + req->op.search.base = ldb_dn_new(req, ldb, NULL); } else { req->op.search.base = base; } diff --git a/source3/lib/ldb/common/ldb_dn.c b/source3/lib/ldb/common/ldb_dn.c index 7ef3c38024..09d58555bd 100644 --- a/source3/lib/ldb/common/ldb_dn.c +++ b/source3/lib/ldb/common/ldb_dn.c @@ -332,21 +332,44 @@ failed: return dc; } -struct ldb_dn *ldb_dn_new(void *mem_ctx) +struct ldb_dn *ldb_dn_new(void *mem_ctx, struct ldb_context *ldb, const char *text) { struct ldb_dn *edn; - edn = talloc(mem_ctx, struct ldb_dn); - LDB_DN_NULL_FAILED(edn); - - /* Initially there are no components */ - edn->comp_num = 0; - edn->components = NULL; + if (text == NULL) { + edn = talloc_zero(mem_ctx, struct ldb_dn); + } else { + edn = ldb_dn_explode(mem_ctx, text); + } return edn; +} -failed: - return NULL; +bool ldb_dn_validate(struct ldb_dn *dn) +{ + /* This implementation does not do "lazy" evaluation of DN's, so + * if a DN can be created it will be valid. */ + return true; +} + +struct ldb_dn *ldb_dn_new_fmt(void *mem_ctx, struct ldb_context *ldb, const char *new_fmt, ...) +{ + char *strdn; + va_list ap; + struct ldb_dn *dn; + + if ( (! mem_ctx) || (! ldb)) return NULL; + + va_start(ap, new_fmt); + strdn = talloc_vasprintf(mem_ctx, new_fmt, ap); + if (strdn == NULL) + return NULL; + va_end(ap); + + dn = ldb_dn_explode(mem_ctx, strdn); + + talloc_free(strdn); + return dn; } /* @@ -360,7 +383,7 @@ struct ldb_dn *ldb_dn_explode(void *mem_ctx, const char *dn) if (dn == NULL) return NULL; /* Allocate a structure to hold the exploded DN */ - edn = ldb_dn_new(mem_ctx); + edn = talloc_zero(mem_ctx, struct ldb_dn); if (edn == NULL) { return NULL; } @@ -440,7 +463,7 @@ struct ldb_dn *ldb_dn_explode_or_special(void *mem_ctx, const char *dn) */ /* Allocate a structure to hold the exploded DN */ - if (!(edn = ldb_dn_new(mem_ctx))) { + if (!(edn = talloc_zero(mem_ctx, struct ldb_dn))) { return NULL; } @@ -599,7 +622,7 @@ struct ldb_dn *ldb_dn_casefold(struct ldb_context *ldb, void *mem_ctx, const str if (edn == NULL) return NULL; - cedn = ldb_dn_new(mem_ctx); + cedn = talloc_zero(mem_ctx, struct ldb_dn); if (!cedn) { return NULL; } @@ -737,7 +760,7 @@ struct ldb_dn *ldb_dn_copy_partial(void *mem_ctx, const struct ldb_dn *dn, int n if (dn == NULL) return NULL; if (num_el <= 0) return NULL; - newdn = ldb_dn_new(mem_ctx); + newdn = talloc_zero(mem_ctx, struct ldb_dn); LDB_DN_NULL_FAILED(newdn); newdn->comp_num = num_el; @@ -814,7 +837,7 @@ struct ldb_dn *ldb_dn_build_child(void *mem_ctx, const char *attr, newdn = ldb_dn_copy_partial(mem_ctx, base, base->comp_num + 1); LDB_DN_NULL_FAILED(newdn); } else { - newdn = ldb_dn_new(mem_ctx); + newdn = talloc_zero(mem_ctx, struct ldb_dn); LDB_DN_NULL_FAILED(newdn); newdn->comp_num = 1; @@ -847,7 +870,7 @@ struct ldb_dn *ldb_dn_compose(void *mem_ctx, const struct ldb_dn *dn1, const str } if (dn2 == NULL) { - newdn = ldb_dn_new(mem_ctx); + newdn = talloc_zero(mem_ctx, struct ldb_dn); LDB_DN_NULL_FAILED(newdn); newdn->comp_num = dn1->comp_num; diff --git a/source3/lib/ldb/include/ldb.h b/source3/lib/ldb/include/ldb.h index 113652a1a7..466e4a21ee 100644 --- a/source3/lib/ldb/include/ldb.h +++ b/source3/lib/ldb/include/ldb.h @@ -795,10 +795,13 @@ int ldb_global_init(void); \param mem_ctx pointer to a talloc memory context. Pass NULL if there is no suitable context available. + \param ev_ctx Event context. This is here for API compatibility + with the Samba 4 version of LDB and ignored in this version of LDB. + \return pointer to ldb_context that should be free'd (using talloc_free()) at the end of the program. */ -struct ldb_context *ldb_init(void *mem_ctx); +struct ldb_context *ldb_init(void *mem_ctx, struct tevent_context *ev_ctx); /** Connect to a database. @@ -1275,7 +1278,9 @@ int ldb_attrib_add_handlers(struct ldb_context *ldb, int ldb_dn_is_special(const struct ldb_dn *dn); int ldb_dn_check_special(const struct ldb_dn *dn, const char *check); char *ldb_dn_escape_value(void *mem_ctx, struct ldb_val value); -struct ldb_dn *ldb_dn_new(void *mem_ctx); +struct ldb_dn *ldb_dn_new(TALLOC_CTX *mem_ctx, struct ldb_context *ldb, const char *dn); +bool ldb_dn_validate(struct ldb_dn *dn); +struct ldb_dn *ldb_dn_new_fmt(void *mem_ctx, struct ldb_context *ldb, const char *new_fmt, ...); struct ldb_dn *ldb_dn_explode(void *mem_ctx, const char *dn); struct ldb_dn *ldb_dn_explode_or_special(void *mem_ctx, const char *dn); char *ldb_dn_linearize(void *mem_ctx, const struct ldb_dn *edn); diff --git a/source3/lib/ldb/tools/ldbadd.c b/source3/lib/ldb/tools/ldbadd.c index 155395e065..c23a13ab3c 100644 --- a/source3/lib/ldb/tools/ldbadd.c +++ b/source3/lib/ldb/tools/ldbadd.c @@ -90,7 +90,7 @@ int main(int argc, const char **argv) ldb_global_init(); - ldb = ldb_init(NULL); + ldb = ldb_init(NULL, NULL); options = ldb_cmdline_process(ldb, argc, argv, usage); diff --git a/source3/lib/ldb/tools/ldbdel.c b/source3/lib/ldb/tools/ldbdel.c index c58a82a523..bdd1b60014 100644 --- a/source3/lib/ldb/tools/ldbdel.c +++ b/source3/lib/ldb/tools/ldbdel.c @@ -80,7 +80,7 @@ int main(int argc, const char **argv) ldb_global_init(); - ldb = ldb_init(NULL); + ldb = ldb_init(NULL, NULL); options = ldb_cmdline_process(ldb, argc, argv, usage); diff --git a/source3/lib/ldb/tools/ldbedit.c b/source3/lib/ldb/tools/ldbedit.c index a33e6ae704..6b9eaec111 100644 --- a/source3/lib/ldb/tools/ldbedit.c +++ b/source3/lib/ldb/tools/ldbedit.c @@ -282,7 +282,7 @@ int main(int argc, const char **argv) ldb_global_init(); - ldb = ldb_init(NULL); + ldb = ldb_init(NULL, NULL); options = ldb_cmdline_process(ldb, argc, argv, usage); diff --git a/source3/lib/ldb/tools/ldbmodify.c b/source3/lib/ldb/tools/ldbmodify.c index f12387a8f6..e3552b4ea3 100644 --- a/source3/lib/ldb/tools/ldbmodify.c +++ b/source3/lib/ldb/tools/ldbmodify.c @@ -92,7 +92,7 @@ int main(int argc, const char **argv) ldb_global_init(); - ldb = ldb_init(NULL); + ldb = ldb_init(NULL, NULL); options = ldb_cmdline_process(ldb, argc, argv, usage); diff --git a/source3/lib/ldb/tools/ldbrename.c b/source3/lib/ldb/tools/ldbrename.c index d6c3a4ab62..d66d4b93c3 100644 --- a/source3/lib/ldb/tools/ldbrename.c +++ b/source3/lib/ldb/tools/ldbrename.c @@ -59,7 +59,7 @@ int main(int argc, const char **argv) ldb_global_init(); - ldb = ldb_init(NULL); + ldb = ldb_init(NULL, NULL); options = ldb_cmdline_process(ldb, argc, argv, usage); diff --git a/source3/lib/ldb/tools/ldbsearch.c b/source3/lib/ldb/tools/ldbsearch.c index e5cec0fa66..f1c88d580b 100644 --- a/source3/lib/ldb/tools/ldbsearch.c +++ b/source3/lib/ldb/tools/ldbsearch.c @@ -279,7 +279,7 @@ int main(int argc, const char **argv) ldb_global_init(); - ldb = ldb_init(NULL); + ldb = ldb_init(NULL, NULL); options = ldb_cmdline_process(ldb, argc, argv, usage); |