(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-storage/index/maildir/maildir-sync.c) |
| |
| 358 | | | static int maildir_scan_dir(struct maildir_sync_context *ctx, bool new_dir) |
| 359 | | | { |
| 360 | | | struct mail_storage *storage = &ctx->mbox->storage->storage; |
| 361 | | | const char *path; |
| 362 | | | DIR *dirp; |
| 363 | | | string_t *src, *dest; |
| 364 | | | struct dirent *dp; |
| 365 | | | struct stat st; |
| 366 | | | enum maildir_uidlist_rec_flag flags; |
| 367 | | | unsigned int i = 0, move_count = 0; |
| 368 | | | time_t now; |
| 369 | | | int ret = 1; |
| 370 | | | bool move_new, check_touch, dir_changed = FALSE; |
| 371 | | | |
| 372 | | | path = new_dir ? ctx->new_dir : ctx->cur_dir; |
| 373 | | | for (i = 0;; i++) { |
Useless Assignment
This code assigns the variable the same value it already had. |
|
| 374 | | | dirp = opendir(path); |
| 375 | | | if (dirp != NULL) |
| 376 | | | break; |
| 377 | | | |
| 378 | | | if (errno != ENOENT || i == MAILDIR_DELETE_RETRY_COUNT) {
x /usr/include/asm-generic/errno-base.h |
| |
5 | #define ENOENT 2 /* No such file or directory */ |
| |
|
| 379 | | | if (errno == EACCES) {
x /usr/include/asm-generic/errno-base.h |
| |
16 | #define EACCES 13 /* Permission denied */ |
| |
|
| 380 | | | mail_storage_set_critical(storage, "%s", |
| 381 | | | eacces_error_get("opendir", path)); |
| 382 | | | } else { |
| 383 | | | mail_storage_set_critical(storage, |
| 384 | | | "opendir(%s) failed: %m", path); |
| 385 | | | } |
| 386 | | | return -1; |
| 387 | | | } |
| 388 | | | |
| 389 | | | if (!maildir_set_deleted(ctx->mbox)) |
| 390 | | | return -1; |
| 391 | | | |
| 392 | | | } |
| 393 | | | |
| 394 | | | #ifdef HAVE_DIRFD |
| 395 | | | if (fstat(dirfd(dirp), &st) < 0) { |
| 396 | | | mail_storage_set_critical(storage, |
| 397 | | | "fstat(%s) failed: %m", path); |
| 398 | | | (void)closedir(dirp); |
| 399 | | | return -1; |
| 400 | | | } |
| 401 | | | #else |
| 402 | | | if (maildir_stat(ctx->mbox, path, &st) < 0) { |
| 403 | | | (void)closedir(dirp); |
| 404 | | | return -1; |
| 405 | | | } |
| 406 | | | #endif |
| 407 | | | |
| 408 | | | now = time(NULL); |
| 409 | | | if (new_dir) { |
| 410 | | | ctx->mbox->maildir_hdr.new_check_time = now; |
| 411 | | | ctx->mbox->maildir_hdr.new_mtime = st.st_mtime;
x /usr/include/bits/stat.h |
| |
95 | # define st_mtime st_mtim.tv_sec |
| |
|
| 412 | | | ctx->mbox->maildir_hdr.new_mtime_nsecs = ST_MTIME_NSEC(st);
x /home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/compat.h |
| |
69 | # define ST_MTIME_NSEC(st) ((unsigned long)(st).st_mtim.tv_nsec) |
| |
|
| 413 | | | } else { |
| 414 | | | ctx->mbox->maildir_hdr.cur_check_time = now; |
| 415 | | | ctx->mbox->maildir_hdr.cur_mtime = st.st_mtime;
x /usr/include/bits/stat.h |
| |
95 | # define st_mtime st_mtim.tv_sec |
| |
|
| 416 | | | ctx->mbox->maildir_hdr.cur_mtime_nsecs = ST_MTIME_NSEC(st);
x /home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/compat.h |
| |
69 | # define ST_MTIME_NSEC(st) ((unsigned long)(st).st_mtim.tv_nsec) |
| |
|
| 417 | | | } |
| 418 | | | |
| 419 | | | src = t_str_new(1024); |
| 420 | | | dest = t_str_new(1024); |
| 421 | | | |
| 422 | | | move_new = new_dir && !mailbox_is_readonly(&ctx->mbox->ibox.box) && |
| 423 | | | !ctx->mbox->ibox.keep_recent && ctx->locked; |
| 424 | | | |
| 425 | | | errno = 0; |
| 426 | | | for (; (dp = readdir(dirp)) != NULL; errno = 0) { |
| 427 | | | if (dp->d_name[0] == '.') |
| 428 | | | continue; |
| 429 | | | |
| 430 | | | check_touch = FALSE; |
| 431 | | | flags = 0; |
| 432 | | | if (move_new) { |
| 433 | | | str_truncate(src, 0); |
| 434 | | | str_truncate(dest, 0); |
| 435 | | | str_printfa(src, "%s/%s", ctx->new_dir, dp->d_name); |
| 436 | | | str_printfa(dest, "%s/%s", ctx->cur_dir, dp->d_name); |
| 437 | | | if (strchr(dp->d_name, MAILDIR_INFO_SEP) == NULL) { |
| 438 | | | str_append(dest, MAILDIR_FLAGS_FULL_SEP); |
| 439 | | | } |
| 440 | | | if (rename(str_c(src), str_c(dest)) == 0) { |
| 441 | | | |
| 442 | | | dir_changed = TRUE; |
| 443 | | | move_count++; |
| 444 | | | flags |= MAILDIR_UIDLIST_REC_FLAG_MOVED | |
| 445 | | | MAILDIR_UIDLIST_REC_FLAG_RECENT; |
| 446 | | | } else if (ENOTFOUND(errno)) {
x /home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/compat.h |
| |
246 | #define ENOTFOUND(errno) \ |
247 | ((errno) == ENOENT || (errno) == ENOTDIR || (errno) == ELOOP) |
| |
x /usr/include/asm-generic/errno-base.h |
| |
5 | #define ENOENT 2 /* No such file or directory */ |
| |
x /usr/include/asm-generic/errno-base.h |
| |
23 | #define ENOTDIR 20 /* Not a directory */ |
| |
x /usr/include/asm-generic/errno.h |
| |
11 | #define ELOOP 40 /* Too many symbolic links encountered */ |
| |
|
| 447 | | | |
| 448 | | | dir_changed = TRUE; |
| 449 | | | move_count++; |
| 450 | | | flags |= MAILDIR_UIDLIST_REC_FLAG_MOVED | |
| 451 | | | MAILDIR_UIDLIST_REC_FLAG_RECENT; |
| 452 | | | } else if (ENOSPACE(errno) || errno == EACCES) {
x /home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/compat.h |
| |
233 | # define ENOSPACE(errno) ((errno) == ENOSPC || (errno) == EDQUOT) |
| |
x /usr/include/asm-generic/errno-base.h |
| |
31 | #define ENOSPC 28 /* No space left on device */ |
| |
x /usr/include/asm-generic/errno.h |
| |
95 | #define EDQUOT 122 /* Quota exceeded */ |
| |
x /usr/include/asm-generic/errno-base.h |
| |
16 | #define EACCES 13 /* Permission denied */ |
| |
|
| 453 | | | |
| 454 | | | |
| 455 | | | flags |= MAILDIR_UIDLIST_REC_FLAG_NEW_DIR; |
| 456 | | | move_new = FALSE; |
| 457 | | | } else { |
| 458 | | | flags |= MAILDIR_UIDLIST_REC_FLAG_NEW_DIR; |
| 459 | | | mail_storage_set_critical(storage, |
| 460 | | | "rename(%s, %s) failed: %m", |
| 461 | | | str_c(src), str_c(dest)); |
| 462 | | | } |
| 463 | | | if ((move_count % MAILDIR_SLOW_MOVE_COUNT) == 0) |
| 464 | | | maildir_sync_notify(ctx); |
| 465 | | | } else if (new_dir) { |
| 466 | | | flags |= MAILDIR_UIDLIST_REC_FLAG_NEW_DIR | |
| 467 | | | MAILDIR_UIDLIST_REC_FLAG_RECENT; |
| 468 | | | } |
| 469 | | | |
| 470 | | | i++; |
| 471 | | | if ((i % MAILDIR_SLOW_CHECK_COUNT) == 0) |
| 472 | | | maildir_sync_notify(ctx); |
| 473 | | | |
| 474 | | | ret = maildir_uidlist_sync_next(ctx->uidlist_sync_ctx, |
| 475 | | | dp->d_name, flags); |
| 476 | | | if (ret <= 0) { |
| 477 | | | if (ret < 0) |
| 478 | | | break; |
| 479 | | | |
| 480 | | | |
| 481 | | | T_BEGIN {
x /home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/data-stack.h |
| |
49 | #define T_BEGIN \ |
50 | STMT_START { unsigned int _data_stack_cur_id = t_push(); |
| |
|
| 482 | | | ret = maildir_fix_duplicate(ctx, path, |
| 483 | | | dp->d_name); |
| 484 | | | } T_END; |
| 485 | | | if (ret < 0) |
| 486 | | | break; |
| 487 | | | } |
| 488 | | | } |
| 489 | | | |
| 490 | | | if (errno != 0) { |
| 491 | | | mail_storage_set_critical(storage, |
| 492 | | | "readdir(%s) failed: %m", path); |
| 493 | | | ret = -1; |
| 494 | | | } |
| 495 | | | |
| 496 | | | if (closedir(dirp) < 0) { |
| 497 | | | mail_storage_set_critical(storage, |
| 498 | | | "closedir(%s) failed: %m", path); |
| 499 | | | ret = -1; |
| 500 | | | } |
| 501 | | | |
| 502 | | | if (dir_changed) { |
| 503 | | | |
| 504 | | | |
| 505 | | | |
| 506 | | | if (stat(ctx->new_dir, &st) == 0) { |
| 507 | | | ctx->mbox->maildir_hdr.new_check_time = |
| 508 | | | I_MAX(st.st_mtime, now);
x /usr/include/bits/stat.h |
| |
95 | # define st_mtime st_mtim.tv_sec |
| |
|
| 509 | | | ctx->mbox->maildir_hdr.new_mtime = st.st_mtime;
x /usr/include/bits/stat.h |
| |
95 | # define st_mtime st_mtim.tv_sec |
| |
|
| 510 | | | ctx->mbox->maildir_hdr.new_mtime_nsecs = |
| 511 | | | ST_MTIME_NSEC(st);
x /home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/compat.h |
| |
69 | # define ST_MTIME_NSEC(st) ((unsigned long)(st).st_mtim.tv_nsec) |
| |
|
| 512 | | | } |
| 513 | | | if (stat(ctx->cur_dir, &st) == 0) { |
| 514 | | | ctx->mbox->maildir_hdr.new_check_time = |
| 515 | | | I_MAX(st.st_mtime, now);
x /usr/include/bits/stat.h |
| |
95 | # define st_mtime st_mtim.tv_sec |
| |
|
| 516 | | | ctx->mbox->maildir_hdr.cur_mtime = st.st_mtime;
x /usr/include/bits/stat.h |
| |
95 | # define st_mtime st_mtim.tv_sec |
| |
|
| 517 | | | ctx->mbox->maildir_hdr.cur_mtime_nsecs = |
| 518 | | | ST_MTIME_NSEC(st);
x /home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/compat.h |
| |
69 | # define ST_MTIME_NSEC(st) ((unsigned long)(st).st_mtim.tv_nsec) |
| |
|
| 519 | | | } |
| 520 | | | } |
| 521 | | | |
| 522 | | | return ret < 0 ? -1 : |
| 523 | | | (move_count <= MAILDIR_RENAME_RESCAN_COUNT ? 0 : 1); |
| 524 | | | } |
| |