summaryrefslogtreecommitdiff
path: root/imap/src
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
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')
-rw-r--r--imap/src/c-client/auth_md5.c48
-rw-r--r--imap/src/c-client/imap4r1.c153
-rw-r--r--imap/src/c-client/mail.c98
-rw-r--r--imap/src/c-client/mail.h33
-rw-r--r--imap/src/c-client/misc.c53
-rw-r--r--imap/src/c-client/misc.h29
-rw-r--r--imap/src/c-client/nntp.c41
-rw-r--r--imap/src/c-client/pop3.c38
-rw-r--r--imap/src/c-client/rfc822.c69
-rw-r--r--imap/src/c-client/smanager.c37
-rw-r--r--imap/src/c-client/smtp.c57
-rw-r--r--imap/src/c-client/utf8.c77
-rw-r--r--imap/src/dmail/dmail.c35
-rw-r--r--imap/src/imapd/Makefile28
-rw-r--r--imap/src/imapd/imapd.c376
-rw-r--r--imap/src/mailutil/mailutil.c43
-rw-r--r--imap/src/mtest/mtest.c56
-rw-r--r--[-rwxr-xr-x]imap/src/osdep/amiga/drivers0
-rw-r--r--imap/src/osdep/amiga/dummy.c36
-rw-r--r--imap/src/osdep/amiga/env_ami.c34
-rw-r--r--imap/src/osdep/amiga/env_ami.h31
-rw-r--r--imap/src/osdep/amiga/mbx.c8
-rw-r--r--imap/src/osdep/amiga/mh.c35
-rw-r--r--imap/src/osdep/amiga/mix.c91
-rw-r--r--[-rwxr-xr-x]imap/src/osdep/amiga/mkauths0
-rw-r--r--imap/src/osdep/amiga/scandir.c32
-rw-r--r--imap/src/osdep/amiga/ssl_none.c43
-rw-r--r--imap/src/osdep/amiga/tcp_ami.c30
-rw-r--r--imap/src/osdep/dos/dummydos.c36
-rw-r--r--imap/src/osdep/dos/env_dos.h32
-rw-r--r--imap/src/osdep/dos/tcp_dos.c30
-rw-r--r--imap/src/osdep/dos/tcp_dwa.c32
-rw-r--r--imap/src/osdep/dos/tcp_wsk.c40
-rw-r--r--imap/src/osdep/mac/tcp_mac.c35
-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
-rw-r--r--imap/src/osdep/os2/dummyos2.c36
-rw-r--r--imap/src/osdep/os2/tcp_os2.c30
-rw-r--r--imap/src/osdep/tops-20/shortsym.h34
-rw-r--r--imap/src/osdep/tops-20/tcp_t20.c43
-rw-r--r--imap/src/osdep/unix/Makefile44
-rw-r--r--imap/src/osdep/unix/dummy.c36
-rw-r--r--imap/src/osdep/unix/env_unix.c64
-rw-r--r--imap/src/osdep/unix/env_unix.h31
-rw-r--r--imap/src/osdep/unix/flocklnx.c29
-rw-r--r--imap/src/osdep/unix/ip4_unix.c47
-rw-r--r--imap/src/osdep/unix/ip6_unix.c141
-rw-r--r--imap/src/osdep/unix/ipo_unix.c181
-rw-r--r--imap/src/osdep/unix/mbx.c8
-rw-r--r--imap/src/osdep/unix/mh.c35
-rw-r--r--imap/src/osdep/unix/mix.c91
-rw-r--r--imap/src/osdep/unix/os_bsf.c30
-rw-r--r--imap/src/osdep/unix/os_bsf.h33
-rw-r--r--imap/src/osdep/unix/os_bsi.c30
-rw-r--r--imap/src/osdep/unix/os_bsi.h34
-rw-r--r--imap/src/osdep/unix/os_lnx.c30
-rw-r--r--imap/src/osdep/unix/os_lnx.h33
-rw-r--r--imap/src/osdep/unix/os_osx.c31
-rw-r--r--imap/src/osdep/unix/os_osx.h35
-rw-r--r--imap/src/osdep/unix/os_qn6.c67
-rw-r--r--imap/src/osdep/unix/os_qn6.h76
-rw-r--r--imap/src/osdep/unix/os_slx.c30
-rw-r--r--imap/src/osdep/unix/os_slx.h33
-rw-r--r--imap/src/osdep/unix/scandir.c32
-rw-r--r--imap/src/osdep/unix/ssl_none.c43
-rw-r--r--imap/src/osdep/unix/ssl_unix.c50
-rw-r--r--imap/src/osdep/unix/sslstdio.c48
-rw-r--r--imap/src/osdep/unix/tcp_unix.c119
-rw-r--r--imap/src/osdep/vms/env_vms.h31
-rw-r--r--imap/src/osdep/vms/tcp_vmsl.c32
-rw-r--r--imap/src/osdep/vms/tcp_vmsm.c35
-rw-r--r--imap/src/osdep/vms/tcp_vmsn.c30
-rw-r--r--imap/src/osdep/wce/env_wce.h33
-rw-r--r--imap/src/osdep/wce/tcp_wce.c40
-rw-r--r--imap/src/tmail/tmail.c38
88 files changed, 2234 insertions, 1927 deletions
diff --git a/imap/src/c-client/auth_md5.c b/imap/src/c-client/auth_md5.c
index 29ab947d..f32ebc88 100644
--- a/imap/src/c-client/auth_md5.c
+++ b/imap/src/c-client/auth_md5.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: CRAM-MD5 authenticator
*
* 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: 21 October 1998
- * Last Edited: 30 January 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
+ *
*/
/* MD5 context */
@@ -49,7 +46,8 @@ long auth_md5_client (authchallenge_t challenger,authrespond_t responder,
char *auth_md5_server (authresponse_t responder,int argc,char *argv[]);
char *auth_md5_pwd (char *user);
char *apop_login (char *chal,char *user,char *md5,int argc,char *argv[]);
-char *hmac_md5 (char *text,unsigned long tl,char *key,unsigned long kl);
+char *hmac_md5 (char *hshbuf, char *text,unsigned long tl,char *key,
+ unsigned long kl);
void md5_init (MD5CONTEXT *ctx);
void md5_update (MD5CONTEXT *ctx,unsigned char *data,unsigned long len);
void md5_final (unsigned char *digest,MD5CONTEXT *ctx);
@@ -97,7 +95,7 @@ long auth_md5_client (authchallenge_t challenger,authrespond_t responder,
char *service,NETMBX *mb,void *stream,
unsigned long *trial,char *user)
{
- char pwd[MAILTMPLEN];
+ char pwd[MAILTMPLEN],hshbuf[2*MD5DIGLEN + 1];
void *challenge;
unsigned long clen;
long ret = NIL;
@@ -112,7 +110,7 @@ long auth_md5_client (authchallenge_t challenger,authrespond_t responder,
ret = LONGT; /* will get a BAD response back */
}
else { /* got password, build response */
- sprintf (pwd,"%.65s %.33s",user,hmac_md5 (challenge,clen,
+ sprintf (pwd,"%.65s %.33s",user,hmac_md5 (hshbuf,challenge,clen,
pwd,strlen (pwd)));
fs_give ((void **) &challenge);
/* send credentials, allow retry if OK */
@@ -146,7 +144,7 @@ static int md5try = MAXLOGINTRIALS;
char *auth_md5_server (authresponse_t responder,int argc,char *argv[])
{
char *ret = NIL;
- char *p,*u,*user,*authuser,*hash,chal[MAILTMPLEN];
+ char *p,*u,*user,*authuser,*hash,chal[MAILTMPLEN],hshbuf[2*MD5DIGLEN + 1];
unsigned long cl,pl;
/* generate challenge */
sprintf (chal,"<%lu.%lu@%s>",(unsigned long) getpid (),
@@ -161,7 +159,8 @@ char *auth_md5_server (authresponse_t responder,int argc,char *argv[])
/* get password */
if (p = auth_md5_pwd ((authuser && *authuser) ? authuser : user)) {
pl = strlen (p);
- u = (md5try && !strcmp (hash,hmac_md5 (chal,cl,p,pl))) ? user : NIL;
+ u = (md5try && !strcmp (hash,hmac_md5 (hshbuf,chal,cl,p,pl))) ?
+ user : NIL;
memset (p,0,pl); /* erase sensitive information */
fs_give ((void **) &p); /* flush erased password */
/* now log in for real */
@@ -265,17 +264,18 @@ char *apop_login (char *chal,char *user,char *md5,int argc,char *argv[])
/*
* RFC 2104 HMAC hashing
- * Accepts: text to hash
+ * Accepts: destination buffer of size 2*MD5DIGLEN + 1
+ * text to hash
* text length
* key
* key length
* Returns: hash as text, always
*/
-char *hmac_md5 (char *text,unsigned long tl,char *key,unsigned long kl)
+char *hmac_md5 (char *hshbuf, char *text,unsigned long tl,char *key,
+ unsigned long kl)
{
int i,j;
- static char hshbuf[2*MD5DIGLEN + 1];
char *s;
MD5CONTEXT ctx;
char *hex = "0123456789abcdef";
diff --git a/imap/src/c-client/imap4r1.c b/imap/src/c-client/imap4r1.c
index 48017cab..9c72e642 100644
--- a/imap/src/c-client/imap4r1.c
+++ b/imap/src/c-client/imap4r1.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-2011 Mark Crispin
* ========================================================================
*/
@@ -15,13 +7,19 @@
* Program: Interactive Message Access Protocol 4rev1 (IMAP4R1) routines
*
* Author: Mark Crispin
- * UW Technology
- * University of Washington
- * Seattle, WA 98195
- * Internet: MRC@CAC.Washington.EDU
*
* Date: 15 June 1988
- * Last Edited: 8 May 2008
+ * Last Edited: 3 October 2011
+ *
+ * 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
*
* This original version of this file is
* Copyright 1988 Stanford University
@@ -362,7 +360,7 @@ void *imap_parameters (long function,void *value)
if (((IMAPLOCAL *) ((MAILSTREAM *) value)->local)->cap.namespace &&
!((IMAPLOCAL *) ((MAILSTREAM *) value)->local)->namespace)
imap_send (((MAILSTREAM *) value),"NAMESPACE",NIL);
- value = (void *) &((IMAPLOCAL *) ((MAILSTREAM *) value)->local)->namespace;
+ value = (void *) ((IMAPLOCAL *) ((MAILSTREAM *) value)->local)->namespace;
break;
case GET_THREADERS:
value = (void *)
@@ -493,7 +491,7 @@ void imap_list (MAILSTREAM *stream,char *ref,char *pat)
void imap_lsub (MAILSTREAM *stream,char *ref,char *pat)
{
void *sdb = NIL;
- char *s,mbx[MAILTMPLEN];
+ char *s,mbx[MAILTMPLEN],tmp[MAILTMPLEN];
/* do it on the server */
imap_list_work (stream,"LSUB",ref,pat,NIL);
if (*pat == '{') { /* if remote pattern, must be IMAP */
@@ -506,9 +504,10 @@ void imap_lsub (MAILSTREAM *stream,char *ref,char *pat)
if (ref && *ref) sprintf (mbx,"%s%s",ref,pat);
else strcpy (mbx,pat);
- if (s = sm_read (&sdb)) do if (imap_valid (s) && pmatch (s,mbx))
+ if (s = sm_read (tmp,&sdb)) do if (imap_valid (s) && pmatch (s,mbx))
mm_lsub (stream,NIL,s,NIL);
- while (s = sm_read (&sdb)); /* until no more subscriptions */
+ /* until no more subscriptions */
+ while (s = sm_read (tmp,&sdb));
}
/* IMAP find list of mailboxes
@@ -965,7 +964,7 @@ MAILSTREAM *imap_open (MAILSTREAM *stream)
if (LOCAL->tls1) strcat (tmp,"/tls1");
if (LOCAL->tls1_1) strcat (tmp,"/tls1_1");
if (LOCAL->tls1_2) strcat (tmp,"/tls1_2");
- if (LOCAL->dtls1) strcat (tmp,"/dtls");
+ if (LOCAL->dtls1) strcat (tmp,"/dtls1");
if (LOCAL->tlssslv23) strcat (tmp,"/tls-sslv23");
if (LOCAL->notlsflag) strcat (tmp,"/notls");
if (LOCAL->sslflag) strcat (tmp,"/ssl");
@@ -3715,8 +3714,7 @@ void imap_parse_unsolicited (MAILSTREAM *stream,IMAPPARSEDREPLY *reply)
}
/* get message data type, canonicalize upper */
s = ucase (strtok_r (reply->text," ",&r));
- /* and locate the text after it */
- t = strtok_r (NIL,"\n",&r);
+ t = strtok_r (NIL,"\n",&r); /* and locate the text after it */
/* now take the action */
/* change in size of mailbox */
if (!strcmp (s,"EXISTS") && (msgno >= stream->nmsgs))
@@ -3731,7 +3729,7 @@ void imap_parse_unsolicited (MAILSTREAM *stream,IMAPPARSEDREPLY *reply)
mail_expunged (stream,msgno);
}
- else if ((!strcmp (s,"FETCH") || !strcmp (s,"STORE")) &&
+ else if (t && (!strcmp (s,"FETCH") || !strcmp (s,"STORE")) &&
msgno && (msgno <= stream->nmsgs)) {
char *prop;
GETS_DATA md;
@@ -3742,8 +3740,7 @@ void imap_parse_unsolicited (MAILSTREAM *stream,IMAPPARSEDREPLY *reply)
(imapenvelope_t) mail_parameters (stream,GET_IMAPENVELOPE,NIL);
++t; /* skip past open parenthesis */
/* parse Lisp-form property list */
- while (prop = (strtok_r (t," )",&r))) {
- t = strtok_r (NIL,"\n",&r);
+ while ((prop = (strtok_r (t," )",&r))) && (t = strtok_r (NIL,"\n",&r))) {
INIT_GETS (md,stream,elt->msgno,NIL,0,0);
e = NIL; /* not pointing at any envelope yet */
/* canonicalize property, parse it */
@@ -3892,6 +3889,11 @@ void imap_parse_unsolicited (MAILSTREAM *stream,IMAPPARSEDREPLY *reply)
}
if (e && *e) env = *e; /* note envelope if we got one */
}
+ if (prop) {
+ sprintf (LOCAL->tmp,"Missing data for property: %.80s",prop);
+ mm_notify (stream,LOCAL->tmp,WARN);
+ stream->unhealthy = T;
+ }
/* do callback if requested */
if (ie && env) (*ie) (stream,msgno,env);
}
@@ -4278,17 +4280,7 @@ void imap_parse_response (MAILSTREAM *stream,char *text,long errflg,long ntfy)
if (s = strchr (strncpy (t = LOCAL->tmp,s,i),' ')) *s++ = '\0';
if (s) { /* have argument? */
ntfy = NIL; /* suppress mm_notify if normal SELECT data */
- if (!compare_cstring (t,"UIDVALIDITY") &&
- ((j = strtoul (s,NIL,10)) != stream->uid_validity)) {
- mailcache_t mc = (mailcache_t) mail_parameters (NIL,GET_CACHE,NIL);
- stream->uid_validity = j;
- /* purge any UIDs in cache */
- for (j = 1; j <= stream->nmsgs; j++)
- if (elt = (MESSAGECACHE *) (*mc) (stream,j,CH_ELT))
- elt->private.uid = 0;
- }
- else if (!compare_cstring (t,"UIDNEXT"))
- stream->uid_last = strtoul (s,NIL,10) - 1;
+ if (!compare_cstring (t,"CAPABILITY")) imap_parse_capabilities(stream,s);
else if (!compare_cstring (t,"PERMANENTFLAGS") && (*s == '(') &&
(t[i-1] == ')')) {
t[i-1] = '\0'; /* tie off flags */
@@ -4312,8 +4304,19 @@ void imap_parse_response (MAILSTREAM *stream,char *text,long errflg,long ntfy)
while (s = strtok_r (NIL," ",&r));
}
- else if (!compare_cstring (t,"CAPABILITY"))
- imap_parse_capabilities (stream,s);
+ else if (!compare_cstring (t,"UIDVALIDITY") && (j = strtoul (s,NIL,10))){
+ /* do this in separate if because of ntfy */
+ if (j != stream->uid_validity) {
+ mailcache_t mc = (mailcache_t) mail_parameters (NIL,GET_CACHE,NIL);
+ stream->uid_validity = j;
+ /* purge any UIDs in cache */
+ for (j = 1; j <= stream->nmsgs; j++)
+ if (elt = (MESSAGECACHE *) (*mc) (stream,j,CH_ELT))
+ elt->private.uid = 0;
+ }
+ }
+ else if (!compare_cstring (t,"UIDNEXT"))
+ stream->uid_last = strtoul (s,NIL,10) - 1;
else if ((j = LEVELUIDPLUS (stream) && LOCAL->appendmailbox) &&
!compare_cstring (t,"COPYUID") &&
(cu = (copyuid_t) mail_parameters (NIL,GET_COPYUID,NIL)) &&
@@ -4574,9 +4577,10 @@ void imap_parse_envelope (MAILSTREAM *stream,ENVELOPE **env,
unsigned char **txtptr,IMAPPARSEDREPLY *reply)
{
ENVELOPE *oenv = *env;
- char c = *((*txtptr)++); /* grab first character */
+ char c = **txtptr; /* grab first character */
/* ignore leading spaces */
- while (c == ' ') c = *((*txtptr)++);
+ while (c == ' ') c = *++*txtptr;
+ if (c) ++*txtptr; /* skip past first character */
switch (c) { /* dispatch on first character */
case '(': /* if envelope S-expression */
*env = mail_newenvelope (); /* parse the new envelope */
@@ -4639,7 +4643,7 @@ ADDRESS *imap_parse_adrlist (MAILSTREAM *stream,unsigned char **txtptr,
char c = **txtptr; /* sniff at first character */
/* ignore leading spaces */
while (c == ' ') c = *++*txtptr;
- ++*txtptr; /* skip past open paren */
+ if (c) ++*txtptr; /* skip past open paren */
switch (c) {
case '(': /* if envelope S-expression */
adr = imap_parse_address (stream,txtptr,reply);
@@ -4786,11 +4790,11 @@ void imap_parse_flags (MAILSTREAM *stream,MESSAGECACHE *elt,
elt->user_flags = NIL; /* zap old flag values */
elt->seen = elt->deleted = elt->flagged = elt->answered = elt->draft =
elt->recent = NIL;
- while (c != ')') { /* parse list of flags */
+ do { /* parse list of flags */
/* point at a flag */
while (*(flag = ++*txtptr) == ' ');
/* scan for end of flag */
- while (**txtptr != ' ' && **txtptr != ')') ++*txtptr;
+ while (**txtptr && (**txtptr != ' ') && (**txtptr != ')')) ++*txtptr;
c = **txtptr; /* save delimiter */
**txtptr = '\0'; /* tie off flag */
if (!*flag) break; /* null flag */
@@ -4805,8 +4809,12 @@ void imap_parse_flags (MAILSTREAM *stream,MESSAGECACHE *elt,
}
/* otherwise user flag */
else elt->user_flags |= imap_parse_user_flag (stream,flag);
+ } while (c && (c != ')'));
+ if (c) ++*txtptr; /* bump past delimiter */
+ else {
+ mm_notify (stream,"Unterminated flags list",WARN);
+ stream->unhealthy = T;
}
- ++*txtptr; /* bump past delimiter */
if (!old.valid || (old.seen != elt->seen) ||
(old.deleted != elt->deleted) || (old.flagged != elt->flagged) ||
(old.answered != elt->answered) || (old.draft != elt->draft) ||
@@ -4899,7 +4907,7 @@ unsigned char *imap_parse_string (MAILSTREAM *stream,unsigned char **txtptr,
(readprogress_t) mail_parameters (NIL,GET_READPROGRESS,NIL);
/* ignore leading spaces */
while (c == ' ') c = *++*txtptr;
- st = ++*txtptr; /* remember start of string */
+ if (c) st = ++*txtptr; /* remember start of string */
switch (c) {
case '"': /* if quoted string */
i = 0; /* initial byte count */
@@ -4947,14 +4955,21 @@ unsigned char *imap_parse_string (MAILSTREAM *stream,unsigned char **txtptr,
if (len) *len = 0;
break;
case '{': /* if literal string */
+ if (!isdigit (**txtptr)) {
+ sprintf (LOCAL->tmp,"Invalid server literal length %.80s",*txtptr);
+ mm_notify (stream,LOCAL->tmp,WARN);
+ stream->unhealthy = T; /* read and discard */
+ i = 0;
+ }
/* get size of string */
- if ((i = strtoul (*txtptr,(char **) txtptr,10)) > MAXSERVERLIT) {
+ else if ((i = strtoul (*txtptr,(char **) txtptr,10)) > MAXSERVERLIT) {
sprintf (LOCAL->tmp,"Absurd server literal length %lu",i);
mm_notify (stream,LOCAL->tmp,WARN);
stream->unhealthy = T; /* read and discard */
- do net_getbuffer (LOCAL->netstream,j = min (i,(long) IMAPTMPLEN - 1),
- LOCAL->tmp);
- while (i -= j);
+ for (j = IMAPTMPLEN - 1; i; i -= j) {
+ if (j > i) j = i;
+ net_getbuffer (LOCAL->netstream,j,LOCAL->tmp);
+ }
}
if (len) *len = i; /* set return value */
if (md && mg) { /* have special routine to slurp string? */
@@ -5113,9 +5128,10 @@ void imap_parse_body_structure (MAILSTREAM *stream,BODY *body,
int i;
char *s;
PART *part = NIL;
- char c = *((*txtptr)++); /* grab first character */
+ char c = **txtptr; /* grab first character */
/* ignore leading spaces */
- while (c == ' ') c = *((*txtptr)++);
+ while (c == ' ') c = *++*txtptr;
+ if (c) ++*txtptr; /* skip past first character */
switch (c) { /* dispatch on first character */
case '(': /* body structure list */
if (**txtptr == '(') { /* multipart body? */
@@ -5172,9 +5188,12 @@ void imap_parse_body_structure (MAILSTREAM *stream,BODY *body,
(i <= TYPEMAX) && body_types[i] && strcmp (s,body_types[i]); i++);
if (i <= TYPEMAX) { /* only if found a slot */
body->type = i; /* set body type */
- if (body_types[i]) fs_give ((void **) &s);
- else body_types[i]=s; /* assign empty slot */
+ if (!body_types[i]) { /* assign empty slot */
+ body_types[i] = s;
+ s = NIL; /* don't free this string */
+ }
}
+ if (s) fs_give ((void **) &s);
}
if (body->subtype = imap_parse_string(stream,txtptr,reply,NIL,NIL,LONGT))
ucase (body->subtype); /* parse subtype */
@@ -5195,10 +5214,13 @@ void imap_parse_body_structure (MAILSTREAM *stream,BODY *body,
if (i > ENCMAX) body->encoding = ENCOTHER;
else { /* only if found a slot */
body->encoding = i; /* set body encoding */
- if (body_encodings[i]) fs_give ((void **) &s);
/* assign empty slot */
- else body_encodings[i] = s;
+ if (!body_encodings[i]) {
+ body_encodings[i] = s;
+ s = NIL; /* don't free this string */
+ }
}
+ if (s) fs_give ((void **) &s);
}
/* parse size of contents in bytes */
body->size.bytes = strtoul (*txtptr,(char **) txtptr,10);
@@ -5212,6 +5234,7 @@ void imap_parse_body_structure (MAILSTREAM *stream,BODY *body,
if (!env) {
mm_notify (stream,"Missing body message envelope",WARN);
stream->unhealthy = T;
+ fs_give ((void **) &body->subtype);
body->subtype = cpystr ("RFC822_MISSING_ENVELOPE");
break;
}
@@ -5284,8 +5307,7 @@ PARAMETER *imap_parse_body_parameter (MAILSTREAM *stream,
char c,*s;
/* ignore leading spaces */
while ((c = *(*txtptr)++) == ' ');
- /* parse parameter list */
- if (c == '(') while (c != ')') {
+ if (c == '(') do { /* parse parameter list */
/* append new parameter to tail */
if (ret) par = par->next = mail_newbody_parameter ();
else ret = par = mail_newbody_parameter ();
@@ -5308,13 +5330,17 @@ PARAMETER *imap_parse_body_parameter (MAILSTREAM *stream,
case ')': /* end of attribute/value pairs */
++*txtptr; /* skip past closing paren */
break;
+ case '\0':
+ mm_notify (stream,"Unterminated parameter list", WARN);
+ stream->unhealthy = T;
+ break;
default:
sprintf (LOCAL->tmp,"Junk at end of parameter: %.80s",(char *) *txtptr);
mm_notify (stream,LOCAL->tmp,WARN);
stream->unhealthy = T;
break;
}
- }
+ } while (c && (c != ')'));
/* empty parameter, must be NIL */
else if (((c == 'N') || (c == 'n')) &&
((*(s = *txtptr) == 'I') || (*s == 'i')) &&
@@ -5364,7 +5390,7 @@ void imap_parse_disposition (MAILSTREAM *stream,BODY *body,
mm_notify (stream,LOCAL->tmp,WARN);
stream->unhealthy = T;
/* try to skip to next space */
- while ((*++*txtptr != ' ') && (**txtptr != ')') && **txtptr);
+ while (**txtptr && (*++*txtptr != ' ') && (**txtptr != ')'));
break;
}
}
@@ -5437,12 +5463,13 @@ void imap_parse_extension (MAILSTREAM *stream,unsigned char **txtptr,
unsigned long i,j;
switch (*++*txtptr) { /* action depends upon first character */
case '(':
- while (**txtptr != ')') imap_parse_extension (stream,txtptr,reply);
- ++*txtptr; /* bump past closing parenthesis */
+ while (**txtptr && (**txtptr != ')'))
+ imap_parse_extension (stream,txtptr,reply);
+ if (**txtptr) ++*txtptr; /* bump past closing parenthesis */
break;
case '"': /* if quoted string */
- while (*++*txtptr != '"') if (**txtptr == '\\') ++*txtptr;
- ++*txtptr; /* bump past closing quote */
+ while ((*++*txtptr != '"') && **txtptr) if (**txtptr == '\\') ++*txtptr;
+ if (**txtptr) ++*txtptr; /* bump past closing quote */
break;
case 'N': /* if NIL */
case 'n':
@@ -5471,7 +5498,7 @@ void imap_parse_extension (MAILSTREAM *stream,unsigned char **txtptr,
mm_notify (stream,LOCAL->tmp,WARN);
stream->unhealthy = T;
/* try to skip to next space */
- while ((*++*txtptr != ' ') && (**txtptr != ')') && **txtptr);
+ while (**txtptr && (*++*txtptr != ' ') && (**txtptr != ')'));
break;
}
}
diff --git a/imap/src/c-client/mail.c b/imap/src/c-client/mail.c
index 0b479a1c..871d07eb 100644
--- a/imap/src/c-client/mail.c
+++ b/imap/src/c-client/mail.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,20 @@
* Program: Mailbox Access routines
*
* Author: Mark Crispin
- * UW Technology
- * University of Washington
- * Seattle, WA 98195
- * Internet: MRC@Washington.EDU
*
* Date: 22 November 1989
- * Last Edited: 15 April 2008
+ * Last Edited: 15 November 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
+ *
*/
@@ -30,7 +29,9 @@
#include <time.h>
#include "c-client.h"
-char *UW_copyright = "Copyright 1988-2007 University of Washington\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n";
+char *Panda_copyright = "Copyright 2008-2010 Mark Crispin\n";
+
+char *UW_copyright = "Copyright 1988-2008 University of Washington\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n";
/* c-client global data */
@@ -349,6 +350,11 @@ void *mail_parameters (MAILSTREAM *stream,long function,void *value)
else ret = env_parameters (function,value);
break;
case GET_NAMESPACE:
+ ret = (stream && stream->dtb && !(stream->dtb->flags & DR_LOCAL)) ?
+ /* KLUDGE ALERT: note stream passed as value */
+ (*stream->dtb->parameters) (function,stream) :
+ env_parameters (function,value);
+ break;
case GET_NEWSRC: /* use stream dtb instead of environment */
ret = (stream && stream->dtb) ?
/* KLUDGE ALERT: note stream passed as value */
@@ -3395,12 +3401,14 @@ unsigned long mail_filter (char *text,unsigned long len,STRINGLIST *lines,
while (((*src++ != '\012') && (*src++ != '\012') && (*src++ != '\012') &&
(*src++ != '\012') && (*src++ != '\012') && (*src++ != '\012') &&
(*src++ != '\012') && (*src++ != '\012') && (*src++ != '\012') &&
- (*src++ != '\012')) || ((*src == ' ') || (*src == '\t')));
+ (*src++ != '\012')) ||
+ ((src < end) && ((*src == ' ') || (*src == '\t'))));
else if (src == dst) { /* copy to self */
while (((*src++ != '\012') && (*src++ != '\012') && (*src++ != '\012') &&
(*src++ != '\012') && (*src++ != '\012') && (*src++ != '\012') &&
(*src++ != '\012') && (*src++ != '\012') && (*src++ != '\012') &&
- (*src++ != '\012')) || ((*src == ' ') || (*src == '\t')));
+ (*src++ != '\012')) ||
+ ((src < end) && ((*src == ' ') || (*src == '\t'))));
dst = src; /* update destination */
}
else { /* copy line and any continuation line */
@@ -3409,7 +3417,7 @@ unsigned long mail_filter (char *text,unsigned long len,STRINGLIST *lines,
((*dst++ = *src++) != '\012') && ((*dst++ = *src++) != '\012') &&
((*dst++ = *src++) != '\012') && ((*dst++ = *src++) != '\012') &&
((*dst++ = *src++) != '\012') && ((*dst++ = *src++) != '\012'))||
- ((*src == ' ') || (*src == '\t')));
+ ((src < end) && ((*src == ' ') || (*src == '\t'))));
/* in case hit the guard LF */
if (src > end) dst -= (src - end);
}
@@ -4402,7 +4410,8 @@ SORTCACHE **mail_sort_loadcache (MAILSTREAM *stream,SORTPGM *pgm)
default: /* tie off extraneous text */
*x = x[1] = '\0';
}
- if (adr = rfc822_parse_address (&adr,adr,&t,BADHOST,0)) {
+ rfc822_parse_adrlist (&adr,t,BADHOST);
+ if (adr) {
s->from = adr->mailbox;
adr->mailbox = NIL;
mail_free_address (&adr);
@@ -4435,7 +4444,8 @@ SORTCACHE **mail_sort_loadcache (MAILSTREAM *stream,SORTPGM *pgm)
default: /* tie off extraneous text */
*x = x[1] = '\0';
}
- if (adr = rfc822_parse_address (&adr,adr,&t,BADHOST,0)) {
+ rfc822_parse_adrlist (&adr,t,BADHOST);
+ if (adr) {
s->to = adr->mailbox;
adr->mailbox = NIL;
mail_free_address (&adr);
@@ -4459,8 +4469,8 @@ SORTCACHE **mail_sort_loadcache (MAILSTREAM *stream,SORTPGM *pgm)
case '\t':
memmove (x,v,strlen (v));
break;
- case 't': /* continuation but with extra "To:" */
- case 'T':
+ case 'c': /* continuation but with extra "cc:" */
+ case 'C':
if (v = strchr (v,':')) {
memmove (x,v+1,strlen (v+1));
break;
@@ -4468,7 +4478,8 @@ SORTCACHE **mail_sort_loadcache (MAILSTREAM *stream,SORTPGM *pgm)
default: /* tie off extraneous text */
*x = x[1] = '\0';
}
- if (adr = rfc822_parse_address (&adr,adr,&t,BADHOST,0)) {
+ rfc822_parse_adrlist (&adr,t,BADHOST);
+ if (adr) {
s->cc = adr->mailbox;
adr->mailbox = NIL;
mail_free_address (&adr);
@@ -4663,16 +4674,16 @@ int mail_sort_compare (const void *a1,const void *a2)
i = compare_ulong (s1->size,s2->size);
break;
case SORTFROM: /* sort by first from */
- i = compare_cstring (s1->from,s2->from);
+ i = compare_string (s1->from,s2->from);
break;
case SORTTO: /* sort by first to */
- i = compare_cstring (s1->to,s2->to);
+ i = compare_string (s1->to,s2->to);
break;
case SORTCC: /* sort by first cc */
- i = compare_cstring (s1->cc,s2->cc);
+ i = compare_string (s1->cc,s2->cc);
break;
case SORTSUBJECT: /* sort by subject */
- i = compare_cstring (s1->subject,s2->subject);
+ i = compare_string (s1->subject,s2->subject);
break;
}
if (pgm->reverse) i = -i; /* flip results if necessary */
@@ -5522,21 +5533,24 @@ long mail_parse_flags (MAILSTREAM *stream,char *flag,unsigned long *uf)
long mail_usable_network_stream (MAILSTREAM *stream,char *name)
{
NETMBX smb,nmb,omb;
- return (stream && stream->dtb && !(stream->dtb->flags & DR_LOCAL) &&
- mail_valid_net_parse (name,&nmb) &&
- mail_valid_net_parse (stream->mailbox,&smb) &&
- mail_valid_net_parse (stream->original_mailbox,&omb) &&
- ((!compare_cstring (smb.host,
- trustdns ? tcp_canonical (nmb.host) : nmb.host)&&
- !strcmp (smb.service,nmb.service) &&
- (!nmb.port || (smb.port == nmb.port)) &&
- (nmb.anoflag == stream->anonymous) &&
- (!nmb.user[0] || !strcmp (smb.user,nmb.user))) ||
- (!compare_cstring (omb.host,nmb.host) &&
- !strcmp (omb.service,nmb.service) &&
- (!nmb.port || (omb.port == nmb.port)) &&
- (nmb.anoflag == stream->anonymous) &&
- (!nmb.user[0] || !strcmp (omb.user,nmb.user))))) ? LONGT : NIL;
+ char *s = NIL;
+ long ret= (stream && stream->dtb && !(stream->dtb->flags & DR_LOCAL) &&
+ mail_valid_net_parse (name,&nmb) &&
+ mail_valid_net_parse (stream->mailbox,&smb) &&
+ mail_valid_net_parse (stream->original_mailbox,&omb) &&
+ ((!compare_cstring (smb.host,trustdns ?
+ (s = tcp_canonical (nmb.host)) : nmb.host) &&
+ !strcmp (smb.service,nmb.service) &&
+ (!nmb.port || (smb.port == nmb.port)) &&
+ (nmb.anoflag == stream->anonymous) &&
+ (!nmb.user[0] || !strcmp (smb.user,nmb.user))) ||
+ (!compare_cstring (omb.host,nmb.host) &&
+ !strcmp (omb.service,nmb.service) &&
+ (!nmb.port || (omb.port == nmb.port)) &&
+ (nmb.anoflag == stream->anonymous) &&
+ (!nmb.user[0] || !strcmp (omb.user,nmb.user))))) ? LONGT : NIL;
+ if(s) fs_give((void **) &s);
+ return ret;
}
/* Mail data structure instantiation routines */
diff --git a/imap/src/c-client/mail.h b/imap/src/c-client/mail.h
index ad63fa2d..fe7eaa77 100644
--- a/imap/src/c-client/mail.h
+++ b/imap/src/c-client/mail.h
@@ -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-2011 Mark Crispin
* ========================================================================
*/
@@ -15,18 +7,25 @@
* Program: Mailbox Access routines
*
* Author: Mark Crispin
- * UW Technology
- * University of Washington
- * Seattle, WA 98195
- * Internet: MRC@Washington.EDU
*
* Date: 22 November 1989
- * Last Edited: 16 December 2008
+ * Last Edited: 8 April 2011
+ *
+ * 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
+ *
*/
/* The Version */
-#define CCLIENTVERSION "2007e"
+#define CCLIENTVERSION "2010"
/* Build parameters */
@@ -177,6 +176,8 @@
#define SET_EXTERNALAUTHID (long) 230
#define GET_SSLCAPATH (long) 231
#define SET_SSLCAPATH (long) 232
+#define GET_RESTRICTIONS (long) 233
+#define SET_RESTRICTIONS (long) 234
/* 3xx: TCP/IP */
#define GET_OPENTIMEOUT (long) 300
@@ -1839,7 +1840,7 @@ char *net_localhost (NETSTREAM *stream);
long sm_subscribe (char *mailbox);
long sm_unsubscribe (char *mailbox);
-char *sm_read (void **sdb);
+char *sm_read (char *sbname,void **sdb);
void ssl_onceonlyinit (void);
char *ssl_start_tls (char *s);
diff --git a/imap/src/c-client/misc.c b/imap/src/c-client/misc.c
index 4b789af8..bcbc49e2 100644
--- a/imap/src/c-client/misc.c
+++ b/imap/src/c-client/misc.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,19 @@
* Program: Miscellaneous utility 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: 5 July 1988
- * Last Edited: 6 December 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
*
* This original version of this file is
* Copyright 1988 Stanford University
@@ -434,14 +430,35 @@ int compare_ulong (unsigned long l1,unsigned long l2)
int compare_uchar (unsigned char c1,unsigned char c2)
{
- return compare_ulong (((c1 >= 'A') && (c1 <= 'Z')) ? c1 + ('a' - 'A') : c1,
- ((c2 >= 'A') && (c2 <= 'Z')) ? c2 + ('a' - 'A') : c2);
+ return compare_ulong (((c1 >= 'a') && (c1 <= 'z')) ? c1 - ('a' - 'A') : c1,
+ ((c2 >= 'a') && (c2 <= 'z')) ? c2 - ('a' - 'A') : c2);
}
+/* Compare two strings by octet
+ * Accepts: first string
+ * second string
+ * Returns: -1 if s1 < s2, 0 if s1 == s2, 1 if s1 > s2
+ *
+ * Effectively strcmp() but without locales
+ */
+
+int compare_string (unsigned char *s1,unsigned char *s2)
+{
+ int i;
+ if (!s1) return s2 ? -1 : 0; /* empty string cases */
+ else if (!s2) return 1;
+ for (; *s1 && *s2; s1++,s2++) if (i = (compare_ulong (*s1,*s2))) return i;
+ if (*s1) return 1; /* first string is longer */
+ return *s2 ? -1 : 0; /* second string longer : strings identical */
+}
+
+
/* Compare two case-independent ASCII strings
* Accepts: first string
* second string
* Returns: -1 if s1 < s2, 0 if s1 == s2, 1 if s1 > s2
+ *
+ * Effectively strcasecmp() but without locales
*/
int compare_cstring (unsigned char *s1,unsigned char *s2)
diff --git a/imap/src/c-client/misc.h b/imap/src/c-client/misc.h
index 1ac79485..4e7afc23 100644
--- a/imap/src/c-client/misc.h
+++ b/imap/src/c-client/misc.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 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,19 @@
* Program: Miscellaneous utility 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: 5 July 1988
- * 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
*
* This original version of this file is
* Copyright 1988 Stanford University
@@ -106,5 +102,6 @@ void **hash_lookup_and_add (HASHTAB *hashtab,char *key,void *data,long extra);
unsigned char hex2byte (unsigned char c1,unsigned char c2);
int compare_ulong (unsigned long l1,unsigned long l2);
int compare_uchar (unsigned char c1,unsigned char c2);
+int compare_string (unsigned char *s1,unsigned char *s2);
int compare_cstring (unsigned char *s1,unsigned char *s2);
int compare_csizedtext (unsigned char *s1,SIZEDTEXT *s2);
diff --git a/imap/src/c-client/nntp.c b/imap/src/c-client/nntp.c
index 5a805e86..cee546d1 100644
--- a/imap/src/c-client/nntp.c
+++ b/imap/src/c-client/nntp.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,18 +7,24 @@
* Program: Network News Transfer Protocol (NNTP) 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: 10 February 1992
- * Last Edited: 6 September 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
+ *
*/
+
#include <ctype.h>
#include <stdio.h>
#include "c-client.h"
@@ -385,7 +383,7 @@ void nntp_list (MAILSTREAM *stream,char *ref,char *pat)
void nntp_lsub (MAILSTREAM *stream,char *ref,char *pat)
{
void *sdb = NIL;
- char *s,mbx[MAILTMPLEN];
+ char *s,mbx[MAILTMPLEN],tmp[MAILTMPLEN];
/* return data from newsrc */
if (nntp_canonicalize (ref,pat,mbx,NIL)) newsrc_lsub (stream,mbx);
if (*pat == '{') { /* if remote pattern, must be NNTP */
@@ -398,9 +396,10 @@ void nntp_lsub (MAILSTREAM *stream,char *ref,char *pat)
if (ref && *ref) sprintf (mbx,"%s%s",ref,pat);
else strcpy (mbx,pat);
- if (s = sm_read (&sdb)) do if (nntp_valid (s) && pmatch (s,mbx))
+ if (s = sm_read (tmp,&sdb)) do if (nntp_valid (s) && pmatch (s,mbx))
mm_lsub (stream,NIL,s,NIL);
- while (s = sm_read (&sdb)); /* until no more subscriptions */
+ /* until no more subscriptions */
+ while (s = sm_read (tmp,&sdb));
}
/* NNTP canonicalize newsgroup name
@@ -760,6 +759,10 @@ MAILSTREAM *nntp_mopen (MAILSTREAM *stream)
if (LOCAL->tlssslv23) strcat (tmp,"/tls-sslv23");
if (LOCAL->notlsflag) strcat (tmp,"/notls");
if (LOCAL->sslflag) strcat (tmp,"/ssl");
+ if (LOCAL->tls1) strcat (tmp,"/tls1");
+ if (LOCAL->dtls1) strcat (tmp,"/dtls1");
+ if (LOCAL->tls1_1) strcat (tmp,"/tls1_1");
+ if (LOCAL->tls1_2) strcat (tmp,"/tls1_2");
if (LOCAL->novalidate) strcat (tmp,"/novalidate-cert");
if (LOCAL->nntpstream->loser) strcat (tmp,"/loser");
if (stream->secure) strcat (tmp,"/secure");
diff --git a/imap/src/c-client/pop3.c b/imap/src/c-client/pop3.c
index 123abd9d..52573f52 100644
--- a/imap/src/c-client/pop3.c
+++ b/imap/src/c-client/pop3.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: Post Office Protocol 3 (POP3) client 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: 6 June 1994
- * Last Edited: 4 April 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
+ *
*/
@@ -265,7 +262,7 @@ void pop3_list (MAILSTREAM *stream,char *ref,char *pat)
void pop3_lsub (MAILSTREAM *stream,char *ref,char *pat)
{
void *sdb = NIL;
- char *s,mbx[MAILTMPLEN];
+ char *s,mbx[MAILTMPLEN],tmp[MAILTMPLEN];
if (*pat == '{') { /* if remote pattern, must be POP3 */
if (!pop3_valid (pat)) return;
ref = NIL; /* good POP3 pattern, punt reference */
@@ -276,9 +273,10 @@ void pop3_lsub (MAILSTREAM *stream,char *ref,char *pat)
if (ref && *ref) sprintf (mbx,"%s%s",ref,pat);
else strcpy (mbx,pat);
- if (s = sm_read (&sdb)) do if (pop3_valid (s) && pmatch (s,mbx))
+ if (s = sm_read (tmp,&sdb)) do if (pop3_valid (s) && pmatch (s,mbx))
mm_lsub (stream,NIL,s,NIL);
- while (s = sm_read (&sdb)); /* until no more subscriptions */
+ /* until no more subscriptions */
+ while (s = sm_read (tmp,&sdb));
}
@@ -425,7 +423,7 @@ MAILSTREAM *pop3_open (MAILSTREAM *stream)
if (mb.tlssslv23) strcat (tmp,"/tls-sslv23");
if (mb.tls1) strcat (tmp,"/tls1");
if (mb.tls1_1) strcat (tmp,"/tls1_1");
- if (mb.tls1_2) strcat (tmp,"/tls1_1");
+ if (mb.tls1_2) strcat (tmp,"/tls1_2");
if (mb.dtls1) strcat (tmp,"/dtls1");
if (mb.notlsflag) strcat (tmp,"/notls");
if (mb.sslflag) strcat (tmp,"/ssl");
diff --git a/imap/src/c-client/rfc822.c b/imap/src/c-client/rfc822.c
index d9239646..03e92ca3 100644
--- a/imap/src/c-client/rfc822.c
+++ b/imap/src/c-client/rfc822.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: RFC 2822 and MIME routines
*
* Author: Mark Crispin
- * UW Technology
- * University of Washington
- * Seattle, WA 98195
- * Internet: MRC@Washington.EDU
*
* Date: 27 July 1988
- * Last Edited: 14 May 2008
+ * Last Edited: 30 September 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
*
* This original version of this file is
* Copyright 1988 Stanford University
@@ -284,17 +282,26 @@ void rfc822_parse_content (BODY *body,STRING *bs,char *h,unsigned long depth,
}
if (!body->subtype) /* default subtype if still unknown */
body->subtype = cpystr (rfc822_default_subtype (body->type));
- /* note offset and sizes */
- body->contents.offset = GETPOS (bs);
- /* note internal body size in all cases */
- body->size.bytes = body->contents.text.size = i = SIZE (bs);
- if (!(flags & DR_CRLF)) body->size.bytes = strcrlflen (bs);
+ /* calculate offset */
+ if (bs->size >= (body->contents.offset = GETPOS (bs))) {
+ body->contents.text.size = i = SIZE (bs);
+ body->size.bytes = (flags & DR_CRLF) ? i : strcrlflen (bs);
+ }
+ else { /* paranoia code */
+#if 0
+ fatal("rfc822_parse_content botch");
+#endif
+ body->size.bytes = body->contents.text.size = i = 0;
+ body->contents.offset = bs->size;
+ SETPOS(bs,bs->size);
+ }
+
switch (body->type) { /* see if anything else special to do */
case TYPETEXT: /* text content */
if (!body->parameter) { /* no parameters set */
body->parameter = mail_newbody_parameter ();
body->parameter->attribute = cpystr ("CHARSET");
- while (i--) { /* count lines and guess charset */
+ while (i && i--) { /* count lines and guess charset */
c = SNX (bs); /* get current character */
/* charset still unknown? */
if (!body->parameter->value) {
@@ -319,7 +326,7 @@ void rfc822_parse_content (BODY *body,STRING *bs,char *h,unsigned long depth,
}
}
/* just count lines */
- else while (i--) if ((SNX (bs)) == '\n') body->size.lines++;
+ else while (i && i--) if ((SNX (bs)) == '\n') body->size.lines++;
break;
case TYPEMESSAGE: /* encapsulated message */
@@ -363,6 +370,7 @@ void rfc822_parse_content (BODY *body,STRING *bs,char *h,unsigned long depth,
/* count number of lines */
while (i--) if (SNX (bs) == '\n') body->size.lines++;
break;
+
case TYPEMULTIPART: /* multiple parts */
switch (body->encoding) { /* make sure valid encoding */
case ENC7BIT: /* these are valid nested encodings */
@@ -380,7 +388,6 @@ void rfc822_parse_content (BODY *body,STRING *bs,char *h,unsigned long depth,
if (!s1) s1 = "-"; /* yucky default */
j = strlen (s1) + 2; /* length of cookie and header */
c = '\012'; /* initially at beginning of line */
-
while (i > j) { /* examine data */
if (m = GETPOS (bs)) m--; /* get position in front of character */
switch (c) { /* examine each line */
@@ -405,6 +412,7 @@ void rfc822_parse_content (BODY *body,STRING *bs,char *h,unsigned long depth,
}
break;
}
+
/* swallow trailing whitespace */
while ((c == ' ') || (c == '\t'))
c = ((i && i--) ? (SNX (bs)) : '\012');
@@ -478,7 +486,6 @@ void rfc822_parse_content (BODY *body,STRING *bs,char *h,unsigned long depth,
/* end of data ties off the header */
if (!i || !--i) s1[j++] = c = '\0';
}
-
/* find header item type */
if (((s1[0] == 'C') || (s1[0] == 'c')) &&
((s1[1] == 'O') || (s1[1] == 'o')) &&
@@ -494,6 +501,7 @@ void rfc822_parse_content (BODY *body,STRING *bs,char *h,unsigned long depth,
rfc822_parse_content_header (&part->body,ucase (s1+8),s);
}
}
+
/* skip header trailing (CR)LF */
if (i && (CHR (bs) =='\015')) {i--; c1 = SNX (bs);}
if (i && (CHR (bs) =='\012')) {i--; c1 = SNX (bs);}
@@ -1061,7 +1069,7 @@ ADDRESS *rfc822_parse_addrspec (char *string,char **ret,char *defaulthost)
else if (!(adr->host = rfc822_parse_domain (++end,&end)))
adr->host = cpystr (errhst);
/* default host if missing */
- if (!adr->host) adr->host = cpystr (defaulthost);
+ if (!adr->host) adr->host = cpystr (defaulthost ? defaulthost : "@");
/* try person name in comments if missing */
if (end && !(adr->personal && *adr->personal)) {
while (*end == ' ') ++end; /* see if we can find a person name here */
@@ -1380,7 +1388,7 @@ static long rfc822_output_data (RFC822BUFFER *buf,char *string,long len)
}
/* soutr buffer now if full */
if ((len || (buf->cur == buf->end)) && !rfc822_output_flush (buf))
- return NIL;
+ return NIL;
}
return LONGT;
}
@@ -2064,8 +2072,12 @@ unsigned char *rfc822_qprint (unsigned char *src,unsigned long srcl,
t = d; /* accept any leading spaces */
break;
default: /* two hex digits then */
- if (!(isxdigit (c) && (((unsigned long) (s - src)) < srcl) &&
- (e = *s++) && isxdigit (e))) {
+ if (isxdigit (c) && (((unsigned long) (s - src)) < srcl) &&
+ isxdigit(*s)) {
+ e = *s++; /* eat second hex digit now */
+ *d++ = hex2byte (c,e);/* merge the two hex digits */
+ }
+ else {
/* This indicates bad MIME. One way that it can be caused is if
a single-section message was QUOTED-PRINTABLE encoded and then
something (e.g. a mailing list processor) appended text. The
@@ -2081,10 +2093,7 @@ unsigned char *rfc822_qprint (unsigned char *src,unsigned long srcl,
}
*d++ = '='; /* treat = as ordinary character */
*d++ = c; /* and the character following */
- t = d; /* note point of non-space */
- break;
}
- *d++ = hex2byte (c,e); /* merge the two hex digits */
t = d; /* note point of non-space */
break;
}
diff --git a/imap/src/c-client/smanager.c b/imap/src/c-client/smanager.c
index cee659ff..1f9b508c 100644
--- a/imap/src/c-client/smanager.c
+++ b/imap/src/c-client/smanager.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,18 +7,24 @@
* Program: Subscription Manager
*
* 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: 3 December 1992
- * Last Edited: 6 December 2006
+ * Last Edited: 8 April 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
+ *
*/
+
#include <stdio.h>
#include <ctype.h>
#include "c-client.h"
@@ -103,13 +101,12 @@ long sm_unsubscribe (char *mailbox)
}
/* Read subscription database
- * Accepts: pointer to subscription database handle (handle NIL if first time)
+ * Accepts: pointer to destination buffer of size MAILTMPLEN
+ * pointer to subscription database handle (handle NIL if first time)
* Returns: character string for subscription database or NIL if done
*/
-static char sbname[MAILTMPLEN];
-
-char *sm_read (void **sdb)
+char *sm_read (char *sbname,void **sdb)
{
FILE *f = (FILE *) *sdb;
char *s;
diff --git a/imap/src/c-client/smtp.c b/imap/src/c-client/smtp.c
index fe38cad0..47c7e5a6 100644
--- a/imap/src/c-client/smtp.c
+++ b/imap/src/c-client/smtp.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 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,19 @@
* Program: Simple Mail Transfer Protocol (SMTP) 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: 27 July 1988
- * Last Edited: 28 January 2008
+ * Last Edited: 19 November 2008
+ *
+ * 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
*
* This original version of this file is
* Copyright 1988 Stanford University
@@ -395,8 +391,7 @@ SENDSTREAM *smtp_close (SENDSTREAM *stream)
if (stream) { /* send "QUIT" */
if (stream->netstream) { /* do close actions if have netstream */
smtp_send (stream,"QUIT",NIL);
- if (stream->netstream) /* could have been closed during "QUIT" */
- net_close (stream->netstream);
+ if (stream->netstream) net_close (stream->netstream);
}
/* clean up */
if (stream->host) fs_give ((void **) &stream->host);
@@ -436,13 +431,13 @@ long smtp_mail (SENDSTREAM *stream,char *type,ENVELOPE *env,BODY *body)
sprintf (smtpserver,"{%.200s/smtp%s}<none>",
(long) mail_parameters (NIL,GET_TRUSTDNS,NIL) ?
((long) mail_parameters (NIL,GET_SASLUSESPTRNAME,NIL) ?
- net_remotehost (stream->netstream) :
- net_host (stream->netstream)) :
- stream->host,
- (stream->netstream->dtb ==
- (NETDRIVER *) mail_parameters (NIL,GET_SSLDRIVER,NIL)) ?
- "/ssl" : "");
- do {
+ net_remotehost (stream->netstream) :
+ net_host (stream->netstream)) :
+ stream->host,
+ (stream->netstream->dtb ==
+ (NETDRIVER *) mail_parameters (NIL,GET_SSLDRIVER,NIL)) ?
+ "/ssl" : "");
+ do { /* make sure stream is in good shape */
smtp_send (stream,"RSET",NIL);
if (retry) { /* need to retry with authentication? */
NETMBX mb;
@@ -487,6 +482,7 @@ long smtp_mail (SENDSTREAM *stream,char *type,ENVELOPE *env,BODY *body)
case SMTPOK: /* looks good */
break;
default: /* other failure */
+ smtp_send (stream,"RSET",NIL);
return NIL;
}
/* negotiate the recipients */
@@ -500,7 +496,10 @@ long smtp_mail (SENDSTREAM *stream,char *type,ENVELOPE *env,BODY *body)
}
} while (retry);
/* negotiate data command */
- if (!(smtp_send (stream,"DATA",NIL) == SMTPREADY)) return NIL;
+ if (!(smtp_send (stream,"DATA",NIL) == SMTPREADY)) {
+ smtp_send (stream,"RSET",NIL);
+ return NIL;
+ }
/* send message data */
if (!rfc822_output_full (&buf,env,body,
ESMTP.eightbit.ok && ESMTP.eightbit.want)) {
@@ -508,7 +507,11 @@ long smtp_mail (SENDSTREAM *stream,char *type,ENVELOPE *env,BODY *body)
return NIL; /* can't do much else here */
}
/* send trailing dot */
- return (smtp_send (stream,".",NIL) == SMTPOK) ? LONGT : NIL;
+ if (smtp_send (stream,".",NIL) != SMTPOK) {
+ smtp_send (stream,"RSET",NIL);
+ return NIL;
+ }
+ return LONGT;
}
/* Simple Mail Transfer Protocol send VERBose
diff --git a/imap/src/c-client/utf8.c b/imap/src/c-client/utf8.c
index 8fda7ffd..c752d7a2 100644
--- a/imap/src/c-client/utf8.c
+++ b/imap/src/c-client/utf8.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,15 +7,20 @@
* Program: UTF-8 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: 11 June 1997
- * Last Edited: 17 January 2008
+ * Last Edited: 28 May 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
+ *
*/
@@ -1023,20 +1020,52 @@ unsigned long utf8_get_raw (unsigned char **s,unsigned long *i)
if (c < 0x80) ret = c; /* U+0000 - U+007f */
else if (c < 0xc2); /* c0 and c1 never valid */
else if (c < 0xe0) { /* U+0080 - U+07ff */
- if (c &= 0x1f) more = 1;
+ c &= 0x1f;
+ if (c1 >= 0x80) more = 1;
+ }
+ else if (c == 0xe0) { /* U+0800 - U+0fff */
+ c &= 0x0f;
+ if (c1 >= 0xa0) more = 2;
+ }
+ else if (c < 0xed) { /* U+1000 - U+cfff */
+ c &= 0x0f;
+ if (c1 >= 0x80) more = 2;
}
- else if (c < 0xf0) { /* U+0800 - U+ffff */
- if ((c &= 0x0f) || (c1 >= 0xa0)) more = 2;
+ else if (c == 0xed) { /* U+d000 - U+d7ff */
+ c &= 0x0f;
+ if ((c1 >= 0x80) && (c1 <= 0x9f)) more = 2;
}
- else if (c < 0xf8) { /* U+10000 - U+10ffff (and 110000 - 1fffff) */
- if ((c &= 0x07) || (c1 >= 0x90)) more = 3;
+ else if (c < 0xf0) { /* U+e000 - U+ffff */
+ c &= 0x0f;
+ if (c1 >= 0x80) more = 2;
+ }
+ else if (c == 0xf0) { /* U+10000 - U+3ffff */
+ c &= 0x07;
+ if (c1 >= 0x90) more = 3;
+ }
+ else if (c < 0xf3) { /* U+40000 - U+fffff */
+ c &= 0x07;
+ if (c1 >= 0x80) more = 3;
+ }
+#if 0
+ else if (c == 0xf4) { /* U+100000 - U+10ffff */
+ c &= 0x07;
+ if (((c1 >= 0x80) && (c1 <= 0x8f))) more = 3;
+ }
+#else
+ else if (c < 0xf8) { /* U+100000 - U+10ffff (and 110000 - 1fffff) */
+ c &= 0x07;
+ if ((c1 >= 0x80)) more = 3;
}
else if (c < 0xfc) { /* ISO 10646 200000 - 3ffffff */
- if ((c &= 0x03) || (c1 >= 0x88)) more = 4;
+ c &= 0x03;
+ if ((c1 >= 0x80)) more = 4;
}
else if (c < 0xfe) { /* ISO 10646 4000000 - 7fffffff */
- if ((c &= 0x01) || (c1 >= 0x84)) more = 5;
+ c &= 0x01;
+ if ((c1 >= 0x80)) more = 5;
}
+#endif
/* fe and ff never valid */
if (more) { /* multi-octet, make sure more to come */
if (!j) return U8G_ENDSTRI;
@@ -1186,7 +1215,7 @@ unsigned long ucs4_cs_get (CHARSET *cs,unsigned char **s,unsigned long *i)
if (j--) c1 = *t++; /* get second octet */
else return U8G_ENDSTRI;
SJISTOJIS (c,c1);
- c = JISTOUNICODE (c,c1,ku,ten);
+ ret = JISTOUNICODE (c,c1,ku,ten);
}
break;
diff --git a/imap/src/dmail/dmail.c b/imap/src/dmail/dmail.c
index f78b9576..25bc547f 100644
--- a/imap/src/dmail/dmail.c
+++ b/imap/src/dmail/dmail.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 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,21 @@
* Program: Procmail-Callable Mail Delivery 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: 5 April 1993
- * Last Edited: 30 October 2008
+ * Last Edited: 19 November 2008
+ *
+ * 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 <stdio.h>
@@ -39,7 +37,7 @@ extern int errno; /* just in case */
/* Globals */
-char *version = "18"; /* dmail edit version */
+char *version = "19"; /* dmail edit version */
int debug = NIL; /* debugging (don't fork) */
int flagseen = NIL; /* flag message as seen */
int trycreate = NIL; /* flag saying gotta create before appending */
@@ -241,7 +239,8 @@ int deliver (FILE *f,unsigned long msglen,char *user)
if (mailbox) { /* non-INBOX name */
switch (mailbox[0]) { /* make sure a valid name */
default: /* other names, try to deliver if not INBOX */
- if (!strstr (mailbox,"..") && !strstr (mailbox,"//") &&
+ if ((strlen (mailbox) <= NETMAXMBX) &&
+ !strstr (mailbox,"..") && !strstr (mailbox,"//") &&
!strstr (mailbox,"/~") && mailboxfile (path,mailbox) && path[0] &&
!deliver_safely (NIL,&st,mailbox,path,tmp)) return NIL;
case '%': case '*': /* wildcards not valid */
diff --git a/imap/src/imapd/Makefile b/imap/src/imapd/Makefile
index c3078f42..ae54bfed 100644
--- a/imap/src/imapd/Makefile
+++ b/imap/src/imapd/Makefile
@@ -1,16 +1,7 @@
# ========================================================================
-# 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
# ========================================================================
-
# Program: IMAPD Makefile
#
# Author: Mark Crispin
@@ -23,6 +14,16 @@
#
# Date: 5 November 1990
# Last Edited: 30 August 2006
+#
+# 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
ALERT=/etc/imapd.alert
@@ -37,15 +38,18 @@ SHELL= /bin/sh
# causes the "Manage Mail" menu item to open the given URL, e.g. to point to
# an alternative IMAP client (e.g. Pine) or perhaps to a homebrew mail
# account management page.
-#NSBD= -DNETSCAPE_BRAIN_DAMAGE=\"http://www.washington.edu/pine\"
+#NSBD= -DNETSCAPE_BRAIN_DAMAGE=\"http://sourceforge.net/projects/re-alpine\"
+# Un-comment to enable the ESEARCH command. Unfortunately, the iOS4 Mail
+# client misinterprets the ESEARCH results due to an ambiguity in RFC 4731.
+#ESEARCH= -DESEARCH=1
# Get local definitions from c-client directory
C = ../c-client
CCLIENTLIB = $C/c-client.a
CC = `cat $C/CCTYPE`
-CFLAGS = -I$C `cat $C/CFLAGS` $(NSBD) $(ENBD) -DANOFILE=\"$(ANO)\" \
+CFLAGS = -I$C `cat $C/CFLAGS` $(NSBD) $(ESEARCH) -DANOFILE=\"$(ANO)\" \
-DALERTFILE=\"$(ALERT)\" -DNNTPFILE=\"$(NNTP)\" \
-DUSERALERTFILE=\"$(USERALERT)\" -DSHUTDOWNFILE=\"$(SHUTDOWN)\"
LDFLAGS = $(CCLIENTLIB) `cat $C/LDFLAGS`
diff --git a/imap/src/imapd/imapd.c b/imap/src/imapd/imapd.c
index d3d15660..5f72ac70 100644
--- a/imap/src/imapd/imapd.c
+++ b/imap/src/imapd/imapd.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-2011 Mark Crispin
* ========================================================================
*/
@@ -15,13 +7,20 @@
* Program: IMAP4rev1 server
*
* Author: Mark Crispin
- * UW Technology
- * University of Washington
- * Seattle, WA 98195
- * Internet: MRC@Washington.EDU
*
* Date: 5 November 1990
- * Last Edited: 3 March 2008
+ * Last Edited: 30 July 2011
+ *
+ * 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
+ *
*/
/* Parameter files */
@@ -33,6 +32,7 @@ extern int errno; /* just in case */
#include <signal.h>
#include <setjmp.h>
#include <time.h>
+#include <limits.h>
#include "c-client.h"
#include "newsrc.h"
#include <sys/stat.h>
@@ -51,9 +51,12 @@ extern int errno; /* just in case */
#define ALERTTIMER 1 MINUTES /* alert check timer */
#define SHUTDOWNTIMER 1 MINUTES /* shutdown dally timer */
#define IDLETIMER 1 MINUTES /* IDLE command poll timer */
-#define CHECKTIMER 15 MINUTES /* IDLE command last checkpoint timer */
+#define CHECKTIMER 5 MINUTES /* IDLE command last checkpoint timer */
+#define SIGNALTIMER 10 MINUTES /* allocated time to die at signal */
+#define MAXNLIBADCOMMAND 3 /* limit on number of NLI bad commands */
+#define MAXTAG 50 /* maximum tag length */
#define LITSTKLEN 20 /* length of literal stack */
#define MAXCLIENTLIT 10000 /* maximum non-APPEND client literal size
* must be smaller than 4294967295
@@ -66,10 +69,12 @@ extern int errno; /* just in case */
/* Server states */
-#define LOGIN 0
-#define SELECT 1
-#define OPEN 2
-#define LOGOUT 3
+typedef enum {
+ LOGIN = 0,
+ SELECT,
+ OPEN,
+ LOGOUT
+} IMAPSTATE;
/* Body text fetching */
@@ -118,6 +123,7 @@ void msg_string_setpos (STRING *s,unsigned long i);
void new_flags (MAILSTREAM *stream);
void settimeout (unsigned int i);
void clkint (void);
+void dieint (void);
void kodint (void);
void hupint (void);
void trmint (void);
@@ -130,6 +136,7 @@ unsigned char *flush (void);
void ioerror (FILE *f,char *reason);
unsigned char *parse_astring (unsigned char **arg,unsigned long *i,
unsigned char *del);
+unsigned char *parse_tag (unsigned char *cmd,unsigned char **ret);
unsigned char *snarf (unsigned char **arg);
unsigned char *snarf_base64 (unsigned char **arg);
unsigned char *snarf_list (unsigned char **arg);
@@ -207,7 +214,7 @@ char *lasterror (void);
/* Global storage */
-char *version = "404"; /* edit number of this server */
+char *version = "417"; /* edit number of this server */
char *logout = "Logout"; /* syslogreason for logout */
char *goodbye = NIL; /* bye reason */
time_t alerttime = 0; /* time of last alert */
@@ -215,7 +222,9 @@ time_t sysalerttime = 0; /* time of last system alert */
time_t useralerttime = 0; /* time of last user alert */
time_t lastcheck = 0; /* time of last checkpoint */
time_t shutdowntime = 0; /* time of last shutdown */
-int state = LOGIN; /* server state */
+int blackberry = 0; /* 1 if BlackBerry, -1 if not, 0 if unknown */
+int nlibcm = MAXNLIBADCOMMAND; /* limit number of bad commands */
+IMAPSTATE state = LOGIN; /* server state */
int cancelled = NIL; /* authenticate cancelled */
int trycreate = 0; /* saw a trycreate */
int finding = NIL; /* doing old FIND command */
@@ -243,6 +252,7 @@ char *lstwrn = NIL; /* last warning message from c-client */
char *lsterr = NIL; /* last error message from c-client */
char *lstref = NIL; /* last referral from c-client */
char *response = NIL; /* command response */
+char *sstate = NIL; /* strtok state */
struct {
unsigned long size; /* size of current LITERAL+ */
unsigned int ok : 1; /* LITERAL+ in effect */
@@ -267,9 +277,10 @@ char *rowin = "%.80s OK [READ-ONLY] %.80s completed\015\012";
char *rwwin = "%.80s OK [READ-WRITE] %.80s completed\015\012";
char *lose = "%.80s NO ";
char *logwin = "%.80s OK [";
-char *losetry = "%.80s NO [TRYCREATE] %.80s failed: %.900s\015\012";
-char *loseunknowncte = "%.80s NO [UNKNOWN-CTE] %.80s failed: %.900s\015\012";
+char *losetry = "%.80s NO [TRYCREATE] %.80s failed: %.800s\015\012";
+char *loseunknowncte = "%.80s NO [UNKNOWN-CTE] %.80s failed: %.800s\015\012";
char *badcmd = "%.80s BAD Command unrecognized: %.80s\015\012";
+char *badcml = "%.80s BAD Command unrecognized\015\012";
char *misarg = "%.80s BAD Missing or invalid argument to %.80s\015\012";
char *badarg = "%.80s BAD Argument given to %.80s when none expected\015\012";
char *badseq = "%.80s BAD Bogus sequence in %.80s: %.80s\015\012";
@@ -362,7 +373,7 @@ int main (int argc,char *argv[])
state = LOGOUT;
}
PSOUT (tcp_serverhost ());
- PSOUT (" IMAP4rev1 ");
+ PSOUT (" Panda IMAP ");
PSOUT (CCLIENTVERSION);
PBOUT ('.');
PSOUT (version);
@@ -396,46 +407,65 @@ int main (int argc,char *argv[])
if (lstref) fs_give ((void **) &lstref);
while (litsp) fs_give ((void **) &litstk[--litsp]);
/* find end of line */
- if (!strchr (cmdbuf,'\012')) {
- if (t = strchr (cmdbuf,' ')) *t = '\0';
- if ((t - cmdbuf) > 100) t = NIL;
- flush (); /* flush excess */
- if (state == LOGIN) /* error if NLI */
+ if (t = strchr (cmdbuf,'\012')) {
+ /* tie off command termination */
+ if ((t > cmdbuf) && (t[-1] == '\015')) --t;
+ *t = '\0'; /* tie off LF or CRLF */
+ }
+ if (!t) { /* probably line too long if not terminated */
+ if (t = strchr (cmdbuf,' ')) {
+ if ((t - cmdbuf) > MAXTAG) t = NIL;
+ else *t = '\0';
+ }
+ flush (); /* flush excess, set response */
+ if (state == LOGIN) { /* error if NLI */
syslog (LOG_INFO,"Line too long before authentication host=%.80s",
tcp_clienthost ());
+ state = LOGOUT;
+ }
sprintf (tmp,response,t ? (char *) cmdbuf : "*");
PSOUT (tmp);
}
- else if (!(tag = strtok (cmdbuf," \015\012"))) {
- if (state == LOGIN) /* error if NLI */
+ else if (!(tag = parse_tag (cmdbuf,&s))) {
+ if (state == LOGIN) { /* error if NLI */
syslog (LOG_INFO,"Null command before authentication host=%.80s",
tcp_clienthost ());
- PSOUT ("* BAD Null command\015\012");
+ state = LOGOUT;
+ }
+ PSOUT ("* BAD Missing command tag\015\012");
}
- else if (strlen (tag) > 50) PSOUT ("* BAD Excessively long tag\015\012");
- else if (!(s = strtok (NIL," \015\012"))) {
- if (state == LOGIN) /* error if NLI */
+ else if (strlen (tag) > MAXTAG)
+ PSOUT ("* BAD Excessively long tag\015\012");
+ else if (!*s) { /* make sure have command */
+ if (state == LOGIN) { /* error if NLI */
syslog (LOG_INFO,"Missing command before authentication host=%.80s",
tcp_clienthost ());
+ state = LOGOUT;
+ }
PSOUT (tag);
PSOUT (" BAD Missing command\015\012");
}
else { /* parse command */
response = win; /* set default response */
finding = NIL; /* no longer FINDing */
- ucase (s); /* canonicalize command case */
/* UID command? */
- if (!strcmp (s,"UID") && strtok (NIL," \015\012")) {
+ if (((s[0] == 'U') || (s[0] == 'u')) &&
+ ((s[1] == 'I') || (s[1] == 'i')) &&
+ ((s[2] == 'D') || (s[2] == 'd')) && (s[3] == ' ')) {
uid = T; /* a UID command */
- s[3] = ' '; /* restore the space delimiter */
- ucase (s); /* make sure command all uppercase */
+ arg = strchr (s+4,' '); /* find argument */
+ }
+ else {
+ uid = NIL; /* not a UID command */
+ arg = strchr (s,' '); /* find argument */
}
- else uid = NIL; /* not a UID command */
+ if (arg) *arg++ = '\0'; /* tie off command argument */
+ ucase (s); /* canonicalize command case */
/* flush previous saved command */
if (cmd) fs_give ((void **) &cmd);
cmd = cpystr (s); /* save current command */
/* snarf argument, see if possible litplus */
- if ((arg = strtok (NIL,"\015\012")) && ((i = strlen (arg)) > 3) &&
+ if (arg && ((i = strlen (arg)) > 3) &&
(arg[i - 1] == '}') && (arg[i - 2] == '+') && isdigit (arg[i - 3])) {
/* back over possible count */
for (i -= 4; i && isdigit (arg[i]); i--);
@@ -445,6 +475,26 @@ int main (int argc,char *argv[])
}
}
+ if (!blackberry) { /* do we know if it's a BlackBerry yet? */
+ char *bb[] = {".blackberry.com", ".blackberry.net", NIL};
+ size_t bbs;
+ unsigned char *cl = cpystr (tcp_clienthost ());
+ size_t cls;
+ /* get just host name, calculate length */
+ if (t = strchr (cl,' ')) {
+ *t = '\0';
+ cls = t - cl;
+ }
+ else cls = strlen (cl);
+ for (i = 0; bb[i]; ++i) {
+ if (((bbs = strlen (bb[i])) < cls) &&
+ !compare_cstring(bb[i], cl + cls - bbs))
+ blackberry = 1;
+ }
+ fs_give ((void **) & cl);
+ /* not a blackberry if no match on list */
+ if(!blackberry) blackberry = -1;
+ }
/* these commands always valid */
if (!strcmp (cmd,"NOOP")) {
if (arg) response = badarg;
@@ -544,7 +594,7 @@ int main (int argc,char *argv[])
tcp_clienthost ());
}
else {
- response = badcmd;
+ response = badcml;
syslog (LOG_INFO,"AUTHENTICATE %.80s invalid host=%.80s",s,
tcp_clienthost ());
}
@@ -591,13 +641,18 @@ int main (int argc,char *argv[])
if (arg) response = badarg;
else if (lsterr = ssl_start_tls (pgmname)) response = lose;
}
- else response = badcmd;
+ else {
+ response = badcml;
+ /* limit the number of bad commands */
+ if (--nlibcm <= 0) state = LOGOUT;
+ }
break;
case OPEN: /* valid only when mailbox open */
/* fetch mailbox attributes */
if (!strcmp (cmd,"FETCH") || !strcmp (cmd,"UID FETCH")) {
- if (!(arg && (s = strtok (arg," ")) && (t = strtok(NIL,"\015\012"))))
+ if (!(arg && (s = strtok_r (arg," ",&sstate)) &&
+ (t = strtok_r (NIL,"\015\012",&sstate))))
response = misarg;
else if (uid ? mail_uid_sequence (stream,s) :
mail_sequence (stream,s)) fetch (t,uid);
@@ -606,8 +661,9 @@ int main (int argc,char *argv[])
/* store mailbox attributes */
else if (!strcmp (cmd,"STORE") || !strcmp (cmd,"UID STORE")) {
/* must have three arguments */
- if (!(arg && (s = strtok (arg," ")) && (v = strtok (NIL," ")) &&
- (t = strtok (NIL,"\015\012")))) response = misarg;
+ if (!(arg && (s = strtok_r (arg," ",&sstate)) &&
+ (v = strtok_r (NIL," ",&sstate)) &&
+ (t = strtok_r (NIL,"\015\012",&sstate)))) response = misarg;
else if (!(uid ? mail_uid_sequence (stream,s) :
mail_sequence (stream,s))) response = badseq;
else {
@@ -681,7 +737,8 @@ int main (int argc,char *argv[])
else if (!anonymous && /* copy message(s) */
(!strcmp (cmd,"COPY") || !strcmp (cmd,"UID COPY"))) {
trycreate = NIL; /* no trycreate status */
- if (!(arg && (s = strtok (arg," ")) && (arg = strtok(NIL,"\015\012"))
+ if (!(arg && (s = strtok_r (arg," ",&sstate)) &&
+ (arg = strtok_r (NIL,"\015\012",&sstate))
&& (t = snarf (&arg)))) response = misarg;
else if (arg) response = badarg;
else if (!nmsgs) {
@@ -708,14 +765,14 @@ int main (int argc,char *argv[])
SORTPGM *pgm = NIL,*pg = NIL;
unsigned long *slst,*sl;
*t = NIL; /* tie off criteria list */
- if (!(s = strtok (ucase (s)," "))) response = badatt;
+ if (!(s = strtok_r (ucase (s)," ",&sstate))) response = badatt;
else {
do { /* parse sort attributes */
if (pg) pg = pg->next = mail_newsortpgm ();
else pgm = pg = mail_newsortpgm ();
if (!strcmp (s,"REVERSE")) {
pg->reverse = T;
- if (!(s = strtok (NIL," "))) {
+ if (!(s = strtok_r (NIL," ",&sstate))) {
s = ""; /* end of attributes */
break;
}
@@ -728,7 +785,7 @@ int main (int argc,char *argv[])
else if (!strcmp (s,"CC")) pg->function = SORTCC;
else if (!strcmp (s,"SIZE")) pg->function = SORTSIZE;
else break;
- } while (s = strtok (NIL," "));
+ } while (s = strtok_r (NIL," ",&sstate));
/* bad SORT attribute */
if (s) response = badatt;
/* get charset and search criteria */
@@ -760,8 +817,9 @@ int main (int argc,char *argv[])
SEARCHPGM *spg = NIL;
char *cs = NIL;
/* must have four arguments */
- if (!(arg && (s = strtok (arg," ")) && (cs = strtok (NIL," ")) &&
- (cs = cpystr (cs)) && (arg = strtok (NIL,"\015\012"))))
+ if (!(arg && (s = strtok_r (arg," ",&sstate)) &&
+ (cs = strtok_r (NIL," ",&sstate)) && (cs = cpystr (cs)) &&
+ (arg = strtok_r (NIL,"\015\012",&sstate))))
response = misarg;
else if (!parse_criteria (spg = mail_newsearchpgm (),&arg,nmsgs,
uidmax (stream),0)) response = badatt;
@@ -881,30 +939,58 @@ int main (int argc,char *argv[])
/* wants ALL */
if (retval & 0x4) {
- unsigned long j;
+ unsigned long j,juid,iuid;
/* find first match */
for (i = 1; (i <= nmsgs) && !mail_elt (stream,i)->searched;
++i);
if (i <= nmsgs) {
+ juid= (uid ? mail_uid (stream,i) : i);
PSOUT (" ALL ");
- pnum (uid ? mail_uid (stream,i) : i);
- j = i; /* last message output */
+ pnum (juid);
+ j = i; /* last message index processed */
}
- while (++i <= nmsgs) {
- if (mail_elt (stream,i)->searched) {
- while ((++i <= nmsgs) && mail_elt (stream,i)->searched);
- /* previous message is end of range */
- if (j != --i) {
- PBOUT (':');
- pnum (uid ? mail_uid (stream,i) : i);
+ if (uid) { /* doing UIDs, no MRC optimization */
+ while (++i <= nmsgs) {
+ if (mail_elt (stream,i)->searched) { /* this message matches */
+ iuid= mail_uid (stream,i);
+ if (juid == (iuid - (i-j))) { /* in sequence of UIDs */
+ if ( i < nmsgs) continue; /* may be more, check next */
+ PBOUT (':'); pnum(iuid); /* done with all, tie it off */
+ j = i; juid= iuid;
+ } else { /* break in sequence of UIDs */
+ if ((i-1) > j) { /* prev sequence, tie it off */
+ j= i-1; juid= mail_uid (stream,j);
+ PBOUT (':'); pnum(juid);
+ }
+ PBOUT (','); pnum(iuid);
+ j = i; juid= iuid; /* record last done message/UID */
+ }
+ } else { /* this message doesn't match, have a pending sequence? */
+ /* if pending sequence, tie it off & reset flags */
+ if ((i-1) > j) { /* prev sequence, tie it off */
+ j= i-1; juid= mail_uid (stream,j);
+ PBOUT (':'); pnum(juid);
+ }
+ j= nmsgs+1; juid= ULONG_MAX; /* flag that we're not in a sequence of matches */
}
}
+ } else { /* doing message-IDs, use MRC optimization */
+ while (++i <= nmsgs) {
+ if (mail_elt (stream,i)->searched) {
+ while ((++i <= nmsgs) && mail_elt (stream,i)->searched);
+ /* previous message is end of range */
+ if (j != --i) {
+ PBOUT (':');
+ pnum (i);
+ }
+ }
/* search for next match */
- while ((++i <= nmsgs) && !mail_elt (stream,i)->searched);
- if (i <= nmsgs) {
- PBOUT (',');
- pnum (uid ? mail_uid (stream,i) : i);
- j = i; /* last message output */
+ while ((++i <= nmsgs) && !mail_elt (stream,i)->searched);
+ if (i <= nmsgs) {
+ PBOUT (',');
+ pnum (i);
+ j = i; /* last message output */
+ }
}
}
}
@@ -942,8 +1028,8 @@ int main (int argc,char *argv[])
else if (arg) response = badarg;
else if (nameok (NIL,s = bboardname (cmd,s))) {
DRIVER *factory = mail_valid (NIL,s,NIL);
- f = (anonymous ? OP_ANONYMOUS + OP_READONLY : NIL) |
- ((*cmd == 'S') ? NIL : OP_READONLY);
+ f = anonymous ? OP_ANONYMOUS | OP_READONLY :
+ (((blackberry > 0) || (*cmd == 'S')) ? NIL : OP_READONLY);
curdriver = NIL; /* no drivers known */
/* no last uid */
uidvalidity = lastuid = 0;
@@ -1084,9 +1170,10 @@ int main (int argc,char *argv[])
/* find mailboxes */
else if (!strcmp (cmd,"FIND")) {
/* get subcommand and true argument */
- if (!(arg && (s = strtok (arg," \015\012")) && (s == cmd + 5) &&
- (cmd[4] = ' ') && ucase (s) &&
- (arg = strtok (NIL,"\015\012")) && (s = snarf_list (&arg))))
+ if (!(arg && (s = strtok_r (arg," \015\012",&sstate)) &&
+ (s == cmd + 5) && (cmd[4] = ' ') && ucase (s) &&
+ (arg = strtok_r (NIL,"\015\012",&sstate)) &&
+ (s = snarf_list (&arg))))
response = misarg; /* missing required argument */
else if (arg) response = badarg;
/* punt on single-char wildcards */
@@ -1117,7 +1204,7 @@ int main (int argc,char *argv[])
f = NIL; /* initially no flags */
*t = '\0'; /* tie off flag string */
/* read flags */
- t = strtok (ucase (arg)," ");
+ t = strtok_r (ucase (arg)," ",&sstate);
do { /* parse each one; unknown generate warning */
if (!strcmp (t,"MESSAGES")) f |= SA_MESSAGES;
else if (!strcmp (t,"RECENT")) f |= SA_RECENT;
@@ -1129,7 +1216,7 @@ int main (int argc,char *argv[])
PSOUT (t);
CRLF;
}
- } while (t = strtok (NIL," "));
+ } while (t = strtok_r (NIL," ",&sstate));
ping_mailbox (uid); /* in case the fool did STATUS on open mbx */
PFLUSH (); /* make sure stdout is dumped in case slave */
if (!compare_cstring (s,"INBOX")) s = "INBOX";
@@ -1308,7 +1395,8 @@ int main (int argc,char *argv[])
(void *) stream);
ping_mailbox (uid);
/* maybe do a checkpoint if not anonymous */
- if (!anonymous && stream && (time (0) > lastcheck + CHECKTIMER)) {
+ if (!anonymous && stream &&
+ (time (0) > (lastcheck + CHECKTIMER))) {
mail_check (stream);
/* cancel likely altwin from mail_check() */
if (lsterr) fs_give ((void **) &lsterr);
@@ -1760,17 +1848,23 @@ void settimeout (unsigned int i)
void clkint (void)
{
- settimeout (0); /* disable all interrupts */
- server_init (NIL,NIL,NIL,SIG_IGN,SIG_IGN,SIG_IGN,SIG_IGN,SIG_IGN);
+ settimeout (SIGNALTIMER); /* disable most interrupts */
+ server_init (NIL,NIL,NIL,dieint,SIG_IGN,SIG_IGN,SIG_IGN,SIG_IGN);
logout = "Autologout";
goodbye = "Autologout (idle for too long)";
- if (critical) { /* must defer if in critical code(?) */
- close (0); /* kill stdin */
- state = LOGOUT; /* die as soon as we can */
- }
+ if (critical) state = LOGOUT; /* must defer if in critical code */
else longjmp (jmpenv,1); /* die now */
}
+/* Clock interrupt after signal
+ * Never returns
+ */
+
+void dieint (void)
+{
+ _exit(1); /* slay the beast. Now. */
+}
+
/* Kiss Of Death interrupt
* Returns only if critical code in progress
@@ -1778,13 +1872,10 @@ void clkint (void)
void kodint (void)
{
- settimeout (0); /* disable all interrupts */
- server_init (NIL,NIL,NIL,SIG_IGN,SIG_IGN,SIG_IGN,SIG_IGN,SIG_IGN);
+ settimeout (SIGNALTIMER); /* disable most interrupts */
+ server_init (NIL,NIL,NIL,dieint,SIG_IGN,SIG_IGN,SIG_IGN,SIG_IGN);
logout = goodbye = "Killed (lost mailbox lock)";
- if (critical) { /* must defer if in critical code */
- close (0); /* kill stdin */
- state = LOGOUT; /* die as soon as we can */
- }
+ if (critical) state = LOGOUT; /* must defer if in critical code */
else longjmp (jmpenv,1); /* die now */
}
@@ -1794,15 +1885,11 @@ void kodint (void)
void hupint (void)
{
- settimeout (0); /* disable all interrupts */
- server_init (NIL,NIL,NIL,SIG_IGN,SIG_IGN,SIG_IGN,SIG_IGN,SIG_IGN);
+ settimeout (SIGNALTIMER); /* disable most interrupts */
+ server_init (NIL,NIL,NIL,dieint,SIG_IGN,SIG_IGN,SIG_IGN,SIG_IGN);
logout = "Hangup";
goodbye = NIL; /* other end is already gone */
- if (critical) { /* must defer if in critical code */
- close (0); /* kill stdin */
- close (1); /* and stdout */
- state = LOGOUT; /* die as soon as we can */
- }
+ if (critical) state = LOGOUT; /* must defer if in critical code */
else longjmp (jmpenv,1); /* die now */
}
@@ -1813,18 +1900,14 @@ void hupint (void)
void trmint (void)
{
- settimeout (0); /* disable all interrupts */
- server_init (NIL,NIL,NIL,SIG_IGN,SIG_IGN,SIG_IGN,SIG_IGN,SIG_IGN);
+ settimeout (SIGNALTIMER); /* disable most interrupts */
+ server_init (NIL,NIL,NIL,dieint,SIG_IGN,SIG_IGN,SIG_IGN,SIG_IGN);
logout = goodbye = "Killed (terminated)";
/* Make no attempt at graceful closure since a shutdown may be in
* progress, and we won't have any time to do mail_close() actions
*/
stream = NIL;
- if (critical) { /* must defer if in critical code */
- close (0); /* kill stdin */
- close (1); /* and stdout */
- state = LOGOUT; /* die as soon as we can */
- }
+ if (critical) state = LOGOUT; /* must defer if in critical code */
else longjmp (jmpenv,1); /* die now */
}
@@ -1855,7 +1938,6 @@ void staint (void)
if ((fd = open (buf,O_WRONLY | O_CREAT | O_TRUNC,0666)) >= 0) {
fchmod (fd,0666);
s = nout (sout (buf,"PID="),pid,10);
- if (user) s = sout (sout (s,", user="),user);
switch (state) {
case LOGIN:
s = sout (s,", not logged in");
@@ -1870,14 +1952,29 @@ void staint (void)
s = sout (s,", logging out");
break;
}
- if (stream && stream->mailbox)
- s = sout (sout (s,"\nmailbox="),stream->mailbox);
+ if (user) {
+ s = sout (sout (s,"\nuser="),user);
+ }
+ if (blackberry) {
+ /* Don't report client host until Blackberryness known. This is
+ because tcp_clienthost() may not have been called yet and so the
+ string might not be cached. As this is a signal handler, we want to
+ minimize any system calls.
+ */
+ s = sout (sout (s,"\nhost="),tcp_clienthost ());
+ if (blackberry > 0) s = sout (s, " (blackberry)");
+ }
+ if (stream && stream->mailbox) {
+ s = sout (sout (sout (s,"\nmailbox="),stream->mailbox),
+ stream->rdonly ? " (read-only)" : " (read-write)");
+ }
*s++ = '\n';
if (status) {
s = sout (s,status);
if (cmd) s = sout (sout (s,", last command="),cmd);
}
- else s = sout (sout (s,cmd)," in progress");
+ else if (cmd) s = sout (sout (s,cmd)," in progress");
+ else s = sout (s,"UNKNOWN STATE");
*s++ = '\n';
write (fd,buf,s-buf);
close (fd);
@@ -1975,7 +2072,7 @@ void inliteral (char *s,unsigned long n)
}
/* Flush until newline seen
- * Returns: NIL, always
+ * Returns: NIL and sets response, always
*/
unsigned char *flush (void)
@@ -2004,16 +2101,14 @@ void ioerror (FILE *f,char *reason)
static char msg[MAILTMPLEN];
char *s,*t;
if (logout) { /* say nothing if already dying */
- settimeout (0); /* disable all interrupts */
- server_init (NIL,NIL,NIL,SIG_IGN,SIG_IGN,SIG_IGN,SIG_IGN,SIG_IGN);
+ settimeout (SIGNALTIMER); /* disable most interrupts */
+ server_init (NIL,NIL,NIL,dieint,SIG_IGN,SIG_IGN,SIG_IGN,SIG_IGN);
/* write error string */
for (s = ferror (f) ? strerror (errno) : "Unexpected client disconnect",
t = logout = msg; *s; *t++ = *s++);
for (s = ", while "; *s; *t++ = *s++);
for (s = reason; *s; *t++ = *s++);
if (critical) { /* must defer if in critical code */
- close (0); /* kill stdin */
- close (1); /* and stdout */
state = LOGOUT; /* die as soon as we can */
}
else longjmp (jmpenv,1); /* die now */
@@ -2081,9 +2176,10 @@ unsigned char *parse_astring (unsigned char **arg,unsigned long *size,
inliteral (s = litstk[litsp++] = (char *) fs_get (i+1),i);
/* get new command tail */
slurp (*arg = t,CMDLEN - (t - cmdbuf),INPUTTIMEOUT);
+ /* if too long, flush and set response */
if (!strchr (t,'\012')) return flush ();
/* reset strtok mechanism, tie off if done */
- if (!strtok (t,"\015\012")) *t = '\0';
+ if (!strtok_r (t,"\015\012",&sstate)) *t = '\0';
/* possible LITERAL+? */
if (((i = strlen (t)) > 3) && (t[i - 1] == '}') &&
(t[i - 2] == '+') && isdigit (t[i - 3])) {
@@ -2104,6 +2200,27 @@ unsigned char *parse_astring (unsigned char **arg,unsigned long *size,
return s;
}
+/* Parse tag
+ * Accepts: command tag
+ * Returns: tag if valid, NIL otherwise
+ */
+
+unsigned char *parse_tag (unsigned char *cmd,unsigned char **ret)
+{
+ unsigned char *s;
+ *ret = cmd; /* make sure this stays defined */
+ if (!*cmd) return NIL; /* empty command line */
+ /* find end of tag */
+ for (s = cmd; *s && (*s > ' ') && (*s < 0x7f) &&
+ (*s != '(') && (*s != ')') && (*s != '{') &&
+ (*s != '%') && (*s != '*') &&
+ (*s != '"') && (*s != '\\'); ++s);
+ if (*s != ' ') return NIL; /* tag must be delimited by space */
+ *s++ = '\0'; /* tie off tag */
+ *ret = s; /* set pointer to remainder of command */
+ return cmd; /* return tag */
+}
+
/* Snarf a command argument (simple jacket into parse_astring())
* Accepts: pointer to argument text pointer
* Returns: argument
@@ -2141,7 +2258,7 @@ unsigned char *snarf_base64 (unsigned char **arg)
/* must be at least one BASE64 char */
else if (!base64mask[*ret]) return NIL;
else { /* quick and dirty */
- while (base64mask[*s++]); /* scan until end of BASE64 */
+ while (base64mask[*s]) ++s; /* scan until end of BASE64 */
if (*s == '=') ++s; /* allow up to two padding chars */
if (*s == '=') ++s;
}
@@ -2198,8 +2315,9 @@ unsigned char *snarf_list (unsigned char **arg)
STRINGLIST *parse_stringlist (unsigned char **s,int *list)
{
- char c = ' ',*t;
+ char *t;
unsigned long i;
+ char c = ' ';
STRINGLIST *ret = NIL,*cur = NIL;
if (*s && **s == '(') { /* proper list? */
++*s; /* for each item in list */
@@ -2215,14 +2333,10 @@ STRINGLIST *parse_stringlist (unsigned char **s,int *list)
/* must be end of list */
if (c != ')') mail_free_stringlist (&ret);
}
- if (t = *s) { /* need to reload strtok() state? */
+ if (t = *s) { /* need to reload strtok state? */
/* end of a list? */
if (*list && (*t == ')') && !t[1]) *list = NIL;
- else {
- *--t = ' '; /* patch a space back in */
- *--t = 'x'; /* and a hokey character before that */
- t = strtok (t," "); /* reset to *s */
- }
+ else sstate = t; /* otherwise reset strtok state to s */
}
return ret;
}
@@ -2644,7 +2758,8 @@ void fetch_work (char *t,unsigned long uid,fetchfn_t f[],void *fa[])
strcpy (t,"(FLAGS INTERNALDATE RFC822.SIZE ENVELOPE BODY)");
else if (!strcmp (t,"FAST")) strcpy (t,"(FLAGS INTERNALDATE RFC822.SIZE)");
if (list = (*t == '(')) t++; /* skip open paren */
- if (s = strtok (t," ")) do { /* parse attribute list */
+ /* parse attribute list */
+ if (s = strtok_r (t," ",&sstate)) do {
if (list && (i = strlen (s)) && (s[i-1] == ')')) {
list = NIL; /* done with list */
s[i-1] = '\0'; /* tie off last item */
@@ -2744,12 +2859,13 @@ void fetch_work (char *t,unsigned long uid,fetchfn_t f[],void *fa[])
v += 4; /* want to exclude named headers */
ta->flags |= FT_NOT;
}
- if (*v || !(v = strtok (NIL,"\015\012")) ||
+ if (*v || !(v = strtok_r (NIL,"\015\012",&sstate)) ||
!(ta->lines = parse_stringlist (&v,&list))) {
fs_give ((void **) &ta);/* clean up */
response = "%.80s BAD Syntax error in header fields\015\012";
return;
}
+ ucase (v); /* make sure followup is ucase */
}
}
else if (!strncmp (v,"TEXT",4)) {
@@ -2786,16 +2902,15 @@ void fetch_work (char *t,unsigned long uid,fetchfn_t f[],void *fa[])
}
switch (*v) { /* what's there now? */
case ' ': /* more follows */
- *--v = ' '; /* patch a space back in */
- *--v = 'x'; /* and a hokey character before that */
- strtok (v," "); /* reset strtok mechanism */
+ sstate = v + 1; /* reset strtok mechanism */
break;
case '\0': /* none */
break;
case ')': /* end of list */
if (list && !v[1]) { /* make sure of that */
list = NIL;
- strtok (v," "); /* reset strtok mechanism */
+ /* reset strtok mechanism */
+ strtok_r (v," ",&sstate);
break; /* all done */
}
/* otherwise it's a bogon, drop in */
@@ -2813,7 +2928,7 @@ void fetch_work (char *t,unsigned long uid,fetchfn_t f[],void *fa[])
response = badatt;
return;
}
- } while ((s = strtok (NIL," ")) && (k < MAXFETCH) && list);
+ } while ((s = strtok_r (NIL," ",&sstate)) && (k < MAXFETCH) && list);
else {
response = misarg; /* missing attribute list */
return;
@@ -3817,13 +3932,18 @@ void pcapability (long flag)
PSOUT (" X-NETSCAPE");
#endif
if (flag >= 0) { /* want post-authentication capabilities? */
- PSOUT (" IDLE UIDPLUS NAMESPACE CHILDREN MAILBOX-REFERRALS BINARY UNSELECT ESEARCH WITHIN SCAN SORT");
+ PSOUT (" IDLE UIDPLUS NAMESPACE CHILDREN MAILBOX-REFERRALS BINARY UNSELECT");
+#ifdef ESEARCH
+ PSOUT (" ESEARCH");
+#endif
+ PSOUT (" WITHIN SORT");
while (thr) { /* threaders */
PSOUT (" THREAD=");
PSOUT (thr->name);
thr = thr->next;
}
if (!anonymous) PSOUT (" MULTIAPPEND");
+ PSOUT (" SCAN"); /* private extension */
}
if (flag <= 0) { /* want pre-authentication capabilities? */
PSOUT (" SASL-IR LOGIN-REFERRALS");
@@ -4148,7 +4268,7 @@ long append_msg (MAILSTREAM *stream,void *data,char **flags,char **date,
slurp (ad->arg,CMDLEN - (ad->arg - cmdbuf),INPUTTIMEOUT);
if (strchr (ad->arg,'\012')) {
/* reset strtok mechanism, tie off if done */
- if (!strtok (ad->arg,"\015\012")) *ad->arg = '\0';
+ if (!strtok_r (ad->arg,"\015\012",&sstate)) *ad->arg = '\0';
/* possible LITERAL+? */
if (((j = strlen (ad->arg)) > 3) && (ad->arg[j - 1] == '}') &&
(ad->arg[j - 2] == '+') && isdigit (ad->arg[j - 3])) {
diff --git a/imap/src/mailutil/mailutil.c b/imap/src/mailutil/mailutil.c
index 2489195f..cb62290a 100644
--- a/imap/src/mailutil/mailutil.c
+++ b/imap/src/mailutil/mailutil.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 2009 Mark Crispin
* ========================================================================
*/
@@ -15,13 +7,20 @@
* Program: Mail utility
*
* Author: Mark Crispin
- * UW Technology
- * University of Washington
- * Seattle, WA 98195
- * Internet: MRC@Washington.EDU
*
* Date: 2 February 1994
- * Last Edited: 19 February 2008
+ * Last Edited: 14 May 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
+ *
*/
@@ -35,7 +34,7 @@ extern int errno; /* just in case */
/* Globals */
-char *version = "13"; /* edit number */
+char *version = "16"; /* edit number */
int debugp = NIL; /* flag saying debug */
int verbosep = NIL; /* flag saying verbose */
int rwcopyp = NIL; /* flag saying readwrite copy (for POP) */
@@ -79,7 +78,7 @@ char ms_next (STRING *s);
void ms_setpos (STRING *s,unsigned long i);
int main (int argc,char *argv[]);
SEARCHPGM *prune_criteria (char *criteria);
-int prune_criteria_number (unsigned long *number,char **r);
+int criteria_number (unsigned long *number,char **r);
int mbxcopy (MAILSTREAM *source,MAILSTREAM *dest,char *dst,int create,int del,
int mode);
long mm_append (MAILSTREAM *stream,void *data,char **flags,char **date,
@@ -220,6 +219,10 @@ int main (int argc,char *argv[])
perror ("unable to change user id");
exit (retcode);
}
+ /* become victim in environment */
+ env_init (argv[1], pw->pw_dir);
+ /* cancel restrictions since root call */
+ mail_parameters (NIL,SET_RESTRICTIONS,NIL);
}
#endif
/* -- means no more switches, so mailbox
@@ -481,7 +484,7 @@ SEARCHPGM *prune_criteria (char *criteria)
break;
case 'L': /* possible LARGER */
if (!strcmp (criterion+1,"ARGER"))
- f = prune_criteria_number (&pgm->larger,&r);
+ f = criteria_number (&pgm->larger,&r);
case 'N': /* possible NEW */
if (!strcmp (criterion+1,"EW")) f = pgm->recent = pgm->unseen = T;
@@ -508,7 +511,7 @@ SEARCHPGM *prune_criteria (char *criteria)
else if (!strcmp (criterion+1,"INCE"))
f = mail_criteria_date (&pgm->since,&r);
else if (!strcmp (criterion+1,"MALLER"))
- f = prune_criteria_number (&pgm->smaller,&r);
+ f = criteria_number (&pgm->smaller,&r);
else if (!strcmp (criterion+1,"UBJECT"))
f = mail_criteria_string (&pgm->subject,&r);
break;
@@ -553,7 +556,7 @@ SEARCHPGM *prune_criteria (char *criteria)
* Returns: T if successful, else NIL
*/
-int prune_criteria_number (unsigned long *number,char **r)
+int criteria_number (unsigned long *number,char **r)
{
char *t;
STRINGLIST *s = NIL;
@@ -895,7 +898,7 @@ void mm_login (NETMBX *mb,char *username,char *password,long trial)
if (s = strchr (username,'\n')) *s = '\0';
s = "password: ";
}
- strcpy (password,getpass (s));
+ if(strlen (s = getpass (s)) < MAILTMPLEN) strcpy (password,s);
}
diff --git a/imap/src/mtest/mtest.c b/imap/src/mtest/mtest.c
index 12a05e33..8e997d0b 100644
--- a/imap/src/mtest/mtest.c
+++ b/imap/src/mtest/mtest.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-2010 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,19 @@
* Program: Mail library test program
*
* 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: 8 July 1988
- * Last Edited: 5 November 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
*
* This original version of this file is
* Copyright 1988 Stanford University
@@ -90,7 +86,7 @@ int main ()
{
MAILSTREAM *stream = NIL;
void *sdb = NIL;
- char *s,tmp[MAILTMPLEN];
+ char *s,tmp[MAILTMPLEN],tmpx[MAILTMPLEN];
long debug;
#include "linkage.c"
#if MACOS
@@ -129,10 +125,10 @@ int main ()
puts ("Enter INBOX, mailbox name, or IMAP mailbox as {host}mailbox");
puts ("Known local mailboxes:");
mail_list (NIL,NIL,"%");
- if (s = sm_read (&sdb)) {
+ if (s = sm_read (tmpx,&sdb)) {
puts ("Local subscribed mailboxes:");
do (mm_lsub (NIL,NIL,s,NIL));
- while (s = sm_read (&sdb));
+ while (s = sm_read (tmpx,&sdb));
}
puts ("or just hit return to quit");
}
@@ -153,14 +149,14 @@ int main ()
void mm (MAILSTREAM *stream,long debug)
{
void *sdb = NIL;
- char cmd[MAILTMPLEN];
+ char cmd[MAILTMPLEN],tmp[MAILTMPLEN];
char *s, *arg;
unsigned long i;
unsigned long last = 0;
BODY *body;
status (stream); /* first report message status */
while (stream) {
- prompt ("MTest> ",cmd, sizeof(cmd)); /* prompt user, get command */
+ prompt ("MTest> ",cmd, sizeof(cmd)); /* prompt user, get command */
/* get argument */
if (arg = strchr (cmd,' ')) *arg++ = '\0';
switch (*ucase (cmd)) { /* dispatch based on command */
@@ -202,10 +198,10 @@ void mm (MAILSTREAM *stream,long debug)
case 'F': /* Find command */
if (!arg) {
arg = "%";
- if (s = sm_read (&sdb)) {
+ if (s = sm_read (tmp,&sdb)) {
puts ("Local network subscribed mailboxes:");
do if (*s == '{') (mm_lsub (NIL,NIL,s,NIL));
- while (s = sm_read (&sdb));
+ while (s = sm_read (tmp,&sdb));
}
}
puts ("Subscribed mailboxes:");
@@ -344,10 +340,22 @@ void mm (MAILSTREAM *stream,long debug)
case '-':
mail_nodebug (stream); debug = NIL;
break;
+ case '#':
+ {
+ NAMESPACE *ns;
+ NAMESPACE **nslist = (NAMESPACE **) mail_parameters (stream,GET_NAMESPACE,NIL);
+ static char *nstypes[] = {"Personal", "Other User", "Shared"};
+ for(i = 0; i < 3; ++i) {
+ puts(nstypes[i]);
+ for(ns = nslist[i]; ns; ns = ns->next)
+ printf(" namespace = %s, delimeter = %c\n", ns->name, ns->delimiter);
+ }
+ }
+ break;
case '?': /* ? command */
puts ("Body, Check, Delete, Expunge, Find, GC, Headers, Literal,");
puts (" MailboxStatus, New Mailbox, Overview, Ping, Quit, Send, Type,");
- puts ("Undelete, Xit, +, -, or <RETURN> for next message");
+ puts ("Undelete, Xit, #Namespace, +, -, or <RETURN> for next message");
break;
default: /* bogus command */
printf ("?Unrecognized command: %s\n",cmd);
diff --git a/imap/src/osdep/amiga/drivers b/imap/src/osdep/amiga/drivers
index bd49365f..bd49365f 100755..100644
--- a/imap/src/osdep/amiga/drivers
+++ b/imap/src/osdep/amiga/drivers
diff --git a/imap/src/osdep/amiga/dummy.c b/imap/src/osdep/amiga/dummy.c
index b003a0ba..cb3b45bd 100644
--- a/imap/src/osdep/amiga/dummy.c
+++ b/imap/src/osdep/amiga/dummy.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
*
* 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: 9 May 1991
- * 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
+ *
*/
@@ -216,10 +213,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],tmp[MAILTMPLEN];
+ char *s,*t,test[MAILTMPLEN],tmp[MAILTMPLEN],tmpx[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 (tmpx,&sdb))) do
if (*s != '{') {
if (!compare_cstring (s,"INBOX") &&
pmatch ("INBOX",ucase (strcpy (tmp,test))))
@@ -230,7 +227,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 (tmpx,&sdb));
}
diff --git a/imap/src/osdep/amiga/env_ami.c b/imap/src/osdep/amiga/env_ami.c
index 843757ed..30c1acce 100644
--- a/imap/src/osdep/amiga/env_ami.c
+++ b/imap/src/osdep/amiga/env_ami.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,12 +7,19 @@
* Program: Amiga environment routines
*
* Author: Mark Crispin
- * UW Technology
- * Seattle, WA 98195
- * Internet: MRC@Washington.EDU
*
* Date: 1 August 1988
- * Last Edited: 15 May 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
*/
#include <grp.h>
@@ -684,6 +683,8 @@ char *myusername_full (unsigned long *flags)
else if (flags) *flags = MU_NOTLOGGEDIN;
return ret;
}
+
+
/* Return my local host name
* Returns: my local host name
*/
@@ -692,9 +693,10 @@ char *mylocalhost ()
{
char tmp[MAILTMPLEN];
struct hostent *host_name;
- if (!myLocalHost) myLocalHost = cpystr (gethostname (tmp,MAILTMPLEN-1) ?
- "random-pc" : tcp_canonical (tmp));
- return myLocalHost;
+ if (!myLocalHost && !gethostname (tmp,MAILTMPLEN-1))
+ myLocalHost = tcp_canonical (tmp);
+ }
+ return myLocalHost ? myLocalHost : "random-amiga";
}
/* Return my home directory name
diff --git a/imap/src/osdep/amiga/env_ami.h b/imap/src/osdep/amiga/env_ami.h
index 365e5128..087430ab 100644
--- a/imap/src/osdep/amiga/env_ami.h
+++ b/imap/src/osdep/amiga/env_ami.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
* ========================================================================
*/
@@ -15,15 +7,20 @@
* Program: UNIX environment 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: 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
+ *
*/
@@ -68,7 +65,7 @@ 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);
long dotlock_lock (char *file,DOTLOCK *base,int fd);
long dotlock_unlock (DOTLOCK *base);
diff --git a/imap/src/osdep/amiga/mbx.c b/imap/src/osdep/amiga/mbx.c
index 1ece5d8d..dc902b20 100644
--- a/imap/src/osdep/amiga/mbx.c
+++ b/imap/src/osdep/amiga/mbx.c
@@ -1,5 +1,5 @@
/* ========================================================================
- * Copyright 1988-2007 University of Washington
+ * Copyright 1988-2012 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.
@@ -23,7 +23,7 @@
* Internet: MRC@CAC.Washington.EDU
*
* Date: 3 October 1995
- * Last Edited: 11 October 2007
+ * Last Edited: 21 February 2012
*/
@@ -1178,8 +1178,8 @@ long mbx_append (MAILSTREAM *stream,char *mailbox,append_t af,void *data)
else { /* write message */
size_t j;
if (!message->cursize) SETPOS (message,GETPOS (message));
- while (i && (j = fwrite (message->curpos,1,message->cursize,df))) {
- i -= j;
+ for (errno = 0; !errno && i &&
+ (j = fwrite (message->curpos,1,message->cursize,df)); i -= j) {
SETPOS (message,GETPOS (message) + j);
}
/* get next message */
diff --git a/imap/src/osdep/amiga/mh.c b/imap/src/osdep/amiga/mh.c
index 0226b7af..005000d6 100644
--- a/imap/src/osdep/amiga/mh.c
+++ b/imap/src/osdep/amiga/mh.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: MH mail routines
*
* Author(s): Mark Crispin
- * Networks and Distributed Computing
- * Computing & Communications
- * University of Washington
- * Administration Building, AG-44
- * Seattle, WA 98195
- * Internet: MRC@CAC.Washington.EDU
*
* Date: 23 February 1992
- * Last Edited: 11 October 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
+ *
*/
@@ -400,11 +397,11 @@ void mh_list (MAILSTREAM *stream,char *ref,char *pat)
void mh_lsub (MAILSTREAM *stream,char *ref,char *pat)
{
void *sdb = NIL;
- char *s,test[MAILTMPLEN];
+ char *s,test[MAILTMPLEN],tmp[MAILTMPLEN];
/* get canonical form of name */
- if (mh_canonicalize (test,ref,pat) && (s = sm_read (&sdb))) {
+ if (mh_canonicalize (test,ref,pat) && (s = sm_read (tmp,&sdb))) {
do if (pmatch_full (s,test,'/')) mm_lsub (stream,'/',s,NIL);
- while (s = sm_read (&sdb)); /* until no more subscriptions */
+ while (s = sm_read (tmp,&sdb)); /* until no more subscriptions */
}
}
diff --git a/imap/src/osdep/amiga/mix.c b/imap/src/osdep/amiga/mix.c
index fbf4a023..63009bb2 100644
--- a/imap/src/osdep/amiga/mix.c
+++ b/imap/src/osdep/amiga/mix.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-2012 Mark Crispin
* ========================================================================
*/
@@ -15,13 +7,19 @@
* Program: MIX mail routines
*
* Author(s): Mark Crispin
- * UW Technology
- * University of Washington
- * Seattle, WA 98195
- * Internet: MRC@Washington.EDU
*
* Date: 1 March 2006
- * Last Edited: 7 May 2008
+ * Last Edited: 15 February 2012
+ *
+ * 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
*/
@@ -417,7 +415,7 @@ long mix_create (MAILSTREAM *stream,char *mailbox)
strerror (errno));
else { /* success, write initial metadata */
fprintf (f,SEQFMT,now);
- fprintf (f,MTAFMT,now,0,now);
+ fprintf (f,MTAFMT,now,(unsigned long) 0,now);
for (i = 0, c = 'K'; (i < NUSERFLAGS) &&
(t = (stream && stream->user_flags[i]) ? stream->user_flags[i] :
default_user_flag (i)) && *t; ++i) {
@@ -1040,7 +1038,7 @@ long mix_expunge (MAILSTREAM *stream,char *sequence,long options)
/* expunge unless just burping */
if (!burponly) for (i = 1; i <= stream->nmsgs;) {
elt = mail_elt (stream,i);/* need to expunge this message? */
- if (sequence ? elt->sequence : elt->deleted) {
+ if (elt->deleted && (sequence ? elt->sequence : T)) {
++nexp; /* yes, make it so */
mail_expunged (stream,i);
}
@@ -1061,7 +1059,7 @@ long mix_expunge (MAILSTREAM *stream,char *sequence,long options)
/* another file found */
if (cur) cur = cur->next = nxt;
else cur = burp = nxt;
- cur->name = names[i]->d_name;
+ cur->name = cpystr (names[i]->d_name);
cur->fileno = strtoul (cur->name + sizeof (MIXNAME) - 1,NIL,16);
cur->tail = &cur->set;
fs_give ((void **) &names[i]);
@@ -1104,6 +1102,12 @@ long mix_expunge (MAILSTREAM *stream,char *sequence,long options)
MM_LOG (LOCAL->buf,WARN);
}
}
+ while (burp) { /* flush the burp list */
+ cur = burp->next;
+ if (burp->name) fs_give ((void **) &burp->name);
+ fs_give ((void **) &burp);
+ burp = cur;
+ }
}
else MM_LOG ("No mix message files found during expunge",WARN);
/* free directory list */
@@ -1116,7 +1120,7 @@ long mix_expunge (MAILSTREAM *stream,char *sequence,long options)
/* Do this step even if ret is NIL (meaning some burp problem)! */
if (nexp || reclaimed) { /* rewrite index and status if changed */
LOCAL->indexseq = mix_modseq (LOCAL->indexseq);
- if (mix_index_update (stream,idxf,NIL)) {
+ if (ret = mix_index_update (stream,idxf,NIL)) {
LOCAL->statusseq = mix_modseq (LOCAL->statusseq);
/* set failure if update fails */
ret = mix_status_update (stream,statf,NIL);
@@ -1269,7 +1273,7 @@ long mix_burp (MAILSTREAM *stream,MIXBURP *burp,unsigned long *reclaimed)
return NIL; /* burp fails for this file */
}
/* burp out each old message */
- for (set = &burp->set, wpos = 0; set; set = set->next) {
+ for (set = &burp->set, rpos = wpos = 0; set; set = set->next) {
/* move down this range */
for (rpos = set->first, size = set->last - set->first;
size; size -= wsize) {
@@ -1288,8 +1292,8 @@ long mix_burp (MAILSTREAM *stream,MIXBURP *burp,unsigned long *reclaimed)
MM_DISKERROR (stream,errno,T);
}
/* and especially not here */
- for (s = LOCAL->buf, wpending = wsize; wpending; wpending -= written)
- if (!(written = fwrite (LOCAL->buf,1,wpending,f))) {
+ for (s = LOCAL->buf, wpending = wsize; wpending; s += written, wpending -= written)
+ if (!(written = fwrite (s,1,wpending,f))) {
MM_NOTIFY (stream,strerror (errno),WARN);
MM_DISKERROR (stream,errno,T);
}
@@ -1390,7 +1394,8 @@ long mix_copy (MAILSTREAM *stream,char *sequence,char *mailbox,long options)
if (local->indexseq > seq) seq = local->indexseq + 1;
if (local->statusseq > seq) seq = local->statusseq + 1;
/* calculate size of per-message header */
- sprintf (local->buf,MSRFMT,MSGTOK,0,0,0,0,0,0,0,'+',0,0,0);
+ sprintf (local->buf,MSRFMT,MSGTOK,(unsigned long) 0,0,0,0,0,0,0,'+',0,0,
+ (unsigned long) 0);
hdrsize = strlen (local->buf);
MM_CRITICAL (stream); /* go critical */
@@ -1547,7 +1552,8 @@ long mix_append (MAILSTREAM *stream,char *mailbox,append_t af,void *data)
if (local->indexseq > seq) seq = local->indexseq + 1;
if (local->statusseq > seq) seq = local->statusseq + 1;
/* calculate size of per-message header */
- sprintf (local->buf,MSRFMT,MSGTOK,0,0,0,0,0,0,0,'+',0,0,0);
+ sprintf (local->buf,MSRFMT,MSGTOK,(unsigned long) 0,0,0,0,0,0,0,'+',0,0,
+ (unsigned long) 0);
hdrsize = strlen (local->buf);
MM_CRITICAL (astream); /* go critical */
astream->silent = T; /* no events here */
@@ -1631,6 +1637,7 @@ long mix_append_msg (MAILSTREAM *stream,FILE *f,char *flags,MESSAGECACHE *delt,
int c,cs;
unsigned long i,j,k,uf,hoff;
long sf;
+ void *s;
stream->kwd_create = NIL; /* don't copy unknown keywords */
sf = mail_parse_flags (stream,flags,&uf);
/* swell the cache */
@@ -1669,8 +1676,8 @@ long mix_append_msg (MAILSTREAM *stream,FILE *f,char *flags,MESSAGECACHE *delt,
for (cs = 0; SIZE (msg); ) { /* copy message */
if (elt->private.msg.header.text.size) {
if (msg->cursize) /* blat entire chunk if have it */
- for (j = msg->cursize; j; j -= k)
- if (!(k = fwrite (msg->curpos,1,j,f))) return NIL;
+ for (s = msg->curpos,j = msg->cursize; j; s += k, j -= k)
+ if (!(k = fwrite (s,1,j,f))) return NIL;
SETPOS (msg,GETPOS (msg) + msg->cursize);
}
else { /* still searching for delimiter */
@@ -1813,6 +1820,7 @@ FILE *mix_parse (MAILSTREAM *stream,FILE **idxf,long iflags,long sflags)
}
/* sequence changed from last time? */
else if (j || (i > LOCAL->indexseq)) {
+ unsigned long prevuid = 0;
unsigned long uid,nmsgs,curfile,curfilesize,curpos;
char *t,*msg,tmp[MAILTMPLEN];
/* start with no messages */
@@ -1870,6 +1878,12 @@ FILE *mix_parse (MAILSTREAM *stream,FILE **idxf,long iflags,long sflags)
/* ignore expansion values */
if (*s++ == ':') {
MESSAGECACHE *elt;
+ if(prevuid > uid) {
+ sprintf (tmp,"mix index backwards UID: %lx",uid);
+ MM_LOG (tmp,ERROR);
+ return NIL;
+ }
+ prevuid = uid;
++nmsgs; /* this is another mesage */
/* within current known range of messages? */
while (nmsgs <= stream->nmsgs) {
@@ -2234,7 +2248,9 @@ long mix_index_update (MAILSTREAM *stream,FILE *idxf,long flag)
for (i = 1, size = 0; i <= stream->nmsgs; ++i)
if (!mail_elt (stream,i)->private.ghost) ++size;
if (size) { /* Winston Smith's first dairy entry */
- sprintf (tmp,IXRFMT,0,14,4,4,13,0,0,'+',0,0,0,0,0,0,0);
+ sprintf (tmp,IXRFMT,(unsigned long) 0,14,4,4,13,0,0,'+',0,0,
+ (unsigned long) 0,(unsigned long) 0,(unsigned long) 0,
+ (unsigned long) 0,(unsigned long) 0);
size *= strlen (tmp);
}
/* calculate file size we need */
@@ -2315,7 +2331,8 @@ long mix_status_update (MAILSTREAM *stream,FILE *statf,long flag)
for (i = 1, size = 0; i <= stream->nmsgs; ++i)
if (!mail_elt (stream,i)->private.ghost) ++size;
if (size) { /* number of living messages */
- sprintf (tmp,STRFMT,0,0,0,0);
+ sprintf (tmp,STRFMT,(unsigned long) 0,(unsigned long) 0,0,
+ (unsigned long) 0);
size *= strlen (tmp);
}
sprintf (tmp,SEQFMT,LOCAL->statusseq);
@@ -2408,14 +2425,30 @@ FILE *mix_data_open (MAILSTREAM *stream,int *fd,long *size,
if (curend > sbuf.st_size) {
char tmp[MAILTMPLEN];
sprintf (tmp,"short mix message file %.08lx (%ld > %ld), rolling",
- LOCAL->newmsg,curend,sbuf.st_size);
+ LOCAL->newmsg,curend,(unsigned long) sbuf.st_size);
MM_LOG (tmp,WARN); /* shouldn't happen */
}
close (*fd); /* roll to a new file */
+ errno = NIL;
while ((*fd = open (mix_file_data
(LOCAL->buf,stream->mailbox,
LOCAL->newmsg = mix_modseq (LOCAL->newmsg)),
- O_RDWR | O_CREAT | O_EXCL,sbuf.st_mode)) < 0);
+ O_RDWR | O_CREAT | O_EXCL,sbuf.st_mode)) < 0) {
+ switch(errno) {
+ case EEXIST: /* always retry if path exists or interrupt */
+ case EINTR:
+ errno = NIL;
+ break;
+ default: /* probably EDQUOT */
+ {
+ char tmp[MAILTMPLEN];
+ sprintf (tmp,"data file %.08lx creation failure: %.80s",
+ LOCAL->newmsg,strerror (errno));
+ MM_LOG (tmp,ERROR); /* shouldn't happen */
+ return NIL;
+ }
+ }
+ }
*size = 0; /* brand new file */
fchmod (*fd,sbuf.st_mode);/* with same mode as previous file */
}
diff --git a/imap/src/osdep/amiga/mkauths b/imap/src/osdep/amiga/mkauths
index 8e9cc0cf..8e9cc0cf 100755..100644
--- a/imap/src/osdep/amiga/mkauths
+++ b/imap/src/osdep/amiga/mkauths
diff --git a/imap/src/osdep/amiga/scandir.c b/imap/src/osdep/amiga/scandir.c
index 878343e8..c5e4541b 100644
--- a/imap/src/osdep/amiga/scandir.c
+++ b/imap/src/osdep/amiga/scandir.c
@@ -1,4 +1,18 @@
/* ========================================================================
+ * Copyright 2008-2009 Mark Crispin
+ * ========================================================================
+ */
+
+/*
+ * Program: Scan directories
+ *
+ * Author: Mark Crispin
+ *
+ * Date: 1 August 1988
+ * Last Edited: 12 June 2009
+ *
+ * Previous versions of this file were:
+ *
* Copyright 1988-2006 University of Washington
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -10,21 +24,6 @@
*
* ========================================================================
*/
-
-/*
- * Program: Scan directories
- *
- * 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: 1 August 1988
- * Last Edited: 15 September 2006
- */
/* Emulator for BSD scandir() call
* Accepts: directory name
@@ -43,7 +42,8 @@ int scandir (char *dirname,struct direct ***namelist,select_t select,
long nlmax;
DIR *dirp = opendir (dirname);/* open directory and get status poop */
if ((!dirp) || (fstat (dirp->dd_fd,&stb) < 0)) return -1;
- nlmax = stb.st_size / 24; /* guesstimate at number of files */
+ /* guesstimate at number of files */
+ nlmax = max (stb.st_size / 24,32);
names = (struct direct **) fs_get (nlmax * sizeof (struct direct *));
nitems = 0; /* initially none found */
while (d = readdir (dirp)) { /* read directory item */
diff --git a/imap/src/osdep/amiga/ssl_none.c b/imap/src/osdep/amiga/ssl_none.c
index e4dedda7..a87c4be6 100644
--- a/imap/src/osdep/amiga/ssl_none.c
+++ b/imap/src/osdep/amiga/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/amiga/tcp_ami.c b/imap/src/osdep/amiga/tcp_ami.c
index 974717c0..c0666bd3 100644
--- a/imap/src/osdep/amiga/tcp_ami.c
+++ b/imap/src/osdep/amiga/tcp_ami.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,15 +7,19 @@
* Program: Amiga TCP/IP 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: 1 August 1988
- * Last Edited: 13 January 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
*/
#undef write /* don't use redefined write() */
@@ -735,7 +731,7 @@ char *tcp_canonical (char *name)
(*bn) (BLOCK_NONSENSITIVE,data);
(*bn) (BLOCK_NONE,NIL); /* alarms OK now */
if (tcpdebug) mm_log ("DNS canonicalization done",TCPDEBUG);
- return ret;
+ return cpystr (ret);
}
diff --git a/imap/src/osdep/dos/dummydos.c b/imap/src/osdep/dos/dummydos.c
index 4bf147b8..29f38d29 100644
--- a/imap/src/osdep/dos/dummydos.c
+++ b/imap/src/osdep/dos/dummydos.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,20 @@
* Program: Dummy routines for DOS
*
* 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: 30 August 2006
+ * Last Edited: 8 April 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
+ *
*/
@@ -205,10 +202,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);
@@ -219,7 +216,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/dos/env_dos.h b/imap/src/osdep/dos/env_dos.h
index bb0e8c0a..c24cbbb5 100644
--- a/imap/src/osdep/dos/env_dos.h
+++ b/imap/src/osdep/dos/env_dos.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
* ========================================================================
*/
@@ -15,15 +7,21 @@
* Program: DOS environment 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: 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
+ *
+ *
*/
@@ -39,7 +37,7 @@
char *dos_default_gets (readfn_t f,void *stream,unsigned long size,
GETS_DATA *md);
long safe_write (int fd,char *buf,long nbytes);
-long random ();
+long random (void);
#if _MSC_VER < 700
#define getpid random
#endif
diff --git a/imap/src/osdep/dos/tcp_dos.c b/imap/src/osdep/dos/tcp_dos.c
index 062f260c..d5787be6 100644
--- a/imap/src/osdep/dos/tcp_dos.c
+++ b/imap/src/osdep/dos/tcp_dos.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,15 +7,19 @@
* Program: MS-DOS TCP/IP 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: 11 April 1989
- * Last Edited: 13 January 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 tcptimeout_t tmoh = NIL; /* TCP timeout handler routine */
@@ -420,7 +416,7 @@ char *tcp_localhost (TCPSTREAM *stream)
char *tcp_canonical (char *name)
{
- return name;
+ return cpystr (name);
}
diff --git a/imap/src/osdep/dos/tcp_dwa.c b/imap/src/osdep/dos/tcp_dwa.c
index 4275f27c..3d68c483 100644
--- a/imap/src/osdep/dos/tcp_dwa.c
+++ b/imap/src/osdep/dos/tcp_dwa.c
@@ -1,29 +1,25 @@
/* ========================================================================
- * 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
* ========================================================================
*/
/*
- * Program: Waterloo DOS TCP/IP routines
+ * Program: MS-DOS TCP/IP 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: 11 April 1989
- * Last Edited: 13 January 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
*/
@@ -330,7 +326,7 @@ char *tcp_localhost (TCPSTREAM *stream)
char *tcp_canonical (char *name)
{
- return name;
+ return cpystr (name);
}
diff --git a/imap/src/osdep/dos/tcp_wsk.c b/imap/src/osdep/dos/tcp_wsk.c
index 90e206a9..226750cb 100644
--- a/imap/src/osdep/dos/tcp_wsk.c
+++ b/imap/src/osdep/dos/tcp_wsk.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,15 +7,19 @@
* 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 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
*/
@@ -735,7 +731,7 @@ char *tcp_canonical (char *name)
ret = (he = gethostbyname (lcase (strcpy (host,name)))) ? he->h_name : name;
(*bn) (BLOCK_NONE,NIL);
if (tcpdebug) mm_log ("DNS canonicalization done",TCPDEBUG);
- return ret;
+ return cpystr(ret);
}
@@ -785,15 +781,13 @@ char *mylocalhost (void)
char tmp[MAILTMPLEN];
if (!wsa_initted++) { /* init Windows Sockets */
WSADATA wsock;
- if (WSAStartup (WSA_VERSION,&wsock)) {
+ if (WSAStartup (WSA_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";
}
diff --git a/imap/src/osdep/mac/tcp_mac.c b/imap/src/osdep/mac/tcp_mac.c
index 8d39d4f3..7abd56a5 100644
--- a/imap/src/osdep/mac/tcp_mac.c
+++ b/imap/src/osdep/mac/tcp_mac.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,15 +7,19 @@
* Program: Macintosh TCP/IP 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: 26 January 1992
- * Last Edited: 13 January 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
*/
@@ -529,7 +525,8 @@ char *tcp_canonical (char *name)
int i;
struct hostInfo hst;
/* look like domain literal? */
- if (name[0] == '[' && name[i = (strlen (name))-1] == ']') return name;
+ if (name[0] == '[' && name[i = (strlen (name))-1] == ']')
+ return cpystr (name);
if (StrToAddr (name,&hst,tcp_dns_upp,NIL)) {
while (hst.rtnCode == cacheFault && wait ());
/* kludge around MacTCP bug */
@@ -541,9 +538,9 @@ char *tcp_canonical (char *name)
while (hst.rtnCode == cacheFault && wait ());
}
/* still have error status? */
- if (hst.rtnCode) return name;
+ if (hst.rtnCode) return cpystr (name);
}
- return hst.cname; /* success */
+ return cpystr (hst.cname);
}
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;
diff --git a/imap/src/osdep/os2/dummyos2.c b/imap/src/osdep/os2/dummyos2.c
index f54999fc..5130297c 100644
--- a/imap/src/osdep/os2/dummyos2.c
+++ b/imap/src/osdep/os2/dummyos2.c
@@ -1,4 +1,18 @@
/* ========================================================================
+ * Copyright 2008-2011 Mark Crispin
+ * ========================================================================
+ */
+
+/*
+ * Program: Dummy routines for OS2
+ *
+ * Author: Mark Crispin
+ *
+ * Date: 24 May 1993
+ * Last Edited: 8 April 2011
+ *
+ * Previous versions of this file were:
+ *
* Copyright 1988-2006 University of Washington
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -11,21 +25,6 @@
* ========================================================================
*/
-/*
- * Program: Dummy routines for OS2
- *
- * 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: 30 August 2006
- */
-
/* Thanks to Nicholas Sheppard for the original version */
@@ -209,10 +208,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);
@@ -223,7 +222,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/os2/tcp_os2.c b/imap/src/osdep/os2/tcp_os2.c
index 062f260c..d5787be6 100644
--- a/imap/src/osdep/os2/tcp_os2.c
+++ b/imap/src/osdep/os2/tcp_os2.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,15 +7,19 @@
* Program: MS-DOS TCP/IP 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: 11 April 1989
- * Last Edited: 13 January 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 tcptimeout_t tmoh = NIL; /* TCP timeout handler routine */
@@ -420,7 +416,7 @@ char *tcp_localhost (TCPSTREAM *stream)
char *tcp_canonical (char *name)
{
- return name;
+ return cpystr (name);
}
diff --git a/imap/src/osdep/tops-20/shortsym.h b/imap/src/osdep/tops-20/shortsym.h
index 2bd54649..32a93b6a 100644
--- a/imap/src/osdep/tops-20/shortsym.h
+++ b/imap/src/osdep/tops-20/shortsym.h
@@ -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 Mark Crispin
* ========================================================================
*/
/*
- * Program: Definitions for compilers with 6-letter symbol limits
+ * Program: Mailbox Access 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: 24 May 1995
- * Last Edited: 1 January 2008
+ * Last Edited: 19 November 2008
+ *
+ * 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 auth_link a_link
@@ -45,7 +42,8 @@
#define body_encodings bencds
#define body_types btypes
#define compare_csizedtext cm_szt
-#define compare_cstring cm_str
+#define compare_cstring cm_cst
+#define compare_string cm_str
#define compare_uchar cm_uch
#define compare_ulong cm_uln
#define default_proto d_prot
diff --git a/imap/src/osdep/tops-20/tcp_t20.c b/imap/src/osdep/tops-20/tcp_t20.c
index 7b2a2580..6e045809 100644
--- a/imap/src/osdep/tops-20/tcp_t20.c
+++ b/imap/src/osdep/tops-20/tcp_t20.c
@@ -1,4 +1,18 @@
/* ========================================================================
+ * Copyright 2008-2010 Mark Crispin
+ * ========================================================================
+ */
+
+/*
+ * Program: TOPS-20 TCP/IP routines
+ *
+ * Author: Mark Crispin
+ *
+ * Date: 1 August 1988
+ * Last Edited: 19 November 2008
+ *
+ * Previous versions of this file were
+ *
* Copyright 1988-2008 University of Washington
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -11,21 +25,6 @@
* ========================================================================
*/
-/*
- * Program: TOPS-20 TCP/IP 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: 1 August 1988
- * Last Edited: 13 January 2008
- */
-
/* Dedication:
* This file is dedicated with affection to the TOPS-20 operating system, which
@@ -146,7 +145,8 @@ TCPSTREAM *tcp_aopen (NETMBX *mb,char *service,char *usrbuf)
char *tcp_getline (TCPSTREAM *stream)
{
- unsigned long n,contd;
+ long contd;
+ unsigned long n;
char *ret = tcp_getline_work (stream,&n,&contd);
if (ret && contd) { /* got a line needing continuation? */
STRINGLIST *stl = mail_newstringlist ();
@@ -332,9 +332,10 @@ char *tcp_localhost (TCPSTREAM *stream)
char *tcp_canonical (char *name)
{
int argblk[5];
- static char tmp[MAILTMPLEN];
+ char tmp[MAILTMPLEN];
/* look like domain literal? */
- if (name[0] == '[' && name[strlen (name) - 1] == ']') return name;
+ if (name[0] == '[' && name[strlen (name) - 1] == ']')
+ return cpystr (name);
argblk[1] = _GTHPN; /* get IP address and primary name */
argblk[2] = (int) (name-1); /* pointer to host */
argblk[4] = (int) (tmp-1); /* pointer to return destination */
@@ -344,14 +345,14 @@ char *tcp_canonical (char *name)
argblk[4] = (int) (tmp-1);
if (!jsys (GTDOM,argblk)) { /* try the CHIVES domain way */
argblk[1] = _GTHSN; /* failed, do the host table then */
- if (!jsys (GTHST,argblk)) return name;
+ if (!jsys (GTHST,argblk)) return cpystr (name);
argblk[1] = _GTHNS; /* convert number to string */
argblk[2] = (int) (tmp-1);
/* get the official name */
- if (!jsys (GTHST,argblk)) return name;
+ if (!jsys (GTHST,argblk)) return cpystr (name);
}
}
- return tmp;
+ return cpystr (tmp);
}
diff --git a/imap/src/osdep/unix/Makefile b/imap/src/osdep/unix/Makefile
index 78913acc..a38d15fb 100644
--- a/imap/src/osdep/unix/Makefile
+++ b/imap/src/osdep/unix/Makefile
@@ -1,15 +1,7 @@
# ========================================================================
-# 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
# ========================================================================
-
+#
# Program: C client makefile
#
# Author: Mark Crispin
@@ -21,7 +13,17 @@
# Internet: MRC@CAC.Washington.EDU
#
# Date: 11 May 1989
-# Last Edited: 17 December 2007
+# Last Edited: 29 August 2011
+#
+# 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
# Command line build parameters
@@ -199,7 +201,7 @@ a41: # AIX 4.1 for RS/6000
BASECFLAGS="-g -Dunix=1 -D_BSD -qro -qroconst" \
BASELDFLAGS="-ls"
-a52: # Attempt at AIX 5.2
+a52: # AIX 5.2
$(BUILD) `$(CAT) SPECIALS` OS=$@ \
SIGTYPE=psx CHECKPW=a41 CRXTYPE=nfs \
SPOOLDIR=/var/spool \
@@ -437,7 +439,7 @@ gso: os_sol.h # GCC Solaris
ACTIVEFILE=/usr/share/news/active \
RSHPATH=/usr/bin/rsh \
BASECFLAGS="$(GCCCFLAGS)" \
- BASELDFLAGS="-lsocket -lnsl -lgen" \
+ BASELDFLAGS="-lsocket -lnsl -lgen -R/usr/local/ssl/lib" \
RANLIB=true CC=gcc
gsu: # GCC SUN-OS
@@ -608,6 +610,14 @@ pyr: # Pyramid
CRXTYPE=nfs \
BASECFLAGS="-g -Dconst="
+qn6: # QNX 6
+ $(BUILD) `$(CAT) SPECIALS` OS=$@ \
+ CRXTYPE=nfs \
+ SPOOLDIR=/var/spool \
+ ACTIVEFILE=/var/lib/news/active \
+ RSHPATH=/usr/bin/rsh \
+ BASECFLAGS="$(GCCFLAGS)"
+
qnx: # QNX
$(BUILD) `$(CAT) SPECIALS` OS=$@ \
CHECKPW=psx LOGINPW=old \
@@ -725,7 +735,7 @@ soc: os_sol.h # Solaris with cc
ACTIVEFILE=/usr/share/news/active \
RSHPATH=/usr/bin/rsh \
BASECFLAGS="-g -O -w" \
- BASELDFLAGS="-lsocket -lnsl -lgen" \
+ BASELDFLAGS="-lsocket -lnsl -lgen -R/usr/local/ssl/lib" \
RANLIB=true CC=/opt/SUNWspro/bin/cc
@@ -773,7 +783,7 @@ sol: os_sol.h # Solaris
ACTIVEFILE=/usr/share/news/active \
RSHPATH=/usr/bin/rsh \
BASECFLAGS="-g -O2" \
- BASELDFLAGS="-lsocket -lnsl -lgen" \
+ BASELDFLAGS="-lsocket -lnsl -lgen -R/usr/local/ssl/lib" \
RANLIB=true CC=ucbcc
sos: # Secure OSF/1
@@ -859,8 +869,8 @@ all: $(ARCHIVE)
$(ARCHIVE): $(BINARIES)
sh -c '$(RM) $(ARCHIVE) || true'
- @$(CAT) ARCHIVE
- @$(SH) ARCHIVE
+ @$(CAT) ./ARCHIVE
+ @$(SH) ./ARCHIVE
.c.o:
`$(CAT) CCTYPE` -c `$(CAT) CFLAGS` $*.c
diff --git a/imap/src/osdep/unix/dummy.c b/imap/src/osdep/unix/dummy.c
index b003a0ba..cb3b45bd 100644
--- a/imap/src/osdep/unix/dummy.c
+++ b/imap/src/osdep/unix/dummy.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
*
* 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: 9 May 1991
- * 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
+ *
*/
@@ -216,10 +213,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],tmp[MAILTMPLEN];
+ char *s,*t,test[MAILTMPLEN],tmp[MAILTMPLEN],tmpx[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 (tmpx,&sdb))) do
if (*s != '{') {
if (!compare_cstring (s,"INBOX") &&
pmatch ("INBOX",ucase (strcpy (tmp,test))))
@@ -230,7 +227,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 (tmpx,&sdb));
}
diff --git a/imap/src/osdep/unix/env_unix.c b/imap/src/osdep/unix/env_unix.c
index 6b2c4471..b13d5066 100644
--- a/imap/src/osdep/unix/env_unix.c
+++ b/imap/src/osdep/unix/env_unix.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,20 @@
* Program: UNIX environment routines
*
* Author: Mark Crispin
- * UW Technology
- * University of Washington
- * Seattle, WA 98195
- * Internet: MRC@Washington.EDU
*
* Date: 1 August 1988
- * Last Edited: 23 February 2009
+ * Last Edited: 15 November 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
+ *
*/
#include <grp.h>
@@ -77,7 +76,7 @@ static char *sslCApath = NIL; /* non-standard CA path */
static short anonymous = NIL; /* is anonymous */
static short blackBox = NIL; /* is a black box */
static short closedBox = NIL; /* is a closed box (uses chroot() jail) */
-static short restrictBox = NIL; /* is a restricted box */
+static long restrictBox = NIL; /* is a restricted box */
static short has_no_life = NIL; /* is a cretin with no life */
/* block environment init */
static short block_env_init = NIL;
@@ -398,6 +397,10 @@ void *env_parameters (long function,void *value)
case GET_SHAREDDIRPROTECTION:
ret = (void *) shared_dir_protection;
break;
+ case SET_RESTRICTIONS:
+ restrictBox = (long) value;
+ case GET_RESTRICTIONS:
+ ret = (void *) restrictBox;
case SET_LOCKTIMEOUT:
locktimeout = (long) value;
@@ -618,14 +621,17 @@ void server_init (char *server,char *service,char *sslservice,
long server_input_wait (long seconds)
{
+ int err;
fd_set rfd,efd;
struct timeval tmo;
- FD_ZERO (&rfd);
- FD_ZERO (&efd);
- FD_SET (0,&rfd);
- FD_SET (0,&efd);
- tmo.tv_sec = seconds; tmo.tv_usec = 0;
- return select (1,&rfd,0,&efd,&tmo) ? LONGT : NIL;
+ do {
+ FD_ZERO (&rfd);
+ FD_ZERO (&efd);
+ FD_SET (0,&rfd);
+ FD_SET (0,&efd);
+ tmo.tv_sec = seconds; tmo.tv_usec = 0;
+ } while (((err = select (1,&rfd,0,&efd,&tmo)) < 0) && (errno = EINTR));
+ return err ? LONGT : NIL;
}
/* Return UNIX password entry for user name
@@ -933,16 +939,14 @@ char *mylocalhost ()
{
if (!myLocalHost) {
char *s,tmp[MAILTMPLEN];
- char *t = "unknown";
tmp[0] = tmp[MAILTMPLEN-1] = '\0';
if (!gethostname (tmp,MAILTMPLEN-1) && tmp[0]) {
/* sanity check of name */
for (s = tmp; (*s > 0x20) && (*s < 0x7f); ++s);
- if (!*s) t = tcp_canonical (tmp);
+ if (!*s) myLocalHost = tcp_canonical (tmp);
}
- myLocalHost = cpystr (t);
}
- return myLocalHost;
+ return myLocalHost ? myLocalHost : "unknown";
}
/* Return my home directory name
@@ -1071,9 +1075,13 @@ char *mailboxfile (char *dst,char *name)
}
else sprintf (dst,"%s/%s",blackBoxDir,name+1);
}
- else if ((restrictBox & RESTRICTROOT) && strcmp (name,sysinbox ()))
- dst = NIL; /* restricted and not access to sysinbox */
- else strcpy (dst,name); /* unrestricted, copy root name */
+ else {
+ size_t i = strlen (mymailboxdir ());
+ if ((restrictBox & RESTRICTROOT) && strcmp (name,sysinbox ()) &&
+ (!i || strncmp (name,mymailboxdir (),i) || (name[i] !='/')))
+ dst = NIL; /* restricted and not sysinbox or home */
+ else strcpy (dst,name); /* unrestricted, copy root name */
+ }
break;
case '~': /* other user access */
/* bad syntax or anonymous can't win */
diff --git a/imap/src/osdep/unix/env_unix.h b/imap/src/osdep/unix/env_unix.h
index 365e5128..087430ab 100644
--- a/imap/src/osdep/unix/env_unix.h
+++ b/imap/src/osdep/unix/env_unix.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
* ========================================================================
*/
@@ -15,15 +7,20 @@
* Program: UNIX environment 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: 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
+ *
*/
@@ -68,7 +65,7 @@ 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);
long dotlock_lock (char *file,DOTLOCK *base,int fd);
long dotlock_unlock (DOTLOCK *base);
diff --git a/imap/src/osdep/unix/flocklnx.c b/imap/src/osdep/unix/flocklnx.c
index 06940b8d..3dc6b5dc 100644
--- a/imap/src/osdep/unix/flocklnx.c
+++ b/imap/src/osdep/unix/flocklnx.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-2009 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,20 @@
* Program: Safe File Lock for Linux
*
* 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: 20 April 2005
- * Last Edited: 30 August 2006
+ * Last Edited: 18 May 2009
+ *
+ * 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
+ *
*/
#undef flock
diff --git a/imap/src/osdep/unix/ip4_unix.c b/imap/src/osdep/unix/ip4_unix.c
index 23d399e1..4ebb32b1 100644
--- a/imap/src/osdep/unix/ip4_unix.c
+++ b/imap/src/osdep/unix/ip4_unix.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/unix/ip6_unix.c b/imap/src/osdep/unix/ip6_unix.c
index c15dfbc0..2727adb2 100644
--- a/imap/src/osdep/unix/ip6_unix.c
+++ b/imap/src/osdep/unix/ip6_unix.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/unix/ipo_unix.c b/imap/src/osdep/unix/ipo_unix.c
deleted file mode 100644
index 665fb2e8..00000000
--- a/imap/src/osdep/unix/ipo_unix.c
+++ /dev/null
@@ -1,181 +0,0 @@
-/* ========================================================================
- * 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
- *
- *
- * ========================================================================
- */
-
-/*
- * Program: UNIX IPv4 old 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)
-
-#define SADR4(sadr) ((struct sockaddr_in *) sadr)
-#define SADR4LEN sizeof (struct sockaddr_in)
-#define SADR4ADR(sadr) SADR4 (sadr)->sin_addr
-#define ADR4LEN sizeof (struct in_addr)
-#define SADR4PORT(sadr) SADR4 (sadr)->sin_port
-
-
-/* IP abstraction layer */
-
-char *ip_sockaddrtostring (struct sockaddr *sadr);
-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);
-void *ip_nametoaddr (char *name,size_t *len,int *family,char **canonical,
- void **next);
-
-/* Return IP address string from socket address
- * Accepts: socket address
- * Returns: IP address as name string
- */
-
-char *ip_sockaddrtostring (struct sockaddr *sadr)
-{
- return (sadr->sa_family == PF_INET) ?
- inet_ntoa (SADR4ADR (sadr)) : "NON-IPv4";
-}
-
-
-/* Return port from socket address
- * Accepts: socket address
- * Returns: port number or -1 if can't determine it
- */
-
-long ip_sockaddrtoport (struct sockaddr *sadr)
-{
- return (sadr->sa_family == PF_INET) ? ntohs (SADR4PORT (sadr)) : -1;
-}
-
-
-/* Return IP address from string
- * Accepts: name string
- * pointer to returned length
- * pointer to returned address family
- * Returns: address if valid, length and family updated, or NIL
- */
-
-void *ip_stringtoaddr (char *text,size_t *len,int *family)
-{
- unsigned long adr;
- struct in_addr *ret;
- /* get address */
- if ((adr = inet_addr (text)) == -1) ret = NIL;
- else { /* make in_addr */
- ret = (struct in_addr *) fs_get (*len = ADR4LEN);
- *family = AF_INET; /* IPv4 */
- ret->s_addr = adr; /* set address */
- }
- return (void *) ret;
-}
-
-/* Create a maximum-size socket address
- * Accepts: pointer to return maximum socket address length
- * Returns: new, empty socket address of maximum size
- */
-
-struct sockaddr *ip_newsockaddr (size_t *len)
-{
- return (struct sockaddr *) memset (fs_get (SADRLEN),0,*len = SADRLEN);
-}
-
-
-/* Stuff a socket address
- * Accepts: address family
- * IPv4 address
- * length of address (always 4 in IPv4)
- * port number
- * pointer to return socket address length
- * Returns: socket address or NIL if error
- */
-
-struct sockaddr *ip_sockaddr (int family,void *adr,size_t adrlen,
- unsigned short port,size_t *len)
-{
- struct sockaddr *sadr = ip_newsockaddr (len);
- switch (family) { /* build socket address based upon family */
- case AF_INET: /* IPv4 */
- sadr->sa_family = PF_INET;
- /* copy host address */
- memcpy (&SADR4ADR (sadr),adr,adrlen);
- /* copy port number in network format */
- SADR4PORT (sadr) = htons (port);
- *len = SADR4LEN;
- break;
- default: /* non-IP?? */
- sadr->sa_family = PF_UNSPEC;
- break;
- }
- return sadr;
-}
-
-/* Return name from socket address
- * Accepts: socket address
- * Returns: canonical name for that address or NIL if none
- */
-
-char *ip_sockaddrtoname (struct sockaddr *sadr)
-{
- struct hostent *he;
- return ((sadr->sa_family == PF_INET) &&
- (he = gethostbyaddr ((char *) &SADR4ADR (sadr),ADR4LEN,AF_INET))) ?
- (char *) he->h_name : NIL;
-}
-
-
-/* Return address from name
- * Accepts: name or NIL to return next address
- * pointer to previous/returned length
- * pointer to previous/returned address family
- * pointer to previous/returned canonical name
- * pointer to previous/return state for next-address calls
- * 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)
-{
- char tmp[MAILTMPLEN];
- struct hostent *he;
- void *ret = NIL;
- if (name) { /* first lookup? */
- /* yes, do case-independent lookup */
- if ((strlen (name) < MAILTMPLEN) &&
- (he = gethostbyname (lcase (strcpy (tmp,name))))) {
- if (len) *len = he->h_length;
- if (family) *family = he->h_addrtype;
- if (canonical) *canonical = (char *) he->h_name;
- if (next) *next = 0;
- ret = he->h_addr; /* set result to this one and only block */
- }
- else { /* error */
- if (len) *len = 0;
- if (family) *family = 0;
- if (canonical) *canonical = NIL;
- if (next) *next = NIL;
- }
- }
- return ret; /* return result */
-}
diff --git a/imap/src/osdep/unix/mbx.c b/imap/src/osdep/unix/mbx.c
index 1ece5d8d..dc902b20 100644
--- a/imap/src/osdep/unix/mbx.c
+++ b/imap/src/osdep/unix/mbx.c
@@ -1,5 +1,5 @@
/* ========================================================================
- * Copyright 1988-2007 University of Washington
+ * Copyright 1988-2012 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.
@@ -23,7 +23,7 @@
* Internet: MRC@CAC.Washington.EDU
*
* Date: 3 October 1995
- * Last Edited: 11 October 2007
+ * Last Edited: 21 February 2012
*/
@@ -1178,8 +1178,8 @@ long mbx_append (MAILSTREAM *stream,char *mailbox,append_t af,void *data)
else { /* write message */
size_t j;
if (!message->cursize) SETPOS (message,GETPOS (message));
- while (i && (j = fwrite (message->curpos,1,message->cursize,df))) {
- i -= j;
+ for (errno = 0; !errno && i &&
+ (j = fwrite (message->curpos,1,message->cursize,df)); i -= j) {
SETPOS (message,GETPOS (message) + j);
}
/* get next message */
diff --git a/imap/src/osdep/unix/mh.c b/imap/src/osdep/unix/mh.c
index 0226b7af..005000d6 100644
--- a/imap/src/osdep/unix/mh.c
+++ b/imap/src/osdep/unix/mh.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: MH mail routines
*
* Author(s): Mark Crispin
- * Networks and Distributed Computing
- * Computing & Communications
- * University of Washington
- * Administration Building, AG-44
- * Seattle, WA 98195
- * Internet: MRC@CAC.Washington.EDU
*
* Date: 23 February 1992
- * Last Edited: 11 October 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
+ *
*/
@@ -400,11 +397,11 @@ void mh_list (MAILSTREAM *stream,char *ref,char *pat)
void mh_lsub (MAILSTREAM *stream,char *ref,char *pat)
{
void *sdb = NIL;
- char *s,test[MAILTMPLEN];
+ char *s,test[MAILTMPLEN],tmp[MAILTMPLEN];
/* get canonical form of name */
- if (mh_canonicalize (test,ref,pat) && (s = sm_read (&sdb))) {
+ if (mh_canonicalize (test,ref,pat) && (s = sm_read (tmp,&sdb))) {
do if (pmatch_full (s,test,'/')) mm_lsub (stream,'/',s,NIL);
- while (s = sm_read (&sdb)); /* until no more subscriptions */
+ while (s = sm_read (tmp,&sdb)); /* until no more subscriptions */
}
}
diff --git a/imap/src/osdep/unix/mix.c b/imap/src/osdep/unix/mix.c
index fbf4a023..63009bb2 100644
--- a/imap/src/osdep/unix/mix.c
+++ b/imap/src/osdep/unix/mix.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-2012 Mark Crispin
* ========================================================================
*/
@@ -15,13 +7,19 @@
* Program: MIX mail routines
*
* Author(s): Mark Crispin
- * UW Technology
- * University of Washington
- * Seattle, WA 98195
- * Internet: MRC@Washington.EDU
*
* Date: 1 March 2006
- * Last Edited: 7 May 2008
+ * Last Edited: 15 February 2012
+ *
+ * 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
*/
@@ -417,7 +415,7 @@ long mix_create (MAILSTREAM *stream,char *mailbox)
strerror (errno));
else { /* success, write initial metadata */
fprintf (f,SEQFMT,now);
- fprintf (f,MTAFMT,now,0,now);
+ fprintf (f,MTAFMT,now,(unsigned long) 0,now);
for (i = 0, c = 'K'; (i < NUSERFLAGS) &&
(t = (stream && stream->user_flags[i]) ? stream->user_flags[i] :
default_user_flag (i)) && *t; ++i) {
@@ -1040,7 +1038,7 @@ long mix_expunge (MAILSTREAM *stream,char *sequence,long options)
/* expunge unless just burping */
if (!burponly) for (i = 1; i <= stream->nmsgs;) {
elt = mail_elt (stream,i);/* need to expunge this message? */
- if (sequence ? elt->sequence : elt->deleted) {
+ if (elt->deleted && (sequence ? elt->sequence : T)) {
++nexp; /* yes, make it so */
mail_expunged (stream,i);
}
@@ -1061,7 +1059,7 @@ long mix_expunge (MAILSTREAM *stream,char *sequence,long options)
/* another file found */
if (cur) cur = cur->next = nxt;
else cur = burp = nxt;
- cur->name = names[i]->d_name;
+ cur->name = cpystr (names[i]->d_name);
cur->fileno = strtoul (cur->name + sizeof (MIXNAME) - 1,NIL,16);
cur->tail = &cur->set;
fs_give ((void **) &names[i]);
@@ -1104,6 +1102,12 @@ long mix_expunge (MAILSTREAM *stream,char *sequence,long options)
MM_LOG (LOCAL->buf,WARN);
}
}
+ while (burp) { /* flush the burp list */
+ cur = burp->next;
+ if (burp->name) fs_give ((void **) &burp->name);
+ fs_give ((void **) &burp);
+ burp = cur;
+ }
}
else MM_LOG ("No mix message files found during expunge",WARN);
/* free directory list */
@@ -1116,7 +1120,7 @@ long mix_expunge (MAILSTREAM *stream,char *sequence,long options)
/* Do this step even if ret is NIL (meaning some burp problem)! */
if (nexp || reclaimed) { /* rewrite index and status if changed */
LOCAL->indexseq = mix_modseq (LOCAL->indexseq);
- if (mix_index_update (stream,idxf,NIL)) {
+ if (ret = mix_index_update (stream,idxf,NIL)) {
LOCAL->statusseq = mix_modseq (LOCAL->statusseq);
/* set failure if update fails */
ret = mix_status_update (stream,statf,NIL);
@@ -1269,7 +1273,7 @@ long mix_burp (MAILSTREAM *stream,MIXBURP *burp,unsigned long *reclaimed)
return NIL; /* burp fails for this file */
}
/* burp out each old message */
- for (set = &burp->set, wpos = 0; set; set = set->next) {
+ for (set = &burp->set, rpos = wpos = 0; set; set = set->next) {
/* move down this range */
for (rpos = set->first, size = set->last - set->first;
size; size -= wsize) {
@@ -1288,8 +1292,8 @@ long mix_burp (MAILSTREAM *stream,MIXBURP *burp,unsigned long *reclaimed)
MM_DISKERROR (stream,errno,T);
}
/* and especially not here */
- for (s = LOCAL->buf, wpending = wsize; wpending; wpending -= written)
- if (!(written = fwrite (LOCAL->buf,1,wpending,f))) {
+ for (s = LOCAL->buf, wpending = wsize; wpending; s += written, wpending -= written)
+ if (!(written = fwrite (s,1,wpending,f))) {
MM_NOTIFY (stream,strerror (errno),WARN);
MM_DISKERROR (stream,errno,T);
}
@@ -1390,7 +1394,8 @@ long mix_copy (MAILSTREAM *stream,char *sequence,char *mailbox,long options)
if (local->indexseq > seq) seq = local->indexseq + 1;
if (local->statusseq > seq) seq = local->statusseq + 1;
/* calculate size of per-message header */
- sprintf (local->buf,MSRFMT,MSGTOK,0,0,0,0,0,0,0,'+',0,0,0);
+ sprintf (local->buf,MSRFMT,MSGTOK,(unsigned long) 0,0,0,0,0,0,0,'+',0,0,
+ (unsigned long) 0);
hdrsize = strlen (local->buf);
MM_CRITICAL (stream); /* go critical */
@@ -1547,7 +1552,8 @@ long mix_append (MAILSTREAM *stream,char *mailbox,append_t af,void *data)
if (local->indexseq > seq) seq = local->indexseq + 1;
if (local->statusseq > seq) seq = local->statusseq + 1;
/* calculate size of per-message header */
- sprintf (local->buf,MSRFMT,MSGTOK,0,0,0,0,0,0,0,'+',0,0,0);
+ sprintf (local->buf,MSRFMT,MSGTOK,(unsigned long) 0,0,0,0,0,0,0,'+',0,0,
+ (unsigned long) 0);
hdrsize = strlen (local->buf);
MM_CRITICAL (astream); /* go critical */
astream->silent = T; /* no events here */
@@ -1631,6 +1637,7 @@ long mix_append_msg (MAILSTREAM *stream,FILE *f,char *flags,MESSAGECACHE *delt,
int c,cs;
unsigned long i,j,k,uf,hoff;
long sf;
+ void *s;
stream->kwd_create = NIL; /* don't copy unknown keywords */
sf = mail_parse_flags (stream,flags,&uf);
/* swell the cache */
@@ -1669,8 +1676,8 @@ long mix_append_msg (MAILSTREAM *stream,FILE *f,char *flags,MESSAGECACHE *delt,
for (cs = 0; SIZE (msg); ) { /* copy message */
if (elt->private.msg.header.text.size) {
if (msg->cursize) /* blat entire chunk if have it */
- for (j = msg->cursize; j; j -= k)
- if (!(k = fwrite (msg->curpos,1,j,f))) return NIL;
+ for (s = msg->curpos,j = msg->cursize; j; s += k, j -= k)
+ if (!(k = fwrite (s,1,j,f))) return NIL;
SETPOS (msg,GETPOS (msg) + msg->cursize);
}
else { /* still searching for delimiter */
@@ -1813,6 +1820,7 @@ FILE *mix_parse (MAILSTREAM *stream,FILE **idxf,long iflags,long sflags)
}
/* sequence changed from last time? */
else if (j || (i > LOCAL->indexseq)) {
+ unsigned long prevuid = 0;
unsigned long uid,nmsgs,curfile,curfilesize,curpos;
char *t,*msg,tmp[MAILTMPLEN];
/* start with no messages */
@@ -1870,6 +1878,12 @@ FILE *mix_parse (MAILSTREAM *stream,FILE **idxf,long iflags,long sflags)
/* ignore expansion values */
if (*s++ == ':') {
MESSAGECACHE *elt;
+ if(prevuid > uid) {
+ sprintf (tmp,"mix index backwards UID: %lx",uid);
+ MM_LOG (tmp,ERROR);
+ return NIL;
+ }
+ prevuid = uid;
++nmsgs; /* this is another mesage */
/* within current known range of messages? */
while (nmsgs <= stream->nmsgs) {
@@ -2234,7 +2248,9 @@ long mix_index_update (MAILSTREAM *stream,FILE *idxf,long flag)
for (i = 1, size = 0; i <= stream->nmsgs; ++i)
if (!mail_elt (stream,i)->private.ghost) ++size;
if (size) { /* Winston Smith's first dairy entry */
- sprintf (tmp,IXRFMT,0,14,4,4,13,0,0,'+',0,0,0,0,0,0,0);
+ sprintf (tmp,IXRFMT,(unsigned long) 0,14,4,4,13,0,0,'+',0,0,
+ (unsigned long) 0,(unsigned long) 0,(unsigned long) 0,
+ (unsigned long) 0,(unsigned long) 0);
size *= strlen (tmp);
}
/* calculate file size we need */
@@ -2315,7 +2331,8 @@ long mix_status_update (MAILSTREAM *stream,FILE *statf,long flag)
for (i = 1, size = 0; i <= stream->nmsgs; ++i)
if (!mail_elt (stream,i)->private.ghost) ++size;
if (size) { /* number of living messages */
- sprintf (tmp,STRFMT,0,0,0,0);
+ sprintf (tmp,STRFMT,(unsigned long) 0,(unsigned long) 0,0,
+ (unsigned long) 0);
size *= strlen (tmp);
}
sprintf (tmp,SEQFMT,LOCAL->statusseq);
@@ -2408,14 +2425,30 @@ FILE *mix_data_open (MAILSTREAM *stream,int *fd,long *size,
if (curend > sbuf.st_size) {
char tmp[MAILTMPLEN];
sprintf (tmp,"short mix message file %.08lx (%ld > %ld), rolling",
- LOCAL->newmsg,curend,sbuf.st_size);
+ LOCAL->newmsg,curend,(unsigned long) sbuf.st_size);
MM_LOG (tmp,WARN); /* shouldn't happen */
}
close (*fd); /* roll to a new file */
+ errno = NIL;
while ((*fd = open (mix_file_data
(LOCAL->buf,stream->mailbox,
LOCAL->newmsg = mix_modseq (LOCAL->newmsg)),
- O_RDWR | O_CREAT | O_EXCL,sbuf.st_mode)) < 0);
+ O_RDWR | O_CREAT | O_EXCL,sbuf.st_mode)) < 0) {
+ switch(errno) {
+ case EEXIST: /* always retry if path exists or interrupt */
+ case EINTR:
+ errno = NIL;
+ break;
+ default: /* probably EDQUOT */
+ {
+ char tmp[MAILTMPLEN];
+ sprintf (tmp,"data file %.08lx creation failure: %.80s",
+ LOCAL->newmsg,strerror (errno));
+ MM_LOG (tmp,ERROR); /* shouldn't happen */
+ return NIL;
+ }
+ }
+ }
*size = 0; /* brand new file */
fchmod (*fd,sbuf.st_mode);/* with same mode as previous file */
}
diff --git a/imap/src/osdep/unix/os_bsf.c b/imap/src/osdep/unix/os_bsf.c
index afe26e23..f32b1fb2 100644
--- a/imap/src/osdep/unix/os_bsf.c
+++ b/imap/src/osdep/unix/os_bsf.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-2009 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,20 @@
* Program: Operating-system dependent routines -- BSDI BSD/386 version
*
* 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: 1 August 1988
- * Last Edited: 16 August 2007
+ * Last Edited: 18 May 2009
+ *
+ * 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 "tcp_unix.h" /* must be before osdep includes tcp.h */
@@ -52,3 +49,4 @@ extern int errno; /* just in case */
#include "tcp_unix.c"
#include "gr_waitp.c"
#include "tz_bsd.c"
+#include "utime.c"
diff --git a/imap/src/osdep/unix/os_bsf.h b/imap/src/osdep/unix/os_bsf.h
index af18d567..914192de 100644
--- a/imap/src/osdep/unix/os_bsf.h
+++ b/imap/src/osdep/unix/os_bsf.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-2009 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,20 @@
* Program: Operating-system dependent routines -- FreeBSD version
*
* 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: 5 March 1993
- * Last Edited: 30 August 2006
+ * Last Edited: 18 May 2009
+ *
+ * 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
+ *
*/
#include <stdlib.h>
@@ -32,12 +29,16 @@
#include <sys/types.h>
#include <dirent.h>
#include <fcntl.h>
+#include <utime.h>
#include <syslog.h>
#include <sys/file.h>
#define direct dirent
+#define utime portable_utime
+int portable_utime (char *file,time_t timep[2]);
+
#include "env_unix.h"
#include "fs.h"
diff --git a/imap/src/osdep/unix/os_bsi.c b/imap/src/osdep/unix/os_bsi.c
index afe26e23..f32b1fb2 100644
--- a/imap/src/osdep/unix/os_bsi.c
+++ b/imap/src/osdep/unix/os_bsi.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-2009 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,20 @@
* Program: Operating-system dependent routines -- BSDI BSD/386 version
*
* 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: 1 August 1988
- * Last Edited: 16 August 2007
+ * Last Edited: 18 May 2009
+ *
+ * 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 "tcp_unix.h" /* must be before osdep includes tcp.h */
@@ -52,3 +49,4 @@ extern int errno; /* just in case */
#include "tcp_unix.c"
#include "gr_waitp.c"
#include "tz_bsd.c"
+#include "utime.c"
diff --git a/imap/src/osdep/unix/os_bsi.h b/imap/src/osdep/unix/os_bsi.h
index 15f371a3..f2d9f75d 100644
--- a/imap/src/osdep/unix/os_bsi.h
+++ b/imap/src/osdep/unix/os_bsi.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-2009 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,20 @@
* Program: Operating-system dependent routines -- BSDI BSD/386 version
*
* 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: 5 March 1993
- * Last Edited: 30 August 2006
+ * Last Edited: 2 September 2009
+ *
+ * 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
+ *
*/
#include <stdlib.h>
@@ -32,9 +29,14 @@
#include <sys/types.h>
#include <sys/dir.h>
#include <fcntl.h>
+#include <time.h>
+#include <utime.h>
#include <syslog.h>
#include <sys/file.h>
+#define utime portable_utime
+int portable_utime (char *file,time_t timep[2]);
+
#include "env_unix.h"
#include "fs.h"
diff --git a/imap/src/osdep/unix/os_lnx.c b/imap/src/osdep/unix/os_lnx.c
index 03fd17d9..e95b2ac2 100644
--- a/imap/src/osdep/unix/os_lnx.c
+++ b/imap/src/osdep/unix/os_lnx.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-2009 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,20 @@
* Program: Operating-system dependent routines -- old Linux version
*
* 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: 1 August 1993
- * Last Edited: 16 August 2007
+ * Last Edited: 18 May 2009
+ *
+ * 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 "tcp_unix.h" /* must be before osdep includes tcp.h */
@@ -52,3 +49,4 @@ extern int errno; /* just in case */
#include "gr_waitp.c"
#include "tz_sv4.c"
#include "flocklnx.c"
+#include "utime.c"
diff --git a/imap/src/osdep/unix/os_lnx.h b/imap/src/osdep/unix/os_lnx.h
index b5f39ffa..4656b12c 100644
--- a/imap/src/osdep/unix/os_lnx.h
+++ b/imap/src/osdep/unix/os_lnx.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-2009 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,20 @@
* Program: Operating-system dependent routines -- Linux version
*
* 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: 10 September 1993
- * Last Edited: 30 August 2006
+ * Last Edited: 18 May 2009
+ *
+ * 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
+ *
*/
/*
@@ -47,6 +44,7 @@
#include <dirent.h>
#include <time.h> /* for struct tm */
#include <fcntl.h>
+#include <utime.h>
#include <syslog.h>
#include <sys/file.h>
@@ -59,6 +57,9 @@
#define flock safe_flock
+#define utime portable_utime
+int portable_utime (char *file,time_t timep[2]);
+
#include "env_unix.h"
#include "fs.h"
diff --git a/imap/src/osdep/unix/os_osx.c b/imap/src/osdep/unix/os_osx.c
index 25eb1a7d..e09806c2 100644
--- a/imap/src/osdep/unix/os_osx.c
+++ b/imap/src/osdep/unix/os_osx.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-2009 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,21 @@
* Program: Operating-system dependent routines -- Mac OS X version
*
* 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: 1 August 1988
- * Last Edited: 16 August 2007
+ * Last Edited: 18 May 2009
+ *
+ * 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 "tcp_unix.h" /* must be before osdep includes tcp.h */
@@ -52,3 +50,4 @@ extern int errno; /* just in case */
#include "tcp_unix.c"
#include "gr_wait4.c"
#include "tz_bsd.c"
+#include "utime.c"
diff --git a/imap/src/osdep/unix/os_osx.h b/imap/src/osdep/unix/os_osx.h
index 3480e14a..6fcb014d 100644
--- a/imap/src/osdep/unix/os_osx.h
+++ b/imap/src/osdep/unix/os_osx.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-2009 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,20 @@
* Program: Operating-system dependent routines -- Mac OS X version
*
* 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: 1 August 1988
- * Last Edited: 26 October 2007
+ * Last Edited: 18 May 2009
+ *
+ * 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
+ *
*/
#include <stdlib.h>
@@ -32,6 +29,7 @@
#include <sys/types.h>
#include <sys/dir.h>
#include <fcntl.h>
+#include <utime.h>
#include <syslog.h>
#include <sys/file.h>
@@ -49,6 +47,11 @@
#define checkpw Checkpw
+
+#define utime portable_utime
+int portable_utime (char *file,time_t timep[2]);
+
+
#include "env_unix.h"
#include "fs.h"
#include "ftl.h"
diff --git a/imap/src/osdep/unix/os_qn6.c b/imap/src/osdep/unix/os_qn6.c
new file mode 100644
index 00000000..ded8c848
--- /dev/null
+++ b/imap/src/osdep/unix/os_qn6.c
@@ -0,0 +1,67 @@
+/* ========================================================================
+ * Copyright 2008-2009 Mark Crispin
+ * ========================================================================
+ */
+
+/*
+ * Program: Operating-system dependent routines -- QNX 6 version
+ *
+ * Author: Mark Crispin
+ *
+ * Date: 1 August 1993
+ * Last Edited: 17 April 2009
+ *
+ * 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
+ *
+ */
+
+#include "tcp_unix.h" /* must be before osdep includes tcp.h */
+#include "mail.h"
+#include "osdep.h"
+#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <ctype.h>
+#include <errno.h>
+extern int errno; /* just in case */
+#include <pwd.h>
+#include <shadow.h>
+#include <sys/select.h>
+#include "misc.h"
+
+#define DIR_SIZE(d) d->d_reclen
+
+#include "fs_unix.c"
+#include "ftl_unix.c"
+#include "nl_unix.c"
+#include "env_unix.c"
+#include "tcp_unix.c"
+#include "gr_wait.c"
+#include "tz_sv4.c"
+#include "gethstid.c"
+#include "flocksim.c"
+#include "utime.c"
+
+/* QNX local ustat()
+ * Accepts: device id
+ * returned statistics
+ * Returns: 0 if success, -1 if failure with errno set
+ */
+
+int ustat (dev_t dev,struct ustat *ub)
+{
+ errno = ENOSYS; /* fstatvfs() should have been tried first */
+ return -1;
+}
diff --git a/imap/src/osdep/unix/os_qn6.h b/imap/src/osdep/unix/os_qn6.h
new file mode 100644
index 00000000..9d4f379c
--- /dev/null
+++ b/imap/src/osdep/unix/os_qn6.h
@@ -0,0 +1,76 @@
+/* ========================================================================
+ * Copyright 2008-2009 Mark Crispin
+ * ========================================================================
+ */
+
+/*
+ * Program: Operating-system dependent routines -- QNX 6 version
+ *
+ * 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: 10 September 1993
+ * Last Edited: 17 April 2009
+ *
+ * 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
+ *
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <syslog.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/dir.h>
+#include <sys/types.h>
+#include <time.h>
+#include <utime.h>
+#include <ustat.h>
+
+
+/* QNX gets this wrong */
+
+#define setpgrp setpgid
+#define FNDELAY O_NONBLOCK
+
+
+/* Different names, equivalent things in BSD and SysV */
+
+#ifndef L_SET
+#define L_SET SEEK_SET
+#endif
+#ifndef L_INCR
+#define L_INCR SEEK_CUR
+#endif
+#ifndef L_XTND
+#define L_XTND SEEK_END
+#endif
+
+
+#define utime portable_utime
+int portable_utime (char *file,time_t timep[2]);
+
+long gethostid (void);
+typedef int (*select_t) (struct direct *name);
+typedef int (*compar_t) (void *d1,void *d2);
+
+#include "env_unix.h"
+#include "fs.h"
+#include "ftl.h"
+#include "nl.h"
+#include "tcp.h"
+#include "flocksim.h"
diff --git a/imap/src/osdep/unix/os_slx.c b/imap/src/osdep/unix/os_slx.c
index c94d6322..95c586af 100644
--- a/imap/src/osdep/unix/os_slx.c
+++ b/imap/src/osdep/unix/os_slx.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-2009 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,20 @@
* Program: Operating-system dependent routines -- modern Linux version
*
* 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: 1 August 1993
- * Last Edited: 16 August 2007
+ * Last Edited: 18 May 2009
+ *
+ * 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 "tcp_unix.h" /* must be before osdep includes tcp.h */
@@ -54,3 +51,4 @@ extern int errno; /* just in case */
#include "gr_waitp.c"
#include "tz_sv4.c"
#include "flocklnx.c"
+#include "utime.c"
diff --git a/imap/src/osdep/unix/os_slx.h b/imap/src/osdep/unix/os_slx.h
index b5f39ffa..4656b12c 100644
--- a/imap/src/osdep/unix/os_slx.h
+++ b/imap/src/osdep/unix/os_slx.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-2009 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,20 @@
* Program: Operating-system dependent routines -- Linux version
*
* 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: 10 September 1993
- * Last Edited: 30 August 2006
+ * Last Edited: 18 May 2009
+ *
+ * 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
+ *
*/
/*
@@ -47,6 +44,7 @@
#include <dirent.h>
#include <time.h> /* for struct tm */
#include <fcntl.h>
+#include <utime.h>
#include <syslog.h>
#include <sys/file.h>
@@ -59,6 +57,9 @@
#define flock safe_flock
+#define utime portable_utime
+int portable_utime (char *file,time_t timep[2]);
+
#include "env_unix.h"
#include "fs.h"
diff --git a/imap/src/osdep/unix/scandir.c b/imap/src/osdep/unix/scandir.c
index 878343e8..c5e4541b 100644
--- a/imap/src/osdep/unix/scandir.c
+++ b/imap/src/osdep/unix/scandir.c
@@ -1,4 +1,18 @@
/* ========================================================================
+ * Copyright 2008-2009 Mark Crispin
+ * ========================================================================
+ */
+
+/*
+ * Program: Scan directories
+ *
+ * Author: Mark Crispin
+ *
+ * Date: 1 August 1988
+ * Last Edited: 12 June 2009
+ *
+ * Previous versions of this file were:
+ *
* Copyright 1988-2006 University of Washington
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -10,21 +24,6 @@
*
* ========================================================================
*/
-
-/*
- * Program: Scan directories
- *
- * 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: 1 August 1988
- * Last Edited: 15 September 2006
- */
/* Emulator for BSD scandir() call
* Accepts: directory name
@@ -43,7 +42,8 @@ int scandir (char *dirname,struct direct ***namelist,select_t select,
long nlmax;
DIR *dirp = opendir (dirname);/* open directory and get status poop */
if ((!dirp) || (fstat (dirp->dd_fd,&stb) < 0)) return -1;
- nlmax = stb.st_size / 24; /* guesstimate at number of files */
+ /* guesstimate at number of files */
+ nlmax = max (stb.st_size / 24,32);
names = (struct direct **) fs_get (nlmax * sizeof (struct direct *));
nitems = 0; /* initially none found */
while (d = readdir (dirp)) { /* read directory item */
diff --git a/imap/src/osdep/unix/ssl_none.c b/imap/src/osdep/unix/ssl_none.c
index e4dedda7..a87c4be6 100644
--- a/imap/src/osdep/unix/ssl_none.c
+++ b/imap/src/osdep/unix/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/unix/ssl_unix.c b/imap/src/osdep/unix/ssl_unix.c
index 3f6bcce9..d77ed719 100644
--- a/imap/src/osdep/unix/ssl_unix.c
+++ b/imap/src/osdep/unix/ssl_unix.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,18 +7,24 @@
* Program: 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: 22 September 1998
- * Last Edited: 13 January 2007
+ * 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 crypt ssl_private_crypt
+#define STRING OPENSSL_STRING
#include <x509v3.h>
#include <ssl.h>
#include <err.h>
@@ -35,11 +33,27 @@
#include <bio.h>
#include <crypto.h>
#include <rand.h>
+#undef STRING
#undef crypt
#define SSLBUFLEN 8192
-#define SSLCIPHERLIST "ALL:!LOW"
+/*
+ * PCI auditing compliance, disable:
+ * SSLv2
+ * anonymous D-H (no certificate
+ * export encryption ciphers (40 and 56 bits)
+ * low encryption cipher suites (40 and 56 bits, excluding export)
+ * null encryption (disabling implied by "ALL")
+ *
+ * UW imapd just disables low-grade and null ("ALL:!LOW"). This setting
+ * will break clients that attempt to use the newly-prohibited mechanisms.
+ *
+ * I question the value of disabling SSLv2, as opposed to disabling the SSL
+ * ports (e.g., 993 for IMAP, 995 for POP3) and using TLS exclusively.
+ */
+
+#define SSLCIPHERLIST "ALL:!SSLv2:!ADH:!EXP:!LOW"
/* SSL I/O stream */
@@ -635,7 +649,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/unix/sslstdio.c b/imap/src/osdep/unix/sslstdio.c
index 4059a859..3d3b1e06 100644
--- a/imap/src/osdep/unix/sslstdio.c
+++ b/imap/src/osdep/unix/sslstdio.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: SSL standard I/O routines for server use
*
* 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: 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
+ *
*/
/* Get character
@@ -32,7 +29,15 @@
int PBIN (void)
{
- if (!sslstdio) return getchar ();
+ if (!sslstdio) {
+ int ret;
+ do {
+ clearerr (stdin);
+ ret = getchar ();
+ } while ((ret == EOF) && !feof (stdin) && ferror (stdin) &&
+ (errno == EINTR));
+ return ret;
+ }
if (!ssl_getdata (sslstdio->sslstream)) return EOF;
/* one last byte available */
sslstdio->sslstream->ictr--;
@@ -53,7 +58,14 @@ char *PSIN (char *s,int n)
ssl_server_init (start_tls);/* enter the mode */
start_tls = NIL; /* don't do this again */
}
- if (!sslstdio) return fgets (s,n,stdin);
+ if (!sslstdio) {
+ char *ret;
+ do {
+ clearerr (stdin);
+ ret = fgets (s,n,stdin);
+ } while (!ret && !feof (stdin) && ferror (stdin) && (errno == EINTR));
+ return ret;
+ }
for (i = c = 0, n-- ; (c != '\n') && (i < n); sslstdio->sslstream->ictr--) {
if ((sslstdio->sslstream->ictr <= 0) && !ssl_getdata (sslstdio->sslstream))
return NIL; /* read error */
diff --git a/imap/src/osdep/unix/tcp_unix.c b/imap/src/osdep/unix/tcp_unix.c
index 127cf2ae..652f1250 100644
--- a/imap/src/osdep/unix/tcp_unix.c
+++ b/imap/src/osdep/unix/tcp_unix.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-2011 Mark Crispin
* ========================================================================
*/
@@ -15,20 +7,30 @@
* Program: UNIX TCP/IP 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: 1 August 1988
- * Last Edited: 13 January 2008
+ * Last Edited: 29 August 2011
+ *
+ * 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
+ *
*/
#include "ip_unix.c"
#undef write /* don't use redefined write() */
+
+#ifndef NI_MAXHOST
+#define NI_MAXHOST 1025
+#endif
+
static tcptimeout_t tmoh = NIL; /* TCP timeout handler routine */
static long ttmo_open = 0; /* TCP timeouts, in seconds */
@@ -155,9 +157,11 @@ TCPSTREAM *tcp_open (char *host,char *service,unsigned long port)
int ctr = 0;
int silent = (port & NET_SILENT) ? T : NIL;
int *ctrp = (port & NET_NOOPENTIMEOUT) ? NIL : &ctr;
- char *s,*hostname,tmp[MAILTMPLEN];
+ char *s,tmp[MAILTMPLEN];
+ char *hostname = NIL;
void *adr;
size_t adrlen;
+ void *cleanup = NIL;
struct servent *sv = NIL;
blocknotify_t bn = (blocknotify_t) mail_parameters (NIL,GET_BLOCKNOTIFY,NIL);
void *data,*next;
@@ -175,7 +179,8 @@ TCPSTREAM *tcp_open (char *host,char *service,unsigned long port)
if (adr = ip_stringtoaddr (tmp,&adrlen,&family)) {
(*bn) (BLOCK_TCPOPEN,NIL);
/* get an open socket for this system */
- sock = tcp_socket_open (family,adr,adrlen,port,tmp,ctrp,hostname = host);
+ sock = tcp_socket_open (family,adr,adrlen,port,tmp,ctrp,
+ hostname = cpystr(host));
(*bn) (BLOCK_NONE,NIL);
fs_give ((void **) &adr);
}
@@ -189,7 +194,7 @@ TCPSTREAM *tcp_open (char *host,char *service,unsigned long port)
}
(*bn) (BLOCK_DNSLOOKUP,NIL);/* quell alarms */
data = (*bn) (BLOCK_SENSITIVE,NIL);
- if (!(s = ip_nametoaddr (host,&adrlen,&family,&hostname,&next)))
+ if (!(s = ip_nametoaddr (host,&adrlen,&family,&hostname,&next,&cleanup)))
sprintf (tmp,"No such host as %.80s",host);
(*bn) (BLOCK_NONSENSITIVE,data);
(*bn) (BLOCK_NONE,NIL);
@@ -199,13 +204,19 @@ TCPSTREAM *tcp_open (char *host,char *service,unsigned long port)
(*bn) (BLOCK_TCPOPEN,NIL);
if (((sock = tcp_socket_open (family,s,adrlen,port,tmp,ctrp,
hostname)) < 0) &&
- (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 < 0) && s);/* repeat until success or no more addreses */
}
+ ip_nametoaddr (NIL,NIL,NIL,NIL,NIL,&cleanup);
+ }
+ if (sock < 0) { /* lost? */
+ if (!silent) mm_log (tmp,ERROR);
+ if (hostname) fs_give ((void **) &hostname);
}
- if (sock >= 0) { /* won */
+ else { /* won */
stream = (TCPSTREAM *) memset (fs_get (sizeof (TCPSTREAM)),0,
sizeof (TCPSTREAM));
stream->port = port; /* port number */
@@ -213,11 +224,9 @@ TCPSTREAM *tcp_open (char *host,char *service,unsigned long port)
stream->tcpsi = stream->tcpso = sock;
/* stash in the snuck-in byte */
if (stream->ictr = ctr) *(stream->iptr = stream->ibuf) = tmp[0];
- /* 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);
}
- else if (!silent) mm_log (tmp,ERROR);
return stream; /* return success */
}
@@ -238,17 +247,17 @@ int tcp_socket_open (int family,void *adr,size_t adrlen,unsigned short port,
int i,ti,sock,flgs;
size_t len;
time_t now;
- struct protoent *pt = getprotobyname ("tcp");
- fd_set fds,efds;
+ fd_set rfds,wfds,efds;
+ char buf[NI_MAXHOST];
struct timeval tmo;
struct sockaddr *sadr = ip_sockaddr (family,adr,adrlen,port,&len);
blocknotify_t bn = (blocknotify_t) mail_parameters (NIL,GET_BLOCKNOTIFY,NIL);
/* fetid Solaris */
void *data = (*bn) (BLOCK_SENSITIVE,NIL);
- sprintf (tmp,"Trying IP address [%s]",ip_sockaddrtostring (sadr));
+ sprintf (tmp,"Trying IP address [%s]",ip_sockaddrtostring (sadr,buf));
mm_log (tmp,NIL);
/* make a socket */
- if ((sock = socket (sadr->sa_family,SOCK_STREAM,pt ? pt->p_proto : 0)) < 0) {
+ if ((sock = socket (sadr->sa_family,SOCK_STREAM,0)) < 0) {
sprintf (tmp,"Unable to create TCP socket: %s",strerror (errno));
(*bn) (BLOCK_NONSENSITIVE,data);
}
@@ -285,13 +294,15 @@ int tcp_socket_open (int family,void *adr,size_t adrlen,unsigned short port,
now = time (0); /* open timeout */
ti = ttmo_open ? now + ttmo_open : 0;
tmo.tv_usec = 0;
- FD_ZERO (&fds); /* initialize selection vector */
+ FD_ZERO (&rfds); /* initialize selection vector */
+ FD_ZERO (&wfds);
FD_ZERO (&efds); /* handle errors too */
- FD_SET (sock,&fds); /* block for error or readable */
+ FD_SET (sock,&rfds); /* block for readable, writeable, or error */
+ FD_SET (sock,&wfds);
FD_SET (sock,&efds);
do { /* block under timeout */
tmo.tv_sec = ti ? ti - now : 0;
- i = select (sock+1,&fds,NIL,&efds,ti ? &tmo : NIL);
+ i = select (sock+1,&rfds,&wfds,&efds,ti ? &tmo : NIL);
now = time (0); /* fake timeout if interrupt & time expired */
if ((i < 0) && (errno == EINTR) && ti && (ti <= now)) i = 0;
} while ((i < 0) && (errno == EINTR));
@@ -300,7 +311,8 @@ int tcp_socket_open (int family,void *adr,size_t adrlen,unsigned short port,
fcntl (sock,F_SETFL,flgs);
/* This used to be a zero-byte read(), but that crashes Solaris */
/* get socket status */
- while (((i = *ctr = read (sock,tmp,1)) < 0) && (errno == EINTR));
+ if(FD_ISSET(sock,&rfds))
+ while (((i = *ctr = read (sock,tmp,1)) < 0) && (errno == EINTR));
}
if (i <= 0) { /* timeout or error? */
i = i ? errno : ETIMEDOUT;/* determine error code */
@@ -366,7 +378,10 @@ TCPSTREAM *tcp_aopen (NETMBX *mb,char *service,char *usrbuf)
return NIL;
}
}
- else strcpy (host,tcp_canonical (mb->host));
+ else {
+ strcpy (host,r = tcp_canonical (mb->host));
+ fs_give((void **) &r);
+ }
if (*service == '*') /* build ssh command */
sprintf (tmp,sshcommand,sshpath,host,
@@ -765,7 +780,8 @@ long tcp_abort (TCPSTREAM *stream)
char *tcp_host (TCPSTREAM *stream)
{
- return stream->host; /* use tcp_remotehost() if want guarantees */
+ /* use tcp_remotehost() if want guarantees */
+ return stream ? stream->host : "UNKNOWN";
}
@@ -825,12 +841,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))
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);
@@ -846,6 +863,7 @@ 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)) {
@@ -861,7 +879,7 @@ char *tcp_clienthost ()
}
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);
@@ -887,12 +905,13 @@ long tcp_clientport ()
char *tcp_serveraddr ()
{
if (!myServerAddr) {
+ char buf[NI_MAXHOST];
size_t sadrlen;
struct sockaddr *sadr = ip_newsockaddr (&sadrlen);
if (getsockname (0,sadr,(void *) &sadrlen))
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);
@@ -908,6 +927,7 @@ char *tcp_serveraddr ()
char *tcp_serverhost ()
{
if (!myServerHost) { /* once-only */
+ char buf[NI_MAXHOST];
size_t sadrlen;
struct sockaddr *sadr = ip_newsockaddr (&sadrlen);
/* get stdin's name */
@@ -915,7 +935,7 @@ char *tcp_serverhost ()
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);
@@ -953,7 +973,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_NONSENSITIVE,data);
(*bn) (BLOCK_NONE,NIL); /* alarms OK now */
if (tcpdebug) mm_log ("DNS canonicalization done",TCPDEBUG);
@@ -968,8 +988,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);
void *data;
@@ -980,7 +1000,7 @@ char *tcp_name (struct sockaddr *sadr,long flag)
(*bn) (BLOCK_DNSLOOKUP,NIL);/* quell alarms */
data = (*bn) (BLOCK_SENSITIVE,NIL);
/* 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;
@@ -1023,18 +1043,23 @@ long tcp_isclienthost (char *host)
int family;
size_t adrlen,sadrlen,len;
void *adr,*next;
+ char buf[NI_MAXHOST];
struct sockaddr *sadr;
+ void *cleanup = NIL;
long ret = NIL;
/* make sure that myClientAddr is set */
- if (tcp_clienthost () && myClientAddr)
+ if (tcp_clienthost () && myClientAddr) {
/* get sockaddr of client */
- for (adr = ip_nametoaddr (host,&adrlen,&family,NIL,&next); adr && !ret;
- adr = ip_nametoaddr (NIL,&adrlen,&family,NIL,&next)) {
+ for (adr = ip_nametoaddr (host,&adrlen,&family,NIL,&next,&cleanup);
+ adr && !ret;
+ adr = ip_nametoaddr (NIL,&adrlen,&family,NIL,&next,&cleanup)) {
/* build sockaddr of given address */
sadr = ip_sockaddr (family,adr,adrlen,1,&len);
- if (!strcmp (myClientAddr,ip_sockaddrtostring (sadr))) ret = LONGT;
+ if (!strcmp (myClientAddr,ip_sockaddrtostring (sadr,buf))) ret = LONGT;
fs_give ((void **) &sadr); /* done with client sockaddr */
}
+ ip_nametoaddr (NIL,NIL,NIL,NIL,NIL,&cleanup);
+ }
return ret;
}
diff --git a/imap/src/osdep/vms/env_vms.h b/imap/src/osdep/vms/env_vms.h
index 59160a06..314333bd 100644
--- a/imap/src/osdep/vms/env_vms.h
+++ b/imap/src/osdep/vms/env_vms.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
* ========================================================================
*/
@@ -15,15 +7,20 @@
* Program: VMS environment 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: 2 August 1994
- * 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
+ *
*/
@@ -34,7 +31,7 @@
#include "env.h"
-char *myusername ();
+char *myusername (void);
/* syslog() emulation */
diff --git a/imap/src/osdep/vms/tcp_vmsl.c b/imap/src/osdep/vms/tcp_vmsl.c
index 692c9212..37e09dfd 100644
--- a/imap/src/osdep/vms/tcp_vmsl.c
+++ b/imap/src/osdep/vms/tcp_vmsl.c
@@ -1,29 +1,25 @@
/* ========================================================================
- * 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
* ========================================================================
*/
/*
- * Program: VMS TCP/IP routines for Netlib.
+ * Program: VMS TCP/IP routines for Netlib
*
* 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: 2 August 1994
- * Last Edited: 13 January 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
*/
/* Thanks to Yehavi Bourvine at The Hebrew University of Jerusalem who
@@ -364,7 +360,7 @@ char *mylocalhost ()
char *tcp_canonical (char *name)
{
- return name;
+ return cpystr (name);
}
diff --git a/imap/src/osdep/vms/tcp_vmsm.c b/imap/src/osdep/vms/tcp_vmsm.c
index bc9d9ca7..4a5483d6 100644
--- a/imap/src/osdep/vms/tcp_vmsm.c
+++ b/imap/src/osdep/vms/tcp_vmsm.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,15 +7,19 @@
* Program: VMS TCP/IP routines for Multinet
*
* 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: 2 August 1994
- * Last Edited: 13 January 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
*/
@@ -462,10 +458,11 @@ char *tcp_canonical (char *name)
char host[MAILTMPLEN];
struct hostent *he;
/* look like domain literal? */
- if (name[0] == '[' && name[strlen (name) - 1] == ']') return name;
+ if (name[0] == '[' && name[strlen (name) - 1] == ']')
+ return cpystr (name);
/* note that Unix requires lowercase! */
- else return (he = gethostbyname (lcase (strcpy (host,name)))) ?
- he->h_name : name;
+ else return cpystr ((he = gethostbyname (lcase (strcpy (host,name)))) ?
+ he->h_name : name);
}
diff --git a/imap/src/osdep/vms/tcp_vmsn.c b/imap/src/osdep/vms/tcp_vmsn.c
index 4648e48d..6ae12803 100644
--- a/imap/src/osdep/vms/tcp_vmsn.c
+++ b/imap/src/osdep/vms/tcp_vmsn.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-2010 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,19 @@
* Program: Dummy VMS TCP/IP routines for non-TCP/IP systems
*
* 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: 2 August 1994
- * Last Edited: 30 August 2006
+ * 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
*/
/* TCP/IP manipulate parameters
@@ -208,7 +204,7 @@ char *mylocalhost ()
char *tcp_canonical (char *name)
{
- return name;
+ return cpystr (name);
}
diff --git a/imap/src/osdep/wce/env_wce.h b/imap/src/osdep/wce/env_wce.h
index e3c6c7f0..585948a2 100644
--- a/imap/src/osdep/wce/env_wce.h
+++ b/imap/src/osdep/wce/env_wce.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
* ========================================================================
*/
@@ -15,15 +7,20 @@
* Program: WCE environment 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: 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
+ *
*/
@@ -39,8 +36,8 @@
static char *defaultDrive (void);
static char *homeDrive (void);
static char *homePath (char *path);
-char *sysinbox ();
-long random ();
+char *sysinbox (void);
+long random (void);
unsigned long unix_crlfcpy (char **dst,unsigned long *dstl,char *src,
unsigned long srcl);
unsigned long unix_crlflen (STRING *s);
diff --git a/imap/src/osdep/wce/tcp_wce.c b/imap/src/osdep/wce/tcp_wce.c
index 90e206a9..226750cb 100644
--- a/imap/src/osdep/wce/tcp_wce.c
+++ b/imap/src/osdep/wce/tcp_wce.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,15 +7,19 @@
* 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 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
*/
@@ -735,7 +731,7 @@ char *tcp_canonical (char *name)
ret = (he = gethostbyname (lcase (strcpy (host,name)))) ? he->h_name : name;
(*bn) (BLOCK_NONE,NIL);
if (tcpdebug) mm_log ("DNS canonicalization done",TCPDEBUG);
- return ret;
+ return cpystr(ret);
}
@@ -785,15 +781,13 @@ char *mylocalhost (void)
char tmp[MAILTMPLEN];
if (!wsa_initted++) { /* init Windows Sockets */
WSADATA wsock;
- if (WSAStartup (WSA_VERSION,&wsock)) {
+ if (WSAStartup (WSA_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";
}
diff --git a/imap/src/tmail/tmail.c b/imap/src/tmail/tmail.c
index ed5fc589..923a98a9 100644
--- a/imap/src/tmail/tmail.c
+++ b/imap/src/tmail/tmail.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 Mark Crispin
* ========================================================================
*/
@@ -15,15 +7,20 @@
* Program: Mail Delivery 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: 5 April 1993
- * Last Edited: 30 October 2008
+ * Last Edited: 27 November 2008
+ *
+ * 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 <stdio.h>
@@ -39,7 +36,7 @@ extern int errno; /* just in case */
/* Globals */
-char *version = "22"; /* tmail edit version */
+char *version = "25"; /* tmail edit version */
int debug = NIL; /* debugging (don't fork) */
int trycreate = NIL; /* flag saying gotta create before appending */
int critical = NIL; /* flag saying in critical code */
@@ -283,7 +280,7 @@ int deliver (FILE *f,unsigned long msglen,char *user)
uid_t duid;
uid_t euid = geteuid ();
/* get user record */
- if (!(pwd = getpwnam (getusername (user,&mailbox)))) {
+ if (!((s = getusername (user,&mailbox)) && (pwd = getpwnam (s)))) {
sprintf (tmp,"no such user as %.80s",user);
return fail (tmp,EX_NOUSER);
}
@@ -597,13 +594,16 @@ int fail (char *string,int code)
/* Get user name from username+mailbox specifier
* Accepts: username/mailbox specifier
* pointer to return location for mailbox specifier
- * Returns: user name, mailbox specifier value NIL if INBOX, patches out +
+ * Returns: user name, mailbox specifier value NIL if INBOX, patches out +,
+ * or NIL if error
*/
char *getusername (char *s,char **t)
{
if (*t = strchr (s,'+')) { /* have a mailbox specifier? */
*(*t)++ = '\0'; /* yes, tie off user name */
+ /* forbid overlong name */
+ if (strlen (*t) > NETMAXMBX) return NIL;
/* user+ and user+INBOX same as user */
if (!**t || !compare_cstring ((unsigned char *) *t,"INBOX")) *t = NIL;
}