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

Diff of /imapfilter/socket.c

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

revision 1.1 by lefcha, Wed Oct 17 14:03:37 2001 UTC revision 1.2 by lefcha, Tue Oct 23 09:23:08 2001 UTC
# Line 58  int init_connection(char *serv, unsigned Line 58  int init_connection(char *serv, unsigned
58      strncpy(serv, he->h_name, SERVER_LEN - 1);      strncpy(serv, he->h_name, SERVER_LEN - 1);
59    
60      log_info(LOG_SERVER, serv);      log_info(LOG_SERVER, serv);
61        
62  #ifdef SSL_TLS  #ifdef SSL_TLS
63      if (protocol != SSL_DISABLED) {      if (protocol != SSL_DISABLED) {
64          ssl_init(protocol);          ssl_init(protocol);
# Line 70  int init_connection(char *serv, unsigned Line 70  int init_connection(char *serv, unsigned
70  #ifdef SSL_TLS  #ifdef SSL_TLS
71      }      }
72  #endif  #endif
73        
74    
75      return 0;      return 0;
76  }  }
# Line 85  int ssl_init(unsigned int protocol) Line 85  int ssl_init(unsigned int protocol)
85      int e;      int e;
86      SSL_CTX *ctx;      SSL_CTX *ctx;
87      SSL_METHOD *method = NULL;      SSL_METHOD *method = NULL;
88        
89      SSL_library_init();      SSL_library_init();
90        
91      switch (protocol) {      switch (protocol) {
92      case SSL_SSL_V2:      case SSL_SSL_V2:
93          method = SSLv2_client_method();          method = SSLv2_client_method();
# Line 99  int ssl_init(unsigned int protocol) Line 99  int ssl_init(unsigned int protocol)
99          method = TLSv1_client_method();          method = TLSv1_client_method();
100          break;          break;
101      }      }
102        
103      if (!(ctx = SSL_CTX_new(method)))      if (!(ctx = SSL_CTX_new(method)))
104          return ERROR_SSL;          return ERROR_SSL;
105        
106      if (!(ssl = SSL_new(ctx)))      if (!(ssl = SSL_new(ctx)))
107          return ERROR_SSL;          return ERROR_SSL;
108        
109      SSL_set_fd(ssl, sock);      SSL_set_fd(ssl, sock);
110    
111      e = SSL_connect(ssl);      e = SSL_connect(ssl);
112        
113      if (e <= 0) {      if (e <= 0) {
114          error("imapfilter: initiating SSL connection; %s",          error("imapfilter: initiating SSL connection; %s",
115                ERR_error_string(e, NULL));                ERR_error_string(e, NULL));
116          return ERROR_SSL;          return ERROR_SSL;
117      }      }
       
118      SSL_CTX_free(ctx);      SSL_CTX_free(ctx);
119    
120      return 0;      return 0;
# Line 132  int close_connection(void) Line 131  int close_connection(void)
131      if (ssl) {      if (ssl) {
132          SSL_shutdown(ssl);          SSL_shutdown(ssl);
133          SSL_free(ssl);          SSL_free(ssl);
         ssl = NULL;  
134      }      }
135  #endif  #endif
136    
# Line 173  int socket_read(char *buf) Line 171  int socket_read(char *buf)
171          else          else
172  #endif  #endif
173              e = read(sock, buf, RESPONSE_BUF - 1);              e = read(sock, buf, RESPONSE_BUF - 1);
174            
175          fcntl(sock, F_SETFL, flags);          fcntl(sock, F_SETFL, flags);
176    
177  #ifdef SSL_TLS  #ifdef SSL_TLS
# Line 183  int socket_read(char *buf) Line 181  int socket_read(char *buf)
181                        ERR_error_string(e, NULL));                        ERR_error_string(e, NULL));
182          } else          } else
183  #endif  #endif
184              if(e == -1)          if (e == -1)
185                  fatal(ERROR_NETWORK, "imapfilter: reading data; %s",              fatal(ERROR_NETWORK, "imapfilter: reading data; %s",
186                        strerror(errno));                    strerror(errno));
187            
188          return 0;          return 0;
189      }      }
       
190      fcntl(sock, F_SETFL, flags);      fcntl(sock, F_SETFL, flags);
191    
192      fatal(ERROR_NETWORK, "imapfilter: waiting input from socket; %s\n",      fatal(ERROR_NETWORK, "imapfilter: waiting input from socket; %s\n",
# Line 218  int socket_write(char *data) Line 215  int socket_write(char *data)
215      if (write(sock, data, strlen(data)) == -1)      if (write(sock, data, strlen(data)) == -1)
216          fatal(ERROR_NETWORK, "imapfilter: sending data; %s",          fatal(ERROR_NETWORK, "imapfilter: sending data; %s",
217                strerror(errno));                strerror(errno));
218        
219      return 0;      return 0;
220  }  }
   

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26