From 759d9842b70ef7923f49c82cd65d7d261a2cb051 Mon Sep 17 00:00:00 2001 From: Theodore Tso Date: Fri, 13 Nov 1998 20:44:06 +0000 Subject: [PATCH] Makefile.in: Set the myfulldir and mydir variables (which are relative to buildtop and thisconfigdir, respectively.) configure.in: Remove KRB5_POSIX_LOCKS test. win_store.c (krb__get_srvtabname): g_cnffile.c: Use krb5__krb4_context instead of init'ing and free'ing a krb5_context each time we need to read data from the configuration file. We also define krb5__krb4_context in g_cnnfile.c, since it's a likely that any use of the krb4 library will pull in that file. tf_util.c (tf_init): Use krb5_lock_file instead of trying to roll our own flock emulation. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@11026 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb4/Makefile.in | 2 ++ src/lib/krb4/configure.in | 1 - src/lib/krb4/g_cnffile.c | 23 +++++++------- src/lib/krb4/tf_util.c | 66 ++++++++++++++------------------------- src/lib/krb4/win_store.c | 11 ++++--- 5 files changed, 45 insertions(+), 58 deletions(-) diff --git a/src/lib/krb4/Makefile.in b/src/lib/krb4/Makefile.in index af2dca43c..f3be7d1eb 100644 --- a/src/lib/krb4/Makefile.in +++ b/src/lib/krb4/Makefile.in @@ -1,4 +1,6 @@ thisconfigdir=. +myfulldir=lib/krb4 +mydir=. BUILDTOP=$(REL)$(U)$(S)$(U) CFLAGS = $(CCOPTS) $(DEFS) $(DEFINES) DEFINES=-I$(srcdir)/../../include/kerberosIV diff --git a/src/lib/krb4/configure.in b/src/lib/krb4/configure.in index b79215db9..0434c7d0e 100644 --- a/src/lib/krb4/configure.in +++ b/src/lib/krb4/configure.in @@ -5,7 +5,6 @@ AC_PROG_ARCHIVE_ADD AC_PROG_RANLIB AC_PROG_INSTALL AC_CONST -KRB5_POSIX_LOCKS AC_CHECK_HEADERS(sys/select.h time.h unistd.h) dnl Could check for full stdc environment, but will only test dnl for stdlib.h diff --git a/src/lib/krb4/g_cnffile.c b/src/lib/krb4/g_cnffile.c index 569789f89..c50cd50e4 100644 --- a/src/lib/krb4/g_cnffile.c +++ b/src/lib/krb4/g_cnffile.c @@ -19,29 +19,31 @@ #include "krb.h" #include "k5-int.h" +krb5_context krb5__krb4_context = 0; + static FILE* krb__v5_get_file(s) char *s; { FILE *cnffile = 0; - krb5_context context; const char* names[3]; char **full_name = 0, **cpp; krb5_error_code retval; - krb5_init_context(&context); + if (!krb5__krb4_context) + krb5_init_context(&krb5__krb4_context); names[0] = "libdefaults"; names[1] = s; names[2] = 0; - if (context) { - retval = profile_get_values(context->profile, names, &full_name); + if (krb5__krb4_context) { + retval = profile_get_values(krb5__krb4_context->profile, names, + &full_name); if (retval == 0 && full_name && full_name[0]) { cnffile = fopen(full_name[0],"r"); for (cpp = full_name; *cpp; cpp++) krb5_xfree(*cpp); krb5_xfree(full_name); } - krb5_free_context(context); } return cnffile; } @@ -50,18 +52,19 @@ char * krb__get_srvtabname(default_srvtabname) char *default_srvtabname; { - krb5_context context; const char* names[3]; char **full_name = 0, **cpp; krb5_error_code retval; char *retname; - krb5_init_context(&context); + if (!krb5__krb4_context) + krb5_init_context(&krb5__krb4_context); names[0] = "libdefaults"; names[1] = "krb4_srvtab"; names[2] = 0; - if (context && - (retval = profile_get_values(context->profile, names, &full_name)) + if (krb5__krb4_context && + (retval = profile_get_values(krb5__krb4_context->profile, names, + &full_name)) && retval == 0 && full_name && full_name[0]) { retname = strdup(full_name[0]); for (cpp = full_name; *cpp; cpp++) @@ -70,8 +73,6 @@ krb__get_srvtabname(default_srvtabname) }else { retname = strdup(default_srvtabname); } - if (context != NULL) - krb5_free_context(context); return retname; } diff --git a/src/lib/krb4/tf_util.c b/src/lib/krb4/tf_util.c index 1c7aadd9f..ebf500bf2 100644 --- a/src/lib/krb4/tf_util.c +++ b/src/lib/krb4/tf_util.c @@ -10,6 +10,7 @@ #include "mit-copyright.h" #include "krb.h" +#include "k5-int.h" #include #include @@ -30,6 +31,8 @@ extern int errno; extern int krb_debug; +void tf_close(); + #ifdef TKT_SHMEM char *krb_shm_addr; static char *tmp_shm_addr; @@ -58,42 +61,6 @@ int utimes(path, times) return utime(path,&tv); } #endif -#ifndef LOCK_SH -#define LOCK_SH 1 /* shared lock */ -#define LOCK_EX 2 /* exclusive lock */ -#define LOCK_NB 4 /* don't block when locking */ -#define LOCK_UN 8 /* unlock */ -#endif - - -#ifdef POSIX_FILE_LOCKS - -/* - * This function emulates a subset of flock() - */ -int emul_flock(fd, cmd) - int fd, cmd; -{ - static struct flock flock_zero; - struct flock f; - - f = flock_zero; - - memset(&f, 0, sizeof (f)); - - if (cmd & LOCK_UN) - f.l_type = F_UNLCK; - if (cmd & LOCK_SH) - f.l_type = F_RDLCK; - if (cmd & LOCK_EX) - f.l_type = F_WRLCK; - - return fcntl(fd, (cmd & LOCK_NB) ? F_SETLK : F_SETLKW, &f); -} - -#define flock(f,c) emul_flock(f,c) -#endif - /* * fd must be initialized to something that won't ever occur as a real @@ -190,6 +157,11 @@ int tf_init(tf_name, rw) int shmid; #endif + if (!krb5__krb4_context) { + if (krb5_init_context(&krb5__krb4_context)) + return TKT_FIL_LCK; + } + me = getuid(); switch (rw) { @@ -335,9 +307,13 @@ int tf_init(tf_name, rw) fd = -1; return TKT_FIL_ACC; } - if (flock(fd, LOCK_EX | LOCK_NB) < 0) { + if (krb5_lock_file(krb5__krb4_context, fd, + KRB5_LOCKMODE_EXCLUSIVE | + KRB5_LOCKMODE_DONTBLOCK) < 0) { sleep(TF_LCK_RETRY); - if (flock(fd, LOCK_EX | LOCK_NB) < 0) { + if (krb5_lock_file(krb5__krb4_context, fd, + KRB5_LOCKMODE_EXCLUSIVE | + KRB5_LOCKMODE_DONTBLOCK) < 0) { (void) close(fd); fd = -1; return TKT_FIL_LCK; @@ -386,9 +362,13 @@ int tf_init(tf_name, rw) fd = -1; return TKT_FIL_ACC; } - if (flock(fd, LOCK_SH | LOCK_NB) < 0) { + if (krb5_lock_file(krb5__krb4_context, fd, + KRB5_LOCKMODE_SHARED | + KRB5_LOCKMODE_DONTBLOCK) < 0) { sleep(TF_LCK_RETRY); - if (flock(fd, LOCK_SH | LOCK_NB) < 0) { + if (krb5_lock_file(krb5__krb4_context, fd, + KRB5_LOCKMODE_SHARED | + KRB5_LOCKMODE_DONTBLOCK) < 0) { (void) close(fd); fd = -1; return TKT_FIL_LCK; @@ -520,7 +500,7 @@ int tf_get_cred(c) * The return value is not defined. */ -tf_close() +void tf_close() { if (!(fd < 0)) { #ifdef TKT_SHMEM @@ -532,7 +512,9 @@ tf_close() krb_shm_addr = 0; } #endif /* TKT_SHMEM */ - (void) flock(fd, LOCK_UN); + if (!krb5__krb4_context) + krb5_init_context(&krb5__krb4_context); + (void) krb5_lock_file(krb5__krb4_context, fd, KRB5_LOCKMODE_UNLOCK); (void) close(fd); fd = -1; /* see declaration of fd above */ } diff --git a/src/lib/krb4/win_store.c b/src/lib/krb4/win_store.c index 706205fe5..46fe51692 100644 --- a/src/lib/krb4/win_store.c +++ b/src/lib/krb4/win_store.c @@ -19,17 +19,21 @@ char * krb__get_srvtabname(default_srvtabname) char *default_srvtabname; { - krb5_context context; const char* names[3]; char **full_name = 0, **cpp; krb5_error_code retval; char *retname; - krb5_init_context(&context); + if (!krb5__krb4_context) { + retval = krb5_init_context(&krb5__krb4_context); + if (!retval) + return NULL; + } names[0] = "libdefaults"; names[1] = "krb4_srvtab"; names[2] = 0; - retval = profile_get_values(context->profile, names, &full_name); + retval = profile_get_values(krb5__krb4_context->profile, names, + &full_name); if (retval == 0 && full_name && full_name[0]) { retname = strdup(full_name[0]); for (cpp = full_name; *cpp; cpp++) @@ -38,7 +42,6 @@ krb__get_srvtabname(default_srvtabname) } else { retname = strdup(default_srvtabname); } - krb5_free_context(context); return retname; } -- 2.26.2