~arges/ubuntu/quantal/rsyslog/fix-lp1059592

« back to all changes in this revision

Viewing changes to plugins/omgssapi/omgssapi.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2009-02-15 21:56:23 UTC
  • mto: (3.2.4 squeeze) (1.1.9 upstream)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20090215215623-xsycf628eo3kguc0
Tags: upstream-3.20.4
ImportĀ upstreamĀ versionĀ 3.20.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
#endif
44
44
#include <pthread.h>
45
45
#include <gssapi/gssapi.h>
46
 
#include "syslogd.h"
 
46
#include "dirty.h"
47
47
#include "syslogd-types.h"
48
48
#include "srUtils.h"
49
49
#include "net.h"
50
 
#include "omfwd.h"
51
50
#include "template.h"
52
51
#include "msg.h"
53
 
#include "tcpsyslog.h"
54
52
#include "cfsysline.h"
55
53
#include "module-template.h"
56
54
#include "gss-misc.h"
57
55
#include "tcpclt.h"
 
56
#include "glbl.h"
58
57
#include "errmsg.h"
59
58
 
60
59
MODULE_TYPE_OUTPUT
61
60
 
62
 
#define INET_SUSPEND_TIME 60
63
 
/* equal to 1 minute - TODO: see if we can get rid of this now that we have
64
 
 * the retry intervals in the engine -- rgerhards, 2008-03-12
65
 
 */
66
 
 
67
 
#define INET_RETRY_MAX 30               /* maximum of retries for gethostbyname() */
68
 
        /* was 10, changed to 30 because we reduced INET_SUSPEND_TIME by one third. So
69
 
         * this "fixes" some of implications of it (see comment on INET_SUSPEND_TIME).
70
 
         * rgerhards, 2005-07-26
71
 
         * TODO: this needs to be reviewed in spite of the new engine, too -- rgerhards, 2008-03-12
72
 
         */
73
61
 
74
62
/* internal structures
75
63
 */
76
64
DEF_OMOD_STATIC_DATA
77
65
DEFobjCurrIf(errmsg)
 
66
DEFobjCurrIf(glbl)
78
67
DEFobjCurrIf(gssutil)
79
68
DEFobjCurrIf(tcpclt)
80
69
 
86
75
                eDestFORW_SUSP,
87
76
                eDestFORW_UNKN
88
77
        } eDestState;
89
 
        int iRtryCnt;
90
78
        struct addrinfo *f_addr;
91
79
        int compressionLevel; /* 0 - no compression, else level for zlib */
92
80
        char *port;
93
 
        time_t  ttSuspend;      /* time selector was suspended */
94
81
        tcpclt_t *pTCPClt;              /* our tcpclt object */
95
82
        gss_ctx_id_t gss_context;
96
83
        OM_uint32 gss_flags;
174
161
ENDdbgPrintInstInfo
175
162
 
176
163
 
177
 
/* CODE FOR SENDING TCP MESSAGES */
178
 
 
179
164
/* This function is called immediately before a send retry is attempted.
180
165
 * It shall clean up whatever makes sense.
181
166
 * rgerhards, 2007-12-28
207
192
 
208
193
        base = (gss_base_service_name == NULL) ? "host" : gss_base_service_name;
209
194
        out_tok.length = strlen(pData->f_hname) + strlen(base) + 2;
210
 
        if ((out_tok.value = malloc(out_tok.length)) == NULL) {
211
 
                ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
212
 
        }
 
195
        CHKmalloc(out_tok.value = malloc(out_tok.length));
213
196
        strcpy(out_tok.value, base);
214
197
        strcat(out_tok.value, "@");
215
198
        strcat(out_tok.value, pData->f_hname);
285
268
        RETiRet;
286
269
 
287
270
 fail:
288
 
        errmsg.LogError(NO_ERRCODE, "GSS-API Context initialization failed\n");
 
271
        errmsg.LogError(0, RS_RET_GSS_SENDINIT_ERROR, "GSS-API Context initialization failed\n");
289
272
        gss_release_name(&min_stat, &target_name);
290
273
        gss_release_buffer(&min_stat, &out_tok);
291
274
        if (*context != GSS_C_NO_CONTEXT) {
365
348
                 * a common function.
366
349
                 */
367
350
                hints.ai_flags = AI_NUMERICSERV;
368
 
                hints.ai_family = family;
 
351
                hints.ai_family = glbl.GetDefPFFamily();
369
352
                hints.ai_socktype = SOCK_STREAM;
