comparison mcabber/src/utils.c @ 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 2f9852610cf4
children dfd9c62b3a39
comparison
equal deleted inserted replaced
427:ac85ce87f539 428:4470868f90e5
37 static char *FName; 37 static char *FName;
38 38
39 void ut_InitDebug(unsigned int level, const char *filename) 39 void ut_InitDebug(unsigned int level, const char *filename)
40 { 40 {
41 FILE *fp; 41 FILE *fp;
42 struct stat buf;
43 int err;
42 44
43 if (level < 1) { 45 if (level < 1) {
44 DebugEnabled = 0; 46 DebugEnabled = 0;
45 FName = NULL; 47 FName = NULL;
46 return; 48 return;
65 fp = fopen(FName, "a"); 67 fp = fopen(FName, "a");
66 if (!fp) { 68 if (!fp) {
67 fprintf(stderr, "ERROR: Cannot open tracelog file\n"); 69 fprintf(stderr, "ERROR: Cannot open tracelog file\n");
68 return; 70 return;
69 } 71 }
72
73 err = fstat(fileno(fp), &buf);
74 if (err || buf.st_uid != geteuid()) {
75 fclose(fp);
76 DebugEnabled = 0;
77 FName = NULL;
78 if (err) {
79 fprintf(stderr, "ERROR: cannot stat the tracelog file!\n");
80 } else {
81 fprintf(stderr, "ERROR: tracelog file does not belong to you!\n");
82 }
83 return;
84 }
85 fchmod(fileno(fp), S_IRUSR|S_IWUSR);
86
70 fprintf(fp, "New trace log started.\n" 87 fprintf(fp, "New trace log started.\n"
71 "----------------------\n"); 88 "----------------------\n");
72 fchmod(fileno(fp), S_IRUSR|S_IWUSR);
73 fclose(fp); 89 fclose(fp);
74 } 90 }
75 91
76 void ut_WriteLog(unsigned int flag, const char *data) 92 void ut_WriteLog(unsigned int flag, const char *data)
77 { 93 {