[502] in Kerberos-V5-bugs

home help back first fref pref prev next nref lref last post

more prebeta4 bugs/comments

daemon@ATHENA.MIT.EDU (John T Kohl)
Thu Jun 16 01:08:59 1994

Date: Thu, 16 Jun 1994 00:37:11 -0400
From: John T Kohl <jtk@kolvir.blrc.ma.us>
To: krb5-bugs@MIT.EDU

-----BEGIN PGP SIGNED MESSAGE-----

(a) Is the function tell() something in the C standard?  I don't have it
on my system:

fcc_nseq.c:101: Undefined symbol _tell referenced from text segment
fcc_sseq.c:73: Undefined symbol _tell referenced from text segment

You should use lseek(fd, 0, SEEK_CUR):
===================================================================
RCS file: fcc_nseq.c,v
retrieving revision 1.1
diff -c -r1.1 fcc_nseq.c
*** 1.1	1994/06/16 04:30:23
- --- fcc_nseq.c	1994/06/16 04:31:37
***************
*** 98,104 ****
       kret = krb5_fcc_read_data(id, &creds->second_ticket);
       TCHECK(kret);
       
!      fcursor->pos = tell(((krb5_fcc_data *) id->data)->fd);
       cursor = (krb5_cc_cursor *) fcursor;
  
  lose:
- --- 98,104 ----
       kret = krb5_fcc_read_data(id, &creds->second_ticket);
       TCHECK(kret);
       
!      fcursor->pos = lseek(((krb5_fcc_data *) id->data)->fd, 0, SEEK_CUR);
       cursor = (krb5_cc_cursor *) fcursor;
  
  lose:
===================================================================
RCS file: fcc_sseq.c,v
retrieving revision 1.1
diff -c -r1.1 fcc_sseq.c
*** 1.1	1994/06/16 04:30:33
- --- fcc_sseq.c	1994/06/16 04:31:30
***************
*** 70,76 ****
       /* Make sure we start reading right after the primary principal */
  
       krb5_fcc_skip_principal(id);
!      fcursor->pos = tell(((krb5_fcc_data *) id->data)->fd);
       *cursor = (krb5_cc_cursor) fcursor;
  
       MAYBE_CLOSE(id, ret);
- --- 70,76 ----
       /* Make sure we start reading right after the primary principal */
  
       krb5_fcc_skip_principal(id);
!      fcursor->pos = lseek(((krb5_fcc_data *) id->data)->fd, 0, SEEK_CUR);
       *cursor = (krb5_cc_cursor) fcursor;
  
       MAYBE_CLOSE(id, ret);

(b) I sent in a bad patch yesterday for kprop.c.  "krb5_file_lock"
should be "krb5_lock_file".  Here's a replacement:

===================================================================
RCS file: kprop.c,v
retrieving revision 1.1
diff -c -r1.1 kprop.c
*** 1.1	1994/06/15 02:45:11
- --- kprop.c	1994/06/16 04:24:43
***************
*** 36,46 ****
  #include <krb5/kdb_dbm.h>
  #include <krb5/ext-proto.h>
  #include <krb5/los-proto.h>
  #include <com_err.h>
  #include <errno.h>
- - #ifdef POSIX_FILE_LOCKS
- - #include <fcntl.h>
- - #endif
  
  #include <stdio.h>
  #include <ctype.h>
- --- 36,44 ----
  #include <krb5/kdb_dbm.h>
  #include <krb5/ext-proto.h>
  #include <krb5/los-proto.h>
+ #include <krb5/libos.h>
  #include <com_err.h>
  #include <errno.h>
  
  #include <stdio.h>
  #include <ctype.h>
***************
*** 77,89 ****
  
  void	PRS();
  void	get_tickets();
! void	usage();
! krb5_error_code open_connection();
! void	kerberos_authenticate();
! int	open_database();
! void	xmit_database();
! void	send_error();
! void	update_last_prop_file();
  
  static void usage()
  {
- --- 75,88 ----
  
  void	PRS();
  void	get_tickets();
! void	usage NPROTOTYPE((void));
! krb5_error_code open_connection NPROTOTYPE((char *, int *, char *));
! void	kerberos_authenticate NPROTOTYPE((int, krb5_principal));
! int	open_database NPROTOTYPE((char *, int *));
! void	close_database NPROTOTYPE((int));
! void	xmit_database NPROTOTYPE((int, int, int));
! void	send_error NPROTOTYPE((int, char *, krb5_error_code));
! void	update_last_prop_file NPROTOTYPE((char *, char *));
  
  static void usage()
  {
***************
*** 123,128 ****
- --- 122,128 ----
  	xmit_database(fd, database_fd, database_size);
  	update_last_prop_file(slave_host, file);
  	printf("Database propagation to %s: SUCCEEDED\n", slave_host);
+ 	close_database(database_fd);
  	exit(0);
  }
  
***************
*** 395,400 ****
- --- 395,402 ----
  	krb5_free_ap_rep_enc_part(rep_result);
  }
  
