aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>1997-01-14 08:04:51 +0000
committerEric S. Raymond <esr@thyrsus.com>1997-01-14 08:04:51 +0000
commita6b586be3027c12b38c2bbda956770bba0f61bc4 (patch)
treef37a3f86b1de5ed1e030731f159605431372f0ad
parentbe9c9f0a5b6d598fb9eeb8e4d2d2cfef367dd759 (diff)
downloadfetchmail-a6b586be3027c12b38c2bbda956770bba0f61bc4.tar.gz
fetchmail-a6b586be3027c12b38c2bbda956770bba0f61bc4.tar.bz2
fetchmail-a6b586be3027c12b38c2bbda956770bba0f61bc4.zip
Dynamic allocation for the query structure string entries.
svn path=/trunk/; revision=757
-rw-r--r--driver.c24
-rw-r--r--fetchmail.c25
-rw-r--r--fetchmail.h16
-rw-r--r--imap.c2
-rw-r--r--options.c8
-rw-r--r--pop2.c2
-rw-r--r--pop3.c2
-rw-r--r--rcfile_y.y53
8 files changed, 60 insertions, 72 deletions
diff --git a/driver.c b/driver.c
index 95bcb2f2..68347610 100644
--- a/driver.c
+++ b/driver.c
@@ -551,7 +551,7 @@ char *realname; /* real name of host */
save_str(&xmit_names, -1, ctl->localnames->id);
/* time to address the message */
- if (ctl->mda[0]) /* we have a declared MDA */
+ if (ctl->mda) /* we have a declared MDA */
{
int length = 0;
char *names, *cmd;
@@ -604,7 +604,7 @@ char *realname; /* real name of host */
char *ap;
/* build a connection to the SMTP listener */
- if (ctl->mda[0] == '\0' && ((sinkfp = smtp_open(ctl)) == NULL))
+ if (!ctl->mda && ((sinkfp = smtp_open(ctl)) == NULL))
{
free_str_list(&xmit_names);
error(0, 0, "SMTP connect failed");
@@ -668,7 +668,7 @@ char *realname; /* real name of host */
*cp = '\n';
/* replace all LFs with CR-LF before sending to the SMTP server */
- if (!ctl->mda[0])
+ if (!ctl->mda)
{
char *newheaders = xmalloc(1 + oldlen * 2);
@@ -679,7 +679,7 @@ char *realname; /* real name of host */
/* write all the headers */
n = 0;
- if (ctl->mda[0])
+ if (ctl->mda)
n = fwrite(headers, 1, oldlen, sinkfp);
else if (sinkfp)
n = SockWrite(headers, 1, oldlen, sinkfp);
@@ -689,7 +689,7 @@ char *realname; /* real name of host */
free(headers);
headers = NULL;
error(0, errno, "writing RFC822 headers");
- if (ctl->mda[0])
+ if (ctl->mda)
{
pclose(sinkfp);
signal(SIGCHLD, sigchld);
@@ -752,13 +752,13 @@ char *realname; /* real name of host */
/* SMTP byte-stuffing */
if (*bufp == '.')
- if (ctl->mda[0])
+ if (ctl->mda)
fputs(".", sinkfp);
else if (sinkfp)
SockWrite(bufp, 1, 1, sinkfp);
/* replace all LFs with CR-LF in the line */
- if (!ctl->mda[0])
+ if (!ctl->mda)
{
char *newbufp = xmalloc(1 + strlen(bufp) * 2);
@@ -768,17 +768,17 @@ char *realname; /* real name of host */
/* ship out the text line */
n = 0;
- if (ctl->mda[0])
+ if (ctl->mda)
n = fwrite(bufp, 1, strlen(bufp), sinkfp);
else if (sinkfp)
n = SockWrite(bufp, 1, strlen(bufp), sinkfp);
- if (!ctl->mda[0])
+ if (!ctl->mda)
free(bufp);
if (n < 0)
{
error(0, errno, "writing message text");
- if (ctl->mda[0])
+ if (ctl->mda)
{
pclose(sinkfp);
signal(SIGCHLD, sigchld);
@@ -795,7 +795,7 @@ char *realname; /* real name of host */
if (outlevel == O_VERBOSE)
fputc('\n', stderr);
- if (ctl->mda[0])
+ if (ctl->mda)
{
int rc;
@@ -926,7 +926,7 @@ const struct method *proto; /* protocol method table */
int *msgsizes, len, num, count, new, deletions = 0;
FILE *sockfp;
/* execute pre-initialization command, if any */
- if (ctl->preconnect[0] && (ok = system(ctl->preconnect)))
+ if (ctl->preconnect && (ok = system(ctl->preconnect)))
{
sprintf(buf, "pre-connection command failed with status %d", ok);
error(0, 0, buf);
diff --git a/fetchmail.c b/fetchmail.c
index 7a1ed4d7..529f18ec 100644
--- a/fetchmail.c
+++ b/fetchmail.c
@@ -300,13 +300,12 @@ int main (int argc, char **argv)
/* pick up interactively any passwords we need but don't have */
for (ctl = querylist; ctl; ctl = ctl->next)
- if (ctl->active && !(implicitmode && ctl->server.skip) && !ctl->password[0])
+ if (ctl->active && !(implicitmode && ctl->server.skip) && !ctl->password)
{
if (ctl->server.authenticate == A_KERBEROS)
/* Server won't care what the password is, but there
must be some non-null string here. */
- (void) strncpy(ctl->password,
- ctl->remotename, PASSWORDLEN-1);
+ ctl->password = ctl->remotename;
else
{
/* Look up the host and account in the .netrc file. */
@@ -317,17 +316,15 @@ int main (int argc, char **argv)
if (p)
{
/* We found the entry, so use the password. */
- (void) strncpy (ctl->password, p->password,
- PASSWORDLEN - 1);
+ ctl->password = xstrdup(p->password);
}
}
- if (!ctl->password[0])
+ if (!ctl->password)
{
(void) sprintf(tmpbuf, "Enter password for %s@%s: ",
ctl->remotename, ctl->server.names->id);
- (void) strncpy(ctl->password,
- (char *)getpassword(tmpbuf),PASSWORDLEN-1);
+ ctl->password = xstrdup((char *)getpassword(tmpbuf));
}
}
@@ -531,8 +528,8 @@ static int load_params(int argc, char **argv, int optind)
def_opts.server.protocol = P_AUTO;
def_opts.server.timeout = CLIENT_TIMEOUT;
- strcpy(def_opts.remotename, user);
- strcpy(def_opts.smtphost, "localhost");
+ def_opts.remotename = user;
+ def_opts.smtphost = "localhost";
/* this builds the host list */
if (prc_parse_file(rcfile) != 0)
@@ -625,7 +622,7 @@ static int load_params(int argc, char **argv, int optind)
* client machine) and thus just one SMTP leader (and one listener
* process) through the entire poll cycle.
*/
- if (!ctl->mda[0])
+ if (!ctl->mda)
{
ctl->smtp_sockfp = (FILE *)NULL;
for (mp = querylist; mp && mp != ctl; mp = mp->next)
@@ -814,7 +811,7 @@ void dump_params (struct query *ctl)
if (ctl->server.skip || outlevel == O_VERBOSE)
printf(" This host will%s be queried when no host is specified.\n",
ctl->server.skip ? " not" : "");
- if (ctl->password[0] == '\0')
+ if (!ctl->password)
printf(" Password will be prompted for.\n");
else if (outlevel == O_VERBOSE)
if (ctl->server.protocol == P_APOP)
@@ -872,11 +869,11 @@ void dump_params (struct query *ctl)
ctl->fetchlimit, ctl->fetchlimit);
else if (outlevel == O_VERBOSE)
printf(" No received-message limit (--fetchlimit 0).\n");
- if (ctl->mda[0])
+ if (ctl->mda)
printf(" Messages will be delivered with '%s.'\n", visbuf(ctl->mda));
else
printf(" Messages will be SMTP-forwarded to '%s'.\n", visbuf(ctl->smtphost));
- if (ctl->preconnect[0])
+ if (ctl->preconnect)
printf(" Server connection will be preinitialized with '%s.'\n", visbuf(ctl->preconnect));
else if (outlevel == O_VERBOSE)
printf(" No preinitialization command.\n");
diff --git a/fetchmail.h b/fetchmail.h
index 5145ed6d..a329c19f 100644
--- a/fetchmail.h
+++ b/fetchmail.h
@@ -21,11 +21,8 @@
#define HOSTLEN 128 /* max hostname length */
#define USERNAMELEN 32 /* max user-name length */
#define PASSWORDLEN 64 /* max password length */
-#define FOLDERLEN 256 /* max folder name length */
#define DIGESTLEN 33 /* length of MD5 digest */
-#define MDALEN 256 /* length of delivery agent command */
#define IDLEN 128 /* length of UIDL message ID */
-#define CMDLEN 128 /* length of initialization command */
/* exit code values */
#define PS_SUCCESS 0 /* successful receipt of messages */
@@ -46,7 +43,6 @@
#define O_VERBOSE 2 /* excessive */
#define SIZETICKER 1024 /* print 1 dot per this many bytes */
-#define MDA_MAXARGS 32 /* max arguments per MDA call */
struct idlist
{
@@ -87,12 +83,12 @@ struct query
/* per-user data */
struct idlist *localnames; /* including calling user's name */
int wildcard; /* should unmatched names be passed through */
- char remotename [USERNAMELEN+1];
- char password [PASSWORDLEN+1];
- char mailbox [FOLDERLEN+1];
- char smtphost[HOSTLEN+1];
- char mda [MDALEN+1];
- char preconnect [CMDLEN+1];
+ char *remotename;
+ char *password;
+ char *mailbox;
+ char *smtphost;
+ char *mda;
+ char *preconnect;
/* per-user control flags */
int keep;
diff --git a/imap.c b/imap.c
index e65807ec..404f75c0 100644
--- a/imap.c
+++ b/imap.c
@@ -100,7 +100,7 @@ static int imap_getrange(FILE *sockfp, struct query *ctl, int*countp, int*newp)
recent = unseen = 0;
ok = gen_transact(sockfp,
"SELECT %s",
- ctl->mailbox[0] ? ctl->mailbox : "INBOX");
+ ctl->mailbox ? ctl->mailbox : "INBOX");
if (ok != 0)
return(ok);
diff --git a/options.c b/options.c
index b474666d..5bf97888 100644
--- a/options.c
+++ b/options.c
@@ -216,7 +216,7 @@ struct query *ctl; /* option record to be initialized */
case 'u':
case LA_USERNAME:
- strncpy(ctl->remotename,optarg,sizeof(ctl->remotename)-1);
+ ctl->remotename = xstrdup(optarg);
break;
case 'a':
case LA_ALL:
@@ -244,11 +244,11 @@ struct query *ctl; /* option record to be initialized */
break;
case 'r':
case LA_REMOTEFILE:
- strncpy(ctl->mailbox,optarg,sizeof(ctl->mailbox)-1);
+ ctl->mailbox = xstrdup(optarg);
break;
case 'S':
case LA_SMTPHOST:
- strncpy(ctl->smtphost,optarg,sizeof(ctl->smtphost)-1);
+ ctl->smtphost = xstrdup(optarg);
ocount++;
break;
case 'b':
@@ -261,7 +261,7 @@ struct query *ctl; /* option record to be initialized */
break;
case 'm':
case LA_MDA:
- strncpy(ctl->mda,optarg,sizeof(ctl->mda));
+ ctl->mda = xstrdup(optarg);
ocount++;
break;
diff --git a/pop2.c b/pop2.c
index 667732e8..b606a291 100644
--- a/pop2.c
+++ b/pop2.c
@@ -76,7 +76,7 @@ static int pop2_getrange(FILE *sockfp, struct query *ctl, int*countp, int*newp)
return(PS_ERROR);
/* maybe the user wanted a non-default folder */
- if (ctl->mailbox[0])
+ if (ctl->mailbox)
{
int ok = gen_transact(sockfp, "FOLD %s", ctl->mailbox);
diff --git a/pop3.c b/pop3.c
index 95602345..b095f4cc 100644
--- a/pop3.c
+++ b/pop3.c
@@ -287,7 +287,7 @@ const static struct method pop3 =
int doPOP3 (struct query *ctl)
/* retrieve messages using POP3 */
{
- if (ctl->mailbox[0]) {
+ if (ctl->mailbox) {
fprintf(stderr,"Option --remote is not supported with POP3\n");
return(PS_SYNTAX);
}
diff --git a/rcfile_y.y b/rcfile_y.y
index 9bd40686..9da2769e 100644
--- a/rcfile_y.y
+++ b/rcfile_y.y
@@ -135,9 +135,9 @@ explicits : explicitdef {prc_register(); prc_reset();}
explicitdef : userdef user0opts
;
-userdef : USERNAME STRING {strcpy(current.remotename, $2);}
+userdef : USERNAME STRING {current.remotename = xstrdup($2);}
| USERNAME mapping_list HERE
- | USERNAME STRING THERE {strcpy(current.remotename, $2);}
+ | USERNAME STRING THERE {current.remotename = xstrdup($2);}
;
user0opts : /* EMPTY */
@@ -168,12 +168,12 @@ user_option : TO localnames HERE
| IS localnames HERE
| IS localnames
- | IS STRING THERE {strcpy(current.remotename, $2);}
- | PASSWORD STRING {strcpy(current.password, $2);}
- | FOLDER STRING {strcpy(current.mailbox, $2);}
- | SMTPHOST STRING {strcpy(current.smtphost, $2);}
- | MDA STRING {strcpy(current.mda, $2);}
- | PRECONNECT STRING {strcpy(current.preconnect, $2);}
+ | IS STRING THERE {current.remotename = xstrdup($2);}
+ | PASSWORD STRING {current.password = xstrdup($2);}
+ | FOLDER STRING {current.mailbox = xstrdup($2);}
+ | SMTPHOST STRING {current.smtphost = xstrdup($2);}
+ | MDA STRING {current.mda = xstrdup($2);}
+ | PRECONNECT STRING {current.preconnect = xstrdup($2);}
| KEEP {current.keep = ($1==FLAG_TRUE);}
| FLUSH {current.flush = ($1==FLAG_TRUE);}
@@ -311,24 +311,21 @@ struct query *init; /* pointer to block containing initial values */
static void prc_register(void)
/* register current parameters and append to the host list */
{
-#define STR_FORCE(fld, len) if (cmd_opts.fld[0]) \
- strcpy(current.fld, cmd_opts.fld)
- STR_FORCE(remotename, USERNAMELEN);
- STR_FORCE(password, PASSWORDLEN);
- STR_FORCE(mailbox, FOLDERLEN);
- STR_FORCE(smtphost, HOSTLEN);
- STR_FORCE(mda, MDALEN);
- STR_FORCE(preconnect, CMDLEN);
-#undef STR_FORCE
-
#define FLAG_FORCE(fld) if (cmd_opts.fld) current.fld = cmd_opts.fld
FLAG_FORCE(server.protocol);
FLAG_FORCE(server.port);
FLAG_FORCE(server.authenticate);
FLAG_FORCE(server.timeout);
- FLAG_FORCE(server.envelope); /* yes, even though this is a string */
+ FLAG_FORCE(server.envelope);
FLAG_FORCE(server.skip);
+ FLAG_FORCE(remotename);
+ FLAG_FORCE(password);
+ FLAG_FORCE(mailbox);
+ FLAG_FORCE(smtphost);
+ FLAG_FORCE(mda);
+ FLAG_FORCE(preconnect);
+
FLAG_FORCE(keep);
FLAG_FORCE(flush);
FLAG_FORCE(fetchall);
@@ -346,23 +343,21 @@ void optmerge(struct query *h2, struct query *h1)
append_str_list(&h2->server.localdomains, &h1->server.localdomains);
append_str_list(&h2->localnames, &h1->localnames);
-#define STR_MERGE(fld, len) if (*(h2->fld) == '\0') strcpy(h2->fld, h1->fld)
- STR_MERGE(remotename, USERNAMELEN);
- STR_MERGE(password, PASSWORDLEN);
- STR_MERGE(mailbox, FOLDERLEN);
- STR_MERGE(smtphost, HOSTLEN);
- STR_MERGE(mda, MDALEN);
- STR_MERGE(preconnect, CMDLEN);
-#undef STR_MERGE
-
#define FLAG_MERGE(fld) if (!h2->fld) h2->fld = h1->fld
FLAG_MERGE(server.protocol);
FLAG_MERGE(server.port);
FLAG_MERGE(server.authenticate);
FLAG_MERGE(server.timeout);
- FLAG_MERGE(server.envelope); /* yes, even though this is a string */
+ FLAG_MERGE(server.envelope);
FLAG_MERGE(server.skip);
+ FLAG_MERGE(remotename);
+ FLAG_MERGE(password);
+ FLAG_MERGE(mailbox);
+ FLAG_MERGE(smtphost);
+ FLAG_MERGE(mda);
+ FLAG_MERGE(preconnect);
+
FLAG_MERGE(keep);
FLAG_MERGE(flush);
FLAG_MERGE(fetchall);