[1247] in Kerberos-V5-bugs

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

krb5b4pl3: lib/krb5/ccache/file/fcc_gennew.c: use 3rd arg to open instead of chmod/fchmod

daemon@ATHENA.MIT.EDU (Jonathan I. Kamens)
Tue Mar 21 20:22:51 1995

From: "Jonathan I. Kamens" <jik@cam.ov.com>
Date: Tue, 21 Mar 1995 20:26:02 -0500
To: krb5-bugs@MIT.EDU

There's code in krb5_fcc_generate_new which open()s a new file and
then immediately uses chmod or fchmod to change its permissions to
0600.

It seems to me that there's no good reason not to use the third
argument to open() to specify the permissions of the file, thus
eliminating an unnecessary system call and making the code cleaner.

Here's a patch:

--- fcc_gennew.c	1995/03/22 01:23:00	1.1
+++ fcc_gennew.c	1995/03/22 01:26:04
@@ -98,7 +98,7 @@
 
      /* Make sure the file name is reserved */
      ret = open(((krb5_fcc_data *) lid->data)->filename,
-		O_CREAT | O_EXCL | O_WRONLY, 0);
+		O_CREAT | O_EXCL | O_WRONLY, S_IRUSR | S_IWUSR);
      if (ret == -1) {
 	  retcode = krb5_fcc_interpret(errno);
           goto err_out;
@@ -106,12 +106,6 @@
 	  krb5_int16 fcc_fvno = htons(KRB5_FCC_FVNO);
 	  int errsave, cnt;
 
-	  /* Ignore user's umask, set mode = 0600 */
-#ifdef NOFCHMOD
-	  chmod(((krb5_fcc_data *) lid->data)->filename, S_IRUSR | S_IWUSR);
-#else
-	  fchmod(ret, S_IRUSR | S_IWUSR);
-#endif
 	  if ((cnt = write(ret, (char *)&fcc_fvno, sizeof(fcc_fvno)))
 	      != sizeof(fcc_fvno)) {
 	      errsave = errno;

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