~ubuntu-branches/ubuntu/hardy/fetchmail/hardy-security

« back to all changes in this revision

Viewing changes to transact.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2006-12-21 00:34:15 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20061221003415-gc0wnuaykisbajav
Tags: 6.3.6~rc3-1ubuntu1
* Merge from debian unstable. Remaining Ubuntu changes:
  - debian/control:
    + exim4 -> postfix dependency.
    + Add sysv-rc (>= 2.86.ds1-14.1ubuntu2) dependency for the 'multiuser'
      update-rc.d feature.
  - debian/fetchmail.postinst:
    + Install 'multiuser' rc.d symlinks.
    + Remove unnecessary rc.d symlinks on upgrades.

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
struct msgblk msgblk;
56
56
static int accept_count, reject_count;
57
57
 
 
58
/** add given address to xmit_names if it exactly matches a full address
 
59
 * \returns nonzero if matched */
 
60
static int map_address(const char *addr, struct query *ctl, struct idlist **xmit_names)
 
61
{
 
62
    const char  *lname;
 
63
 
 
64
    lname = idpair_find(&ctl->localnames, addr);
 
65
    if (lname) {
 
66
        if (outlevel >= O_DEBUG)
 
67
            report(stdout, GT_("mapped address %s to local %s\n"), addr, lname);
 
68
        save_str(xmit_names, lname, XMIT_ACCEPT);
 
69
        accept_count++;
 
70
    }
 
71
    return lname != NULL;
 
72
}
 
73
 
 
74
/** add given name to xmit_names if it matches declared localnames */
58
75
static void map_name(const char *name, struct query *ctl, struct idlist **xmit_names)
59
 
/* add given name to xmit_names if it matches declared localnames */
60
76
/*   name:       name to map */
61
77
/*   ctl:        list of permissible aliases */
62
78
/*   xmit_names: list of recipient names parsed out */
63
79
{
64
80
    const char  *lname;
65
 
    int off = 0;
66
 
    
67
 
    lname = idpair_find(&ctl->localnames, name+off);
 
81
 
 
82
    lname = idpair_find(&ctl->localnames, name);
68
83
    if (!lname && ctl->wildcard)
69
 
        lname = name+off;
 
84
        lname = name;
70
85
 
71
86
    if (lname != (char *)NULL)
72
87
    {
119
134
            if ((atsign = strchr((char *)cp, '@'))) {
120
135
                struct idlist   *idp;
121
136
 
 
137
                /* try to match full address first, this takes
 
138
                 * precedence over localdomains and alias mappings */
 
139
                if (map_address(cp, ctl, xmit_names))
 
140
                    goto nomap;
 
141
 
122
142
                /*
123
143
                 * Does a trailing segment of the hostname match something
124
144
                 * on the localdomains list?  If so, save the whole name
150
170
                     * not, skip this name.  If it is, we'll keep
151
171
                     * going and try to find a mapping to a client name.
152
172
                     */
153
 
                    if (!is_host_alias(atsign+1, ctl))
 
173
                    if (!is_host_alias(atsign+1, ctl, &ai0))
154
174
                    {
155
175
                        save_str(xmit_names, cp, XMIT_REJECT);
156
176
                        reject_count++;
190
210
{
191
211
    char *base, *ok = (char *)NULL;
192
212
    static char rbuf[HOSTLEN + USERNAMELEN + 4]; 
 
213
    struct addrinfo *ai0;
193
214
 
194
215
#define RBUF_WRITE(value) if (tp < rbuf+sizeof(rbuf)-1) *tp++=value
195
216
 
237
258
         * recipient name after a following "for".  Otherwise
238
259
         * punt.
239
260
         */
240
 
        if (is_host_alias(rbuf, ctl))
 
261
        if (is_host_alias(rbuf, ctl, &ai0))
241
262
        {
242
263
            if (outlevel >= O_DEBUG)
243
264
                report(stdout, 
1176
1197
        if (n != -1)
1177
1198
        {
1178
1199
            /*
1179
 
             * This header is technically invalid under RFC822.
1180
 
             * POP3, IMAP, etc. are not legal mail-parameter values.
 
1200
             * We SHOULD (RFC-2821 sec. 4.4/p. 53) make sure to only use
 
1201
             * IANA registered protocol names here.
1181
1202
             */
1182
1203
            snprintf(buf, sizeof(buf),
1183
1204
                    "\tby %s with %s (fetchmail-%s",
1305
1326
    *cp++ = '\r';
1306
1327
    *cp++ = '\n';
1307
1328
    *cp++ = '\0';
1308
 
    stuffline(ctl, buf);
 
1329
    n = stuffline(ctl, buf);
1309
1330
 
1310
 
    return(PS_SUCCESS);
 
1331
    if (n == strlen(buf))
 
1332
        return PS_SUCCESS;
 
1333
    else
 
1334
        return PS_SOCKET;
1311
1335
}
1312
1336
 
1313
1337
int readbody(int sock, struct query *ctl, flag forward, int len)
1335
1359
    while (protocol->delimited || len > 0)
1336
1360
    {
1337
1361
        set_timeout(mytimeout);
 
1362
        /* XXX FIXME: for undelimited protocols that ship the size, such
 
1363
         * as IMAP, we might want to use the count of remaining characters
 
1364
         * instead of the buffer size -- not for fetchmail 6.3.X though */
1338
1365
        if ((linelen = SockRead(sock, inbufp, sizeof(buf)-4-(inbufp-buf)))==-1)
1339
1366
        {
1340
1367
            set_timeout(0);
1357
1384
                sizeticker -= SIZETICKER;
1358
1385
            }
1359
1386
        }
 
1387
 
 
1388
        /* Mike Jones, Manchester University, 2006:
 
1389
         * "To fix IMAP MIME Messages in which fetchmail adds the remainder of
 
1390
         * the IMAP packet including the ')' character (part of the IMAP)
 
1391
         * Protocol causing the addition of an extra MIME boundary locally."
 
1392
         *
 
1393
         * However, we shouldn't do this for delimited protocols:
 
1394
         * many POP3 servers (Microsoft, qmail) goof up message sizes
 
1395
         * so we might end truncating messages prematurely.
 
1396
         */
 
1397
        if (!protocol->delimited && linelen > len) {
 
1398
            inbufp[len] = '\0';
 
1399
        }
 
1400
 
1360
1401
        len -= linelen;
1361
1402
 
1362
1403
        /* check for end of message */
1401
1442
 
1402
1443
            if (n < 0)
1403
1444
            {
1404
 
                report(stdout, GT_("writing message text\n"));
 
1445
                report(stdout, GT_("error writing message text\n"));
1405
1446
                release_sink(ctl);
1406
1447
                return(PS_IOERR);
1407
1448
            }