Changeset 745 for trunk/server/source4/lib/registry/dir.c
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
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/registry/dir.c
r414 r745 41 41 42 42 path = talloc_asprintf(mem_ctx, "%s/%s", dk->path, name); 43 W_ERROR_HAVE_NO_MEMORY(path); 43 44 ret = mkdir(path, 0700); 44 45 if (ret == 0) { 45 46 struct dir_key *key = talloc(mem_ctx, struct dir_key); 47 W_ERROR_HAVE_NO_MEMORY(key); 46 48 key->key.ops = ®_backend_dir; 47 49 key->path = talloc_steal(key, path); … … 77 79 78 80 path = talloc_asprintf(name, "%s/%s", name, e->d_name); 79 if (!path) 80 return WERR_NOMEM; 81 W_ERROR_HAVE_NO_MEMORY(path); 81 82 82 83 stat(path, &stbuf); … … 109 110 } 110 111 111 static WERROR reg_dir_del_key(const struct hive_key *k, const char *name) 112 static WERROR reg_dir_del_key(TALLOC_CTX *mem_ctx, const struct hive_key *k, 113 const char *name) 112 114 { 113 115 struct dir_key *dk = talloc_get_type(k, struct dir_key); 114 char *child = talloc_asprintf(NULL, "%s/%s", dk->path, name);116 char *child; 115 117 WERROR ret; 118 119 child = talloc_asprintf(mem_ctx, "%s/%s", dk->path, name); 120 W_ERROR_HAVE_NO_MEMORY(child); 116 121 117 122 ret = reg_dir_delete_recursive(child); … … 137 142 138 143 fullpath = talloc_asprintf(mem_ctx, "%s/%s", p->path, name); 144 W_ERROR_HAVE_NO_MEMORY(fullpath); 139 145 140 146 d = opendir(fullpath); … … 142 148 DEBUG(3,("Unable to open '%s': %s\n", fullpath, 143 149 strerror(errno))); 150 talloc_free(fullpath); 144 151 return WERR_BADFILE; 145 152 } … … 160 167 struct dirent *e; 161 168 const struct dir_key *dk = talloc_get_type(k, struct dir_key); 162 int i = 0;169 unsigned int i = 0; 163 170 DIR *d; 164 171 … … 174 181 175 182 /* Check if file is a directory */ 176 asprintf(&thispath, "%s/%s", dk->path, e->d_name); 183 thispath = talloc_asprintf(mem_ctx, "%s/%s", dk->path, 184 e->d_name); 185 W_ERROR_HAVE_NO_MEMORY(thispath); 177 186 stat(thispath, &stbuf); 178 187 179 188 if (!S_ISDIR(stbuf.st_mode)) { 180 SAFE_FREE(thispath);189 talloc_free(thispath); 181 190 continue; 182 191 } … … 185 194 struct stat st; 186 195 *name = talloc_strdup(mem_ctx, e->d_name); 196 W_ERROR_HAVE_NO_MEMORY(*name); 187 197 *classname = NULL; 188 198 stat(thispath, &st); 189 199 unix_to_nt_time(last_mod_time, st.st_mtime); 190 SAFE_FREE(thispath);200 talloc_free(thispath); 191 201 closedir(d); 192 202 return WERR_OK; … … 194 204 i++; 195 205 196 SAFE_FREE(thispath);206 talloc_free(thispath); 197 207 } 198 208 } … … 212 222 213 223 dk = talloc(parent_ctx, struct dir_key); 224 W_ERROR_HAVE_NO_MEMORY(dk); 214 225 dk->key.ops = ®_backend_dir; 215 226 dk->path = talloc_strdup(dk, location); … … 271 282 char *path = talloc_asprintf(ctx, "%s/%s", 272 283 dk->path, e->d_name); 284 W_ERROR_HAVE_NO_MEMORY(path); 273 285 274 286 if (stat(path, &st) < 0) { 275 287 DEBUG(0, ("Error statting %s: %s\n", path, 276 288 strerror(errno))); 289 talloc_free(path); 277 290 continue; 278 291 } … … 309 322 { 310 323 const struct dir_key *dk = talloc_get_type(key, struct dir_key); 311 char *path = talloc_asprintf(dk, "%s/%s", dk->path, name); 312 313 if (!file_save(path, data.data, data.length)) 324 char *path; 325 bool ret; 326 327 path = talloc_asprintf(dk, "%s/%s", dk->path, name); 328 W_ERROR_HAVE_NO_MEMORY(path); 329 330 ret = file_save(path, data.data, data.length); 331 332 talloc_free(path); 333 334 if (!ret) { 314 335 return WERR_GENERAL_FAILURE; 336 } 315 337 316 338 /* FIXME: Type */ … … 324 346 { 325 347 const struct dir_key *dk = talloc_get_type(key, struct dir_key); 326 char *path = talloc_asprintf(mem_ctx, "%s/%s", dk->path, name);348 char *path; 327 349 size_t size; 328 350 char *contents; 329 351 352 path = talloc_asprintf(mem_ctx, "%s/%s", dk->path, name); 353 W_ERROR_HAVE_NO_MEMORY(path); 354 330 355 contents = file_load(path, &size, 0, mem_ctx); 356 331 357 talloc_free(path); 358 332 359 if (contents == NULL) 333 360 return WERR_BADFILE; … … 343 370 344 371 static WERROR reg_dir_enum_value(TALLOC_CTX *mem_ctx, 345 struct hive_key *key, int idx,372 struct hive_key *key, uint32_t idx, 346 373 const char **name, 347 374 uint32_t *type, DATA_BLOB *data) … … 350 377 DIR *d; 351 378 struct dirent *e; 352 int i;379 unsigned int i; 353 380 354 381 d = opendir(dk->path); … … 365 392 366 393 if (i == idx) { 367 if (name != NULL) 394 if (name != NULL) { 368 395 *name = talloc_strdup(mem_ctx, e->d_name); 396 W_ERROR_HAVE_NO_MEMORY(*name); 397 } 369 398 W_ERROR_NOT_OK_RETURN(reg_dir_get_value(mem_ctx, key, 370 399 *name, type, … … 381 410 382 411 383 static WERROR reg_dir_del_value (struct hive_key *key, const char *name) 412 static WERROR reg_dir_del_value(TALLOC_CTX *mem_ctx, 413 struct hive_key *key, const char *name) 384 414 { 385 415 const struct dir_key *dk = talloc_get_type(key, struct dir_key); 386 char *path = talloc_asprintf(key, "%s/%s", dk->path, name); 387 if (unlink(path) < 0) { 388 talloc_free(path); 416 char *path; 417 int ret; 418 419 path = talloc_asprintf(mem_ctx, "%s/%s", dk->path, name); 420 W_ERROR_HAVE_NO_MEMORY(path); 421 422 ret = unlink(path); 423 424 talloc_free(path); 425 426 if (ret < 0) { 389 427 if (errno == ENOENT) 390 428 return WERR_BADFILE; 391 429 return WERR_GENERAL_FAILURE; 392 430 } 393 talloc_free(path);394 431 395 432 return WERR_OK;
Note:
See TracChangeset
for help on using the changeset viewer.