~ubuntu-branches/ubuntu/saucy/postfix/saucy

« back to all changes in this revision

Viewing changes to src/tls/tls_proxy_scan.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2011-02-22 11:20:43 UTC
  • mfrom: (1.1.27 upstream)
  • Revision ID: james.westby@ubuntu.com-20110222112043-c34ht219w3ybrilr
Tags: 2.8.0-2
* a little more lintian cleanup
* Fix missing format strings in smtp-sink.c

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*++
 
2
/* NAME
 
3
/*      tls_proxy_scan
 
4
/* SUMMARY
 
5
/*      read TLS session state from stream
 
6
/* SYNOPSIS
 
7
/*      #include <tls_proxy.h>
 
8
/*
 
9
/*      int     tls_proxy_context_scan(scan_fn, stream, flags, ptr)
 
10
/*      ATTR_SCAN_MASTER_FN scan_fn;
 
11
/*      VSTREAM *stream;
 
12
/*      int     flags;
 
13
/*      void    *ptr;
 
14
/* DESCRIPTION
 
15
/*      tls_proxy_context_scan() reads a TLS_SESS_STATE structure
 
16
/*      from the named stream using the specified attribute scan
 
17
/*      routine.  tls_proxy_context_scan() is meant to be passed as
 
18
/*      a call-back to attr_scan(), thusly:
 
19
/*
 
20
/*      ... ATTR_TYPE_FUNC, tls_proxy_context_scan, (void *) tls_context, ...
 
21
/* DIAGNOSTICS
 
22
/*      Fatal: out of memory.
 
23
/* LICENSE
 
24
/* .ad
 
25
/* .fi
 
26
/*      The Secure Mailer license must be distributed with this software.
 
27
/* AUTHOR(S)
 
28
/*      Wietse Venema
 
29
/*      IBM T.J. Watson Research
 
30
/*      P.O. Box 704
 
31
/*      Yorktown Heights, NY 10598, USA
 
32
/*--*/
 
33
 
 
34
#ifdef USE_TLS
 
35
 
 
36
/* System library. */
 
37
 
 
38
#include <sys_defs.h>
 
39
 
 
40
/* Utility library */
 
41
 
 
42
#include <attr.h>
 
43
 
 
44
/* Global library. */
 
45
 
 
46
#include <mail_proto.h>
 
47
 
 
48
/* TLS library. */
 
49
 
 
50
#include <tls.h>
 
51
#include <tls_proxy.h>
 
52
 
 
53
/* tls_proxy_context_scan - receive TLS session state from stream */
 
54
 
 
55
int     tls_proxy_context_scan(ATTR_SCAN_MASTER_FN scan_fn, VSTREAM *fp,
 
56
                                     int flags, void *ptr)
 
57
{
 
58
    TLS_SESS_STATE *tls_context = (TLS_SESS_STATE *) ptr;
 
59
    int     ret;
 
60
    VSTRING *peer_CN = vstring_alloc(25);
 
61
    VSTRING *issuer_CN = vstring_alloc(25);
 
62
    VSTRING *peer_fingerprint = vstring_alloc(25);
 
63
    VSTRING *protocol = vstring_alloc(25);
 
64
    VSTRING *cipher_name = vstring_alloc(25);
 
65
 
 
66
    /*
 
67
     * Note: memset() is not a portable way to initialize non-integer types.
 
68
     */
 
69
    memset(ptr, 0, sizeof(TLS_SESS_STATE));
 
70
    ret = scan_fn(fp, flags | ATTR_FLAG_MORE,
 
71
                  ATTR_TYPE_STR, MAIL_ATTR_PEER_CN, peer_CN,
 
72
                  ATTR_TYPE_STR, MAIL_ATTR_ISSUER_CN, issuer_CN,
 
73
                  ATTR_TYPE_STR, MAIL_ATTR_PEER_FPT, peer_fingerprint,
 
74
                  ATTR_TYPE_INT, MAIL_ATTR_PEER_STATUS,
 
75
                  &tls_context->peer_status,
 
76
                  ATTR_TYPE_STR, MAIL_ATTR_CIPHER_PROTOCOL, protocol,
 
77
                  ATTR_TYPE_STR, MAIL_ATTR_CIPHER_NAME, cipher_name,
 
78
                  ATTR_TYPE_INT, MAIL_ATTR_CIPHER_USEBITS,
 
79
                  &tls_context->cipher_usebits,
 
80
                  ATTR_TYPE_INT, MAIL_ATTR_CIPHER_ALGBITS,
 
81
                  &tls_context->cipher_algbits,
 
82
                  ATTR_TYPE_END);
 
83
    tls_context->peer_CN = vstring_export(peer_CN);
 
84
    tls_context->issuer_CN = vstring_export(issuer_CN);
 
85
    tls_context->peer_fingerprint = vstring_export(peer_fingerprint);
 
86
    tls_context->protocol = vstring_export(protocol);
 
87
    tls_context->cipher_name = vstring_export(cipher_name);
 
88
    return (ret == 8 ? 1 : -1);
 
89
}
 
90
 
 
91
#endif