--- asterisk-1.2.10/apps/app_voicemail.c 2006-07-13 23:22:11.000000000 +0200 +++ asterisk-1.2.10-mod/apps/app_voicemail.c 2006-08-01 08:32:48.497779280 +0200 @@ -814,15 +814,37 @@ return 1; } +/* Check if a given path exists or not. Return + negativ value if it does not +*/ +static int check_path_exist(const char *path) +{ + char *fs; + int fd; + + fs = alloca(strlen(path) + 20); + fd = open(fs, O_WRONLY | O_EXCL | O_DIRECTORY, 0600); + if ( ( fd < 0 ) && ( ( errno == 2 ) || ( errno == 20 ) ) ) { + return -1; + } else { + return 0; + } + close(fd); +} + /* only return failure if ast_lock_path returns 'timeout', not if the path does not exist or any other reason */ static int vm_lock_path(const char *path) { - switch (ast_lock_path(path)) { - case AST_LOCK_TIMEOUT: - return -1; - default: + if (check_path_exist(path) == 0) { + switch (ast_lock_path(path)) { + case AST_LOCK_TIMEOUT: + return -1; + default: + return 0; + } + } else { return 0; } } @@ -1388,7 +1410,9 @@ } closedir(vmdir); } - ast_unlock_path(dir); + if (check_path_exist(dir) == 0) { + ast_unlock_path(dir); + } return vmcount; } @@ -1478,7 +1502,9 @@ if (ast_fileexists(fn, NULL, NULL) < 1) break; } - ast_unlock_path(dir); + if (check_path_exist(dir) == 0) { + ast_unlock_path(dir); + } return x - 1; } @@ -2332,7 +2358,9 @@ } else { ast_log(LOG_ERROR, "Recipient mailbox %s@%s is full\n", recip->mailbox, recip->context); } - ast_unlock_path(todir); + if (check_path_exist(todir) == 0) { + ast_unlock_path(todir); + } notify_new_message(chan, recip, recipmsgnum, duration, fmt, chan->cid.cid_num, chan->cid.cid_name); return 0; @@ -2618,7 +2646,9 @@ if (option_debug) ast_log(LOG_DEBUG, "The recorded media file is gone, so we should remove the .txt file too!\n"); unlink(tmptxtfile); - ast_unlock_path(dir); + if (check_path_exist(dir) == 0) { + ast_unlock_path(dir); + } } else { for (;;) { make_file(fn, sizeof(fn), dir, msgnum); @@ -2634,7 +2664,9 @@ ast_filerename(tmptxtfile, fn, NULL); rename(tmptxtfile, txtfile); - ast_unlock_path(dir); + if (check_path_exist(dir) == 0) { + ast_unlock_path(dir); + } /* Are there to be more recipients of this message? */ while (tmpptr) { @@ -2702,7 +2734,9 @@ dest++; } } - ast_unlock_path(dir); + if (check_path_exist(dir) == 0) { + ast_unlock_path(dir); + } return 0; } @@ -2734,13 +2768,18 @@ break; } if (x >= vmu->maxmsg) { - ast_unlock_path(ddir); + if (check_path_exist(ddir) == 0) { + ast_unlock_path(ddir); + } return -1; } if (strcmp(sfn, dfn)) { COPY(dir, msg, ddir, x, username, context, sfn, dfn); } - ast_unlock_path(ddir); + if (check_path_exist(ddir) == 0) { + ast_log(LOG_ERROR,"Checking Path in Line 2788\n"); + ast_unlock_path(ddir); + } return 0; } @@ -3952,7 +3991,9 @@ if (EXISTS(vms->curdir, x, vms->fn, NULL)) DELETE(vms->curdir, x, vms->fn); } - ast_unlock_path(vms->curdir); + if (check_path_exist(vms->curdir) == 0) { + ast_unlock_path(vms->curdir); + } done: if (vms->deleted)