From 305eb9de72a961f8bf5cbb8844e34a12cd1f523e Mon Sep 17 00:00:00 2001 From: Chris Provenzano Date: Wed, 16 Aug 1995 07:31:37 +0000 Subject: [PATCH] Pass fds to krb5_lock_file() and krb5_unlock_file() git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@6539 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/ccache/stdio/ChangeLog | 4 ++++ src/lib/krb5/ccache/stdio/scc_maybe.c | 16 ++++++++-------- src/lib/krb5/keytab/file/ChangeLog | 4 ++++ src/lib/krb5/keytab/file/ktf_util.c | 11 +++++------ src/slave/ChangeLog | 3 +++ src/slave/kprop.c | 15 ++++----------- src/slave/kpropd.c | 11 +++++------ 7 files changed, 33 insertions(+), 31 deletions(-) diff --git a/src/lib/krb5/ccache/stdio/ChangeLog b/src/lib/krb5/ccache/stdio/ChangeLog index b62956693..64544d2b6 100644 --- a/src/lib/krb5/ccache/stdio/ChangeLog +++ b/src/lib/krb5/ccache/stdio/ChangeLog @@ -1,3 +1,7 @@ +Wed Aug 16 02:45:19 1995 Chris Provenzano + + * scc_maybe.c: Pass fds to krb5_lock_file() and krb5_unlock_file() + Tue Jul 11 19:22:17 1995 Ezra Peisach * scc-proto.h: Add prototype for krb5_scc_read. diff --git a/src/lib/krb5/ccache/stdio/scc_maybe.c b/src/lib/krb5/ccache/stdio/scc_maybe.c index 3e9194ee2..f6e008ddd 100644 --- a/src/lib/krb5/ccache/stdio/scc_maybe.c +++ b/src/lib/krb5/ccache/stdio/scc_maybe.c @@ -56,12 +56,12 @@ krb5_scc_close_file (context, id) memset (data->stdio_buffer, 0, sizeof (data->stdio_buffer)); if (ret == EOF) { int errsave = errno; - (void) krb5_unlock_file(context, data->file, data->filename); + (void) krb5_unlock_file(context, fileno(data->file)); (void) fclose (data->file); data->file = 0; return krb5_scc_interpret (context, errsave); } - retval = krb5_unlock_file(context, data->file, data->filename); + retval = krb5_unlock_file(context, fileno(data->file)); ret = fclose (data->file); data->file = 0; if (retval) @@ -85,7 +85,7 @@ krb5_scc_open_file (context, id, mode) data = (krb5_scc_data *) id->data; if (data->file) { /* Don't know what state it's in; shut down and start anew. */ - (void) krb5_unlock_file(context, data->file, data->filename); + (void) krb5_unlock_file(context, fileno(data->file)); (void) fclose (data->file); data->file = 0; } @@ -127,14 +127,14 @@ krb5_scc_open_file (context, id, mode) #endif switch (mode) { case SCC_OPEN_RDONLY: - if ((retval = krb5_lock_file(context, f, data->filename, KRB5_LOCKMODE_SHARED))) { + if ((retval = krb5_lock_file(context,fileno(f),KRB5_LOCKMODE_SHARED))){ (void) fclose(f); return retval; } break; case SCC_OPEN_RDWR: case SCC_OPEN_AND_ERASE: - if ((retval = krb5_lock_file(context, f, data->filename, + if ((retval = krb5_lock_file(context, fileno(f), KRB5_LOCKMODE_EXCLUSIVE))) { (void) fclose(f); return retval; @@ -150,14 +150,14 @@ krb5_scc_open_file (context, id, mode) data->version = krb5_scc_default_format; if (!fwrite((char *)fvno_bytes, sizeof(fvno_bytes), 1, f)) { errsave = errno; - (void) krb5_unlock_file(context, f, data->filename); + (void) krb5_unlock_file(context, fileno(f)); (void) fclose(f); return krb5_scc_interpret(context, errsave); } } else { /* verify a valid version number is there */ if (!fread((char *)fvno_bytes, sizeof(fvno_bytes), 1, f)) { - (void) krb5_unlock_file(context, f, data->filename); + (void) krb5_unlock_file(context, fileno(f)); (void) fclose(f); return KRB5_CCACHE_BADVNO; } @@ -165,7 +165,7 @@ krb5_scc_open_file (context, id, mode) if ((data->version != KRB5_SCC_FVNO_1) && (data->version != KRB5_SCC_FVNO_2) && (data->version != KRB5_SCC_FVNO_3)) { - (void) krb5_unlock_file(context, f, data->filename); + (void) krb5_unlock_file(context, fileno(f)); (void) fclose(f); return KRB5_CCACHE_BADVNO; } diff --git a/src/lib/krb5/keytab/file/ChangeLog b/src/lib/krb5/keytab/file/ChangeLog index 134f97a6d..7f22f2710 100644 --- a/src/lib/krb5/keytab/file/ChangeLog +++ b/src/lib/krb5/keytab/file/ChangeLog @@ -1,3 +1,7 @@ +Wed Aug 16 02:45:19 1995 Chris Provenzano + + * ktf_util.c: Pass fds to krb5_lock_file() and krb5_unlock_file() + Tue Aug 15 01:34:57 1995 Tom Yu * ktf_util.c: return KRB5_KEYTAB_BADVNO instead of -1 diff --git a/src/lib/krb5/keytab/file/ktf_util.c b/src/lib/krb5/keytab/file/ktf_util.c index 9c2f7aa55..42009a050 100644 --- a/src/lib/krb5/keytab/file/ktf_util.c +++ b/src/lib/krb5/keytab/file/ktf_util.c @@ -122,8 +122,7 @@ int mode; } else /* some other error */ return errno; } - if ((kerror = krb5_lock_file(context, KTFILEP(id), KTFILENAME(id), - mode))) { + if ((kerror = krb5_lock_file(context, fileno(KTFILEP(id)), mode))) { (void) fclose(KTFILEP(id)); KTFILEP(id) = 0; return kerror; @@ -137,7 +136,7 @@ int mode; KTVERSION(id) = krb5_kt_default_vno; if (!xfwrite(&kt_vno, sizeof(kt_vno), 1, KTFILEP(id))) { kerror = errno; - (void) krb5_unlock_file(context, KTFILEP(id), KTFILENAME(id)); + (void) krb5_unlock_file(context, fileno(KTFILEP(id))); (void) fclose(KTFILEP(id)); return kerror; } @@ -145,14 +144,14 @@ int mode; /* gotta verify it instead... */ if (!xfread(&kt_vno, sizeof(kt_vno), 1, KTFILEP(id))) { kerror = errno; - (void) krb5_unlock_file(context, KTFILEP(id), KTFILENAME(id)); + (void) krb5_unlock_file(context, fileno(KTFILEP(id))); (void) fclose(KTFILEP(id)); return kerror; } kt_vno = KTVERSION(id) = ntohs(kt_vno); if ((kt_vno != KRB5_KT_VNO) && (kt_vno != KRB5_KT_VNO_1)) { - (void) krb5_unlock_file(context, KTFILEP(id), KTFILENAME(id)); + (void) krb5_unlock_file(context, fileno(KTFILEP(id))); (void) fclose(KTFILEP(id)); return KRB5_KEYTAB_BADVNO; } @@ -185,7 +184,7 @@ krb5_keytab id; if (!KTFILEP(id)) return 0; - kerror = krb5_unlock_file(context, KTFILEP(id), KTFILENAME(id)); + kerror = krb5_unlock_file(context, fileno(KTFILEP(id))); (void) fclose(KTFILEP(id)); KTFILEP(id) = 0; return kerror; diff --git a/src/slave/ChangeLog b/src/slave/ChangeLog index 710798539..bc8c9e79c 100644 --- a/src/slave/ChangeLog +++ b/src/slave/ChangeLog @@ -1,3 +1,6 @@ +Wed Aug 16 02:45:19 1995 Chris Provenzano + + * kprop.c, kpropd.c: Pass fds to krb5_lock_file() and krb5_unlock_file() Fri Jul 7 16:34:36 EDT 1995 Paul Park (pjpark@mit.edu) * Makefile.in - Remove all explicit library handling and LDFLAGS. diff --git a/src/slave/kprop.c b/src/slave/kprop.c index 34607e309..8a4618fdc 100644 --- a/src/slave/kprop.c +++ b/src/slave/kprop.c @@ -437,7 +437,6 @@ void kerberos_authenticate(context, auth_context, fd, me, new_creds) krb5_free_ap_rep_enc_part(context, rep_result); } -FILE * dbfp; char * dbpathname; /* * Open the Kerberos database dump file. Takes care of locking it @@ -465,13 +464,13 @@ open_database(context, data_fn, size) data_fn); exit(1); } - if ((dbfp = fopen(dbpathname, "r")) == 0) { + if ((fd = open(dbpathname, O_RDONLY)) < 0) { com_err(progname, errno, "while trying to open %s", dbpathname); exit(1); } - err = krb5_lock_file(context, dbfp, dbpathname, + err = krb5_lock_file(context, fd, KRB5_LOCKMODE_SHARED|KRB5_LOCKMODE_DONTBLOCK); if (err == EAGAIN || err == EWOULDBLOCK || errno == EACCES) { com_err(progname, 0, "database locked"); @@ -480,7 +479,6 @@ open_database(context, data_fn, size) com_err(progname, err, "while trying to lock '%s'", dbpathname); exit(1); } - fd = fileno(dbfp); if (fstat(fd, &stbuf)) { com_err(progname, errno, "while trying to stat %s", data_fn); @@ -514,15 +512,10 @@ close_database(context, fd) int fd; { int err; - if (fd != fileno(dbfp)) { - com_err(progname, 0, "bad fd passed to close_database"); - exit(1); - } - err = krb5_lock_file(context, dbfp, dbpathname, KRB5_LOCKMODE_UNLOCK); - if (err) + if (err = krb5_lock_file(context, fd, KRB5_LOCKMODE_UNLOCK)); com_err(progname, err, "while unlocking database '%s'", dbpathname); free(dbpathname); - (void) fclose(dbfp); + (void)close(fd); return; } diff --git a/src/slave/kpropd.c b/src/slave/kpropd.c index 013c47e84..73d5dd4b5 100644 --- a/src/slave/kpropd.c +++ b/src/slave/kpropd.c @@ -232,7 +232,7 @@ void doit(fd) int on = 1, fromlen; struct hostent *hp; krb5_error_code retval; - FILE *lock_fp; + int lock_fd; int omask; fromlen = sizeof (from); @@ -279,9 +279,9 @@ void doit(fd) exit(1); } omask = umask(077); - lock_fp = fopen(temp_file_name, "a"); + lock_fd = fopen(temp_file_name, O_RDONLY); (void) umask(omask); - retval = krb5_lock_file(kpropd_context, lock_fp, temp_file_name, + retval = krb5_lock_file(kpropd_context, lock_fd, KRB5_LOCKMODE_EXCLUSIVE|KRB5_LOCKMODE_DONTBLOCK); if (retval) { com_err(progname, retval, "while trying to lock '%s'", @@ -307,13 +307,12 @@ void doit(fd) exit(1); } load_database(kpropd_context, kdb5_edit, file); - retval = krb5_lock_file(kpropd_context, lock_fp, temp_file_name, - KRB5_LOCKMODE_UNLOCK); + retval = krb5_lock_file(kpropd_context, lock_fd, KRB5_LOCKMODE_UNLOCK); if (retval) { com_err(progname, retval, "while unlocking '%s'", temp_file_name); exit(1); } - (void) fclose(lock_fp); + (void)close(lock_fd); exit(0); } -- 2.26.2