changeset 428:4470868f90e5

Check the tracelog file actually belongs to the user (if logging enabled)
author Mikael Berthe <mikael@lilotux.net>
date Sat, 10 Sep 2005 14:51:57 +0200
parents ac85ce87f539
children 0bb3d37579aa
files mcabber/src/utils.c
diffstat 1 files changed, 17 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/utils.c	Tue Sep 06 21:49:27 2005 +0200
+++ b/mcabber/src/utils.c	Sat Sep 10 14:51:57 2005 +0200
@@ -39,6 +39,8 @@
 void ut_InitDebug(unsigned int level, const char *filename)
 {
   FILE *fp;
+  struct stat buf;
+  int err;
 
   if (level < 1) {
     DebugEnabled = 0;
@@ -67,9 +69,23 @@
     fprintf(stderr, "ERROR: Cannot open tracelog file\n");
     return;
   }
+
+  err = fstat(fileno(fp), &buf);
+  if (err || buf.st_uid != geteuid()) {
+    fclose(fp);
+    DebugEnabled = 0;
+    FName = NULL;
+    if (err) {
+      fprintf(stderr, "ERROR: cannot stat the tracelog file!\n");
+    } else {
+      fprintf(stderr, "ERROR: tracelog file does not belong to you!\n");
+    }
+    return;
+  }
+  fchmod(fileno(fp), S_IRUSR|S_IWUSR);
+
   fprintf(fp, "New trace log started.\n"
 	  "----------------------\n");
-  fchmod(fileno(fp), S_IRUSR|S_IWUSR);
   fclose(fp);
 }