snmpagent.c (150921) | snmpagent.c (216294) |
---|---|
1/* 2 * Copyright (c) 2001-2003 3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4 * All rights reserved. 5 * 6 * Author: Harti Brandt <harti@freebsd.org> 7 * 8 * Redistribution and use in source and binary forms, with or without --- 151 unchanged lines hidden (view full) --- 160 161 for (tp = tree; tp < tree + tree_size; tp++) { 162 if (asn_is_suboid(&value->var, &tp->oid)) 163 return (tp); 164 } 165 return (NULL); 166} 167 | 1/* 2 * Copyright (c) 2001-2003 3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4 * All rights reserved. 5 * 6 * Author: Harti Brandt <harti@freebsd.org> 7 * 8 * Redistribution and use in source and binary forms, with or without --- 151 unchanged lines hidden (view full) --- 160 161 for (tp = tree; tp < tree + tree_size; tp++) { 162 if (asn_is_suboid(&value->var, &tp->oid)) 163 return (tp); 164 } 165 return (NULL); 166} 167 |
168static void 169snmp_pdu_create_response(struct snmp_pdu *pdu, struct snmp_pdu *resp) 170{ 171 memset(resp, 0, sizeof(*resp)); 172 strcpy(resp->community, pdu->community); 173 resp->version = pdu->version; 174 resp->type = SNMP_PDU_RESPONSE; 175 resp->request_id = pdu->request_id; 176 resp->version = pdu->version; 177 178 if (resp->version != SNMP_V3) 179 return; 180 181 snmp_pdu_init_secparams(resp, &pdu->engine, &pdu->user); 182 resp->identifier = pdu->identifier; 183 resp->security_model = pdu->security_model; 184 resp->context_engine_len = pdu->context_engine_len; 185 memcpy(resp->context_engine, pdu->context_engine, 186 resp->context_engine_len); 187 strlcpy(resp->context_name, pdu->context_name, 188 sizeof(resp->context_name)); 189} 190 |
|
168/* 169 * Execute a GET operation. The tree is rooted at the global 'root'. 170 * Build the response PDU on the fly. If the return code is SNMP_RET_ERR 171 * the pdu error status and index will be set. 172 */ 173enum snmp_ret 174snmp_get(struct snmp_pdu *pdu, struct asn_buf *resp_b, 175 struct snmp_pdu *resp, void *data) 176{ 177 int ret; 178 u_int i; 179 struct snmp_node *tp; 180 enum snmp_syntax except; 181 struct context context; 182 enum asn_err err; 183 184 memset(&context, 0, sizeof(context)); 185 context.ctx.data = data; 186 | 191/* 192 * Execute a GET operation. The tree is rooted at the global 'root'. 193 * Build the response PDU on the fly. If the return code is SNMP_RET_ERR 194 * the pdu error status and index will be set. 195 */ 196enum snmp_ret 197snmp_get(struct snmp_pdu *pdu, struct asn_buf *resp_b, 198 struct snmp_pdu *resp, void *data) 199{ 200 int ret; 201 u_int i; 202 struct snmp_node *tp; 203 enum snmp_syntax except; 204 struct context context; 205 enum asn_err err; 206 207 memset(&context, 0, sizeof(context)); 208 context.ctx.data = data; 209 |
187 memset(resp, 0, sizeof(*resp)); 188 strcpy(resp->community, pdu->community); 189 resp->version = pdu->version; 190 resp->type = SNMP_PDU_RESPONSE; 191 resp->request_id = pdu->request_id; 192 resp->version = pdu->version; | 210 snmp_pdu_create_response(pdu, resp); |
193 194 if (snmp_pdu_encode_header(resp_b, resp) != SNMP_CODE_OK) 195 /* cannot even encode header - very bad */ 196 return (SNMP_RET_IGN); 197 198 for (i = 0; i < pdu->nbindings; i++) { 199 resp->bindings[i].var = pdu->bindings[i].var; 200 if ((tp = find_node(&pdu->bindings[i], &except)) == NULL) { --- 178 unchanged lines hidden (view full) --- 379 struct context context; 380 u_int i; 381 enum asn_err err; 382 enum snmp_ret result; 383 384 memset(&context, 0, sizeof(context)); 385 context.ctx.data = data; 386 | 211 212 if (snmp_pdu_encode_header(resp_b, resp) != SNMP_CODE_OK) 213 /* cannot even encode header - very bad */ 214 return (SNMP_RET_IGN); 215 216 for (i = 0; i < pdu->nbindings; i++) { 217 resp->bindings[i].var = pdu->bindings[i].var; 218 if ((tp = find_node(&pdu->bindings[i], &except)) == NULL) { --- 178 unchanged lines hidden (view full) --- 397 struct context context; 398 u_int i; 399 enum asn_err err; 400 enum snmp_ret result; 401 402 memset(&context, 0, sizeof(context)); 403 context.ctx.data = data; 404 |
387 memset(resp, 0, sizeof(*resp)); 388 strcpy(resp->community, pdu->community); 389 resp->type = SNMP_PDU_RESPONSE; 390 resp->request_id = pdu->request_id; 391 resp->version = pdu->version; | 405 snmp_pdu_create_response(pdu, resp); |
392 393 if (snmp_pdu_encode_header(resp_b, resp)) 394 return (SNMP_RET_IGN); 395 396 for (i = 0; i < pdu->nbindings; i++) { 397 result = do_getnext(&context, &pdu->bindings[i], 398 &resp->bindings[i], pdu); 399 --- 35 unchanged lines hidden (view full) --- 435 u_int non_rep; 436 int eomib; 437 enum snmp_ret result; 438 enum asn_err err; 439 440 memset(&context, 0, sizeof(context)); 441 context.ctx.data = data; 442 | 406 407 if (snmp_pdu_encode_header(resp_b, resp)) 408 return (SNMP_RET_IGN); 409 410 for (i = 0; i < pdu->nbindings; i++) { 411 result = do_getnext(&context, &pdu->bindings[i], 412 &resp->bindings[i], pdu); 413 --- 35 unchanged lines hidden (view full) --- 449 u_int non_rep; 450 int eomib; 451 enum snmp_ret result; 452 enum asn_err err; 453 454 memset(&context, 0, sizeof(context)); 455 context.ctx.data = data; 456 |
443 memset(resp, 0, sizeof(*resp)); 444 strcpy(resp->community, pdu->community); 445 resp->version = pdu->version; 446 resp->type = SNMP_PDU_RESPONSE; 447 resp->request_id = pdu->request_id; 448 resp->version = pdu->version; | 457 snmp_pdu_create_response(pdu, resp); |
449 450 if (snmp_pdu_encode_header(resp_b, resp) != SNMP_CODE_OK) 451 /* cannot even encode header - very bad */ 452 return (SNMP_RET_IGN); 453 454 if ((non_rep = pdu->error_status) > pdu->nbindings) 455 non_rep = pdu->nbindings; 456 --- 190 unchanged lines hidden (view full) --- 647 const struct snmp_node *np; 648 struct snmp_value *b; 649 enum snmp_syntax except; 650 651 memset(&context, 0, sizeof(context)); 652 TAILQ_INIT(&context.dlist); 653 context.ctx.data = data; 654 | 458 459 if (snmp_pdu_encode_header(resp_b, resp) != SNMP_CODE_OK) 460 /* cannot even encode header - very bad */ 461 return (SNMP_RET_IGN); 462 463 if ((non_rep = pdu->error_status) > pdu->nbindings) 464 non_rep = pdu->nbindings; 465 --- 190 unchanged lines hidden (view full) --- 656 const struct snmp_node *np; 657 struct snmp_value *b; 658 enum snmp_syntax except; 659 660 memset(&context, 0, sizeof(context)); 661 TAILQ_INIT(&context.dlist); 662 context.ctx.data = data; 663 |
655 memset(resp, 0, sizeof(*resp)); 656 strcpy(resp->community, pdu->community); 657 resp->type = SNMP_PDU_RESPONSE; 658 resp->request_id = pdu->request_id; 659 resp->version = pdu->version; | 664 snmp_pdu_create_response(pdu, resp); |
660 661 if (snmp_pdu_encode_header(resp_b, resp)) 662 return (SNMP_RET_IGN); 663 664 /* 665 * 1. Find all nodes, check that they are writeable and 666 * that the syntax is ok, copy over the binding to the response. 667 */ --- 278 unchanged lines hidden (view full) --- 946 struct asn_buf *resp_b) 947{ 948 asn_len_t len; 949 struct snmp_pdu resp; 950 enum asn_err err; 951 enum snmp_code code; 952 953 memset(&resp, 0, sizeof(resp)); | 665 666 if (snmp_pdu_encode_header(resp_b, resp)) 667 return (SNMP_RET_IGN); 668 669 /* 670 * 1. Find all nodes, check that they are writeable and 671 * that the syntax is ok, copy over the binding to the response. 672 */ --- 278 unchanged lines hidden (view full) --- 951 struct asn_buf *resp_b) 952{ 953 asn_len_t len; 954 struct snmp_pdu resp; 955 enum asn_err err; 956 enum snmp_code code; 957 958 memset(&resp, 0, sizeof(resp)); |
954 955 /* Message sequence */ 956 if (asn_get_sequence(pdu_b, &len) != ASN_ERR_OK) | 959 if ((code = snmp_pdu_decode_header(pdu_b, &resp)) != SNMP_CODE_OK) |
957 return (SNMP_RET_IGN); | 960 return (SNMP_RET_IGN); |
958 if (pdu_b->asn_len < len) 959 return (SNMP_RET_IGN); | |
960 | 961 |
961 err = snmp_parse_message_hdr(pdu_b, &resp, &len); 962 if (ASN_ERR_STOPPED(err)) 963 return (SNMP_RET_IGN); | |
964 if (pdu_b->asn_len < len) 965 return (SNMP_RET_IGN); 966 pdu_b->asn_len = len; 967 968 err = snmp_parse_pdus_hdr(pdu_b, &resp, &len); 969 if (ASN_ERR_STOPPED(err)) 970 return (SNMP_RET_IGN); 971 if (pdu_b->asn_len < len) --- 36 unchanged lines hidden --- | 962 if (pdu_b->asn_len < len) 963 return (SNMP_RET_IGN); 964 pdu_b->asn_len = len; 965 966 err = snmp_parse_pdus_hdr(pdu_b, &resp, &len); 967 if (ASN_ERR_STOPPED(err)) 968 return (SNMP_RET_IGN); 969 if (pdu_b->asn_len < len) --- 36 unchanged lines hidden --- |