Wes Hardaker | c3c403c | 1997-03-07 08:06:34 +0000 | [diff] [blame] | 1 | #include <config.h> |
| 2 | |
| 3 | #if HAVE_STDLIB_H |
| 4 | #include <stdlib.h> |
| 5 | #endif |
| 6 | #if HAVE_UNISTD_H |
| 7 | #include <unistd.h> |
| 8 | #endif |
| 9 | #if HAVE_FCNTL_H |
| 10 | #include <fcntl.h> |
| 11 | #endif |
| 12 | #include <signal.h> |
Wes Hardaker | e74d0f9 | 1997-04-22 13:02:56 +0000 | [diff] [blame] | 13 | #if TIME_WITH_SYS_TIME |
| 14 | # include <sys/time.h> |
| 15 | # include <time.h> |
| 16 | #else |
| 17 | # if HAVE_SYS_TIME_H |
| 18 | # include <sys/time.h> |
| 19 | # else |
| 20 | # include <time.h> |
| 21 | # endif |
| 22 | #endif |
Wes Hardaker | c3c403c | 1997-03-07 08:06:34 +0000 | [diff] [blame] | 23 | #if HAVE_MACHINE_PARAM_H |
| 24 | #include <machine/param.h> |
| 25 | #endif |
Wes Hardaker | a1a822e | 1998-03-26 15:22:30 +0000 | [diff] [blame] | 26 | #if HAVE_SYS_PARAM_H |
| 27 | #include <sys/param.h> |
| 28 | #endif |
Wes Hardaker | c3c403c | 1997-03-07 08:06:34 +0000 | [diff] [blame] | 29 | #if HAVE_SYS_VMMETER_H |
Wes Hardaker | 4e5278b | 1997-10-29 19:20:54 +0000 | [diff] [blame] | 30 | #if !(defined(bsdi2) || defined(netbsd1)) |
Wes Hardaker | c3c403c | 1997-03-07 08:06:34 +0000 | [diff] [blame] | 31 | #include <sys/vmmeter.h> |
| 32 | #endif |
| 33 | #endif |
| 34 | #if HAVE_SYS_CONF_H |
| 35 | #include <sys/conf.h> |
| 36 | #endif |
Wes Hardaker | f1f5874 | 1999-01-20 23:17:17 +0000 | [diff] [blame] | 37 | #if HAVE_ASM_PAGE_H |
| 38 | #include <asm/page.h> |
| 39 | #endif |
Wes Hardaker | c3c403c | 1997-03-07 08:06:34 +0000 | [diff] [blame] | 40 | #if HAVE_SYS_SWAP_H |
| 41 | #include <sys/swap.h> |
| 42 | #endif |
| 43 | #if HAVE_SYS_FS_H |
| 44 | #include <sys/fs.h> |
| 45 | #else |
| 46 | #if HAVE_UFS_FS_H |
| 47 | #include <ufs/fs.h> |
| 48 | #else |
Wes Hardaker | c3adf70 | 1997-07-01 13:41:44 +0000 | [diff] [blame] | 49 | #ifdef HAVE_SYS_STAT_H |
| 50 | #include <sys/stat.h> |
| 51 | #endif |
| 52 | #ifdef HAVE_SYS_VNODE_H |
| 53 | #include <sys/vnode.h> |
| 54 | #endif |
| 55 | #ifdef HAVE_UFS_UFS_QUOTA_H |
| 56 | #include <ufs/ufs/quota.h> |
| 57 | #endif |
| 58 | #ifdef HAVE_UFS_UFS_INODE_H |
| 59 | #include <ufs/ufs/inode.h> |
| 60 | #endif |
Wes Hardaker | c3c403c | 1997-03-07 08:06:34 +0000 | [diff] [blame] | 61 | #if HAVE_UFS_FFS_FS_H |
| 62 | #include <ufs/ffs/fs.h> |
| 63 | #endif |
| 64 | #endif |
| 65 | #endif |
| 66 | #if HAVE_MTAB_H |
| 67 | #include <mtab.h> |
| 68 | #endif |
| 69 | #include <sys/stat.h> |
| 70 | #include <errno.h> |
| 71 | #if HAVE_FSTAB_H |
| 72 | #include <fstab.h> |
| 73 | #endif |
Wes Hardaker | 7a2cb58 | 1997-08-14 14:38:17 +0000 | [diff] [blame] | 74 | #if HAVE_SYS_STATFS_H |
| 75 | #include <sys/statfs.h> |
| 76 | #endif |
Wes Hardaker | c3c403c | 1997-03-07 08:06:34 +0000 | [diff] [blame] | 77 | #if HAVE_SYS_STATVFS_H |
| 78 | #include <sys/statvfs.h> |
| 79 | #endif |
| 80 | #if HAVE_SYS_VFS_H |
| 81 | #include <sys/vfs.h> |
| 82 | #endif |
| 83 | #if (!defined(HAVE_STATVFS)) && defined(HAVE_STATFS) |
| 84 | #if HAVE_SYS_PARAM_H |
| 85 | #include <sys/param.h> |
| 86 | #endif |
| 87 | #if HAVE_SYS_MOUNT_H |
| 88 | #include <sys/mount.h> |
| 89 | #endif |
| 90 | #if HAVE_SYS_SYSCTL_H |
| 91 | #include <sys/sysctl.h> |
| 92 | #endif |
| 93 | #define statvfs statfs |
| 94 | #endif |
Michael Slifcak | 316513a | 1999-11-04 13:13:05 +0000 | [diff] [blame] | 95 | #if HAVE_VM_VM_H |
| 96 | #include <vm/vm.h> |
| 97 | #endif |
Wes Hardaker | c3c403c | 1997-03-07 08:06:34 +0000 | [diff] [blame] | 98 | #if HAVE_VM_SWAP_PAGER_H |
| 99 | #include <vm/swap_pager.h> |
| 100 | #endif |
| 101 | #if HAVE_SYS_FIXPOINT_H |
| 102 | #include <sys/fixpoint.h> |
| 103 | #endif |
| 104 | #if HAVE_MALLOC_H |
| 105 | #include <malloc.h> |
| 106 | #endif |
Michael Slifcak | 5dc0a73 | 1999-11-04 12:14:28 +0000 | [diff] [blame] | 107 | #if HAVE_STRING_H |
Wes Hardaker | c3c403c | 1997-03-07 08:06:34 +0000 | [diff] [blame] | 108 | #include <string.h> |
| 109 | #endif |
| 110 | |
Niels Baggesen | 4416a54 | 1999-10-25 21:13:57 +0000 | [diff] [blame] | 111 | #if HAVE_DMALLOC_H |
| 112 | #include <dmalloc.h> |
| 113 | #endif |
| 114 | |
Wes Hardaker | c3c403c | 1997-03-07 08:06:34 +0000 | [diff] [blame] | 115 | #include "mibincl.h" |
Wes Hardaker | e7e82b4 | 1998-01-21 19:12:34 +0000 | [diff] [blame] | 116 | #include "struct.h" |
Wes Hardaker | c3c403c | 1997-03-07 08:06:34 +0000 | [diff] [blame] | 117 | #include "errormib.h" |
Wes Hardaker | b41e8f8 | 1997-03-07 08:59:28 +0000 | [diff] [blame] | 118 | #include "util_funcs.h" |
Wes Hardaker | 7510f2e | 1998-02-09 19:03:02 +0000 | [diff] [blame] | 119 | #include "auto_nlist.h" |
Wes Hardaker | c3c403c | 1997-03-07 08:06:34 +0000 | [diff] [blame] | 120 | |
| 121 | static time_t errorstatustime=0; |
| 122 | static int errorstatusprior=0; |
| 123 | static char errorstring[STRMAX]; |
| 124 | |
| 125 | void |
Niels Baggesen | 34058af | 1999-04-26 19:13:52 +0000 | [diff] [blame] | 126 | setPerrorstatus(const char *to) |
Wes Hardaker | c3c403c | 1997-03-07 08:06:34 +0000 | [diff] [blame] | 127 | { |
| 128 | char buf[STRMAX]; |
Wes Hardaker | c3c403c | 1997-03-07 08:06:34 +0000 | [diff] [blame] | 129 | |
Wes Hardaker | 4e5278b | 1997-10-29 19:20:54 +0000 | [diff] [blame] | 130 | sprintf(buf,"%s: %s",to,strerror(errno)); |
Niels Baggesen | ce215d8 | 1999-08-18 16:31:09 +0000 | [diff] [blame] | 131 | snmp_log_perror(to); |
Wes Hardaker | c3c403c | 1997-03-07 08:06:34 +0000 | [diff] [blame] | 132 | seterrorstatus(buf,5); |
| 133 | } |
| 134 | |
| 135 | void |
Niels Baggesen | 34058af | 1999-04-26 19:13:52 +0000 | [diff] [blame] | 136 | seterrorstatus(const char *to, int prior) |
Wes Hardaker | c3c403c | 1997-03-07 08:06:34 +0000 | [diff] [blame] | 137 | { |
| 138 | if (errorstatusprior <= prior || |
| 139 | (ERRORTIMELENGTH < (time(NULL) - errorstatustime))) { |
| 140 | strcpy(errorstring,to); |
| 141 | errorstatusprior = prior; |
| 142 | errorstatustime = time(NULL); |
| 143 | } |
| 144 | } |
Wes Hardaker | 3af42a8 | 1999-01-15 23:24:03 +0000 | [diff] [blame] | 145 | |
Wes Hardaker | 40b2bf1 | 1999-01-18 18:47:36 +0000 | [diff] [blame] | 146 | void init_errormib(void) |
| 147 | { |
Wes Hardaker | 3af42a8 | 1999-01-15 23:24:03 +0000 | [diff] [blame] | 148 | |
| 149 | /* define the structure we're going to ask the agent to register our |
| 150 | information at */ |
| 151 | struct variable2 extensible_error_variables[] = { |
| 152 | {MIBINDEX, ASN_INTEGER, RONLY, var_extensible_errors, 1, {MIBINDEX}}, |
| 153 | {ERRORNAME, ASN_OCTET_STR, RONLY, var_extensible_errors, 1, {ERRORNAME}}, |
| 154 | {ERRORFLAG, ASN_INTEGER, RONLY, var_extensible_errors, 1, {ERRORFLAG}}, |
| 155 | {ERRORMSG, ASN_OCTET_STR, RONLY, var_extensible_errors, 1, {ERRORMSG}} |
| 156 | }; |
| 157 | |
| 158 | /* Define the OID pointer to the top of the mib tree that we're |
| 159 | registering underneath */ |
| 160 | oid extensible_error_variables_oid[] = { EXTENSIBLEMIB,ERRORMIBNUM }; |
| 161 | |
| 162 | /* register ourselves with the agent to handle our mib tree */ |
Dave Shield | 88da1f7 | 1999-07-27 13:38:09 +0000 | [diff] [blame] | 163 | REGISTER_MIB("ucd-snmp/errormib", extensible_error_variables, \ |
Wes Hardaker | 3af42a8 | 1999-01-15 23:24:03 +0000 | [diff] [blame] | 164 | variable2, extensible_error_variables_oid); |
| 165 | } |
| 166 | |
Wes Hardaker | 40b2bf1 | 1999-01-18 18:47:36 +0000 | [diff] [blame] | 167 | /* |
| 168 | var_extensible_errors(... |
| 169 | Arguments: |
| 170 | vp IN - pointer to variable entry that points here |
| 171 | name IN/OUT - IN/name requested, OUT/name found |
| 172 | length IN/OUT - length of IN/OUT oid's |
| 173 | exact IN - TRUE if an exact match was requested |
| 174 | var_len OUT - length of variable or 0 if function returned |
| 175 | write_method |
Wes Hardaker | c3c403c | 1997-03-07 08:06:34 +0000 | [diff] [blame] | 176 | |
Wes Hardaker | 40b2bf1 | 1999-01-18 18:47:36 +0000 | [diff] [blame] | 177 | */ |
Niels Baggesen | bc88147 | 1999-05-04 07:51:16 +0000 | [diff] [blame] | 178 | u_char *var_extensible_errors(struct variable *vp, |
Wes Hardaker | 40b2bf1 | 1999-01-18 18:47:36 +0000 | [diff] [blame] | 179 | oid *name, |
Niels Baggesen | 0045e2f | 1999-05-03 22:40:11 +0000 | [diff] [blame] | 180 | size_t *length, |
Wes Hardaker | 40b2bf1 | 1999-01-18 18:47:36 +0000 | [diff] [blame] | 181 | int exact, |
Niels Baggesen | 0045e2f | 1999-05-03 22:40:11 +0000 | [diff] [blame] | 182 | size_t *var_len, |
Wes Hardaker | 5ae6c98 | 1999-02-09 07:22:33 +0000 | [diff] [blame] | 183 | WriteMethod **write_method) |
Wes Hardaker | c3c403c | 1997-03-07 08:06:34 +0000 | [diff] [blame] | 184 | { |
| 185 | |
Wes Hardaker | c3c403c | 1997-03-07 08:06:34 +0000 | [diff] [blame] | 186 | static long long_ret; |
| 187 | static char errmsg[300]; |
| 188 | |
| 189 | |
Wes Hardaker | abbf691 | 1998-05-06 21:58:23 +0000 | [diff] [blame] | 190 | if (header_generic(vp,name,length,exact,var_len,write_method)) |
Wes Hardaker | c3c403c | 1997-03-07 08:06:34 +0000 | [diff] [blame] | 191 | return(NULL); |
| 192 | |
| 193 | errmsg[0] = 0; |
| 194 | |
| 195 | switch (vp->magic) { |
| 196 | case MIBINDEX: |
Wes Hardaker | abbf691 | 1998-05-06 21:58:23 +0000 | [diff] [blame] | 197 | long_ret = name[*length - 1]; |
Wes Hardaker | c3c403c | 1997-03-07 08:06:34 +0000 | [diff] [blame] | 198 | return((u_char *) (&long_ret)); |
| 199 | case ERRORNAME: |
| 200 | strcpy(errmsg,"snmp"); |
| 201 | *var_len = strlen(errmsg); |
| 202 | return((u_char *) errmsg); |
| 203 | case ERRORFLAG: |
| 204 | long_ret = (ERRORTIMELENGTH >= time(NULL)-errorstatustime) ? 1 : 0; |
| 205 | return((u_char *) (&long_ret)); |
| 206 | case ERRORMSG: |
| 207 | if ((ERRORTIMELENGTH >= time(NULL)-errorstatustime) ? 1 : 0) |
| 208 | strcpy(errmsg,errorstring); |
| 209 | else |
| 210 | errmsg[0] = 0; |
| 211 | *var_len = strlen(errmsg); |
| 212 | return((u_char *) errmsg); |
| 213 | } |
| 214 | return NULL; |
| 215 | } |
| 216 | |