This file is indexed.

/usr/include/bobcat/milter is in libbobcat-dev 3.23.01-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#ifndef INCLUDED_BOBCAT_MILTER_
#define INCLUDED_BOBCAT_MILTER_

#include <sys/types.h>
#include <sys/stat.h>
#include <libmilter/mfapi.h>
#include <unordered_map>
#include <string>

namespace FBB
{

class Milter
{
    static std::string s_name;
    static Milter *s_mp;
    static bool s_callClose;

    typedef std::unordered_map<SMFICTX *, Milter *>::iterator iterator;
    static std::unordered_map<SMFICTX *, Milter *> s_map;

    SMFICTX *d_ctx;                 // for local use only

    public:
        typedef size_t callback_set;
        enum CallBack
        {
            CONNECT     = 1 << 0,
            HELO        = 1 << 1,
            SENDER      = 1 << 2,
            RECIPIENT   = 1 << 3,
            HEADER      = 1 << 4,
            EOH         = 1 << 5,
            BODY        = 1 << 6,
            EOM         = 1 << 7,
            ABORT       = 1 << 8,
            CLOSE       = 1 << 9,
            UNKNOWN     = 1 << 10, // version > 2
            DATA        = 1 << 11, // version > 3

            ALL_CALLBACKS = (DATA << 1) - 1
        };

        typedef unsigned long flag_set;
        enum Flags
        {
            NO_FLAGS = 0L,
            ADD_HEADERS     = SMFIF_ADDHDRS,    // filter may add headers
            ADD_RECIPIENTS  = SMFIF_ADDRCPT,    // filter may add recipients
            CHANGE_BODY     = SMFIF_CHGBODY,    // filter may replace body
            CHANGE_HEADERS  = SMFIF_CHGHDRS,    // filter may change/delete 
                                                // headers
            DELETE_RECIPIENTS = SMFIF_DELRCPT,  // filter may delete recipients
            QUARANTINE      = SMFIF_QUARANTINE, // filter may quarantine 
                                                // envelope

            ALL_FLAGS   =   ADD_HEADERS         | ADD_RECIPIENTS    |    
                            CHANGE_BODY         | CHANGE_HEADERS    |
                            DELETE_RECIPIENTS   | QUARANTINE
                            
        };

        enum Status
        {
            ACCEPT  = SMFIS_ACCEPT,
            CONTINUE = SMFIS_CONTINUE,
            DISCARD = SMFIS_DISCARD,
            REJECT = SMFIS_REJECT,
            TEMPFAIL = SMFIS_TEMPFAIL,
        };

        enum Return
        {
            FAILURE = MI_FAILURE,
            SUCCESS = MI_SUCCESS,
        };

        static void initialize(std::string const &name, Milter &milter,
                callback_set callbacks = CONNECT, flag_set flags = NO_FLAGS);

        static bool start()
        {
            return smfi_main() == MI_SUCCESS;
        }

        static void stop()
        {
            smfi_stop();
        }

        static std::string const &name()
        {
            return s_name;
        }

    protected:
        virtual ~Milter();          // empty

        virtual sfsistat abort();

        bool addHeader(std::string const &hdrName, 
                        std::string const &hdrValue)
        {
            return smfi_addheader(d_ctx, 
                            const_cast<char *>(hdrName.c_str()), 
                            const_cast<char *>(hdrValue.c_str())) 
                    == SUCCESS;
        }
                                    // from eom() only
                                    // hdr-name: without :
                                    // hdr-value: \n and \t ok.
        bool addRecipient(std::string const &rcptName)
        {
            return smfi_addrcpt(d_ctx, 
                    const_cast<char *>(rcptName.c_str())) == SUCCESS;
        }
        virtual sfsistat body(unsigned char *text, size_t length);

        bool changeHeader(std::string const &hdrName, 
                        unsigned headerNr, std::string const &hdrValue)
        {
            return smfi_chgheader(d_ctx, 
                        const_cast<char *>(hdrName.c_str()), 
                        headerNr, 
                        hdrValue.length() ? 
                            const_cast<char *>(hdrValue.c_str())
                        :
                            0
                    ) == SUCCESS;
        }
        virtual Milter *clone() const = 0;       // cloning required
        virtual sfsistat close();
        virtual sfsistat connect(char *hostname, _SOCK_ADDR *hostaddr);
#if SMFI_VERSION > 3
        virtual sfsistat data();
#endif
        bool deleteRecipient(std::string const &rcptName)
        {
            return smfi_delrcpt(d_ctx, 
                    const_cast<char *>(rcptName.c_str())) == SUCCESS;
        }
        virtual sfsistat eoh();
        virtual sfsistat eom();
        virtual sfsistat header(char *headerf, char *headerv);
        virtual sfsistat helo(char *helohost);
        SMFICTX *id() const
        {
            return d_ctx;
        }

