~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to snmplib/snmp_pdu.c

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2009-09-24 14:51:06 UTC
  • mfrom: (1.1.12 upstream)
  • mto: (20.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20090924145106-38jgrzmj0d73pha5
Tags: 3.1.0.13-1
* Upload to experimental

* New upstream release
  - Fixes Follow-X-Forwarded-For support (Closes: #523943)
  - Adds IPv6 support (Closes: #432351)

* debian/rules
  - Removed obsolete configuration options
  - Enable db and radius basic authentication modules

* debian/patches/01-cf.data.debian
  - Adapted to new upstream version

* debian/patches/02-makefile-defaults
  - Adapted to new upstream version

* debian/{squid.postinst,squid.rc,README.Debian,watch}
  - Updated references to squid 3.1

* debian/squid3.install
  - Install CSS file for error pages
  - Install manual pages for new authentication modules

* debian/squid3-common.install
  - Install documented version of configuration file in /usr/share/doc/squid3

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
/**********************************************************************
11
11
 *
12
12
 *           Copyright 1997 by Carnegie Mellon University
13
 
 * 
 
13
 *
14
14
 *                       All Rights Reserved
15
 
 * 
 
15
 *
16
16
 * Permission to use, copy, modify, and distribute this software and its
17
17
 * documentation for any purpose and without fee is hereby granted,
18
18
 * provided that the above copyright notice appear in all copies and that
20
20
 * supporting documentation, and that the name of CMU not be
21
21
 * used in advertising or publicity pertaining to distribution of the
22
22
 * software without specific, written prior permission.
23
 
 * 
 
23
 *
24
24
 * CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
25
25
 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
26
26
 * CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
28
28
 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
29
29
 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
30
30
 * SOFTWARE.
31
 
 * 
 
31
 *
32
32
 * Author: Ryan Troll <ryan+@andrew.cmu.edu>
33
 
 * 
 
33
 *
34
34
 **********************************************************************/
35
35
 
36
36
#include "config.h"
104
104
 */
105
105
 
106
106
struct snmp_pdu *
107
 
snmp_pdu_create(int command)
108
 
{
 
107
            snmp_pdu_create(int command) {
109
108
    struct snmp_pdu *pdu;
110
109
 
111
110
#ifdef DEBUG_PDU
114
113
 
115
114
    pdu = (struct snmp_pdu *) xmalloc(sizeof(struct snmp_pdu));
116
115
    if (pdu == NULL) {
117
 
        snmp_set_api_error(SNMPERR_OS_ERR);
118
 
        return (NULL);
 
116
        snmp_set_api_error(SNMPERR_OS_ERR);
 
117
        return (NULL);
119
118
    }
120
119
    memset((char *) pdu, '\0', sizeof(struct snmp_pdu));
121
120
 
139
138
/* Clone an existing PDU.
140
139
 */
141
140
struct snmp_pdu *
142
 
snmp_pdu_clone(struct snmp_pdu *Src)
143
 
{
 
141
            snmp_pdu_clone(struct snmp_pdu *Src) {
144
142
    struct snmp_pdu *Dest;
145
143
 
146
144
#ifdef DEBUG_PDU
149
147
 
150
148
    Dest = (struct snmp_pdu *) xmalloc(sizeof(struct snmp_pdu));
151
149
    if (Dest == NULL) {
152
 
        snmp_set_api_error(SNMPERR_OS_ERR);
153
 
        return (NULL);
 
150
        snmp_set_api_error(SNMPERR_OS_ERR);
 
151
        return (NULL);
154
152
    }
155
153
    xmemcpy((char *) Dest, (char *) Src, sizeof(struct snmp_pdu));
156
154
 
174
172
 * be returned.
175
173
 */
176
174
struct snmp_pdu *
177
 
snmp_pdu_fix(struct snmp_pdu *pdu, int command)
178
 
{
 
175
            snmp_pdu_fix(struct snmp_pdu *pdu, int command) {
179
176
    return (snmp_fix_pdu(pdu, command));
180
177
}
181
178
 
182
179
struct snmp_pdu *
183
 
snmp_fix_pdu(struct snmp_pdu *pdu, int command)
184
 
{
 
180
            snmp_fix_pdu(struct snmp_pdu *pdu, int command) {
185
181
    struct variable_list *var, *newvar;
186
182
    struct snmp_pdu *newpdu;
187
183
    int i;
189
185
 
190
186
#ifdef DEBUG_PDU
191
187
    snmplib_debug(8, "PDU %x:  Fixing.  Err index is %d\n",
192
 
        (unsigned int) pdu, (unsigned int) pdu->errindex);
 
188
                  (unsigned int) pdu, (unsigned int) pdu->errindex);
193
189
#endif
194
190
 
195
191
    if (pdu->command != SNMP_PDU_RESPONSE ||
196
 
        pdu->errstat == SNMP_ERR_NOERROR ||
197
 
        pdu->errindex <= 0) {
198
 
        snmp_set_api_error(SNMPERR_UNABLE_TO_FIX);
199
 
        return (NULL);
 
192
            pdu->errstat == SNMP_ERR_NOERROR ||
 
193
            pdu->errindex <= 0) {
 
194
        snmp_set_api_error(SNMPERR_UNABLE_TO_FIX);
 
195
        return (NULL);
200
196
    }
201
197
    /* clone the pdu */
202
198
    newpdu = snmp_pdu_clone(pdu);
203
199
    if (newpdu == NULL)
204
 
        return (NULL);
 
200
        return (NULL);
205
201
 
206
202
    newpdu->variables = 0;
207
203
    newpdu->command = command;
216
212
 
217
213
    /* skip first variable if necessary */
218
214
    if (pdu->errindex == i) {
219
 
        var = var->next_variable;
220
 
        i++;
 
215
        var = var->next_variable;
 
216
        i++;
221
217
    }
222
218
    if (var != NULL) {
223
219
 
224
 
        /* VAR is the first uncopied variable */
225
 
 
226
 
        /* Clone this variable */
227
 
        newpdu->variables = snmp_var_clone(var);
228
 
        if (newpdu->variables == NULL) {
229
 
            snmp_pdu_free(newpdu);
230
 
            return (NULL);
231
 
        }
232
 
        copied++;
233
 
 
234
 
        newvar = newpdu->variables;
235
 
 
236
 
        /* VAR has been copied to NEWVAR. */
237
 
        while (var->next_variable) {
238
 
 
239
 
            /* Skip the item that was bad */
240
 
            if (++i == pdu->errindex) {
241
 
                var = var->next_variable;
242
 
                continue;
243
 
            }
244
 
            /* Copy this var */
245
 
            newvar->next_variable = snmp_var_clone(var->next_variable);
246
 
            if (newvar->next_variable == NULL) {
247
 
                snmp_pdu_free(newpdu);
248
 
                return (NULL);
249
 
            }
250
 
            /* Move to the next one */
251
 
            newvar = newvar->next_variable;
252
 
            var = var->next_variable;
253
 
            copied++;
254
 
        }
255
 
        newvar->next_variable = NULL;
 
220
        /* VAR is the first uncopied variable */
 
221
 
 
222
        /* Clone this variable */
 
223
        newpdu->variables = snmp_var_clone(var);
 
224
        if (newpdu->variables == NULL) {
 
225
            snmp_pdu_free(newpdu);
 
226
            return (NULL);
 
227
        }
 
228
        copied++;
 
229
 
 
230
        newvar = newpdu->variables;
 
231
 
 
232
        /* VAR has been copied to NEWVAR. */
 
233
        while (var->next_variable) {
 
234
 
 
235
            /* Skip the item that was bad */
 
236
            if (++i == pdu->errindex) {
 
237
                var = var->next_variable;
 
238
                continue;
 
239
            }
 
240
            /* Copy this var */
 
241
            newvar->next_variable = snmp_var_clone(var->next_variable);
 
242
            if (newvar->next_variable == NULL) {
 
243
                snmp_pdu_free(newpdu);
 
244
                return (NULL);
 
245
            }
 
246
            /* Move to the next one */
 
247
            newvar = newvar->next_variable;
 
248
            var = var->next_variable;
 
249
            copied++;
 
250
        }
 
251
        newvar->next_variable = NULL;
256
252
    }
257
253
    /* If we didn't copy anything, free the new pdu. */
258
254
    if (i < pdu->errindex || copied == 0) {
259
 
        snmp_free_pdu(newpdu);
260
 
        snmp_set_api_error(SNMPERR_UNABLE_TO_FIX);
261
 
        return (NULL);
 
255
        snmp_free_pdu(newpdu);
 
256
        snmp_set_api_error(SNMPERR_UNABLE_TO_FIX);
 
257
        return (NULL);
262
258
    }
263
259
#ifdef DEBUG_PDU
264
260
    snmplib_debug(8, "PDU %x:  Fixed PDU is %x\n",
265
 
        (unsigned int) pdu, (unsigned int) newpdu);
 
261
                  (unsigned int) pdu, (unsigned int) newpdu);
266
262
#endif
267
263
    return (newpdu);
268
264
}
286
282
 
287
283
    vp = pdu->variables;
288
284
    while (vp) {
289
 
        ovp = vp;
290
 
        vp = vp->next_variable;
291
 
        snmp_var_free(ovp);
 
285
        ovp = vp;
 
286
        vp = vp->next_variable;
 
287
        snmp_var_free(ovp);
292
288
    }
293
289
 
294
290
    if (pdu->enterprise)
295
 
        xfree((char *) pdu->enterprise);
 
291
        xfree((char *) pdu->enterprise);
296
292
    xfree((char *) pdu);
297
293
}
298
294
 
307
303
/*
308
304
 * RFC 1902: Structure of Management Information for SNMPv2
309
305
 *
310
 
 *   PDU ::= 
 
306
 *   PDU ::=
311
307
 *    SEQUENCE {
312
308
 *      request-id   INTEGER32
313
309
 *      error-status INTEGER
327
323
/*
328
324
 * RFC 1157: A Simple Network Management Protocol (SNMP)
329
325
 *
330
 
 *   PDU ::= 
 
326
 *   PDU ::=
331
327
 *    SEQUENCE {
332
328
 *      request-id   INTEGER
333
329
 *      error-status INTEGER
347
343
 
348
344
u_char *
349
345
snmp_pdu_encode(u_char * DestBuf, int *DestBufLen,
350
 
    struct snmp_pdu *PDU)
 
346
                struct snmp_pdu *PDU)
351
347
{
352
348
    u_char *bufp;
353
349
 
358
354
    /* ASN.1 Header */
359
355
    switch (PDU->command) {
360
356
 
361
 
/**********************************************************************/
 
357
        /**********************************************************************/
362
358
#ifdef TRP_REQ_MSG
363
359
    case TRP_REQ_MSG:
364
360
 
365
 
        /* SNMPv1 Trap */
366
 
 
367
 
        /* enterprise */
368
 
        bufp = asn_build_objid(DestBuf, DestBufLen,
369
 
            (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OBJECT_ID),
370
 
            (oid *) PDU->enterprise, PDU->enterprise_length);
371
 
        if (bufp == NULL)
372
 
            return (NULL);
373
 
 
374
 
        /* agent-addr */
375
 
        bufp = asn_build_string(bufp, DestBufLen,
376
 
            (u_char) (SMI_IPADDRESS | ASN_PRIMITIVE),
377
 
            (u_char *) & PDU->agent_addr.sin_addr.s_addr,
378
 
            sizeof(PDU->agent_addr.sin_addr.s_addr));
379
 
        if (bufp == NULL)
380
 
            return (NULL);
381
 
 
382
 
        /* generic trap */
383
 
        bufp = asn_build_int(bufp, DestBufLen,
384
 
            (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
385
 
            (int *) &PDU->trap_type, sizeof(PDU->trap_type));
386
 
        if (bufp == NULL)
387
 
            return (NULL);
388
 
 
389
 
        /* specific trap */
390
 
        bufp = asn_build_int(bufp, DestBufLen,
391
 
            (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
392
 
            (int *) &PDU->specific_type,
393
 
            sizeof(PDU->specific_type));
394
 
        if (bufp == NULL)
395
 
            return (NULL);
396
 
 
397
 
        /* timestamp */
398
 
        bufp = asn_build_unsigned_int(bufp, DestBufLen,
399
 
            (u_char) (SMI_TIMETICKS | ASN_PRIMITIVE),
400
 
            &PDU->time, sizeof(PDU->time));
401
 
        if (bufp == NULL)
402
 
            return (NULL);
403
 
        break;
 
361
        /* SNMPv1 Trap */
 
362
 
 
363
        /* enterprise */
 
364
        bufp = asn_build_objid(DestBuf, DestBufLen,
 
365
                               (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OBJECT_ID),
 
366
                               (oid *) PDU->enterprise, PDU->enterprise_length);
 
367
        if (bufp == NULL)
 
368
            return (NULL);
 
369
 
 
370
        /* agent-addr */
 
371
        bufp = asn_build_string(bufp, DestBufLen,
 
372
                                (u_char) (SMI_IPADDRESS | ASN_PRIMITIVE),
 
373
                                (u_char *) & PDU->agent_addr.sin_addr.s_addr,
 
374
                                sizeof(PDU->agent_addr.sin_addr.s_addr));
 
375
        if (bufp == NULL)
 
376
            return (NULL);
 
377
 
 
378
        /* generic trap */
 
379
        bufp = asn_build_int(bufp, DestBufLen,
 
380
                             (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
 
381
                             (int *) &PDU->trap_type, sizeof(PDU->trap_type));
 
382
        if (bufp == NULL)
 
383
            return (NULL);
 
384
 
 
385
        /* specific trap */
 
386
        bufp = asn_build_int(bufp, DestBufLen,
 
387
                             (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
 
388
                             (int *) &PDU->specific_type,
 
389
                             sizeof(PDU->specific_type));
 
390
        if (bufp == NULL)
 
391
            return (NULL);
 
392
 
 
393
        /* timestamp */
 
394
        bufp = asn_build_unsigned_int(bufp, DestBufLen,
 
395
                                      (u_char) (SMI_TIMETICKS | ASN_PRIMITIVE),
 
396
                                      &PDU->time, sizeof(PDU->time));
 
397
        if (bufp == NULL)
 
398
            return (NULL);
 
399
        break;
404
400
#endif
405
401
 
406
 
/**********************************************************************/
 
402
        /**********************************************************************/
407
403
 
408
404
    case SNMP_PDU_GETBULK:
409
405
 
410
 
        /* SNMPv2 Bulk Request */
411
 
 
412
 
        /* request id */
413
 
        bufp = asn_build_int(DestBuf, DestBufLen,
414
 
            (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
415
 
            &PDU->reqid, sizeof(PDU->reqid));
416
 
        if (bufp == NULL)
417
 
            return (NULL);
418
 
 
419
 
        /* non-repeaters */
420
 
        bufp = asn_build_int(bufp, DestBufLen,
421
 
            (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
422
 
            &PDU->non_repeaters,
423
 
            sizeof(PDU->non_repeaters));
424
 
        if (bufp == NULL)
425
 
            return (NULL);
426
 
 
427
 
        /* max-repetitions */
428
 
        bufp = asn_build_int(bufp, DestBufLen,
429
 
            (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
430
 
            &PDU->max_repetitions,
431
 
            sizeof(PDU->max_repetitions));
432
 
        if (bufp == NULL)
433
 
            return (NULL);
434
 
        break;
435
 
 
436
 
/**********************************************************************/
 
406
        /* SNMPv2 Bulk Request */
 
407
 
 
408
        /* request id */
 
409
        bufp = asn_build_int(DestBuf, DestBufLen,
 
410
                             (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
 
411
                             &PDU->reqid, sizeof(PDU->reqid));
 
412
        if (bufp == NULL)
 
413
            return (NULL);
 
414
 
 
415
        /* non-repeaters */
 
416
        bufp = asn_build_int(bufp, DestBufLen,
 
417
                             (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
 
418
                             &PDU->non_repeaters,
 
419
                             sizeof(PDU->non_repeaters));
 
420
        if (bufp == NULL)
 
421
            return (NULL);
 
422
 
 
423
        /* max-repetitions */
 
424
        bufp = asn_build_int(bufp, DestBufLen,
 
425
                             (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
 
426
                             &PDU->max_repetitions,
 
427
                             sizeof(PDU->max_repetitions));
 
428
        if (bufp == NULL)
 
429
            return (NULL);
 
430
        break;
 
431
 
 
432
        /**********************************************************************/
437
433
 
438
434
    default:
439
435
 
440
 
        /* Normal PDU Encoding */
441
 
 
442
 
        /* request id */
443
 
#ifdef DEBUG_PDU_ENCODE
444
 
        snmplib_debug(8, "PDU: Request ID %d (0x%x)\n", PDU->reqid, DestBuf);
445
 
#endif
446
 
        bufp = asn_build_int(DestBuf, DestBufLen,
447
 
            (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
448
 
            &PDU->reqid, sizeof(PDU->reqid));
449
 
        if (bufp == NULL)
450
 
            return (NULL);
451
 
 
452
 
        /* error status */
453
 
#ifdef DEBUG_PDU_ENCODE
454
 
        snmplib_debug(8, "PDU: Error Status %d (0x%x)\n", PDU->errstat, bufp);
455
 
#endif
456
 
        bufp = asn_build_int(bufp, DestBufLen,
457
 
            (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
458
 
            &PDU->errstat, sizeof(PDU->errstat));
459
 
        if (bufp == NULL)
460
 
            return (NULL);
461
 
 
462
 
        /* error index */
463
 
#ifdef DEBUG_PDU_ENCODE
464
 
        snmplib_debug(8, "PDU: Error index %d (0x%x)\n", PDU->errindex, bufp);
465
 
#endif
466
 
        bufp = asn_build_int(bufp, DestBufLen,
467
 
            (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
468
 
            &PDU->errindex, sizeof(PDU->errindex));
469
 
        if (bufp == NULL)
470
 
            return (NULL);
471
 
        break;
 
436
        /* Normal PDU Encoding */
 
437
 
 
438
        /* request id */
 
439
#ifdef DEBUG_PDU_ENCODE
 
440
        snmplib_debug(8, "PDU: Request ID %d (0x%x)\n", PDU->reqid, DestBuf);
 
441
#endif
 
442
        bufp = asn_build_int(DestBuf, DestBufLen,
 
443
                             (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
 
444
                             &PDU->reqid, sizeof(PDU->reqid));
 
445
        if (bufp == NULL)
 
446
            return (NULL);
 
447
 
 
448
        /* error status */
 
449
#ifdef DEBUG_PDU_ENCODE
 
450
        snmplib_debug(8, "PDU: Error Status %d (0x%x)\n", PDU->errstat, bufp);
 
451
#endif
 
452
        bufp = asn_build_int(bufp, DestBufLen,
 
453
                             (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
 
454
                             &PDU->errstat, sizeof(PDU->errstat));
 
455
        if (bufp == NULL)
 
456
            return (NULL);
 
457
 
 
458
        /* error index */
 
459
#ifdef DEBUG_PDU_ENCODE
 
460
        snmplib_debug(8, "PDU: Error index %d (0x%x)\n", PDU->errindex, bufp);
 
461
#endif
 
462
        bufp = asn_build_int(bufp, DestBufLen,
 
463
                             (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
 
464
                             &PDU->errindex, sizeof(PDU->errindex));
 
465
        if (bufp == NULL)
 
466
            return (NULL);
 
467
        break;
472
468
    }                           /* End of encoding */
473
469
 
474
470
    return (bufp);
483
479
 */
484
480
u_char *
485
481
snmp_pdu_decode(u_char * Packet,        /* data */
486
 
    int *Length,                /* &length */
487
 
    struct snmp_pdu * PDU)
 
482
                int *Length,            /* &length */
 
483
                struct snmp_pdu * PDU)
488
484
{                               /* pdu */
489
485
    u_char *bufp;
490
486
    u_char PDUType;
496
492
 
497
493
    bufp = asn_parse_header(Packet, Length, &PDUType);
498
494
    if (bufp == NULL)
499
 
        ASN_PARSE_ERROR(NULL);
 
495
        ASN_PARSE_ERROR(NULL);
500
496
 
501
497
#ifdef DEBUG_PDU_DECODE
502
498
    snmplib_debug(8, "PDU Type: %d\n", PDUType);
508
504
#ifdef TRP_REQ_MSG
509
505
    case TRP_REQ_MSG:
510
506
 
511
 
        /* SNMPv1 Trap Message */
512
 
 
513
 
        /* enterprise */
514
 
        PDU->enterprise_length = MAX_NAME_LEN;
515
 
        bufp = asn_parse_objid(bufp, Length,
516
 
            &ASNType, objid, &PDU->enterprise_length);
517
 
        if (bufp == NULL)
518
 
            ASN_PARSE_ERROR(NULL);
519
 
 
520
 
        PDU->enterprise = (oid *) xmalloc(PDU->enterprise_length * sizeof(oid));
521
 
        if (PDU->enterprise == NULL) {
522
 
            snmp_set_api_error(SNMPERR_OS_ERR);
523
 
            return (NULL);
524
 
        }
525
 
        xmemcpy((char *) PDU->enterprise, (char *) objid,
526
 
            PDU->enterprise_length * sizeof(oid));
527
 
 
528
 
        /* Agent-addr */
529
 
        four = 4;
530
 
        bufp = asn_parse_string(bufp, Length,
531
 
            &ASNType,
532
 
            (u_char *) & PDU->agent_addr.sin_addr.s_addr,
533
 
            &four);
534
 
        if (bufp == NULL)
535
 
            ASN_PARSE_ERROR(NULL);
536
 
 
537
 
        /* Generic trap */
538
 
        bufp = asn_parse_int(bufp, Length,
539
 
            &ASNType,
540
 
            (int *) &PDU->trap_type,
541
 
            sizeof(PDU->trap_type));
542
 
        if (bufp == NULL)
543
 
            ASN_PARSE_ERROR(NULL);
544
 
 
545
 
        /* Specific Trap */
546
 
        bufp = asn_parse_int(bufp, Length,
547
 
            &ASNType,
548
 
            (int *) &PDU->specific_type,
549
 
            sizeof(PDU->specific_type));
550
 
        if (bufp == NULL)
551
 
            ASN_PARSE_ERROR(NULL);
552
 
 
553
 
        /* Timestamp */
554
 
        bufp = asn_parse_unsigned_int(bufp, Length,
555
 
            &ASNType,
556
 
            &PDU->time, sizeof(PDU->time));
557
 
        if (bufp == NULL)
558
 
            ASN_PARSE_ERROR(NULL);
559
 
        break;
 
507
        /* SNMPv1 Trap Message */
 
508
 
 
509
        /* enterprise */
 
510
        PDU->enterprise_length = MAX_NAME_LEN;
 
511
        bufp = asn_parse_objid(bufp, Length,
 
512
                               &ASNType, objid, &PDU->enterprise_length);
 
513
        if (bufp == NULL)
 
514
            ASN_PARSE_ERROR(NULL);
 
515
 
 
516
        PDU->enterprise = (oid *) xmalloc(PDU->enterprise_length * sizeof(oid));
 
517
        if (PDU->enterprise == NULL) {
 
518
            snmp_set_api_error(SNMPERR_OS_ERR);
 
519
            return (NULL);
 
520
        }
 
521
        xmemcpy((char *) PDU->enterprise, (char *) objid,
 
522
                PDU->enterprise_length * sizeof(oid));
 
523
 
 
524
        /* Agent-addr */
 
525
        four = 4;
 
526
        bufp = asn_parse_string(bufp, Length,
 
527
                                &ASNType,
 
528
                                (u_char *) & PDU->agent_addr.sin_addr.s_addr,
 
529
                                &four);
 
530
        if (bufp == NULL)
 
531
            ASN_PARSE_ERROR(NULL);
 
532
 
 
533
        /* Generic trap */
 
534
        bufp = asn_parse_int(bufp, Length,
 
535
                             &ASNType,
 
536
                             (int *) &PDU->trap_type,
 
537
                             sizeof(PDU->trap_type));
 
538
        if (bufp == NULL)
 
539
            ASN_PARSE_ERROR(NULL);
 
540
 
 
541
        /* Specific Trap */
 
542
        bufp = asn_parse_int(bufp, Length,
 
543
                             &ASNType,
 
544
                             (int *) &PDU->specific_type,
 
545
                             sizeof(PDU->specific_type));
 
546
        if (bufp == NULL)
 
547
            ASN_PARSE_ERROR(NULL);
 
548
 
 
549
        /* Timestamp */
 
550
        bufp = asn_parse_unsigned_int(bufp, Length,
 
551
                                      &ASNType,
 
552
                                      &PDU->time, sizeof(PDU->time));
 
553
        if (bufp == NULL)
 
554
            ASN_PARSE_ERROR(NULL);
 
555
        break;
560
556
#endif
561
557
 
562
 
/**********************************************************************/
 
558
        /**********************************************************************/
563
559
 
564
560
    case SNMP_PDU_GETBULK:
565
561
 
566
 
        /* SNMPv2 Bulk Request */
567
 
 
568
 
        /* request id */
569
 
        bufp = asn_parse_int(bufp, Length,
570
 
            &ASNType,
571
 
            &PDU->reqid, sizeof(PDU->reqid));
572
 
        if (bufp == NULL)
573
 
            ASN_PARSE_ERROR(NULL);
574
 
 
575
 
        /* non-repeaters */
576
 
        bufp = asn_parse_int(bufp, Length,
577
 
            &ASNType,
578
 
            &PDU->non_repeaters, sizeof(PDU->non_repeaters));
579
 
        if (bufp == NULL)
580
 
            ASN_PARSE_ERROR(NULL);
581
 
 
582
 
        /* max-repetitions */
583
 
        bufp = asn_parse_int(bufp, Length,
584
 
            &ASNType,
585
 
            &PDU->max_repetitions, sizeof(PDU->max_repetitions));
586
 
        if (bufp == NULL)
587
 
            ASN_PARSE_ERROR(NULL);
588
 
        break;
589
 
 
590
 
/**********************************************************************/
 
562
        /* SNMPv2 Bulk Request */
 
563
 
 
564
        /* request id */
 
565
        bufp = asn_parse_int(bufp, Length,
 
566
                             &ASNType,
 
567
                             &PDU->reqid, sizeof(PDU->reqid));
 
568
        if (bufp == NULL)
 
569
            ASN_PARSE_ERROR(NULL);
 
570
 
 
571
        /* non-repeaters */
 
572
        bufp = asn_parse_int(bufp, Length,
 
573
                             &ASNType,
 
574
                             &PDU->non_repeaters, sizeof(PDU->non_repeaters));
 
575
        if (bufp == NULL)
 
576
            ASN_PARSE_ERROR(NULL);
 
577
 
 
578
        /* max-repetitions */
 
579
        bufp = asn_parse_int(bufp, Length,
 
580
                             &ASNType,
 
581
                             &PDU->max_repetitions, sizeof(PDU->max_repetitions));
 
582
        if (bufp == NULL)
 
583
            ASN_PARSE_ERROR(NULL);
 
584
        break;
 
585
 
 
586
        /**********************************************************************/
591
587
 
592
588
    default:
593
589
 
594
 
        /* Normal PDU Encoding */
595
 
 
596
 
        /* request id */
597
 
        bufp = asn_parse_int(bufp, Length,
598
 
            &ASNType,
599
 
            &PDU->reqid, sizeof(PDU->reqid));
600
 
        if (bufp == NULL)
601
 
            ASN_PARSE_ERROR(NULL);
602
 
 
603
 
#ifdef DEBUG_PDU_DECODE
604
 
        snmplib_debug(8, "PDU Request ID: %d\n", PDU->reqid);
605
 
#endif
606
 
 
607
 
        /* error status */
608
 
        bufp = asn_parse_int(bufp, Length,
609
 
            &ASNType,
610
 
            &PDU->errstat, sizeof(PDU->errstat));
611
 
        if (bufp == NULL)
612
 
            ASN_PARSE_ERROR(NULL);
613
 
 
614
 
#ifdef DEBUG_PDU_DECODE
615
 
        snmplib_debug(8, "PDU Error Status: %d\n", PDU->errstat);
616
 
#endif
617
 
 
618
 
        /* error index */
619
 
        bufp = asn_parse_int(bufp, Length,
620
 
            &ASNType,
621
 
            &PDU->errindex, sizeof(PDU->errindex));
622
 
        if (bufp == NULL)
623
 
            ASN_PARSE_ERROR(NULL);
624
 
 
625
 
#ifdef DEBUG_PDU_DECODE
626
 
        snmplib_debug(8, "PDU Error Index: %d\n", PDU->errindex);
627
 
#endif
628
 
 
629
 
        break;
 
590
        /* Normal PDU Encoding */
 
591
 
 
592
        /* request id */
 
593
        bufp = asn_parse_int(bufp, Length,
 
594
                             &ASNType,
 
595
                             &PDU->reqid, sizeof(PDU->reqid));
 
596
        if (bufp == NULL)
 
597
            ASN_PARSE_ERROR(NULL);
 
598
 
 
599
#ifdef DEBUG_PDU_DECODE
 
600
        snmplib_debug(8, "PDU Request ID: %d\n", PDU->reqid);
 
601
#endif
 
602
 
 
603
        /* error status */
 
604
        bufp = asn_parse_int(bufp, Length,
 
605
                             &ASNType,
 
606
                             &PDU->errstat, sizeof(PDU->errstat));
 
607
        if (bufp == NULL)
 
608
            ASN_PARSE_ERROR(NULL);
 
609
 
 
610
#ifdef DEBUG_PDU_DECODE
 
611
        snmplib_debug(8, "PDU Error Status: %d\n", PDU->errstat);
 
612
#endif
 
613
 
 
614
        /* error index */
 
615
        bufp = asn_parse_int(bufp, Length,
 
616
                             &ASNType,
 
617
                             &PDU->errindex, sizeof(PDU->errindex));
 
618
        if (bufp == NULL)
 
619
            ASN_PARSE_ERROR(NULL);
 
620
 
 
621
#ifdef DEBUG_PDU_DECODE
 
622
        snmplib_debug(8, "PDU Error Index: %d\n", PDU->errindex);
 
623
#endif
 
624
 
 
625
        break;
630
626
    }
631
627
 
632
628
    return (bufp);
644
640
 
645
641
    vars = snmp_var_new(name, name_length);
646
642
    if (vars == NULL) {
647
 
        perror("snmp_add_null_var:xmalloc");
648
 
        return;
 
643
        perror("snmp_add_null_var:xmalloc");
 
644
        return;
649
645
    }
650
646
    if (pdu->variables == NULL) {
651
 
        pdu->variables = vars;
 
647
        pdu->variables = vars;
652
648
    } else {
653
649
 
654
 
        /* Insert at the end */
655
 
        for (ptr = pdu->variables;
656
 
            ptr->next_variable;
657
 
            ptr = ptr->next_variable)
658
 
            /*EXIT */ ;
659
 
        ptr->next_variable = vars;
 
650
        /* Insert at the end */
 
651
        for (ptr = pdu->variables;
 
652
                ptr->next_variable;
 
653
                ptr = ptr->next_variable)
 
654
            /*EXIT */ ;
 
655
        ptr->next_variable = vars;
660
656
    }
661
657
 
662
658
    return;