Logo
Home page Net-SNMP

Archive Search:

Require all words?

Site Search:
Google
old_api.c File Reference
Main Page   Data Structures   File List   Data Fields   Globals  

old_api.c File Reference

#include <config.h>
#include <string.h>
#include "mibincl.h"
#include "tools.h"
#include "snmp_agent.h"
#include "old_api.h"
#include <dmalloc.h>

Go to the source code of this file.


Defines

#define MIB_CLIENTS_ARE_EVIL   1

Functions

agent_snmp_sessionget_current_agent_session ()
void set_current_agent_session (struct agent_snmp_session *asp)
mib_handlerget_old_api_handler (void)
int register_old_api (const char *moduleName, struct variable *var, size_t varsize, size_t numvars, oid *mibloc, size_t mibloclen, int priority, int range_subid, oid range_ubound, struct snmp_session *ss, const char *context, int timeout, int flags)
int old_api_helper (mib_handler *handler, handler_registration *reginfo, agent_request_info *reqinfo, request_info *requests)

Define Documentation

#define MIB_CLIENTS_ARE_EVIL   1
 

Definition at line 18 of file old_api.c.


Function Documentation

struct agent_snmp_session* get_current_agent_session void   
 

Definition at line 22 of file old_api.c.

00022                             {
00023     return current_agent_session;
00024 }

mib_handler* get_old_api_handler void   
 

Definition at line 32 of file old_api.c.

Referenced by register_old_api().

00032                           {
00033     return create_handler("old_api", old_api_helper);
00034 }

int old_api_helper mib_handler   handler,
handler_registration   reginfo,
agent_request_info   reqinfo,
request_info   requests
 

Definition at line 97 of file old_api.c.

00100                                                     {
00101 
00102 #if MIB_CLIENTS_ARE_EVIL
00103     oid                 save[MAX_OID_LEN];
00104     size_t              savelen = 0;
00105 #endif
00106     struct variable     compat_var, *cvp = &compat_var;
00107     int exact = 1;
00108     int status;
00109     int have_delegated = 0;
00110     
00111     struct variable *vp;
00112     WriteMethod *write_method = NULL;
00113     size_t len;
00114     u_char *access = NULL;
00115     old_api_cache *cacheptr;
00116     AddVarMethod *add_method;
00117     struct agent_snmp_session  *oldasp = NULL;
00118 
00119     vp = (struct variable *) handler->myvoid;
00120 
00121     /* create old variable structure with right information */
00122     memcpy(cvp->name, reginfo->rootoid, reginfo->rootoid_len * sizeof(oid));
00123     cvp->namelen = reginfo->rootoid_len;
00124     cvp->type = vp->type;
00125     cvp->magic = vp->magic;
00126     cvp->acl = vp->acl;
00127     cvp->findVar = vp->findVar;
00128 
00129     switch(reqinfo->mode) {
00130         case MODE_GETNEXT:
00131         case MODE_GETBULK:
00132             exact = 0;
00133     }
00134 
00135     while(requests) {
00136         
00137 #if MIB_CLIENTS_ARE_EVIL
00138         savelen = requests->requestvb->name_length;
00139         memcpy(save, requests->requestvb->name,
00140                savelen*sizeof(oid));
00141 #endif
00142 
00143         switch(reqinfo->mode) {
00144             case MODE_GET:
00145             case MODE_GETNEXT:
00146             case MODE_GETBULK:   /* WWW */
00147             case MODE_SET_RESERVE1:
00148                 /* Actually call the old mib-module function */
00149                 if (vp && vp->findVar)
00150                     access = (*(vp->findVar))(cvp, requests->requestvb->name,
00151                                               &(requests->requestvb->name_length),
00152                                               exact, &len, &write_method);
00153                 else
00154                     access = NULL;
00155 
00156 #ifdef WWW_FIX
00157                 if (IS_DELEGATED(cvp->type)) {
00158                     add_method = (AddVarMethod*)statP;
00159                     requests->delayed = 1;
00160                     have_delegated = 1;
00161                     continue; /* WWW: This may not get to the right place */
00162                 }
00163 #endif
00164 
00165                 /* WWW: end range checking */
00166                 if (access) {
00167                     /* result returned */
00168                     if (reqinfo->mode != MODE_SET_RESERVE1)
00169                         snmp_set_var_typed_value(requests->requestvb,
00170                                                  cvp->type, access, len);
00171                 } else {
00172                     /* no result returned */
00173 #if MIB_CLIENTS_ARE_EVIL
00174                     if (access == NULL) {
00175                         if (snmp_oid_compare(requests->requestvb->name,
00176                                              requests->requestvb->name_length,
00177                                              save, savelen) != 0) {
00178                             snmp_log(LOG_WARNING, "evil_client: %s\n",
00179                                      reginfo->handlerName);
00180                             memcpy(requests->requestvb->name, save,
00181                                    savelen*sizeof(oid));
00182                             requests->requestvb->name_length = savelen;
00183                         }
00184                     }
00185 #endif
00186                 }
00187 
00188                 /* AAA: fall through for everything that is a set (see BBB) */
00189                 if (reqinfo->mode != MODE_SET_RESERVE1)
00190                     break;
00191 
00192                 cacheptr = SNMP_MALLOC_TYPEDEF(old_api_cache);
00193                 if (!cacheptr)
00194                     return set_request_error(reqinfo, requests,
00195                                              SNMP_ERR_RESOURCEUNAVAILABLE);
00196                 cacheptr->data = access;
00197                 cacheptr->write_method = write_method;
00198                 request_add_list_data(requests,
00199                                       create_data_list(OLD_API_NAME, cacheptr,
00200                                                        free));
00201                 /* BBB: fall through for everything that is a set (see AAA) */
00202                 
00203             default:
00204                 /* WWW: explicitly list the SET conditions */
00205                 /* (the rest of the) SET contions */
00206                 cacheptr =
00207                     (old_api_cache *) request_get_list_data(requests,
00208                                                             OLD_API_NAME);
00209 
00210                 if (cacheptr == NULL || cacheptr->write_method == NULL) {
00211                     /* WWW: try to set ourselves if possible? */
00212                     return set_request_error(reqinfo, requests,
00213                                              SNMP_ERR_NOTWRITABLE);
00214                 }
00215 
00216                 oldasp = get_current_agent_session();
00217                 set_current_agent_session(reqinfo->asp);
00218                 status =
00219                     (*(cacheptr->write_method))(reqinfo->mode,
00220                                                 requests->requestvb->val.string,
00221                                                 requests->requestvb->type,
00222                                                 requests->requestvb->val_len,
00223                                                 cacheptr->data,
00224                                                 requests->requestvb->name,
00225                                                 requests->requestvb->name_length);
00226                 set_current_agent_session(oldasp);
00227 
00228                 if (requests->status != SNMP_ERR_NOERROR)
00229                     set_request_error(reqinfo, requests, status);
00230 
00231                 /* clean up is done by the automatic freeing of the
00232                    cache stored in the request. */
00233 
00234                 break;
00235         }
00236         requests = requests->next;
00237     }
00238     return SNMP_ERR_NOERROR;
00239 }

