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

Diff of /imapfilter/imapfilter.c

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

revision 1.28 by lefcha, Wed Jan 30 19:19:00 2002 UTC revision 1.29 by lefcha, Thu Jan 31 17:08:13 2002 UTC
# Line 14  extern account_t *accounts; Line 14  extern account_t *accounts;
14  extern filter_t *filters;  extern filter_t *filters;
15    
16  unsigned int options;           /* Program options. */  unsigned int options;           /* Program options. */
17    unsigned int flags = 0;         /* Program flags. */
18  unsigned int capabilities;      /* Capabilities of mail server. */  unsigned int capabilities;      /* Capabilities of mail server. */
19    unsigned int interval = 0;      /* Poll at the specified interval. */
20  char logfile[PATH_MAX];         /* Log file. */  char logfile[PATH_MAX];         /* Log file. */
21  char *home = NULL;              /* User's home directory. */  char *home = NULL;              /* User's home directory. */
22  uid_t ruid, euid;               /* Real and effective UID. */  uid_t ruid, euid;               /* Real and effective UID. */
23    
24    
25    
26  /*  /*
27   * In the beginning there was main()...   * In the beginning there was main()...
28   */   */
29  int main(int argc, char *argv[])  int main(int argc, char *argv[])
30  {  {
31      int c, r;      int c, r, f = 0;
32        pid_t pid;
33      char *confile = NULL;       /* Configuration file. */      char *confile = NULL;       /* Configuration file. */
34      account_t *ca;              /* Current account. */      account_t *ca;              /* Current account. */
35      mbox_t *cm;                 /* Current mailbox. */      mbox_t *cm;                 /* Current mailbox. */
# Line 38  int main(int argc, char *argv[]) Line 42  int main(int argc, char *argv[])
42      options = (OPTION_DETAILS_NORMAL | OPTION_NAMESPACE);      options = (OPTION_DETAILS_NORMAL | OPTION_NAMESPACE);
43      *logfile = 0;      *logfile = 0;
44            
45  #ifndef ENCRYPTED_PASSWORDS      while ((c = getopt(argc, argv, "c:d:hkl:"
46      while ((c = getopt(argc, argv, "c:hl:qv")) != -1) {  #ifdef ENCRYPTED_PASSWORDS
47  #else                         "p"
     while ((c = getopt(argc, argv, "c:hl:pqv")) != -1) {  
48  #endif  #endif
49                           "qv")) != -1) {
50          switch (c) {          switch (c) {
51          case 'c':          case 'c':
52              confile = optarg;              confile = optarg;
53              break;              break;
54            case 'd':
55                options |= OPTION_DAEMON_MODE;
56                errno = 0;
57                interval = strtoul(optarg, NULL, 10);
58                if (errno)
59                    interval = 0;
60                break;
61          case 'h':          case 'h':
62              usage();              usage();
63              exit(ERROR_UNDEFINED);              exit(ERROR_UNDEFINED);
64              break;              break;
65            case 'k':
66                kill_imapfilter();
67                break;
68          case 'l':          case 'l':
69              strncat(logfile, optarg, PATH_MAX - 1);              strncat(logfile, optarg, PATH_MAX - 1);
70              break;              break;
# Line 73  int main(int argc, char *argv[]) Line 87  int main(int argc, char *argv[])
87              break;              break;
88          }          }
89      }      }
90            
91      lockfile_check();      lockfile_check();
92      lockfile_create();      lockfile_create();
93    
# Line 86  int main(int argc, char *argv[]) Line 100  int main(int argc, char *argv[])
100    
101      read_config(confile);      read_config(confile);
102      open_logfile();      open_logfile();
103            
104    
105  #ifdef ENCRYPTED_PASSWORDS  #ifdef ENCRYPTED_PASSWORDS
106      read_passwords();      read_passwords();
# Line 93  int main(int argc, char *argv[]) Line 108  int main(int argc, char *argv[])
108      if ((options & OPTION_PASSWORD_EDITOR))      if ((options & OPTION_PASSWORD_EDITOR))
109          password_editor();          password_editor();
110  #endif  #endif
       
     setuid(ruid);               /* Capability to regain root privileges  
                                    will not be needed any more. */  
       
111    
112      for (ca = accounts; ca; ca = ca->next) {      if (options & OPTION_DAEMON_MODE) {
113            f = 1;
114            options &= OPTION_DETAILS_CLEAR;
115            options |= OPTION_DETAILS_QUIET;
116        }
117        
118        do {
119            for (ca = accounts; ca; ca = ca->next) {
120    
121  #ifndef SSL_TLS  #ifndef SSL_TLS
122          if (init_connection(ca->server, ca->port))          if (init_connection(ca->server, ca->port))
# Line 120  int main(int argc, char *argv[]) Line 138  int main(int argc, char *argv[])
138              if (ca->passwdattr == PASSWORD_NONE) {              if (ca->passwdattr == PASSWORD_NONE) {
139                  printf("Enter password for %s@%s: ", ca->username, ca->server);                  printf("Enter password for %s@%s: ", ca->username, ca->server);
140                  get_password(ca->password, PASSWORD_LEN);                  get_password(ca->password, PASSWORD_LEN);
141                    ca->passwdattr = PASSWORD_PLAIN;
142              }              }
143              if (login(ca->username, ca->password))              if (login(ca->username, ca->password))
144                  continue;                  continue;
# Line 137  int main(int argc, char *argv[]) Line 156  int main(int argc, char *argv[])
156    
157          close_connection();          close_connection();
158      }      }
159            
160        if (f) {
161            f = 0;
162            pid = fork();
163            switch (pid) {
164            case -1:
165                fatal(ERROR_FORK, "imapfilter: forking; %s\n", strerror(errno));
166                break;
167            case 0:
168                secmem_lock();
169                setuid(ruid);       /* Capability to regain root privileges
170                                       will not be needed any more. */
171                lockfile_create();
172                corefile_disable();
173                break;
174            default:
175                secmem_clear();
176                close_logfile();
177                exit(0);
178                break;
179            }
180        }
181    
182        if (interval)
183            sleep(interval);
184        } while (options & OPTION_DAEMON_MODE && interval);
185    
186      secmem_clear();      secmem_clear();
187      close_logfile();      close_logfile();
188            
189      lockfile_remove();      lockfile_remove();
190            
191      exit(0);      exit(0);
192  }  }
193    
# Line 153  int main(int argc, char *argv[]) Line 198  int main(int argc, char *argv[])
198  void usage(void)  void usage(void)
199  {  {
200      fprintf(stderr,      fprintf(stderr,
201              "usage: imapfilter [-h"              "usage: imapfilter [-hk"
202  #ifdef ENCRYPTED_PASSWORDS  #ifdef ENCRYPTED_PASSWORDS
203              "p"              "p"
204  #endif        #endif      
205              "qv] [-c configfile] [-l logfile]\n");              "qv] [-c configfile] [-d interval] [-l logfile]\n");
206  }  }

Legend:
Removed from v.1.28  
changed lines
  Added in v.1.29

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26