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

Diff of /imapfilter/parse.c

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

revision 1.11 by lefcha, Tue Feb 10 22:21:09 2004 UTC revision 1.12 by lefcha, Fri Feb 13 12:17:16 2004 UTC
# Line 5  Line 5 
5  #include <errno.h>  #include <errno.h>
6  #include <limits.h>  #include <limits.h>
7  #include <sys/stat.h>  #include <sys/stat.h>
8  #include <sys/types.h>          /* IEEE Std 1003.1-2001 non-conformance. */  #include <sys/types.h>          /* IEEE Std 1003.1-2001 transitional. */
9  #include <regex.h>  #include <regex.h>
10    
11  #include "config.h"  #include "config.h"
# Line 13  Line 13 
13  #include "pathnames.h"  #include "pathnames.h"
14    
15    
16  extern opts_t opts;  extern options_t opts;
17  extern unsigned int flags;  extern unsigned int flags;
18  extern char *home;  extern char *home;
19    
# Line 24  char *passphr = NULL;          /* Master passwor Line 24  char *passphr = NULL;          /* Master passwor
24    
25    
26  int parse_config(FILE * fd);  int parse_config(FILE * fd);
27  void set_options(char *line, regmatch_t * match);  void set_options(char *line, regmatch_t * m);
28    
29  int parse_passwords(FILE * fd);  int parse_passwords(FILE * fd);
30    
# Line 43  read_config(char *cfg) Line 43  read_config(char *cfg)
43    
44          if (cfg == NULL) {          if (cfg == NULL) {
45                  cfg = c = (char *)xmalloc(PATH_MAX * sizeof(char));                  cfg = c = (char *)xmalloc(PATH_MAX * sizeof(char));
46                  snprintf(cfg, PATH_MAX, "%s/%s", home, PATHNAME_CONFIG_FILE);                  snprintf(cfg, PATH_MAX, "%s/%s", home, PATHNAME_CONFIG);
47          }          }
48          debug("configuration file: '%s'\n", cfg);          debug("configuration file: '%s'\n", cfg);
49    
# Line 51  read_config(char *cfg) Line 51  read_config(char *cfg)
51    
52          fd = fopen(cfg, "r");          fd = fopen(cfg, "r");
53          if (fd == NULL)          if (fd == NULL)
54                  fatal(ERROR_FILE_OPEN, "opening config file %s; %s\n", cfg,                  fatal(ERROR_FILEOPEN, "opening config file %s; %s\n", cfg,
55                      strerror(errno));                      strerror(errno));
56    
57          if (c != NULL)          if (c != NULL)
58                  xfree(c);                  xfree(c);
59    
60          if ((r = parse_config(fd)))          if ((r = parse_config(fd)))
61                  fatal(ERROR_CONFIG_PARSE,                  fatal(ERROR_PARSER,
62                      "parse error in config file at row %d\n", r);                      "parse error in config file at row %d\n", r);
63    
64          fclose(fd);          fclose(fd);
# Line 186  parse_config(FILE * fd) Line 186  parse_config(FILE * fd)
186                  else                  else
187                          return row;                          return row;
188    
189                  if (r == ERROR_CONFIG_PARSE)                  if (r == ERROR_PARSER)
190                          return row;                          return row;
191          }          }
192    
# Line 211  reread_config(char *cfg) Line 211  reread_config(char *cfg)
211  #ifdef ENCRYPTED_PASSWORDS  #ifdef ENCRYPTED_PASSWORDS
212          read_passwords();          read_passwords();
213  #endif  #endif
214          flags &= ~(FLAG_SIGUSR1_RECEIVED);          flags &= ~(FLAG_SIGUSR1);
215  }  }
216    
217    
# Line 297  read_passwords(void) Line 297  read_passwords(void)
297          FILE *fd;          FILE *fd;
298          char pwfile[PATH_MAX];          char pwfile[PATH_MAX];
299    
300          if (!(flags & FLAG_BLANK_PASSWORD))          if (!(flags & FLAG_BLANKPASS))
301                  return ERROR_CONFIG_PARSE;                  return ERROR_PARSER;
302    
303          if (!passphr) {          if (!passphr) {
304                  passphr = (char *)smalloc(PASSPHRASE_LEN);                  passphr = (char *)smalloc(PASSPHRASE_LEN);
305                  *passphr = '\0';                  *passphr = '\0';
306          }          }
307          snprintf(pwfile, PATH_MAX, "%s/%s", home, PATHNAME_PASSWORD_FILE);          snprintf(pwfile, PATH_MAX, "%s/%s", home, PATHNAME_PASSWORDS);
308          debug("passwords file: '%s'\n", pwfile);          debug("passwords file: '%s'\n", pwfile);
309    
310          if (!exists_file(pwfile))          if (!exists_file(pwfile))
311                  return ERROR_FILE_OPEN;                  return ERROR_FILEOPEN;
312    
313          check_file_perms(pwfile, S_IRUSR | S_IWUSR);          check_file_perms(pwfile, S_IRUSR | S_IWUSR);
314    
315          fd = fopen(pwfile, "r");          fd = fopen(pwfile, "r");
316          if (fd == NULL)          if (fd == NULL)
317                  fatal(ERROR_FILE_OPEN, "opening passwords file %s; %s\n",                  fatal(ERROR_FILEOPEN, "opening passwords file %s; %s\n",
318                      pwfile, strerror(errno));                      pwfile, strerror(errno));
319    
320          parse_passwords(fd);          parse_passwords(fd);
# Line 333  parse_passwords(FILE * fd) Line 333  parse_passwords(FILE * fd)
333  {  {
334          int t;          int t;
335          char *pe;          char *pe;
336          char user[USERNAME_LEN], serv[SERVER_LEN];          char user[USER_LEN], serv[SERVER_LEN];
337          unsigned char *buf;          unsigned char *buf;
338          char *c, *cp, *line;          char *c, *cp, *line;
339          regex_t creg;          regex_t creg;
# Line 344  parse_passwords(FILE * fd) Line 344  parse_passwords(FILE * fd)
344          pe = NULL;          pe = NULL;
345          reg = "([[:alnum:].-]+) ([[:graph:]]+) ([[:graph:]]+)";          reg = "([[:alnum:].-]+) ([[:graph:]]+) ([[:graph:]]+)";
346    
347          if (!(flags & FLAG_DAEMON_MODE)) {          if (!(flags & FLAG_DAEMON)) {
348                  do {                  do {
349                          fseek(fd, 0L, SEEK_SET);                          fseek(fd, 0L, SEEK_SET);
350                          printf("Enter master passphrase: ");                          printf("Enter master passphrase: ");
# Line 368  parse_passwords(FILE * fd) Line 368  parse_passwords(FILE * fd)
368                  strncat(serv, line + match[1].rm_so,                  strncat(serv, line + match[1].rm_so,
369                      min(match[1].rm_eo - match[1].rm_so, SERVER_LEN - 1));                      min(match[1].rm_eo - match[1].rm_so, SERVER_LEN - 1));
370                  strncat(user, line + match[2].rm_so,                  strncat(user, line + match[2].rm_so,
371                      min(match[2].rm_eo - match[2].rm_so, USERNAME_LEN - 1));                      min(match[2].rm_eo - match[2].rm_so, USER_LEN - 1));
372    
373                  if ((pe = (char *)find_password(user, serv)))                  if ((pe = (char *)find_password(user, serv)))
374                          strncat(pe, line + match[3].rm_so,                          strncat(pe, line + match[3].rm_so,
375                              min(match[3].rm_eo - match[3].rm_so,                              min(match[3].rm_eo - match[3].rm_so,
376                                  PASSWORD_LEN - 1));                                  PASS_LEN - 1));
377    
378                  line = strtok_r(NULL, "\n", &c);                  line = strtok_r(NULL, "\n", &c);
379          }          }

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26