Skip to content

Commit

Permalink
Add: support for nasl snmp getnext (#1047)
Browse files Browse the repository at this point in the history
* Add prototypes and make the functions available

* Add comments and update docstrings

* Rework nasl_snmpv3_get().
Now is called nasl_snmpv3_get_action() and receives the new parameter "action"
to specify if it will be called the "get" or "getnext" action.
Add wrappers for this function which call nasl_snmpv3_get_action() with the requiered action.

* Modify nasl_snmpv1v2c_get () function signature. Now receives a new parameter "action".
Pass the new action parameter set with NASL_SNMP_GET in the existing nasl_snmpv*_get() wrapper functions
Add the new wrapper functions nasl_snmpv1_getnext() and nasl_snmpv2c_getnext()

* Add log domain

* Define snmp versions

* Add request struct for snmp v1 and v2c

* Add request struct for snmp v3

* Use snmpv3_request struct in nasl_snmpv3_get_action. Also uses the action var

* Use snmpv3_request struct in snmpv3_get().

* Use snmpv3_request struct in snmpv3_get() (cmd wrap-up).

* Add definition for action. Depends on the method, cmd wrapper or library

* Use snmpv1v2_request struct in nasl_snmpv1v2c_get(). Also uses the action var

* Use snmpv1v2_request struct in snmpv1v2c_get() (cmd wrap-up).

* Use snmpv1v2_request struct in snmpv1v2c_get() (libnet-snmp)

* Receive and use the action param in snmp_get()

* Add struct snmp_result

* Change array_from_smmp_result() to use the new struct snmp_result

* Add array_from_snmp_error()

* Use snmp_result struct where necessary

* Adjust format

* Define new type snmp_result_t for snmp_result*

* Use the new type for results, and allocate memory for results

This fixes a segmentation fault in the original PR, because result didn't have allocated memory.

* Define new type snmpv1v2_request_t for struct snmpv1v2_request*

* Use the new type and allocate memory for the request struct

* Define new type snmpv3_request_t for struct snmpv3_request*

* Use snmpv3_request_t and allocate memory for the request struct

* Adjust format again

* Make the oid optional for "snmp getnext" (lib version)
The first time the oid is requiered. The next time, the oid is optional for getnext

While snmpgetnext support mib descriptions instead of oids (like iso.3.6....), the older version
snmp v1 doesn't. Therfore the iso. is formated in the right place, so the oid can be saved once it is in the result.

* Get the oid also in the result for the snmp cmd wrapper
Now, also the oid is get with name.

* Parse the result (snmp cmd wrapper), and stores the oid and name in the result struct.
The oid can be used now for getnext. (See some commits above.)

* Adjust format one more time

* Free memory allocated for request

Co-authored-by: Juan Jose Nicola <juan.nicola@greenbone.net>
  • Loading branch information
Kraemii and jjnicola committed Mar 28, 2022
1 parent 40c0a27 commit 0bbf047
Show file tree
Hide file tree
Showing 3 changed files with 363 additions and 155 deletions.
3 changes: 3 additions & 0 deletions nasl/nasl_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,11 @@ static init_func libfuncs[] = {
{"gzip", nasl_gzip},
{"DES", nasl_cipher_des},
{"snmpv1_get", nasl_snmpv1_get},
{"snmpv1_getnext", nasl_snmpv1_getnext},
{"snmpv2c_get", nasl_snmpv2c_get},
{"snmpv2c_getnext", nasl_snmpv2c_getnext},
{"snmpv3_get", nasl_snmpv3_get},
{"snmpv3_getnext", nasl_snmpv3_getnext},
{"ssh_connect", nasl_ssh_connect},
{"ssh_disconnect", nasl_ssh_disconnect},
{"ssh_session_id_from_sock", nasl_ssh_session_id_from_sock},
Expand Down

0 comments on commit 0bbf047

Please sign in to comment.