This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
+ version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
/*
* Author: Andrew Tridgell
*/
-#include "includes.h"
-#include "ldb/include/includes.h"
-#include "ldb/tools/cmdline.h"
+#include "ldb.h"
+#include "tools/cmdline.h"
static struct ldb_cmdline *options;
if (ldb_modify(ldb, mod) != 0) {
fprintf(stderr, "failed to modify %s - %s\n",
- ldb_dn_linearize(ldb, msg1->dn), ldb_errstring(ldb));
+ ldb_dn_get_linearized(msg1->dn), ldb_errstring(ldb));
return -1;
}
static struct ldb_message *msg_find(struct ldb_context *ldb,
struct ldb_message **msgs,
int count,
- const struct ldb_dn *dn)
+ struct ldb_dn *dn)
{
int i;
for (i=0;i<count;i++) {
- if (ldb_dn_compare(ldb, dn, msgs[i]->dn) == 0) {
+ if (ldb_dn_compare(dn, msgs[i]->dn) == 0) {
return msgs[i];
}
}
int ret = 0;
int adds=0, modifies=0, deletes=0;
+ if (ldb_transaction_start(ldb) != 0) {
+ fprintf(stderr, "Failed to start transaction: %s\n", ldb_errstring(ldb));
+ return -1;
+ }
+
/* do the adds and modifies */
for (i=0;i<count2;i++) {
msg = msg_find(ldb, msgs1, count1, msgs2[i]->dn);
}
if (ldb_add(ldb, msgs2[i]) != 0) {
fprintf(stderr, "failed to add %s - %s\n",
- ldb_dn_linearize(ldb, msgs2[i]->dn),
+ ldb_dn_get_linearized(msgs2[i]->dn),
ldb_errstring(ldb));
return -1;
}
}
if (ldb_delete(ldb, msgs1[i]->dn) != 0) {
fprintf(stderr, "failed to delete %s - %s\n",
- ldb_dn_linearize(ldb, msgs1[i]->dn),
+ ldb_dn_get_linearized(msgs1[i]->dn),
ldb_errstring(ldb));
return -1;
}
}
}
+ if (ldb_transaction_commit(ldb) != 0) {
+ fprintf(stderr, "Failed to commit transaction: %s\n", ldb_errstring(ldb));
+ return -1;
+ }
+
printf("# %d adds %d modifies %d deletes\n", adds, modifies, deletes);
return ret;
{
int fd, ret;
FILE *f;
- char template[] = "/tmp/ldbedit.XXXXXX";
+ char file_template[] = "/tmp/ldbedit.XXXXXX";
char *cmd;
struct ldb_ldif *ldif;
struct ldb_message **msgs2 = NULL;
/* write out the original set of messages to a temporary
file */
- fd = mkstemp(template);
+ fd = mkstemp(file_template);
if (fd == -1) {
- perror(template);
+ perror(file_template);
return -1;
}
if (!f) {
perror("fopen");
close(fd);
- unlink(template);
+ unlink(file_template);
return -1;
}
fclose(f);
- cmd = talloc_asprintf(ldb, "%s %s", editor, template);
+ cmd = talloc_asprintf(ldb, "%s %s", editor, file_template);
if (!cmd) {
- unlink(template);
+ unlink(file_template);
fprintf(stderr, "out of memory\n");
return -1;
}
talloc_free(cmd);
if (ret != 0) {
- unlink(template);
+ unlink(file_template);
fprintf(stderr, "edit with %s failed\n", editor);
return -1;
}
/* read the resulting ldif into msgs2 */
- f = fopen(template, "r");
+ f = fopen(file_template, "r");
if (!f) {
- perror(template);
+ perror(file_template);
return -1;
}
}
fclose(f);
- unlink(template);
+ unlink(file_template);
return merge_edits(ldb, msgs1, count1, msgs2, count2);
}
const char *expression = "(|(objectClass=*)(distinguishedName=*))";
const char * const * attrs = NULL;
- ldb_global_init();
-
- ldb = ldb_init(NULL);
+ ldb = ldb_init(NULL, NULL);
options = ldb_cmdline_process(ldb, argc, argv, usage);
}
if (options->basedn != NULL) {
- basedn = ldb_dn_explode(ldb, options->basedn);
- if (basedn == NULL) {
+ basedn = ldb_dn_new(ldb, ldb, options->basedn);
+ if ( ! ldb_dn_validate(basedn)) {
printf("Invalid Base DN format\n");
exit(1);
}
}
- ret = ldb_search(ldb, basedn, options->scope, expression, attrs, &result);
+ ret = ldb_search(ldb, ldb, &result, basedn, options->scope, attrs, "%s", expression);
if (ret != LDB_SUCCESS) {
printf("search failed - %s\n", ldb_errstring(ldb));
exit(1);