/src/net-snmp/agent/helpers/read_only.c
Line | Count | Source |
1 | | /* |
2 | | * Portions of this file are subject to the following copyright(s). See |
3 | | * the Net-SNMP's COPYING file for more details and other copyrights |
4 | | * that may apply: |
5 | | * |
6 | | * Portions of this file are copyrighted by: |
7 | | * Copyright (c) 2016 VMware, Inc. All rights reserved. |
8 | | * Use is subject to license terms specified in the COPYING file |
9 | | * distributed with the Net-SNMP package. |
10 | | */ |
11 | | |
12 | | #include <net-snmp/net-snmp-config.h> |
13 | | |
14 | | #include <net-snmp/net-snmp-includes.h> |
15 | | #include <net-snmp/agent/net-snmp-agent-includes.h> |
16 | | |
17 | | #include <net-snmp/agent/read_only.h> |
18 | | |
19 | | /** @defgroup read_only read_only |
20 | | * Make your handler read_only automatically |
21 | | * The only purpose of this handler is to return an |
22 | | * appropriate error for any requests passed to it in a SET mode. |
23 | | * Inserting it into your handler chain will ensure you're never |
24 | | * asked to perform a SET request so you can ignore those error |
25 | | * conditions. |
26 | | * @ingroup utilities |
27 | | * @{ |
28 | | */ |
29 | | |
30 | | /** returns a read_only handler that can be injected into a given |
31 | | * handler chain. |
32 | | */ |
33 | | netsnmp_mib_handler * |
34 | | netsnmp_get_read_only_handler(void) |
35 | 3.33k | { |
36 | 3.33k | netsnmp_mib_handler *ret = NULL; |
37 | | |
38 | 3.33k | ret = netsnmp_create_handler("read_only", |
39 | 3.33k | netsnmp_read_only_helper); |
40 | 3.33k | if (ret) { |
41 | 3.33k | ret->flags |= MIB_HANDLER_AUTO_NEXT; |
42 | 3.33k | } |
43 | 3.33k | return ret; |
44 | 3.33k | } |
45 | | |
46 | | /** @internal Implements the read_only handler */ |
47 | | int |
48 | | netsnmp_read_only_helper(netsnmp_mib_handler *handler, |
49 | | netsnmp_handler_registration *reginfo, |
50 | | netsnmp_agent_request_info *reqinfo, |
51 | | netsnmp_request_info *requests) |
52 | 0 | { |
53 | |
|
54 | 0 | DEBUGMSGTL(("helper:read_only", "Got request\n")); |
55 | |
|
56 | 0 | switch (reqinfo->mode) { |
57 | | |
58 | 0 | #ifndef NETSNMP_NO_WRITE_SUPPORT |
59 | 0 | case MODE_SET_RESERVE1: |
60 | 0 | case MODE_SET_RESERVE2: |
61 | 0 | case MODE_SET_ACTION: |
62 | 0 | case MODE_SET_COMMIT: |
63 | 0 | case MODE_SET_FREE: |
64 | 0 | case MODE_SET_UNDO: |
65 | 0 | netsnmp_request_set_error_all(requests, SNMP_ERR_NOTWRITABLE); |
66 | 0 | return SNMP_ERR_NOTWRITABLE; |
67 | 0 | #endif /* NETSNMP_NO_WRITE_SUPPORT */ |
68 | | |
69 | 0 | case MODE_GET: |
70 | 0 | case MODE_GETNEXT: |
71 | 0 | case MODE_GETBULK: |
72 | | /* next handler called automatically - 'AUTO_NEXT' */ |
73 | 0 | return SNMP_ERR_NOERROR; |
74 | 0 | } |
75 | | |
76 | 0 | netsnmp_request_set_error_all(requests, SNMP_ERR_GENERR); |
77 | 0 | return SNMP_ERR_GENERR; |
78 | 0 | } |
79 | | |
80 | | /** initializes the read_only helper which then registers a read_only |
81 | | * handler as a run-time injectable handler for configuration file |
82 | | * use. |
83 | | */ |
84 | | void |
85 | | netsnmp_init_read_only_helper(void) |
86 | 3.33k | { |
87 | 3.33k | netsnmp_mib_handler *handler = netsnmp_get_read_only_handler(); |
88 | 3.33k | if (!handler) { |
89 | 0 | snmp_log(LOG_ERR, "could not create read_only handler\n"); |
90 | 0 | return; |
91 | 0 | } |
92 | 3.33k | netsnmp_register_handler_by_name("read_only", handler); |
93 | 3.33k | } |
94 | | /** @} */ |
95 | | |