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

Diff of /imapfilter/imapfilter.c

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

revision 1.54 by lefcha, Sun Aug 3 17:40:10 2003 UTC revision 1.54.2.4 by lefcha, Mon Jan 26 21:38:51 2004 UTC
# Line 1  Line 1 
1  #include <stdio.h>  #include <stdio.h>
2  #include <stdlib.h>  #include <stdlib.h>
3  #include <string.h>  #include <sys/types.h>
4  #include <unistd.h>  #include <unistd.h>
5    #include <string.h>
6  #include <errno.h>  #include <errno.h>
7  #include <limits.h>  #include <limits.h>
8    #include <fcntl.h>
9  #include <setjmp.h>  #include <setjmp.h>
10  #include <locale.h>  #include <locale.h>
11    
# Line 15  Line 17 
17  #include "buffer.h"  #include "buffer.h"
18    
19  #if defined SSL_TLS || defined ENCRYPTED_PASSWORDS || defined CRAM_MD5  #if defined SSL_TLS || defined ENCRYPTED_PASSWORDS || defined CRAM_MD5
20    #include <openssl/opensslv.h>
21  #include <openssl/crypto.h>  #include <openssl/crypto.h>
22  #endif  #endif
23    
# Line 45  void version(void); Line 48  void version(void);
48  int  int
49  main(int argc, char *argv[])  main(int argc, char *argv[])
50  {  {
51          int c, r, f;          int c, r;
52          pid_t pid;          char *conffile;         /* Configuration file. */
         char *confile;          /* Configuration file. */  
53          account_t *ca;          /* Current account. */          account_t *ca;          /* Current account. */
54          mbox_t *cm;             /* Current mailbox. */          mbox_t *cm;             /* Current mailbox. */
55    
56          setlocale(LC_ALL, "");          setlocale(LC_ALL, "");
57    
         f = 0;  
58          home = getenv("HOME");          home = getenv("HOME");
59          options = (OPTION_DETAILS_NORMAL | OPTION_NAMESPACE);          options = (OPTION_DETAILS_NORMAL | OPTION_NAMESPACE | OPTION_PEEK);
60          *charset = 0;          *charset = 0;
61          *logfile = 0;          *logfile = 0;
62          confile = NULL;          conffile = NULL;
63            connpri.sock = connaux.sock = -1;
64    
65          while ((c = getopt(argc, argv, "c:d:hkl:"          while ((c = getopt(argc, argv, "c:d:hkl:"
66  #ifdef ENCRYPTED_PASSWORDS  #ifdef ENCRYPTED_PASSWORDS
# Line 67  main(int argc, char *argv[]) Line 69  main(int argc, char *argv[])
69                      "qvV")) != -1) {                      "qvV")) != -1) {
70                  switch (c) {                  switch (c) {
71                  case 'c':                  case 'c':
72                          confile = optarg;                          conffile = optarg;
73                          break;                          break;
74                  case 'd':                  case 'd':
75                          options |= OPTION_DAEMON_MODE;                          options |= OPTION_DAEMON_MODE;
# Line 92  main(int argc, char *argv[]) Line 94  main(int argc, char *argv[])
94                          break;                          break;
95  #endif  #endif
96                  case 'q':                  case 'q':
97                          options &= OPTION_DETAILS_CLEAR;                          options &= ~(OPTION_DETAILS_QUIET |
98                                OPTION_DETAILS_NORMAL | OPTION_DETAILS_VERBOSE);
99                          options |= OPTION_DETAILS_QUIET;                          options |= OPTION_DETAILS_QUIET;
100                          break;                          break;
101                  case 'v':                  case 'v':
102                          options &= OPTION_DETAILS_CLEAR;                          options &= ~(OPTION_DETAILS_QUIET |
103                                OPTION_DETAILS_NORMAL | OPTION_DETAILS_VERBOSE);
104                          options |= OPTION_DETAILS_VERBOSE;                          options |= OPTION_DETAILS_VERBOSE;
105                          break;                          break;
106                  case 'V':                  case 'V':
# Line 122  main(int argc, char *argv[]) Line 126  main(int argc, char *argv[])
126          tty_store();          tty_store();
127          catch_signals();          catch_signals();
128    
129          read_config(confile);          read_config(conffile);
130    
131  #ifdef ENCRYPTED_PASSWORDS  #ifdef ENCRYPTED_PASSWORDS
132          read_passwords();          read_passwords();
# Line 143  main(int argc, char *argv[]) Line 147  main(int argc, char *argv[])
147          init_buffer(&obuf);          init_buffer(&obuf);
148    
149          if (options & OPTION_DAEMON_MODE) {          if (options & OPTION_DAEMON_MODE) {
150                  f = 1;                  options &= ~(OPTION_DETAILS_QUIET |
151                  options &= OPTION_DETAILS_CLEAR;                      OPTION_DETAILS_NORMAL | OPTION_DETAILS_VERBOSE);
152                  options |= OPTION_DETAILS_QUIET;                  options |= OPTION_DETAILS_QUIET;
153          }          }
154          do {          do {
# Line 212  main(int argc, char *argv[]) Line 216  main(int argc, char *argv[])
216                  }                  }
217    
218                  /* Fork if in daemon mode. */                  /* Fork if in daemon mode. */
219                  if (f) {                  if (options & OPTION_DAEMON_MODE &&
220                          f = 0;                      !(flags & FLAG_DAEMON_MODE)) {
221                          pid = fork();  
222                          switch (pid) {                          close_logfile();
223    
224                            switch (fork()) {
225                            case -1:
226                                    fatal(ERROR_FORK, "forking; %s\n",
227                                        strerror(errno));
228                                    break;
229                            case 0:
230                                    break;
231                            default:
232                                    secmem_clear();
233                                    exit(0);
234                                    break;
235                            }
236    
237                            if (setsid() == -1)
238                                    fatal(ERROR_FORK, "creating session; %s\n",
239                                        strerror(errno));
240    
241                            switch (fork()) {
242                          case -1:                          case -1:
243                                  fatal(ERROR_FORK, "forking; %s\n",                                  fatal(ERROR_FORK, "forking; %s\n",
244                                      strerror(errno));                                      strerror(errno));
245                                  break;                                  break;
246                          case 0:                          case 0:
                                 lockfile_create();  
                                 corefile_disable();  
                                 flags |= FLAG_DAEMON_MODE;  
247                                  break;                                  break;
248                          default:                          default:
249                                  secmem_clear();                                  secmem_clear();
                                 close_logfile();  
250                                  exit(0);                                  exit(0);
251                                  break;                                  break;
252                          }                          }
253    
254                            close(STDIN_FILENO);
255                            close(STDOUT_FILENO);
256                            close(STDERR_FILENO);
257                            if (open("/dev/null", O_RDWR) != -1) {
258                                    dup(STDIN_FILENO);
259                                    dup(STDIN_FILENO);
260                            }
261                            open_logfile();
262                            lockfile_create();
263                            corefile_disable();
264    
265                            flags |= FLAG_DAEMON_MODE;
266                  }                  }
267                  if (options & OPTION_DAEMON_MODE &&                  if (options & OPTION_DAEMON_MODE &&
268                      flags & FLAG_SIGUSR1_RECEIVED) {                      flags & FLAG_SIGUSR1_RECEIVED) {
269                          reread_config(confile);                          reread_config(conffile);
270                          continue;                          continue;
271                  }                  }
272                  if (interval)                  if (interval)
# Line 246  main(int argc, char *argv[]) Line 278  main(int argc, char *argv[])
278    
279          lockfile_remove();          lockfile_remove();
280    
281          return 0;          exit(0);
282  }  }
283    
284    

Legend:
Removed from v.1.54  
changed lines
  Added in v.1.54.2.4

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26