From: John Kohl Date: Fri, 14 Jun 1991 15:21:49 +0000 (+0000) Subject: with POSIX locks, we gotta have the file open for write if we want to flock X-Git-Tag: krb5-1.0-beta2~282 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=64e6971128064ee52aba26221da499facf591626;p=krb5.git with POSIX locks, we gotta have the file open for write if we want to flock git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@2180 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/kdb/kdb_dbm.c b/src/lib/kdb/kdb_dbm.c index 8991d0a39..640b6016d 100644 --- a/src/lib/kdb/kdb_dbm.c +++ b/src/lib/kdb/kdb_dbm.c @@ -179,9 +179,21 @@ krb5_dbm_db_init() char *filename = gen_dbsuffix (current_db_name, ".ok"); if (!filename) return ENOMEM; - if ((dblfd = open(filename, 0, 0)) < 0) { +#ifdef POSIX_FILE_LOCKS + /* needs be open read/write so that write locking can work with + POSIX systems */ + if ((dblfd = open(filename, O_RDWR, 0)) == -1) { + if (errno == EACCES) { + if ((dblfd = open(filename, O_RDONLY, 0)) == -1) + return errno; + } else + return errno; + } +#else + if ((dblfd = open(filename, 0, 0)) == -1) { return errno; } +#endif free(filename); inited++; } @@ -601,8 +613,14 @@ int mode; fl.l_whence = 0; fl.l_start = 0; fl.l_len = 0; - if (fcntl(dblfd, non_blocking ? F_SETLK : F_SETLKW, &fl) == -1) + if (fcntl(dblfd, non_blocking ? F_SETLK : F_SETLKW, &fl) == -1) { + if (errno == EBADF && mode == KRB5_DBM_EXCLUSIVE) { + /* tried to exclusive-lock something we don't have write access + to. */ + return KRB5_KDB_CANTLOCK_DB; + } return errno; + } #else switch (mode) { case KRB5_DBM_EXCLUSIVE: