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

Diff of /imapfilter/imapfilter.c

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

revision 1.34 by lefcha, Fri Jul 26 18:18:42 2002 UTC revision 1.34.2.5 by lefcha, Fri Mar 28 16:57:52 2003 UTC
# Line 4  Line 4 
4  #include <string.h>  #include <string.h>
5  #include <limits.h>  #include <limits.h>
6  #include <errno.h>  #include <errno.h>
7    #include <setjmp.h>
8    
9  #include "config.h"  #include "config.h"
10  #include "imapfilter.h"  #include "imapfilter.h"
11  #include "data.h"  #include "data.h"
12    
13    #if defined SSL_TLS || defined ENCRYPTED_PASSWORDS
14    #include <openssl/crypto.h>
15    #endif
16    
17    
18  extern int sockpri;  extern int sockpri;
19  extern account_t *accounts;  extern account_t *accounts;
# Line 21  unsigned int capabilities;     /* Capabiliti Line 26  unsigned int capabilities;     /* Capabiliti
26  unsigned int interval = 0;      /* Poll at the specified interval. */  unsigned int interval = 0;      /* Poll at the specified interval. */
27  char logfile[PATH_MAX];         /* Log file. */  char logfile[PATH_MAX];         /* Log file. */
28  char *home = NULL;              /* User's home directory. */  char *home = NULL;              /* User's home directory. */
29    #ifdef MEMORY_LOCK
30  uid_t ruid, euid;               /* Real and effective UID. */  uid_t ruid, euid;               /* Real and effective UID. */
31    #endif
32    jmp_buf acctloop;
33    
34    
35  /*  /*
# Line 36  int main(int argc, char *argv[]) Line 43  int main(int argc, char *argv[])
43      account_t *ca;              /* Current account. */      account_t *ca;              /* Current account. */
44      mbox_t *cm;                 /* Current mailbox. */      mbox_t *cm;                 /* Current mailbox. */
45    
46    #ifdef MEMORY_LOCK
47      ruid = getuid();      ruid = getuid();
48      euid = geteuid();      euid = geteuid();
49      seteuid(ruid);              /* Drop root privileges. */      seteuid(ruid);              /* Drop root privileges. */
50    #endif
51    
52      home = getenv("HOME");      home = getenv("HOME");
53      options = (OPTION_DETAILS_NORMAL | OPTION_NAMESPACE | OPTION_WARNING);      options = (OPTION_DETAILS_NORMAL | OPTION_NAMESPACE | OPTION_WARNING);
# Line 48  int main(int argc, char *argv[]) Line 57  int main(int argc, char *argv[])
57  #ifdef ENCRYPTED_PASSWORDS  #ifdef ENCRYPTED_PASSWORDS
58                         "p"                         "p"
59  #endif  #endif
60                         "qv")) != -1) {                         "qvV")) != -1) {
61          switch (c) {          switch (c) {
62          case 'c':          case 'c':
63              confile = optarg;              confile = optarg;
# Line 83  int main(int argc, char *argv[]) Line 92  int main(int argc, char *argv[])
92              options &= OPTION_DETAILS_CLEAR;              options &= OPTION_DETAILS_CLEAR;
93              options |= OPTION_DETAILS_VERBOSE;              options |= OPTION_DETAILS_VERBOSE;
94              break;              break;
95            case 'V':
96                version();
97                exit(ERROR_UNDEFINED);
98                break;
99          default:          default:
100              usage();              usage();
101              exit(ERROR_UNDEFINED);              exit(ERROR_UNDEFINED);
# Line 119  int main(int argc, char *argv[]) Line 132  int main(int argc, char *argv[])
132    
133      init_vbuf();      init_vbuf();
134    
   
135      if (options & OPTION_DAEMON_MODE) {      if (options & OPTION_DAEMON_MODE) {
136          f = 1;          f = 1;
137          options &= OPTION_DETAILS_CLEAR;          options &= OPTION_DETAILS_CLEAR;
# Line 128  int main(int argc, char *argv[]) Line 140  int main(int argc, char *argv[])
140      do {      do {
141          for (ca = accounts; ca; ca = ca->next) {          for (ca = accounts; ca; ca = ca->next) {
142    
143                if (setjmp(acctloop))
144                    continue;
145    
146              if (init_connection(&sockpri, ca->server, ca->port, ca->ssl))              if (init_connection(&sockpri, ca->server, ca->port, ca->ssl))
147                  continue;                  continue;
148    
149              r = greeting_response(&sockpri);              r = greeting_response(&sockpri);
150    
151              if (r == RESPONSE_BYE || check_capabilities(&sockpri))              if (check_capabilities(&sockpri))
152                  continue;                  continue;
153                
154                log_info(LOG_ACCOUNT, ca->key);
155    
156  #ifdef DEBUG  #ifdef DEBUG
157              test(&sockpri);              test(&sockpri);
# Line 142  int main(int argc, char *argv[]) Line 159  int main(int argc, char *argv[])
159    
160              if (r != RESPONSE_PREAUTH) {              if (r != RESPONSE_PREAUTH) {
161                  if (ca->passwdattr == PASSWORD_NONE) {                  if (ca->passwdattr == PASSWORD_NONE) {
162                      printf("Enter password for %s@%s: ", ca->username, ca->server);                      printf("Enter password for %s@%s: ", ca->username,
163                               ca->server);
164                      get_password(ca->password, PASSWORD_LEN);                      get_password(ca->password, PASSWORD_LEN);
165                      ca->passwdattr = PASSWORD_PLAIN;                      ca->passwdattr = PASSWORD_PLAIN;
166                  }                  }
167                  if (login(&sockpri, ca->username, ca->password) == RESPONSE_NO) {                  if (login(&sockpri, ca->username, ca->password) ==
168                      error("imapfilter: username %s or password rejected at %s\n",                      RESPONSE_NO) {
169                            ca->username, ca->server);                      error("imapfilter: username %s or password rejected "
170                              "at %s\n", ca->username, ca->server);
171                      continue;                      continue;
172                  }                  }
173              }              }
# Line 175  int main(int argc, char *argv[]) Line 194  int main(int argc, char *argv[])
194                  fatal(ERROR_FORK, "imapfilter: forking; %s\n", strerror(errno));                  fatal(ERROR_FORK, "imapfilter: forking; %s\n", strerror(errno));
195                  break;                  break;
196              case 0:              case 0:
197    #ifdef MEMORY_LOCK
198                  secmem_lock();                  secmem_lock();
199                  setuid(ruid);   /* Capability to regain root privileges will                  setuid(ruid);   /* Capability to regain root privileges will
200                                     not be needed any more. */                                     not be needed any more. */
201    #endif
202                  lockfile_create();                  lockfile_create();
203                  corefile_disable();                  corefile_disable();
204                  break;                  break;
# Line 211  void usage(void) Line 232  void usage(void)
232  #ifdef ENCRYPTED_PASSWORDS  #ifdef ENCRYPTED_PASSWORDS
233              "p"              "p"
234  #endif  #endif
235              "qv] [-c configfile] [-d interval] [-l logfile]\n");              "qvV] [-c configfile] [-d interval] [-l logfile]\n");
236    }
237    
238    
239    /*
240     * Print program's version, and if it is built in, OpenSSL's version number.
241     */
242    void version(void)
243    {
244        fprintf(stderr, "IMAPFilter %s"
245    #if defined SSL_TLS || defined ENCRYPTED_PASSWORDS
246                ", OpenSSL 0x%8.8lx"
247    #endif
248                "\n", IMAPFILTER_VERSION
249    #if defined SSL_TLS || defined ENCRYPTED_PASSWORDS
250                ,SSLeay()
251    #endif
252        );
253  }  }

Legend:
Removed from v.1.34  
changed lines
  Added in v.1.34.2.5

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26