+ FILE * dbfp;
+ char * dbpathname;
  /*
   * Open the Kerberos database dump file.  Takes care of locking it
   * and making sure that the .ok file is more recent that the database
***************
*** 409,449 ****
  	int	*size;
  {
  	int		fd;
  	struct stat 	stbuf, stbuf_ok;
  	char		*data_ok_fn;
  	static char ok[] = ".dump_ok";
- - #ifdef POSIX_FILE_LOCKS
- - 	struct flock lock_arg;
- - #endif
  
! 	if ((fd = open(data_fn, O_RDONLY)) < 0) {
  		com_err(progname, errno, "while trying to open %s",
! 			data_fn);
  		exit(1);
  	}
  	
! #ifdef POSIX_FILE_LOCKS
! 	lock_arg.l_whence = 0;
! 	lock_arg.l_start = 0;
! 	lock_arg.l_len = 0;
! 	if (fcntl(fd, F_SETLK, &lock_arg) == -1) {
! 		if (errno == EACCES || errno == EAGAIN)
! 			com_err(progname, 0, "database locked");
! 		else
! 			com_err(progname, errno, "while trying to flock %s",
! 				data_fn);
! 		exit(1);
! 	}
! #else
! 	if (flock(fd, LOCK_SH | LOCK_NB) < 0) {
! 		if (errno == EWOULDBLOCK || errno == EAGAIN)
! 			com_err(progname, 0, "database locked");
! 		else
! 			com_err(progname, errno, "while trying to flock %s",
! 				data_fn);
! 		exit(1);
! 	}
! #endif
  	if (fstat(fd, &stbuf)) {
  		com_err(progname, errno, "while trying to stat %s",
  			data_fn);
- --- 411,443 ----
  	int	*size;
  {
  	int		fd;
+ 	int		err;
  	struct stat 	stbuf, stbuf_ok;
  	char		*data_ok_fn;
  	static char ok[] = ".dump_ok";
  
! 	dbpathname = strdup(data_fn);
! 	if (!dbpathname) {
! 	    com_err(progname, ENOMEM, "allocating database file name '%s'",
! 		    data_fn);
! 	    exit(1);
! 	}
! 	if ((dbfp = fopen(dbpathname, "r")) == 0) {
  		com_err(progname, errno, "while trying to open %s",
! 			dbpathname);
  		exit(1);
  	}
  	
! 	err = krb5_lock_file(dbfp, dbpathname,
! 			     KRB5_LOCKMODE_SHARED|KRB5_LOCKMODE_DONTBLOCK);
! 	if (err == EAGAIN || err == EWOULDBLOCK || errno == EACCES) {
! 	    com_err(progname, 0, "database locked");
! 	    exit(1);
! 	} else if (err) {
! 	    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);
***************
*** 469,474 ****
- --- 463,485 ----
  	}
  	*size = stbuf.st_size;
  	return(fd);
+ }
+ 
+ void
+ close_database(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(dbfp, dbpathname, KRB5_LOCKMODE_UNLOCK);
+     if (err)
+ 	com_err(progname, err, "while unlocking database '%s'", dbpathname);
+     free(dbpathname);
+     (void) fclose(dbfp);
+     return;
  }
  
  /*

-----BEGIN PGP SIGNATURE-----
Version: 2.6

iQCVAgUBLf/WElTdX6I8ZiRnAQH1IAQAkeAAbv7v9U/8FWTxhvBQZFAyOcKOJbeu
IXuwZsqZFrQ3HzpoZkmBct79ju+1sQOtx9iVXqcjKJbhbm/FcwOo1CSEzDwX2tMq
TWLO/dimDqwtRXe4oc5kwFtWslInE9Dl8IPHrz2/8LoPkQo+Ljba6r+fI+xAUDLr
Xh8I7JV/4Ms=
=wjsS
-----END PGP SIGNATURE-----

home help back first fref pref prev next nref lref last post