SNMP Subagent Programmer's Guide
Security Checker
2-90 119728—SNMP Subagent Programmer’s Guide
Programming Tutorials
wait:
event_fileno = -1;
status = AWAITIOX(&event_fileno,,&count_xferd,,100*helloPrintFreq);
if (status != CCE) {
FILE_GETINFO_(event_fileno, &error);
if (error == 40) {
(void) fputs((char *) helloText.val, stderr);
(void) fputs("\n", stderr);
helloPrintCnt++;
goto wait;
} else {
(void) fprintf(stderr, "%s: AWAITIO error %i on file %i\n",
argv[0], error, event_fileno);
/* handle other errors here, may want to goto wait after */
} /* end if error == 40 */
} /* end if status != CCE */
if (event_fileno == agent_fileno) {
<--8
/* security */
authenticated = 0;
status = mgmt_security(mgmt_env, &community, &hostaddr);
<--9
fprintf(stderr, "mgmt_security() status == %i\n", status);
if (status == MGMT_SECURITY_OK) {
fprintf(stderr, " hostaddr == 0x%x\n", hostaddr);
fprintf(stderr, " community == '%s'\n", community.val);
if (authenticated = authenticate())
<--10
{ fprintf(stderr, "... community string is correct."); }
else
{ fprintf(stderr, "... community string is incorrect."); }
}
/* security */
if (mgmt_poll((struct mgmt_env *) mgmt_env,(struct timeval *) NULL,
<--11
&count_xferd) < 0)
{
(void) fprintf(stderr,"%s: agent unavailable for poll\n", argv[0]);
break;
}
/* If the print frequency has been modified output the
* helloFreqChange trap.
*/
if (last_freq != helloPrintFreq)
{
last_freq = helloPrintFreq;
authenticated = 1; /* ensure access functions work if called */
<--12
(void) mgmt_trap(mgmt_env, &TRAP_helloFreqChange);
}
Example 2-18. Security Checker Main Program (page 4 of 5)