summaryrefslogtreecommitdiff
path: root/imap/src/osdep/nt
diff options
context:
space:
mode:
authorEduardo Chappa <chappa@washington.edu>2013-11-02 02:51:18 -0600
committerEduardo Chappa <chappa@washington.edu>2013-11-02 02:51:18 -0600
commit7fe712882b909931088a318c08041b0e7974a000 (patch)
tree2770f9b084e2efc7fc55e96e9bf4352cf2ff33a3 /imap/src/osdep/nt
parentbdfc834badee92ceeb2befe02f1d065ced5b9ddf (diff)
downloadalpine-7fe712882b909931088a318c08041b0e7974a000.tar.xz
* Update to version 2.19.1
* Upgrade UW-IMAP to Panda IMAP from https://github.com/jonabbey/panda-imap. * Replace tabs by spaces in From and Subject fields to control for size in screen of these fields. Change only in index screen display.
Diffstat (limited to 'imap/src/osdep/nt')
-rw-r--r--[-rwxr-xr-x]imap/src/osdep/nt/drivers.bat0
-rw-r--r--[-rwxr-xr-x]imap/src/osdep/nt/drivraux.bat0
-rw-r--r--imap/src/osdep/nt/dummynt.c36
-rw-r--r--imap/src/osdep/nt/env_nt.c36
-rw-r--r--imap/src/osdep/nt/env_nt.h27
-rw-r--r--imap/src/osdep/nt/ip4_nt.c47
-rw-r--r--imap/src/osdep/nt/ip6_nt.c141
-rw-r--r--[-rwxr-xr-x]imap/src/osdep/nt/mkautaux.bat0
-rw-r--r--[-rwxr-xr-x]imap/src/osdep/nt/mkauths.bat0
-rw-r--r--[-rwxr-xr-x]imap/src/osdep/nt/setproto.bat0
-rw-r--r--imap/src/osdep/nt/ssl_none.c43
-rw-r--r--imap/src/osdep/nt/ssl_nt.c32
-rw-r--r--imap/src/osdep/nt/ssl_old.c32
-rw-r--r--imap/src/osdep/nt/ssl_w2k.c34
-rw-r--r--imap/src/osdep/nt/tcp_nt.c74
15 files changed, 261 insertions, 241 deletions
diff --git a/imap/src/osdep/nt/drivers.bat b/imap/src/osdep/nt/drivers.bat
index 0964f537..0964f537 100755..100644
--- a/imap/src/osdep/nt/drivers.bat
+++ b/imap/src/osdep/nt/drivers.bat
diff --git a/imap/src/osdep/nt/drivraux.bat b/imap/src/osdep/nt/drivraux.bat
index 30649a78..30649a78 100755..100644
--- a/imap/src/osdep/nt/drivraux.bat
+++ b/imap/src/osdep/nt/drivraux.bat
diff --git a/imap/src/osdep/nt/dummynt.c b/imap/src/osdep/nt/dummynt.c
index b44d271f..09a72f7a 100644
--- a/imap/src/osdep/nt/dummynt.c
+++ b/imap/src/osdep/nt/dummynt.c
@@ -1,13 +1,5 @@
/* ========================================================================
- * Copyright 1988-2007 University of Washington
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- *
+ * Copyright 2008-2011 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,20 @@
* Program: Dummy routines for NT
*
* Author: Mark Crispin
- * Networks and Distributed Computing
- * Computing & Communications
- * University of Washington
- * Administration Building, AG-44
- * Seattle, WA 98195
- * Internet: MRC@CAC.Washington.EDU
*
* Date: 24 May 1993
- * Last Edited: 1 June 2007
+ * Last Edited: 8 April 2011
+ *
+ * Previous versions of this file were
+ *
+ * Copyright 1988-2007 University of Washington
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
*/
@@ -203,10 +200,10 @@ void dummy_list (MAILSTREAM *stream,char *ref,char *pat)
void dummy_lsub (MAILSTREAM *stream,char *ref,char *pat)
{
void *sdb = NIL;
- char *s,*t,test[MAILTMPLEN];
+ char *s,*t,test[MAILTMPLEN],tmp[MAILTMPLEN];
int showuppers = pat[strlen (pat) - 1] == '%';
/* get canonical form of name */
- if (dummy_canonicalize (test,ref,pat) && (s = sm_read (&sdb))) do
+ if (dummy_canonicalize (test,ref,pat) && (s = sm_read (tmp,&sdb))) do
if (*s != '{') {
if (pmatch_full (s,test,'\\')) {
if (pmatch (s,"INBOX")) mm_lsub (stream,NIL,s,LATT_NOINFERIORS);
@@ -217,7 +214,8 @@ void dummy_lsub (MAILSTREAM *stream,char *ref,char *pat)
if (pmatch_full (s,test,'\\')) mm_lsub (stream,'\\',s,LATT_NOSELECT);
}
}
- while (s = sm_read (&sdb)); /* until no more subscriptions */
+ /* until no more subscriptions */
+ while (s = sm_read (tmp,&sdb));
}
diff --git a/imap/src/osdep/nt/env_nt.c b/imap/src/osdep/nt/env_nt.c
index 18bc2369..6f961a95 100644
--- a/imap/src/osdep/nt/env_nt.c
+++ b/imap/src/osdep/nt/env_nt.c
@@ -1,13 +1,5 @@
/* ========================================================================
- * Copyright 1988-2008 University of Washington
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- *
+ * Copyright 2008-2010 Mark Crispin
* ========================================================================
*/
@@ -15,13 +7,19 @@
* Program: NT environment routines
*
* Author: Mark Crispin
- * UW Technology
- * University of Washington
- * Seattle, WA 98195
- * Internet: MRC@Washington.EDU
*
* Date: 1 August 1988
- * Last Edited: 15 February 2008
+ * Last Edited: 3 April 2010
+ *
+ * Previous versions of this file were:
+ *
+ * Copyright 1988-2008 University of Washington
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
*/
static char *myUserName = NIL; /* user name */
@@ -538,15 +536,13 @@ char *mylocalhost (void)
char tmp[MAILTMPLEN];
if (!wsa_initted++) { /* init Windows Sockets */
WSADATA wsock;
- if (WSAStartup (WINSOCK_VERSION,&wsock)) {
+ if (WSAStartup (WINSOCK_VERSION,&wsock))
wsa_initted = 0;
- return "random-pc"; /* try again later? */
- }
}
- myLocalHost = cpystr ((gethostname (tmp,MAILTMPLEN-1) == SOCKET_ERROR) ?
- "random-pc" : tcp_canonical (tmp));
+ if (wsa_initted && gethostname (tmp,MAILTMPLEN-1) != SOCKET_ERROR)
+ myLocalHost = tcp_canonical (tmp);
}
- return myLocalHost;
+ return myLocalHost ? myLocalHost : "random-pc";
}
/* Return my home directory name
diff --git a/imap/src/osdep/nt/env_nt.h b/imap/src/osdep/nt/env_nt.h
index 95575246..dd52f7bc 100644
--- a/imap/src/osdep/nt/env_nt.h
+++ b/imap/src/osdep/nt/env_nt.h
@@ -1,13 +1,5 @@
/* ========================================================================
- * Copyright 1988-2006 University of Washington
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- *
+ * Copyright 2008-2010 Mark Crispin
* ========================================================================
*/
@@ -23,7 +15,18 @@
* Internet: MRC@CAC.Washington.EDU
*
* Date: 1 August 1988
- * Last Edited: 30 August 2006
+ * Last Edited: 15 November 2010
+ *
+ * Previous versions of this file were:
+ *
+ * Copyright 1988-2006 University of Washington
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
*/
@@ -55,14 +58,14 @@ char *myusername_full (unsigned long *flags);
#define MU_ANONYMOUS 2
#define myusername() \
myusername_full (NIL)
-char *sysinbox ();
+char *sysinbox (void);
char *mailboxdir (char *dst,char *dir,char *name);
int lockname (char *lock,char *fname,int op);
char *lockdir (char *lock,char *first,char *last);
void unlockfd (int fd,char *lock);
long safe_write (int fd,char *buf,long nbytes);
void *mm_blocknotify (int reason,void *data);
-long random ();
+long random (void);
#if _MSC_VER < 700
#define getpid random
#endif
diff --git a/imap/src/osdep/nt/ip4_nt.c b/imap/src/osdep/nt/ip4_nt.c
index 23d399e1..4ebb32b1 100644
--- a/imap/src/osdep/nt/ip4_nt.c
+++ b/imap/src/osdep/nt/ip4_nt.c
@@ -1,4 +1,18 @@
/* ========================================================================
+ * Copyright 2008-2011 Mark Crispin
+ * ========================================================================
+ */
+
+/*
+ * Program: UNIX IPv4 routines
+ *
+ * Author: Mark Crispin
+ *
+ * Date: 18 December 2003
+ * Last Edited: 23 May 2011
+ *
+ * Previous versions of this file were:
+ *
* Copyright 1988-2006 University of Washington
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -11,20 +25,6 @@
* ========================================================================
*/
-/*
- * Program: UNIX IPv4 routines
- *
- * Author: Mark Crispin
- * Networks and Distributed Computing
- * Computing & Communications
- * University of Washington
- * Administration Building, AG-44
- * Seattle, WA 98195
- * Internet: MRC@CAC.Washington.EDU
- *
- * Date: 18 December 2003
- * Last Edited: 30 August 2006
- */
#define SADRLEN sizeof (struct sockaddr)
@@ -37,22 +37,23 @@
/* IP abstraction layer */
-char *ip_sockaddrtostring (struct sockaddr *sadr);
+char *ip_sockaddrtostring (struct sockaddr *sadr,char *buf);
long ip_sockaddrtoport (struct sockaddr *sadr);
void *ip_stringtoaddr (char *text,size_t *len,int *family);
struct sockaddr *ip_newsockaddr (size_t *len);
struct sockaddr *ip_sockaddr (int family,void *adr,size_t adrlen,
unsigned short port,size_t *len);
-char *ip_sockaddrtoname (struct sockaddr *sadr);
+char *ip_sockaddrtoname (struct sockaddr *sadr,char *buf);
void *ip_nametoaddr (char *name,size_t *len,int *family,char **canonical,
- void **next);
+ void **next,void **cleanup);
/* Return IP address string from socket address
* Accepts: socket address
+ * buffer
* Returns: IP address as name string
*/
-char *ip_sockaddrtostring (struct sockaddr *sadr)
+char *ip_sockaddrtostring (struct sockaddr *sadr,char *buf)
{
return (sadr->sa_family == PF_INET) ?
inet_ntoa (SADR4ADR (sadr)) : "NON-IPv4";
@@ -133,10 +134,11 @@ struct sockaddr *ip_sockaddr (int family,void *adr,size_t adrlen,
/* Return name from socket address
* Accepts: socket address
+ * buffer
* Returns: canonical name for that address or NIL if none
*/
-char *ip_sockaddrtoname (struct sockaddr *sadr)
+char *ip_sockaddrtoname (struct sockaddr *sadr,char *buf)
{
struct hostent *he;
return ((sadr->sa_family == PF_INET) &&
@@ -151,14 +153,17 @@ char *ip_sockaddrtoname (struct sockaddr *sadr)
* pointer to previous/returned address family
* pointer to previous/returned canonical name
* pointer to previous/return state for next-address calls
+ * pointer to cleanup
* Returns: address with length/family/canonical updated if needed, or NIL
*/
void *ip_nametoaddr (char *name,size_t *len,int *family,char **canonical,
- void **next)
+ void **next,void **cleanup)
{
char **adl,tmp[MAILTMPLEN];
struct hostent *he;
+ /* cleanup data never permitted */
+ if (cleanup && *cleanup) abort ();
if (name) { /* first lookup? */
/* yes, do case-independent lookup */
if ((strlen (name) < MAILTMPLEN) &&
@@ -166,7 +171,7 @@ void *ip_nametoaddr (char *name,size_t *len,int *family,char **canonical,
adl = he->h_addr_list;
if (len) *len = he->h_length;
if (family) *family = he->h_addrtype;
- if (canonical) *canonical = (char *) he->h_name;
+ if (canonical) *canonical = cpystr ((char *) he->h_name);
if (next) *next = (void *) adl;
}
else { /* error */
diff --git a/imap/src/osdep/nt/ip6_nt.c b/imap/src/osdep/nt/ip6_nt.c
index c15dfbc0..2727adb2 100644
--- a/imap/src/osdep/nt/ip6_nt.c
+++ b/imap/src/osdep/nt/ip6_nt.c
@@ -1,13 +1,5 @@
/* ========================================================================
- * Copyright 1988-2006 University of Washington
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- *
+ * Copyright 2008-2011 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,19 @@
* Program: UNIX IPv6 routines
*
* Author: Mark Crispin
- * Networks and Distributed Computing
- * Computing & Communications
- * University of Washington
- * Administration Building, AG-44
- * Seattle, WA 98195
- * Internet: MRC@CAC.Washington.EDU
*
* Date: 18 December 2003
- * Last Edited: 30 August 2006
+ * Last Edited: 30 July 2011
+ *
+ * Previous versions of this file were
+ *
+ * Copyright 1988-2006 University of Washington
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
*/
@@ -61,32 +57,32 @@
/* IP abstraction layer */
-char *ip_sockaddrtostring (struct sockaddr *sadr);
+char *ip_sockaddrtostring (struct sockaddr *sadr,char buf[NI_MAXHOST]);
long ip_sockaddrtoport (struct sockaddr *sadr);
void *ip_stringtoaddr (char *text,size_t *len,int *family);
struct sockaddr *ip_newsockaddr (size_t *len);
struct sockaddr *ip_sockaddr (int family,void *adr,size_t adrlen,
unsigned short port,size_t *len);
-char *ip_sockaddrtoname (struct sockaddr *sadr);
+char *ip_sockaddrtoname (struct sockaddr *sadr,char buf[NI_MAXHOST]);
void *ip_nametoaddr (char *name,size_t *len,int *family,char **canonical,
- void **next);
+ void **next,void **cleanup);
/* Return IP address string from socket address
* Accepts: socket address
+ * buffer
* Returns: IP address as name string
*/
-char *ip_sockaddrtostring (struct sockaddr *sadr)
+char *ip_sockaddrtostring (struct sockaddr *sadr,char buf[NI_MAXHOST])
{
- static char tmp[NI_MAXHOST];
switch (sadr->sa_family) {
case PF_INET: /* IPv4 */
- if (!getnameinfo (sadr,SADR4LEN,tmp,NI_MAXHOST,NIL,NIL,NI_NUMERICHOST))
- return tmp;
+ if (!getnameinfo (sadr,SADR4LEN,buf,NI_MAXHOST,NIL,NIL,NI_NUMERICHOST))
+ return buf;
break;
case PF_INET6: /* IPv6 */
- if (!getnameinfo (sadr,SADR6LEN,tmp,NI_MAXHOST,NIL,NIL,NI_NUMERICHOST))
- return tmp;
+ if (!getnameinfo (sadr,SADR6LEN,buf,NI_MAXHOST,NIL,NIL,NI_NUMERICHOST))
+ return buf;
break;
}
return "NON-IP";
@@ -120,20 +116,18 @@ void *ip_stringtoaddr (char *text,size_t *len,int *family)
{
char tmp[MAILTMPLEN];
- static struct addrinfo *hints;
+ struct addrinfo hints;
struct addrinfo *ai;
void *adr = NIL;
- if (!hints) { /* hints set up yet? */
- hints = (struct addrinfo *) /* one-time setup */
- memset (fs_get (sizeof (struct addrinfo)),0,sizeof (struct addrinfo));
- hints->ai_family = AF_UNSPEC;/* allow any address family */
- hints->ai_socktype = SOCK_STREAM;
+ /* initialize hints */
+ memset (&hints,NIL,sizeof (hints));
+ hints.ai_family = AF_UNSPEC;/* allow any address family */
+ hints.ai_socktype = SOCK_STREAM;
/* numeric name only */
- hints->ai_flags = AI_NUMERICHOST;
- }
+ hints.ai_flags = AI_NUMERICHOST;
/* case-independent lookup */
if (text && (strlen (text) < MAILTMPLEN) &&
- (!getaddrinfo (lcase (strcpy (tmp,text)),NIL,hints,&ai))) {
+ (!getaddrinfo (lcase (strcpy (tmp,text)),NIL,&hints,&ai))) {
switch (*family = ai->ai_family) {
case AF_INET: /* IPv4 */
adr = fs_get (*len = ADR4LEN);
@@ -199,20 +193,20 @@ struct sockaddr *ip_sockaddr (int family,void *adr,size_t adrlen,
/* Return name from socket address
* Accepts: socket address
+ * buffer
* Returns: canonical name for that address or NIL if none
*/
-char *ip_sockaddrtoname (struct sockaddr *sadr)
+char *ip_sockaddrtoname (struct sockaddr *sadr,char buf[NI_MAXHOST])
{
- static char tmp[NI_MAXHOST];
switch (sadr->sa_family) {
case PF_INET: /* IPv4 */
- if (!getnameinfo (sadr,SADR4LEN,tmp,NI_MAXHOST,NIL,NIL,NI_NAMEREQD))
- return tmp;
+ if (!getnameinfo (sadr,SADR4LEN,buf,NI_MAXHOST,NIL,NIL,NI_NAMEREQD))
+ return buf;
break;
case PF_INET6: /* IPv6 */
- if (!getnameinfo (sadr,SADR6LEN,tmp,NI_MAXHOST,NIL,NIL,NI_NAMEREQD))
- return tmp;
+ if (!getnameinfo (sadr,SADR6LEN,buf,NI_MAXHOST,NIL,NIL,NI_NAMEREQD))
+ return buf;
break;
}
return NIL;
@@ -224,38 +218,40 @@ char *ip_sockaddrtoname (struct sockaddr *sadr)
* pointer to previous/returned address family
* pointer to previous/returned canonical name
* pointer to previous/return state for next-address calls
+ * pointer to cleanup (or NIL to get canonical name only)
* Returns: address with length/family/canonical updated if needed, or NIL
*/
void *ip_nametoaddr (char *name,size_t *len,int *family,char **canonical,
- void **next)
+ void **next,void **cleanup)
{
+ char tmp[MAILTMPLEN];
struct addrinfo *cur = NIL;
- static struct addrinfo *hints;
- static struct addrinfo *ai = NIL;
- static char lcname[MAILTMPLEN];
- if (!hints) { /* hints set up yet? */
- hints = (struct addrinfo *) /* one-time setup */
- memset (fs_get (sizeof (struct addrinfo)),0,sizeof (struct addrinfo));
+ struct addrinfo hints;
+ void *ret = NIL;
+ /* initialize hints */
+ memset (&hints,NIL,sizeof (hints));
/* allow any address family */
- hints->ai_family = AF_UNSPEC;
- hints->ai_socktype = SOCK_STREAM;
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
/* need canonical name */
- hints->ai_flags = AI_CANONNAME;
- }
+ hints.ai_flags = AI_CANONNAME;
if (name) { /* name supplied? */
- if (ai) {
- freeaddrinfo (ai); /* free old addrinfo */
- ai = NIL;
+ struct addrinfo *aitmp = NIL;
+ if (!cleanup) cleanup = (void **) &aitmp;
+ else if (*cleanup) {
+ freeaddrinfo (*cleanup); /* free old addrinfo */
+ *cleanup = NIL;
}
/* case-independent lookup */
if ((strlen (name) < MAILTMPLEN) &&
- (!getaddrinfo (lcase (strcpy (lcname,name)),NIL,hints,&ai))) {
- cur = ai; /* current block */
+ (!getaddrinfo (lcase (strcpy (tmp,name)),NIL,&hints,
+ (struct addrinfo **) cleanup))) {
+ cur = *cleanup; /* current block */
if (canonical) /* set canonical name */
- *canonical = cur->ai_canonname ? cur->ai_canonname : lcname;
+ *canonical = cpystr (cur->ai_canonname ? cur->ai_canonname : tmp);
/* remember as next block */
- if (next) *next = (void *) ai;
+ if (next) *next = (void *) cur;
}
else { /* error */
cur = NIL;
@@ -264,25 +260,42 @@ void *ip_nametoaddr (char *name,size_t *len,int *family,char **canonical,
if (canonical) *canonical = NIL;
if (next) *next = NIL;
}
+ if (aitmp) { /* special call to get canonical name */
+ freeaddrinfo (aitmp);
+ if (len) *len = 0;
+ if (family) *family = 0;
+ if (next) *next = NIL;
+ return VOIDT; /* return only needs to be non-NIL */
+ }
}
+
/* return next in series */
else if (next && (cur = ((struct addrinfo *) *next)->ai_next)) {
*next = cur; /* set as last address */
/* set canonical in case changed */
- if (canonical && cur->ai_canonname) *canonical = cur->ai_canonname;
+ if (canonical && cur->ai_canonname) {
+ if (*canonical) fs_give ((void **) canonical);
+ *canonical = cpystr (cur->ai_canonname);
+ }
+ }
+ else if (*cleanup) {
+ freeaddrinfo (*cleanup); /* free old addrinfo */
+ *cleanup = NIL;
}
-
if (cur) { /* got data? */
if (family) *family = cur->ai_family;
switch (cur->ai_family) {
case AF_INET:
if (len) *len = ADR4LEN;
- return (void *) &SADR4ADR (cur->ai_addr);
+ ret = (void *) &SADR4ADR (cur->ai_addr);
+ break;
case AF_INET6:
if (len) *len = ADR6LEN;
- return (void *) &SADR6ADR (cur->ai_addr);
+ ret = (void *) &SADR6ADR (cur->ai_addr);
+ break;
+ default:
+ if (len) *len = 0; /* error return */
}
}
- if (len) *len = 0; /* error return */
- return NIL;
+ return ret;
}
diff --git a/imap/src/osdep/nt/mkautaux.bat b/imap/src/osdep/nt/mkautaux.bat
index c65022d2..c65022d2 100755..100644
--- a/imap/src/osdep/nt/mkautaux.bat
+++ b/imap/src/osdep/nt/mkautaux.bat
diff --git a/imap/src/osdep/nt/mkauths.bat b/imap/src/osdep/nt/mkauths.bat
index d8c5e360..d8c5e360 100755..100644
--- a/imap/src/osdep/nt/mkauths.bat
+++ b/imap/src/osdep/nt/mkauths.bat
diff --git a/imap/src/osdep/nt/setproto.bat b/imap/src/osdep/nt/setproto.bat
index ce7cb1ef..ce7cb1ef 100755..100644
--- a/imap/src/osdep/nt/setproto.bat
+++ b/imap/src/osdep/nt/setproto.bat
diff --git a/imap/src/osdep/nt/ssl_none.c b/imap/src/osdep/nt/ssl_none.c
index e4dedda7..a87c4be6 100644
--- a/imap/src/osdep/nt/ssl_none.c
+++ b/imap/src/osdep/nt/ssl_none.c
@@ -1,13 +1,5 @@
/* ========================================================================
- * Copyright 1988-2006 University of Washington
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- *
+ * Copyright 2008 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,20 @@
* Program: Dummy (no SSL) authentication/encryption module
*
* Author: Mark Crispin
- * Networks and Distributed Computing
- * Computing & Communications
- * University of Washington
- * Administration Building, AG-44
- * Seattle, WA 98195
- * Internet: MRC@CAC.Washington.EDU
*
* Date: 7 February 2001
- * Last Edited: 30 August 2006
+ * Last Edited: 19 November 2008
+ *
+ * Previous versions of this file were
+ *
+ * Copyright 1988-2006 University of Washington
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
*/
/* Init server for SSL
@@ -53,7 +50,12 @@ char *ssl_start_tls (char *server)
int PBIN (void)
{
- return getchar ();
+ int ret;
+ do {
+ clearerr (stdin);
+ ret = getchar ();
+ } while ((ret == EOF) && !feof (stdin) && ferror (stdin) &&(errno == EINTR));
+ return ret;
}
@@ -65,7 +67,12 @@ int PBIN (void)
char *PSIN (char *s,int n)
{
- return fgets (s,n,stdin);
+ char *ret;
+ do {
+ clearerr (stdin);
+ ret = fgets (s,n,stdin);
+ } while (!ret && !feof (stdin) && ferror (stdin) && (errno == EINTR));
+ return ret;
}
diff --git a/imap/src/osdep/nt/ssl_nt.c b/imap/src/osdep/nt/ssl_nt.c
index c7efa486..7c2248d1 100644
--- a/imap/src/osdep/nt/ssl_nt.c
+++ b/imap/src/osdep/nt/ssl_nt.c
@@ -1,13 +1,5 @@
/* ========================================================================
- * Copyright 1988-2008 University of Washington
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- *
+ * Copyright 2008-2009 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,20 @@
* Program: SSL authentication/encryption module for Windows 9x and NT
*
* Author: Mark Crispin
- * Networks and Distributed Computing
- * Computing & Communications
- * University of Washington
- * Administration Building, AG-44
- * Seattle, WA 98195
- * Internet: MRC@CAC.Washington.EDU
*
* Date: 22 September 1998
- * Last Edited: 13 January 2008
+ * Last Edited: 8 November 2009
+ *
+ * Previous versions of this file were
+ *
+ * Copyright 1988-2008 University of Washington
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
*/
#define SECURITY_WIN32
@@ -536,6 +533,7 @@ long ssl_getdata (SSLSTREAM *stream)
SecBufferDesc msg;
size_t i;
size_t n = 0; /* initially no bytes to decrypt */
+ if (!stream->tcpstream) return NIL;
do { /* yes, make sure have data from TCP */
if (stream->iextractr) { /* have previous unread data? */
memcpy (stream->ibuf + n,stream->iextraptr,stream->iextractr);
@@ -682,7 +680,7 @@ static long ssl_abort (SSLSTREAM *stream)
char *ssl_host (SSLSTREAM *stream)
{
- return tcp_host (stream->tcpstream);
+ return stream ? tcp_host (stream->tcpstream) : "UNKNOWN";
}
diff --git a/imap/src/osdep/nt/ssl_old.c b/imap/src/osdep/nt/ssl_old.c
index 121bd02e..5d00b48b 100644
--- a/imap/src/osdep/nt/ssl_old.c
+++ b/imap/src/osdep/nt/ssl_old.c
@@ -1,13 +1,5 @@
/* ========================================================================
- * Copyright 1988-2008 University of Washington
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- *
+ * Copyright 2008-2009 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,20 @@
* Program: SSL authentication/encryption module for Windows 9x and NT
*
* Author: Mark Crispin
- * Networks and Distributed Computing
- * Computing & Communications
- * University of Washington
- * Administration Building, AG-44
- * Seattle, WA 98195
- * Internet: MRC@CAC.Washington.EDU
*
* Date: 22 September 1998
- * Last Edited: 13 January 2008
+ * Last Edited: 9 November 2009
+ *
+ * Previous versions of this file were
+ *
+ * Copyright 1988-2008 University of Washington
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
*/
#define SECURITY_WIN32
@@ -442,6 +439,7 @@ long ssl_getdata (SSLSTREAM *stream)
SecBufferDesc msg;
size_t i;
size_t n = 0; /* initially no bytes to decrypt */
+ if (!stream->tcpstream) return NIL;
do { /* yes, make sure have data from TCP */
if (stream->iextractr) { /* have previous unread data? */
memcpy (stream->ibuf + n,stream->iextraptr,stream->iextractr);
@@ -586,7 +584,7 @@ static long ssl_abort (SSLSTREAM *stream)
char *ssl_host (SSLSTREAM *stream)
{
- return tcp_host (stream->tcpstream);
+ return stream ? tcp_host (stream->tcpstream) : "UNKNOWN";
}
diff --git a/imap/src/osdep/nt/ssl_w2k.c b/imap/src/osdep/nt/ssl_w2k.c
index f5d8d1f5..ed469fa8 100644
--- a/imap/src/osdep/nt/ssl_w2k.c
+++ b/imap/src/osdep/nt/ssl_w2k.c
@@ -1,29 +1,26 @@
/* ========================================================================
- * Copyright 1988-2008 University of Washington
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- *
+ * Copyright 2008-2009 Mark Crispin
* ========================================================================
*/
/*
- * Program: SSL authentication/encryption module for Windows 2000
+ * Program: SSL authentication/encryption module for Windows 9x and NT
*
* Author: Mark Crispin
- * Networks and Distributed Computing
- * Computing & Communications
- * University of Washington
- * Administration Building, AG-44
- * Seattle, WA 98195
- * Internet: MRC@CAC.Washington.EDU
*
* Date: 22 September 1998
- * Last Edited: 13 January 2008
+ * Last Edited: 9 November 2009
+ *
+ * Previous versions of this file were
+ *
+ * Copyright 1988-2008 University of Washington
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
*/
#define SECURITY_WIN32
@@ -499,6 +496,7 @@ long ssl_getdata (SSLSTREAM *stream)
SecBufferDesc msg;
size_t i;
size_t n = 0; /* initially no bytes to decrypt */
+ if (!stream->tcpstream) return NIL;
do { /* yes, make sure have data from TCP */
if (stream->iextractr) { /* have previous unread data? */
memcpy (stream->ibuf + n,stream->iextraptr,stream->iextractr);
@@ -644,7 +642,7 @@ static long ssl_abort (SSLSTREAM *stream)
char *ssl_host (SSLSTREAM *stream)
{
- return tcp_host (stream->tcpstream);
+ return stream ? tcp_host (stream->tcpstream) : "UNKNOWN";
}
diff --git a/imap/src/osdep/nt/tcp_nt.c b/imap/src/osdep/nt/tcp_nt.c
index a6d735dc..aeb05a3e 100644
--- a/imap/src/osdep/nt/tcp_nt.c
+++ b/imap/src/osdep/nt/tcp_nt.c
@@ -1,13 +1,5 @@
/* ========================================================================
- * Copyright 1988-2007 University of Washington
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- *
+ * Copyright 2008-2011 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,20 @@
* Program: Winsock TCP/IP routines
*
* Author: Mark Crispin from Mike Seibel's Winsock code
- * Networks and Distributed Computing
- * Computing & Communications
- * University of Washington
- * Administration Building, AG-44
- * Seattle, WA 98195
- * Internet: MRC@CAC.Washington.EDU
*
* Date: 11 April 1989
- * Last Edited: 13 January 2007
+ * Last Edited: 3 August 2011
+ *
+ * Previous versions of this file were:
+ *
+ * Copyright 1988-2007 University of Washington
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
*/
#include "ip_nt.c"
@@ -119,9 +116,11 @@ TCPSTREAM *tcp_open (char *host,char *service,unsigned long port)
int i,family;
SOCKET sock = INVALID_SOCKET;
int silent = (port & NET_SILENT) ? T : NIL;
- char *s,*hostname,tmp[MAILTMPLEN];
+ char *s,tmp[MAILTMPLEN];
+ char *hostname = NIL;
void *adr,*next;
size_t adrlen;
+ void *cleanup = NIL;
struct servent *sv = NIL;
blocknotify_t bn = (blocknotify_t) mail_parameters (NIL,GET_BLOCKNOTIFY,NIL);
if (!wsa_initted++) { /* init Windows Sockets */
@@ -147,7 +146,7 @@ TCPSTREAM *tcp_open (char *host,char *service,unsigned long port)
if (adr = ip_stringtoaddr (tmp,&adrlen,&family)) {
(*bn) (BLOCK_TCPOPEN,NIL);
sock = tcp_socket_open (family,adr,adrlen,(unsigned short) port,tmp,
- hostname = host);
+ hostname = cpystr(host));
(*bn) (BLOCK_NONE,NIL);
fs_give ((void **) &adr);
}
@@ -160,7 +159,7 @@ TCPSTREAM *tcp_open (char *host,char *service,unsigned long port)
mm_log (tmp,TCPDEBUG);
}
(*bn) (BLOCK_DNSLOOKUP,NIL);/* look up name */
- if (!(s = ip_nametoaddr (host,&adrlen,&family,&hostname,&next)))
+ if (!(s = ip_nametoaddr (host,&adrlen,&family,&hostname,&next,&cleanup)))
sprintf (tmp,"Host not found (#%d): %s",WSAGetLastError (),host);
(*bn) (BLOCK_NONE,NIL);
if (s) { /* DNS resolution won? */
@@ -171,16 +170,19 @@ TCPSTREAM *tcp_open (char *host,char *service,unsigned long port)
(*bn) (BLOCK_TCPOPEN,NIL);
if (((sock = tcp_socket_open (family,s,adrlen,(unsigned short) port,
tmp,hostname)) == INVALID_SOCKET) &&
- (s = ip_nametoaddr (NIL,&adrlen,&family,&hostname,&next)) &&
- !silent) mm_log (tmp,WARN);
+ (s = ip_nametoaddr (NIL,&adrlen,&family,&hostname,&next,
+ &cleanup)) && !silent)
+ mm_log (tmp,WARN);
(*bn) (BLOCK_NONE,NIL);
} while ((sock == INVALID_SOCKET) && s);
wsa_sock_open--; /* undo protection */
}
+ ip_nametoaddr (NIL,NIL,NIL,NIL,NIL,&cleanup);
}
if (sock == INVALID_SOCKET) { /* do possible cleanup action */
if (!silent) mm_log (tmp,ERROR);
tcp_close_socket (&sock);
+ if (hostname) fs_give ((void **) &hostname);
}
else { /* got a socket, create TCP/IP stream */
stream = (TCPSTREAM *) memset (fs_get (sizeof (TCPSTREAM)),0,
@@ -189,8 +191,7 @@ TCPSTREAM *tcp_open (char *host,char *service,unsigned long port)
/* init socket */
stream->tcpsi = stream->tcpso = sock;
stream->ictr = 0; /* init input counter */
- /* copy official host name */
- stream->host = cpystr (hostname);
+ stream->host = hostname; /* copy official host name */
if (tcpdebug) mm_log ("Stream open and ready for read",TCPDEBUG);
}
return stream; /* return success */
@@ -215,14 +216,13 @@ int tcp_socket_open (int family,void *adr,size_t adrlen,unsigned short port,
DWORD eo;
WSAEVENT event;
WSANETWORKEVENTS events;
+ char buf[NI_MAXHOST];
unsigned long cmd = 0;
- struct protoent *pt = getprotobyname ("tcp");
struct sockaddr *sadr = ip_sockaddr (family,adr,adrlen,port,&len);
- sprintf (tmp,"Trying IP address [%s]",ip_sockaddrtostring (sadr));
+ sprintf (tmp,"Trying IP address [%s]",ip_sockaddrtostring (sadr,buf));
mm_log (tmp,NIL);
/* get a TCP stream */
- if ((sock = socket (sadr->sa_family,SOCK_STREAM,pt ? pt->p_proto : 0)) ==
- INVALID_SOCKET)
+ if ((sock = socket (sadr->sa_family,SOCK_STREAM,0)) == INVALID_SOCKET)
sprintf (tmp,"Unable to create TCP socket (%d)",WSAGetLastError ());
else {
/* On Windows, FD_SETSIZE is the number of descriptors which can be
@@ -728,12 +728,13 @@ char *tcp_localhost (TCPSTREAM *stream)
char *tcp_clientaddr ()
{
if (!myClientAddr) {
+ char buf[NI_MAXHOST];
size_t sadrlen;
struct sockaddr *sadr = ip_newsockaddr (&sadrlen);
if ((getpeername (0,sadr,(void *) &sadrlen) == SOCKET_ERROR) ||
(sadrlen <= 0)) myClientAddr = cpystr ("UNKNOWN");
else { /* get stdin's peer name */
- myClientAddr = cpystr (ip_sockaddrtostring (sadr));
+ myClientAddr = cpystr (ip_sockaddrtostring (sadr,buf));
if (myClientPort < 0) myClientPort = ip_sockaddrtoport (sadr);
}
fs_give ((void **) &sadr);
@@ -749,13 +750,14 @@ char *tcp_clientaddr ()
char *tcp_clienthost ()
{
if (!myClientHost) {
+ char buf[NI_MAXHOST];
size_t sadrlen;
struct sockaddr *sadr = ip_newsockaddr (&sadrlen);
if ((getpeername (0,sadr,(void *) &sadrlen) == SOCKET_ERROR) ||
(sadrlen <= 0)) myClientHost = cpystr ("UNKNOWN");
else { /* get stdin's peer name */
myClientHost = tcp_name (sadr,T);
- if (!myClientAddr) myClientAddr = cpystr (ip_sockaddrtostring (sadr));
+ if (!myClientAddr) myClientAddr = cpystr (ip_sockaddrtostring(sadr,buf));
if (myClientPort < 0) myClientPort = ip_sockaddrtoport (sadr);
}
fs_give ((void **) &sadr);
@@ -781,6 +783,7 @@ long tcp_clientport ()
char *tcp_serveraddr ()
{
if (!myServerAddr) {
+ char buf[NI_MAXHOST];
size_t sadrlen;
struct sockaddr *sadr = ip_newsockaddr (&sadrlen);
if (!wsa_initted++) { /* init Windows Sockets */
@@ -793,7 +796,7 @@ char *tcp_serveraddr ()
if ((getsockname (0,sadr,(void *) &sadrlen) == SOCKET_ERROR) ||
(sadrlen <= 0)) myServerAddr = cpystr ("UNKNOWN");
else { /* get stdin's name */
- myServerAddr = cpystr (ip_sockaddrtostring (sadr));
+ myServerAddr = cpystr (ip_sockaddrtostring (sadr,buf));
if (myServerPort < 0) myServerPort = ip_sockaddrtoport (sadr);
}
fs_give ((void **) &sadr);
@@ -809,6 +812,7 @@ char *tcp_serveraddr ()
char *tcp_serverhost ()
{
if (!myServerHost) { /* once-only */
+ char buf[NI_MAXHOST];
size_t sadrlen;
struct sockaddr *sadr = ip_newsockaddr (&sadrlen);
if (!wsa_initted++) { /* init Windows Sockets */
@@ -823,7 +827,7 @@ char *tcp_serverhost ()
(sadrlen <= 0)) myServerHost = cpystr (mylocalhost ());
else { /* get stdin's name */
myServerHost = tcp_name (sadr,NIL);
- if (!myServerAddr) myServerAddr = cpystr (ip_sockaddrtostring (sadr));
+ if (!myServerAddr) myServerAddr = cpystr (ip_sockaddrtostring(sadr,buf));
if (myServerPort < 0) myServerPort = ip_sockaddrtoport (sadr);
}
fs_give ((void **) &sadr);
@@ -859,7 +863,7 @@ char *tcp_canonical (char *name)
mm_log (host,TCPDEBUG);
}
/* get canonical name */
- if (!ip_nametoaddr (name,NIL,NIL,&ret,NIL)) ret = name;
+ if (!ip_nametoaddr (name,NIL,NIL,&ret,NIL,NIL)) ret = cpystr (name);
(*bn) (BLOCK_NONE,NIL); /* alarms OK now */
if (tcpdebug) mm_log ("DNS canonicalization done",TCPDEBUG);
return ret;
@@ -874,8 +878,8 @@ char *tcp_canonical (char *name)
char *tcp_name (struct sockaddr *sadr,long flag)
{
- char *ret,*t,adr[MAILTMPLEN],tmp[MAILTMPLEN];
- sprintf (ret = adr,"[%.80s]",ip_sockaddrtostring (sadr));
+ char *ret,*t,adr[MAILTMPLEN],tmp[MAILTMPLEN],buf[NI_MAXHOST];
+ sprintf (ret = adr,"[%.80s]",ip_sockaddrtostring (sadr,buf));
if (allowreversedns) {
blocknotify_t bn = (blocknotify_t)mail_parameters(NIL,GET_BLOCKNOTIFY,NIL);
if (tcpdebug) {
@@ -884,7 +888,7 @@ char *tcp_name (struct sockaddr *sadr,long flag)
}
(*bn) (BLOCK_DNSLOOKUP,NIL);/* quell alarms */
/* translate address to name */
- if (t = tcp_name_valid (ip_sockaddrtoname (sadr))) {
+ if (t = tcp_name_valid (ip_sockaddrtoname (sadr,buf))) {
/* produce verbose form if needed */
if (flag) sprintf (ret = tmp,"%s %s",t,adr);
else ret = t;