Initial commit.
This commit is contained in:
commit
b0110de180
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
pg_dump_camembert.dump
|
56
backend/camembert/Makefile
Normal file
56
backend/camembert/Makefile
Normal file
@ -0,0 +1,56 @@
|
||||
|
||||
CC=g++
|
||||
OPTIONS=-D_THREAD_SAFE -O3 -march=pentiumpro -c -Wall -I/usr/local/include -Ilibkmsnmp/
|
||||
LINKOPTIONS=-D_THREAD_SAFE -Wall -I/usr/local/include -Ilibkmsnmp/ -L/usr/local/lib
|
||||
|
||||
main: main.o monitor.o neighbours.o functions.o vlan.o materiel.o interface.o action.o fdb.o arp.o pgdb.o snmpobject.o snmp.o ip.o libkmsnmp/libkmsnmp.a
|
||||
$(CC) $(LINKOPTIONS) -pthread -lpq main.o monitor.o neighbours.o functions.o vlan.o materiel.o interface.o action.o fdb.o arp.o pgdb.o snmpobject.o snmp.o ip.o libkmsnmp/libkmsnmp.a -o main
|
||||
|
||||
libkmsnmp/libkmsnmp.a:
|
||||
cd libkmsnmp/ && make libkmsnmp.a
|
||||
|
||||
main.o: main.cpp camembert.h
|
||||
$(CC) $(OPTIONS) main.cpp
|
||||
|
||||
monitor.o: monitor.cpp monitor.h
|
||||
$(CC) $(OPTIONS) monitor.cpp
|
||||
|
||||
neighbours.o: neighbours.cpp neighbours.h
|
||||
$(CC) $(OPTIONS) neighbours.cpp
|
||||
|
||||
functions.o: functions.h functions.cpp
|
||||
$(CC) $(OPTIONS) functions.cpp
|
||||
|
||||
vlan.o: vlan.h vlan.cpp
|
||||
$(CC) $(OPTIONS) vlan.cpp
|
||||
|
||||
action.o: action.h action.cpp
|
||||
$(CC) $(OPTIONS) action.cpp
|
||||
|
||||
interface.o: interface.h interface.cpp
|
||||
$(CC) $(OPTIONS) interface.cpp
|
||||
|
||||
materiel.o: materiel.h materiel.cpp
|
||||
$(CC) $(OPTIONS) materiel.cpp
|
||||
|
||||
fdb.o: fdb.h fdb.cpp
|
||||
$(CC) $(OPTIONS) fdb.cpp
|
||||
|
||||
arp.o: arp.h arp.cpp
|
||||
$(CC) $(OPTIONS) arp.cpp
|
||||
|
||||
pgdb.o: pgdb.cpp pgdb.h
|
||||
$(CC) $(OPTIONS) pgdb.cpp
|
||||
|
||||
snmpobject.o: snmpobject.cpp snmpobject.h
|
||||
$(CC) $(OPTIONS) snmpobject.cpp
|
||||
|
||||
snmp.o: snmp.cpp snmp.h
|
||||
$(CC) $(OPTIONS) snmp.cpp
|
||||
|
||||
ip.o: ip.cpp ip.h
|
||||
$(CC) $(OPTIONS) ip.cpp
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
cd libkmsnmp/ && rm -f *.o
|
22
backend/camembert/action.cpp
Normal file
22
backend/camembert/action.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include "action.h"
|
||||
|
||||
Action::Action(unsigned short int num, const char *opt) {
|
||||
this->_numAction = num;
|
||||
this->_option = new char[strlen(opt)+1];
|
||||
strcpy(this->_option, opt);
|
||||
this->_next = NULL;
|
||||
}
|
||||
|
||||
Action::~Action() {
|
||||
delete[] _option;
|
||||
if(_next)
|
||||
delete _next;
|
||||
}
|
||||
|
||||
void Action::addAction(unsigned short int num, const char *opt) {
|
||||
if(_next) // flemme de faire propre sans récurrence
|
||||
_next->addAction(num, opt);
|
||||
else
|
||||
_next = new Action(num, opt);
|
||||
}
|
||||
|
24
backend/camembert/action.h
Normal file
24
backend/camembert/action.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef __CAMEMBERT_ACTION_H
|
||||
#define __CAMEMBERT_ACTION_H
|
||||
|
||||
#include <string.h>
|
||||
|
||||
class Action {
|
||||
private:
|
||||
unsigned short int _numAction;
|
||||
char *_option;
|
||||
Action *_next;
|
||||
|
||||
public:
|
||||
Action(unsigned short int num, const char *opt);
|
||||
~Action();
|
||||
|
||||
void addAction(unsigned short int num, const char *opt);
|
||||
unsigned short int getNum() const { return _numAction; }
|
||||
const char *getOption() const { return _option; }
|
||||
Action *getNext() const { return _next; }
|
||||
};
|
||||
|
||||
|
||||
#endif /* __CAMEMBERT_ACTION_H */
|
||||
|
BIN
backend/camembert/action.o
Normal file
BIN
backend/camembert/action.o
Normal file
Binary file not shown.
31
backend/camembert/arp.cpp
Normal file
31
backend/camembert/arp.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
#include "arp.h"
|
||||
|
||||
ARPCache::ARPCache() {
|
||||
mac[0] = 0;
|
||||
ip = NULL;
|
||||
next = NULL;
|
||||
}
|
||||
|
||||
ARPCache::ARPCache(const char *macaddr, const char *i) {
|
||||
strcpy(mac, macaddr);
|
||||
ip = new IP(i);
|
||||
next = NULL;
|
||||
}
|
||||
|
||||
ARPCache::~ARPCache() {
|
||||
if(ip)
|
||||
delete ip;
|
||||
if(next)
|
||||
delete next;
|
||||
}
|
||||
|
||||
void ARPCache::addEntry(const char *mac, const char *ip) {
|
||||
ARPCache *arp = this, *prev = NULL;
|
||||
while(arp) {
|
||||
if(!strcmp(mac, arp->mac) && !strcmp(ip, arp->ip->getIPstr()))
|
||||
return;
|
||||
prev = arp;
|
||||
arp = arp->next;
|
||||
}
|
||||
prev->next = new ARPCache(mac, ip);
|
||||
}
|
23
backend/camembert/arp.h
Normal file
23
backend/camembert/arp.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef __CAMEMBERT_ARP_H
|
||||
#define __CAMEMBERT_ARP_H
|
||||
|
||||
#include "ip.h"
|
||||
|
||||
class ARPCache {
|
||||
private:
|
||||
char mac[24];
|
||||
IP *ip;
|
||||
ARPCache *next;
|
||||
|
||||
public:
|
||||
ARPCache();
|
||||
ARPCache(const char *mac, const char *ip);
|
||||
~ARPCache();
|
||||
void addEntry(const char *mac, const char *ip);
|
||||
|
||||
const char *getMAC() const { return mac; }
|
||||
IP *getIP() const { return ip; }
|
||||
ARPCache *getNext() const { return next; }
|
||||
};
|
||||
|
||||
#endif /* __CAMEMBERT_H */
|
BIN
backend/camembert/arp.o
Normal file
BIN
backend/camembert/arp.o
Normal file
Binary file not shown.
30
backend/camembert/camembert.h
Normal file
30
backend/camembert/camembert.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef __CAMEMBERT_H
|
||||
#define __CAMEMBERT_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "ip.h"
|
||||
#include "snmp.h"
|
||||
#include "snmpobject.h"
|
||||
#include "pgdb.h"
|
||||
#include "interface.h"
|
||||
#include "materiel.h"
|
||||
#include "monitor.h"
|
||||
#include "functions.h"
|
||||
#include "neighbours.h"
|
||||
|
||||
extern SNMP* snmp;
|
||||
extern MaterielList* lstMateriel;
|
||||
extern pthread_mutex_t mtx_materiels;
|
||||
extern Monitor* monitor;
|
||||
extern unsigned int maxIdMateriel;
|
||||
extern unsigned int maxIdInterface;
|
||||
|
||||
#define FIRST_IP "172.17.24.1"
|
||||
#define COMMUNITY "pacadmins"
|
||||
|
||||
#define MAX_JOBS 256
|
||||
#define MAX_THREADS 8
|
||||
#define THREADED 1
|
||||
|
||||
#endif /* __CAMEMBERT_H */
|
35
backend/camembert/fdb.cpp
Normal file
35
backend/camembert/fdb.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include "fdb.h"
|
||||
|
||||
ForwardingDatabase::ForwardingDatabase(const char *macaddr, unsigned short int vlan, unsigned short int type) {
|
||||
strcpy(mac, macaddr);
|
||||
this->vlan = vlan;
|
||||
this->type = type;
|
||||
next = NULL;
|
||||
}
|
||||
|
||||
ForwardingDatabase::~ForwardingDatabase() {
|
||||
if(next)
|
||||
delete next;
|
||||
}
|
||||
|
||||
bool ForwardingDatabase::hasMAC(const char *macaddr, unsigned short int vlan) const {
|
||||
const ForwardingDatabase *fdb;
|
||||
for(fdb=this; fdb!=NULL; fdb=fdb->next) {
|
||||
if(vlan == fdb->vlan && !strcmp(fdb->mac, macaddr))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ForwardingDatabase::addEntry(const char *macaddr, unsigned short int vlan, unsigned short int type) {
|
||||
ForwardingDatabase *fdb = this, *prev = NULL;
|
||||
while(fdb) {
|
||||
if(!strcmp(macaddr, fdb->mac) && vlan == fdb->vlan)
|
||||
return;
|
||||
prev = fdb;
|
||||
fdb = fdb->next;
|
||||
}
|
||||
prev->next = new ForwardingDatabase(macaddr, vlan, type);
|
||||
|
||||
}
|
||||
|
29
backend/camembert/fdb.h
Normal file
29
backend/camembert/fdb.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef __CAMEMBERT_FDB_H
|
||||
#define __CAMEMBERT_FDB_H
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// Bon, c'est pas tres beau, mais on utilise aussi cette classe pour
|
||||
// les secure Mac addresses (port-security)
|
||||
class ForwardingDatabase {
|
||||
private:
|
||||
char mac[24];
|
||||
unsigned short int vlan, type;
|
||||
ForwardingDatabase *next;
|
||||
|
||||
public:
|
||||
ForwardingDatabase(const char *macaddr, unsigned short int vlan, unsigned short int type);
|
||||
~ForwardingDatabase();
|
||||
|
||||
bool hasMAC(const char *macaddr, unsigned short int vlan) const;
|
||||
void addEntry(const char *macaddr, unsigned short int vlan, unsigned short int type);
|
||||
|
||||
const char *getMAC() const { return mac; }
|
||||
unsigned short int getVLAN() const { return vlan; }
|
||||
unsigned short int getType() const { return type; }
|
||||
ForwardingDatabase *getNext() { return next; }
|
||||
};
|
||||
|
||||
#endif /* __CAMEMBERT_H */
|
||||
|
BIN
backend/camembert/fdb.o
Normal file
BIN
backend/camembert/fdb.o
Normal file
Binary file not shown.
465
backend/camembert/functions.cpp
Normal file
465
backend/camembert/functions.cpp
Normal file
@ -0,0 +1,465 @@
|
||||
#include <regex.h>
|
||||
#include "functions.h"
|
||||
#include "vlan.h"
|
||||
|
||||
#define ACTION_SHUTDOWN 0
|
||||
#define ACTION_NO_SHUTDOWN 1
|
||||
#define ACTION_DESCRIPTION 2
|
||||
#define ACTION_MAX_MAC_COUNT 3
|
||||
#define ACTION_NO_STICKY 4
|
||||
#define ACTION_VLAN 7
|
||||
|
||||
#define OID_DESCRIPTION "1.3.6.1.2.1.31.1.1.1.18"
|
||||
#define OID_ADMINSTATUS "1.3.6.1.2.1.2.2.1.7"
|
||||
#define OID_MAXMACCOUNT "1.3.6.1.4.1.9.9.315.1.2.1.1.3"
|
||||
#define OID_SECUREMACROWSTATUS "1.3.6.1.4.1.9.9.315.1.2.2.1.4"
|
||||
#define OID_ACCESSVLAN "1.3.6.1.4.1.9.9.68.1.2.2.1.2"
|
||||
|
||||
Oid OID_ifName ("1.3.6.1.2.1.2.2.1.2");
|
||||
Oid OID_ifType ("1.3.6.1.2.1.2.2.1.3");
|
||||
Oid OID_ifAddress ("1.3.6.1.2.1.2.2.1.6");
|
||||
Oid OID_ifDescription (OID_DESCRIPTION);
|
||||
Oid OID_ifSpeed ("1.3.6.1.2.1.2.2.1.5");
|
||||
Oid OID_ifAdminStatus (OID_ADMINSTATUS);
|
||||
Oid OID_ifOperStatus ("1.3.6.1.2.1.2.2.1.8");
|
||||
|
||||
Oid OID_ifAccessVlan (OID_ACCESSVLAN);
|
||||
Oid OID_ifVoiceVlan ("1.3.6.1.4.1.9.9.68.1.5.1.1.1");
|
||||
Oid OID_ifNativeVlan ("1.3.6.1.4.1.9.9.46.1.6.1.1.5");
|
||||
|
||||
Oid OID_ifDot1dPort("1.3.6.1.2.1.17.1.4.1.2");
|
||||
|
||||
Oid OID_PortInterface ("1.3.6.1.4.1.9.9.87.1.4.1.1.25");
|
||||
Oid OID_PortDot1D ("1.3.6.1.4.1.9.9.87.1.4.1.1.35");
|
||||
Oid OID_SpanningTreePortFast ("1.3.6.1.4.1.9.9.87.1.4.1.1.36");
|
||||
|
||||
Oid OID_ARPCache("1.3.6.1.2.1.3.1.1.2");
|
||||
|
||||
Oid OID_ForwardingInterface ("1.3.6.1.2.1.17.4.3.1.2");
|
||||
Oid OID_ForwardingType ("1.3.6.1.2.1.17.4.3.1.3");
|
||||
|
||||
Oid OID_PortSecurityEnabled ("1.3.6.1.4.1.9.9.315.1.2.1.1.1");
|
||||
Oid OID_PortSecureStatus ("1.3.6.1.4.1.9.9.315.1.2.1.1.2");
|
||||
Oid OID_MaximumSecureMacCount (OID_MAXMACCOUNT);
|
||||
Oid OID_CurrentSecureMacCount ("1.3.6.1.4.1.9.9.315.1.2.1.1.4");
|
||||
Oid OID_ViolationCount ("1.3.6.1.4.1.9.9.315.1.2.1.1.9");
|
||||
Oid OID_SecureLastMac ("1.3.6.1.4.1.9.9.315.1.2.1.1.10");
|
||||
Oid OID_StickyEnabled ("1.3.6.1.4.1.9.9.315.1.2.1.1.15");
|
||||
|
||||
Oid OID_SecureMacType("1.3.6.1.4.1.9.9.315.1.2.2.1.2");
|
||||
|
||||
// ==================================
|
||||
// Fonctions sur les interfaces
|
||||
// ==================================
|
||||
|
||||
// set_admin_status
|
||||
// Blabla commentaire
|
||||
void set_admin_status(Materiel *m, unsigned int ifNum, bool newStatus) {
|
||||
//I = m->getInterface
|
||||
char oidC[64];
|
||||
oidC[0] = 0;
|
||||
sprintf(oidC, OID_ADMINSTATUS".%d", ifNum);
|
||||
Oid OID_AdminStatusSetting(oidC);
|
||||
m->snmpset(&OID_AdminStatusSetting, 2-newStatus);
|
||||
}
|
||||
|
||||
void set_description(Materiel *m, unsigned int ifNum, const char *newDesc) {
|
||||
char oidC[64];
|
||||
oidC[0] = 0;
|
||||
sprintf(oidC, OID_DESCRIPTION".%d", ifNum);
|
||||
Oid OID_DescriptionSetting(oidC);
|
||||
m->snmpset(&OID_DescriptionSetting, newDesc);
|
||||
}
|
||||
|
||||
void set_max_mac_count(Materiel *m, unsigned int ifNum, unsigned int newMax) {
|
||||
char oidC[64];
|
||||
oidC[0] = 0;
|
||||
sprintf(oidC, OID_MAXMACCOUNT".%d", ifNum);
|
||||
Oid OID_MaximumSecureMacCountSetting(oidC);
|
||||
m->snmpset(&OID_MaximumSecureMacCountSetting, newMax);
|
||||
}
|
||||
|
||||
void delete_sticky(Materiel *m, unsigned int ifNum, const char *macToDelete) {
|
||||
char oidC[64];
|
||||
oidC[0] = 0;
|
||||
|
||||
char *c;
|
||||
char mac[24];
|
||||
strcpy(mac, macToDelete);
|
||||
int intmac[6], i = 0;
|
||||
c = strtok(mac, ":");
|
||||
while(c) {
|
||||
intmac[i++] = strtol(c, NULL, 16);
|
||||
c = strtok(NULL, ":");
|
||||
}
|
||||
// ugly workaround for 2950 switch, to be removed after ios upgrade
|
||||
if (ifNum < 100) {
|
||||
sprintf(oidC, OID_SECUREMACROWSTATUS".%d.%d.%d.%d.%d.%d.%d", ifNum, intmac[0], intmac[1], intmac[2], intmac[3], intmac[4], intmac[5]);
|
||||
}
|
||||
else {
|
||||
sprintf(oidC, "1.3.6.1.4.1.9.9.315.1.2.3.1.5.%d.%d.%d.%d.%d.%d.%d.%d", ifNum, intmac[0], intmac[1], intmac[2], intmac[3], intmac[4], intmac[5], 964);
|
||||
}
|
||||
Oid OID_SecureMacAddrRowStatus(oidC);
|
||||
m->snmpset(&OID_SecureMacAddrRowStatus, 6);
|
||||
}
|
||||
|
||||
void set_vlan(Materiel *m, unsigned int ifNum, unsigned int newVlan) {
|
||||
char oidC[64];
|
||||
oidC[0] = 0;
|
||||
sprintf(oidC, OID_ACCESSVLAN".%d", ifNum);
|
||||
Oid OID_ifAccessVlanSetting(oidC);
|
||||
m->snmpset(&OID_ifAccessVlanSetting, newVlan);
|
||||
}
|
||||
|
||||
void apply_actions(Materiel *m) {
|
||||
InterfaceList *ifl;
|
||||
Interface *I;
|
||||
Action *a;
|
||||
unsigned short int n;
|
||||
|
||||
for(ifl=m->getInterfaces(); ifl!=NULL; ifl=ifl->getNext()) {
|
||||
I = ifl->getInterface();
|
||||
for(a=I->getActions(); a!=NULL; a=a->getNext()) {
|
||||
switch(n = a->getNum()) {
|
||||
case ACTION_SHUTDOWN:
|
||||
case ACTION_NO_SHUTDOWN: set_admin_status(m, I->getIfNumber(), n); break;
|
||||
case ACTION_DESCRIPTION: set_description(m, I->getIfNumber(), a->getOption()); break;
|
||||
case ACTION_MAX_MAC_COUNT: set_max_mac_count(m, I->getIfNumber(), atoi(a->getOption())); break;
|
||||
case ACTION_NO_STICKY: delete_sticky(m, I->getIfNumber(), a->getOption()); break;
|
||||
case ACTION_VLAN: set_vlan(m, I->getIfNumber(), atoi(a->getOption())); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get_interfaces_infos_base
|
||||
// Va chercher le nom, type, l'adresse MAC, la vitesse et le statut d'un équipement donné
|
||||
// Crée les interfaces si elles n'existent pas
|
||||
void get_interfaces_infos_base(Materiel *m) {
|
||||
const SNMPResult *r;
|
||||
unsigned short int ifNum;
|
||||
Interface *i;
|
||||
int val;
|
||||
unsigned long value;
|
||||
|
||||
SNMPResults res(m->multiplesnmpwalk(6, 0,
|
||||
&OID_ifOperStatus,
|
||||
&OID_ifAdminStatus,
|
||||
&OID_ifSpeed,
|
||||
&OID_ifAddress,
|
||||
&OID_ifType,
|
||||
&OID_ifName));
|
||||
// Parcourt les résultats du SNMPWalk
|
||||
while(r = res.getNext()) {
|
||||
const Oid &o = r->get_oid();
|
||||
ifNum = o[10];
|
||||
i = m->getInterfaceById(ifNum);
|
||||
// Si l'interface n'existe pas sur l'équipement...
|
||||
if(!i) {
|
||||
pthread_mutex_lock(&mtx_materiels);
|
||||
// On la crée...
|
||||
i = new Interface(++maxIdInterface, ifNum);
|
||||
pthread_mutex_unlock(&mtx_materiels);
|
||||
// et on l'ajoute au matériel.
|
||||
m->addInterface(i, DBSTATUS_NEW);
|
||||
}
|
||||
switch(o[9]) {
|
||||
// Blabla mise à jour des infos sur l'interface.
|
||||
case 2: i->setName(r->get_printable_value()); break;
|
||||
case 3: r->get_value(val); i->ifType = val; break;
|
||||
case 6: i->setAddress(r->get_printable_value()); break;
|
||||
case 5: r->get_value(value); i->speed = value; break;
|
||||
case 7: r->get_value(val); i->adminStatus = 2-val; break;
|
||||
case 8: r->get_value(val); i->operStatus = 2-val; break;
|
||||
}
|
||||
|
||||
// On signale qu'on a mis à jour les infos.
|
||||
m->getInterfaces()->foundInterface(ifNum);
|
||||
}
|
||||
}
|
||||
|
||||
void get_interfaces_dot1d(Materiel *m) {
|
||||
const SNMPResult *r;
|
||||
int value;
|
||||
unsigned short int vlan;
|
||||
VlanList vlans;
|
||||
Interface *i;
|
||||
|
||||
for(InterfaceList *ifl=m->getInterfaces(); ifl!=NULL; ifl=ifl->getNext()) {
|
||||
if((value = ifl->getInterface()->vlan) > 0)
|
||||
vlans.addVlan(value);
|
||||
}
|
||||
vlans.addVlan(0);
|
||||
|
||||
while(vlans.getNext(vlan)) {
|
||||
SNMPResults res(m->snmpwalk(&OID_ifDot1dPort, vlan));
|
||||
while(r = res.getNext()) {
|
||||
const Oid &o = r->get_oid();
|
||||
r->get_value(value);
|
||||
i = m->getInterfaceById(value);
|
||||
if(i)
|
||||
i->ifDot1d = o[11];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get_interfaces_description
|
||||
// Récupère la description des interfaces d'un équipement donné
|
||||
void get_interfaces_description(Materiel *m) {
|
||||
const SNMPResult *r;
|
||||
Interface *i;
|
||||
|
||||
SNMPResults res(m->snmpwalk(&OID_ifDescription));
|
||||
while(r = res.getNext()) {
|
||||
const Oid &o = r->get_oid();
|
||||
if((i = m->getInterfaceById(o[11])) != NULL)
|
||||
i->setDescription(r->get_printable_value());
|
||||
}
|
||||
}
|
||||
|
||||
// get_interfaces_vlan
|
||||
// Récupère le VLAN et le VLAN voix des interfaces de l'équipement donné
|
||||
void get_interfaces_vlan(Materiel *m) {
|
||||
const SNMPResult *r;
|
||||
Interface *i;
|
||||
int val;
|
||||
|
||||
SNMPResults res(m->multiplesnmpwalk(2, 0, &OID_ifVoiceVlan, &OID_ifAccessVlan));
|
||||
while(r = res.getNext()) {
|
||||
const Oid &o = r->get_oid();
|
||||
if((i = m->getInterfaceById(o[14])) != NULL) {
|
||||
switch(o[10]) {
|
||||
case 2: r->get_value(val); i->vlan = val; break;
|
||||
case 5: r->get_value(val); i->voiceVlan = val; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get_interfaces_trunk
|
||||
// Vérifie si les interfaces sont en Trunk et récupère le native VLAN
|
||||
void get_interfaces_trunk(Materiel *m) {
|
||||
const SNMPResult *r;
|
||||
Interface *i;
|
||||
int val;
|
||||
|
||||
SNMPResults res(m->snmpwalk(&OID_ifNativeVlan));
|
||||
while(r = res.getNext()) {
|
||||
const Oid &o = r->get_oid();
|
||||
if((i = m->getInterfaceById(o[14])) != NULL) {
|
||||
r->get_value(val);
|
||||
i->vlan = -1;
|
||||
i->nativeVlan = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void get_interfaces_c2900(Materiel *m) {
|
||||
Interface *i;
|
||||
SNMPResult const *r;
|
||||
int portnum, modulenum, rx;
|
||||
|
||||
SNMPResults res(m->multiplesnmpwalk(3, 0,
|
||||
&OID_SpanningTreePortFast,
|
||||
&OID_PortDot1D,
|
||||
&OID_PortInterface));
|
||||
|
||||
while (r = res.getNext()) {
|
||||
const Oid& o = r->get_oid();
|
||||
|
||||
portnum = o[15];
|
||||
modulenum = o[14];
|
||||
r->get_value(rx);
|
||||
|
||||
if (o[13] == 25 && ((i = m->getInterfaceById(rx)) != NULL)) {
|
||||
i->portNum = portnum;
|
||||
i->moduleNum = modulenum;
|
||||
}
|
||||
else if ((i = m->getInterfaceByPort(modulenum, portnum)) != NULL) {
|
||||
switch(o[13]) {
|
||||
case 36: i->spanningTree = 2-rx; break;
|
||||
case 35: i->portDot1d = rx; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool is_mac_address_correct(const char *mac) {
|
||||
regex_t preg;
|
||||
int match;
|
||||
|
||||
if((regcomp(&preg, "([0-9a-fA-F]{2}[ :-]){5}[0-9a-fA-F]{2}[ :-]?", REG_NOSUB | REG_EXTENDED)) == 0) {
|
||||
match = regexec(&preg, mac, 0, NULL, 0);
|
||||
regfree(&preg);
|
||||
return match == 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void get_interfaces_port_security(Materiel *m) {
|
||||
Interface *i;
|
||||
SNMPResult const *r;
|
||||
int val;
|
||||
unsigned long value;
|
||||
|
||||
SNMPResults res(m->multiplesnmpwalk(7, 0,
|
||||
&OID_PortSecurityEnabled,
|
||||
&OID_PortSecureStatus,
|
||||
&OID_MaximumSecureMacCount,
|
||||
&OID_CurrentSecureMacCount,
|
||||
&OID_ViolationCount,
|
||||
&OID_SecureLastMac,
|
||||
&OID_StickyEnabled));
|
||||
|
||||
while(r = res.getNext()) {
|
||||
const Oid& o = r->get_oid();
|
||||
if((i = m->getInterfaceById(o[14])) != NULL) {
|
||||
switch(o[13]) {
|
||||
case 1: r->get_value(val); i->portSecEnabled = 2-val; break;
|
||||
case 2: r->get_value(val); i->portSecStatus = val; break;
|
||||
case 3: r->get_value(val); i->maxMacCount = val; break;
|
||||
case 4: r->get_value(val); i->currMacCount = val; break;
|
||||
case 9: r->get_value(value); i->violationCount = value; break;
|
||||
case 10:
|
||||
if(is_mac_address_correct(r->get_printable_value()))
|
||||
i->setLastMacAddr(r->get_printable_value());
|
||||
break;
|
||||
case 15: r->get_value(val); i->stickyEnabled = 2-val; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get_interfaces_infos
|
||||
// Va chercher toutes les informations sur les interfaces
|
||||
void get_interfaces_infos(Materiel *m) {
|
||||
get_interfaces_infos_base(m);
|
||||
get_interfaces_description(m);
|
||||
get_interfaces_trunk(m);
|
||||
get_interfaces_vlan(m);
|
||||
get_interfaces_dot1d(m);
|
||||
get_interfaces_c2900(m);
|
||||
get_interfaces_port_security(m);
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// Fonction ARP
|
||||
// ==========================================
|
||||
|
||||
void get_arp_infos(Materiel *m) {
|
||||
const SNMPResult *r;
|
||||
int len, c;
|
||||
const char *oid, *pres;
|
||||
|
||||
SNMPResults res(m->snmpwalk(&OID_ARPCache));
|
||||
while(r = res.getNext()) {
|
||||
oid = r->get_printable_oid();
|
||||
pres = r->get_printable_value();
|
||||
|
||||
len = strlen(oid);
|
||||
c = 0;
|
||||
while(len > 0 && c < 4) {
|
||||
if(oid[--len] == '.')
|
||||
c++;
|
||||
}
|
||||
if(c == 4)
|
||||
m->addARPEntry(pres, &oid[len+1]);
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================================
|
||||
// Fonction Forwarding Database
|
||||
// ===========================================
|
||||
|
||||
void get_real_fdb_infos(Materiel *m) {
|
||||
const SNMPResult *r;
|
||||
int i;
|
||||
unsigned short int vlan;
|
||||
VlanList vlans;
|
||||
ForwardingDatabase *fdb = NULL;
|
||||
Interface *I;
|
||||
char buffer[8], mac[24];
|
||||
char hextable[] = "0123456789ABCDEF";
|
||||
|
||||
for(InterfaceList *ifl=m->getInterfaces(); ifl!=NULL; ifl=ifl->getNext()) {
|
||||
if((i = ifl->getInterface()->vlan) > 0)
|
||||
vlans.addVlan(i);
|
||||
}
|
||||
//vlans.addVlan(0);
|
||||
|
||||
while(vlans.getNext(vlan)) {
|
||||
SNMPResults res(m->multiplesnmpwalk(2, vlan, &OID_ForwardingInterface, &OID_ForwardingType));
|
||||
|
||||
while(r = res.getNext()) {
|
||||
const Oid &o = r->get_oid();
|
||||
|
||||
mac[0] = 0;
|
||||
for(i=0; i<6; i++) {
|
||||
sprintf(buffer, "%c%c:", hextable[o[11+i]/16], hextable[o[11+i]%16]);
|
||||
strcat(mac, buffer);
|
||||
}
|
||||
mac[17] = 0;
|
||||
|
||||
switch(o[10]) {
|
||||
case 3:
|
||||
r->get_value(i);
|
||||
if(i == 3) {
|
||||
if(!fdb) {
|
||||
fdb = new ForwardingDatabase(mac, vlan, 0);
|
||||
}
|
||||
else {
|
||||
fdb->addEntry(mac, vlan, 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
r->get_value(i);
|
||||
if(i > 0) {
|
||||
I = m->getInterfaceByDot1d(i);
|
||||
if(!I)
|
||||
I = m->getInterfaceByPortDot1d(i);
|
||||
if(!I)
|
||||
I = m->getInterfaceById(i);
|
||||
if(I && fdb->hasMAC(mac, vlan) && (I->vlan != -1 || (I->voiceVlan > 0 && I->voiceVlan < 4096)))
|
||||
I->addForwardingDBEntry(mac, vlan, 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(fdb)
|
||||
delete fdb;
|
||||
}
|
||||
|
||||
void get_secure_addresses_infos(Materiel *m) {
|
||||
const SNMPResult *r;
|
||||
Interface *I;
|
||||
char buffer[8], mac[24];
|
||||
char hextable[] = "0123456789ABCDEF";
|
||||
int val;
|
||||
|
||||
SNMPResults res(m->snmpwalk(&OID_SecureMacType));
|
||||
while(r = res.getNext()) {
|
||||
const Oid &o = r->get_oid();
|
||||
|
||||
mac[0] = 0;
|
||||
for(unsigned short int i=0; i<6; i++) {
|
||||
sprintf(buffer, "%c%c:", hextable[o[15+i]/16], hextable[o[15+i]%16]);
|
||||
strcat(mac, buffer);
|
||||
}
|
||||
mac[17] = 0;
|
||||
|
||||
r->get_value(val);
|
||||
I = m->getInterfaceById(o[14]);
|
||||
if(I)
|
||||
I->addForwardingDBEntry(mac, 0, val);
|
||||
}
|
||||
}
|
||||
|
||||
void get_fdb_infos(Materiel *m) {
|
||||
get_real_fdb_infos(m);
|
||||
get_secure_addresses_infos(m);
|
||||
}
|
||||
|
12
backend/camembert/functions.h
Normal file
12
backend/camembert/functions.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef __CAMEMBERT_FUNCTIONS_H
|
||||
#define __CAMEMBERT_FUNCTIONS_H
|
||||
|
||||
#include "camembert.h"
|
||||
|
||||
void get_interfaces_infos(Materiel *m);
|
||||
void get_arp_infos(Materiel *m);
|
||||
void get_fdb_infos(Materiel *m);
|
||||
void apply_actions(Materiel *m);
|
||||
|
||||
#endif /* __CAMEMBERT_FUNCTIONS_H */
|
||||
|
BIN
backend/camembert/functions.o
Normal file
BIN
backend/camembert/functions.o
Normal file
Binary file not shown.
231
backend/camembert/interface.cpp
Normal file
231
backend/camembert/interface.cpp
Normal file
@ -0,0 +1,231 @@
|
||||
#include "interface.h"
|
||||
|
||||
Interface::Interface(unsigned int dbID, unsigned short int ifNum) {
|
||||
_dbID = dbID;
|
||||
_number = ifNum;
|
||||
|
||||
_description = NULL;
|
||||
_name = NULL;
|
||||
_address[0] = 0;
|
||||
_fdb = NULL;
|
||||
|
||||
oldLinks = NULL;
|
||||
nbOldLinks = 0;
|
||||
|
||||
vlan = 0;
|
||||
voiceVlan = 0;
|
||||
nativeVlan = 0;
|
||||
|
||||
ifType = 0;
|
||||
speed = 0;
|
||||
adminStatus = 0;
|
||||
operStatus = 0;
|
||||
ifDot1d = 0;
|
||||
|
||||
moduleNum = 0;
|
||||
portNum = 0;
|
||||
portDot1d = 0;
|
||||
spanningTree = 0;
|
||||
|
||||
_dstDevice = NULL;
|
||||
|
||||
portSecEnabled = 0;
|
||||
portSecStatus = 0;
|
||||
maxMacCount = 0;
|
||||
currMacCount = 0;
|
||||
violationCount = 0;
|
||||
_lastSecAddr[0] = 0;
|
||||
stickyEnabled = 0;
|
||||
|
||||
_actions = NULL;
|
||||
}
|
||||
|
||||
Interface::~Interface() {
|
||||
if(_description)
|
||||
delete[] _description;
|
||||
if(_name)
|
||||
delete[] _name;
|
||||
if(oldLinks)
|
||||
delete[] oldLinks;
|
||||
if(_fdb)
|
||||
delete _fdb;
|
||||
if(_dstDevice) {
|
||||
dstDevice_t* dd = _dstDevice;
|
||||
/* while(_dstDevice->next) {
|
||||
dd = _dstDevice->next;
|
||||
while(dd->next)
|
||||
dd = dd->next;
|
||||
delete dd->dstIfName;
|
||||
delete dd;
|
||||
}*/
|
||||
delete _dstDevice;
|
||||
}
|
||||
if(_actions)
|
||||
delete _actions;
|
||||
}
|
||||
|
||||
void Interface::setName(const char *name) {
|
||||
if(_name)
|
||||
delete[] _name;
|
||||
_name = new char[strlen(name)+1];
|
||||
strcpy(_name, name);
|
||||
}
|
||||
|
||||
void Interface::setAddress(const char *addr) {
|
||||
strcpy(_address, addr);
|
||||
}
|
||||
|
||||
void Interface::setDescription(const char *descr) {
|
||||
if(_description)
|
||||
delete[] _description;
|
||||
_description = new char[strlen(descr)+1];
|
||||
strcpy(_description, descr);
|
||||
|
||||
char *c;
|
||||
while(c = strchr(_description, '\''))
|
||||
*c = ' ';
|
||||
}
|
||||
|
||||
void Interface::addForwardingDBEntry(const char *mac, unsigned short int vlan, unsigned short int type) {
|
||||
if(!_fdb)
|
||||
_fdb = new ForwardingDatabase(mac, vlan, type);
|
||||
else
|
||||
_fdb->addEntry(mac, vlan, type);
|
||||
}
|
||||
|
||||
void Interface::addDistantDevice(const char* ifName, void const* device) {
|
||||
if(!_dstDevice) {
|
||||
_dstDevice = new dstDevice_t;
|
||||
_dstDevice->dstIfName = new char[strlen(ifName)+1];
|
||||
strcpy(_dstDevice->dstIfName, ifName);
|
||||
_dstDevice->distantDevice = device;
|
||||
_dstDevice->next = NULL;
|
||||
}
|
||||
else {
|
||||
dstDevice_t* dd = _dstDevice;
|
||||
while(dd->next)
|
||||
dd = dd->next;
|
||||
dd->next = new dstDevice_t;
|
||||
dd->next->dstIfName = new char[strlen(ifName)+1];
|
||||
strcpy(dd->next->dstIfName, ifName);
|
||||
dd->next->distantDevice = device;
|
||||
dd->next->next = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void Interface::setLastMacAddr(const char *addr) {
|
||||
strcpy(_lastSecAddr, addr);
|
||||
}
|
||||
|
||||
void Interface::addAction(unsigned short int num, const char *opt) {
|
||||
if(!_actions)
|
||||
_actions = new Action(num, opt);
|
||||
else
|
||||
_actions->addAction(num, opt);
|
||||
}
|
||||
|
||||
InterfaceList::InterfaceList(Interface *i, unsigned int dbStatus) {
|
||||
_current = i;
|
||||
_next = NULL;
|
||||
_dbStatus = dbStatus;
|
||||
}
|
||||
|
||||
InterfaceList::~InterfaceList() {
|
||||
delete _current;
|
||||
if(_next)
|
||||
delete _next;
|
||||
}
|
||||
|
||||
void InterfaceList::addInterface(Interface *i, unsigned int dbStatus) {
|
||||
InterfaceList *ifl = this;
|
||||
// Va jusqu'à la fin de la liste
|
||||
while(ifl->_next)
|
||||
ifl = ifl->_next;
|
||||
// Ajoute l'interface à la fin
|
||||
ifl->_next = new InterfaceList(i, dbStatus);
|
||||
}
|
||||
|
||||
Interface *InterfaceList::getInterfaceById(unsigned int id) const {
|
||||
const InterfaceList *ifl;
|
||||
Interface *i;
|
||||
|
||||
// Parcourt la liste des interfaces
|
||||
for(ifl=this; ifl!=NULL; ifl=ifl->getNext()) {
|
||||
i = ifl->getInterface();
|
||||
// retourne l'interface courante si son ifNum correspond à celui passé
|
||||
if(i->getIfNumber() == id)
|
||||
return i;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Interface *InterfaceList::getInterfaceByDot1d(unsigned int id) const {
|
||||
const InterfaceList *ifl;
|
||||
Interface *i;
|
||||
|
||||
// Parcourt la liste des interfaces
|
||||
for(ifl=this; ifl!=NULL; ifl=ifl->getNext()) {
|
||||
i = ifl->getInterface();
|
||||
// retourne l'interface courante si son ifNum correspond à celui passé
|
||||
if(i->ifDot1d == id)
|
||||
return i;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Interface *InterfaceList::getInterfaceByPort(unsigned int module, unsigned int port) const {
|
||||
const InterfaceList *ifl;
|
||||
Interface *i;
|
||||
|
||||
// Parcourt la liste des interfaces
|
||||
for(ifl=this; ifl!=NULL; ifl=ifl->getNext()) {
|
||||
i = ifl->getInterface();
|
||||
// retourne l'interface courante si son ifNum correspond à celui passé
|
||||
if(i->moduleNum == module && i->portNum == port)
|
||||
return i;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Interface *InterfaceList::getInterfaceByPortDot1d(unsigned int id) const {
|
||||
const InterfaceList *ifl;
|
||||
Interface *i;
|
||||
|
||||
// Parcourt la liste des interfaces
|
||||
for(ifl=this; ifl!=NULL; ifl=ifl->getNext()) {
|
||||
i = ifl->getInterface();
|
||||
// retourne l'interface courante si son ifNum correspond à celui passé
|
||||
if(i->portDot1d == id)
|
||||
return i;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*Interface *InterfaceList::getInterfaceByDbId(unsigned int dbId) const {
|
||||
const InterfaceList *ifl;
|
||||
Interface *i;
|
||||
|
||||
for(ifl=this; ifl!=NULL; ifl=ifl->getNext()) {
|
||||
i = ifl->getInterface();
|
||||
if(i->getID() == dbId)
|
||||
return i;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
} */
|
||||
|
||||
void InterfaceList::foundInterface(unsigned int id) {
|
||||
InterfaceList *ifl;
|
||||
|
||||
for(ifl=this; ifl!=NULL; ifl=ifl->getNext()) {
|
||||
if(ifl->getInterface()->getIfNumber() == id) {
|
||||
ifl->setDBstatus(DBSTATUS_UPDATED);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
97
backend/camembert/interface.h
Normal file
97
backend/camembert/interface.h
Normal file
@ -0,0 +1,97 @@
|
||||
#ifndef __CAMEMBERT_INTERFACE_H
|
||||
#define __CAMEMBERT_INTERFACE_H
|
||||
|
||||
#include <string.h>
|
||||
#include "pgdb.h"
|
||||
#include "fdb.h"
|
||||
#include "action.h"
|
||||
|
||||
typedef struct dstDevice_s {
|
||||
char* dstIfName;
|
||||
void const* distantDevice;
|
||||
struct dstDevice_s* next;
|
||||
} dstDevice_t;
|
||||
|
||||
class Interface {
|
||||
private:
|
||||
unsigned int _dbID;
|
||||
unsigned short int _number;
|
||||
char *_name;
|
||||
char _address[24];
|
||||
char *_description;
|
||||
|
||||
ForwardingDatabase *_fdb;
|
||||
char _lastSecAddr[24];
|
||||
|
||||
dstDevice_t* _dstDevice;
|
||||
|
||||
Action *_actions;
|
||||
|
||||
public:
|
||||
unsigned int ifType;
|
||||
unsigned int speed;
|
||||
unsigned short int adminStatus;
|
||||
unsigned short int operStatus;
|
||||
unsigned int ifDot1d;
|
||||
unsigned short int spanningTree;
|
||||
|
||||
int vlan, voiceVlan, nativeVlan;
|
||||
|
||||
unsigned int moduleNum, portNum, portDot1d;
|
||||
|
||||
unsigned int *oldLinks;
|
||||
unsigned short int nbOldLinks;
|
||||
|
||||
unsigned short int portSecEnabled;
|
||||
unsigned short int portSecStatus;
|
||||
unsigned short int maxMacCount;
|
||||
unsigned short int currMacCount;
|
||||
unsigned short int violationCount;
|
||||
unsigned short int stickyEnabled;
|
||||
|
||||
Interface(unsigned int dbID, unsigned short int ifNum);
|
||||
~Interface();
|
||||
|
||||
unsigned int getID() const { return _dbID; }
|
||||
unsigned short int getIfNumber() const { return _number; }
|
||||
const char *getName() const { return _name; }
|
||||
const char *getAddress() const { return _address; }
|
||||
const char *getDescription() const { return _description; }
|
||||
ForwardingDatabase *getForwardingDB() const { return _fdb; }
|
||||
dstDevice_t* getDistantDevice() const { return _dstDevice; }
|
||||
const char *getLastMacAddr() const { return _lastSecAddr; }
|
||||
Action *getActions() const { return _actions; }
|
||||
|
||||
void setName(const char *name);
|
||||
void setAddress(const char *addr);
|
||||
void setDescription(const char *descr);
|
||||
void addForwardingDBEntry(const char *mac, unsigned short int vlan, unsigned short int type);
|
||||
void addDistantDevice(const char* ifName, void const* device);
|
||||
void setLastMacAddr(const char *addr);
|
||||
void addAction(unsigned short int num, const char *opt);
|
||||
};
|
||||
|
||||
class InterfaceList: public DBObject {
|
||||
private:
|
||||
InterfaceList *_next;
|
||||
Interface *_current;
|
||||
|
||||
public:
|
||||
InterfaceList(Interface *i, unsigned int dbStatus);
|
||||
~InterfaceList();
|
||||
|
||||
void addInterface(Interface *i, unsigned int dbStatus);
|
||||
Interface *getInterface() const { return _current; }
|
||||
InterfaceList *getNext() const { return _next; }
|
||||
|
||||
Interface *getInterfaceById(unsigned int id) const;
|
||||
Interface *getInterfaceByDot1d(unsigned int id) const;
|
||||
Interface *getInterfaceByPort(unsigned int module, unsigned int port) const;
|
||||
Interface *getInterfaceByPortDot1d(unsigned int id) const;
|
||||
//Interface *getInterfaceByDbId(unsigned int dbId) const;
|
||||
|
||||
void foundInterface(unsigned int id);
|
||||
};
|
||||
|
||||
#endif /* __CAMEMBERT_INTERFACE_H */
|
||||
|
BIN
backend/camembert/interface.o
Normal file
BIN
backend/camembert/interface.o
Normal file
Binary file not shown.
219
backend/camembert/ip.cpp
Normal file
219
backend/camembert/ip.cpp
Normal file
@ -0,0 +1,219 @@
|
||||
/* ========================================================
|
||||
|
||||
Camembert Project
|
||||
Alban FERON, 2007
|
||||
|
||||
IP et IPNetmask repris de Kindmana, par Aurélien Méré
|
||||
|
||||
======================================================== */
|
||||
|
||||
#include "ip.h"
|
||||
|
||||
// --------------------------------------
|
||||
// Class IP
|
||||
// --------------------------------------
|
||||
|
||||
IP::IP() {
|
||||
strcpy(ip, "0.0.0.0");
|
||||
ipint = 0;
|
||||
}
|
||||
|
||||
|
||||
IP::IP(char const * const ip) { this->setIP(ip); }
|
||||
IP::IP(unsigned int const ip) { this->ipint = ip; this->computestring(); }
|
||||
IP::IP(IP const &ip) { this->ipint = ip.getIPint(); this->computestring(); }
|
||||
IP::IP(IP const * const ip) { this->ipint = ip->getIPint(); this->computestring(); }
|
||||
|
||||
void IP::computestring() {
|
||||
sprintf(this->ip, "%d.%d.%d.%d", ((ipint/16777216)%256), (ipint/65536)%256, (ipint/256)%256, ipint%256);
|
||||
}
|
||||
|
||||
IP &IP::operator = (char const * const ip) {
|
||||
this->setIP(ip);
|
||||
return(*this);
|
||||
}
|
||||
|
||||
IP &IP::operator = (unsigned int const ip) {
|
||||
this->ipint = ip;
|
||||
this->computestring();
|
||||
return(*this);
|
||||
}
|
||||
|
||||
IP &IP::operator = (IP const &ip) {
|
||||
this->ipint = ip.getIPint();
|
||||
strcpy(this->ip, ip.getIPstr());
|
||||
return(*this);
|
||||
}
|
||||
|
||||
char const * IP::getIPstr() const { return(ip); }
|
||||
unsigned int const IP::getIPint() const { return (ipint); }
|
||||
bool const IP::operator==(IP const &ip) const { return (ip.getIPint() == this->ipint); }
|
||||
bool const IP::operator==(char const * const ip) const { return (!strcmp(this->ip, ip)); }
|
||||
bool const IP::operator==(unsigned int const ip) const { return (ip == this->ipint); }
|
||||
bool const IP::operator==(IP const * const ip) const { return (ip->getIPint() == this->ipint); }
|
||||
bool const IP::operator!=(IP const &ip) const { return (ip.getIPint()!=this->ipint); }
|
||||
bool const IP::operator!=(char const * const ip) const { return (strcmp(this->ip, ip)); }
|
||||
bool const IP::operator!=(unsigned int const ip) const { return (ip != this->ipint); }
|
||||
bool const IP::operator!=(IP const * const ip) const { return (ip->getIPint() != this->ipint); }
|
||||
unsigned int const IP::operator &(IP const &ip) const { return (this->ipint & ip.getIPint()); }
|
||||
unsigned int const IP::operator &(IP const * const ip) const { return (this->ipint & ip->getIPint()); }
|
||||
|
||||
IP &IP::operator &= (const IP &ip) {
|
||||
this->ipint &= ip.getIPint();
|
||||
this->computestring();
|
||||
return(*this);
|
||||
}
|
||||
|
||||
IP &IP::operator &= (const IP *ip) {
|
||||
this->ipint &= ip->getIPint();
|
||||
this->computestring();
|
||||
return(*this);
|
||||
}
|
||||
|
||||
void IP::setIP(char const * ip) {
|
||||
unsigned int ipi[4];
|
||||
int i=0;
|
||||
const char *ip2 = ip;
|
||||
|
||||
this->ipint = 0;
|
||||
this->ip[0] = 0;
|
||||
|
||||
while (i<4 && ip!=NULL) {
|
||||
if (*ip != 0) {
|
||||
if ((ipi[i]=atoi(ip))>255)
|
||||
return;
|
||||
if ((ip=strchr(ip, '.')) != NULL) {
|
||||
ip+=1;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((strlen(ip2) < IP_LENGTH) && (i==3)) {
|
||||
strcpy(this->ip, ip2);
|
||||
this->ipint = ipi[0]*16777216+ipi[1]*65536+ipi[2]*256+ipi[3];
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// ----------------------------------------
|
||||
// Class IPNetmask
|
||||
// ----------------------------------------
|
||||
IPNetmask::IPNetmask() {
|
||||
smallmask = 0;
|
||||
}
|
||||
|
||||
IPNetmask::IPNetmask(char const * const ip) {
|
||||
int i=31;
|
||||
unsigned int mask;
|
||||
|
||||
netmask = ip;
|
||||
mask = netmask.getIPint();
|
||||
|
||||
smallmask=0;
|
||||
|
||||
while (i>=0) {
|
||||
if ((mask & (1 << i)) != 0) {
|
||||
smallmask++;
|
||||
i--;
|
||||
} else
|
||||
i=-1;
|
||||
}
|
||||
}
|
||||
|
||||
IPNetmask::IPNetmask(unsigned int const mask) {
|
||||
unsigned int newmask = 0, i;
|
||||
|
||||
for (i=0; i<mask; i++)
|
||||
newmask += (1 << (31-i));
|
||||
netmask = newmask;
|
||||
smallmask = mask;
|
||||
}
|
||||
|
||||
unsigned int const IPNetmask::getMask() const {
|
||||
return netmask.getIPint();
|
||||
}
|
||||
|
||||
char const * IPNetmask::getMaskStr() const {
|
||||
return netmask.getIPstr();
|
||||
}
|
||||
|
||||
unsigned int const IPNetmask::getMaskSmall() const {
|
||||
return smallmask;
|
||||
}
|
||||
|
||||
// -------------------------------------------
|
||||
// Class IPList
|
||||
// -------------------------------------------
|
||||
|
||||
IPList::IPList() {
|
||||
_current = NULL;
|
||||
_next = NULL;
|
||||
_dbStatus = DBSTATUS_UNKNOWN;
|
||||
}
|
||||
|
||||
void IPList::addIP(IP *const ip, unsigned int dbStatus) {
|
||||
if(!ip)
|
||||
return;
|
||||
|
||||
// Si le pointeur sur l'IP courante est nulle, on met l'IP dedans
|
||||
if(!_current) {
|
||||
_current = ip;
|
||||
setDBstatus(dbStatus);
|
||||
return;
|
||||
}
|
||||
|
||||
// Sinon on rajoute l'IP à la suite
|
||||
IPList *lst = this;
|
||||
while(lst->_next)
|
||||
lst = lst->_next;
|
||||
lst->_next = new IPList();
|
||||
lst->_next->_current = ip;
|
||||
lst->_next->setDBstatus(dbStatus);
|
||||
}
|
||||
|
||||
bool IPList::isIPinList(const IP *ip) const {
|
||||
// L'IP passée est nulle ou il n'y a pas d'IP courante, pas la peine d'aller plus loin,
|
||||
// on considère que d'IP passée n'est pas dans la liste
|
||||
if(!ip || !_current)
|
||||
return false;
|
||||
|
||||
// On parcourt la liste à la recherche d'une même IP et on retourne VRAI si on trouve.
|
||||
for(const IPList *lst=this; lst!=NULL; lst=lst->getNext()) {
|
||||
if(lst->getIP()->getIPint() == ip->getIPint())
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void IPList::foundIP(const IP *ip) {
|
||||
if(!ip || !_current)
|
||||
return;
|
||||
|
||||
for(IPList *lst=this; lst!=NULL; lst=lst->getNext()) {
|
||||
if(lst->getIP()->getIPint() == ip->getIPint()) {
|
||||
lst->setDBstatus(DBSTATUS_UPDATED);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IPList::setFirst(IPList *lip) {
|
||||
IP *tmpI = lip->_current;
|
||||
unsigned int tmpD = lip->_dbStatus;
|
||||
|
||||
lip->_current = this->_current;
|
||||
lip->_dbStatus = this->_dbStatus;
|
||||
|
||||
this->_current = tmpI;
|
||||
this->_dbStatus = tmpD;
|
||||
}
|
||||
|
||||
IPList::~IPList() {
|
||||
if(_current)
|
||||
delete _current;
|
||||
if(_next)
|
||||
delete _next;
|
||||
}
|
147
backend/camembert/ip.h
Normal file
147
backend/camembert/ip.h
Normal file
@ -0,0 +1,147 @@
|
||||
/* ========================================================
|
||||
|
||||
Camembert Project
|
||||
Alban FERON, 2007
|
||||
|
||||
IP et IPNetmask repris de Kindmana, par Aurélien Méré
|
||||
|
||||
======================================================== */
|
||||
|
||||
#ifndef __CAMEMBERT_IP_H
|
||||
#define __CAMEMBERT_IP_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "pgdb.h"
|
||||
|
||||
#define IP_LENGTH 24
|
||||
|
||||
class IP {
|
||||
|
||||
private:
|
||||
char ip[IP_LENGTH];
|
||||
unsigned int ipint;
|
||||
|
||||
void setIP(char const * ip);
|
||||
void computestring();
|
||||
|
||||
public:
|
||||
|
||||
// IP Constructor
|
||||
|
||||
IP();
|
||||
IP(char const * const ip);
|
||||
IP(unsigned int const ip);
|
||||
IP(IP const &ip);
|
||||
IP(IP const * const ip);
|
||||
|
||||
// Base informations for getting, setting
|
||||
// and testing an IP
|
||||
|
||||
char const *getIPstr() const;
|
||||
unsigned int const getIPint() const;
|
||||
|
||||
bool const operator == (char const * const ip) const;
|
||||
bool const operator == (IP const &ip) const;
|
||||
bool const operator == (unsigned int const ip) const;
|
||||
bool const operator == (IP const * const ip) const;
|
||||
bool const operator != (char const * const ip) const;
|
||||
bool const operator != (IP const &ip) const;
|
||||
bool const operator != (unsigned int const ip) const;
|
||||
bool const operator != (IP const * const ip) const;
|
||||
|
||||
IP &operator = (char const * const ip);
|
||||
IP &operator = (unsigned int const ip);
|
||||
IP &operator = (IP const &ip);
|
||||
IP &operator = (IP const * const ip);
|
||||
|
||||
unsigned int const operator & (const IP &ip) const;
|
||||
unsigned int const operator & (const IP * const ip) const;
|
||||
|
||||
IP &operator &= (const IP &ip);
|
||||
IP &operator &= (const IP * const ip);
|
||||
};
|
||||
|
||||
class IPNetmask {
|
||||
|
||||
private:
|
||||
IP netmask;
|
||||
unsigned int smallmask;
|
||||
|
||||
public:
|
||||
IPNetmask();
|
||||
IPNetmask(const char * const ip);
|
||||
IPNetmask(const unsigned int mask);
|
||||
|
||||
unsigned int const getMask() const ;
|
||||
char const *getMaskStr() const ;
|
||||
unsigned int const getMaskSmall() const;
|
||||
};
|
||||
|
||||
/**
|
||||
* Liste d'IPs
|
||||
*/
|
||||
class IPList: public DBObject {
|
||||
private:
|
||||
IPList *_next;
|
||||
IP *_current;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Crée une nouvelle liste vide
|
||||
*/
|
||||
IPList();
|
||||
|
||||
/**
|
||||
* Détruit la liste ainsi que les IPs qu'elle contient
|
||||
*/
|
||||
~IPList();
|
||||
|
||||
/**
|
||||
* Ajoute une IP à la fin de la liste
|
||||
*
|
||||
* @param ip - IP à ajouter
|
||||
* @param dbStatus - L'IP est sortie de la base où est à créer ?
|
||||
*/
|
||||
void addIP(IP *const ip, unsigned int dbStatus);
|
||||
|
||||
/**
|
||||
* @return IP courante
|
||||
*/
|
||||
IP *getIP() const { return _current; }
|
||||
|
||||
/**
|
||||
* @return Sous liste contenant les IP suivantes
|
||||
*/
|
||||
IPList *getNext() const { return _next; }
|
||||
|
||||
/**
|
||||
* Cherche si une IP donnée existe dans la liste
|
||||
*
|
||||
* @param ip - IP à chercher
|
||||
* @return VRAI si l'ip donnée est dans la liste, FAUX sinon
|
||||
*/
|
||||
bool isIPinList(const IP *ip) const;
|
||||
|
||||
/**
|
||||
* Spécifie que l'IP donnée a été trouvée, donc qu'elle peut être
|
||||
* gardée dans la base de données
|
||||
*
|
||||
* @param ip - IP à déclarer comme "trouvée"
|
||||
*/
|
||||
void foundIP(const IP *ip);
|
||||
|
||||
/**
|
||||
* Etablit l'IP passée (ou plutot l'élément de liste contenant l'IP) comme
|
||||
* première de la liste.
|
||||
* Attention à ne passer que des éléments appartenant effectivement bien à la liste.
|
||||
* Aucune vérification n'est faite.
|
||||
*
|
||||
* @param lip - Elément à passer au début de la liste.
|
||||
*/
|
||||
void setFirst(IPList *lip);
|
||||
};
|
||||
|
||||
#endif /* __CAMEMBERT_H */
|
BIN
backend/camembert/ip.o
Normal file
BIN
backend/camembert/ip.o
Normal file
Binary file not shown.
37
backend/camembert/libkmsnmp/CVS/Entries
Normal file
37
backend/camembert/libkmsnmp/CVS/Entries
Normal file
@ -0,0 +1,37 @@
|
||||
/Makefile/1.1.1.1/Mon Mar 14 10:55:30 2005//
|
||||
/address.cpp/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/address.h/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/asn1.cpp/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/asn1.h/1.1.1.1/Mon Mar 14 10:55:30 2005//
|
||||
/collect.h/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/collect1.h/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/config_snmp_pp.h/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/counter.cpp/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/counter.h/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/ctr64.cpp/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/ctr64.h/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/gauge.cpp/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/gauge.h/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/integer.cpp/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/integer.h/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/mp_v3.h/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/octet.cpp/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/octet.h/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/oid.cpp/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/oid.h/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/oid_def.h/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/pdu.cpp/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/pdu.h/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/smi.h/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/smival.h/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/snmperrs.h/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/snmpmsg.cpp/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/snmpmsg.h/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/target.h/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/timetick.cpp/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/timetick.h/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/usm_v3.h/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/v3.h/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/vb.cpp/1.1.1.1/Mon Mar 14 10:55:29 2005//
|
||||
/vb.h/1.1.1.1/Mon Mar 14 10:55:30 2005//
|
||||
D
|
1
backend/camembert/libkmsnmp/CVS/Repository
Normal file
1
backend/camembert/libkmsnmp/CVS/Repository
Normal file
@ -0,0 +1 @@
|
||||
libkmsnmp
|
1
backend/camembert/libkmsnmp/CVS/Root
Normal file
1
backend/camembert/libkmsnmp/CVS/Root
Normal file
@ -0,0 +1 @@
|
||||
:ext:kindman@www.amc-os.com:/cvsroot/kindmana
|
44
backend/camembert/libkmsnmp/Makefile
Normal file
44
backend/camembert/libkmsnmp/Makefile
Normal file
@ -0,0 +1,44 @@
|
||||
libkmsnmp.a: address.o asn1.o counter.o ctr64.o gauge.o integer.o octet.o oid.o pdu.o snmpmsg.o timetick.o vb.o
|
||||
ar -r libkmsnmp.a address.o asn1.o counter.o ctr64.o gauge.o integer.o octet.o oid.o pdu.o snmpmsg.o timetick.o vb.o
|
||||
|
||||
CC=g++
|
||||
CCOPT= -D_THREAD_SAFE -c -O2 -Wall
|
||||
|
||||
address.o: address.cpp address.h
|
||||
$(CC) $(CCOPT) address.cpp
|
||||
|
||||
asn1.o: asn1.cpp
|
||||
$(CC) $(CCOPT) asn1.cpp
|
||||
|
||||
counter.o: counter.cpp counter.h
|
||||
$(CC) $(CCOPT) counter.cpp
|
||||
|
||||
ctr64.o: ctr64.cpp ctr64.h
|
||||
$(CC) $(CCOPT) ctr64.cpp
|
||||
|
||||
gauge.o: gauge.cpp gauge.h
|
||||
$(CC) $(CCOPT) gauge.cpp
|
||||
|
||||
integer.o: integer.cpp integer.h
|
||||
$(CC) $(CCOPT) integer.cpp
|
||||
|
||||
octet.o: octet.cpp octet.h
|
||||
$(CC) $(CCOPT) octet.cpp
|
||||
|
||||
oid.o: oid.cpp oid.h
|
||||
$(CC) $(CCOPT) oid.cpp
|
||||
|
||||
pdu.o: pdu.cpp pdu.h
|
||||
$(CC) $(CCOPT) pdu.cpp
|
||||
|
||||
snmpmsg.o: snmpmsg.cpp snmpmsg.h
|
||||
$(CC) $(CCOPT) snmpmsg.cpp
|
||||
|
||||
timetick.o: timetick.cpp timetick.h
|
||||
$(CC) $(CCOPT) timetick.cpp
|
||||
|
||||
vb.o: vb.cpp vb.h
|
||||
$(CC) $(CCOPT) vb.cpp
|
||||
|
||||
clean:
|
||||
rm -f *.o libkmsnmp.a
|
2446
backend/camembert/libkmsnmp/address.cpp
Normal file
2446
backend/camembert/libkmsnmp/address.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1081
backend/camembert/libkmsnmp/address.h
Normal file
1081
backend/camembert/libkmsnmp/address.h
Normal file
File diff suppressed because it is too large
Load Diff
2093
backend/camembert/libkmsnmp/asn1.cpp
Normal file
2093
backend/camembert/libkmsnmp/asn1.cpp
Normal file
File diff suppressed because it is too large
Load Diff
440
backend/camembert/libkmsnmp/asn1.h
Normal file
440
backend/camembert/libkmsnmp/asn1.h
Normal file
@ -0,0 +1,440 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## asn1.h
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
// $Id: asn1.h,v 1.1.1.1 2005/03/14 10:55:30 kindman Exp $
|
||||
|
||||
#ifndef _ASN1
|
||||
#define _ASN1
|
||||
|
||||
#ifdef WIN32
|
||||
#ifndef __unix
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "target.h"
|
||||
|
||||
#define MAXLENGTH_BUFFER SNMP_MSG_LENGTH
|
||||
#ifndef EIGHTBIT_SUBIDS
|
||||
typedef unsigned long oid;
|
||||
#define MAX_SUBID 0xFFFFFFFF
|
||||
#else
|
||||
typedef unsigned char oid;
|
||||
#define MAX_SUBID 0xFF
|
||||
#endif
|
||||
|
||||
#define MAX_OID_LEN 128 /* max subid's in an oid */
|
||||
|
||||
// asn.1 values
|
||||
#define ASN_BOOLEAN (0x01)
|
||||
#ifndef ASN_INTEGER
|
||||
#define ASN_INTEGER (0x02)
|
||||
#endif
|
||||
#define ASN_BIT_STR (0x03)
|
||||
#define ASN_OCTET_STR (0x04)
|
||||
#ifndef ASN_NULL
|
||||
#define ASN_NULL (0x05)
|
||||
#endif
|
||||
#define ASN_OBJECT_ID (0x06)
|
||||
#ifndef ASN_SEQUENCE
|
||||
#define ASN_SEQUENCE (0x10)
|
||||
#endif
|
||||
#define ASN_SET (0x11)
|
||||
#ifndef ASN_UNIVERSAL
|
||||
#define ASN_UNIVERSAL (0x00)
|
||||
#endif
|
||||
#ifndef ASN_APPLICATION
|
||||
#define ASN_APPLICATION (0x40)
|
||||
#endif
|
||||
#ifndef ASN_CONTEXT
|
||||
#define ASN_CONTEXT (0x80)
|
||||
#endif
|
||||
#ifndef ASN_PRIVATE
|
||||
#define ASN_PRIVATE (0xC0)
|
||||
#endif
|
||||
#ifndef ASN_PRIMITIVE
|
||||
#define ASN_PRIMITIVE (0x00)
|
||||
#endif
|
||||
#ifndef ASN_CONSTRUCTOR
|
||||
#define ASN_CONSTRUCTOR (0x20)
|
||||
#endif
|
||||
#define ASN_LONG_LEN (0x80)
|
||||
#define ASN_EXTENSION_ID (0x1F)
|
||||
#define ASN_BIT8 (0x80)
|
||||
|
||||
#define IS_CONSTRUCTOR(byte) ((byte) & ASN_CONSTRUCTOR)
|
||||
#define IS_EXTENSION_ID(byte) (((byte) & ASN_EXTENSION_ID) == ASN_EXTENSION_ID)
|
||||
|
||||
#define ASN_MAX_NAME_LEN 128
|
||||
#define SNMP_VERSION_1 0
|
||||
#define SNMP_VERSION_2C 1
|
||||
#define SNMP_VERSION_2STERN 2
|
||||
#define SNMP_VERSION_3 3
|
||||
|
||||
// defined types (from the SMI, RFC 1065)
|
||||
#define SMI_IPADDRESS (ASN_APPLICATION | 0)
|
||||
#define SMI_COUNTER (ASN_APPLICATION | 1)
|
||||
#define SMI_GAUGE (ASN_APPLICATION | 2)
|
||||
#define SMI_TIMETICKS (ASN_APPLICATION | 3)
|
||||
#define SMI_OPAQUE (ASN_APPLICATION | 4)
|
||||
#define SMI_NSAP (ASN_APPLICATION | 5)
|
||||
#define SMI_COUNTER64 (ASN_APPLICATION | 6)
|
||||
#define SMI_UINTEGER (ASN_APPLICATION | 7)
|
||||
|
||||
#define GET_REQ_MSG (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x0)
|
||||
#define GETNEXT_REQ_MSG (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x1)
|
||||
#define GET_RSP_MSG (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x2)
|
||||
#define SET_REQ_MSG (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x3)
|
||||
#define TRP_REQ_MSG (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x4)
|
||||
|
||||
#define GETBULK_REQ_MSG (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x5)
|
||||
#define INFORM_REQ_MSG (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x6)
|
||||
#define TRP2_REQ_MSG (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x7)
|
||||
#define REPORT_MSG (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x8)
|
||||
|
||||
#define SNMP_NOSUCHOBJECT (ASN_CONTEXT | ASN_PRIMITIVE | 0x0)
|
||||
#define SNMP_NOSUCHINSTANCE (ASN_CONTEXT | ASN_PRIMITIVE | 0x1)
|
||||
#define SNMP_ENDOFMIBVIEW (ASN_CONTEXT | ASN_PRIMITIVE | 0x2)
|
||||
|
||||
#define SNMP_MSG_LENGTH MAX_SNMP_PACKET
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define ASNERROR( string) debugprintf(3, "ASN parse error (%s)\n", string )
|
||||
#else
|
||||
#define ASNERROR( string)
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct sockaddr_in ipaddr;
|
||||
|
||||
// pdu
|
||||
struct snmp_pdu {
|
||||
int command; // pdu type
|
||||
unsigned long reqid; // Request id
|
||||
#ifdef _SNMPv3
|
||||
unsigned long msgid;
|
||||
unsigned long maxsize_scopedpdu;
|
||||
#endif
|
||||
unsigned long errstat; // Error status
|
||||
unsigned long errindex; // Error index
|
||||
|
||||
// Trap information
|
||||
oid *enterprise; // System OID
|
||||
int enterprise_length;
|
||||
ipaddr agent_addr; // address of object generating trap
|
||||
int trap_type; // trap type
|
||||
int specific_type; // specific type
|
||||
unsigned long time; // Uptime
|
||||
|
||||
// vb list
|
||||
struct variable_list *variables;
|
||||
};
|
||||
|
||||
// vb list
|
||||
struct variable_list {
|
||||
struct variable_list *next_variable; // NULL for last variable
|
||||
oid *name; // Object identifier of variable
|
||||
int name_length; // number of subid's in name
|
||||
unsigned char type; // ASN type of variable
|
||||
union { // value of variable
|
||||
long *integer;
|
||||
unsigned char *string;
|
||||
oid *objid;
|
||||
unsigned char *bitstring;
|
||||
struct counter64 *counter64;
|
||||
} val;
|
||||
int val_len;
|
||||
};
|
||||
|
||||
struct counter64 {
|
||||
unsigned long high;
|
||||
unsigned long low;
|
||||
};
|
||||
|
||||
|
||||
// prototypes for encoding routines
|
||||
DLLOPT unsigned char *asn_parse_int( unsigned char *data, int *datalength,
|
||||
unsigned char *type,
|
||||
long int *intp, int intsize);
|
||||
|
||||
|
||||
DLLOPT unsigned char *asn_parse_unsigned_int( unsigned char *data,
|
||||
int *datalength,
|
||||
unsigned char *type,
|
||||
unsigned long *intp,
|
||||
int intsize);
|
||||
|
||||
DLLOPT unsigned char *asn_build_int( unsigned char *data, int *datalength,
|
||||
unsigned char type,
|
||||
long *intp, int intsize);
|
||||
|
||||
DLLOPT unsigned char *asn_build_unsigned_int( unsigned char *data,
|
||||
int *datalength,
|
||||
unsigned char type,
|
||||
unsigned long *intp,
|
||||
int intsize);
|
||||
|
||||
DLLOPT unsigned char *asn_parse_string( unsigned char *data, int *datalength,
|
||||
unsigned char *type,
|
||||
unsigned char *string,
|
||||
int *strlength);
|
||||
|
||||
DLLOPT unsigned char *asn_build_string( unsigned char *data, int *datalength,
|
||||
unsigned char type,
|
||||
unsigned char *string,
|
||||
int strlength);
|
||||
|
||||
DLLOPT unsigned char *asn_parse_header( unsigned char *data, int *datalength,
|
||||
unsigned char *type);
|
||||
|
||||
DLLOPT unsigned char *asn_build_header( unsigned char *data, int *datalength,
|
||||
unsigned char type,
|
||||
int length);
|
||||
|
||||
DLLOPT unsigned char *asn_build_sequence( unsigned char *data,
|
||||
int *datalength,
|
||||
unsigned char type,
|
||||
int length);
|
||||
|
||||
DLLOPT unsigned char *asn_parse_length( unsigned char *data,
|
||||
unsigned long *length);
|
||||
|
||||
DLLOPT unsigned char *asn_build_length( unsigned char *data, int *datalength,
|
||||
int length);
|
||||
|
||||
DLLOPT unsigned char *asn_parse_objid( unsigned char *data, int *datalength,
|
||||
unsigned char *type,
|
||||
oid *objid,
|
||||
int *objidlength);
|
||||
|
||||
DLLOPT unsigned char *asn_build_objid( unsigned char *data,
|
||||
int *datalength,
|
||||
unsigned char type,
|
||||
oid *objid,
|
||||
int objidlength);
|
||||
|
||||
DLLOPT unsigned char *asn_parse_null(unsigned char *data, int *datalength,
|
||||
unsigned char *type);
|
||||
|
||||
DLLOPT unsigned char *asn_build_null( unsigned char *data,int *datalength,
|
||||
unsigned char type);
|
||||
|
||||
DLLOPT unsigned char *asn_parse_bitstring( unsigned char *data,
|
||||
int *datalength,
|
||||
unsigned char *type,
|
||||
unsigned char *string,
|
||||
int *strlength);
|
||||
|
||||
DLLOPT unsigned char *asn_build_bitstring( unsigned char *data,
|
||||
int *datalength,
|
||||
unsigned char type,
|
||||
unsigned char *string,
|
||||
int strlength);
|
||||
|
||||
DLLOPT unsigned char *asn_parse_unsigned_int64( unsigned char *data,
|
||||
int *datalength,
|
||||
unsigned char *type,
|
||||
struct counter64 *cp,
|
||||
int countersize);
|
||||
|
||||
DLLOPT unsigned char *asn_build_unsigned_int64( unsigned char *data,
|
||||
int *datalength,
|
||||
unsigned char type,
|
||||
struct counter64 *cp,
|
||||
int countersize);
|
||||
|
||||
DLLOPT struct snmp_pdu *snmp_pdu_create( int command);
|
||||
|
||||
DLLOPT void snmp_free_pdu( struct snmp_pdu *pdu);
|
||||
|
||||
DLLOPT int snmp_build( struct snmp_pdu *pdu,
|
||||
unsigned char *packet,
|
||||
int *out_length,
|
||||
long version,
|
||||
unsigned char* community,
|
||||
int community_len);
|
||||
|
||||
DLLOPT void snmp_add_var(struct snmp_pdu *pdu,
|
||||
oid *name, int name_length,
|
||||
SmiVALUE *smival);
|
||||
|
||||
DLLOPT int snmp_parse( struct snmp_pdu *pdu,
|
||||
unsigned char *data,
|
||||
unsigned char *community_name,
|
||||
unsigned long &community_len,
|
||||
snmp_version &version,
|
||||
int length);
|
||||
|
||||
DLLOPT unsigned char *build_vb(struct snmp_pdu *pdu,
|
||||
unsigned char *buf, int *buf_len);
|
||||
|
||||
DLLOPT unsigned char *build_data_pdu(struct snmp_pdu *pdu,
|
||||
unsigned char *buf, int *buf_len,
|
||||
unsigned char *vb_buf, int vb_buf_len);
|
||||
|
||||
DLLOPT unsigned char *snmp_build_var_op(unsigned char *data,
|
||||
oid * var_name,
|
||||
int *var_name_len,
|
||||
unsigned char var_val_type,
|
||||
int var_val_len,
|
||||
unsigned char *var_val,
|
||||
int *listlength);
|
||||
|
||||
DLLOPT unsigned char *snmp_parse_var_op( unsigned char *data,
|
||||
oid *var_name,
|
||||
int *var_name_len,
|
||||
unsigned char *var_val_type,
|
||||
int *var_val_len,
|
||||
unsigned char **var_val,
|
||||
int *listlength);
|
||||
|
||||
DLLOPT int snmp_parse_data_pdu(struct snmp_pdu *pdu,
|
||||
unsigned char *&data, int &length);
|
||||
|
||||
DLLOPT int snmp_parse_vb(struct snmp_pdu *pdu,
|
||||
unsigned char *&data, int &data_len);
|
||||
|
||||
DLLOPT void clear_pdu(struct snmp_pdu *pdu);
|
||||
|
||||
/**
|
||||
* Encode the given values for the HeaderData into the buffer.
|
||||
* <pre>
|
||||
* HeaderData ::= SEQUENCE {
|
||||
* msgID INTEGER (0..2147483647),
|
||||
* msgMaxSize INTEGER (484..2147483647),
|
||||
* msgFlags OCTET STRING (SIZE(1)),
|
||||
* msgSecurityModel INTEGER (0..2147483647)
|
||||
* }
|
||||
* </pre>
|
||||
* @param outBuf - The buffer
|
||||
* @param maxLength - IN: length of the buffer
|
||||
* OUT: free bytes left in the buffer
|
||||
* @param msgID - The message ID
|
||||
* @param maxMessageSize - The maximum size of a SNMPv3 message
|
||||
* @param msgFlags - The message Flags
|
||||
* @param securityModel - The security model
|
||||
*
|
||||
* @return - Pointer to the first free byte in the buffer or
|
||||
* NULL if an error occured
|
||||
*/
|
||||
DLLOPT unsigned char *asn1_build_header_data(unsigned char *outBuf,
|
||||
int *maxLength,
|
||||
long msgID,
|
||||
long maxMessageSize,
|
||||
unsigned char msgFlags,
|
||||
long securityModel);
|
||||
|
||||
/**
|
||||
* Parse the filled HeaderData of a SNMPv3 message and return
|
||||
* the encoded values.
|
||||
* <pre>
|
||||
* HeaderData ::= SEQUENCE {
|
||||
* msgID INTEGER (0..2147483647),
|
||||
* msgMaxSize INTEGER (484..2147483647),
|
||||
* msgFlags OCTET STRING (SIZE(1)),
|
||||
* msgSecurityModel INTEGER (0..2147483647)
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @param buf - The buffer to parse
|
||||
* @param buf_len - IN: The length of the buffer
|
||||
* OUT: The number of bytes after this object
|
||||
* int the buffer
|
||||
* @param msg_id - OUT: The message id
|
||||
* @param msg_max_size - OUT: THe maximum message size of the sender
|
||||
* @param msg_flags - OUT: The message flags
|
||||
* @param msg_security_model - OUT: The security model used to build this
|
||||
* message
|
||||
*
|
||||
* @return - Returns a pointer to the first byte past the end of
|
||||
* the object HeaderData (i.e. the start of the next object).
|
||||
* Returns NULL on any error.
|
||||
*/
|
||||
DLLOPT unsigned char *asn1_parse_header_data(unsigned char *buf, int *buf_len,
|
||||
long *msg_id, long *msg_max_size,
|
||||
unsigned char *msg_flags,
|
||||
long *msg_security_model);
|
||||
|
||||
/**
|
||||
* Parse the ScopedPDU and return the encoded values.
|
||||
* <pre>
|
||||
* ScopedPDU ::= SEQUENCE {
|
||||
* contextEngineID OCTET STRING,
|
||||
* contextName OCTET STRING,
|
||||
* data ANY -- e.g., PDUs as defined in RFC 1905
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @param scoped_pdu - The buffer to parse
|
||||
* @param scoped_pdu_len - IN: The length of the buffer
|
||||
* OUT: The number of bytes after this object
|
||||
* int the buffer
|
||||
* @param context_engine_id - OUT: The parsed contextEngineID
|
||||
* @param context_engine_id_len - OUT: The length of the contextEngineID
|
||||
* @param context_name - OUT: The parsed contextName
|
||||
* @param context_name_len - OUT: The length of the contextName
|
||||
*
|
||||
* @return - Pointer to the data object of the scopedPDU or
|
||||
* NULL on any error.
|
||||
*/
|
||||
DLLOPT unsigned char *asn1_parse_scoped_pdu(
|
||||
unsigned char *scoped_pdu, int *scoped_pdu_len,
|
||||
unsigned char *context_engine_id, int *context_engine_id_len,
|
||||
unsigned char *context_name, int *context_name_len );
|
||||
|
||||
/**
|
||||
* Encode the given values for the scopedPDU into the buffer.
|
||||
* <pre>
|
||||
* ScopedPDU ::= SEQUENCE {
|
||||
* contextEngineID OCTET STRING
|
||||
* contextName OCTET STRING
|
||||
* data ANY -- PDU
|
||||
* }
|
||||
* </pre>
|
||||
* param outBuf - The buffer
|
||||
* param max_len - IN: length of the buffer
|
||||
* OUT: free bytes left in the buffer
|
||||
* param contextEngineID - The contextEngineID
|
||||
* param contextEngineIDLength - The length of the contextEngineID
|
||||
* param contextName - The contextName
|
||||
* param contextNameLength - The length of the contextName
|
||||
* param data - The already encoded data
|
||||
* param dataLength - The length of the data
|
||||
*
|
||||
* @return - Pointer to the first free byte in the buffer or
|
||||
* NULL if an error occured
|
||||
*/
|
||||
DLLOPT unsigned char *asn1_build_scoped_pdu(
|
||||
unsigned char *outBuf, int *max_len,
|
||||
unsigned char *contextEngineID, long contextEngineIDLength,
|
||||
unsigned char *contextName, long contextNameLength,
|
||||
unsigned char *data, long dataLength);
|
||||
|
||||
|
||||
#endif // _ASN1
|
||||
|
98
backend/camembert/libkmsnmp/collect.h
Normal file
98
backend/camembert/libkmsnmp/collect.h
Normal file
@ -0,0 +1,98 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## collect.h
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
/*===================================================================
|
||||
|
||||
Copyright (c) 1999
|
||||
Hewlett-Packard Company
|
||||
|
||||
ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
Permission to use, copy, modify, distribute and/or sell this software
|
||||
and/or its documentation is hereby granted without fee. User agrees
|
||||
to display the above copyright notice and this license notice in all
|
||||
copies of the software and any documentation of the software. User
|
||||
agrees to assume all liability for the use of the software; Hewlett-Packard
|
||||
makes no representations about the suitability of this software for any
|
||||
purpose. It is provided "AS-IS without warranty of any kind,either express
|
||||
or implied. User hereby grants a royalty-free license to any and all
|
||||
derivatives based upon this software code base.
|
||||
|
||||
|
||||
SNMP++ C O L L E C T . H
|
||||
|
||||
COLLECTION CLASS DEFINITION
|
||||
|
||||
DESIGN + AUTHOR:
|
||||
Peter E Mellquist
|
||||
|
||||
LANGUAGE:
|
||||
ANSI C++
|
||||
|
||||
OPERATING SYSTEMS:
|
||||
Win 32
|
||||
BSD UNIX
|
||||
|
||||
DESCRIPTION:
|
||||
Simple Collection classes for SNMP++ classes.
|
||||
|
||||
=====================================================================*/
|
||||
// $Id: collect.h,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $
|
||||
|
||||
#ifndef _COLLECTION_H_
|
||||
#define _COLLECTION_H_
|
||||
|
||||
#include "config_snmp_pp.h"
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
#define MAXT 25 // elements per block
|
||||
|
||||
// If you have problems with the collection code:
|
||||
// 1. Send a mail to katz@agentpp.com with details about the used
|
||||
// compile flags, compiler (for example g++ -dumpspecs),...
|
||||
// so we can change the default behaviour for your system
|
||||
// 2. comment in the define _OLD_TEMPLATE_COLLECTION in
|
||||
// config_snmp_pp.h
|
||||
#ifdef _OLD_TEMPLATE_COLLECTION
|
||||
|
||||
#include "collect2.h"
|
||||
|
||||
#else
|
||||
|
||||
#include "collect1.h"
|
||||
|
||||
#endif
|
||||
|
||||
#endif // _COLLECTION_H_
|
||||
|
344
backend/camembert/libkmsnmp/collect1.h
Normal file
344
backend/camembert/libkmsnmp/collect1.h
Normal file
@ -0,0 +1,344 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## collect1.h
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
// $Id: collect1.h,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $
|
||||
|
||||
template <class T> class SnmpCollection
|
||||
{
|
||||
class cBlock
|
||||
{
|
||||
public:
|
||||
cBlock(cBlock *p, cBlock *n) : prev(p), next(n) {};
|
||||
T *item[MAXT];
|
||||
cBlock *prev;
|
||||
cBlock *next;
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Create an empty collection.
|
||||
*/
|
||||
SnmpCollection()
|
||||
: count(0), data(0,0) {};
|
||||
|
||||
/**
|
||||
* Create a collection using a single template object.
|
||||
*/
|
||||
SnmpCollection(const T &t)
|
||||
: count(1), data(0, 0)
|
||||
{
|
||||
data.item[0] = (T*) (t.clone());
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a collection with another collection (copy constructor).
|
||||
*/
|
||||
SnmpCollection(const SnmpCollection<T> &c)
|
||||
: count(0), data(0, 0)
|
||||
{
|
||||
if (c.count == 0) return;
|
||||
|
||||
// load up the new collection
|
||||
cBlock *current = &data;
|
||||
cBlock *nextBlock;
|
||||
int cn = 0;
|
||||
|
||||
while (count < c.count)
|
||||
{
|
||||
if (cn >= MAXT)
|
||||
{
|
||||
nextBlock = new cBlock(current, 0);
|
||||
current->next = nextBlock;
|
||||
current = nextBlock;
|
||||
cn=0;
|
||||
}
|
||||
T *tmp;
|
||||
c.get_element(tmp, count);
|
||||
current->item[cn] = (T*) (tmp->clone());
|
||||
count++;
|
||||
cn++;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Destroy the collection.
|
||||
*/
|
||||
~SnmpCollection()
|
||||
{
|
||||
clear(); // just delete the data
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the size of the collection.
|
||||
*/
|
||||
int size()
|
||||
{
|
||||
return count;
|
||||
};
|
||||
|
||||
/**
|
||||
* Append an item to the collection.
|
||||
*/
|
||||
SnmpCollection& operator +=(const T &i)
|
||||
{
|
||||
cBlock *current = &data;
|
||||
cBlock *add;
|
||||
int cn = (int) count % MAXT;
|
||||
while (current->next)
|
||||
current = current->next;
|
||||
if ((count > 0) && ((count % MAXT) == 0))
|
||||
{
|
||||
add = new cBlock(current, 0);
|
||||
current->next = add;
|
||||
add->item[0] = (T*) (i.clone());
|
||||
}
|
||||
else
|
||||
{
|
||||
current->item[cn] = (T*) (i.clone());
|
||||
}
|
||||
count++;
|
||||
|
||||
return *this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Assign one collection to another.
|
||||
*/
|
||||
SnmpCollection &operator =(const SnmpCollection<T> &c)
|
||||
{
|
||||
if (this == &c) return *this; // check for self assignment
|
||||
|
||||
clear(); // delete the data
|
||||
|
||||
if (c.count == 0) return *this;
|
||||
|
||||
// load up the new collection
|
||||
cBlock *current = &data;
|
||||
cBlock *nextBlock;
|
||||
int cn = 0;
|
||||
count = 0;
|
||||
while (count < c.count)
|
||||
{
|
||||
if (cn >= MAXT)
|
||||
{
|
||||
nextBlock = new cBlock(current, 0);
|
||||
current->next = nextBlock;
|
||||
current = nextBlock;
|
||||
cn=0;
|
||||
}
|
||||
T *tmp;
|
||||
c.get_element(tmp, count);
|
||||
current->item[cn] = (T*) (tmp->clone());
|
||||
count++;
|
||||
cn++;
|
||||
}
|
||||
|
||||
return *this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Access an element in the collection.
|
||||
*
|
||||
* @return The requestet element or an empty element if out of bounds.
|
||||
*/
|
||||
T operator[](const int p) const
|
||||
{
|
||||
if ((p < count) && (p >= 0))
|
||||
{
|
||||
cBlock const *current = &data;
|
||||
int bn = (int) (p / MAXT);
|
||||
int cn = (int) p % MAXT;
|
||||
for (int z=0; z<bn; z++)
|
||||
current = current->next;
|
||||
return *(current->item[cn]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// return an instance of nothing!!
|
||||
T t;
|
||||
return t;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set an element in the collection.
|
||||
*
|
||||
* @return 0 on success and -1 on failure.
|
||||
*/
|
||||
int set_element( const T& i, const int p)
|
||||
{
|
||||
if ((p < 0) || (p > count)) return -1; // not found!
|
||||
|
||||
cBlock *current = &data;
|
||||
int bn = (int) p / MAXT;
|
||||
int cn = (int) p % MAXT;
|
||||
for (int z=0; z<bn; z++)
|
||||
current = current->next;
|
||||
delete current->item[cn];
|
||||
current->item[cn] = (T*) (i.clone());
|
||||
return 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get an element in the collection.
|
||||
*
|
||||
* @return 0 on success and -1 on failure.
|
||||
*/
|
||||
int get_element(T &t, const int p) const
|
||||
{
|
||||
if ((p < 0) || (p > count)) return -1; // not found!
|
||||
|
||||
cBlock const *current = &data;
|
||||
int bn = (int) p / MAXT;
|
||||
int cn = (int) p % MAXT;
|
||||
for (int z=0; z<bn; z++)
|
||||
current = current->next;
|
||||
t = *(current->item[cn]);
|
||||
return 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a pointer to an element in the collection.
|
||||
*
|
||||
* @return 0 on success and -1 on failure.
|
||||
*/
|
||||
int get_element(T *&t, const int p) const
|
||||
{
|
||||
if ((p < 0) || (p > count)) return -1; // not found!
|
||||
|
||||
cBlock const *current = &data;
|
||||
int bn = (int) p / MAXT;
|
||||
int cn = (int) p % MAXT;
|
||||
for (int z=0; z<bn; z++)
|
||||
current = current->next;
|
||||
t = current->item[cn];
|
||||
return 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Apply an function to the entire collection, iterator.
|
||||
*/
|
||||
void apply(void f(T&))
|
||||
{
|
||||
T temp;
|
||||
for ( int z=0; z<count; z++)
|
||||
{
|
||||
this->get_element(temp, z);
|
||||
f(temp);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Looks for an element in the collection.
|
||||
*
|
||||
* @return TRUE if found.
|
||||
*/
|
||||
int find(const T& i, int &pos)
|
||||
{
|
||||
T temp;
|
||||
for (int z=0; z<count; z++)
|
||||
{
|
||||
this->get_element(temp, z);
|
||||
if ( temp == i) {
|
||||
pos = z;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete an element in the collection.
|
||||
*/
|
||||
int remove(const T& i)
|
||||
{
|
||||
// first see if we have it
|
||||
int pos;
|
||||
if (find(i, pos))
|
||||
{
|
||||
SnmpCollection<T> newCollection;
|
||||
|
||||
for (int z=0; z<count; z++)
|
||||
{
|
||||
if (z != pos)
|
||||
{
|
||||
T item;
|
||||
get_element(item, z);
|
||||
newCollection += item;
|
||||
}
|
||||
}
|
||||
|
||||
// assign new collection to 'this'
|
||||
operator =(newCollection);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE; // not found thus not removed
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete all elements within the collection.
|
||||
*/
|
||||
void clear()
|
||||
{
|
||||
if (count == 0) return;
|
||||
|
||||
cBlock *current = &data;
|
||||
int z=0;
|
||||
int cn=0;
|
||||
while ( z< count)
|
||||
{
|
||||
if (cn >= MAXT)
|
||||
{
|
||||
cn =0;
|
||||
current = current->next;
|
||||
}
|
||||
delete current->item[cn];
|
||||
cn++;
|
||||
z++;
|
||||
}
|
||||
|
||||
// delete the blocks
|
||||
while (current->next)
|
||||
current = current->next;
|
||||
while (current->prev)
|
||||
{
|
||||
current = current->prev;
|
||||
delete current->next;
|
||||
}
|
||||
|
||||
count = 0;
|
||||
data.next=0;
|
||||
data.prev=0;
|
||||
};
|
||||
|
||||
private:
|
||||
int count;
|
||||
cBlock data;
|
||||
};
|
142
backend/camembert/libkmsnmp/config_snmp_pp.h
Normal file
142
backend/camembert/libkmsnmp/config_snmp_pp.h
Normal file
@ -0,0 +1,142 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## config_snmp_pp.h
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
|
||||
// $Id: config_snmp_pp.h,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $
|
||||
|
||||
#ifndef _CONFIG_SNMP_PP_H_
|
||||
#define _CONFIG_SNMP_PP_H_
|
||||
|
||||
//! This is the amount of variable bindings, a snmp++ Pdu object can contain.
|
||||
#define PDU_MAX_VBS 50
|
||||
|
||||
//! The maximum size of a message that can be sent or received.
|
||||
#define MAX_SNMP_PACKET 4096
|
||||
|
||||
#ifndef DLLOPT
|
||||
#if defined (WIN32) && defined (SNMP_PP_DLL)
|
||||
#ifdef SNMP_PP_EXPORTS
|
||||
#define DLLOPT __declspec(dllexport)
|
||||
#else
|
||||
#define DLLOPT __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define DLLOPT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// define SNMP_PP_IPv6 if you want to use IPv6
|
||||
#ifndef WIN32
|
||||
#define SNMP_PP_IPv6
|
||||
#endif
|
||||
|
||||
// define _NO_SNMPv3 here or in the Makefile if you do not want to use SNMPv3
|
||||
// (default is to use SNMPv3)
|
||||
#define _NO_SNMPv3
|
||||
|
||||
// If you have not disabled SNMPv3, snmp++ will use libdes
|
||||
// (separate package) as default.
|
||||
// define _USE_LIBTOMCRYPT if you want to use libtomcrypt instead
|
||||
// Note that _USE_OPENSSL will override libtomcrypt for SHA1, MD5 and DES.
|
||||
// #define _USE_LIBTOMCRYPT
|
||||
|
||||
// If you define _USE_OPENSSL, snmp++ will use OpenSSL for SHA1,
|
||||
// MD5 and DES.
|
||||
//#define _USE_OPENSSL
|
||||
|
||||
// If you do not use SNMP++ for commercial purposes or if you
|
||||
// have licensed IDEA (read README.v3) you may define the following
|
||||
// to enable IDEA support.
|
||||
// #define _USE_IDEA
|
||||
|
||||
// define _NO_THREADS here or in the Makefile if you do not want thread support
|
||||
// (default is to include thread support)
|
||||
// #define _NO_THREADS
|
||||
|
||||
// define _IPX_ADDRESS and/or _MAC_ADDRESS if you want to use the
|
||||
// classess IpxAddress/IpxSockAddress and/or MacAddress
|
||||
#define _IPX_ADDRESS
|
||||
#define _MAC_ADDRESS
|
||||
|
||||
// define this if you want to send out broadcasts
|
||||
#define SNMP_BROADCAST
|
||||
|
||||
|
||||
// Some older(?) compilers need a special declaration of
|
||||
// template classes
|
||||
// #define _OLD_TEMPLATE_COLLECTION
|
||||
|
||||
// We have inet_aton() function if not compiling with VC++
|
||||
#ifndef _MSC_VER
|
||||
#define HAVE_INET_ATON
|
||||
#endif
|
||||
|
||||
// If IPv6 is enabled assume that inet_pton() is available
|
||||
// If IPv6 and gcc then assume gethostbyname2() is available
|
||||
#ifdef SNMP_PP_IPv6
|
||||
#define HAVE_INET_PTON
|
||||
#ifdef __GNUC__
|
||||
#define HAVE_GETHOSTBYNAME2
|
||||
#endif
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Changes below this line should not be necessary
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _NO_SNMPv3
|
||||
#ifndef _SNMPv3
|
||||
#define _SNMPv3
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _NO_THREADS
|
||||
#ifdef WIN32
|
||||
|
||||
#ifndef _THREADS
|
||||
#define _WIN32THREADS
|
||||
#define VC_EXTRALEAN
|
||||
#define _THREADS
|
||||
#endif
|
||||
|
||||
#else // !WIN32
|
||||
|
||||
#ifndef _THREADS
|
||||
#define _THREADS
|
||||
#endif
|
||||
|
||||
#ifndef POSIX_THREADS
|
||||
#ifdef __unix
|
||||
#define POSIX_THREADS
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // WIN32
|
||||
#endif // !_NO_THREADS
|
||||
|
||||
#endif // _CONFIG_SNMP_PP_H_
|
99
backend/camembert/libkmsnmp/counter.cpp
Normal file
99
backend/camembert/libkmsnmp/counter.cpp
Normal file
@ -0,0 +1,99 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## counter.cpp
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
/*===================================================================
|
||||
|
||||
Copyright (c) 1999
|
||||
Hewlett-Packard Company
|
||||
|
||||
ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
Permission to use, copy, modify, distribute and/or sell this software
|
||||
and/or its documentation is hereby granted without fee. User agrees
|
||||
to display the above copyright notice and this license notice in all
|
||||
copies of the software and any documentation of the software. User
|
||||
agrees to assume all liability for the use of the software; Hewlett-Packard
|
||||
makes no representations about the suitability of this software for any
|
||||
purpose. It is provided "AS-IS" without warranty of any kind,either express
|
||||
or implied. User hereby grants a royalty-free license to any and all
|
||||
derivatives based upon this software code base.
|
||||
|
||||
|
||||
|
||||
C O U N T E R. C P P
|
||||
|
||||
COUNTER32 CLASS IMPLEMENTATION
|
||||
|
||||
DESIGN + AUTHOR:
|
||||
Peter E Mellquist
|
||||
|
||||
LANGUAGE:
|
||||
ANSI C++
|
||||
|
||||
OPERATING SYSTEMS:
|
||||
MS-Windows Win32
|
||||
BSD UNIX
|
||||
|
||||
DESCRIPTION:
|
||||
Class implementation for SMI Counter32 class.
|
||||
|
||||
|
||||
=====================================================================*/
|
||||
char counter_cpp_version[]="@(#) SNMP++ $Id: counter.cpp,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $";
|
||||
|
||||
#include "counter.h"
|
||||
|
||||
// copy constructor
|
||||
Counter32::Counter32( const Counter32 &c)
|
||||
{ this->smival.value.uNumber = c.smival.value.uNumber;
|
||||
smival.syntax = sNMP_SYNTAX_CNTR32;
|
||||
valid_flag = true;
|
||||
}
|
||||
|
||||
// general assignment from any Value
|
||||
SnmpSyntax& Counter32::operator=(const SnmpSyntax &in_val)
|
||||
{
|
||||
if (this == &in_val) return *this; // handle assignement from itself
|
||||
|
||||
valid_flag = false; // will get set true if really valid
|
||||
if (in_val.valid())
|
||||
{
|
||||
switch (in_val.get_syntax())
|
||||
{
|
||||
case sNMP_SYNTAX_UINT32:
|
||||
// case sNMP_SYNTAX_GAUGE32: .. indistinquishable from UINT32
|
||||
case sNMP_SYNTAX_CNTR32:
|
||||
case sNMP_SYNTAX_TIMETICKS:
|
||||
case sNMP_SYNTAX_INT32: // implied cast int -> uint
|
||||
this->smival.value.uNumber =
|
||||
((Counter32 &)in_val).smival.value.uNumber;
|
||||
valid_flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
145
backend/camembert/libkmsnmp/counter.h
Normal file
145
backend/camembert/libkmsnmp/counter.h
Normal file
@ -0,0 +1,145 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## counter.h
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
/*===================================================================
|
||||
|
||||
Copyright (c) 1999
|
||||
Hewlett-Packard Company
|
||||
|
||||
ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
Permission to use, copy, modify, distribute and/or sell this software
|
||||
and/or its documentation is hereby granted without fee. User agrees
|
||||
to display the above copyright notice and this license notice in all
|
||||
copies of the software and any documentation of the software. User
|
||||
agrees to assume all liability for the use of the software; Hewlett-Packard
|
||||
makes no representations about the suitability of this software for any
|
||||
purpose. It is provided "AS-IS without warranty of any kind,either express
|
||||
or implied. User hereby grants a royalty-free license to any and all
|
||||
derivatives based upon this software code base.
|
||||
|
||||
|
||||
SNMP++ C O U N T E R. H
|
||||
|
||||
COUNTER32 CLASS DEFINITION
|
||||
|
||||
DESIGN + AUTHOR:
|
||||
Peter E Mellquist
|
||||
|
||||
LANGUAGE:
|
||||
ANSI C++
|
||||
|
||||
OPERATING SYSTEMS:
|
||||
MS-Windows Win32
|
||||
BSD UNIX
|
||||
|
||||
DESCRIPTION:
|
||||
Class definition for SMI Counter32 class.
|
||||
|
||||
=====================================================================*/
|
||||
// $Id: counter.h,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $
|
||||
|
||||
#ifndef _COUNTER
|
||||
#define _COUNTER
|
||||
|
||||
#include "integer.h"
|
||||
|
||||
//------------[ Counter32 Class ]------------------------------------------
|
||||
/**
|
||||
* The counter class allows all the functionality of unsigned
|
||||
* integers but is recognized as a distinct SMI type. Counter32
|
||||
* class objects may be set or get into Vb objects.
|
||||
*/
|
||||
class DLLOPT Counter32: public SnmpUInt32
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor to create a Counter object with value zero.
|
||||
*/
|
||||
Counter32() : SnmpUInt32() { smival.syntax = sNMP_SYNTAX_CNTR32; };
|
||||
|
||||
/**
|
||||
* Constructor with a value.
|
||||
*
|
||||
* @param i - unsigned 32 bit value
|
||||
*/
|
||||
Counter32( const unsigned long i) : SnmpUInt32(i)
|
||||
{ smival.syntax = sNMP_SYNTAX_CNTR32; };
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*
|
||||
* @param c - Object to copy from
|
||||
*/
|
||||
Counter32( const Counter32 &c);
|
||||
|
||||
/**
|
||||
* Return the syntax.
|
||||
*
|
||||
* @return Returns always sNMP_SYNTAX_CNTR32
|
||||
*/
|
||||
SmiUINT32 get_syntax() const { return sNMP_SYNTAX_CNTR32; };
|
||||
|
||||
/**
|
||||
* Clone operator.
|
||||
*
|
||||
* @return Pointer to a newly created copy of the object.
|
||||
*/
|
||||
SnmpSyntax *clone() const { return (SnmpSyntax *)new Counter32(*this); };
|
||||
|
||||
/**
|
||||
* Map other SnmpSyntax objects to Counter32.
|
||||
*/
|
||||
SnmpSyntax& operator=(const SnmpSyntax &val);
|
||||
|
||||
/**
|
||||
* Overloaded assignment for Counter32.
|
||||
*
|
||||
* @param uli - new value
|
||||
* @return self reference
|
||||
*/
|
||||
Counter32& operator=(const Counter32 &uli)
|
||||
{ smival.value.uNumber = uli.smival.value.uNumber; return *this;};
|
||||
|
||||
/**
|
||||
* Overloaded assignment for unsigned longs.
|
||||
*
|
||||
* @param i - new value
|
||||
* @return self reference
|
||||
*/
|
||||
Counter32& operator=( const unsigned long i)
|
||||
{ smival.value.uNumber = i; return *this;};
|
||||
|
||||
/**
|
||||
* Casting to unsigned long.
|
||||
*
|
||||
* @return Current value as an unsigned long
|
||||
*/
|
||||
operator unsigned long() { return this->smival.value.uNumber; };
|
||||
};
|
||||
|
||||
#endif // _COUNTER
|
300
backend/camembert/libkmsnmp/ctr64.cpp
Normal file
300
backend/camembert/libkmsnmp/ctr64.cpp
Normal file
@ -0,0 +1,300 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## ctr64.cpp
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
/*===================================================================
|
||||
|
||||
Copyright (c) 1999
|
||||
Hewlett-Packard Company
|
||||
|
||||
ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
Permission to use, copy, modify, distribute and/or sell this software
|
||||
and/or its documentation is hereby granted without fee. User agrees
|
||||
to display the above copyright notice and this license notice in all
|
||||
copies of the software and any documentation of the software. User
|
||||
agrees to assume all liability for the use of the software; Hewlett-Packard
|
||||
makes no representations about the suitability of this software for any
|
||||
purpose. It is provided "AS-IS" without warranty of any kind,either express
|
||||
or implied. User hereby grants a royalty-free license to any and all
|
||||
derivatives based upon this software code base.
|
||||
|
||||
|
||||
C O U N T E R 6 4. C P P
|
||||
|
||||
COUNTER64 CLASS IMPLEMENTATION
|
||||
|
||||
DESIGN + AUTHOR:
|
||||
Peter E. Mellquist
|
||||
|
||||
DESCRIPTION:
|
||||
Implementation for
|
||||
Counter64 ( 64 bit counter class).
|
||||
|
||||
LANGUAGE:
|
||||
ANSI C++
|
||||
|
||||
OPERATING SYSTEM(S):
|
||||
MS-Windows Win32
|
||||
BSD UNIX
|
||||
|
||||
=====================================================================*/
|
||||
char counter64_cpp_version[]="@(#) SNMP++ $Id: ctr64.cpp,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $";
|
||||
|
||||
#include "ctr64.h"
|
||||
#include <stdio.h> // for pretty printing...
|
||||
|
||||
#define MAX32 4294967295u
|
||||
|
||||
//------------------[ constructor with no value ]------------------------
|
||||
Counter64::Counter64()
|
||||
{
|
||||
smival.syntax = sNMP_SYNTAX_CNTR64;
|
||||
smival.value.hNumber.hipart = 0;
|
||||
smival.value.hNumber.lopart = 0;
|
||||
}
|
||||
|
||||
//------------------[ constructor with values ]--------------------------
|
||||
Counter64::Counter64(unsigned long hi, unsigned long lo)
|
||||
{
|
||||
smival.syntax = sNMP_SYNTAX_CNTR64;
|
||||
smival.value.hNumber.hipart = hi;
|
||||
smival.value.hNumber.lopart = lo;
|
||||
}
|
||||
|
||||
//------------------[ constructor with low value only ]------------------
|
||||
Counter64::Counter64(unsigned long lo)
|
||||
{
|
||||
smival.syntax = sNMP_SYNTAX_CNTR64;
|
||||
smival.value.hNumber.hipart = 0;
|
||||
smival.value.hNumber.lopart = lo;
|
||||
}
|
||||
|
||||
//------------------[ copy constructor ]---------------------------------
|
||||
Counter64::Counter64( const Counter64 &ctr64 )
|
||||
{
|
||||
smival.syntax = sNMP_SYNTAX_CNTR64;
|
||||
smival.value.hNumber.hipart = ctr64.high();
|
||||
smival.value.hNumber.lopart = ctr64.low();
|
||||
}
|
||||
|
||||
//------------------[ operator=( const Counter64 &ctr64) ]-------------
|
||||
// assign a ctr64 to a ctr64
|
||||
Counter64& Counter64::operator=(const Counter64 &ctr64)
|
||||
{
|
||||
if (this == &ctr64) return *this; // check for self assignment
|
||||
smival.value.hNumber.hipart = ctr64.high();
|
||||
smival.value.hNumber.lopart = ctr64.low();
|
||||
return *this;
|
||||
}
|
||||
|
||||
//-------------------[ operator=( const unsigned long int i) ]---------
|
||||
// assign a ul to a ctr64, clears the high part
|
||||
// and assugns the low part
|
||||
Counter64& Counter64::operator=( const unsigned long i)
|
||||
{
|
||||
smival.value.hNumber.hipart = 0;
|
||||
smival.value.hNumber.lopart = i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//-----------[ c64_to_ld( Counter64 c64) ]-----------------------------
|
||||
// convert a Counter 64 to a long double
|
||||
long double Counter64::c64_to_ld( const Counter64 &c64)
|
||||
{
|
||||
long double ld = c64.high();
|
||||
ld *= (long double)MAX32 + 1.0l; // gotta be MAX32 + 1 to move it to next pos
|
||||
ld += c64.low();
|
||||
return ld;
|
||||
}
|
||||
|
||||
//-----------[ c64_to_ld( ) ]------------------------------------------
|
||||
long double Counter64::c64_to_ld() const
|
||||
{
|
||||
long double ld = high();
|
||||
ld *= (long double)MAX32 + 1.0l; // gotta be MAX32 + 1 to move it to next pos
|
||||
ld += low();
|
||||
return ld;
|
||||
}
|
||||
|
||||
|
||||
//-----------[ ld_to_c64( long double ld) ]----------------------------
|
||||
// convert a long double to a Counter64
|
||||
Counter64 Counter64::ld_to_c64( const long double &ld)
|
||||
{
|
||||
long double high = MAX32 + 1.0l; // look above
|
||||
unsigned long h = (unsigned long)(ld / high);
|
||||
return Counter64( h, (unsigned long)(ld - (h * high)));
|
||||
}
|
||||
|
||||
//----------[ Counter64::operator+( const Counter64 &c) ]---------------
|
||||
// add two Counter64s
|
||||
Counter64 Counter64::operator+( const Counter64 &c) const
|
||||
{
|
||||
long double ldsum = c64_to_ld() + c.c64_to_ld();
|
||||
return ld_to_c64( ldsum);
|
||||
}
|
||||
|
||||
//------------[ Counter64::operator-( const Counter64 &c) ]-------------
|
||||
// subtract two Counter64s
|
||||
Counter64 Counter64::operator-( const Counter64 &c) const
|
||||
{
|
||||
long double lddiff = c64_to_ld() - c.c64_to_ld();
|
||||
return ld_to_c64( lddiff);
|
||||
}
|
||||
|
||||
//------------[ Counter64::operator*( const Counter64 &c) ]-------------
|
||||
// multiply two Counter64s
|
||||
Counter64 Counter64::operator*( const Counter64 &c) const
|
||||
{
|
||||
long double ldmult = c64_to_ld() * c.c64_to_ld();
|
||||
return ld_to_c64( ldmult);
|
||||
}
|
||||
|
||||
//------------[ Counter64::operator/( const Counter64 &c) ]--------------
|
||||
// divide two Counter64s
|
||||
Counter64 Counter64::operator/( const Counter64 &c) const
|
||||
{
|
||||
long double lddiv = c64_to_ld() / c.c64_to_ld();
|
||||
return ld_to_c64( lddiv);
|
||||
}
|
||||
|
||||
//-------[ overloaded equivlence test ]----------------------------------
|
||||
bool operator==( Counter64 &lhs, Counter64 &rhs)
|
||||
{
|
||||
return (( lhs.high() == rhs.high()) && ( lhs.low() == rhs.low()));
|
||||
}
|
||||
|
||||
//-------[ overloaded not equal test ]-----------------------------------
|
||||
bool operator!=( Counter64 &lhs, Counter64 &rhs)
|
||||
{
|
||||
return (( lhs.high() != rhs.high()) || ( lhs.low() != rhs.low()));
|
||||
}
|
||||
|
||||
//--------[ overloaded less than ]---------------------------------------
|
||||
bool operator<( Counter64 &lhs, Counter64 &rhs)
|
||||
{
|
||||
return ( (lhs.high() < rhs.high()) ||
|
||||
((lhs.high() == rhs.high()) && (lhs.low() < rhs.low())));
|
||||
}
|
||||
|
||||
//---------[ overloaded less than or equal ]-----------------------------
|
||||
bool operator<=( Counter64 &lhs, Counter64 &rhs)
|
||||
{
|
||||
return ( (lhs.high() < rhs.high()) ||
|
||||
((lhs.high() == rhs.high()) && (lhs.low() <= rhs.low())));
|
||||
}
|
||||
|
||||
//---------[ overloaded greater than ]-----------------------------------
|
||||
bool operator>( Counter64 &lhs, Counter64 &rhs)
|
||||
{
|
||||
return ( (lhs.high() > rhs.high()) ||
|
||||
((lhs.high() == rhs.high()) && (lhs.low() > rhs.low())));
|
||||
}
|
||||
|
||||
//----------[ overloaded greater than or equal ]-------------------------
|
||||
bool operator>=( Counter64 &lhs, Counter64 &rhs)
|
||||
{
|
||||
return ( (lhs.high() > rhs.high()) ||
|
||||
((lhs.high() == rhs.high()) && (lhs.low() >= rhs.low())));
|
||||
}
|
||||
|
||||
//----------[ return ASCII format ]-------------------------
|
||||
// TODO: Fix up to do real 64bit decimal value printing...
|
||||
// For now, print > 32-bit values in hex
|
||||
// 26Nov2002 M.Evstiounin - this method is not thread safe!
|
||||
const char *Counter64::get_printable() const
|
||||
{
|
||||
char *buf = PP_CONST_CAST(char*, output_buffer);
|
||||
if ( high() != 0 )
|
||||
sprintf(buf, "0x%lX%08lX", high(), low());
|
||||
else
|
||||
sprintf(buf, "%lu", low());
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
//----------------[ general Value = operator ]---------------------
|
||||
SnmpSyntax& Counter64::operator=(const SnmpSyntax &val)
|
||||
{
|
||||
// protect against assignment from itself
|
||||
if (this == &val) return *this;
|
||||
|
||||
smival.value.hNumber.lopart = 0; // pessimsitic - assume no mapping
|
||||
smival.value.hNumber.hipart = 0;
|
||||
|
||||
// try to make assignment valid
|
||||
if (val.valid())
|
||||
{
|
||||
switch (val.get_syntax())
|
||||
{
|
||||
case sNMP_SYNTAX_CNTR64:
|
||||
smival.value.hNumber.hipart =
|
||||
((Counter64 &)val).smival.value.hNumber.hipart;
|
||||
smival.value.hNumber.lopart =
|
||||
((Counter64 &)val).smival.value.hNumber.lopart;
|
||||
break;
|
||||
|
||||
case sNMP_SYNTAX_CNTR32:
|
||||
case sNMP_SYNTAX_TIMETICKS:
|
||||
case sNMP_SYNTAX_GAUGE32:
|
||||
// case sNMP_SYNTAX_UINT32: .. indistinguishable from GAUGE32
|
||||
case sNMP_SYNTAX_INT32:
|
||||
// take advantage of union...
|
||||
smival.value.hNumber.lopart = ((Counter64 &)val).smival.value.uNumber;
|
||||
smival.value.hNumber.hipart = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Return the space needed for serialization
|
||||
int Counter64::get_asn1_length() const
|
||||
{
|
||||
if (smival.value.hNumber.hipart == 0)
|
||||
{
|
||||
if (smival.value.hNumber.lopart < 0x80)
|
||||
return 3;
|
||||
else if (smival.value.hNumber.lopart < 0x8000)
|
||||
return 4;
|
||||
else if (smival.value.hNumber.lopart < 0x800000)
|
||||
return 5;
|
||||
else if (smival.value.hNumber.lopart < 0x80000000)
|
||||
return 6;
|
||||
return 7;
|
||||
}
|
||||
if (smival.value.hNumber.hipart < 0x80)
|
||||
return 7;
|
||||
else if (smival.value.hNumber.hipart < 0x8000)
|
||||
return 8;
|
||||
else if (smival.value.hNumber.hipart < 0x800000)
|
||||
return 9;
|
||||
else if (smival.value.hNumber.hipart < 0x80000000)
|
||||
return 10;
|
||||
return 11;
|
||||
}
|
318
backend/camembert/libkmsnmp/ctr64.h
Normal file
318
backend/camembert/libkmsnmp/ctr64.h
Normal file
@ -0,0 +1,318 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## ctr64.h
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
/*===================================================================
|
||||
|
||||
Copyright (c) 1999
|
||||
Hewlett-Packard Company
|
||||
|
||||
ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
Permission to use, copy, modify, distribute and/or sell this software
|
||||
and/or its documentation is hereby granted without fee. User agrees
|
||||
to display the above copyright notice and this license notice in all
|
||||
copies of the software and any documentation of the software. User
|
||||
agrees to assume all liability for the use of the software; Hewlett-Packard
|
||||
makes no representations about the suitability of this software for any
|
||||
purpose. It is provided "AS-IS without warranty of any kind,either express
|
||||
or implied. User hereby grants a royalty-free license to any and all
|
||||
derivatives based upon this software code base.
|
||||
|
||||
|
||||
SNMP++ C O U N T E R 6 4 . H
|
||||
|
||||
COUNTER64 CLASSES DEFINITION
|
||||
|
||||
DESIGN + AUTHOR:
|
||||
Peter E Mellquist
|
||||
|
||||
LANGUAGE:
|
||||
ANSI C++
|
||||
|
||||
OPERATING SYSTEMS:
|
||||
MS-Windows Win32
|
||||
BSD UNIX
|
||||
|
||||
DESCRIPTION:
|
||||
SNMP Counter64 class definition.
|
||||
|
||||
=====================================================================*/
|
||||
// $Id: ctr64.h,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $
|
||||
|
||||
#ifndef _CTR64
|
||||
#define _CTR64
|
||||
|
||||
#include "smival.h"
|
||||
|
||||
#define CTR64OUTBUF 30 //!< maximum ascii string for a 64-bit counter
|
||||
|
||||
|
||||
//---------[ 64 bit Counter Class ]--------------------------------
|
||||
/**
|
||||
* Counter64 Class encapsulates two unsigned integers into a
|
||||
* a single entity. This type has is available in SNMPv2 but
|
||||
* may be used anywhere where needed.
|
||||
*/
|
||||
class DLLOPT Counter64: public SnmpSyntax
|
||||
{
|
||||
public:
|
||||
|
||||
//-----------[ Constructors and Destrucotr ]----------------------
|
||||
|
||||
/**
|
||||
* Constructs a valid Couter64 with value 0.
|
||||
*/
|
||||
Counter64();
|
||||
|
||||
/**
|
||||
* Constructs a valid Counter64 with the given value as the lower 32 bits.
|
||||
*
|
||||
* @param lo - value (0..MAX_UINT32)
|
||||
*/
|
||||
Counter64(unsigned long lo);
|
||||
|
||||
/**
|
||||
* Constructs a valid Counter64 with the given values.
|
||||
*
|
||||
* @param hi - value for the high 32 bits (0..MAX_UINT32)
|
||||
* @param lo - value for the low 32 bits (0..MAX_UINT32)
|
||||
*/
|
||||
Counter64(unsigned long hi, unsigned long lo);
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*
|
||||
* @param ctr64 - value
|
||||
*/
|
||||
Counter64(const Counter64 &ctr64);
|
||||
|
||||
/**
|
||||
* Destructor (ensure that SnmpSyntax::~SnmpSyntax() is overridden).
|
||||
*/
|
||||
~Counter64() {};
|
||||
|
||||
//-----------[ conversion from/to long double ]----------------------
|
||||
|
||||
/**
|
||||
* Get the value of the object as long double.
|
||||
*
|
||||
* @param c64 - The Counter64 object whose value should be returned
|
||||
* @return value as a long double
|
||||
*/
|
||||
static long double c64_to_ld( const Counter64 &c64);
|
||||
|
||||
/**
|
||||
* Get the value of this object as long double.
|
||||
*
|
||||
* @return value as a long double
|
||||
*/
|
||||
long double c64_to_ld() const;
|
||||
|
||||
/**
|
||||
* Convert a long double to a Counter64.
|
||||
*
|
||||
* @param ld - the value to convert
|
||||
* @return A Counter64 object with the value of the param ld.
|
||||
*/
|
||||
static Counter64 ld_to_c64( const long double &ld);
|
||||
|
||||
//-----------[ get/set using 32 bit variables ]----------------------
|
||||
|
||||
/**
|
||||
* Get the high 32 bit part.
|
||||
*
|
||||
* @return The high part of the Counter64
|
||||
*/
|
||||
unsigned long high() const { return smival.value.hNumber.hipart; };
|
||||
|
||||
/**
|
||||
* Get the low 32 bit part.
|
||||
*
|
||||
* @return The low part of the Counter64
|
||||
*/
|
||||
unsigned long low() const { return smival.value.hNumber.lopart; };
|
||||
|
||||
/**
|
||||
* Set the high 32 bit part. The low part will stay unchanged.
|
||||
*
|
||||
* @param h - The new high part of the Counter64
|
||||
*/
|
||||
void set_high(const unsigned long h) { smival.value.hNumber.hipart = h; };
|
||||
|
||||
/**
|
||||
* Set the low 32 bit part. The high part will stay unchanged.
|
||||
*
|
||||
* @param l - The new low part of the Counter64
|
||||
*/
|
||||
void set_low(const unsigned long l) { smival.value.hNumber.lopart = l; };
|
||||
|
||||
|
||||
//-----------[ SnmpSyntax methods ]----------------------
|
||||
|
||||
/**
|
||||
* Get a printable ASCII string representing the current value.
|
||||
*
|
||||
* @note The returned string is valid as long as the object is not
|
||||
* modified.
|
||||
*
|
||||
* @return Null terminated string.
|
||||
*/
|
||||
const char *get_printable() const;
|
||||
|
||||
/**
|
||||
* Get the Syntax of the object.
|
||||
*
|
||||
* @return This method always returns sNMP_SYNTAX_CNTR64.
|
||||
*/
|
||||
SmiUINT32 get_syntax() const { return sNMP_SYNTAX_CNTR64; };
|
||||
|
||||
/**
|
||||
* Clone the object.
|
||||
*
|
||||
* @return A cloned Counter64 object allocated through new.
|
||||
*/
|
||||
SnmpSyntax *clone() const { return (SnmpSyntax *) new Counter64(*this); };
|
||||
|
||||
/**
|
||||
* Overloaded assignement operator.
|
||||
*
|
||||
* @param val - Try to map the given value to a Counter64 and assign it
|
||||
* @return Always *this with the new value.
|
||||
*/
|
||||
SnmpSyntax& operator=(const SnmpSyntax &val);
|
||||
|
||||
/**
|
||||
* Return validity of the object.
|
||||
*
|
||||
* @return Always true
|
||||
*/
|
||||
bool valid() const { return true; };
|
||||
|
||||
/**
|
||||
* Return the space needed for serialization.
|
||||
*
|
||||
* @return The needed space that depends on the current value.
|
||||
*/
|
||||
int get_asn1_length() const;
|
||||
|
||||
|
||||
//-----------[ overloaded operators ]----------------------
|
||||
|
||||
/**
|
||||
* Assign a Counter64 to a Counter64.
|
||||
*/
|
||||
Counter64& operator=( const Counter64 &ctr64);
|
||||
|
||||
/**
|
||||
* Assign a unsigned long to a Counter64.
|
||||
*
|
||||
* @param i - The new low part. The high part is cleared.
|
||||
*/
|
||||
Counter64& operator=( const unsigned long i);
|
||||
|
||||
/**
|
||||
* Add two Counter64.
|
||||
*/
|
||||
Counter64 operator+( const Counter64 &c) const;
|
||||
|
||||
/**
|
||||
* Add a unsigned long and a Counter64.
|
||||
*/
|
||||
DLLOPT friend Counter64 operator+( unsigned long ul, const Counter64 &c64)
|
||||
{ return Counter64( ul) + c64; };
|
||||
|
||||
/**
|
||||
* Subtract two Counter64.
|
||||
*/
|
||||
Counter64 operator-( const Counter64 &c) const;
|
||||
|
||||
/**
|
||||
* Subtract a unsigned long and a Counter64.
|
||||
*/
|
||||
DLLOPT friend Counter64 operator-( unsigned long ul, const Counter64 &c64)
|
||||
{ return Counter64( ul) - c64; };
|
||||
|
||||
/**
|
||||
* Multiply two Counter64.
|
||||
*/
|
||||
Counter64 operator*( const Counter64 &c) const;
|
||||
|
||||
/**
|
||||
* Multiply a unsigned long and a Counter64.
|
||||
*/
|
||||
DLLOPT friend Counter64 operator*( unsigned long ul, const Counter64 &c64)
|
||||
{ return Counter64( ul) * c64; };
|
||||
|
||||
/**
|
||||
* Divide two Counter64.
|
||||
*/
|
||||
Counter64 operator/( const Counter64 &c) const;
|
||||
|
||||
/**
|
||||
* Divide a unsigned long and a Counter64.
|
||||
*/
|
||||
DLLOPT friend Counter64 operator/( unsigned long ul, const Counter64 &c64)
|
||||
{ return Counter64( ul) / c64; };
|
||||
|
||||
//-------[ overloaded comparison operators ]--------------
|
||||
|
||||
/**
|
||||
* Equal operator for two Cunter64.
|
||||
*/
|
||||
DLLOPT friend bool operator==( Counter64 &lhs, Counter64 &rhs);
|
||||
|
||||
/**
|
||||
* Not equal operator for two Cunter64.
|
||||
*/
|
||||
DLLOPT friend bool operator!=( Counter64 &lhs, Counter64 &rhs);
|
||||
|
||||
/**
|
||||
* Less than operator for two Cunter64.
|
||||
*/
|
||||
DLLOPT friend bool operator<( Counter64 &lhs, Counter64 &rhs);
|
||||
|
||||
/**
|
||||
* Less than or equal operator for two Cunter64.
|
||||
*/
|
||||
DLLOPT friend bool operator<=( Counter64 &lhs, Counter64 &rhs);
|
||||
|
||||
/**
|
||||
* Greater than operator for two Cunter64.
|
||||
*/
|
||||
DLLOPT friend bool operator>( Counter64 &lhs, Counter64 &rhs);
|
||||
|
||||
/**
|
||||
* Greater than or equal operator for two Cunter64.
|
||||
*/
|
||||
DLLOPT friend bool operator>=( Counter64 &lhs, Counter64 &rhs);
|
||||
|
||||
private:
|
||||
/*mutable*/ char output_buffer[CTR64OUTBUF];
|
||||
|
||||
};
|
||||
|
||||
#endif
|
75
backend/camembert/libkmsnmp/gauge.cpp
Normal file
75
backend/camembert/libkmsnmp/gauge.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## gauge.cpp
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
/*===================================================================
|
||||
|
||||
Copyright (c) 1999
|
||||
Hewlett-Packard Company
|
||||
|
||||
ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
Permission to use, copy, modify, distribute and/or sell this software
|
||||
and/or its documentation is hereby granted without fee. User agrees
|
||||
to display the above copyright notice and this license notice in all
|
||||
copies of the software and any documentation of the software. User
|
||||
agrees to assume all liability for the use of the software; Hewlett-Packard
|
||||
makes no representations about the suitability of this software for any
|
||||
purpose. It is provided "AS-IS" without warranty of any kind,either express
|
||||
or implied. User hereby grants a royalty-free license to any and all
|
||||
derivatives based upon this software code base.
|
||||
|
||||
|
||||
|
||||
G A U G E. C P P
|
||||
|
||||
GAUGE32 CLASS IMPLEMTATION
|
||||
|
||||
DESIGN + AUTHOR:
|
||||
Peter E Mellquist
|
||||
|
||||
LANGUAGE:
|
||||
ANSI C++
|
||||
|
||||
OPERATING SYSTEMS:
|
||||
MS-Windows Win32
|
||||
BSD UNIX
|
||||
|
||||
DESCRIPTION:
|
||||
Class implemtation for SMI Gauge32 class.
|
||||
|
||||
=====================================================================*/
|
||||
char gauge_cpp_version[]="@(#) SNMP++ $Id: gauge.cpp,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $";
|
||||
|
||||
#include "gauge.h" // header file for gauge class
|
||||
|
||||
// copy constructor
|
||||
Gauge32::Gauge32(const Gauge32 &g32)
|
||||
: SnmpUInt32()
|
||||
{
|
||||
smival.value.uNumber = g32.smival.value.uNumber;
|
||||
smival.syntax = sNMP_SYNTAX_GAUGE32;
|
||||
}
|
149
backend/camembert/libkmsnmp/gauge.h
Normal file
149
backend/camembert/libkmsnmp/gauge.h
Normal file
@ -0,0 +1,149 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## gauge.h
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
/*===================================================================
|
||||
|
||||
Copyright (c) 1999
|
||||
Hewlett-Packard Company
|
||||
|
||||
ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
Permission to use, copy, modify, distribute and/or sell this software
|
||||
and/or its documentation is hereby granted without fee. User agrees
|
||||
to display the above copyright notice and this license notice in all
|
||||
copies of the software and any documentation of the software. User
|
||||
agrees to assume all liability for the use of the software; Hewlett-Packard
|
||||
makes no representations about the suitability of this software for any
|
||||
purpose. It is provided "AS-IS without warranty of any kind,either express
|
||||
or implied. User hereby grants a royalty-free license to any and all
|
||||
derivatives based upon this software code base.
|
||||
|
||||
|
||||
SNMP++ G A U G E. H
|
||||
|
||||
GAUGE32 CLASS DEFINITION
|
||||
|
||||
DESIGN + AUTHOR:
|
||||
Peter E Mellquist
|
||||
|
||||
LANGUAGE:
|
||||
ANSI C++
|
||||
|
||||
OPERATING SYSTEMS:
|
||||
MS-Windows Win32
|
||||
BSD UNIX
|
||||
|
||||
DESCRIPTION:
|
||||
Class definition for SMI Gauge32 class.
|
||||
|
||||
=====================================================================*/
|
||||
// $Id: gauge.h,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $
|
||||
|
||||
#ifndef _GAUGE_H_
|
||||
#define _GAUGE_H_
|
||||
|
||||
#include "integer.h"
|
||||
|
||||
//------------[ Gauge32 Class ]------------------------------------------
|
||||
/**
|
||||
* The gauge class allows all the functionality of unsigned integers
|
||||
* but is recognized as a distinct SMI type. Gauge32 objects may be
|
||||
* set or get into Vb objects.
|
||||
*/
|
||||
class DLLOPT Gauge32: public SnmpUInt32
|
||||
{
|
||||
public:
|
||||
|
||||
//-----------[ Constructors and Destrucotr ]----------------------
|
||||
|
||||
/**
|
||||
* Constructs a valid Gauge32 with value 0.
|
||||
*/
|
||||
Gauge32() : SnmpUInt32() { smival.syntax = sNMP_SYNTAX_GAUGE32; };
|
||||
|
||||
/**
|
||||
* Constructs a valid Gauge32 with the given value.
|
||||
*
|
||||
* @param ul - value (0..MAX_UINT32)
|
||||
*/
|
||||
Gauge32(const unsigned long ul) : SnmpUInt32(ul)
|
||||
{ smival.syntax = sNMP_SYNTAX_GAUGE32; };
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*
|
||||
* @param g32 - value
|
||||
*/
|
||||
Gauge32(const Gauge32 &g32);
|
||||
|
||||
/**
|
||||
* Destructor (ensure that SnmpUInt32::~SnmpUInt32() is overridden).
|
||||
*/
|
||||
~Gauge32() {};
|
||||
|
||||
//-----------[ SnmpSyntax methods ]----------------------
|
||||
|
||||
/**
|
||||
* Get the Syntax of the object.
|
||||
*
|
||||
* @return This method always returns sNMP_SYNTAX_GAUGE32.
|
||||
*/
|
||||
SmiUINT32 get_syntax() const { return sNMP_SYNTAX_GAUGE32; };
|
||||
|
||||
/**
|
||||
* Clone the object.
|
||||
*
|
||||
* @return A cloned Gauge32 object allocated through new.
|
||||
*/
|
||||
SnmpSyntax *clone() const { return (SnmpSyntax *) new Gauge32(*this); };
|
||||
|
||||
//-----------[ Overload some operators ]----------------------
|
||||
|
||||
/**
|
||||
* Assign a Gauge32 to a Gauge32.
|
||||
*/
|
||||
Gauge32& operator=(const Gauge32 &uli)
|
||||
{ smival.value.uNumber = uli.smival.value.uNumber; return *this;};
|
||||
|
||||
/**
|
||||
* Assign a unsigned long to a Gauge32.
|
||||
*
|
||||
* @param ul - New value
|
||||
*/
|
||||
Gauge32& operator=(const unsigned long ul)
|
||||
{ smival.value.uNumber = ul; return *this; };
|
||||
|
||||
// otherwise, behave like an unsigned int
|
||||
/**
|
||||
* Cast a Gauge32 to unsigned long.
|
||||
*
|
||||
* @return Current value as unsigned long.
|
||||
*/
|
||||
operator unsigned long() { return smival.value.uNumber; };
|
||||
|
||||
};
|
||||
#endif // _GAUGE_H_
|
245
backend/camembert/libkmsnmp/integer.cpp
Normal file
245
backend/camembert/libkmsnmp/integer.cpp
Normal file
@ -0,0 +1,245 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## integer.cpp
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
/*===================================================================
|
||||
|
||||
Copyright (c) 1999
|
||||
Hewlett-Packard Company
|
||||
|
||||
ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
Permission to use, copy, modify, distribute and/or sell this software
|
||||
and/or its documentation is hereby granted without fee. User agrees
|
||||
to display the above copyright notice and this license notice in all
|
||||
copies of the software and any documentation of the software. User
|
||||
agrees to assume all liability for the use of the software; Hewlett-Packard
|
||||
makes no representations about the suitability of this software for any
|
||||
purpose. It is provided "AS-IS" without warranty of any kind,either express
|
||||
or implied. User hereby grants a royalty-free license to any and all
|
||||
derivatives based upon this software code base.
|
||||
|
||||
|
||||
|
||||
I N T E G E R . C P P
|
||||
|
||||
SMI INTEGER CLASS IMPLEMTATION
|
||||
|
||||
DESIGN + AUTHOR: Jeff Meyer
|
||||
|
||||
LANGUAGE:
|
||||
ANSI C++
|
||||
|
||||
OPERATING SYSTEMS:
|
||||
MS-Windows Win32
|
||||
BSD UNIX
|
||||
|
||||
DESCRIPTION:
|
||||
Class implemtation for SMI Integer classes.
|
||||
|
||||
=====================================================================*/
|
||||
char integer_cpp_version[]="#(@) SNMP++ $Id: integer.cpp,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $";
|
||||
|
||||
#include "stdio.h" // for sprintf()
|
||||
#include "integer.h" // header file for gauge class
|
||||
|
||||
// constructor no value
|
||||
SnmpUInt32::SnmpUInt32()
|
||||
: valid_flag(true)
|
||||
{
|
||||
smival.value.uNumber = 0;
|
||||
smival.syntax = sNMP_SYNTAX_UINT32;
|
||||
}
|
||||
|
||||
// constructor with value
|
||||
SnmpUInt32::SnmpUInt32 (const unsigned long i)
|
||||
: valid_flag(true)
|
||||
{
|
||||
smival.value.uNumber = i;
|
||||
smival.syntax = sNMP_SYNTAX_UINT32;
|
||||
}
|
||||
|
||||
// copy constructor
|
||||
SnmpUInt32::SnmpUInt32(const SnmpUInt32 &c)
|
||||
: valid_flag(true)
|
||||
{
|
||||
smival.value.uNumber=c.smival.value.uNumber;
|
||||
smival.syntax = sNMP_SYNTAX_UINT32;
|
||||
}
|
||||
|
||||
// overloaded assignment
|
||||
SnmpUInt32& SnmpUInt32::operator=(const unsigned long i)
|
||||
{
|
||||
smival.value.uNumber = i;
|
||||
valid_flag = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// general assignment from any Value
|
||||
SnmpSyntax& SnmpUInt32::operator=(const SnmpSyntax &in_val)
|
||||
{
|
||||
if (this == &in_val) return *this; // handle assignement from itself
|
||||
|
||||
valid_flag = false; // will get set true if really valid
|
||||
if (in_val.valid())
|
||||
{
|
||||
switch (in_val.get_syntax())
|
||||
{
|
||||
case sNMP_SYNTAX_UINT32:
|
||||
// case sNMP_SYNTAX_GAUGE32: .. indistinquishable from UINT32
|
||||
case sNMP_SYNTAX_CNTR32:
|
||||
case sNMP_SYNTAX_TIMETICKS:
|
||||
case sNMP_SYNTAX_INT32: // implied cast int -> uint
|
||||
smival.value.uNumber =
|
||||
((SnmpUInt32 &)in_val).smival.value.uNumber;
|
||||
valid_flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// overloaded assignment
|
||||
SnmpUInt32& SnmpUInt32::operator=(const SnmpUInt32 &uli)
|
||||
{
|
||||
if (this == &uli) return *this; // check for self assignment
|
||||
|
||||
smival.value.uNumber = uli.smival.value.uNumber;
|
||||
valid_flag = uli.valid_flag;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ASCII format return
|
||||
const char *SnmpUInt32::get_printable() const
|
||||
{
|
||||
char *buf = PP_CONST_CAST(char*, output_buffer);
|
||||
sprintf(buf, "%lu", smival.value.uNumber);
|
||||
return buf;
|
||||
}
|
||||
|
||||
// Return the space needed for serialization
|
||||
int SnmpUInt32::get_asn1_length() const
|
||||
{
|
||||
if (smival.value.uNumber < 0x80)
|
||||
return 3;
|
||||
else if (smival.value.uNumber < 0x8000)
|
||||
return 4;
|
||||
else if (smival.value.uNumber < 0x800000)
|
||||
return 5;
|
||||
else if (smival.value.uNumber < 0x80000000)
|
||||
return 6;
|
||||
return 7;
|
||||
}
|
||||
|
||||
//====================================================================
|
||||
// INT 32 Implementation
|
||||
//====================================================================
|
||||
|
||||
// constructor no value
|
||||
SnmpInt32::SnmpInt32() : valid_flag(true)
|
||||
{
|
||||
smival.value.sNumber = 0;
|
||||
smival.syntax = sNMP_SYNTAX_INT32;
|
||||
}
|
||||
|
||||
// constructor with value
|
||||
SnmpInt32::SnmpInt32(const long i) : valid_flag(true)
|
||||
{
|
||||
smival.value.sNumber = i;
|
||||
smival.syntax = sNMP_SYNTAX_INT32;
|
||||
}
|
||||
|
||||
// constructor with value
|
||||
SnmpInt32::SnmpInt32(const SnmpInt32 &c) : valid_flag(true)
|
||||
{
|
||||
smival.value.sNumber = c.smival.value.sNumber;
|
||||
smival.syntax = sNMP_SYNTAX_INT32;
|
||||
}
|
||||
|
||||
// overloaded assignment
|
||||
SnmpInt32& SnmpInt32::operator=(const long i)
|
||||
{
|
||||
smival.value.sNumber = (unsigned long) i;
|
||||
valid_flag = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// overloaded assignment
|
||||
SnmpInt32& SnmpInt32::operator=(const SnmpInt32 &uli)
|
||||
{
|
||||
if (this == &uli) return *this; // check for self assignment
|
||||
|
||||
smival.value.sNumber = uli.smival.value.sNumber;
|
||||
valid_flag = uli.valid_flag;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// general assignment from any Value
|
||||
SnmpSyntax& SnmpInt32::operator=(const SnmpSyntax &in_val)
|
||||
{
|
||||
if (this == &in_val) return *this; // handle assignement from itself
|
||||
|
||||
valid_flag = false; // will get set true if really valid
|
||||
if (in_val.valid())
|
||||
{
|
||||
switch (in_val.get_syntax())
|
||||
{
|
||||
case sNMP_SYNTAX_INT32:
|
||||
case sNMP_SYNTAX_UINT32: // implied cast uint -> int
|
||||
// case sNMP_SYNTAX_GAUGE32: .. indistinquishable from UINT32
|
||||
case sNMP_SYNTAX_CNTR32: // implied cast uint -> int
|
||||
case sNMP_SYNTAX_TIMETICKS: // implied cast uint -> int
|
||||
smival.value.sNumber =
|
||||
((SnmpInt32 &)in_val).smival.value.sNumber;
|
||||
valid_flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ASCII format return
|
||||
const char *SnmpInt32::get_printable() const
|
||||
{
|
||||
char *buf = PP_CONST_CAST(char*, output_buffer);
|
||||
sprintf(buf, "%ld", (long)smival.value.sNumber);
|
||||
return buf;
|
||||
}
|
||||
|
||||
// Return the space needed for serialization
|
||||
int SnmpInt32::get_asn1_length() const
|
||||
{
|
||||
if ((smival.value.sNumber < 0x80) &&
|
||||
(smival.value.sNumber >= -0x80))
|
||||
return 3;
|
||||
else if ((smival.value.sNumber < 0x8000) &&
|
||||
(smival.value.sNumber >= -0x8000))
|
||||
return 4;
|
||||
else if ((smival.value.sNumber < 0x800000) &&
|
||||
(smival.value.sNumber >= -0x800000))
|
||||
return 5;
|
||||
return 6;
|
||||
}
|
271
backend/camembert/libkmsnmp/integer.h
Normal file
271
backend/camembert/libkmsnmp/integer.h
Normal file
@ -0,0 +1,271 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## integer.h
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
/*===================================================================
|
||||
|
||||
Copyright (c) 1999
|
||||
Hewlett-Packard Company
|
||||
|
||||
ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
Permission to use, copy, modify, distribute and/or sell this software
|
||||
and/or its documentation is hereby granted without fee. User agrees
|
||||
to display the above copyright notice and this license notice in all
|
||||
copies of the software and any documentation of the software. User
|
||||
agrees to assume all liability for the use of the software; Hewlett-Packard
|
||||
makes no representations about the suitability of this software for any
|
||||
purpose. It is provided "AS-IS without warranty of any kind,either express
|
||||
or implied. User hereby grants a royalty-free license to any and all
|
||||
derivatives based upon this software code base.
|
||||
|
||||
|
||||
SNMP++ I N T E G E R. H
|
||||
|
||||
INTEGER CLASS DEFINITION
|
||||
|
||||
DESIGN + AUTHOR:
|
||||
Jeff Meyer
|
||||
|
||||
LANGUAGE:
|
||||
ANSI C++
|
||||
|
||||
OPERATING SYSTEMS:
|
||||
MS-Windows Win32
|
||||
BSD UNIX
|
||||
|
||||
DESCRIPTION:
|
||||
Class definition for Integer classes.
|
||||
|
||||
=====================================================================*/
|
||||
// $Id: integer.h,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $
|
||||
|
||||
#ifndef _SNMPINTEGER
|
||||
#define _SNMPINTEGER
|
||||
|
||||
#include "smival.h"
|
||||
|
||||
#define INTOUTBUF 15 // largest ASCII formatted integer
|
||||
|
||||
//------------[ Integer Classes ]------------------------------------------
|
||||
|
||||
/**
|
||||
* 32 bit unsigned integer class.
|
||||
*
|
||||
* The integer class allows all the functionality of the various
|
||||
* integers but is contained in a Value object for consistency
|
||||
* among the various types.
|
||||
* class objects may be set or get into Vb objects.
|
||||
*/
|
||||
class DLLOPT SnmpUInt32 : public SnmpSyntax
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor, sets value to zero.
|
||||
*/
|
||||
SnmpUInt32();
|
||||
|
||||
/**
|
||||
* Constructor with value.
|
||||
*
|
||||
* @param i - initial value
|
||||
*/
|
||||
SnmpUInt32(const unsigned long i);
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*
|
||||
* @param c - initial value
|
||||
*/
|
||||
SnmpUInt32( const SnmpUInt32 &c);
|
||||
|
||||
/**
|
||||
* Destructor (ensure that SnmpSyntax::~SnmpSyntax() is overridden).
|
||||
*/
|
||||
virtual ~SnmpUInt32() {};
|
||||
|
||||
/**
|
||||
* Return the syntax.
|
||||
*
|
||||
* @return This method always returns sNMP_SYNTAX_UINT32.
|
||||
*/
|
||||
virtual SmiUINT32 get_syntax() const { return sNMP_SYNTAX_UINT32; };
|
||||
|
||||
/**
|
||||
* Overloaded assignment for unsigned longs.
|
||||
*
|
||||
* @param i - new value
|
||||
* @return self reference
|
||||
*/
|
||||
SnmpUInt32& operator=(const unsigned long i);
|
||||
|
||||
/**
|
||||
* Overloaded assignment for SnmpUInt32.
|
||||
*
|
||||
* @param uli - new value
|
||||
* @return self reference
|
||||
*/
|
||||
SnmpUInt32& operator=(const SnmpUInt32 &uli);
|
||||
|
||||
/**
|
||||
* Map other SnmpSyntax objects to SnmpUInt32.
|
||||
*/
|
||||
SnmpSyntax& operator=(const SnmpSyntax &val);
|
||||
|
||||
/**
|
||||
* Behave like an unsigned long.
|
||||
*
|
||||
* @return value as unsigned long
|
||||
*/
|
||||
operator unsigned long() { return smival.value.uNumber; };
|
||||
|
||||
/**
|
||||
* Get a printable ASCII value.
|
||||
*/
|
||||
virtual const char *get_printable() const;
|
||||
|
||||
/**
|
||||
* Clone operator.
|
||||
*
|
||||
* @return Pointer to a newly created copy of the object.
|
||||
*/
|
||||
virtual SnmpSyntax *clone() const
|
||||
{ return (SnmpSyntax *)new SnmpUInt32(*this); };
|
||||
|
||||
/**
|
||||
* Return validity of the object.
|
||||
* An SnmpUInt32 will only be invalid after a failed asignment
|
||||
* of another SnmpSyntax object.
|
||||
*/
|
||||
bool valid() const { return valid_flag; };
|
||||
|
||||
/**
|
||||
* Return the space needed for serialization.
|
||||
*/
|
||||
int get_asn1_length() const;
|
||||
|
||||
protected:
|
||||
bool valid_flag;
|
||||
/*mutable*/ char output_buffer[INTOUTBUF];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 32 bit signed integer class.
|
||||
*/
|
||||
class DLLOPT SnmpInt32 : public SnmpSyntax
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor, sets value to zero.
|
||||
*/
|
||||
SnmpInt32();
|
||||
|
||||
/**
|
||||
* Constructor with value.
|
||||
*
|
||||
* @param i - initial value
|
||||
*/
|
||||
SnmpInt32 (const long i);
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*
|
||||
* @param c - initial value
|
||||
*/
|
||||
SnmpInt32 (const SnmpInt32 &c);
|
||||
|
||||
/**
|
||||
* Destructor (ensure that SnmpSyntax::~SnmpSyntax() is overridden).
|
||||
*/
|
||||
virtual ~SnmpInt32() {};
|
||||
|
||||
/**
|
||||
* Return the syntax.
|
||||
*
|
||||
* @return This method always returns sNMP_SYNTAX_INT32.
|
||||
*/
|
||||
virtual SmiUINT32 get_syntax() const { return sNMP_SYNTAX_INT32; };
|
||||
|
||||
/**
|
||||
* Overloaded assignment for longs.
|
||||
*
|
||||
* @param i - new value
|
||||
* @return self reference
|
||||
*/
|
||||
SnmpInt32& operator=(const long i);
|
||||
|
||||
/**
|
||||
* Overloaded assignment for SnmpInt32.
|
||||
*
|
||||
* @param li - new value
|
||||
* @return self reference
|
||||
*/
|
||||
SnmpInt32& operator=(const SnmpInt32 &li);
|
||||
|
||||
/**
|
||||
* Map other SnmpSyntax objects to SnmpInt32.
|
||||
*/
|
||||
SnmpSyntax& operator=(const SnmpSyntax &val);
|
||||
|
||||
/**
|
||||
* Behave like an long.
|
||||
*
|
||||
* @return value as long
|
||||
*/
|
||||
operator long() { return (long) smival.value.sNumber; };
|
||||
|
||||
/**
|
||||
* Get a printable ASCII value.
|
||||
*/
|
||||
const char *get_printable() const;
|
||||
|
||||
/**
|
||||
* Clone operator.
|
||||
*
|
||||
* @return Pointer to a newly created copy of the object.
|
||||
*/
|
||||
SnmpSyntax *clone() const { return ( SnmpSyntax *)new SnmpInt32(*this); };
|
||||
|
||||
/**
|
||||
* Return validity of the object.
|
||||
* An SnmpUInt32 will only be invalid after a failed asignment
|
||||
* of another SnmpSyntax object.
|
||||
*/
|
||||
bool valid() const { return valid_flag; };
|
||||
|
||||
/**
|
||||
* Return the space needed for serialization.
|
||||
*/
|
||||
int get_asn1_length() const;
|
||||
|
||||
protected:
|
||||
bool valid_flag;
|
||||
/*mutable*/ char output_buffer[INTOUTBUF];
|
||||
};
|
||||
#endif
|
BIN
backend/camembert/libkmsnmp/libkmsnmp.a
Normal file
BIN
backend/camembert/libkmsnmp/libkmsnmp.a
Normal file
Binary file not shown.
544
backend/camembert/libkmsnmp/mp_v3.h
Normal file
544
backend/camembert/libkmsnmp/mp_v3.h
Normal file
@ -0,0 +1,544 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## mp_v3.h
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
|
||||
// $Id: mp_v3.h,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $
|
||||
|
||||
#ifndef _MP_V3
|
||||
#define _MP_V3
|
||||
|
||||
#include "config_snmp_pp.h"
|
||||
|
||||
#ifdef _SNMPv3
|
||||
|
||||
#include "reentrant.h"
|
||||
#include "target.h"
|
||||
|
||||
class Pdu;
|
||||
class OctetStr;
|
||||
|
||||
#define MAX_HOST_NAME_LENGTH 128
|
||||
|
||||
#define oidMPDGroup "1.3.6.1.6.3.11.2.1"
|
||||
#define oidSnmpUnknownSecurityModels "1.3.6.1.6.3.11.2.1.1.0"
|
||||
#define oidSnmpInvalidMsgs "1.3.6.1.6.3.11.2.1.2.0"
|
||||
#define oidSnmpUnknownPDUHandlers "1.3.6.1.6.3.11.2.1.3.0"
|
||||
|
||||
/** @name Error codes of the v3MP */
|
||||
//@{
|
||||
#define SNMPv3_MP_ERROR -1400
|
||||
#define SNMPv3_MP_OK -1401
|
||||
#define SNMPv3_MP_UNSUPPORTED_SECURITY_MODEL -1402
|
||||
#define SNMPv3_MP_NOT_IN_TIME_WINDOW -1403
|
||||
#define SNMPv3_MP_DOUBLED_MESSAGE -1404
|
||||
#define SNMPv3_MP_INVALID_MESSAGE -1405
|
||||
#define SNMPv3_MP_INVALID_ENGINEID -1406
|
||||
#define SNMPv3_MP_NOT_INITIALIZED -1407
|
||||
#define SNMPv3_MP_PARSE_ERROR -1408
|
||||
#define SNMPv3_MP_UNKNOWN_MSGID -1409
|
||||
#define SNMPv3_MP_MATCH_ERROR -1410
|
||||
#define SNMPv3_MP_COMMUNITY_ERROR -1411
|
||||
#define SNMPv3_MP_WRONG_USER_NAME -1412
|
||||
#define SNMPv3_MP_BUILD_ERROR -1413
|
||||
#define SNMPv3_MP_USM_ERROR -1414
|
||||
#define SNMPv3_MP_UNKNOWN_PDU_HANDLERS -1415
|
||||
#define SNMPv3_MP_UNAVAILABLE_CONTEXT -1416
|
||||
#define SNMPv3_MP_UNKNOWN_CONTEXT -1417
|
||||
#define SNMPv3_MP_REPORT_SENT -1418
|
||||
//@}
|
||||
|
||||
/** @name Statistics on status codes. */
|
||||
//@{
|
||||
#define SNMPv3_MP_MAX_ERROR SNMPv3_MP_ERROR
|
||||
#define SNMPv3_MP_MIN_ERROR SNMPv3_MP_REPORT_SENT
|
||||
#define SNMPv3_MP_ERRORCOUNT SNMPv3_MP_MAX_ERROR - SNMPv3_MP_MIN_ERROR
|
||||
//@}
|
||||
|
||||
class Snmp;
|
||||
class USM;
|
||||
|
||||
/**
|
||||
* The SNMPv3 Message Processing Model (v3MP).
|
||||
*
|
||||
* If SNMPv3 is used, the application needs to create _one_ object of
|
||||
* this class. This object will automatically create an object of the
|
||||
* USM class. A pointer to this object is returned from the get_usm()
|
||||
* method. See the USM documentation for a description on how to create
|
||||
* and delete users.
|
||||
*
|
||||
* The only thing that may be configured after creation of the v3MP is
|
||||
* the engine id table of the v3MP. Entries for other SNMP entities
|
||||
* can be added through add_to_engine_id_table(). It is only required
|
||||
* to add entries to this table if you want to disable engine id
|
||||
* discovery and/or you don't want the delay caused by the automatic
|
||||
* engine id discovery of SNMPv3.
|
||||
*/
|
||||
class DLLOPT v3MP
|
||||
{
|
||||
friend class SnmpMessage;
|
||||
friend class CSNMPMessageQueue;
|
||||
public:
|
||||
/**
|
||||
* Initialize the v3MP.
|
||||
*
|
||||
* Set the engineID of this SNMP entity and the Snmp object used to
|
||||
* send reports. This function creates a new USM object that can
|
||||
* be configured after getting a pointer to it through get_usm().
|
||||
*
|
||||
* The user is responsible to save and restore and increment the
|
||||
* snmpEngineBoots counter (The functions getBootCounter() and
|
||||
* saveBootCounter() can be used to do this.).
|
||||
*
|
||||
* @param snmp_session - The Snmp object to use for sending reports
|
||||
* @param engine_id - The locale engine id
|
||||
* @param engine_boots - The new value for the snmpEngineBoots counter
|
||||
* @param construct_status - OUT: SNMPv3_MP_OK or SNMPv3_MP_ERROR
|
||||
*
|
||||
*/
|
||||
v3MP(Snmp *snmp_session, const OctetStr& engine_id,
|
||||
unsigned int engine_boots, int &construct_status);
|
||||
|
||||
/**
|
||||
* Get the engine id of this SNMP entity.
|
||||
*
|
||||
* @param id - OUT: The engineID of this SNMP entity
|
||||
*
|
||||
* @return - SNMPv3_MP_OK or SNMPv3_MP_ERROR
|
||||
*/
|
||||
void get_local_engine_id(OctetStr &id) { id = own_engine_id_oct; };
|
||||
|
||||
/**
|
||||
* Get the engine id of this SNMP entity as a OctetStr reference.
|
||||
*
|
||||
* @return Local engine id.
|
||||
*/
|
||||
const OctetStr& get_local_engine_id() const
|
||||
{ return own_engine_id_oct; };
|
||||
|
||||
/**
|
||||
* Get a pointer to the USM object that is used by the v3MP.
|
||||
*/
|
||||
USM *get_usm() { return usm; };
|
||||
|
||||
/**
|
||||
* Free all allocated ressources of the v3MP and leave it in an
|
||||
* uninitialized state. After a call to this function, you can use
|
||||
* mpInit() to reinitialize the v3MP.
|
||||
*
|
||||
*/
|
||||
~v3MP();
|
||||
|
||||
/**
|
||||
* Add an entry to the engine id table.
|
||||
*
|
||||
* In this table all known engine ids are stored. If the discovery
|
||||
* mode of the USM is enabled, snmp++ will add entries to this table
|
||||
* whenever a new engine id is dicovered.
|
||||
*
|
||||
* @param engine_id - The engine id
|
||||
* @param host - The numerical IP address
|
||||
* @param port - The port
|
||||
*
|
||||
* @return - SNMPv3_MP_ERROR, SNMPv3_MP_OK
|
||||
*/
|
||||
int add_to_engine_id_table(const OctetStr &engine_id,
|
||||
const OctetStr &host, int port)
|
||||
{ return engine_id_table.add_entry(engine_id, host, port); };
|
||||
|
||||
/**
|
||||
* Get the engine id of the SNMP entity at the given host/port.
|
||||
*
|
||||
* @param engine_id - OUT: The engine id
|
||||
* @param hostport - The numerical IP address and port
|
||||
* (syntax: a.b.c.d/port)
|
||||
*
|
||||
* @return - SNMPv3_MP_NOT_INITIALIZED, SNMPv3_MP_ERROR,
|
||||
* SNMPv3_MP_OK
|
||||
*/
|
||||
int get_from_engine_id_table(OctetStr &engine_id,
|
||||
const OctetStr &hostport) const
|
||||
{ return engine_id_table.get_entry(engine_id, hostport); };
|
||||
|
||||
/**
|
||||
* Get the engineID of the SNMP entity at the given host/port.
|
||||
*
|
||||
* @param engineID - OUT: The engineID
|
||||
* @param host - The numerical IP address
|
||||
* @param port - The port
|
||||
*
|
||||
* @return - SNMPv3_MP_NOT_INITIALIZED, SNMPv3_MP_ERROR,
|
||||
* SNMPv3_MP_OK
|
||||
*/
|
||||
int get_from_engine_id_table(OctetStr &engineID,
|
||||
const OctetStr &host, int port) const
|
||||
{ return engine_id_table.get_entry(engineID, host, port); };
|
||||
|
||||
// ----------[ Access to status counters for agent++ ]--------------
|
||||
|
||||
/**
|
||||
* Get the value of the status counter snmpUnknownSecurityModels.
|
||||
*
|
||||
* @return - The status counter
|
||||
*/
|
||||
unsigned long get_stats_unknown_security_models() const
|
||||
{ return snmpUnknownSecurityModels; };
|
||||
|
||||
/**
|
||||
* Get the value of the status counter snmpInvalidMsgs.
|
||||
*
|
||||
* @return - The status counter
|
||||
*/
|
||||
unsigned long get_stats_invalid_msgs() const
|
||||
{ return snmpInvalidMsgs; };
|
||||
|
||||
/**
|
||||
* Get the value of the status counter snmpUnknownPDUHandlers.
|
||||
*
|
||||
* @return - The status counter
|
||||
*/
|
||||
unsigned long get_stats_unknown_pdu_handlers() const
|
||||
{ return snmpUnknownPDUHandlers; };
|
||||
|
||||
/**
|
||||
* Increment the value of the status counter snmpUnknownSecurityModels.
|
||||
*/
|
||||
void inc_stats_unknown_security_models()
|
||||
{ snmpUnknownSecurityModels++; };
|
||||
|
||||
/**
|
||||
* Increment the value of the status counter snmpInvalidMsgs.
|
||||
*/
|
||||
void inc_stats_invalid_msgs() { snmpInvalidMsgs++; };
|
||||
|
||||
/**
|
||||
* Increment the value of the status counter snmpUnknownPDUHandlers.
|
||||
*/
|
||||
void inc_stats_unknown_pdu_handlers() { snmpUnknownPDUHandlers++; };
|
||||
|
||||
// temporary pointer will be removed...
|
||||
static v3MP *I;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Parse the given buffer as a SNMPv3-Message.
|
||||
*
|
||||
* @param pdu - OUT: Parsed values are put into this struct
|
||||
* @param inBuf - The buffer to parse
|
||||
* @param inBufLength - The length of the buffer
|
||||
* @param securityEngineID - OUT: The parsed securityEngineID
|
||||
* @param securityName - OUT: The parsed securityName
|
||||
* @param contextEngineID - OUT: The parsed contextEngineID
|
||||
* @param contextName - OUT: The parsed contextName
|
||||
* @param securityLevel - OUT: The parsed security level
|
||||
* @param msgSecurityModel - OUT: The security model used
|
||||
* @param spp_version - OUT: SNMP version (SNMPv3)
|
||||
* @param from_address - Where the message came from (used to send
|
||||
* a report if neccessary)
|
||||
*
|
||||
* @return - SNMPv3_MP_OK or any error listed in snmperr.h
|
||||
*/
|
||||
int snmp_parse(struct snmp_pdu *pdu,
|
||||
unsigned char *inBuf,
|
||||
int inBufLength,
|
||||
OctetStr &securityEngineID,
|
||||
OctetStr &securityName,
|
||||
OctetStr &contextEngineID,
|
||||
OctetStr &contextName,
|
||||
long &securityLevel,
|
||||
long &msgSecurityModel,
|
||||
snmp_version &spp_version,
|
||||
UdpAddress from_address);
|
||||
|
||||
/**
|
||||
* Tests if the given buffer contains a SNMPv3-Message. The buffer is
|
||||
* only parsed to extract the version of the message, no other checks
|
||||
* are made.
|
||||
*
|
||||
* @param buffer - The message
|
||||
* @param length - The length of the message
|
||||
*
|
||||
* @return - TRUE if the version could be extracted and it
|
||||
* is a SNMPv3 message. On any error: FALSE.
|
||||
*
|
||||
*/
|
||||
static bool is_v3_msg( unsigned char *buffer, int length);
|
||||
|
||||
/**
|
||||
* Do the complete process of encoding the given values into the buffer
|
||||
* ready to send to the target.
|
||||
*
|
||||
* @param pdu - The pdu structure
|
||||
* @param packet - The buffer to store the serialized message
|
||||
* @param out_length - IN: Length of the buffer,
|
||||
* OUT: Length of the message
|
||||
* @param securityEngineID - The securityEngineID
|
||||
* @param securityNameIn - The securityName
|
||||
* @param securityModel - Use this security model
|
||||
* @param securityLevel - Use this security level
|
||||
* @param contextEngineID - The contextEngineID
|
||||
* @param contextName - The contextName
|
||||
*
|
||||
* @return - SNMPv3_MP_OK or any error listed in snmperr.h
|
||||
*/
|
||||
int snmp_build(struct snmp_pdu *pdu,
|
||||
unsigned char *packet,
|
||||
int *out_length, // maximum Bytes in packet
|
||||
const OctetStr &securityEngineID,
|
||||
const OctetStr &securityNameIn,
|
||||
int securityModel, int securityLevel,
|
||||
const OctetStr &contextEngineID,
|
||||
const OctetStr &contextName);
|
||||
|
||||
/**
|
||||
* Delete the entry with the given request id from the cache.
|
||||
* This function is used in eventlist.cpp when a request
|
||||
* has timed out.
|
||||
*
|
||||
* @param requestID - The request id.
|
||||
*/
|
||||
void delete_from_cache(unsigned long requestID)
|
||||
{ cache.delete_entry(requestID); };
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Send a report message.
|
||||
*
|
||||
* @param scopedPDU - The scopedPDU as received. If the pdu is not
|
||||
* encrypted, the request id is extracted
|
||||
* @param scopedPDULength - The lkength of the scopedPDU
|
||||
* @param pdu - The pdu structure.
|
||||
* @param errorCode - The code of the error that occured.
|
||||
* @param sLevel - Send the report with this security level.
|
||||
* @param sModel - Use this security model.
|
||||
* @param sName - Use this security name
|
||||
* @param destination - Send the report to this address.
|
||||
*
|
||||
* @return - SNMPv3_MP_ERROR, SNMPv3_MP_OK
|
||||
*/
|
||||
int send_report(unsigned char* scopedPDU, int scopedPDULength,
|
||||
struct snmp_pdu *pdu, int errorCode, int sLevel,
|
||||
int sModel, OctetStr &sName,
|
||||
UdpAddress &destination);
|
||||
|
||||
|
||||
|
||||
// =====================[ member classes ]==============================
|
||||
|
||||
/**
|
||||
* The engine id table is used to store known engine ids with
|
||||
* corresponding hostadress and port.
|
||||
*/
|
||||
class DLLOPT EngineIdTable
|
||||
{
|
||||
public:
|
||||
|
||||
EngineIdTable(int initial_size = 10);
|
||||
~EngineIdTable();
|
||||
|
||||
/**
|
||||
* Add an entry to the table.
|
||||
*
|
||||
* @param engine_id - The engineID
|
||||
* @param host - The numerical IP address
|
||||
* @param port - The port
|
||||
*
|
||||
* @return - SNMPv3_MP_ERROR, SNMPv3_MP_OK
|
||||
*/
|
||||
int add_entry(const OctetStr &engine_id,
|
||||
const OctetStr &host, int port);
|
||||
|
||||
/**
|
||||
* Get the engine_id of the SNMP entity at the given host/port.
|
||||
*
|
||||
* @param engine_id - OUT: The engineID
|
||||
* @param hostport - The numerical IP address and port
|
||||
* (syntax: a.b.c.d/port)
|
||||
*
|
||||
* @return - SNMPv3_MP_NOT_INITIALIZED, SNMPv3_MP_ERROR,
|
||||
* SNMPv3_MP_OK
|
||||
*/
|
||||
int get_entry(OctetStr &engine_id, const OctetStr &hostport) const;
|
||||
|
||||
/**
|
||||
* Get the engineID of the SNMP entity at the given host/port.
|
||||
*
|
||||
* @param engine_id - OUT: The engineID
|
||||
* @param host - The numerical IP address
|
||||
* @param port - The port
|
||||
*
|
||||
* @return - SNMPv3_MP_NOT_INITIALIZED, SNMPv3_MP_ERROR,
|
||||
* SNMPv3_MP_OK
|
||||
*/
|
||||
int get_entry(OctetStr &engine_id, const OctetStr &host, int port) const;
|
||||
|
||||
private:
|
||||
int initialize_table(const int size);
|
||||
|
||||
struct Entry_T
|
||||
{
|
||||
OctetStr engine_id;
|
||||
OctetStr host;
|
||||
int port;
|
||||
};
|
||||
|
||||
struct Entry_T *table;
|
||||
int max_entries; ///< the maximum number of entries
|
||||
int entries; ///< the current amount of entries
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Holds cache entries for currently processed requests.
|
||||
*/
|
||||
class DLLOPT Cache
|
||||
{
|
||||
public:
|
||||
Cache();
|
||||
~Cache();
|
||||
|
||||
struct Entry_T
|
||||
{
|
||||
int msg_id;
|
||||
unsigned long req_id;
|
||||
OctetStr sec_engine_id;
|
||||
int sec_model;
|
||||
OctetStr sec_name;
|
||||
int sec_level;
|
||||
OctetStr context_engine_id;
|
||||
OctetStr context_name;
|
||||
struct SecurityStateReference *sec_state_ref;
|
||||
int error_code;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add an entry to the cache.
|
||||
*
|
||||
* @param msg_id - The message id of the message
|
||||
* @param req_id - The request id of the message
|
||||
* @param sec_engine_id - The authoritative engineID
|
||||
* @param sec_model - The security model used for this message
|
||||
* @param sec_name - The name of the user
|
||||
* @param sec_level - The security level used for this message
|
||||
* @param context_engine_id - The context_engine_id
|
||||
* @param context_name - The context_name
|
||||
* @param sec_state_ref - The reference of the USM
|
||||
* @param error_code - The code of the error that occured while
|
||||
* parsing the received message
|
||||
*
|
||||
* @return - SNMPv3_MP_OK, SNMPv3_MP_ERROR or SNMPv3_DOUBLED_MESSAGE
|
||||
* (an entry with the given values is already in the cache)
|
||||
*/
|
||||
int add_entry(int msg_id, unsigned long req_id,
|
||||
const OctetStr &sec_engine_id,
|
||||
int sec_model,
|
||||
const OctetStr &sec_name,
|
||||
int sec_level,
|
||||
const OctetStr &context_engine_id,
|
||||
const OctetStr &context_name,
|
||||
struct SecurityStateReference *sec_state_ref,
|
||||
int error_code);
|
||||
/**
|
||||
* Search the cache for a message id, return the error code and
|
||||
* the sec_state_ref and delete the entry from the cache.
|
||||
*
|
||||
* @param msg_id - Search for this message id
|
||||
* @param error_code - OUT: The error code of the received message
|
||||
* @param sec_state_ref - IN: Pointer to a pointer of the structure
|
||||
* OUT: The structure as received by the USM when
|
||||
* the message was parsed.
|
||||
*
|
||||
* @return - SNMPv3_MP_ERROR, SNMPv3_MP_OK
|
||||
*/
|
||||
int get_entry(int msg_id, int *error_code,
|
||||
struct SecurityStateReference **sec_state_ref);
|
||||
|
||||
/**
|
||||
* Delete the entry with the given request id from the cache.
|
||||
* This function is used in eventlist.cpp when a request
|
||||
* has timed out.
|
||||
*
|
||||
* @param req_id - The request id.
|
||||
*/
|
||||
void delete_entry(unsigned long req_id);
|
||||
|
||||
/**
|
||||
* Search the cache for a message id, return the whole entry and
|
||||
* delete the entry from the cache.
|
||||
*
|
||||
* @param searchedID - Search for this message id
|
||||
* @param res - IN: Pointer to an empy structure
|
||||
* OUT: The filled structure
|
||||
*
|
||||
* @return - SNMPv3_MP_ERROR, SNMPv3_MP_OK
|
||||
*/
|
||||
int get_entry(int searchedID, struct Cache::Entry_T *res);
|
||||
|
||||
void delete_content(struct Cache::Entry_T &ce);
|
||||
|
||||
void set_usm(USM *usm_to_use) { usm = usm_to_use; };
|
||||
|
||||
private:
|
||||
#ifdef _THREADS
|
||||
SnmpSynchronized _cachesync;
|
||||
#endif
|
||||
struct Entry_T *table; ///< whole table
|
||||
int max_entries; ///< the maximum number of entries
|
||||
int entries; ///< the current amount of entries
|
||||
USM *usm;
|
||||
};
|
||||
|
||||
|
||||
// =====================[ member variables ]==============================
|
||||
EngineIdTable engine_id_table;
|
||||
Cache cache;
|
||||
|
||||
// the engineID of this SNMP entity
|
||||
unsigned char *own_engine_id;
|
||||
int own_engine_id_len;
|
||||
OctetStr own_engine_id_oct;
|
||||
|
||||
// msgID to use for next message
|
||||
unsigned int cur_msg_id;
|
||||
|
||||
// used for sending report messages
|
||||
Snmp *snmp;
|
||||
|
||||
// the USM object used
|
||||
USM *usm;
|
||||
|
||||
// MIB Counters
|
||||
unsigned int snmpUnknownSecurityModels;
|
||||
unsigned int snmpInvalidMsgs;
|
||||
unsigned int snmpUnknownPDUHandlers;
|
||||
};
|
||||
|
||||
#endif // _SNMPv3
|
||||
|
||||
#endif
|
709
backend/camembert/libkmsnmp/octet.cpp
Normal file
709
backend/camembert/libkmsnmp/octet.cpp
Normal file
@ -0,0 +1,709 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## octet.cpp
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
/*===================================================================
|
||||
|
||||
Copyright (c) 1999
|
||||
Hewlett-Packard Company
|
||||
|
||||
ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
Permission to use, copy, modify, distribute and/or sell this software
|
||||
and/or its documentation is hereby granted without fee. User agrees
|
||||
to display the above copyright notice and this license notice in all
|
||||
copies of the software and any documentation of the software. User
|
||||
agrees to assume all liability for the use of the software; Hewlett-Packard
|
||||
makes no representations about the suitability of this software for any
|
||||
purpose. It is provided "AS-IS" without warranty of any kind,either express
|
||||
or implied. User hereby grants a royalty-free license to any and all
|
||||
derivatives based upon this software code base.
|
||||
|
||||
|
||||
|
||||
O C T E T . C P P
|
||||
|
||||
OCTETSTR CLASS IMPLEMENTATION
|
||||
|
||||
DESIGN + AUTHOR:
|
||||
Peter E Mellquist
|
||||
|
||||
LANGUAGE:
|
||||
ANSI C++
|
||||
|
||||
OPERATING SYSTEMS:
|
||||
MS-WINDOWS Win32
|
||||
BSD UNIX
|
||||
|
||||
DESCRIPTION:
|
||||
This class is fully contained and does not rely on or any other
|
||||
SNMP libraries. This class is portable across any platform
|
||||
which supports C++.
|
||||
|
||||
|
||||
=====================================================================*/
|
||||
char octet_cpp_version[]="@(#) SNMP++ $Id: octet.cpp,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $";
|
||||
|
||||
#include "octet.h" // include definition for octet class
|
||||
#include <ctype.h> // for isprint() used by get_printable()
|
||||
#include <stdio.h> // for sprintf() used by get_printable_hex()
|
||||
#include <string.h> // for strlen() and memcpy()
|
||||
|
||||
|
||||
//============[ constructor using no arguments ]======================
|
||||
OctetStr::OctetStr()
|
||||
: output_buffer(0), output_buffer_len(0), validity(true)
|
||||
{
|
||||
smival.syntax = sNMP_SYNTAX_OCTETS;
|
||||
smival.value.string.ptr = 0;
|
||||
smival.value.string.len = 0;
|
||||
}
|
||||
|
||||
//============[ constructor using a string ]=========================
|
||||
OctetStr::OctetStr(const char *str)
|
||||
: output_buffer(0), output_buffer_len(0), validity(true)
|
||||
{
|
||||
smival.syntax = sNMP_SYNTAX_OCTETS;
|
||||
smival.value.string.ptr = 0;
|
||||
smival.value.string.len = 0;
|
||||
|
||||
size_t z;
|
||||
|
||||
// check for null string
|
||||
if (!str || !(z = (size_t) STRLEN(str)))
|
||||
return;
|
||||
|
||||
// get mem needed
|
||||
smival.value.string.ptr = (SmiLPBYTE) new unsigned char[z];
|
||||
|
||||
if (smival.value.string.ptr)
|
||||
{
|
||||
MEMCPY(smival.value.string.ptr, str, z);
|
||||
smival.value.string.len = z;
|
||||
}
|
||||
else
|
||||
validity = false;
|
||||
}
|
||||
|
||||
|
||||
//============[ constructor using an unsigned char * ]================
|
||||
OctetStr::OctetStr(const unsigned char *str, unsigned long len)
|
||||
: output_buffer(0), output_buffer_len(0), validity(true)
|
||||
{
|
||||
smival.syntax = sNMP_SYNTAX_OCTETS;
|
||||
smival.value.string.ptr = 0;
|
||||
smival.value.string.len = 0;
|
||||
|
||||
if (!str || !len) return; // check for zero len
|
||||
|
||||
// get the mem needed
|
||||
smival.value.string.ptr = (SmiLPBYTE) new unsigned char[len];
|
||||
|
||||
if (smival.value.string.ptr)
|
||||
{
|
||||
MEMCPY(smival.value.string.ptr, str, (size_t) len);
|
||||
smival.value.string.len = len;
|
||||
}
|
||||
else
|
||||
validity = false;
|
||||
}
|
||||
|
||||
//============[ constructor using another octet object ]==============
|
||||
OctetStr::OctetStr (const OctetStr &octet)
|
||||
: output_buffer(0), output_buffer_len(0), validity(true)
|
||||
{
|
||||
smival.syntax = sNMP_SYNTAX_OCTETS;
|
||||
smival.value.string.ptr = 0;
|
||||
smival.value.string.len = 0;
|
||||
|
||||
if (octet.smival.value.string.len == 0) return; // check for zero len case
|
||||
|
||||
// must be a valid object
|
||||
if (!octet.validity)
|
||||
{
|
||||
validity = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// get the mem needed
|
||||
smival.value.string.ptr = (SmiLPBYTE) new unsigned char[octet.smival.value.string.len];
|
||||
|
||||
if (smival.value.string.ptr)
|
||||
{
|
||||
MEMCPY(smival.value.string.ptr,
|
||||
octet.smival.value.string.ptr,
|
||||
(size_t) octet.smival.value.string.len);
|
||||
smival.value.string.len = octet.smival.value.string.len;
|
||||
}
|
||||
else
|
||||
validity = false;
|
||||
}
|
||||
|
||||
//=============[ destructor ]=========================================
|
||||
OctetStr::~OctetStr()
|
||||
{
|
||||
// if not empty, free it up
|
||||
if (smival.value.string.ptr) delete [] smival.value.string.ptr;
|
||||
if (output_buffer) delete [] output_buffer;
|
||||
}
|
||||
|
||||
|
||||
//============[ set the data on an already constructed Octet ]============
|
||||
void OctetStr::set_data(const unsigned char *str, unsigned long len)
|
||||
{
|
||||
// free up already used space
|
||||
if (smival.value.string.ptr)
|
||||
{
|
||||
delete [] smival.value.string.ptr;
|
||||
smival.value.string.ptr = 0;
|
||||
}
|
||||
smival.value.string.len = 0;
|
||||
|
||||
// check for zero len
|
||||
if (!str || !len)
|
||||
{
|
||||
validity = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// get the mem needed
|
||||
smival.value.string.ptr = (SmiLPBYTE) new unsigned char[len];
|
||||
|
||||
if (smival.value.string.ptr)
|
||||
{
|
||||
MEMCPY(smival.value.string.ptr, str, (size_t) len);
|
||||
smival.value.string.len = len;
|
||||
validity = true;
|
||||
}
|
||||
else
|
||||
validity = false;
|
||||
}
|
||||
|
||||
//=============[ assignment to a string operator overloaded ]=========
|
||||
OctetStr& OctetStr::operator=(const char *str)
|
||||
{
|
||||
size_t nz;
|
||||
|
||||
// free up previous memory if needed
|
||||
if (smival.value.string.ptr )
|
||||
{
|
||||
delete [] smival.value.string.ptr;
|
||||
smival.value.string.ptr = 0;
|
||||
smival.value.string.len = 0;
|
||||
}
|
||||
|
||||
// if empty then we are done; get the string size
|
||||
if (!str || !(nz = (size_t) STRLEN(str)))
|
||||
{
|
||||
validity = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// get memory needed
|
||||
smival.value.string.ptr = (SmiLPBYTE) new unsigned char[nz];
|
||||
|
||||
if (smival.value.string.ptr)
|
||||
{
|
||||
MEMCPY(smival.value.string.ptr, str, (size_t) nz);
|
||||
smival.value.string.len = nz;
|
||||
validity = true;
|
||||
}
|
||||
else
|
||||
validity = false;
|
||||
|
||||
return *this; // return self reference
|
||||
}
|
||||
|
||||
//=============[ assignment to another oid object overloaded ]========
|
||||
OctetStr& OctetStr::operator=(const OctetStr &octet)
|
||||
{
|
||||
if (this == &octet) return *this; // protect against assignment from self
|
||||
|
||||
if (!octet.validity) return *this; // don't assign from invalid objs
|
||||
|
||||
set_data(octet.smival.value.string.ptr, octet.smival.value.string.len);
|
||||
|
||||
return *this; // return self reference
|
||||
}
|
||||
|
||||
//==============[ equivlence operator overloaded ]====================
|
||||
int operator==(const OctetStr &lhs, const OctetStr &rhs)
|
||||
{
|
||||
if (lhs.smival.value.string.len != rhs.smival.value.string.len)
|
||||
return false;
|
||||
return (lhs.nCompare(rhs.smival.value.string.len, rhs) == 0);
|
||||
}
|
||||
|
||||
//==============[ not equivlence operator overloaded ]================
|
||||
int operator!=(const OctetStr &lhs, const OctetStr &rhs)
|
||||
{
|
||||
if (lhs.smival.value.string.len != rhs.smival.value.string.len)
|
||||
return true;
|
||||
return (lhs.nCompare(rhs.smival.value.string.len, rhs) != 0);
|
||||
}
|
||||
|
||||
//==============[ less than < overloaded ]============================
|
||||
int operator<(const OctetStr &lhs, const OctetStr &rhs)
|
||||
{
|
||||
int maxlen = lhs.smival.value.string.len > rhs.smival.value.string.len
|
||||
? lhs.smival.value.string.len : rhs.smival.value.string.len;
|
||||
return (lhs.nCompare(maxlen, rhs) < 0);
|
||||
}
|
||||
|
||||
//==============[ less than <= overloaded ]===========================
|
||||
int operator<=(const OctetStr &lhs, const OctetStr &rhs)
|
||||
{
|
||||
int maxlen = lhs.smival.value.string.len > rhs.smival.value.string.len
|
||||
? lhs.smival.value.string.len : rhs.smival.value.string.len;
|
||||
return (lhs.nCompare(maxlen, rhs) <= 0);
|
||||
}
|
||||
|
||||
//===============[ greater than > overloaded ]========================
|
||||
int operator>(const OctetStr &lhs, const OctetStr &rhs)
|
||||
{
|
||||
int maxlen = lhs.smival.value.string.len > rhs.smival.value.string.len
|
||||
? lhs.smival.value.string.len : rhs.smival.value.string.len;
|
||||
return (lhs.nCompare(maxlen, rhs) > 0);
|
||||
}
|
||||
|
||||
//===============[ greater than >= overloaded ]=======================
|
||||
int operator>=(const OctetStr &lhs, const OctetStr &rhs)
|
||||
{
|
||||
int maxlen = lhs.smival.value.string.len > rhs.smival.value.string.len
|
||||
? lhs.smival.value.string.len : rhs.smival.value.string.len;
|
||||
return (lhs.nCompare(maxlen, rhs) >=0);
|
||||
}
|
||||
|
||||
//===============[ equivlence operator overloaded ]===================
|
||||
int operator==(const OctetStr &lhs, const char *rhs)
|
||||
{
|
||||
OctetStr to(rhs);
|
||||
if (lhs.smival.value.string.len != to.smival.value.string.len)
|
||||
return false;
|
||||
return (lhs.nCompare(to.smival.value.string.len, to) == 0);
|
||||
}
|
||||
|
||||
//===============[ not equivlence operator overloaded ]===============
|
||||
int operator!=(const OctetStr &lhs, const char *rhs)
|
||||
{
|
||||
OctetStr to(rhs);
|
||||
if (lhs.smival.value.string.len != to.smival.value.string.len)
|
||||
return true;
|
||||
return (lhs.nCompare(to.smival.value.string.len, to) != 0);
|
||||
}
|
||||
|
||||
//===============[ less than < operator overloaded ]==================
|
||||
int operator<(const OctetStr &lhs, const char *rhs)
|
||||
{
|
||||
OctetStr to(rhs);
|
||||
int maxlen = lhs.smival.value.string.len > to.smival.value.string.len
|
||||
? lhs.smival.value.string.len : to.smival.value.string.len;
|
||||
return (lhs.nCompare(maxlen,to) < 0);
|
||||
}
|
||||
|
||||
//===============[ less than <= operator overloaded ]=================
|
||||
int operator<=(const OctetStr &lhs, const char *rhs)
|
||||
{
|
||||
OctetStr to(rhs);
|
||||
int maxlen = lhs.smival.value.string.len > to.smival.value.string.len
|
||||
? lhs.smival.value.string.len : to.smival.value.string.len;
|
||||
return (lhs.nCompare(maxlen, to) <= 0);
|
||||
}
|
||||
|
||||
//===============[ greater than > operator overloaded ]===============
|
||||
int operator>(const OctetStr &lhs, const char *rhs)
|
||||
{
|
||||
OctetStr to(rhs);
|
||||
int maxlen = lhs.smival.value.string.len > to.smival.value.string.len
|
||||
? lhs.smival.value.string.len : to.smival.value.string.len;
|
||||
return (lhs.nCompare(maxlen, to) > 0);
|
||||
}
|
||||
|
||||
//===============[ greater than >= operator overloaded ]==============
|
||||
int operator>=(const OctetStr &lhs, const char *rhs)
|
||||
{
|
||||
OctetStr to(rhs);
|
||||
int maxlen = lhs.smival.value.string.len > to.smival.value.string.len
|
||||
? lhs.smival.value.string.len : to.smival.value.string.len;
|
||||
return (lhs.nCompare(maxlen, to) >= 0);
|
||||
}
|
||||
|
||||
//===============[ append operator, appends a string ]================
|
||||
OctetStr& OctetStr::operator+=(const char *a)
|
||||
{
|
||||
unsigned char *tmp;
|
||||
size_t slen, nlen;
|
||||
|
||||
// get len of string
|
||||
if (!a || ((slen = (size_t) STRLEN(a)) == 0))
|
||||
return *this;
|
||||
|
||||
// total len of new octet
|
||||
nlen = slen + (size_t) smival.value.string.len;
|
||||
// get mem needed
|
||||
tmp = (SmiLPBYTE) new unsigned char[nlen];
|
||||
|
||||
if (tmp)
|
||||
{
|
||||
// copy in the original 1st
|
||||
MEMCPY(tmp, smival.value.string.ptr, (size_t) smival.value.string.len);
|
||||
// copy in the string
|
||||
MEMCPY(tmp + smival.value.string.len, a, (size_t) slen);
|
||||
// delete the original
|
||||
if (smival.value.string.ptr )
|
||||
delete [] smival.value.string.ptr;
|
||||
// point to the new one
|
||||
smival.value.string.ptr = tmp;
|
||||
smival.value.string.len = nlen;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
//================[ append one OctetStr to another ]==================
|
||||
OctetStr& OctetStr::operator+=(const OctetStr& octet)
|
||||
{
|
||||
unsigned char *tmp;
|
||||
size_t slen, nlen;
|
||||
|
||||
if (!octet.validity ||
|
||||
!(slen = (size_t)octet.len()))
|
||||
return *this;
|
||||
|
||||
// total len of new octet
|
||||
nlen = slen + (size_t) smival.value.string.len;
|
||||
// get mem needed
|
||||
tmp = (SmiLPBYTE) new unsigned char[nlen];
|
||||
|
||||
if (tmp)
|
||||
{
|
||||
// copy in the original 1st
|
||||
MEMCPY(tmp, smival.value.string.ptr, (size_t) smival.value.string.len);
|
||||
// copy in the string
|
||||
MEMCPY(tmp + smival.value.string.len, octet.data(), (size_t) slen);
|
||||
// delete the original
|
||||
if (smival.value.string.ptr )
|
||||
delete [] smival.value.string.ptr;
|
||||
// point to the new one
|
||||
smival.value.string.ptr = tmp;
|
||||
smival.value.string.len = nlen;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
//================[ appends a char ]==================================
|
||||
OctetStr& OctetStr::operator+=(const unsigned char c)
|
||||
{
|
||||
unsigned char *tmp;
|
||||
|
||||
// get the memory needed plus one extra byte
|
||||
tmp = (SmiLPBYTE) new unsigned char[smival.value.string.len + 1];
|
||||
|
||||
if (tmp)
|
||||
{
|
||||
MEMCPY(tmp, smival.value.string.ptr, (size_t)smival.value.string.len);
|
||||
tmp[smival.value.string.len] = c; // assign in new byte
|
||||
|
||||
if (smival.value.string.ptr) // delete the original
|
||||
delete [] smival.value.string.ptr;
|
||||
|
||||
smival.value.string.ptr = tmp; // point to new one
|
||||
smival.value.string.len++; // up the len
|
||||
}
|
||||
return *this; // return self reference
|
||||
}
|
||||
|
||||
|
||||
//================[ compare n elements of an Octet ]==================
|
||||
int OctetStr::nCompare(const unsigned long n, const OctetStr &o) const
|
||||
{
|
||||
unsigned long n_max;
|
||||
unsigned long w,strlen;
|
||||
|
||||
if (n == 0) return 0; // Nothing to compare, strings are equal
|
||||
|
||||
// both are empty, they are equal
|
||||
if ((smival.value.string.len == 0) && (o.smival.value.string.len == 0))
|
||||
return 0; // equal
|
||||
|
||||
// self is empty and param has something
|
||||
if ((smival.value.string.len == 0) && (o.smival.value.string.len > 0))
|
||||
return -1;
|
||||
|
||||
// self has something and param has nothing
|
||||
if ((smival.value.string.len > 0) && (o.smival.value.string.len == 0))
|
||||
return 1;
|
||||
|
||||
// now: n > 0; this.len > 0; o.len > 0 !!!
|
||||
|
||||
// pick the Min of n, this and the param len
|
||||
// this is the maximum # to iterate a search
|
||||
strlen = smival.value.string.len < o.smival.value.string.len
|
||||
? smival.value.string.len : o.smival.value.string.len;
|
||||
w = (n <= strlen) ? n : strlen;
|
||||
|
||||
unsigned long z = 0;
|
||||
while (z < w)
|
||||
{
|
||||
if (smival.value.string.ptr[z] < o.smival.value.string.ptr[z])
|
||||
return -1; // less than
|
||||
if (smival.value.string.ptr[z] > o.smival.value.string.ptr[z])
|
||||
return 1; // greater than
|
||||
z++;
|
||||
}
|
||||
|
||||
// now: z == w > 0
|
||||
// set n_max to min(n, max(len of strings))
|
||||
n_max = smival.value.string.len > o.smival.value.string.len
|
||||
? smival.value.string.len : o.smival.value.string.len;
|
||||
if (n< n_max) n_max = n;
|
||||
|
||||
if (w < n_max) // ==> we have compared too few bytes
|
||||
{
|
||||
if (smival.value.string.len < o.smival.value.string.len)
|
||||
return -1;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//================[ ASCII format return ]=============================
|
||||
const char *OctetStr::get_printable() const
|
||||
{
|
||||
for (unsigned long i=0; i < smival.value.string.len; i++)
|
||||
{
|
||||
if ((smival.value.string.ptr[i] != '\r')&&
|
||||
(smival.value.string.ptr[i] != '\n')&&
|
||||
(isprint((int) (smival.value.string.ptr[i]))==0))
|
||||
return get_printable_hex();
|
||||
}
|
||||
|
||||
OctetStr *ncthis = PP_CONST_CAST(OctetStr*, this);
|
||||
if (output_buffer_len < smival.value.string.len + 1)
|
||||
{
|
||||
if (output_buffer) delete [] ncthis->output_buffer;
|
||||
|
||||
ncthis->output_buffer = new char[smival.value.string.len + 1];
|
||||
if (ncthis->output_buffer)
|
||||
ncthis->output_buffer_len = smival.value.string.len + 1;
|
||||
}
|
||||
if (smival.value.string.len)
|
||||
MEMCPY(ncthis->output_buffer,
|
||||
smival.value.string.ptr, (unsigned int) smival.value.string.len);
|
||||
ncthis->output_buffer[smival.value.string.len] = '\0';
|
||||
return output_buffer;
|
||||
}
|
||||
|
||||
|
||||
//================[ general Value = operator ]========================
|
||||
SnmpSyntax& OctetStr::operator=(const SnmpSyntax &val)
|
||||
{
|
||||
if (this == &val) return *this; // protect against assignment from self
|
||||
|
||||
// blow away the old value
|
||||
if (smival.value.string.ptr)
|
||||
{
|
||||
delete [] smival.value.string.ptr;
|
||||
smival.value.string.ptr = 0;
|
||||
}
|
||||
smival.value.string.len = 0;
|
||||
validity = false;
|
||||
|
||||
if (val.valid()){
|
||||
switch (val.get_syntax()){
|
||||
case sNMP_SYNTAX_OPAQUE:
|
||||
case sNMP_SYNTAX_BITS:
|
||||
case sNMP_SYNTAX_OCTETS:
|
||||
case sNMP_SYNTAX_IPADDR:
|
||||
set_data(((OctetStr &)val).smival.value.string.ptr,
|
||||
((OctetStr &)val).smival.value.string.len);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
#define ATOI(x) if ((x >= 48) && (x <= 57)) x = x-48; /* 0-9 */ \
|
||||
else if ((x >= 65) && (x <= 70)) x = x-55; /* A-F */ \
|
||||
else if ((x >= 97) && (x <=102)) x = x-87; /* a-f */ \
|
||||
else x = 0
|
||||
|
||||
//=======[ create an octet string from a hex string ]===================
|
||||
OctetStr OctetStr::from_hex_string(const OctetStr &hex_string)
|
||||
{
|
||||
OctetStr val;
|
||||
unsigned int p = 0;
|
||||
unsigned int hex_len = 0;
|
||||
|
||||
// make sure the string has at least one byte
|
||||
if (hex_string.len() == 0) return val;
|
||||
|
||||
// allocate max needed space for copy without spaces
|
||||
unsigned char *hex, *hex_ptr;
|
||||
hex = hex_ptr = new unsigned char[hex_string.len()];
|
||||
if (!hex) return val;
|
||||
|
||||
// delete spaces
|
||||
const unsigned char *ptr = hex_string.smival.value.string.ptr;
|
||||
for (p = hex_string.len(); p > 0; p--)
|
||||
{
|
||||
unsigned char c = *ptr++;
|
||||
if (c != ' ')
|
||||
{
|
||||
*hex_ptr++ = c;
|
||||
++hex_len;
|
||||
}
|
||||
}
|
||||
|
||||
// leading 0 may be omitted
|
||||
if (hex_len % 2)
|
||||
{
|
||||
unsigned char c = hex[0];
|
||||
ATOI(c);
|
||||
val += c;
|
||||
p = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
p = 0;
|
||||
}
|
||||
|
||||
while (p < hex_len)
|
||||
{
|
||||
unsigned char c = hex[p++];
|
||||
unsigned char d = hex[p++];
|
||||
|
||||
ATOI(c);
|
||||
ATOI(d);
|
||||
val += (c*16 + d);
|
||||
}
|
||||
delete[] hex;
|
||||
return val;
|
||||
}
|
||||
|
||||
#undef ATOI
|
||||
|
||||
//================[ format the output into hex ]========================
|
||||
const char *OctetStr::get_printable_hex() const
|
||||
{
|
||||
int cnt;
|
||||
char char_buf[80]; // holds ASCII representation of data
|
||||
char *buf_ptr; // pointer into ASCII listing
|
||||
char *line_ptr; // pointer into Hex listing
|
||||
unsigned int storageNeeded; // how much space do we need ?
|
||||
int local_len = (int) smival.value.string.len;
|
||||
unsigned char *bytes = smival.value.string.ptr;
|
||||
|
||||
storageNeeded = (unsigned int) ((smival.value.string.len/16)+1) * 72 + 1;
|
||||
OctetStr *ncthis = PP_CONST_CAST(OctetStr*, this);
|
||||
|
||||
if (output_buffer_len < storageNeeded)
|
||||
{
|
||||
if (output_buffer) delete [] ncthis->output_buffer;
|
||||
|
||||
ncthis->output_buffer = new char[storageNeeded];
|
||||
if (ncthis->output_buffer)
|
||||
ncthis->output_buffer_len = storageNeeded;
|
||||
}
|
||||
|
||||
line_ptr = ncthis->output_buffer;
|
||||
|
||||
/*----------------------------------------*/
|
||||
/* processing loop for entire data buffer */
|
||||
/*----------------------------------------*/
|
||||
while (local_len > 0)
|
||||
{
|
||||
cnt = 16; /* print 16 bytes per line */
|
||||
buf_ptr = char_buf;
|
||||
//sprintf(line_ptr, " ");
|
||||
//line_ptr += 2; /* indent */
|
||||
|
||||
/*-----------------------*/
|
||||
/* process a single line */
|
||||
/*-----------------------*/
|
||||
while (cnt-- > 0 && local_len-- > 0)
|
||||
{
|
||||
sprintf(line_ptr, "%2.2X ", *bytes);
|
||||
|
||||
line_ptr +=3; /* the display of a byte always 3 chars long */
|
||||
/* if (isprint(*bytes))
|
||||
*buf_ptr++ = *bytes;
|
||||
else
|
||||
*buf_ptr++ = '.';*/
|
||||
++bytes;
|
||||
}
|
||||
++cnt;
|
||||
//*buf_ptr = 0; // null terminate string
|
||||
|
||||
/*----------------------------------------------------------*/
|
||||
/* this is to make sure that the ASCII displays line up for */
|
||||
/* incomplete lines of hex */
|
||||
/*----------------------------------------------------------*/
|
||||
/* while (cnt-- > 0)
|
||||
{
|
||||
*line_ptr++ = ' ';
|
||||
*line_ptr++ = ' ';
|
||||
*line_ptr++ = ' ';
|
||||
}
|
||||
*/
|
||||
/*------------------------------------------*/
|
||||
/* append the ASCII display to the Hex line */
|
||||
/*------------------------------------------*/
|
||||
/*#ifndef __unix
|
||||
sprintf(line_ptr," %s\n", char_buf);
|
||||
line_ptr += 4 + strlen(char_buf);
|
||||
#else
|
||||
sprintf(line_ptr," %s\r\n", char_buf);
|
||||
line_ptr += 5 + strlen(char_buf);
|
||||
#endif // __unix
|
||||
*/
|
||||
}
|
||||
return ncthis->output_buffer;
|
||||
}
|
||||
|
||||
|
||||
//==============[ Null out the contents of the string ]===================
|
||||
void OctetStr::clear()
|
||||
{
|
||||
if (smival.value.string.ptr)
|
||||
memset(smival.value.string.ptr, 0, smival.value.string.len);
|
||||
if (output_buffer)
|
||||
memset(output_buffer, 0, output_buffer_len);
|
||||
}
|
||||
|
||||
//============[Return the space needed for serialization]=================
|
||||
int OctetStr::get_asn1_length() const
|
||||
{
|
||||
if (smival.value.string.len < 0x80)
|
||||
return smival.value.string.len + 2;
|
||||
else if (smival.value.string.len < 0x100)
|
||||
return smival.value.string.len + 3;
|
||||
else if (smival.value.string.len < 0x10000)
|
||||
return smival.value.string.len + 4;
|
||||
else if (smival.value.string.len < 0x1000000)
|
||||
return smival.value.string.len + 5;
|
||||
return smival.value.string.len + 6; // should be safe for some time...
|
||||
}
|
387
backend/camembert/libkmsnmp/octet.h
Normal file
387
backend/camembert/libkmsnmp/octet.h
Normal file
@ -0,0 +1,387 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## octet.h
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
/*===================================================================
|
||||
|
||||
Copyright (c) 1999
|
||||
Hewlett-Packard Company
|
||||
|
||||
ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
Permission to use, copy, modify, distribute and/or sell this software
|
||||
and/or its documentation is hereby granted without fee. User agrees
|
||||
to display the above copyright notice and this license notice in all
|
||||
copies of the software and any documentation of the software. User
|
||||
agrees to assume all liability for the use of the software; Hewlett-Packard
|
||||
makes no representations about the suitability of this software for any
|
||||
purpose. It is provided "AS-IS without warranty of any kind,either express
|
||||
or implied. User hereby grants a royalty-free license to any and all
|
||||
derivatives based upon this software code base.
|
||||
|
||||
|
||||
SNMP++ O C T E T . H
|
||||
|
||||
OCTETSTR CLASS DEFINITION
|
||||
|
||||
DESIGN + AUTHOR:
|
||||
Peter E Mellquist
|
||||
|
||||
LANGUAGE:
|
||||
ANSI C++
|
||||
|
||||
OPERATING SYSTEMS:
|
||||
MS-WINDOWS Win32
|
||||
BSD UNIX
|
||||
|
||||
DESCRIPTION:
|
||||
This class is fully contained and does not rely on or any other
|
||||
SNMP libraries. This class is portable across any platform
|
||||
which supports C++.
|
||||
|
||||
=====================================================================*/
|
||||
// $Id: octet.h,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $
|
||||
|
||||
#ifndef _OCTET_CLS
|
||||
#define _OCTET_CLS
|
||||
|
||||
#include "smival.h"
|
||||
|
||||
//------------[ SNMP++ OCTETSTR CLASS DEF ]-----------------------------
|
||||
class DLLOPT OctetStr: public SnmpSyntax
|
||||
{
|
||||
public:
|
||||
|
||||
//-----------[ Constructors and Destrucotr ]----------------------
|
||||
|
||||
/**
|
||||
* Constructs a valid OctetStr with zero length.
|
||||
*/
|
||||
OctetStr();
|
||||
|
||||
/**
|
||||
* Constructs a OctetStr with the given value.
|
||||
* The OctetStr will be valid unless a call to new fails.
|
||||
*
|
||||
* @param str - Null terminated string
|
||||
*/
|
||||
OctetStr(const char *str);
|
||||
|
||||
/**
|
||||
* Constructs a OctetStr with the given value.
|
||||
* The OctetStr will be valid unless a call to new fails.
|
||||
*
|
||||
* @param str - string that may contain null bytes
|
||||
* @param len - length of the string
|
||||
*/
|
||||
OctetStr(const unsigned char *str, unsigned long len);
|
||||
|
||||
/**
|
||||
* Construct a OctetStr from another OctetStr.
|
||||
* The OctetStr will be valid unless a call to new fails.
|
||||
*
|
||||
* @param octet - Value for the new object
|
||||
*/
|
||||
OctetStr(const OctetStr &octet);
|
||||
|
||||
/**
|
||||
* Destructor, frees allocated space.
|
||||
*/
|
||||
~OctetStr();
|
||||
|
||||
//-----------[ Overloaded operators ]----------------------
|
||||
|
||||
/**
|
||||
* Assign a char string to a OctetStr.
|
||||
*/
|
||||
OctetStr& operator=(const char *str);
|
||||
|
||||
/**
|
||||
* Assign a OctetStr to a OctetStr.
|
||||
*/
|
||||
OctetStr& operator=(const OctetStr &octet);
|
||||
|
||||
/**
|
||||
* Equal operator for two OctetStr.
|
||||
*/
|
||||
DLLOPT friend int operator==( const OctetStr &lhs, const OctetStr &rhs);
|
||||
|
||||
/**
|
||||
* Not equal operator for two OctetStr.
|
||||
*/
|
||||
DLLOPT friend int operator!=( const OctetStr &lhs, const OctetStr &rhs);
|
||||
|
||||
/**
|
||||
* Not equal operator for two OctetStr.
|
||||
*/
|
||||
DLLOPT friend int operator<( const OctetStr &lhs, const OctetStr &rhs);
|
||||
|
||||
/**
|
||||
* Less than operator for two OctetStr.
|
||||
*/
|
||||
DLLOPT friend int operator<=( const OctetStr &lhs,const OctetStr &rhs);
|
||||
|
||||
/**
|
||||
* Greater than operator for two OctetStr.
|
||||
*/
|
||||
DLLOPT friend int operator>( const OctetStr &lhs, const OctetStr &rhs);
|
||||
|
||||
/**
|
||||
* Greater than or equal operator for two OctetStr.
|
||||
*/
|
||||
DLLOPT friend int operator>=( const OctetStr &lhs, const OctetStr &rhs);
|
||||
|
||||
/**
|
||||
* Equal operator for OctetStr and char string.
|
||||
*/
|
||||
DLLOPT friend int operator==( const OctetStr &lhs, const char *rhs);
|
||||
|
||||
/**
|
||||
* Not equal operator for OctetStr and char string.
|
||||
*/
|
||||
DLLOPT friend int operator!=( const OctetStr &lhs, const char *rhs);
|
||||
|
||||
/**
|
||||
* Less than operator for OctetStr and char string.
|
||||
*/
|
||||
DLLOPT friend int operator<( const OctetStr &lhs, const char *rhs);
|
||||
|
||||
/**
|
||||
* Less than or equal operator for OctetStr and char string.
|
||||
*/
|
||||
DLLOPT friend int operator<=( const OctetStr &lhs, const char *rhs);
|
||||
|
||||
/**
|
||||
* Greater than operator for OctetStr and char string.
|
||||
*/
|
||||
DLLOPT friend int operator>( const OctetStr &lhs, const char *rhs);
|
||||
|
||||
/**
|
||||
* Greater than or equal operator for OctetStr and char string.
|
||||
*/
|
||||
DLLOPT friend int operator>=( const OctetStr &lhs, const char *rhs);
|
||||
|
||||
/**
|
||||
* Append a char string to this OctetStr.
|
||||
*/
|
||||
OctetStr& operator+=( const char *a);
|
||||
|
||||
/**
|
||||
* Append a single char to this OctetStr.
|
||||
*/
|
||||
OctetStr& operator+=( const unsigned char c);
|
||||
|
||||
/**
|
||||
* Append another OctetStr to this OctetStr.
|
||||
*/
|
||||
OctetStr& operator+=( const OctetStr& octet);
|
||||
|
||||
/**
|
||||
* Allow access as if it was an array.
|
||||
*
|
||||
* @note The given param is not checked for validity.
|
||||
*/
|
||||
unsigned char &operator[](int i) { return smival.value.string.ptr[i]; };
|
||||
|
||||
/**
|
||||
* Allow access as if it was an array for const OctetStr objects.
|
||||
*
|
||||
* @note The given param is not checked for validity.
|
||||
*/
|
||||
unsigned char operator[](int i) const { return smival.value.string.ptr[i]; };
|
||||
|
||||
/**
|
||||
* Return the syntax.
|
||||
*
|
||||
* @return This method always returns sNMP_SYNTAX_OCTETS.
|
||||
*/
|
||||
SmiUINT32 get_syntax() const { return sNMP_SYNTAX_OCTETS; };
|
||||
|
||||
/**
|
||||
* Return the space needed for serialization.
|
||||
*/
|
||||
int get_asn1_length() const;
|
||||
|
||||
/**
|
||||
* Return validity of the object.
|
||||
*/
|
||||
bool valid() const { return validity; };
|
||||
|
||||
/**
|
||||
* Clone this object.
|
||||
*
|
||||
* @return Pointer to the newly created object (allocated through new).
|
||||
*/
|
||||
SnmpSyntax *clone() const { return ( SnmpSyntax *) new OctetStr(*this); };
|
||||
|
||||
/**
|
||||
* Map other SnmpSyntax objects to OctetStr.
|
||||
*/
|
||||
SnmpSyntax& operator=(const SnmpSyntax &val);
|
||||
|
||||
/**
|
||||
* Get a printable ASCII value of the string.
|
||||
*
|
||||
* @note This method will return get_printable_hex() if the string
|
||||
* contains not printable characters.
|
||||
*
|
||||
* @return Printable, null terminated string
|
||||
*/
|
||||
const char *get_printable() const;
|
||||
|
||||
/**
|
||||
* Get an ASCII formatted hex dump of the contents.
|
||||
* The produced string of this method will look like this:
|
||||
* <pre>
|
||||
* 09 4F 63 74 65 74 53 74 72 3A 3A 67 65 74 5F 70 .OctetStr::get_p
|
||||
* 72 69 6E 74 61 62 6C 65 5F 68 65 78 28 29 rintable_hex()
|
||||
* </pre>
|
||||
* @return Printable, null terminated string.
|
||||
*/
|
||||
const char *get_printable_hex() const;
|
||||
|
||||
/**
|
||||
* Set the data on an already constructed OctetStr.
|
||||
* The given string is copied to an internal member var, so the
|
||||
* params can be destroyed afterwards.
|
||||
*
|
||||
* @param str - The new string value
|
||||
* @param len - Length of the given string
|
||||
*/
|
||||
void set_data(const unsigned char *str, unsigned long len);
|
||||
|
||||
/**
|
||||
* Get the length of the string.
|
||||
*/
|
||||
unsigned long len() const { return smival.value.string.len; };
|
||||
|
||||
/**
|
||||
* Get a pointer to internal data.
|
||||
*/
|
||||
unsigned char *data() const { return smival.value.string.ptr; };
|
||||
|
||||
// compare n elements of an octet
|
||||
int nCompare( const unsigned long n,
|
||||
const OctetStr &o) const;
|
||||
|
||||
/**
|
||||
* Build an OctetStr from a hex string.
|
||||
* Called with "5465 737469 6e672074686973206D657468 6f 64 21"
|
||||
* the returned value will be "Testing this method!"
|
||||
*
|
||||
* @param hex_string - The hex string (may contain spaces)
|
||||
* @return created string
|
||||
*/
|
||||
static OctetStr from_hex_string(const OctetStr &hex_string);
|
||||
|
||||
/**
|
||||
* Null out the contents of the string. The string will be empty
|
||||
* after calling this method
|
||||
*/
|
||||
void clear();
|
||||
|
||||
protected:
|
||||
|
||||
/*mutable*/ char *output_buffer; // formatted Octet value
|
||||
/*mutable*/ unsigned int output_buffer_len; // allocated space for outstring
|
||||
bool validity; // validity boolean
|
||||
};
|
||||
|
||||
//-----------[ End OctetStr Class ]-------------------------------------
|
||||
|
||||
/**
|
||||
* This class behaves exactly as the OctetStr class, beside the Syntax
|
||||
* of this class is sNMP_SYNTAX_OPAQUE.
|
||||
*/
|
||||
class OpaqueStr: public OctetStr
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor creating a valid zero length OpaqueStr.
|
||||
*/
|
||||
OpaqueStr(): OctetStr()
|
||||
{ smival.syntax = sNMP_SYNTAX_OPAQUE; };
|
||||
|
||||
/**
|
||||
* Constructs a OpaqueStr with the given value.
|
||||
* The OpaqueStr will be valid unless a call to new fails.
|
||||
*
|
||||
* @param str - Null terminated string
|
||||
*/
|
||||
OpaqueStr(const char *str) : OctetStr(str)
|
||||
{ smival.syntax = sNMP_SYNTAX_OPAQUE; };
|
||||
|
||||
/**
|
||||
* Constructs a OpaqueStr with the given value.
|
||||
* The OpaqueStr will be valid unless a call to new fails.
|
||||
*
|
||||
* @param str - string that may contain null bytes
|
||||
* @param len - length of the string
|
||||
*/
|
||||
OpaqueStr( const unsigned char *str, unsigned long len)
|
||||
: OctetStr(str, len) { smival.syntax = sNMP_SYNTAX_OPAQUE; };
|
||||
|
||||
/**
|
||||
* Construct a OpaqueStr from an OctetStr.
|
||||
* The OpaqueStr will be valid unless a call to new fails.
|
||||
*
|
||||
* @param octet - Value for the new object
|
||||
*/
|
||||
OpaqueStr( const OctetStr &octet) : OctetStr(octet)
|
||||
{ smival.syntax = sNMP_SYNTAX_OPAQUE; };
|
||||
|
||||
/**
|
||||
* Construct a OpaqueStr from another OpaqueStr.
|
||||
* The OpaqueStr will be valid unless a call to new fails.
|
||||
*
|
||||
* @param opaque - Value for the new object
|
||||
*/
|
||||
OpaqueStr( const OpaqueStr& opaque) : OctetStr(opaque)
|
||||
{ smival.syntax = sNMP_SYNTAX_OPAQUE; };
|
||||
|
||||
/**
|
||||
* Clone this object.
|
||||
*
|
||||
* @return Pointer to the newly created object (allocated through new).
|
||||
*/
|
||||
virtual SnmpSyntax *clone() const { return new OpaqueStr(*this); }
|
||||
|
||||
/**
|
||||
* Return the syntax.
|
||||
*
|
||||
* @return This method always returns sNMP_SYNTAX_OPAQUE.
|
||||
*/
|
||||
virtual SmiUINT32 get_syntax() const { return sNMP_SYNTAX_OPAQUE; };
|
||||
|
||||
/**
|
||||
* Map other SnmpSyntax objects to OpaqueStr.
|
||||
*/
|
||||
SnmpSyntax& operator=(const SnmpSyntax &val)
|
||||
{ return OctetStr::operator=(val); }
|
||||
|
||||
};
|
||||
|
||||
#endif // _OCTET_CLS
|
741
backend/camembert/libkmsnmp/oid.cpp
Normal file
741
backend/camembert/libkmsnmp/oid.cpp
Normal file
@ -0,0 +1,741 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## oid.cpp
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
/*===================================================================
|
||||
|
||||
Copyright (c) 1999
|
||||
Hewlett-Packard Company
|
||||
|
||||
ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
Permission to use, copy, modify, distribute and/or sell this software
|
||||
and/or its documentation is hereby granted without fee. User agrees
|
||||
to display the above copyright notice and this license notice in all
|
||||
copies of the software and any documentation of the software. User
|
||||
agrees to assume all liability for the use of the software; Hewlett-Packard
|
||||
makes no representations about the suitability of this software for any
|
||||
purpose. It is provided "AS-IS" without warranty of any kind,either express
|
||||
or implied. User hereby grants a royalty-free license to any and all
|
||||
derivatives based upon this software code base.
|
||||
|
||||
|
||||
|
||||
O I D. C P P
|
||||
|
||||
OID CLASS IMPLEMENTATION
|
||||
|
||||
DESIGN + AUTHOR:
|
||||
Peter E. Mellquist
|
||||
|
||||
DESCRIPTION:
|
||||
This module contains the implementation of the oid class. This
|
||||
includes all protected and public member functions. The oid class
|
||||
may be compiled stand alone without the use of any other library.
|
||||
|
||||
LANGUAGE:
|
||||
ANSI C++
|
||||
|
||||
OPERATING SYSTEM(S):
|
||||
MS-Windows Win32
|
||||
BSD UNIX
|
||||
|
||||
|
||||
=====================================================================*/
|
||||
char oid_cpp_version[]="#(@) SNMP++ $Id: oid.cpp,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $";
|
||||
|
||||
//---------[ external C libaries used ]--------------------------------
|
||||
#include <stdio.h> // standard io
|
||||
#include <memory.h> // memcpy's
|
||||
#include <string.h> // strlen, etc..
|
||||
#include <stdlib.h> // standard library
|
||||
#include <ctype.h> // isdigit
|
||||
#include <stdlib.h> // malloc, free
|
||||
|
||||
#include "oid.h" // include def for oid class
|
||||
|
||||
#define SNMPBUFFSIZE 11 // size of scratch buffer
|
||||
#define SNMPCHARSIZE 11 // an individual oid instance as a string
|
||||
|
||||
/* Borlands isdigit has a bug */
|
||||
#ifdef __BCPLUSPLUS__
|
||||
#define my_isdigit(c) ((c) >= '0' && (c) <= '9')
|
||||
#else
|
||||
#define my_isdigit isdigit
|
||||
#endif
|
||||
|
||||
//=============[Oid::Oid(void)]============================================
|
||||
// constructor using no arguments
|
||||
// initialize octet ptr and string
|
||||
// ptr to null
|
||||
Oid::Oid()
|
||||
: iv_str(0)
|
||||
{
|
||||
smival.syntax = sNMP_SYNTAX_OID;
|
||||
smival.value.oid.len = 0;
|
||||
smival.value.oid.ptr = 0;
|
||||
}
|
||||
|
||||
|
||||
//=============[Oid::Oid(const char *dotted_string ]=====================
|
||||
// constructor using a dotted string
|
||||
//
|
||||
// do a string to oid using the string passed in
|
||||
Oid::Oid(const char *dotted_oid_string)
|
||||
: iv_str(0)
|
||||
{
|
||||
smival.syntax = sNMP_SYNTAX_OID;
|
||||
smival.value.oid.len = 0;
|
||||
smival.value.oid.ptr = 0;
|
||||
StrToOid(dotted_oid_string, &smival.value.oid);
|
||||
}
|
||||
|
||||
|
||||
//=============[Oid::Oid(const Oid &oid) ]================================
|
||||
// constructor using another oid object
|
||||
//
|
||||
// do an oid copy using the oid object passed in
|
||||
Oid::Oid(const Oid &oid)
|
||||
: iv_str(0)
|
||||
{
|
||||
smival.syntax = sNMP_SYNTAX_OID;
|
||||
smival.value.oid.len = 0;
|
||||
smival.value.oid.ptr = 0;
|
||||
|
||||
// allocate some memory for the oid
|
||||
// in this case the size to allocate is the same size as the source oid
|
||||
if (oid.smival.value.oid.len)
|
||||
{
|
||||
smival.value.oid.ptr = (SmiLPUINT32) new unsigned long[oid.smival.value.oid.len];
|
||||
if (smival.value.oid.ptr)
|
||||
OidCopy((SmiLPOID)&(oid.smival.value.oid), (SmiLPOID)&smival.value.oid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//=============[Oid::Oid(const unsigned long *raw_oid, int oid_len) ]====
|
||||
// constructor using raw numeric form
|
||||
//
|
||||
// copy the integer values into the private member
|
||||
Oid::Oid(const unsigned long *raw_oid, int oid_len)
|
||||
: iv_str(0)
|
||||
{
|
||||
smival.syntax = sNMP_SYNTAX_OID;
|
||||
smival.value.oid.len = 0;
|
||||
smival.value.oid.ptr = 0;
|
||||
|
||||
if (raw_oid && (oid_len > 0))
|
||||
{
|
||||
smival.value.oid.ptr = (SmiLPUINT32) new unsigned long[oid_len];
|
||||
if (smival.value.oid.ptr)
|
||||
{
|
||||
smival.value.oid.len = oid_len;
|
||||
for (int i=0; i < oid_len; i++)
|
||||
smival.value.oid.ptr[i] = raw_oid[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//=============[Oid::~Oid]==============================================
|
||||
Oid::~Oid()
|
||||
{
|
||||
delete_oid_ptr();
|
||||
if (iv_str) delete [] iv_str; // free up the output string
|
||||
}
|
||||
|
||||
|
||||
//=============[Oid::operator = const char * dotted_string ]==============
|
||||
// assignment to a string operator overloaded
|
||||
//
|
||||
// free the existing oid
|
||||
// create the new oid from the string
|
||||
// return this object
|
||||
Oid& Oid::operator=(const char *dotted_oid_string)
|
||||
{
|
||||
delete_oid_ptr();
|
||||
|
||||
// assign the new value
|
||||
StrToOid(dotted_oid_string, &smival.value.oid);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//=============[Oid:: operator = const Oid &oid ]==========================
|
||||
// assignment to another oid object overloaded
|
||||
//
|
||||
// free the existing oid
|
||||
// create a new one from the object passed in
|
||||
Oid& Oid::operator=(const Oid &oid)
|
||||
{
|
||||
if (this == &oid) return *this; // protect against assignment from self
|
||||
|
||||
delete_oid_ptr();
|
||||
|
||||
// check for zero len on source
|
||||
if (oid.smival.value.oid.len == 0)
|
||||
return *this;
|
||||
|
||||
// allocate some memory for the oid
|
||||
smival.value.oid.ptr = (SmiLPUINT32) new unsigned long[oid.smival.value.oid.len];
|
||||
if (smival.value.oid.ptr)
|
||||
OidCopy((SmiLPOID)&(oid.smival.value.oid), (SmiLPOID)&smival.value.oid);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//==============[Oid:: operator += const char *a ]=========================
|
||||
// append operator, appends a string
|
||||
//
|
||||
// allocate some space for a max oid string
|
||||
// extract current string into space
|
||||
// concat new string
|
||||
// free up existing oid
|
||||
// make a new oid from string
|
||||
// delete allocated space
|
||||
Oid& Oid::operator+=(const char *a)
|
||||
{
|
||||
unsigned long n;
|
||||
|
||||
if (!a) return *this;
|
||||
|
||||
if (*a == '.') ++a;
|
||||
|
||||
n = (smival.value.oid.len * SNMPCHARSIZE) + (smival.value.oid.len)
|
||||
+ 1 + STRLEN(a);
|
||||
char *ptr = new char[n];
|
||||
if (ptr)
|
||||
{
|
||||
OidToStr(&smival.value.oid, n, ptr);
|
||||
if (ptr[0])
|
||||
STRCAT(ptr,".");
|
||||
STRCAT(ptr,a);
|
||||
if (smival.value.oid.len)
|
||||
{
|
||||
delete [] smival.value.oid.ptr;
|
||||
smival.value.oid.len = 0;
|
||||
}
|
||||
StrToOid(ptr, &smival.value.oid);
|
||||
delete [] ptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
//=============[ int operator == oid,oid ]=================================
|
||||
// equivlence operator overloaded
|
||||
int operator==(const Oid &lhs, const Oid &rhs)
|
||||
{
|
||||
// ensure same len, then use nCompare
|
||||
if (rhs.len() != lhs.len()) return 0;
|
||||
return (lhs.nCompare(rhs.len(), rhs) == 0);
|
||||
}
|
||||
|
||||
//==============[ operator!=(Oid &x,Oid &y) ]=============================
|
||||
//not equivlence operator overloaded
|
||||
int operator!=(const Oid &lhs, const Oid &rhs)
|
||||
{
|
||||
return (!(lhs==rhs)); // just invert ==
|
||||
}
|
||||
|
||||
//==============[ operator<(Oid &x,Oid &y) ]=============================
|
||||
// less than < overloaded
|
||||
int operator<(const Oid &lhs, const Oid &rhs)
|
||||
{
|
||||
int result;
|
||||
// call nCompare with the current
|
||||
// Oidx, Oidy and len of Oidx
|
||||
if((result = lhs.nCompare(rhs.len(), rhs))<0) return 1;
|
||||
if (result > 0) return 0;
|
||||
|
||||
// if here, equivalent substrings, call the shorter one <
|
||||
return (lhs.len() < rhs.len());
|
||||
}
|
||||
|
||||
//==============[ operator<=(Oid &x,Oid &y) ]=============================
|
||||
// less than <= overloaded
|
||||
int operator<=(const Oid &x, const Oid &y)
|
||||
{
|
||||
return ((x<y) || (x==y));
|
||||
}
|
||||
|
||||
//==============[ operator>(Oid &x,Oid &y) ]=============================
|
||||
// greater than > overloaded
|
||||
int operator>(const Oid &x, const Oid &y)
|
||||
{
|
||||
return (!(x<=y)); // just invert existing <=
|
||||
}
|
||||
|
||||
//==============[ operator==(Oid &x,char *) ]=============================
|
||||
// equivlence operator overloaded
|
||||
int operator==(const Oid &x, const char *dotted_oid_string)
|
||||
{
|
||||
Oid to(dotted_oid_string); // create a temp oid object
|
||||
return (x == to); // compare using existing operator
|
||||
}
|
||||
|
||||
//==============[ operator!=(Oid &x,char*) ]=============================
|
||||
// not equivlence operator overloaded
|
||||
int operator!=(const Oid &x, const char *dotted_oid_string)
|
||||
{
|
||||
Oid to(dotted_oid_string); // create a temp oid object
|
||||
return (x != to); // compare using existing operator
|
||||
}
|
||||
|
||||
//==============[ operator<(Oid &x,char*) ]=============================
|
||||
// less than < operator overloaded
|
||||
int operator<(const Oid &x, const char *dotted_oid_string)
|
||||
{
|
||||
Oid to(dotted_oid_string); // create a temp oid object
|
||||
return (x < to); // compare using existing operator
|
||||
}
|
||||
|
||||
//==============[ operator<=(Oid &x,char *) ]=============================
|
||||
// less than <= operator overloaded
|
||||
int operator<=(const Oid &x,char *dotted_oid_string)
|
||||
{
|
||||
Oid to(dotted_oid_string); // create a temp oid object
|
||||
return (x <= to); // compare using existing operator
|
||||
}
|
||||
|
||||
//==============[ operator>(Oid &x,char* ]=============================
|
||||
// greater than > operator overloaded
|
||||
int operator>(const Oid &x,const char *dotted_oid_string)
|
||||
{
|
||||
Oid to(dotted_oid_string); // create a temp oid object
|
||||
return (x > to); // compare using existing operator
|
||||
}
|
||||
|
||||
//==============[ operator>=(Oid &x,char*) ]=============================
|
||||
// greater than >= operator overloaded
|
||||
int operator>=(const Oid &x,const char *dotted_oid_string)
|
||||
{
|
||||
Oid to(dotted_oid_string); // create a temp oid object
|
||||
return (x >= to); // compare using existing operator
|
||||
}
|
||||
|
||||
//===============[Oid::set_data ]==---=====================================
|
||||
// copy data from raw form...
|
||||
void Oid::set_data(const unsigned long *raw_oid,
|
||||
const unsigned int oid_len)
|
||||
{
|
||||
if (smival.value.oid.len < oid_len)
|
||||
{
|
||||
delete_oid_ptr();
|
||||
|
||||
smival.value.oid.ptr = (SmiLPUINT32) new unsigned long[oid_len];
|
||||
if (!smival.value.oid.ptr) return;
|
||||
}
|
||||
MEMCPY((SmiLPBYTE) smival.value.oid.ptr,
|
||||
(SmiLPBYTE) raw_oid,
|
||||
(size_t) (oid_len*sizeof(SmiUINT32)));
|
||||
smival.value.oid.len = oid_len;
|
||||
}
|
||||
|
||||
|
||||
//===============[Oid::trim(unsigned int) ]============================
|
||||
// trim off the n leftmost values of an oid
|
||||
// Note!, does not adjust actual space for
|
||||
// speed
|
||||
void Oid::trim(const unsigned long n)
|
||||
{
|
||||
// verify that n is legal
|
||||
if ((n <= smival.value.oid.len) && (n > 0))
|
||||
{
|
||||
smival.value.oid.len -= n;
|
||||
if (smival.value.oid.len == 0)
|
||||
delete_oid_ptr();
|
||||
}
|
||||
}
|
||||
|
||||
//===============[Oid::operator += const unsigned int) ]====================
|
||||
// append operator, appends an int
|
||||
//
|
||||
Oid& Oid::operator+=(const unsigned long i)
|
||||
{
|
||||
Oid other(&i, 1);
|
||||
(*this) += other;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//===============[Oid::operator += const Oid) ]========================
|
||||
// append operator, appends an Oid
|
||||
//
|
||||
// allocate some space for a max oid string
|
||||
// extract current string into space
|
||||
// concat new string
|
||||
// free up existing oid
|
||||
// make a new oid from string
|
||||
// delete allocated space
|
||||
Oid& Oid::operator+=(const Oid &o)
|
||||
{
|
||||
SmiLPUINT32 new_oid;
|
||||
|
||||
if (o.smival.value.oid.len == 0)
|
||||
return *this;
|
||||
|
||||
new_oid = (SmiLPUINT32) new unsigned long[smival.value.oid.len + o.smival.value.oid.len];
|
||||
if (new_oid == 0)
|
||||
{
|
||||
delete_oid_ptr();
|
||||
return *this;
|
||||
}
|
||||
|
||||
if (smival.value.oid.ptr)
|
||||
{
|
||||
MEMCPY((SmiLPBYTE) new_oid,
|
||||
(SmiLPBYTE) smival.value.oid.ptr,
|
||||
(size_t) (smival.value.oid.len*sizeof(SmiUINT32)));
|
||||
|
||||
delete [] smival.value.oid.ptr;
|
||||
}
|
||||
|
||||
// out with the old, in with the new...
|
||||
smival.value.oid.ptr = new_oid;
|
||||
|
||||
MEMCPY((SmiLPBYTE) &new_oid[smival.value.oid.len],
|
||||
(SmiLPBYTE) o.smival.value.oid.ptr,
|
||||
(size_t) (o.smival.value.oid.len*sizeof(SmiUINT32)));
|
||||
|
||||
smival.value.oid.len += o.smival.value.oid.len;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//==============[Oid::get_printable(unsigned int start, n) ]=============
|
||||
// return a dotted string starting at start,
|
||||
// going n positions to the left
|
||||
// NOTE, start is 1 based (the first id is at position #1)
|
||||
const char *Oid::get_printable(const unsigned long start,
|
||||
const unsigned long n) const
|
||||
{
|
||||
Oid *ncthis = PP_CONST_CAST(Oid*, this);
|
||||
char *&nc_iv_str = ncthis->iv_str;
|
||||
unsigned long nz;
|
||||
unsigned long my_start = start - 1;
|
||||
unsigned long my_end = my_start + n;
|
||||
|
||||
nz = (smival.value.oid.len * (SNMPCHARSIZE + 1)) + 1;
|
||||
|
||||
if (iv_str) delete [] iv_str; // delete the previous output string
|
||||
|
||||
nc_iv_str = new char[nz]; // allocate some space for the output string
|
||||
if (iv_str == 0)
|
||||
return 0;
|
||||
|
||||
nc_iv_str[0] = 0; // init the string
|
||||
|
||||
// cannot ask for more than there is..
|
||||
if ((my_start < 0) || (my_end > smival.value.oid.len))
|
||||
return nc_iv_str;
|
||||
|
||||
char *cur_ptr = nc_iv_str;
|
||||
bool first = true;
|
||||
|
||||
// loop through and build up a string
|
||||
for (unsigned long index = my_start; index < my_end; ++index)
|
||||
{
|
||||
// if not at begin, pad with a dot
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
*cur_ptr++ = '.';
|
||||
|
||||
// convert data element to a string
|
||||
cur_ptr += sprintf(cur_ptr, "%lu", smival.value.oid.ptr[index]);
|
||||
}
|
||||
return nc_iv_str;
|
||||
}
|
||||
|
||||
|
||||
//=============[Oid::StrToOid(char *string, SmiLPOID dst) ]==============
|
||||
// convert a string to an oid
|
||||
int Oid::StrToOid(const char *str, SmiLPOID dstOid)
|
||||
{
|
||||
unsigned long index = 0;
|
||||
|
||||
// make a temp buffer to copy the data into first
|
||||
SmiLPUINT32 temp;
|
||||
unsigned long nz;
|
||||
|
||||
if (str && *str)
|
||||
{
|
||||
nz = STRLEN(str);
|
||||
}
|
||||
else
|
||||
{
|
||||
dstOid->len = 0;
|
||||
dstOid->ptr = 0;
|
||||
return -1;
|
||||
}
|
||||
temp = (SmiLPUINT32) new unsigned long[nz];
|
||||
|
||||
if (temp == 0) return -1; // return if can't get the mem
|
||||
|
||||
while ((*str) && (index < nz))
|
||||
{
|
||||
unsigned long number = 0;
|
||||
// skip over the dot
|
||||
if (*str == '.') ++str;
|
||||
|
||||
// grab a digit token and convert it to a long int
|
||||
while (my_isdigit(*str))
|
||||
number = (number * 10) + *(str++) - '0';
|
||||
|
||||
// check for invalid chars
|
||||
if ((*str) && (*str != '.'))
|
||||
{
|
||||
// found String -> converting it into an oid
|
||||
if ((*str) && (*str == '$'))
|
||||
{
|
||||
++str;
|
||||
while ((*str) && (*str != '$')) {
|
||||
temp[index] = (unsigned char)*str;
|
||||
++str;
|
||||
++index;
|
||||
}
|
||||
// skip over the $
|
||||
if (*str) ++str;
|
||||
continue;
|
||||
}
|
||||
delete [] temp;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// stuff the value into the array and bump the counter
|
||||
temp[index++] = number;
|
||||
}
|
||||
|
||||
// get some space for the real oid
|
||||
dstOid->ptr = (SmiLPUINT32) new unsigned long[index];
|
||||
// return if can't get the mem needed
|
||||
if(dstOid->ptr == 0)
|
||||
{
|
||||
delete [] temp;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// copy in the temp data
|
||||
MEMCPY((SmiLPBYTE) dstOid->ptr,
|
||||
(SmiLPBYTE) temp,
|
||||
(size_t) (index*sizeof(SmiUINT32)));
|
||||
|
||||
// set the len of the oid
|
||||
dstOid->len = index;
|
||||
|
||||
// free up temp data
|
||||
delete [] temp;
|
||||
|
||||
return (int) index;
|
||||
}
|
||||
|
||||
|
||||
//===============[Oid::OidCopy(source, destination) ]====================
|
||||
// Copy an oid
|
||||
int Oid::OidCopy(SmiLPOID srcOid, SmiLPOID dstOid)
|
||||
{
|
||||
// check source len ! zero
|
||||
if (srcOid->len == 0) return -1;
|
||||
|
||||
// copy source to destination
|
||||
MEMCPY((SmiLPBYTE) dstOid->ptr,
|
||||
(SmiLPBYTE) srcOid->ptr,
|
||||
(size_t) (srcOid->len*sizeof(SmiUINT32)));
|
||||
|
||||
//set the new len
|
||||
dstOid->len = srcOid->len;
|
||||
return (int) srcOid->len;
|
||||
}
|
||||
|
||||
|
||||
//===============[Oid::nCompare(n, Oid) ]=================================
|
||||
// compare the n leftmost values of two oids (left-to_right )
|
||||
//
|
||||
// self == Oid then return 0, they are equal
|
||||
// self < Oid then return -1, <
|
||||
// self > Oid then return 1, >
|
||||
int Oid::nCompare(const unsigned long n,
|
||||
const Oid &o) const
|
||||
{
|
||||
unsigned long length = n;
|
||||
bool reduced_len = false;
|
||||
|
||||
// If both oids are too short, decrease len
|
||||
while ((smival.value.oid.len < length) && (o.smival.value.oid.len < length))
|
||||
length--;
|
||||
|
||||
if (length == 0) return 0; // equal
|
||||
|
||||
// only compare for the minimal length
|
||||
if (length > smival.value.oid.len)
|
||||
{
|
||||
length = smival.value.oid.len;
|
||||
reduced_len = true;
|
||||
}
|
||||
if (length > o.smival.value.oid.len)
|
||||
{
|
||||
length = o.smival.value.oid.len;
|
||||
reduced_len = true;
|
||||
}
|
||||
|
||||
unsigned long z = 0;
|
||||
while (z < length)
|
||||
{
|
||||
if (smival.value.oid.ptr[z] < o.smival.value.oid.ptr[z])
|
||||
return -1; // less than
|
||||
if (smival.value.oid.ptr[z] > o.smival.value.oid.ptr[z])
|
||||
return 1; // greater than
|
||||
++z;
|
||||
}
|
||||
|
||||
// if we truncated the len then these may not be equal
|
||||
if (reduced_len)
|
||||
{
|
||||
if (smival.value.oid.len < o.smival.value.oid.len) return -1;
|
||||
if (smival.value.oid.len > o.smival.value.oid.len) return 1;
|
||||
}
|
||||
return 0; // equal
|
||||
}
|
||||
|
||||
|
||||
//===============[Oid::nCompare(n, Oid) ]=================================
|
||||
// compare the n rightmost bytes (right-to-left)
|
||||
// returns 0, equal
|
||||
// returns -1, <
|
||||
// returns 1 , >
|
||||
int Oid::RnCompare(const unsigned long n, const Oid &o) const
|
||||
{
|
||||
unsigned long nz = n;
|
||||
|
||||
// If both oids are too short, decrease nz
|
||||
while ((len() < nz) && (o.len() < nz))
|
||||
nz--;
|
||||
|
||||
// oid to compare must have at least the same number of sub-ids to
|
||||
// comparison else the argument Oid is less than THIS
|
||||
if (o.len() < nz) return -1;
|
||||
|
||||
// also can't compare argument oid for sub-ids which THIS does not have
|
||||
if (len() < nz) return -1;
|
||||
|
||||
int start = (int) (len() -1);
|
||||
int end = (int) start - (int) nz;
|
||||
for (int z = start; z > end; z--)
|
||||
{
|
||||
// printf("s: %i e: %i z: %i o: %i, this: %i\n",
|
||||
// start, end, z, o.smival.value.oid.ptr[z],this->smival.value.oid.ptr[z]);
|
||||
if (smival.value.oid.ptr[z] < o.smival.value.oid.ptr[z]) return -1;
|
||||
if (smival.value.oid.ptr[z] > o.smival.value.oid.ptr[z]) return 1;
|
||||
}
|
||||
return 0; // they are equal
|
||||
}
|
||||
|
||||
|
||||
//================[Oid::OidToStr ]=========================================
|
||||
// convert an oid to a string
|
||||
int Oid::OidToStr(const SmiOID *srcOid,
|
||||
SmiUINT32 size,
|
||||
char *str) const
|
||||
{
|
||||
unsigned totLen = 0;
|
||||
char szNumber[SNMPBUFFSIZE];
|
||||
int cur_len;
|
||||
|
||||
str[0] = 0; // init the string
|
||||
|
||||
// verify there is something to copy
|
||||
if (srcOid->len == 0)
|
||||
return -1;
|
||||
|
||||
// loop through and build up a string
|
||||
for (unsigned long index = 0; index < srcOid->len; ++index)
|
||||
{
|
||||
// convert data element to a string
|
||||
cur_len = sprintf(szNumber, "%lu", srcOid->ptr[index]);
|
||||
|
||||
// verify len is not over
|
||||
if (totLen + cur_len + 1 >= size)
|
||||
return -2;
|
||||
|
||||
// if not at begin, pad with a dot
|
||||
if (totLen)
|
||||
str[totLen++] = '.';
|
||||
|
||||
// copy the string token into the main string
|
||||
STRCPY(str + totLen, szNumber);
|
||||
|
||||
// adjust the total len
|
||||
totLen += cur_len;
|
||||
}
|
||||
return totLen+1;
|
||||
}
|
||||
|
||||
|
||||
//================[ general Value = operator ]========================
|
||||
SnmpSyntax& Oid::operator=(const SnmpSyntax &val)
|
||||
{
|
||||
if (this == &val) return *this; // protect against assignment from self
|
||||
|
||||
delete_oid_ptr();
|
||||
|
||||
// assign new value
|
||||
if (val.valid())
|
||||
{
|
||||
switch (val.get_syntax())
|
||||
{
|
||||
case sNMP_SYNTAX_OID:
|
||||
set_data(((Oid &)val).smival.value.oid.ptr,
|
||||
(unsigned int)((Oid &)val).smival.value.oid.len);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
int Oid::get_asn1_length() const
|
||||
{
|
||||
int length = 1; // for first 2 subids
|
||||
|
||||
for (unsigned int i = 2; i < smival.value.oid.len; ++i)
|
||||
{
|
||||
unsigned long v = smival.value.oid.ptr[i];
|
||||
|
||||
if (v < 0x80) // 7 bits long subid
|
||||
length += 1;
|
||||
else if (v < 0x4000) // 14 bits long subid
|
||||
length += 2;
|
||||
else if (v < 0x200000) // 21 bits long subid
|
||||
length += 3;
|
||||
else if (v < 0x10000000) // 28 bits long subid
|
||||
length += 4;
|
||||
else // 32 bits long subid
|
||||
length += 5;
|
||||
}
|
||||
|
||||
if (length < 128)
|
||||
return length + 2;
|
||||
else if (length < 256)
|
||||
return length + 3;
|
||||
return length + 4;
|
||||
}
|
419
backend/camembert/libkmsnmp/oid.h
Normal file
419
backend/camembert/libkmsnmp/oid.h
Normal file
@ -0,0 +1,419 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## oid.h
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
/*===================================================================
|
||||
|
||||
Copyright (c) 1999
|
||||
Hewlett-Packard Company
|
||||
|
||||
ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
Permission to use, copy, modify, distribute and/or sell this software
|
||||
and/or its documentation is hereby granted without fee. User agrees
|
||||
to display the above copyright notice and this license notice in all
|
||||
copies of the software and any documentation of the software. User
|
||||
agrees to assume all liability for the use of the software; Hewlett-Packard
|
||||
makes no representations about the suitability of this software for any
|
||||
purpose. It is provided "AS-IS without warranty of any kind,either express
|
||||
or implied. User hereby grants a royalty-free license to any and all
|
||||
derivatives based upon this software code base.
|
||||
|
||||
|
||||
SNMP++ O I D. H
|
||||
|
||||
OID CLASS DEFINITION
|
||||
|
||||
DESIGN + AUTHOR:
|
||||
Peter E Mellquist
|
||||
|
||||
LANGUAGE:
|
||||
ANSI C++
|
||||
|
||||
OPERATING SYSTEMS:
|
||||
MS-Windows Win32
|
||||
BSD UNIX
|
||||
|
||||
DESCRIPTION:
|
||||
This class is fully contained and does not rely on or any other
|
||||
SNMP libraries. This class is portable across any platform
|
||||
which supports C++.
|
||||
|
||||
=====================================================================*/
|
||||
// $Id: oid.h,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $
|
||||
|
||||
#ifndef _OID_H_
|
||||
#define _OID_H_
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
#include "smival.h" // derived class for all values
|
||||
#include "collect.h"
|
||||
|
||||
/**
|
||||
* The Object Identifier Class.
|
||||
*
|
||||
* The Object Identification (Oid) class is the encapsulation of an
|
||||
* SMI object identifier. The SMI object is a data identifier for a
|
||||
* data element found in a Management Information Base (MIB), as
|
||||
* defined by a MIB definition. The SMI Oid, its related structures
|
||||
* and functions, are a natural fit for object orientation. In fact,
|
||||
* the Oid class shares many common features to the C++ String
|
||||
* class. For those of you familiar with the C++ String class or
|
||||
* Microsoft's Foundation Classes (MFC) CString class, the Oid class
|
||||
* will be familiar and easy to use. The Oid class is designed to be
|
||||
* efficient and fast. The Oid class allows definition and
|
||||
* manipulation of object identifiers.
|
||||
*/
|
||||
class DLLOPT Oid : public SnmpSyntax
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Construct an invalid Oid.
|
||||
*/
|
||||
Oid();
|
||||
|
||||
/**
|
||||
* Construct an Oid from a dotted string.
|
||||
*
|
||||
* @param dotted_oid_string - for example "1.3.1.6.1.10"
|
||||
*/
|
||||
Oid(const char *dotted_oid_string);
|
||||
|
||||
/**
|
||||
* Constructor using another oid object (copy constructor).
|
||||
*
|
||||
* @param oid - Source Oid
|
||||
*/
|
||||
Oid (const Oid &oid);
|
||||
|
||||
/**
|
||||
* Constructor from array.
|
||||
*
|
||||
* @param raw_oid - array of oid values
|
||||
* @param oid_len - length of array
|
||||
*/
|
||||
Oid(const unsigned long *raw_oid, int oid_len);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
virtual ~Oid();
|
||||
|
||||
/**
|
||||
* Return the current syntax.
|
||||
*
|
||||
* @return always sNMP_SYNTAX_OID
|
||||
*/
|
||||
SmiUINT32 get_syntax() const { return sNMP_SYNTAX_OID; };
|
||||
|
||||
/**
|
||||
* Assignment from a string.
|
||||
*
|
||||
* @param dotted_oid_string - New value (for example "1.3.6.1.6.0");
|
||||
*/
|
||||
virtual Oid& operator=(const char *dotted_oid_string);
|
||||
|
||||
/**
|
||||
* Assign one Oid to another.
|
||||
*/
|
||||
virtual Oid& operator=(const Oid &oid);
|
||||
|
||||
/**
|
||||
* Return the space needed for serialization.
|
||||
*/
|
||||
int get_asn1_length() const;
|
||||
|
||||
/**
|
||||
* Overloaded equal operator.
|
||||
*/
|
||||
DLLOPT friend int operator==(const Oid &lhs, const Oid &rhs);
|
||||
|
||||
/**
|
||||
* Overloaded not equal operator.
|
||||
*/
|
||||
DLLOPT friend int operator!=(const Oid &lhs, const Oid &rhs);
|
||||
|
||||
/**
|
||||
* Overloaded less than < operator.
|
||||
*/
|
||||
DLLOPT friend int operator<(const Oid &lhs, const Oid &rhs);
|
||||
|
||||
/**
|
||||
* Overloaded less than <= operator.
|
||||
*/
|
||||
DLLOPT friend int operator<=(const Oid &lhs, const Oid &rhs);
|
||||
|
||||
/**
|
||||
* Overloaded greater than > operator.
|
||||
*/
|
||||
DLLOPT friend int operator>(const Oid &lhs, const Oid &rhs);
|
||||
|
||||
/**
|
||||
* Overloaded greater than >= operator.
|
||||
*/
|
||||
DLLOPT friend int operator>=(const Oid &lhs, const Oid &rhs);
|
||||
|
||||
/**
|
||||
* Overloaded equal operator operator.
|
||||
*/
|
||||
DLLOPT friend int operator==(const Oid &lhs, const char *rhs);
|
||||
|
||||
/**
|
||||
* Overloaded not equal operator.
|
||||
*/
|
||||
DLLOPT friend int operator!=(const Oid &lhs, const char *rhs);
|
||||
|
||||
/**
|
||||
* Overloaded less than < operator.
|
||||
*/
|
||||
DLLOPT friend int operator<(const Oid &lhs, const char *rhs);
|
||||
|
||||
/**
|
||||
* Overloaded less than <= operator.
|
||||
*/
|
||||
DLLOPT friend int operator<=(const Oid &lhs, char *rhs);
|
||||
|
||||
/**
|
||||
* Overloaded greater than > operator.
|
||||
*/
|
||||
DLLOPT friend int operator>(const Oid &lhs, const char *rhs);
|
||||
|
||||
/**
|
||||
* Overloaded greater than >= operator.
|
||||
*/
|
||||
DLLOPT friend int operator>=(const Oid &lhs, const char *rhs);
|
||||
|
||||
/**
|
||||
* Overloaded operator +, Concatenate two Oids.
|
||||
*/
|
||||
DLLOPT friend Oid operator +(const Oid &lhs, const Oid &rhs)
|
||||
{ Oid tmp(lhs); tmp += rhs; return tmp;};
|
||||
|
||||
/**
|
||||
* Append operator, appends the dotted oid string.
|
||||
*
|
||||
* @param a - dotted oid string, for example "5.192.14.6"
|
||||
*/
|
||||
Oid& operator+=(const char *a);
|
||||
|
||||
/**
|
||||
* Appends an int.
|
||||
*
|
||||
* @param i - Value to add at the end of the Oid
|
||||
*/
|
||||
Oid& operator+=(const unsigned long i);
|
||||
|
||||
/**
|
||||
* Appends an Oid.
|
||||
*
|
||||
* @param o - Oid to add at the end
|
||||
*/
|
||||
Oid& operator+=(const Oid &o);
|
||||
|
||||
/**
|
||||
* Allows element access as an array.
|
||||
* This method behaves like real array: if your position
|
||||
* is out of bounds, you're lost!
|
||||
*
|
||||
* @param position - valid position -- 0 to (len() - 1)
|
||||
*
|
||||
* @return Value on the given position
|
||||
*/
|
||||
unsigned long &operator[](int position)
|
||||
{ return smival.value.oid.ptr[position]; };
|
||||
|
||||
/**
|
||||
* Allows element access as an array for const objects.
|
||||
* This method behaves like real array: if your position
|
||||
* is out of bounds, you're lost!
|
||||
*
|
||||
* @param position - valid position -- 0 to (len() - 1)
|
||||
*
|
||||
* @return Value on the given position
|
||||
*/
|
||||
unsigned long operator[](int position) const
|
||||
{ return smival.value.oid.ptr[position]; };
|
||||
|
||||
/**
|
||||
* Get the WinSnmp oid part.
|
||||
* @note This method returns a pointer to internal data.
|
||||
* If it is modified, the Oid changes too.
|
||||
*
|
||||
* @return pointer to the internal oid structure.
|
||||
*/
|
||||
SmiLPOID oidval() { return (SmiLPOID) &smival.value.oid; };
|
||||
|
||||
/**
|
||||
* Set the data from raw form.
|
||||
*
|
||||
* @param raw_oid - Array of new values
|
||||
* @param oid_len - Length of the array raw_oid
|
||||
*/
|
||||
void set_data(const unsigned long *raw_oid, const unsigned int oid_len);
|
||||
|
||||
|
||||
/**
|
||||
* Get the length of the oid.
|
||||
*/
|
||||
unsigned long len() const { return smival.value.oid.len; };
|
||||
|
||||
/**
|
||||
* Trim off the rightmost values of an oid.
|
||||
*
|
||||
* @param n - Trim off n values from the right (default is one)
|
||||
*/
|
||||
void trim(const unsigned long n = 1);
|
||||
|
||||
/**
|
||||
* Compare two Oids from the left in direction left-to-right.
|
||||
*
|
||||
* @param n - Subvalues to compare
|
||||
* @param o - The Oid to compare with
|
||||
*
|
||||
* @return 0 if equal / -1 if less / 1 if greater
|
||||
*/
|
||||
int nCompare(const unsigned long n, const Oid &o) const;
|
||||
|
||||
/**
|
||||
* Compare two Oids from the right in direction right-to left.
|
||||
*
|
||||
* @param n - Subvalues to compare
|
||||
* @param o - The Oid to compare with
|
||||
*
|
||||
* @return 0 if equal / -1 if less / 1 if greater
|
||||
*/
|
||||
int RnCompare(const unsigned long n, const Oid &o) const;
|
||||
|
||||
/**
|
||||
* Return validity of the object.
|
||||
*/
|
||||
bool valid() const { return (smival.value.oid.ptr ? true : false); };
|
||||
|
||||
/**
|
||||
* Get a printable ASCII string of the whole value.
|
||||
*
|
||||
* @return Dotted oid string (for example "1.3.6.1.6.0")
|
||||
*/
|
||||
const char *get_printable() const
|
||||
{ return get_printable(1, smival.value.oid.len); };
|
||||
|
||||
/**
|
||||
* Get a printable ASCII string of the right part of the value.
|
||||
*
|
||||
* @param n - positions to print, counted from right.
|
||||
*
|
||||
* @return Dotted oid string (for example "6.0")
|
||||
*/
|
||||
const char *get_printable(const unsigned long n) const
|
||||
{ return get_printable(smival.value.oid.len - n + 1, n); };
|
||||
|
||||
/**
|
||||
* Get a printable ASCII string of a part of the value.
|
||||
*
|
||||
* @param start - First position to print, starting with 1 (not zero!)
|
||||
* @param n - positions to print.
|
||||
*
|
||||
* @return Dotted oid string (for example "3.6.1.6")
|
||||
*/
|
||||
const char *get_printable(const unsigned long start,
|
||||
const unsigned long n) const;
|
||||
|
||||
/**
|
||||
* Clone this object.
|
||||
*
|
||||
* @return Pointer to the newly created object (allocated through new).
|
||||
*/
|
||||
SnmpSyntax *clone() const { return (SnmpSyntax *) new Oid(*this); };
|
||||
|
||||
/**
|
||||
* Map other SnmpSyntax objects to Oid.
|
||||
*/
|
||||
SnmpSyntax& operator=(const SnmpSyntax &val);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Convert a string to an smi oid.
|
||||
*
|
||||
* @param string - input string
|
||||
* @param dstOid - destination oid
|
||||
*/
|
||||
virtual int StrToOid(const char *string, SmiLPOID dstOid);
|
||||
|
||||
/**
|
||||
* Clone an smi oid.
|
||||
*
|
||||
* @param srcOid - source oid
|
||||
* @param dstOid - destination oid
|
||||
*/
|
||||
virtual int OidCopy(SmiLPOID srcOid, SmiLPOID dstOid);
|
||||
|
||||
/**
|
||||
* Convert an smi oid to its string representation.
|
||||
*
|
||||
* @param srcOid - source oid
|
||||
* @param size - size of string
|
||||
* @param string - pointer to string
|
||||
*/
|
||||
virtual int OidToStr(const SmiOID *srcOid,
|
||||
SmiUINT32 size,
|
||||
char *string) const;
|
||||
|
||||
/**
|
||||
* Free the internal oid pointer and set the pointer and the length to zeor.
|
||||
*/
|
||||
inline void delete_oid_ptr();
|
||||
|
||||
//----[ instance variables ]
|
||||
|
||||
/*mutable*/ char *iv_str; // used for returning oid string
|
||||
};
|
||||
|
||||
//-----------[ End Oid Class ]-------------------------------------
|
||||
|
||||
// create OidCollection type
|
||||
typedef SnmpCollection <Oid> OidCollection;
|
||||
|
||||
inline void Oid::delete_oid_ptr()
|
||||
{
|
||||
// delete the old value
|
||||
if (smival.value.oid.ptr)
|
||||
{
|
||||
delete [] smival.value.oid.ptr;
|
||||
smival.value.oid.ptr = 0;
|
||||
}
|
||||
smival.value.oid.len = 0;
|
||||
};
|
||||
|
||||
//==============[ operator>=(Oid &x,Oid &y) ]=============================
|
||||
// greater than >= overloaded
|
||||
inline int operator>=(const Oid &x, const Oid &y)
|
||||
{
|
||||
return (!(x<y)); // just invert existing <
|
||||
}
|
||||
|
||||
#endif //_OID_H_
|
118
backend/camembert/libkmsnmp/oid_def.h
Normal file
118
backend/camembert/libkmsnmp/oid_def.h
Normal file
@ -0,0 +1,118 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## oid_def.h
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
/*===================================================================
|
||||
|
||||
Copyright (c) 1999
|
||||
Hewlett-Packard Company
|
||||
|
||||
ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
Permission to use, copy, modify, distribute and/or sell this software
|
||||
and/or its documentation is hereby granted without fee. User agrees
|
||||
to display the above copyright notice and this license notice in all
|
||||
copies of the software and any documentation of the software. User
|
||||
agrees to assume all liability for the use of the software; Hewlett-Packard
|
||||
makes no representations about the suitability of this software for any
|
||||
purpose. It is provided "AS-IS" without warranty of any kind,either express
|
||||
or implied. User hereby grants a royalty-free license to any and all
|
||||
derivatives based upon this software code base.
|
||||
|
||||
SNMP++ O I D _ D E F . H
|
||||
|
||||
OID_DEF DEFINITIONS
|
||||
|
||||
DESCRIPTION:
|
||||
Some common Oid definitions.
|
||||
|
||||
DESIGN + AUTHOR:
|
||||
Peter E Mellquist
|
||||
|
||||
LANGUAGE:
|
||||
ANSI C++
|
||||
|
||||
OPERATING SYSTEMS:
|
||||
DOS / Windows 3.1
|
||||
BSD UNIX
|
||||
|
||||
=====================================================================*/
|
||||
// $Id: oid_def.h,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $
|
||||
|
||||
#ifndef _OID_DEF
|
||||
#define _OID_DEF
|
||||
|
||||
#include "oid.h"
|
||||
|
||||
/** SMI trap oid def */
|
||||
class snmpTrapsOid: public Oid {
|
||||
public:
|
||||
DLLOPT snmpTrapsOid() : Oid("1.3.6.1.6.3.1.1.5") {};
|
||||
};
|
||||
|
||||
/** SMI Enterprose Oid */
|
||||
class snmpTrapEnterpriseOid: public Oid {
|
||||
public:
|
||||
DLLOPT snmpTrapEnterpriseOid() : Oid("1.3.6.1.6.3.1.1.4.3.0") {};
|
||||
};
|
||||
|
||||
/** SMI Cold Start Oid */
|
||||
class coldStartOid: public snmpTrapsOid {
|
||||
public:
|
||||
DLLOPT coldStartOid() { *this+=".1"; };
|
||||
};
|
||||
|
||||
/** SMI WarmStart Oid */
|
||||
class warmStartOid: public snmpTrapsOid {
|
||||
public:
|
||||
DLLOPT warmStartOid() { *this+=".2"; };
|
||||
};
|
||||
|
||||
/** SMI LinkDown Oid */
|
||||
class linkDownOid: public snmpTrapsOid {
|
||||
public:
|
||||
DLLOPT linkDownOid() { *this+=".3"; };
|
||||
};
|
||||
|
||||
/** SMI LinkUp Oid */
|
||||
class linkUpOid: public snmpTrapsOid {
|
||||
public:
|
||||
DLLOPT linkUpOid() { *this+=".4"; };
|
||||
};
|
||||
|
||||
/** SMI Authentication Failure Oid */
|
||||
class authenticationFailureOid: public snmpTrapsOid {
|
||||
public:
|
||||
DLLOPT authenticationFailureOid() { *this+=".5"; };
|
||||
};
|
||||
|
||||
/** SMI egpneighborloss Oid */
|
||||
class egpNeighborLossOid: public snmpTrapsOid {
|
||||
public:
|
||||
DLLOPT egpNeighborLossOid() { *this+=".6"; };
|
||||
};
|
||||
|
||||
#endif // _OID_DEF
|
413
backend/camembert/libkmsnmp/pdu.cpp
Normal file
413
backend/camembert/libkmsnmp/pdu.cpp
Normal file
@ -0,0 +1,413 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## pdu.cpp
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
/*===================================================================
|
||||
|
||||
Copyright (c) 1999
|
||||
Hewlett-Packard Company
|
||||
|
||||
ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
Permission to use, copy, modify, distribute and/or sell this software
|
||||
and/or its documentation is hereby granted without fee. User agrees
|
||||
to display the above copyright notice and this license notice in all
|
||||
copies of the software and any documentation of the software. User
|
||||
agrees to assume all liability for the use of the software; Hewlett-Packard
|
||||
makes no representations about the suitability of this software for any
|
||||
purpose. It is provided "AS-IS" without warranty of any kind,either express
|
||||
or implied. User hereby grants a royalty-free license to any and all
|
||||
derivatives based upon this software code base.
|
||||
|
||||
|
||||
|
||||
P D U . C P P
|
||||
|
||||
PDU CLASS IMPLEMENTATION
|
||||
|
||||
DESIGN + AUTHOR:
|
||||
Peter E Mellquist
|
||||
|
||||
LANGUAGE:
|
||||
ANSI C++
|
||||
|
||||
OPERATING SYSTEMS:
|
||||
MS-Windows Win32
|
||||
BSD UNIX
|
||||
|
||||
DESCRIPTION:
|
||||
Pdu class implementation. Encapsulation of an SMI Protocol
|
||||
Data Unit (PDU) in C++.
|
||||
|
||||
=====================================================================*/
|
||||
char pdu_cpp_version[]="@(#) SNMP++ $Id: pdu.cpp,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $";
|
||||
|
||||
#include "pdu.h" // include Pdu class definition
|
||||
#include "usm_v3.h"
|
||||
#include "vb.h"
|
||||
|
||||
//=====================[ constructor no args ]=========================
|
||||
Pdu::Pdu()
|
||||
: vb_count(0), error_status(0), error_index(0), validity(true),
|
||||
request_id(0), pdu_type(0), notify_timestamp(0), v1_trap_address_set(false)
|
||||
#ifdef _SNMPv3
|
||||
, security_level(SNMP_SECURITY_LEVEL_NOAUTH_NOPRIV),
|
||||
message_id(0), maxsize_scopedpdu(0)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
//=====================[ constructor with vbs and count ]==============
|
||||
Pdu::Pdu(Vb* pvbs, const int pvb_count)
|
||||
: vb_count(0), error_status(0), error_index(0), validity(true),
|
||||
request_id(0), pdu_type(0), notify_timestamp(0), v1_trap_address_set(false)
|
||||
#ifdef _SNMPv3
|
||||
, security_level(SNMP_SECURITY_LEVEL_NOAUTH_NOPRIV),
|
||||
message_id(0), maxsize_scopedpdu(0)
|
||||
#endif
|
||||
{
|
||||
if (pvb_count == 0) return; // zero is ok
|
||||
|
||||
// check for over then max
|
||||
if (pvb_count > PDU_MAX_VBS) { validity = false; return; }
|
||||
|
||||
// loop through and assign internal vbs
|
||||
for (int z = 0; z < pvb_count; ++z)
|
||||
{
|
||||
vbs[z] = new Vb(pvbs[z]);
|
||||
if (vbs[z] == 0) // check for new fail
|
||||
{
|
||||
for (int y = 0; y < z; ++y) delete vbs[y]; // free vbs
|
||||
validity = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
vb_count = pvb_count; // assign the vb count
|
||||
}
|
||||
|
||||
//=====================[ destructor ]====================================
|
||||
Pdu::~Pdu()
|
||||
{
|
||||
for (int z = 0; z < vb_count; ++z)
|
||||
delete vbs[z];
|
||||
}
|
||||
|
||||
//=====================[ assignment to another Pdu object overloaded ]===
|
||||
Pdu& Pdu::operator=(const Pdu &pdu)
|
||||
{
|
||||
if (this == &pdu) return *this; // check for self assignment
|
||||
|
||||
// Initialize all mv's
|
||||
error_status = pdu.error_status;
|
||||
error_index = pdu.error_index;
|
||||
request_id = pdu.request_id;
|
||||
pdu_type = pdu.pdu_type;
|
||||
notify_id = pdu.notify_id;
|
||||
notify_timestamp = pdu.notify_timestamp;
|
||||
notify_enterprise = pdu.notify_enterprise;
|
||||
#ifdef _SNMPv3
|
||||
security_level = pdu.security_level;
|
||||
message_id = pdu.message_id;
|
||||
context_name = pdu.context_name;
|
||||
context_engine_id = pdu.context_engine_id;
|
||||
maxsize_scopedpdu = pdu.maxsize_scopedpdu;
|
||||
#endif
|
||||
if (pdu.v1_trap_address_set)
|
||||
{
|
||||
v1_trap_address = pdu.v1_trap_address;
|
||||
v1_trap_address_set = true;
|
||||
}
|
||||
else
|
||||
v1_trap_address_set = false;
|
||||
|
||||
validity = true;
|
||||
|
||||
// free up old vbs
|
||||
for (int z = 0; z < vb_count; ++z)
|
||||
delete vbs[z];
|
||||
vb_count = 0;
|
||||
|
||||
// check for zero case
|
||||
if (pdu.vb_count == 0) return *this;
|
||||
|
||||
// loop through and fill em up
|
||||
for (int y = 0; y < pdu.vb_count; ++y)
|
||||
{
|
||||
vbs[y] = new Vb(*(pdu.vbs[y]));
|
||||
// new failure
|
||||
if (vbs[y] == 0)
|
||||
{
|
||||
for (int x = 0; x < y; ++x) delete vbs[x]; // free vbs
|
||||
validity = false;
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
vb_count = pdu.vb_count;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// append operator, appends a string
|
||||
Pdu& Pdu::operator+=(Vb &vb)
|
||||
{
|
||||
if (vb_count + 1> PDU_MAX_VBS) // do we have room?
|
||||
return *this;
|
||||
|
||||
vbs[vb_count] = new Vb(vb); // add the new one
|
||||
|
||||
if (vbs[vb_count]) // up the vb count on success
|
||||
{
|
||||
++vb_count;
|
||||
validity = true; // set up validity
|
||||
}
|
||||
|
||||
return *this; // return self reference
|
||||
}
|
||||
|
||||
//=====================[ extract Vbs from Pdu ]==========================
|
||||
int Pdu::get_vblist(Vb* pvbs, const int pvb_count)
|
||||
{
|
||||
if ((!pvbs) || (pvb_count < 0) || (pvb_count > vb_count))
|
||||
return FALSE;
|
||||
|
||||
// loop through all vbs and assign to params
|
||||
for (int z = 0; z < pvb_count; ++z)
|
||||
pvbs[z] = *vbs[z];
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
//=====================[ deposit Vbs ]===================================
|
||||
int Pdu::set_vblist(Vb* pvbs, const int pvb_count)
|
||||
{
|
||||
// if invalid then don't destroy
|
||||
if ((!pvbs) || (pvb_count < 0) || (pvb_count > PDU_MAX_VBS))
|
||||
return FALSE;
|
||||
|
||||
// free up current vbs
|
||||
for (int z = 0; z < vb_count; ++z) delete vbs[z];
|
||||
vb_count = 0;
|
||||
|
||||
// check for zero case
|
||||
if (pvb_count == 0)
|
||||
{
|
||||
validity = true;
|
||||
error_status = 0;
|
||||
error_index = 0;
|
||||
request_id = 0;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// loop through all vbs and reassign them
|
||||
for (int y = 0; y < pvb_count; ++y)
|
||||
{
|
||||
vbs[y] = new Vb(pvbs[y]);
|
||||
// check for new fail
|
||||
if (vbs[y] == 0)
|
||||
{
|
||||
for (int x = 0; x < y; ++x) delete vbs[x]; // free vbs
|
||||
validity = false;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
vb_count = pvb_count;
|
||||
|
||||
// clear error status and index since no longer valid
|
||||
// request id may still apply so don't reassign it
|
||||
error_status = 0;
|
||||
error_index = 0;
|
||||
validity = true;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
//===================[ get a particular vb ]=============================
|
||||
// here the caller has already instantiated a vb object
|
||||
// index is zero based
|
||||
int Pdu::get_vb(Vb &vb, const int index) const
|
||||
{
|
||||
if (index < 0) return FALSE; // can't have an index less than 0
|
||||
if (index > vb_count - 1) return FALSE; // can't ask for something not there
|
||||
|
||||
vb = *vbs[index]; // asssign it
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
//===================[ set a particular vb ]=============================
|
||||
int Pdu::set_vb(Vb &vb, const int index)
|
||||
{
|
||||
if (index < 0) return FALSE; // can't have an index less than 0
|
||||
if (index > vb_count - 1) return FALSE; // can't ask for something not there
|
||||
|
||||
Vb *victim = vbs[index]; // save in case new fails
|
||||
vbs[index] = new Vb (vb);
|
||||
if (vbs[index])
|
||||
delete victim;
|
||||
else
|
||||
{
|
||||
vbs[index] = victim;
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// trim off the last vb
|
||||
int Pdu::trim(const int count)
|
||||
{
|
||||
// verify that count is legal
|
||||
if ((count < 0) || (count > vb_count)) return FALSE;
|
||||
|
||||
int lp = count;
|
||||
|
||||
while (lp != 0)
|
||||
{
|
||||
if (vb_count > 0)
|
||||
{
|
||||
delete vbs[vb_count-1];
|
||||
vb_count--;
|
||||
}
|
||||
lp--;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// delete a Vb anywhere within the Pdu
|
||||
int Pdu::delete_vb(const int p)
|
||||
{
|
||||
// position has to be in range
|
||||
if ((p<0) || (p > vb_count - 1)) return FALSE;
|
||||
|
||||
// safe to remove it
|
||||
delete vbs[ p];
|
||||
|
||||
for (int z = p; z < vb_count - 1; ++z)
|
||||
{
|
||||
vbs[z] = vbs[z+1];
|
||||
}
|
||||
vb_count--;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
// Get the SNMPv1 trap address
|
||||
int Pdu::get_v1_trap_address(GenAddress &address) const
|
||||
{
|
||||
if (v1_trap_address_set == false)
|
||||
return FALSE;
|
||||
|
||||
address = v1_trap_address;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// Set the SNMPv1 trap address
|
||||
int Pdu::set_v1_trap_address(const Address &address)
|
||||
{
|
||||
v1_trap_address = address;
|
||||
if (v1_trap_address.valid())
|
||||
v1_trap_address_set = true;
|
||||
else
|
||||
v1_trap_address_set = false;
|
||||
|
||||
return v1_trap_address_set;
|
||||
}
|
||||
|
||||
int Pdu::get_asn1_length() const
|
||||
{
|
||||
int length = 0;
|
||||
|
||||
// length for all vbs
|
||||
for (int i = 0; i < vb_count; ++i)
|
||||
{
|
||||
length += vbs[i]->get_asn1_length();
|
||||
}
|
||||
|
||||
// header for vbs
|
||||
if (length < 0x80)
|
||||
length += 2;
|
||||
else if (length <= 0xFF)
|
||||
length += 3;
|
||||
else if (length <= 0xFFFF)
|
||||
length += 4;
|
||||
else if (length <= 0xFFFFFF)
|
||||
length += 5;
|
||||
else
|
||||
length += 6;
|
||||
|
||||
// req id, error status, error index
|
||||
SnmpInt32 i32(request_id ? request_id : PDU_MAX_RID);
|
||||
length += i32.get_asn1_length();
|
||||
i32 = error_status;
|
||||
length += i32.get_asn1_length();
|
||||
i32 = error_index;
|
||||
length += i32.get_asn1_length();
|
||||
|
||||
// header for data_pdu
|
||||
if (length < 0x80)
|
||||
length += 2;
|
||||
else if (length <= 0xFF)
|
||||
length += 3;
|
||||
else if (length <= 0xFFFF)
|
||||
length += 4;
|
||||
else if (length <= 0xFFFFFF)
|
||||
length += 5;
|
||||
else
|
||||
length += 6;
|
||||
|
||||
#ifdef _SNMPv3
|
||||
// now the scopedpdu part sequence (4), context engine, id context name
|
||||
length += 4 + 2 + context_engine_id.len() + 2 + context_name.len();
|
||||
|
||||
// An encrypted message is transported as an octet string
|
||||
if (security_level == SNMP_SECURITY_LEVEL_AUTH_PRIV)
|
||||
{
|
||||
// assume that encryption increases the data to a multiple of 16
|
||||
int mod = length % 16;
|
||||
if (mod) length += 16 - mod;
|
||||
|
||||
length += 4;
|
||||
}
|
||||
#endif
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// DEPRECATED FUNCTIONS
|
||||
void set_error_status( Pdu *pdu, const int status)
|
||||
{ if (pdu) pdu->set_error_status(status); }
|
||||
void set_error_index( Pdu *pdu, const int index)
|
||||
{ if (pdu) pdu->set_error_index(index); }
|
||||
void clear_error_status( Pdu *pdu)
|
||||
{ if (pdu) pdu->clear_error_status(); }
|
||||
void clear_error_index( Pdu *pdu)
|
||||
{ if (pdu) pdu->clear_error_index(); }
|
||||
void set_request_id( Pdu *pdu, const unsigned long rid)
|
||||
{ if (pdu) pdu->set_request_id(rid); }
|
492
backend/camembert/libkmsnmp/pdu.h
Normal file
492
backend/camembert/libkmsnmp/pdu.h
Normal file
@ -0,0 +1,492 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## pdu.h
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
/*===================================================================
|
||||
|
||||
Copyright (c) 1999
|
||||
Hewlett-Packard Company
|
||||
|
||||
ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
Permission to use, copy, modify, distribute and/or sell this software
|
||||
and/or its documentation is hereby granted without fee. User agrees
|
||||
to display the above copyright notice and this license notice in all
|
||||
copies of the software and any documentation of the software. User
|
||||
agrees to assume all liability for the use of the software; Hewlett-Packard
|
||||
makes no representations about the suitability of this software for any
|
||||
purpose. It is provided "AS-IS without warranty of any kind,either express
|
||||
or implied. User hereby grants a royalty-free license to any and all
|
||||
derivatives based upon this software code base.
|
||||
|
||||
|
||||
SNMP++ P D U . H
|
||||
|
||||
PDU CLASS DEFINITION
|
||||
|
||||
DESIGN + AUTHOR:
|
||||
Peter E Mellquist
|
||||
|
||||
LANGUAGE:
|
||||
ANSI C++
|
||||
|
||||
OPERATING SYSTEMS:
|
||||
MS-Windows Win32
|
||||
BSD UNIX
|
||||
|
||||
DESCRIPTION:
|
||||
Pdu class definition. Encapsulation of an SMI Protocol
|
||||
Data Unit (PDU) in C++.
|
||||
|
||||
=====================================================================*/
|
||||
// $Id: pdu.h,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $
|
||||
|
||||
#ifndef _PDU_CLS
|
||||
#define _PDU_CLS
|
||||
|
||||
#include "config_snmp_pp.h"
|
||||
#include "address.h"
|
||||
#include "timetick.h"
|
||||
#include "octet.h"
|
||||
#include "oid.h"
|
||||
|
||||
class Vb;
|
||||
|
||||
/** The maximum amount of Vb objects a Pdu can contain (config_snmp_pp.h). */
|
||||
#define MAX_VBS PDU_MAX_VBS
|
||||
|
||||
#define PDU_MAX_RID 32767 ///< max request id to use
|
||||
#define PDU_MIN_RID 1000 ///< min request id to use
|
||||
|
||||
//=======================================================================
|
||||
// Pdu Class
|
||||
//=======================================================================
|
||||
/**
|
||||
* Pdu class...
|
||||
*/
|
||||
class DLLOPT Pdu
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor no args.
|
||||
*
|
||||
* This constructor creates a valid empty Pdu object.
|
||||
*/
|
||||
Pdu();
|
||||
|
||||
/**
|
||||
* Constructor with vbs.
|
||||
*
|
||||
* The Pdu class does not take ownership of the array and the Vb
|
||||
* objects, so if these were allocated with new, they must be freed
|
||||
* by te user with delete.
|
||||
*
|
||||
* @param pvbs - Array of pointers to Vb objects
|
||||
* @param pvb_count - Length of the array
|
||||
*/
|
||||
Pdu(Vb* pvbs, const int pvb_count);
|
||||
|
||||
/**
|
||||
* Constructor with another Pdu instance.
|
||||
*
|
||||
* @param pdu - source pdu object
|
||||
*/
|
||||
Pdu(const Pdu &pdu) : vb_count(0) { *this = pdu; };
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
virtual ~Pdu();
|
||||
|
||||
/**
|
||||
* Overloaded assignment operator.
|
||||
*
|
||||
* @param pdu - Pdu that should be assigned to this object
|
||||
*/
|
||||
Pdu& operator=(const Pdu &pdu);
|
||||
|
||||
/**
|
||||
* Append a vb to the pdu.
|
||||
*
|
||||
* @param vb - The Vb that should be added (as last vb) to the pdu
|
||||
*/
|
||||
Pdu& operator+=(Vb &vb);
|
||||
|
||||
/**
|
||||
* Clone a Pdu object.
|
||||
*
|
||||
* @return Pointer to a newly created Pdu object, that is identical to this
|
||||
*/
|
||||
Pdu *clone() const { return new Pdu(*this); };
|
||||
|
||||
/**
|
||||
* Get Pointers to all Vbs from Pdu.
|
||||
*
|
||||
* The caller has to allocate the array. The returned pointers point
|
||||
* to the Vb objects that are internally used by the pdu. So any
|
||||
* changes to the returned Vb objects will change the pdu. If the
|
||||
* pdu is modified (e.g. through Pdu::trim()) afterwards, the
|
||||
* returned array will contain invalid pointers.
|
||||
*
|
||||
* @param pvbs - Array of empty pointers of size pvb_count
|
||||
* @param pvb_count - Amount of Vb pointers to get
|
||||
*
|
||||
* @return TRUE on success
|
||||
*/
|
||||
int get_vblist(Vb* pvbs, const int pvb_count);
|
||||
|
||||
/**
|
||||
* Deposit all Vbs to Pdu.
|
||||
*
|
||||
* The vb objects of the pdu will be freed and the objects from the
|
||||
* array will be cloned and added to the pdu. If this method returns
|
||||
* FALSE, the pdu will not conatin any Vb objects.
|
||||
*
|
||||
* @param pvbs - Array of valid pointers of size pvb_count
|
||||
* @param pvb_count - Amount of Vb pointers i the array
|
||||
*
|
||||
* @return TRUE on success
|
||||
*/
|
||||
int set_vblist(Vb* pvbs, const int pvb_count);
|
||||
|
||||
/**
|
||||
* Get a particular Vb.
|
||||
*
|
||||
* @param vb - Object to store the vb
|
||||
* @param index - The vb to get (zero is the first vb)
|
||||
*
|
||||
* @return TRUE on success
|
||||
*/
|
||||
int get_vb(Vb &vb, const int index) const;
|
||||
|
||||
/**
|
||||
* Return a reference to a particular Vb.
|
||||
*
|
||||
* @note Before calling this method, make sure that there
|
||||
* is a Vb using get_vb_count().
|
||||
*
|
||||
* @param index - The Vb to return starting with 0.
|
||||
* @return A const reference to the Vb
|
||||
*/
|
||||
const Vb &get_vb(const int index) const { return *vbs[index]; };
|
||||
|
||||
/**
|
||||
* Set a particular vb.
|
||||
*
|
||||
* If this method returns FALSE, the pdu has not been modified.
|
||||
*
|
||||
* @param vb - Source vb
|
||||
* @param index - The vb to set (zero is the first vb)
|
||||
*
|
||||
* @return TRUE on success
|
||||
*/
|
||||
int set_vb(Vb &vb, const int index);
|
||||
|
||||
/**
|
||||
* Get the number of vbs.
|
||||
*
|
||||
* @return The number of Vb objects within the pdu.
|
||||
*/
|
||||
int get_vb_count() const { return vb_count; };
|
||||
|
||||
/**
|
||||
* Get the error status.
|
||||
*
|
||||
* @return The SNMP error status
|
||||
*/
|
||||
int get_error_status() const { return error_status; };
|
||||
|
||||
/**
|
||||
* Set the error status.
|
||||
*
|
||||
* @param err - The SNMP error status.
|
||||
*/
|
||||
void set_error_status(const int err) { error_status = err; };
|
||||
|
||||
/**
|
||||
* Clear the error status.
|
||||
*/
|
||||
void clear_error_status() { error_status = 0; };
|
||||
|
||||
/**
|
||||
* Get the error index.
|
||||
*
|
||||
* @return The SNMP error index
|
||||
*/
|
||||
int get_error_index() const { return error_index; };
|
||||
|
||||
/**
|
||||
* Set the error index.
|
||||
*
|
||||
* @param err - The SNMP error index.
|
||||
*/
|
||||
void set_error_index(const int err) { error_index = err; };
|
||||
|
||||
/**
|
||||
* Clear the error index.
|
||||
*/
|
||||
void clear_error_index() { error_index = 0; };
|
||||
|
||||
/**
|
||||
* Get the request id.
|
||||
*
|
||||
* @return The SNMP request id
|
||||
*/
|
||||
unsigned long get_request_id() const { return request_id; };
|
||||
|
||||
/**
|
||||
* Set the request id.
|
||||
*
|
||||
* @param rid - The SNMP request id
|
||||
*/
|
||||
void set_request_id(const unsigned long rid) { request_id = rid; };
|
||||
|
||||
/**
|
||||
* Get the pdu type.
|
||||
*/
|
||||
unsigned short get_type() const { return pdu_type; };
|
||||
|
||||
/**
|
||||
* Set the pdu type.
|
||||
*/
|
||||
void set_type(unsigned short type) { pdu_type = type; };
|
||||
|
||||
/**
|
||||
* Returns validity of Pdu instance.
|
||||
*/
|
||||
bool valid() const { return validity; };
|
||||
|
||||
/**
|
||||
* Trim off vbs.
|
||||
*
|
||||
* @param count - number of vbs to trim of, starting with the last
|
||||
* @return TRUE on success, FALSE if nothing was done
|
||||
*/
|
||||
int trim(const int count=1);
|
||||
|
||||
/**
|
||||
* Delete a Vb anywhere within the Pdu.
|
||||
*
|
||||
* @param position - Delete the Vb at this position (starting with 0)
|
||||
* @return TRUE on success
|
||||
*/
|
||||
int delete_vb(const int position);
|
||||
|
||||
/**
|
||||
* Set notify timestamp.
|
||||
*/
|
||||
void set_notify_timestamp(const TimeTicks &ts) { notify_timestamp = ts; };
|
||||
|
||||
/**
|
||||
* Get notify timestamp.
|
||||
*/
|
||||
void get_notify_timestamp(TimeTicks &ts) const { ts = notify_timestamp; };
|
||||
|
||||
/**
|
||||
* Set the notify id.
|
||||
*/
|
||||
void set_notify_id(const Oid id) { notify_id = id; };
|
||||
|
||||
/**
|
||||
* Get the notify id.
|
||||
*/
|
||||
void get_notify_id(Oid &id) const { id = notify_id; };
|
||||
|
||||
/**
|
||||
* Set the notify enterprise.
|
||||
*/
|
||||
void set_notify_enterprise(const Oid &e) { notify_enterprise = e; };
|
||||
|
||||
/**
|
||||
* Get the notify enterprise.
|
||||
*/
|
||||
void get_notify_enterprise(Oid & e) const { e = notify_enterprise; };
|
||||
|
||||
#ifdef _SNMPv3
|
||||
/**
|
||||
* Set the security level that should be used when this Pdu is sent.
|
||||
* The default security level of a Pdu is SNMP_SECURITY_LEVEL_NOAUTH_NOPRIV.
|
||||
*
|
||||
* @param level - One of SNMP_SECURITY_LEVEL_NOAUTH_NOPRIV,
|
||||
* SNMP_SECURITY_LEVEL_AUTH_NOPRIV,
|
||||
* SNMP_SECURITY_LEVEL_AUTH_PRIV
|
||||
*/
|
||||
void set_security_level(const int level) { security_level = level; };
|
||||
|
||||
/**
|
||||
* Return the security level of the Pdu.
|
||||
*
|
||||
* @return - the security level
|
||||
*/
|
||||
int get_security_level() const { return security_level; };
|
||||
|
||||
/**
|
||||
* Set the context name of the Pdu.
|
||||
*
|
||||
* @param name - The context name
|
||||
*/
|
||||
void set_context_name(const OctetStr &name) { context_name = name; };
|
||||
|
||||
/**
|
||||
* Set the context name of the Pdu.
|
||||
*
|
||||
* @param name - The context name
|
||||
*/
|
||||
void set_context_name(const char * name) { context_name = name; };
|
||||
|
||||
/**
|
||||
* Get the context name of the Pdu.
|
||||
*
|
||||
* @param name - Object fot the context name
|
||||
*/
|
||||
void get_context_name(OctetStr &name) const { name = context_name; };
|
||||
|
||||
/**
|
||||
* Get the context name of the Pdu.
|
||||
*
|
||||
* @return - Return the context name as an OctetStr
|
||||
*/
|
||||
const OctetStr& get_context_name() const { return context_name; };
|
||||
|
||||
/**
|
||||
* Set the context engine id of the Pdu.
|
||||
*
|
||||
* @param id - The new context engine id
|
||||
*/
|
||||
void set_context_engine_id(const OctetStr &id) { context_engine_id = id; };
|
||||
|
||||
/**
|
||||
* Set the context engine id of the Pdu.
|
||||
*
|
||||
* @param id - The new context engine id
|
||||
*/
|
||||
void set_context_engine_id(const char *id) { context_engine_id = id; };
|
||||
|
||||
/**
|
||||
* Get the context engine id of the Pdu.
|
||||
*
|
||||
* @param id - Object for the context engine
|
||||
*/
|
||||
void get_context_engine_id(OctetStr &id) const { id = context_engine_id; };
|
||||
|
||||
/**
|
||||
* Get the context engine id of the Pdu.
|
||||
*
|
||||
* @return - Return the context engine id as an OctetStr
|
||||
*/
|
||||
const OctetStr& get_context_engine_id() const { return context_engine_id; };
|
||||
|
||||
/**
|
||||
* Set the SNMPv3 message id (msgID)
|
||||
*
|
||||
* @param msg_id - the message id of the received message
|
||||
*/
|
||||
void set_message_id(const unsigned long msg_id) { message_id = msg_id; }
|
||||
|
||||
/**
|
||||
* Get the SNMPv3 message id (msgID)
|
||||
*
|
||||
* @return - the message id of the received message
|
||||
*/
|
||||
unsigned long get_message_id() const { return message_id; }
|
||||
|
||||
/**
|
||||
* Set the maximum size of the scoped pdu to be included in a
|
||||
* possible response message.
|
||||
*
|
||||
* @param l - the maximum size
|
||||
*/
|
||||
void set_maxsize_scopedpdu(unsigned long l) { maxsize_scopedpdu = l; };
|
||||
|
||||
/**
|
||||
* Get the maximum size of the scoped pdu to be included in a
|
||||
* possible response message.
|
||||
*
|
||||
* @return - the maximum size
|
||||
*/
|
||||
unsigned long get_maxsize_scopedpdu() const { return maxsize_scopedpdu; };
|
||||
|
||||
#endif // _SNMPv3
|
||||
|
||||
/**
|
||||
* Get the SNMPv1 trap address
|
||||
*/
|
||||
int get_v1_trap_address(GenAddress &address) const;
|
||||
|
||||
/**
|
||||
* Set the SNMPv1 trap address
|
||||
*/
|
||||
int set_v1_trap_address(const Address &address);
|
||||
|
||||
/**
|
||||
* Return the length of the encoded vbs with pdu header.
|
||||
*
|
||||
* @note this method wll not work for v1 traps.
|
||||
*/
|
||||
int get_asn1_length() const;
|
||||
|
||||
//-------------[ protected instance variables ]--------------------------
|
||||
protected:
|
||||
Vb *vbs[PDU_MAX_VBS]; // pointer to array of Vbs
|
||||
int vb_count; // count of Vbs
|
||||
int error_status; // SMI error status
|
||||
int error_index; // SMI error index
|
||||
bool validity; // valid boolean
|
||||
unsigned long request_id; // SMI request id
|
||||
unsigned short pdu_type; // derived at run time based on request type
|
||||
// for notify Pdu objects only
|
||||
// traps & notifies
|
||||
TimeTicks notify_timestamp; // a timestamp associated with an infor
|
||||
Oid notify_id; // an id
|
||||
Oid notify_enterprise;
|
||||
GenAddress v1_trap_address; // address object
|
||||
int v1_trap_address_set;
|
||||
#ifdef _SNMPv3
|
||||
// specific Objects for SNMPv3
|
||||
int security_level; // the securityLevel with which this Pdu
|
||||
// should be sent or was received
|
||||
unsigned long message_id;
|
||||
unsigned long maxsize_scopedpdu;
|
||||
OctetStr context_name;
|
||||
OctetStr context_engine_id;
|
||||
#endif // _SNMPv3
|
||||
|
||||
};
|
||||
|
||||
#if 1
|
||||
//! deprecated: set the error status
|
||||
DLLOPT void set_error_status(Pdu *pdu, const int status);
|
||||
//! deprecated: set the error index
|
||||
DLLOPT void set_error_index(Pdu *pdu, const int index);
|
||||
//! deprecated: clear error status
|
||||
DLLOPT void clear_error_status(Pdu *pdu);
|
||||
//! deprecated: clear error index
|
||||
DLLOPT void clear_error_index(Pdu *pdu);
|
||||
//! deprecated: set the request id
|
||||
DLLOPT void set_request_id(Pdu *pdu, const unsigned long rid);
|
||||
#endif
|
||||
#endif //_PDU_CLS
|
235
backend/camembert/libkmsnmp/smi.h
Normal file
235
backend/camembert/libkmsnmp/smi.h
Normal file
@ -0,0 +1,235 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## smi.h
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
/*===================================================================
|
||||
|
||||
Copyright (c) 1999
|
||||
Hewlett-Packard Company
|
||||
|
||||
ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
Permission to use, copy, modify, distribute and/or sell this software
|
||||
and/or its documentation is hereby granted without fee. User agrees
|
||||
to display the above copyright notice and this license notice in all
|
||||
copies of the software and any documentation of the software. User
|
||||
agrees to assume all liability for the use of the software; Hewlett-Packard
|
||||
makes no representations about the suitability of this software for any
|
||||
purpose. It is provided "AS-IS without warranty of any kind,either express
|
||||
or implied. User hereby grants a royalty-free license to any and all
|
||||
derivatives based upon this software code base.
|
||||
|
||||
|
||||
SNMP++ S M I . H
|
||||
|
||||
SMI DEFINITIONS
|
||||
|
||||
AUTHOR:
|
||||
Peter E Mellquist
|
||||
|
||||
LANGUAGE:
|
||||
ANSI C++
|
||||
|
||||
OPERATING SYSTEMS:
|
||||
MS-Windows Win32
|
||||
BSD UNIX
|
||||
|
||||
DESCRIPTION:
|
||||
Address class definition. Encapsulates various network
|
||||
addresses into easy to use, safe and portable classes.
|
||||
|
||||
=====================================================================*/
|
||||
// $Id: smi.h,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $
|
||||
|
||||
#ifndef _SMIDEF
|
||||
#define _SMIDEF
|
||||
|
||||
// make sure configuration is included first
|
||||
#include "config_snmp_pp.h"
|
||||
|
||||
#define WINFAR
|
||||
#define STRCAT strcat
|
||||
#define STRLEN strlen
|
||||
#define MEMCPY memcpy
|
||||
#define STRCPY strcpy
|
||||
#define MEMCMP memcmp
|
||||
#define XPORT
|
||||
|
||||
// HANDLE needs to be defined for each type of platform
|
||||
// for win32 - HANDLE is a HWND
|
||||
// for unix - HANDLE is an unsigned long
|
||||
// unix and win32 ( Windu compile , unix takes presedence )
|
||||
#ifdef WIN32
|
||||
#ifndef SNMPHANDLE
|
||||
#define SNMPHANDLE HWND
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __unix
|
||||
#ifndef SNMPHANDLE
|
||||
#define SNMPHANDLE unsigned long
|
||||
#define DLLOPT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
//----------[ ASN/BER Base Types ]-----------------------------------------
|
||||
/** @name ASN/BER Base Types
|
||||
*
|
||||
* Basic Encoding Rules (BER) (used in forming SYNTAXes and certain
|
||||
* SNMP types/values).
|
||||
*/
|
||||
//@{
|
||||
#define aSN_UNIVERSAL (0x00)
|
||||
#define aSN_APPLICATION (0x40)
|
||||
#define aSN_CONTEXT (0x80)
|
||||
#define aSN_PRIVATE (0xC0)
|
||||
#define aSN_PRIMITIVE (0x00)
|
||||
#define aSN_CONSTRUCTOR (0x20)
|
||||
//@}
|
||||
|
||||
//------[ SNMP ObjectSyntax Values ]---------------------------------------
|
||||
#define sNMP_SYNTAX_SEQUENCE (aSN_CONTEXT | aSN_CONSTRUCTOR | 0x10)
|
||||
|
||||
/** @name Syntax Types
|
||||
*
|
||||
* These values are used in the "syntax" member of the smiVALUE
|
||||
* structure which follows.
|
||||
*
|
||||
* The get_syntax() method of any class derived from SnmpSyntax returns
|
||||
* one of these values.
|
||||
*
|
||||
* @note UInt32 is indistinguishable from Gauge32 per SNMPv2 Draft Standard
|
||||
* @note NsapAddr is obsoleted as unique SMI type per SNMPv2 Draft Standard
|
||||
*/
|
||||
//@{
|
||||
#define sNMP_SYNTAX_INT (aSN_UNIVERSAL | aSN_PRIMITIVE | 0x02)
|
||||
#define sNMP_SYNTAX_BITS (aSN_UNIVERSAL | aSN_PRIMITIVE | 0x03)
|
||||
#define sNMP_SYNTAX_OCTETS (aSN_UNIVERSAL | aSN_PRIMITIVE | 0x04)
|
||||
#define sNMP_SYNTAX_NULL (aSN_UNIVERSAL | aSN_PRIMITIVE | 0x05)
|
||||
#define sNMP_SYNTAX_OID (aSN_UNIVERSAL | aSN_PRIMITIVE | 0x06)
|
||||
#define sNMP_SYNTAX_INT32 sNMP_SYNTAX_INT
|
||||
#define sNMP_SYNTAX_IPADDR (aSN_APPLICATION | aSN_PRIMITIVE | 0x00)
|
||||
#define sNMP_SYNTAX_CNTR32 (aSN_APPLICATION | aSN_PRIMITIVE | 0x01)
|
||||
#define sNMP_SYNTAX_GAUGE32 (aSN_APPLICATION | aSN_PRIMITIVE | 0x02)
|
||||
#define sNMP_SYNTAX_TIMETICKS (aSN_APPLICATION | aSN_PRIMITIVE | 0x03)
|
||||
#define sNMP_SYNTAX_OPAQUE (aSN_APPLICATION | aSN_PRIMITIVE | 0x04)
|
||||
#define sNMP_SYNTAX_CNTR64 (aSN_APPLICATION | aSN_PRIMITIVE | 0x06)
|
||||
#define sNMP_SYNTAX_UINT32 sNMP_SYNTAX_GAUGE32
|
||||
//@}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
//---------------[ Exception conditions for SNMPv2 ]-----------------------
|
||||
/** @name Exception conditions for SNMPv2 */
|
||||
//@{
|
||||
#define sNMP_SYNTAX_NOSUCHOBJECT (aSN_CONTEXT | aSN_PRIMITIVE | 0x00)
|
||||
#define sNMP_SYNTAX_NOSUCHINSTANCE (aSN_CONTEXT | aSN_PRIMITIVE | 0x01)
|
||||
#define sNMP_SYNTAX_ENDOFMIBVIEW (aSN_CONTEXT | aSN_PRIMITIVE | 0x02)
|
||||
//@}
|
||||
|
||||
//--------------[ different types of PDU's ]-------------------------------
|
||||
/** @name Pdu types */
|
||||
//@{
|
||||
#define sNMP_PDU_GET (aSN_CONTEXT | aSN_CONSTRUCTOR | 0x0)
|
||||
#define sNMP_PDU_GETNEXT (aSN_CONTEXT | aSN_CONSTRUCTOR | 0x1)
|
||||
#define sNMP_PDU_RESPONSE (aSN_CONTEXT | aSN_CONSTRUCTOR | 0x2)
|
||||
#define sNMP_PDU_SET (aSN_CONTEXT | aSN_CONSTRUCTOR | 0x3)
|
||||
#define sNMP_PDU_V1TRAP (aSN_CONTEXT | aSN_CONSTRUCTOR | 0x4)
|
||||
#define sNMP_PDU_GETBULK (aSN_CONTEXT | aSN_CONSTRUCTOR | 0x5)
|
||||
#define sNMP_PDU_INFORM (aSN_CONTEXT | aSN_CONSTRUCTOR | 0x6)
|
||||
#define sNMP_PDU_TRAP (aSN_CONTEXT | aSN_CONSTRUCTOR | 0x7)
|
||||
#define sNMP_PDU_REPORT (aSN_CONTEXT | aSN_CONSTRUCTOR | 0x8)
|
||||
//@}
|
||||
|
||||
|
||||
//------[ smi typedefs ]---------------------------------------------------
|
||||
/** @name SMI typedefs
|
||||
*
|
||||
* SNMP-related types from RFC1442 (SMI).
|
||||
*/
|
||||
//@{
|
||||
|
||||
// byte
|
||||
typedef unsigned char SmiBYTE, WINFAR *SmiLPBYTE;
|
||||
|
||||
// int
|
||||
typedef long SmiINT, WINFAR *SmiLPINT;
|
||||
|
||||
// int 32
|
||||
typedef SmiINT SmiINT32, WINFAR *SmiLPINT32;
|
||||
|
||||
// unit32
|
||||
typedef unsigned long SmiUINT32, WINFAR *SmiLPUINT32;
|
||||
|
||||
// octet struct
|
||||
typedef struct {
|
||||
SmiUINT32 len;
|
||||
SmiLPBYTE ptr;} SmiOCTETS, WINFAR *SmiLPOCTETS;
|
||||
|
||||
// bits
|
||||
typedef SmiOCTETS SmiBITS, WINFAR *SmiLPBITS;
|
||||
|
||||
// SMI oid struct
|
||||
typedef struct {
|
||||
SmiUINT32 len;
|
||||
SmiLPUINT32 ptr;} SmiOID, WINFAR *SmiLPOID;
|
||||
|
||||
// ipaddr
|
||||
typedef SmiOCTETS SmiIPADDR, WINFAR *SmiLPIPADDR;
|
||||
|
||||
// 32bit counter
|
||||
typedef SmiUINT32 SmiCNTR32, WINFAR *SmiLPCNTR32;
|
||||
|
||||
// gauge
|
||||
typedef SmiUINT32 SmiGAUGE32, WINFAR *SmiLPGAUGE32;
|
||||
|
||||
// timeticks
|
||||
typedef SmiUINT32 SmiTIMETICKS, WINFAR *SmiLPTIMETICKS;
|
||||
|
||||
// opaque
|
||||
typedef SmiOCTETS SmiOPAQUE, WINFAR *SmiLPOPAQUE;
|
||||
|
||||
// nsapaddr
|
||||
typedef SmiOCTETS SmiNSAPADDR, WINFAR *SmiLPNSAPADDR;
|
||||
|
||||
// 64 bit counter
|
||||
typedef struct {
|
||||
SmiUINT32 hipart;
|
||||
SmiUINT32 lopart;} SmiCNTR64, WINFAR *SmiLPCNTR64;
|
||||
//@}
|
||||
|
||||
#endif
|
||||
|
||||
|
170
backend/camembert/libkmsnmp/smival.h
Normal file
170
backend/camembert/libkmsnmp/smival.h
Normal file
@ -0,0 +1,170 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## smival.h
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
/*===================================================================
|
||||
|
||||
Copyright (c) 1999
|
||||
Hewlett-Packard Company
|
||||
|
||||
ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
Permission to use, copy, modify, distribute and/or sell this software
|
||||
and/or its documentation is hereby granted without fee. User agrees
|
||||
to display the above copyright notice and this license notice in all
|
||||
copies of the software and any documentation of the software. User
|
||||
agrees to assume all liability for the use of the software; Hewlett-Packard
|
||||
makes no representations about the suitability of this software for any
|
||||
purpose. It is provided "AS-IS without warranty of any kind,either express
|
||||
or implied. User hereby grants a royalty-free license to any and all
|
||||
derivatives based upon this software code base.
|
||||
|
||||
|
||||
SNMP++ S M I V A L . H
|
||||
|
||||
SMIVALUE CLASS DEFINITION
|
||||
|
||||
DESIGN + AUTHOR: Jeff Meyer
|
||||
|
||||
LANGUAGE:
|
||||
ANSI C++
|
||||
|
||||
OPERATING SYSTEMS:
|
||||
MS-Windows Win32
|
||||
BSD UNIX
|
||||
|
||||
DESCRIPTION:
|
||||
SMIValue class definition. Superclass for the various types
|
||||
of SNMP values (Address, Oid, Octet, etc.). Provides
|
||||
only a few functions, most info is in subclass.
|
||||
|
||||
=====================================================================*/
|
||||
// $Id: smival.h,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $
|
||||
|
||||
#ifndef _SMIVALUE
|
||||
#define _SMIVALUE
|
||||
|
||||
//----[ includes ]-----------------------------------------------------
|
||||
#include "smi.h"
|
||||
|
||||
//----[ macros ]-------------------------------------------------------
|
||||
#if defined(USE_CPP_CASTS)
|
||||
#define PP_CONST_CAST(___type, ___ptr) const_cast< ___type >(___ptr)
|
||||
#else
|
||||
#define PP_CONST_CAST(___type, ___ptr) ((___type)(___ptr))
|
||||
#endif
|
||||
|
||||
//======================================================================
|
||||
// SMI value structure conforming with SMI RFC
|
||||
//
|
||||
typedef struct { /* smiVALUE portion of VarBind */
|
||||
SmiUINT32 syntax; /* Insert SNMP_SYNTAX_<type> */
|
||||
union {
|
||||
SmiINT sNumber; /* SNMP_SYNTAX_INT
|
||||
SNMP_SYNTAX_INT32 */
|
||||
SmiUINT32 uNumber; /* SNMP_SYNTAX_UINT32
|
||||
SNMP_SYNTAX_CNTR32
|
||||
SNMP_SYNTAX_GAUGE32
|
||||
SNMP_SYNTAX_TIMETICKS */
|
||||
SmiCNTR64 hNumber; /* SNMP_SYNTAX_CNTR64 */
|
||||
SmiOCTETS string; /* SNMP_SYNTAX_OCTETS
|
||||
SNMP_SYNTAX_BITS
|
||||
SNMP_SYNTAX_OPAQUE
|
||||
SNMP_SYNTAX_IPADDR
|
||||
SNMP_SYNTAX_NSAPADDR */
|
||||
SmiOID oid; /* SNMP_SYNTAX_OID */
|
||||
SmiBYTE empty; /* SNMP_SYNTAX_NULL
|
||||
SNMP_SYNTAX_NOSUCHOBJECT
|
||||
SNMP_SYNTAX_NOSUCHINSTANCE
|
||||
SNMP_SYNTAX_ENDOFMIBVIEW */
|
||||
} value;
|
||||
} SmiVALUE, *SmiLPVALUE;
|
||||
//=================================================================
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//----[ SnmpSyntax class ]--------------------------------------------
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* An "abstract" (pure virtual) class that serves as the base class
|
||||
* for all specific SNMP syntax types.
|
||||
*/
|
||||
class DLLOPT SnmpSyntax {
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Virtual function for getting a printable ASCII value for any SNMP
|
||||
* value.
|
||||
*
|
||||
* @note The returned string is valid as long as the object is not
|
||||
* modified.
|
||||
*/
|
||||
virtual const char *get_printable() const = 0;
|
||||
|
||||
/**
|
||||
* Return the current syntax.
|
||||
*/
|
||||
virtual SmiUINT32 get_syntax() const = 0;
|
||||
|
||||
/**
|
||||
* Virtual clone operation for creating a new Value from an existing
|
||||
* value.
|
||||
*
|
||||
* @note The caller MUST use the delete operation on the return
|
||||
* value when done.
|
||||
*/
|
||||
virtual SnmpSyntax * clone() const = 0;
|
||||
|
||||
/**
|
||||
* Virtual destructor to ensure deletion of derived classes...
|
||||
*/
|
||||
virtual ~SnmpSyntax() {};
|
||||
|
||||
/**
|
||||
* Overloaded assignment operator.
|
||||
*
|
||||
* @note This should be pure virtual, but buggy VC++ compiler
|
||||
* complains about unresolved reference at link time.
|
||||
*/
|
||||
virtual SnmpSyntax& operator=(const SnmpSyntax &/*val*/) { return *this; };
|
||||
|
||||
/**
|
||||
* Return validity of the object.
|
||||
*/
|
||||
virtual bool valid() const = 0;
|
||||
|
||||
/**
|
||||
* Return the space needed for serialization.
|
||||
*/
|
||||
virtual int get_asn1_length() const = 0;
|
||||
|
||||
protected:
|
||||
|
||||
SmiVALUE smival;
|
||||
};
|
||||
|
||||
#endif // _SMIVALUE
|
273
backend/camembert/libkmsnmp/snmperrs.h
Normal file
273
backend/camembert/libkmsnmp/snmperrs.h
Normal file
@ -0,0 +1,273 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## snmperrs.h
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
/*===================================================================
|
||||
|
||||
Copyright (c) 1999
|
||||
Hewlett-Packard Company
|
||||
|
||||
ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
Permission to use, copy, modify, distribute and/or sell this software
|
||||
and/or its documentation is hereby granted without fee. User agrees
|
||||
to display the above copyright notice and this license notice in all
|
||||
copies of the software and any documentation of the software. User
|
||||
agrees to assume all liability for the use of the software; Hewlett-Packard
|
||||
makes no representations about the suitability of this software for any
|
||||
purpose. It is provided "AS-IS without warranty of any kind,either express
|
||||
or implied. User hereby grants a royalty-free license to any and all
|
||||
derivatives based upon this software code base.
|
||||
|
||||
|
||||
SNMP++ S N M P E R R S. H
|
||||
|
||||
SNMP++ ERROR CODE AND STRING DEFINITIONS
|
||||
|
||||
DESCRIPTION:
|
||||
Definition of error macros and error strings
|
||||
|
||||
DESIGN + AUTHOR:
|
||||
Jeff Meyer
|
||||
|
||||
LANGUAGE:
|
||||
ANSI C++
|
||||
|
||||
OPERATING SYSTEMS:
|
||||
WIN32
|
||||
BSD UNIX
|
||||
|
||||
============================================================================*/
|
||||
// $Id: snmperrs.h,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $
|
||||
|
||||
#ifndef _SNMPERRS_H
|
||||
#define _SNMPERRS_H
|
||||
|
||||
#include "config_snmp_pp.h"
|
||||
|
||||
//-------[ Positive SNMP ++ Error Return Codes ]------------------------------
|
||||
/** @name Pdu error codes
|
||||
* These values are error status values from RFC 1905
|
||||
*
|
||||
* The values can be returned via Pdu::get_error_status()
|
||||
*/
|
||||
//@{
|
||||
#define SNMP_ERROR_SUCCESS 0 //!< Success Status
|
||||
#define SNMP_ERROR_TOO_BIG 1 //!< Pdu encoding too big
|
||||
#define SNMP_ERROR_NO_SUCH_NAME 2 //!< No such VB name, see error index
|
||||
#define SNMP_ERROR_BAD_VALUE 3 //!< Bad Vb
|
||||
#define SNMP_ERROR_READ_ONLY 4 //!< VB is read only, see error index
|
||||
#define SNMP_ERROR_GENERAL_VB_ERR 5 //!< General VB error, see error index
|
||||
#define SNMP_ERROR_NO_ACCESS 6 //!< No access to MIBs data
|
||||
#define SNMP_ERROR_WRONG_TYPE 7 //!< Requested type was incorrect
|
||||
#define SNMP_ERROR_WRONG_LENGTH 8 //!< Request Pdu has inccorect length
|
||||
#define SNMP_ERROR_WRONG_ENCODING 9 //!< Request Pdu has wrong encoding
|
||||
#define SNMP_ERROR_WRONG_VALUE 10 //!< Request Pdu has wrong value
|
||||
#define SNMP_ERROR_NO_CREATION 11 //!< Unable to create object specified
|
||||
#define SNMP_ERROR_INCONSIST_VAL 12 //!< Inconsistent value in request
|
||||
#define SNMP_ERROR_RESOURCE_UNAVAIL 13 //!< Resources unavailable
|
||||
#define SNMP_ERROR_COMITFAIL 14 //!< Unable to comit
|
||||
#define SNMP_ERROR_UNDO_FAIL 15 //!< Unable to undo
|
||||
#define SNMP_ERROR_AUTH_ERR 16 //!< Authentication failure
|
||||
#define SNMP_ERROR_NOT_WRITEABLE 17 //!< Mib Object not writeable
|
||||
#define SNMP_ERROR_INCONSIS_NAME 18 //!< Inconsistent naming used
|
||||
//@}
|
||||
|
||||
//-------[ Negative SNMP ++ Result/Error Return Codes ]-------------------
|
||||
|
||||
/** @name Snmp class return codes
|
||||
*/
|
||||
//@{
|
||||
|
||||
// General
|
||||
#define SNMP_CLASS_SUCCESS 0 //!< success
|
||||
#define SNMP_CLASS_ERROR -1 //!< general error
|
||||
#define SNMP_CLASS_RESOURCE_UNAVAIL -2 //!< e.g., malloc failed
|
||||
#define SNMP_CLASS_INTERNAL_ERROR -3 //!< unexpected / internal error
|
||||
#define SNMP_CLASS_UNSUPPORTED -4 //!< unsupported function
|
||||
|
||||
// Callback reasons:
|
||||
#define SNMP_CLASS_TIMEOUT -5 //!< outstanding request timed out
|
||||
#define SNMP_CLASS_ASYNC_RESPONSE -6 //!< received response for outstd request
|
||||
#define SNMP_CLASS_NOTIFICATION -7 //!< received notification (trap/inform)
|
||||
#define SNMP_CLASS_SESSION_DESTROYED -8 //!< snmp::destroyed with oustanding reqs pending
|
||||
|
||||
// Snmp Class:
|
||||
#define SNMP_CLASS_INVALID -10 //!< snmp::mf called on invalid instance
|
||||
#define SNMP_CLASS_INVALID_PDU -11 //!< invalid pdu passed to mf
|
||||
#define SNMP_CLASS_INVALID_TARGET -12 //!< invalid target passed to mf
|
||||
#define SNMP_CLASS_INVALID_CALLBACK -13 //!< invalid callback to mf
|
||||
#define SNMP_CLASS_INVALID_REQID -14 //!< invalid request id to cancel
|
||||
#define SNMP_CLASS_INVALID_NOTIFYID -15 //!< missing trap/inform oid
|
||||
#define SNMP_CLASS_INVALID_OPERATION -16 //!< snmp operation not allowed for specified target
|
||||
#define SNMP_CLASS_INVALID_OID -17 //!< invalid oid passed to mf
|
||||
#define SNMP_CLASS_INVALID_ADDRESS -18 //!< invalid address passed to mf
|
||||
#define SNMP_CLASS_ERR_STATUS_SET -19 //!< agent returned response pdu with error_status set
|
||||
|
||||
// Transport Errors:
|
||||
#define SNMP_CLASS_TL_UNSUPPORTED -20 //!< transport unsupported
|
||||
#define SNMP_CLASS_TL_IN_USE -21 //!< transport in use
|
||||
#define SNMP_CLASS_TL_FAILED -22 //!< transport operation failed
|
||||
|
||||
// extras
|
||||
#define SNMP_CLASS_SHUTDOWN -23 //!< used for back door shutdown
|
||||
|
||||
// ASN.1 parse errors
|
||||
#define SNMP_CLASS_BADVERSION -50 //!< unsupported version
|
||||
#define SNMP_CLASS_ASN1ERROR -51 //!< used for ASN.1 parse errors
|
||||
//@}
|
||||
|
||||
#define MAX_POS_ERROR SNMP_ERROR_INCONSIS_NAME
|
||||
#define MAX_NEG_ERROR SNMP_CLASS_SHUTDOWN
|
||||
|
||||
|
||||
#ifdef _INCLUDE_SNMP_ERR_STRINGS
|
||||
|
||||
/**
|
||||
* ASCII strings returned through Snmp::error() function.
|
||||
*
|
||||
* @note altering the strings in this header file will not affect the
|
||||
* return values of Snmp::error(), unless you rebuild the SNMP++
|
||||
* library from source.
|
||||
*/
|
||||
//@{
|
||||
static const char * pErrs[] = {
|
||||
"Success", // 0
|
||||
"SNMP: Response PDU Too Big", // 1
|
||||
"SNMP: Variable does not exist", // 2
|
||||
"SNMP: Cannot modify variable: Bad Value", // 3
|
||||
"SNMP: Cannot modify object, Read Only", // 4
|
||||
"SNMP: Cannot perform operation, General Error", // 5
|
||||
"SNMP: Cannot access variable, No Access", // 6
|
||||
"SNMP: Cannot create/modify variable, Wrong Type", // 7
|
||||
"SNMP: Cannot create/set variable, Wrong Length", // 8
|
||||
"SNMP: Cannot create/set variable, Wrong Encoding", // 9
|
||||
"SNMP: Cannot create/set variable, Wrong Value", // 10
|
||||
"SNMP: Cannot create variable, Creation Not Allowed", // 11
|
||||
"SNMP: Cannot create/set variable, Inconsistent Value", // 12
|
||||
"SNMP: Cannot create/set variable, Resource Unavailable", // 13
|
||||
"SNMP: Cannot create/set variable, Commit Failed", // 14
|
||||
"SNMP: Cannot create/set variable, Undo Failed", // 15
|
||||
"SNMP: Cannot perform operation, Authorization Error", // 16
|
||||
"SNMP: Cannot create/set variable, Not Writable", // 17
|
||||
"SNMP: Cannot create variable, Inconsistent Name", // 18
|
||||
"SNMP: Unknown Error Status" // 19
|
||||
};
|
||||
|
||||
#ifdef _SNMPv3
|
||||
static const char * nv3Errs[] = {
|
||||
"SNMPv3: v3MP error", // -1400
|
||||
"SNMPv3: v3MP ok", // -1401
|
||||
"SNMPv3: Unsupported Security Model", // -1402
|
||||
"SNMPv3: Message not in Time Window", // -1403
|
||||
"SNMPv3: received same Message twice",// -1404
|
||||
"SNMPv3: Invalid Message", // -1405
|
||||
"SNMPv3: Invalid EngineID", // -1406
|
||||
"SNMPv3: v3MP not initialized", // -1407
|
||||
"SNMPv3: Parse Error", // -1408
|
||||
"SNMPv3: Received Message with unknown MsgID", // -1409
|
||||
"SNMPv3: Message does not match known message", // -1410
|
||||
"SNMPv3: Community format error", // -1411
|
||||
"SNMPv3: Unknown UserName", //-1412
|
||||
"SNMPv3: Build error", //-1413
|
||||
"SNMPv3: USM: error", //-1414
|
||||
"SNMPv3: Unknown pdu handlers", //-1415
|
||||
"SNMPv3: Unavailable Context", //-1416
|
||||
"SNMPv3: Unknown Context", //-1417
|
||||
"SNMPv3: Report sent", //-1418
|
||||
"SNMPv3: Unknown errorcode"
|
||||
};
|
||||
|
||||
static const char * pv3Errs[] = {
|
||||
"SNMPv3: USM: ok", // 1400
|
||||
"SNMPv3: USM: error", // 1401
|
||||
"SNMPv3: USM: Configfile write error", // 1402
|
||||
"SNMPv3: USM: Unsupported SecurityLevel", // 1403
|
||||
"SNMPv3: USM: Unknown SecurityName", // 1404
|
||||
"SNMPv3: USM: Encryption error", // 1405
|
||||
"SNMPv3: USM: Decryption error", // 1406
|
||||
"SNMPv3: USM: Authentication error", // 1407
|
||||
"SNMPv3: USM: Authentication failure", // 1408
|
||||
"SNMPv3: USM: Parse error", // 1409
|
||||
"SNMPv3: USM: Unknown EngineID", // 1410
|
||||
"SNMPv3: USM: Message not in TimeWindow", // 1411
|
||||
"SNMPv3: USM: Unsupported AuthProtocol", // 1412
|
||||
"SNMPv3: USM: Unsupported PrivProtocol" // 1413
|
||||
"SNMPv3: USM: Address error", // 1414
|
||||
"SNMPv3: USM: Could not create file", // 1415
|
||||
"SNMPv3: USM: Could not open file", // 1416
|
||||
"SNMPv3: USM: Could not rename file", // 1417
|
||||
"SNMPv3: USM: Could not delete file", // 1418
|
||||
"SNMPv3: USM: Could not write into file", // 1419
|
||||
"SNMPv3: USM: Could not read from file", // 1420
|
||||
"SNMPv3: USM: unknown errorcode"
|
||||
};
|
||||
#endif
|
||||
|
||||
static const char * nErrs[] =
|
||||
{
|
||||
// General:
|
||||
"SNMP++: Success", // 0 SNMP_CLASS_SUCCESS
|
||||
"SNMP++: Operation failed", // 1 SNMP_CLASS_ERROR
|
||||
"SNMP++: Resource unavailable", // 2 SNMP_CLASS_RESOURCE_UNAVAIL
|
||||
"SNMP++: Internal error", // 3 SNMP_CLASS_INTERNAL_ERROR
|
||||
"SNMP++: Unsupported function", // 4 SNMP_CLASS_UNSUPPORTED
|
||||
|
||||
// Callback reasons:
|
||||
"SNMP++: SNMP request timed out", // 5 SNMP_CLASS_TIMEOUT
|
||||
"SNMP++: Received SNMP Response", // 6 SNMP_CLASS_ASYNC_RESPONSE
|
||||
// 7 SNMP_CLASS_NOTIFICATION
|
||||
"SNMP++: Received SNMP Notification (trap or inform)",
|
||||
// 8 SNMP_CLASS_SESSION_DESTROYED
|
||||
"SNMP++: Closing session with outstanding requests",
|
||||
"Unknown error code", // 9 reserved for future
|
||||
|
||||
// Snmp Class errors:
|
||||
"SNMP++: Class not valid", // 10 SNMP_CLASS_INVALID
|
||||
"SNMP++: Invalid Pdu", // 11 SNMP_CLASS_INVALID_PDU
|
||||
"SNMP++: Invalid Target", // 12 SNMP_CLASS_INVALID_TARGET
|
||||
"SNMP++: Invalid (null) Callback Function", // 13 SNMP_CLASS_INVALID_CALLBACK
|
||||
"SNMP++: Invalid Request Id", // 14 SNMP_CLASS_INVALID_REQID
|
||||
"SNMP++: Invalid Notification Id", // 15 SNMP_CLASS_INVALID_NOTIFYID
|
||||
// 16 SNMP_CLASS_INVALID_OPERATION
|
||||
"SNMP++: SNMP Operation not supported on specified Target",
|
||||
"SNMP++: Invalid Object Identifier", // 17 SNMP_CLASS_INVALID_OID
|
||||
"SNMP++: Invalid Address", // 18 SNMP_CLASS_INVALID_ADDRESS
|
||||
// 19 SNMP_CLASS_ERR_STATUS_SET
|
||||
"SNMP++: Agent indicates error in SNMP request",
|
||||
|
||||
// Transport Errors:
|
||||
"SNMP++: Transport is not supported", // 20 SNMP_CLASS_TL_UNSUPPORTED
|
||||
"SNMP++: Transport is in use", // 21 SNMP_CLASS_TL_IN_USE
|
||||
"SNMP++: Transport operation failed", // 22 SNMP_CLASS_TL_FAILED
|
||||
"SNMP++: Blocked Mode Shutdown", // 23 SNMP_CLASS_SHUTDOWN
|
||||
|
||||
"Unknown error code", // unknown error code
|
||||
};
|
||||
//@}
|
||||
#endif //_INCLUDE_SNMP_ERR_STRINGS
|
||||
|
||||
#endif //_SNMPERRS_H
|
791
backend/camembert/libkmsnmp/snmpmsg.cpp
Normal file
791
backend/camembert/libkmsnmp/snmpmsg.cpp
Normal file
@ -0,0 +1,791 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## snmpmsg.cpp
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
/*===================================================================
|
||||
|
||||
Copyright (c) 1996
|
||||
Hewlett-Packard Company
|
||||
|
||||
ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
Permission to use, copy, modify, distribute and/or sell this software
|
||||
and/or its documentation is hereby granted without fee. User agrees
|
||||
to display the above copyright notice and this license notice in all
|
||||
copies of the software and any documentation of the software. User
|
||||
agrees to assume all liability for the use of the software; Hewlett-Packard
|
||||
makes no representations about the suitability of this software for any
|
||||
purpose. It is provided "AS-IS" without warranty of any kind,either express
|
||||
or implied. User hereby grants a royalty-free license to any and all
|
||||
derivatives based upon this software code base.
|
||||
|
||||
|
||||
SNMP++ S N M P M S G . C P P
|
||||
|
||||
SNMPMESSAGE CLASS DEFINITION
|
||||
|
||||
DESIGN + AUTHOR:
|
||||
Peter E Mellquist
|
||||
|
||||
LANGUAGE:
|
||||
ANSI C++
|
||||
|
||||
DESCRIPTION:
|
||||
ASN.1 encoding / decoding class
|
||||
|
||||
=====================================================================*/
|
||||
char snmpmsg_cpp_version[]="#(@) SNMP++ $Id: snmpmsg.cpp,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $";
|
||||
|
||||
#ifdef WIN32
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
#include <stdio.h> // standard io file
|
||||
|
||||
#include "snmpmsg.h" // header file for SnmpMessage
|
||||
#include "oid_def.h" // changed (Frank Fock)
|
||||
#include "v3.h"
|
||||
#include "vb.h"
|
||||
|
||||
const coldStartOid coldStart;
|
||||
const warmStartOid warmStart;
|
||||
const linkDownOid linkDown;
|
||||
const linkUpOid linkUp;
|
||||
const authenticationFailureOid authenticationFailure;
|
||||
const egpNeighborLossOid egpNeighborLoss;
|
||||
const snmpTrapEnterpriseOid snmpTrapEnterprise;
|
||||
|
||||
//------------[ convert SNMP++ VB to WinSNMP smiVALUE ]----------------
|
||||
int convertVbToSmival( const Vb &tempvb, SmiVALUE *smival )
|
||||
{
|
||||
smival->syntax = tempvb.get_syntax();
|
||||
switch ( smival->syntax ) {
|
||||
|
||||
// case sNMP_SYNTAX_NULL
|
||||
case sNMP_SYNTAX_NULL:
|
||||
case sNMP_SYNTAX_NOSUCHOBJECT:
|
||||
case sNMP_SYNTAX_NOSUCHINSTANCE:
|
||||
case sNMP_SYNTAX_ENDOFMIBVIEW:
|
||||
break;
|
||||
|
||||
// case sNMP_SYNTAX_INT32:
|
||||
case sNMP_SYNTAX_INT:
|
||||
tempvb.get_value(smival->value.sNumber);
|
||||
break;
|
||||
|
||||
// case sNMP_SYNTAX_UINT32:
|
||||
case sNMP_SYNTAX_GAUGE32:
|
||||
case sNMP_SYNTAX_CNTR32:
|
||||
case sNMP_SYNTAX_TIMETICKS:
|
||||
// case sNMP_SYNTAX_UINT32:
|
||||
tempvb.get_value(smival->value.uNumber);
|
||||
break;
|
||||
|
||||
// case Counter64
|
||||
case sNMP_SYNTAX_CNTR64:
|
||||
{
|
||||
Counter64 c64;
|
||||
tempvb.get_value(c64);
|
||||
smival->value.hNumber.hipart = c64.high();
|
||||
smival->value.hNumber.lopart = c64.low();
|
||||
}
|
||||
break;
|
||||
|
||||
case sNMP_SYNTAX_BITS:
|
||||
case sNMP_SYNTAX_OCTETS:
|
||||
case sNMP_SYNTAX_OPAQUE:
|
||||
case sNMP_SYNTAX_IPADDR:
|
||||
{
|
||||
OctetStr os;
|
||||
tempvb.get_value(os);
|
||||
smival->value.string.ptr = NULL;
|
||||
smival->value.string.len = os.len();
|
||||
if ( smival->value.string.len > 0 )
|
||||
{
|
||||
smival->value.string.ptr
|
||||
= (SmiLPBYTE) new unsigned char [smival->value.string.len];
|
||||
if ( smival->value.string.ptr )
|
||||
{
|
||||
for (int i=0; i<(int) smival->value.string.len ; i++)
|
||||
smival->value.string.ptr[i] = os[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
smival->syntax = sNMP_SYNTAX_NULL; // invalidate the smival
|
||||
return SNMP_CLASS_RESOURCE_UNAVAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case sNMP_SYNTAX_OID:
|
||||
{
|
||||
Oid oid;
|
||||
tempvb.get_value(oid);
|
||||
smival->value.oid.ptr = NULL;
|
||||
smival->value.oid.len = oid.len();
|
||||
if ( smival->value.oid.len > 0 )
|
||||
{
|
||||
smival->value.oid.ptr
|
||||
= (SmiLPUINT32) new unsigned long [ smival->value.oid.len];
|
||||
if ( smival->value.oid.ptr )
|
||||
{
|
||||
for (int i=0; i<(int)smival->value.oid.len ; i++)
|
||||
smival->value.oid.ptr[i] = oid[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
smival->syntax = sNMP_SYNTAX_NULL; // invalidate the smival
|
||||
return SNMP_CLASS_RESOURCE_UNAVAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return SNMP_CLASS_INTERNAL_ERROR;
|
||||
}
|
||||
return SNMP_CLASS_SUCCESS;
|
||||
}
|
||||
|
||||
// free a SMI value
|
||||
void freeSmivalDescriptor( SmiVALUE *smival )
|
||||
{
|
||||
switch ( smival->syntax ) {
|
||||
case sNMP_SYNTAX_OCTETS:
|
||||
case sNMP_SYNTAX_OPAQUE:
|
||||
case sNMP_SYNTAX_IPADDR:
|
||||
case sNMP_SYNTAX_BITS: // obsoleted in SNMPv2 Draft Std
|
||||
delete [] smival->value.string.ptr;
|
||||
break;
|
||||
|
||||
case sNMP_SYNTAX_OID:
|
||||
delete [] smival->value.oid.ptr;
|
||||
break;
|
||||
}
|
||||
smival->syntax = sNMP_SYNTAX_NULL;
|
||||
}
|
||||
|
||||
#ifdef _SNMPv3
|
||||
|
||||
int SnmpMessage::unloadv3( Pdu &pdu, // Pdu returned
|
||||
snmp_version &version, // version
|
||||
OctetStr &engine_id, // optional v3
|
||||
OctetStr &security_name, // optional v3
|
||||
long int &security_model,
|
||||
UdpAddress &from_addr)
|
||||
{
|
||||
OctetStr tmp;
|
||||
return unload(pdu, tmp, version, &engine_id,
|
||||
&security_name, &security_model, &from_addr);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int SnmpMessage::load( Pdu pdu,
|
||||
const OctetStr &community,
|
||||
const snmp_version version
|
||||
#ifdef _SNMPv3
|
||||
,const OctetStr* engine_id,
|
||||
const OctetStr* security_name,
|
||||
const int security_model
|
||||
#endif
|
||||
)
|
||||
{
|
||||
int status;
|
||||
|
||||
// make sure pdu is valid
|
||||
if ( !pdu.valid())
|
||||
return SNMP_CLASS_INVALID_PDU;
|
||||
|
||||
// create a raw pdu
|
||||
snmp_pdu *raw_pdu;
|
||||
raw_pdu = snmp_pdu_create( (int) pdu.get_type());
|
||||
|
||||
Oid enterprise;
|
||||
|
||||
// load it up
|
||||
raw_pdu->reqid = pdu.get_request_id();
|
||||
#ifdef _SNMPv3
|
||||
raw_pdu->msgid = pdu.get_message_id();
|
||||
#endif
|
||||
raw_pdu->errstat= (unsigned long) pdu.get_error_status();
|
||||
raw_pdu->errindex= (unsigned long) pdu.get_error_index();
|
||||
|
||||
// if its a V1 trap then load up other values
|
||||
// for v2, use normal pdu format
|
||||
if ( raw_pdu->command == sNMP_PDU_V1TRAP) {
|
||||
// DON'T forget about the v1 trap agent address (changed by Frank Fock)
|
||||
GenAddress gen_addr;
|
||||
IpAddress ip_addr;
|
||||
int addr_set = FALSE;
|
||||
|
||||
if (pdu.get_v1_trap_address(gen_addr))
|
||||
{
|
||||
/* User did set the v1 trap address */
|
||||
if ((gen_addr.get_type() != Address::type_ip) &&
|
||||
(gen_addr.get_type() != Address::type_udp) )
|
||||
{
|
||||
debugprintf(0, "Bad v1 trap address type in pdu");
|
||||
snmp_free_pdu( raw_pdu);
|
||||
return SNMP_CLASS_INVALID_PDU;
|
||||
}
|
||||
|
||||
ip_addr = gen_addr;
|
||||
if (!ip_addr.valid()) {
|
||||
debugprintf(0, "Copy of v1 trap address failed");
|
||||
snmp_free_pdu( raw_pdu);
|
||||
return SNMP_CLASS_RESOURCE_UNAVAIL;
|
||||
}
|
||||
addr_set = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* User did not set the v1 trap address */
|
||||
char addrString[256];
|
||||
if (gethostname(addrString, 255) == 0)
|
||||
{
|
||||
ip_addr = addrString;
|
||||
addr_set = TRUE;
|
||||
}
|
||||
}
|
||||
struct sockaddr_in agent_addr; // agent address socket struct
|
||||
// prepare the agent address
|
||||
memset(&agent_addr, 0, sizeof(agent_addr));
|
||||
agent_addr.sin_family = AF_INET;
|
||||
if (addr_set)
|
||||
{
|
||||
agent_addr.sin_addr.s_addr
|
||||
= inet_addr(((IpAddress &)ip_addr).IpAddress::get_printable());
|
||||
debugprintf(3, "setting v1 trap address to (%s).",
|
||||
((IpAddress &)ip_addr).IpAddress::get_printable());
|
||||
}
|
||||
raw_pdu->agent_addr = agent_addr;
|
||||
|
||||
//-----[ compute generic trap value ]-------------------------------
|
||||
// determine the generic value
|
||||
// 0 - cold start
|
||||
// 1 - warm start
|
||||
// 2 - link down
|
||||
// 3 - link up
|
||||
// 4 - authentication failure
|
||||
// 5 - egpneighborloss
|
||||
// 6 - enterprise specific
|
||||
Oid trapid;
|
||||
pdu.get_notify_id( trapid);
|
||||
if ( !trapid.valid() || trapid.len() < 2 )
|
||||
{
|
||||
snmp_free_pdu( raw_pdu);
|
||||
return SNMP_CLASS_INVALID_NOTIFYID;
|
||||
}
|
||||
raw_pdu->specific_type=0;
|
||||
if ( trapid == coldStart)
|
||||
raw_pdu->trap_type = 0; // cold start
|
||||
else if ( trapid == warmStart)
|
||||
raw_pdu->trap_type = 1; // warm start
|
||||
else if( trapid == linkDown)
|
||||
raw_pdu->trap_type = 2; // link down
|
||||
else if ( trapid == linkUp)
|
||||
raw_pdu->trap_type = 3; // link up
|
||||
else if ( trapid == authenticationFailure )
|
||||
raw_pdu->trap_type = 4; // authentication failure
|
||||
else if ( trapid == egpNeighborLoss)
|
||||
raw_pdu->trap_type = 5; // egp neighbor loss
|
||||
else {
|
||||
raw_pdu->trap_type = 6; // enterprise specific
|
||||
// last oid subid is the specific value
|
||||
// if 2nd to last subid is "0", remove it
|
||||
// enterprise is always the notify oid prefix
|
||||
raw_pdu->specific_type = (int) trapid[(int) (trapid.len()-1)];
|
||||
|
||||
trapid.trim(1);
|
||||
if ( trapid[(int)(trapid.len()-1)] == 0 )
|
||||
trapid.trim(1);
|
||||
enterprise = trapid;
|
||||
}
|
||||
|
||||
if ( raw_pdu->trap_type !=6)
|
||||
pdu.get_notify_enterprise( enterprise);
|
||||
if ( enterprise.len() >0) {
|
||||
// note!!
|
||||
// these are hooks into an SNMP++ oid
|
||||
// and therefor the raw_pdu enterprise
|
||||
// should not free them. null them out!!
|
||||
SmiLPOID rawOid;
|
||||
rawOid = enterprise.oidval();
|
||||
raw_pdu->enterprise = rawOid->ptr;
|
||||
raw_pdu->enterprise_length = (int) rawOid->len;
|
||||
}
|
||||
|
||||
// timestamp
|
||||
TimeTicks timestamp;
|
||||
pdu.get_notify_timestamp( timestamp);
|
||||
raw_pdu->time = ( unsigned long) timestamp;
|
||||
|
||||
}
|
||||
|
||||
// if its a v2 trap then we need to make a few adjustments
|
||||
// vb #1 is the timestamp
|
||||
// vb #2 is the id, represented as an Oid
|
||||
if (( raw_pdu->command == sNMP_PDU_TRAP) ||
|
||||
( raw_pdu->command == sNMP_PDU_INFORM))
|
||||
{
|
||||
Pdu temppdu(pdu);
|
||||
Vb tempvb;
|
||||
|
||||
temppdu.trim(temppdu.get_vb_count());
|
||||
|
||||
// vb #1 is the timestamp
|
||||
TimeTicks timestamp;
|
||||
tempvb.set_oid(SNMP_MSG_OID_SYSUPTIME); // sysuptime
|
||||
pdu.get_notify_timestamp( timestamp);
|
||||
tempvb.set_value ( timestamp);
|
||||
temppdu += tempvb;
|
||||
|
||||
// vb #2 is the id
|
||||
Oid trapid;
|
||||
tempvb.set_oid(SNMP_MSG_OID_TRAPID);
|
||||
pdu.get_notify_id( trapid);
|
||||
tempvb.set_value( trapid);
|
||||
temppdu += tempvb;
|
||||
|
||||
// append the remaining vbs
|
||||
for ( int z=0;z<pdu.get_vb_count();z++) {
|
||||
pdu.get_vb( tempvb,z);
|
||||
temppdu += tempvb;
|
||||
}
|
||||
|
||||
pdu = temppdu; // reassign the pdu to the temp one
|
||||
}
|
||||
// load up the payload
|
||||
// for all Vbs in list, add them to the pdu
|
||||
int vb_count;
|
||||
Vb tempvb;
|
||||
Oid tempoid;
|
||||
SmiLPOID smioid;
|
||||
SmiVALUE smival;
|
||||
|
||||
vb_count = pdu.get_vb_count();
|
||||
for (int z=0;z<vb_count;z++) {
|
||||
pdu.get_vb( tempvb,z);
|
||||
tempvb.get_oid( tempoid);
|
||||
smioid = tempoid.oidval();
|
||||
// clear the value portion, in case its
|
||||
// not already been done so by the app writer
|
||||
// only do it in the case its a get,next or bulk
|
||||
if ((raw_pdu->command == sNMP_PDU_GET) ||
|
||||
(raw_pdu->command == sNMP_PDU_GETNEXT) ||
|
||||
(raw_pdu->command == sNMP_PDU_GETBULK))
|
||||
tempvb.set_null();
|
||||
status = convertVbToSmival( tempvb, &smival );
|
||||
if ( status != SNMP_CLASS_SUCCESS) {
|
||||
snmp_free_pdu( raw_pdu);
|
||||
return status;
|
||||
}
|
||||
// add the vb to the raw pdu
|
||||
snmp_add_var( raw_pdu, smioid->ptr, (int) smioid->len, &smival);
|
||||
|
||||
freeSmivalDescriptor( &smival);
|
||||
}
|
||||
|
||||
// ASN1 encode the pdu
|
||||
#ifdef _SNMPv3
|
||||
if (version == version3)
|
||||
{
|
||||
if ((!engine_id) || (!security_name))
|
||||
{
|
||||
debugprintf(1, "SnmpMessage::load, security_name and engine_id needed for SNMPv3 message.");
|
||||
snmp_free_pdu( raw_pdu);
|
||||
return SNMP_CLASS_INVALID_TARGET;
|
||||
}
|
||||
|
||||
status = v3MP::I->snmp_build(raw_pdu, databuff, (int *)&bufflen,
|
||||
*engine_id, *security_name, security_model,
|
||||
pdu.get_security_level(),
|
||||
pdu.get_context_engine_id(),
|
||||
pdu.get_context_name());
|
||||
if (status == SNMPv3_MP_OK) {
|
||||
if ((pdu.get_type() == sNMP_PDU_RESPONSE) &&
|
||||
((int)pdu.get_maxsize_scopedpdu() < pdu.get_asn1_length())) {
|
||||
debugprintf(0, "ERROR: TOO BIG should not happen.");
|
||||
// prevention of SNMP++ Enterprise Oid death
|
||||
if ( enterprise.len() >0) {
|
||||
raw_pdu->enterprise = 0;
|
||||
raw_pdu->enterprise_length=0;
|
||||
}
|
||||
snmp_free_pdu( raw_pdu);
|
||||
return SNMP_ERROR_TOO_BIG;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
status = snmp_build( raw_pdu, databuff, (int *) &bufflen, version,
|
||||
community.data(), (int) community.len());
|
||||
debugprintf(3, "SnmpMsg: return status of snmpBuild (%i)",status);
|
||||
|
||||
if ((status != 0)
|
||||
#ifdef _SNMPv3
|
||||
&& ((version != version3) || (status != SNMPv3_MP_OK))
|
||||
#endif
|
||||
) {
|
||||
valid_flag = false;
|
||||
// prevention of SNMP++ Enterprise Oid death
|
||||
if ( enterprise.len() >0) {
|
||||
raw_pdu->enterprise = 0;
|
||||
raw_pdu->enterprise_length=0;
|
||||
}
|
||||
snmp_free_pdu( raw_pdu);
|
||||
#ifdef _SNMPv3
|
||||
if (version == version3)
|
||||
return status;
|
||||
else
|
||||
#endif
|
||||
// NOTE: This is an assumption - in most cases during normal
|
||||
// operation the reason is a tooBig - another could be a
|
||||
// damaged variable binding.
|
||||
return SNMP_ERROR_TOO_BIG;
|
||||
}
|
||||
valid_flag = true;
|
||||
|
||||
// prevention of SNMP++ Enterprise Oid death
|
||||
if ( enterprise.len() >0) {
|
||||
raw_pdu->enterprise = 0;
|
||||
raw_pdu->enterprise_length=0;
|
||||
}
|
||||
|
||||
snmp_free_pdu( raw_pdu);
|
||||
|
||||
return SNMP_CLASS_SUCCESS;
|
||||
}
|
||||
|
||||
// load up a SnmpMessage
|
||||
int SnmpMessage::load( unsigned char *data,
|
||||
unsigned long len)
|
||||
{
|
||||
bufflen = SNMP_MSG_LENGTH;
|
||||
valid_flag = false;
|
||||
|
||||
if ( len <= SNMP_MSG_LENGTH) {
|
||||
memcpy( (unsigned char *) databuff, (unsigned char *) data,
|
||||
(unsigned int) len);
|
||||
bufflen = len;
|
||||
valid_flag = true;
|
||||
}
|
||||
else
|
||||
return SNMP_ERROR_WRONG_LENGTH;
|
||||
|
||||
return SNMP_CLASS_SUCCESS;
|
||||
}
|
||||
|
||||
// unload the data into SNMP++ objects
|
||||
int SnmpMessage::unload( Pdu &pdu, // Pdu object
|
||||
OctetStr &community, // community object
|
||||
snmp_version &version // SNMP version #
|
||||
#ifdef _SNMPv3
|
||||
,OctetStr *engine_id, // optional v3
|
||||
OctetStr *security_name, // optional v3
|
||||
long int *security_model,
|
||||
UdpAddress *from_addr
|
||||
#endif
|
||||
)
|
||||
{
|
||||
unsigned char community_name[255];
|
||||
unsigned long community_len;
|
||||
|
||||
Pdu tmppdu; // Only used to reset "pdu"
|
||||
pdu = tmppdu;
|
||||
|
||||
if ( !valid_flag)
|
||||
return SNMP_CLASS_INVALID;
|
||||
|
||||
snmp_pdu *raw_pdu;
|
||||
raw_pdu = snmp_pdu_create(0); // do a "snmp_free_pdu( raw_pdu)" before return
|
||||
|
||||
int status;
|
||||
|
||||
#ifdef _SNMPv3
|
||||
OctetStr context_engine_id;
|
||||
OctetStr context_name;
|
||||
long int security_level;
|
||||
|
||||
if ((security_model) && (security_name) && (engine_id)) {
|
||||
status = v3MP::I->snmp_parse(raw_pdu, databuff, (int)bufflen, *engine_id,
|
||||
*security_name, context_engine_id, context_name,
|
||||
security_level, *security_model, version, *from_addr);
|
||||
pdu.set_context_engine_id(context_engine_id);
|
||||
pdu.set_context_name(context_name);
|
||||
pdu.set_security_level(security_level);
|
||||
pdu.set_message_id(raw_pdu->msgid);
|
||||
pdu.set_maxsize_scopedpdu(raw_pdu->maxsize_scopedpdu);
|
||||
if (status != SNMPv3_MP_OK) {
|
||||
pdu.set_request_id( raw_pdu->reqid);
|
||||
pdu.set_type( raw_pdu->command);
|
||||
snmp_free_pdu( raw_pdu);
|
||||
return status;
|
||||
}
|
||||
}
|
||||
else {
|
||||
#endif
|
||||
status = snmp_parse( raw_pdu, databuff, community_name, community_len,
|
||||
version, (int) bufflen);
|
||||
if ( status != 0) {
|
||||
snmp_free_pdu( raw_pdu);
|
||||
return status;
|
||||
}
|
||||
community.set_data( community_name, community_len);
|
||||
|
||||
#ifdef _SNMPv3
|
||||
}
|
||||
#endif
|
||||
// load up the SNMP++ variables
|
||||
pdu.set_request_id(raw_pdu->reqid);
|
||||
pdu.set_error_status((int) raw_pdu->errstat);
|
||||
pdu.set_error_index((int) raw_pdu->errindex);
|
||||
pdu.set_type( raw_pdu->command);
|
||||
|
||||
// deal with traps a little different
|
||||
if ( raw_pdu->command == sNMP_PDU_V1TRAP) {
|
||||
// timestamp
|
||||
TimeTicks timestamp;
|
||||
timestamp = raw_pdu->time;
|
||||
pdu.set_notify_timestamp( timestamp);
|
||||
|
||||
// set the agent address
|
||||
IpAddress agent_addr(inet_ntoa(raw_pdu->agent_addr.sin_addr));
|
||||
if (agent_addr != "0.0.0.0")
|
||||
{
|
||||
pdu.set_v1_trap_address(agent_addr);
|
||||
debugprintf(4, "reveiced trap with v1 trap address (%s).",
|
||||
agent_addr.get_printable());
|
||||
}
|
||||
// set enterprise, notifyid
|
||||
Oid enterprise;
|
||||
|
||||
if (raw_pdu->enterprise_length >0) {
|
||||
for (int i=0; i< raw_pdu->enterprise_length; i++) {
|
||||
enterprise += (int) (raw_pdu->enterprise[i]);
|
||||
}
|
||||
pdu.set_notify_enterprise(enterprise);
|
||||
}
|
||||
switch (raw_pdu->trap_type) {
|
||||
case 0:
|
||||
pdu.set_notify_id(coldStart);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
pdu.set_notify_id(warmStart);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
pdu.set_notify_id(linkDown);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
pdu.set_notify_id(linkUp);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
pdu.set_notify_id(authenticationFailure);
|
||||
break;
|
||||
|
||||
case 5:
|
||||
pdu.set_notify_id(egpNeighborLoss);
|
||||
break;
|
||||
|
||||
case 6: { // enterprise specific
|
||||
// base id + specific #
|
||||
Oid eOid = enterprise;
|
||||
eOid += 0ul;
|
||||
eOid += raw_pdu->specific_type;
|
||||
pdu.set_notify_id( eOid);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
debugprintf(1, "snmpmsg: Wrong trap_type");
|
||||
}
|
||||
}
|
||||
|
||||
// vbs
|
||||
Vb tempvb;
|
||||
Oid tempoid;
|
||||
struct variable_list *vp;
|
||||
int vb_nr = 1;
|
||||
|
||||
for(vp = raw_pdu->variables; vp; vp = vp->next_variable, vb_nr++) {
|
||||
|
||||
// extract the oid portion
|
||||
tempoid.set_data( (unsigned long *)vp->name,
|
||||
( unsigned int) vp->name_length);
|
||||
tempvb.set_oid( tempoid);
|
||||
|
||||
// extract the value portion
|
||||
switch(vp->type){
|
||||
|
||||
// octet string
|
||||
case sNMP_SYNTAX_OCTETS:
|
||||
{
|
||||
OctetStr octets( (unsigned char *) vp->val.string,
|
||||
(unsigned long) vp->val_len);
|
||||
tempvb.set_value( octets);
|
||||
}
|
||||
break;
|
||||
case sNMP_SYNTAX_OPAQUE:
|
||||
{
|
||||
OpaqueStr octets( (unsigned char *) vp->val.string,
|
||||
(unsigned long) vp->val_len);
|
||||
tempvb.set_value( octets);
|
||||
}
|
||||
break;
|
||||
|
||||
// object id
|
||||
case sNMP_SYNTAX_OID:
|
||||
{
|
||||
Oid oid( (unsigned long*) vp->val.objid,
|
||||
(int) vp->val_len);
|
||||
tempvb.set_value( oid);
|
||||
if ((vb_nr == 2) &&
|
||||
((raw_pdu->command == sNMP_PDU_TRAP) ||
|
||||
(raw_pdu->command == sNMP_PDU_INFORM)) &&
|
||||
(tempoid == SNMP_MSG_OID_TRAPID))
|
||||
{
|
||||
// set notify_id
|
||||
pdu.set_notify_id(oid);
|
||||
continue; // don't add vb to pdu
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
// timeticks
|
||||
case sNMP_SYNTAX_TIMETICKS:
|
||||
{
|
||||
TimeTicks timeticks( (unsigned long) *(vp->val.integer));
|
||||
tempvb.set_value( timeticks);
|
||||
if ((vb_nr == 1) &&
|
||||
((raw_pdu->command == sNMP_PDU_TRAP) ||
|
||||
(raw_pdu->command == sNMP_PDU_INFORM)) &&
|
||||
(tempoid == SNMP_MSG_OID_SYSUPTIME))
|
||||
{
|
||||
// set notify_timestamp
|
||||
pdu.set_notify_timestamp( timeticks);
|
||||
continue; // don't add vb to pdu
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
// 32 bit counter
|
||||
case sNMP_SYNTAX_CNTR32:
|
||||
{
|
||||
Counter32 counter32( (unsigned long) *(vp->val.integer));
|
||||
tempvb.set_value( counter32);
|
||||
}
|
||||
break;
|
||||
|
||||
// 32 bit gauge
|
||||
case sNMP_SYNTAX_GAUGE32:
|
||||
{
|
||||
Gauge32 gauge32( (unsigned long) *(vp->val.integer));
|
||||
tempvb.set_value( gauge32);
|
||||
}
|
||||
break;
|
||||
|
||||
// ip address
|
||||
case sNMP_SYNTAX_IPADDR:
|
||||
{
|
||||
char buffer[42];
|
||||
|
||||
if (vp->val_len == 16)
|
||||
sprintf( buffer, "%02x%02x:%02x%02x:%02x%02x:%02x%02x:"
|
||||
"%02x%02x:%02x%02x:%02x%02x:%02x%02x",
|
||||
vp->val.string[ 0], vp->val.string[ 1], vp->val.string[ 2],
|
||||
vp->val.string[ 3], vp->val.string[ 4], vp->val.string[ 5],
|
||||
vp->val.string[ 6], vp->val.string[ 7], vp->val.string[ 8],
|
||||
vp->val.string[ 9], vp->val.string[10], vp->val.string[11],
|
||||
vp->val.string[12], vp->val.string[13], vp->val.string[14],
|
||||
vp->val.string[15]);
|
||||
else
|
||||
sprintf( buffer,"%d.%d.%d.%d",
|
||||
vp->val.string[0], vp->val.string[1],
|
||||
vp->val.string[2], vp->val.string[3]);
|
||||
IpAddress ipaddress( buffer);
|
||||
tempvb.set_value( ipaddress);
|
||||
}
|
||||
break;
|
||||
|
||||
// 32 bit integer
|
||||
case sNMP_SYNTAX_INT:
|
||||
{
|
||||
SnmpInt32 int32( (long) *(vp->val.integer));
|
||||
tempvb.set_value( int32);
|
||||
}
|
||||
break;
|
||||
|
||||
// 32 bit unsigned integer
|
||||
/* Not distinguishable from Gauge32
|
||||
case sNMP_SYNTAX_UINT32:
|
||||
{
|
||||
SnmpUInt32 uint32( (unsigned long) *(vp->val.integer));
|
||||
tempvb.set_value( uint32);
|
||||
}
|
||||
break;
|
||||
*/
|
||||
// v2 counter 64's
|
||||
case sNMP_SYNTAX_CNTR64:
|
||||
{ // Frank Fock (was empty before)
|
||||
Counter64 c64(((counter64*)vp->val.counter64)->high,
|
||||
((counter64*)vp->val.counter64)->low);
|
||||
tempvb.set_value( c64);
|
||||
break;
|
||||
}
|
||||
case sNMP_SYNTAX_NULL:
|
||||
tempvb.set_null();
|
||||
break;
|
||||
|
||||
// v2 vb exceptions
|
||||
case sNMP_SYNTAX_NOSUCHOBJECT:
|
||||
case sNMP_SYNTAX_NOSUCHINSTANCE:
|
||||
case sNMP_SYNTAX_ENDOFMIBVIEW:
|
||||
set_exception_status( &tempvb, vp->type);
|
||||
break;
|
||||
|
||||
default:
|
||||
tempvb.set_null();
|
||||
|
||||
} // end switch
|
||||
|
||||
// append the vb to the pdu
|
||||
pdu += tempvb;
|
||||
}
|
||||
|
||||
snmp_free_pdu( raw_pdu);
|
||||
|
||||
// if incoming number of vbs > max number
|
||||
// -> return TOO BIG error!
|
||||
if (vb_nr-1 > MAX_VBS)
|
||||
return SNMP_ERROR_TOO_BIG;
|
||||
|
||||
return SNMP_CLASS_SUCCESS;
|
||||
}
|
||||
|
165
backend/camembert/libkmsnmp/snmpmsg.h
Normal file
165
backend/camembert/libkmsnmp/snmpmsg.h
Normal file
@ -0,0 +1,165 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## snmpmsg.h
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
/*===================================================================
|
||||
|
||||
Copyright (c) 1999
|
||||
Hewlett-Packard Company
|
||||
|
||||
ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
Permission to use, copy, modify, distribute and/or sell this software
|
||||
and/or its documentation is hereby granted without fee. User agrees
|
||||
to display the above copyright notice and this license notice in all
|
||||
copies of the software and any documentation of the software. User
|
||||
agrees to assume all liability for the use of the software; Hewlett-Packard
|
||||
makes no representations about the suitability of this software for any
|
||||
purpose. It is provided "AS-IS without warranty of any kind,either express
|
||||
or implied. User hereby grants a royalty-free license to any and all
|
||||
derivatives based upon this software code base.
|
||||
|
||||
|
||||
SNMP++ S N M P M E S S A G E . H
|
||||
|
||||
SNMPMESSAGE CLASS DEFINITION
|
||||
|
||||
DESIGN + AUTHOR:
|
||||
Peter E Mellquist
|
||||
|
||||
LANGUAGE:
|
||||
ANSI C++
|
||||
|
||||
OPERATING SYSTEMS:
|
||||
Win 32
|
||||
BSD UNIX
|
||||
|
||||
DESCRIPTION:
|
||||
ASN.1 encoding / decoding class
|
||||
|
||||
=====================================================================*/
|
||||
// $Id: snmpmsg.h,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $
|
||||
|
||||
#ifndef _SNMPMSG
|
||||
#define _SNMPMSG
|
||||
|
||||
#include "config_snmp_pp.h"
|
||||
|
||||
#include "smival.h"
|
||||
#include "pdu.h"
|
||||
#include "target.h"
|
||||
#include "asn1.h"
|
||||
#include "mp_v3.h"
|
||||
|
||||
DLLOPT void freeSmivalDescriptor( SmiVALUE* );
|
||||
DLLOPT int convertVbToSmival( const Vb&, SmiVALUE* );
|
||||
|
||||
#define SNMP_MSG_OID_SYSUPTIME "1.3.6.1.2.1.1.3.0"
|
||||
#define SNMP_MSG_OID_TRAPID "1.3.6.1.6.3.1.1.4.1.0"
|
||||
|
||||
// SnmpMessage Class
|
||||
class DLLOPT SnmpMessage
|
||||
{
|
||||
public:
|
||||
|
||||
// construct a SnmpMessage object
|
||||
SnmpMessage() : bufflen(SNMP_MSG_LENGTH), valid_flag(false) {};
|
||||
// load up using a Pdu, community and SNMP version
|
||||
// performs ASN.1 serialization
|
||||
// result status returned
|
||||
#ifdef _SNMPv3
|
||||
int load( Pdu pdu, // Pdu to serialize
|
||||
const OctetStr &community, // community name to use
|
||||
const snmp_version version, // SNMP version, v1 or v2
|
||||
const OctetStr *engine_id = 0, // optional v3
|
||||
const OctetStr *security_name = 0, // optional v3
|
||||
const int security_model = 0); // optional v3
|
||||
#else
|
||||
int load( Pdu pdu, // Pdu to serialize
|
||||
const OctetStr &community, // community name to use
|
||||
const snmp_version version); // SNMP version, v1 or v2
|
||||
#endif
|
||||
|
||||
// load up message using ASN.1 data stream
|
||||
// status is returned
|
||||
int load( unsigned char *data, // data to be loaded
|
||||
unsigned long len); // len of data to be loaded
|
||||
|
||||
// unload ( unserialize ) into SNMP++ Pdu, community and version
|
||||
// status is returned
|
||||
#ifdef _SNMPv3
|
||||
int unload( Pdu &pdu, // Pdu returned
|
||||
OctetStr &community, // community name
|
||||
snmp_version &version, // version
|
||||
OctetStr *engine_id = 0, // optional v3
|
||||
OctetStr *security_name = 0, // optional v3
|
||||
long int *security_model = 0,
|
||||
UdpAddress *from_addr = 0);
|
||||
#else
|
||||
int unload( Pdu &pdu, // Pdu returned
|
||||
OctetStr &community, // community name
|
||||
snmp_version &version); // version
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef _SNMPv3
|
||||
int loadv3( Pdu pdu, // Pdu to serialize
|
||||
const OctetStr &engine_id, // engine_id to use
|
||||
const OctetStr &sec_name, // securit_name to use
|
||||
const int sec_model, // security_model to use
|
||||
const snmp_version version) // SNMP version, v3
|
||||
{ return load(pdu, "", version, &engine_id, &sec_name, sec_model); }
|
||||
|
||||
int unloadv3( Pdu &pdu, // Pdu returned
|
||||
snmp_version &version, // version
|
||||
OctetStr &engine_id, // optional v3
|
||||
OctetStr &security_name, // optional v3
|
||||
long int &security_model,
|
||||
UdpAddress &from_addr);
|
||||
|
||||
// returns TRUE if the message in the buffer is a v3 message
|
||||
bool is_v3_message() {return v3MP::is_v3_msg(databuff, (int)bufflen);};
|
||||
|
||||
#endif
|
||||
|
||||
// return the validity of the message
|
||||
bool valid() const { return valid_flag;};
|
||||
|
||||
// return raw data
|
||||
// check validity
|
||||
unsigned char *data() { return databuff; };
|
||||
|
||||
// returns len
|
||||
// check validity
|
||||
unsigned long len() const { return bufflen; };
|
||||
|
||||
protected:
|
||||
|
||||
unsigned char databuff[SNMP_MSG_LENGTH];
|
||||
unsigned int bufflen;
|
||||
bool valid_flag;
|
||||
};
|
||||
#endif // _SNMPMSG
|
652
backend/camembert/libkmsnmp/target.h
Normal file
652
backend/camembert/libkmsnmp/target.h
Normal file
@ -0,0 +1,652 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## target.h
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
/*===================================================================
|
||||
|
||||
Copyright (c) 1999
|
||||
Hewlett-Packard Company
|
||||
|
||||
ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
Permission to use, copy, modify, distribute and/or sell this software
|
||||
and/or its documentation is hereby granted without fee. User agrees
|
||||
to display the above copyright notice and this license notice in all
|
||||
copies of the software and any documentation of the software. User
|
||||
agrees to assume all liability for the use of the software; Hewlett-Packard
|
||||
makes no representations about the suitability of this software for any
|
||||
purpose. It is provided "AS-IS" without warranty of any kind,either express
|
||||
or implied. User hereby grants a royalty-free license to any and all
|
||||
derivatives based upon this software code base.
|
||||
|
||||
|
||||
SNMP++ T A R G E T . H
|
||||
|
||||
TARGET CLASS DEFINITION
|
||||
|
||||
DESIGN + AUTHOR:
|
||||
Peter E Mellquist
|
||||
|
||||
LANGUAGE:
|
||||
ANSI C++
|
||||
|
||||
OPERATING SYSTEMS:
|
||||
DOS/WINDOWS 3.1
|
||||
BSD UNIX
|
||||
|
||||
DESCRIPTION:
|
||||
Target class defines target SNMP agents.
|
||||
|
||||
=====================================================================*/
|
||||
// $Id: target.h,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $
|
||||
|
||||
#ifndef _TARGET
|
||||
#define _TARGET
|
||||
|
||||
//----[ includes ]-----------------------------------------------------
|
||||
|
||||
#include "config_snmp_pp.h"
|
||||
#include "address.h"
|
||||
#include "octet.h"
|
||||
#include "collect.h"
|
||||
|
||||
//----[ enumerated types for SNMP versions ]---------------------------
|
||||
/**
|
||||
* The SNMP version to use is passed with this enum.
|
||||
*/
|
||||
enum snmp_version
|
||||
{
|
||||
version1, ///< (0) SNMPv1
|
||||
version2c ///< (1) SNMPv2c
|
||||
#ifdef _SNMPv3
|
||||
,version2stern, ///< (2) Dont use this!
|
||||
version3 ///< (3) SNMPv3
|
||||
#endif
|
||||
};
|
||||
|
||||
//----[ Target class ]-------------------------------------------------
|
||||
/**
|
||||
* Abstract class used to provide a virtual interface into Targets.
|
||||
*
|
||||
* @note Although it is possible to create an object of this class,
|
||||
* you won't be happy with that...
|
||||
*/
|
||||
class DLLOPT SnmpTarget
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Enum to identify a target object through SnmpTarget::get_type() method.
|
||||
*/
|
||||
enum target_type
|
||||
{
|
||||
type_base, ///< It is a SnmpTarget object
|
||||
type_ctarget, ///< It is a CTarget object
|
||||
type_utarget ///< It is a Utarget object
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a SnmpTarget object with default values.
|
||||
* The validity of the target will be false.
|
||||
*/
|
||||
SnmpTarget()
|
||||
: validity(false), timeout(default_timeout), retries(default_retries),
|
||||
version(version1), ttype(type_base) {};
|
||||
|
||||
/**
|
||||
* Create a SnmpTarget object with the given Address.
|
||||
*/
|
||||
SnmpTarget( const Address &address)
|
||||
: validity(false), timeout(default_timeout), retries(default_retries),
|
||||
version(version1), ttype(type_base), my_address(address)
|
||||
{ if (my_address.valid()) validity = true; };
|
||||
|
||||
/**
|
||||
* Destructor that has nothing to do.
|
||||
*/
|
||||
virtual ~SnmpTarget() {};
|
||||
|
||||
/**
|
||||
* Return the type of the target object.
|
||||
*
|
||||
* If a SNMP message is received through a callback (that only
|
||||
* passes a SnmpTarget pointer to the callback function), this
|
||||
* method can be used to check the type of the object before doing a
|
||||
* cast to CTarget or UTarget.
|
||||
*/
|
||||
target_type get_type() const { return ttype; };
|
||||
|
||||
/**
|
||||
* Returns the validity of the target object.
|
||||
*
|
||||
* @return true, if the target is valid.
|
||||
*/
|
||||
bool valid() const { return validity;};
|
||||
|
||||
/**
|
||||
* Set the retry value.
|
||||
*
|
||||
* @param r - The number of retries if no response is received.
|
||||
*/
|
||||
void set_retry( const int r) { retries = r; };
|
||||
|
||||
/**
|
||||
* Get the retry value.
|
||||
*
|
||||
* @return The number of retries on timeout.
|
||||
*/
|
||||
int get_retry() const { return retries; };
|
||||
|
||||
|
||||
/**
|
||||
* Set the timeout for requests.
|
||||
*
|
||||
* The default timeout for requests is 1 second (100).
|
||||
*
|
||||
* @param t - Timeout in 10ms, so 100 will set the timeout to 1 second.
|
||||
*/
|
||||
void set_timeout( const unsigned long t) { timeout = t; };
|
||||
|
||||
/**
|
||||
* Get the timeout.
|
||||
*
|
||||
* @return The timeout for requests sent using this target object.
|
||||
*/
|
||||
unsigned long get_timeout() const { return timeout; };
|
||||
|
||||
/**
|
||||
* Change the default timeout.
|
||||
*
|
||||
* Changing the default timeout value will only have an effect for
|
||||
* target objects that are created after setting this value.
|
||||
*
|
||||
* @param t - The new default timeout value
|
||||
*/
|
||||
static void set_default_timeout( const unsigned long t)
|
||||
{ default_timeout = t; };
|
||||
|
||||
/**
|
||||
* Change the default retries vlaue.
|
||||
*
|
||||
* Changing the default retries value will only have an effect for
|
||||
* target objects that are created after setting this value.
|
||||
*
|
||||
* @param r - The new retries value
|
||||
*/
|
||||
static void set_default_retries( const int r) { default_retries = r; };
|
||||
|
||||
/**
|
||||
* Clone operator.
|
||||
*
|
||||
* Virtual clone operation for creating a new SnmpTarget from an existing
|
||||
* SnmpTarget.
|
||||
*
|
||||
* @note The caller MUST use the delete operation on the return
|
||||
* value when done.
|
||||
*
|
||||
* @return A pointer to the new object on success, 0 on failure.
|
||||
*/
|
||||
virtual SnmpTarget *clone() const;
|
||||
|
||||
/**
|
||||
* Get the address object.
|
||||
*
|
||||
* @param address - GenAddress object to store the target address.
|
||||
* @return TRUE on success.
|
||||
*/
|
||||
int get_address( GenAddress &address) const;
|
||||
|
||||
/**
|
||||
* Get the address object.
|
||||
*
|
||||
* @param address - GenAddress object to store the target address.
|
||||
* @return TRUE on success.
|
||||
*/
|
||||
const GenAddress &get_address() const { return my_address; };
|
||||
|
||||
/**
|
||||
* Set the address object.
|
||||
*
|
||||
* @param address - The address that this target should use.
|
||||
* @return TRUE on success.
|
||||
*/
|
||||
virtual int set_address( const Address &address);
|
||||
|
||||
/**
|
||||
* Get the SNMP version for this target.
|
||||
*
|
||||
* @return The SNMP version of this target object.
|
||||
* @see enum snmp_version
|
||||
*/
|
||||
snmp_version get_version() const { return version;};
|
||||
|
||||
/**
|
||||
* Set the SNMP version of this target.
|
||||
*
|
||||
* @param v - The SNMP version that should be used for sending messages.
|
||||
*/
|
||||
void set_version( const snmp_version v) { version = v; };
|
||||
|
||||
/**
|
||||
* Overloeaded compare operator.
|
||||
*
|
||||
* Two SnmpTarget objects are considered equal, if all member
|
||||
* variables are equal.
|
||||
*
|
||||
* @return 1 if targets are equal, 0 if not.
|
||||
*/
|
||||
int operator==(const SnmpTarget &rhs);
|
||||
|
||||
protected:
|
||||
bool validity; ///< Validity of the object
|
||||
unsigned long timeout; ///< xmit timeout in 10 milli secs
|
||||
int retries; ///< number of retries
|
||||
snmp_version version; ///< SNMP version to use
|
||||
target_type ttype; ///< Type of the target
|
||||
GenAddress my_address; ///< Address object
|
||||
|
||||
static unsigned long default_timeout; ///< default timeout for new objects
|
||||
static int default_retries; ///< default retries for new objects
|
||||
};
|
||||
|
||||
//----[ CTarget class ]----------------------------------------------
|
||||
/**
|
||||
* Community based target object.
|
||||
* This target can be used for SNMPv1 and SNMPv2c messages.
|
||||
*/
|
||||
class DLLOPT CTarget: public SnmpTarget
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor with no args.
|
||||
* The validity of the target will be false.
|
||||
*/
|
||||
CTarget();
|
||||
|
||||
/**
|
||||
* Constructor with all args.
|
||||
*
|
||||
* @param address - Address of the target host (cann be any address object)
|
||||
* @param read_community_name - Community for get requests
|
||||
* @param write_community_name - Community for set requests
|
||||
*/
|
||||
CTarget( const Address &address,
|
||||
const char *read_community_name,
|
||||
const char *write_community_name);
|
||||
|
||||
/**
|
||||
* Constructor with all args.
|
||||
*
|
||||
* @param address - Address of the target host (cann be any address object)
|
||||
* @param read_community_name - Community for get requests
|
||||
* @param write_community_name - Community for set requests
|
||||
*/
|
||||
CTarget( const Address &address,
|
||||
const OctetStr &read_community_name,
|
||||
const OctetStr &write_community_name);
|
||||
|
||||
/**
|
||||
* Constructor with only address.
|
||||
*
|
||||
* The read and write community names will be set to "public".
|
||||
*
|
||||
* @param address - Address of the target host (cann be any address object)
|
||||
*/
|
||||
CTarget( const Address &address);
|
||||
|
||||
/**
|
||||
* Constructor from existing CTarget.
|
||||
*/
|
||||
CTarget( const CTarget &target);
|
||||
|
||||
/**
|
||||
* Destructor, that has nothing to do.
|
||||
*/
|
||||
~CTarget() {};
|
||||
|
||||
/**
|
||||
* Clone operator.
|
||||
*
|
||||
* Clone operation for creating a new CTarget from an existing
|
||||
* CTarget.
|
||||
*
|
||||
* @note The caller MUST use the delete operation on the return
|
||||
* value when done.
|
||||
*
|
||||
* @return A pointer to the new object on success, 0 on failure.
|
||||
*/
|
||||
SnmpTarget *clone() const { return (SnmpTarget *) new CTarget(*this); };
|
||||
|
||||
/**
|
||||
* Get the read community name.
|
||||
*
|
||||
* @return C string of the read community.
|
||||
*/
|
||||
const char * get_readcommunity() const
|
||||
{ return (const char *) read_community.get_printable(); };
|
||||
|
||||
/**
|
||||
* Get the read community name.
|
||||
*
|
||||
* @param oct - OctetStr that will be filled with the read community name.
|
||||
*/
|
||||
void get_readcommunity( OctetStr& oct) const { oct = read_community; };
|
||||
|
||||
/**
|
||||
* Set the read community name.
|
||||
*
|
||||
* @param str - The new read community name
|
||||
*/
|
||||
void set_readcommunity( const char * str) { read_community = str; };
|
||||
|
||||
/**
|
||||
* Set the read community name.
|
||||
*
|
||||
* @param oct - The new read community name
|
||||
*/
|
||||
void set_readcommunity( const OctetStr& oct) { read_community = oct; };
|
||||
|
||||
/**
|
||||
* Get the write community name.
|
||||
*
|
||||
* @return C string of the write community.
|
||||
*/
|
||||
const char * get_writecommunity() const
|
||||
{ return (const char *) write_community.get_printable(); };
|
||||
|
||||
/**
|
||||
* Get the write community name.
|
||||
*
|
||||
* @param oct - OctetStr that will be filled with the write community name.
|
||||
*/
|
||||
void get_writecommunity( OctetStr &oct) const { oct = write_community; };
|
||||
|
||||
/**
|
||||
* Set the write community name.
|
||||
*
|
||||
* @param str - The new write community name
|
||||
*/
|
||||
void set_writecommunity( const char * str) { write_community = str; };
|
||||
|
||||
/**
|
||||
* Set the write community name.
|
||||
*
|
||||
* @param oct - The new write community name
|
||||
*/
|
||||
void set_writecommunity( const OctetStr &oct) { write_community = oct; };
|
||||
|
||||
/**
|
||||
* Overloaded assignment operator.
|
||||
*/
|
||||
CTarget& operator=( const CTarget& target);
|
||||
|
||||
/**
|
||||
* Overloeaded compare operator.
|
||||
*
|
||||
* Two CTarget objects are considered equal, if all member variables
|
||||
* and the base classes are equal.
|
||||
*
|
||||
* @return 1 if targets are equal, 0 if not.
|
||||
*/
|
||||
int operator==( const CTarget &rhs);
|
||||
|
||||
/**
|
||||
* Get all values of a CTarget object.
|
||||
*
|
||||
* @param read_comm - Read community name
|
||||
* @param write_comm - Write community name
|
||||
* @param address - Address of the target
|
||||
* @param t - Timeout value
|
||||
* @param r - Retries value
|
||||
* @param v - The SNMP version of this target
|
||||
*
|
||||
* @return TRUE on success and FALSE on failure.
|
||||
*/
|
||||
int resolve_to_C( OctetStr& read_comm,
|
||||
OctetStr& write_comm,
|
||||
GenAddress &address,
|
||||
unsigned long &t,
|
||||
int &r,
|
||||
unsigned char &v) const;
|
||||
|
||||
protected:
|
||||
OctetStr read_community; // get community
|
||||
OctetStr write_community; // set community
|
||||
};
|
||||
|
||||
// create OidCollection type
|
||||
typedef SnmpCollection<SnmpTarget> TargetCollection;
|
||||
|
||||
#ifdef _SNMPv3
|
||||
#define INITIAL_USER "initial"
|
||||
#else
|
||||
#define INITIAL_USER "public"
|
||||
#endif
|
||||
|
||||
//----[ UTarget class ]----------------------------------------------
|
||||
/**
|
||||
* User based Target.
|
||||
*
|
||||
* This class is used for SNMPv3 targets.
|
||||
*/
|
||||
class DLLOPT UTarget: public SnmpTarget
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor with no args.
|
||||
* The validity of the target will be false.
|
||||
*/
|
||||
UTarget( void);
|
||||
|
||||
/**
|
||||
* Constructor with all args.
|
||||
*
|
||||
* @param address - Address of the target host (cann be any address object)
|
||||
* @param sec_name - The security name
|
||||
* @param sec_model - The security model to use
|
||||
*/
|
||||
UTarget( const Address &address,
|
||||
const char *sec_name,
|
||||
const int sec_model);
|
||||
|
||||
/**
|
||||
* Constructor with all args.
|
||||
*
|
||||
* @param address - Address of the target host (cann be any address object)
|
||||
* @param sec_name - The security name
|
||||
* @param sec_model - The security model to use
|
||||
*/
|
||||
UTarget( const Address &address,
|
||||
const OctetStr &sec_name,
|
||||
const int sec_model);
|
||||
|
||||
/**
|
||||
* Constructor with only address.
|
||||
*
|
||||
* Assumes the following defaults: security_name: initial, version: SNMPv3,
|
||||
* security_model: v3MP.
|
||||
*
|
||||
* @param address - Address of the target host (cann be any address object)
|
||||
*/
|
||||
UTarget( const Address &address);
|
||||
|
||||
/**
|
||||
* Constructor from existing UTarget.
|
||||
*/
|
||||
UTarget( const UTarget &target);
|
||||
|
||||
/**
|
||||
* Destructor, that has nothing to do.
|
||||
*/
|
||||
~UTarget() {};
|
||||
|
||||
/**
|
||||
* Clone operator.
|
||||
*
|
||||
* Clone operation for creating a new UTarget from an existing
|
||||
* UTarget.
|
||||
*
|
||||
* @note The caller MUST use the delete operation on the return
|
||||
* value when done.
|
||||
*
|
||||
* @return A pointer to the new object on success, 0 on failure.
|
||||
*/
|
||||
SnmpTarget *clone() const { return (SnmpTarget *) new UTarget(*this); };
|
||||
|
||||
/**
|
||||
* Set the address object.
|
||||
*
|
||||
* This method is the same as in SnmpTarget, but it deletes engine_id.
|
||||
*
|
||||
* @param address - The address that this target should use.
|
||||
* @return TRUE on success.
|
||||
*/
|
||||
int set_address(const Address &address);
|
||||
|
||||
/**
|
||||
* Get the security name.
|
||||
*
|
||||
* @return A const reference to the security name.
|
||||
*/
|
||||
const OctetStr& get_security_name() const { return security_name;} ;
|
||||
|
||||
/**
|
||||
* Get the security name.
|
||||
*
|
||||
* @param oct - OctetStr that will be filled with the security name.
|
||||
*/
|
||||
void get_security_name( OctetStr& oct) const { oct = security_name; };
|
||||
|
||||
/**
|
||||
* Set the security name.
|
||||
*
|
||||
* @param str - The new security name
|
||||
*/
|
||||
void set_security_name( const char * str) { security_name = str; };
|
||||
|
||||
/**
|
||||
* Set the security name.
|
||||
*
|
||||
* @param oct - The new security name
|
||||
*/
|
||||
void set_security_name( const OctetStr& oct) { security_name = oct; };
|
||||
|
||||
#ifdef _SNMPv3
|
||||
/**
|
||||
* Set the engine id.
|
||||
*
|
||||
* In most cases it is not necessary for the user to set the engine
|
||||
* id as snmp++ performs engine id discovery. If the engine id is
|
||||
* set by the user, no engine_id discovery is made, even if the
|
||||
* engine id set by the user is wrong.
|
||||
*
|
||||
* @param str - The engine id to use
|
||||
*/
|
||||
void set_engine_id( const char * str) { engine_id = str; };
|
||||
|
||||
/**
|
||||
* Set the engine id.
|
||||
*
|
||||
* In most cases it is not necessary for the user to set the engine
|
||||
* id as snmp++ performs engine id discovery. If the engine id is
|
||||
* set by the user, no engine_id discovery is made, even if the
|
||||
* engine id set by the user is wrong.
|
||||
*
|
||||
* @param oct - The engine id to use
|
||||
*/
|
||||
void set_engine_id( const OctetStr &oct) { engine_id = oct; };
|
||||
|
||||
/**
|
||||
* Get the engine id.
|
||||
*
|
||||
* @return A const reference to the enigne id of this target.
|
||||
*/
|
||||
const OctetStr& get_engine_id() const { return engine_id; };
|
||||
|
||||
/**
|
||||
* Get the engine id.
|
||||
*
|
||||
* @param oct - OctetStr that will be filled with the engine id
|
||||
*/
|
||||
void get_engine_id( OctetStr& oct) const { oct = engine_id; };
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Get the security_model.
|
||||
*
|
||||
* @return An integer representing the security_model of this target.
|
||||
*/
|
||||
int get_security_model() const { return security_model; };
|
||||
|
||||
/**
|
||||
* Set the security_model.
|
||||
*
|
||||
* @param sec_model - The security model to use.
|
||||
*/
|
||||
void set_security_model(int sec_model) { security_model = sec_model; };
|
||||
|
||||
/**
|
||||
* Overloaded assignment operator.
|
||||
*/
|
||||
UTarget& operator=( const UTarget& target);
|
||||
|
||||
/**
|
||||
* Overloeaded compare operator.
|
||||
*
|
||||
* Two UTarget objects are considered equal, if all member variables
|
||||
* (beside the engine id) and the base classes are equal.
|
||||
*
|
||||
* @return 1 if targets are equal, 0 if not.
|
||||
*/
|
||||
virtual int operator==( const UTarget &rhs);
|
||||
|
||||
/**
|
||||
* Get all values of a UTarget object.
|
||||
*
|
||||
* @param sec_name - security name
|
||||
* @param sec_model - security model
|
||||
* @param address - Address of the target
|
||||
* @param t - Timeout value
|
||||
* @param r - Retries value
|
||||
* @param v - The SNMP version of this target
|
||||
*
|
||||
* @return TRUE on success and FALSE on failure.
|
||||
*/
|
||||
int resolve_to_U( OctetStr& sec_name,
|
||||
int &sec_model,
|
||||
GenAddress &address,
|
||||
unsigned long &t,
|
||||
int &r,
|
||||
unsigned char &v) const;
|
||||
|
||||
protected:
|
||||
OctetStr security_name;
|
||||
int security_model;
|
||||
#ifdef _SNMPv3
|
||||
OctetStr engine_id;
|
||||
#endif
|
||||
};
|
||||
#endif //_TARGET
|
135
backend/camembert/libkmsnmp/timetick.cpp
Normal file
135
backend/camembert/libkmsnmp/timetick.cpp
Normal file
@ -0,0 +1,135 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## timetick.cpp
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
/*===================================================================
|
||||
|
||||
Copyright (c) 1999
|
||||
Hewlett-Packard Company
|
||||
|
||||
ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
Permission to use, copy, modify, distribute and/or sell this software
|
||||
and/or its documentation is hereby granted without fee. User agrees
|
||||
to display the above copyright notice and this license notice in all
|
||||
copies of the software and any documentation of the software. User
|
||||
agrees to assume all liability for the use of the software; Hewlett-Packard
|
||||
makes no representations about the suitability of this software for any
|
||||
purpose. It is provided "AS-IS" without warranty of any kind,either express
|
||||
or implied. User hereby grants a royalty-free license to any and all
|
||||
derivatives based upon this software code base.
|
||||
|
||||
|
||||
|
||||
T I M E T I C K. C P P
|
||||
|
||||
TIMETICK CLASS IMPLEMENTATION
|
||||
|
||||
DESIGN + AUTHOR:
|
||||
Peter E Mellquist
|
||||
|
||||
LANGUAGE:
|
||||
ANSI C++
|
||||
|
||||
OPERATING SYSTEMS:
|
||||
MS-Windows Win32
|
||||
BSD UNIX
|
||||
|
||||
DESCRIPTION:
|
||||
Class implentation for SMI Timeticks class.
|
||||
|
||||
=====================================================================*/
|
||||
char timetick_cpp_version[]="#(@) SNMP++ $Id: timetick.cpp,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $";
|
||||
|
||||
#include "timetick.h" // include header file for timetick class
|
||||
#include <stdio.h> // for sprintf() usage.
|
||||
|
||||
// Copy constructor
|
||||
TimeTicks::TimeTicks( const TimeTicks &t)
|
||||
{
|
||||
smival.value.uNumber = t.smival.value.uNumber;
|
||||
smival.syntax = sNMP_SYNTAX_TIMETICKS;
|
||||
}
|
||||
|
||||
// general assignment from any Value
|
||||
SnmpSyntax& TimeTicks::operator=(const SnmpSyntax &in_val)
|
||||
{
|
||||
if (this == &in_val) return *this; // handle assignement from itself
|
||||
|
||||
valid_flag = false; // will get set true if really valid
|
||||
if (in_val.valid())
|
||||
{
|
||||
switch (in_val.get_syntax())
|
||||
{
|
||||
case sNMP_SYNTAX_UINT32:
|
||||
// case sNMP_SYNTAX_GAUGE32: .. indistinquishable from UINT32
|
||||
case sNMP_SYNTAX_CNTR32:
|
||||
case sNMP_SYNTAX_TIMETICKS:
|
||||
case sNMP_SYNTAX_INT32: // implied cast int -> uint
|
||||
smival.value.uNumber =
|
||||
((TimeTicks &)in_val).smival.value.uNumber;
|
||||
valid_flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ASCII format return
|
||||
const char *TimeTicks::get_printable() const
|
||||
{
|
||||
char *buf = PP_CONST_CAST(char *, output_buffer);
|
||||
|
||||
/* unsigned long hseconds, seconds, minutes, hours, days;
|
||||
unsigned long tt = smival.value.uNumber;
|
||||
char *buf = PP_CONST_CAST(char*, output_buffer);
|
||||
|
||||
days = tt / 8640000;
|
||||
tt %= 8640000;
|
||||
|
||||
hours = tt / 360000;
|
||||
tt %= 360000;
|
||||
|
||||
minutes = tt / 6000;
|
||||
tt %= 6000;
|
||||
|
||||
seconds = tt / 100;
|
||||
tt %= 100;
|
||||
|
||||
hseconds = tt;
|
||||
|
||||
if (days == 0)
|
||||
sprintf(buf, "%lu:%02lu:%02lu.%02lu", hours, minutes, seconds, hseconds);
|
||||
else if (days == 1)
|
||||
sprintf(buf, "1 day %lu:%02lu:%02lu.%02lu",
|
||||
hours, minutes, seconds, hseconds);
|
||||
else
|
||||
sprintf(buf, "%lu days, %lu:%02lu:%02lu.%02lu",
|
||||
days, hours, minutes, seconds, hseconds);
|
||||
*/
|
||||
sprintf(buf, "%d", smival.value.uNumber);
|
||||
return buf;
|
||||
}
|
161
backend/camembert/libkmsnmp/timetick.h
Normal file
161
backend/camembert/libkmsnmp/timetick.h
Normal file
@ -0,0 +1,161 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## timetick.h
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
/*===================================================================
|
||||
|
||||
Copyright (c) 1999
|
||||
Hewlett-Packard Company
|
||||
|
||||
ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
Permission to use, copy, modify, distribute and/or sell this software
|
||||
and/or its documentation is hereby granted without fee. User agrees
|
||||
to display the above copyright notice and this license notice in all
|
||||
copies of the software and any documentation of the software. User
|
||||
agrees to assume all liability for the use of the software; Hewlett-Packard
|
||||
makes no representations about the suitability of this software for any
|
||||
purpose. It is provided "AS-IS without warranty of any kind,either express
|
||||
or implied. User hereby grants a royalty-free license to any and all
|
||||
derivatives based upon this software code base.
|
||||
|
||||
|
||||
SNMP++ T I M E T I C K. H
|
||||
|
||||
TIMETICK CLASS DEFINITION
|
||||
|
||||
DESIGN + AUTHOR:
|
||||
Peter E Mellquist
|
||||
|
||||
LANGUAGE:
|
||||
ANSI C++
|
||||
|
||||
OPERATING SYSTEMS:
|
||||
MS-Windows Win32
|
||||
BSD UNIX
|
||||
|
||||
DESCRIPTION:
|
||||
Class definition for SMI Timeticks class.
|
||||
|
||||
=====================================================================*/
|
||||
// $Id: timetick.h,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $
|
||||
|
||||
#ifndef _TIMETICKS
|
||||
#define _TIMETICKS
|
||||
|
||||
#include "integer.h"
|
||||
|
||||
#define TICKOUTBUF 30 // max formatted time string
|
||||
|
||||
//------------[ TimeTicks Class ]-----------------------------------
|
||||
/**
|
||||
* The timeticks class allows all the functionality of unsigned
|
||||
* integers but is recognized as a distinct SMI type. TimeTicks
|
||||
* objects may be get or set into Vb objects.
|
||||
*/
|
||||
class DLLOPT TimeTicks : public SnmpUInt32
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructs a zero TimeTicks object.
|
||||
*/
|
||||
TimeTicks() : SnmpUInt32()
|
||||
{ smival.syntax = sNMP_SYNTAX_TIMETICKS; };
|
||||
|
||||
/**
|
||||
* Constructs a TimeTicks object with the given value.
|
||||
*
|
||||
* @param val - time in hundredths of seconds.
|
||||
*/
|
||||
TimeTicks(const unsigned long val) : SnmpUInt32(val)
|
||||
{ smival.syntax = sNMP_SYNTAX_TIMETICKS; };
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*
|
||||
* @param t - Time for the new object.
|
||||
*/
|
||||
TimeTicks(const TimeTicks &t);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~TimeTicks() {};
|
||||
|
||||
/**
|
||||
* Return the syntax.
|
||||
*
|
||||
* @return Always returns sNMP_SYNTAX_TIMETICKS.
|
||||
*/
|
||||
SmiUINT32 get_syntax() const { return sNMP_SYNTAX_TIMETICKS; };
|
||||
|
||||
/**
|
||||
* Get a printable ASCII value.
|
||||
*/
|
||||
const char *get_printable() const;
|
||||
|
||||
/**
|
||||
* Clone operator.
|
||||
*
|
||||
* @return Pointer to a newly created copy of the object.
|
||||
*/
|
||||
SnmpSyntax *clone() const { return (SnmpSyntax *) new TimeTicks(*this); };
|
||||
|
||||
/**
|
||||
* Map other SnmpSyntax objects to TimeTicks.
|
||||
*/
|
||||
SnmpSyntax& operator=(const SnmpSyntax &val);
|
||||
|
||||
/**
|
||||
* Overloaded assignment for TimeTicks.
|
||||
*
|
||||
* @param uli - new value
|
||||
* @return self reference
|
||||
*/
|
||||
TimeTicks& operator=(const TimeTicks &uli)
|
||||
{ smival.value.uNumber = uli.smival.value.uNumber; return *this; };
|
||||
|
||||
/**
|
||||
* Overloaded assignment for unsigned longs.
|
||||
*
|
||||
* @param i - new value in hundrets of seconds
|
||||
* @return self reference
|
||||
*/
|
||||
TimeTicks& operator=(const unsigned long i)
|
||||
{ smival.value.uNumber = i; return *this; };
|
||||
|
||||
/**
|
||||
* Casting to unsigned long.
|
||||
*
|
||||
* @return Current value as hundrets of seconds
|
||||
*/
|
||||
operator unsigned long() { return smival.value.uNumber; };
|
||||
|
||||
protected:
|
||||
/*mutable*/ char output_buffer[TICKOUTBUF]; // for storing printed form
|
||||
|
||||
};
|
||||
#endif
|
942
backend/camembert/libkmsnmp/usm_v3.h
Normal file
942
backend/camembert/libkmsnmp/usm_v3.h
Normal file
@ -0,0 +1,942 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## usm_v3.h
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
// $Id: usm_v3.h,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $
|
||||
|
||||
#ifndef _USM_V3
|
||||
#define _USM_V3
|
||||
|
||||
#include "config_snmp_pp.h"
|
||||
|
||||
#ifdef _SNMPv3
|
||||
|
||||
#include "smi.h"
|
||||
#include "octet.h"
|
||||
|
||||
|
||||
#define MAXUINT32 4294967295u
|
||||
|
||||
// the maximum allowed length of the username
|
||||
#define MAXLEN_USMUSERNAME 32
|
||||
#define MAXLEN_USMSECURITYNAME MAXLEN_USMUSERNAME
|
||||
|
||||
#define SNMPv3_AUTHFLAG 0x01
|
||||
#define SNMPv3_PRIVFLAG 0x02
|
||||
#define SNMPv3_REPORTABLEFLAG 0x04
|
||||
|
||||
#define NOKEY 0
|
||||
#define AUTHKEY 1
|
||||
#define PRIVKEY 2
|
||||
#define OWNAUTHKEY 3
|
||||
#define OWNPRIVKEY 4
|
||||
|
||||
#define SNMP_SECURITY_LEVEL_NOAUTH_NOPRIV 1
|
||||
#define SNMP_SECURITY_LEVEL_AUTH_NOPRIV 2
|
||||
#define SNMP_SECURITY_LEVEL_AUTH_PRIV 3
|
||||
|
||||
#define SNMP_AUTHPROTOCOL_NONE 1
|
||||
#define SNMP_AUTHPROTOCOL_HMACMD5 2
|
||||
#define SNMP_AUTHPROTOCOL_HMACSHA 3
|
||||
|
||||
#define SNMP_PRIVPROTOCOL_NONE 1
|
||||
#define SNMP_PRIVPROTOCOL_DES 2
|
||||
#define SNMP_PRIVPROTOCOL_IDEA 9
|
||||
#define SNMP_PRIVPROTOCOL_AES128 19
|
||||
#define SNMP_PRIVPROTOCOL_AES192 20
|
||||
#define SNMP_PRIVPROTOCOL_AES256 21
|
||||
|
||||
#define SNMPv3_USM_OK 1400
|
||||
#define SNMPv3_USM_ERROR 1401
|
||||
#define SNMPv3_USM_ERROR_CONFIGFILE 1402
|
||||
#define SNMPv3_USM_UNSUPPORTED_SECURITY_LEVEL 1403
|
||||
#define SNMPv3_USM_UNKNOWN_SECURITY_NAME 1404
|
||||
#define SNMPv3_USM_ENCRYPTION_ERROR 1405
|
||||
#define SNMPv3_USM_DECRYPTION_ERROR 1406
|
||||
#define SNMPv3_USM_AUTHENTICATION_ERROR 1407
|
||||
#define SNMPv3_USM_AUTHENTICATION_FAILURE 1408
|
||||
#define SNMPv3_USM_PARSE_ERROR 1409
|
||||
#define SNMPv3_USM_UNKNOWN_ENGINEID 1410
|
||||
#define SNMPv3_USM_NOT_IN_TIME_WINDOW 1411
|
||||
#define SNMPv3_USM_UNSUPPORTED_AUTHPROTOCOL 1412
|
||||
#define SNMPv3_USM_UNSUPPORTED_PRIVPROTOCOL 1413
|
||||
#define SNMPv3_USM_ADDRESS_ERROR 1414
|
||||
#define SNMPv3_USM_FILECREATE_ERROR 1415
|
||||
#define SNMPv3_USM_FILEOPEN_ERROR 1416
|
||||
#define SNMPv3_USM_FILERENAME_ERROR 1417
|
||||
#define SNMPv3_USM_FILEDELETE_ERROR 1418
|
||||
#define SNMPv3_USM_FILEWRITE_ERROR 1419
|
||||
#define SNMPv3_USM_FILEREAD_ERROR 1420
|
||||
|
||||
|
||||
#define SNMPv3_USM_MAX_ERROR SNMPv3_USM_FILEREAD_ERROR
|
||||
#define SNMPv3_USM_MIN_ERROR SNMPv3_USM_OK
|
||||
#define SNMPv3_USM_ERRORCOUNT SNMPv3_USM_MAX_ERROR - SNMPv3_USM_MIN_ERROR
|
||||
|
||||
#define oidUsmStats "1.3.6.1.6.3.15.1.1"
|
||||
#define oidUsmStatsUnsupportedSecLevels "1.3.6.1.6.3.15.1.1.1.0"
|
||||
#define oidUsmStatsNotInTimeWindows "1.3.6.1.6.3.15.1.1.2.0"
|
||||
#define oidUsmStatsUnknownUserNames "1.3.6.1.6.3.15.1.1.3.0"
|
||||
#define oidUsmStatsUnknownEngineIDs "1.3.6.1.6.3.15.1.1.4.0"
|
||||
#define oidUsmStatsWrongDigests "1.3.6.1.6.3.15.1.1.5.0"
|
||||
#define oidUsmStatsDecryptionErrors "1.3.6.1.6.3.15.1.1.6.0"
|
||||
|
||||
#define oidUsmUserTable "1.3.6.1.6.3.15.1.2.2"
|
||||
#define oidUsmUserEntry "1.3.6.1.6.3.15.1.2.2.1"
|
||||
|
||||
#define oidUsmAuthProtocolBase "1.3.6.1.6.3.10.1.1"
|
||||
#define oidUsmNoAuthProtocol "1.3.6.1.6.3.10.1.1.1"
|
||||
#define oidUsmHMACMD5AuthProtocol "1.3.6.1.6.3.10.1.1.2"
|
||||
#define oidUsmHMACSHAAuthProtocol "1.3.6.1.6.3.10.1.1.3"
|
||||
|
||||
#define oidUsmPrivProtocolBase "1.3.6.1.6.3.10.1.2"
|
||||
#define oidUsmNoPrivProtocol "1.3.6.1.6.3.10.1.2.1"
|
||||
#define oidUsmDESPrivProtocol "1.3.6.1.6.3.10.1.2.2"
|
||||
#define oidUsmIDEAPrivProtocol "1.3.6.1.6.3.10.1.2.9"
|
||||
#define oidUsmAES128PrivProtocol "1.3.6.1.6.3.10.1.2.19"
|
||||
#define oidUsmAES192PrivProtocol "1.3.6.1.6.3.10.1.2.20"
|
||||
#define oidUsmAES256PrivProtocol "1.3.6.1.6.3.10.1.2.21"
|
||||
|
||||
|
||||
#define USM_KeyUpdate 1
|
||||
#define USM_PasswordUpdate 2
|
||||
#define USM_PasswordKeyUpdate 3
|
||||
#define USM_PasswordAllKeyUpdate 4
|
||||
|
||||
class SnmpTarget;
|
||||
class Pdu;
|
||||
|
||||
struct UsmKeyUpdate;
|
||||
|
||||
struct UsmUserTableEntry {
|
||||
unsigned char *usmUserEngineID; long int usmUserEngineIDLength;
|
||||
unsigned char *usmUserName; long int usmUserNameLength;
|
||||
unsigned char *usmUserSecurityName; long int usmUserSecurityNameLength;
|
||||
long int usmUserAuthProtocol;
|
||||
unsigned char *usmUserAuthKey; long int usmUserAuthKeyLength;
|
||||
long int usmUserPrivProtocol;
|
||||
unsigned char *usmUserPrivKey; long int usmUserPrivKeyLength;
|
||||
};
|
||||
|
||||
struct UsmUser {
|
||||
unsigned char *engineID; long int engineIDLength;
|
||||
unsigned char *usmUserName; long int usmUserNameLength;
|
||||
unsigned char *securityName; long int securityNameLength;
|
||||
long int authProtocol;
|
||||
unsigned char *authKey; long int authKeyLength;
|
||||
long int privProtocol;
|
||||
unsigned char *privKey; long int privKeyLength;
|
||||
};
|
||||
|
||||
struct UsmUserNameTableEntry {
|
||||
OctetStr usmUserName;
|
||||
OctetStr usmUserSecurityName;
|
||||
long int usmUserAuthProtocol;
|
||||
long int usmUserPrivProtocol;
|
||||
unsigned char *authPassword; long int authPasswordLength;
|
||||
unsigned char *privPassword; long int privPasswordLength;
|
||||
};
|
||||
|
||||
//-----------[ async methods callback ]-----------------------------------
|
||||
typedef void (*usm_add_user_callback)(const OctetStr &engine_id,
|
||||
const OctetStr &usm_user_name,
|
||||
const OctetStr &usm_user_security_name,
|
||||
const int auth_protocol,
|
||||
const OctetStr &auth_key,
|
||||
const int priv_protocol,
|
||||
const OctetStr &priv_key);
|
||||
|
||||
struct SecurityStateReference;
|
||||
|
||||
class AuthPriv;
|
||||
class USMTimeTable;
|
||||
class USMUserNameTable;
|
||||
class USMUserTable;
|
||||
class v3MP;
|
||||
|
||||
/**
|
||||
* This is the class for the User Based Security Model.
|
||||
*
|
||||
* To add or delete users, the methods add_usm_user() and delete_usm_user()
|
||||
* should be used.
|
||||
*/
|
||||
class DLLOPT USM
|
||||
{
|
||||
friend class v3MP;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Create an instance of the USM.
|
||||
*
|
||||
* @param engine_boots - The new value for the snmpEngineBoots counter
|
||||
* @param engine_id - The local snmp engine id
|
||||
* @param v3_mp - Pointer to the parent v3MP object.
|
||||
* @param msg_id - OUT: The initial value for the msgID
|
||||
* @param result - OUT: construct status, should be SNMPv3_USM_OK
|
||||
*/
|
||||
USM(unsigned int engine_boots, const OctetStr &engine_id, const v3MP *v3_mp,
|
||||
unsigned int *msg_id, int &result);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~USM();
|
||||
|
||||
/**
|
||||
* Enables the discovery mode of the USM, i.e. the USM accepts all messages
|
||||
* with unknown engine ids and adds these engine ids to its tables.
|
||||
*/
|
||||
void set_discovery_mode() { discovery_mode = 1; };
|
||||
|
||||
/**
|
||||
* Disables the discovery mode of the USM, i.e. the USM will not accept any
|
||||
* message with an unknown engine id.
|
||||
*/
|
||||
void unset_discovery_mode() { discovery_mode = 0; };
|
||||
|
||||
/**
|
||||
* Return TRUE if the USM discovery mode is enabled, FALSE else.
|
||||
*/
|
||||
int is_discovery_enabled() const { return discovery_mode; };
|
||||
|
||||
/**
|
||||
* Add a new user to the usmUserNameTable. If the User is already known
|
||||
* to the USM, the old entry is replaced.
|
||||
* The USM will compute a userName for the given securityName, which
|
||||
* will be the same as securityName (recommended).
|
||||
*
|
||||
* @param security_name - Unique securityName
|
||||
* @param auth_protocol - Possible values are:
|
||||
* SNMP_AUTHPROTOCOL_NONE,
|
||||
* SNMP_AUTHPROTOCOL_HMACMD5,
|
||||
* SNMP_AUTHPROTOCOL_HMACSHA
|
||||
* @param priv_protocol - Possible values are:
|
||||
* SNMP_PRIVPROTOCOL_NONE,
|
||||
* SNMP_PRIVPROTOCOL_DES,
|
||||
* SNMP_PRIVPROTOCOL_IDEA
|
||||
* @param auth_password - Secret password for authentication
|
||||
* @param priv_password - Secret password for privacy
|
||||
*
|
||||
* @return - SNMPv3_USM_OK or
|
||||
* SNMP_v3_USM_ERROR (memory error, not initialized)
|
||||
*/
|
||||
int add_usm_user(const OctetStr& security_name,
|
||||
const long int auth_protocol,
|
||||
const long int priv_protocol,
|
||||
const OctetStr& auth_password,
|
||||
const OctetStr& priv_password);
|
||||
|
||||
/**
|
||||
* Add a new user to the usmUserNameTable. If the userName is already known
|
||||
* to the USM, the old entry is replaced.
|
||||
*
|
||||
* It is not recommended to add users with userName != securityName.
|
||||
*
|
||||
* @param user_name - Unique userName
|
||||
* @param security_name - Unique securityName
|
||||
* @param auth_protocol - Possible values are:
|
||||
* SNMP_AUTHPROTOCOL_NONE,
|
||||
* SNMP_AUTHPROTOCOL_HMACMD5,
|
||||
* SNMP_AUTHPROTOCOL_HMACSHA
|
||||
* @param priv_protocol - Possible values are:
|
||||
* SNMP_PRIVPROTOCOL_NONE,
|
||||
* SNMP_PRIVPROTOCOL_DES,
|
||||
* SNMP_PRIVPROTOCOL_IDEA
|
||||
* @param auth_password - Secret password for authentication
|
||||
* @param priv_password - Secret password for privacy
|
||||
*
|
||||
* @return - SNMPv3_USM_OK or
|
||||
* SNMP_v3_USM_ERROR (memory error, not initialized)
|
||||
*/
|
||||
int add_usm_user(const OctetStr& user_name,
|
||||
const OctetStr& security_name,
|
||||
const long int auth_protocol,
|
||||
const long int priv_protocol,
|
||||
const OctetStr& auth_password,
|
||||
const OctetStr& priv_password);
|
||||
|
||||
/**
|
||||
* Delete all occurences of the user with the given security name
|
||||
* from the USM.
|
||||
*
|
||||
* @param security_name - the securityName of the user
|
||||
*
|
||||
* @return - SNMPv3_USM_OK, SNMPv3_USM_ERROR (not initialized)
|
||||
*/
|
||||
int delete_usm_user(const OctetStr& security_name);
|
||||
|
||||
|
||||
/**
|
||||
* Save all localized users into a file.
|
||||
*
|
||||
* @param file - filename including path
|
||||
*
|
||||
* @return SNMPv3_USM_ERROR, SNMPv3_USM_FILECREATE_ERROR,
|
||||
* SNMPv3_USM_FILERENAME_ERROR or SNMPv3_USM_OK
|
||||
*/
|
||||
int save_localized_users(const char *file);
|
||||
|
||||
/**
|
||||
* Load localized users from a file.
|
||||
*
|
||||
* @param file - filename including path
|
||||
*
|
||||
* @return SNMPv3_USM_ERROR, SNMPv3_USM_FILEOPEN_ERROR,
|
||||
* SNMPv3_USM_FILEREAD_ERROR or SNMPv3_USM_OK
|
||||
*/
|
||||
int load_localized_users(const char *file);
|
||||
|
||||
/**
|
||||
* Save all users with their passwords into a file.
|
||||
*
|
||||
* @param file - filename including path
|
||||
*
|
||||
* @return SNMPv3_USM_ERROR, SNMPv3_USM_FILECREATE_ERROR,
|
||||
* SNMPv3_USM_FILERENAME_ERROR or SNMPv3_USM_OK
|
||||
*/
|
||||
int save_users(const char *file);
|
||||
|
||||
/**
|
||||
* Load users with their passwords from a file.
|
||||
*
|
||||
* @param file - filename including path
|
||||
*
|
||||
* @return SNMPv3_USM_ERROR, SNMPv3_USM_FILEOPEN_ERROR,
|
||||
* SNMPv3_USM_FILEREAD_ERROR or SNMPv3_USM_OK
|
||||
*/
|
||||
int load_users(const char *file);
|
||||
|
||||
/**
|
||||
* Add or replace a localized user in the USM table. Use this method
|
||||
* only, if you know what you are doing.
|
||||
*
|
||||
* @param engine_id - The engineID, the key was localized with
|
||||
* @param user_name - The name of the user (in the USM)
|
||||
* @param security_name - The securityName of the user, this name
|
||||
* is the same for all securityModels
|
||||
* @param auth_protocol - Possible values are:
|
||||
* SNMP_AUTHPROTOCOL_NONE,
|
||||
* SNMP_AUTHPROTOCOL_HMACMD5,
|
||||
* SNMP_AUTHPROTOCOL_HMACSHA
|
||||
* @param auth_key - The key used for authentications
|
||||
* @param priv_protocol - Possible values are:
|
||||
* SNMP_PRIVPROTOCOL_NONE,
|
||||
* SNMP_PRIVPROTOCOL_DES,
|
||||
* SNMP_PRIVPROTOCOL_IDEA
|
||||
* @param priv_key - The key used for privacy
|
||||
*
|
||||
* @return - SNMPv3_USM_OK
|
||||
* SNMP_v3_USM_ERROR (not initialized, no memory) */
|
||||
int add_localized_user(const OctetStr &engine_id,
|
||||
const OctetStr &user_name,
|
||||
const OctetStr &security_name,
|
||||
const long auth_protocol,
|
||||
const OctetStr &auth_key,
|
||||
const long priv_protocol,
|
||||
const OctetStr &priv_key);
|
||||
#if 0
|
||||
// deprecated!
|
||||
int add_localized_user(
|
||||
const unsigned char *engine_id, const long engine_id_len,
|
||||
const unsigned char *user_name, const long user_name_len,
|
||||
const unsigned char *security_name, const long security_name_len,
|
||||
const long auth_protocol,
|
||||
const unsigned char *auth_key, const long auth_key_len,
|
||||
const long priv_protocol,
|
||||
const unsigned char *priv_key, const long priv_key_len);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Delete all localized entries of this user from the usmUserTable.
|
||||
*
|
||||
* @param user_name - The userName that should be deleted
|
||||
*
|
||||
* @return - SNMPv3_USM_ERROR (not initialized),
|
||||
* SNMPv3_USM_OK (user deleted or not in table)
|
||||
*/
|
||||
int delete_localized_user(const OctetStr& user_name);
|
||||
|
||||
|
||||
/**
|
||||
* Delete the entry with the given userName and engineID
|
||||
* from the usmUserTable
|
||||
*
|
||||
* @param engine_id - The engineID
|
||||
* @param user_name - The userName that should be deleted
|
||||
*
|
||||
* @return - SNMPv3_USM_ERROR (not initialkized),
|
||||
* SNMPv3_USM_OK (user deleted or not in table)
|
||||
*/
|
||||
int delete_localized_user(const OctetStr& engine_id,
|
||||
const OctetStr& user_name);
|
||||
|
||||
|
||||
/**
|
||||
* Replace a localized key of the user and engineID in the
|
||||
* usmUserTable.
|
||||
*
|
||||
* @param user_name - The name of the user in the USM
|
||||
* @param user_name_len - The length of the user name
|
||||
* @param engine_id - Change the localized key for the SNMP
|
||||
* entity with this engine id
|
||||
* @param engine_id_len - The length of the engine id
|
||||
* @param new_key - The new key
|
||||
* @param new_key_len - The length of the new key
|
||||
* @param type_of_key - AUTHKEY, OWNAUTHKEY, PRIVKEY or OWNPRIVKEY
|
||||
*
|
||||
* @return - SNMPv3_USM_ERROR (no such entry or not initialized),
|
||||
* SNMPv3_USM_OK
|
||||
*/
|
||||
int update_key(const unsigned char* user_name, const long user_name_len,
|
||||
const unsigned char* engine_id, const long engine_id_len,
|
||||
const unsigned char* new_key, const long new_key_len,
|
||||
const int type_of_key);
|
||||
|
||||
/**
|
||||
* Search for a user with the given securityName and engineID
|
||||
* in the usmUserTable and return the entry. If no entry
|
||||
* could be found, the usmUserNameTable is searched for the given
|
||||
* securityName. If this table has an entry of this user, a
|
||||
* localized entry is generated, added to the usmUserTable and
|
||||
* returned to the caller.
|
||||
*
|
||||
* The caller has to do a delete on the returned struct.
|
||||
*
|
||||
* @param engine_id -
|
||||
* @param security_name -
|
||||
*
|
||||
* @return - a pointer to the structure if an entry could be found
|
||||
* or was generated, NULL for all errors
|
||||
*/
|
||||
struct UsmUser *get_user(const OctetStr &engine_id,
|
||||
const OctetStr &security_name);
|
||||
|
||||
|
||||
/**
|
||||
* Get the security name from a user name.
|
||||
*
|
||||
* @param user_name -
|
||||
* @param user_name_len -
|
||||
* @param security_name - Buffer for the securityName
|
||||
*
|
||||
* @return - SNMPv3_USM_ERROR (not initialized, not found, buffer too small),
|
||||
* SNMPv3_USM_OK
|
||||
*/
|
||||
int get_security_name(const unsigned char *user_name,
|
||||
const long int user_name_len,
|
||||
OctetStr &security_name);
|
||||
|
||||
/**
|
||||
* Get the user name from a security name.
|
||||
*
|
||||
* @param user_name - Buffer for the userName
|
||||
* @param user_name_len - Has to be set to the max length of the
|
||||
* buffer. Is set to the length of the found
|
||||
* securityName or to 0 if not found.
|
||||
* @param security_name -
|
||||
* @param security_name_len -
|
||||
*
|
||||
* @return - SNMPv3_USM_ERROR (not initialized, not found, buffer too small),
|
||||
* SNMPv3_USM_OK
|
||||
*/
|
||||
int get_user_name(unsigned char *user_name,
|
||||
long int *user_name_len,
|
||||
const unsigned char *security_name,
|
||||
const long int security_name_len);
|
||||
|
||||
|
||||
/**
|
||||
* Prepare a key update in the USM. The following procedure is used: To
|
||||
* prepare the key update, this function adds the neccessary variable
|
||||
* bindings to the Pdu to do the key update on the target SNMP entity.
|
||||
* The Pdu has to be sent to the target. If the key update on the target
|
||||
* is successful, usmCommitKeyUpdate() has to be called to do the local key
|
||||
* update. On failure usmAbortKeyUpdate() has to be called to free
|
||||
* temporary ressources.
|
||||
*
|
||||
* @param securityName - The name of the user
|
||||
* @param target - A target to identify the SNMP entity on which the
|
||||
* key will be updated
|
||||
* @param newPassword - The new password for the user
|
||||
* @param pdu - A PDU into which this funktion adds the VBs needed
|
||||
* to change the keys on the target
|
||||
* @param type - Indicates how and which key should be chaned:
|
||||
* possilbe values are: AUTHKEY, PRIVKEY and
|
||||
* OWNAUTHKEY, OWNPRIVKEY.
|
||||
* @param status - The return status: SNMPv3_USM_OK or one of the
|
||||
* error codes
|
||||
*
|
||||
* @return - A structure, that is needed to commit/abort the key update.
|
||||
* If an error occurs, the return value is NULL
|
||||
*/
|
||||
struct UsmKeyUpdate* key_update_prepare(const OctetStr& securityName,
|
||||
SnmpTarget& target,
|
||||
const OctetStr& newPassword,
|
||||
Pdu& pdu, int type,
|
||||
int &status,
|
||||
const OctetStr& oldpass = "",
|
||||
const OctetStr& oldengid= "",
|
||||
const OctetStr& newengid= "");
|
||||
|
||||
/**
|
||||
* Abort the local key update.
|
||||
*
|
||||
* @param uku - The pointer returned by usmPrepareKeyUpdate()
|
||||
*/
|
||||
void key_update_abort(struct UsmKeyUpdate *uku);
|
||||
|
||||
|
||||
/**
|
||||
* Commit the local key update.
|
||||
*
|
||||
* @param uku - The pointer returned by usmPrepareKeyUpdate()
|
||||
* @param update_type - One of USM_KeyUpdate, USM_PasswordKeyUpdate,
|
||||
* USM_PasswordAllKeyUpdate
|
||||
*
|
||||
* @return - SNMPv3_USM_ERROR, SNMPv3_USM_OK
|
||||
*/
|
||||
int key_update_commit(struct UsmKeyUpdate *uku, int update_type);
|
||||
|
||||
|
||||
/**
|
||||
* Get a pointer to the AuthPriv object used by the USM.
|
||||
*
|
||||
*/
|
||||
AuthPriv *get_auth_priv();
|
||||
|
||||
|
||||
/**
|
||||
* Return engineBoots and engineTime for a given engineID
|
||||
*
|
||||
* @param engine_id - The engineID of the SNMP entity
|
||||
* @param engine_boots - OUT: boot counter (0 if not found)
|
||||
* @param engine_time - OUT: engine time (0 if not found)
|
||||
*
|
||||
* @return - SNMPv3_USM_ERROR (not initialized),
|
||||
* SNMPv3_USM_OK (entry found, values are filled)
|
||||
* SNMPv3_USM_UNKNOWN_ENGINEID ( not found)
|
||||
*/
|
||||
int get_time(const OctetStr &engine_id,
|
||||
long int *engine_boots, long int *engine_time);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return engineBoots and engineTime of the local snmp entity
|
||||
*
|
||||
* @param engine_boots - OUT: boot counter (0 if not found)
|
||||
* @param engine_time - OUT: engine time (0 if not found)
|
||||
*
|
||||
* @return - SNMPv3_USM_ERROR (not initialized),
|
||||
* SNMPv3_USM_OK (entry found, values are filled)
|
||||
*/
|
||||
int get_local_time(long int *engine_boots, long int *engine_time) const;
|
||||
|
||||
|
||||
/**
|
||||
* Return the local snmp engine id.
|
||||
*/
|
||||
const OctetStr& get_local_engine_id() const { return local_snmp_engine_id; };
|
||||
|
||||
/**
|
||||
* Get the number of received messages with an unsupported securityLevel
|
||||
*
|
||||
* @return - usmStatsUnsupportedSecLevels
|
||||
*/
|
||||
unsigned long get_stats_unsupported_sec_levels() const
|
||||
{ return usmStatsUnsupportedSecLevels; };
|
||||
|
||||
/**
|
||||
* Get the number of received messages outside time window
|
||||
*
|
||||
* @return - usmStatsNotInTimeWindows
|
||||
*/
|
||||
unsigned long get_stats_not_in_time_windows() const
|
||||
{ return usmStatsNotInTimeWindows; };
|
||||
|
||||
/**
|
||||
* Get the number of received messages with a unknown userName
|
||||
*
|
||||
* @return - usmStatsUnknownUserNames
|
||||
*/
|
||||
unsigned long get_stats_unknown_user_names() const
|
||||
{ return usmStatsUnknownUserNames; };
|
||||
|
||||
/**
|
||||
* Get the number of received messages with a unknown engineID
|
||||
*
|
||||
* @return - usmStatsUnknownEngineIDs
|
||||
*/
|
||||
unsigned long get_stats_unknown_engine_ids() const
|
||||
{ return usmStatsUnknownEngineIDs; };
|
||||
|
||||
/**
|
||||
* Get the number of received messages with a wrong digest
|
||||
*
|
||||
* @return - usmStatsWrongDigests
|
||||
*/
|
||||
unsigned long get_stats_wrong_digests() const
|
||||
{ return usmStatsWrongDigests; };
|
||||
|
||||
/**
|
||||
* Get the number of received messages with decryption errors
|
||||
*
|
||||
* @return - usmStatsDecryptionErrors
|
||||
*/
|
||||
unsigned long get_stats_decryption_errors() const
|
||||
{ return usmStatsDecryptionErrors; };
|
||||
|
||||
//@{
|
||||
/**
|
||||
* Increase the stats counter. Should only be used by agent++.
|
||||
*/
|
||||
void inc_stats_unsupported_sec_levels();
|
||||
void inc_stats_not_in_time_windows();
|
||||
void inc_stats_unknown_user_names();
|
||||
void inc_stats_unknown_engine_ids();
|
||||
void inc_stats_wrong_digests();
|
||||
void inc_stats_decryption_errors();
|
||||
//@}
|
||||
|
||||
|
||||
/**
|
||||
* Get a const pointer to the first entry of the UsmUserNameTable.
|
||||
*/
|
||||
const UsmUserNameTableEntry *peek_first_user();
|
||||
|
||||
/**
|
||||
* Get a const pointer to the next entry of the UsmUserNameTable.
|
||||
*/
|
||||
const UsmUserNameTableEntry *peek_next_user(const UsmUserNameTableEntry *e);
|
||||
|
||||
|
||||
/**
|
||||
* Get a const pointer to the first entry of the UsmUserTable.
|
||||
*/
|
||||
const UsmUserTableEntry *peek_first_luser();
|
||||
|
||||
/**
|
||||
* Get a const pointer to the next entry of the UsmUserTable.
|
||||
*/
|
||||
const UsmUserTableEntry *peek_next_luser(const UsmUserTableEntry *e);
|
||||
|
||||
#if 0
|
||||
//! deprecated
|
||||
int get_security_name(const unsigned char *user_name,
|
||||
const long int user_name_len,
|
||||
unsigned char *security_name,
|
||||
int *security_name_len);
|
||||
//! deprecated
|
||||
struct UsmUser *get_user(const unsigned char *engine_id,
|
||||
const long int engine_id_len,
|
||||
const unsigned char *security_name,
|
||||
const long int security_name_len);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* for v3MP:
|
||||
*
|
||||
* Delete the pointers within the structure and the structure
|
||||
* itself.
|
||||
*
|
||||
* @param ssr - The structure that should be deleted.
|
||||
*/
|
||||
void delete_sec_state_reference(struct SecurityStateReference *ssr);
|
||||
|
||||
/**
|
||||
* Protected (for agent++):
|
||||
*
|
||||
* Get the user at the specified position of the usmUserTable.
|
||||
*
|
||||
* The caller is responsible to delete the entries usmUserEngineID,
|
||||
* usmUserNamem, usmUserSecurityName of the returned struct and the
|
||||
* struct.
|
||||
*
|
||||
* @param number - get the entry at position number (1...)
|
||||
*
|
||||
* @return - a pointer to the structure or NULL if number is out
|
||||
* of range
|
||||
*/
|
||||
struct UsmUserTableEntry *get_user(int number);
|
||||
|
||||
/**
|
||||
* Protected (for agent++):
|
||||
*
|
||||
* Get the properties of the specified user.
|
||||
*
|
||||
* The caller is responsible to delete the returned struct.
|
||||
*
|
||||
* @param security_name - The security name of the user
|
||||
*
|
||||
* @return - a pointer to the structure or NULL if number is out
|
||||
* of range
|
||||
*/
|
||||
struct UsmUserNameTableEntry *get_user(const OctetStr &security_name);
|
||||
|
||||
/**
|
||||
* Protected (for agent++):
|
||||
*
|
||||
* Get the number of elements in the usmUserTable
|
||||
*
|
||||
* @return - number of elements
|
||||
*/
|
||||
int get_user_count() const;
|
||||
|
||||
|
||||
/**
|
||||
* Protected (for agent++)
|
||||
*
|
||||
* Register a callback function that is called if a new localized user
|
||||
* has been added to the usm user table
|
||||
*/
|
||||
void add_user_added_callback(const usm_add_user_callback cb);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Get a new security state reference (for v3MP).
|
||||
*
|
||||
* @return - A newly created security state reference.
|
||||
*/
|
||||
struct SecurityStateReference *get_new_sec_state_reference();
|
||||
|
||||
/**
|
||||
* Generate a complete message that is ready to send to the target.
|
||||
*
|
||||
* @param globalData - Buffer containing the serialized globalData,
|
||||
* ready to be copied into the wholeMsg
|
||||
* @param globalDataLength - The length of this buffer
|
||||
* @param maxMessageSize - The maximum message size
|
||||
* @param securityEngineID - The engineID of the authoritative SNMP entity
|
||||
* @param securityName - The name of the user
|
||||
* @param securityLevel - The security Level for this Message
|
||||
* @param scopedPDU - Buffer containing the serialized scopedPDU,
|
||||
* ready to be copied into the wholeMsg
|
||||
* @param scopedPDULength - The length of this Buffer
|
||||
* @param securityStateReference - The reference that was generated when
|
||||
* the request was parsed. For request, this
|
||||
* param has to be NULL. The reference
|
||||
* is deleted by this function.
|
||||
* @param wholeMsg - OUT: the buffer for the whole message
|
||||
* @param wholeMsgLength - IN: lenght of the buffer.
|
||||
* OUT: length of the generated message
|
||||
*
|
||||
* @return - SNMPv3_USM_OK on success. See snmperrs.h for the error codes
|
||||
* of the USM.
|
||||
*/
|
||||
int generate_msg(
|
||||
unsigned char *globalData, // message header, admin data
|
||||
int globalDataLength,
|
||||
int maxMessageSize, // of the sending SNMP entity
|
||||
const OctetStr &securityEngineID,// authoritative SNMP entity
|
||||
const OctetStr &securityName, // on behalf of this principal
|
||||
int securityLevel, // Level of Security requested
|
||||
unsigned char *scopedPDU, // message (plaintext) payload
|
||||
int scopedPDULength,
|
||||
struct SecurityStateReference *securityStateReference,
|
||||
unsigned char *wholeMsg, // OUT complete generated message
|
||||
int *wholeMsgLength); // OUT length of generated message
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Parse a received message.
|
||||
*
|
||||
* @param maxMessageSize - The maximum message size of the snding
|
||||
* SNMP entity.
|
||||
* @param securityParameters - The security parameters as received
|
||||
* @param securityParametersLength - The length of the security parameters
|
||||
* @param securityParametersPosition - The position of the security
|
||||
* parameters in the message
|
||||
* @param securityLevel - The securityLevel of the message
|
||||
* @param wholeMsg - The buffer with the whole message
|
||||
* @param wholeMsgLength - The length of the whole message
|
||||
* @param msgData - The buffer with the messageData
|
||||
* @param msgDataLength - The length of the messageData buffer
|
||||
* @param security_engine_id - OUT: the authoritative engineID
|
||||
* @param security_name - OUT: the name of the user
|
||||
* @param scopedPDU - OUT: buffer containing the scopedPDU
|
||||
* @param scopedPDULength - IN: length of the buffer
|
||||
* OUT: length of the scopedPDU
|
||||
* @param maxSizeResponseScopedPDU - OUT: maximum size for a scopedPDU in a
|
||||
* response message
|
||||
* @param securityStateReference - OUT: the securityStateReference
|
||||
*
|
||||
* @return - SNMPv3_USM_OK on success. See snmperrs.h for the error codes
|
||||
* of the USM.
|
||||
*/
|
||||
int process_msg(
|
||||
int maxMessageSize, // of the sending SNMP entity
|
||||
unsigned char *securityParameters, // for the received message
|
||||
int securityParametersLength,
|
||||
int securityParametersPosition,
|
||||
long int securityLevel, // Level of Security
|
||||
unsigned char *wholeMsg, // as received on the wire
|
||||
int wholeMsgLength, // length as received on the wire
|
||||
unsigned char *msgData,
|
||||
int msgDataLength,
|
||||
OctetStr &security_engine_id, // authoritative SNMP entity
|
||||
OctetStr &security_name, //identification of the principal
|
||||
unsigned char *scopedPDU, // message (plaintext) payload
|
||||
int *scopedPDULength,
|
||||
long *maxSizeResponseScopedPDU,// maximum size of the Response PDU
|
||||
struct SecurityStateReference *securityStateReference
|
||||
// reference to security state
|
||||
); // information, needed for response
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Delete the pointers in the structure and set all values to 0/NULL.
|
||||
*
|
||||
* @param usp - The structure that should be deleted
|
||||
*/
|
||||
void delete_sec_parameters( struct UsmSecurityParameters *usp);
|
||||
|
||||
|
||||
/**
|
||||
* Serialize the given values into the buffer according to the BER.
|
||||
*
|
||||
* UsmSecurityParameters ::=
|
||||
* SEQUENCE {
|
||||
* -- global User-based security parameters
|
||||
* msgAuthoritativeEngineID OCTET STRING (5..32)
|
||||
* msgAuthoritativeEngineBoots INTEGER (0..2147483647),
|
||||
* msgAuthoritativeEngineTime INTEGER (0..2147483647),
|
||||
* msgUserName OCTET STRING (SIZE(0..32)),
|
||||
* -- authentication protocol specific parameters
|
||||
* msgAuthenticationParameters OCTET STRING,
|
||||
* -- privacy protocol specific parameters
|
||||
* msgPrivacyParameters OCTET STRING
|
||||
* }
|
||||
*
|
||||
* @param outBuf - buffer for the serialized values
|
||||
* @param maxLength - before call: length of the buffer
|
||||
* after call: bytes left in the buffer
|
||||
* @param sp - the values to serialize
|
||||
* @param position - after call: points to the first byte of the
|
||||
* field for the authentication parameter
|
||||
*
|
||||
* @return - a pointer to the first free byte in the buffer,
|
||||
* NULL on error
|
||||
*/
|
||||
unsigned char *build_sec_params(unsigned char *outBuf, int *maxLength,
|
||||
struct UsmSecurityParameters sp,
|
||||
int *position);
|
||||
|
||||
/**
|
||||
* Serialize the given values acording to the BER into the
|
||||
* buffer. On success, the buffer contains a valid SNMPv3 message.
|
||||
*
|
||||
* @param outBuf - buffer for the serialized values
|
||||
* @param maxLength - before call: length of the buffer
|
||||
* after call: bytes left in the buffer
|
||||
* @param globalData - Buffer that contains the serialized globalData
|
||||
* @param globalDataLength - The length of this buffer
|
||||
* @param positionAuthPar - after call: points to the first byte of the
|
||||
* field for the authentication parameter
|
||||
* @param securityParameters - The security parameters
|
||||
* @param msgData - Buffer that contains the serialized msgData
|
||||
* @param msgDataLength - The length of this buffer
|
||||
*
|
||||
* @return - a pointer to the first free byte in the buffer,
|
||||
* NULL on error
|
||||
*/
|
||||
unsigned char *build_whole_msg(
|
||||
unsigned char *outBuf, int *maxLength,
|
||||
unsigned char *globalData, long int globalDataLength,
|
||||
int *positionAuthPar,
|
||||
struct UsmSecurityParameters securityParameters,
|
||||
unsigned char *msgData, long int msgDataLength);
|
||||
|
||||
|
||||
/**
|
||||
* Delete the pointers in the structure
|
||||
*
|
||||
* @param user - The structure that should be deleted
|
||||
*/
|
||||
inline void delete_user_ptr(struct UsmUser *user);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
OctetStr local_snmp_engine_id; ///< local snmp engine id
|
||||
const v3MP *v3mp; ///< Pointer to the v3MP that created this object
|
||||
|
||||
// 0: don't accept messages from hosts with a unknown engine id
|
||||
int discovery_mode;
|
||||
|
||||
// MIB Counters
|
||||
unsigned int usmStatsUnsupportedSecLevels;
|
||||
unsigned int usmStatsNotInTimeWindows;
|
||||
unsigned int usmStatsUnknownUserNames;
|
||||
unsigned int usmStatsUnknownEngineIDs;
|
||||
unsigned int usmStatsWrongDigests;
|
||||
unsigned int usmStatsDecryptionErrors;
|
||||
|
||||
// the instance of AuthPriv
|
||||
AuthPriv *auth_priv;
|
||||
|
||||
// this table contains time values of contacted snmp entities
|
||||
USMTimeTable *usm_time_table;
|
||||
|
||||
// Users that are known but not localized to a engine ID
|
||||
USMUserNameTable *usm_user_name_table;
|
||||
|
||||
// Table containing localized Users ready to use
|
||||
USMUserTable *usm_user_table;
|
||||
|
||||
// Callback for agent++ to indicate new users in usm tables
|
||||
usm_add_user_callback usm_add_user_cb;
|
||||
|
||||
};
|
||||
|
||||
|
||||
// only for compatibility do not use these values and functions:
|
||||
// =============================================================
|
||||
|
||||
#define SecurityLevel_noAuthNoPriv SNMP_SECURITY_LEVEL_NOAUTH_NOPRIV
|
||||
#define SecurityLevel_authNoPriv SNMP_SECURITY_LEVEL_AUTH_NOPRIV
|
||||
#define SecurityLevel_authPriv SNMP_SECURITY_LEVEL_AUTH_PRIV
|
||||
|
||||
#define SNMPv3_usmNoAuthProtocol SNMP_AUTHPROTOCOL_NONE
|
||||
#define SNMPv3_usmHMACMD5AuthProtocol SNMP_AUTHPROTOCOL_HMACMD5
|
||||
#define SNMPv3_usmHMACSHAAuthProtocol SNMP_AUTHPROTOCOL_HMACSHA
|
||||
|
||||
#define SNMPv3_usmNoPrivProtocol SNMP_PRIVPROTOCOL_NONE
|
||||
#define SNMPv3_usmDESPrivProtocol SNMP_PRIVPROTOCOL_DES
|
||||
#define SNMPv3_usmIDEAPrivProtocol SNMP_PRIVPROTOCOL_IDEA
|
||||
#define SNMPv3_usmAES128PrivProtocol SNMP_PRIVPROTOCOL_AES128
|
||||
#define SNMPv3_usmAES192PrivProtocol SNMP_PRIVPROTOCOL_AES192
|
||||
#define SNMPv3_usmAES256PrivProtocol SNMP_PRIVPROTOCOL_AES256
|
||||
|
||||
|
||||
#endif // _SNMPv3
|
||||
|
||||
#endif
|
243
backend/camembert/libkmsnmp/v3.h
Normal file
243
backend/camembert/libkmsnmp/v3.h
Normal file
@ -0,0 +1,243 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## v3.h
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
// $Id: v3.h,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $
|
||||
|
||||
#ifndef _V3_H
|
||||
#define _V3_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "config_snmp_pp.h"
|
||||
|
||||
class OctetStr;
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
/** @name SNMPv3 Security Model values
|
||||
*/
|
||||
//@{
|
||||
#define SNMP_SECURITY_MODEL_ANY 0 //!< Not used in SNMP++.
|
||||
#define SNMP_SECURITY_MODEL_V1 1 //!< Can be used for SNMPv1 only.
|
||||
#define SNMP_SECURITY_MODEL_V2 2 //!< Can be used for SNMPv2 only.
|
||||
#define SNMP_SECURITY_MODEL_USM 3 //!< Can be used for SNMPv3 only.
|
||||
//@}
|
||||
|
||||
/**
|
||||
* Set the logfile for logging output.
|
||||
*
|
||||
* @param filename - Complete path and name of the logfile.
|
||||
*
|
||||
* @note The string may not be deleted after the call.
|
||||
*/
|
||||
DLLOPT void debug_set_logfile(const char *filename);
|
||||
|
||||
/**
|
||||
* Set the amount of log messages you want to get. To disable all
|
||||
* messages, set the level to -1
|
||||
*
|
||||
* @param level - New level
|
||||
*/
|
||||
DLLOPT void debug_set_level(const int db_level);
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
/**
|
||||
* SNMP++ logging function.
|
||||
*
|
||||
* The default is to log all messages with a level < 19. To change
|
||||
* that either edit v3.cpp or use a "extern unsigned int debug_level"
|
||||
* to change the level.
|
||||
*
|
||||
* @param db_level - Priority of the message (0 = high)
|
||||
* @param format - Just like printf
|
||||
*/
|
||||
DLLOPT void debugprintf(int db_level, const char *format, ...);
|
||||
|
||||
/**
|
||||
* SNMP++ logging function for hex strings.
|
||||
*
|
||||
* @param db_level - Priority of the message (0 = high)
|
||||
* @param comment - Comment printed before the hex dump (may be 0)
|
||||
* @param data - pointer to the hex data
|
||||
* @param len - length of the hex data
|
||||
*/
|
||||
DLLOPT void debughexcprintf(int db_level, const char* comment,
|
||||
const unsigned char *data, const unsigned int len);
|
||||
|
||||
//! Wrapper for debughexcprintf() without comment.
|
||||
#define debughexprintf(db_level, data, len) \
|
||||
debughexcprintf(db_level, NULL, data, len);
|
||||
|
||||
#else
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||
#define debugprintf(db_level,format...)
|
||||
#else
|
||||
void debugprintf(int db_level, const char *format, ...);
|
||||
#endif
|
||||
#else
|
||||
// disable any warning for wrong number of arguments in macro
|
||||
#pragma warning(disable:4002)
|
||||
#define debugprintf(db_level,format)
|
||||
#endif //_MSC_VER
|
||||
|
||||
#define debughexprintf( db_level, data, len)
|
||||
#define debughexcprintf(db_level, comment, data, len)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _SNMPv3
|
||||
|
||||
#define V3MAXMESSAGESIZE SNMP_MSG_LENGTH
|
||||
#define MAXLENGTH_ENGINEID 32
|
||||
#define MAXLENGTH_FILENAME 255
|
||||
|
||||
#define oidV3SnmpEngine "1.3.6.1.6.3.10.2.1"
|
||||
#define oidV3SnmpEngineID "1.3.6.1.6.3.10.2.1.1.0"
|
||||
#define oidV3SnmpEngineBoots "1.3.6.1.6.3.10.2.1.2.0"
|
||||
#define oidV3SnmpEngineTime "1.3.6.1.6.3.10.2.1.3.0"
|
||||
#define oidV3SnmpEngineMaxMessageSize "1.3.6.1.6.3.10.2.1.4.0"
|
||||
|
||||
// also defined in agent++/include/vacm.h
|
||||
#ifndef oidSnmpUnavailableContexts
|
||||
#define oidSnmpUnavailableContexts "1.3.6.1.6.3.12.1.4.0"
|
||||
#define oidSnmpUnknownContexts "1.3.6.1.6.3.12.1.5.0"
|
||||
#endif
|
||||
|
||||
/** @name Error codes (storing engineBoots)
|
||||
*
|
||||
* These values are returned by getBootCounter() and saveBootCounter().
|
||||
*/
|
||||
//@{
|
||||
#define SNMPv3_OK 0 //!< No error
|
||||
#define SNMPv3_NO_ENTRY_ERROR -1 //!< No line for the engine id found
|
||||
#define SNMPv3_FILEOPEN_ERROR -2 //!< Unable to open file
|
||||
#define SNMPv3_TOO_LONG_ERROR -3 //!< The given engineID is too long
|
||||
#define SNMPv3_FILE_ERROR -4 //!< The given file contains a wrong line
|
||||
#define SNMPv3_FILECREATE_ERROR -5 //!< The File could not be created
|
||||
#define SNMPv3_FILERENAME_ERROR -6 //!< Error renaming the temporary file
|
||||
//@}
|
||||
|
||||
/**
|
||||
* Compare two strings.
|
||||
*
|
||||
* @param str1 - The first byte array
|
||||
* @param ptr1len - Length of first array
|
||||
* @param str2 - The second byte array
|
||||
* @param ptr2len - Length of second array
|
||||
*
|
||||
* @return 1 if the strings are identical, 0 if not.
|
||||
*/
|
||||
DLLOPT int unsignedCharCompare(const unsigned char *str1,
|
||||
const long int ptr1len,
|
||||
const unsigned char *str2,
|
||||
const long int ptr2len);
|
||||
|
||||
/**
|
||||
* String copy function.
|
||||
*
|
||||
* @note The returned string has to be deleted with "delete []".
|
||||
*
|
||||
* @param src - Source string
|
||||
* @param srclen - Length of source string
|
||||
*
|
||||
* @return Pointer to a null terminated copy of src (or 0 on error).
|
||||
*/
|
||||
DLLOPT unsigned char *v3strcpy(const unsigned char *src, const int srclen);
|
||||
|
||||
/**
|
||||
* Encode the given string into the output buffer. For each byte
|
||||
* of the string two bytes in the output buffer are used. The
|
||||
* output buffer will contain chars from 0x64 to 0x79.
|
||||
*
|
||||
* @param in - The string (for example engine id) to encode
|
||||
* @param in_length - The length of the engineID
|
||||
* @param out - The output buffer for the encoded string, must have
|
||||
* lenth 2 * in_length
|
||||
*/
|
||||
DLLOPT void encodeString(const unsigned char* in, const int in_length,
|
||||
char* out);
|
||||
|
||||
/**
|
||||
* Decode the given encoded string into the output buffer.
|
||||
*
|
||||
* @param in - The encoded string
|
||||
* @param in_length - The length of the encoded string
|
||||
* @param out - Buffer for the decoded string (half size of input
|
||||
* string). The String will be null terminated.
|
||||
*/
|
||||
DLLOPT void decodeString(const unsigned char* in, const int in_length,
|
||||
char* out);
|
||||
|
||||
/**
|
||||
* Read the bootCounter of the given engineID stored in the given file.
|
||||
*
|
||||
* @param fileName - The name of the file
|
||||
* @param engineId - Read the bootCounter for this enigneID
|
||||
* @param boot - OUT: the bootCounter that was read
|
||||
*
|
||||
* @return One of SNMPv3_OK, SNMPv3_TOO_LONG_ERROR, SNMPv3_FILE_ERROR,
|
||||
* SNMPv3_NO_ENTRY_ERROR, SNMPv3_FILEOPEN_ERROR
|
||||
*
|
||||
*/
|
||||
DLLOPT int getBootCounter(const char *fileName,
|
||||
const OctetStr &engineId, unsigned int &boot);
|
||||
|
||||
/**
|
||||
* Store the bootCounter of the given engineID in the given file.
|
||||
*
|
||||
* @param fileName - The name of the file
|
||||
* @param engineId - Store the bootCounter for this enigneID
|
||||
* @param boot - The bootCounter
|
||||
*
|
||||
* @return One of SNMPv3_OK, SNMPv3_FILEOPEN_ERROR, SNMPv3_FILECREATE_ERROR,
|
||||
* SNMPv3_FILERENAME_ERROR.
|
||||
*
|
||||
*/
|
||||
DLLOPT int saveBootCounter(const char *fileName,
|
||||
const OctetStr &engineId, const unsigned int boot);
|
||||
|
||||
|
||||
#endif // _SNMPv3
|
||||
|
||||
// only for compatibility do not use these values:
|
||||
#define SecurityModel_any SNMP_SECURITY_MODEL_ANY
|
||||
#define SecurityModel_v1 SNMP_SECURITY_MODEL_V1
|
||||
#define SecurityModel_v2 SNMP_SECURITY_MODEL_V2
|
||||
#define SecurityModel_USM SNMP_SECURITY_MODEL_USM
|
||||
|
||||
#endif // _V3_H
|
363
backend/camembert/libkmsnmp/vb.cpp
Normal file
363
backend/camembert/libkmsnmp/vb.cpp
Normal file
@ -0,0 +1,363 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## vb.cpp
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
/*===================================================================
|
||||
|
||||
Copyright (c) 1999
|
||||
Hewlett-Packard Company
|
||||
|
||||
ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
Permission to use, copy, modify, distribute and/or sell this software
|
||||
and/or its documentation is hereby granted without fee. User agrees
|
||||
to display the above copyright notice and this license notice in all
|
||||
copies of the software and any documentation of the software. User
|
||||
agrees to assume all liability for the use of the software; Hewlett-Packard
|
||||
makes no representations about the suitability of this software for any
|
||||
purpose. It is provided "AS-IS" without warranty of any kind,either express
|
||||
or implied. User hereby grants a royalty-free license to any and all
|
||||
derivatives based upon this software code base.
|
||||
|
||||
|
||||
|
||||
V B . C P P
|
||||
|
||||
VARIABLE BINDING CLASS IMPLEMENTATION
|
||||
|
||||
DESCRIPTION:
|
||||
This module contains the class implementation of the VB class.
|
||||
The Vb class is an encapsulation of the snmp variable binding.
|
||||
|
||||
DESIGN + AUTHOR:
|
||||
Peter E Mellquist
|
||||
|
||||
LANGAUGE:
|
||||
ANSI C++
|
||||
|
||||
OPERATING SYSTEMS:
|
||||
MS-Windows Win32
|
||||
BSD UNIX
|
||||
|
||||
=====================================================================*/
|
||||
char vb_cpp_version[]="#(@) SNMP++ $Id: vb.cpp,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $";
|
||||
|
||||
#include "vb.h" // include vb class defs
|
||||
|
||||
#define IP_ADDR_SIZE 4
|
||||
#define IPX_ADDR_SIZE 10
|
||||
#define MAC_ADDR_SIZE 6
|
||||
|
||||
//--------------[ Vb::valid() ]-----------------------------------------
|
||||
// returns validity of a Vb object
|
||||
// must have a valid oid and value
|
||||
bool Vb::valid() const
|
||||
{
|
||||
if (iv_vb_oid.valid() &&
|
||||
#ifdef WHEN_WE_HAVE_SNMPNULL_CLASS
|
||||
iv_vb_value && iv_vb_value->valid()
|
||||
#else
|
||||
((iv_vb_value == NULL) || (iv_vb_value && iv_vb_value->valid()))
|
||||
#endif
|
||||
)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
//---------------[ Vb& Vb::operator=(const Vb &vb) ]--------------------
|
||||
// overloaded assignment allows assigning one Vb to another
|
||||
// this involves deep memory thus target vb needs to be freed
|
||||
// before assigning source
|
||||
Vb& Vb::operator=(const Vb &vb)
|
||||
{
|
||||
if (this == &vb) return *this; // check for self assignment
|
||||
|
||||
free_vb(); // free up target to begin with
|
||||
|
||||
//-----[ reassign the Oid portion 1st ]
|
||||
vb.get_oid(iv_vb_oid);
|
||||
|
||||
//-----[ next set the vb value portion ]
|
||||
if (vb.iv_vb_value == NULL)
|
||||
iv_vb_value = NULL;
|
||||
else
|
||||
iv_vb_value = vb.iv_vb_value->clone();
|
||||
|
||||
exception_status = vb.exception_status;
|
||||
|
||||
return *this; // return self reference
|
||||
}
|
||||
|
||||
//----------------[ void Vb::free_vb() ]--------------------------------
|
||||
// protected method to free memory
|
||||
// this method is used to free memory when assigning new vbs
|
||||
// or destructing
|
||||
// in the case of oids and octets, we need to do a deep free
|
||||
void Vb::free_vb()
|
||||
{
|
||||
if (iv_vb_value)
|
||||
{
|
||||
delete iv_vb_value;
|
||||
iv_vb_value = NULL;
|
||||
}
|
||||
exception_status = SNMP_CLASS_SUCCESS;
|
||||
}
|
||||
|
||||
//---------------------[ Vb::get_value(int &i) ]----------------------
|
||||
// get value int
|
||||
// returns 0 on success and value
|
||||
int Vb::get_value(int &i) const
|
||||
{
|
||||
if (iv_vb_value &&
|
||||
iv_vb_value->valid() &&
|
||||
(iv_vb_value->get_syntax() == sNMP_SYNTAX_INT32 ))
|
||||
{
|
||||
long lval;
|
||||
lval = *((SnmpInt32 *)iv_vb_value);// SnmpInt32 includes cast to long,
|
||||
i = (int) lval; // but not to int.
|
||||
return SNMP_CLASS_SUCCESS;
|
||||
}
|
||||
return SNMP_CLASS_INVALID;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------[ Vb::get_value(long int &i) ]-------------------------
|
||||
// get the signed long int
|
||||
// returns 0 on success and a value
|
||||
int Vb::get_value(long &i) const
|
||||
{
|
||||
if (iv_vb_value &&
|
||||
iv_vb_value->valid() &&
|
||||
(iv_vb_value->get_syntax() == sNMP_SYNTAX_INT32 ))
|
||||
{
|
||||
i = *((SnmpInt32 *)iv_vb_value); // SnmpInt32 includes cast to long
|
||||
return SNMP_CLASS_SUCCESS;
|
||||
}
|
||||
return SNMP_CLASS_INVALID;
|
||||
}
|
||||
|
||||
|
||||
//-----------------[ Vb::get_value(unsigned long int &i) ]--------------
|
||||
// get the unsigned long int
|
||||
// returns 0 on success and a value
|
||||
int Vb::get_value(unsigned long &i) const
|
||||
{
|
||||
if (iv_vb_value &&
|
||||
iv_vb_value->valid() &&
|
||||
((iv_vb_value->get_syntax() == sNMP_SYNTAX_UINT32 ) ||
|
||||
(iv_vb_value->get_syntax() == sNMP_SYNTAX_CNTR32 ) ||
|
||||
(iv_vb_value->get_syntax() == sNMP_SYNTAX_GAUGE32 ) ||
|
||||
(iv_vb_value->get_syntax() == sNMP_SYNTAX_TIMETICKS )))
|
||||
{
|
||||
i = *((SnmpUInt32 *)iv_vb_value); // SnmpUint32 has includes to ulong
|
||||
return SNMP_CLASS_SUCCESS;
|
||||
}
|
||||
return SNMP_CLASS_INVALID;
|
||||
}
|
||||
|
||||
|
||||
//--------------[ Vb::get_value(unsigned char WINFAR * ptr, unsigned long &len)
|
||||
// get a unsigned char string value
|
||||
// destructive, copies into given ptr
|
||||
// also returned is the length
|
||||
//
|
||||
// Note!! The user must provide a target string
|
||||
// which is big enough to hold the string
|
||||
int Vb::get_value(unsigned char *ptr, unsigned long &len) const
|
||||
{
|
||||
if (iv_vb_value &&
|
||||
iv_vb_value->valid() &&
|
||||
(iv_vb_value->get_syntax() == sNMP_SYNTAX_OCTETS))
|
||||
{
|
||||
OctetStr *p_os = (OctetStr *)iv_vb_value;
|
||||
len = p_os->len();
|
||||
memcpy(ptr, p_os->data(), len);
|
||||
ptr[len] = 0;
|
||||
return SNMP_CLASS_SUCCESS;
|
||||
}
|
||||
|
||||
ptr[0] = 0;
|
||||
len = 0;
|
||||
return SNMP_CLASS_INVALID;
|
||||
}
|
||||
|
||||
//---------------[ Vb::get_value ]-------------------------------------
|
||||
// get an unsigned char array
|
||||
// caller specifies max len of target space
|
||||
int Vb::get_value(unsigned char *ptr, unsigned long &len,
|
||||
const unsigned long maxlen) const
|
||||
{
|
||||
if (iv_vb_value &&
|
||||
iv_vb_value->valid() &&
|
||||
(iv_vb_value->get_syntax() == sNMP_SYNTAX_OCTETS))
|
||||
{
|
||||
OctetStr *p_os = (OctetStr *)iv_vb_value;
|
||||
len = p_os->len();
|
||||
if (len > maxlen) len = maxlen;
|
||||
memcpy(ptr, p_os->data(), len);
|
||||
ptr[len] = 0;
|
||||
return SNMP_CLASS_SUCCESS;
|
||||
}
|
||||
|
||||
ptr[0] = 0;
|
||||
len = 0;
|
||||
return SNMP_CLASS_INVALID;
|
||||
}
|
||||
|
||||
|
||||
//---------------[ Vb::get_value(Value &val) ]--------
|
||||
int Vb::get_value(SnmpSyntax &val) const
|
||||
{
|
||||
if (iv_vb_value)
|
||||
{
|
||||
val = *iv_vb_value;
|
||||
if (val.valid())
|
||||
return SNMP_CLASS_SUCCESS;
|
||||
return SNMP_CLASS_INVALID;
|
||||
}
|
||||
// TM: should set val to be invalid
|
||||
return SNMP_CLASS_INVALID;
|
||||
}
|
||||
|
||||
//--------------[ Vb::get_value(char WINFAR *ptr) ]-------------------
|
||||
// get a char * from an octet string
|
||||
// the user must provide space or
|
||||
// memory will be stepped on
|
||||
int Vb::get_value(char *ptr) const
|
||||
{
|
||||
if (iv_vb_value &&
|
||||
iv_vb_value->valid() &&
|
||||
(iv_vb_value->get_syntax() == sNMP_SYNTAX_OCTETS))
|
||||
{
|
||||
OctetStr *p_os = (OctetStr *)iv_vb_value;
|
||||
unsigned long len = p_os->len();
|
||||
memcpy(ptr, p_os->data(), len);
|
||||
ptr[len] = 0;
|
||||
return SNMP_CLASS_SUCCESS;
|
||||
}
|
||||
|
||||
ptr[0] = 0;
|
||||
return SNMP_CLASS_INVALID;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----[ misc]--------------------------------------------------------
|
||||
|
||||
// return the current syntax
|
||||
// This method violates Object Orientation but may be useful if
|
||||
// the caller has a vb object and does not know what it is.
|
||||
// This would be useful in the implementation of a browser.
|
||||
SmiUINT32 Vb::get_syntax() const
|
||||
{
|
||||
if (exception_status != SNMP_CLASS_SUCCESS)
|
||||
return exception_status;
|
||||
else
|
||||
return (iv_vb_value ? iv_vb_value->get_syntax() : sNMP_SYNTAX_NULL);
|
||||
}
|
||||
|
||||
void Vb::set_syntax(SmiUINT32 syntax)
|
||||
{
|
||||
free_vb(); // setting to SNMP_SYNTAX_NULL
|
||||
|
||||
exception_status = SNMP_CLASS_SUCCESS;
|
||||
|
||||
switch (syntax) {
|
||||
case sNMP_SYNTAX_INT32:
|
||||
iv_vb_value = new SnmpInt32();
|
||||
break;
|
||||
case sNMP_SYNTAX_TIMETICKS:
|
||||
iv_vb_value = new TimeTicks();
|
||||
break;
|
||||
case sNMP_SYNTAX_CNTR32:
|
||||
iv_vb_value = new Counter32();
|
||||
break;
|
||||
case sNMP_SYNTAX_GAUGE32:
|
||||
iv_vb_value = new Gauge32();
|
||||
break;
|
||||
/* Not distinguishable from Gauge32
|
||||
case sNMP_SYNTAX_UINT32:
|
||||
iv_vb_value = new SnmpUInt32();
|
||||
break;
|
||||
*/
|
||||
case sNMP_SYNTAX_CNTR64:
|
||||
iv_vb_value = new Counter64();
|
||||
break;
|
||||
case sNMP_SYNTAX_BITS:
|
||||
case sNMP_SYNTAX_OCTETS:
|
||||
iv_vb_value = new OctetStr();
|
||||
break;
|
||||
case sNMP_SYNTAX_OPAQUE:
|
||||
iv_vb_value = new OpaqueStr();
|
||||
break;
|
||||
case sNMP_SYNTAX_IPADDR:
|
||||
iv_vb_value = new IpAddress();
|
||||
break;
|
||||
case sNMP_SYNTAX_OID:
|
||||
iv_vb_value = new Oid();
|
||||
break;
|
||||
case sNMP_SYNTAX_NULL:
|
||||
break;
|
||||
case sNMP_SYNTAX_NOSUCHINSTANCE:
|
||||
exception_status = sNMP_SYNTAX_NOSUCHINSTANCE;
|
||||
break;
|
||||
case sNMP_SYNTAX_NOSUCHOBJECT:
|
||||
exception_status = sNMP_SYNTAX_NOSUCHOBJECT;
|
||||
break;
|
||||
case sNMP_SYNTAX_ENDOFMIBVIEW:
|
||||
exception_status = sNMP_SYNTAX_ENDOFMIBVIEW;
|
||||
break;
|
||||
case sNMP_SYNTAX_SEQUENCE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static char blank_string[] = "";
|
||||
|
||||
// return the printabel value
|
||||
const char WINFAR *Vb::get_printable_value() const
|
||||
{
|
||||
if (iv_vb_value)
|
||||
return iv_vb_value->get_printable();
|
||||
return blank_string;
|
||||
}
|
||||
|
||||
int Vb::get_asn1_length() const
|
||||
{
|
||||
// Header for vbs is always 4 Bytes! FIXME
|
||||
if (iv_vb_value)
|
||||
return iv_vb_oid.get_asn1_length() + iv_vb_value->get_asn1_length() + 4;
|
||||
|
||||
return iv_vb_oid.get_asn1_length() + 2 + 4;
|
||||
}
|
||||
|
||||
// deprecated friend function to set exception status
|
||||
void set_exception_status(Vb *vb, const SmiUINT32 status)
|
||||
{
|
||||
if (vb)
|
||||
vb->set_exception_status(status);
|
||||
}
|
384
backend/camembert/libkmsnmp/vb.h
Normal file
384
backend/camembert/libkmsnmp/vb.h
Normal file
@ -0,0 +1,384 @@
|
||||
/*_############################################################################
|
||||
_##
|
||||
_## vb.h
|
||||
_##
|
||||
_## SNMP++v3.2.9c
|
||||
_## -----------------------------------------------
|
||||
_## Copyright (c) 2001-2003 Jochen Katz, Frank Fock
|
||||
_##
|
||||
_## This software is based on SNMP++2.6 from Hewlett Packard:
|
||||
_##
|
||||
_## Copyright (c) 1996
|
||||
_## Hewlett-Packard Company
|
||||
_##
|
||||
_## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
_## Permission to use, copy, modify, distribute and/or sell this software
|
||||
_## and/or its documentation is hereby granted without fee. User agrees
|
||||
_## to display the above copyright notice and this license notice in all
|
||||
_## copies of the software and any documentation of the software. User
|
||||
_## agrees to assume all liability for the use of the software;
|
||||
_## Hewlett-Packard and Jochen Katz make no representations about the
|
||||
_## suitability of this software for any purpose. It is provided
|
||||
_## "AS-IS" without warranty of any kind, either express or implied. User
|
||||
_## hereby grants a royalty-free license to any and all derivatives based
|
||||
_## upon this software code base.
|
||||
_##
|
||||
_## Stuttgart, Germany, Tue Dec 2 01:31:09 CET 2003
|
||||
_##
|
||||
_##########################################################################*/
|
||||
/*===================================================================
|
||||
|
||||
Copyright (c) 1999
|
||||
Hewlett-Packard Company
|
||||
|
||||
ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
|
||||
Permission to use, copy, modify, distribute and/or sell this software
|
||||
and/or its documentation is hereby granted without fee. User agrees
|
||||
to display the above copyright notice and this license notice in all
|
||||
copies of the software and any documentation of the software. User
|
||||
agrees to assume all liability for the use of the software; Hewlett-Packard
|
||||
makes no representations about the suitability of this software for any
|
||||
purpose. It is provided "AS-IS without warranty of any kind,either express
|
||||
or implied. User hereby grants a royalty-free license to any and all
|
||||
derivatives based upon this software code base.
|
||||
|
||||
|
||||
SNMP++ V B . H
|
||||
|
||||
VARIABLE BINDING CLASS DEFINITION
|
||||
|
||||
DESCRIPTION:
|
||||
This module contains the class definition for the variable binding
|
||||
class. The VB class is an encapsulation of a SNMP VB. A VB object is
|
||||
composed of an SNMP++ Oid and an SMI value. The Vb class utilizes Oid
|
||||
objects and thus requires the Oid class. The Vb class may be used
|
||||
stand alone and does not require use of any other snmp library.
|
||||
|
||||
|
||||
DESIGN + AUTHOR:
|
||||
Peter E. Mellquist
|
||||
|
||||
LANGAUGE:
|
||||
ANSI C++
|
||||
|
||||
OPERATING SYSTEM:
|
||||
MS-Windows Win32
|
||||
BSD UNIX
|
||||
|
||||
=====================================================================*/
|
||||
// $Id: vb.h,v 1.1.1.1 2005/03/14 10:55:30 kindman Exp $
|
||||
|
||||
#ifndef _VB_CLS
|
||||
#define _VB_CLS
|
||||
|
||||
#include "oid.h" // oid class def
|
||||
#include "timetick.h" // time ticks
|
||||
#include "counter.h" // counter
|
||||
#include "gauge.h" // gauge class
|
||||
#include "ctr64.h" // 64 bit counters
|
||||
#include "octet.h" // octet class
|
||||
#include "address.h" // address class def
|
||||
#include "integer.h" // integer class
|
||||
#include "snmperrs.h"
|
||||
|
||||
//------------[ VB Class Def ]-------------------------------------
|
||||
/**
|
||||
* The Vb class is the encapsulation of the SNMP variable binding.
|
||||
*
|
||||
* Variable binding lists in SNMP++ are represented as arrays of Vb
|
||||
* objects. Vb objects are passed to and from SNMP objects to provide
|
||||
* getting or setting MIB values. The vb class keeps its own memory
|
||||
* for objects and does not utilize pointers to external data
|
||||
* structures.
|
||||
*/
|
||||
class DLLOPT Vb
|
||||
{
|
||||
//-----[ public members ]
|
||||
public:
|
||||
|
||||
//-----[ constructors / destructors ]-------------------------------
|
||||
|
||||
/**
|
||||
* Constructor with no arguments.
|
||||
*
|
||||
* This constructor creates an unitialized vb.
|
||||
*/
|
||||
Vb() : iv_vb_value(0), exception_status(SNMP_CLASS_SUCCESS) {};
|
||||
|
||||
/**
|
||||
* Constructor to initialize the oid.
|
||||
*
|
||||
* This constructor creates a vb with oid portion initialized.
|
||||
*/
|
||||
Vb(const Oid &oid)
|
||||
: iv_vb_oid(oid), iv_vb_value(0), exception_status(SNMP_CLASS_SUCCESS) {};
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*/
|
||||
Vb(const Vb &vb) : iv_vb_value(0) { *this = vb; };
|
||||
|
||||
/**
|
||||
* Destructor that frees all allocated memory.
|
||||
*/
|
||||
~Vb() { free_vb(); };
|
||||
|
||||
/**
|
||||
* Overloaded assignment operator.
|
||||
*/
|
||||
Vb& operator=(const Vb &vb);
|
||||
|
||||
/**
|
||||
* Clone operator.
|
||||
*/
|
||||
Vb *clone( ) const { return new Vb(*this); };
|
||||
|
||||
//-----[ set oid / get oid ]------------------------------------------
|
||||
|
||||
/**
|
||||
* Set the oid from another oid.
|
||||
*/
|
||||
void set_oid(const Oid &oid) { iv_vb_oid = oid; };
|
||||
|
||||
/**
|
||||
* Get the oid portion.
|
||||
*
|
||||
* @note Check the validity of the object through Vb::valid() before
|
||||
* calling this method.
|
||||
*/
|
||||
void get_oid(Oid &oid) const { oid = iv_vb_oid; };
|
||||
|
||||
/**
|
||||
* Get the oid portion as a const.
|
||||
*
|
||||
* @note Check the validity of the object through Vb::valid() before
|
||||
* calling this method.
|
||||
*/
|
||||
const Oid &get_oid() const { return iv_vb_oid; };
|
||||
|
||||
//-----[ set value ]--------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set the value using any SnmpSyntax object.
|
||||
*/
|
||||
void set_value(const SnmpSyntax &val)
|
||||
{ free_vb(); iv_vb_value = val.clone(); };
|
||||
|
||||
/**
|
||||
* Set the value with an int.
|
||||
*
|
||||
* The syntax of the Vb will be set to SMI INT32.
|
||||
*/
|
||||
void set_value(const int i) { free_vb(); iv_vb_value = new SnmpInt32(i); };
|
||||
|
||||
/**
|
||||
* Set the value with an int.
|
||||
*
|
||||
* The syntax of the Vb will be set to SMI INT32.
|
||||
*/
|
||||
void set_value(const long i)
|
||||
{ free_vb(); iv_vb_value = new SnmpInt32(i); };
|
||||
|
||||
/**
|
||||
* Set the value with an unsigned long int.
|
||||
*
|
||||
* The syntax of the Vb will be set to SMI UINT32.
|
||||
*/
|
||||
void set_value(const unsigned long i)
|
||||
{ free_vb(); iv_vb_value = new SnmpUInt32(i); };
|
||||
|
||||
/**
|
||||
* Set value using a null terminated string.
|
||||
*
|
||||
* The syntax of the Vb will be set to SMI octet.
|
||||
*/
|
||||
void set_value(const char *ptr)
|
||||
{ free_vb(); iv_vb_value = new OctetStr(ptr); };
|
||||
|
||||
/**
|
||||
* Set value using a string and length.
|
||||
*
|
||||
* The syntax of the Vb will be set to SMI octet.
|
||||
*/
|
||||
void set_value(const unsigned char *ptr, const unsigned int len)
|
||||
{ free_vb(); iv_vb_value = new OctetStr(ptr, len); };
|
||||
|
||||
/**
|
||||
* Set the value portion of the vb to null, if its not already.
|
||||
*/
|
||||
void set_null() { free_vb(); };
|
||||
|
||||
//----[ get value ]------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get the value using a SnmpSyntax object.
|
||||
*
|
||||
* @param val - An object of a subclass of SnmpSyntax that will be
|
||||
* assigned the value of the vb.
|
||||
*
|
||||
* @return SNMP_CLASS_SUCCESS if the vb value could be assigned to
|
||||
* the passed SnmpSyntax object, else SNMP_CLASS_INVALID.
|
||||
*/
|
||||
int get_value(SnmpSyntax &val) const;
|
||||
|
||||
/**
|
||||
* Get the value.
|
||||
*
|
||||
* This method will only return success if the value of the vb is SMI INT32.
|
||||
*
|
||||
* @param i - returned value
|
||||
*
|
||||
* @return SNMP_CLASS_SUCCESS on success, else SNMP_CLASS_INVALID.
|
||||
*/
|
||||
int get_value(int &i) const;
|
||||
|
||||
/**
|
||||
* Get the value.
|
||||
*
|
||||
* This method will only return success if the value of the vb is SMI INT32.
|
||||
*
|
||||
* @param i - returned value
|
||||
*
|
||||
* @return SNMP_CLASS_SUCCESS on success, else SNMP_CLASS_INVALID.
|
||||
*/
|
||||
int get_value(long &i) const;
|
||||
|
||||
/**
|
||||
* Get the value.
|
||||
*
|
||||
* This method will only return success if the value of the vb can
|
||||
* be mapped to an unsigned long (SMI types uint32, counter32, gauge
|
||||
* and timeticks).
|
||||
*
|
||||
* @param i - returned value
|
||||
*
|
||||
* @return SNMP_CLASS_SUCCESS on success, else SNMP_CLASS_INVALID.
|
||||
*/
|
||||
int get_value(unsigned long &i) const;
|
||||
|
||||
/**
|
||||
* Get the value.
|
||||
*
|
||||
* This method will only return success if the value of the vb is SMI OCTET.
|
||||
*
|
||||
* @note The caller must provide a target string big enough to
|
||||
* handle the vb string. No length checks are done within
|
||||
* this method.
|
||||
*
|
||||
* @param ptr - Pointer to already allocated space to hold the vb
|
||||
* value. The first char will be set to zero on failure.
|
||||
* @param len - Returned length of the string. Will be set to 0 on failure.
|
||||
*
|
||||
* @return SNMP_CLASS_SUCCESS on success, else SNMP_CLASS_INVALID.
|
||||
*/
|
||||
int get_value(unsigned char *ptr, unsigned long &len) const;
|
||||
|
||||
/**
|
||||
* Get the value.
|
||||
*
|
||||
* This method will only return success if the value of the vb is SMI OCTET.
|
||||
*
|
||||
* @note If the target space is not big enough to hold the complete
|
||||
* string only maxlen bytes are copied. In any case the returned
|
||||
* string is NOT null terminated.
|
||||
*
|
||||
* @param ptr - Pointer to already allocated space to hold the vb
|
||||
* value. The first char will be set to zero on failure.
|
||||
* @param len - Returned length of the string. Will be set to 0
|
||||
* on failure.
|
||||
* @param maxlen - Maximum length of the space that ptr points to.
|
||||
*
|
||||
* @return SNMP_CLASS_SUCCESS on success, else SNMP_CLASS_INVALID.
|
||||
*/
|
||||
int get_value(unsigned char *ptr,
|
||||
unsigned long &len,
|
||||
const unsigned long maxlen) const;
|
||||
|
||||
/**
|
||||
* Get the value.
|
||||
*
|
||||
* This method will only return success if the value of the vb is SMI OCTET.
|
||||
*
|
||||
* @note The caller must provide a target string big enough to
|
||||
* handle the vb string. No length checks are done within
|
||||
* this method. The returned string will be null terminated.
|
||||
*
|
||||
* @param ptr - Pointer to already allocated space to hold the vb
|
||||
* value. The first char will be set to zero on failure.
|
||||
*
|
||||
* @return SNMP_CLASS_SUCCESS on success, else SNMP_CLASS_INVALID.
|
||||
*/
|
||||
int get_value(char *ptr) const;
|
||||
|
||||
//-----[ misc]--------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Return the syntax or the exception status.
|
||||
*
|
||||
* @return If the SNMPv2 exception status is set, it is returned.
|
||||
* otherwise the syntax of the value object is returned.
|
||||
*/
|
||||
SmiUINT32 get_syntax() const;
|
||||
|
||||
/**
|
||||
* Set the syntax.
|
||||
*
|
||||
* The Value portion of the Vb will be deleted and a new value portion
|
||||
* is allocated with it's default value (zero).
|
||||
*
|
||||
* @param syntax - The new syntax.
|
||||
*/
|
||||
void set_syntax(const SmiUINT32 syntax);
|
||||
|
||||
/**
|
||||
* Set the exception status.
|
||||
*
|
||||
* @param status - the new SNMPv2 exception status.
|
||||
*/
|
||||
void set_exception_status(const SmiUINT32 status)
|
||||
{ exception_status = status; };
|
||||
|
||||
//! deprecated! Use Vb::set_exception_status()
|
||||
DLLOPT friend void set_exception_status(Vb *vb, const SmiUINT32 status);
|
||||
|
||||
/**
|
||||
* Return a formatted version of the value.
|
||||
*
|
||||
* @return A null terminated string (empty if no value).
|
||||
*/
|
||||
const char *get_printable_value() const;
|
||||
|
||||
/**
|
||||
* Return a formatted version of the Oid.
|
||||
*
|
||||
* @return A null terminated string (may be empty if no Oid has been set).
|
||||
*/
|
||||
const char *get_printable_oid() const
|
||||
{ return iv_vb_oid.get_printable(); };
|
||||
|
||||
/**
|
||||
* Return the validity of a Vb object.
|
||||
*
|
||||
* @return TRUE if oid and value have been set.
|
||||
*/
|
||||
bool valid() const;
|
||||
|
||||
/**
|
||||
* Return the space needed for serialization.
|
||||
*
|
||||
* @return the length of the BER encoding of this Vb.
|
||||
*/
|
||||
int get_asn1_length() const;
|
||||
|
||||
//-----[ protected members ]
|
||||
protected:
|
||||
Oid iv_vb_oid; // a vb is made up of a oid
|
||||
SnmpSyntax *iv_vb_value; // and a value...
|
||||
SmiUINT32 exception_status; // are there any vb exceptions??
|
||||
|
||||
/**
|
||||
* Free the value portion.
|
||||
*/
|
||||
void free_vb();
|
||||
};
|
||||
#endif
|
BIN
backend/camembert/main
Executable file
BIN
backend/camembert/main
Executable file
Binary file not shown.
529
backend/camembert/main.cpp
Normal file
529
backend/camembert/main.cpp
Normal file
@ -0,0 +1,529 @@
|
||||
/* =================================
|
||||
|
||||
Camembert Project
|
||||
Alban FERON, 2007
|
||||
|
||||
================================== */
|
||||
|
||||
#include "camembert.h"
|
||||
|
||||
int snmp_answers, snmp_requests, snmp_dups;
|
||||
|
||||
SNMP* snmp;
|
||||
MaterielList* lstMateriel;
|
||||
|
||||
Monitor* monitor;
|
||||
|
||||
pthread_mutex_t
|
||||
mtx_materiels,
|
||||
mtx_activity,
|
||||
mtx_jobs;
|
||||
pthread_cond_t allConsumed;
|
||||
unsigned int jobsrunning = 0;
|
||||
|
||||
unsigned int maxIdMateriel;
|
||||
unsigned int maxIdInterface;
|
||||
|
||||
int tehdate;
|
||||
|
||||
void addMateriel(Materiel *const mat) {
|
||||
if(!lstMateriel)
|
||||
lstMateriel = new MaterielList(mat);
|
||||
else
|
||||
lstMateriel = lstMateriel->addMateriel(mat);
|
||||
}
|
||||
|
||||
|
||||
// Destruction des mutex et libération de la mémoire
|
||||
void free_memory() {
|
||||
pthread_mutex_destroy(&mtx_materiels);
|
||||
pthread_mutex_destroy(&mtx_jobs);
|
||||
pthread_mutex_destroy(&mtx_activity);
|
||||
pthread_cond_destroy(&allConsumed);
|
||||
|
||||
delete snmp;
|
||||
delete lstMateriel;
|
||||
delete monitor;
|
||||
}
|
||||
|
||||
void terminate(int code) {
|
||||
free_memory();
|
||||
DisconnectDB();
|
||||
exit(code);
|
||||
}
|
||||
|
||||
void init_globals() {
|
||||
// Connection à la base de données.
|
||||
if (ConnectDB() == 0) {
|
||||
printf( "!! Impossible de se connecter à la base de données\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// Création des grosse variables.
|
||||
snmp = new SNMP();
|
||||
monitor = new Monitor(MAX_JOBS);
|
||||
|
||||
lstMateriel = NULL;
|
||||
|
||||
// Mutexes pour la protection des données avec les threads
|
||||
pthread_mutex_init(&mtx_materiels, NULL);
|
||||
pthread_mutex_init(&mtx_jobs, NULL);
|
||||
pthread_mutex_init(&mtx_activity, NULL);
|
||||
pthread_cond_init(&allConsumed, NULL);
|
||||
|
||||
snmp_answers = 0;
|
||||
snmp_requests = 0;
|
||||
snmp_dups = 0;
|
||||
|
||||
tehdate = time(NULL);
|
||||
}
|
||||
|
||||
void read_db_materiel() {
|
||||
void *r, *r2;
|
||||
unsigned int i, j, n, m;
|
||||
Materiel *mat;
|
||||
IPList *ipl;
|
||||
char buffer[256];
|
||||
|
||||
// On charge tout le matériel depuis la base de données
|
||||
r = QueryDB("SELECT * FROM materiel");
|
||||
n = _PQntuples(r);
|
||||
for(i=0; i<n; i++) {
|
||||
// Avec toutes leurs IPs
|
||||
sprintf(buffer, "SELECT ip FROM ip WHERE idmateriel = %d ORDER BY main DESC, datelast DESC", atoi(_PQgetvalue(r, i, 0)));
|
||||
r2 = QueryDB(buffer);
|
||||
m = _PQntuples(r2);
|
||||
ipl = new IPList();
|
||||
for(j=0; j<m; j++)
|
||||
ipl->addIP(new IP(_PQgetvalue(r2, j, 0)), DBSTATUS_OLD);
|
||||
_PQclear(r2);
|
||||
|
||||
// Instanciation du matériel
|
||||
mat = new Materiel(atoi(_PQgetvalue(r, i, 0)), snmp, COMMUNITY, ipl);
|
||||
mat->setHostName (_PQgetvalue(r, i, 1));
|
||||
mat->setManageable (atoi(_PQgetvalue(r, i, 2)));
|
||||
mat->setVersion (atoi(_PQgetvalue(r, i, 3)));
|
||||
mat->setType (_PQgetvalue(r, i, 4));
|
||||
mat->setOSType (_PQgetvalue(r, i, 5));
|
||||
mat->setCapabilities(atoi(_PQgetvalue(r, i, 6)));
|
||||
mat->setDBstatus(DBSTATUS_OLD);
|
||||
addMateriel(mat);
|
||||
|
||||
if(mat->getManageableStatus() != STATUS_NOTMANAGEABLE)
|
||||
monitor->addJob(mat);
|
||||
}
|
||||
_PQclear(r);
|
||||
}
|
||||
|
||||
void read_db_interfaces() {
|
||||
void *r, *r2;
|
||||
unsigned int i, j, n, m, ifDbId;
|
||||
Materiel *mat;
|
||||
Interface *iface;
|
||||
char buffer[256];
|
||||
|
||||
r = QueryDB("SELECT idinterface, idmateriel, ifnumber FROM interface");
|
||||
n = _PQntuples(r);
|
||||
for(i=0; i<n; i++) {
|
||||
ifDbId = atoi(_PQgetvalue(r, i, 0));
|
||||
iface = new Interface(ifDbId, atoi(_PQgetvalue(r, i, 2)));
|
||||
|
||||
// On reprend les liens sur l'interface
|
||||
sprintf(buffer, "SELECT iddstmateriel FROM link WHERE idinterface = %d", ifDbId);
|
||||
r2 = QueryDB(buffer);
|
||||
m = _PQntuples(r2);
|
||||
iface->nbOldLinks = m;
|
||||
if(m > 0) {
|
||||
iface->oldLinks = new unsigned int[m];
|
||||
for(j=0; j<m; j++)
|
||||
iface->oldLinks[j] = atoi(_PQgetvalue(r2, j, 0));
|
||||
}
|
||||
_PQclear(r2);
|
||||
|
||||
// Actions sur l'interface
|
||||
sprintf(buffer, "SELECT numaction, option FROM action WHERE idinterface = %d", ifDbId);
|
||||
r2 = QueryDB(buffer);
|
||||
m = _PQntuples(r2);
|
||||
for(j=0; j<m; j++)
|
||||
iface->addAction(atoi(_PQgetvalue(r2, j, 0)), _PQgetvalue(r2, j, 1));
|
||||
_PQclear(r2);
|
||||
sprintf(buffer, "DELETE FROM action WHERE idinterface = %d", ifDbId);
|
||||
QueryDB(buffer);
|
||||
|
||||
// Ajout de l'interface au materiel correspondant
|
||||
mat = lstMateriel->getMaterielById(atoi(_PQgetvalue(r, i, 1)));
|
||||
if(mat)
|
||||
mat->addInterface(iface, DBSTATUS_OLD);
|
||||
}
|
||||
_PQclear(r);
|
||||
}
|
||||
|
||||
void read_db() {
|
||||
void *r;
|
||||
|
||||
read_db_materiel();
|
||||
read_db_interfaces();
|
||||
|
||||
r = QueryDB("SELECT MAX(idmateriel) FROM materiel");
|
||||
maxIdMateriel = atoi(_PQgetvalue(r, 0, 0));
|
||||
_PQclear(r);
|
||||
|
||||
r = QueryDB("SELECT MAX(idinterface) FROM interface");
|
||||
maxIdInterface = atoi(_PQgetvalue(r, 0, 0));
|
||||
_PQclear(r);
|
||||
}
|
||||
|
||||
void check_materiel() {
|
||||
if(!lstMateriel) {
|
||||
Materiel *planet = new Materiel(++maxIdMateriel, snmp, COMMUNITY, new IP(FIRST_IP));
|
||||
planet->setDBstatus(DBSTATUS_NEW);
|
||||
addMateriel(planet);
|
||||
monitor->addJob(planet);
|
||||
}
|
||||
}
|
||||
|
||||
void update_db_materiel() {
|
||||
MaterielList *ml;
|
||||
IPList *ipl;
|
||||
Materiel *m;
|
||||
char *buffer = new char[4*1024];
|
||||
int ptr;
|
||||
bool bFirst;
|
||||
|
||||
// Parcourt la liste du matériel
|
||||
for(ml=lstMateriel; ml!=NULL; ml=ml->getNext()) {
|
||||
ptr = sprintf(buffer, "BEGIN;\n");
|
||||
|
||||
m = ml->getCurrentMateriel();
|
||||
// Si il est nouveau, on l'insère
|
||||
if(m->getDBstatus() == DBSTATUS_NEW) {
|
||||
ptr += sprintf(&buffer[ptr], "INSERT INTO materiel VALUES(%d, '%s', %d, %d, '%s', '%s', %d, %d, %d);\n",
|
||||
m->getID(), m->getHostName(), m->isManageable(), m->getVersion(), m->getType(),
|
||||
m->getOSType(), m->getCapabilities(), tehdate, tehdate);
|
||||
}
|
||||
// si il n'est pas nouveau mais qu'il a été trouvé, on l'update
|
||||
else if(m->getDBstatus() == DBSTATUS_UPDATED) {
|
||||
ptr += sprintf(&buffer[ptr], "UPDATE materiel SET hostname='%s', manageable=%d, snmpversion=%d, type='%s'",
|
||||
m->getHostName(), m->isManageable(), m->getVersion(), m->getType());
|
||||
ptr += sprintf(&buffer[ptr], ", ostype='%s', capabilities=%d, datelast=%d WHERE idmateriel=%d;\n",
|
||||
m->getOSType(), m->getCapabilities(), tehdate, m->getID());
|
||||
}
|
||||
|
||||
// On fait le tour des IP pour vérifier qu'une vieille IP ne soit pas déclarée comme principale
|
||||
for(ipl=m->getIPList(); ipl!=NULL; ipl=ipl->getNext()) {
|
||||
if(ipl->getDBstatus() > DBSTATUS_OLD) {
|
||||
m->getIPList()->setFirst(ipl);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bFirst = true;
|
||||
// Parcourt la liste des IPs du matériel
|
||||
for(ipl=m->getIPList(); ipl!=NULL; ipl=ipl->getNext()) {
|
||||
if(ipl->getDBstatus() == DBSTATUS_NEW) {
|
||||
ptr += sprintf(&buffer[ptr], "INSERT INTO ip VALUES('%s', %d, '%d', %d, %d);\n", ipl->getIP()->getIPstr(),
|
||||
m->getID(), bFirst, tehdate, tehdate);
|
||||
}
|
||||
else if(ipl->getDBstatus() == DBSTATUS_UPDATED) {
|
||||
ptr += sprintf(&buffer[ptr], "UPDATE ip SET main='%d', datelast=%d WHERE ip='%s' AND idmateriel=%d;\n",
|
||||
bFirst, tehdate, ipl->getIP()->getIPstr(), m->getID());
|
||||
}
|
||||
else if(ipl->getDBstatus() == DBSTATUS_OLD && !bFirst) {
|
||||
ptr += sprintf(&buffer[ptr], "UPDATE ip SET main='f' WHERE ip='%s' AND idmateriel='%d';\n",
|
||||
ipl->getIP()->getIPstr(), m->getID());
|
||||
}
|
||||
bFirst = false;
|
||||
}
|
||||
|
||||
ptr += sprintf(&buffer[ptr], "END;\n");
|
||||
QueryDB(buffer);
|
||||
}
|
||||
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
void update_db_interfaces() {
|
||||
MaterielList *ml;
|
||||
Materiel *m;
|
||||
InterfaceList *ifl;
|
||||
Interface *i;
|
||||
char *buffer = new char[1024*1024];
|
||||
int ptr;
|
||||
char macaddr[24], descr[256], tmpdescr[256], lastsrc[24];
|
||||
unsigned short int n;
|
||||
unsigned int idLink;
|
||||
bool bOldLink;
|
||||
dstDevice_t* dd;
|
||||
|
||||
for(ml=lstMateriel; ml!=NULL; ml=ml->getNext()) {
|
||||
m = ml->getCurrentMateriel();
|
||||
ifl = m->getInterfaces();
|
||||
if(!ifl)
|
||||
continue;
|
||||
|
||||
ptr = sprintf(buffer, "BEGIN;\n");
|
||||
for(; ifl!=NULL; ifl=ifl->getNext()) {
|
||||
i = ifl->getInterface();
|
||||
|
||||
if(strlen(i->getAddress()) == 0)
|
||||
strcpy(macaddr, "NULL");
|
||||
else
|
||||
sprintf(macaddr, "'%s'", i->getAddress());
|
||||
|
||||
if(!i->getDescription())
|
||||
strcpy(descr, "NULL");
|
||||
else {
|
||||
sprintf(descr, "'%s'", i->getDescription());
|
||||
//_PQescapeString(tmpdescr, i->getDescription());
|
||||
//sprintf(descr, "'%s'", tmpdescr);
|
||||
}
|
||||
|
||||
if(strlen(i->getLastMacAddr()) == 0)
|
||||
strcpy(lastsrc, "NULL");
|
||||
else
|
||||
sprintf(lastsrc, "'%s'", i->getLastMacAddr());
|
||||
|
||||
if(ifl->getDBstatus() == DBSTATUS_NEW) {
|
||||
ptr += sprintf(&buffer[ptr], "INSERT INTO interface VALUES(%d, %d, %d, '%s', %s, %s, %d, '%d', '%d', %d, %d, %d, %d, %d, %d, %d, '%d', '%d', %d, %d, %d, %d, %s, '%d');\n",
|
||||
i->getID(), m->getID(), i->getIfNumber(), i->getName(), descr,
|
||||
macaddr, i->speed, i->adminStatus, i->operStatus, i->ifType, i->vlan, i->voiceVlan, i->nativeVlan,
|
||||
i->moduleNum, i->portNum, i->portDot1d, i->spanningTree, i->portSecEnabled, i->portSecStatus,
|
||||
i->maxMacCount, i->currMacCount, i->violationCount, lastsrc, i->stickyEnabled);
|
||||
}
|
||||
else if(ifl->getDBstatus() == DBSTATUS_UPDATED) {
|
||||
ptr += sprintf(&buffer[ptr], "UPDATE interface SET ifname='%s', ifdescription=%s, ifaddress=%s, ifspeed=%d, ifadminstatus='%d', ",
|
||||
i->getName(), descr, macaddr, i->speed, i->adminStatus);
|
||||
ptr += sprintf(&buffer[ptr], "ifoperstatus='%d', iftype=%d, ifvlan=%d, ifvoicevlan=%d, ifnativevlan=%d, ifmodule=%d, ifport=%d, ",
|
||||
i->operStatus, i->ifType, i->vlan, i->voiceVlan, i->nativeVlan, i->moduleNum, i->portNum);
|
||||
ptr += sprintf(&buffer[ptr], "portdot1d=%d, portfast='%d', portsecenable='%d', portsecstatus=%d, portsecmaxmac=%d, ",
|
||||
i->portDot1d, i->spanningTree, i->portSecEnabled, i->portSecStatus, i->maxMacCount);
|
||||
ptr += sprintf(&buffer[ptr], "portseccurrmac=%d, portsecviolation=%d, portseclastsrcaddr=%s, portsecsticky='%d' WHERE idinterface=%d;\n",
|
||||
i->currMacCount, i->violationCount, lastsrc, i->stickyEnabled, i->getID());
|
||||
}
|
||||
|
||||
dd = i->getDistantDevice();
|
||||
while(dd) {
|
||||
bOldLink = false;
|
||||
idLink = ((Materiel*)dd->distantDevice)->getID();
|
||||
for(n=0; n<i->nbOldLinks; n++) {
|
||||
if(idLink == i->oldLinks[n]) {
|
||||
ptr += sprintf(&buffer[ptr], "UPDATE link SET dstifname='%s', datelast=%d WHERE idinterface=%d AND iddstmateriel=%d;\n",
|
||||
dd->dstIfName, tehdate, i->getID(), idLink);
|
||||
bOldLink = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!bOldLink)
|
||||
ptr += sprintf(&buffer[ptr], "INSERT INTO link VALUES(%d, %d, '%s', %d, %d);\n", i->getID(),
|
||||
idLink, dd->dstIfName, tehdate, tehdate);
|
||||
|
||||
dd = dd->next;
|
||||
}
|
||||
}
|
||||
|
||||
ptr += sprintf(&buffer[ptr], "END;\n");
|
||||
QueryDB(buffer);
|
||||
}
|
||||
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
void update_db_arp() {
|
||||
MaterielList *ml;
|
||||
Materiel *m;
|
||||
ARPCache *arp;
|
||||
char *buffer = new char[2*1024*1024];
|
||||
int ptr;
|
||||
|
||||
sprintf(buffer, "CREATE TABLE arp_%d (mac macaddr, ip inet)", tehdate);
|
||||
QueryDB(buffer);
|
||||
|
||||
for(ml=lstMateriel; ml!=NULL; ml=ml->getNext()) {
|
||||
m = ml->getCurrentMateriel();
|
||||
arp = m->getARPCache();
|
||||
|
||||
if(!arp)
|
||||
continue;
|
||||
|
||||
ptr = sprintf(buffer, "BEGIN;\n");
|
||||
for(; arp!=NULL; arp=arp->getNext())
|
||||
ptr += sprintf(&buffer[ptr], "INSERT INTO arp_%d VALUES('%s', '%s');\n", tehdate, arp->getMAC(), arp->getIP()->getIPstr());
|
||||
|
||||
ptr += sprintf(&buffer[ptr], "UPDATE arpcache SET datelast=%d, foundon=%d WHERE (mac, ip) IN (SELECT mac, ip FROM arp_%d);\n",
|
||||
tehdate, m->getID(), tehdate);
|
||||
ptr += sprintf(&buffer[ptr], "INSERT INTO arpcache SELECT mac, ip, %d, %d, %d FROM arp_%d WHERE (mac, ip) NOT IN (SELECT mac, ip FROM arpcache);\n",
|
||||
m->getID(), tehdate, tehdate, tehdate);
|
||||
ptr += sprintf(&buffer[ptr], "DELETE FROM arp_%d; END;\n", tehdate);
|
||||
QueryDB(buffer);
|
||||
}
|
||||
|
||||
sprintf(buffer, "DROP TABLE arp_%d", tehdate);
|
||||
QueryDB(buffer);
|
||||
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
void update_db_fdb() {
|
||||
MaterielList *ml;
|
||||
InterfaceList *ifl;
|
||||
Interface *i;
|
||||
ForwardingDatabase *fdb;
|
||||
char *buffer = new char[1024*1024];
|
||||
int ptr;
|
||||
|
||||
sprintf(buffer, "CREATE TABLE fdb_%d (idinterface integer, vlan integer, mac macaddr, type integer)", tehdate);
|
||||
QueryDB(buffer);
|
||||
|
||||
for(ml=lstMateriel; ml!=NULL; ml=ml->getNext()) {
|
||||
ifl = ml->getCurrentMateriel()->getInterfaces();
|
||||
|
||||
ptr = sprintf(buffer, "BEGIN;\n");
|
||||
|
||||
for(; ifl!=NULL; ifl=ifl->getNext()) {
|
||||
i = ifl->getInterface();
|
||||
fdb = i->getForwardingDB();
|
||||
if(!fdb)
|
||||
continue;
|
||||
|
||||
for(; fdb!=NULL; fdb=fdb->getNext())
|
||||
ptr += sprintf(&buffer[ptr], "INSERT INTO fdb_%d VALUES(%d, %d, '%s', %d);\n", tehdate, i->getID(), fdb->getVLAN(), fdb->getMAC(), fdb->getType());
|
||||
|
||||
}
|
||||
|
||||
ptr += sprintf(&buffer[ptr], "UPDATE fdb SET datelast=%d WHERE (idinterface, vlan, mac, type) IN (SELECT * FROM fdb_%d);\n",
|
||||
tehdate, tehdate);
|
||||
ptr += sprintf(&buffer[ptr], "INSERT INTO fdb SELECT idinterface, vlan, mac, %d, %d, type FROM fdb_%d WHERE (idinterface, vlan, mac, type) NOT IN (SELECT idinterface, vlan, mac, type FROM fdb);\n",
|
||||
tehdate, tehdate, tehdate);
|
||||
|
||||
ptr += sprintf(&buffer[ptr], "DELETE FROM fdb_%d; END;\n", tehdate);
|
||||
QueryDB(buffer);
|
||||
}
|
||||
|
||||
sprintf(buffer, "DROP TABLE fdb_%d", tehdate);
|
||||
QueryDB(buffer);
|
||||
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
void update_db() {
|
||||
update_db_materiel();
|
||||
update_db_interfaces();
|
||||
update_db_arp();
|
||||
update_db_fdb();
|
||||
}
|
||||
|
||||
void analyseMateriel(Materiel *mat) {
|
||||
// Si on l'a déjà analysé, on zappe.
|
||||
if(mat->isTreated())
|
||||
return;
|
||||
|
||||
mat->setTreated(true);
|
||||
|
||||
// Manageable ?
|
||||
if(mat->snmpcheck()) {
|
||||
mat->setManageable(MAT_IS_MANAGEABLE);
|
||||
mat->setDBstatus(DBSTATUS_UPDATED);
|
||||
|
||||
// Ouverture de connexion
|
||||
mat->snmpopen();
|
||||
|
||||
mat->retrieveInfos();
|
||||
apply_actions(mat);
|
||||
get_interfaces_infos(mat);
|
||||
get_arp_infos(mat);
|
||||
get_fdb_infos(mat);
|
||||
look_for_neighbours(mat);
|
||||
|
||||
// Fermeture de la connexion
|
||||
mat->snmpclose();
|
||||
}
|
||||
else if(mat->isManageable() != MAT_NOT_MANAGEABLE)
|
||||
mat->setManageable(MAT_WAS_MANAGEABLE);
|
||||
else
|
||||
mat->setManageable(MAT_NOT_MANAGEABLE);
|
||||
}
|
||||
|
||||
// Thread d'analyse du réseau
|
||||
void* camembert_thread(void*) {
|
||||
Materiel *m;
|
||||
|
||||
while(true) {
|
||||
m = (Materiel *)monitor->getJob();
|
||||
|
||||
pthread_mutex_lock(&mtx_jobs);
|
||||
++jobsrunning;
|
||||
pthread_mutex_unlock(&mtx_jobs);
|
||||
|
||||
if (!m->isTreated())
|
||||
analyseMateriel(m);
|
||||
|
||||
pthread_mutex_lock(&mtx_jobs);
|
||||
if (!(--jobsrunning) && !monitor->isJobPending())
|
||||
pthread_cond_signal(&allConsumed);
|
||||
|
||||
pthread_mutex_unlock(&mtx_jobs);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Attend que le monitor soit vide, donc qu'il n'y ait plus de matériel à analyser
|
||||
void wait_end_of_jobs() {
|
||||
#if THREADED
|
||||
pthread_mutex_lock(&mtx_activity);
|
||||
pthread_cond_wait(&allConsumed, &mtx_activity);
|
||||
pthread_mutex_unlock(&mtx_activity);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Crée les threads d'analyse du réseau.
|
||||
void create_threads() {
|
||||
#if THREADED
|
||||
pthread_t p;
|
||||
|
||||
for(unsigned int i=0; i<MAX_THREADS; i++) {
|
||||
if(pthread_create(&p, NULL, camembert_thread, NULL) != 0) {
|
||||
fprintf(stderr, "Erreur de création des threads. (%d)\n", i);
|
||||
terminate(1);
|
||||
}
|
||||
}
|
||||
#else
|
||||
Materiel *m;
|
||||
while(monitor->isJobPending()) {
|
||||
m = (Materiel *)monitor->getJob();
|
||||
if(!m->isTreated())
|
||||
analyseMateriel(m);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Parcourt la liste du matériel à la recherche du matériel qui n'a pas été analysé
|
||||
// Et l'analyse le cas échéant (peu probable que ça se produise anyway vu comment mon appli est construite)
|
||||
void check_untreated() {
|
||||
unsigned int untreated = 0;
|
||||
Materiel *m;
|
||||
|
||||
for(MaterielList *lst=lstMateriel; lst!=NULL; lst=lst->getNext()) {
|
||||
m = lst->getCurrentMateriel();
|
||||
if(!m->isTreated()) {
|
||||
printf("%s not treated\n", m->getHostName());
|
||||
monitor->addJob((void*)m);
|
||||
untreated++;
|
||||
}
|
||||
}
|
||||
|
||||
if(untreated)
|
||||
wait_end_of_jobs();
|
||||
}
|
||||
|
||||
// Programme principal
|
||||
int main(int argc, char* argv[]) {
|
||||
init_globals();
|
||||
read_db();
|
||||
check_materiel();
|
||||
create_threads();
|
||||
wait_end_of_jobs();
|
||||
check_untreated();
|
||||
update_db();
|
||||
terminate(0);
|
||||
}
|
BIN
backend/camembert/main.o
Normal file
BIN
backend/camembert/main.o
Normal file
Binary file not shown.
260
backend/camembert/materiel.cpp
Normal file
260
backend/camembert/materiel.cpp
Normal file
@ -0,0 +1,260 @@
|
||||
/* =========================================
|
||||
|
||||
Camembert Project
|
||||
Alban FERON, 2007
|
||||
|
||||
Représentation d'un équipement matériel et
|
||||
liste de matériel.
|
||||
|
||||
========================================== */
|
||||
|
||||
#include "materiel.h"
|
||||
|
||||
Oid OID_Hostname("1.3.6.1.2.1.1.5.0");
|
||||
Oid OID_OSType ("1.3.6.1.2.1.1.1.0");
|
||||
|
||||
// ---------------------------
|
||||
// Materiel::Constructeurs
|
||||
// ---------------------------
|
||||
|
||||
Materiel::Materiel(unsigned int id, SNMP *snmp, const char* community, IP* ip):
|
||||
SNMPObject(snmp, community, ip)
|
||||
{
|
||||
_id = id;
|
||||
_type = NULL;
|
||||
_name = NULL;
|
||||
_osType = NULL;
|
||||
_capabilities = 0;
|
||||
bTreated = false;
|
||||
_dbStatus = DBSTATUS_UNKNOWN;
|
||||
_manageable = 0;
|
||||
_ifs = NULL;
|
||||
_arp = NULL;
|
||||
}
|
||||
|
||||
Materiel::Materiel(unsigned int id, SNMP *snmp, const char* community, IPList* lip):
|
||||
SNMPObject(snmp, community, lip)
|
||||
{
|
||||
_id = id;
|
||||
_type = NULL;
|
||||
_name = NULL;
|
||||
_osType = NULL;
|
||||
_capabilities = 0;
|
||||
bTreated = false;
|
||||
_dbStatus = DBSTATUS_UNKNOWN;
|
||||
_manageable = 0;
|
||||
_ifs = NULL;
|
||||
_arp = NULL;
|
||||
}
|
||||
|
||||
// ----------------------------
|
||||
// Materiel::Destructeur
|
||||
// ----------------------------
|
||||
|
||||
Materiel::~Materiel() {
|
||||
if(_name)
|
||||
delete[] _name;
|
||||
if(_type)
|
||||
delete[] _type;
|
||||
if(_osType)
|
||||
delete[] _osType;
|
||||
if(_ifs)
|
||||
delete _ifs;
|
||||
if(_arp)
|
||||
delete _arp;
|
||||
}
|
||||
|
||||
// --------------------------------
|
||||
// Materiel::Setters
|
||||
// --------------------------------
|
||||
|
||||
void Materiel::setHostName(const char* name) {
|
||||
// Si il a déjà un nom, on le vire
|
||||
if(_name)
|
||||
delete[] _name;
|
||||
// On affecte le nom
|
||||
_name = new char[strlen(name)+1];
|
||||
strcpy(_name, name);
|
||||
}
|
||||
|
||||
void Materiel::setType(const char* type) {
|
||||
if(_type)
|
||||
delete[] _type;
|
||||
_type = new char[strlen(type)+1];
|
||||
strcpy(_type, type);
|
||||
}
|
||||
|
||||
void Materiel::setOSType(const char* os) {
|
||||
if(_osType)
|
||||
delete[] _osType;
|
||||
_osType = new char[strlen(os)+1];
|
||||
strcpy(_osType, os);
|
||||
|
||||
char *c;
|
||||
// Remplace les apostrophes par des espaces sinon ça va bugger lors des modifs de la BDD
|
||||
while(c = strchr(_osType, '\''))
|
||||
*c = ' ';
|
||||
}
|
||||
|
||||
void Materiel::setCapabilities(unsigned int capabilities) {
|
||||
_capabilities = capabilities;
|
||||
|
||||
// Si c'est un téléphone, on dit qu'il a été traité car
|
||||
// de toutes façons il est pas manageable
|
||||
if(capabilities & CAPABILITY_PHONE) {
|
||||
status = STATUS_NOTMANAGEABLE;
|
||||
_manageable = MAT_NOT_MANAGEABLE;
|
||||
setTreated(true);
|
||||
}
|
||||
}
|
||||
|
||||
void Materiel::addInterface(Interface *i, unsigned int dbStatus) {
|
||||
if(!_ifs)
|
||||
_ifs = new InterfaceList(i, dbStatus);
|
||||
else
|
||||
_ifs->addInterface(i, dbStatus);
|
||||
}
|
||||
|
||||
Interface *Materiel::getInterfaceById(unsigned int id) const {
|
||||
if(!_ifs)
|
||||
return NULL;
|
||||
return _ifs->getInterfaceById(id);
|
||||
}
|
||||
|
||||
Interface *Materiel::getInterfaceByDot1d(unsigned int id) const {
|
||||
if(!_ifs)
|
||||
return NULL;
|
||||
return _ifs->getInterfaceByDot1d(id);
|
||||
}
|
||||
|
||||
Interface *Materiel::getInterfaceByPort(unsigned int module, unsigned int port) const {
|
||||
if(!_ifs)
|
||||
return NULL;
|
||||
return _ifs->getInterfaceByPort(module, port);
|
||||
}
|
||||
|
||||
Interface *Materiel::getInterfaceByPortDot1d(unsigned int id) const {
|
||||
if(!_ifs)
|
||||
return NULL;
|
||||
return _ifs->getInterfaceByPortDot1d(id);
|
||||
}
|
||||
|
||||
/*Interface *Materiel::getInterafceByDBId(unsigned int dbId) const {
|
||||
if(!_ifs)
|
||||
return NULL;
|
||||
return _ifs->getInterfaceByDBId(dbId);
|
||||
} */
|
||||
|
||||
void Materiel::retrieveInfos() {
|
||||
const SNMPResult *r;
|
||||
|
||||
// Si il a pas de nom, on va le récupérer
|
||||
if(!_name) {
|
||||
r = this->snmpget(&OID_Hostname);
|
||||
if(r) {
|
||||
this->setHostName(r->get_printable_value());
|
||||
delete r;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Materiel::addARPEntry(const char *mac, const char *ip) {
|
||||
if(!_arp)
|
||||
_arp = new ARPCache(mac, ip);
|
||||
else
|
||||
_arp->addEntry(mac, ip);
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
// MaterielList::Constructeurs
|
||||
// -----------------------------
|
||||
|
||||
MaterielList::MaterielList(Materiel *const mat) {
|
||||
_mat = mat;
|
||||
_next = NULL;
|
||||
}
|
||||
|
||||
MaterielList::MaterielList(Materiel *const mat, MaterielList *next) {
|
||||
_mat = mat;
|
||||
_next = next;
|
||||
}
|
||||
|
||||
// ------------------------------
|
||||
// MaterielList::Destructeur
|
||||
// ------------------------------
|
||||
|
||||
MaterielList::~MaterielList() {
|
||||
if(_mat)
|
||||
delete _mat;
|
||||
if(_next)
|
||||
delete _next;
|
||||
}
|
||||
|
||||
MaterielList *MaterielList::addMateriel(Materiel *const mat) {
|
||||
return new MaterielList(mat, this);
|
||||
}
|
||||
|
||||
Materiel *MaterielList::getMaterielById(unsigned int id) const {
|
||||
const MaterielList *l;
|
||||
Materiel *m;
|
||||
|
||||
for(l=this; l!=NULL; l=l->getNext()) {
|
||||
m = l->getCurrentMateriel();
|
||||
if(m->getID() == id)
|
||||
return m;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Materiel *MaterielList::getMaterielByHostname(const char *hostname, const char *type, const char *ostype) const {
|
||||
const MaterielList *l;
|
||||
Materiel *m;
|
||||
char *c;
|
||||
|
||||
// Parcourt la liste du matos
|
||||
for(l=this; l!=NULL; l=l->getNext()) {
|
||||
m = l->getCurrentMateriel();
|
||||
// Si il a le même nom...
|
||||
if(!strcmp(m->getHostName(), hostname)) {
|
||||
// Si le nom commence par SEP, on retourne le matériel, pas besoin de faire d'autres vérifications
|
||||
// vu que pour les SEP, le nom est unique.
|
||||
if((c = strstr((char *)m->getHostName(), "SEP")) && (c - m->getHostName() == 0))
|
||||
return m;
|
||||
// Sinon on vérifie le type et l'OS (s'ils sont définis)
|
||||
if((type[0] == 0 || !m->getType() || !strcmp(m->getType(), type)) &&
|
||||
(ostype[0] == 0 || !m->getOSType() || !strcmp(m->getOSType(), ostype)))
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Materiel *MaterielList::getMaterielByIP(const IP* ip, const char *type, const char *ostype) const {
|
||||
const MaterielList *l;
|
||||
Materiel *m;
|
||||
|
||||
// Parcourt la liste du matos
|
||||
for(l=this; l!=NULL; l=l->getNext()) {
|
||||
m = l->getCurrentMateriel();
|
||||
// Si le matos a l'IP passée et que le type et l'os correspondent, on retourne le matos.
|
||||
if(m->getIPList()->isIPinList(ip) &&
|
||||
(type[0] == 0 || !m->getType() || !strcmp(m->getType(), type)) &&
|
||||
(ostype[0] == 0 || !m->getOSType() || !strcmp(m->getOSType(), ostype)))
|
||||
return m;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Materiel *MaterielList::getMaterielByHostnameAndIP(const char *hostname, const IP *ip) const {
|
||||
const MaterielList *l;
|
||||
Materiel *m;
|
||||
|
||||
for(l=this; l!=NULL; l=l->getNext()) {
|
||||
m = l->getCurrentMateriel();
|
||||
if(!strcmp(m->getHostName(), hostname) && m->getIPList()->isIPinList(ip))
|
||||
return m;
|
||||
}
|
||||
return NULL;
|
||||
}
|
246
backend/camembert/materiel.h
Normal file
246
backend/camembert/materiel.h
Normal file
@ -0,0 +1,246 @@
|
||||
/* =========================================
|
||||
|
||||
Camembert Project
|
||||
Alban FERON, 2007
|
||||
|
||||
Représentation d'un équipement matériel et
|
||||
liste de matériel.
|
||||
|
||||
========================================== */
|
||||
|
||||
#ifndef __CAMEMBERT_MATERIEL_H
|
||||
#define __CAMEMBERT_MATERIEL_H
|
||||
|
||||
#include "snmpobject.h"
|
||||
#include "pgdb.h"
|
||||
#include "arp.h"
|
||||
#include "interface.h"
|
||||
|
||||
/* See http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/frames.htm#18843
|
||||
for more informations */
|
||||
#define CAPABILITY_LVL3_ROUTING 0x01
|
||||
#define CAPABILITY_LVL2_TRANSPARENT_BRIDGE 0x02
|
||||
#define CAPABILITY_LVL2_SRC_ROUTE_BRIDGING 0x04
|
||||
#define CAPABILITY_LVL2_SWITCHING 0x08
|
||||
#define CAPABILITY_SEND_RECIEVE_PACKETS 0x10
|
||||
#define CAPABILITY_IGMP_NONFORWARDING 0x20
|
||||
#define CAPABILITY_LVL1_FUNCTIONALITY 0x40
|
||||
#define CAPABILITY_PHONE 0x80
|
||||
|
||||
#define MAT_NOT_MANAGEABLE 0
|
||||
#define MAT_IS_MANAGEABLE 1
|
||||
#define MAT_WAS_MANAGEABLE 2
|
||||
|
||||
/**
|
||||
* Représentation d'un équipement matériel
|
||||
* Permet d'avoir accès au nom, type et capabilities du matériel
|
||||
*/
|
||||
class Materiel: public SNMPObject, public DBObject {
|
||||
private:
|
||||
unsigned int _id;
|
||||
char *_name; /* Hostname du matos */
|
||||
char *_type; /* Type */
|
||||
char *_osType;
|
||||
unsigned int _capabilities; /* Capabilities récupérées via CDP */
|
||||
bool bTreated; /* Si on a déjà fait l'analyse à partir de ce materiel */
|
||||
unsigned int _manageable;
|
||||
InterfaceList *_ifs;
|
||||
ARPCache *_arp;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructeur
|
||||
*
|
||||
* @param id - ID du matos dans la base de données
|
||||
* @param snmp - Pointeur vers une instance de class SNMP pour effectuer les requêtes
|
||||
* @param community - Communauté SNMP à utiliser lors des connexions
|
||||
* @param ip - IP principale du matériel
|
||||
*/
|
||||
Materiel(unsigned int id, SNMP *snmp, const char* community, IP* ip);
|
||||
|
||||
/**
|
||||
* Constructeur
|
||||
*
|
||||
* @param id - ID du matos dans la base de données
|
||||
* @param snmp - Pointeur vers une instance de class SNMP pour effectuer les requêtes
|
||||
* @param community - Communauté SNMP à utiliser lors des connexions
|
||||
* @param lip - Pointeur sur une liste d'IP du matériel
|
||||
*/
|
||||
Materiel(unsigned int id, SNMP *snmp, const char* community, IPList* lip);
|
||||
|
||||
/**
|
||||
* Destructeur
|
||||
* Fait les libérations de mémoire nécéssaires
|
||||
*/
|
||||
~Materiel();
|
||||
|
||||
/**
|
||||
* Récupère les infos de base (tel que le nom) si elles ne sont pas initialisées
|
||||
*/
|
||||
void retrieveInfos();
|
||||
|
||||
void setManageable(unsigned int manageable) { _manageable = manageable; }
|
||||
unsigned int isManageable() const { return _manageable; }
|
||||
void setVersion(int v) { version = v; }
|
||||
|
||||
/**
|
||||
* Change le type du matériel
|
||||
*/
|
||||
void setType(const char *type);
|
||||
|
||||
/**
|
||||
* Change le nom du matériel
|
||||
*/
|
||||
void setHostName(const char *name);
|
||||
|
||||
/**
|
||||
* Change la description de l'OS
|
||||
*/
|
||||
void setOSType(const char *os);
|
||||
|
||||
/**
|
||||
* Change les capabilities
|
||||
*
|
||||
* @param capabilities - Masque des capabilities à affecter
|
||||
* @note Si les capabilities spécifient que c'est un téléphone, le matériel est déclaré
|
||||
* non manageable
|
||||
* @see http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/frames.htm#18843
|
||||
*/
|
||||
void setCapabilities(const unsigned int capabilities);
|
||||
|
||||
/**
|
||||
* Définit si le matériel a été analysé ou non
|
||||
*/
|
||||
void setTreated(const bool treated) { bTreated = treated; }
|
||||
|
||||
void addInterface(Interface *i, unsigned int dbStatus);
|
||||
|
||||
unsigned int getID() const { return _id; }
|
||||
|
||||
/**
|
||||
* Récupère le nom
|
||||
*
|
||||
* @return Le nom du matériel
|
||||
*/
|
||||
const char *getHostName() const { return _name; }
|
||||
|
||||
/**
|
||||
* Récupère le type
|
||||
*
|
||||
* @return Le type du matériel
|
||||
*/
|
||||
const char *getType() const { return _type; }
|
||||
|
||||
/**
|
||||
* Récupère l'OS
|
||||
*/
|
||||
const char *getOSType() const { return _osType; }
|
||||
|
||||
/**
|
||||
* Récupère les capabilities
|
||||
*
|
||||
* @return Le masque de capabilities du matériel
|
||||
* @see http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/frames.htm#18843
|
||||
*/
|
||||
const unsigned int getCapabilities() const { return _capabilities; }
|
||||
|
||||
/**
|
||||
* @return VRAI si le matériel a été traité.
|
||||
*/
|
||||
const bool isTreated() const { return bTreated; }
|
||||
|
||||
InterfaceList *getInterfaces() const { return _ifs; }
|
||||
Interface *getInterfaceById(unsigned int id) const;
|
||||
Interface *getInterfaceByDot1d(unsigned int id) const;
|
||||
Interface *getInterfaceByPort(unsigned int module, unsigned int port) const;
|
||||
Interface *getInterfaceByPortDot1d(unsigned int id) const;
|
||||
//Interface *getInterfaceByDBId(unsigned int dbId) const;
|
||||
|
||||
void addARPEntry(const char *mac, const char *ip);
|
||||
ARPCache *getARPCache() const { return _arp; }
|
||||
};
|
||||
|
||||
/**
|
||||
* Liste de matériel
|
||||
*/
|
||||
class MaterielList {
|
||||
private:
|
||||
MaterielList *_next; /* Sous liste permettant d'acceder au matériels suivants */
|
||||
Materiel *_mat; /* Matériel courant */
|
||||
|
||||
public:
|
||||
/**
|
||||
* Crée une liste avec un unique matériel
|
||||
*
|
||||
* @param mat - Pointeur sur le matériel à mettre dans la liste
|
||||
*/
|
||||
MaterielList(Materiel *const mat);
|
||||
|
||||
/**
|
||||
* Crée une liste avec un ancienne liste et un matériel à lui ajouter
|
||||
*
|
||||
* @param mat - Materiel à ajouter
|
||||
* @param next - Ancienne liste utilisée pour déterminer les matériels suivants
|
||||
*/
|
||||
MaterielList(Materiel *const mat, MaterielList *next);
|
||||
|
||||
/**
|
||||
* Libère la mémoire
|
||||
*
|
||||
* @note Détruit aussi le matériel pointé
|
||||
*/
|
||||
~MaterielList();
|
||||
|
||||
/**
|
||||
* Ajoute un nouveau matériel au début de la liste
|
||||
*
|
||||
* @param mat - Materiel à ajouter
|
||||
* @return une nouvelle liste contenant le nouveau matériel et ceux présent
|
||||
* dans la liste actuelle
|
||||
* @note Ne modifie pas la liste actuelle
|
||||
*/
|
||||
MaterielList *addMateriel(Materiel *const mat);
|
||||
|
||||
/**
|
||||
* @return Sous liste pour avoir les matériels suivant
|
||||
*/
|
||||
MaterielList *getNext() const { return _next; }
|
||||
|
||||
/**
|
||||
* @return Matériel actuellement pointé par la liste
|
||||
*/
|
||||
Materiel *getCurrentMateriel() const { return _mat; }
|
||||
|
||||
Materiel *getMaterielById(unsigned int id) const;
|
||||
|
||||
/**
|
||||
* Cherche un matériel dans la liste à partir d'un nom donné
|
||||
*
|
||||
* @param hostname - Nom du matériel à chercher
|
||||
* @param type -
|
||||
* @param ostype -
|
||||
* @return Le matériel dont le nom correspond à 'hostname'
|
||||
*/
|
||||
Materiel *getMaterielByHostname(const char *hostname, const char *type, const char *ostype) const;
|
||||
|
||||
/**
|
||||
* Cherche un matériel dans la liste à partir d'une IP donnée
|
||||
*
|
||||
* @param ip - L'IP du matériel à chercher
|
||||
* @param type -
|
||||
* @param ostype -
|
||||
* @return Le matériel ayant l'IP 'ip'
|
||||
*/
|
||||
Materiel *getMaterielByIP(const IP* ip, const char *type, const char *ostype) const;
|
||||
|
||||
/**
|
||||
* Cherche un materiel dans la liste à partir d'un nom et d'une IP donnés
|
||||
*
|
||||
* @param hostname - Nom du matériel à chercher
|
||||
* @param ip - IP du matériel à chercher
|
||||
* @return Le matériel ayant le nom 'hostname' et l'IP 'ip'
|
||||
*/
|
||||
Materiel *getMaterielByHostnameAndIP(const char *hostname, const IP *ip) const;
|
||||
};
|
||||
|
||||
#endif /* __CAMEMBERT_MATERIEL_H */
|
BIN
backend/camembert/materiel.o
Normal file
BIN
backend/camembert/materiel.o
Normal file
Binary file not shown.
100
backend/camembert/monitor.cpp
Normal file
100
backend/camembert/monitor.cpp
Normal file
@ -0,0 +1,100 @@
|
||||
/* =================================================
|
||||
|
||||
Camembert Project
|
||||
Alban FERON, 2007
|
||||
|
||||
Monitor class.
|
||||
Entièrement repris de Kindmana, par Aurélien Méré
|
||||
(avec quelques commentaires en plus)
|
||||
|
||||
================================================== */
|
||||
|
||||
#include <pthread.h>
|
||||
#include "monitor.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
Monitor::Monitor(unsigned int const maxjobs) {
|
||||
want_to_consume = 0;
|
||||
want_to_produce = 0;
|
||||
firstjob = 0;
|
||||
nextjob =0;
|
||||
this->maxjobs = maxjobs;
|
||||
jobs = (void **)malloc(sizeof(void*)*maxjobs);
|
||||
|
||||
pthread_mutex_init(&mutex, NULL);
|
||||
pthread_cond_init(&can_produce, NULL);
|
||||
pthread_cond_init(&can_consume, NULL);
|
||||
}
|
||||
|
||||
Monitor::~Monitor() {
|
||||
pthread_mutex_destroy(&mutex);
|
||||
pthread_cond_destroy(&can_produce);
|
||||
pthread_cond_destroy(&can_consume);
|
||||
free(jobs);
|
||||
}
|
||||
|
||||
void Monitor::addJob(void * const job) {
|
||||
pthread_mutex_lock(&mutex);
|
||||
|
||||
// Tant que le monitor est "plein"
|
||||
while (((nextjob + 1) % maxjobs) == firstjob) {
|
||||
// On dit qu'on veut ajouter un job
|
||||
++want_to_produce;
|
||||
// Et on attend qu'une place se libère
|
||||
pthread_cond_wait(&can_produce, &mutex);
|
||||
--want_to_produce;
|
||||
}
|
||||
|
||||
// On ajoute le job
|
||||
jobs[nextjob++] = job;
|
||||
nextjob %= maxjobs;
|
||||
|
||||
// Si un thread attend pour ajouter un job et qu'il y a de la place,
|
||||
// on le signale pour qu'il se réveille.
|
||||
if (want_to_produce && (((nextjob + 1) % maxjobs) != firstjob))
|
||||
pthread_cond_signal(&can_produce);
|
||||
|
||||
// Si un thread attend pour "lire" un job, comme on vient d'en ajouter un
|
||||
// on lui dit qu'il peut lire.
|
||||
if (want_to_consume)
|
||||
pthread_cond_signal(&can_consume);
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
}
|
||||
|
||||
void * const Monitor::getJob() {
|
||||
void *res;
|
||||
|
||||
pthread_mutex_lock(&mutex);
|
||||
|
||||
// Tant que ya rien à lire
|
||||
while (firstjob == nextjob) {
|
||||
// On dit qu'on veut lire
|
||||
++want_to_consume;
|
||||
// Et on attend qu'il y ait quelque chose à lire
|
||||
pthread_cond_wait(&can_consume, &mutex);
|
||||
--want_to_consume;
|
||||
}
|
||||
|
||||
// On prend le job pour le retourner
|
||||
res = jobs[firstjob++];
|
||||
firstjob %= maxjobs;
|
||||
|
||||
// Si un thread attend d'ajouter un job, comme on vient d'en "supprimer" un,
|
||||
// on lui dit qu'il peut l'ajouter
|
||||
if (want_to_produce)
|
||||
pthread_cond_signal(&can_produce);
|
||||
|
||||
// Si un thread veut lire et qu'il y a encore des trucs à lire, on lui dit.
|
||||
if ((firstjob != nextjob) && want_to_consume)
|
||||
pthread_cond_signal(&can_consume);
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
return res;
|
||||
}
|
||||
|
||||
bool const Monitor::isJobPending() const {
|
||||
return (firstjob != nextjob);
|
||||
}
|
||||
|
35
backend/camembert/monitor.h
Normal file
35
backend/camembert/monitor.h
Normal file
@ -0,0 +1,35 @@
|
||||
/* =================================================
|
||||
|
||||
Camembert Project
|
||||
Alban FERON, 2007
|
||||
|
||||
Monitor class.
|
||||
Entièrement repris de Kindmana, par Aurélien Méré
|
||||
|
||||
================================================== */
|
||||
|
||||
#ifndef __CAMEMBERT_MONITOR_H
|
||||
#define __CAMEMBERT_MONITOR_H
|
||||
|
||||
class Monitor
|
||||
{
|
||||
private:
|
||||
pthread_mutex_t mutex;
|
||||
pthread_cond_t can_produce;
|
||||
pthread_cond_t can_consume;
|
||||
unsigned int want_to_consume;
|
||||
unsigned int want_to_produce;
|
||||
unsigned int firstjob;
|
||||
unsigned int nextjob;
|
||||
unsigned int maxjobs;
|
||||
void **jobs;
|
||||
|
||||
public:
|
||||
Monitor(unsigned int const maxjobs);
|
||||
~Monitor();
|
||||
void addJob(void * const job);
|
||||
void * const getJob();
|
||||
bool const isJobPending() const;
|
||||
};
|
||||
|
||||
#endif /* __CAMEMBERT_MONITOR_H */
|
BIN
backend/camembert/monitor.o
Normal file
BIN
backend/camembert/monitor.o
Normal file
Binary file not shown.
275
backend/camembert/neighbours.cpp
Normal file
275
backend/camembert/neighbours.cpp
Normal file
@ -0,0 +1,275 @@
|
||||
/* =================================================
|
||||
|
||||
Camembert Project
|
||||
Alban FERON, 2007
|
||||
|
||||
Fonctions pour la recherche des voisins (CDP)
|
||||
|
||||
=================================================== */
|
||||
|
||||
#include "camembert.h"
|
||||
|
||||
Oid OID_NeighboursNames ("1.3.6.1.4.1.9.9.23.1.2.1.1.6");
|
||||
Oid OID_NeighboursIPs ("1.3.6.1.4.1.9.9.23.1.2.1.1.4");
|
||||
Oid OID_NeighboursTypes ("1.3.6.1.4.1.9.9.23.1.2.1.1.8");
|
||||
Oid OID_NeighboursOS ("1.3.6.1.4.1.9.9.23.1.2.1.1.5");
|
||||
Oid OID_NeighboursCapab ("1.3.6.1.4.1.9.9.23.1.2.1.1.9");
|
||||
Oid OID_NeighboursIfName("1.3.6.1.4.1.9.9.23.1.2.1.1.7");
|
||||
|
||||
Oid OID_ARP("1.3.6.1.2.1.3.1.1.2");
|
||||
|
||||
/* Petite liste contenant les infos sur les voisins */
|
||||
typedef struct neighbourList_s {
|
||||
int key[2]; /* Clé CDP du voisin */
|
||||
char name[64]; /* Nom du voisin */
|
||||
char type[64]; /* Type du voisin */
|
||||
char os[512]; /* Description de l'OS du voisin */
|
||||
char ifName[64]; /* Nom de l'interface distante */
|
||||
unsigned int capa; /* Masque des capabilities */
|
||||
IPList *lip; /* Liste d'IP du voisin */
|
||||
struct neighbourList_s *next; /* Voisin suivant */
|
||||
} neighbourList;
|
||||
|
||||
neighbourList *addNeighbour(neighbourList *nl, const char *name, int key[]) {
|
||||
neighbourList *n;
|
||||
|
||||
// Cherche si la clé existe déjà et retourne la structure passée (qui doit correspondre au premier voisin)
|
||||
for(n = nl; n!=NULL; n=n->next)
|
||||
if(key[0] == n->key[0] && key[1] == n->key[1])
|
||||
return nl;
|
||||
|
||||
// Création du nouveau voisin
|
||||
n = new neighbourList;
|
||||
n->key[0] = key[0];
|
||||
n->key[1] = key[1];
|
||||
strcpy(n->name, name);
|
||||
n->type[0] = 0;
|
||||
n->os[0] = 0;
|
||||
n->ifName[0] = 0;
|
||||
n->capa = 0;
|
||||
n->lip = new IPList();
|
||||
n->next = nl;
|
||||
return n;
|
||||
}
|
||||
|
||||
void addNeighbourType(neighbourList *nl, const char *type, int key[]) {
|
||||
neighbourList *n;
|
||||
|
||||
// Cherche le voisin correspondant à la clé
|
||||
for(n=nl; n!=NULL; n=n->next) {
|
||||
if(key[0] == n->key[0] && key[1] == n->key[1]) {
|
||||
// Change son type
|
||||
strcpy(n->type, type);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void addNeighbourOS(neighbourList *nl, const char *os, int key[]) {
|
||||
neighbourList *n;
|
||||
|
||||
// Cherche le voisin correspondant à la clé
|
||||
for(n=nl; n!=NULL; n=n->next) {
|
||||
if(key[0] == n->key[0] && key[1] == n->key[1]) {
|
||||
// Change son type
|
||||
strcpy(n->os, os);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void addNeighbourIfName(neighbourList *nl, const char *ifname, int key[]) {
|
||||
neighbourList *n;
|
||||
|
||||
// Cherche le voisin correspondant à la clé
|
||||
for(n=nl; n!=NULL; n=n->next) {
|
||||
if(key[0] == n->key[0] && key[1] == n->key[1]) {
|
||||
// Change son type
|
||||
strcpy(n->ifName, ifname);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void addNeighbourIP(neighbourList *nl, unsigned int ipnum, int key[]) {
|
||||
neighbourList *n;
|
||||
IP *ip;
|
||||
|
||||
// Cherche le voisin correspondant à la clé
|
||||
for(n=nl; n!=NULL; n=n->next) {
|
||||
if(key[0] == n->key[0] && key[1] == n->key[1]) {
|
||||
ip = new IP(ipnum);
|
||||
// Si l'IP trouvé n'est pas dans la liste, on l'ajoute
|
||||
if(!n->lip->isIPinList(ip)) {
|
||||
n->lip->addIP(ip, DBSTATUS_NEW);
|
||||
}
|
||||
else
|
||||
delete ip;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void addNeighbourCapability(neighbourList *nl, unsigned int capa, int key[]) {
|
||||
neighbourList *n;
|
||||
|
||||
// Cherche le voisin correspondant à la clé
|
||||
for(n=nl; n!=NULL; n=n->next) {
|
||||
if(key[0] == n->key[0] && key[1] == n->key[1]) {
|
||||
// Met à jour les capabilities
|
||||
n->capa = capa;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// C'est censé libérer la mémoire, mais en fait ça fait des erreurs
|
||||
void clearNeighbours(neighbourList *nl) {
|
||||
neighbourList *next;
|
||||
while(nl) {
|
||||
next = nl->next;
|
||||
delete nl;
|
||||
nl = next;
|
||||
}
|
||||
}
|
||||
|
||||
bool look_for_neighbours(Materiel *m) {
|
||||
neighbourList *nl = NULL;
|
||||
const SNMPResult *r;
|
||||
int key[2];
|
||||
unsigned char buffer[16];
|
||||
unsigned int num;
|
||||
unsigned long int size;
|
||||
|
||||
SNMPResults res(m->multiplesnmpwalk(6, 0,
|
||||
&OID_NeighboursCapab,
|
||||
&OID_NeighboursIfName,
|
||||
&OID_NeighboursOS,
|
||||
&OID_NeighboursTypes,
|
||||
&OID_NeighboursIPs,
|
||||
&OID_NeighboursNames));
|
||||
// Recherche des voisins
|
||||
while(r = res.getNext()) {
|
||||
const Oid &o = r->get_oid();
|
||||
key[0] = o[14];
|
||||
key[1] = o[15];
|
||||
|
||||
switch (o[13]) {
|
||||
case 6:
|
||||
nl = addNeighbour(nl, r->get_printable_value(), key);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
r->get_value(buffer, size);
|
||||
if(buffer[0] != 0) {
|
||||
num = buffer[0]*16777216 + buffer[1]*65536 + buffer[2]*256 + buffer[3];
|
||||
addNeighbourIP(nl, num, key);
|
||||
}
|
||||
break;
|
||||
|
||||
case 8:
|
||||
addNeighbourType(nl, r->get_printable_value(), key);
|
||||
break;
|
||||
|
||||
case 5:
|
||||
addNeighbourOS(nl, r->get_printable_value(), key);
|
||||
break;
|
||||
|
||||
case 7:
|
||||
addNeighbourIfName(nl, r->get_printable_value(), key);
|
||||
break;
|
||||
|
||||
case 9:
|
||||
r->get_value(buffer, size);
|
||||
num = buffer[0]*16777216 + buffer[1]*65536 + buffer[2]*256 + buffer[3];
|
||||
addNeighbourCapability(nl, num, key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
neighbourList *n;
|
||||
Materiel *mat = NULL;
|
||||
IPList *lip;
|
||||
bool bNew = false;
|
||||
Interface *i;
|
||||
|
||||
// Pour chaque voisin trouvé...
|
||||
for(n=nl; n!=NULL; n=n->next) {
|
||||
|
||||
// On bloque l'acces au matériel pour éviter qu'un autre thread modifie en même
|
||||
// temps la liste du matériel
|
||||
pthread_mutex_lock(&mtx_materiels);
|
||||
|
||||
// Commence par chercher si un materiel porte le même nom et a la même IP que le voisin
|
||||
lip = n->lip;
|
||||
while(lip!=NULL) {
|
||||
mat = lstMateriel->getMaterielByHostnameAndIP(n->name, lip->getIP());
|
||||
if(mat)
|
||||
lip = NULL;
|
||||
else
|
||||
lip = lip->getNext();
|
||||
}
|
||||
// S'il y en a aucun, on cherche juste sur le nom (en vérifiant que le type et l'OS soient les mêmes)
|
||||
if(!mat)
|
||||
mat = lstMateriel->getMaterielByHostname(n->name, n->type, n->os);
|
||||
// S'il y en a toujours aucun, on cherche sur les IPs (en vérifiant que le type et l'OS soient les mêmes)
|
||||
if(!mat) {
|
||||
lip = n->lip;
|
||||
while(lip!=NULL) {
|
||||
mat = lstMateriel->getMaterielByIP(lip->getIP(), n->type, n->os);
|
||||
if(mat)
|
||||
lip = NULL;
|
||||
else
|
||||
lip = lip->getNext();
|
||||
}
|
||||
}
|
||||
|
||||
if(!mat) {
|
||||
// Si aucun ne correspond aux critères, on en crée un nouveau et on l'ajoute à la liste
|
||||
mat = new Materiel(++maxIdMateriel, snmp, COMMUNITY, n->lip);
|
||||
mat->setDBstatus(DBSTATUS_NEW);
|
||||
lstMateriel = lstMateriel->addMateriel(mat);
|
||||
bNew = true;
|
||||
}
|
||||
else {
|
||||
// Sinon on parcourt la liste des IPs du voisin et on ajoute celles qui
|
||||
// ne sont pas dans la liste d'IP du matériel correspondant
|
||||
for(lip=n->lip; lip!=NULL; lip=lip->getNext()) {
|
||||
if(!mat->getIPList()->isIPinList(lip->getIP())) {
|
||||
mat->addIP(lip->getIP(), DBSTATUS_NEW);
|
||||
}
|
||||
else
|
||||
mat->getIPList()->foundIP(lip->getIP());
|
||||
}
|
||||
}
|
||||
|
||||
i = m->getInterfaceById(n->key[0]);
|
||||
/*if(i) {
|
||||
i->distantDevice = mat;
|
||||
i->setDistantIfName(n->ifName);
|
||||
}*/
|
||||
if(i)
|
||||
i->addDistantDevice(n->ifName, mat);
|
||||
|
||||
if(!mat->getHostName() || strcmp(mat->getHostName(), n->name))
|
||||
mat->setHostName(n->name);
|
||||
// Si il a pas de type on le met à jour
|
||||
if(!mat->getType() || strcmp(mat->getType(), n->type))
|
||||
mat->setType(n->type);
|
||||
if(!mat->getOSType() || strcmp(mat->getOSType(), n->os))
|
||||
mat->setOSType(n->os);
|
||||
// et pareil pour les capabilities
|
||||
if(!mat->getCapabilities() || n->capa != mat->getCapabilities())
|
||||
mat->setCapabilities(n->capa);
|
||||
mat->setDBstatus(DBSTATUS_UPDATED);
|
||||
|
||||
// On débloque l'acces au matériel
|
||||
pthread_mutex_unlock(&mtx_materiels);
|
||||
|
||||
if(!mat->isTreated())
|
||||
monitor->addJob(mat);
|
||||
}
|
||||
|
||||
//clearNeighbours(nl);
|
||||
return bNew;
|
||||
}
|
25
backend/camembert/neighbours.h
Normal file
25
backend/camembert/neighbours.h
Normal file
@ -0,0 +1,25 @@
|
||||
/* =================================================
|
||||
|
||||
Camembert Project
|
||||
Alban FERON, 2007
|
||||
|
||||
Fonctions pour la recherche des voisins (CDP)
|
||||
|
||||
=================================================== */
|
||||
|
||||
#ifndef __CAMEMBERT_NEIGHBOURS_H
|
||||
#define __CAMEMBERT_NEIGHBOURS_H
|
||||
|
||||
#include "camembert.h"
|
||||
|
||||
/**
|
||||
* Cherche les voisins d'un materiel donné
|
||||
* Les nouveaux voisins sont ajoutés à la liste globale du matériel
|
||||
* et au monitor pour exu aussi être analysés.
|
||||
*
|
||||
* @param m - Materiel à partir duquel on doit chercher les voisins
|
||||
* @return VRAI si au moins un nouveau voisin a été trouvé, FAUX sinon.
|
||||
*/
|
||||
bool look_for_neighbours(Materiel *m);
|
||||
|
||||
#endif /* __CAMEMBERT_NEIGHBOURS_H */
|
BIN
backend/camembert/neighbours.o
Normal file
BIN
backend/camembert/neighbours.o
Normal file
Binary file not shown.
77
backend/camembert/pgdb.cpp
Normal file
77
backend/camembert/pgdb.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
/* =================================================
|
||||
|
||||
Camembert Project
|
||||
Alban FERON, 2007
|
||||
|
||||
Connexion à la base de données
|
||||
Entièrement repris de Kindmana, par Aurélien Méré
|
||||
|
||||
Juste viré ce qui servait à rien
|
||||
|
||||
================================================== */
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "pgdb.h"
|
||||
#include <postgresql/libpq-fe.h>
|
||||
|
||||
pthread_mutex_t mtxDB;
|
||||
PGconn *db;
|
||||
|
||||
int ConnectDB() {
|
||||
#ifdef DBPASSWORD
|
||||
db = PQconnectdb("host="DBHOST" user="DBUSERNAME" dbname="DBNAME" password="DBPASSWORD);
|
||||
#else
|
||||
db = PQconnectdb("host="DBHOST" user="DBUSERNAME" dbname="DBNAME);
|
||||
#endif
|
||||
|
||||
pthread_mutex_init(&mtxDB, NULL);
|
||||
|
||||
if (db == NULL) {
|
||||
printf("Failed to connect to PostgreSQL database\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void DisconnectDB() {
|
||||
pthread_mutex_destroy(&mtxDB);
|
||||
PQfinish(db);
|
||||
}
|
||||
|
||||
void *QueryDB(char *query) {
|
||||
PGresult *r;
|
||||
ExecStatusType e;
|
||||
|
||||
pthread_mutex_lock(&mtxDB);
|
||||
|
||||
if ((r = PQexec(db, query)) == NULL) {
|
||||
printf("POSTGRES FATAL : Query [%s] returned NULL\n", query);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
e = PQresultStatus(r);
|
||||
if ((e != PGRES_TUPLES_OK) && (e != PGRES_COMMAND_OK)) {
|
||||
printf("POSTGRES FATAL : Query [%s] failed returning error [%s]\n", query, PQresultErrorMessage(r));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&mtxDB);
|
||||
return ((void *)r);
|
||||
}
|
||||
|
||||
char *_PQcmdTuples(void* a) { return PQcmdTuples((PGresult *)a); }
|
||||
void _PQclear(void *a) { PQclear((PGresult *)a); }
|
||||
int _PQntuples(void *a) { return PQntuples((PGresult *)a); }
|
||||
char *_PQgetvalue(void *a,int b, int c) { return PQgetvalue((PGresult *)a, b, c); }
|
||||
void *_PQgetResult() { return (void *)PQgetResult(db); }
|
||||
int _PQescapeString(char *to, const char *from) { return PQescapeStringConn(db, to, from, strlen(from), NULL); }
|
||||
|
||||
/* ======================================================= */
|
||||
|
||||
void DBObject::setDBstatus(unsigned int status) {
|
||||
if(status > _dbStatus)
|
||||
_dbStatus = status;
|
||||
}
|
69
backend/camembert/pgdb.h
Normal file
69
backend/camembert/pgdb.h
Normal file
@ -0,0 +1,69 @@
|
||||
/* =================================================
|
||||
|
||||
Camembert Project
|
||||
Alban FERON, 2007
|
||||
|
||||
Connexion à la base de données
|
||||
Entièrement repris de Kindmana, par Aurélien Méré
|
||||
|
||||
================================================== */
|
||||
|
||||
#ifndef __PGDB_H
|
||||
#define __PGDB_H
|
||||
|
||||
#define DBSTATUS_UNKNOWN 0
|
||||
#define DBSTATUS_OLD 1
|
||||
#define DBSTATUS_UPDATED 2
|
||||
#define DBSTATUS_NEW 3
|
||||
|
||||
#define DBNAME "camembert"
|
||||
#define DBUSERNAME "camembert"
|
||||
#define DBHOST "127.0.0.1"
|
||||
#define DBPASSWORD "CamembertDB@Pacat"
|
||||
|
||||
/**
|
||||
* Effectue une connexion à la base de données.
|
||||
* @return NULL en cas de problème, 1 en cas de succès
|
||||
*/
|
||||
int ConnectDB();
|
||||
|
||||
/**
|
||||
* Déconnecte l'objet de connexion à la base de
|
||||
* données. Il est important d'appeler cette fonction
|
||||
* avant toute terminaison du programme.
|
||||
*/
|
||||
void DisconnectDB();
|
||||
|
||||
/**
|
||||
* Effectue une requête dans la base de données. Le
|
||||
* programme se termine dans le cas où la requête
|
||||
* n'est pas valide.
|
||||
*/
|
||||
void *QueryDB(char *query);
|
||||
|
||||
char *_PQcmdTuples(void*);
|
||||
void _PQclear(void *);
|
||||
int _PQntuples(void *);
|
||||
char *_PQgetvalue(void *,int, int);
|
||||
void *_PQgetResult();
|
||||
int _PQescapeString(char *to, const char *from);
|
||||
|
||||
/**
|
||||
* Décrit un objet possèdant une entrée dans la base de données
|
||||
* Permet de déterminer s'il doit etre crée, mis à jour, etc.
|
||||
*/
|
||||
class DBObject {
|
||||
protected:
|
||||
unsigned int _dbStatus;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* @return Le statut de l'objet par rapport à son homologue dans la base de données
|
||||
*/
|
||||
unsigned int getDBstatus() const { return _dbStatus; }
|
||||
void setDBstatus(unsigned int status);
|
||||
};
|
||||
|
||||
#endif /* __PGDB_H */
|
||||
|
BIN
backend/camembert/pgdb.o
Normal file
BIN
backend/camembert/pgdb.o
Normal file
Binary file not shown.
226
backend/camembert/snmp.cpp
Normal file
226
backend/camembert/snmp.cpp
Normal file
@ -0,0 +1,226 @@
|
||||
/* ========================================================
|
||||
|
||||
Camembert Project
|
||||
Alban FERON, 2007
|
||||
|
||||
SNMP Base class.
|
||||
Totalement repris de Kindmana, par Aurélien Méré
|
||||
|
||||
======================================================== */
|
||||
|
||||
#include "snmp.h"
|
||||
#include <errno.h>
|
||||
|
||||
extern int snmp_answers, snmp_requests, snmp_dups;
|
||||
|
||||
SNMPResult::SNMPResult(const Vb &vb):Vb(vb),next(NULL) { }
|
||||
SNMPResult::SNMPResult(const Vb *vb):Vb(*vb),next(NULL) { }
|
||||
SNMPResult::SNMPResult(const Vb &vb, const SNMPResult *next):Vb(vb),next(next) { }
|
||||
SNMPResult::SNMPResult(const Vb *vb, const SNMPResult *next):Vb(*vb),next(next) { }
|
||||
|
||||
//inline const SNMPResult *SNMPResult::getNext() const { return next; }
|
||||
|
||||
|
||||
SNMP::SNMP() {
|
||||
current_rid = (rand() % (PDU_MAX_RID - PDU_MIN_RID - 1)) + PDU_MIN_RID;
|
||||
pthread_mutex_init(&mtx_rid, NULL);
|
||||
}
|
||||
|
||||
const SNMPResult *SNMP::snmpwalk(const unsigned int idconn,
|
||||
const Oid *oid,
|
||||
const unsigned int version,
|
||||
const char *community,
|
||||
const unsigned int timeout,
|
||||
const unsigned int retry,
|
||||
const SNMPResult *prev)
|
||||
{
|
||||
int i;
|
||||
Pdu pdu;
|
||||
Vb vb(*oid);
|
||||
pdu += vb;
|
||||
|
||||
SNMPResult *last = (SNMPResult *)prev;
|
||||
|
||||
++snmp_requests;
|
||||
|
||||
while(1) {
|
||||
pdu.set_type(sNMP_PDU_GETBULK);
|
||||
//printf("Suite boucle ... \n");
|
||||
if ((snmpengine(idconn, &pdu, version, community, timeout, retry)) == 0) {
|
||||
if (pdu.get_vb_count()>0) {
|
||||
for (i=0; i<pdu.get_vb_count(); ++i) {
|
||||
pdu.get_vb(vb, i);
|
||||
if ((vb.get_syntax() == SNMP_ENDOFMIBVIEW) || (vb.get_oid().nCompare(oid->len(), *oid) != 0))
|
||||
return(last);
|
||||
last = new SNMPResult(vb, last);
|
||||
}
|
||||
pdu.set_vblist(&vb, 1);
|
||||
}
|
||||
else return prev;
|
||||
}
|
||||
else return prev;
|
||||
}
|
||||
printf("Fin snmpwalk 2 +++++++++++++++\n");
|
||||
}
|
||||
|
||||
const unsigned int SNMP::snmpopen(const IP *ip) {
|
||||
|
||||
int sock;
|
||||
struct sockaddr_in sa;
|
||||
|
||||
if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) <= 0) {
|
||||
fprintf(stderr, "FATAL: Couldn't create socket\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sin_family = AF_INET;
|
||||
sa.sin_addr.s_addr = htonl(((IP *)ip)->getIPint());
|
||||
sa.sin_port = htons(161);
|
||||
|
||||
if (connect(sock, (struct sockaddr *)&sa, (socklen_t)sizeof(sa)) == -1) {
|
||||
close(sock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return sock;
|
||||
}
|
||||
|
||||
void SNMP::snmpclose(unsigned int idconn) {
|
||||
|
||||
close(idconn);
|
||||
|
||||
}
|
||||
|
||||
const unsigned int SNMP::snmpengine(const unsigned int idconn,
|
||||
Pdu *pdu,
|
||||
const unsigned int version,
|
||||
const char *community,
|
||||
const unsigned int timeout,
|
||||
const unsigned int retry)
|
||||
{
|
||||
fd_set fd;
|
||||
int status, bytes;
|
||||
char buffer[4096];
|
||||
struct timeval tout;
|
||||
SnmpMessage snmpmsg;
|
||||
SnmpMessage snmpmsg_ret;
|
||||
OctetStr community_ret;
|
||||
snmp_version version_ret;
|
||||
unsigned short pdu_action;
|
||||
unsigned int id, tries=0;
|
||||
OctetStr comm(community);
|
||||
snmp_version ver;
|
||||
/*
|
||||
Vb vb;
|
||||
pdu->get_vb(vb, 0);
|
||||
|
||||
printf("snmpengine : %d %s %d %s %d %d\n", idconn, vb.get_printable_oid(), version, community, timeout, retry);
|
||||
*/
|
||||
if (version==1) ver=version1;
|
||||
else ver=version2c;
|
||||
|
||||
pdu_action = pdu->get_type();
|
||||
pdu->set_error_index(0);
|
||||
|
||||
pthread_mutex_lock(&mtx_rid);
|
||||
if (++current_rid > PDU_MAX_RID) current_rid=PDU_MIN_RID;
|
||||
pdu->set_request_id(id = current_rid);
|
||||
pthread_mutex_unlock(&mtx_rid);
|
||||
|
||||
if (pdu_action == sNMP_PDU_GETBULK) {
|
||||
if (ver == version1) {
|
||||
pdu->set_type(sNMP_PDU_GETNEXT);
|
||||
}
|
||||
else {
|
||||
pdu->set_error_status((int)0);
|
||||
pdu->set_error_index((int)20);
|
||||
}
|
||||
}
|
||||
|
||||
if ((status = snmpmsg.load(*pdu, comm, ver)) != SNMP_CLASS_SUCCESS) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (tries < retry) {
|
||||
|
||||
bytes = send(idconn, snmpmsg.data(), (size_t)snmpmsg.len(), 0);
|
||||
if (bytes != (int)snmpmsg.len()) {
|
||||
fprintf(stderr, "FATAL: Send failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
tout.tv_sec = timeout/1000;
|
||||
tout.tv_usec = (timeout%1000)*1000;
|
||||
FD_ZERO(&fd);
|
||||
FD_SET(idconn, &fd);
|
||||
|
||||
if (select(idconn+1, &fd, NULL, NULL, &tout)>0) {
|
||||
|
||||
if ((bytes = recv(idconn, buffer, sizeof(buffer), 0))>0) {
|
||||
if (snmpmsg_ret.load((unsigned char *)buffer, bytes) == SNMP_CLASS_SUCCESS) {
|
||||
if (snmpmsg_ret.unload(*pdu, community_ret, version_ret) == SNMP_CLASS_SUCCESS) {
|
||||
|
||||
if (pdu->get_request_id() == id) {
|
||||
++snmp_answers;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else fprintf(stderr, "FATAL: Read error\n");
|
||||
}
|
||||
++tries;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
const SNMPResult *SNMP::snmpget(const unsigned int idconn,
|
||||
const Oid *oid,
|
||||
const unsigned int version,
|
||||
const char *community,
|
||||
const unsigned int timeout,
|
||||
const unsigned int retry)
|
||||
{
|
||||
unsigned int result;
|
||||
Pdu pdu;
|
||||
Vb vb(*oid);
|
||||
|
||||
++snmp_requests;
|
||||
pdu += vb;
|
||||
pdu.set_type(sNMP_PDU_GET);
|
||||
|
||||
if ((result = snmpengine(idconn, &pdu, version, community, timeout, retry)) == 0) {
|
||||
|
||||
if (pdu.get_vb_count()>0) {
|
||||
pdu.get_vb(vb, 0);
|
||||
return(new SNMPResult(vb));
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
const SNMPResult *SNMP::snmpset(const unsigned int idconn,
|
||||
const Vb *vb,
|
||||
const unsigned int version,
|
||||
const char * community,
|
||||
const unsigned int timeout,
|
||||
const unsigned int retry)
|
||||
{
|
||||
Pdu pdu;
|
||||
pdu += (Vb &)(*vb);
|
||||
Vb vb_res;
|
||||
int res;
|
||||
++snmp_requests;
|
||||
|
||||
pdu.set_type(sNMP_PDU_SET);
|
||||
|
||||
if ((res = snmpengine(idconn, &pdu, version, community, timeout, retry)) == 0) {
|
||||
|
||||
pdu.get_vb(vb_res, 0);
|
||||
return(new SNMPResult(vb_res));
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
123
backend/camembert/snmp.h
Normal file
123
backend/camembert/snmp.h
Normal file
@ -0,0 +1,123 @@
|
||||
/* ========================================================
|
||||
|
||||
Camembert Project
|
||||
Alban FERON, 2007
|
||||
|
||||
SNMP Base class.
|
||||
Totalement repris de Kindmana, par Aurélien Méré
|
||||
(juste réindenté :p)
|
||||
|
||||
======================================================== */
|
||||
|
||||
#ifndef __CAMEMBERT_SNMP_H
|
||||
#define __CAMEMBERT_SNMP_H
|
||||
|
||||
#include "ip.h"
|
||||
#include "oid.h"
|
||||
#include "pdu.h"
|
||||
#include "vb.h"
|
||||
#include "octet.h"
|
||||
#include "snmpmsg.h"
|
||||
#include "ip.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/time.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
#include <pthread.h>
|
||||
|
||||
class SNMPResult:public Vb {
|
||||
const SNMPResult *next;
|
||||
|
||||
public:
|
||||
inline const SNMPResult *getNext() const { return next; }
|
||||
|
||||
SNMPResult(const Vb &vb);
|
||||
SNMPResult(const Vb *vb);
|
||||
SNMPResult(const Vb &vb, const SNMPResult *next);
|
||||
SNMPResult(const Vb *vb, const SNMPResult *next);
|
||||
inline ~SNMPResult() {}
|
||||
};
|
||||
|
||||
|
||||
class SNMP {
|
||||
|
||||
int current_rid;
|
||||
pthread_mutex_t mtx_rid;
|
||||
|
||||
const unsigned int snmpengine(const unsigned int idconn,
|
||||
Pdu *pdu,
|
||||
const unsigned int version,
|
||||
const char *community,
|
||||
const unsigned int timeout,
|
||||
const unsigned int retry);
|
||||
|
||||
public:
|
||||
|
||||
SNMP();
|
||||
|
||||
const unsigned int snmpopen(const IP *ip);
|
||||
void snmpclose(const unsigned int idconn);
|
||||
|
||||
const SNMPResult *snmpget(const unsigned int idconn,
|
||||
const Oid *oid,
|
||||
const unsigned int version,
|
||||
const char *community,
|
||||
const unsigned int timeout,
|
||||
const unsigned int retry) ;
|
||||
|
||||
const SNMPResult *snmpwalk(const unsigned int idconn,
|
||||
const Oid *oid,
|
||||
const unsigned int version,
|
||||
const char *community,
|
||||
const unsigned int timeout,
|
||||
const unsigned int retry,
|
||||
const SNMPResult *prev);
|
||||
|
||||
const SNMPResult *snmpset(const unsigned int idconn,
|
||||
const Vb *vb,
|
||||
const unsigned int version,
|
||||
const char * community,
|
||||
const unsigned int timeout,
|
||||
const unsigned int retry);
|
||||
};
|
||||
|
||||
class SNMPResults {
|
||||
|
||||
SNMPResult const * ptr;
|
||||
SNMPResult const * current;
|
||||
|
||||
public:
|
||||
|
||||
SNMPResults &operator=(SNMPResult const *res) {
|
||||
if (ptr != NULL)
|
||||
delete ptr;
|
||||
ptr=res;
|
||||
current = NULL;
|
||||
return *this;
|
||||
}
|
||||
|
||||
SNMPResults(SNMPResult const *res):ptr(res),current(NULL) {}
|
||||
|
||||
inline ~SNMPResults() {
|
||||
SNMPResult const *p = ptr, *next;
|
||||
while (p != NULL) {
|
||||
next=p->getNext();
|
||||
delete p;
|
||||
p=next;
|
||||
}
|
||||
}
|
||||
|
||||
inline SNMPResult const *getNext() {
|
||||
if (current == NULL)
|
||||
current=ptr;
|
||||
else
|
||||
current=current->getNext();
|
||||
return current;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif /* __CAMEMBERT_H */
|
BIN
backend/camembert/snmp.o
Normal file
BIN
backend/camembert/snmp.o
Normal file
Binary file not shown.
225
backend/camembert/snmpobject.cpp
Normal file
225
backend/camembert/snmpobject.cpp
Normal file
@ -0,0 +1,225 @@
|
||||
/* ========================================================
|
||||
|
||||
Camembert Project
|
||||
Alban FERON, 2007
|
||||
|
||||
SNMPObject class.
|
||||
Repris (et simplifié) de Kindmana, par Aurélien Méré
|
||||
|
||||
======================================================== */
|
||||
|
||||
#include "snmpobject.h"
|
||||
#include "pgdb.h"
|
||||
|
||||
unsigned int versions[NB_VERSIONS] = {2, 1};
|
||||
|
||||
SNMPObject::SNMPObject(SNMP *snmp, const char* community, IPList* lip) {
|
||||
this->lip = lip;
|
||||
this->snmp = snmp;
|
||||
this->community = new char[strlen(community)+1];
|
||||
strcpy(this->community, community);
|
||||
snmpid = 0;
|
||||
status = STATUS_UNTESTED;
|
||||
version = -1;
|
||||
by_vlan = SNMP_VLANUNKNOWN;
|
||||
}
|
||||
|
||||
SNMPObject::SNMPObject(SNMP *snmp, const char* community, IP* ip) {
|
||||
this->lip = new IPList();
|
||||
this->lip->addIP(ip, DBSTATUS_NEW);
|
||||
this->snmp = snmp;
|
||||
this->community = new char[strlen(community)+1];
|
||||
strcpy(this->community, community);
|
||||
snmpid = 0;
|
||||
status = STATUS_UNTESTED;
|
||||
version = -1;
|
||||
by_vlan = SNMP_VLANUNKNOWN;
|
||||
}
|
||||
|
||||
SNMPObject::~SNMPObject() {
|
||||
if(lip)
|
||||
delete lip;
|
||||
delete[] community;
|
||||
}
|
||||
|
||||
const unsigned int SNMPObject::snmpopen() {
|
||||
if(status == STATUS_MANAGEABLE && lip->getIP())
|
||||
snmpid = snmp->snmpopen(lip->getIP());
|
||||
return (snmpid != 0);
|
||||
}
|
||||
|
||||
const unsigned int SNMPObject::snmpclose() {
|
||||
if(snmpid)
|
||||
snmp->snmpclose(snmpid);
|
||||
snmpid = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
const SNMPResult *SNMPObject::snmpwalk(const Oid *oid, const unsigned int vlan, const SNMPResult *sres)
|
||||
{
|
||||
int ix_vers=0;
|
||||
const SNMPResult *res = sres;
|
||||
char commu[128];
|
||||
|
||||
if ((status == STATUS_MANAGEABLE) && (snmpid>0))
|
||||
{
|
||||
ix_vers = version;
|
||||
if (vlan != 0)
|
||||
{
|
||||
if (by_vlan != SNMP_VLANUNSUPPORTED)
|
||||
{
|
||||
sprintf(commu, "%s@%d", community, vlan);
|
||||
res = snmp->snmpwalk(snmpid, oid, ix_vers, commu, TIMEOUT, RETRY, sres);
|
||||
|
||||
if (res!=NULL && (by_vlan != SNMP_VLANSUPPORTED))
|
||||
by_vlan = SNMP_VLANSUPPORTED;
|
||||
else if (by_vlan == SNMP_VLANUNKNOWN)
|
||||
by_vlan = SNMP_VLANUNSUPPORTED;
|
||||
}
|
||||
}
|
||||
else
|
||||
res = snmp->snmpwalk(snmpid, oid, ix_vers, community, TIMEOUT, RETRY, sres);
|
||||
}
|
||||
|
||||
return(res);
|
||||
}
|
||||
|
||||
const SNMPResult *SNMPObject::snmpwalk(const Oid *oid) { return this->snmpwalk(oid, 0, NULL); }
|
||||
const SNMPResult *SNMPObject::snmpwalk(const Oid *oid, const unsigned int vlan) { return this->snmpwalk(oid, vlan, NULL); }
|
||||
|
||||
const unsigned int SNMPObject::snmpcheck() {
|
||||
|
||||
int ix_vers=0;
|
||||
unsigned int id;
|
||||
const SNMPResult *res;
|
||||
Oid oid("1.3.6.1.2.1.1.5.0"); /* RFC 1213 -> sysName (hostname) */
|
||||
|
||||
if (status == STATUS_UNTESTED && lip->getIP()) {
|
||||
|
||||
status = STATUS_TESTING;
|
||||
|
||||
// Check default IP with default community
|
||||
|
||||
for (ix_vers=0; ix_vers<NB_VERSIONS; ix_vers++) {
|
||||
id = snmp->snmpopen(lip->getIP());
|
||||
res = snmp->snmpget(id, &oid, versions[ix_vers], community, TIMEOUT, RETRY);
|
||||
snmp->snmpclose(id);
|
||||
|
||||
if (res != NULL) {
|
||||
delete res;
|
||||
version = ix_vers;
|
||||
status = STATUS_MANAGEABLE;
|
||||
lip->setDBstatus(DBSTATUS_UPDATED);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Check other IPs
|
||||
|
||||
for(IPList *l=lip->getNext(); l!=NULL; l=l->getNext()) {
|
||||
for (ix_vers=0; ix_vers<NB_VERSIONS; ix_vers++) {
|
||||
id = snmp->snmpopen(l->getIP());
|
||||
res = snmp->snmpget(id, &oid, versions[ix_vers], community, TIMEOUT, RETRY);
|
||||
snmp->snmpclose(id);
|
||||
|
||||
if (res != NULL) {
|
||||
delete res;
|
||||
version = ix_vers;
|
||||
status = STATUS_MANAGEABLE;
|
||||
l->setDBstatus(DBSTATUS_UPDATED);
|
||||
lip->setFirst(l);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
status = STATUS_NOTMANAGEABLE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (status == STATUS_MANAGEABLE);
|
||||
}
|
||||
|
||||
const SNMPResult *SNMPObject::multiplesnmpwalk(const unsigned int nboid, const unsigned int vlan, ...) {
|
||||
|
||||
va_list varptr;
|
||||
const SNMPResult *r = NULL;
|
||||
const Oid *oid;
|
||||
unsigned int i;
|
||||
|
||||
va_start(varptr, vlan);
|
||||
for (i=0; i<nboid; ++i) {
|
||||
oid = va_arg(varptr, const Oid *);
|
||||
r = this->snmpwalk(oid, vlan, r);
|
||||
}
|
||||
|
||||
va_end(varptr);
|
||||
return(r);
|
||||
}
|
||||
|
||||
const SNMPResult *SNMPObject::snmpget(const Oid *oid)
|
||||
{
|
||||
if ((status == STATUS_MANAGEABLE) && (snmpid>0))
|
||||
return snmp->snmpget(snmpid, oid, versions[version], community, TIMEOUT, RETRY);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const SNMPResult *SNMPObject::snmpset(const Oid *oid, const char *str)
|
||||
{
|
||||
Vb vb;
|
||||
|
||||
if ((status == STATUS_MANAGEABLE) && (snmpid>0)) {
|
||||
vb.set_value(str);
|
||||
vb.set_oid(*oid);
|
||||
return snmp->snmpset(snmpid, &vb, versions[version], community, TIMEOUT, RETRY);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const SNMPResult *SNMPObject::snmpset(const Oid *oid, const SnmpSyntax &stx) {
|
||||
|
||||
Vb vb(*oid);
|
||||
|
||||
if ((status == STATUS_MANAGEABLE) && (snmpid>0)) {
|
||||
vb.set_value(stx);
|
||||
return snmp->snmpset(snmpid, &vb, versions[version], community, TIMEOUT, RETRY);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
const SNMPResult *SNMPObject::snmpset(const Oid *oid, const int value) {
|
||||
|
||||
Vb vb;
|
||||
|
||||
if ((status == STATUS_MANAGEABLE) && (snmpid>0)) {
|
||||
vb.set_value(value);
|
||||
vb.set_oid(*oid);
|
||||
return snmp->snmpset(snmpid, &vb, versions[version], community, TIMEOUT, RETRY);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void SNMPObject::addIP(IP *const ip, unsigned int indb) const {
|
||||
lip->addIP(ip, indb);
|
||||
}
|
||||
|
||||
const int SNMPObject::getVersion() const {
|
||||
return version;
|
||||
}
|
||||
|
||||
const int SNMPObject::getManageableStatus() const {
|
||||
return status;
|
||||
}
|
||||
|
||||
IPList* SNMPObject::getIPList() const {
|
||||
return lip;
|
||||
}
|
||||
|
||||
const char* SNMPObject::getCommunity() const {
|
||||
return community;
|
||||
}
|
74
backend/camembert/snmpobject.h
Normal file
74
backend/camembert/snmpobject.h
Normal file
@ -0,0 +1,74 @@
|
||||
/* ========================================================
|
||||
|
||||
Camembert Project
|
||||
Alban FERON, 2007
|
||||
|
||||
SNMPObject class.
|
||||
Repris (et simplifié) de Kindmana, par Aurélien Méré
|
||||
|
||||
======================================================== */
|
||||
|
||||
#ifndef __CAMEMBERT_SNMPOBJECT_H
|
||||
#define __CAMEMBERT_SNMPOBJECT_H
|
||||
|
||||
#include "snmp.h"
|
||||
#include "ip.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
#define STATUS_UNTESTED -1
|
||||
#define STATUS_NOTMANAGEABLE 0
|
||||
#define STATUS_MANAGEABLE 1
|
||||
#define STATUS_TESTING 2
|
||||
|
||||
#define SNMP_VLANUNKNOWN -1
|
||||
#define SNMP_VLANSUPPORTED 1
|
||||
#define SNMP_VLANUNSUPPORTED 0
|
||||
|
||||
#define RETRY 3
|
||||
#define NB_VERSIONS 2
|
||||
#define TIMEOUT 2500
|
||||
|
||||
class SNMPObject {
|
||||
protected:
|
||||
SNMP *snmp;
|
||||
unsigned int snmpid;
|
||||
|
||||
int status;
|
||||
int version;
|
||||
int by_vlan;
|
||||
|
||||
IPList* lip;
|
||||
char* community;
|
||||
|
||||
const SNMPResult *snmpwalk(const Oid *oid, const unsigned int vlan, const SNMPResult *sres);
|
||||
|
||||
public:
|
||||
|
||||
SNMPObject(SNMP *snmp, const char* community, IPList* lip);
|
||||
SNMPObject(SNMP *snmp, const char* community, IP* ip);
|
||||
~SNMPObject();
|
||||
|
||||
const unsigned int snmpopen();
|
||||
const unsigned int snmpclose();
|
||||
const unsigned int snmpcheck();
|
||||
|
||||
const SNMPResult *snmpwalk(const Oid *oid);
|
||||
const SNMPResult *snmpwalk(const Oid *oid, const unsigned int vlan);
|
||||
|
||||
const SNMPResult *multiplesnmpwalk(const unsigned int nboid, ...);
|
||||
const SNMPResult *multiplesnmpwalk(const unsigned int nboid, const unsigned int vlan, ...);
|
||||
|
||||
const SNMPResult *snmpget(const Oid *oid);
|
||||
const SNMPResult *snmpset(const Oid *oid, const char *str);
|
||||
const SNMPResult *snmpset(const Oid *oid, const int value);
|
||||
const SNMPResult *snmpset(const Oid *oid, const SnmpSyntax &stx);
|
||||
|
||||
const int getVersion() const;
|
||||
const int getManageableStatus() const;
|
||||
|
||||
void addIP(IP *const ip, unsigned int indb) const;
|
||||
IPList* getIPList() const;
|
||||
const char* getCommunity() const;
|
||||
};
|
||||
|
||||
#endif /* __CAMEMBERT_H */
|
BIN
backend/camembert/snmpobject.o
Normal file
BIN
backend/camembert/snmpobject.o
Normal file
Binary file not shown.
49
backend/camembert/vlan.cpp
Normal file
49
backend/camembert/vlan.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
#include "vlan.h"
|
||||
|
||||
VlanList::VlanList() {
|
||||
vlans = NULL;
|
||||
curr = NULL;
|
||||
}
|
||||
|
||||
VlanList::~VlanList() {
|
||||
curr = vlans;
|
||||
while(curr) {
|
||||
vlans = vlans->next;
|
||||
delete curr;
|
||||
curr = vlans;
|
||||
}
|
||||
}
|
||||
|
||||
void VlanList::addVlan(unsigned short int vlan) {
|
||||
lstVLANs *newptr, *prev, *ptr;
|
||||
|
||||
for(ptr=vlans, prev=NULL; ptr!=NULL; ptr=ptr->next) {
|
||||
if (ptr->vlan == vlan) return;
|
||||
if (ptr->vlan < vlan) break;
|
||||
prev = ptr;
|
||||
}
|
||||
|
||||
newptr = new lstVLANs;
|
||||
newptr->vlan = vlan;
|
||||
if (prev == NULL) {
|
||||
newptr->next = vlans;
|
||||
vlans = newptr;
|
||||
return;
|
||||
}
|
||||
|
||||
newptr->next = prev->next;
|
||||
prev->next = newptr;
|
||||
}
|
||||
|
||||
bool VlanList::getNext(unsigned short int &vlan) const {
|
||||
if(!curr)
|
||||
curr = vlans;
|
||||
else
|
||||
curr = curr->next;
|
||||
|
||||
if(!curr)
|
||||
return false;
|
||||
|
||||
vlan = curr->vlan;
|
||||
return true;
|
||||
}
|
25
backend/camembert/vlan.h
Normal file
25
backend/camembert/vlan.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef __CAMEMBERT_VLAN_H
|
||||
#define __CAMEMBERT_VLAN_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct lstVLANs_s
|
||||
{
|
||||
unsigned short int vlan;
|
||||
struct lstVLANs_s *next;
|
||||
} lstVLANs;
|
||||
|
||||
class VlanList {
|
||||
private:
|
||||
lstVLANs *vlans;
|
||||
mutable lstVLANs *curr;
|
||||
|
||||
public:
|
||||
VlanList();
|
||||
~VlanList();
|
||||
|
||||
void addVlan(unsigned short int vlan);
|
||||
bool getNext(unsigned short int &vlan) const;
|
||||
};
|
||||
|
||||
#endif /* __CAMEMBERT_VLAN_H */
|
BIN
backend/camembert/vlan.o
Normal file
BIN
backend/camembert/vlan.o
Normal file
Binary file not shown.
4
backend/multi-telnet/commandes.txt
Normal file
4
backend/multi-telnet/commandes.txt
Normal file
@ -0,0 +1,4 @@
|
||||
conf t
|
||||
int gi0/1
|
||||
end
|
||||
write mem
|
8
backend/multi-telnet/liste.txt
Normal file
8
backend/multi-telnet/liste.txt
Normal file
@ -0,0 +1,8 @@
|
||||
sn1
|
||||
sn2
|
||||
sn3
|
||||
sn4
|
||||
ss1
|
||||
ss2
|
||||
ss3
|
||||
ss4
|
177
backend/multi-telnet/script.sh
Normal file
177
backend/multi-telnet/script.sh
Normal file
@ -0,0 +1,177 @@
|
||||
#!/bin/bash
|
||||
#script.sh
|
||||
|
||||
echo "veuillez donner le mot de passe"
|
||||
stty -echo #[1]
|
||||
read password
|
||||
stty echo
|
||||
|
||||
export ssh='./ssh.sh' #[2]
|
||||
export telnet='./telnet.sh'
|
||||
export erreur='./rapport_erreurs.log'
|
||||
export temp='./tmp_routeur.log'
|
||||
export cmdcisco='./commandes.txt'
|
||||
export liste='./liste.txt'
|
||||
export password
|
||||
export routeur
|
||||
export commande
|
||||
|
||||
rm -f $erreur #[3]
|
||||
rm -f $ssh
|
||||
rm -f $telnet
|
||||
|
||||
cat $liste | while read routeur;
|
||||
do
|
||||
if [ "$routeur" != "" ]
|
||||
then
|
||||
if[ ! -f $ssh ] #[4]
|
||||
then
|
||||
echo 'expect 2>&1 << EOF'>> $ssh
|
||||
echo 'spawn ssh admin@$routeur' >> $ssh
|
||||
echo 'expect {' >> $ssh
|
||||
echo '"Password:" {send "$password\r"}' >> $ssh
|
||||
echo 'timeout {exit}' >> $ssh
|
||||
echo ' }' >> $ssh
|
||||
echo 'expect "#"' >> $ssh
|
||||
|
||||
cat $cmdcisco | while read commande
|
||||
do
|
||||
echo "send \"$commande\r\""
|
||||
echo 'expect "#"'
|
||||
done >> $ssh
|
||||
|
||||
echo 'send "exit\r"' >> $ssh
|
||||
echo 'expect "closed"' >> $ssh
|
||||
echo 'exit' >> $ssh
|
||||
echo 'EOF' >> $ssh
|
||||
|
||||
chmod +x $ssh #[5]
|
||||
fi
|
||||
time -p $ssh > $temp 2>&1 #[6]
|
||||
|
||||
COD_RET=$?
|
||||
|
||||
auth='cat $temp | grep -c "Password: "' #[7]
|
||||
if [ "$auth" -gt "1" ]
|
||||
then
|
||||
echo "Problème d'authentification sur $routeur !"
|
||||
echo "$routeur : wrong log-in/password" >> $erreur
|
||||
continue
|
||||
fi
|
||||
|
||||
temps='grep 'real ' $temp | sed 's/real /§/' | cut -d'§' -f2 | cut -d' ' -f1 | cut -d'.' -f1'
|
||||
if [ $temps -ge 10 -a ! "'grep 'closed' $temp'" ] #[8]
|
||||
then
|
||||
echo "L'equipement $routeur ne réponds pas !";
|
||||
echo "$routeur : connection timed out" >> $erreur
|
||||
continue
|
||||
fi
|
||||
|
||||
if [ "$COD_RET" != "0" ] #[9]
|
||||
then
|
||||
#Erreur de connexion a l'équipement en SSH
|
||||
if [ ! -f $telnet ]
|
||||
then
|
||||
echo 'expect 2>&1 << EOF'>> $telnet
|
||||
echo 'spawn telnet $routeur' >> $telnet
|
||||
echo 'send "admin\r"' >> $telnet
|
||||
echo 'expect "Password:"' >> $telnet
|
||||
echo 'send "$password\r"' >> $telnet
|
||||
echo 'expect "#"' >> $telnet
|
||||
|
||||
cat $cmdcisco | while read commande
|
||||
do
|
||||
echo "send \"$commande\r\""
|
||||
echo 'expect "#"'
|
||||
done >> $telnet
|
||||
|
||||
echo 'send "exit\r"' >> $telnet
|
||||
echo 'expect "closed"' >> $telnet
|
||||
echo 'exit' >> $telnet
|
||||
echo 'EOF' >> $telnet
|
||||
|
||||
chmod +x $telnet
|
||||
fi
|
||||
$telnet > $temp 2>&1
|
||||
fi
|
||||
COD_RET=$?
|
||||
|
||||
auth='cat $temp | grep -c "Password: "' #[10]
|
||||
if [ "$auth" -gt "1" ]
|
||||
then
|
||||
echo "Problème d'authentification sur $routeur !"
|
||||
echo "$routeur : wrong log-in/password" >> $erreur
|
||||
elif [ "'grep 'Host name lookup failure' $temp'" ]
|
||||
then
|
||||
echo "l'equipement $routeur n'existe pas !"
|
||||
echo "$routeur : does not exist" >> $erreur
|
||||
elif [ "'grep 'Unknown host' $temp'" ]
|
||||
then
|
||||
echo "la saisie de l'ip ou du nom $routeur est incorrecte !"
|
||||
echo "$routeur : wrong spelling" >> $erreur
|
||||
elif [ "'grep 'send: spawn id exp4 not open' $temp'" ]
|
||||
then
|
||||
echo "/!\ ERREUR dans la procédure. Consultez le fichier log de $routeur !!!"
|
||||
echo "$routeur : Expect script execution failed !" >> $erreur
|
||||
cp $temp $routeur.error.log
|
||||
elif [ "'grep 'Authentication failed' $temp'" ]
|
||||
then
|
||||
echo "Mot de passe erroné pour $routeur !"
|
||||
echo "$routeur : wrong log-in/password" >> $erreur
|
||||
elif [ "'grep 'Connection refused' $temp'" ]
|
||||
then
|
||||
echo "Connexion à distance sur $routeur désactivé !"
|
||||
echo "$routeur : vty connection disabled" >> $erreur
|
||||
elif [ "'grep 'No route to host' $temp'" ]
|
||||
then
|
||||
echo "Alias DNS $routeur existant mais IP invalide !"
|
||||
echo "$routeur : No route to host" >> $erreur
|
||||
elif [ "'grep 'ProCurve' $temp'" ]
|
||||
then
|
||||
echo "routeur $routeur HP et non Cisco !"
|
||||
echo "$routeur : non Cisco router (HP ProCurve)" >> $erreur
|
||||
elif [ "'grep 'Alcatel' $temp'" ]
|
||||
then
|
||||
echo "routeur $routeur Alcatel et non Cisco !"
|
||||
echo "$routeur : non Cisco router (Alcatel)" >> $erreur
|
||||
elif [ "'grep 'Welcome to X1000' $temp'" ]
|
||||
then
|
||||
echo "routeur $routeur X1000 et non Cisco !"
|
||||
echo "$routeur : non Cisco equipement (X1000)" >> $erreur
|
||||
elif [ "'grep '% Unknown command' $temp'" -o "'grep '% Invalid' $temp'" ]
|
||||
then
|
||||
echo "/!\ Commandes Cisco non reconnues par l'equipement. Consultez le fichier log de $routeur !!!"
|
||||
echo "$routeur : Unrecognized commands found" >> $erreur
|
||||
cp $temp $routeur.error.log
|
||||
elif [ "'grep 'Connected to ' $temp'" -o "'grep 'Connection closed by foreign host.' $temp'" ]
|
||||
then
|
||||
echo "$routeur Telnet OK !"
|
||||
elif [ "'grep 'Connexion enregistree sur le terminal' $temp'" -o "'grep 'Connection to ' $temp'" ]
|
||||
then
|
||||
echo "$routeur SSH OK !"
|
||||
elif [ "$COD_RET" != "0" ]
|
||||
then
|
||||
echo "Problème de connexion a l'equipement $routeur !"
|
||||
echo "$routeur : connection problem" >> $erreur
|
||||
fi
|
||||
fi
|
||||
done
|
||||
rm -f $temp #[11]
|
||||
exit
|
||||
|
||||
|
||||
#Commentaires
|
||||
#
|
||||
# 1 : On cache la saisie du mot de passe
|
||||
# 2 : Tous les fichiers sont stockés dans des variables en chemin relatif, pour que le script puisse être exécuté de n'importe où
|
||||
# 3 : on supprime les fichiers générés existants si le script à déjà été exécuté
|
||||
# 4 : on génère le fichier Expect si ce n'est pas déjà fait, en rentrant la procédure de connexion SSH ainsi que les commandes provenant de commandes.txt
|
||||
# 5 : on attribue les droits d'exécution au script Expect généré, si on veut qu'il s'exécute correctement
|
||||
# 6 : on execute le script expect, en regroupant la sortie d'erreur avec la sortie standard, en calculant le temps d'exécution pour gérer le timeout, et en crachant le tout dans un fichier temp
|
||||
# 7 : on vérifie qu'il n'y ai pas un problème d'authentification en comptant le nombre d'occurrence "Password:" dans le fichier temp
|
||||
# 8 : on récupère le nombre du temps d'execution, et on vérifie qu'il ne soit pas supérieur à 10 (valeur du timeout du expect)
|
||||
# 9 : En cas d'erreur de connexion en SSH, on refait la procédure en Telnet
|
||||
# 10 : On gère tous les cas d'erreur pris en compte par le script. (c.f. II)
|
||||
# 11 : On supprime le fichier temp, qui devient inutile
|
||||
|
||||
|
85
backend/snmp.py
Executable file
85
backend/snmp.py
Executable file
@ -0,0 +1,85 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Ce script fait un write memory sur chacun des switchs passés en paramètres.
|
||||
|
||||
from pysnmp.entity.rfc3413.oneliner import cmdgen
|
||||
from pysnmp.proto import rfc1902
|
||||
import random
|
||||
import re
|
||||
import os,sys
|
||||
|
||||
CiscoPortSecurityMacAddresses = 1,3,6,1,4,1,9,9,315,1,2,2,1,4
|
||||
CiscoPortSecurityLastAddress = 1,3,6,1,4,1,9,9,315,1,2,1,1,10
|
||||
CiscoifAdminStatus = 1,3,6,1,2,1,2,2,1,7 # 1 = up, 2 = down, 3 = testing
|
||||
CiscoifOperStatus = 1,3,6,1,2,1,2,2,1,8 # 1 = up, 2 = down, 3 = testing
|
||||
Cisco_ccCopySourceFileType = 1,3,6,1,4,1,9,9,96,1,1,1,1,3 # needs a random row and a file type: 3: startupConfig, 4: runningConfig
|
||||
Cisco_ccCopyDestFileType = 1,3,6,1,4,1,9,9,96,1,1,1,1,4 # needs a random row and a file type: 3: startupConfig, 4: runningConfig
|
||||
Cisco_ccCopyEntryRowStatus = 1,3,6,1,4,1,9,9,96,1,1,1,1,14 # needs a random row and a status: 1: starts copying
|
||||
Cisco_ccCopyState = 1,3,6,1,4,1,9,9,96,1,1,1,1,10 # needs a random row; 1: waiting, 2: running, 3: done ok, 4: failed
|
||||
|
||||
CommunityData = cmdgen.CommunityData('cerbere', 'pacadmins')
|
||||
|
||||
def getCMD( host, oid, value=None ):
|
||||
targetAddr = cmdgen.UdpTransportTarget((host, 161))
|
||||
|
||||
if value != None:
|
||||
errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().getCmd(
|
||||
CommunityData, targetAddr, oid + ( value, )
|
||||
)
|
||||
else:
|
||||
errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().getCmd(
|
||||
CommunityData, targetAddr, oid
|
||||
)
|
||||
|
||||
return (errorIndication, errorStatus, errorIndex, varBinds)
|
||||
|
||||
def setCMD( host, oid, value):
|
||||
targetAddr = cmdgen.UdpTransportTarget((host, 161))
|
||||
errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().setCmd(
|
||||
CommunityData, targetAddr, ( oid , value )
|
||||
)
|
||||
return (errorIndication, errorStatus, errorIndex, varBinds)
|
||||
|
||||
def writeMemory( host ):
|
||||
row = random.randrange(1, 10)
|
||||
|
||||
errorIndication, errorStatus, errorIndex, varBinds = setCMD( host, Cisco_ccCopySourceFileType + (row,), rfc1902.Integer(4) )
|
||||
source_result = { 'errorIndication': errorIndication, 'errorStatus': errorStatus, 'errorIndex': errorIndex, 'value': varBinds}
|
||||
|
||||
errorIndication, errorStatus, errorIndex, varBinds = setCMD( host, Cisco_ccCopyDestFileType + (row,), rfc1902.Integer(3) )
|
||||
dest_result = { 'errorIndication': errorIndication, 'errorStatus': errorStatus, 'errorIndex': errorIndex, 'value': varBinds}
|
||||
|
||||
errorIndication, errorStatus, errorIndex, varBinds = setCMD( host, Cisco_ccCopyEntryRowStatus + (row,), rfc1902.Integer(1) )
|
||||
dest_result = { 'errorIndication': errorIndication, 'errorStatus': errorStatus, 'errorIndex': errorIndex, 'value': varBinds}
|
||||
|
||||
ok = False
|
||||
while not ok:
|
||||
errorIndication, errorStatus, errorIndex, varBinds = getCMD( host, Cisco_ccCopyState + (row,) )
|
||||
state_result = { 'errorIndication': errorIndication, 'errorStatus': errorStatus, 'errorIndex': errorIndex, 'value': varBinds}
|
||||
if not state_result['value']:
|
||||
state_result['value']=0
|
||||
return state_result
|
||||
else:
|
||||
tmp=state_result['value']
|
||||
state_result['value']=tmp[0][1]
|
||||
if state_result['value'] == 3 or state_result['value'] == 4:
|
||||
ok = True
|
||||
return state_result
|
||||
|
||||
|
||||
def wr_mem(switch):
|
||||
wr_mem_result = writeMemory( switch )
|
||||
if wr_mem_result['value'] == 3:
|
||||
print "La sauvegarde du switch "+switch+" a réussi."
|
||||
else:
|
||||
print "La sauvegarde du switch "+switch+" a échoué."
|
||||
print "Pour information: "
|
||||
print wr_mem_result
|
||||
return wr_mem_result
|
||||
|
||||
i = 1
|
||||
while i < len(sys.argv):
|
||||
wr_mem(sys.argv[i])
|
||||
i = i+1
|
||||
|
24
camembert-before-ldap/.htaccess
Normal file
24
camembert-before-ldap/.htaccess
Normal file
@ -0,0 +1,24 @@
|
||||
ErrorDocument 401 /denied.php
|
||||
ErrorDocument 403 /denied.php
|
||||
ErrorDocument 404 /404.php
|
||||
# Customized error messages.
|
||||
#ErrorDocument 404 /var/www/index.php
|
||||
|
||||
# Various rewrite rules.
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine on
|
||||
|
||||
# If your site can be accessed both with and without the 'www.' prefix, you
|
||||
# can use one of the following settings to redirect users to your preferred
|
||||
# URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
|
||||
#
|
||||
# To redirect all users to access the site WITH the 'www.' prefix,
|
||||
# (http://example.com/... will be redirected to http://www.example.com/...)
|
||||
# adapt and uncomment the following:
|
||||
# RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
|
||||
# RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
|
||||
|
||||
RewriteCond %{HTTP_HOST} ^camembert$ [NC]
|
||||
RewriteRule ^(.*)$ http://camembert.pacaterie.u-psud.fr/$1 [L,R=301]
|
||||
|
||||
</IfModule>
|
2
camembert-before-ldap/.htpasswd
Normal file
2
camembert-before-ldap/.htpasswd
Normal file
@ -0,0 +1,2 @@
|
||||
test:y0Uiblabl6ciNo
|
||||
test2:B0blay5Ez.qE.
|
10
camembert-before-ldap/404.php
Normal file
10
camembert-before-ldap/404.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
$page_name = "Page introuvable";
|
||||
|
||||
include "inc/inc.header.php";
|
||||
?>
|
||||
|
||||
<p class="error">La page que vous avez demandé est introuvable.</p>
|
||||
|
||||
<?php include "inc/inc.footer.php"; ?>
|
||||
|
32
camembert-before-ldap/anomalies.php
Normal file
32
camembert-before-ldap/anomalies.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php $time0 = 1372100461; ?><h5>Interfaces en ERR-DIS :</h5><ul>
|
||||
<li><a href="interface.php?id=353">Ss3.pacaterie.u-psud.fr / FastEthernet0/22</a></li>
|
||||
</ul><h5>Incohérence DHCP-ARP :</h5><ul>
|
||||
</ul><h5>Incohérence DHCP-Sticky :</h5><ul>
|
||||
<li><a href="findmac.php?mac=00:1d:09:77:e2:5f">00:1d:09:77:e2:5f</a></li>
|
||||
<li><a href="findmac.php?mac=b4:99:ba:c3:64:bb">b4:99:ba:c3:64:bb</a></li>
|
||||
<li><a href="findmac.php?mac=00:1e:68:60:20:0c">00:1e:68:60:20:0c</a></li>
|
||||
<li><a href="findmac.php?mac=00:09:2d:74:9e:be">00:09:2d:74:9e:be</a></li>
|
||||
<li><a href="findmac.php?mac=70:f1:a1:c2:66:a6">70:f1:a1:c2:66:a6</a></li>
|
||||
<li><a href="findmac.php?mac=00:16:d4:e1:8b:c6">00:16:d4:e1:8b:c6</a></li>
|
||||
<li><a href="findmac.php?mac=00:21:00:80:f0:b4">00:21:00:80:f0:b4</a></li>
|
||||
<li><a href="findmac.php?mac=00:16:ea:a6:84:90">00:16:ea:a6:84:90</a></li>
|
||||
<li><a href="findmac.php?mac=00:13:02:26:aa:9c">00:13:02:26:aa:9c</a></li>
|
||||
<li><a href="findmac.php?mac=b4:07:f9:88:de:bb">b4:07:f9:88:de:bb</a></li>
|
||||
<li><a href="findmac.php?mac=00:22:64:6f:38:52">00:22:64:6f:38:52</a></li>
|
||||
<li><a href="findmac.php?mac=00:26:b6:e9:e0:cc">00:26:b6:e9:e0:cc</a></li>
|
||||
<li><a href="findmac.php?mac=d8:a2:5e:8d:e7:d7">d8:a2:5e:8d:e7:d7</a></li>
|
||||
<li><a href="findmac.php?mac=00:1f:16:a5:90:1f">00:1f:16:a5:90:1f</a></li>
|
||||
<li><a href="findmac.php?mac=64:a7:69:43:55:b2">64:a7:69:43:55:b2</a></li>
|
||||
<li><a href="findmac.php?mac=5c:ac:4c:5a:d1:f6">5c:ac:4c:5a:d1:f6</a></li>
|
||||
<li><a href="findmac.php?mac=00:1d:09:77:c2:42">00:1d:09:77:c2:42</a></li>
|
||||
<li><a href="findmac.php?mac=00:1d:09:77:c2:13">00:1d:09:77:c2:13</a></li>
|
||||
<li><a href="findmac.php?mac=00:0f:1f:e0:3e:f1">00:0f:1f:e0:3e:f1</a></li>
|
||||
<li><a href="findmac.php?mac=00:1d:09:77:d8:29">00:1d:09:77:d8:29</a></li>
|
||||
<li><a href="findmac.php?mac=00:1d:09:77:c2:1c">00:1d:09:77:c2:1c</a></li>
|
||||
<li><a href="findmac.php?mac=00:0c:f1:9a:ce:bf">00:0c:f1:9a:ce:bf</a></li>
|
||||
<li><a href="findmac.php?mac=00:0d:56:c8:0f:cd">00:0d:56:c8:0f:cd</a></li>
|
||||
<li><a href="findmac.php?mac=10:bf:48:35:ca:ac">10:bf:48:35:ca:ac</a></li>
|
||||
<li><a href="findmac.php?mac=d0:df:9a:a8:8d:e7">d0:df:9a:a8:8d:e7</a></li>
|
||||
<li><a href="findmac.php?mac=a0:0b:ba:25:18:cc">a0:0b:ba:25:18:cc</a></li>
|
||||
<li><a href="findmac.php?mac=08:60:6e:38:35:11">08:60:6e:38:35:11</a></li>
|
||||
</ul>
|
BIN
camembert-before-ldap/arrow.gif
Normal file
BIN
camembert-before-ldap/arrow.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 847 B |
BIN
camembert-before-ldap/arrow2.gif
Normal file
BIN
camembert-before-ldap/arrow2.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 839 B |
86
camembert-before-ldap/cam_users.php
Normal file
86
camembert-before-ldap/cam_users.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
$page_name = "Utilisateurs";
|
||||
include "inc/roles.php";
|
||||
//include "inc/inc.db.php"; ConnectDB();
|
||||
|
||||
if(!$roles['roles']) {
|
||||
include "denied.php";
|
||||
exit();
|
||||
}
|
||||
|
||||
include "inc/inc.header.php";
|
||||
|
||||
if(isset($_GET['id'])) {
|
||||
$r = pg_query("SELECT iduser, login, groupe FROM cam_user WHERE iduser = ".$_GET['id']);
|
||||
if($a = pg_fetch_array($r)) {
|
||||
if(isset($_GET['del']) && $_GET['del'] == 1) {
|
||||
pg_query("DELETE FROM cam_user WHERE iduser = ".$a['iduser']);
|
||||
pg_query("DELETE FROM id WHERE idcam_user = ".$a['iduser']);
|
||||
echo "<p>User <b>".$a['login']."</b> supprimé.</p>\n";
|
||||
}
|
||||
else {
|
||||
if(isset($_GET['group'])) {
|
||||
pg_query("UPDATE cam_user SET groupe = ".$_GET['group']." WHERE iduser = ".$a['iduser']);
|
||||
$a['groupe'] = $_GET['group'];
|
||||
// insertion dans la trésorerie
|
||||
$roles2 = array();
|
||||
$r = pg_query("SELECT login FROM cam_user WHERE iduser = ".$a['iduser']);
|
||||
$login = pg_fetch_array($r);
|
||||
get_roles($login[0], $roles2);
|
||||
if ($roles2['inscription']) {
|
||||
$r = pg_query("SELECT * FROM account WHERE iduser = ".$a['iduser']);
|
||||
// si n'existe pas déjà dans la trésorerie
|
||||
if (! $a2 = pg_fetch_array($r)) {
|
||||
$r = pg_query("SELECT iduser FROM id WHERE idcam_user = ".$a['iduser']);
|
||||
if ($a3 = pg_fetch_array($r)) {
|
||||
$r = pg_query("SELECT nom, prenom FROM user_pac WHERE iduser = ".$a3['iduser']);
|
||||
$a4 = pg_fetch_array($r);
|
||||
pg_query("INSERT INTO account(iduser, nom, prenom, amount) VALUES('".$a['iduser']."', '".$a4['nom']."', '".$a4['prenom']."', 0)");
|
||||
}
|
||||
// else wtf !?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo "<h3>".$a['login']."</h3>\n";
|
||||
echo "<blockquote><p><form method=\"get\" action=\"\">Groupe : <select name=\"group\">\n";
|
||||
$r = pg_query("SELECT idgroupe, name FROM groupe ORDER BY idgroupe");
|
||||
while($a2 = pg_fetch_array($r)) {
|
||||
echo "<option value=\"".$a2['idgroupe']."\" ";
|
||||
if($a2['idgroupe'] == $a['groupe'])
|
||||
echo "selected=\"selected\"";
|
||||
echo ">".$a2['name']."</option>\n";
|
||||
}
|
||||
echo "</select><input type=\"hidden\" name=\"id\" value=\"".$a['iduser']."\" /><input type=\"submit\" /></form></p></blockquote>\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
echo "<p class=\"error\">Cet id n'existe pas</p>\n";
|
||||
}
|
||||
|
||||
?>
|
||||
<h3>Liste des utilisateurs</h3>
|
||||
<blockquote>
|
||||
<?php
|
||||
$r = pg_query("SELECT iduser, login, name FROM cam_user u, groupe g WHERE groupe = idgroupe ORDER BY iduser");
|
||||
if($a = pg_fetch_array($r)) {
|
||||
?>
|
||||
<table class="list" cellpadding="1" cellspacing="1"><tr><th width="20">id</th><th width="100">login</th><th width="30">chambre</th><th width="50">groupe</th><th width="30">suppr</th></tr>
|
||||
<?php
|
||||
$bline = false;
|
||||
while($a) {
|
||||
$r2 = pg_query("SELECT r.idroom, r.name FROM user_pac u, id i, room r WHERE i.idcam_user = ".$a['iduser']." AND u.iduser = i.iduser AND u.idroom = r.idroom");
|
||||
$a2 = pg_fetch_array($r2);
|
||||
echo "<tr class=\"normal"; if($bline) echo "2";
|
||||
echo "\"><td>".$a['iduser']."</td><td><a href=\"?id=".$a['iduser']."\">".$a['login']."</a></td><td><a href=\"room.php?id=${a2['idroom']}\">".$a2['name']."</a></td><td>".$a['name']."</td>";
|
||||
echo "<td><a href=\"?id=".$a['iduser']."&del=1\">suppr</a></td></tr>\n";
|
||||
$a = pg_fetch_array($r);
|
||||
$bline = !$bline;
|
||||
}
|
||||
echo "</table>\n";
|
||||
}
|
||||
?>
|
||||
</blockquote>
|
||||
<?php
|
||||
include "inc/inc.footer.php";
|
||||
?>
|
234
camembert-before-ldap/comp.php
Normal file
234
camembert-before-ldap/comp.php
Normal file
@ -0,0 +1,234 @@
|
||||
<?php
|
||||
$page_name = "Machine";
|
||||
include "inc/roles.php";
|
||||
|
||||
function FormNew($user) {
|
||||
$r = pg_query("SELECT nom, prenom FROM user_pac WHERE iduser = $user");
|
||||
$a = pg_fetch_array($r);
|
||||
if(!$a) {
|
||||
echo "<p class=\"error\">Erreur : cet utilisateur n'existe pas</p>\n";
|
||||
return;
|
||||
}
|
||||
$name = "pc-de-".str_replace(" ", "-", strtolower($a['prenom']));
|
||||
$r = pg_query("SELECT name FROM computer");
|
||||
$a = pg_fetch_all_columns($r);
|
||||
$i = 2;
|
||||
while(in_array($name, $a)) {
|
||||
$name .= $i;
|
||||
$i++;
|
||||
}
|
||||
?>
|
||||
<h3>Nouvelle machine pour <?php echo $a['nom']." ".$a['prenom']; ?></h3>
|
||||
<form action="" method="post"><input type="hidden" name="user" value="<?php echo $user; ?>" /><table>
|
||||
<tr><td>Nom de machine</td><td><input type="text" name="name" value="<?php echo $name; ?>"/></td></tr>
|
||||
<tr><td>Adresse MAC</td><td><input type="text" name="mac0" maxlength="2" size="1" /> : <input type="text" name="mac1" maxlength="2" size="1" /> :
|
||||
<input type="text" name="mac2" maxlength="2" size="1" /> : <input type="text" name="mac3" maxlength="2" size="1" /> :
|
||||
<input type="text" name="mac4" maxlength="2" size="1" /> : <input type="text" name="mac5" maxlength="2" size="1" /></td></tr>
|
||||
<tr><td><input type="submit" /></td><td></td></tr></table></form>
|
||||
<?php
|
||||
}
|
||||
|
||||
function FormEdit($comp) {
|
||||
$r = pg_query("SELECT idcomp, name, mac FROM computer WHERE idcomp = $comp");
|
||||
$a = pg_fetch_array($r);
|
||||
if(!$a) {
|
||||
echo "<p class=\"error\">Erreur : cette machine n'existe pas</p>\n";
|
||||
return;
|
||||
}
|
||||
$mac = explode(":", strtoupper($a['mac']));
|
||||
?>
|
||||
<h3>Modification de machine</h3>
|
||||
<form action="" method="post"><input type="hidden" name="comp" value="<?php echo $comp; ?>" /><table>
|
||||
<tr><td>Nom de machine</td><td><input type="text" name="name" value="<?php echo $a['name']; ?>" /></td></tr>
|
||||
<tr><td>Adresse MAC</td><td><input type="text" name="mac0" maxlength="2" size="1" value="<?php echo $mac[0]; ?>" /> :
|
||||
<input type="text" name="mac1" maxlength="2" size="1" value="<?php echo $mac[1]; ?>" /> :
|
||||
<input type="text" name="mac2" maxlength="2" size="1" value="<?php echo $mac[2]; ?>" /> :
|
||||
<input type="text" name="mac3" maxlength="2" size="1" value="<?php echo $mac[3]; ?>" /> :
|
||||
<input type="text" name="mac4" maxlength="2" size="1" value="<?php echo $mac[4]; ?>" /> :
|
||||
<input type="text" name="mac5" maxlength="2" size="1" value="<?php echo $mac[5]; ?>" /></td></tr>
|
||||
<tr><td><input type="submit" /></td><td></td></tr></table></form>
|
||||
<?php
|
||||
}
|
||||
|
||||
function ValidateNew($user) {
|
||||
$r = pg_query("SELECT nom, prenom FROM user_pac WHERE iduser = $user");
|
||||
$a = pg_fetch_array($r);
|
||||
if(!$a)
|
||||
return "Erreur : cet utilisateur n'existe pas";
|
||||
|
||||
if(!isset($_POST['name']) || !isset($_POST['mac0']) || !isset($_POST['mac1']) || !isset($_POST['mac2']) || !isset($_POST['mac3']) || !isset($_POST['mac4'])
|
||||
|| !isset($_POST['mac5']) || $_POST['name'] == "" || $_POST['mac0'] == "" || $_POST['mac1'] == "" || $_POST['mac2'] == "" || $_POST['mac3'] == ""
|
||||
|| $_POST['mac4'] == "" || $_POST['mac5'] == "")
|
||||
return "Erreur : formulaire incomplet";
|
||||
|
||||
if(preg_match("/^[a-z0-9-]+$/", $_POST['name']) == 0)
|
||||
return "Erreur : nom de machine incorrect. Sont autorisés : les lettres minuscules, les chiffres et le trait d'union";
|
||||
|
||||
$mac = $_POST['mac0'].":".$_POST['mac1'].":".$_POST['mac2'].":".$_POST['mac3'].":".$_POST['mac4'].":".$_POST['mac5'];
|
||||
if(preg_match("/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/", $mac) == 0)
|
||||
return "Erreur : MAC incorrecte. Sont autorisés : les chiffres et les lettres de A à F. Deux caractères par champ.";
|
||||
|
||||
$r = pg_query("SELECT idcomp FROM computer WHERE name = '".$_POST['name']."' OR mac = '$mac'");
|
||||
$a = pg_fetch_array($r);
|
||||
if($a)
|
||||
return "Erreur : il y a deja une machine avec ce nom ou cette adresse MAC";
|
||||
|
||||
$r = pg_query("SELECT MAX(idcomp) FROM computer");
|
||||
if($a = pg_fetch_array($r))
|
||||
$newid = $a[0]+1;
|
||||
else
|
||||
$newid = 1;
|
||||
$r = pg_query("SELECT ip FROM ip_user WHERE free = '1' ORDER BY ip LIMIT 1");
|
||||
$a = pg_fetch_array($r);
|
||||
$ip = $a['ip'];
|
||||
pg_query("INSERT INTO computer(idcomp, name, mac, iduser, ip) VALUES($newid, '".$_POST['name']."', '$mac', $user, '$ip')");
|
||||
pg_query("UPDATE ip_user SET free = '0' WHERE ip = '$ip'");
|
||||
|
||||
UpdateInterface($user);
|
||||
return true;
|
||||
}
|
||||
|
||||
function ValidateEdit($comp) {
|
||||
$r = pg_query("SELECT iduser FROM computer WHERE idcomp = $comp");
|
||||
$a = pg_fetch_array($r);
|
||||
if(!$a)
|
||||
return "Erreur : cette machine n'existe pas";
|
||||
$user = $a['iduser'];
|
||||
|
||||
if(!isset($_POST['name']) || !isset($_POST['mac0']) || !isset($_POST['mac1']) || !isset($_POST['mac2']) || !isset($_POST['mac3']) || !isset($_POST['mac4'])
|
||||
|| !isset($_POST['mac5']) || $_POST['name'] == "" || $_POST['mac0'] == "" || $_POST['mac1'] == "" || $_POST['mac2'] == "" || $_POST['mac3'] == ""
|
||||
|| $_POST['mac4'] == "" || $_POST['mac5'] == "")
|
||||
return "Erreur : formulaire incomplet";
|
||||
|
||||
if(preg_match("/^[a-z0-9-]+$/", $_POST['name']) == 0)
|
||||
return "Erreur : nom de machine incorrect. Sont autorisés : les lettres minuscules, les chiffres et le trait d'union";
|
||||
|
||||
$mac = $_POST['mac0'].":".$_POST['mac1'].":".$_POST['mac2'].":".$_POST['mac3'].":".$_POST['mac4'].":".$_POST['mac5'];
|
||||
if(preg_match("/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/", $mac) == 0)
|
||||
return "Erreur : MAC incorrecte. Sont autorisés : les chiffres et les lettres de A à F. Deux caractères par champ.";
|
||||
|
||||
$r = pg_query("SELECT idcomp FROM computer WHERE (name = '".$_POST['name']."' OR mac = '$mac') AND idcomp <> $comp");
|
||||
$a = pg_fetch_array($r);
|
||||
if($a)
|
||||
return "Erreur : il y a deja une machine avec ce nom ou cette adresse MAC";
|
||||
|
||||
pg_query("UPDATE computer SET name = '".$_POST['name']."', mac = '$mac' WHERE idcomp = $comp");
|
||||
|
||||
UpdateInterface($user);
|
||||
return true;
|
||||
}
|
||||
|
||||
function DeleteComp($comp) {
|
||||
$r = pg_query("SELECT iduser FROM computer WHERE idcomp = $comp");
|
||||
$a = pg_fetch_array($r);
|
||||
if(!$a)
|
||||
return false;
|
||||
|
||||
pg_query("UPDATE ip_user SET free = '1' WHERE ip IN(SELECT ip FROM computer WHERE idcomp = $comp)");
|
||||
pg_query("DELETE FROM computer WHERE idcomp = $comp");
|
||||
UpdateInterface($a['iduser']);
|
||||
return $a['iduser'];
|
||||
}
|
||||
|
||||
function UpdateInterface($user) {
|
||||
$r = pg_query("SELECT idinterface, datedeco, certif FROM room r, user_pac u WHERE u.idroom = r.idroom AND iduser = $user");
|
||||
$a = pg_fetch_array($r);
|
||||
$idif = $a['idinterface'];
|
||||
$ddeco = explode("-", $a['datedeco']);
|
||||
$adeco = $ddeco[0];
|
||||
$mdeco = $ddeco[1];
|
||||
$certif = ($a['certif'] == 't' || (date("n") >= 9 && date("n") < 11));
|
||||
|
||||
$r = pg_query("SELECT MAX(idaction) FROM action");
|
||||
$a = pg_fetch_array($r);
|
||||
if($a)
|
||||
$newid = $a[0]+1;
|
||||
else
|
||||
$newid = 1;
|
||||
|
||||
$r = pg_query("SELECT COUNT(*) FROM computer WHERE iduser = $user");
|
||||
$a = pg_fetch_array($r);
|
||||
$nb = max(1, $a[0]);
|
||||
|
||||
pg_query("INSERT INTO action(idaction, idinterface, numaction) VALUES($newid, $idif, 0)"); $newid++;
|
||||
pg_query("INSERT INTO action(idaction, idinterface, numaction, option) VALUES($newid, $idif, 3, '$nb')"); $newid++;
|
||||
$r = pg_query("SELECT mac FROM fdb WHERE idinterface = $idif AND type = 2 AND datelast = (SELECT MAX(datelast) FROM fdb)");
|
||||
while($a = pg_fetch_array($r)) {
|
||||
pg_query("INSERT INTO action(idaction, idinterface, numaction, option) VALUES($newid, $idif, 4, '".$a['mac']."')");
|
||||
$newid++;
|
||||
}
|
||||
if(($adeco > date("Y") || $mdeco >= date("m")) && $certif)
|
||||
pg_query("INSERT INTO action(idaction, idinterface, numaction) VALUES($newid, $idif, 1)");
|
||||
}
|
||||
|
||||
if(isset($_POST['user']) && $_POST['user'] != "") {
|
||||
if($roles['inscription']) {
|
||||
$val = ValidateNew($_POST['user']);
|
||||
if($val === true)
|
||||
header("Location: user.php?id=".$_POST['user']);
|
||||
else {
|
||||
include "inc/inc.header.php";
|
||||
echo "<p class=\"error\">$val</p>\n";
|
||||
}
|
||||
}
|
||||
else {
|
||||
include "denied.php";
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if(isset($_POST['comp']) && $_POST['comp'] != "") {
|
||||
if($roles['edit_comp']) {
|
||||
$val = ValidateEdit($_POST['comp']);
|
||||
if($val === true) {
|
||||
$r = pg_query("SELECT iduser FROM computer WHERE idcomp = ".$_POST['comp']);
|
||||
$a = pg_fetch_array($r);
|
||||
header("Location: user.php?id=".$a['iduser']);
|
||||
}
|
||||
else {
|
||||
include "inc/inc.header.php";
|
||||
echo "<p class=\"error\">$val</p>\n";
|
||||
}
|
||||
}
|
||||
else {
|
||||
include "denied.php";
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if(isset($_GET['user']) && $_GET['user'] != "") {
|
||||
if($roles['inscription']) {
|
||||
include "inc/inc.header.php";
|
||||
FormNew($_GET['user']);
|
||||
}
|
||||
else {
|
||||
include "denied.php";
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if(isset($_GET['id']) && $_GET['id'] != "") {
|
||||
if($roles['edit_comp']) {
|
||||
include "inc/inc.header.php";
|
||||
FormEdit($_GET['id']);
|
||||
}
|
||||
else {
|
||||
include "denied.php";
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if(isset($_GET['del']) && $_GET['del'] != "") {
|
||||
if($roles['inscription']) {
|
||||
$user = DeleteComp($_GET['del']);
|
||||
if($user === false) {
|
||||
include "inc/inc.header.php";
|
||||
echo "<p class=\"error\">Erreur : cette machine n'existe pas</p>\n";
|
||||
}
|
||||
else
|
||||
header("Location: user.php?id=$user");
|
||||
}
|
||||
else {
|
||||
include "denied.php";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
include "inc/inc.footer.php";
|
||||
?>
|
37
camembert-before-ldap/denied.php
Normal file
37
camembert-before-ldap/denied.php
Normal file
@ -0,0 +1,37 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Camembert :: Accès refusé</title>
|
||||
<style type="text/css">
|
||||
body {
|
||||
background-color: #F0F0F0;
|
||||
font-family: Tahoma, Arial, sans serif;
|
||||
font-size: 12;
|
||||
}
|
||||
h1,h2 {
|
||||
text-align: center;
|
||||
margin: 3px;
|
||||
}
|
||||
.error {
|
||||
color: #CC0000;
|
||||
font-weight: bold;
|
||||
}
|
||||
.footer {
|
||||
font-size: 10;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Camembert</h1>
|
||||
<h2>Accès refusé</h2>
|
||||
<hr>
|
||||
|
||||
<p class="error">Vous n'êtes pas autorisé à accéder à cette page.</p>
|
||||
|
||||
<hr>
|
||||
<p class="footer"><b>Camembert version 42e^(-petitpois)</b><br>
|
||||
Alban 'spl0k' FERON</p>
|
||||
</body>
|
||||
</html>
|
||||
|
10
camembert-before-ldap/disconnected_user.php
Normal file
10
camembert-before-ldap/disconnected_user.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
$page_name = "Déconnecté";
|
||||
|
||||
include "inc/roles.php";
|
||||
include "inc/inc.header.php";
|
||||
include "libfind.php";
|
||||
|
||||
|
||||
|
||||
include "inc/inc.footer.php"; ?>
|
100
camembert-before-ldap/findip.php
Normal file
100
camembert-before-ldap/findip.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
$page_name = "Recherche d'IP";
|
||||
|
||||
$ip = $_GET['ip'];
|
||||
if($ip == '')
|
||||
header("Location: index.php");
|
||||
|
||||
include "inc/roles.php";
|
||||
include "inc/inc.header.php";
|
||||
|
||||
?>
|
||||
|
||||
<form action="findip.php">Chercher une adresse IP
|
||||
<input type="text" name="ip" value="<?php echo $ip; ?>">
|
||||
<input type="submit" value="Rechercher">
|
||||
</form>
|
||||
<blockquote>
|
||||
|
||||
<?php
|
||||
|
||||
$r = pg_query("SELECT MAX(datelast) FROM ip");
|
||||
$datelast = pg_fetch_array($r);
|
||||
$datelast = $datelast[0];
|
||||
|
||||
// IPs associées à un équipement
|
||||
$r = pg_query("SELECT m.idmateriel, hostname, ip.datecreation, ip.datelast
|
||||
FROM materiel m, ip WHERE m.idmateriel = ip.idmateriel AND ip = '$ip' ORDER BY ip.datelast DESC");
|
||||
$a = pg_fetch_array($r);
|
||||
if($a) {
|
||||
?>
|
||||
<p>L'adresse IP <b><?php echo $ip; ?></b> a été associée au matériel suivant</p>
|
||||
<table class="list" cellspacing="1" cellpadding="1">
|
||||
<tr><th width="160">Matériel</th><th width="140">Associée le</th><th width="140">Jusqu'au</th></tr>
|
||||
<?php
|
||||
$bline = false;
|
||||
while($a) {
|
||||
if($a[3] == $datelast)
|
||||
$mat = "<b>${a[1]}</b>";
|
||||
else
|
||||
$mat = $a[1];
|
||||
echo "<tr class=\"normal".($bline?2:"")."\"><td><a href=\"materiel.php?id=${a[0]}\">$mat</a></td>";
|
||||
echo "<td>".date("D d/m/Y H:i", $a[2])."</td><td>".date("D d/m/Y H:i", $a[3])."</td></tr>\n";
|
||||
$bline = !$bline;
|
||||
|
||||
$a = pg_fetch_array($r);
|
||||
}
|
||||
echo "</table>\n";
|
||||
}
|
||||
|
||||
// IP dans le cache ARP
|
||||
$r = pg_query("SELECT mac, foundon, hostname, a.datefirst, a.datelast
|
||||
FROM arpcache a, materiel m WHERE foundon = idmateriel AND ip = '$ip' ORDER BY a.datelast DESC");
|
||||
$a = pg_fetch_array($r);
|
||||
if($a) {
|
||||
?>
|
||||
<p>L'adresse IP <b><?php echo $ip; ?></b> a été associée aux adresses MAC suivantes</p>
|
||||
<table class="list" cellspacing="1" cellpadding="1">
|
||||
<tr><th width="120">MAC</th><th width="160">Associé par</th><th width="140">Associée le</th><th width="140">Jusqu'au</th></tr>
|
||||
<?php
|
||||
$bline = false;
|
||||
while($a) {
|
||||
if($a[4] == $datelast)
|
||||
$mac = "<b>${a[0]}</b>";
|
||||
else
|
||||
$mac = $a[0];
|
||||
echo "<tr class=\"normal".($bline?2:"")."\"><td><a href=\"findmac.php?mac=${a[0]}\">$mac</a></td>";
|
||||
echo "<td><a href=\"materiel.php?id=${a[1]}\">${a[2]}</a></td>";
|
||||
echo "<td>".date("D d/m/Y H:i", $a[3])."</td><td>".date("D d/m/Y H:i", $a[4])."</td></tr>\n";
|
||||
$bline = !$bline;
|
||||
|
||||
$a = pg_fetch_array($r);
|
||||
}
|
||||
echo "</table>\n";
|
||||
}
|
||||
|
||||
// IP dans le DHCP
|
||||
$r = pg_query("SELECT u.iduser, nom, prenom, c.name, r.idroom, r.name FROM computer c, user_pac u, room r
|
||||
WHERE c.iduser = u.iduser AND u.idroom = r.idroom AND ip = '$ip'");
|
||||
$a = pg_fetch_array($r);
|
||||
if($a) {
|
||||
?>
|
||||
<p>L'adresse IP <b><?php echo $ip; ?></b> est présente dans le DHCP</p>
|
||||
<table class="list" cellspacing="1" cellpadding="1">
|
||||
<tr><th width="160">Utilisateur</th><th width="60">Chambre</th><th width="100">Nom de machine</th></tr>
|
||||
<?php
|
||||
while($a) {
|
||||
$bline = false;
|
||||
echo "<tr class=\"normal".($bline?2:"")."\"><td><a href=\"user.php?id=".$a[0]."\">".$a[1]." ".$a[2]."</a></td>";
|
||||
echo "<td><a href=\"room.php?id=".$a[4]."\">".$a[5]."</a></td><td>".$a[3]."</td></tr>\n";
|
||||
$bline = !$bline;
|
||||
|
||||
$a = pg_fetch_array($r);
|
||||
}
|
||||
echo "</table>\n";
|
||||
}
|
||||
|
||||
echo "</blockquote>\n";
|
||||
include "inc/inc.footer.php";
|
||||
|
||||
?>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user