From aff69127b61f6fcceacc4384b0bb85ee03d743b3 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Sun, 9 Oct 2022 11:59:26 +0200 Subject: [PATCH] Fixed: [Trying to change the "config false" node through snmpset](https://github.com/clicon/clixon/issues/377) * Fixed by returning `SNMP_ERR_NOTWRITABLE` when trying to reserve object --- CHANGELOG.md | 2 ++ apps/snmp/snmp_handler.c | 8 ++++++++ test/test_snmp_get.sh | 3 +++ 3 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index affb827d..03547b42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,6 +78,8 @@ Developers may need to change their code ### Corrected Bugs +* Fixed: [Trying to change the "config false" node through snmpset](https://github.com/clicon/clixon/issues/377) + * Fixed by returning `SNMP_ERR_NOTWRITABLE` when trying to reserve object * Fixed: [Non-obvious behavior of clixon_snmp after snmpset command when transaction validation returns an error](https://github.com/clicon/clixon/issues/375) * Fixed: [clixon_snmp module crashes on snmpwalk command](https://github.com/clicon/clixon/issues/378) * Fixed: [unneeded trailing zero character on SNMP strings](https://github.com/clicon/clixon/issues/367) diff --git a/apps/snmp/snmp_handler.c b/apps/snmp/snmp_handler.c index 6c509c8c..ddc86914 100644 --- a/apps/snmp/snmp_handler.c +++ b/apps/snmp/snmp_handler.c @@ -731,6 +731,10 @@ clixon_snmp_scalar_handler1(netsnmp_mib_handler *handler, case MODE_GETNEXT: /* 161 */ break; case MODE_SET_RESERVE1: /* 0 */ + if (!yang_config_ancestor(sh->sh_ys)){ + retval = SNMP_ERR_NOTWRITABLE; + goto done;; + } /* Translate from YANG ys leaf type to SNMP asn1.1 type ids (not value), also cvtype */ if (type_yang2asn1(sh->sh_ys, &asn1_type, 0) < 0) goto done; @@ -1289,6 +1293,10 @@ clixon_snmp_table_handler1(netsnmp_mib_handler *handler, } break; case MODE_SET_RESERVE1: // 0 + if (!yang_config_ancestor(sh->sh_ys)){ + retval = SNMP_ERR_NOTWRITABLE; + goto done;; + } // Check types: compare type in requestvb to yang type (or do later) break; case MODE_SET_RESERVE2: // 1 diff --git a/test/test_snmp_get.sh b/test/test_snmp_get.sh index e8d10703..e7fc9d2d 100755 --- a/test/test_snmp_get.sh +++ b/test/test_snmp_get.sh @@ -290,6 +290,9 @@ expectpart "$($snmpget $OID19)" 0 "$OID19 = Hex-STRING: 74 65 73 74 00" new "Test SNMP getnext netSnmpHostName" expectpart "$($snmpgetnext $OID19)" 0 "$OID20 = INTEGER: 1" +new "Negative test: Try to set object" +expectpart "$($snmpset $OID1 i 4 2> /dev/null)" 2 "^$" + new "Cleaning up" testexit