~ubuntu-branches/ubuntu/karmic/rsyslog/karmic-200908151517

« back to all changes in this revision

Viewing changes to plugins/omsnmp/omsnmp.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2008-05-03 09:59:59 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20080503095959-3zue1idtwaf9zu6m
Tags: 3.16.1-1
* New upstream release.
  - Fixes a segfault in the imklog input plugin. Closes: #479117

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
static int iTrapType = SNMP_TRAP_ENTERPRISESPECIFIC;/*Default is SNMP_TRAP_ENTERPRISESPECIFIC */
75
75
/* 
76
76
                        Possible Values
77
 
        SNMP_TRAP_COLDSTART                             (0)
78
 
        SNMP_TRAP_WARMSTART                             (1)
79
 
        SNMP_TRAP_LINKDOWN                              (2)
80
 
        SNMP_TRAP_LINKUP                                (3)
81
 
        SNMP_TRAP_AUTHFAIL                              (4)
82
 
        SNMP_TRAP_EGPNEIGHBORLOSS               (5)
 
77
        SNMP_TRAP_COLDSTART             (0)
 
78
        SNMP_TRAP_WARMSTART             (1)
 
79
        SNMP_TRAP_LINKDOWN              (2)
 
80
        SNMP_TRAP_LINKUP                (3)
 
81
        SNMP_TRAP_AUTHFAIL              (4)
 
82
        SNMP_TRAP_EGPNEIGHBORLOSS       (5)
83
83
        SNMP_TRAP_ENTERPRISESPECIFIC    (6)
84
84
*/
85
85
 
86
86
typedef struct _instanceData {
87
87
        uchar   szTransport[OMSNMP_MAXTRANSPORLENGTH+1];        /* Transport - Can be udp, tcp, udp6, tcp6 and other types supported by NET-SNMP */ 
88
 
        uchar   szTarget[MAXHOSTNAMELEN+1];                                     /* IP/hostname of Snmp Target*/ 
89
 
        uchar   szTargetAndPort[MAXHOSTNAMELEN+1];                      /* IP/hostname + Port,needed format for SNMP LIB */ 
 
88
        uchar   *szTarget;                                      /* IP/hostname of Snmp Target*/ 
 
89
        uchar   *szTargetAndPort;                               /* IP/hostname + Port,needed format for SNMP LIB */ 
90
90
        uchar   szCommunity[OMSNMP_MAXCOMMUNITYLENGHT+1];       /* Snmp Community */ 
91
91
        uchar   szEnterpriseOID[OMSNMP_MAXOIDLENGHT+1];         /* Snmp Enterprise OID - default is (1.3.6.1.4.1.3.1.1 = enterprises.cmu.1.1) */ 
92
92
        uchar   szSnmpTrapOID[OMSNMP_MAXOIDLENGHT+1];           /* Snmp Trap OID - default is (1.3.6.1.4.1.19406.1.2.1 = ADISCON-MONITORWARE-MIB::syslogtrap) */ 
93
 
        uchar   szSyslogMessageOID[OMSNMP_MAXOIDLENGHT+1];      /* Snmp OID used for the Syslog Message - default is 1.3.6.1.4.1.19406.1.1.2.1 - ADISCON-MONITORWARE-MIB::syslogMsg
94
 
                                                                                                                *       You will need the ADISCON-MONITORWARE-MIB and ADISCON-MIB mibs installed on the receiver side in order to decode this mib. 
95
 
                                                                                                                *       Downloads of these mib files can be found here: 
96
 
                                                                                                                *               http://www.adiscon.org/download/ADISCON-MONITORWARE-MIB.txt
97
 
                                                                                                                *               http://www.adiscon.org/download/ADISCON-MIB.txt
98
 
                                                                                                                */ 
99
 
        int iPort;                                                                                      /* Target Port */
100
 
        int iSNMPVersion;                                                                       /* SNMP Version to use */
101
 
        int iTrapType;                                                                          /* Snmp TrapType or GenericType */
102
 
        int iSpecificType;                                                                      /* Snmp Specific Type */
 
93
        uchar   szSyslogMessageOID[OMSNMP_MAXOIDLENGHT+1];      /* Snmp OID used for the Syslog Message:
 
94
                * default is 1.3.6.1.4.1.19406.1.1.2.1 - ADISCON-MONITORWARE-MIB::syslogMsg
 
95
                * You will need the ADISCON-MONITORWARE-MIB and ADISCON-MIB mibs installed on the receiver
 
96
                * side in order to decode this mib. 
 
97
                * Downloads of these mib files can be found here: 
 
98
                *       http://www.adiscon.org/download/ADISCON-MONITORWARE-MIB.txt
 
99
                *       http://www.adiscon.org/download/ADISCON-MIB.txt
 
100
                */ 
 
101
        int iPort;                                              /* Target Port */
 
102
        int iSNMPVersion;                                       /* SNMP Version to use */
 
103
        int iTrapType;                                          /* Snmp TrapType or GenericType */
 
104
        int iSpecificType;                                      /* Snmp Specific Type */
103
105
 
104
106
        netsnmp_session *snmpsession;                                           /* Holds to SNMP Session, NULL if not initialized */
105
107
} instanceData;
313
315
BEGINdoAction
314
316
CODESTARTdoAction
315
317
        /* Abort if the STRING is not set, should never happen */
316
 
        if (ppString[0] == NULL)
317
 
        {
 
318
        if (ppString[0] == NULL) {
318
319
                ABORT_FINALIZE(RS_RET_INVALID_PARAMS);
319
320
        }
320
321
        
327
328
CODESTARTfreeInstance
328
329
        /* free snmp Session here */
329
330
        omsnmp_exitSession(pData);
 
331
 
 
332
        if(pData->szTarget != NULL)
 
333
                free(pData->szTarget);
 
334
        if(pData->szTargetAndPort != NULL)
 
335
                free(pData->szTargetAndPort);
 
336
 
330
337
ENDfreeInstance
331
338
 
332
339
 
333
340
BEGINparseSelectorAct
 
341
        uchar szTargetAndPort[MAXHOSTNAMELEN+128]; /* work buffer for specifying a full target and port string */
334
342
CODESTARTparseSelectorAct
335
343
CODE_STD_STRING_REQUESTparseSelectorAct(1)
336
344
        if(!strncmp((char*) p, ":omsnmp:", sizeof(":omsnmp:") - 1)) {
359
367
                ABORT_FINALIZE( RS_RET_PARAM_ERROR );
360
368
        } else {
361
369
                /* Copy Target */
362
 
                strncpy( (char*) pData->szTarget, (char*) pszTarget, strlen((char*) pszTarget) );
 
370
                CHKmalloc(pData->szTarget = (uchar*) strdup((char*)pszTarget));
363
371
        }
364
372
 
365
373
        /* Copy Community */
412
420
                pData->iTrapType = iTrapType;
413
421
 
414
422
        /* Create string for session peername! */
415
 
        snprintf( (char*) pData->szTargetAndPort, sizeof(pData->szTargetAndPort) / sizeof(char), "%s:%s:%d", pData->szTransport, pData->szTarget, pData->iPort );
 
423
        snprintf((char*)szTargetAndPort, sizeof(szTargetAndPort), "%s:%s:%d", pData->szTransport, pData->szTarget, pData->iPort);
 
424
        CHKmalloc(pData->szTargetAndPort = (uchar*)strdup((char*)szTargetAndPort));
416
425
        
417
426
        /* Print Debug info */
418
427
        dbgprintf("SNMPTransport: %s\n", pData->szTransport);