370
353
                if((e = getaddrinfo(pData->f_hname,
371
354
                                    getFwdSyslogPt(pData), &hints, &res)) == 0) {
372
355
                        dbgprintf("%s found, resuming.\n", pData->f_hname);
373
356
                        pData->f_addr = res;
374
 
                        pData->iRtryCnt = 0;
375
357
                        pData->eDestState = eDestFORW;
376
358
                } else {
377
359
                        iRet = RS_RET_SUSPENDED;
410
392
 
411
393
        case eDestFORW:
412
394
                dbgprintf(" %s:%s/%s\n", pData->f_hname, getFwdSyslogPt(pData), "tcp-gssapi");
413
 
                pData->ttSuspend = time(NULL);
414
395
                psz = (char*) ppString[0];
415
396
                l = strlen((char*) psz);
416
397
                if (l > MAXLINE)
520
501
                                        ++p; /* eat */
521
502
                                        pData->compressionLevel = iLevel;
522
503
                                } else {
523
 
                                        errmsg.LogError(NO_ERRCODE, "Invalid compression level '%c' specified in "
 
504
                                        errmsg.LogError(0, NO_ERRCODE, "Invalid compression level '%c' specified in "
524
505
                                                 "forwardig action - NOT turning on compression.",
525
506
                                                 *p);
526
507
                                }
527
508
#                                       else
528
 
                                errmsg.LogError(NO_ERRCODE, "Compression requested, but rsyslogd is not compiled "
 
509
                                errmsg.LogError(0, NO_ERRCODE, "Compression requested, but rsyslogd is not compiled "
529
510
                                         "with compression support - request ignored.");
530
511
#                                       endif /* #ifdef USE_NETZIP */
531
512
                        } else if(*p == 'o') { /* octet-couting based TCP framing? */
533
514
                                /* no further options settable */
534
515
                                tcp_framing = TCP_FRAMING_OCTET_COUNTING;
535
516
                        } else { /* invalid option! Just skip it... */
536
 
                                errmsg.LogError(NO_ERRCODE, "Invalid option %c in forwarding action - ignoring.", *p);
 
517
                                errmsg.LogError(0, NO_ERRCODE, "Invalid option %c in forwarding action - ignoring.", *p);
537
518
                                ++p; /* eat invalid option */
538
519
                        }
539
520
                        /* the option processing is done. We now do a generic skip
549
530
                        /* we probably have end of string - leave it for the rest
550
531
                         * of the code to handle it (but warn the user)
551
532
                         */
552
 
                        errmsg.LogError(NO_ERRCODE, "Option block not terminated in gssapi forward action.");
 
533
                        errmsg.LogError(0, NO_ERRCODE, "Option block not terminated in gssapi forward action.");
553
534
        }
554
535
        /* extract the host first (we do a trick - we replace the ';' or ':' with a '\0')
555
536
         * now skip to port and then template name. rgerhards 2005-07-06
567
548
                        /* SKIP AND COUNT */;
568
549
                pData->port = malloc(i + 1);
569
550
                if(pData->port == NULL) {
570
 
                        errmsg.LogError(NO_ERRCODE, "Could not get memory to store syslog forwarding port, "
 
551
                        errmsg.LogError(0, NO_ERRCODE, "Could not get memory to store syslog forwarding port, "
571
552
                                 "using default port, results may not be what you intend\n");
572
553
                        /* we leave f_forw.port set to NULL, this is then handled by
573
554
                         * getFwdSyslogPt().
581
562
                
582
563
        /* now skip to template */
583
564
        bErr = 0;
584
 
        while(*p && *p != ';'  && *p != '#' && !isspace((int) *p))
585
 
                ++p; /*JUST SKIP*/
 
565
        while(*p && *p != ';') {
 
566
                if(*p && *p != ';' && !isspace((int) *p)) {
 
567
                        if(bErr == 0) { /* only 1 error msg! */
 
568
                                bErr = 1;
 
569
                                errno = 0;
 
570
                                errmsg.LogError(0, NO_ERRCODE, "invalid selector line (port), probably not doing "
 
571
                                         "what was intended");
 
572
                        }
 
573
                }
 
574
                ++p;
 
575
        }
586
576
 
587
577
        /* TODO: make this if go away! */
588
578
        if(*p == ';' || *p == '#' || isspace(*p)) {
602
592
        memset(&hints, 0, sizeof(hints));
603
593
        /* port must be numeric, because config file syntax requests this */
604
594
        hints.ai_flags = AI_NUMERICSERV;
605
 
        hints.ai_family = family;
 
595
        hints.ai_family = glbl.GetDefPFFamily();
606
596
        hints.ai_socktype = SOCK_STREAM;
607
597
        if( (error = getaddrinfo(pData->f_hname, getFwdSyslogPt(pData), &hints, &res)) != 0) {
608
598
                pData->eDestState = eDestFORW_UNKN;
609
 
                pData->iRtryCnt = INET_RETRY_MAX;
610
 
                pData->ttSuspend = time(NULL);
611
599
        } else {
612
600
                pData->eDestState = eDestFORW;
613
601
                pData->f_addr = res;
630
618
 
631
619
BEGINmodExit
632
620
CODESTARTmodExit
 
621
        objRelease(glbl, CORE_COMPONENT);
633
622
        objRelease(errmsg, CORE_COMPONENT);
634
623
        objRelease(gssutil, LM_GSSUTIL_FILENAME);
635
624
        objRelease(tcpclt, LM_TCPCLT_FILENAME);
659
648
                gss_mode = GSSMODE_ENC;
660
649
                dbgprintf("GSS-API gssmode set to GSSMODE_ENC\n");
661
650
        } else {
662
 
                errmsg.LogError(NO_ERRCODE, "unknown gssmode parameter: %s", (char *) mode);
 
651
                errmsg.LogError(0, RS_RET_INVALID_PARAMS, "unknown gssmode parameter: %s", (char *) mode);
663
652
                iRet = RS_RET_INVALID_PARAMS;
664
653
        }
665
654
        free(mode);
688
677
        *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */
689
678
CODEmodInit_QueryRegCFSLineHdlr
690
679
        CHKiRet(objUse(errmsg, CORE_COMPONENT));
 
680
        CHKiRet(objUse(glbl, CORE_COMPONENT));
691
681
        CHKiRet(objUse(gssutil, LM_GSSUTIL_FILENAME));
692
682
        CHKiRet(objUse(tcpclt, LM_TCPCLT_FILENAME));
693
683