int register_old_api const char *    moduleName,
struct variable   var,
size_t    varsize,
size_t    numvars,
oid *    mibloc,
size_t    mibloclen,
int    priority,
int    range_subid,
oid    range_ubound,
struct snmp_session *    ss,
const char *    context,
int    timeout,
int    flags
 

Definition at line 38 of file old_api.c.

00050                             {
00051     
00052     old_api_info *old_info = SNMP_MALLOC_TYPEDEF(old_api_info);
00053     int i;
00054     
00055     old_info->var = var;
00056     old_info->varsize = varsize;
00057     old_info->numvars = numvars;
00058     old_info->ss = ss;
00059     old_info->flags = flags;
00060     
00061     /* register all subtree nodes */
00062     for(i = 0; i < numvars; i++) {
00063         struct variable *vp;
00064         handler_registration *reginfo =
00065             SNMP_MALLOC_TYPEDEF(handler_registration);
00066 
00067         memdup((void *) &vp,
00068                (void *) (struct variable *) ((char *) var + varsize*i),
00069                varsize);
00070  
00071         reginfo->handler = get_old_api_handler();
00072         reginfo->handlerName = strdup(moduleName);
00073         reginfo->rootoid_len = (mibloclen + vp->namelen);
00074         reginfo->rootoid =
00075             (oid *) malloc(reginfo->rootoid_len * sizeof(oid));
00076         
00077         memcpy(reginfo->rootoid, mibloc, mibloclen*sizeof(oid));
00078         memcpy(reginfo->rootoid + mibloclen, vp->name, vp->namelen
00079                * sizeof(oid));
00080         reginfo->handler->myvoid = (void *) vp;
00081 
00082         reginfo->priority = priority;
00083         reginfo->range_subid = range_subid;
00084         
00085         reginfo->range_ubound = range_ubound;
00086         reginfo->timeout = timeout;
00087         reginfo->contextName = (context) ? strdup(context) : NULL;
00088         reginfo->modes = HANDLER_CAN_RWRITE;
00089 
00090         /* register ourselves in the mib tree */
00091         register_handler(reginfo);
00092     }
00093     return SNMPERR_SUCCESS;
00094 }

void set_current_agent_session struct agent_snmp_session   asp
 

Definition at line 27 of file old_api.c.

Referenced by old_api_helper().

00027                                                            {
00028     current_agent_session = asp;
00029 }

Generated on Sat Nov 10 14:09:55 2001 for net-snmp by doxygen1.2.11 written by Dimitri van Heesch, © 1997-2001
[an error occurred while processing this directive] [an error occurred while processing this directive]

Valid CSS!


Last modified: Wednesday, 01-Aug-2018 04:41:28 UTC
For questions regarding web content and site functionality, please write to the net-snmp-users mail list.