]> git.ozlabs.org Git - ppp.git/commitdiff
create log file safely, don't create world-writable files
authorPaul Mackerras <paulus@samba.org>
Mon, 15 Nov 1999 03:55:37 +0000 (03:55 +0000)
committerPaul Mackerras <paulus@samba.org>
Mon, 15 Nov 1999 03:55:37 +0000 (03:55 +0000)
pppd/main.c
pppd/options.c

index e5d2977fc2363d99bccf9b98d5cf01dc804d2d15..4de4b994156c801566415b34693dc6ee59bb0ff1 100644 (file)
@@ -17,7 +17,7 @@
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
-#define RCSID  "$Id: main.c,v 1.86 1999/09/11 12:08:57 paulus Exp $"
+#define RCSID  "$Id: main.c,v 1.87 1999/11/15 03:55:37 paulus Exp $"
 
 #include <stdio.h>
 #include <ctype.h>
 
 #include <stdio.h>
 #include <ctype.h>
@@ -252,6 +252,9 @@ main(argc, argv)
     }
     hostname[MAXNAMELEN-1] = 0;
 
     }
     hostname[MAXNAMELEN-1] = 0;
 
+    /* make sure we don't create world or group writable files. */
+    umask(umask(0777) | 022);
+
     uid = getuid();
     privileged = uid == 0;
     slprintf(numbuf, sizeof(numbuf), "%d", uid);
     uid = getuid();
     privileged = uid == 0;
     slprintf(numbuf, sizeof(numbuf), "%d", uid);
index 6fd750f3ebfd489eb9a2664b015c02a32920ec46..66770a5918606578c9e7b6e10cb4d19b7dc9d13d 100644 (file)
@@ -17,7 +17,7 @@
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
-#define RCSID  "$Id: options.c,v 1.67 1999/11/15 01:51:52 paulus Exp $"
+#define RCSID  "$Id: options.c,v 1.68 1999/11/15 03:55:37 paulus Exp $"
 
 #include <ctype.h>
 #include <stdio.h>
 
 #include <ctype.h>
 #include <stdio.h>
@@ -1523,7 +1523,9 @@ setlogfile(argv)
 
     if (!privileged_option)
        seteuid(getuid());
 
     if (!privileged_option)
        seteuid(getuid());
-    fd = open(*argv, O_WRONLY | O_APPEND);
+    fd = open(*argv, O_WRONLY | O_APPEND | O_CREAT | O_EXCL, 0644);
+    if (fd < 0 && errno == EEXIST)
+       fd = open(*argv, O_WRONLY | O_APPEND);
     err = errno;
     if (!privileged_option)
        seteuid(0);
     err = errno;
     if (!privileged_option)
        seteuid(0);