diff options
Diffstat (limited to 'contrib/sendmail/libsmdb/smndbm.c')
-rw-r--r-- | contrib/sendmail/libsmdb/smndbm.c | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/contrib/sendmail/libsmdb/smndbm.c b/contrib/sendmail/libsmdb/smndbm.c index 421b4bc..949f09b 100644 --- a/contrib/sendmail/libsmdb/smndbm.c +++ b/contrib/sendmail/libsmdb/smndbm.c @@ -1,5 +1,5 @@ /* -** Copyright (c) 1999-2001 Sendmail, Inc. and its suppliers. +** Copyright (c) 1999-2002 Sendmail, Inc. and its suppliers. ** All rights reserved. ** ** By using this file, you agree to the terms and conditions set @@ -8,7 +8,7 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: smndbm.c,v 8.50 2001/09/11 04:04:53 gshapiro Exp $") +SM_RCSID("@(#)$Id: smndbm.c,v 8.51 2002/01/21 04:10:44 gshapiro Exp $") #include <fcntl.h> #include <stdlib.h> @@ -492,6 +492,7 @@ smdb_ndbm_open(database, db_name, mode, mode_mask, sff, type, user_info, SMDB_USER_INFO *user_info; SMDB_DBPARAMS *db_params; { + bool lockcreated = false; int result; int lock_fd; SMDB_DATABASE *smdb_db; @@ -516,15 +517,34 @@ smdb_ndbm_open(database, db_name, mode, mode_mask, sff, type, user_info, if (result != SMDBE_OK) return result; + if ((dir_stat_info.st_mode == ST_MODE_NOFILE || + pag_stat_info.st_mode == ST_MODE_NOFILE) && + bitset(mode, O_CREAT)) + lockcreated = true; + lock_fd = -1; -# if O_EXLOCK - mode |= O_EXLOCK; -# else /* O_EXLOCK */ result = smdb_lock_file(&lock_fd, db_name, mode, sff, SMNDB_DIR_FILE_EXTENSION); if (result != SMDBE_OK) return result; -# endif /* O_EXLOCK */ + + if (lockcreated) + { + int pag_fd; + + /* Need to pre-open the .pag file as well with O_EXCL */ + result = smdb_lock_file(&pag_fd, db_name, mode, sff, + SMNDB_PAG_FILE_EXTENSION); + if (result != SMDBE_OK) + { + (void) close(lock_fd); + return result; + } + (void) close(pag_fd); + + mode |= O_TRUNC; + mode &= ~(O_CREAT|O_EXCL); + } smdb_db = smdb_malloc_database(); if (smdb_db == NULL) |