Makefile.in: Set the myfulldir and mydir variables (which are relative
authorTheodore Tso <tytso@mit.edu>
Fri, 13 Nov 1998 20:44:06 +0000 (20:44 +0000)
committerTheodore Tso <tytso@mit.edu>
Fri, 13 Nov 1998 20:44:06 +0000 (20:44 +0000)
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
src/lib/krb4/configure.in
src/lib/krb4/g_cnffile.c
src/lib/krb4/tf_util.c
src/lib/krb4/win_store.c

index af2dca43c52d860e78b30db63bb26d5896d07094..f3be7d1eb724e971fe72f344e1b52ff19c0dc486 100644 (file)
@@ -1,4 +1,6 @@
 thisconfigdir=.
+myfulldir=lib/krb4
+mydir=.
 BUILDTOP=$(REL)$(U)$(S)$(U)
 CFLAGS = $(CCOPTS) $(DEFS) $(DEFINES)
 DEFINES=-I$(srcdir)/../../include/kerberosIV
index b79215db9c9d4cc58ba2c5245b8a65078a1debb1..0434c7d0e034e2d6ab480a425a29e5bb2b37ac61 100644 (file)
@@ -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
index 569789f8949167e3d11127402025d0bf0f6f3f2b..c50cd50e45cdbbc1617fd2d32ba8379795268d89 100644 (file)
 #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;
 }
 
index 1c7aadd9fa12c3598a6adc5b92665589a7e707d8..ebf500bf2955b0d540624c798d75b151abaa98e6 100644 (file)
@@ -10,6 +10,7 @@
 #include "mit-copyright.h"
 
 #include "krb.h"
+#include "k5-int.h"
 
 #include <stdio.h>
 #include <string.h>
@@ -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 */
     }
index 706205fe5cad29c080f96ed21d5fcf7738386842..46fe516929a4074a33c7cdf5e0b8dc9ee5e45b53 100644 (file)
@@ -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;
 }