        bool insertHeader(size_t hdrIdx, std::string const &hdrName, 
                          std::string const &hdrValue)
        {
            return smfi_insheader(d_ctx, hdrIdx,
                    const_cast<char *>(hdrName.c_str()), 
                    const_cast<char *>(hdrValue.c_str()));
        }
        static bool openSocket(bool removeIfTrue = true)
        {
            return smfi_opensocket(removeIfTrue) == SUCCESS;
        }
        bool quarantine(std::string const &reason)
        {
            return  smfi_quarantine(d_ctx, 
                    const_cast<char *>(reason.c_str())) == SUCCESS;
        }
        virtual sfsistat recipient(char **argv);
        bool replaceBody(std::string const &body)
        {
            return smfi_replacebody(d_ctx, 
                        reinterpret_cast<unsigned char *>
                        (
                            const_cast<char *>(body.c_str())
                        ),
                        body.length()) == SUCCESS;
        }
        virtual sfsistat sender(char **argv);
        static bool setBacklog(size_t backlog = 5)
        {
            return smfi_setbacklog(backlog) == SUCCESS;
        }

        static void setConnection(std::string const &socketName)
        {
            smfi_setconn(const_cast<char *>(socketName.c_str()));
        }
        bool setReply(std::string const &rcode, std::string const &xcode = "",
                      std::string const &msg = "")
        {
            return smfi_setreply(d_ctx, 
                        const_cast<char *>(rcode.c_str()),
                        xcode.length() ? 
                            const_cast<char *>(xcode.c_str()) 
                        :
                            0,
                        const_cast<char *>(msg.c_str()));

                // rcode: The three-digit (RFC 821/2821) SMTP reply code, as a
                // null-terminated string. rcode cannot be NULL, and must be a
                // valid 4XX or 5XX reply code.

                // xxcode The extended (RFC 1893/2034) reply code. If xcode is
                // NULL, no extended code is used. Otherwise, xcode must
                // conform to RFC 1893/2034.  

    

                // * Values passed to smfi_setreply are not checked for
                // standards compliance.

                // * The message parameter should contain only printable
                // characters, other characters may lead to undefined
                // behavior. For example, CR or LF will cause the call to
                // fail, single '%' characters will cause the text to be
                // ignored (if there really should be a '%' in the string, use
                // '%%' just like for printf(3)).

                // * If the reply code (rcode) given is a '4XX' code but
                // SMFI_REJECT is used for the message, the custom reply is
                // not used.

                // * Similarly, if the reply code (rcode) given is a '5XX'
                // code but SMFI_TEMPFAIL is used for the message, the custom
                // reply is not used.

                // Note: in neither of the last two cases an error is returned
                // to the milter, libmilter silently ignores the reply code.

                // * If the milter returns SMFI_TEMPFAIL and sets the reply
                // code to '421', then the SMTP server will terminate the SMTP
                // session with a 421 error code.
        }
        // can't do smfi_setmlreply(ctx, ...) 
        // since there is no smfi_Vsetmlreply(ctx, ...)
        static void setTimeout(size_t seconds = 7210)
        {
            smfi_settimeout(seconds);
        }
        char const *symval(std::string const &name) const
        {
            return smfi_getsymval(d_ctx, 
                    const_cast<char *>(name.c_str()));
        }
#if SMFI_VERSION > 2
        sfsistat unknown(char const *ptr);
#endif
        bool wait()                           // from eom() only
        {
            return smfi_progress(d_ctx) == SUCCESS;
        }

    private:
        static Milter *install(SMFICTX *ctx);

        static sfsistat mConnect(SMFICTX *ctx, char *hostname, 
                                             _SOCK_ADDR *hostaddr)
        {
            return install(ctx)->connect(hostname, hostaddr);
        }

        static sfsistat mAbort(SMFICTX *ctx)
        {
            return install(ctx)->abort();
        }
        static sfsistat mBody(SMFICTX *ctx, unsigned char *body, size_t len)
        {
            return install(ctx)->body(body, len);
        }
        static sfsistat mSender(SMFICTX *ctx, char **argv)
        {
            return install(ctx)->sender(argv);
        }
        static sfsistat mRecipient(SMFICTX *ctx, char **argv)
        {
            return install(ctx)->recipient(argv);
        }
        static sfsistat mEoh(SMFICTX *ctx)
        {
            return install(ctx)->eoh();
        }
        static sfsistat mEom(SMFICTX *ctx)
        {
            return install(ctx)->eom();
        }
        static sfsistat mHeader(SMFICTX *ctx, char *headerf, char *headerv)
        {
            return install(ctx)->header(headerf, headerv);
        }
        static sfsistat mHelo(SMFICTX *ctx, char *helohost)
        {
            return install(ctx)->helo(helohost);
        }
        static sfsistat mClose(SMFICTX *ctx);

#if SMFI_VERSION > 2
        static sfsistat mUnknown(SMFICTX *ctx, char const *ptr)
        {
            return install(ctx)->unknown(ptr);
        }
#endif /* SMFI_VERSION > 2 */

#if SMFI_VERSION > 3
        static sfsistat mData(SMFICTX *ctx)
        {
            return install(ctx)->data();
        }
#endif /* SMFI_VERSION > 3 */
};

}

#endif