/[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.4 by lefcha, Sat Nov 9 14:44:48 2002 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  #ifdef DEBUG  #ifdef DEBUG
# Line 142  int main(int argc, char *argv[]) Line 157  int main(int argc, char *argv[])
157    
158              if (r != RESPONSE_PREAUTH) {              if (r != RESPONSE_PREAUTH) {
159                  if (ca->passwdattr == PASSWORD_NONE) {                  if (ca->passwdattr == PASSWORD_NONE) {
160                      printf("Enter password for %s@%s: ", ca->username, ca->server);                      printf("Enter password for %s@%s: ", ca->username,
161                               ca->server);
162                      get_password(ca->password, PASSWORD_LEN);                      get_password(ca->password, PASSWORD_LEN);
163                      ca->passwdattr = PASSWORD_PLAIN;                      ca->passwdattr = PASSWORD_PLAIN;
164                  }                  }
165                  if (login(&sockpri, ca->username, ca->password) == RESPONSE_NO) {                  if (login(&sockpri, ca->username, ca->password) ==
166                      error("imapfilter: username %s or password rejected at %s\n",                      RESPONSE_NO) {
167                            ca->username, ca->server);                      error("imapfilter: username %s or password rejected "
168                              "at %s\n", ca->username, ca->server);
169                      continue;                      continue;
170                  }                  }
171              }              }
# Line 175  int main(int argc, char *argv[]) Line 192  int main(int argc, char *argv[])
192                  fatal(ERROR_FORK, "imapfilter: forking; %s\n", strerror(errno));                  fatal(ERROR_FORK, "imapfilter: forking; %s\n", strerror(errno));
193                  break;                  break;
194              case 0:              case 0:
195    #ifdef MEMORY_LOCK
196                  secmem_lock();                  secmem_lock();
197                  setuid(ruid);   /* Capability to regain root privileges will                  setuid(ruid);   /* Capability to regain root privileges will
198                                     not be needed any more. */                                     not be needed any more. */
199    #endif
200                  lockfile_create();                  lockfile_create();
201                  corefile_disable();                  corefile_disable();
202                  break;                  break;
# Line 211  void usage(void) Line 230  void usage(void)
230  #ifdef ENCRYPTED_PASSWORDS  #ifdef ENCRYPTED_PASSWORDS
231              "p"              "p"
232  #endif  #endif
233              "qv] [-c configfile] [-d interval] [-l logfile]\n");              "qvV] [-c configfile] [-d interval] [-l logfile]\n");
234    }
235    
236    
237    /*
238     * Print program's version, and if it is built in, OpenSSL's version number.
239     */
240    void version(void)
241    {
242        fprintf(stderr, "IMAPFilter %s"
243    #if defined SSL_TLS || defined ENCRYPTED_PASSWORDS
244                ", OpenSSL 0x%8.8lx"
245    #endif
246                "\n", IMAPFILTER_VERSION
247    #if defined SSL_TLS || defined ENCRYPTED_PASSWORDS
248                ,SSLeay()
249    #endif
250        );
251  }  }

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26