1d76947f3SHartmut Brandt /*-
2d76947f3SHartmut Brandt * Copyright (c) 2005-2006 The FreeBSD Project
3d76947f3SHartmut Brandt * All rights reserved.
4d76947f3SHartmut Brandt *
5d76947f3SHartmut Brandt * Author: Victor Cruceru <soc-victor@freebsd.org>
6d76947f3SHartmut Brandt *
7d76947f3SHartmut Brandt * Redistribution of this software and documentation and use in source and
8d76947f3SHartmut Brandt * binary forms, with or without modification, are permitted provided that
9d76947f3SHartmut Brandt * the following conditions are met:
10d76947f3SHartmut Brandt *
11d76947f3SHartmut Brandt * 1. Redistributions of source code or documentation must retain the above
12d76947f3SHartmut Brandt * copyright notice, this list of conditions and the following disclaimer.
13d76947f3SHartmut Brandt * 2. Redistributions in binary form must reproduce the above copyright
14d76947f3SHartmut Brandt * notice, this list of conditions and the following disclaimer in the
15d76947f3SHartmut Brandt * documentation and/or other materials provided with the distribution.
16d76947f3SHartmut Brandt *
17d76947f3SHartmut Brandt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18d76947f3SHartmut Brandt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19d76947f3SHartmut Brandt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20d76947f3SHartmut Brandt * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21d76947f3SHartmut Brandt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22d76947f3SHartmut Brandt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23d76947f3SHartmut Brandt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24d76947f3SHartmut Brandt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25d76947f3SHartmut Brandt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26d76947f3SHartmut Brandt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27d76947f3SHartmut Brandt * SUCH DAMAGE.
28d76947f3SHartmut Brandt */
29d76947f3SHartmut Brandt
30d76947f3SHartmut Brandt /*
31d76947f3SHartmut Brandt * Host Resources MIB scalars implementation for SNMPd.
32d76947f3SHartmut Brandt */
33d76947f3SHartmut Brandt
3418d124d9SEnji Cooper #include <sys/param.h>
35d76947f3SHartmut Brandt #include <sys/sysctl.h>
36d76947f3SHartmut Brandt
37d76947f3SHartmut Brandt #include <pwd.h>
38d76947f3SHartmut Brandt #include <stdlib.h>
39d76947f3SHartmut Brandt #include <stdint.h>
40d76947f3SHartmut Brandt #include <string.h>
41d76947f3SHartmut Brandt #include <syslog.h>
42b5810e94SEd Schouten #include <utmpx.h>
43d76947f3SHartmut Brandt
44d76947f3SHartmut Brandt #include "hostres_snmp.h"
45d76947f3SHartmut Brandt #include "hostres_oid.h"
46d76947f3SHartmut Brandt #include "hostres_tree.h"
47d76947f3SHartmut Brandt
48d76947f3SHartmut Brandt /* physical memory size in Kb */
49d76947f3SHartmut Brandt static uint64_t phys_mem_size;
50d76947f3SHartmut Brandt
51d76947f3SHartmut Brandt /* boot line (malloced) */
52d76947f3SHartmut Brandt static u_char *boot_line;
53d76947f3SHartmut Brandt
54d76947f3SHartmut Brandt /* maximum number of processes */
55d76947f3SHartmut Brandt static uint32_t max_proc;
56d76947f3SHartmut Brandt
57d76947f3SHartmut Brandt /**
58d76947f3SHartmut Brandt * Free all static data
59d76947f3SHartmut Brandt */
60d76947f3SHartmut Brandt void
fini_scalars(void)61d76947f3SHartmut Brandt fini_scalars(void)
62d76947f3SHartmut Brandt {
63d76947f3SHartmut Brandt
64d76947f3SHartmut Brandt free(boot_line);
65d76947f3SHartmut Brandt }
66d76947f3SHartmut Brandt
67d76947f3SHartmut Brandt /**
68d76947f3SHartmut Brandt * Get system uptime in hundredths of seconds since the epoch
69d76947f3SHartmut Brandt * Returns 0 in case of an error
70d76947f3SHartmut Brandt */
71d76947f3SHartmut Brandt static int
OS_getSystemUptime(uint32_t * ut)72d76947f3SHartmut Brandt OS_getSystemUptime(uint32_t *ut)
73d76947f3SHartmut Brandt {
74f009aedaSWarner Losh uint64_t uptime;
75f009aedaSWarner Losh struct timespec ts;
76d76947f3SHartmut Brandt
77f009aedaSWarner Losh if (clock_gettime(CLOCK_UPTIME, &ts)) {
78f009aedaSWarner Losh syslog(LOG_ERR, "clock_gettime failed: %m");
79d76947f3SHartmut Brandt return (SNMP_ERR_GENERR);
80d76947f3SHartmut Brandt }
81d76947f3SHartmut Brandt
82f009aedaSWarner Losh uptime = ts.tv_sec * 100 + ts.tv_nsec / 1000000;
83f009aedaSWarner Losh if (uptime > UINT32_MAX)
84d76947f3SHartmut Brandt *ut = UINT32_MAX;
85d76947f3SHartmut Brandt else
86f009aedaSWarner Losh *ut = (uint32_t)uptime;
87d76947f3SHartmut Brandt
88d76947f3SHartmut Brandt return (SNMP_ERR_NOERROR);
89d76947f3SHartmut Brandt }
90d76947f3SHartmut Brandt
91d76947f3SHartmut Brandt /**
92d76947f3SHartmut Brandt * Get system local date and time in a foramt suitable for DateAndTime TC:
93d76947f3SHartmut Brandt * field octets contents range
94d76947f3SHartmut Brandt * ----- ------ -------- -----
95d76947f3SHartmut Brandt * 1 1-2 year* 0..65536
96d76947f3SHartmut Brandt * 2 3 month 1..12
97d76947f3SHartmut Brandt * 3 4 day 1..31
98d76947f3SHartmut Brandt * 4 5 hour 0..23
99d76947f3SHartmut Brandt * 5 6 minutes 0..59
100d76947f3SHartmut Brandt * 6 7 seconds 0..60
101d76947f3SHartmut Brandt * (use 60 for leap-second)
102d76947f3SHartmut Brandt * 7 8 deci-seconds 0..9
103d76947f3SHartmut Brandt * 8 9 direction from UTC '+' / '-'
104d76947f3SHartmut Brandt * 9 10 hours from UTC* 0..13
105d76947f3SHartmut Brandt * 10 11 minutes from UTC 0..59
106d76947f3SHartmut Brandt *
107d76947f3SHartmut Brandt * * Notes:
108d76947f3SHartmut Brandt * - the value of year is in network-byte order
109d76947f3SHartmut Brandt * - daylight saving time in New Zealand is +13
110d76947f3SHartmut Brandt *
111d76947f3SHartmut Brandt * For example, Tuesday May 26, 1992 at 1:30:15 PM EDT would be
112d76947f3SHartmut Brandt * displayed as:
113d76947f3SHartmut Brandt *
114d76947f3SHartmut Brandt * 1992-5-26,13:30:15.0,-4:0
115d76947f3SHartmut Brandt *
116d76947f3SHartmut Brandt * Returns -1 in case of an error or the length of the string (8 or 11)
117d76947f3SHartmut Brandt * Actually returns always 11 on freebsd
118d76947f3SHartmut Brandt */
119d76947f3SHartmut Brandt static int
OS_getSystemDate(struct snmp_value * value)120d76947f3SHartmut Brandt OS_getSystemDate(struct snmp_value *value)
121d76947f3SHartmut Brandt {
122d76947f3SHartmut Brandt u_char s_date_time[11];
123d76947f3SHartmut Brandt struct tm tloc_tm;
124d76947f3SHartmut Brandt time_t tloc_time_t;
125d76947f3SHartmut Brandt struct timeval right_now;
126d76947f3SHartmut Brandt int string_len;
127d76947f3SHartmut Brandt
128d76947f3SHartmut Brandt if (gettimeofday(&right_now, NULL) < 0) {
129d76947f3SHartmut Brandt syslog(LOG_ERR, "gettimeofday failed: %m");
130d76947f3SHartmut Brandt return (SNMP_ERR_GENERR);
131d76947f3SHartmut Brandt }
132d76947f3SHartmut Brandt
133d76947f3SHartmut Brandt tloc_time_t = right_now.tv_sec;
134d76947f3SHartmut Brandt
135d76947f3SHartmut Brandt if (localtime_r(&tloc_time_t, &tloc_tm) == NULL) {
136d76947f3SHartmut Brandt syslog(LOG_ERR, "localtime_r() failed: %m ");
137d76947f3SHartmut Brandt return (SNMP_ERR_GENERR);
138d76947f3SHartmut Brandt }
139d76947f3SHartmut Brandt
140d76947f3SHartmut Brandt string_len = make_date_time(s_date_time, &tloc_tm,
141d76947f3SHartmut Brandt right_now.tv_usec / 100000);
142d76947f3SHartmut Brandt
143d76947f3SHartmut Brandt return (string_get(value, s_date_time, string_len));
144d76947f3SHartmut Brandt }
145d76947f3SHartmut Brandt
146d76947f3SHartmut Brandt /**
147d76947f3SHartmut Brandt * Get kernel boot path. For FreeBSD it seems that no arguments are
1483df5ecacSUlrich Spörlein * present. Returns NULL if an error occurred. The returned data is a
1493df5ecacSUlrich Spörlein * pointer to a global storage.
150d76947f3SHartmut Brandt */
151d76947f3SHartmut Brandt int
OS_getSystemInitialLoadParameters(u_char ** params)152d76947f3SHartmut Brandt OS_getSystemInitialLoadParameters(u_char **params)
153d76947f3SHartmut Brandt {
154d76947f3SHartmut Brandt
155d76947f3SHartmut Brandt if (boot_line == NULL) {
156d76947f3SHartmut Brandt int mib[2] = { CTL_KERN, KERN_BOOTFILE };
157d76947f3SHartmut Brandt char *buf;
158d76947f3SHartmut Brandt size_t buf_len = 0;
159d76947f3SHartmut Brandt
160d76947f3SHartmut Brandt /* get the needed buffer len */
161d76947f3SHartmut Brandt if (sysctl(mib, 2, NULL, &buf_len, NULL, 0) != 0) {
162d76947f3SHartmut Brandt syslog(LOG_ERR,
163d76947f3SHartmut Brandt "sysctl({CTL_KERN,KERN_BOOTFILE}) failed: %m");
164d76947f3SHartmut Brandt return (SNMP_ERR_GENERR);
165d76947f3SHartmut Brandt }
166d76947f3SHartmut Brandt
167d76947f3SHartmut Brandt if ((buf = malloc(buf_len)) == NULL) {
168d76947f3SHartmut Brandt syslog(LOG_ERR, "malloc failed");
169d76947f3SHartmut Brandt return (SNMP_ERR_GENERR);
170d76947f3SHartmut Brandt }
171d76947f3SHartmut Brandt if (sysctl(mib, 2, buf, &buf_len, NULL, 0)) {
172d76947f3SHartmut Brandt syslog(LOG_ERR,
173d76947f3SHartmut Brandt "sysctl({CTL_KERN,KERN_BOOTFILE}) failed: %m");
174d76947f3SHartmut Brandt free(buf);
175d76947f3SHartmut Brandt return (SNMP_ERR_GENERR);
176d76947f3SHartmut Brandt }
177d76947f3SHartmut Brandt
178d76947f3SHartmut Brandt boot_line = buf;
179d76947f3SHartmut Brandt HRDBG("kernel boot file: %s", boot_line);
180d76947f3SHartmut Brandt }
181d76947f3SHartmut Brandt
182d76947f3SHartmut Brandt *params = boot_line;
183d76947f3SHartmut Brandt return (SNMP_ERR_NOERROR);
184d76947f3SHartmut Brandt }
185d76947f3SHartmut Brandt
186d76947f3SHartmut Brandt /**
187d76947f3SHartmut Brandt * Get number of current users which are logged in
188d76947f3SHartmut Brandt */
189d76947f3SHartmut Brandt static int
OS_getSystemNumUsers(uint32_t * nu)190d76947f3SHartmut Brandt OS_getSystemNumUsers(uint32_t *nu)
191d76947f3SHartmut Brandt {
19271713ba2SEd Schouten struct utmpx *utmp;
193d76947f3SHartmut Brandt
19471713ba2SEd Schouten setutxent();
195d76947f3SHartmut Brandt *nu = 0;
19671713ba2SEd Schouten while ((utmp = getutxent()) != NULL) {
19771713ba2SEd Schouten if (utmp->ut_type == USER_PROCESS)
198d76947f3SHartmut Brandt (*nu)++;
199d76947f3SHartmut Brandt }
20071713ba2SEd Schouten endutxent();
201d76947f3SHartmut Brandt
202d76947f3SHartmut Brandt return (SNMP_ERR_NOERROR);
203d76947f3SHartmut Brandt }
204d76947f3SHartmut Brandt
205d76947f3SHartmut Brandt /**
206d76947f3SHartmut Brandt * Get number of current processes existing into the system
207d76947f3SHartmut Brandt */
208d76947f3SHartmut Brandt static int
OS_getSystemProcesses(uint32_t * proc_count)209d76947f3SHartmut Brandt OS_getSystemProcesses(uint32_t *proc_count)
210d76947f3SHartmut Brandt {
211d76947f3SHartmut Brandt int pc;
212d76947f3SHartmut Brandt
213d76947f3SHartmut Brandt if (hr_kd == NULL)
214d76947f3SHartmut Brandt return (SNMP_ERR_GENERR);
215d76947f3SHartmut Brandt
2166a9e7628SGleb Smirnoff if (kvm_getprocs(hr_kd, KERN_PROC_PROC, 0, &pc) == NULL) {
217d76947f3SHartmut Brandt syslog(LOG_ERR, "kvm_getprocs failed: %m");
218d76947f3SHartmut Brandt return (SNMP_ERR_GENERR);
219d76947f3SHartmut Brandt }
220d76947f3SHartmut Brandt
221d76947f3SHartmut Brandt *proc_count = pc;
222d76947f3SHartmut Brandt return (SNMP_ERR_NOERROR);
223d76947f3SHartmut Brandt }
224d76947f3SHartmut Brandt
225d76947f3SHartmut Brandt /**
226d76947f3SHartmut Brandt * Get maximum number of processes allowed on this system
227d76947f3SHartmut Brandt */
228d76947f3SHartmut Brandt static int
OS_getSystemMaxProcesses(uint32_t * mproc)229d76947f3SHartmut Brandt OS_getSystemMaxProcesses(uint32_t *mproc)
230d76947f3SHartmut Brandt {
231d76947f3SHartmut Brandt
232d76947f3SHartmut Brandt if (max_proc == 0) {
233d76947f3SHartmut Brandt int mib[2] = { CTL_KERN, KERN_MAXPROC };
234d76947f3SHartmut Brandt int mp;
235d76947f3SHartmut Brandt size_t len = sizeof(mp);
236d76947f3SHartmut Brandt
237d76947f3SHartmut Brandt if (sysctl(mib, 2, &mp, &len, NULL, 0) == -1) {
238d76947f3SHartmut Brandt syslog(LOG_ERR, "sysctl KERN_MAXPROC failed: %m");
239d76947f3SHartmut Brandt return (SNMP_ERR_GENERR);
240d76947f3SHartmut Brandt }
241d76947f3SHartmut Brandt max_proc = mp;
242d76947f3SHartmut Brandt }
243d76947f3SHartmut Brandt
244d76947f3SHartmut Brandt *mproc = max_proc;
245d76947f3SHartmut Brandt return (SNMP_ERR_NOERROR);
246d76947f3SHartmut Brandt }
247d76947f3SHartmut Brandt
248d76947f3SHartmut Brandt /*
249*de8b4900SElyes Haouas * Get the physical memory size in Kbytes.
250d76947f3SHartmut Brandt * Returns SNMP error code.
251d76947f3SHartmut Brandt */
252d76947f3SHartmut Brandt static int
OS_getMemorySize(uint32_t * ms)253d76947f3SHartmut Brandt OS_getMemorySize(uint32_t *ms)
254d76947f3SHartmut Brandt {
255d76947f3SHartmut Brandt
256d76947f3SHartmut Brandt if (phys_mem_size == 0) {
257d76947f3SHartmut Brandt int mib[2] = { CTL_HW, HW_PHYSMEM };
258d76947f3SHartmut Brandt u_long physmem;
259d76947f3SHartmut Brandt size_t len = sizeof(physmem);
260d76947f3SHartmut Brandt
261d76947f3SHartmut Brandt if (sysctl(mib, 2, &physmem, &len, NULL, 0) == -1) {
262d76947f3SHartmut Brandt syslog(LOG_ERR,
263d76947f3SHartmut Brandt "sysctl({ CTL_HW, HW_PHYSMEM }) failed: %m");
264d76947f3SHartmut Brandt return (SNMP_ERR_GENERR);
265d76947f3SHartmut Brandt }
266d76947f3SHartmut Brandt
267d76947f3SHartmut Brandt phys_mem_size = physmem / 1024;
268d76947f3SHartmut Brandt }
269d76947f3SHartmut Brandt
270d76947f3SHartmut Brandt if (phys_mem_size > UINT32_MAX)
271d76947f3SHartmut Brandt *ms = UINT32_MAX;
272d76947f3SHartmut Brandt else
273d76947f3SHartmut Brandt *ms = phys_mem_size;
274d76947f3SHartmut Brandt return (SNMP_ERR_NOERROR);
275d76947f3SHartmut Brandt }
276d76947f3SHartmut Brandt
277d76947f3SHartmut Brandt /*
278d76947f3SHartmut Brandt * Try to use the s_date_time parameter as a DateAndTime TC to fill in
279d76947f3SHartmut Brandt * the second parameter.
280d76947f3SHartmut Brandt * Returns 0 on succes and -1 for an error.
281d76947f3SHartmut Brandt * Bug: time zone info is not used
282d76947f3SHartmut Brandt */
283d76947f3SHartmut Brandt static struct timeval *
OS_checkSystemDateInput(const u_char * str,u_int len)284d76947f3SHartmut Brandt OS_checkSystemDateInput(const u_char *str, u_int len)
285d76947f3SHartmut Brandt {
286d76947f3SHartmut Brandt struct tm tm_to_set;
287d76947f3SHartmut Brandt time_t t;
288d76947f3SHartmut Brandt struct timeval *tv;
289d76947f3SHartmut Brandt
290d76947f3SHartmut Brandt if (len != 8 && len != 11)
291d76947f3SHartmut Brandt return (NULL);
292d76947f3SHartmut Brandt
293d76947f3SHartmut Brandt if (str[2] == 0 || str[2] > 12 ||
294d76947f3SHartmut Brandt str[3] == 0 || str[3] > 31 ||
295d76947f3SHartmut Brandt str[4] > 23 || str[5] > 59 || str[6] > 60 || str[7] > 9)
296d76947f3SHartmut Brandt return (NULL);
297d76947f3SHartmut Brandt
298d76947f3SHartmut Brandt tm_to_set.tm_year = ((str[0] << 8) + str[1]) - 1900;
299d76947f3SHartmut Brandt tm_to_set.tm_mon = str[2] - 1;
300d76947f3SHartmut Brandt tm_to_set.tm_mday = str[3];
301d76947f3SHartmut Brandt tm_to_set.tm_hour = str[4];
302d76947f3SHartmut Brandt tm_to_set.tm_min = str[5];
303d76947f3SHartmut Brandt tm_to_set.tm_sec = str[6];
304d76947f3SHartmut Brandt tm_to_set.tm_isdst = 0;
305d76947f3SHartmut Brandt
306d76947f3SHartmut Brandt /* now make UTC from it */
307d76947f3SHartmut Brandt if ((t = timegm(&tm_to_set)) == (time_t)-1)
308d76947f3SHartmut Brandt return (NULL);
309d76947f3SHartmut Brandt
310d76947f3SHartmut Brandt /* now apply timezone if specified */
311d76947f3SHartmut Brandt if (len == 11) {
312d76947f3SHartmut Brandt if (str[9] > 13 || str[10] > 59)
313d76947f3SHartmut Brandt return (NULL);
314d76947f3SHartmut Brandt if (str[8] == '+')
315d76947f3SHartmut Brandt t += 3600 * str[9] + 60 * str[10];
316d76947f3SHartmut Brandt else
317d76947f3SHartmut Brandt t -= 3600 * str[9] + 60 * str[10];
318d76947f3SHartmut Brandt }
319d76947f3SHartmut Brandt
320d76947f3SHartmut Brandt if ((tv = malloc(sizeof(*tv))) == NULL)
321d76947f3SHartmut Brandt return (NULL);
322d76947f3SHartmut Brandt
323d76947f3SHartmut Brandt tv->tv_sec = t;
324d76947f3SHartmut Brandt tv->tv_usec = (int32_t)str[7] * 100000;
325d76947f3SHartmut Brandt
326d76947f3SHartmut Brandt return (tv);
327d76947f3SHartmut Brandt }
328d76947f3SHartmut Brandt
329d76947f3SHartmut Brandt /*
330d76947f3SHartmut Brandt * Set system date and time. Timezone is not changed
331d76947f3SHartmut Brandt */
332d76947f3SHartmut Brandt static int
OS_setSystemDate(const struct timeval * timeval_to_set)333d76947f3SHartmut Brandt OS_setSystemDate(const struct timeval *timeval_to_set)
334d76947f3SHartmut Brandt {
335d76947f3SHartmut Brandt if (settimeofday(timeval_to_set, NULL) == -1) {
336d76947f3SHartmut Brandt syslog(LOG_ERR, "settimeofday failed: %m");
337d76947f3SHartmut Brandt return (SNMP_ERR_GENERR);
338d76947f3SHartmut Brandt }
339d76947f3SHartmut Brandt return (SNMP_ERR_NOERROR);
340d76947f3SHartmut Brandt }
341d76947f3SHartmut Brandt
342d76947f3SHartmut Brandt /*
343*de8b4900SElyes Haouas * prototype of this function was generated by gensnmptree tool in header file
344d76947f3SHartmut Brandt * hostres_tree.h
345d76947f3SHartmut Brandt * Returns SNMP_ERR_NOERROR on success
346d76947f3SHartmut Brandt */
347d76947f3SHartmut Brandt int
op_hrSystem(struct snmp_context * ctx,struct snmp_value * value,u_int sub,u_int iidx __unused,enum snmp_op curr_op)348d76947f3SHartmut Brandt op_hrSystem(struct snmp_context *ctx, struct snmp_value *value,
349d76947f3SHartmut Brandt u_int sub, u_int iidx __unused, enum snmp_op curr_op)
350d76947f3SHartmut Brandt {
351d76947f3SHartmut Brandt int err;
352d76947f3SHartmut Brandt u_char *str;
353d76947f3SHartmut Brandt
354d76947f3SHartmut Brandt switch (curr_op) {
355d76947f3SHartmut Brandt
356d76947f3SHartmut Brandt case SNMP_OP_GET:
357d76947f3SHartmut Brandt switch (value->var.subs[sub - 1]) {
358d76947f3SHartmut Brandt
359d76947f3SHartmut Brandt case LEAF_hrSystemUptime:
360d76947f3SHartmut Brandt return (OS_getSystemUptime(&value->v.uint32));
361d76947f3SHartmut Brandt
362d76947f3SHartmut Brandt case LEAF_hrSystemDate:
363d76947f3SHartmut Brandt return (OS_getSystemDate(value));
364d76947f3SHartmut Brandt
365d76947f3SHartmut Brandt case LEAF_hrSystemInitialLoadDevice:
366d76947f3SHartmut Brandt value->v.uint32 = 0; /* FIXME */
367d76947f3SHartmut Brandt return (SNMP_ERR_NOERROR);
368d76947f3SHartmut Brandt
369d76947f3SHartmut Brandt case LEAF_hrSystemInitialLoadParameters:
370d76947f3SHartmut Brandt if ((err = OS_getSystemInitialLoadParameters(&str)) !=
371d76947f3SHartmut Brandt SNMP_ERR_NOERROR)
372d76947f3SHartmut Brandt return (err);
373d76947f3SHartmut Brandt return (string_get(value, str, -1));
374d76947f3SHartmut Brandt
375d76947f3SHartmut Brandt case LEAF_hrSystemNumUsers:
376d76947f3SHartmut Brandt return (OS_getSystemNumUsers(&value->v.uint32));
377d76947f3SHartmut Brandt
378d76947f3SHartmut Brandt case LEAF_hrSystemProcesses:
379d76947f3SHartmut Brandt return (OS_getSystemProcesses(&value->v.uint32));
380d76947f3SHartmut Brandt
381d76947f3SHartmut Brandt case LEAF_hrSystemMaxProcesses:
382d76947f3SHartmut Brandt return (OS_getSystemMaxProcesses(&value->v.uint32));
383d76947f3SHartmut Brandt }
384d76947f3SHartmut Brandt abort();
385d76947f3SHartmut Brandt
386d76947f3SHartmut Brandt case SNMP_OP_SET:
387d76947f3SHartmut Brandt switch (value->var.subs[sub - 1]) {
388d76947f3SHartmut Brandt
389d76947f3SHartmut Brandt case LEAF_hrSystemDate:
390d76947f3SHartmut Brandt if ((ctx->scratch->ptr1 =
391d76947f3SHartmut Brandt OS_checkSystemDateInput(value->v.octetstring.octets,
392d76947f3SHartmut Brandt value->v.octetstring.len)) == NULL)
393d76947f3SHartmut Brandt return (SNMP_ERR_WRONG_VALUE);
394d76947f3SHartmut Brandt
395d76947f3SHartmut Brandt return (SNMP_ERR_NOERROR);
396d76947f3SHartmut Brandt
397d76947f3SHartmut Brandt case LEAF_hrSystemInitialLoadDevice:
398d76947f3SHartmut Brandt case LEAF_hrSystemInitialLoadParameters:
399d76947f3SHartmut Brandt return (SNMP_ERR_NOT_WRITEABLE);
400d76947f3SHartmut Brandt
401d76947f3SHartmut Brandt }
402d76947f3SHartmut Brandt abort();
403d76947f3SHartmut Brandt
404d76947f3SHartmut Brandt case SNMP_OP_ROLLBACK:
405d76947f3SHartmut Brandt switch (value->var.subs[sub - 1]) {
406d76947f3SHartmut Brandt
407d76947f3SHartmut Brandt case LEAF_hrSystemDate:
408d76947f3SHartmut Brandt free(ctx->scratch->ptr1);
409d76947f3SHartmut Brandt return (SNMP_ERR_NOERROR);
410d76947f3SHartmut Brandt
411d76947f3SHartmut Brandt case LEAF_hrSystemInitialLoadDevice:
412d76947f3SHartmut Brandt case LEAF_hrSystemInitialLoadParameters:
413d76947f3SHartmut Brandt abort();
414d76947f3SHartmut Brandt }
415d76947f3SHartmut Brandt abort();
416d76947f3SHartmut Brandt
417d76947f3SHartmut Brandt case SNMP_OP_COMMIT:
418d76947f3SHartmut Brandt switch (value->var.subs[sub - 1]) {
419d76947f3SHartmut Brandt
420d76947f3SHartmut Brandt case LEAF_hrSystemDate:
421d76947f3SHartmut Brandt (void)OS_setSystemDate(ctx->scratch->ptr1);
422d76947f3SHartmut Brandt free(ctx->scratch->ptr1);
423d76947f3SHartmut Brandt return (SNMP_ERR_NOERROR);
424d76947f3SHartmut Brandt
425d76947f3SHartmut Brandt case LEAF_hrSystemInitialLoadDevice:
426d76947f3SHartmut Brandt case LEAF_hrSystemInitialLoadParameters:
427d76947f3SHartmut Brandt abort();
428d76947f3SHartmut Brandt }
429d76947f3SHartmut Brandt abort();
430d76947f3SHartmut Brandt
431d76947f3SHartmut Brandt case SNMP_OP_GETNEXT:
432d76947f3SHartmut Brandt abort();
433d76947f3SHartmut Brandt }
434d76947f3SHartmut Brandt abort();
435d76947f3SHartmut Brandt }
436d76947f3SHartmut Brandt
437d76947f3SHartmut Brandt /*
438*de8b4900SElyes Haouas * prototype of this function was generated by gensnmptree tool
439d76947f3SHartmut Brandt * in the header file hostres_tree.h
440d76947f3SHartmut Brandt * Returns SNMP_ERR_NOERROR on success
441d76947f3SHartmut Brandt */
442d76947f3SHartmut Brandt int
op_hrStorage(struct snmp_context * ctx __unused,struct snmp_value * value,u_int sub,u_int iidx __unused,enum snmp_op curr_op)443d76947f3SHartmut Brandt op_hrStorage(struct snmp_context *ctx __unused, struct snmp_value *value,
444d76947f3SHartmut Brandt u_int sub, u_int iidx __unused, enum snmp_op curr_op)
445d76947f3SHartmut Brandt {
446d76947f3SHartmut Brandt
447d76947f3SHartmut Brandt /* only GET is possible */
448d76947f3SHartmut Brandt switch (curr_op) {
449d76947f3SHartmut Brandt
450d76947f3SHartmut Brandt case SNMP_OP_GET:
451d76947f3SHartmut Brandt switch (value->var.subs[sub - 1]) {
452d76947f3SHartmut Brandt
453d76947f3SHartmut Brandt case LEAF_hrMemorySize:
454d76947f3SHartmut Brandt return (OS_getMemorySize(&value->v.uint32));
455d76947f3SHartmut Brandt }
456d76947f3SHartmut Brandt abort();
457d76947f3SHartmut Brandt
458d76947f3SHartmut Brandt case SNMP_OP_SET:
459d76947f3SHartmut Brandt return (SNMP_ERR_NOT_WRITEABLE);
460d76947f3SHartmut Brandt
461d76947f3SHartmut Brandt case SNMP_OP_ROLLBACK:
462d76947f3SHartmut Brandt case SNMP_OP_COMMIT:
463d76947f3SHartmut Brandt case SNMP_OP_GETNEXT:
464d76947f3SHartmut Brandt abort();
465d76947f3SHartmut Brandt }
466d76947f3SHartmut Brandt abort();
467d76947f3SHartmut Brandt }
468