/[imapfilter]/imapfilter/file.c
ViewVC logotype

Diff of /imapfilter/file.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.57.2.1 by lefcha, Fri Aug 8 00:28:29 2003 UTC revision 1.63 by lefcha, Fri Feb 13 12:17:15 2004 UTC
# Line 13  Line 13 
13    
14    
15  extern char *home;  extern char *home;
16    extern options_t opts;
17    
18    
19  /*  /*
# Line 23  create_homedir(void) Line 24  create_homedir(void)
24  {  {
25          char hd[PATH_MAX];          char hd[PATH_MAX];
26    
27          snprintf(hd, PATH_MAX, "%s/%s", home, PATHNAME_HOME_DIR);          snprintf(hd, PATH_MAX, "%s/%s", home, PATHNAME_HOME);
28    
29          if (!exists_dir(hd)) {          if (!exists_dir(hd)) {
30                  if (mkdir(hd, S_IRUSR | S_IWUSR | S_IXUSR))                  if (mkdir(hd, S_IRUSR | S_IWUSR | S_IXUSR))
31                          error("could not create directory %s; %s\n", hd,                          error("could not create directory %s; %s\n", hd,
32                              strerror(errno));                              strerror(errno));
33          }          } else {
 #ifdef CHECK_PERMISSIONS  
         else {  
34                  check_dir_perms(hd, S_IRUSR | S_IWUSR | S_IXUSR);                  check_dir_perms(hd, S_IRUSR | S_IWUSR | S_IXUSR);
35          }          }
 #endif  
   
36          return 0;          return 0;
37  }  }
38    
# Line 54  exists_file(char *fname) Line 51  exists_file(char *fname)
51          stat(fname, &fs);          stat(fname, &fs);
52          if (!S_ISREG(fs.st_mode)) {          if (!S_ISREG(fs.st_mode)) {
53                  error("file %s not a regular file\n", fname);                  error("file %s not a regular file\n", fname);
54                  return ERROR_FILE_OPEN;                  return ERROR_FILEOPEN;
55          }          }
56          return 1;          return 1;
57  }  }
# Line 74  exists_dir(char *dname) Line 71  exists_dir(char *dname)
71          stat(dname, &ds);          stat(dname, &ds);
72          if (!S_ISDIR(ds.st_mode)) {          if (!S_ISDIR(ds.st_mode)) {
73                  error("file %s not a directory\n", dname);                  error("file %s not a directory\n", dname);
74                  return ERROR_FILE_OPEN;                  return ERROR_FILEOPEN;
75          }          }
76          return 1;          return 1;
77  }  }
# Line 95  create_file(char *fname, mode_t mode) Line 92  create_file(char *fname, mode_t mode)
92                  if (fd == -1) {                  if (fd == -1) {
93                          error("could not create file %s; %s\n", fname,                          error("could not create file %s; %s\n", fname,
94                              strerror(errno));                              strerror(errno));
95                          return ERROR_FILE_OPEN;                          return ERROR_FILEOPEN;
96                  }                  }
97                  close(fd);                  close(fd);
98          }          }
# Line 103  create_file(char *fname, mode_t mode) Line 100  create_file(char *fname, mode_t mode)
100  }  }
101    
102    
 #ifdef CHECK_PERMISSIONS  
103  /*  /*
104   * Check the permissions of a file.   * Check the permissions of a file.
105   */   */
# Line 112  check_file_perms(char *fname, mode_t mod Line 108  check_file_perms(char *fname, mode_t mod
108  {  {
109          struct stat fs;          struct stat fs;
110    
111            if (opts.verbosity <= -1)
112                    return 0;
113    
114          if (stat(fname, &fs)) {          if (stat(fname, &fs)) {
115                  error("getting file %s status; %s\n", fname,                  error("getting file %s status; %s\n", fname,
116                      strerror(errno));                      strerror(errno));
# Line 122  check_file_perms(char *fname, mode_t mod Line 121  check_file_perms(char *fname, mode_t mod
121                  return ERROR_TRIVIAL;                  return ERROR_TRIVIAL;
122          }          }
123          if ((fs.st_mode & 00777) != mode) {          if ((fs.st_mode & 00777) != mode) {
124                  error("warning: improper file %s permissions\n", fname);                  error("warning: file's %s mode should be %o not %o\n", fname,
125                  error("warning: file's mode should be %o not %o\n", mode,                      mode, fs.st_mode & 00777);
                     fs.st_mode & 00777);  
126                  return ERROR_TRIVIAL;                  return ERROR_TRIVIAL;
127          }          }
128          return 0;          return 0;
# Line 139  check_dir_perms(char *dname, mode_t mode Line 137  check_dir_perms(char *dname, mode_t mode
137  {  {
138          struct stat ds;          struct stat ds;
139    
140            if (opts.verbosity <= -1)
141                    return 0;
142    
143          if (stat(dname, &ds)) {          if (stat(dname, &ds)) {
144                  error("getting file %s status; %s\n", dname,                  error("getting file %s status; %s\n", dname,
145                      strerror(errno));                      strerror(errno));
# Line 149  check_dir_perms(char *dname, mode_t mode Line 150  check_dir_perms(char *dname, mode_t mode
150                  return ERROR_TRIVIAL;                  return ERROR_TRIVIAL;
151          }          }
152          if ((ds.st_mode & 00777) != mode) {          if ((ds.st_mode & 00777) != mode) {
153                  error("warning: improper dir %s permissions\n", dname);                  error("warning: dir's %s mode should be %o not %o\n", dname,
154                  error("warning: dir's mode should be %o not %o\n", mode,                      mode, ds.st_mode & 00777);
                     ds.st_mode & 00777);  
155                  return ERROR_TRIVIAL;                  return ERROR_TRIVIAL;
156          }          }
157          return 0;          return 0;
158  }  }
 #endif                          /* CHECK_PERMISSIONS */  

Legend:
Removed from v.1.57.2.1  
changed lines
  Added in v.1.63

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26