action.c (163821) | action.c (216294) |
---|---|
1/* 2 * Copyright (c) 2001-2003 3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4 * All rights reserved. 5 * Copyright (c) 2004-2006 6 * Hartmut Brandt. 7 * All rights reserved. 8 * --- 20 unchanged lines hidden (view full) --- 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * $Begemot: action.c 517 2006-10-31 08:52:04Z brandt_h $ 33 * 34 * Variable access for SNMPd 35 */ 36#include <sys/types.h> | 1/* 2 * Copyright (c) 2001-2003 3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4 * All rights reserved. 5 * Copyright (c) 2004-2006 6 * Hartmut Brandt. 7 * All rights reserved. 8 * --- 20 unchanged lines hidden (view full) --- 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * $Begemot: action.c 517 2006-10-31 08:52:04Z brandt_h $ 33 * 34 * Variable access for SNMPd 35 */ 36#include <sys/types.h> |
37#include <sys/queue.h> |
|
37#include <sys/sysctl.h> 38#include <sys/un.h> 39#include <sys/utsname.h> 40#include <stdio.h> 41#include <stdlib.h> 42#include <stdarg.h> 43#include <string.h> 44#include <ctype.h> | 38#include <sys/sysctl.h> 39#include <sys/un.h> 40#include <sys/utsname.h> 41#include <stdio.h> 42#include <stdlib.h> 43#include <stdarg.h> 44#include <string.h> 45#include <ctype.h> |
46#include <errno.h> |
|
45#include <syslog.h> 46 47#include "snmpmod.h" 48#include "snmpd.h" 49#include "tree.h" 50#include "oid.h" 51 52static const struct asn_oid --- 104 unchanged lines hidden (view full) --- 157 } 158#endif 159 160 free(hostid); 161 162 return (0); 163} 164 | 47#include <syslog.h> 48 49#include "snmpmod.h" 50#include "snmpd.h" 51#include "tree.h" 52#include "oid.h" 53 54static const struct asn_oid --- 104 unchanged lines hidden (view full) --- 159 } 160#endif 161 162 free(hostid); 163 164 return (0); 165} 166 |
167/* 168 * Initialize global variables of the snmpEngine group. 169 */ 170int 171init_snmpd_engine(void) 172{ 173 char *hostid; |
|
165 | 174 |
175 snmpd_engine.engine_boots = 1; 176 snmpd_engine.engine_time = 1; 177 snmpd_engine.max_msg_size = 1500; /* XXX */ |
|
166 | 178 |
179 snmpd_engine.engine_id[0] = ((OID_freeBSD & 0xff000000) >> 24) | 0x80; 180 snmpd_engine.engine_id[1] = (OID_freeBSD & 0xff0000) >> 16; 181 snmpd_engine.engine_id[2] = (OID_freeBSD & 0xff00) >> 8; 182 snmpd_engine.engine_id[3] = OID_freeBSD & 0xff; 183 snmpd_engine.engine_id[4] = 128; 184 snmpd_engine.engine_len = 5; 185 186 if ((hostid = act_getkernint(KERN_HOSTID)) == NULL) 187 return (-1); 188 189 if (strlen(hostid) > SNMP_ENGINE_ID_SIZ - snmpd_engine.engine_len) { 190 memcpy(snmpd_engine.engine_id + snmpd_engine.engine_len, 191 hostid, SNMP_ENGINE_ID_SIZ - snmpd_engine.engine_len); 192 snmpd_engine.engine_len = SNMP_ENGINE_ID_SIZ; 193 } else { 194 memcpy(snmpd_engine.engine_id + snmpd_engine.engine_len, 195 hostid, strlen(hostid)); 196 snmpd_engine.engine_len += strlen(hostid); 197 } 198 199 free(hostid); 200 201 return (0); 202} 203 204int 205set_snmpd_engine(void) 206{ 207 FILE *fp; 208 uint32_t i; 209 uint8_t *cptr, engine[2 * SNMP_ENGINE_ID_SIZ + 2]; 210 uint8_t myengine[2 * SNMP_ENGINE_ID_SIZ + 2]; 211 212 if (engine_file[0] == '\0') 213 return (-1); 214 215 cptr = myengine; 216 for (i = 0; i < snmpd_engine.engine_len; i++) 217 cptr += sprintf(cptr, "%.2x", snmpd_engine.engine_id[i]); 218 *cptr++ = '\n'; 219 *cptr++ = '\0'; 220 221 if ((fp = fopen(engine_file, "r+")) != NULL) { 222 if (fgets(engine, sizeof(engine) - 1, fp) == NULL || 223 fscanf(fp, "%u", &snmpd_engine.engine_boots) <= 0) { 224 fclose(fp); 225 goto save_boots; 226 } 227 228 fclose(fp); 229 if (strcmp(myengine, engine) != 0) 230 snmpd_engine.engine_boots = 1; 231 else 232 snmpd_engine.engine_boots++; 233 } else if (errno != ENOENT) 234 return (-1); 235 236save_boots: 237 if ((fp = fopen(engine_file, "w+")) == NULL) 238 return (-1); 239 fprintf(fp, "%s%u\n", myengine, snmpd_engine.engine_boots); 240 fclose(fp); 241 242 return (0); 243} 244 |
|
167/************************************************************* 168 * 169 * System group 170 */ 171int 172op_system_group(struct snmp_context *ctx, struct snmp_value *value, 173 u_int sub, u_int iidx __unused, enum snmp_op op) 174{ --- 800 unchanged lines hidden (view full) --- 975 if (snmp_serial_no++ == 2147483647) 976 snmp_serial_no = 0; 977 return (SNMP_ERR_NOERROR); 978 } 979 abort(); 980} 981 982/* | 245/************************************************************* 246 * 247 * System group 248 */ 249int 250op_system_group(struct snmp_context *ctx, struct snmp_value *value, 251 u_int sub, u_int iidx __unused, enum snmp_op op) 252{ --- 800 unchanged lines hidden (view full) --- 1053 if (snmp_serial_no++ == 2147483647) 1054 snmp_serial_no = 0; 1055 return (SNMP_ERR_NOERROR); 1056 } 1057 abort(); 1058} 1059 1060/* |
1061 * SNMP Engine 1062 */ 1063int 1064op_snmp_engine(struct snmp_context *ctx __unused, struct snmp_value *value, 1065 u_int sub, u_int iidx __unused, enum snmp_op op) 1066{ 1067 asn_subid_t which = value->var.subs[sub - 1]; 1068 1069 switch (op) { 1070 case SNMP_OP_GETNEXT: 1071 abort(); 1072 1073 case SNMP_OP_GET: 1074 break; 1075 1076 case SNMP_OP_SET: 1077 if (community != COMM_INITIALIZE) 1078 return (SNMP_ERR_NOT_WRITEABLE); 1079 switch (which) { 1080 case LEAF_snmpEngineID: 1081 if (value->v.octetstring.len > SNMP_ENGINE_ID_SIZ) 1082 return (SNMP_ERR_WRONG_VALUE); 1083 ctx->scratch->ptr1 = malloc(snmpd_engine.engine_len); 1084 if (ctx->scratch->ptr1 == NULL) 1085 return (SNMP_ERR_GENERR); 1086 memcpy(ctx->scratch->ptr1, snmpd_engine.engine_id, 1087 snmpd_engine.engine_len); 1088 ctx->scratch->int1 = snmpd_engine.engine_len; 1089 snmpd_engine.engine_len = value->v.octetstring.len; 1090 memcpy(snmpd_engine.engine_id, 1091 value->v.octetstring.octets, 1092 value->v.octetstring.len); 1093 break; 1094 1095 case LEAF_snmpEngineMaxMessageSize: 1096 ctx->scratch->int1 = snmpd_engine.max_msg_size; 1097 snmpd_engine.max_msg_size = value->v.integer; 1098 break; 1099 1100 default: 1101 return (SNMP_ERR_NOT_WRITEABLE); 1102 } 1103 return (SNMP_ERR_NOERROR); 1104 1105 case SNMP_OP_ROLLBACK: 1106 switch (which) { 1107 case LEAF_snmpEngineID: 1108 snmpd_engine.engine_len = ctx->scratch->int1; 1109 memcpy(snmpd_engine.engine_id, ctx->scratch->ptr1, 1110 snmpd_engine.engine_len); 1111 free(ctx->scratch->ptr1); 1112 break; 1113 1114 case LEAF_snmpEngineMaxMessageSize: 1115 snmpd_engine.max_msg_size = ctx->scratch->int1; 1116 break; 1117 1118 default: 1119 abort(); 1120 } 1121 return (SNMP_ERR_NOERROR); 1122 1123 case SNMP_OP_COMMIT: 1124 if (which == LEAF_snmpEngineID) { 1125 if (set_snmpd_engine() < 0) { 1126 snmpd_engine.engine_len = ctx->scratch->int1; 1127 memcpy(snmpd_engine.engine_id, 1128 ctx->scratch->ptr1, ctx->scratch->int1); 1129 } 1130 free(ctx->scratch->ptr1); 1131 } 1132 return (SNMP_ERR_NOERROR); 1133 } 1134 1135 1136 switch (which) { 1137 case LEAF_snmpEngineID: 1138 return (string_get(value, snmpd_engine.engine_id, 1139 snmpd_engine.engine_len)); 1140 case LEAF_snmpEngineBoots: 1141 value->v.integer = snmpd_engine.engine_boots; 1142 break; 1143 case LEAF_snmpEngineTime: 1144 snmpd_engine.engine_time = (get_ticks() - start_tick) / 100ULL; 1145 value->v.integer = snmpd_engine.engine_time; 1146 break; 1147 case LEAF_snmpEngineMaxMessageSize: 1148 value->v.integer = snmpd_engine.max_msg_size; 1149 break; 1150 default: 1151 return (SNMP_ERR_NOSUCHNAME); 1152 } 1153 1154 return (SNMP_ERR_NOERROR); 1155} 1156 1157/* |
|
983 * Transport table 984 */ 985int 986op_transport_table(struct snmp_context *ctx __unused, struct snmp_value *value, 987 u_int sub, u_int iidx, enum snmp_op op) 988{ 989 asn_subid_t which = value->var.subs[sub - 1]; 990 struct transport *t; --- 66 unchanged lines hidden --- | 1158 * Transport table 1159 */ 1160int 1161op_transport_table(struct snmp_context *ctx __unused, struct snmp_value *value, 1162 u_int sub, u_int iidx, enum snmp_op op) 1163{ 1164 asn_subid_t which = value->var.subs[sub - 1]; 1165 struct transport *t; --- 66 unchanged lines hidden --- |