Changeset 745 for trunk/server/source4/lib/ldb/tools
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 1 deleted
- 10 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/source4/lib/ldb/tools/cmdline.c
r414 r745 22 22 */ 23 23 24 #include "ldb_includes.h" 24 #include "replace.h" 25 #include "system/filesys.h" 26 #include "system/time.h" 25 27 #include "ldb.h" 28 #include "ldb_module.h" 26 29 #include "tools/cmdline.h" 27 30 28 #if (_SAMBA_BUILD_ >= 4)29 #include "includes.h"30 #include "lib/cmdline/popt_common.h"31 #include "lib/ldb-samba/ldif_handlers.h"32 #include "auth/gensec/gensec.h"33 #include "auth/auth.h"34 #include "ldb_wrap.h"35 #include "param/param.h"36 #endif37 38 31 static struct ldb_cmdline options; /* needs to be static for older compilers */ 39 32 40 static struct poptOption popt_options[] = { 33 enum ldb_cmdline_options { CMDLINE_RELAX=1 }; 34 35 static struct poptOption builtin_popt_options[] = { 41 36 POPT_AUTOHELP 42 37 { "url", 'H', POPT_ARG_STRING, &options.url, 0, "database URL", "URL" }, … … 54 49 { "nosync", 0, POPT_ARG_NONE, &options.nosync, 0, "non-synchronous transactions", NULL }, 55 50 { "sorted", 'S', POPT_ARG_NONE, &options.sorted, 0, "sort attributes", NULL }, 56 { "input", 'I', POPT_ARG_STRING, &options.input, 0, "Input File", "Input" },57 { "output", 'O', POPT_ARG_STRING, &options.output, 0, "Output File", "Output" },58 51 { NULL, 'o', POPT_ARG_STRING, NULL, 'o', "ldb_connect option", "OPTION" }, 59 52 { "controls", 0, POPT_ARG_STRING, NULL, 'c', "controls", NULL }, 60 53 { "show-binary", 0, POPT_ARG_NONE, &options.show_binary, 0, "display binary LDIF", NULL }, 61 #if (_SAMBA_BUILD_ >= 4) 62 POPT_COMMON_SAMBA 63 POPT_COMMON_CREDENTIALS 64 POPT_COMMON_CONNECTION 65 POPT_COMMON_VERSION 66 #endif 54 { "paged", 0, POPT_ARG_NONE, NULL, 'P', "use a paged search", NULL }, 55 { "show-deleted", 0, POPT_ARG_NONE, NULL, 'D', "show deleted objects", NULL }, 56 { "show-recycled", 0, POPT_ARG_NONE, NULL, 'R', "show recycled objects", NULL }, 57 { "show-deactivated-link", 0, POPT_ARG_NONE, NULL, 'd', "show deactivated links", NULL }, 58 { "reveal", 0, POPT_ARG_NONE, NULL, 'r', "reveal ldb internals", NULL }, 59 { "relax", 0, POPT_ARG_NONE, NULL, CMDLINE_RELAX, "pass relax control", NULL }, 60 { "cross-ncs", 0, POPT_ARG_NONE, NULL, 'N', "search across NC boundaries", NULL }, 61 { "extended-dn", 0, POPT_ARG_NONE, NULL, 'E', "show extended DNs", NULL }, 67 62 { NULL } 68 63 }; 69 64 70 void ldb_cmdline_help( const char *cmdname, FILE *f)65 void ldb_cmdline_help(struct ldb_context *ldb, const char *cmdname, FILE *f) 71 66 { 72 67 poptContext pc; 73 pc = poptGetContext(cmdname, 0, NULL, popt_options, 68 struct poptOption **popt_options = ldb_module_popt_options(ldb); 69 pc = poptGetContext(cmdname, 0, NULL, *popt_options, 74 70 POPT_CONTEXT_KEEP_FIRST); 75 71 poptPrintHelp(pc, f, 0); 72 } 73 74 /* 75 add a control to the options structure 76 */ 77 static bool add_control(TALLOC_CTX *mem_ctx, const char *control) 78 { 79 unsigned int i; 80 81 /* count how many controls we already have */ 82 for (i=0; options.controls && options.controls[i]; i++) ; 83 84 options.controls = talloc_realloc(mem_ctx, options.controls, const char *, i + 2); 85 if (options.controls == NULL) { 86 return false; 87 } 88 options.controls[i] = control; 89 options.controls[i+1] = NULL; 90 return true; 76 91 } 77 92 … … 81 96 struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, 82 97 int argc, const char **argv, 83 void (*usage)( void))98 void (*usage)(struct ldb_context *)) 84 99 { 85 100 struct ldb_cmdline *ret=NULL; 86 101 poptContext pc; 87 #if (_SAMBA_BUILD_ >= 4)88 int r;89 #endif90 102 int num_options = 0; 91 103 int opt; 92 104 int flags = 0; 93 94 #if (_SAMBA_BUILD_ >= 4) 95 r = ldb_register_samba_handlers(ldb); 96 if (r != 0) { 97 goto failed; 98 } 99 100 #endif 105 int rc; 106 struct poptOption **popt_options; 107 108 /* make the ldb utilities line buffered */ 109 setlinebuf(stdout); 101 110 102 111 ret = talloc_zero(ldb, struct ldb_cmdline); … … 122 131 options.scope = LDB_SCOPE_DEFAULT; 123 132 124 pc = poptGetContext(argv[0], argc, argv, popt_options, 133 popt_options = ldb_module_popt_options(ldb); 134 (*popt_options) = builtin_popt_options; 135 136 rc = ldb_modules_hook(ldb, LDB_MODULE_HOOK_CMDLINE_OPTIONS); 137 if (rc != LDB_SUCCESS) { 138 fprintf(stderr, "ldb: failed to run command line hooks : %s\n", ldb_strerror(rc)); 139 goto failed; 140 } 141 142 pc = poptGetContext(argv[0], argc, argv, *popt_options, 125 143 POPT_CONTEXT_KEEP_FIRST); 126 144 … … 160 178 case 'c': { 161 179 const char *cs = poptGetOptArg(pc); 162 const char *p, *q; 163 int cc; 164 165 for (p = cs, cc = 1; (q = strchr(p, ',')); cc++, p = q + 1) ; 166 167 options.controls = talloc_array(ret, char *, cc + 1); 168 if (options.controls == NULL) { 169 fprintf(stderr, "Out of memory!\n"); 170 goto failed; 171 } 172 for (p = cs, cc = 0; p != NULL; cc++) { 173 const char *t; 180 const char *p; 181 182 for (p = cs; p != NULL; ) { 183 const char *t, *c; 174 184 175 185 t = strchr(p, ','); 176 186 if (t == NULL) { 177 options.controls[cc]= talloc_strdup(options.controls, p);187 c = talloc_strdup(options.controls, p); 178 188 p = NULL; 179 189 } else { 180 options.controls[cc]= talloc_strndup(options.controls, p, t-p);190 c = talloc_strndup(options.controls, p, t-p); 181 191 p = t + 1; 182 192 } 183 } 184 options.controls[cc] = NULL; 193 if (c == NULL || !add_control(ret, c)) { 194 fprintf(stderr, __location__ ": out of memory\n"); 195 goto failed; 196 } 197 } 185 198 186 199 break; 187 200 } 201 case 'P': 202 if (!add_control(ret, "paged_results:1:1024")) { 203 fprintf(stderr, __location__ ": out of memory\n"); 204 goto failed; 205 } 206 break; 207 case 'D': 208 if (!add_control(ret, "show_deleted:1")) { 209 fprintf(stderr, __location__ ": out of memory\n"); 210 goto failed; 211 } 212 break; 213 case 'R': 214 if (!add_control(ret, "show_recycled:0")) { 215 fprintf(stderr, __location__ ": out of memory\n"); 216 goto failed; 217 } 218 break; 219 case 'd': 220 if (!add_control(ret, "show_deactivated_link:0")) { 221 fprintf(stderr, __location__ ": out of memory\n"); 222 goto failed; 223 } 224 break; 225 case 'r': 226 if (!add_control(ret, "reveal_internals:0")) { 227 fprintf(stderr, __location__ ": out of memory\n"); 228 goto failed; 229 } 230 break; 231 case CMDLINE_RELAX: 232 if (!add_control(ret, "relax:0")) { 233 fprintf(stderr, __location__ ": out of memory\n"); 234 goto failed; 235 } 236 break; 237 case 'N': 238 if (!add_control(ret, "search_options:1:2")) { 239 fprintf(stderr, __location__ ": out of memory\n"); 240 goto failed; 241 } 242 break; 243 case 'E': 244 if (!add_control(ret, "extended_dn:1:1")) { 245 fprintf(stderr, __location__ ": out of memory\n"); 246 goto failed; 247 } 248 break; 188 249 default: 189 250 fprintf(stderr, "Invalid option %s: %s\n", 190 251 poptBadOption(pc, 0), poptStrerror(opt)); 191 if (usage) usage( );252 if (usage) usage(ldb); 192 253 goto failed; 193 254 } … … 206 267 if (ret->url == NULL) { 207 268 fprintf(stderr, "You must supply a url with -H or with $LDB_URL\n"); 208 if (usage) usage( );269 if (usage) usage(ldb); 209 270 goto failed; 210 271 } … … 226 287 } 227 288 228 #if (_SAMBA_BUILD_ >= 4)229 /* Must be after we have processed command line options */230 gensec_init(cmdline_lp_ctx);231 232 if (ldb_set_opaque(ldb, "sessionInfo", system_session(ldb, cmdline_lp_ctx))) {233 goto failed;234 }235 if (ldb_set_opaque(ldb, "credentials", cmdline_credentials)) {236 goto failed;237 }238 if (ldb_set_opaque(ldb, "loadparm", cmdline_lp_ctx)) {239 goto failed;240 }241 242 ldb_set_utf8_fns(ldb, NULL, wrap_casefold);243 #endif244 245 289 if (options.modules_path != NULL) { 246 290 ldb_set_modules_dir(ldb, options.modules_path); 247 } else if (getenv("LDB_MODULES_PATH") != NULL) { 248 ldb_set_modules_dir(ldb, getenv("LDB_MODULES_PATH")); 291 } 292 293 rc = ldb_modules_hook(ldb, LDB_MODULE_HOOK_CMDLINE_PRECONNECT); 294 if (rc != LDB_SUCCESS) { 295 fprintf(stderr, "ldb: failed to run preconnect hooks : %s\n", ldb_strerror(rc)); 296 goto failed; 249 297 } 250 298 … … 256 304 } 257 305 306 rc = ldb_modules_hook(ldb, LDB_MODULE_HOOK_CMDLINE_POSTCONNECT); 307 if (rc != LDB_SUCCESS) { 308 fprintf(stderr, "ldb: failed to run post connect hooks : %s\n", ldb_strerror(rc)); 309 goto failed; 310 } 311 258 312 return ret; 259 313 260 314 failed: 261 315 talloc_free(ret); 262 exit( 1);316 exit(LDB_ERR_OPERATIONS_ERROR); 263 317 return NULL; 264 318 } … … 274 328 int handle_controls_reply(struct ldb_control **reply, struct ldb_control **request) 275 329 { 276 int i, j;277 330 unsigned int i, j; 331 int ret = 0; 278 332 279 333 if (reply == NULL || request == NULL) return -1; -
trunk/server/source4/lib/ldb/tools/cmdline.h
r414 r745 42 42 int num_searches; 43 43 const char *sasl_mechanism; 44 const char *input; 45 const char *output; 46 char **controls; 44 const char **controls; 47 45 int show_binary; 48 46 int tracing; 49 47 }; 50 48 51 struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, int argc, const char **argv, 52 void (*usage)(void)); 49 struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, int argc, 50 const char **argv, 51 void (*usage)(struct ldb_context *)); 53 52 54 53 55 54 int handle_controls_reply(struct ldb_control **reply, struct ldb_control **request); 56 void ldb_cmdline_help( const char *cmdname, FILE *f);55 void ldb_cmdline_help(struct ldb_context *ldb, const char *cmdname, FILE *f); 57 56 -
trunk/server/source4/lib/ldb/tools/ldbadd.c
r414 r745 1 /* 1 /* 2 2 ldb database library 3 3 … … 7 7 ** library. This does NOT imply that all of Samba is released 8 8 ** under the LGPL 9 9 10 10 This library is free software; you can redistribute it and/or 11 11 modify it under the terms of the GNU Lesser General Public … … 34 34 #include "ldb.h" 35 35 #include "tools/cmdline.h" 36 #include "ldbutil.h" 36 37 37 static int failures; 38 static unsigned int failures; 39 static struct ldb_cmdline *options; 38 40 39 static void usage( void)41 static void usage(struct ldb_context *ldb) 40 42 { 41 printf("Usage: ldbadd <options> <ldif...>\n"); 43 printf("Usage: ldbadd <options> <ldif...>\n"); 42 44 printf("Adds records to a ldb, reading ldif the specified list of files\n\n"); 43 ldb_cmdline_help( "ldbadd", stdout);44 exit( 1);45 ldb_cmdline_help(ldb, "ldbadd", stdout); 46 exit(LDB_ERR_OPERATIONS_ERROR); 45 47 } 46 48 … … 49 51 add records from an opened file 50 52 */ 51 static int process_file(struct ldb_context *ldb, FILE *f, int *count)53 static int process_file(struct ldb_context *ldb, FILE *f, unsigned int *count) 52 54 { 53 55 struct ldb_ldif *ldif; 54 56 int ret = LDB_SUCCESS; 57 struct ldb_control **req_ctrls = ldb_parse_control_strings(ldb, ldb, (const char **)options->controls); 58 if (options->controls != NULL && req_ctrls== NULL) { 59 printf("parsing controls failed: %s\n", ldb_errstring(ldb)); 60 return LDB_ERR_OPERATIONS_ERROR; 61 } 62 55 63 56 64 while ((ldif = ldb_ldif_read_file(ldb, f))) { … … 61 69 } 62 70 63 ldif->msg = ldb_msg_canonicalize(ldb, ldif->msg); 71 ret = ldb_msg_normalize(ldb, ldif, ldif->msg, &ldif->msg); 72 if (ret != LDB_SUCCESS) { 73 fprintf(stderr, 74 "ERR: Message canonicalize failed - %s\n", 75 ldb_strerror(ret)); 76 failures++; 77 ldb_ldif_read_free(ldb, ldif); 78 continue; 79 } 64 80 65 ret = ldb_add (ldb, ldif->msg);81 ret = ldb_add_ctrl(ldb, ldif->msg,req_ctrls); 66 82 if (ret != LDB_SUCCESS) { 67 fprintf(stderr, "ERR: \"%s\" on DN %s\n", 68 ldb_errstring(ldb), ldb_dn_get_linearized(ldif->msg->dn)); 83 fprintf(stderr, "ERR: %s : \"%s\" on DN %s\n", 84 ldb_strerror(ret), ldb_errstring(ldb), 85 ldb_dn_get_linearized(ldif->msg->dn)); 69 86 failures++; 70 87 } else { 71 88 (*count)++; 89 if (options->verbose) { 90 printf("Added %s\n", ldb_dn_get_linearized(ldif->msg->dn)); 91 } 72 92 } 73 93 ldb_ldif_read_free(ldb, ldif); … … 82 102 { 83 103 struct ldb_context *ldb; 84 int i, ret=0, count=0; 85 struct ldb_cmdline *options; 104 unsigned int i, count = 0; 105 int ret = LDB_SUCCESS; 106 TALLOC_CTX *mem_ctx = talloc_new(NULL); 86 107 87 ldb = ldb_init(NULL, NULL); 108 ldb = ldb_init(mem_ctx, NULL); 109 if (ldb == NULL) { 110 return LDB_ERR_OPERATIONS_ERROR; 111 } 88 112 89 113 options = ldb_cmdline_process(ldb, argc, argv, usage); 90 114 91 if (ldb_transaction_start(ldb) != 0) { 115 ret = ldb_transaction_start(ldb); 116 if (ret != LDB_SUCCESS) { 92 117 printf("Failed to start transaction: %s\n", ldb_errstring(ldb)); 93 exit(1);118 return ret; 94 119 } 95 120 … … 103 128 if (!f) { 104 129 perror(fname); 105 exit(1);130 return LDB_ERR_OPERATIONS_ERROR; 106 131 } 107 132 ret = process_file(ldb, f, &count); … … 111 136 112 137 if (count != 0) { 113 if (ldb_transaction_commit(ldb) != 0) { 138 ret = ldb_transaction_commit(ldb); 139 if (ret != LDB_SUCCESS) { 114 140 printf("Failed to commit transaction: %s\n", ldb_errstring(ldb)); 115 exit(1);141 return ret; 116 142 } 117 143 } else { … … 119 145 } 120 146 121 talloc_free( ldb);147 talloc_free(mem_ctx); 122 148 123 printf("Added % d records with %dfailures\n", count, failures);124 149 printf("Added %u records with %u failures\n", count, failures); 150 125 151 return ret; 126 152 } -
trunk/server/source4/lib/ldb/tools/ldbdel.c
r414 r745 32 32 */ 33 33 34 #include "replace.h" 34 35 #include "ldb.h" 35 36 #include "tools/cmdline.h" 37 #include "ldbutil.h" 36 38 37 static int ldb_delete_recursive(struct ldb_context *ldb, struct ldb_dn *dn)39 static int dn_cmp(struct ldb_message **msg1, struct ldb_message **msg2) 38 40 { 39 int ret, i, total=0; 41 return ldb_dn_compare((*msg1)->dn, (*msg2)->dn); 42 } 43 44 static int ldb_delete_recursive(struct ldb_context *ldb, struct ldb_dn *dn,struct ldb_control **req_ctrls) 45 { 46 int ret; 47 unsigned int i, total=0; 40 48 const char *attrs[] = { NULL }; 41 49 struct ldb_result *res; 42 50 43 51 ret = ldb_search(ldb, ldb, &res, dn, LDB_SCOPE_SUBTREE, attrs, "distinguishedName=*"); 44 if (ret != LDB_SUCCESS) return -1; 52 if (ret != LDB_SUCCESS) return ret; 53 54 /* sort the DNs, deepest first */ 55 TYPESAFE_QSORT(res->msgs, res->count, dn_cmp); 45 56 46 57 for (i = 0; i < res->count; i++) { 47 if (ldb_delete (ldb, res->msgs[i]->dn) == 0) {58 if (ldb_delete_ctrl(ldb, res->msgs[i]->dn,req_ctrls) == LDB_SUCCESS) { 48 59 total++; 60 } else { 61 printf("Failed to delete '%s' - %s\n", 62 ldb_dn_get_linearized(res->msgs[i]->dn), 63 ldb_errstring(ldb)); 49 64 } 50 65 } … … 53 68 54 69 if (total == 0) { 55 return -1;70 return LDB_ERR_OPERATIONS_ERROR; 56 71 } 57 printf("Deleted % drecords\n", total);58 return 0;72 printf("Deleted %u records\n", total); 73 return LDB_SUCCESS; 59 74 } 60 75 61 static void usage( void)76 static void usage(struct ldb_context *ldb) 62 77 { 63 78 printf("Usage: ldbdel <options> <DN...>\n"); 64 79 printf("Deletes records from a ldb\n\n"); 65 ldb_cmdline_help( "ldbdel", stdout);66 exit( 1);80 ldb_cmdline_help(ldb, "ldbdel", stdout); 81 exit(LDB_ERR_OPERATIONS_ERROR); 67 82 } 68 83 69 84 int main(int argc, const char **argv) 70 85 { 86 struct ldb_control **req_ctrls; 87 struct ldb_cmdline *options; 71 88 struct ldb_context *ldb; 72 89 int ret = 0, i; 73 struct ldb_cmdline *options;90 TALLOC_CTX *mem_ctx = talloc_new(NULL); 74 91 75 ldb = ldb_init(NULL, NULL); 92 ldb = ldb_init(mem_ctx, NULL); 93 if (ldb == NULL) { 94 return LDB_ERR_OPERATIONS_ERROR; 95 } 76 96 77 97 options = ldb_cmdline_process(ldb, argc, argv, usage); 78 98 79 99 if (options->argc < 1) { 80 usage(); 81 exit(1); 100 usage(ldb); 101 } 102 103 req_ctrls = ldb_parse_control_strings(ldb, ldb, (const char **)options->controls); 104 if (options->controls != NULL && req_ctrls== NULL) { 105 printf("parsing controls failed: %s\n", ldb_errstring(ldb)); 106 return LDB_ERR_OPERATIONS_ERROR; 82 107 } 83 108 … … 86 111 87 112 dn = ldb_dn_new(ldb, ldb, options->argv[i]); 88 if ( ! ldb_dn_validate(dn)) { 89 printf("Invalid DN format\n"); 90 exit(1); 113 if (dn == NULL) { 114 return LDB_ERR_OPERATIONS_ERROR; 91 115 } 92 116 if (options->recursive) { 93 ret = ldb_delete_recursive(ldb, dn );117 ret = ldb_delete_recursive(ldb, dn,req_ctrls); 94 118 } else { 95 ret = ldb_delete (ldb, dn);96 if (ret == 0) {119 ret = ldb_delete_ctrl(ldb, dn,req_ctrls); 120 if (ret == LDB_SUCCESS) { 97 121 printf("Deleted 1 record\n"); 98 122 } 99 123 } 100 if (ret != 0) { 101 printf("delete of '%s' failed - %s\n", 102 ldb_dn_get_linearized(dn), 103 ldb_errstring(ldb)); 124 if (ret != LDB_SUCCESS) { 125 printf("delete of '%s' failed - (%s) %s\n", 126 ldb_dn_get_linearized(dn), 127 ldb_strerror(ret), 128 ldb_errstring(ldb)); 104 129 } 105 130 } 106 131 107 talloc_free( ldb);132 talloc_free(mem_ctx); 108 133 109 134 return ret; -
trunk/server/source4/lib/ldb/tools/ldbedit.c
r414 r745 1 /* 1 /* 2 2 ldb database library 3 3 … … 7 7 ** library. This does NOT imply that all of Samba is released 8 8 ** under the LGPL 9 9 10 10 This library is free software; you can redistribute it and/or 11 11 modify it under the terms of the GNU Lesser General Public … … 31 31 * Author: Andrew Tridgell 32 32 */ 33 #include "ldb_includes.h" 33 34 #include "replace.h" 35 #include "system/filesys.h" 36 #include "system/time.h" 37 #include "system/filesys.h" 34 38 #include "ldb.h" 35 39 #include "tools/cmdline.h" 40 #include "tools/ldbutil.h" 36 41 37 42 static struct ldb_cmdline *options; 38 43 39 44 /* 40 debug routine 41 */ 42 static void ldif_write_msg(struct ldb_context *ldb, 43 FILE *f, 45 debug routine 46 */ 47 static void ldif_write_msg(struct ldb_context *ldb, 48 FILE *f, 44 49 enum ldb_changetype changetype, 45 50 struct ldb_message *msg) … … 55 60 returns the number of modified elements 56 61 */ 57 static int modify_record(struct ldb_context *ldb, 62 static int modify_record(struct ldb_context *ldb, 58 63 struct ldb_message *msg1, 59 struct ldb_message *msg2) 60 { 64 struct ldb_message *msg2, 65 struct ldb_control **req_ctrls) 66 { 67 int ret; 61 68 struct ldb_message *mod; 62 69 63 mod = ldb_msg_diff(ldb, msg1, msg2); 64 if (mod == NULL) { 70 if (ldb_msg_difference(ldb, ldb, msg1, msg2, &mod) != LDB_SUCCESS) { 65 71 fprintf(stderr, "Failed to calculate message differences\n"); 66 72 return -1; 67 73 } 68 74 69 if (mod->num_elements == 0) { 70 return 0; 75 ret = mod->num_elements; 76 if (ret == 0) { 77 goto done; 71 78 } 72 79 … … 75 82 } 76 83 77 if (ldb_modify (ldb, mod) != 0) {78 fprintf(stderr, "failed to modify %s - %s\n", 84 if (ldb_modify_ctrl(ldb, mod, req_ctrls) != LDB_SUCCESS) { 85 fprintf(stderr, "failed to modify %s - %s\n", 79 86 ldb_dn_get_linearized(msg1->dn), ldb_errstring(ldb)); 80 return -1; 81 } 82 83 return mod->num_elements; 87 ret = -1; 88 goto done; 89 } 90 91 done: 92 talloc_free(mod); 93 return ret; 84 94 } 85 95 … … 89 99 static struct ldb_message *msg_find(struct ldb_context *ldb, 90 100 struct ldb_message **msgs, 91 int count,101 unsigned int count, 92 102 struct ldb_dn *dn) 93 103 { 94 int i;104 unsigned int i; 95 105 for (i=0;i<count;i++) { 96 106 if (ldb_dn_compare(dn, msgs[i]->dn) == 0) { … … 105 115 */ 106 116 static int merge_edits(struct ldb_context *ldb, 107 struct ldb_message **msgs1, int count1,108 struct ldb_message **msgs2, int count2)109 { 110 int i;117 struct ldb_message **msgs1, unsigned int count1, 118 struct ldb_message **msgs2, unsigned int count2) 119 { 120 unsigned int i; 111 121 struct ldb_message *msg; 112 int ret = 0; 113 int adds=0, modifies=0, deletes=0; 114 115 if (ldb_transaction_start(ldb) != 0) { 122 int ret; 123 unsigned int adds=0, modifies=0, deletes=0; 124 struct ldb_control **req_ctrls = ldb_parse_control_strings(ldb, ldb, (const char **)options->controls); 125 if (options->controls != NULL && req_ctrls == NULL) { 126 fprintf(stderr, "parsing controls failed: %s\n", ldb_errstring(ldb)); 127 return -1; 128 } 129 130 if (ldb_transaction_start(ldb) != LDB_SUCCESS) { 116 131 fprintf(stderr, "Failed to start transaction: %s\n", ldb_errstring(ldb)); 117 132 return -1; … … 125 140 ldif_write_msg(ldb, stdout, LDB_CHANGETYPE_ADD, msgs2[i]); 126 141 } 127 if (ldb_add (ldb, msgs2[i]) != 0) {142 if (ldb_add_ctrl(ldb, msgs2[i], req_ctrls) != LDB_SUCCESS) { 128 143 fprintf(stderr, "failed to add %s - %s\n", 129 144 ldb_dn_get_linearized(msgs2[i]->dn), … … 134 149 adds++; 135 150 } else { 136 if (modify_record(ldb, msg, msgs2[i]) > 0) { 137 modifies++; 151 ret = modify_record(ldb, msg, msgs2[i], req_ctrls); 152 if (ret != -1) { 153 modifies += (unsigned int) ret; 154 } else { 155 return -1; 138 156 } 139 157 } … … 147 165 ldif_write_msg(ldb, stdout, LDB_CHANGETYPE_DELETE, msgs1[i]); 148 166 } 149 if (ldb_delete (ldb, msgs1[i]->dn) != 0) {167 if (ldb_delete_ctrl(ldb, msgs1[i]->dn, req_ctrls) != LDB_SUCCESS) { 150 168 fprintf(stderr, "failed to delete %s - %s\n", 151 169 ldb_dn_get_linearized(msgs1[i]->dn), … … 158 176 } 159 177 160 if (ldb_transaction_commit(ldb) != 0) {178 if (ldb_transaction_commit(ldb) != LDB_SUCCESS) { 161 179 fprintf(stderr, "Failed to commit transaction: %s\n", ldb_errstring(ldb)); 162 180 return -1; 163 181 } 164 182 165 printf("# % d adds %d modifies %ddeletes\n", adds, modifies, deletes);166 167 return ret;183 printf("# %u adds %u modifies %u deletes\n", adds, modifies, deletes); 184 185 return 0; 168 186 } 169 187 … … 171 189 save a set of messages as ldif to a file 172 190 */ 173 static int save_ldif(struct ldb_context *ldb, 174 FILE *f, struct ldb_message **msgs, int count)175 { 176 int i;177 178 fprintf(f, "# editing % drecords\n", count);191 static int save_ldif(struct ldb_context *ldb, 192 FILE *f, struct ldb_message **msgs, unsigned int count) 193 { 194 unsigned int i; 195 196 fprintf(f, "# editing %u records\n", count); 179 197 180 198 for (i=0;i<count;i++) { 181 199 struct ldb_ldif ldif; 182 fprintf(f, "# record % d\n", i+1);200 fprintf(f, "# record %u\n", i+1); 183 201 184 202 ldif.changetype = LDB_CHANGETYPE_NONE; … … 195 213 edit the ldb search results in msgs using the user selected editor 196 214 */ 197 static int do_edit(struct ldb_context *ldb, struct ldb_message **msgs1, int count1,198 const char *editor)215 static int do_edit(struct ldb_context *ldb, struct ldb_message **msgs1, 216 unsigned int count1, const char *editor) 199 217 { 200 218 int fd, ret; … … 204 222 struct ldb_ldif *ldif; 205 223 struct ldb_message **msgs2 = NULL; 206 int count2 = 0;224 unsigned int count2 = 0; 207 225 208 226 /* write out the original set of messages to a temporary … … 270 288 } 271 289 272 static void usage( void)290 static void usage(struct ldb_context *ldb) 273 291 { 274 292 printf("Usage: ldbedit <options> <expression> <attributes ...>\n"); 275 ldb_cmdline_help( "ldbedit", stdout);276 exit( 1);293 ldb_cmdline_help(ldb, "ldbedit", stdout); 294 exit(LDB_ERR_OPERATIONS_ERROR); 277 295 } 278 296 … … 285 303 const char *expression = "(|(objectClass=*)(distinguishedName=*))"; 286 304 const char * const * attrs = NULL; 287 288 ldb = ldb_init(NULL, NULL); 305 TALLOC_CTX *mem_ctx = talloc_new(NULL); 306 struct ldb_control **req_ctrls; 307 308 ldb = ldb_init(mem_ctx, NULL); 309 if (ldb == NULL) { 310 return LDB_ERR_OPERATIONS_ERROR; 311 } 289 312 290 313 options = ldb_cmdline_process(ldb, argc, argv, usage); 291 314 292 315 /* the check for '=' is for compatibility with ldapsearch */ 293 if (options->argc > 0 && 316 if (options->argc > 0 && 294 317 strchr(options->argv[0], '=')) { 295 318 expression = options->argv[0]; … … 304 327 if (options->basedn != NULL) { 305 328 basedn = ldb_dn_new(ldb, ldb, options->basedn); 306 if ( ! ldb_dn_validate(basedn)) { 307 printf("Invalid Base DN format\n"); 308 exit(1); 309 } 310 } 311 312 ret = ldb_search(ldb, ldb, &result, basedn, options->scope, attrs, "%s", expression); 329 if (basedn == NULL) { 330 return LDB_ERR_OPERATIONS_ERROR; 331 } 332 } 333 334 req_ctrls = ldb_parse_control_strings(ldb, ldb, (const char **)options->controls); 335 if (options->controls != NULL && req_ctrls== NULL) { 336 printf("parsing controls failed: %s\n", ldb_errstring(ldb)); 337 return LDB_ERR_OPERATIONS_ERROR; 338 } 339 340 ret = ldb_search_ctrl(ldb, ldb, &result, basedn, options->scope, attrs, req_ctrls, "%s", expression); 313 341 if (ret != LDB_SUCCESS) { 314 342 printf("search failed - %s\n", ldb_errstring(ldb)); 315 exit(1);343 return ret; 316 344 } 317 345 318 346 if (result->count == 0) { 319 347 printf("no matching records - cannot edit\n"); 320 return 0; 321 } 322 323 do_edit(ldb, result->msgs, result->count, options->editor); 324 325 if (result) { 326 ret = talloc_free(result); 327 if (ret == -1) { 328 fprintf(stderr, "talloc_free failed\n"); 329 exit(1); 330 } 331 } 332 333 talloc_free(ldb); 334 return 0; 335 } 348 talloc_free(mem_ctx); 349 return LDB_SUCCESS; 350 } 351 352 ret = do_edit(ldb, result->msgs, result->count, options->editor); 353 354 talloc_free(mem_ctx); 355 356 return ret == 0 ? LDB_SUCCESS : LDB_ERR_OPERATIONS_ERROR; 357 } -
trunk/server/source4/lib/ldb/tools/ldbmodify.c
r414 r745 34 34 #include "ldb.h" 35 35 #include "tools/cmdline.h" 36 #include "ldbutil.h" 36 37 37 static int failures; 38 static unsigned int failures; 39 static struct ldb_cmdline *options; 38 40 39 static void usage( void)41 static void usage(struct ldb_context *ldb) 40 42 { 41 43 printf("Usage: ldbmodify <options> <ldif...>\n"); 42 44 printf("Modifies a ldb based upon ldif change records\n\n"); 43 ldb_cmdline_help( "ldbmodify", stdout);44 exit( 1);45 ldb_cmdline_help(ldb, "ldbmodify", stdout); 46 exit(LDB_ERR_OPERATIONS_ERROR); 45 47 } 46 48 … … 48 50 process modifies for one file 49 51 */ 50 static int process_file(struct ldb_context *ldb, FILE *f, int *count)52 static int process_file(struct ldb_context *ldb, FILE *f, unsigned int *count) 51 53 { 52 54 struct ldb_ldif *ldif; 53 55 int ret = LDB_SUCCESS; 54 56 struct ldb_control **req_ctrls = ldb_parse_control_strings(ldb, ldb, (const char **)options->controls); 57 58 if (options->controls != NULL && req_ctrls== NULL) { 59 printf("parsing controls failed: %s\n", ldb_errstring(ldb)); 60 exit(LDB_ERR_OPERATIONS_ERROR); 61 } 62 55 63 while ((ldif = ldb_ldif_read_file(ldb, f))) { 56 64 switch (ldif->changetype) { 57 65 case LDB_CHANGETYPE_NONE: 58 66 case LDB_CHANGETYPE_ADD: 59 ret = ldb_add (ldb, ldif->msg);67 ret = ldb_add_ctrl(ldb, ldif->msg,req_ctrls); 60 68 break; 61 69 case LDB_CHANGETYPE_DELETE: 62 ret = ldb_delete (ldb, ldif->msg->dn);70 ret = ldb_delete_ctrl(ldb, ldif->msg->dn,req_ctrls); 63 71 break; 64 72 case LDB_CHANGETYPE_MODIFY: 65 ret = ldb_modify (ldb, ldif->msg);73 ret = ldb_modify_ctrl(ldb, ldif->msg,req_ctrls); 66 74 break; 67 75 } 68 76 if (ret != LDB_SUCCESS) { 69 fprintf(stderr, "ERR: \"%s\" on DN %s\n", 77 fprintf(stderr, "ERR: (%s) \"%s\" on DN %s\n", 78 ldb_strerror(ret), 70 79 ldb_errstring(ldb), ldb_dn_get_linearized(ldif->msg->dn)); 71 80 failures++; 72 81 } else { 73 82 (*count)++; 83 if (options->verbose) { 84 printf("Modified %s\n", ldb_dn_get_linearized(ldif->msg->dn)); 85 } 74 86 } 75 87 ldb_ldif_read_free(ldb, ldif); … … 82 94 { 83 95 struct ldb_context *ldb; 84 int count=0;85 int i, ret=LDB_SUCCESS;86 struct ldb_cmdline *options;96 unsigned int i, count = 0; 97 int ret = LDB_SUCCESS; 98 TALLOC_CTX *mem_ctx = talloc_new(NULL); 87 99 88 ldb = ldb_init(NULL, NULL); 100 ldb = ldb_init(mem_ctx, NULL); 101 if (ldb == NULL) { 102 return LDB_ERR_OPERATIONS_ERROR; 103 } 89 104 90 105 options = ldb_cmdline_process(ldb, argc, argv, usage); … … 99 114 if (!f) { 100 115 perror(fname); 101 exit(1);116 return LDB_ERR_OPERATIONS_ERROR; 102 117 } 103 118 ret = process_file(ldb, f, &count); … … 106 121 } 107 122 108 talloc_free( ldb);123 talloc_free(mem_ctx); 109 124 110 printf("Modified % d records with %dfailures\n", count, failures);125 printf("Modified %u records with %u failures\n", count, failures); 111 126 112 127 return ret; -
trunk/server/source4/lib/ldb/tools/ldbrename.c
r414 r745 37 37 #include "tools/cmdline.h" 38 38 39 static void usage( void)39 static void usage(struct ldb_context *ldb) 40 40 { 41 41 printf("Usage: ldbrename [<options>] <olddn> <newdn>\n"); 42 42 printf("Renames records in a ldb\n\n"); 43 ldb_cmdline_help( "ldbmodify", stdout);44 exit( 1);43 ldb_cmdline_help(ldb, "ldbmodify", stdout); 44 exit(LDB_ERR_OPERATIONS_ERROR); 45 45 } 46 46 … … 52 52 struct ldb_cmdline *options; 53 53 struct ldb_dn *dn1, *dn2; 54 TALLOC_CTX *mem_ctx = talloc_new(NULL); 54 55 55 ldb = ldb_init(NULL, NULL); 56 ldb = ldb_init(mem_ctx, NULL); 57 if (ldb == NULL) { 58 return LDB_ERR_OPERATIONS_ERROR; 59 } 56 60 57 61 options = ldb_cmdline_process(ldb, argc, argv, usage); 58 62 59 63 if (options->argc < 2) { 60 usage( );64 usage(ldb); 61 65 } 62 66 63 67 dn1 = ldb_dn_new(ldb, ldb, options->argv[0]); 64 68 dn2 = ldb_dn_new(ldb, ldb, options->argv[1]); 65 66 if ( ! ldb_dn_validate(dn1)) { 67 printf("Invalid DN1: %s\n", options->argv[0]); 68 return -1; 69 } 70 if ( ! ldb_dn_validate(dn2)) { 71 printf("Invalid DN2: %s\n", options->argv[1]); 72 return -1; 69 if ((dn1 == NULL) || (dn2 == NULL)) { 70 return LDB_ERR_OPERATIONS_ERROR; 73 71 } 74 72 75 73 ret = ldb_rename(ldb, dn1, dn2); 76 if (ret == 0) {74 if (ret == LDB_SUCCESS) { 77 75 printf("Renamed 1 record\n"); 78 76 } else { … … 81 79 } 82 80 83 talloc_free( ldb);81 talloc_free(mem_ctx); 84 82 85 83 return ret; -
trunk/server/source4/lib/ldb/tools/ldbsearch.c
r414 r745 32 32 */ 33 33 34 #include "ldb_includes.h" 34 #include "replace.h" 35 #include "system/filesys.h" 36 #include "system/time.h" 35 37 #include "ldb.h" 36 38 #include "tools/cmdline.h" 37 39 38 static void usage( void)40 static void usage(struct ldb_context *ldb) 39 41 { 40 42 printf("Usage: ldbsearch <options> <expression> <attrs...>\n"); 41 ldb_cmdline_help( "ldbsearch", stdout);42 exit( 1);43 ldb_cmdline_help(ldb, "ldbsearch", stdout); 44 exit(LDB_ERR_OPERATIONS_ERROR); 43 45 } 44 46 … … 55 57 56 58 int sort; 57 int num_stored;59 unsigned int num_stored; 58 60 struct ldb_message **store; 59 int refs_stored;61 unsigned int refs_stored; 60 62 char **refs_store; 61 63 62 int entries;63 int refs;64 65 int pending;64 unsigned int entries; 65 unsigned int refs; 66 67 unsigned int pending; 66 68 int status; 67 69 }; … … 132 134 { 133 135 struct search_context *sctx; 134 int ret ;136 int ret = LDB_SUCCESS; 135 137 136 138 sctx = talloc_get_type(req->context, struct search_context); … … 173 175 174 176 talloc_free(ares); 175 if (ret ) {177 if (ret != LDB_SUCCESS) { 176 178 return ldb_request_done(req, LDB_ERR_OPERATIONS_ERROR); 177 179 } … … 192 194 req = NULL; 193 195 194 sctx = talloc (ldb, struct search_context);195 if (!sctx) return -1;196 sctx = talloc_zero(ldb, struct search_context); 197 if (!sctx) return LDB_ERR_OPERATIONS_ERROR; 196 198 197 199 sctx->ldb = ldb; 198 200 sctx->sort = options->sorted; 199 sctx->num_stored = 0;200 sctx->refs_stored = 0;201 sctx->store = NULL;202 201 sctx->req_ctrls = ldb_parse_control_strings(ldb, sctx, (const char **)options->controls); 203 202 if (options->controls != NULL && sctx->req_ctrls== NULL) { 204 203 printf("parsing controls failed: %s\n", ldb_errstring(ldb)); 205 return -1; 206 } 207 sctx->entries = 0; 208 sctx->refs = 0; 204 return LDB_ERR_OPERATIONS_ERROR; 205 } 209 206 210 207 if (basedn == NULL) { … … 225 222 talloc_free(sctx); 226 223 printf("allocating request failed: %s\n", ldb_errstring(ldb)); 227 return -1;224 return ret; 228 225 } 229 226 … … 233 230 if (ret != LDB_SUCCESS) { 234 231 printf("search failed - %s\n", ldb_errstring(ldb)); 235 return -1;232 return ret; 236 233 } 237 234 238 235 ret = ldb_wait(req->handle, LDB_WAIT_ALL); 239 236 if (ret != LDB_SUCCESS) { 240 237 printf("search error - %s\n", ldb_errstring(ldb)); 241 return -1;238 return ret; 242 239 } 243 240 … … 246 243 247 244 if (sctx->sort && (sctx->num_stored != 0 || sctx->refs != 0)) { 248 int i;245 unsigned int i; 249 246 250 247 if (sctx->num_stored) { 251 ldb_qsort(sctx->store, sctx->num_stored, sizeof(struct ldb_message *), 252 ldb, (ldb_qsort_cmp_fn_t)do_compare_msg); 248 LDB_TYPESAFE_QSORT(sctx->store, sctx->num_stored, ldb, do_compare_msg); 253 249 } 254 250 for (i = 0; i < sctx->num_stored; i++) { … … 261 257 } 262 258 263 printf("# returned % d records\n# %d entries\n# %dreferrals\n",259 printf("# returned %u records\n# %u entries\n# %u referrals\n", 264 260 sctx->entries + sctx->refs, sctx->entries, sctx->refs); 265 261 … … 267 263 talloc_free(req); 268 264 269 return 0;265 return LDB_SUCCESS; 270 266 } 271 267 … … 278 274 int ret = -1; 279 275 const char *expression = "(|(objectClass=*)(distinguishedName=*))"; 280 281 ldb = ldb_init(NULL, NULL); 276 TALLOC_CTX *mem_ctx = talloc_new(NULL); 277 278 ldb = ldb_init(mem_ctx, NULL); 282 279 if (ldb == NULL) { 283 return -1;280 return LDB_ERR_OPERATIONS_ERROR; 284 281 } 285 282 … … 301 298 if (options->basedn != NULL) { 302 299 basedn = ldb_dn_new(ldb, ldb, options->basedn); 303 if ( ! ldb_dn_validate(basedn)) { 304 fprintf(stderr, "Invalid Base DN format\n"); 305 exit(1); 300 if (basedn == NULL) { 301 return LDB_ERR_OPERATIONS_ERROR; 306 302 } 307 303 } … … 310 306 char line[1024]; 311 307 while (fgets(line, sizeof(line), stdin)) { 312 if (do_search(ldb, basedn, options, line, attrs) == -1) { 313 ret = -1; 314 } 308 ret = do_search(ldb, basedn, options, line, attrs); 315 309 } 316 310 } else { … … 318 312 } 319 313 320 talloc_free(ldb); 314 talloc_free(mem_ctx); 315 321 316 return ret; 322 317 } -
trunk/server/source4/lib/ldb/tools/ldbtest.c
r414 r745 32 32 */ 33 33 34 #include "ldb_includes.h" 34 #include "replace.h" 35 #include "system/filesys.h" 36 #include "system/time.h" 35 37 #include "ldb.h" 36 38 #include "tools/cmdline.h" 37 39 38 static struct time valtp1,tp2;40 static struct timespec tp1,tp2; 39 41 static struct ldb_cmdline *options; 40 42 41 43 static void _start_timer(void) 42 44 { 43 gettimeofday(&tp1,NULL); 45 if (clock_gettime(CUSTOM_CLOCK_MONOTONIC, &tp1) != 0) { 46 clock_gettime(CLOCK_REALTIME, &tp1); 47 } 44 48 } 45 49 46 50 static double _end_timer(void) 47 51 { 48 gettimeofday(&tp2,NULL); 52 if (clock_gettime(CUSTOM_CLOCK_MONOTONIC, &tp2) != 0) { 53 clock_gettime(CLOCK_REALTIME, &tp2); 54 } 49 55 return((tp2.tv_sec - tp1.tv_sec) + 50 (tp2.tv_ usec - tp1.tv_usec)*1.0e-6);56 (tp2.tv_nsec - tp1.tv_nsec)*1.0e-9); 51 57 } 52 58 53 59 static void add_records(struct ldb_context *ldb, 54 60 struct ldb_dn *basedn, 55 int count)61 unsigned int count) 56 62 { 57 63 struct ldb_message msg; 58 int i;64 unsigned int i; 59 65 60 66 #if 0 61 67 if (ldb_lock(ldb, "transaction") != 0) { 62 68 printf("transaction lock failed\n"); 63 exit( 1);69 exit(LDB_ERR_OPERATIONS_ERROR); 64 70 } 65 71 #endif … … 123 129 if (ldb_add(ldb, &msg) != 0) { 124 130 printf("Add of %s failed - %s\n", name, ldb_errstring(ldb)); 125 exit( 1);131 exit(LDB_ERR_OPERATIONS_ERROR); 126 132 } 127 133 … … 134 140 if (ldb_unlock(ldb, "transaction") != 0) { 135 141 printf("transaction unlock failed\n"); 136 exit( 1);142 exit(LDB_ERR_OPERATIONS_ERROR); 137 143 } 138 144 #endif … … 142 148 static void modify_records(struct ldb_context *ldb, 143 149 struct ldb_dn *basedn, 144 int count)150 unsigned int count) 145 151 { 146 152 struct ldb_message msg; 147 int i;153 unsigned int i; 148 154 149 155 for (i=0;i<count;i++) { … … 180 186 if (ldb_modify(ldb, &msg) != 0) { 181 187 printf("Modify of %s failed - %s\n", name, ldb_errstring(ldb)); 182 exit( 1);188 exit(LDB_ERR_OPERATIONS_ERROR); 183 189 } 184 190 … … 195 201 static void delete_records(struct ldb_context *ldb, 196 202 struct ldb_dn *basedn, 197 int count)198 { 199 int i;203 unsigned int count) 204 { 205 unsigned int i; 200 206 201 207 for (i=0;i<count;i++) { … … 210 216 if (ldb_delete(ldb, dn) != 0) { 211 217 printf("Delete of %s failed - %s\n", ldb_dn_get_linearized(dn), ldb_errstring(ldb)); 212 exit( 1);218 exit(LDB_ERR_OPERATIONS_ERROR); 213 219 } 214 220 talloc_free(name); … … 218 224 } 219 225 220 static void search_uid(struct ldb_context *ldb, struct ldb_dn *basedn, int nrecords, int nsearches) 221 { 222 int i; 226 static void search_uid(struct ldb_context *ldb, struct ldb_dn *basedn, 227 unsigned int nrecords, unsigned int nsearches) 228 { 229 unsigned int i; 223 230 224 231 for (i=0;i<nsearches;i++) { … … 233 240 if (ret != LDB_SUCCESS || (uid < nrecords && res->count != 1)) { 234 241 printf("Failed to find %s - %s\n", expr, ldb_errstring(ldb)); 235 exit( 1);242 exit(LDB_ERR_OPERATIONS_ERROR); 236 243 } 237 244 238 245 if (uid >= nrecords && res->count > 0) { 239 246 printf("Found %s !? - %d\n", expr, ret); 240 exit( 1);247 exit(LDB_ERR_OPERATIONS_ERROR); 241 248 } 242 249 243 printf(" testing uid %d/%d - %d \r", i, uid, res->count);250 printf("Testing uid %d/%d - %d \r", i, uid, res->count); 244 251 fflush(stdout); 245 252 … … 251 258 } 252 259 253 static void start_test(struct ldb_context *ldb, int nrecords, int nsearches) 260 static void start_test(struct ldb_context *ldb, unsigned int nrecords, 261 unsigned int nsearches) 254 262 { 255 263 struct ldb_dn *basedn; … … 257 265 basedn = ldb_dn_new(ldb, ldb, options->basedn); 258 266 if ( ! ldb_dn_validate(basedn)) { 259 printf("Invalid base DN \n");260 exit( 1);267 printf("Invalid base DN format\n"); 268 exit(LDB_ERR_INVALID_DN_SYNTAX); 261 269 } 262 270 … … 323 331 if (ldb_add(*ldb, msg) != 0) { 324 332 printf("Add of %s failed - %s\n", ldb_dn_get_linearized(msg->dn), ldb_errstring(*ldb)); 325 exit( 1);333 exit(LDB_ERR_OPERATIONS_ERROR); 326 334 } 327 335 … … 338 346 if (ldb_add(*ldb, msg) != 0) { 339 347 printf("Add of %s failed - %s\n", ldb_dn_get_linearized(msg->dn), ldb_errstring(*ldb)); 340 exit( 1);348 exit(LDB_ERR_OPERATIONS_ERROR); 341 349 } 342 350 343 351 if (talloc_free(*ldb) != 0) { 344 352 printf("failed to free/close ldb database"); 345 exit( 1);353 exit(LDB_ERR_OPERATIONS_ERROR); 346 354 } 347 355 … … 351 359 if (ret != 0) { 352 360 printf("failed to connect to %s\n", options->url); 353 exit( 1);361 exit(LDB_ERR_OPERATIONS_ERROR); 354 362 } 355 363 356 364 basedn = ldb_dn_new(*ldb, *ldb, options->basedn); 365 msg->dn = basedn; 366 ldb_dn_add_child_fmt(msg->dn, "cn=test"); 357 367 358 368 ret = ldb_search(*ldb, *ldb, &res, basedn, LDB_SCOPE_SUBTREE, NULL, "uid=test"); 359 369 if (ret != LDB_SUCCESS) { 360 370 printf("Search with (uid=test) filter failed!\n"); 361 exit( 1);371 exit(LDB_ERR_OPERATIONS_ERROR); 362 372 } 363 373 if(res->count != 1) { 364 374 printf("Should have found 1 record - found %d\n", res->count); 365 exit( 1);375 exit(LDB_ERR_OPERATIONS_ERROR); 366 376 } 367 377 … … 371 381 ldb_delete(*ldb, indexlist) != 0) { 372 382 printf("cleanup failed - %s\n", ldb_errstring(*ldb)); 373 exit( 1);383 exit(LDB_ERR_OPERATIONS_ERROR); 374 384 } 375 385 … … 378 388 379 389 380 static void usage( void)390 static void usage(struct ldb_context *ldb) 381 391 { 382 392 printf("Usage: ldbtest <options>\n"); … … 387 397 printf("\n"); 388 398 printf("tests ldb API\n\n"); 389 exit( 1);399 exit(LDB_ERR_OPERATIONS_ERROR); 390 400 } 391 401 … … 396 406 397 407 ldb = ldb_init(mem_ctx, NULL); 408 if (ldb == NULL) { 409 return LDB_ERR_OPERATIONS_ERROR; 410 } 398 411 399 412 options = ldb_cmdline_process(ldb, argc, argv, usage); … … 410 423 options->num_records, options->num_searches); 411 424 412 start_test(ldb, options->num_records, options->num_searches); 425 start_test(ldb, 426 (unsigned int) options->num_records, 427 (unsigned int) options->num_searches); 413 428 414 429 start_test_index(&ldb); … … 416 431 talloc_free(mem_ctx); 417 432 418 return 0;419 } 433 return LDB_SUCCESS; 434 }
Note:
See TracChangeset
for help on using the changeset viewer.