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

« back to all changes in this revision

Viewing changes to src/local/biff_notify.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2005-02-27 09:33:07 UTC
  • Revision ID: james.westby@ubuntu.com-20050227093307-cn789t27ibnlh6tf
Tags: upstream-2.1.5
ImportĀ upstreamĀ versionĀ 2.1.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*++
 
2
/* NAME
 
3
/*      biff_notify 3
 
4
/* SUMMARY
 
5
/*      send biff notification
 
6
/* SYNOPSIS
 
7
/*      #include <biff_notify.h>
 
8
/*
 
9
/*      void    biff_notify(text, len)
 
10
/*      const char *text;
 
11
/*      int     len;
 
12
/* DESCRIPTION
 
13
/*      biff_notify() sends a \fBBIFF\fR notification request to the
 
14
/*      \fBcomsat\fR daemon.
 
15
/*
 
16
/*      Arguments:
 
17
/* .IP text
 
18
/*      Null-terminated text (username@mailbox-offset).
 
19
/* .IP len
 
20
/*      Length of text, including null terminator.
 
21
/* BUGS
 
22
/*      The \fBBIFF\fR "service" can be a noticeable load for
 
23
/*      systems that have many logged-in users.
 
24
/* LICENSE
 
25
/* .ad
 
26
/* .fi
 
27
/*      The Secure Mailer license must be distributed with this software.
 
28
/* AUTHOR(S)
 
29
/*      Wietse Venema
 
30
/*      IBM T.J. Watson Research
 
31
/*      P.O. Box 704
 
32
/*      Yorktown Heights, NY 10598, USA
 
33
/*--*/
 
34
 
 
35
/* System library. */
 
36
 
 
37
#include "sys_defs.h"
 
38
#include <sys/socket.h>
 
39
#include <netinet/in.h>
 
40
#include <netdb.h>
 
41
#include <string.h>
 
42
 
 
43
/* Utility library. */
 
44
 
 
45
#include <msg.h>
 
46
 
 
47
/* Application-specific. */
 
48
 
 
49
#include <biff_notify.h>
 
50
 
 
51
/* biff_notify - notify recipient via the biff "protocol" */
 
52
 
 
53
void    biff_notify(const char *text, int len)
 
54
{
 
55
    static struct sockaddr_in sin;
 
56
    static int sock = -1;
 
57
    struct hostent *hp;
 
58
    struct servent *sp;
 
59
 
 
60
    /*
 
61
     * Initialize a socket address structure, or re-use an existing one.
 
62
     */
 
63
    if (sin.sin_family == 0) {
 
64
        if ((sp = getservbyname("biff", "udp")) == 0) {
 
65
            msg_warn("service not found: biff/udp");
 
66
            return;
 
67
        }
 
68
        if ((hp = gethostbyname("localhost")) == 0) {
 
69
            msg_warn("host not found: localhost");
 
70
            return;
 
71
        }
 
72
        if ((int) hp->h_length > (int) sizeof(sin.sin_addr)) {
 
73
            msg_warn("bad address size %d for localhost", hp->h_length);
 
74
            return;
 
75
        }
 
76
        sin.sin_family = hp->h_addrtype;
 
77
        sin.sin_port = sp->s_port;
 
78
        memcpy((char *) &sin.sin_addr, hp->h_addr_list[0], hp->h_length);
 
79
    }
 
80
 
 
81
    /*
 
82
     * Open a socket, or re-use an existing one.
 
83
     */
 
84
    if (sock < 0 && (sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
 
85
        msg_warn("socket: %m");
 
86
        return;
 
87
    }
 
88
 
 
89
    /*
 
90
     * Biff!
 
91
     */
 
92
    if (sendto(sock, text, len, 0, (struct sockaddr *) & sin, sizeof(sin)) != len)
 
93
        msg_warn("biff_notify: %m");
 
94
}