commit b0110de18050dd8148c227cfadd2f6ffbea3c13f
Author: yohan <783b8c87@scimetis.net>
Date: Sun Apr 14 20:37:40 2019 +0200
Initial commit.
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..13f86e6
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+pg_dump_camembert.dump
diff --git a/backend/camembert/Makefile b/backend/camembert/Makefile
new file mode 100644
index 0000000..009f1c2
--- /dev/null
+++ b/backend/camembert/Makefile
@@ -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
diff --git a/backend/camembert/action.cpp b/backend/camembert/action.cpp
new file mode 100644
index 0000000..77541af
--- /dev/null
+++ b/backend/camembert/action.cpp
@@ -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);
+}
+
diff --git a/backend/camembert/action.h b/backend/camembert/action.h
new file mode 100644
index 0000000..8c2d7c0
--- /dev/null
+++ b/backend/camembert/action.h
@@ -0,0 +1,24 @@
+#ifndef __CAMEMBERT_ACTION_H
+#define __CAMEMBERT_ACTION_H
+
+#include
+
+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 */
+
diff --git a/backend/camembert/action.o b/backend/camembert/action.o
new file mode 100644
index 0000000..8b1c2f0
Binary files /dev/null and b/backend/camembert/action.o differ
diff --git a/backend/camembert/arp.cpp b/backend/camembert/arp.cpp
new file mode 100644
index 0000000..5b9d51f
--- /dev/null
+++ b/backend/camembert/arp.cpp
@@ -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);
+}
diff --git a/backend/camembert/arp.h b/backend/camembert/arp.h
new file mode 100644
index 0000000..7a84ce2
--- /dev/null
+++ b/backend/camembert/arp.h
@@ -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 */
diff --git a/backend/camembert/arp.o b/backend/camembert/arp.o
new file mode 100644
index 0000000..c3a3770
Binary files /dev/null and b/backend/camembert/arp.o differ
diff --git a/backend/camembert/camembert.h b/backend/camembert/camembert.h
new file mode 100644
index 0000000..a5da705
--- /dev/null
+++ b/backend/camembert/camembert.h
@@ -0,0 +1,30 @@
+#ifndef __CAMEMBERT_H
+#define __CAMEMBERT_H
+
+#include
+
+#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 */
diff --git a/backend/camembert/fdb.cpp b/backend/camembert/fdb.cpp
new file mode 100644
index 0000000..018b163
--- /dev/null
+++ b/backend/camembert/fdb.cpp
@@ -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);
+
+}
+
diff --git a/backend/camembert/fdb.h b/backend/camembert/fdb.h
new file mode 100644
index 0000000..334ec82
--- /dev/null
+++ b/backend/camembert/fdb.h
@@ -0,0 +1,29 @@
+#ifndef __CAMEMBERT_FDB_H
+#define __CAMEMBERT_FDB_H
+
+#include
+#include
+
+// 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 */
+
diff --git a/backend/camembert/fdb.o b/backend/camembert/fdb.o
new file mode 100644
index 0000000..0f044f7
Binary files /dev/null and b/backend/camembert/fdb.o differ
diff --git a/backend/camembert/functions.cpp b/backend/camembert/functions.cpp
new file mode 100644
index 0000000..f96d1a2
--- /dev/null
+++ b/backend/camembert/functions.cpp
@@ -0,0 +1,465 @@
+#include
+#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);
+}
+
diff --git a/backend/camembert/functions.h b/backend/camembert/functions.h
new file mode 100644
index 0000000..fd560e3
--- /dev/null
+++ b/backend/camembert/functions.h
@@ -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 */
+
diff --git a/backend/camembert/functions.o b/backend/camembert/functions.o
new file mode 100644
index 0000000..8cec1b1
Binary files /dev/null and b/backend/camembert/functions.o differ
diff --git a/backend/camembert/interface.cpp b/backend/camembert/interface.cpp
new file mode 100644
index 0000000..54ac923
--- /dev/null
+++ b/backend/camembert/interface.cpp
@@ -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;
+ }
+ }
+}
+
diff --git a/backend/camembert/interface.h b/backend/camembert/interface.h
new file mode 100644
index 0000000..541d369
--- /dev/null
+++ b/backend/camembert/interface.h
@@ -0,0 +1,97 @@
+#ifndef __CAMEMBERT_INTERFACE_H
+#define __CAMEMBERT_INTERFACE_H
+
+#include
+#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 */
+
diff --git a/backend/camembert/interface.o b/backend/camembert/interface.o
new file mode 100644
index 0000000..76c91c9
Binary files /dev/null and b/backend/camembert/interface.o differ
diff --git a/backend/camembert/ip.cpp b/backend/camembert/ip.cpp
new file mode 100644
index 0000000..c19c81f
--- /dev/null
+++ b/backend/camembert/ip.cpp
@@ -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_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;
+}
diff --git a/backend/camembert/ip.h b/backend/camembert/ip.h
new file mode 100644
index 0000000..718bfb5
--- /dev/null
+++ b/backend/camembert/ip.h
@@ -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
+#include
+#include
+
+#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 */
diff --git a/backend/camembert/ip.o b/backend/camembert/ip.o
new file mode 100644
index 0000000..1dddf85
Binary files /dev/null and b/backend/camembert/ip.o differ
diff --git a/backend/camembert/libkmsnmp/CVS/Entries b/backend/camembert/libkmsnmp/CVS/Entries
new file mode 100644
index 0000000..c445e40
--- /dev/null
+++ b/backend/camembert/libkmsnmp/CVS/Entries
@@ -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
diff --git a/backend/camembert/libkmsnmp/CVS/Repository b/backend/camembert/libkmsnmp/CVS/Repository
new file mode 100644
index 0000000..f00ac4b
--- /dev/null
+++ b/backend/camembert/libkmsnmp/CVS/Repository
@@ -0,0 +1 @@
+libkmsnmp
diff --git a/backend/camembert/libkmsnmp/CVS/Root b/backend/camembert/libkmsnmp/CVS/Root
new file mode 100644
index 0000000..4631372
--- /dev/null
+++ b/backend/camembert/libkmsnmp/CVS/Root
@@ -0,0 +1 @@
+:ext:kindman@www.amc-os.com:/cvsroot/kindmana
diff --git a/backend/camembert/libkmsnmp/Makefile b/backend/camembert/libkmsnmp/Makefile
new file mode 100644
index 0000000..4775e8f
--- /dev/null
+++ b/backend/camembert/libkmsnmp/Makefile
@@ -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
diff --git a/backend/camembert/libkmsnmp/address.cpp b/backend/camembert/libkmsnmp/address.cpp
new file mode 100644
index 0000000..d2f4a89
--- /dev/null
+++ b/backend/camembert/libkmsnmp/address.cpp
@@ -0,0 +1,2446 @@
+/*_############################################################################
+ _##
+ _## address.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.
+
+
+ A D D R E S S. C P P
+
+ ADDRESS CLASS IMPLEMENTATION
+
+ DESIGN + AUTHOR:
+ Peter E. Mellquist
+
+ DESCRIPTION:
+ Implementation file for Address classes.
+
+ LANGUAGE:
+ ANSI C++
+
+ OPERATING SYSTEM(S):
+ MS-Windows Win32
+ BSD UNIX
+
+=====================================================================*/
+char address_cpp_version[]="@(#) SNMP++ $Id: address.cpp,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $";
+
+#include
+#include
+#include
+
+#include "address.h"
+#include "v3.h"
+
+/* Borlands isdigit has a bug */
+#ifdef __BCPLUSPLUS__
+#define my_isdigit(c) ((c) >= '0' && (c) <= '9')
+#else
+#define my_isdigit isdigit
+#endif
+
+#ifdef ADDRESS_DEBUG
+#define ADDRESS_TRACE debugprintf(0, "ADDRESS %p Enter %s", this, __PRETTY_FUNCTION__)
+#define ADDRESS_TRACE2 debugprintf(0, "ADDRESS op Enter %s", __PRETTY_FUNCTION__)
+#else
+#define ADDRESS_TRACE
+#define ADDRESS_TRACE2
+#endif
+
+//=================================================================
+//======== Abstract Address Class Implementation ==================
+//=================================================================
+
+Address::Address()
+ : addr_changed(true), valid_flag(false)
+{
+ ADDRESS_TRACE;
+
+ memset(address_buffer, 0, sizeof(unsigned char)*BUFSIZE);
+}
+
+//------------[ Address::trim_white_space( char * ptr) ]------------
+// destructive trim white space
+void Address::trim_white_space(char *ptr)
+{
+ ADDRESS_TRACE;
+
+ char *tmp = ptr; // init
+ while (*tmp==' ') tmp++; // skip leading white space
+ while (*tmp && (*tmp != ' ')) *ptr++ = *tmp++; // move string to beginning
+ *ptr = 0; // set end of string
+}
+
+//-----------------------------------------------------------------------
+// overloaded equivlence operator, are two addresses equal?
+int operator==(const Address &lhs, const Address &rhs)
+{
+ ADDRESS_TRACE2;
+
+ return (strcmp((const char*)lhs, (const char*)rhs) == 0);
+}
+
+//------------------------------------------------------------------
+// overloaded > operator, is a1 > a2
+int operator>(const Address &lhs, const Address &rhs)
+{
+ ADDRESS_TRACE2;
+
+ return (strcmp((const char*)lhs, (const char*)rhs) > 0);
+}
+
+//-----------------------------------------------------------------
+// overloaded < operator, is a1 < a2
+int operator<(const Address &lhs, const Address &rhs)
+{
+ ADDRESS_TRACE2;
+
+ return (strcmp((const char*)lhs, (const char*)rhs) < 0);
+}
+
+//------------------------------------------------------------------
+// equivlence operator overloaded, are an address and a string equal?
+int operator==(const Address &lhs, const char *rhs)
+{
+ ADDRESS_TRACE2;
+
+ if (!rhs && !lhs.valid())
+ return TRUE;
+ if (strcmp((const char *)lhs, rhs) == 0)
+ return TRUE;
+ return FALSE;
+}
+
+//------------------------------------------------------------------
+// overloaded > , is a > inaddr
+int operator>(const Address &lhs, const char *rhs)
+{
+ ADDRESS_TRACE2;
+
+ if (!rhs)
+ return lhs.valid(); // if lhs valid then > NULL, else invalid !> NULL
+ if (strcmp((const char *)lhs, rhs) > 0)
+ return TRUE;
+ return FALSE;
+}
+
+//------------------------------------------------------------------
+// overloaded >= , is a >= inaddr
+int operator>=(const Address &lhs, const char *rhs)
+{
+ ADDRESS_TRACE2;
+
+ if (!rhs)
+ return TRUE; // always >= NULL
+ if (strcmp((const char *)lhs, rhs) >= 0)
+ return TRUE;
+ return FALSE;
+}
+
+//-----------------------------------------------------------------
+// overloaded < , are an address and a string equal?
+int operator<(const Address &lhs, const char *rhs)
+{
+ ADDRESS_TRACE2;
+
+ if (!rhs)
+ return FALSE; // always >= NULL
+ if (strcmp((const char *)lhs, rhs) < 0)
+ return TRUE;
+ return FALSE;
+}
+
+//-----------------------------------------------------------------
+// overloaded <= , is a <= inaddr
+int operator<=(const Address &lhs, const char *rhs)
+{
+ ADDRESS_TRACE2;
+
+ if (!rhs)
+ return !lhs.valid(); // invalid == NULL, else valid > NULL
+ if (strcmp((const char *)lhs, rhs) <= 0)
+ return TRUE;
+ return FALSE;
+}
+
+//=====================================================================
+//============ IPAddress Implementation ===============================
+//=====================================================================
+
+//-------[ construct an IP address with no agrs ]----------------------
+IpAddress::IpAddress()
+ : Address(), iv_friendly_name_status(0), ip_version(version_ipv4)
+{
+ ADDRESS_TRACE;
+
+ // always initialize what type this object is
+ smival.syntax = sNMP_SYNTAX_IPADDR;
+ smival.value.string.len = IPLEN;
+ smival.value.string.ptr = address_buffer;
+
+ iv_friendly_name[0]=0;
+}
+
+//-------[ construct an IP address with a string ]---------------------
+IpAddress::IpAddress(const char *inaddr)
+ : Address()
+{
+ ADDRESS_TRACE;
+
+ // always initialize what type this object is
+ smival.syntax = sNMP_SYNTAX_IPADDR;
+ smival.value.string.len = IPLEN;
+ smival.value.string.ptr = address_buffer;
+
+ // parse_address initializes valid, address_buffer & iv_friendly_name
+ valid_flag = parse_address(inaddr);
+}
+
+//-----[ IP Address copy constructor ]---------------------------------
+IpAddress::IpAddress(const IpAddress &ipaddr)
+ : iv_friendly_name_status(0), ip_version(ipaddr.ip_version)
+{
+ ADDRESS_TRACE;
+
+ // always initialize what type this object is
+ smival.syntax = sNMP_SYNTAX_IPADDR;
+ smival.value.string.len = ipaddr.smival.value.string.len;
+ smival.value.string.ptr = address_buffer;
+
+ iv_friendly_name[0]=0;
+ valid_flag = ipaddr.valid_flag;
+ if (valid_flag)
+ {
+ // copy the address data
+ MEMCPY(address_buffer, ipaddr.address_buffer, smival.value.string.len);
+ // and the friendly name
+ strcpy(iv_friendly_name, ipaddr.iv_friendly_name);
+
+ if (!ipaddr.addr_changed)
+ {
+ memcpy(output_buffer, ipaddr.output_buffer,
+ sizeof(unsigned char) * OUTBUFF);
+ addr_changed = false;
+ }
+ }
+}
+
+//-----[ construct an IP address with a GenAddress ]---------------------
+IpAddress::IpAddress(const GenAddress &genaddr)
+ : iv_friendly_name_status(0)
+{
+ ADDRESS_TRACE;
+
+ // always initialize what type this object is
+ smival.syntax = sNMP_SYNTAX_IPADDR;
+ smival.value.string.len = IPLEN;
+ smival.value.string.ptr = address_buffer;
+
+ iv_friendly_name[0]=0;
+ output_buffer[0]=0;
+
+ // allow use of an ip or udp genaddress
+ valid_flag = genaddr.valid();
+ if (valid_flag)
+ {
+ if (genaddr.get_type() == type_ip)
+ {
+ // copy in the IP address data
+ *this = genaddr.cast_ipaddress();
+ return;
+ }
+ else if (genaddr.get_type() == type_udp)
+ {
+ // copy in the IP address data
+ *this = genaddr.cast_udpaddress();
+ return;
+ }
+ }
+ valid_flag = false;
+ addr_changed = true;
+}
+
+//-----[ IP Address general = operator ]-------------------------------
+SnmpSyntax& IpAddress::operator=(const SnmpSyntax &val)
+{
+ ADDRESS_TRACE;
+
+ if (this == &val) return *this; // protect against assignment from itself
+
+ addr_changed = true;
+ valid_flag = false; // will get set TRUE if really valid
+ iv_friendly_name[0]=0;
+
+ if (val.valid())
+ {
+ switch (val.get_syntax())
+ {
+ case sNMP_SYNTAX_IPADDR:
+ case sNMP_SYNTAX_OCTETS:
+ if ((((IpAddress &)val).smival.value.string.len == IPLEN) ||
+ (((IpAddress &)val).smival.value.string.len == UDPIPLEN))
+ {
+ MEMCPY(address_buffer,
+ ((IpAddress &)val).smival.value.string.ptr, IPLEN);
+ valid_flag = true;
+ ip_version = version_ipv4;
+ smival.value.string.len = IPLEN;
+ }
+ else if ((((IpAddress &)val).smival.value.string.len == IP6LEN) ||
+ (((IpAddress &)val).smival.value.string.len == UDPIP6LEN))
+ {
+ MEMCPY(address_buffer,
+ ((IpAddress &)val).smival.value.string.ptr, IP6LEN);
+ valid_flag = true;
+ ip_version = version_ipv6;
+ smival.value.string.len = IP6LEN;
+ }
+ break;
+
+ // NOTE: as a value add, other types could have "logical"
+ // mappings, i.e. integer32 and unsigned32
+ }
+ }
+ return *this;
+}
+
+//------[ assignment to another ipaddress object overloaded ]-----------------
+IpAddress& IpAddress::operator=(const IpAddress &ipaddr)
+{
+ ADDRESS_TRACE;
+
+ if (this == &ipaddr) return *this; // protect against assignment from itself
+
+ valid_flag = ipaddr.valid_flag;
+ iv_friendly_name[0]=0;
+
+ if (valid_flag)
+ {
+ if (ipaddr.ip_version == version_ipv4)
+ {
+ MEMCPY(address_buffer, ipaddr.address_buffer, IPLEN);
+ ip_version = version_ipv4;
+ smival.value.string.len = IPLEN;
+ }
+ else
+ {
+ MEMCPY(address_buffer, ipaddr.address_buffer, IP6LEN);
+ ip_version = version_ipv6;
+ smival.value.string.len = IP6LEN;
+ }
+ strcpy(iv_friendly_name, ipaddr.iv_friendly_name);
+
+ if (ipaddr.addr_changed)
+ addr_changed = true;
+ else
+ {
+ memcpy(output_buffer, ipaddr.output_buffer,
+ sizeof(unsigned char) * OUTBUFF);
+ addr_changed = false;
+ }
+ }
+ else
+ addr_changed = true;
+ return *this;
+}
+
+IpAddress& IpAddress::operator=(const char *inaddr)
+{
+ ADDRESS_TRACE;
+
+ valid_flag = parse_address(inaddr);
+ addr_changed = true;
+ return *this;
+}
+
+//-------[ return the friendly name ]----------------------------------
+char *IpAddress::friendly_name(int &status)
+{
+ ADDRESS_TRACE;
+
+ if ((iv_friendly_name[0]==0) && (valid_flag))
+ this->addr_to_friendly();
+ status = iv_friendly_name_status;
+ return iv_friendly_name;
+}
+
+// parse a dotted string
+int IpAddress::parse_dotted_ipstring(const char *inaddr)
+{
+ ADDRESS_TRACE;
+
+ char *ip_token;
+ int token_count=0;
+ unsigned int value;
+ int error_status = FALSE;
+ char temp[30]; // temp buffer for destruction
+ int z,w;
+
+ // check len, an ip can never be bigger than 15
+ // 123456789012345
+ // XXX.XXX.XXX.XXX
+ if (!inaddr || (strlen(inaddr) > 30)) return FALSE;
+
+ strcpy(temp, inaddr);
+ trim_white_space(temp);
+ if (strlen(temp) > 15) return FALSE;
+
+ // must only have three dots strtok will not catch this !
+ char *ptr = temp;
+ int dot_count = 0;
+ while (*ptr != 0)
+ {
+ if (*ptr == '.') dot_count++;
+ ptr++;
+ }
+ if (dot_count != 3)
+ return FALSE;
+
+ // look for dot token separator
+#ifdef linux
+ char* lasts = 0;
+ ip_token = strtok_r((char *) temp,".", &lasts);
+#else
+ ip_token = strtok((char *) temp,".");
+#endif
+
+ // while more tokens..
+ while (ip_token)
+ {
+ // verify that the token is all numerics
+ w = strlen(ip_token);
+ if (w>3) return FALSE;
+ for (z=0;z '9'))
+ return FALSE;
+
+ value = atoi(ip_token);
+ if ((value > 0)&& (value <=255))
+ address_buffer[token_count] = (unsigned char) value;
+ else
+ if (strcmp(ip_token,"0")==0)
+ address_buffer[token_count]= (unsigned char) 0;
+ else
+ error_status = TRUE;
+ token_count++;
+#ifdef linux
+ ip_token = strtok_r(NULL, ".", &lasts);
+#else
+ ip_token = strtok(NULL, ".");
+#endif
+ }
+
+ // gota be four in len
+ if (token_count != 4)
+ return FALSE;
+
+ // any parsing errors?
+ if (error_status)
+ return FALSE;
+
+ ip_version = version_ipv4;
+ smival.value.string.len = IPLEN;
+ return TRUE;
+}
+
+#define ATOI(x) if ((x >= 48) && (x <= 57)) x = x-48; /* 0-9 */ \
+ else if ((x >= 97) && (x <=102)) x = x-87; /* a-f */ \
+ else if ((x >= 65) && (x <= 70)) x = x-55; /* A-F */ \
+ else x=0
+
+// parse a coloned string
+int IpAddress::parse_coloned_ipstring(const char *inaddr)
+{
+ ADDRESS_TRACE;
+
+ char temp[60]; // temp buffer for destruction
+
+ // check len, an ipv6 can never be bigger than 39
+ // 123456789012345678901234567890123456789
+ // 1BCD:2BCD:3BCD:4BCD:5BCD:6BCD:7BCD:8BCD
+ if (!inaddr || (strlen(inaddr) > 60)) return FALSE;
+ strcpy(temp, inaddr);
+ trim_white_space(temp);
+ if (strlen(temp) > 39) return FALSE;
+
+ char *in_ptr = temp;
+ char *out_ptr = (char*)address_buffer;
+ char *end_first_part = NULL;
+ char second[39];
+ int second_used = FALSE;
+ int colon_count = 0;
+ int had_double_colon = FALSE;
+ int last_was_colon = FALSE;
+ int had_dot = FALSE;
+ int dot_count = 0;
+ int digit_count = 0;
+ char digits[4];
+ char last_deliminiter = 0;
+
+ while (*in_ptr != 0)
+ {
+ if (*in_ptr == '.')
+ {
+ last_deliminiter = *in_ptr;
+ had_dot = TRUE;
+ dot_count++;
+ if (dot_count > 3)
+ return FALSE;
+ if ((digit_count > 3) || (digit_count < 1))
+ return FALSE;
+ for (int i=0; i 0) && (value <= 255))
+ *out_ptr++ = (unsigned char) value;
+ else
+ {
+ if (strcmp(digits, "0") == 0)
+ *out_ptr++ = (unsigned char) 0;
+ else
+ return FALSE;
+ }
+ digit_count = 0;
+ }
+ else if (*in_ptr == ':')
+ {
+ last_deliminiter = *in_ptr;
+
+ if (had_dot)
+ return FALSE; // don't allow : after a dot
+
+ if (digit_count)
+ {
+ // move digits to right
+ {
+ for (int i=0; i= 4)
+ return FALSE;
+ if (!isxdigit(*in_ptr))
+ return FALSE;
+ digits[digit_count] = tolower(*in_ptr);
+
+ digit_count++;
+ if (digit_count > 4)
+ return FALSE;
+ last_was_colon = 0;
+ }
+ in_ptr++;
+ }
+
+ // put last bytes from digits into buffer
+ if (digit_count)
+ {
+ if (last_deliminiter == ':')
+ {
+ {
+ // move digits to right
+ for (int i=0; i 3) || (digit_count < 1))
+ return FALSE;
+ for (int i=0; i 0) && (value <= 255))
+ *out_ptr++ = (unsigned char) value;
+ else
+ {
+ if (strcmp(digits, "0") == 0)
+ *out_ptr++ = (unsigned char) 0;
+ else
+ return FALSE;
+ }
+ digit_count = 0;
+ }
+ else
+ return FALSE;
+ }
+
+ // must have between two and seven colons
+ if ((colon_count > 7) || (colon_count < 2))
+ return FALSE;
+
+ // if there was a dot there must be three of them
+ if ((dot_count > 0) && (dot_count != 3))
+ return FALSE;
+
+ if (second_used)
+ {
+ int len_first = end_first_part - (char*)address_buffer;
+ int len_second = out_ptr - second;
+
+ int i=0;
+ for (i=0; ih_length == sizeof(in6_addr))
+ {
+ in6_addr ipAddr;
+ memcpy((void *) &ipAddr, (void *) lookupResult->h_addr,
+ sizeof(in6_addr));
+
+ // now lets check out the coloned string
+ if (!inet_ntop(AF_INET6, &ipAddr, ds, 48))
+ return FALSE;
+ debugprintf(4, "from inet_ntop: %s", ds);
+ if (!parse_coloned_ipstring(ds))
+ return FALSE;
+
+ // save the friendly name
+ strcpy(iv_friendly_name, inaddr);
+
+ return TRUE;
+ }
+#endif // SNMP_PP_IPv6
+ if (lookupResult->h_length == sizeof(in_addr))
+ {
+ in_addr ipAddr;
+
+ memcpy((void *) &ipAddr, (void *) lookupResult->h_addr,
+ sizeof(in_addr));
+
+ // now lets check out the dotted string
+ strcpy(ds,inet_ntoa(ipAddr));
+
+ if (!parse_dotted_ipstring(ds))
+ return FALSE;
+
+ // save the friendly name
+ strcpy(iv_friendly_name, inaddr);
+
+ return TRUE;
+ }
+ } // end if lookup result
+ else
+ {
+#ifdef linux
+ iv_friendly_name_status = herrno;
+#else
+ iv_friendly_name_status = h_errno;
+#endif
+ return FALSE;
+ }
+ } // end else not a dotted string
+ return TRUE;
+}
+
+// using the currently defined address, do a DNS
+// and try to fill up the name
+int IpAddress::addr_to_friendly()
+{
+ ADDRESS_TRACE;
+
+ hostent *lookupResult;
+ char ds[48];
+
+ // can't look up an invalid address
+ if (!valid_flag) return -1;
+
+ // lets try and get the friendly name from the DNS
+ strcpy(ds, this->IpAddress::get_printable());
+
+#ifdef linux
+ int herrno = 0;
+ hostent lookup;
+ char buf[2048]; // TODO: Buf size too big?
+#endif
+ if (ip_version == version_ipv4)
+ {
+ in_addr ipAddr;
+
+#if defined HAVE_INET_ATON
+ if (inet_aton((char*)ds, &ipAddr) == 0)
+ return -1; // bad address
+#elif defined HAVE_INET_PTON
+ if (inet_pton(AF_INET, (char*)ds, &ipAddr) <= 0)
+ return -1; // bad address
+#else
+ ipAddr.s_addr = inet_addr((char*)ds);
+ if (ipAddr.s_addr == INADDR_NONE)
+ return -1; // bad address
+#endif
+
+#ifdef linux
+ gethostbyaddr_r((char *) &ipAddr, sizeof(in_addr),
+ AF_INET, &lookup, buf, 2048, &lookupResult, &herrno);
+#else
+ lookupResult = gethostbyaddr((char *) &ipAddr, sizeof(in_addr),
+ AF_INET);
+#endif
+ }
+ else
+ {
+#ifdef SNMP_PP_IPv6
+ in6_addr ipAddr;
+
+ if (inet_pton(AF_INET6, (char*)ds, &ipAddr) <= 0)
+ return -1; // bad address
+
+#ifdef linux
+ gethostbyaddr_r((char *) &ipAddr, sizeof(in_addr),
+ AF_INET6, &lookup, buf, 2048, &lookupResult, &herrno);
+#else
+ lookupResult = gethostbyaddr((char *) &ipAddr, sizeof(in6_addr),
+ AF_INET6);
+#endif // linux
+#else
+ return -1;
+#endif // SNMP_PP_IPv6
+ }
+ // if we found the name, then update the iv friendly name
+ if (lookupResult)
+ {
+ strcpy(iv_friendly_name, lookupResult->h_name);
+ return 0;
+ }
+ else
+ {
+#ifdef linux
+ iv_friendly_name_status = herrno;
+#else
+ iv_friendly_name_status = h_errno;
+#endif
+ return iv_friendly_name_status;
+ }
+}
+
+//----[ IP address format output ]------------------------------------
+void IpAddress::format_output() const
+{
+ ADDRESS_TRACE;
+
+ // if valid format else null it
+ if (valid_flag)
+ {
+ if (ip_version == version_ipv4)
+ sprintf((char *) output_buffer,"%d.%d.%d.%d",address_buffer[0],
+ address_buffer[1], address_buffer[2], address_buffer[3]);
+ else
+ sprintf((char *) output_buffer,
+ "%02x%02x:%02x%02x:%02x%02x:%02x%02x:"
+ "%02x%02x:%02x%02x:%02x%02x:%02x%02x",
+ address_buffer[ 0], address_buffer[ 1], address_buffer[ 2],
+ address_buffer[ 3], address_buffer[ 4], address_buffer[ 5],
+ address_buffer[ 6], address_buffer[ 7], address_buffer[ 8],
+ address_buffer[ 9], address_buffer[10], address_buffer[11],
+ address_buffer[12], address_buffer[13], address_buffer[14],
+ address_buffer[15]);
+ }
+ else
+ *(char *)output_buffer = 0;
+ ((IpAddress *)this)->addr_changed = false;
+}
+
+//-----------------------------------------------------------------
+// logically and two IPaddresses and
+// return the new one
+void IpAddress::mask(const IpAddress& ipaddr)
+{
+ ADDRESS_TRACE;
+
+ if (valid() && ipaddr.valid())
+ {
+ int count = (ip_version == version_ipv4) ? IPLEN : IP6LEN;
+
+ for (int i = 0; i < count; i++)
+ address_buffer[i] = address_buffer[i] & ipaddr.address_buffer[i];
+ addr_changed = true;
+ }
+}
+
+/**
+ * Map a IPv4 Address to a IPv6 address.
+ *
+ * @return - TRUE if no error occured.
+ */
+int IpAddress::map_to_ipv6()
+{
+ ADDRESS_TRACE;
+
+ if (!valid())
+ return FALSE;
+
+ if (ip_version != version_ipv4)
+ return FALSE;
+
+ /* just copy IPv4 address to the end of the buffer
+ zero the first 10 bytes and fill 2 Bytes with 0xff */
+ memcpy(&address_buffer[12], address_buffer, 4);
+ memset(address_buffer, 0, 10);
+ address_buffer[10] = 0xff;
+ address_buffer[11] = 0xff;
+
+ smival.value.string.len = IP6LEN;
+ ip_version = version_ipv6;
+
+ addr_changed = true;
+ return TRUE;
+}
+
+//=======================================================================
+//========== Udp Address Implementation =================================
+//=======================================================================
+
+//-------[ construct an IP address with no agrs ]----------------------
+UdpAddress::UdpAddress()
+ : IpAddress()
+{
+ ADDRESS_TRACE;
+
+ // Inherits IP Address attributes
+ // Always initialize (override) what type this object is
+ smival.syntax = sNMP_SYNTAX_OCTETS;
+ smival.value.string.len = UDPIPLEN;
+ smival.value.string.ptr = address_buffer;
+
+ sep = ':';
+ set_port(0);
+}
+
+//-----------------[ construct an Udp address with another Udp address ]---
+UdpAddress::UdpAddress(const UdpAddress &udpaddr)
+ : IpAddress(udpaddr)
+{
+ ADDRESS_TRACE;
+
+ // always initialize SMI info
+ smival.syntax = sNMP_SYNTAX_OCTETS;
+ smival.value.string.len = udpaddr.smival.value.string.len;
+ smival.value.string.ptr = address_buffer;
+
+ // Copy the port value
+ sep = ':';
+ set_port(udpaddr.get_port());
+
+ if (!udpaddr.addr_changed)
+ {
+ memcpy(output_buffer, udpaddr.output_buffer,
+ sizeof(unsigned char) * OUTBUFF);
+ addr_changed = false;
+ }
+}
+
+// constructor with a dotted string
+UdpAddress::UdpAddress(const char *inaddr) : IpAddress()
+{
+ ADDRESS_TRACE;
+
+ // always initialize SMI info
+ smival.syntax = sNMP_SYNTAX_OCTETS;
+ smival.value.string.len = UDPIPLEN;
+ smival.value.string.ptr = address_buffer;
+
+ valid_flag = parse_address(inaddr);
+ addr_changed = true;
+}
+
+//-----------------[ construct a UdpAddress from a GenAddress ]--------------
+UdpAddress::UdpAddress(const GenAddress &genaddr) : IpAddress()
+{
+ ADDRESS_TRACE;
+
+ // always initialize SMI info
+ smival.syntax = sNMP_SYNTAX_OCTETS;
+ smival.value.string.len = UDPIPLEN;
+ smival.value.string.ptr = address_buffer;
+
+ valid_flag = genaddr.valid();
+
+ // allow use of an ip or udp genaddress
+ if (valid_flag)
+ {
+ if (genaddr.get_type() == type_udp)
+ {
+ *this = genaddr.cast_udpaddress(); // copy in the IP address data
+ }
+ else if (genaddr.get_type() == type_ip)
+ {
+ *this = genaddr.cast_ipaddress(); // copy in the IP address data
+ }
+ else
+ {
+ valid_flag = false;
+ }
+ }
+ sep = ':';
+}
+
+
+//--------[ construct a udp from an IpAddress ]--------------------------
+UdpAddress::UdpAddress(const IpAddress &ipaddr):IpAddress(ipaddr)
+{
+ ADDRESS_TRACE;
+
+ // always initialize SMI info
+ smival.syntax = sNMP_SYNTAX_OCTETS;
+ if (ip_version == version_ipv4)
+ smival.value.string.len = UDPIPLEN;
+ else
+ smival.value.string.len = UDPIP6LEN;
+ smival.value.string.ptr = address_buffer;
+
+ sep = ':';
+ addr_changed = true;
+ set_port(0);
+}
+
+// copy an instance of this Value
+SnmpSyntax& UdpAddress::operator=(const SnmpSyntax &val)
+{
+ ADDRESS_TRACE;
+
+ if (this == &val) return *this; // protect against assignment from itself
+
+ valid_flag = false; // will get set TRUE if really valid
+ addr_changed = true;
+ if (val.valid())
+ {
+ switch (val.get_syntax())
+ {
+ case sNMP_SYNTAX_IPADDR:
+ {
+ UdpAddress temp_udp(val.get_printable());
+ *this = temp_udp; // valid_flag is set by the udp assignment
+ break;
+ }
+ case sNMP_SYNTAX_OCTETS:
+ if (((UdpAddress &)val).smival.value.string.len == UDPIPLEN)
+ {
+ MEMCPY(address_buffer,((UdpAddress &)val).smival.value.string.ptr,
+ UDPIPLEN);
+ iv_friendly_name[0]=0;
+ valid_flag = true;
+ ip_version = version_ipv4;
+ smival.value.string.len = UDPIPLEN;
+ }
+ else if (((UdpAddress &)val).smival.value.string.len == UDPIP6LEN)
+ {
+ MEMCPY(address_buffer,((UdpAddress &)val).smival.value.string.ptr,
+ UDPIP6LEN);
+ iv_friendly_name[0]=0;
+ valid_flag = true;
+ ip_version = version_ipv6;
+ smival.value.string.len = UDPIP6LEN;
+ }
+ break;
+ // NOTE: as a value add, other types could have "logical"
+ // mappings, i.e. integer32 and unsigned32
+ }
+ }
+ return *this;
+}
+
+// assignment to another UdpAddress object overloaded
+UdpAddress& UdpAddress::operator=(const UdpAddress &udpaddr)
+{
+ ADDRESS_TRACE;
+
+ if (this == &udpaddr) return *this; // protect against assignment from itself
+
+ (IpAddress &)*this = udpaddr; // use ancestor assignment for ipaddr value
+ if (ip_version == version_ipv4)
+ smival.value.string.len = UDPIPLEN;
+ else
+ smival.value.string.len = UDPIP6LEN;
+
+ set_port(udpaddr.get_port()); // copy to port value
+ if (udpaddr.addr_changed)
+ {
+ addr_changed = true;
+ }
+ else
+ {
+ memcpy(output_buffer, udpaddr.output_buffer,
+ sizeof(unsigned char) * OUTBUFF);
+ addr_changed = false;
+ }
+
+ return *this;
+}
+
+// assignment to another UdpAddress object overloaded
+UdpAddress& UdpAddress::operator=(const IpAddress &ipaddr)
+{
+ ADDRESS_TRACE;
+
+ if (this == &ipaddr) return *this; // protect against assignment from itself
+
+ (IpAddress &)*this = ipaddr; // use ancestor assignment for ipaddr value
+ if (ip_version == version_ipv4)
+ smival.value.string.len = UDPIPLEN;
+ else
+ smival.value.string.len = UDPIP6LEN;
+
+ set_port(0); // copy to port value
+ addr_changed = true;
+ return *this;
+}
+
+UdpAddress& UdpAddress::operator=(const char *inaddr)
+{
+ ADDRESS_TRACE;
+
+ valid_flag = parse_address(inaddr);
+ addr_changed = true;
+ return *this;
+}
+
+//-----[ IP Address parse Address ]---------------------------------
+bool UdpAddress::parse_address(const char *inaddr)
+{
+ ADDRESS_TRACE;
+
+ addr_changed = true;
+
+ char buffer[MAX_FRIENDLY_NAME];
+
+ unsigned short port = 0;
+ if (inaddr && (strlen(inaddr)< MAX_FRIENDLY_NAME))
+ {
+ strcpy(buffer, inaddr);
+ trim_white_space(buffer);
+ }
+ else
+ {
+ valid_flag = false;
+ return FALSE;
+ }
+ // look for port info @ the end of the string
+ // port can be delineated by a ':' or a '/'
+ // if neither are present then just treat it
+ // like a normal IpAddress
+
+ int remove_brackets = FALSE;
+ int found = FALSE;
+ int pos = strlen(buffer) - 1;
+ int do_loop = TRUE;
+ int another_colon_found = FALSE;
+
+ if (pos < 0)
+ {
+ valid_flag = false;
+ return FALSE;
+ }
+
+ // search from the end, to find the start of the port
+ // [ipv4]:port [ipv4]/port ipv4/port ipv4:port [ipv4] ipv4
+ // [ipv6]:port [ipv6]/port ipv6/port [ipv6] ipv6
+ while (do_loop)
+ {
+ if (buffer[pos] == '/')
+ {
+ found = TRUE;
+ sep='/';
+ if (buffer[pos -1] == ']')
+ remove_brackets = TRUE;
+ break;
+ }
+ if (buffer[pos] == ':')
+ {
+ if ((pos > 1) && (buffer[pos -1] == ']'))
+ {
+ found = TRUE;
+ remove_brackets = TRUE;
+ sep=':';
+ break;
+ }
+
+ for (int i=pos - 1; i >= 0 ; i--)
+ if (buffer[i] == ':')
+ {
+ another_colon_found = TRUE;
+ }
+ if (!another_colon_found)
+ {
+ sep=':';
+ found = TRUE;
+ break;
+ }
+ }
+ if (buffer[pos] == ']')
+ {
+ // we found a ] without following a port, so increase pos
+ ++pos;
+ remove_brackets = TRUE;
+ break;
+ }
+ pos--;
+ do_loop = ((found == FALSE) && (pos >= 0) &&
+ (another_colon_found == FALSE));
+ }
+
+ if (remove_brackets)
+ {
+ buffer[pos-1] = 0;
+ buffer[0] = ' ';
+ }
+
+ bool result;
+
+ if (found)
+ {
+ buffer[pos] = 0;
+ port = atoi(&buffer[pos+1]);
+ result = IpAddress::parse_address(buffer);
+ }
+ else
+ {
+ port = 0;
+ result = IpAddress::parse_address (buffer);
+ }
+
+ if (ip_version == version_ipv4)
+ smival.value.string.len = UDPIPLEN;
+ else
+ smival.value.string.len = UDPIP6LEN;
+
+ set_port(port);
+ return result;
+}
+
+
+//--------[ set the port number ]---------------------------------------
+void UdpAddress::set_port(const unsigned short p)
+{
+ ADDRESS_TRACE;
+
+ unsigned short *port_nbo;
+ if (ip_version == version_ipv4)
+ port_nbo = (unsigned short*)(address_buffer + IPLEN);
+ else
+ port_nbo = (unsigned short*)(address_buffer + IP6LEN);
+ *port_nbo = htons(p);
+ addr_changed = true;
+}
+
+//---------[ get the port number ]--------------------------------------
+unsigned short UdpAddress::get_port() const
+{
+ ADDRESS_TRACE;
+
+ if (valid_flag)
+ {
+ unsigned short *port_nbo;
+ if (ip_version == version_ipv4)
+ port_nbo = (unsigned short*)(address_buffer + IPLEN);
+ else
+ port_nbo = (unsigned short*)(address_buffer + IP6LEN);
+ return ntohs(*port_nbo);
+ }
+ return 0;// don't use uninitialized memory
+}
+
+//----[ UDP address format output ]------------------------------------
+void UdpAddress::format_output() const
+{
+ ADDRESS_TRACE;
+
+ IpAddress::format_output(); // allow ancestors to format their buffers
+
+ // if valid format else null it
+ if (valid_flag)
+ {
+ if (ip_version == version_ipv4)
+ sprintf((char *) output_buffer,"%s%c%d",
+ IpAddress::get_printable(),
+ '/',//TODO:look for problems in old code and change to "sep"
+ get_port() );
+ else
+ sprintf((char *) output_buffer,"[%s]%c%d",
+ IpAddress::get_printable(),
+ '/',//TODO:look for problems in old code and change to "sep"
+ get_port() );
+ }
+ else
+ *(char*)output_buffer = 0;
+ ((UdpAddress *)this)->addr_changed = false;
+}
+
+/**
+ * Map a IPv4 UDP address to a IPv6 UDP address.
+ *
+ * @return - TRUE if no error occured.
+ */
+int UdpAddress::map_to_ipv6()
+{
+ ADDRESS_TRACE;
+
+ /* Save the port, as IpAddress::map_to_ipv6 destroys it */
+ unsigned short old_port = get_port();
+
+ /* Map IpAddress */
+ if (!IpAddress::map_to_ipv6())
+ return FALSE;
+
+ set_port(old_port);
+ smival.value.string.len = UDPIP6LEN;
+ ip_version = version_ipv6;
+
+ addr_changed = true;
+ return TRUE;
+}
+
+
+#ifdef _IPX_ADDRESS
+//=======================================================================
+//=========== IPX Address Implementation ================================
+//=======================================================================
+
+//----------[ constructor no args ]--------------------------------------
+IpxAddress::IpxAddress() : Address()
+{
+ // always initialize SMI info
+ smival.syntax = sNMP_SYNTAX_OCTETS;
+ smival.value.string.len = IPXLEN;
+ smival.value.string.ptr = address_buffer;
+
+ separator = 0;
+ valid_flag = false;
+ addr_changed = true;
+}
+
+
+//----------[ constructor with a string arg ]---------------------------
+IpxAddress::IpxAddress(const char *inaddr):Address()
+{
+ // always initialize SMI info
+ smival.syntax = sNMP_SYNTAX_OCTETS;
+ smival.value.string.len = IPXLEN;
+ smival.value.string.ptr = address_buffer;
+
+ separator = 0;
+ valid_flag = parse_address(inaddr);
+ addr_changed = true;
+}
+
+
+//-----[ IPX Address copy constructor ]----------------------------------
+IpxAddress::IpxAddress(const IpxAddress &ipxaddr)
+{
+ // always initialize SMI info
+ smival.syntax = sNMP_SYNTAX_OCTETS;
+ smival.value.string.len = IPXLEN;
+ smival.value.string.ptr = address_buffer;
+
+ separator = 0;
+ valid_flag = ipxaddr.valid_flag;
+ if (valid_flag)
+ MEMCPY(address_buffer, ipxaddr.address_buffer, IPXLEN);
+ addr_changed = true;
+}
+
+
+//----[ construct an IpxAddress from a GenAddress ]---------------------------
+IpxAddress::IpxAddress(const GenAddress &genaddr)
+{
+ // always initialize SMI info
+ smival.syntax = sNMP_SYNTAX_OCTETS;
+ smival.value.string.len = IPXLEN;
+ smival.value.string.ptr = address_buffer;
+
+ valid_flag = genaddr.valid();
+ // allow use of an ipx or ipxsock address
+ if (valid_flag)
+ {
+ if ((genaddr.get_type() == type_ipx) )
+ {
+ *this = genaddr.cast_ipxaddress(); // copy in the Ipx address data
+ }
+ else if ((genaddr.get_type() == type_ipxsock) )
+ {
+ *this = genaddr.cast_ipxsockaddress(); // copy in the Ipx address data
+ }
+ else
+ valid_flag = false;
+ }
+}
+
+//-----[ IPX Address general = operator ]-------------------------------
+SnmpSyntax& IpxAddress::operator=(const SnmpSyntax &val)
+{
+ // protect against assignment from itself
+ if (this == &val) return *this;
+
+ valid_flag = false; // will set to TRUE if really valid
+ if (val.valid()){
+ switch (val.get_syntax()){
+ case sNMP_SYNTAX_OCTETS:
+ if (((IpxAddress &)val).smival.value.string.len == IPXLEN){
+ MEMCPY(address_buffer, ((IpxAddress &)val).smival.value.string.ptr, IPXLEN);
+ valid_flag = true;
+ }
+ break;
+ }
+ }
+ addr_changed = true;
+ return *this;
+}
+
+//--------[ assignment to another IpAddress object overloaded ]----------
+IpxAddress& IpxAddress::operator=(const IpxAddress &ipxaddress)
+{
+ if (this == &ipxaddress) return *this;// protect against assignment from self
+
+ valid_flag = ipxaddress.valid_flag;
+ if (valid_flag)
+ MEMCPY(address_buffer, ipxaddress.address_buffer, IPXLEN);
+ addr_changed = true;
+ return *this;
+}
+
+
+//-----[ IPX Address parse Address ]-----------------------------------
+// Convert a string to a ten byte ipx address
+// On success sets validity TRUE or FALSE
+//
+// IPX address format
+//
+// NETWORK ID| MAC ADDRESS
+// 01 02 03 04|05 06 07 08 09 10
+// XX XX XX XX|XX XX XX XX XX XX
+//
+// Valid input format
+//
+// XXXXXXXX.XXXXXXXXXXXX
+// Total length must be 21
+// Must have a separator in it
+// First string length must be 8
+// Second string length must be 12
+// Each char must take on value 0-F
+//
+//
+// Input formats recognized
+//
+// XXXXXXXX.XXXXXXXXXXXX
+// XXXXXXXX:XXXXXXXXXXXX
+// XXXXXXXX-XXXXXXXXXXXX
+// XXXXXXXX.XXXXXX-XXXXXX
+// XXXXXXXX:XXXXXX-XXXXXX
+// XXXXXXXX-XXXXXX-XXXXXX
+bool IpxAddress::parse_address(const char *inaddr)
+{
+ char unsigned *str1,*str2;
+ char temp[30]; // don't destroy original
+ char unsigned *tmp;
+ size_t z, tmplen;
+
+ // save the orginal source
+ if (!inaddr || (strlen(inaddr) >(sizeof(temp)-1))) return FALSE;
+ strcpy(temp, inaddr);
+ trim_white_space(temp);
+ tmplen = strlen(temp);
+
+ // bad total length check
+ // 123456789012345678901
+ // XXXXXXXX-XXXXXXXXXXXX 21 len
+ //
+ // XXXXXXXX-XXXXXX-XXXXXX 22 len
+ // need at least 21 chars and no more than 22
+ if ((tmplen <21) || (tmplen >22))
+ return FALSE;
+
+ // convert the string to all lower case
+ // this allows hex values to be in upper or lower
+ for (z=0;z< tmplen;z++)
+ temp[z] = tolower(temp[z]);
+
+ // check for separated nodeid
+ // if found remove it
+ if (temp[15] == '-')
+ {
+ for(z=16;z= '0') && (*tmp <= '9'))|| // good 0-9
+ ((*tmp >= 'a') && (*tmp <= 'f'))) // or a-f
+ tmp++;
+ else
+ return FALSE;
+
+ // check out the MAC address
+ tmp = str2;
+ while(*tmp != 0)
+ if (((*tmp >= '0') && (*tmp <= '9'))|| // good 0-9
+ ((*tmp >= 'a') && (*tmp <= 'f'))) // or a-f
+ tmp++;
+ else
+ return FALSE;
+
+ // convert to target string
+ tmp = str1;
+ while (*tmp != 0)
+ {
+ if ((*tmp >= '0') && (*tmp <= '9'))
+ *tmp = *tmp - (char unsigned )'0';
+ else
+ *tmp = *tmp - (char unsigned) 'a' + (char unsigned) 10;
+ tmp++;
+ }
+
+ // network id portion
+ address_buffer[0] = (str1[0]*16) + str1[1];
+ address_buffer[1] = (str1[2]*16) + str1[3];
+ address_buffer[2] = (str1[4]*16) + str1[5];
+ address_buffer[3] = (str1[6]*16) + str1[7];
+
+ tmp = str2;
+ while (*tmp != 0)
+ {
+ if ((*tmp >= '0') && (*tmp <= '9'))
+ *tmp = *tmp - (char unsigned) '0';
+ else
+ *tmp = *tmp - (char unsigned) 'a'+ (char unsigned) 10;
+ tmp++;
+ }
+
+ address_buffer[4] = (str2[0]*16) + str2[1];
+ address_buffer[5] = (str2[2]*16) + str2[3];
+ address_buffer[6] = (str2[4]*16) + str2[5];
+ address_buffer[7] = (str2[6]*16) + str2[7];
+ address_buffer[8] = (str2[8]*16) + str2[9];
+ address_buffer[9] = (str2[10]*16) + str2[11];
+
+ return TRUE;
+}
+
+//----[ IPX address format output ]-------------------------------------
+void IpxAddress::format_output() const
+{
+ if (valid_flag)
+ sprintf((char *) output_buffer,
+ "%02x%02x%02x%02x%c%02x%02x%02x%02x%02x%02x",
+ address_buffer[0],address_buffer[1],
+ address_buffer[2],address_buffer[3],'-',
+ address_buffer[4],address_buffer[5],
+ address_buffer[6],address_buffer[7],
+ address_buffer[8],address_buffer[9]);
+ else
+ *(char*)output_buffer = 0;
+ ((IpxAddress *)this)->addr_changed = false;
+}
+
+
+#ifdef _MAC_ADDRESS
+// get the host id portion of an ipx address
+int IpxAddress::get_hostid(MacAddress& mac)
+{
+ if (valid_flag)
+ {
+ char buffer[18];
+ sprintf(buffer,"%02x:%02x:%02x:%02x:%02x:%02x", address_buffer[4],
+ address_buffer[5], address_buffer[6], address_buffer[7],
+ address_buffer[8], address_buffer[9]);
+ MacAddress temp(buffer);
+ mac = temp;
+ if (mac.valid())
+ return TRUE;
+ }
+ return FALSE;
+}
+#endif // function that needs _MAC_ADDRESS
+
+//========================================================================
+//======== IpxSockAddress Implementation =================================
+//========================================================================
+
+//----------[ constructor no args ]--------------------------------------
+IpxSockAddress::IpxSockAddress() : IpxAddress()
+{
+ // always initialize SMI info
+ smival.syntax = sNMP_SYNTAX_OCTETS;
+ smival.value.string.len = IPXSOCKLEN;
+ smival.value.string.ptr = address_buffer;
+
+ set_socket(0);
+ addr_changed = true;
+}
+
+//-----------[ construct an IpxSockAddress with another IpxSockAddress]----
+IpxSockAddress::IpxSockAddress(const IpxSockAddress &ipxaddr)
+ : IpxAddress(ipxaddr)
+{
+ // always initialize SMI info
+ smival.syntax = sNMP_SYNTAX_OCTETS;
+ smival.value.string.len = IPXSOCKLEN;
+ smival.value.string.ptr = address_buffer;
+
+ // copy the socket value
+ set_socket(ipxaddr.get_socket());
+ addr_changed = true;
+}
+
+
+//---------------[ construct a IpxSockAddress from a string ]--------------
+IpxSockAddress::IpxSockAddress(const char *inaddr):IpxAddress()
+{
+ // always initialize SMI info
+ smival.syntax = sNMP_SYNTAX_OCTETS;
+ smival.value.string.len = IPXSOCKLEN;
+ smival.value.string.ptr = address_buffer;
+
+ valid_flag = parse_address(inaddr);
+ addr_changed = true;
+}
+
+
+//---------------[ construct a IpxSockAddress from a GenAddress ]----------
+IpxSockAddress::IpxSockAddress(const GenAddress &genaddr):IpxAddress()
+{
+ // always initialize SMI info
+ smival.syntax = sNMP_SYNTAX_OCTETS;
+ smival.value.string.len = IPXSOCKLEN;
+ smival.value.string.ptr = address_buffer;
+
+ valid_flag = false;
+ unsigned short socketid = 0;
+ // allow use of an ipx or ipxsock address
+ if ((genaddr.get_type() == type_ipx) )
+ {
+ valid_flag = genaddr.valid();
+ if (valid_flag)
+ {
+ // copy in the Ipx address data
+ IpxAddress temp_ipx((const char *) genaddr);
+ *this = temp_ipx;
+ }
+ }
+ else if ((genaddr.get_type() == type_ipxsock) )
+ {
+ valid_flag = genaddr.valid();
+ if (valid_flag)
+ {
+ // copy in the Ipx address data
+ IpxSockAddress temp_ipxsock((const char *) genaddr);
+ *this = temp_ipxsock;
+ // socketid info since are making an IpxSockAddress
+ socketid = temp_ipxsock.get_socket();
+ }
+ }
+ set_socket(socketid);
+ addr_changed = true;
+}
+
+//------------[ construct an IpxSockAddress from a IpxAddress ]--------------
+IpxSockAddress::IpxSockAddress(const IpxAddress &ipxaddr):IpxAddress(ipxaddr)
+{
+ // always initialize SMI info
+ smival.syntax = sNMP_SYNTAX_OCTETS;
+ smival.value.string.len = IPXSOCKLEN;
+ smival.value.string.ptr = address_buffer;
+
+ set_socket(0);
+ addr_changed = true;
+}
+
+// copy an instance of this Value
+SnmpSyntax& IpxSockAddress::operator=(const SnmpSyntax &val)
+{
+ if (this == &val) return *this; // protect against assignment from itself
+
+ valid_flag = false; // will set to TRUE if really valid
+ if (val.valid()){
+ switch (val.get_syntax()){
+ case sNMP_SYNTAX_OCTETS:
+ {
+ // See if it is of the Ipx address family
+ // This handles IpxSockAddress == IpxAddress
+ IpxSockAddress temp_ipx(val.get_printable());
+ if (temp_ipx.valid()){
+ *this = temp_ipx; // ipxsock = ipxsock
+ }
+ // See if it is an OctetStr of appropriate length
+ else if (((IpxSockAddress &)val).smival.value.string.len == IPXSOCKLEN){
+ MEMCPY(address_buffer,
+ ((IpxSockAddress &)val).smival.value.string.ptr,
+ IPXSOCKLEN);
+ valid_flag = true;
+ }
+ }
+ break;
+ }
+ }
+ addr_changed = true;
+ return *this;
+}
+
+// assignment to another IpAddress object overloaded
+IpxSockAddress& IpxSockAddress::operator=(const IpxSockAddress &ipxaddr)
+{
+ if (this == &ipxaddr) return *this; // protect against assignment from itself
+
+ (IpxAddress&)*this = ipxaddr; // use ancestor assignment for ipx addr
+ set_socket(ipxaddr.get_socket()); // copy socket value
+ addr_changed = true;
+ return *this;
+}
+
+//----[ IPX address format output ]-------------------------------------
+void IpxSockAddress::format_output() const
+{
+ IpxAddress::format_output(); // allow ancestors to format their buffers
+
+ if (valid_flag)
+ sprintf((char *) output_buffer,"%s/%d",
+ IpxAddress::get_printable(), get_socket());
+ else
+ *(char*)output_buffer = 0;
+ ((IpxSockAddress *)this)->addr_changed = false;
+}
+
+//-----[ IP Address parse Address ]---------------------------------
+bool IpxSockAddress::parse_address(const char *inaddr)
+{
+ char buffer[MAX_FRIENDLY_NAME];
+ unsigned short socketid=0;
+
+ if (inaddr && (strlen(inaddr)< MAX_FRIENDLY_NAME))
+ strcpy(buffer, inaddr);
+ else
+ {
+ valid_flag = false;
+ return FALSE;
+ }
+ // look for port info @ the end of the string
+ // port can be delineated by a ':' or a '/'
+ // if neither are present then just treat it
+ // like a normal IpAddress
+ char *tmp;
+ tmp = strstr(buffer,"/");
+
+ if (tmp != NULL)
+ {
+ *tmp=0; // new null terminator
+ tmp++;
+ socketid = atoi(tmp);
+ }
+ set_socket(socketid);
+ return IpxAddress::parse_address(buffer);
+}
+
+
+
+//-------------[ set the socket number ]----------------------------------
+void IpxSockAddress::set_socket(const unsigned short s)
+{
+ unsigned short sock_nbo = htons(s);
+ MEMCPY(&address_buffer[IPXLEN], &sock_nbo, 2);
+ addr_changed = true;
+}
+
+//--------------[ get the socket number ]---------------------------------
+unsigned short IpxSockAddress::get_socket() const
+{
+ if (valid_flag)
+ {
+ unsigned short sock_nbo;
+ MEMCPY(&sock_nbo, &address_buffer[IPXLEN], 2);
+ return ntohs(sock_nbo);
+ }
+ return 0; // don't use uninitialized memory
+}
+#endif // _IPX_ADDRESS
+
+#ifdef _MAC_ADDRESS
+//========================================================================
+//======== MACAddress Implementation =====================================
+//========================================================================
+
+//--------[ constructor, no arguments ]-----------------------------------
+MacAddress::MacAddress() : Address()
+{
+ // always initialize SMI info
+ smival.syntax = sNMP_SYNTAX_OCTETS;
+ smival.value.string.len = MACLEN;
+ smival.value.string.ptr = address_buffer;
+
+ valid_flag = false;
+ addr_changed = true;
+}
+
+//-----[ MAC Address copy constructor ]---------------------------------
+MacAddress::MacAddress(const MacAddress &macaddr)
+{
+ // always initialize SMI info
+ smival.syntax = sNMP_SYNTAX_OCTETS;
+ smival.value.string.len = MACLEN;
+ smival.value.string.ptr = address_buffer;
+
+ valid_flag = macaddr.valid_flag;
+ if (valid_flag)
+ MEMCPY(address_buffer, macaddr.address_buffer, MACLEN);
+ addr_changed = true;
+}
+
+//---------[ constructor with a string argument ]-------------------------
+MacAddress::MacAddress(const char *inaddr):Address()
+{
+ // always initialize SMI info
+ smival.syntax = sNMP_SYNTAX_OCTETS;
+ smival.value.string.len = MACLEN;
+ smival.value.string.ptr = address_buffer;
+
+ valid_flag = parse_address(inaddr);
+ addr_changed = true;
+}
+
+//-----[ construct a MacAddress from a GenAddress ]------------------------
+MacAddress::MacAddress(const GenAddress &genaddr)
+{
+ // always initialize SMI info
+ smival.syntax = sNMP_SYNTAX_OCTETS;
+ smival.value.string.len = MACLEN;
+ smival.value.string.ptr = address_buffer;
+
+ valid_flag = false;
+ // allow use of mac address
+ if (genaddr.get_type() == type_mac)
+ {
+ valid_flag = genaddr.valid();
+ if (valid_flag)
+ {
+ // copy in the Mac address data
+ *this = genaddr.cast_macaddress();
+ }
+ }
+ addr_changed = true;
+}
+
+//------[ assignment to another ipaddress object overloaded ]--------------
+MacAddress& MacAddress::operator=(const MacAddress &macaddress)
+{
+ if (this == &macaddress) return *this;// protect against assignment from self
+
+ valid_flag = macaddress.valid_flag;
+ if (valid_flag)
+ MEMCPY(address_buffer, macaddress.address_buffer, MACLEN);
+ addr_changed = true;
+ return *this;
+}
+
+
+
+//-----[ MAC Address general = operator ]---------------------------------
+SnmpSyntax& MacAddress::operator=(const SnmpSyntax &val)
+{
+ if (this == &val) return *this; // protect against assignment from itself
+
+ valid_flag = false; // will set to TRUE if really valid
+ if (val.valid())
+ {
+ switch (val.get_syntax())
+ {
+ case sNMP_SYNTAX_OCTETS:
+ if (((MacAddress &)val).smival.value.string.len == MACLEN)
+ {
+ MEMCPY(address_buffer, ((MacAddress &)val).smival.value.string.ptr,
+ MACLEN);
+ valid_flag = true;
+ }
+ break;
+ }
+ }
+ addr_changed = true;
+ return *this;
+}
+
+//-----[ MAC Address parse Address ]--------------------------------------
+// Convert a string to a six byte MAC address
+// On success sets validity TRUE or FALSE
+//
+// MAC address format
+//
+// MAC ADDRESS
+// 01 02 03 04 05 06
+// XX:XX:XX:XX:XX:XX
+// Valid input format
+//
+// XXXXXXXXXXXX
+// Total length must be 17
+// Each char must take on value 0-F
+//
+//
+bool MacAddress::parse_address(const char *inaddr)
+{
+ char temp[30]; // don't destroy original
+ char unsigned *tmp;
+ size_t z;
+
+
+ // save the orginal source
+ if (!inaddr || (strlen(inaddr) > 30)) return FALSE;
+ strcpy(temp, inaddr);
+ trim_white_space(temp);
+
+ // bad total length check
+ if (strlen(temp) != 17)
+ return FALSE;
+
+ // check for colons
+ if ((temp[2] != ':')||(temp[5] != ':')||(temp[8]!=':')||(temp[11]!=':')||(temp[14] !=':'))
+ return FALSE;
+
+ // strip off the colons
+ tmp = (unsigned char *) temp;
+ int i = 0;
+ while (*tmp != 0)
+ {
+ if (*tmp != ':')
+ {
+ temp[i] = *tmp;
+ i++;
+ }
+ tmp++;
+ }
+ temp[i] = 0;
+
+ // convert to lower
+ for(z=0;z= '0') && (*tmp <= '9'))|| // good 0-9
+ ((*tmp >= 'a') && (*tmp <= 'f'))) // or a-f
+ tmp++;
+ else
+ return FALSE;
+
+ // convert to target string
+ tmp = (unsigned char *) temp;
+ while (*tmp != 0)
+ {
+ if ((*tmp >= '0') && (*tmp <= '9'))
+ *tmp = *tmp - (char unsigned )'0';
+ else
+ *tmp = *tmp - (char unsigned) 'a' + (char unsigned) 10;
+ tmp++;
+ }
+
+ address_buffer[0] = (temp[0]*16) + temp[1];
+ address_buffer[1] = (temp[2]*16) + temp[3];
+ address_buffer[2] = (temp[4]*16) + temp[5];
+ address_buffer[3] = (temp[6]*16) + temp[7];
+ address_buffer[4] = (temp[8]*16) + temp[9];
+ address_buffer[5] = (temp[10]*16) + temp[11];
+
+ return TRUE;
+}
+
+//----[ MAC address format output ]---------------------------------
+void MacAddress::format_output() const
+{
+ if (valid_flag)
+ sprintf((char*)output_buffer,"%02x:%02x:%02x:%02x:%02x:%02x",
+ address_buffer[0], address_buffer[1], address_buffer[2],
+ address_buffer[3], address_buffer[4], address_buffer[5]);
+ else
+ *(char*)output_buffer = 0;
+ ((MacAddress*)this)->addr_changed = false;
+}
+
+unsigned int MacAddress::hashFunction() const
+{
+ return ((((address_buffer[0] << 8) + address_buffer[1]) * HASH0)
+ + (((address_buffer[2] << 8) + address_buffer[3]) * HASH1)
+ + (((address_buffer[4] << 8) + address_buffer[5]) * HASH2));
+}
+#endif // _MAC_ADDRESS
+
+//========================================================================
+//========== Generic Address Implementation ==============================
+//========================================================================
+
+//-----------[ constructor, no arguments ]--------------------------------
+GenAddress::GenAddress() : Address()
+{
+ ADDRESS_TRACE;
+
+ // initialize SMI info
+ // BOK: this is generally not used for GenAddress,
+ // but we need this to be a replica of the real address'
+ // smival info so that operator=SnmpSyntax will work.
+ smival.syntax = sNMP_SYNTAX_NULL; // to be overridden
+ smival.value.string.len = 0; // to be overridden
+ smival.value.string.ptr = address_buffer; // constant
+
+ valid_flag = false;
+ address = 0;
+ output_buffer[0] = 0;
+}
+
+//-----------[ constructor with a string argument ]----------------------
+GenAddress::GenAddress(const char *addr,
+ const Address::addr_type use_type)
+{
+ ADDRESS_TRACE;
+
+ // initialize SMI info
+ // BOK: smival is generally not used for GenAddress, but
+ // we need this to be a replica of the real address'
+ // smival info so that ::operator=SnmpSyntax
+ // will work.
+ smival.syntax = sNMP_SYNTAX_NULL; // to be overridden
+ smival.value.string.len = 0; // to be overridden
+ smival.value.string.ptr = address_buffer; // constant
+
+ address = 0;
+ parse_address(addr, use_type);
+
+ // Copy real address smival info into GenAddr smival
+ // BOK: smival is generally not used for GenAddress, but
+ // we need this to be a replica of the real address'
+ // smival info so that ::operator=SnmpSyntax
+ // will work.
+ if (valid_flag ) {
+ smival.syntax = ((GenAddress *)address)->smival.syntax;
+ smival.value.string.len =
+ ((GenAddress *)address)->smival.value.string.len;
+ memcpy(smival.value.string.ptr,
+ ((GenAddress *)address)->smival.value.string.ptr,
+ (size_t)smival.value.string.len);
+ }
+ output_buffer[0] = 0;
+}
+
+//-----------[ constructor with an Address argument ]--------------------
+GenAddress::GenAddress(const Address &addr)
+{
+ ADDRESS_TRACE;
+
+ output_buffer[0] = 0;
+ // initialize SMI info
+ // BOK: this is generally not used for GenAddress,
+ // but we need this to be a replica of the real address'
+ // smival info so that operator=SnmpSyntax will work.
+ smival.syntax = sNMP_SYNTAX_NULL; // to be overridden
+ smival.value.string.len = 0; // to be overridden
+ smival.value.string.ptr = address_buffer; // constant
+
+ valid_flag = false;
+ // make sure that the object is valid
+ if (!addr.valid()) {
+ address = 0;
+ return;
+ }
+
+ // addr can be a GenAddress object and calling clone() on that is bad...
+ if (addr.is_gen_address())
+ address = (Address *)(((const GenAddress&)addr).address->clone());
+ else
+ address = (Address*)addr.clone();
+
+ if (address)
+ valid_flag = address->valid();
+
+ // Copy real address smival info into GenAddr smival
+ // BOK: smival is generally not used for GenAddress, but
+ // we need this to be a replica of the real address'
+ // smival info so that ::operator=SnmpSyntax
+ // will work.
+ if (valid_flag )
+ {
+ smival.syntax = address->get_syntax();
+ smival.value.string.len = ((GenAddress *)address)->smival.value.string.len;
+ memcpy(smival.value.string.ptr,
+ ((GenAddress *)address)->smival.value.string.ptr,
+ (size_t)smival.value.string.len);
+ }
+}
+
+//-----------------[ constructor with another GenAddress object ]-------------
+GenAddress::GenAddress(const GenAddress &addr)
+{
+ ADDRESS_TRACE;
+
+ output_buffer[0] = 0;
+ // initialize SMI info
+ // BOK: this is generally not used for GenAddress,
+ // but we need this to be a replica of the real address'
+ // smival info so that operator=SnmpSyntax will work.
+ smival.syntax = sNMP_SYNTAX_OCTETS;
+ smival.value.string.len = 0;
+ smival.value.string.ptr = address_buffer;
+
+ valid_flag = false;
+ // make sure that the object is valid
+ if (!addr.valid_flag)
+ {
+ address = 0;
+ return;
+ }
+
+ address = (Address *)addr.address->clone();
+ if (address)
+ valid_flag = address->valid();
+
+ // Copy real address smival info into GenAddr smival
+ // BOK: smival is generally not used for GenAddress, but
+ // we need this to be a replica of the real address'
+ // smival info so that ::operator=SnmpSyntax
+ // will work.
+ if (valid_flag )
+ {
+ smival.syntax = ((GenAddress *)address)->smival.syntax;
+ smival.value.string.len = ((GenAddress *)address)->smival.value.string.len;
+ memcpy(smival.value.string.ptr,
+ ((GenAddress *)address)->smival.value.string.ptr,
+ (size_t)smival.value.string.len);
+ }
+}
+
+//------[ assignment GenAddress = GenAddress ]-----------------------------
+GenAddress& GenAddress::operator=(const GenAddress &addr)
+{
+ ADDRESS_TRACE;
+
+ if (this == &addr) return *this; // protect against assignment from itself
+
+ valid_flag = false;
+ if (address)
+ {
+ delete address;
+ address = 0;
+ }
+ if (addr.address)
+ address = (Address *)(addr.address->clone());
+ if (address)
+ valid_flag = address->valid();
+
+ // Copy real address smival info into GenAddr smival
+ // BOK: smival is generally not used for GenAddress, but
+ // we need this to be a replica of the real address'
+ // smival info so that ::operator=SnmpSyntax
+ // will work.
+ if (valid_flag )
+ {
+ smival.syntax = ((GenAddress *)address)->smival.syntax;
+ smival.value.string.len = ((GenAddress *)address)->smival.value.string.len;
+ memcpy(smival.value.string.ptr,
+ ((GenAddress *)address)->smival.value.string.ptr,
+ (size_t)smival.value.string.len);
+ }
+
+ return *this;
+}
+
+//------[ assignment GenAddress = Address ]--------------------------------
+GenAddress& GenAddress::operator=(const Address &addr)
+{
+ ADDRESS_TRACE;
+
+ if (this == &addr) return *this; // protect against assignment from itself
+
+ valid_flag = false;
+ if (address)
+ {
+ delete address;
+ address = 0;
+ }
+
+ // addr can be a GenAddress object and calling clone() on that is bad...
+ if (addr.is_gen_address())
+ address = (Address *)(((const GenAddress&)addr).address->clone());
+ else
+ address = (Address*)addr.clone();
+
+ if (address)
+ valid_flag = address->valid();
+
+ // Copy real address smival info into GenAddr smival
+ // BOK: smival is generally not used for GenAddress, but
+ // we need this to be a replica of the real address'
+ // smival info so that ::operator=SnmpSyntax
+ // will work.
+ if (valid_flag )
+ {
+ smival.syntax = ((GenAddress *)address)->smival.syntax;
+ smival.value.string.len = ((GenAddress *)address)->smival.value.string.len;
+ memcpy(smival.value.string.ptr,
+ ((GenAddress *)address)->smival.value.string.ptr,
+ (size_t)smival.value.string.len);
+ }
+
+ return *this;
+}
+
+
+//------[ assignment GenAddress = any SnmpSyntax ]-----------------------
+SnmpSyntax& GenAddress::operator=(const SnmpSyntax &val)
+{
+ ADDRESS_TRACE;
+
+ if (this == &val) return *this; // protect against assignment from itself
+
+ valid_flag = false; // will get set to TRUE if really valid
+ if (address)
+ {
+ delete address;
+ address = 0;
+ }
+
+ if (val.valid())
+ {
+ switch (val.get_syntax() )
+ {
+ //-----[ ip address case ]-------------
+ // BOK: this case shouldn't be needed since there is an explicit
+ // GenAddr=Address assignment that will override this assignment.
+ // Left here for posterity.
+ case sNMP_SYNTAX_IPADDR:
+ {
+ address = new IpAddress(val.get_printable());
+ if (address)
+ valid_flag = address->valid();
+ }
+ break;
+
+ //-----[ udp address case ]------------
+ //-----[ ipx address case ]------------
+ //-----[ mac address case ]------------
+ // BOK: This is here only to support GenAddr = primitive OctetStr.
+ // The explicit GenAddr=Address assignment will handle the cases
+ // GenAddr = [UdpAdd|IpxAddr|IpxSock|MacAddr].
+ // Note, using the heuristic of octet str len to determine type of
+ // address to create is not accurate when address lengths are equal
+ // (e.g., UDPIPLEN == MACLEN). It gets worse if we add AppleTalk or
+ // OSI which use variable length addresses!
+ case sNMP_SYNTAX_OCTETS:
+ {
+ unsigned long val_len;
+ val_len = ((GenAddress &)val).smival.value.string.len;
+
+ if ((val_len == UDPIPLEN) || (val_len == UDPIP6LEN))
+ address = new UdpAddress;
+ else if ((val_len == IPLEN) || (val_len == IPLEN))
+ address = new IpAddress;
+#ifdef _IPX_ADDRESS
+ else if (val_len == IPXLEN)
+ address = new IpxAddress;
+ else if (val_len == IPXSOCKLEN)
+ address = new IpxSockAddress;
+#endif
+#ifdef _MAC_ADDRESS
+ else if (val_len == MACLEN)
+ address = new MacAddress;
+#endif
+
+ if (address)
+ {
+ *address = val;
+ valid_flag = address->valid();
+ }
+ }
+ break;
+ } // end switch
+ }
+
+ // Copy real address smival info into GenAddr smival
+ // BOK: smival is generally not used for GenAddress, but
+ // we need this to be a replica of the real address'
+ // smival info so that ::operator=SnmpSyntax
+ // will work.
+ if (valid_flag )
+ {
+ smival.syntax = ((GenAddress *)address)->smival.syntax;
+ smival.value.string.len = ((GenAddress *)address)->smival.value.string.len;
+ memcpy(smival.value.string.ptr,
+ ((GenAddress *)address)->smival.value.string.ptr,
+ (size_t)smival.value.string.len);
+ }
+
+ return *this;
+}
+
+
+// redefined parse address for macs
+bool GenAddress::parse_address(const char *addr,
+ const Address::addr_type use_type)
+{
+ ADDRESS_TRACE;
+
+ if (address) delete address;
+
+ // try to create each of the addresses until the correct one
+ // is found
+
+ //BOK: Need to try IPX Sock and IPX before UDP since on Win32,
+ // gethostbyname() seems to think the ipx network number
+ // portion is a valid ipaddress string... stupid WinSOCK!
+
+#ifdef _IPX_ADDRESS
+ if ((use_type == Address::type_invalid) ||
+ (use_type == Address::type_ipxsock))
+ {
+ // ipxsock address
+ address = new IpxSockAddress(addr);
+ valid_flag = address->valid();
+ if (valid_flag && ((IpxSockAddress*)address)->get_socket())
+ return TRUE; // ok its an ipxsock address
+
+ delete address; // otherwise delete it and try another
+ }
+
+ if ((use_type == Address::type_invalid) ||
+ (use_type == Address::type_ipx))
+ {
+ // ipx address
+ address = new IpxAddress(addr);
+ valid_flag = address->valid();
+ if (valid_flag)
+ return TRUE; // ok its an ipx address
+
+ delete address; // otherwise delete it and try another
+ }
+#endif // _IPX_ADDRESS
+
+ //TM: Must try the derived classes first...one pitfall of the
+ //following solution is if someone creates with a port/socket of 0 the
+ //class will get demoted to ip/ipx. The only proper way to do this is
+ //to parse the strings ourselves.
+
+ if ((use_type == Address::type_invalid) ||
+ (use_type == Address::type_udp))
+ {
+ // udp address
+ address = new UdpAddress(addr);
+ valid_flag = address->valid();
+ if (valid_flag && ((UdpAddress*)address)->get_port())
+ return TRUE; // ok its a udp address
+
+ delete address; // otherwise delete it and try another
+ }
+
+ if ((use_type == Address::type_invalid) ||
+ (use_type == Address::type_ip))
+ {
+ // ip address
+ address = new IpAddress(addr);
+ valid_flag = address->valid();
+ if (valid_flag)
+ return TRUE; // ok its an ip address
+
+ delete address; // otherwise delete it and try another
+ }
+
+#ifdef _MAC_ADDRESS
+ if ((use_type == Address::type_invalid) ||
+ (use_type == Address::type_mac))
+ {
+ // mac address
+ address = new MacAddress(addr);
+ valid_flag = address->valid();
+ if (valid_flag)
+ return TRUE; // ok, its a mac
+
+ delete address; // otherwise its invalid
+ }
+#endif // _MAC_ADDRESS
+
+ address = 0;
+ return FALSE;
+}
diff --git a/backend/camembert/libkmsnmp/address.h b/backend/camembert/libkmsnmp/address.h
new file mode 100644
index 0000000..b1a1ddf
--- /dev/null
+++ b/backend/camembert/libkmsnmp/address.h
@@ -0,0 +1,1081 @@
+/*_############################################################################
+ _##
+ _## address.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++ A D D R E S S . H
+
+ ADDRESS CLASS DEFINITION
+
+ DESIGN + 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: address.h,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $
+
+#ifndef _ADDRESS
+#define _ADDRESS
+
+
+//----[ includes ]-----------------------------------------------------
+#include
+#include
+
+#include "config_snmp_pp.h" // for _IPX_ADDRESS and _MAC_ADDRESS
+#include "smival.h"
+#include "collect.h"
+
+// include sockets header files
+// for Windows16 and Windows32 include Winsock
+// otherwise assume UNIX
+#ifdef __unix
+// The /**/ stuff below is meant to fool MS C++ into skipping these
+// files when creating its makefile. 8-Dec-95 TM
+#include /**/
+#include /**/
+#include /**/
+#include /**/
+#include /**/
+#if defined _AIX
+#include // This is needed for FD_SET, bzero
+#endif
+
+#if !defined __CYGWIN32__ && !defined __hpux && !defined linux && !defined _AIX
+extern int h_errno; // defined in WinSock header, but not for UX?!
+#endif
+#endif // __unix
+
+
+#ifdef WIN32
+#ifndef __unix // __unix overrides WIN32 if both options are present
+#include
+#endif
+#endif
+
+//----[ macros ]-------------------------------------------------------
+#define BUFSIZE 40 // worst case of address lens
+#define OUTBUFF 80 // worst case of output lens
+
+#define IPLEN 4
+#define IP6LEN 16
+#define UDPIPLEN 6
+#define UDPIP6LEN 18
+#define IPXLEN 10
+#define IPXSOCKLEN 12
+#define MACLEN 6
+#define MAX_FRIENDLY_NAME 80
+#define HASH0 19
+#define HASH1 13
+#define HASH2 7
+
+//---[ forward declarations ]-----------------------------------------
+class GenAddress;
+
+//----[ Address class ]-----------------------------------------------
+
+/**
+ * Base class of all Address classes.
+ */
+class DLLOPT Address : public SnmpSyntax
+{
+ friend class GenAddress;
+
+ public:
+ //----[ enumerated types for address types ]---------------------------
+ /**
+ * Type returned by Address::get_type().
+ */
+ enum addr_type
+ {
+ type_ip, ///< IpAddress (IPv4 or IPv6)
+ type_ipx, ///< IpxAddress
+ type_udp, ///< UdpAddress (IPv4 or IPv6)
+ type_ipxsock, ///< IpxSockAddress
+ type_mac, ///< MacAddress
+ type_invalid ///< Used by GenAddress::get_type() if address is not valid
+ };
+
+ /**
+ * Type returned by IpAddress::get_ip_version() and
+ * UdpAddress::get_ip_version().
+ */
+ enum version_type
+ {
+ version_ipv4, ///< IPv4
+ version_ipv6 ///< IPv6
+ };
+
+ /**
+ * Default constructor, clears the buffer and sets valid flag to false.
+ */
+ Address();
+
+ /**
+ * Allow destruction of derived classes.
+ */
+ virtual ~Address() {};
+
+ /// overloaded equivlence operator, are two addresses equal?
+ DLLOPT friend int operator==(const Address &lhs,const Address &rhs);
+
+ /// overloaded not equivlence operator, are two addresses not equal?
+ DLLOPT friend int operator!=(const Address &lhs, const Address &rhs)
+ { return !(lhs == rhs); };
+
+ /// overloaded > operator, is a1 > a2
+ DLLOPT friend int operator>(const Address &lhs,const Address &rhs);
+
+ /// overloaded >= operator, is a1 >= a2
+ DLLOPT friend int operator>=(const Address &lhs,const Address &rhs)
+ { if ((lhs > rhs) || (lhs == rhs)) return true; return false; };
+
+ /// overloaded < operator, is a1 < a2
+ DLLOPT friend int operator<(const Address &lhs,const Address &rhs);
+
+ /// overloaded <= operator, is a1 <= a2
+ DLLOPT friend int operator<=(const Address &lhs, const Address &rhs)
+ { if ((lhs < rhs) || (lhs == rhs)) return true; return false; };
+
+ /// equivlence operator overloaded, are an address and a string equal?
+ DLLOPT friend int operator==(const Address &lhs,const char *rhs);
+
+ /// overloaded not equivlence operator, are an address and string not equal?
+ DLLOPT friend int operator!=(const Address &lhs,const char *rhs)
+ { return !(lhs == rhs); };
+
+ /// overloaded < , is an address greater than a string?
+ DLLOPT friend int operator>(const Address &lhs,const char *rhs);
+
+ /// overloaded >=, is an address greater than or equal to a string?
+ DLLOPT friend int operator>=(const Address &lhs,const char *rhs);
+
+ /// overloaded < , is an address less than a string?
+ DLLOPT friend int operator<(const Address &lhs,const char *rhs);
+
+ /// overloaded <=, is an address less than or equal to a string?
+ DLLOPT friend int operator<=(const Address &lhs,const char *rhs);
+
+ /**
+ * Overloaded operator for streaming output.
+ *
+ * @return String containing the numerical address
+ */
+ virtual operator const char *() const = 0;
+
+ /**
+ * Return if the object contains a valid address.
+ *
+ * @return true if the object is valid
+ */
+ virtual bool valid() const { return valid_flag; };
+
+ /**
+ * Return the space needed for serialization.
+ */
+ virtual int get_asn1_length() const = 0;
+
+ /**
+ * Access as an array (read and write).
+ * @note Only pass in values between 0 and get_length().
+ *
+ * @param position - pos to return
+ * @return reference to the byte at the given position
+ */
+ unsigned char& operator[](const int position)
+ { addr_changed = true;
+ return (position < BUFSIZE) ? address_buffer[position]
+ : address_buffer[0]; };
+
+ /**
+ * Access as an array (read only).
+ * @note Only pass in values between 0 and get_length().
+ *
+ * @param position - pos to return
+ * @return the byte at the given position
+ */
+ unsigned char operator[](const int position) const
+ { return (position < BUFSIZE) ? address_buffer[ position] : 0; }
+
+
+ /**
+ * Get the length of the binary address (accessible through operator[]).
+ */
+ virtual int get_length() = 0;
+
+ /**
+ * Get the type of the address.
+ * @see Address::addr_type
+ */
+ virtual addr_type get_type() const = 0;
+
+ /**
+ * Overloaded assignment operator.
+ */
+ virtual SnmpSyntax& operator=(const SnmpSyntax &val) = 0;
+
+ // return a hash key
+ virtual unsigned int hashFunction() const { return 0;};
+
+ protected:
+ bool addr_changed;
+ bool valid_flag;
+ unsigned char address_buffer[BUFSIZE]; // internal representation
+
+ // parse the address string
+ // redefined for each specific address subclass
+ virtual bool parse_address(const char * inaddr) = 0;
+
+ // format the output
+ // redefined for each specific address subclass
+ virtual void format_output() const = 0;
+
+ /**
+ * Trim of whitespaces at the start and the end of the string.
+ *
+ * @param ptr - string to trim
+ */
+ void trim_white_space(char * ptr);
+
+ /**
+ * Is this a GenAddress object.
+ */
+ virtual bool is_gen_address() const { return false; };
+};
+
+
+//-----------------------------------------------------------------------
+//---------[ IP Address Class ]------------------------------------------
+//-----------------------------------------------------------------------
+class DLLOPT IpAddress : public Address
+{
+ public:
+ /**
+ * Construct an empty invalid IP address.
+ */
+ IpAddress();
+
+ /**
+ * Construct an IP address from a string.
+ *
+ * The following formats can be used:
+ * - hostname with or without domain ("www.agentpp.com", "printsrv")
+ * - Numerical IPv4 address ("192.168.17.1")
+ * - Numerical IPv6 address ("abcd:1234::a:b:1", "::abcd:1")
+ *
+ * @param inaddr - Hostname or IP address
+ */
+ IpAddress(const char *inaddr);
+
+ /**
+ * Construct an IP address from another IP address.
+ *
+ * @param ipaddr - address to copy
+ */
+ IpAddress(const IpAddress &ipaddr);
+
+ /**
+ * Construct an IP address from a GenAddress.
+ *
+ * @param genaddr - address to copy
+ */
+ IpAddress(const GenAddress &genaddr);
+
+ /**
+ * Destructor (ensure that SnmpSyntax::~SnmpSyntax() is overridden).
+ */
+ ~IpAddress() {};
+
+ /**
+ * Map other SnmpSyntax objects to IpAddress.
+ */
+ SnmpSyntax& operator=(const SnmpSyntax &val);
+
+ /**
+ * Overloaded assignment operator for other IP addresses.
+ */
+ IpAddress& operator=(const IpAddress &ipaddress);
+
+ /**
+ * Overloaded assignment operator for strings.
+ */
+ IpAddress& operator=(const char *inaddr);
+
+ /**
+ * Clone this object.
+ *
+ * @return Pointer to the newly created object (allocated through new).
+ */
+ SnmpSyntax *clone() const { return (SnmpSyntax *) new IpAddress(*this); };
+
+ /**
+ * Return the friendly name. Does a reverse DNS lookup for the IP address.
+ *
+ * @param status - The errno value for the lookup
+ *
+ * @return the friendly name or a zero length string (no null pointer)
+ */
+ char *friendly_name(int &status);
+
+ /**
+ * Get a printable ASCII value of the address.
+ *
+ * @return String containing the numerical address
+ */
+ virtual const char *get_printable() const
+ { if (addr_changed) format_output(); return output_buffer; };
+
+ /**
+ * Overloaded operator for streaming output.
+ *
+ * @return String containing the numerical address
+ */
+ virtual operator const char *() const
+ { if (addr_changed) format_output(); return output_buffer; };
+
+ /**
+ * Logically AND the address with the param.
+ *
+ * @param ipaddr - address to use as mask
+ */
+ void mask(const IpAddress &ipaddr);
+
+ /**
+ * Get the length of the binary address (accessible through operator[]).
+ */
+ virtual int get_length()
+ { return (ip_version == version_ipv4) ? IPLEN : IP6LEN; };
+
+ /**
+ * Return the type of the address.
+ * @see Address::addr_type
+ * @return Always Address:type_ip
+ */
+ virtual addr_type get_type() const { return type_ip; };
+
+ /**
+ * Return the syntax.
+ *
+ * @return This method always returns sNMP_SYNTAX_IPADDR.
+ */
+ virtual SmiUINT32 get_syntax() const { return sNMP_SYNTAX_IPADDR; };
+
+ /**
+ * Return the space needed for serialization.
+ */
+ virtual int get_asn1_length() const
+ { return (ip_version == version_ipv4) ? (IPLEN + 2) : (IP6LEN + 2); };
+
+ /**
+ * Return the IP version of the address.
+ *
+ * @return one of Address::version_type
+ */
+ virtual version_type get_ip_version() { return ip_version; };
+
+ /**
+ * Map a IPv4 address to a IPv6 address.
+ *
+ * @return - TRUE if no error occured.
+ */
+ virtual int map_to_ipv6();
+
+ protected:
+ char output_buffer[OUTBUFF]; // output buffer
+
+ // friendly name storage
+ char iv_friendly_name[MAX_FRIENDLY_NAME];
+ int iv_friendly_name_status;
+
+ // redefined parse address
+ // specific to IP addresses
+ virtual bool parse_address(const char *inaddr);
+
+
+ // redefined format output
+ // specific to IP addresses
+ virtual void format_output() const;
+
+ // parse a dotted string
+ int parse_dotted_ipstring(const char *inaddr);
+
+ // parse a coloned string
+ int parse_coloned_ipstring(const char *inaddr);
+
+ // using the currently defined address, do a DNS
+ // and try to fill up the name
+ int addr_to_friendly();
+
+ // support both ipv4 and ipv6 addresses
+ version_type ip_version;
+};
+
+//------------------------------------------------------------------------
+//---------[ UDP Address Class ]------------------------------------------
+//------------------------------------------------------------------------
+class DLLOPT UdpAddress : public IpAddress
+{
+ public:
+ /**
+ * Construct an empty invalid UDP address.
+ */
+ UdpAddress();
+
+ /**
+ * Construct an UDP address from a string.
+ *
+ * The following formats can be used additional to those recognized by
+ * IpAdress:
+ * - Port added to IPv4 address with '/' or ':'
+ * ("192.168.17.1:161", "192.168.17.1/161", "printsrv/161")
+ * - Port added to IPv6 address with '/' or using '[...]:'
+ * ("::1/162", "[::1]/162", "[::1]:162")
+ *
+ * @param inaddr - Hostname or IP address
+ */
+ UdpAddress(const char *inaddr);
+
+ /**
+ * Construct an UDP address from another UDP address.
+ *
+ * @param udpaddr - address to copy
+ */
+ UdpAddress(const UdpAddress &udpaddr);
+
+ /**
+ * Construct an UDP address from a GenAddress.
+ *
+ * @param genaddr - address to copy
+ */
+ UdpAddress(const GenAddress &genaddr);
+
+ /**
+ * Construct an UDP address from a IP address.
+ * The port will be set to 0.
+ *
+ * @param ipaddr - address to copy
+ */
+ UdpAddress(const IpAddress &ipaddr);
+
+ /**
+ * Destructor (ensure that SnmpSyntax::~SnmpSyntax() is overridden).
+ */
+ ~UdpAddress() {};
+
+ /**
+ * Map other SnmpSyntax objects to UdpAddress.
+ */
+ SnmpSyntax& operator=(const SnmpSyntax &val);
+
+ /**
+ * Overloaded assignment operator for UdpAddress.
+ */
+ UdpAddress& operator=(const UdpAddress &udpaddr);
+
+ /**
+ * Overloaded assignment operator for IpAddress.
+ */
+ UdpAddress& operator=(const IpAddress &ipaddr);
+
+ /**
+ * Overloaded assignment operator for strings.
+ */
+ UdpAddress& operator=(const char *inaddr);
+
+ /**
+ * 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.
+ */
+ virtual int get_asn1_length() const
+ { return (ip_version == version_ipv4) ? (UDPIPLEN + 2) : (UDPIP6LEN + 2);};
+
+ /**
+ * Clone this object.
+ *
+ * @return Pointer to the newly created object (allocated through new).
+ */
+ SnmpSyntax *clone() const { return (SnmpSyntax *) new UdpAddress(*this); };
+
+ /**
+ * Get a printable ASCII value of the address.
+ *
+ * @return String containing the numerical address
+ */
+ virtual const char *get_printable() const
+ { if (addr_changed) format_output(); return output_buffer; };
+
+ /**
+ * Overloaded operator for streaming output.
+ *
+ * @return String containing the numerical address
+ */
+ virtual operator const char *() const
+ { if (addr_changed) format_output(); return output_buffer; };
+
+ /**
+ * Set the port number.
+ *
+ * @note If the object is not valid(), the port may not be set.
+ */
+ void set_port(const unsigned short p);
+
+ /**
+ * Get the port number.
+ *
+ * @return The port number, or 0 is the object is not valid.
+ */
+ unsigned short get_port() const;
+
+ /**
+ * Get the length of the binary address (accessible through operator[]).
+ */
+ virtual int get_length()
+ { return (ip_version == version_ipv4) ? UDPIPLEN : UDPIP6LEN; };
+
+ /**
+ * Return the type of the address.
+ * @see Address::addr_type
+ * @return Always Address:type_udp
+ */
+ virtual addr_type get_type() const { return type_udp; };
+
+ /**
+ * Map a IPv4 UDP address to a IPv6 UDP address.
+ *
+ * @return - TRUE if no error occured.
+ */
+ virtual int map_to_ipv6();
+
+protected:
+ char output_buffer[OUTBUFF]; // output buffer
+ char sep; // separator
+
+ // redefined parse address
+ // specific to IP addresses
+ virtual bool parse_address(const char *inaddr);
+
+ // redefined format output
+ // specific to IP addresses
+ virtual void format_output() const;
+};
+
+#ifdef _MAC_ADDRESS
+//-------------------------------------------------------------------------
+//---------[ 802.3 MAC Address Class ]-------------------------------------
+//-------------------------------------------------------------------------
+class DLLOPT MacAddress : public Address {
+
+public:
+ // constructor, no arguments
+ MacAddress();
+
+ // constructor with a string argument
+ MacAddress(const char *inaddr);
+
+ // constructor with another MAC object
+ MacAddress(const MacAddress &macaddr);
+
+ // construct a MacAddress with a GenAddress
+ MacAddress(const GenAddress &genaddr);
+
+ // destructor
+ ~MacAddress() {};
+
+ /**
+ * 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.
+ */
+ virtual int get_asn1_length() const { return MACLEN + 2; };
+
+ /**
+ * Map other SnmpSyntax objects to MacAddress.
+ */
+ SnmpSyntax& operator=(const SnmpSyntax &val);
+
+ // assignment to another IpAddress object overloaded
+ MacAddress& operator=(const MacAddress &macaddress);
+
+ /**
+ * Clone this object.
+ *
+ * @return Pointer to the newly created object (allocated through new).
+ */
+ SnmpSyntax *clone() const { return (SnmpSyntax *) new MacAddress(*this); };
+
+ /**
+ * Get a printable ASCII value of the address.
+ *
+ * @return String containing the numerical address
+ */
+ virtual const char *get_printable() const
+ { if (addr_changed) format_output(); return output_buffer; };
+
+ /**
+ * Overloaded operator for streaming output.
+ *
+ * @return String containing the numerical address
+ */
+ virtual operator const char *() const
+ { if (addr_changed) format_output(); return output_buffer; };
+
+ /**
+ * Get the length of the binary address (accessible through operator[]).
+ */
+ virtual int get_length() { return MACLEN; };
+
+ /**
+ * Return the type of the address.
+ * @see Address::addr_type
+ * @return Always Address:type_mac
+ */
+ virtual addr_type get_type() const { return type_mac; };
+
+ // return a hash key
+ unsigned int hashFunction() const;
+
+
+protected:
+ char output_buffer[OUTBUFF]; // output buffer
+
+ // redefined parse address for macs
+ virtual bool parse_address(const char *inaddr);
+
+ // redefined format output for MACs
+ virtual void format_output() const;
+};
+#endif // _MAC_ADDRESS
+
+#ifdef _IPX_ADDRESS
+//------------------------------------------------------------------------
+//---------[ IPX Address Class ]------------------------------------------
+//------------------------------------------------------------------------
+class DLLOPT IpxAddress : public Address {
+
+public:
+ // constructor no args
+ IpxAddress();
+
+ // constructor with a string arg
+ IpxAddress(const char *inaddr);
+
+ // constructor with another ipx object
+ IpxAddress(const IpxAddress &ipxaddr);
+
+ // construct with a GenAddress
+ IpxAddress(const GenAddress &genaddr);
+
+ // destructor
+ ~IpxAddress() {};
+
+ /**
+ * Return the syntax.
+ *
+ * @return This method always returns sNMP_SYNTAX_OCTETS.
+ */
+ virtual SmiUINT32 get_syntax() const { return sNMP_SYNTAX_OCTETS; };
+
+ /**
+ * Return the space needed for serialization.
+ */
+ virtual int get_asn1_length() const { return IPXLEN + 2; };
+
+ /**
+ * Map other SnmpSyntax objects to IpxAddress.
+ */
+ SnmpSyntax& operator=(const SnmpSyntax &val);
+
+ // assignment to another IpAddress object overloaded
+ IpxAddress& operator=(const IpxAddress &ipxaddress);
+
+#ifdef _MAC_ADDRESS
+ // get the host id portion of an ipx address
+ int get_hostid(MacAddress& mac);
+#endif
+
+ /**
+ * Clone this object.
+ *
+ * @return Pointer to the newly created object (allocated through new).
+ */
+ SnmpSyntax *clone() const { return (SnmpSyntax *) new IpxAddress(*this); };
+
+ /**
+ * Get a printable ASCII value of the address.
+ *
+ * @return String containing the numerical address
+ */
+ virtual const char *get_printable() const
+ { if (addr_changed) format_output(); return output_buffer; };
+
+ /**
+ * Overloaded operator for streaming output.
+ *
+ * @return String containing the numerical address
+ */
+ virtual operator const char *() const
+ { if (addr_changed) format_output(); return output_buffer; };
+
+ /**
+ * Get the length of the binary address (accessible through operator[]).
+ */
+ virtual int get_length() { return IPXLEN; };
+
+ /**
+ * Return the type of the address.
+ * @see Address::addr_type
+ * @return Always Address:type_ipx
+ */
+ virtual addr_type get_type() const { return type_ipx; };
+
+protected:
+ // ipx format separator
+ char separator;
+ char output_buffer[OUTBUFF]; // output buffer
+
+ // redefined parse address for ipx strings
+ virtual bool parse_address(const char *inaddr);
+
+ // redefined format output for ipx strings
+ // uses same separator as when constructed
+ virtual void format_output() const;
+
+};
+
+
+
+//------------------------------------------------------------------------
+//---------[ IpxSock Address Class ]--------------------------------------
+//------------------------------------------------------------------------
+class DLLOPT IpxSockAddress : public IpxAddress {
+
+public:
+ // constructor, no args
+ IpxSockAddress();
+
+ // constructor with a dotted string
+ IpxSockAddress(const char *inaddr);
+
+ // construct an Udp address with another Udp address
+ IpxSockAddress(const IpxSockAddress &ipxaddr);
+
+ //constructor with a GenAddress
+ IpxSockAddress(const GenAddress &genaddr);
+
+ //constructor with a IpxAddress
+ // default socket # is 0
+ IpxSockAddress(const IpxAddress &ipxaddr);
+
+ // destructor
+ ~IpxSockAddress() {};
+
+ // syntax type
+ //virtual SmiUINT32 get_syntax() const { return sNMP_SYNTAX_OCTETS; };
+
+ /**
+ * Return the space needed for serialization.
+ */
+ virtual int get_asn1_length() const { return IPXSOCKLEN + 2; };
+
+ /**
+ * Map other SnmpSyntax objects to IpxSockAddress.
+ */
+ SnmpSyntax& operator=(const SnmpSyntax &val);
+
+ // assignment to another IpAddress object overloaded
+ IpxSockAddress& operator=(const IpxSockAddress &ipxaddr);
+
+ /**
+ * Clone this object.
+ *
+ * @return Pointer to the newly created object (allocated through new).
+ */
+ SnmpSyntax *clone() const { return (SnmpSyntax *)new IpxSockAddress(*this); };
+
+ // set the socket number
+ void set_socket(const unsigned short s);
+
+ // get the socket number
+ unsigned short get_socket() const;
+
+ /**
+ * Get a printable ASCII value of the address.
+ *
+ * @return String containing the numerical address
+ */
+ virtual const char *get_printable() const
+ { if (addr_changed) format_output(); return output_buffer; };
+
+ /**
+ * Overloaded operator for streaming output.
+ *
+ * @return String containing the numerical address
+ */
+ virtual operator const char *() const
+ { if (addr_changed) format_output(); return output_buffer; };
+
+ /**
+ * Get the length of the binary address (accessible through operator[]).
+ */
+ virtual int get_length() { return IPXSOCKLEN; };
+
+ /**
+ * Return the type of the address.
+ * @see Address::addr_type
+ * @return Always Address:type_ipxsock
+ */
+ virtual addr_type get_type() const { return type_ipxsock; };
+
+protected:
+ char output_buffer[OUTBUFF]; // output buffer
+
+ // redefined parse address for ipx strings
+ virtual bool parse_address(const char *inaddr);
+
+ // redefined format output
+ // specific to IP addresses
+ virtual void format_output() const;
+
+};
+#endif // _IPX_ADDRESS
+
+
+
+
+//-------------------------------------------------------------------------
+//--------[ Generic Address ]----------------------------------------------
+//-------------------------------------------------------------------------
+class DLLOPT GenAddress : public Address
+{
+ public:
+ /**
+ * Construct an empty invalid generic address object.
+ */
+ GenAddress();
+
+ /**
+ * Construct a generic address from a string.
+ *
+ * To optimize the speed of the parsing method, use_type can be used
+ * to indicate that the address string is of the specified type.
+ *
+ * @param addr - address string
+ * @param use_type - if this value is set, the input string is only
+ * parsed for the given type
+ */
+ GenAddress(const char *addr,
+ const Address::addr_type use_type = Address::type_invalid);
+
+ /**
+ * Construct a generic address from an Address object.
+ *
+ * @param addr - Any address object
+ */
+ GenAddress(const Address &addr);
+
+ /**
+ * Construct a generic address from another generic address object.
+ *
+ * @param addr - Generic address object to copy
+ */
+ GenAddress(const GenAddress &addr);
+
+ /**
+ * Destructor, free memory.
+ */
+ ~GenAddress() { if (address) delete address; };
+
+ /**
+ * Return the syntax.
+ *
+ * @return This method returns sNMP_SYNTAX_IPADDR, sNMP_SYNTAX_OCTETS
+ * or sNMP_SYNTAX_NULL if the generic address does not have
+ * an address object.
+ */
+ SmiUINT32 get_syntax() const
+ { return address ? address->get_syntax() : sNMP_SYNTAX_NULL; };
+
+ /**
+ * Return the space needed for serialization.
+ */
+ virtual int get_asn1_length() const
+ { return address ? address->get_asn1_length() : 2; };
+
+ /**
+ * Clone this object.
+ *
+ * @return Pointer to the newly created object (allocated through new).
+ */
+ SnmpSyntax *clone() const { return (SnmpSyntax *)new GenAddress(*this); };
+
+ /**
+ * Overloaded assignment operator for a GenAddress.
+ */
+ GenAddress& operator=(const GenAddress &addr);
+
+ /**
+ * Overloaded assignment operator for a Address.
+ */
+ GenAddress& operator=(const Address &addr);
+
+ /**
+ * Map other SnmpSyntax objects to GenAddress.
+ */
+ SnmpSyntax& operator=(const SnmpSyntax &val);
+
+ /**
+ * Get a printable ASCII value of the address.
+ *
+ * @return String containing the numerical address
+ */
+ virtual const char *get_printable() const
+ { return (address) ? address->get_printable() : output_buffer; };
+
+ /**
+ * Overloaded operator for streaming output.
+ *
+ * @return String containing the numerical address
+ */
+ virtual operator const char *() const
+ { return address ? (const char *)*address : output_buffer; };
+
+ /**
+ * Get the length of the binary address (accessible through operator[]).
+ */
+ virtual int get_length() { return (address) ? address->get_length() : 0; };
+
+ /**
+ * Return the type of the address.
+ * @see Address::addr_type
+ * @return Type of the contained address object or Address::type_invalid
+ * if it is not valid().
+ */
+ virtual addr_type get_type() const
+ { return (valid()) ? address->get_type() : type_invalid; };
+
+ /**
+ * Access the protected address.
+ * The caller must make sure that this GenAddress object ist valid()
+ * and is of the right type (get_type()).
+ */
+ const IpAddress &cast_ipaddress() const { return (IpAddress& )*address; };
+
+ /**
+ * Access the protected address.
+ * The caller must make sure that this GenAddress object ist valid()
+ * and is of the right type (get_type()).
+ */
+ const UdpAddress &cast_udpaddress() const { return (UdpAddress&)*address; };
+
+#ifdef _MAC_ADDRESS
+ /**
+ * Access the protected address.
+ * The caller must make sure that this GenAddress object ist valid()
+ * and is of the right type (get_type()).
+ */
+ const MacAddress &cast_macaddress() const { return (MacAddress&)*address; };
+#endif
+
+#ifdef _IPX_ADDRESS
+ /**
+ * Access the protected address.
+ * The caller must make sure that this GenAddress object ist valid()
+ * and is of the right type (get_type()).
+ */
+ const IpxAddress &cast_ipxaddress() const { return (IpxAddress&)*address; };
+
+ /**
+ * Access the protected address.
+ * The caller must make sure that this GenAddress object ist valid()
+ * and is of the right type (get_type()).
+ */
+ const IpxSockAddress &cast_ipxsockaddress() const
+ { return (IpxSockAddress&)*address; };
+#endif
+
+protected:
+ // pointer to a a concrete address
+ Address *address;
+ char output_buffer[1]; // output buffer
+
+ // redefined parse address for generic address
+ virtual bool parse_address(const char *addr)
+ { return parse_address(addr, Address::type_invalid); };
+
+ virtual bool parse_address(const char *addr,
+ const Address::addr_type use_type);
+
+ // format output for a generic address
+ virtual void format_output() const {};
+
+ /**
+ * Is this a GenAddress object.
+ */
+ virtual bool is_gen_address() const { return true; };
+};
+
+// create AddressCollection type
+typedef SnmpCollection AddressCollection;
+typedef SnmpCollection UdpAddressCollection;
+
+#endif //_ADDRESS
diff --git a/backend/camembert/libkmsnmp/asn1.cpp b/backend/camembert/libkmsnmp/asn1.cpp
new file mode 100644
index 0000000..5833990
--- /dev/null
+++ b/backend/camembert/libkmsnmp/asn1.cpp
@@ -0,0 +1,2093 @@
+/*_############################################################################
+ _##
+ _## asn1.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.
+
+
+
+ A S N 1. C P P
+
+ ASN encoder / decoder implementation
+
+ DESIGN + AUTHOR:
+ Peter E. Mellquist
+
+ LANGUAGE:
+ ANSI C++
+
+ OPERATING SYSTEM(S):
+ MS-Windows Win32
+ BSD UNIX
+
+=====================================================================*/
+char asn1_cpp_version[]="#(@) SNMP++ $Id: asn1.cpp,v 1.1.1.1 2005/03/14 10:55:29 kindman Exp $";
+
+#ifdef __unix
+#include /**/
+#include /**/
+#endif
+
+#include /**/
+
+#ifdef WIN32
+#include
+#endif
+
+#include "config_snmp_pp.h"
+#include "asn1.h"
+#include "v3.h"
+#include "snmperrs.h"
+
+#ifndef NULL
+#define NULL 0
+#endif
+
+#define LENMASK 0x0ff
+
+#define ASN_UNI_PRIV (ASN_UNIVERSAL | ASN_PRIMITIVE)
+#define ASN_SEQ_CON (ASN_SEQUENCE | ASN_CONSTRUCTOR)
+
+/*
+ * asn_parse_int - pulls a long out of an ASN int type.
+ * On entry, datalength is input as the number of valid bytes following
+ * "data". On exit, it is returned as the number of valid bytes
+ * following the end of this object.
+ *
+ * Returns a pointer to the first byte past the end
+ * of this object (i.e. the start of the next object).
+ * Returns NULL on any error.
+ */
+unsigned char * asn_parse_int( unsigned char *data,
+ int *datalength,
+ unsigned char *type,
+ long int *intp,
+ int intsize)
+{
+ /*
+ * ASN.1 integer ::= 0x02 asnlength byte {byte}*
+ * timestamp 0x43 asnlength byte {byte}*
+ */
+ unsigned char *bufp = data;
+ unsigned long asn_length;
+ long value = 0;
+
+ if (intsize != sizeof (long)){
+ ASNERROR("not long");
+ return NULL;
+ }
+ *type = *bufp++;
+ if ((*type != 0x02) && (*type != 0x43) &&
+ (*type != 0x41)) {
+ ASNERROR("Wrong Type. Not an integer");
+ return NULL;
+ }
+ bufp = asn_parse_length(bufp, &asn_length);
+ if (bufp == NULL){
+ ASNERROR("bad length");
+ return NULL;
+ }
+ if ((asn_length + (bufp - data)) > (unsigned long)(*datalength)){
+ ASNERROR("overflow of message");
+ return NULL;
+ }
+ if ((int)asn_length > intsize){
+ ASNERROR("I don't support such large integers");
+ return NULL;
+ }
+ *datalength -= (int)asn_length + (bufp - data);
+ if (*bufp & 0x80)
+ value = -1; /* integer is negative */
+ while(asn_length--)
+ value = (value << 8) | *bufp++;
+ *intp = value;
+ return bufp;
+}
+
+
+/*
+ * asn_parse_unsigned_int - pulls an unsigned long out of an ASN int type.
+ * On entry, datalength is input as the number of valid bytes following
+ * "data". On exit, it is returned as the number of valid bytes
+ * following the end of this object.
+ *
+ * Returns a pointer to the first byte past the end
+ * of this object (i.e. the start of the next object).
+ * Returns NULL on any error.
+ */
+unsigned char * asn_parse_unsigned_int( unsigned char *data,
+ int *datalength,
+ unsigned char *type,
+ unsigned long *intp,
+ int intsize)
+{
+ /*
+ * ASN.1 integer ::= 0x02 asnlength byte {byte}*
+ * 0x43 asnlength byte {byte}*
+ */
+ unsigned char *bufp = data;
+ unsigned long asn_length;
+ unsigned long value = 0;
+
+ // check the size of the object being requested
+ if (intsize != sizeof (long)){
+ ASNERROR("not long");
+ return NULL;
+ }
+
+ // get the type
+ *type = *bufp++;
+ if ((*type != 0x02) && (*type != 0x43) &&
+ (*type != 0x41) && (*type != 0x42) &&
+ (*type != 0x47)) {
+ ASNERROR("Wrong Type. Not an unsigned integer");
+ return NULL;
+ }
+ // pick up the len
+ bufp = asn_parse_length(bufp, &asn_length);
+ if (bufp == NULL){
+ ASNERROR("bad length");
+ return NULL;
+ }
+
+ // check the len for message overflow
+ if ((asn_length + (bufp - data)) > (unsigned long)(*datalength)){
+ ASNERROR("overflow of message");
+ return NULL;
+ }
+
+ // check for legal uint size
+ if (( (int)asn_length > 5) || (((int)asn_length > 4) && (*bufp != 0x00))) {
+ ASNERROR("I don't support such large integers");
+ return NULL;
+ }
+
+ // check for leading 0 octet
+ if (*bufp == 0x00) {
+ bufp++;
+ asn_length--;
+ }
+
+ // fix the returned data length value
+ *datalength -= (int)asn_length + (bufp - data);
+
+ // calculate the value
+ for (long i=0;i<(long)asn_length;i++)
+ value = (value << 8) + (unsigned long) *bufp++;
+
+ // assign return value
+ *intp = value;
+
+ // return the bumped pointer
+ return bufp;
+}
+
+
+/*
+ * asn_build_int - builds an ASN object containing an integer.
+ * On entry, datalength is input as the number of valid bytes following
+ * "data". On exit, it is returned as the number of valid bytes
+ * following the end of this object.
+ *
+ * Returns a pointer to the first byte past the end
+ * of this object (i.e. the start of the next object).
+ * Returns NULL on any error.
+ */
+unsigned char * asn_build_int( unsigned char *data,
+ int *datalength,
+ unsigned char type,
+ long *intp,
+ int intsize)
+{
+ /*
+ * ASN.1 integer ::= 0x02 asnlength byte {byte}*
+ */
+
+ long integer;
+ unsigned long mask;
+
+ if (intsize != sizeof (long))
+ return NULL;
+ integer = *intp;
+ /*
+ * Truncate "unnecessary" bytes off of the most significant end of this
+ * 2's complement integer. There should be no sequence of 9
+ * consecutive 1's or 0's at the most significant end of the
+ * integer.
+ */
+ mask = 0x1FFul << ((8 * (sizeof(long) - 1)) - 1);
+ /* mask is 0xFF800000 on a big-endian machine */
+ while((((integer & mask) == 0) || ((integer & mask) == mask))
+ && intsize > 1){
+ intsize--;
+ integer <<= 8;
+ }
+ data = asn_build_header(data, datalength, type, intsize);
+ if (data == NULL)
+ return NULL;
+ if (*datalength < intsize)
+ return NULL;
+ *datalength -= intsize;
+ mask = 0xFFul << (8 * (sizeof(long) - 1));
+ /* mask is 0xFF000000 on a big-endian machine */
+ while(intsize--){
+ *data++ = (unsigned char)((integer & mask) >> (8 * (sizeof(long) - 1)));
+ integer <<= 8;
+ }
+ return data;
+}
+
+
+/*
+ * asn_build_unsigned_int - builds an ASN object containing an integer.
+ * On entry, datalength is input as the number of valid bytes following
+ * "data". On exit, it is returned as the number of valid bytes
+ * following the end of this object.
+ *
+ * Returns a pointer to the first byte past the end
+ * of this object (i.e. the start of the next object).
+ * Returns NULL on any error.
+ */
+unsigned char * asn_build_unsigned_int( unsigned char *data, // modified data
+ int *datalength, // returned buffer length
+ unsigned char type, // SMI type
+ unsigned long *intp, // Uint to encode
+ int intsize) // size of uint to encode
+{
+ /*
+ * ASN.1 integer ::= 0x02 asnlength byte {byte}*
+ */
+
+ unsigned long u_integer;
+ long u_integer_len;
+ long x;
+
+ // check uint size
+ if (intsize != sizeof (long))
+ return NULL;
+
+
+ // local var point to var passed in
+ u_integer = *intp;
+
+ // figure out the len
+ if ((( u_integer >> 24) & LENMASK) != 0)
+ u_integer_len = 4;
+ else if ((( u_integer >> 16) & LENMASK) !=0)
+ u_integer_len = 3;
+ else if ((( u_integer >> 8) & LENMASK) !=0)
+ u_integer_len = 2;
+ else
+ u_integer_len =1;
+
+ // check for 5 byte len where first byte will be
+ // a null
+ if ((( u_integer >> (8 * (u_integer_len -1))) & 0x080) !=0) {
+ u_integer_len++;
+ }
+
+ // build up the header
+ data = asn_build_header( data, // data buffer to be modified
+ datalength, // length of data buffer
+ type, // SMI type to enode
+ (int)u_integer_len); // length of BER encoded item
+
+ // special case, add a null byte for len of 5
+ if ( u_integer_len ==5) {
+ *data++ = (unsigned char) 0;
+ for (x=1;x> (8 * ((u_integer_len-1)-x)& LENMASK));
+ }
+ else
+ {
+ for (x=0;x> (8 * ((u_integer_len-1)-x)& LENMASK));
+ }
+ *datalength -= u_integer_len;
+ return data;
+}
+
+
+/*
+ * asn_parse_string - pulls an octet string out of an ASN octet string type.
+ * On entry, datalength is input as the number of valid bytes following
+ * "data". On exit, it is returned as the number of valid bytes
+ * following the beginning of the next object.
+ *
+ * "string" is filled with the octet string.
+ *
+ * Returns a pointer to the first byte past the end
+ * of this object (i.e. the start of the next object).
+ * Returns NULL on any error.
+ */
+unsigned char * asn_parse_string( unsigned char *data,
+ int *datalength,
+ unsigned char *type,
+ unsigned char *string,
+ int *strlength)
+{
+ /*
+ * ASN.1 octet string ::= primstring | cmpdstring
+ * primstring ::= 0x04 asnlength byte {byte}*
+ * cmpdstring ::= 0x24 asnlength string {string}*
+ * ipaddress ::= 0x40 4 byte byte byte byte
+ */
+ unsigned char *bufp = data;
+ unsigned long asn_length;
+
+ *type = *bufp++;
+ if ((*type != 0x04) && (*type != 0x24) &&
+ (*type != 0x40) && (*type != 0x44) &&
+ (*type != 0x45)) {
+ ASNERROR("Wrong Type. Not a string");
+ return NULL;
+ }
+ bufp = asn_parse_length(bufp, &asn_length);
+ if (bufp == NULL)
+ return NULL;
+ if ((asn_length + (bufp - data)) > (unsigned long)(*datalength)){
+ ASNERROR("overflow of message");
+ return NULL;
+ }
+ if ((int)asn_length > *strlength){
+ ASNERROR("I don't support such long strings");
+ return NULL;
+ }
+ // fixed
+ memcpy((char *)string, (char *)bufp, (int)asn_length);
+ *strlength = (int)asn_length;
+ *datalength -= (int)asn_length + (bufp - data);
+ return bufp + asn_length;
+}
+
+
+/*
+ * asn_build_string - Builds an ASN octet string object containing the input string.
+ * On entry, datalength is input as the number of valid bytes following
+ * "data". On exit, it is returned as the number of valid bytes
+ * following the beginning of the next object.
+ *
+ * Returns a pointer to the first byte past the end
+ * of this object (i.e. the start of the next object).
+ * Returns NULL on any error.
+ */
+unsigned char * asn_build_string( unsigned char *data,
+ int *datalength,
+ unsigned char type,
+ unsigned char *string,
+ int strlength)
+{
+ /*
+ * ASN.1 octet string ::= primstring | cmpdstring
+ * primstring ::= 0x04 asnlength byte {byte}*
+ * cmpdstring ::= 0x24 asnlength string {string}*
+ * This code will never send a compound string.
+ */
+ data = asn_build_header(data, datalength, type, strlength);
+ if (data == NULL)
+ return NULL;
+ if (*datalength < strlength)
+ return NULL;
+ // fixed
+ memcpy((unsigned char *)data,(unsigned char *)string, strlength);
+ *datalength -= strlength;
+ return data + strlength;
+}
+
+
+/*
+ * asn_parse_header - interprets the ID and length of the current object.
+ * On entry, datalength is input as the number of valid bytes following
+ * "data". On exit, it is returned as the number of valid bytes
+ * in this object following the id and length.
+ *
+ * Returns a pointer to the first byte of the contents of this object.
+ * Returns NULL on any error.
+ */
+unsigned char *asn_parse_header( unsigned char *data,
+ int *datalength,
+ unsigned char *type)
+{
+ unsigned char *bufp = data;
+ register int header_len;
+ unsigned long asn_length;
+
+ /* this only works on data types < 30, i.e. no extension octets */
+ if (IS_EXTENSION_ID(*bufp)){
+ ASNERROR("can't process ID >= 30");
+ return NULL;
+ }
+ *type = *bufp;
+ bufp = asn_parse_length(bufp + 1, &asn_length);
+ if (bufp == NULL)
+ return NULL;
+ header_len = bufp - data;
+ if ((unsigned long)(header_len + asn_length) > (unsigned long)*datalength){
+ ASNERROR("asn length too long");
+ return NULL;
+ }
+ *datalength = (int)asn_length;
+ return bufp;
+}
+
+/*
+ * asn_build_header - builds an ASN header for an object with the ID and
+ * length specified.
+ * On entry, datalength is input as the number of valid bytes following
+ * "data". On exit, it is returned as the number of valid bytes
+ * in this object following the id and length.
+ *
+ * This only works on data types < 30, i.e. no extension octets.
+ * The maximum length is 0xFFFF;
+ *
+ * Returns a pointer to the first byte of the contents of this object.
+ * Returns NULL on any error.
+ */
+unsigned char * asn_build_header( unsigned char *data,
+ int *datalength,
+ unsigned char type,
+ int length)
+{
+ if (*datalength < 1)
+ return NULL;
+ *data++ = type;
+ (*datalength)--;
+ return asn_build_length(data, datalength, length);
+
+}
+
+/*
+ * asn_build_sequence - builds an ASN header for a sequence with the ID and
+ * length specified.
+ * On entry, datalength is input as the number of valid bytes following
+ * "data". On exit, it is returned as the number of valid bytes
+ * in this object following the id and length.
+ *
+ * This only works on data types < 30, i.e. no extension octets.
+ * The maximum length is 0xFFFF;
+ *
+ * Returns a pointer to the first byte of the contents of this object.
+ * Returns NULL on any error.
+ */
+unsigned char * asn_build_sequence( unsigned char *data,
+ int *datalength,
+ unsigned char type,
+ int length)
+{
+ *datalength -= 4;
+ if (*datalength < 0){
+ *datalength += 4; /* fix up before punting */
+ return NULL;
+ }
+ *data++ = type;
+ *data++ = (unsigned char)(0x02 | ASN_LONG_LEN);
+ *data++ = (unsigned char)((length >> 8) & 0xFF);
+ *data++ = (unsigned char)(length & 0xFF);
+ return data;
+
+}
+
+/*
+ * asn_parse_length - interprets the length of the current object.
+ * On exit, length contains the value of this length field.
+ *
+ * Returns a pointer to the first byte after this length
+ * field (aka: the start of the data field).
+ * Returns NULL on any error.
+ */
+unsigned char * asn_parse_length( unsigned char *data,
+ unsigned long *length)
+{
+ unsigned char lengthbyte = *data;
+
+ if (lengthbyte & ASN_LONG_LEN){
+ lengthbyte &= ~ASN_LONG_LEN; /* turn MSb off */
+ if (lengthbyte == 0){
+ ASNERROR("We don't support indefinite lengths");
+ return NULL;
+ }
+ if (lengthbyte > sizeof(int)){
+ ASNERROR("we can't support data lengths that long");
+ return NULL;
+ }
+ // fixed
+ memcpy((char *)length, (char *)data + 1, (int)lengthbyte);
+ *length = ntohl(*length);
+ // ntohl even on ALPHA (DEC/COMPAQ) 64bit platforms works on 32bit int,
+ // whereas long is 64bit - therefore:
+#ifdef alpha
+ *length >>= (8 * ((sizeof(int)) - lengthbyte));
+#else
+ *length >>= (8 * ((sizeof(long)) - lengthbyte));
+#endif
+ // check for length greater than 2^31
+ if (*length > 0x80000000ul) {
+ ASNERROR("SNMP does not support data lengths > 2^31");
+ return NULL;
+ }
+ return data + lengthbyte + 1;
+ } else { /* short asnlength */
+ *length = (long)lengthbyte;
+ return data + 1;
+ }
+}
+
+unsigned char *asn_build_length( unsigned char *data,
+ int *datalength,
+ int length)
+{
+ unsigned char *start_data = data;
+
+ /* no indefinite lengths sent */
+ if (length < 0x80){
+ if (*datalength < 1){
+ ASNERROR("build_length");
+ return NULL;
+ }
+ *data++ = (unsigned char)length;
+ }
+ else if (length <= 0xFF){
+ if (*datalength < 2){
+ ASNERROR("build_length");
+ return NULL;
+ }
+ *data++ = (unsigned char)(0x01 | ASN_LONG_LEN);
+ *data++ = (unsigned char)length;
+ } else if (length <= 0xFFFF) { /* 0xFF < length <= 0xFFFF */
+ if (*datalength < 3){
+ ASNERROR("build_length");
+ return NULL;
+ }
+ *data++ = (unsigned char)(0x02 | ASN_LONG_LEN);
+ *data++ = (unsigned char)((length >> 8) & 0xFF);
+ *data++ = (unsigned char)(length & 0xFF);
+ } else if (length <= 0xFFFFFF) { /* 0xFF < length <= 0xFFFF */
+ if (*datalength < 4){
+ ASNERROR("build_length");
+ return NULL;
+ }
+ *data++ = (unsigned char)(0x03 | ASN_LONG_LEN);
+ *data++ = (unsigned char)((length >> 16) & 0xFF);
+ *data++ = (unsigned char)((length >> 8) & 0xFF);
+ *data++ = (unsigned char)(length & 0xFF);
+ }
+ else {
+ if (*datalength < 5){
+ ASNERROR("build_length");
+ return NULL;
+ }
+ *data++ = (unsigned char)(0x04 | ASN_LONG_LEN);
+ *data++ = (unsigned char)((length >> 24) & 0xFF);
+ *data++ = (unsigned char)((length >> 16) & 0xFF);
+ *data++ = (unsigned char)((length >> 8) & 0xFF);
+ *data++ = (unsigned char)(length & 0xFF);
+ }
+ *datalength -= (data - start_data);
+ return data;
+
+}
+
+/*
+ * asn_parse_objid - pulls an object indentifier out of an ASN object identifier type.
+ * On entry, datalength is input as the number of valid bytes following
+ * "data". On exit, it is returned as the number of valid bytes
+ * following the beginning of the next object.
+ *
+ * "objid" is filled with the object identifier.
+ *
+ * Returns a pointer to the first byte past the end
+ * of this object (i.e. the start of the next object).
+ * Returns NULL on any error.
+ */
+unsigned char *asn_parse_objid( unsigned char *data,
+ int *datalength,
+ unsigned char *type,
+ oid *objid,
+ int *objidlength)
+{
+ /*
+ * ASN.1 objid ::= 0x06 asnlength subidentifier {subidentifier}*
+ * subidentifier ::= {leadingbyte}* lastbyte
+ * leadingbyte ::= 1 7bitvalue
+ * lastbyte ::= 0 7bitvalue
+ */
+ unsigned char *bufp = data;
+ oid *oidp = objid + 1;
+ unsigned long subidentifier;
+ long length;
+ unsigned long asn_length;
+
+ *type = *bufp++;
+ if (*type != 0x06) {
+ ASNERROR("Wrong Type. Not an oid");
+ return NULL;
+ }
+ bufp = asn_parse_length(bufp, &asn_length);
+ if (bufp == NULL)
+ return NULL;
+ if ((asn_length + (bufp - data)) > (unsigned long)(*datalength)){
+ ASNERROR("overflow of message");
+ return NULL;
+ }
+ *datalength -= (int)asn_length + (bufp - data);
+
+ /* Handle invalid object identifier encodings of the form 06 00 robustly */
+ if (asn_length == 0)
+ objid[0] = objid[1] = 0;
+
+ length = asn_length;
+ (*objidlength)--; /* account for expansion of first byte */
+ while (length > 0 && (*objidlength)-- > 0){
+ subidentifier = 0;
+ do { /* shift and add in low order 7 bits */
+ subidentifier = (subidentifier << 7) + (*(unsigned char *)bufp & ~ASN_BIT8);
+ length--;
+ } while (*(unsigned char *)bufp++ & ASN_BIT8); /* last byte has high bit clear */
+ if (subidentifier > (unsigned long)MAX_SUBID){
+ ASNERROR("subidentifier too long");
+ return NULL;
+ }
+ *oidp++ = (oid)subidentifier;
+ }
+
+ /*
+ * The first two subidentifiers are encoded into the first component
+ * with the value (X * 40) + Y, where:
+ * X is the value of the first subidentifier.
+ * Y is the value of the second subidentifier.
+ */
+ subidentifier = (unsigned long)objid[1];
+ if (subidentifier == 0x2B){
+ objid[0] = 1;
+ objid[1] = 3;
+ } else {
+ objid[1] = (unsigned char)(subidentifier % 40);
+ objid[0] = (unsigned char)((subidentifier - objid[1]) / 40);
+ }
+
+ *objidlength = (int)(oidp - objid);
+ return bufp;
+}
+
+/*
+ * asn_build_objid - Builds an ASN object identifier object containing the
+ * input string.
+ * On entry, datalength is input as the number of valid bytes following
+ * "data". On exit, it is returned as the number of valid bytes
+ * following the beginning of the next object.
+ *
+ * Returns a pointer to the first byte past the end
+ * of this object (i.e. the start of the next object).
+ * Returns NULL on any error.
+ */
+unsigned char *asn_build_objid( unsigned char *data,
+ int *datalength,
+ unsigned char type,
+ oid *objid,
+ int objidlength)
+{
+ /*
+ * ASN.1 objid ::= 0x06 asnlength subidentifier {subidentifier}*
+ * subidentifier ::= {leadingbyte}* lastbyte
+ * leadingbyte ::= 1 7bitvalue
+ * lastbyte ::= 0 7bitvalue
+ */
+ // F.Fock correct buffer size must be 5*8bit*MAX_OID_LEN
+ unsigned char buf[MAX_OID_LEN*5];
+ unsigned char *bp = buf;
+ oid *op = objid;
+ int asnlength;
+ unsigned long subid, mask, testmask;
+ int bits, testbits;
+
+ if (objidlength < 2){
+ *bp++ = 0;
+ objidlength = 0;
+ } else {
+ *bp++ = (unsigned char) (op[1] + (op[0] * 40));
+ objidlength -= 2;
+ op += 2;
+ }
+
+ while(objidlength-- > 0){
+ subid = *op++;
+ if (subid < 127){ /* off by one? */
+ *bp++ = (unsigned char )subid;
+ } else {
+ mask = 0x7F; /* handle subid == 0 case */
+ bits = 0;
+ /* testmask *MUST* !!!! be of an unsigned type */
+ for(testmask = 0x7F, testbits = 0; testmask != 0;
+ testmask <<= 7, testbits += 7){
+ if (subid & testmask){ /* if any bits set */
+ mask = testmask;
+ bits = testbits;
+ }
+ }
+ /* mask can't be zero here */
+ for(;mask != 0x7F; mask >>= 7, bits -= 7){
+ /* fix a mask that got truncated above */
+ if (mask == 0x1E00000)
+ mask = 0xFE00000;
+ *bp++ = (unsigned char)(((subid & mask) >> bits) | ASN_BIT8);
+ }
+ *bp++ = (unsigned char)(subid & mask);
+ }
+ }
+ asnlength = bp - buf;
+ data = asn_build_header(data, datalength, type, asnlength);
+ if (data == NULL)
+ return NULL;
+ if (*datalength < asnlength)
+ return NULL;
+ // fixed
+ memcpy((char *)data, (char *)buf, asnlength);
+ *datalength -= asnlength;
+ return data + asnlength;
+}
+
+/*
+ * asn_parse_null - Interprets an ASN null type.
+ * On entry, datalength is input as the number of valid bytes following
+ * "data". On exit, it is returned as the number of valid bytes
+ * following the beginning of the next object.
+ *
+ * Returns a pointer to the first byte past the end
+ * of this object (i.e. the start of the next object).
+ * Returns NULL on any error.
+ */
+unsigned char *asn_parse_null(unsigned char *data,
+ int *datalength,
+ unsigned char *type)
+{
+ /*
+ * ASN.1 null ::= 0x05 0x00
+ */
+ unsigned char *bufp = data;
+ unsigned long asn_length;
+
+ *type = *bufp++;
+ if (*type != 0x05) {
+ ASNERROR("Wrong Type. Not a null");
+ return NULL;
+ }
+ bufp = asn_parse_length(bufp, &asn_length);
+ if (bufp == NULL)
+ return NULL;
+ if (asn_length != 0){
+ ASNERROR("Malformed NULL");
+ return NULL;
+ }
+ *datalength -= (bufp - data);
+ return bufp + asn_length;
+}
+
+
+/*
+ * asn_build_null - Builds an ASN null object.
+ * On entry, datalength is input as the number of valid bytes following
+ * "data". On exit, it is returned as the number of valid bytes
+ * following the beginning of the next object.
+ *
+ * Returns a pointer to the first byte past the end
+ * of this object (i.e. the start of the next object).
+ * Returns NULL on any error.
+ */
+unsigned char *asn_build_null( unsigned char *data,
+ int *datalength,
+ unsigned char type)
+{
+ /*
+ * ASN.1 null ::= 0x05 0x00
+ */
+ return asn_build_header(data, datalength, type, 0);
+}
+
+/*
+ * asn_parse_bitstring - pulls a bitstring out of an ASN bitstring type.
+ * On entry, datalength is input as the number of valid bytes following
+ * "data". On exit, it is returned as the number of valid bytes
+ * following the beginning of the next object.
+ *
+ * "string" is filled with the bit string.
+ *
+ * Returns a pointer to the first byte past the end
+ * of this object (i.e. the start of the next object).
+ * Returns NULL on any error.
+ */
+unsigned char *asn_parse_bitstring( unsigned char *data,
+ int *datalength,
+ unsigned char *type,
+ unsigned char *string,
+ int *strlength)
+{
+ /*
+ * bitstring ::= 0x03 asnlength unused {byte}*
+ */
+ unsigned char *bufp = data;
+ unsigned long asn_length;
+
+ *type = *bufp++;
+ if (*type != 0x03) {
+ ASNERROR("Wrong Type. Not a bitstring");
+ return NULL;
+ }
+ bufp = asn_parse_length(bufp, &asn_length);
+ if (bufp == NULL)
+ return NULL;
+ if ((asn_length + (bufp - data)) > (unsigned long)(*datalength)){
+ ASNERROR("overflow of message");
+ return NULL;
+ }
+ if ((int) asn_length > *strlength){
+ ASNERROR("I don't support such long bitstrings");
+ return NULL;
+ }
+ if (asn_length < 1){
+ ASNERROR("Invalid bitstring");
+ return NULL;
+ }
+ if (*bufp > 7){
+ ASNERROR("Invalid bitstring");
+ return NULL;
+ }
+ // fixed
+ memcpy((char *)string,(char *)bufp, (int)asn_length);
+ *strlength = (int)asn_length;
+ *datalength -= (int)asn_length + (bufp - data);
+ return bufp + asn_length;
+}
+
+
+/*
+ * asn_build_bitstring - Builds an ASN bit string object containing the
+ * input string.
+ * On entry, datalength is input as the number of valid bytes following
+ * "data". On exit, it is returned as the number of valid bytes
+ * following the beginning of the next object.
+ *
+ * Returns a pointer to the first byte past the end
+ * of this object (i.e. the start of the next object).
+ * Returns NULL on any error.
+ */
+unsigned char *asn_build_bitstring( unsigned char *data,
+ int *datalength,
+ unsigned char type,
+ unsigned char *string,
+ int strlength)
+{
+ /*
+ * ASN.1 bit string ::= 0x03 asnlength unused {byte}*
+ */
+ if (strlength < 1 || *string > 7){
+ ASNERROR("Building invalid bitstring");
+ return NULL;
+ }
+ data = asn_build_header(data, datalength, type, strlength);
+ if (data == NULL)
+ return NULL;
+ if (*datalength < strlength)
+ return NULL;
+ // fixed
+ memcpy((char *)data,(char *)string, strlength);
+ *datalength -= strlength;
+ return data + strlength;
+}
+
+
+/*
+ * asn_parse_unsigned_int64 - pulls a 64 bit unsigned long out of an ASN int
+ * type.
+ * On entry, datalength is input as the number of valid bytes following
+ * "data". On exit, it is returned as the number of valid bytes
+ * following the end of this object.
+ *
+ * Returns a pointer to the first byte past the end
+ * of this object (i.e. the start of the next object).
+ * Returns NULL on any error.
+ */
+unsigned char * asn_parse_unsigned_int64( unsigned char *data,
+ int *datalength,
+ unsigned char *type,
+ struct counter64 *cp,
+ int countersize)
+{
+ /*
+ * ASN.1 integer ::= 0x02 asnlength byte {byte}*
+ */
+ unsigned char *bufp = data;
+ unsigned long asn_length;
+ unsigned long low = 0, high = 0;
+ int intsize = 4;
+
+ if (countersize != sizeof(struct counter64)){
+ ASNERROR("not right size");
+ return NULL;
+ }
+ *type = *bufp++;
+ if ((*type != 0x02) && (*type != 0x46)) {
+ ASNERROR("Wrong Type. Not an integer 64");
+ return NULL;
+ }
+ bufp = asn_parse_length(bufp, &asn_length);
+ if (bufp == NULL){
+ ASNERROR("bad length");
+ return NULL;
+ }
+ if ((asn_length + (bufp - data)) > (unsigned long)(*datalength)){
+ ASNERROR("overflow of message");
+ return NULL;
+ }
+ if (((int)asn_length > (intsize * 2 + 1)) ||
+ (((int)asn_length == (intsize * 2) + 1) && *bufp != 0x00)){
+ ASNERROR("I don't support such large integers");
+ return NULL;
+ }
+ *datalength -= (int)asn_length + (bufp - data);
+ if (*bufp & 0x80){
+ low = (unsigned long) -1; // integer is negative
+ high = (unsigned long) -1;
+ }
+ while(asn_length--){
+ high = (high << 8) | ((low & 0xFF000000) >> 24);
+ low = (low << 8) | *bufp++;
+ }
+ cp->low = low;
+ cp->high = high;
+ return bufp;
+}
+
+
+/*
+ * asn_build_unsigned_int64 - builds an ASN object containing a 64 bit integer.
+ * On entry, datalength is input as the number of valid bytes following
+ * "data". On exit, it is returned as the number of valid bytes
+ * following the end of this object.
+ *
+ * Returns a pointer to the first byte past the end
+ * of this object (i.e. the start of the next object).
+ * Returns NULL on any error.
+ */
+unsigned char * asn_build_unsigned_int64( unsigned char *data,
+ int *datalength,
+ unsigned char type,
+ struct counter64 *cp,
+ int countersize)
+{
+ /*
+ * ASN.1 integer ::= 0x02 asnlength byte {byte}*
+ */
+
+ unsigned long low, high;
+ unsigned long mask, mask2;
+ int add_null_byte = 0;
+ int intsize;
+
+ if (countersize != sizeof (struct counter64))
+ return NULL;
+ intsize = 8;
+ low = cp->low;
+ high = cp->high;
+ mask = 0xFFul << (8 * (sizeof(long) - 1));
+ /* mask is 0xFF000000 on a big-endian machine */
+ if ((unsigned char)((high & mask) >> (8 * (sizeof(long) - 1))) & 0x80){
+ /* if MSB is set */
+ add_null_byte = 1;
+ intsize++;
+ }
+ else {
+ /*
+ * Truncate "unnecessary" bytes off of the most significant end of this 2's
+ * complement integer.
+ * There should be no sequence of 9 consecutive 1's or 0's at the most
+ * significant end of the integer.
+ */
+ mask2 = 0x1FFul << ((8 * (sizeof(long) - 1)) - 1);
+ /* mask2 is 0xFF800000 on a big-endian machine */
+ while((((high & mask2) == 0) || ((high & mask2) == mask2))
+ && intsize > 1){
+ intsize--;
+ high = (high << 8)
+ | ((low & mask) >> (8 * (sizeof(long) - 1)));
+ low <<= 8;
+ }
+ }
+ data = asn_build_header(data, datalength, type, intsize);
+ if (data == NULL)
+ return NULL;
+ if (*datalength < intsize)
+ return NULL;
+ *datalength -= intsize;
+ if (add_null_byte == 1){
+ *data++ = '\0';
+ intsize--;
+ }
+ while(intsize--){
+ *data++ = (unsigned char)((high & mask) >> (8 * (sizeof(long) - 1)));
+ high = (high << 8)
+ | ((low & mask) >> (8 * (sizeof(long) - 1)));
+ low <<= 8;
+
+ }
+ return data;
+}
+
+
+// create a pdu
+struct snmp_pdu * snmp_pdu_create( int command)
+{
+ struct snmp_pdu *pdu;
+
+ pdu = (struct snmp_pdu *)malloc(sizeof(struct snmp_pdu));
+ memset((char *)pdu, 0,sizeof(struct snmp_pdu));
+ pdu->command = command;
+#ifdef _SNMPv3
+ pdu->msgid = 0;
+#endif
+ pdu->errstat = 0;
+ pdu->errindex = 0;
+ pdu->enterprise = NULL;
+ pdu->enterprise_length = 0;
+ pdu->variables = NULL;
+ return pdu;
+}
+
+// free content and clear pointers
+void clear_pdu(struct snmp_pdu *pdu)
+{
+ struct variable_list *vp, *ovp;
+
+ vp = pdu->variables;
+ while (vp)
+ {
+ if (vp->name) free((char *)vp->name); // free the oid part
+ if (vp->val.string) free((char *)vp->val.string); // free deep data
+ ovp = vp;
+ vp = vp->next_variable; // go to the next one
+ free((char *)ovp); // free up vb itself
+ }
+ pdu->variables = NULL;
+
+ // if enterprise free it up
+ if (pdu->enterprise)
+ free((char *)pdu->enterprise);
+ pdu->enterprise = NULL;
+}
+
+// free a pdu
+void snmp_free_pdu( struct snmp_pdu *pdu)
+{
+ clear_pdu(pdu); // clear and free content
+ free((char *)pdu); // free up pdu itself
+}
+
+
+// add a null var to a pdu
+void snmp_add_var(struct snmp_pdu *pdu,
+ oid *name,
+ int name_length,
+ SmiVALUE *smival)
+{
+ struct variable_list *vars;
+
+ // if we don't have a vb list ,create one
+ if (pdu->variables == NULL)
+ pdu->variables = vars = (struct variable_list *)malloc(sizeof(struct variable_list));
+ else
+ { // we have one, find the end
+ for(vars = pdu->variables; vars->next_variable; vars = vars->next_variable);
+ // create a new one
+ vars->next_variable = (struct variable_list *)malloc(sizeof(struct variable_list));
+ // bump ptr
+ vars = vars->next_variable;
+ }
+
+ // add the oid with no data
+ vars->next_variable = NULL;
+
+ // hook in the Oid portion
+ vars->name = (oid *)malloc(name_length * sizeof(oid));
+ // fixed
+ memcpy((char *)vars->name,(char *)name, name_length * sizeof(oid));
+ vars->name_length = name_length;
+
+ // hook in the SMI value
+ switch( smival->syntax)
+ {
+ // null , do nothing
+ case sNMP_SYNTAX_NULL:
+ case sNMP_SYNTAX_NOSUCHOBJECT:
+ case sNMP_SYNTAX_NOSUCHINSTANCE:
+ case sNMP_SYNTAX_ENDOFMIBVIEW:
+ {
+ vars->type = (unsigned char) smival->syntax;
+ vars->val.string = NULL;
+ vars->val_len = 0;
+ }
+ break;
+
+ // octects
+ case sNMP_SYNTAX_OCTETS:
+ case sNMP_SYNTAX_OPAQUE:
+ case sNMP_SYNTAX_IPADDR:
+ {
+ vars->type = (unsigned char) smival->syntax;
+ vars->val.string = (unsigned char *)malloc((unsigned)smival->value.string.len);
+ vars->val_len = (int) smival->value.string.len;
+ memcpy( (unsigned char *) vars->val.string,
+ (unsigned char *) smival->value.string.ptr,
+ (unsigned) smival->value.string.len);
+ }
+ break;
+
+ // oid
+ case sNMP_SYNTAX_OID:
+ {
+ vars->type = (unsigned char) smival->syntax;
+ vars->val_len = (int) smival->value.oid.len * sizeof(oid);
+ vars->val.objid = (oid *)malloc((unsigned)vars->val_len);
+ memcpy((unsigned long *)vars->val.objid,
+ (unsigned long *)smival->value.oid.ptr,
+ (unsigned) vars->val_len);
+ }
+ break;
+
+
+
+ case sNMP_SYNTAX_TIMETICKS:
+ case sNMP_SYNTAX_CNTR32:
+ case sNMP_SYNTAX_GAUGE32:
+ // case sNMP_SYNTAX_UINT32:
+ {
+ long templong;
+ vars->type = (unsigned char) smival->syntax;
+ vars->val.integer = (long *)malloc(sizeof(long));
+ vars->val_len = sizeof(long);
+ templong = (long) smival->value.uNumber;
+ memcpy( (long*) vars->val.integer,
+ (long*) &templong,
+ sizeof(long));
+ }
+ break;
+
+ case sNMP_SYNTAX_INT32:
+ {
+ long templong;
+ vars->type = (unsigned char) smival->syntax;
+ vars->val.integer = (long *)malloc(sizeof(long));
+ vars->val_len = sizeof(long);
+ templong = (long) smival->value.sNumber;
+ memcpy( (long*) vars->val.integer,
+ (long*) &templong,
+ sizeof(long));
+ }
+ break;
+
+ // 64 bit counter
+ case sNMP_SYNTAX_CNTR64:
+ {
+ vars->type = ( unsigned char) smival->syntax;
+ vars->val.counter64 = (struct counter64 *)malloc( sizeof(struct counter64) );
+ vars->val_len = sizeof(struct counter64);
+ memcpy( (struct counter64*) vars->val.counter64,
+ (SmiLPCNTR64) &(smival->value.hNumber),
+ sizeof( SmiCNTR64));
+ }
+ break;
+
+ } // end switch
+
+}
+
+// build the authentication
+// works for v1 or v2c
+unsigned char *snmp_auth_build( unsigned char *data,
+ int *length,
+ long int version,
+ unsigned char *community,
+ int community_len,
+ int messagelen)
+{
+ unsigned char *params;
+ int plen;
+
+ params = community;
+ plen = community_len;
+
+ data = asn_build_sequence(data,
+ length,
+ (unsigned char)(ASN_SEQUENCE | ASN_CONSTRUCTOR),
+ messagelen + plen + 5);
+ if (data == NULL){
+ ASNERROR("buildheader");
+ return NULL;
+ }
+ data = asn_build_int(data,
+ length,
+ (unsigned char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
+ (long *)&version,
+ sizeof(version));
+ if (data == NULL){
+ ASNERROR("buildint");
+ return NULL;
+ }
+
+ data = asn_build_string(data,
+ length,
+ (unsigned char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OCTET_STR),
+ params,
+ plen );
+ if (data == NULL){
+ ASNERROR("buildstring");
+ return NULL;
+ }
+
+ return (unsigned char *)data;
+}
+
+
+// build a variable binding
+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)
+
+{
+ int dummyLen, headerLen;
+ unsigned char *dataPtr;
+
+ dummyLen = *listlength;
+ dataPtr = data;
+
+
+ data += 4;
+ dummyLen -=4;
+ if (dummyLen < 0)
+ return NULL;
+
+ headerLen = data - dataPtr;
+ *listlength -= headerLen;
+ data = asn_build_objid( data,
+ listlength,
+ (unsigned char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OBJECT_ID),
+ var_name,
+ *var_name_len);
+ if (data == NULL){
+ ASNERROR("data is null");
+ return NULL;
+ }
+
+ // based on the type...
+ switch(var_val_type){
+ case ASN_INTEGER:
+ data = asn_build_int( data,
+ listlength,
+ var_val_type,
+ (long *)var_val,
+ var_val_len);
+ break;
+
+ case SMI_GAUGE:
+ case SMI_COUNTER:
+ case SMI_TIMETICKS:
+ case SMI_UINTEGER:
+ data = asn_build_unsigned_int( data,
+ listlength,
+ var_val_type,
+ (unsigned long *)var_val,
+ var_val_len);
+ break;
+
+ case SMI_COUNTER64:
+ data = asn_build_unsigned_int64(data,
+ listlength,
+ var_val_type,
+ (struct counter64 *)var_val,
+ var_val_len);
+ break;
+
+ case ASN_OCTET_STR:
+ case SMI_IPADDRESS:
+ case SMI_OPAQUE:
+ case SMI_NSAP:
+ data = asn_build_string(data, listlength, var_val_type,
+ var_val, var_val_len);
+ break;
+
+ case ASN_OBJECT_ID:
+ data = asn_build_objid(data, listlength, var_val_type,
+ (oid *)var_val, var_val_len / sizeof(oid));
+ break;
+
+ case ASN_NULL:
+ data = asn_build_null(data, listlength, var_val_type);
+ break;
+
+ case ASN_BIT_STR:
+ data = asn_build_bitstring(data, listlength, var_val_type,
+ var_val, var_val_len);
+ break;
+
+ case SNMP_NOSUCHOBJECT:
+ case SNMP_NOSUCHINSTANCE:
+ case SNMP_ENDOFMIBVIEW:
+ data = asn_build_null(data, listlength, var_val_type);
+ break;
+
+ default:
+ ASNERROR("wrong type");
+ return NULL;
+ }
+ if (data == NULL){
+ ASNERROR("data is null");
+ return NULL;
+ }
+ dummyLen = (data - dataPtr) - headerLen;
+
+ asn_build_sequence(dataPtr,
+ &dummyLen,
+ (unsigned char)(ASN_SEQUENCE | ASN_CONSTRUCTOR),
+ dummyLen);
+ return data;
+}
+
+
+unsigned char *build_vb(struct snmp_pdu *pdu,
+ unsigned char *buf, int *buf_len)
+{
+ struct variable_list *vp;
+ unsigned char *cp;
+ unsigned char tmp_buf[SNMP_MSG_LENGTH];
+ int vb_length;
+ int length;
+
+ // build varbinds into packet buffer
+ cp = tmp_buf;
+ length = SNMP_MSG_LENGTH;
+ for(vp = pdu->variables; vp; vp = vp->next_variable)
+ {
+ cp = snmp_build_var_op( cp, vp->name, &vp->name_length,
+ vp->type, vp->val_len,
+ (unsigned char *)vp->val.string,
+ &length);
+ if (cp == NULL) return 0;
+ }
+ vb_length = cp - tmp_buf;
+ *buf_len -= vb_length;
+ if (*buf_len <= 0) return 0;
+
+ // encode the length of encoded varbinds into buf
+ cp = asn_build_header( buf, buf_len,
+ (unsigned char)(ASN_SEQUENCE | ASN_CONSTRUCTOR),
+ vb_length);
+ if (cp == NULL) return 0;
+
+ // copy varbinds from packet behind header in buf
+ memcpy( (char *)cp, (char *)tmp_buf, vb_length);
+
+ return (cp + vb_length);
+}
+
+unsigned char *build_data_pdu(struct snmp_pdu *pdu,
+ unsigned char *buf, int *buf_len,
+ unsigned char *vb_buf, int vb_buf_len)
+{
+ unsigned char tmp_buf[SNMP_MSG_LENGTH];
+ unsigned char *cp;
+ int totallength;
+ int length;
+
+ // build data of pdu into tmp_buf
+ length = SNMP_MSG_LENGTH;
+ if (pdu->command != TRP_REQ_MSG)
+ {
+ // request id
+ cp = asn_build_int( tmp_buf, &length,
+ (unsigned char )(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
+ (long *)&pdu->reqid, sizeof(pdu->reqid));
+ if (cp == NULL) return 0;
+
+ // error status
+ cp = asn_build_int(cp, &length,
+ (unsigned char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
+ (long *)&pdu->errstat, sizeof(pdu->errstat));
+ if (cp == NULL) return 0;
+
+ // error index
+ cp = asn_build_int(cp, &length,
+ (unsigned char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
+ (long *)&pdu->errindex, sizeof(pdu->errindex));
+ if (cp == NULL) return 0;
+ }
+ else
+ { // this is a trap message
+ // enterprise
+ cp = asn_build_objid( tmp_buf, &length,
+ (unsigned char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OBJECT_ID),
+ (oid *)pdu->enterprise, pdu->enterprise_length);
+ if (cp == NULL) return 0;
+
+ // agent-addr ; must be IPADDRESS changed by Frank Fock
+ cp = asn_build_string(cp, &length,
+ (unsigned char)(SMI_IPADDRESS),
+ (unsigned char *)&pdu->agent_addr.sin_addr.s_addr,
+ sizeof(pdu->agent_addr.sin_addr.s_addr));
+ if (cp == NULL) return 0;
+
+ long dummy = pdu->trap_type;
+ // generic trap
+ cp = asn_build_int(cp, &length,
+ (unsigned char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
+ &dummy, sizeof(dummy));
+ if (cp == NULL) return 0;
+
+ dummy = pdu->specific_type;
+ // specific trap
+ cp = asn_build_int( cp, &length,
+ (unsigned char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
+ &dummy, sizeof(dummy));
+ if (cp == NULL) return 0;
+
+ // timestamp
+ cp = asn_build_unsigned_int(cp, &length,
+ (unsigned char )(SMI_TIMETICKS),
+ &pdu->time, sizeof(pdu->time));
+ if (cp == NULL) return 0;
+ }
+
+ if (length < vb_buf_len) return 0;
+
+ // save relative position of varbinds
+ int vb_rel_pos = cp - tmp_buf;
+ totallength = (cp - tmp_buf) + vb_buf_len;
+
+ // build header for datapdu into buf
+ cp = asn_build_header(buf, buf_len,
+ (unsigned char)pdu->command, totallength);
+ if (cp == NULL) return 0;
+ if (*buf_len < totallength) return 0;
+
+ // copy data behind header
+ memcpy((char *)cp, (char *)tmp_buf, totallength - vb_buf_len);
+ memcpy((char *)cp + vb_rel_pos, (char *)vb_buf, vb_buf_len);
+ *buf_len -= totallength;
+ return (cp + totallength);
+}
+
+// serialize the pdu
+int snmp_build( struct snmp_pdu *pdu,
+ unsigned char *packet,
+ int *out_length,
+ long version,
+ unsigned char* community,
+ int community_len)
+{
+ unsigned char buf[SNMP_MSG_LENGTH];
+ unsigned char *cp;
+ int length;
+ int totallength;
+
+ // encode vbs with header into packet
+ length = *out_length;
+ cp = build_vb(pdu, packet, &length);
+ if (cp == 0) return -1;
+ totallength = cp - packet;
+ if (totallength >= *out_length) return -1;
+
+ // encode datadpu into buf
+ length = SNMP_MSG_LENGTH;
+ cp = build_data_pdu(pdu, buf, &length,
+ packet, totallength);
+ if (cp == 0) return -1;
+ totallength = cp - buf;
+ if (totallength >= *out_length) return -1;
+
+ // build SNMP header
+ length = *out_length;
+ cp = snmp_auth_build( packet, &length, version,
+ community, community_len, totallength );
+ if (cp == NULL) return -1;
+ if ((*out_length - (cp - packet)) < totallength) return -1;
+
+ // copy data
+ memcpy((char *)cp, (char *)buf, totallength);
+ totallength += cp - packet;
+ *out_length = totallength;
+
+ return 0;
+}
+
+// parse the authentication header
+unsigned char *snmp_auth_parse(unsigned char *data,
+ int *length,
+ unsigned char *sid,
+ int *slen,
+ long *version)
+{
+ unsigned char type;
+
+ // get the type
+ data = asn_parse_header( data,
+ length,
+ &type);
+ if (data == NULL){
+ ASNERROR("bad header");
+ return NULL;
+ }
+
+ if (type != (ASN_SEQUENCE | ASN_CONSTRUCTOR)){
+ ASNERROR("wrong auth header type");
+ return NULL;
+ }
+
+ // get the version
+ data = asn_parse_int(data,
+ length,
+ &type,
+ version,
+ sizeof(*version));
+ if (data == NULL){
+ ASNERROR("bad parse of version");
+ return NULL;
+ }
+
+ // get the community name
+ data = asn_parse_string(data,
+ length,
+ &type,
+ sid,
+ slen);
+ if (data == NULL){
+ ASNERROR("bad parse of community");
+ return NULL;
+ }
+
+ return (unsigned char *)data;
+}
+
+unsigned char *
+snmp_parse_var_op( unsigned char *data, // IN - pointer to the start of object
+ oid *var_name, // OUT - object id of variable
+ int *var_name_len, // IN/OUT - length of variable name
+ unsigned char *var_val_type, // OUT - type of variable (int or octet string) (one byte)
+ int *var_val_len, // OUT - length of variable
+ unsigned char **var_val, // OUT - pointer to ASN1 encoded value of variable
+ int *listlength) // IN/OUT - number of valid bytes left in var_op_list
+{
+ unsigned char var_op_type;
+ int var_op_len = *listlength;
+ unsigned char *var_op_start = data;
+
+ data = asn_parse_header(data, &var_op_len, &var_op_type);
+ if (data == NULL){
+ ASNERROR("Error snmp_parse_var_op: 1");
+ return NULL;
+ }
+ if (var_op_type != (unsigned char)(ASN_SEQUENCE | ASN_CONSTRUCTOR))
+ return NULL;
+ data = asn_parse_objid(data, &var_op_len, &var_op_type, var_name, var_name_len);
+ if (data == NULL){
+ ASNERROR("Error snmp_parse_var_op: 2");
+ return NULL;
+ }
+ if (var_op_type != (unsigned char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OBJECT_ID))
+ return NULL;
+ *var_val = data; /* save pointer to this object */
+ /* find out what type of object this is */
+ data = asn_parse_header(data, &var_op_len, var_val_type);
+ if (data == NULL){
+ ASNERROR("Error snmp_parse_var_op: 3");
+ return NULL;
+ }
+ if (((unsigned long)var_op_len + (data - var_op_start)) > (unsigned long)(*listlength)) {
+ ASNERROR("Error snmp_parse_var_op: 4");
+ return NULL;
+ }
+ *var_val_len = (int)var_op_len;
+ data += var_op_len;
+ *listlength -= (int)(data - var_op_start);
+ return data;
+}
+
+
+int snmp_parse_vb(struct snmp_pdu *pdu, unsigned char *&data, int &data_len)
+{
+ unsigned char *var_val;
+ int len;
+ struct variable_list *vp;
+ oid objid[ASN_MAX_NAME_LEN], *op;
+ unsigned char type;
+
+ // get the vb list from received data
+ data = asn_parse_header(data, &data_len, &type);
+ if (data == NULL)
+ return SNMP_CLASS_ASN1ERROR;
+ if (type != (unsigned char)(ASN_SEQUENCE | ASN_CONSTRUCTOR))
+ return SNMP_CLASS_ASN1ERROR;
+ pdu->variables = NULL;
+ while(data_len > 0){
+ if (pdu->variables == NULL){
+ pdu->variables = vp = (struct variable_list *)malloc(sizeof(struct variable_list));
+ } else {
+ vp->next_variable = (struct variable_list *)malloc(sizeof(struct variable_list));
+ vp = vp->next_variable;
+ }
+ vp->next_variable = NULL;
+ vp->val.string = NULL;
+ vp->name = NULL;
+ vp->name_length = ASN_MAX_NAME_LEN;
+ data = snmp_parse_var_op( data, objid, &vp->name_length, &vp->type,
+ &vp->val_len, &var_val, &data_len);
+ if (data == NULL)
+ return SNMP_CLASS_ASN1ERROR;
+ op = (oid *)malloc((unsigned)vp->name_length * sizeof(oid));
+ // fixed
+ memcpy((char *)op, (char *)objid, vp->name_length * sizeof(oid));
+ vp->name = op;
+
+ len = SNMP_MSG_LENGTH;
+ switch((short)vp->type){
+ case ASN_INTEGER:
+ vp->val.integer = (long *)malloc(sizeof(long));
+ vp->val_len = sizeof(long);
+ asn_parse_int(var_val, &len, &vp->type, (long *)vp->val.integer, sizeof(vp->val.integer));
+ break;
+
+ case SMI_COUNTER:
+ case SMI_GAUGE:
+ case SMI_TIMETICKS:
+ case SMI_UINTEGER:
+ vp->val.integer = (long *)malloc(sizeof(long));
+ vp->val_len = sizeof(long);
+ asn_parse_unsigned_int(var_val, &len, &vp->type, (unsigned long *)vp->val.integer, sizeof(vp->val.integer));
+ break;
+
+ case SMI_COUNTER64:
+ vp->val.counter64 = (struct counter64 *)malloc( sizeof(struct counter64) );
+ vp->val_len = sizeof(struct counter64);
+ asn_parse_unsigned_int64(var_val, &len, &vp->type,
+ (struct counter64 *)vp->val.counter64,
+ sizeof(*vp->val.counter64));
+ break;
+
+ case ASN_OCTET_STR:
+ case SMI_IPADDRESS:
+ case SMI_OPAQUE:
+ case SMI_NSAP:
+ vp->val.string = (unsigned char *)malloc((unsigned)vp->val_len);
+ asn_parse_string(var_val, &len, &vp->type, vp->val.string, &vp->val_len);
+ break;
+
+ case ASN_OBJECT_ID:
+ vp->val_len = ASN_MAX_NAME_LEN;
+ asn_parse_objid(var_val, &len, &vp->type, objid, &vp->val_len);
+ //vp->val_len *= sizeof(oid);
+ vp->val.objid = (oid *)malloc((unsigned)vp->val_len * sizeof(oid));
+ // fixed
+ memcpy((char *)vp->val.objid,
+ (char *)objid,
+ vp->val_len * sizeof(oid));
+ break;
+
+ case SNMP_NOSUCHOBJECT:
+ case SNMP_NOSUCHINSTANCE:
+ case SNMP_ENDOFMIBVIEW:
+ case ASN_NULL:
+ break;
+
+ default:
+ ASNERROR("bad type returned ");
+ return SNMP_CLASS_ASN1ERROR;
+ break;
+ }
+ }
+ return SNMP_CLASS_SUCCESS;
+}
+
+
+int snmp_parse_data_pdu(snmp_pdu *pdu, unsigned char *&data, int &length)
+{
+ oid objid[ASN_MAX_NAME_LEN];
+ int four = 4;
+ unsigned char type;
+
+ data = asn_parse_header(data, &length, &type);
+ if (data == NULL) return SNMP_CLASS_ASN1ERROR;
+
+ pdu->command = type;
+
+ if (pdu->command != TRP_REQ_MSG)
+ {
+ // get the rid
+ data = asn_parse_int(data, &length, &type,
+ (long *)&pdu->reqid, sizeof(pdu->reqid));
+ if (data == NULL) return SNMP_CLASS_ASN1ERROR;
+
+ // get the error status
+ data = asn_parse_int(data, &length, &type,
+ (long *)&pdu->errstat, sizeof(pdu->errstat));
+ if (data == NULL) return SNMP_CLASS_ASN1ERROR;
+
+ // get the error index
+ data = asn_parse_int(data, &length, &type,
+ (long *)&pdu->errindex, sizeof(pdu->errindex));
+ if (data == NULL) return SNMP_CLASS_ASN1ERROR;
+ }
+ else
+ { // is a trap
+
+ // get the enterprise
+ pdu->enterprise_length = ASN_MAX_NAME_LEN;
+ data = asn_parse_objid(data, &length, &type,
+ objid, &pdu->enterprise_length);
+ if (data == NULL) return SNMP_CLASS_ASN1ERROR;
+
+ pdu->enterprise = (oid *)malloc(pdu->enterprise_length * sizeof(oid));
+
+ memcpy((char *)pdu->enterprise,(char *)objid,
+ pdu->enterprise_length * sizeof(oid));
+
+ // get source address
+ data = asn_parse_string(data, &length, &type,
+ (unsigned char *)&pdu->agent_addr.sin_addr.s_addr,
+ &four);
+ if (data == NULL) return SNMP_CLASS_ASN1ERROR;
+
+ // get trap type
+ long dummy = 0;
+ data = asn_parse_int(data, &length, &type, &dummy, sizeof(dummy));
+ pdu->trap_type = dummy;
+
+ if (data == NULL) return SNMP_CLASS_ASN1ERROR;
+
+ // trap type
+ dummy = 0;
+ data = asn_parse_int(data, &length, &type, &dummy, sizeof(dummy));
+ pdu->specific_type = dummy;
+ if (data == NULL) return SNMP_CLASS_ASN1ERROR;
+
+ // timestamp
+ data = asn_parse_unsigned_int(data, &length, &type,
+ &pdu->time, sizeof(pdu->time));
+ if (data == NULL) return SNMP_CLASS_ASN1ERROR;
+ }
+ return SNMP_CLASS_SUCCESS;
+}
+
+
+// parse a pdu
+int snmp_parse( struct snmp_pdu *pdu,
+ unsigned char *data,
+ unsigned char *community_name,
+ unsigned long &community_len,
+ snmp_version &spp_version,
+ int length)
+{
+ long version = -1;
+ unsigned char community[256];
+ int community_length = 256;
+
+ // authenticates message and returns length if valid
+ data = snmp_auth_parse(data,
+ &length,
+ community,
+ &community_length,
+ &version);
+ if (data == NULL)
+ return SNMP_CLASS_ASN1ERROR;
+
+ // copy the returned community name
+ memcpy( (unsigned char *) community_name,
+ (unsigned char *) community,
+ community_length);
+ community_len = (long int) community_length;
+
+ if( version != SNMP_VERSION_1 && version != SNMP_VERSION_2C ) {
+ ASNERROR("Wrong version");
+ return SNMP_CLASS_BADVERSION;
+ }
+
+ spp_version = (snmp_version) version;
+
+ int res = snmp_parse_data_pdu(pdu, data, length);
+ if (res != SNMP_CLASS_SUCCESS)
+ return res;
+
+ return snmp_parse_vb(pdu, data, length);
+}
+
+
+// Parse the field HeaderData of a SNMPv3 message and return the values.
+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)
+{
+ unsigned char *buf_ptr = buf;
+ int length = *buf_len;
+ unsigned char type;
+
+ buf = asn_parse_header( buf, &length, &type);
+ if (!buf)
+ {
+ debugprintf(0, "Parse error in header HeaderData");
+ return 0;
+ }
+
+ if (type != (ASN_SEQ_CON)){
+ debugprintf(0, "wrong type in header of msgHeaderData");
+ return 0;
+ }
+
+ buf = asn_parse_int(buf, &length, &type, msg_id, sizeof(*msg_id));
+ if (!buf){
+ debugprintf(0, "Parse error: msg_id");
+ return 0;
+ }
+
+ buf = asn_parse_int(buf, &length,
+ &type, msg_max_size, sizeof(*msg_max_size));
+ if (!buf){
+ debugprintf(0, "Parse error: msg_max_size");
+ return 0;
+ }
+
+ int dummy = 1;
+ buf = asn_parse_string( buf, &length, &type, msg_flags, &dummy);
+
+ if ((dummy !=1) || (!buf)) {
+ debugprintf(0, "Parse error: msg_flags");
+ return 0;
+ }
+
+ buf = asn_parse_int(buf, &length, &type,
+ msg_security_model, sizeof(*msg_security_model));
+ if (!buf){
+ debugprintf(0, "Parse error: msg_security_model");
+ return 0;
+ }
+
+ if (length) {
+ debugprintf(0, "Parse error: wrong length in header of HeaderData");
+ return 0;
+ }
+
+ debugprintf(3, "Parsed HeaderData: globalDataLength(0x%x), msg_id(0x%lx), "
+ "msg_max_size(0x%lx), msg_flags(0x%x), msg_security_model(0x%lx)",
+ length, *msg_id, *msg_max_size, *msg_flags, *msg_security_model);
+
+ *buf_len -= (buf - buf_ptr);
+ return buf;
+}
+
+// Encode the given values for the HeaderData into the buffer.
+unsigned char *asn1_build_header_data(unsigned char *outBuf, int *maxLength,
+ long msgID,
+ long maxMessageSize,
+ unsigned char msgFlags,
+ long securityModel)
+
+{
+ unsigned char buf[MAXLENGTH_BUFFER];
+ unsigned char *bufPtr = (unsigned char*)&buf;
+ unsigned char *outBufPtr = outBuf;
+ int length = *maxLength;
+ int totalLength;
+
+ debugprintf(3, "Coding msgID(0x%lx), maxMessageSize(0x%lx), "
+ "msgFlags(0x%x), securityModel(0x%lx)",
+ maxMessageSize, msgID, msgFlags, securityModel);
+
+ bufPtr = asn_build_int(bufPtr, &length,
+ (unsigned char)(ASN_UNI_PRIV | ASN_INTEGER),
+ (long *)&msgID, sizeof(msgID));
+ if (bufPtr == NULL){
+ debugprintf(0, "asn_build_header_data: Error coding msgID");
+ return NULL;
+ }
+ bufPtr = asn_build_int(bufPtr, &length,
+ (unsigned char)(ASN_UNI_PRIV | ASN_INTEGER),
+ (long *)&maxMessageSize, sizeof(maxMessageSize));
+ if (bufPtr == NULL){
+ debugprintf(0, "asn_build_header_data: Error coding maxMessageSize");
+ return NULL;
+ }
+
+ bufPtr = asn_build_string(bufPtr, &length,
+ (unsigned char)(ASN_UNI_PRIV | ASN_OCTET_STR),
+ (unsigned char*)&msgFlags, 1);
+ if (bufPtr == NULL){
+ debugprintf(0, "asn_build_header_data: Error coding msgFlags");
+ return NULL;
+ }
+
+ bufPtr = asn_build_int(bufPtr, &length,
+ (unsigned char)(ASN_UNI_PRIV | ASN_INTEGER),
+ (long *)&securityModel, sizeof(securityModel));
+ if (bufPtr == NULL){
+ debugprintf(0, "asn_build_header_data: Error coding securityModel");
+ return NULL;
+ }
+
+ totalLength = bufPtr - (unsigned char*)&buf;
+
+ debugprintf(3, "Coding sequence (headerdata), length = 0x%x", totalLength);
+ outBufPtr = asn_build_sequence(outBufPtr, maxLength,
+ (unsigned char)(ASN_SEQ_CON),
+ totalLength);
+
+ if (outBufPtr == NULL) {
+ debugprintf(0, "asn_build_header_data: Error coding seq headerdata");
+ return NULL;
+ }
+
+ if (*maxLength < totalLength) {
+ debugprintf(0, "asn_build_header_data: Length error");
+ return NULL;
+ }
+
+ memcpy(outBufPtr, (unsigned char*)&buf, totalLength);
+ outBufPtr += totalLength;
+ *maxLength -= totalLength;
+
+ debugprintf(21, "bufHeaderData:");
+ debughexprintf(21, outBuf, outBufPtr - outBuf);
+
+ return outBufPtr;
+}
+
+// Parse the ScopedPDU and return the encoded values.
+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 )
+{
+ unsigned char type;
+
+ scoped_pdu = asn_parse_header( scoped_pdu, scoped_pdu_len, &type);
+ if (!scoped_pdu) {
+ debugprintf(0, "Parse error: Wrong header in scoped_pdu.");
+ return 0;
+ }
+
+ if (type != (ASN_SEQ_CON)){
+ debugprintf(0, "Parse error: Wrong header type in scoped_pdu.");
+ return 0;
+ }
+
+ scoped_pdu = asn_parse_string( scoped_pdu, scoped_pdu_len, &type,
+ context_engine_id, context_engine_id_len);
+ if (!scoped_pdu){
+ debugprintf(0, "Parse error: context_engine_id");
+ return 0;
+ }
+
+ scoped_pdu = asn_parse_string( scoped_pdu, scoped_pdu_len, &type,
+ context_name, context_name_len);
+ if (!scoped_pdu){
+ debugprintf(0, "mpParseScopedPDU: bad parse of context_name");
+ return 0;
+ }
+
+ debugprintf(3, "Parsed scoped_pdu: context_engine_id length(0x%x), "
+ "context_name length(0x%x)",
+ *context_engine_id_len, *context_name_len);
+
+ return scoped_pdu;
+}
+
+// Encode the given values for the scopedPDU into the buffer.
+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)
+{
+ unsigned char buf[MAXLENGTH_BUFFER];
+ unsigned char *bufPtr = (unsigned char*)&buf;
+ unsigned char *outBufPtr = outBuf;
+ long bufLength = 0;
+
+ debugprintf(3, "Coding contextEngineID, length(0x%lx)"
+ ", contextName, length(0x%lx)",
+ contextEngineIDLength, contextNameLength);
+
+ bufPtr = asn_build_string(bufPtr, max_len,
+ (unsigned char)(ASN_UNI_PRIV | ASN_OCTET_STR),
+ contextEngineID, contextEngineIDLength);
+ if (bufPtr == NULL) {
+ debugprintf(0, "asn1_build_scoped_pdu: error coding contextEngineID");
+ return NULL;
+ }
+
+ bufPtr = asn_build_string(bufPtr, max_len,
+ (unsigned char)(ASN_UNI_PRIV | ASN_OCTET_STR),
+ contextName, contextNameLength);
+ if (bufPtr == NULL) {
+ debugprintf(0, "asn1_build_scoped_pdu: error coding contextName");
+ return NULL;
+ }
+
+ bufLength = bufPtr - (unsigned char*)&buf;
+
+ memcpy((char *)bufPtr, (char *)data, dataLength);
+ bufLength += dataLength;
+
+ debugprintf(3, "Coding sequence (scopedPDU), length = 0x%lx",bufLength);
+ outBufPtr = asn_build_sequence(outBufPtr, max_len,
+ (unsigned char)(ASN_SEQ_CON),
+ bufLength);
+ if (outBufPtr == NULL) {
+ debugprintf(0, "asn1_build_scoped_pdu: error coding seq scopedPDU");
+ return NULL;
+ }
+
+ memcpy(outBufPtr, buf, bufLength);
+ outBufPtr += bufLength;
+
+ debugprintf(21, "outBuf of build_scoped_pdu:");
+ debughexprintf(21, outBuf, outBufPtr - outBuf);
+
+ return outBufPtr;
+}
diff --git a/backend/camembert/libkmsnmp/asn1.h b/backend/camembert/libkmsnmp/asn1.h
new file mode 100644
index 0000000..f3f4638
--- /dev/null
+++ b/backend/camembert/libkmsnmp/asn1.h
@@ -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
+#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.
+ *
+ * HeaderData ::= SEQUENCE {
+ * msgID INTEGER (0..2147483647),
+ * msgMaxSize INTEGER (484..2147483647),
+ * msgFlags OCTET STRING (SIZE(1)),
+ * msgSecurityModel INTEGER (0..2147483647)
+ * }
+ *
+ * @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.
+ *
+ * HeaderData ::= SEQUENCE {
+ * msgID INTEGER (0..2147483647),
+ * msgMaxSize INTEGER (484..2147483647),
+ * msgFlags OCTET STRING (SIZE(1)),
+ * msgSecurityModel INTEGER (0..2147483647)
+ * }
+ *
+ *
+ * @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.
+ *
+ * ScopedPDU ::= SEQUENCE {
+ * contextEngineID OCTET STRING,
+ * contextName OCTET STRING,
+ * data ANY -- e.g., PDUs as defined in RFC 1905
+ * }
+ *
+ *
+ * @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.
+ *
+ * ScopedPDU ::= SEQUENCE {
+ * contextEngineID OCTET STRING
+ * contextName OCTET STRING
+ * data ANY -- PDU
+ * }
+ *
+ * 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
+
diff --git a/backend/camembert/libkmsnmp/collect.h b/backend/camembert/libkmsnmp/collect.h
new file mode 100644
index 0000000..2c7bf8a
--- /dev/null
+++ b/backend/camembert/libkmsnmp/collect.h
@@ -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_
+
diff --git a/backend/camembert/libkmsnmp/collect1.h b/backend/camembert/libkmsnmp/collect1.h
new file mode 100644
index 0000000..c29f3d2
--- /dev/null
+++ b/backend/camembert/libkmsnmp/collect1.h
@@ -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 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 &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 &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; znext;
+ 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; znext;
+ 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; znext;
+ 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; znext;
+ 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; zget_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; zget_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 newCollection;
+
+ for (int z=0; z= 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;
+};
diff --git a/backend/camembert/libkmsnmp/config_snmp_pp.h b/backend/camembert/libkmsnmp/config_snmp_pp.h
new file mode 100644
index 0000000..a421cb7
--- /dev/null
+++ b/backend/camembert/libkmsnmp/config_snmp_pp.h
@@ -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_
diff --git a/backend/camembert/libkmsnmp/counter.cpp b/backend/camembert/libkmsnmp/counter.cpp
new file mode 100644
index 0000000..007a28c
--- /dev/null
+++ b/backend/camembert/libkmsnmp/counter.cpp
@@ -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;
+}
diff --git a/backend/camembert/libkmsnmp/counter.h b/backend/camembert/libkmsnmp/counter.h
new file mode 100644
index 0000000..bdf2be4
--- /dev/null
+++ b/backend/camembert/libkmsnmp/counter.h
@@ -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
diff --git a/backend/camembert/libkmsnmp/ctr64.cpp b/backend/camembert/libkmsnmp/ctr64.cpp
new file mode 100644
index 0000000..bd8e25e
--- /dev/null
+++ b/backend/camembert/libkmsnmp/ctr64.cpp
@@ -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 // 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;
+}
diff --git a/backend/camembert/libkmsnmp/ctr64.h b/backend/camembert/libkmsnmp/ctr64.h
new file mode 100644
index 0000000..40b6999
--- /dev/null
+++ b/backend/camembert/libkmsnmp/ctr64.h
@@ -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
diff --git a/backend/camembert/libkmsnmp/gauge.cpp b/backend/camembert/libkmsnmp/gauge.cpp
new file mode 100644
index 0000000..6325390
--- /dev/null
+++ b/backend/camembert/libkmsnmp/gauge.cpp
@@ -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;
+}
diff --git a/backend/camembert/libkmsnmp/gauge.h b/backend/camembert/libkmsnmp/gauge.h
new file mode 100644
index 0000000..6a459f7
--- /dev/null
+++ b/backend/camembert/libkmsnmp/gauge.h
@@ -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_
diff --git a/backend/camembert/libkmsnmp/integer.cpp b/backend/camembert/libkmsnmp/integer.cpp
new file mode 100644
index 0000000..fd914a6
--- /dev/null
+++ b/backend/camembert/libkmsnmp/integer.cpp
@@ -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;
+}
diff --git a/backend/camembert/libkmsnmp/integer.h b/backend/camembert/libkmsnmp/integer.h
new file mode 100644
index 0000000..5158e91
--- /dev/null
+++ b/backend/camembert/libkmsnmp/integer.h
@@ -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
diff --git a/backend/camembert/libkmsnmp/libkmsnmp.a b/backend/camembert/libkmsnmp/libkmsnmp.a
new file mode 100644
index 0000000..92d555c
Binary files /dev/null and b/backend/camembert/libkmsnmp/libkmsnmp.a differ
diff --git a/backend/camembert/libkmsnmp/mp_v3.h b/backend/camembert/libkmsnmp/mp_v3.h
new file mode 100644
index 0000000..6ee836d
--- /dev/null
+++ b/backend/camembert/libkmsnmp/mp_v3.h
@@ -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
diff --git a/backend/camembert/libkmsnmp/octet.cpp b/backend/camembert/libkmsnmp/octet.cpp
new file mode 100644
index 0000000..b6a80a6
--- /dev/null
+++ b/backend/camembert/libkmsnmp/octet.cpp
@@ -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 // for isprint() used by get_printable()
+#include // for sprintf() used by get_printable_hex()
+#include // 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...
+}
diff --git a/backend/camembert/libkmsnmp/octet.h b/backend/camembert/libkmsnmp/octet.h
new file mode 100644
index 0000000..b3629c6
--- /dev/null
+++ b/backend/camembert/libkmsnmp/octet.h
@@ -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:
+ *
+ * 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()
+ *
+ * @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
diff --git a/backend/camembert/libkmsnmp/oid.cpp b/backend/camembert/libkmsnmp/oid.cpp
new file mode 100644
index 0000000..0648ccf
--- /dev/null
+++ b/backend/camembert/libkmsnmp/oid.cpp
@@ -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 // standard io
+#include // memcpy's
+#include // strlen, etc..
+#include // standard library
+#include // isdigit
+#include // 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(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;
+}
diff --git a/backend/camembert/libkmsnmp/oid.h b/backend/camembert/libkmsnmp/oid.h
new file mode 100644
index 0000000..ebcac84
--- /dev/null
+++ b/backend/camembert/libkmsnmp/oid.h
@@ -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 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 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); }
diff --git a/backend/camembert/libkmsnmp/pdu.h b/backend/camembert/libkmsnmp/pdu.h
new file mode 100644
index 0000000..17befce
--- /dev/null
+++ b/backend/camembert/libkmsnmp/pdu.h
@@ -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
diff --git a/backend/camembert/libkmsnmp/smi.h b/backend/camembert/libkmsnmp/smi.h
new file mode 100644
index 0000000..466665b
--- /dev/null
+++ b/backend/camembert/libkmsnmp/smi.h
@@ -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
+
+
diff --git a/backend/camembert/libkmsnmp/smival.h b/backend/camembert/libkmsnmp/smival.h
new file mode 100644
index 0000000..638b443
--- /dev/null
+++ b/backend/camembert/libkmsnmp/smival.h
@@ -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_ */
+ 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
diff --git a/backend/camembert/libkmsnmp/snmperrs.h b/backend/camembert/libkmsnmp/snmperrs.h
new file mode 100644
index 0000000..a9780a1
--- /dev/null
+++ b/backend/camembert/libkmsnmp/snmperrs.h
@@ -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
diff --git a/backend/camembert/libkmsnmp/snmpmsg.cpp b/backend/camembert/libkmsnmp/snmpmsg.cpp
new file mode 100644
index 0000000..4b2faab
--- /dev/null
+++ b/backend/camembert/libkmsnmp/snmpmsg.cpp
@@ -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
+#endif
+#include // 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;zcommand == 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;
+}
+
diff --git a/backend/camembert/libkmsnmp/snmpmsg.h b/backend/camembert/libkmsnmp/snmpmsg.h
new file mode 100644
index 0000000..8df7071
--- /dev/null
+++ b/backend/camembert/libkmsnmp/snmpmsg.h
@@ -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
diff --git a/backend/camembert/libkmsnmp/target.h b/backend/camembert/libkmsnmp/target.h
new file mode 100644
index 0000000..0db129b
--- /dev/null
+++ b/backend/camembert/libkmsnmp/target.h
@@ -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 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
diff --git a/backend/camembert/libkmsnmp/timetick.cpp b/backend/camembert/libkmsnmp/timetick.cpp
new file mode 100644
index 0000000..465e37a
--- /dev/null
+++ b/backend/camembert/libkmsnmp/timetick.cpp
@@ -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 // 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;
+}
diff --git a/backend/camembert/libkmsnmp/timetick.h b/backend/camembert/libkmsnmp/timetick.h
new file mode 100644
index 0000000..1d4986c
--- /dev/null
+++ b/backend/camembert/libkmsnmp/timetick.h
@@ -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
diff --git a/backend/camembert/libkmsnmp/usm_v3.h b/backend/camembert/libkmsnmp/usm_v3.h
new file mode 100644
index 0000000..efb5508
--- /dev/null
+++ b/backend/camembert/libkmsnmp/usm_v3.h
@@ -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
diff --git a/backend/camembert/libkmsnmp/v3.h b/backend/camembert/libkmsnmp/v3.h
new file mode 100644
index 0000000..01bf60d
--- /dev/null
+++ b/backend/camembert/libkmsnmp/v3.h
@@ -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
+#include
+
+#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
diff --git a/backend/camembert/libkmsnmp/vb.cpp b/backend/camembert/libkmsnmp/vb.cpp
new file mode 100644
index 0000000..4ad6681
--- /dev/null
+++ b/backend/camembert/libkmsnmp/vb.cpp
@@ -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);
+}
diff --git a/backend/camembert/libkmsnmp/vb.h b/backend/camembert/libkmsnmp/vb.h
new file mode 100644
index 0000000..bc19d30
--- /dev/null
+++ b/backend/camembert/libkmsnmp/vb.h
@@ -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
diff --git a/backend/camembert/main b/backend/camembert/main
new file mode 100755
index 0000000..4eb853b
Binary files /dev/null and b/backend/camembert/main differ
diff --git a/backend/camembert/main.cpp b/backend/camembert/main.cpp
new file mode 100644
index 0000000..6a52e31
--- /dev/null
+++ b/backend/camembert/main.cpp
@@ -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; iaddIP(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; inbOldLinks = m;
+ if(m > 0) {
+ iface->oldLinks = new unsigned int[m];
+ for(j=0; joldLinks[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; jaddAction(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; nnbOldLinks; 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; iisJobPending()) {
+ 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);
+}
diff --git a/backend/camembert/main.o b/backend/camembert/main.o
new file mode 100644
index 0000000..95a7603
Binary files /dev/null and b/backend/camembert/main.o differ
diff --git a/backend/camembert/materiel.cpp b/backend/camembert/materiel.cpp
new file mode 100644
index 0000000..4f9e9f5
--- /dev/null
+++ b/backend/camembert/materiel.cpp
@@ -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;
+}
diff --git a/backend/camembert/materiel.h b/backend/camembert/materiel.h
new file mode 100644
index 0000000..00c3cf4
--- /dev/null
+++ b/backend/camembert/materiel.h
@@ -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 */
diff --git a/backend/camembert/materiel.o b/backend/camembert/materiel.o
new file mode 100644
index 0000000..6b4812d
Binary files /dev/null and b/backend/camembert/materiel.o differ
diff --git a/backend/camembert/monitor.cpp b/backend/camembert/monitor.cpp
new file mode 100644
index 0000000..d2224ca
--- /dev/null
+++ b/backend/camembert/monitor.cpp
@@ -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
+#include "monitor.h"
+#include
+#include
+
+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);
+}
+
diff --git a/backend/camembert/monitor.h b/backend/camembert/monitor.h
new file mode 100644
index 0000000..3f5b838
--- /dev/null
+++ b/backend/camembert/monitor.h
@@ -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 */
diff --git a/backend/camembert/monitor.o b/backend/camembert/monitor.o
new file mode 100644
index 0000000..ceb2632
Binary files /dev/null and b/backend/camembert/monitor.o differ
diff --git a/backend/camembert/neighbours.cpp b/backend/camembert/neighbours.cpp
new file mode 100644
index 0000000..d0d6094
--- /dev/null
+++ b/backend/camembert/neighbours.cpp
@@ -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;
+}
diff --git a/backend/camembert/neighbours.h b/backend/camembert/neighbours.h
new file mode 100644
index 0000000..f09ce4c
--- /dev/null
+++ b/backend/camembert/neighbours.h
@@ -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 */
diff --git a/backend/camembert/neighbours.o b/backend/camembert/neighbours.o
new file mode 100644
index 0000000..3262e3a
Binary files /dev/null and b/backend/camembert/neighbours.o differ
diff --git a/backend/camembert/pgdb.cpp b/backend/camembert/pgdb.cpp
new file mode 100644
index 0000000..8537673
--- /dev/null
+++ b/backend/camembert/pgdb.cpp
@@ -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
+#include
+#include
+#include "pgdb.h"
+#include
+
+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;
+}
diff --git a/backend/camembert/pgdb.h b/backend/camembert/pgdb.h
new file mode 100644
index 0000000..ed14262
--- /dev/null
+++ b/backend/camembert/pgdb.h
@@ -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 */
+
diff --git a/backend/camembert/pgdb.o b/backend/camembert/pgdb.o
new file mode 100644
index 0000000..2901bc0
Binary files /dev/null and b/backend/camembert/pgdb.o differ
diff --git a/backend/camembert/snmp.cpp b/backend/camembert/snmp.cpp
new file mode 100644
index 0000000..3919a04
--- /dev/null
+++ b/backend/camembert/snmp.cpp
@@ -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
+
+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; ilen(), *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;
+}
diff --git a/backend/camembert/snmp.h b/backend/camembert/snmp.h
new file mode 100644
index 0000000..42b2a08
--- /dev/null
+++ b/backend/camembert/snmp.h
@@ -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
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+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 */
diff --git a/backend/camembert/snmp.o b/backend/camembert/snmp.o
new file mode 100644
index 0000000..82afd1e
Binary files /dev/null and b/backend/camembert/snmp.o differ
diff --git a/backend/camembert/snmpobject.cpp b/backend/camembert/snmpobject.cpp
new file mode 100644
index 0000000..dc7ebbf
--- /dev/null
+++ b/backend/camembert/snmpobject.cpp
@@ -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_verssnmpopen(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_verssnmpopen(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; isnmpwalk(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;
+}
diff --git a/backend/camembert/snmpobject.h b/backend/camembert/snmpobject.h
new file mode 100644
index 0000000..616eece
--- /dev/null
+++ b/backend/camembert/snmpobject.h
@@ -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
+
+#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 */
diff --git a/backend/camembert/snmpobject.o b/backend/camembert/snmpobject.o
new file mode 100644
index 0000000..049f34a
Binary files /dev/null and b/backend/camembert/snmpobject.o differ
diff --git a/backend/camembert/vlan.cpp b/backend/camembert/vlan.cpp
new file mode 100644
index 0000000..250d8dc
--- /dev/null
+++ b/backend/camembert/vlan.cpp
@@ -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;
+}
diff --git a/backend/camembert/vlan.h b/backend/camembert/vlan.h
new file mode 100644
index 0000000..281658d
--- /dev/null
+++ b/backend/camembert/vlan.h
@@ -0,0 +1,25 @@
+#ifndef __CAMEMBERT_VLAN_H
+#define __CAMEMBERT_VLAN_H
+
+#include
+
+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 */
diff --git a/backend/camembert/vlan.o b/backend/camembert/vlan.o
new file mode 100644
index 0000000..386129d
Binary files /dev/null and b/backend/camembert/vlan.o differ
diff --git a/backend/multi-telnet/commandes.txt b/backend/multi-telnet/commandes.txt
new file mode 100644
index 0000000..688aab3
--- /dev/null
+++ b/backend/multi-telnet/commandes.txt
@@ -0,0 +1,4 @@
+conf t
+ int gi0/1
+end
+write mem
diff --git a/backend/multi-telnet/liste.txt b/backend/multi-telnet/liste.txt
new file mode 100644
index 0000000..be1d7aa
--- /dev/null
+++ b/backend/multi-telnet/liste.txt
@@ -0,0 +1,8 @@
+sn1
+sn2
+sn3
+sn4
+ss1
+ss2
+ss3
+ss4
diff --git a/backend/multi-telnet/script.sh b/backend/multi-telnet/script.sh
new file mode 100644
index 0000000..1f7f236
--- /dev/null
+++ b/backend/multi-telnet/script.sh
@@ -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
+
+
diff --git a/backend/snmp.py b/backend/snmp.py
new file mode 100755
index 0000000..c1f8529
--- /dev/null
+++ b/backend/snmp.py
@@ -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
+
diff --git a/camembert-before-ldap/.htaccess b/camembert-before-ldap/.htaccess
new file mode 100644
index 0000000..fc56cc6
--- /dev/null
+++ b/camembert-before-ldap/.htaccess
@@ -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.
+
+ 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]
+
+
diff --git a/camembert-before-ldap/.htpasswd b/camembert-before-ldap/.htpasswd
new file mode 100644
index 0000000..1b02c6a
--- /dev/null
+++ b/camembert-before-ldap/.htpasswd
@@ -0,0 +1,2 @@
+test:y0Uiblabl6ciNo
+test2:B0blay5Ez.qE.
diff --git a/camembert-before-ldap/404.php b/camembert-before-ldap/404.php
new file mode 100644
index 0000000..0d493e8
--- /dev/null
+++ b/camembert-before-ldap/404.php
@@ -0,0 +1,10 @@
+
+
+La page que vous avez demandé est introuvable.
+
+
+
diff --git a/camembert-before-ldap/anomalies.php b/camembert-before-ldap/anomalies.php
new file mode 100644
index 0000000..917fc8e
--- /dev/null
+++ b/camembert-before-ldap/anomalies.php
@@ -0,0 +1,32 @@
+Interfaces en ERR-DIS :
Incohérence DHCP-ARP :
Incohérence DHCP-Sticky :
diff --git a/camembert-before-ldap/arrow.gif b/camembert-before-ldap/arrow.gif
new file mode 100644
index 0000000..cccf415
Binary files /dev/null and b/camembert-before-ldap/arrow.gif differ
diff --git a/camembert-before-ldap/arrow2.gif b/camembert-before-ldap/arrow2.gif
new file mode 100644
index 0000000..44f7745
Binary files /dev/null and b/camembert-before-ldap/arrow2.gif differ
diff --git a/camembert-before-ldap/cam_users.php b/camembert-before-ldap/cam_users.php
new file mode 100644
index 0000000..7df22f5
--- /dev/null
+++ b/camembert-before-ldap/cam_users.php
@@ -0,0 +1,86 @@
+User ".$a['login']." supprimé.
\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 "".$a['login']."
\n";
+ echo "
\n";
+ }
+ }
+ else
+ echo "Cet id n'existe pas
\n";
+}
+
+?>
+ Liste des utilisateurs
+
+
+ \n";
+}
+?>
+
+
diff --git a/camembert-before-ldap/comp.php b/camembert-before-ldap/comp.php
new file mode 100644
index 0000000..fc55b80
--- /dev/null
+++ b/camembert-before-ldap/comp.php
@@ -0,0 +1,234 @@
+Erreur : cet utilisateur n'existe pas\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++;
+ }
+?>
+ Nouvelle machine pour
+
+Erreur : cette machine n'existe pas\n";
+ return;
+ }
+ $mac = explode(":", strtoupper($a['mac']));
+?>
+ Modification de machine
+
+ $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 "$val
\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 "$val
\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 "Erreur : cette machine n'existe pas
\n";
+ }
+ else
+ header("Location: user.php?id=$user");
+ }
+ else {
+ include "denied.php";
+ return;
+ }
+}
+
+include "inc/inc.footer.php";
+?>
diff --git a/camembert-before-ldap/denied.php b/camembert-before-ldap/denied.php
new file mode 100644
index 0000000..d2032b8
--- /dev/null
+++ b/camembert-before-ldap/denied.php
@@ -0,0 +1,37 @@
+
+
+ Camembert :: Accès refusé
+
+
+
+
+ Camembert
+ Accès refusé
+
+
+Vous n'êtes pas autorisé à accéder à cette page.
+
+
+
+
+
+
diff --git a/camembert-before-ldap/disconnected_user.php b/camembert-before-ldap/disconnected_user.php
new file mode 100644
index 0000000..a7262a0
--- /dev/null
+++ b/camembert-before-ldap/disconnected_user.php
@@ -0,0 +1,10 @@
+
diff --git a/camembert-before-ldap/findip.php b/camembert-before-ldap/findip.php
new file mode 100644
index 0000000..113dac5
--- /dev/null
+++ b/camembert-before-ldap/findip.php
@@ -0,0 +1,100 @@
+
+
+
+
+
+
+ L'adresse IP a été associée au matériel suivant
+
+ Matériel | Associée le | Jusqu'au |
+${a[1]}";
+ else
+ $mat = $a[1];
+ echo "$mat | ";
+ echo "".date("D d/m/Y H:i", $a[2])." | ".date("D d/m/Y H:i", $a[3])." |
\n";
+ $bline = !$bline;
+
+ $a = pg_fetch_array($r);
+ }
+ echo "
\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) {
+?>
+ L'adresse IP a été associée aux adresses MAC suivantes
+
+ MAC | Associé par | Associée le | Jusqu'au |
+${a[0]}";
+ else
+ $mac = $a[0];
+ echo "$mac | ";
+ echo "${a[2]} | ";
+ echo "".date("D d/m/Y H:i", $a[3])." | ".date("D d/m/Y H:i", $a[4])." |
\n";
+ $bline = !$bline;
+
+ $a = pg_fetch_array($r);
+ }
+ echo "
\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) {
+?>
+ L'adresse IP est présente dans le DHCP
+
+ Utilisateur | Chambre | Nom de machine |
+".$a[1]." ".$a[2]." | ";
+ echo "".$a[5]." | ".$a[3]." | \n";
+ $bline = !$bline;
+
+ $a = pg_fetch_array($r);
+ }
+ echo "
\n";
+}
+
+echo "
\n";
+include "inc/inc.footer.php";
+
+?>
diff --git a/camembert-before-ldap/findmac.php b/camembert-before-ldap/findmac.php
new file mode 100644
index 0000000..c39b957
--- /dev/null
+++ b/camembert-before-ldap/findmac.php
@@ -0,0 +1,199 @@
+
+
+
+
+\n";
+if ($mac == '')
+ echo "L'adresse MAC ".$_GET["mac"]." n'est pas valide.
\n";
+else
+ SearchMAC($mac, $unique);
+echo "\n";
+
+include "inc/inc.footer.php";
+
+
+function SearchMAC($mac, $unique) {
+ // Vérifions si la MAC correspond à l'adresse d'une interface
+ $r = pg_query("SELECT ifaddress, idinterface, ifname, i.idmateriel, hostname
+ FROM interface i, materiel m
+ WHERE i.idmateriel = m.idmateriel
+ AND CAST(ifaddress AS VARCHAR(24)) ILIKE '%$mac%'
+ ORDER BY ifaddress");
+ $a = pg_fetch_array($r);
+ if($a) {
+?>
+ L'adresse correspond aux interfaces suivantes
+
+ Adresse MAC | Matériel | Interface |
+${a[0]} | ${a[4]} | ";
+ echo "${a[2]} | \n";
+ $bline = !$bline;
+ $a = pg_fetch_array($r);
+ }
+ echo "
\n";
+ }
+
+ $r = pg_query("SELECT MAX(datelast) FROM arpcache");
+ $datelast = pg_fetch_array($r);
+ $datelast = $datelast[0];
+
+ if($unique) {
+ $a = SearchMACinDHCP($mac);
+ if($a) {
+ ?>
+ L'adresse MAC est présente dans le DHCP
+
+ Utilisateur | Chambre | Nom de machine |
+ ".$a[1]." ".$a[2]." | ";
+ echo "".$a[5]." | ".$a[3]." | \n";
+ $bline = !$bline;
+
+ $a = pg_fetch_array($r);
+ }
+ echo "
\n";
+ }
+
+ // Recherche dans le cache ARP
+ $r = pg_query("SELECT ip, foundon, hostname, a.datefirst, a.datelast
+ FROM arpcache a, materiel m
+ WHERE foundon = idmateriel AND mac = '$mac'
+ ORDER BY datelast DESC, ip");
+ $a = pg_fetch_array($r);
+ if($a) {
+?>
+ L'adresse a été associée aux IP suivantes
+
+ IP | Associé par | Associée le |
+ Jusqu'au | Equipement correspondant |
+";
+ $bline = !$bline;
+ if($a[4] == $datelast)
+ echo "${a[0]}";
+ else
+ echo $a[0];
+ echo " | ${a[2]} | ".date("D d/m/Y H:i", $a[3])." | ".date("D d/m/Y H:i", $a[4])." | ";
+
+ $r2 = pg_query("SELECT m.idmateriel, hostname FROM materiel m, ip
+ WHERE m.idmateriel = ip.idmateriel AND ip = '${a[0]}' AND ip.datelast = ${a[4]}");
+ $a2 = pg_fetch_array($r2);
+ if($a2)
+ echo "${a2[1]} | ";
+ else
+ echo " | ";
+ echo "\n";
+
+ $a = pg_fetch_array($r);
+ }
+ echo "
\n";
+ }
+
+ $a = SearchMAConInterface($mac);
+ if($a) {
+?>
+ L'adresse a été trouvée sur les interfaces suivantes
+
+ Matériel / Interface | VLAN | Date enr |
+ MàJ |
+".$a[1]."";
+ else
+ $host = $a[1];
+
+ echo "$host / ${a[2]} | ";
+ echo "${a[3]} | ".date("d/m/Y H:i", $a[4])." | ".date("d/m/Y H:i", $a[5])." |
\n";
+ $bline = !$bline;
+ $a = pg_fetch_array($r);
+ }
+ echo "
\n";
+ }
+ }
+ else {
+ // Recherche dans le cache ARP
+ $r = pg_query("SELECT mac, ip, foundon, hostname, a.datefirst, a.datelast
+ FROM arpcache a, materiel m
+ WHERE foundon = idmateriel AND CAST(mac AS VARCHAR(24)) ILIKE '%$mac%'
+ ORDER BY mac");
+ $a = pg_fetch_array($r);
+ if($a) {
+?>
+ Des adresses MAC contenant ont été associées aux IPs suivantes
+
+ MAC | IP | Associé par |
+ Associée le | Jusqu'au | Equipement correspondant |
+${a[0]} | ${a[1]} | ";
+ echo "${a[3]} | ";
+ echo "".date("D d/m/Y H:i", $a[4])." | ".date("D d/m/Y H:i", $a[5])." | ";
+
+ $r2 = pg_query("SELECT m.idmateriel, hostname FROM materiel m, ip
+ WHERE m.idmateriel = ip.idmateriel AND ip = '${a[1]}' AND ip.datelast = ${a[5]}");
+ $a2 = pg_fetch_array($r2);
+ if($a2)
+ echo "${a2[1]} | ";
+ else
+ echo " | ";
+ echo "\n";
+ $bline = !$bline;
+
+ $a = pg_fetch_array($r);
+ }
+ echo "
\n";
+ }
+
+ // Recherche sur les interfaces.
+ $r = pg_query("SELECT mac, m.idmateriel, hostname, ifname, vlan, fdb.datefirst, fdb.datelast
+ FROM materiel m, interface i, fdb
+ WHERE m.idmateriel = i.idmateriel AND i.idinterface = fdb.idinterface
+ AND CAST(mac AS VARCHAR(24)) ILIKE '%$mac%' ORDER BY fdb.datelast DESC, mac, i.idmateriel, ifnumber");
+ $a = pg_fetch_array($r);
+ if($a) {
+?>
+ L'adresse a été trouvée sur les interfaces suivantes
+
+ Matériel / Interface | MAC | VLAN |
+ Date enr | MàJ |
+${a[2]} / ${a[3]} | ";
+ echo "${a[0]} | ${a[4]} | ".date("d/m/Y H:i", $a[5])." | ".date("d/m/Y H:i", $a[6])." | \n";
+ $bline = !$bline;
+ $a = pg_fetch_array($r);
+ }
+ echo "
\n";
+ }
+ }
+}
+
+?>
diff --git a/camembert-before-ldap/findname.php b/camembert-before-ldap/findname.php
new file mode 100644
index 0000000..83935fc
--- /dev/null
+++ b/camembert-before-ldap/findname.php
@@ -0,0 +1,69 @@
+
+
+
+
+\n";
+if ($name == '')
+echo "Le nom ".$_GET["name"]." n'est pas valide.
\n";
+else
+SearchNAME($name);
+echo "\n";
+
+include "inc/inc.footer.php";
+
+
+function CreateTable() {
+ ?>
+ Le nom a été trouvé dans les chambres suivantes
+
+ chambre | nom | prenom |
+
+ $row) {
+ echo "";
+ echo "$id | ";
+ echo "$row[0] | $row[1] | ";
+ $bline = !$bline;
+ }
+ echo "
\n";
+ }
+}
+
+?>
diff --git a/camembert-before-ldap/groups.php b/camembert-before-ldap/groups.php
new file mode 100644
index 0000000..d2d5c25
--- /dev/null
+++ b/camembert-before-ldap/groups.php
@@ -0,0 +1,92 @@
+Erreur: ce groupe existe déjà";
+ else {
+ $r = pg_query("SELECT MAX(idgroupe) FROM groupe");
+ if($a = pg_fetch_array($r))
+ $newid = $a[0]+1;
+ else
+ $newid = 1;
+ pg_query("INSERT INTO groupe(idgroupe, name, roles) VALUES($newid, '".$_POST['name']."', 0)");
+ }
+}
+else if(isset($_POST['act']) && $_POST['act'] == 2) {
+ $r = pg_query("SELECT name FROM groupe WHERE idgroupe = ".$_POST['id']);
+ if(($a = pg_fetch_array($r)) === false) {
+ echo "Mauvais id
\n";
+ }
+ else {
+ $uroles = 0;
+ foreach($_POST as $k => $v)
+ if(is_int($k) && ($v == 'on' || $v == 1 || $v = 'checked'))
+ $uroles += 1 << $k;
+ pg_query("UPDATE groupe SET roles = $uroles WHERE idgroupe = ".$_POST['id']);
+ }
+}
+
+$r = pg_query("SELECT idgroupe, name FROM groupe");
+if($a = pg_fetch_array($r)) {
+?>
+ id | nom |
+".$a['idgroupe']." | ".$a['name']." | \n";
+ $a = pg_fetch_array($r);
+ $bline = !$bline;
+ }
+ echo "
\n";
+}
+?>
+
+
+
+Mauvais id\n";
+ include "inc/inc.footer.php";
+ exit();
+ }
+ $uroles = $a['roles'];
+ echo "".$a['name']."
\n";
+?>
+
+
diff --git a/camembert-before-ldap/img/admin.png b/camembert-before-ldap/img/admin.png
new file mode 100644
index 0000000..fa538c5
Binary files /dev/null and b/camembert-before-ldap/img/admin.png differ
diff --git a/camembert-before-ldap/img/blank.png b/camembert-before-ldap/img/blank.png
new file mode 100644
index 0000000..cee9cd3
Binary files /dev/null and b/camembert-before-ldap/img/blank.png differ
diff --git a/camembert-before-ldap/img/membre_ca.gif b/camembert-before-ldap/img/membre_ca.gif
new file mode 100644
index 0000000..aeba6ce
Binary files /dev/null and b/camembert-before-ldap/img/membre_ca.gif differ
diff --git a/camembert-before-ldap/img/root.gif b/camembert-before-ldap/img/root.gif
new file mode 100644
index 0000000..37bb04c
Binary files /dev/null and b/camembert-before-ldap/img/root.gif differ
diff --git a/camembert-before-ldap/img/tresorier.gif b/camembert-before-ldap/img/tresorier.gif
new file mode 100644
index 0000000..d8ffc9a
Binary files /dev/null and b/camembert-before-ldap/img/tresorier.gif differ
diff --git a/camembert-before-ldap/inc/inc.body.php b/camembert-before-ldap/inc/inc.body.php
new file mode 100644
index 0000000..1bfc07c
--- /dev/null
+++ b/camembert-before-ldap/inc/inc.body.php
@@ -0,0 +1,54 @@
+
+
+
+
+
+
+
+
diff --git a/camembert-before-ldap/inc/inc.db.php b/camembert-before-ldap/inc/inc.db.php
new file mode 100644
index 0000000..8e7e646
--- /dev/null
+++ b/camembert-before-ldap/inc/inc.db.php
@@ -0,0 +1,15 @@
+
+
+
+
+
+