~ubuntu-branches/ubuntu/dapper/postfix/dapper-security

« back to all changes in this revision

Viewing changes to src/util/dict.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2005-12-07 15:39:11 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20051207153911-hutf07z6i8ty25z5
Tags: 2.2.6-1
* New upstream.
  - the *SQL clients did not uniformly choose the database host from
    the available pool
  - raise the "policy violation" flag when a client request exceeds
    a concurrency or rate limit.
  - don't do smtpd_end_of_data_restrictions after the transaction
    failed due to, e.g., a write error.
  - two messages could get the same message ID due to a race
    condition. This time window was increased when queue file creation
    was postponed from MAIL FROM until the first accepted RCPT TO.  The
    window is closed again.
  - the queue manager did not write a per-recipient defer logfile record
    when the delivery agent crashed after the initial handshake with the
    queue manager, and before reporting the delivery status to the queue
    manager.
  - moved code around from one place to another to make REDIRECT, FILTER,
    HOLD and DISCARD access(5) table actions work in
    smtpd_end_of_data_restrictions.  PREPEND will not be fixed; it must
    be specified before the message content is received.
* Updated Italian translations.  Closes: #336925
* Swedish translations.  Closes: #339746
* Switch to libdb4.3.  Closes: #336488
* Add Replaces: mail-transport-agent.  Closes: #325624
* Merge changes from ubuntu.

Show diffs side-by-side

added added

removed removed

Lines of Context:
117
117
/*      dict_eval() expands macro references in the specified string.
118
118
/*      The result is owned by the dictionary manager. Make a copy if the
119
119
/*      result is to survive multiple dict_eval() calls. When the
120
 
/*      \fIrecursive\fR argument is non-zero, macros references are
121
 
/*      expanded recursively.
 
120
/*      \fIrecursive\fR argument is non-zero, macro references in macro
 
121
/*      lookup results are expanded recursively.
122
122
/*
123
123
/*      dict_walk() iterates over all registered dictionaries in some
124
124
/*      arbitrary order, and invokes the specified action routine with
183
183
#include "vstream.h"
184
184
#include "vstring.h"
185
185
#include "readlline.h"
186
 
#include "mac_parse.h"
 
186
#include "mac_expand.h"
187
187
#include "stringops.h"
188
188
#include "iostuff.h"
189
189
#include "dict.h"
410
410
    vstring_free(buf);
411
411
}
412
412
 
413
 
 /*
414
 
  * Helper for macro expansion callback.
415
 
  */
416
 
struct dict_eval_context {
417
 
    const char *dict_name;              /* where to look */
418
 
    VSTRING *buf;                       /* result buffer */
419
 
    int     recursive;                  /* recursive or not */
420
 
};
421
 
 
422
 
/* dict_eval_action - macro parser call-back routine */
423
 
 
424
 
static int dict_eval_action(int type, VSTRING *buf, char *ptr)
 
413
/* dict_eval_lookup - macro parser call-back routine */
 
414
 
 
415
static const char *dict_eval_lookup(const char *key, int unused_type,
 
416
                                            char *dict_name)
425
417
{
426
 
    struct dict_eval_context *ctxt = (struct dict_eval_context *) ptr;
427
 
    char   *myname = "dict_eval_action";
428
418
    const char *pp;
429
419
 
430
 
    if (msg_verbose > 1)
431
 
        msg_info("%s: type %s buf %s context %s \"%s\" %s",
432
 
                 myname, type == MAC_PARSE_VARNAME ? "variable" : "literal",
433
 
                 STR(buf), ctxt->dict_name, STR(ctxt->buf),
434
 
                 ctxt->recursive ? "recursive" : "non-recursive");
435
 
 
436
420
    /*
437
 
     * In order to support recursion, we must save the dict_lookup() result.
438
 
     * We use the input buffer since it will not be needed anymore.
 
421
     * XXX how would one recover?
439
422
     */
440
 
    if (type == MAC_PARSE_VARNAME) {
441
 
        if ((pp = dict_lookup(ctxt->dict_name, STR(buf))) == 0) {
442
 
            if (dict_errno)                     /* XXX how would one recover? */
443
 
                msg_fatal("dictionary %s: lookup %s: temporary error",
444
 
                          ctxt->dict_name, STR(buf));
445
 
        } else if (ctxt->recursive) {
446
 
            vstring_strcpy(buf, pp);            /* XXX clobber input */
447
 
            dict_eval(ctxt->dict_name, STR(buf), ctxt->recursive);
448
 
        } else {
449
 
            vstring_strcat(ctxt->buf, pp);
450
 
        }
451
 
    } else {
452
 
        vstring_strcat(ctxt->buf, STR(buf));
453
 
    }
454
 
    return (0);
 
423
    if ((pp = dict_lookup(dict_name, key)) == 0 && dict_errno != 0)
 
424
        msg_fatal("dictionary %s: lookup %s: temporary error", dict_name, key);
 
425
 
 
426
    return (pp);
455
427
}
456
428
 
457
429
/* dict_eval - expand embedded dictionary references */
458
430
 
459
431
const char *dict_eval(const char *dict_name, const char *value, int recursive)
460
432
{
 
433
    const char *myname = "dict_eval";
461
434
    static VSTRING *buf;
462
 
    static struct dict_eval_context ctxt;
463
 
    static int loop = 0;
464
 
 
465
 
    /*
466
 
     * Sanity check.
467
 
     */
468
 
    if (loop > 100)
469
 
        msg_fatal("unreasonable macro nesting: \"%s\"", value);
 
435
    int     status;
470
436
 
471
437
    /*
472
438
     * Initialize.
473
439
     */
474
440
    if (buf == 0)
475
441
        buf = vstring_alloc(10);
476
 
    if (loop++ == 0)
477
 
        VSTRING_RESET(buf);
478
 
    ctxt.buf = buf;
479
 
    ctxt.recursive = recursive;
480
 
    ctxt.dict_name = dict_name;
481
442
 
482
443
    /*
483
444
     * Expand macros, possibly recursively.
484
445
     */
485
 
    if (msg_verbose > 1)
486
 
        msg_info("dict_eval[%d] %s", loop, value);
487
 
 
488
 
    mac_parse(value, dict_eval_action, (char *) &ctxt);
489
 
 
490
 
    if (msg_verbose > 1)
491
 
        msg_info("dict_eval[%d] result %s", loop, STR(buf));
492
 
 
493
 
    /*
494
 
     * Cleanup.
495
 
     */
496
 
    loop--;
497
 
    VSTRING_TERMINATE(buf);
498
 
 
 
446
#define DONT_FILTER (char *) 0
 
447
 
 
448
    status = mac_expand(buf, value,
 
449
                        recursive ? MAC_EXP_FLAG_RECURSE : MAC_EXP_FLAG_NONE,
 
450
                        DONT_FILTER, dict_eval_lookup, (char *) dict_name);
 
451
    if (status & MAC_PARSE_ERROR)
 
452
        msg_fatal("dictionary %s: macro processing error", dict_name);
 
453
    if (msg_verbose) {
 
454
        if (strcmp(value, STR(buf)) != 0)
 
455
            msg_info("%s: expand %s -> %s", myname, value, STR(buf));
 
456
        else
 
457
            msg_info("%s: const  %s", myname, value);
 
458
    }
499
459
    return (STR(buf));
500
460
}
501
461