SNMP Subagent Programmer's Guide

Programming Tutorials
SNMP Subagent Programmer’s Guide—119728 2-87
Security Checker
Although Security Checker uses only this simple authentication test, more
sophisticated tests could appear in this location. You might, for example, want to
process the request only if one of several possible passwords is associated with the
request.
Example 2-18. Security Checker Main Program (page 1 of 5)
/***********************************************************************************
*
* hellosc.c - demo hello world program to illustrate how a nowait
* subagent can make use of the security information transmitted
* with get and set requests from the D23 version of the (T9576AAD and later)
* NSK SNMP Agent.
*
***********************************************************************************/
#include "tdmporth" nolist
#include "machtyph" nolist
#include "syspubh" nolist
#include "smitypeh" nolist
#include "mgmtpubh" nolist
#include "mgmtenvh" nolist /* needed for mgmt_env buffer manipulations */
#include "snmpvblh" nolist /* to get SNMP_MSG_MAX (also sourced by hello.h)*/
#define DEF_TEXT "this is the secret message"
#define DEF_FREQUENCY 10
/*
* global attributes that will be referenced by SMI
* compiler generated code. These global variables must be
* defined before the file "securit.c" is included because this
* file will make reference to these variables. These are the names
* that appear in the C_VARIABLE clauses.
*/
static char text[256] = {DEF_TEXT};
static DisplayString helloText = {sizeof(DEF_TEXT)-1, (ubyte *) text};
static INTEGER helloPrintFreq = DEF_FREQUENCY;
static Counter helloPrintCnt = 0;
/* stuff for mgmt_security() */
struct mgmt_env *mgmt_env = NULL;
short status; <--1
static char communitytext[256];
static OCTETSTRING community = {0, (ubyte *) communitytext};
static NetworkAddress hostaddr;
/* stuff for authenticate() */
static char password[256]; <--2
short authenticated;
/* gdmoc definitions, authenticate(), and access functions */
#include "authentc" nolist /* authenticate() */ <--3
#pragma nowarn (93)
#include "securitc" nolist /* access functions, based on SMI compiler output */
#include "hellosch" nolist /* SMI compiler output */
#pragma warn (93)
#include <talh> nolist
#include <cextdecs (FILE_GETINFO_,AWAITIOX)> nolist
static int time_to_die = 0;