| 1 |
/* |
| 2 |
* Note: this file originally auto-generated by mib2c using |
| 3 |
* : mib2c.container.conf,v 1.8 2006/07/26 15:58:26 dts12 Exp $ |
| 4 |
*/ |
| 5 |
/* Portions of this file are subject to the following copyright(s). See |
| 6 |
* the Net-SNMP's COPYING file for more details and other copyrights |
| 7 |
* that may apply: |
| 8 |
*/ |
| 9 |
/* |
| 10 |
* Portions of this file are copyrighted by: |
| 11 |
* Copyright (C) 2007 Apple, Inc. All rights reserved. |
| 12 |
* Use is subject to license terms specified in the COPYING file |
| 13 |
* distributed with the Net-SNMP package. |
| 14 |
*/ |
| 15 |
|
| 16 |
#include <net-snmp/net-snmp-config.h> |
| 17 |
#include <net-snmp/net-snmp-includes.h> |
| 18 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 19 |
#include <net-snmp/agent/table_container.h> |
| 20 |
#include <net-snmp/data_access/swrun.h> |
| 21 |
#include <net-snmp/agent/cache_handler.h> |
| 22 |
#include "data_access/swrun.h" |
| 23 |
#include "hrSWRunTable.h" |
| 24 |
|
| 25 |
#include <signal.h> |
| 26 |
|
| 27 |
#define MYTABLE "hrSWRunTable" |
| 28 |
|
| 29 |
static netsnmp_table_registration_info *table_info; |
| 30 |
|
| 31 |
/** Initializes the hrSWRunTable module */ |
| 32 |
void |
| 33 |
init_hrSWRunTable(void) |
| 34 |
{ |
| 35 |
/* |
| 36 |
* here we initialize all the tables we're planning on supporting |
| 37 |
*/ |
| 38 |
initialize_table_hrSWRunTable(); |
| 39 |
} |
| 40 |
|
| 41 |
void |
| 42 |
shutdown_hrSWRunTable(void) |
| 43 |
{ |
| 44 |
if (table_info) { |
| 45 |
netsnmp_table_registration_info_free(table_info); |
| 46 |
table_info = NULL; |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
oid hrSWRunTable_oid[] = { 1, 3, 6, 1, 2, 1, 25, 4, 2 }; |
| 51 |
size_t hrSWRunTable_oid_len = OID_LENGTH(hrSWRunTable_oid); |
| 52 |
|
| 53 |
/** Initialize the hrSWRunTable table by defining its contents and how it's structured */ |
| 54 |
void |
| 55 |
initialize_table_hrSWRunTable(void) |
| 56 |
{ |
| 57 |
netsnmp_handler_registration *reg; |
| 58 |
netsnmp_mib_handler *handler = NULL; |
| 59 |
#ifndef NETSNMP_NO_WRITE_SUPPORT |
| 60 |
#ifdef NETSNMP_INCLUDE_HRSWRUN_WRITE_SUPPORT |
| 61 |
# define SWRUN_ACCESS_LEVEL HANDLER_CAN_RWRITE |
| 62 |
#else |
| 63 |
# define SWRUN_ACCESS_LEVEL HANDLER_CAN_RONLY |
| 64 |
#endif |
| 65 |
#else /* !NETSNMP_NO_WRITE_SUPPORT */ |
| 66 |
# define SWRUN_ACCESS_LEVEL HANDLER_CAN_RONLY |
| 67 |
#endif /* !NETSNMP_NO_WRITE_SUPPORT */ |
| 68 |
reg = |
| 69 |
netsnmp_create_handler_registration(MYTABLE, |
| 70 |
hrSWRunTable_handler, |
| 71 |
hrSWRunTable_oid, |
| 72 |
hrSWRunTable_oid_len, |
| 73 |
SWRUN_ACCESS_LEVEL); |
| 74 |
if (NULL == reg) { |
| 75 |
snmp_log(LOG_ERR,"error creating handler registration for " |
| 76 |
MYTABLE "\n"); |
| 77 |
goto bail; |
| 78 |
} |
| 79 |
reg->modes |= HANDLER_CAN_NOT_CREATE; |
| 80 |
|
| 81 |
table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); |
| 82 |
if (NULL == table_info) { |
| 83 |
snmp_log(LOG_ERR,"error allocating table registration for " |
| 84 |
MYTABLE "\n"); |
| 85 |
goto bail; |
| 86 |
} |
| 87 |
|
| 88 |
netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER, /* index: hrSWRunIndex */ |
| 89 |
0); |
| 90 |
table_info->min_column = COLUMN_HRSWRUNINDEX; |
| 91 |
table_info->max_column = COLUMN_HRSWRUNSTATUS; |
| 92 |
|
| 93 |
/************************************************* |
| 94 |
* |
| 95 |
* inject container_table helper |
| 96 |
*/ |
| 97 |
handler = netsnmp_container_table_handler_get(table_info, netsnmp_swrun_container(), |
| 98 |
TABLE_CONTAINER_KEY_NETSNMP_INDEX); |
| 99 |
if (NULL == handler) { |
| 100 |
snmp_log(LOG_ERR,"error allocating table registration for " |
| 101 |
MYTABLE "\n"); |
| 102 |
goto bail; |
| 103 |
} |
| 104 |
if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) { |
| 105 |
snmp_log(LOG_ERR,"error injecting container_table handler for " |
| 106 |
MYTABLE "\n"); |
| 107 |
goto bail; |
| 108 |
} |
| 109 |
handler = NULL; /* reg has it, will reuse below */ |
| 110 |
|
| 111 |
/************************************************* |
| 112 |
* |
| 113 |
* inject cache helper |
| 114 |
*/ |
| 115 |
handler = netsnmp_cache_handler_get(netsnmp_swrun_cache()); |
| 116 |
if (NULL == handler) { |
| 117 |
snmp_log(LOG_ERR, "error creating cache handler for " MYTABLE "\n"); |
| 118 |
goto bail; |
| 119 |
} |
| 120 |
|
| 121 |
if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) { |
| 122 |
snmp_log(LOG_ERR,"error injecting cache handler for " |
| 123 |
MYTABLE "\n"); |
| 124 |
goto bail; |
| 125 |
} |
| 126 |
handler = NULL; /* reg has it*/ |
| 127 |
|
| 128 |
if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) { |
| 129 |
snmp_log(LOG_ERR,"error registering table handler for " |
| 130 |
MYTABLE "\n"); |
| 131 |
reg = NULL; /* it was freed inside netsnmp_register_table */ |
| 132 |
goto bail; |
| 133 |
} |
| 134 |
|
| 135 |
return; /* ok */ |
| 136 |
|
| 137 |
|
| 138 |
bail: /* not ok */ |
| 139 |
|
| 140 |
if (handler) |
| 141 |
netsnmp_handler_free(handler); |
| 142 |
|
| 143 |
if (table_info) |
| 144 |
netsnmp_table_registration_info_free(table_info); |
| 145 |
|
| 146 |
if (reg) |
| 147 |
netsnmp_handler_registration_free(reg); |
| 148 |
|
| 149 |
} |
| 150 |
|
| 151 |
/** handles requests for the hrSWRunTable table */ |
| 152 |
int |
| 153 |
hrSWRunTable_handler(netsnmp_mib_handler *handler, |
| 154 |
netsnmp_handler_registration *reginfo, |
| 155 |
netsnmp_agent_request_info *reqinfo, |
| 156 |
netsnmp_request_info *requests) |
| 157 |
{ |
| 158 |
netsnmp_request_info *request; |
| 159 |
netsnmp_table_request_info *table_info; |
| 160 |
netsnmp_swrun_entry *table_entry; |
| 161 |
|
| 162 |
switch (reqinfo->mode) { |
| 163 |
/* |
| 164 |
* Read-support (also covers GetNext requests) |
| 165 |
*/ |
| 166 |
case MODE_GET: |
| 167 |
for (request = requests; request; request = request->next) { |
| 168 |
if (request->processed) |
| 169 |
continue; |
| 170 |
table_entry = (netsnmp_swrun_entry *) |
| 171 |
netsnmp_container_table_extract_context(request); |
| 172 |
table_info = netsnmp_extract_table_info(request); |
| 173 |
if ((NULL == table_entry) || (NULL == table_info)) { |
| 174 |
snmp_log(LOG_ERR, "could not extract table entry or info for " |
| 175 |
MYTABLE "\n"); |
| 176 |
snmp_set_var_typed_value(request->requestvb, |
| 177 |
SNMP_ERR_GENERR, NULL, 0); |
| 178 |
continue; |
| 179 |
} |
| 180 |
|
| 181 |
switch (table_info->colnum) { |
| 182 |
case COLUMN_HRSWRUNINDEX: |
| 183 |
snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, |
| 184 |
table_entry->hrSWRunIndex); |
| 185 |
break; |
| 186 |
case COLUMN_HRSWRUNNAME: |
| 187 |
snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, |
| 188 |
(u_char *) table_entry-> |
| 189 |
hrSWRunName, |
| 190 |
table_entry->hrSWRunName_len); |
| 191 |
break; |
| 192 |
case COLUMN_HRSWRUNID: |
| 193 |
snmp_set_var_typed_value(request->requestvb, ASN_OBJECT_ID, |
| 194 |
#ifdef NETSNMP_SWRUN_HAVE_ID |
| 195 |
(u_char *) table_entry->hrSWRunID, |
| 196 |
table_entry->hrSWRunID_len |
| 197 |
#else |
| 198 |
(u_char *) &nullOid, nullOidLen |
| 199 |
#endif |
| 200 |
); |
| 201 |
break; |
| 202 |
case COLUMN_HRSWRUNPATH: |
| 203 |
snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, |
| 204 |
(u_char *) table_entry-> |
| 205 |
hrSWRunPath, |
| 206 |
table_entry->hrSWRunPath_len); |
| 207 |
break; |
| 208 |
case COLUMN_HRSWRUNPARAMETERS: |
| 209 |
snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, |
| 210 |
(u_char *) table_entry-> |
| 211 |
hrSWRunParameters, |
| 212 |
table_entry-> |
| 213 |
hrSWRunParameters_len); |
| 214 |
break; |
| 215 |
case COLUMN_HRSWRUNTYPE: |
| 216 |
snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, |
| 217 |
table_entry->hrSWRunType); |
| 218 |
break; |
| 219 |
case COLUMN_HRSWRUNSTATUS: |
| 220 |
snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, |
| 221 |
table_entry->hrSWRunStatus); |
| 222 |
break; |
| 223 |
default: |
| 224 |
/* |
| 225 |
* An unsupported/unreadable column (if applicable) |
| 226 |
*/ |
| 227 |
snmp_set_var_typed_value(request->requestvb, |
| 228 |
SNMP_NOSUCHOBJECT, NULL, 0); |
| 229 |
} |
| 230 |
} |
| 231 |
break; |
| 232 |
|
| 233 |
#ifndef NETSNMP_NO_WRITE_SUPPORT |
| 234 |
#ifdef NETSNMP_INCLUDE_HRSWRUN_WRITE_SUPPORT |
| 235 |
/* |
| 236 |
* Write-support |
| 237 |
*/ |
| 238 |
case MODE_SET_RESERVE1: |
| 239 |
for (request = requests; request; request = request->next) { |
| 240 |
int pid; |
| 241 |
if (request->processed) |
| 242 |
continue; |
| 243 |
table_entry = (netsnmp_swrun_entry *) |
| 244 |
netsnmp_container_table_extract_context(request); |
| 245 |
table_info = netsnmp_extract_table_info(request); |
| 246 |
if ((NULL == table_entry) || (NULL == table_info)) { |
| 247 |
snmp_log(LOG_ERR, "could not extract table entry or info for " |
| 248 |
MYTABLE "\n"); |
| 249 |
snmp_set_var_typed_value(request->requestvb, |
| 250 |
SNMP_ERR_GENERR, NULL, 0); |
| 251 |
continue; |
| 252 |
} |
| 253 |
|
| 254 |
switch (table_info->colnum) { |
| 255 |
case COLUMN_HRSWRUNSTATUS: |
| 256 |
if (*request->requestvb->val.integer != HRSWRUNSTATUS_INVALID) { |
| 257 |
netsnmp_set_request_error(reqinfo, request, |
| 258 |
SNMP_ERR_WRONGVALUE); |
| 259 |
return SNMP_ERR_NOERROR; |
| 260 |
} |
| 261 |
pid = request->requestvb->name[request->requestvb->name_length-1]; |
| 262 |
if (1 == pid) { |
| 263 |
snmp_log(LOG_WARNING,"refusing to kill pid 1\n"); |
| 264 |
netsnmp_set_request_error(reqinfo, request, |
| 265 |
SNMP_ERR_NOACCESS); |
| 266 |
return SNMP_ERR_NOERROR; |
| 267 |
} |
| 268 |
break; |
| 269 |
default: |
| 270 |
netsnmp_set_request_error(reqinfo, request, |
| 271 |
SNMP_ERR_NOTWRITABLE); |
| 272 |
return SNMP_ERR_NOERROR; |
| 273 |
} |
| 274 |
} |
| 275 |
break; |
| 276 |
|
| 277 |
case MODE_SET_RESERVE2: |
| 278 |
break; |
| 279 |
|
| 280 |
case MODE_SET_FREE: |
| 281 |
break; |
| 282 |
|
| 283 |
case MODE_SET_ACTION: |
| 284 |
for (request = requests; request; request = request->next) { |
| 285 |
if (request->processed) |
| 286 |
continue; |
| 287 |
table_entry = (netsnmp_swrun_entry *) |
| 288 |
netsnmp_container_table_extract_context(request); |
| 289 |
table_info = netsnmp_extract_table_info(request); |
| 290 |
if ((NULL == table_entry) || (NULL == table_info)) { |
| 291 |
snmp_log(LOG_ERR, "could not extract table entry or info for " |
| 292 |
MYTABLE "\n"); |
| 293 |
snmp_set_var_typed_value(request->requestvb, |
| 294 |
SNMP_ERR_GENERR, NULL, 0); |
| 295 |
continue; |
| 296 |
} |
| 297 |
|
| 298 |
switch (table_info->colnum) { |
| 299 |
case COLUMN_HRSWRUNSTATUS: |
| 300 |
table_entry->old_hrSWRunStatus = |
| 301 |
table_entry->hrSWRunStatus; |
| 302 |
table_entry->hrSWRunStatus = |
| 303 |
*request->requestvb->val.integer; |
| 304 |
break; |
| 305 |
} |
| 306 |
} |
| 307 |
break; |
| 308 |
|
| 309 |
case MODE_SET_UNDO: |
| 310 |
for (request = requests; request; request = request->next) { |
| 311 |
if (request->processed) |
| 312 |
continue; |
| 313 |
container = netsnmp_container_table_extract_context(request); |
| 314 |
table_entry = (netsnmp_swrun_entry *) |
| 315 |
netsnmp_container_table_extract_context(request); |
| 316 |
table_info = netsnmp_extract_table_info(request); |
| 317 |
if ((NULL == table_entry) || (NULL == table_info)) { |
| 318 |
snmp_log(LOG_ERR, "could not extract table entry or info for " |
| 319 |
MYTABLE "\n"); |
| 320 |
snmp_set_var_typed_value(request->requestvb, |
| 321 |
SNMP_ERR_GENERR, NULL, 0); |
| 322 |
continue; |
| 323 |
} |
| 324 |
|
| 325 |
switch (table_info->colnum) { |
| 326 |
case COLUMN_HRSWRUNSTATUS: |
| 327 |
table_entry->hrSWRunStatus = |
| 328 |
table_entry->old_hrSWRunStatus; |
| 329 |
table_entry->old_hrSWRunStatus = 0; |
| 330 |
break; |
| 331 |
} |
| 332 |
} |
| 333 |
break; |
| 334 |
|
| 335 |
case MODE_SET_COMMIT: |
| 336 |
for (request = requests; request; request = request->next) { |
| 337 |
int pid; |
| 338 |
if (request->processed) |
| 339 |
continue; |
| 340 |
pid = request->requestvb->name[request->requestvb->name_length-1]; |
| 341 |
DEBUGMSGTL(("hrSWRunTable:commit", "kill(%d,TERM)\n", pid)); |
| 342 |
kill(pid, SIGTERM); |
| 343 |
} |
| 344 |
break; |
| 345 |
#endif /* NETSNMP_INCLUDE_HRSWRUN_WRITE_SUPPORT */ |
| 346 |
#endif /* !NETSNMP_NO_WRITE_SUPPORT */ |
| 347 |
} |
| 348 |
return SNMP_ERR_NOERROR; |
| 349 |
} |
| 350 |
|