00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <net-snmp/net-snmp-config.h>
00029
00030 #ifdef KINETICS
00031 #include "gw.h"
00032 #include "fp4/cmdmacro.h"
00033 #endif
00034
00035 #include <stdio.h>
00036 #if HAVE_STDLIB_H
00037 #include <stdlib.h>
00038 #endif
00039 #if HAVE_STRING_H
00040 #include <string.h>
00041 #else
00042 #include <strings.h>
00043 #endif
00044 #include <sys/types.h>
00045 #if TIME_WITH_SYS_TIME
00046 # ifdef WIN32
00047 # include <sys/timeb.h>
00048 # else
00049 # include <sys/time.h>
00050 # endif
00051 # include <time.h>
00052 #else
00053 # if HAVE_SYS_TIME_H
00054 # include <sys/time.h>
00055 # else
00056 # include <time.h>
00057 # endif
00058 #endif
00059 #if HAVE_SYS_SELECT_H
00060 #include <sys/select.h>
00061 #endif
00062 #if HAVE_NETINET_IN_H
00063 #include <netinet/in.h>
00064 #endif
00065 #if HAVE_ARPA_INET_H
00066 #include <arpa/inet.h>
00067 #endif
00068
00069 #if HAVE_DMALLOC_H
00070 #include <dmalloc.h>
00071 #endif
00072
00073 #if HAVE_WINSOCK_H
00074 #include <winsock.h>
00075 #endif
00076
00077 #ifdef vms
00078 #include <in.h>
00079 #endif
00080
00081 #include <net-snmp/types.h>
00082 #include <net-snmp/output_api.h>
00083 #include <net-snmp/utilities.h>
00084
00085 #include <net-snmp/library/asn1.h>
00086 #include <net-snmp/library/snmp_api.h>
00087 #include <net-snmp/library/mib.h>
00088 #include <net-snmp/library/md5.h>
00089 #include <net-snmp/library/scapi.h>
00090
00091
00092
00093
00094
00095 #if !defined(DISABLE_SNMPV1) || !defined(DISABLE_SNMPV2C)
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 u_char *
00114 snmp_comstr_parse(u_char * data,
00115 size_t * length,
00116 u_char * psid, size_t * slen, long *version)
00117 {
00118 u_char type;
00119 long ver;
00120 size_t origlen = *slen;
00121
00122
00123
00124
00125 data = asn_parse_sequence(data, length, &type,
00126 (ASN_SEQUENCE | ASN_CONSTRUCTOR),
00127 "auth message");
00128 if (data == NULL) {
00129 return NULL;
00130 }
00131
00132
00133
00134
00135 DEBUGDUMPHEADER("recv", "SNMP version");
00136 data = asn_parse_int(data, length, &type, &ver, sizeof(ver));
00137 DEBUGINDENTLESS();
00138 *version = ver;
00139 if (data == NULL) {
00140 ERROR_MSG("bad parse of version");
00141 return NULL;
00142 }
00143
00144
00145
00146
00147 DEBUGDUMPHEADER("recv", "community string");
00148 data = asn_parse_string(data, length, &type, psid, slen);
00149 DEBUGINDENTLESS();
00150 if (data == NULL) {
00151 ERROR_MSG("bad parse of community");
00152 return NULL;
00153 }
00154 psid[SNMP_MIN(*slen, origlen - 1)] = '\0';
00155 return (u_char *) data;
00156
00157 }
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187 u_char *
00188 snmp_comstr_build(u_char * data,
00189 size_t * length,
00190 u_char * psid,
00191 size_t * slen, long *version, size_t messagelen)
00192 {
00193 long verfix = *version;
00194 u_char *h1 = data;
00195 u_char *h1e;
00196 size_t hlength = *length;
00197
00198
00199
00200
00201
00202 data =
00203 asn_build_sequence(data, length,
00204 (u_char) (ASN_SEQUENCE | ASN_CONSTRUCTOR), 0);
00205 if (data == NULL) {
00206 return NULL;
00207 }
00208 h1e = data;
00209
00210
00211
00212
00213
00214 data = asn_build_int(data, length,
00215 (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE |
00216 ASN_INTEGER), &verfix, sizeof(verfix));
00217 if (data == NULL) {
00218 return NULL;
00219 }
00220
00221
00222
00223
00224
00225 data = asn_build_string(data, length,
00226 (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE |
00227 ASN_OCTET_STR), psid,
00228 *(u_char *) slen);
00229 if (data == NULL) {
00230 return NULL;
00231 }
00232
00233
00234
00235
00236
00237 asn_build_sequence(h1, &hlength,
00238 (u_char) (ASN_SEQUENCE | ASN_CONSTRUCTOR),
00239 data - h1e + messagelen);
00240
00241
00242 return data;
00243
00244 }
00245 #endif