SNMP Subagent Programmer's Guide
Writing Subagent Logic
SNMP Subagent Programmer’s Guide—119728 4-21
Management Functions
When a request is received from the NonStop agent, Security Checker initializes the
value of the flag named “authenticated” to 0. The subagent then calls mgmt_security().
The community string returned is parsed by the authentication function, authenticate(),
to determine whether its subagent password component matches the password specified
at subagent invocation:
authenticated = 0;
status = mgmt_security(mgmt_env, &community, &hostaddr);
if (status == MGMT_SECURITY_OK) {
fprintf(stderr, " hostaddr == 0x%x\n", hostaddr);
fprintf(stderr, " community == '%s'\n", community.val);
if (authenticated = authenticate())
{ fprintf(stderr, "... community string is correct."); }
else
{ fprintf(stderr, "... community string is incorrect."); }
}
The authenticate() function resets the value of “authenticate,” assigning 1 if the
passwords match and 0 if they do not. When mgmt_poll() is called, the run-time library
invokes one of the access functions provided by the subagent; if the value of authenticate
is 1, the request is processed; otherwise an error is returned. For example, the access
function that retrieves the value of one of a MIB object named helloPrintFreq looks like
this:
static int
GET_helloPrintFreq(void *ctxt, void **indices, void *attr_ref)
{
INTEGER *attr;
if (!authenticated) {return(SNMP_ERR_GEN_ERR);}
attr = (INTEGER *) attr_ref;
*attr = helloPrintFreq;
return(SNMP_ERR_NO_ERROR);
}