Added experimental snmp extension
This commit is contained in:
parent
b7816390bf
commit
2ef97d88f9
@ -1 +1 @@
|
||||
filelist mball mbchat mblang mbstat mbtoberep mbuser mbbw
|
||||
filelist mball mbchat mblang mbstat mbsnmp mbtoberep mbuser mbbw
|
||||
|
@ -4,14 +4,16 @@
|
||||
|
||||
include ../Makefile.global
|
||||
|
||||
SRCS = mball.c dlcount.c mblang.c mbstat.c mbtoberep.c mbuser.c mbbw.c
|
||||
HDRS = mball.h dlcount.h mbstat.h mbuser.h
|
||||
SRCS = mball.c dlcount.c mblang.c mbstat.c mbsnmp.c mbtoberep.c mbuser.c mbbw.c
|
||||
HDRS = mball.h dlcount.h mbstat.h mbsnmp.h mbuser.h
|
||||
MBALL_OBJS = mball.o dlcount.o
|
||||
MBALL_LIBS = ../lib/libmbse.a ../lib/libdbase.a
|
||||
MBLANG_OBJS = mblang.o
|
||||
MBLANG_LIBS = ../lib/libmbse.a ../lib/libdbase.a
|
||||
MBSTAT_OBJS = mbstat.o
|
||||
MBSTAT_LIBS = ../lib/libmbse.a ../lib/libdbase.a
|
||||
MBSNMP_OBJS = mbsnmp.o
|
||||
MBSNMP_LIBS = ../lib/libmbse.a ../lib/libdbase.a
|
||||
MBTOBE_OBJS = mbtoberep.o
|
||||
MBTOBE_LIBS = ../lib/libmbse.a ../lib/libdbase.a
|
||||
MBUSER_OBJS = mbuser.o
|
||||
@ -19,7 +21,7 @@ MBUSER_LIBS = ../lib/libmbse.a ../lib/libdbase.a
|
||||
MBBW_OBJS = mbbw.o
|
||||
MBBW_LIBS = ../lib/libmbse.a ../lib/libdbase.a
|
||||
OTHER = Makefile
|
||||
TARGET = mball mblang mbstat mbtoberep mbuser mbbw
|
||||
TARGET = mball mblang mbstat mbsnmp mbtoberep mbuser mbbw
|
||||
|
||||
#############################################################################################################
|
||||
|
||||
@ -40,6 +42,9 @@ mblang: ${MBLANG_OBJS} ${MBLANG_LIBS}
|
||||
mbstat: ${MBSTAT_OBJS} ${MBSTAT_LIBS}
|
||||
${CC} -o mbstat ${MBSTAT_OBJS} ${LDFLAGS} ${LIBS} ${MBSTAT_LIBS}
|
||||
|
||||
mbsnmp: ${MBSNMP_OBJS} ${MBSNMP_LIBS}
|
||||
${CC} -o mbsnmp ${MBSNMP_OBJS} ${LDFLAGS} ${LIBS} ${MBSNMP_LIBS}
|
||||
|
||||
mbtoberep: ${MBTOBE_OBJS} ${MBTOBE_LIBS}
|
||||
${CC} -o mbtoberep ${MBTOBE_OBJS} ${LDFLAGS} ${LIBS} ${MBTOBE_LIBS}
|
||||
|
||||
@ -56,6 +61,7 @@ install: all
|
||||
${INSTALL} -c -s -o ${OWNER} -g ${GROUP} -m 0700 mball ${BINDIR}
|
||||
${INSTALL} -c -s -o ${OWNER} -g ${GROUP} -m 0700 mblang ${BINDIR}
|
||||
${INSTALL} -c -s -o ${OWNER} -g ${GROUP} -m 0750 mbstat ${BINDIR}
|
||||
${INSTALL} -c -s -o ${OWNER} -g ${GROUP} -m 4750 mbsnmp ${BINDIR}
|
||||
${INSTALL} -c -s -o ${OWNER} -g ${GROUP} -m 0700 mbtoberep ${BINDIR}
|
||||
${INSTALL} -c -s -o ${ROWNER} -g ${RGROUP} -m 6711 mbuser ${BINDIR}
|
||||
${INSTALL} -c -s -o ${OWNER} -g ${GROUP} -m 0750 mbbw ${BINDIR}
|
||||
@ -94,6 +100,7 @@ mball.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/mbsedb
|
||||
dlcount.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h dlcount.h
|
||||
mblang.o: ../config.h ../lib/mbselib.h
|
||||
mbstat.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h mbstat.h
|
||||
mbsnmp.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h mbsnmp.h
|
||||
mbtoberep.o: ../config.h ../lib/mbselib.h
|
||||
mbuser.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h mbuser.h
|
||||
mbbw.o: ../config.h ../lib/mbselib.h ../lib/bluewave.h
|
||||
|
236
mbutils/mbsnmp.c
Normal file
236
mbutils/mbsnmp.c
Normal file
@ -0,0 +1,236 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* $Id$
|
||||
* Purpose ...............: SNMP passthru support.
|
||||
*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 1997-2008
|
||||
*
|
||||
* Michiel Broek FIDO: 2:280/2802
|
||||
* Beekmansbos 10
|
||||
* 1971 BV IJmuiden
|
||||
* the Netherlands
|
||||
*
|
||||
* This file is part of MBSE BBS.
|
||||
*
|
||||
* This BBS is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* MBSE BBS is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with MBSE BBS; see the file COPYING. If not, write to the Free
|
||||
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "../config.h"
|
||||
#include "../lib/mbselib.h"
|
||||
#include "../lib/users.h"
|
||||
#include "../lib/mbsedb.h"
|
||||
#include "mbsnmp.h"
|
||||
|
||||
|
||||
|
||||
// mbsnmp [-n|-g] .1.3.6.1.4.1.2021.256.group.item
|
||||
// mbsnmp <base oid> <request type> <requested oid>
|
||||
// <base oid> Base oid for this tree.
|
||||
// <request type> -n for SNMP getNext, or -g for SNMP get.
|
||||
// <request oid> Requested OID
|
||||
// outputs: "new oid\n" . "integer\n" . data . "\n"
|
||||
|
||||
|
||||
/*
|
||||
* group command reply
|
||||
* ----- ------- ----------------------------------------------------------------------------------------------
|
||||
* 0 MGMS:0; 100:12,kbrcvd,kbsent,sessin,sessout,sess_sec,sess_unseq,sess_bad,ftsc,yoohoo,emsi,binkp,freqs;
|
||||
* 1 MGTN:0; 100:3,in,out,bad;
|
||||
* 2 MGTI:0; 100:3,in,out,bad;
|
||||
* 3 MGTE:0; 100:4,in,out,bad,dupe;
|
||||
* 4 MGTR:0; 100:4,in,out,bad,dupe;
|
||||
* 5 MGTT:0; 100:4,in,out,bad,dupe;
|
||||
* 6 MGTF:0; 100:6,in,out,bad,dupe,magics,hatched;
|
||||
* 7 MGBB:0; 100:9,sessions,minutes,posted,uploads,kbupload,downloads,kbdownload,chats,chatminutes;
|
||||
* 8 MGOB:0; 100:1,size;
|
||||
*/
|
||||
|
||||
|
||||
void usage(void);
|
||||
void die(int);
|
||||
|
||||
|
||||
|
||||
void usage(void)
|
||||
{
|
||||
fprintf(stderr, "\nMBSNMP: MBSE BBS %s SNMP subagent\n", VERSION);
|
||||
fprintf(stderr, " %s\n", COPYRIGHT);
|
||||
fprintf(stderr, "\nUsage: mbsnmp <base oid> <request type> <request oid>\n\n");
|
||||
exit(MBERR_COMMANDLINE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void die(int onsig)
|
||||
{
|
||||
signal(onsig, SIG_IGN);
|
||||
|
||||
if (onsig)
|
||||
Syslog('+', "Terminated on signal %d", onsig);
|
||||
|
||||
ExitClient(onsig);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i, getnext = FALSE, group = 0, sub = 0, params, val;
|
||||
char *cmd, *t1, *t2, *saveptr1 = NULL, *saveptr2 = NULL, *token1, *token2;
|
||||
char *base_save, *req_save, *envptr = NULL, *req_oid, *base_oid, *resp, *type;
|
||||
struct passwd *pw;
|
||||
|
||||
/*
|
||||
* First, check the syntax and parameters.
|
||||
*/
|
||||
if (argc != 4)
|
||||
usage();
|
||||
if (strcmp(argv[2],"-n") && strcmp(argv[2],"-g"))
|
||||
usage();
|
||||
base_oid = argv[1];
|
||||
req_oid = argv[3];
|
||||
getnext = strcmp(argv[2], "-g");
|
||||
if (strncmp(base_oid, req_oid, strlen(base_oid)))
|
||||
usage();
|
||||
|
||||
/*
|
||||
* The next trick is to supply a fake environment variable
|
||||
* MBSE_ROOT because most likely we are started from snmpd.
|
||||
* This will setup the variable so InitConfig() will work.
|
||||
* The /etc/passwd must point to the correct homedirectory.
|
||||
*/
|
||||
pw = getpwnam((char *)"mbse");
|
||||
if (getenv("MBSE_ROOT") == NULL) {
|
||||
envptr = xstrcpy((char *)"MBSE_ROOT=");
|
||||
envptr = xstrcat(envptr, pw->pw_dir);
|
||||
putenv(envptr);
|
||||
}
|
||||
|
||||
InitConfig();
|
||||
|
||||
/*
|
||||
* Catch or ignore signals
|
||||
*/
|
||||
for (i = 0; i < NSIG; i++) {
|
||||
if ((i == SIGHUP) || (i == SIGINT) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM) || (i == SIGIOT))
|
||||
signal(i, (void (*))die);
|
||||
else if ((i != SIGKILL) && (i != SIGSTOP))
|
||||
signal(i, SIG_IGN);
|
||||
}
|
||||
|
||||
cmd = xstrcpy((char *)"Cmd:");
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
cmd = xstrcat(cmd, (char *)" ");
|
||||
cmd = xstrcat(cmd, argv[i]);
|
||||
}
|
||||
|
||||
pw = getpwuid(getuid());
|
||||
InitClient(pw->pw_name, (char *)"mbsnmp", CFG.location, CFG.logfile,
|
||||
CFG.util_loglevel, CFG.error_log, CFG.mgrlog, CFG.debuglog);
|
||||
|
||||
Syslog('f', cmd);
|
||||
free(cmd);
|
||||
|
||||
// Syslog('+', "base oid %s", base_oid);
|
||||
// Syslog('+', "req_oid %s", req_oid);
|
||||
// Syslog('+', "getnext %s", getnext ? "True":"False");
|
||||
|
||||
base_save = xstrcpy(base_oid);
|
||||
req_save = xstrcpy(req_oid);
|
||||
for (i = 1, t1 = base_oid, t2 = req_oid; ; i++, t1 = NULL, t2 = NULL) {
|
||||
token1 = strtok_r(t1, ".", &saveptr1);
|
||||
token2 = strtok_r(t2, ".", &saveptr2);
|
||||
if ((token1 == NULL) || (token2 == NULL))
|
||||
break;
|
||||
// Syslog('-', "%d %s %s", i, token1, token2);
|
||||
}
|
||||
|
||||
/*
|
||||
* Complete the requested OID if needed.
|
||||
*/
|
||||
if (token2) {
|
||||
group = atoi(token2);
|
||||
// Syslog('-', "%d %s %s", i, token1, token2);
|
||||
t2 = NULL;
|
||||
token2 = strtok_r(t2, ".", &saveptr2);
|
||||
if (token2) {
|
||||
// Syslog('-', "%d %s %s", i, token1, token2);
|
||||
sub = atoi(token2);
|
||||
}
|
||||
}
|
||||
|
||||
// Syslog('+', "group=%d sub=%d", group, sub);
|
||||
|
||||
if ((group < 0) || (group > 8)) {
|
||||
die(MBERR_OK);
|
||||
}
|
||||
|
||||
switch (group) {
|
||||
case 0: resp = SockR("MGMS:0;"); break;
|
||||
case 1: resp = SockR("MGTN:0;"); break;
|
||||
case 2: resp = SockR("MGTI:0;"); break;
|
||||
case 3: resp = SockR("MGTE:0;"); break;
|
||||
case 4: resp = SockR("MGTR:0;"); break;
|
||||
case 5: resp = SockR("MGTT:0;"); break;
|
||||
case 6: resp = SockR("MGTF:0;"); break;
|
||||
case 7: resp = SockR("MGBB:0;"); break;
|
||||
case 8: resp = SockR("MGOB:0;"); break;
|
||||
default: resp = (char *)"200:0;";
|
||||
}
|
||||
|
||||
// Syslog('+', "resp %s", resp);
|
||||
|
||||
t1 = strtok(resp, ":");
|
||||
t1 = strtok(NULL, ",");
|
||||
params = atoi(t1);
|
||||
|
||||
// Syslog('+', "params=%d", params);
|
||||
for (i = 0; i < params; i++) {
|
||||
t1 = strtok(NULL, ",;");
|
||||
// Syslog('+', "t1 %d %s", i, t1);
|
||||
val = atoi(t1);
|
||||
if (i == sub)
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* The value type defaults to counter.
|
||||
*/
|
||||
type = (char *)"counter";
|
||||
if ((group == 8) && (sub == 0))
|
||||
type = (char *)"integer";
|
||||
|
||||
if ((group < 9) && (sub < params)) {
|
||||
if (getnext) {
|
||||
sub++;
|
||||
if ((sub >= params) && (group < 8)) {
|
||||
sub = 0;
|
||||
group++;
|
||||
}
|
||||
}
|
||||
printf("%s.%d.%d\n", base_save, group, sub);
|
||||
printf("%s\n", type);
|
||||
printf("%d\n", val);
|
||||
Syslog('f', "Rsp: %s %s => %s.%d.%d %s %d", req_save, getnext ? "N":"G", base_save, group, sub, type, val);
|
||||
}
|
||||
|
||||
die(MBERR_OK);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
8
mbutils/mbsnmp.h
Normal file
8
mbutils/mbsnmp.h
Normal file
@ -0,0 +1,8 @@
|
||||
/* $Id$ */
|
||||
|
||||
#ifndef _MBSNMP_H
|
||||
#define _MBSNMP_H
|
||||
|
||||
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user