~ubuntu-branches/ubuntu/trusty/net-snmp/trusty

« back to all changes in this revision

Viewing changes to apps/snmpvacm.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2004-09-13 12:06:21 UTC
  • Revision ID: james.westby@ubuntu.com-20040913120621-g952ntonlleihcvm
Tags: upstream-5.1.1
ImportĀ upstreamĀ versionĀ 5.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * snmpvacm.c - send snmp SET requests to a network entity to change the
 
3
 *             vacm database
 
4
 *
 
5
 */
 
6
#include <net-snmp/net-snmp-config.h>
 
7
 
 
8
#if HAVE_STDLIB_H
 
9
#include <stdlib.h>
 
10
#endif
 
11
#if HAVE_UNISTD_H
 
12
#include <unistd.h>
 
13
#endif
 
14
#if HAVE_STRING_H
 
15
#include <string.h>
 
16
#else
 
17
#include <strings.h>
 
18
#endif
 
19
#include <sys/types.h>
 
20
#if HAVE_NETINET_IN_H
 
21
#include <netinet/in.h>
 
22
#endif
 
23
#include <stdio.h>
 
24
#include <ctype.h>
 
25
#if TIME_WITH_SYS_TIME
 
26
# ifdef WIN32
 
27
#  include <sys/timeb.h>
 
28
# else
 
29
#  include <sys/time.h>
 
30
# endif
 
31
# include <time.h>
 
32
#else
 
33
# if HAVE_SYS_TIME_H
 
34
#  include <sys/time.h>
 
35
# else
 
36
#  include <time.h>
 
37
# endif
 
38
#endif
 
39
#if HAVE_SYS_SELECT_H
 
40
#include <sys/select.h>
 
41
#endif
 
42
#if HAVE_WINSOCK_H
 
43
#include <winsock.h>
 
44
#endif
 
45
#if HAVE_NETDB_H
 
46
#include <netdb.h>
 
47
#endif
 
48
#if HAVE_ARPA_INET_H
 
49
#include <arpa/inet.h>
 
50
#endif
 
51
 
 
52
#include <net-snmp/net-snmp-includes.h>
 
53
 
 
54
int             main(int, char **);
 
55
 
 
56
#define CMD_CREATESEC2GROUP_NAME    "createSec2Group"
 
57
#define CMD_CREATESEC2GROUP         1
 
58
#define CMD_DELETESEC2GROUP_NAME    "deleteSec2Group"
 
59
#define CMD_DELETESEC2GROUP         2
 
60
#define CMD_CREATEACCESS_NAME           "createAccess"
 
61
#define CMD_CREATEACCESS                3
 
62
#define CMD_DELETEACCESS_NAME           "deleteAccess"
 
63
#define CMD_DELETEACCESS                4
 
64
#define CMD_CREATEVIEW_NAME             "createView"
 
65
#define CMD_CREATEVIEW                  5
 
66
#define CMD_DELETEVIEW_NAME             "deleteView"
 
67
#define CMD_DELETEVIEW                  6
 
68
 
 
69
#define CMD_NUM    6
 
70
 
 
71
static const char *successNotes[CMD_NUM] = {
 
72
    "Sec2group successfully created.",
 
73
    "Sec2group successfully deleted.",
 
74
    "Access successfully created.",
 
75
    "Access successfully deleted.",
 
76
    "View successfully created.",
 
77
    "View successfully deleted."
 
78
};
 
79
 
 
80
#define                   SEC2GROUP_OID_LEN     11
 
81
#define                   ACCESS_OID_LEN        11
 
82
#define                   VIEW_OID_LEN          12
 
83
 
 
84
static oid      vacmGroupName[MAX_OID_LEN] =
 
85
    { 1, 3, 6, 1, 6, 3, 16, 1, 2, 1, 3 },
 
86
    vacmSec2GroupStorageType[MAX_OID_LEN] = {
 
87
1, 3, 6, 1, 6, 3, 16, 1, 2, 1, 4}, vacmSec2GroupStatus[MAX_OID_LEN] = {
 
88
1, 3, 6, 1, 6, 3, 16, 1, 2, 1, 5}, vacmAccessContextMatch[MAX_OID_LEN] = {
 
89
1, 3, 6, 1, 6, 3, 16, 1, 4, 1, 4}, vacmAccessReadViewName[MAX_OID_LEN] = {
 
90
1, 3, 6, 1, 6, 3, 16, 1, 4, 1, 5}, vacmAccessWriteViewName[MAX_OID_LEN] = {
 
91
1, 3, 6, 1, 6, 3, 16, 1, 4, 1, 6}, vacmAccessNotifyViewName[MAX_OID_LEN] = {
 
92
1, 3, 6, 1, 6, 3, 16, 1, 4, 1, 7}, vacmAccessStorageType[MAX_OID_LEN] = {
 
93
1, 3, 6, 1, 6, 3, 16, 1, 4, 1, 8}, vacmAccessStatus[MAX_OID_LEN] = {
 
94
1, 3, 6, 1, 6, 3, 16, 1, 4, 1, 9}, vacmViewTreeFamilyMask[MAX_OID_LEN] = {
 
95
1, 3, 6, 1, 6, 3, 16, 1, 5, 2, 1, 3}, vacmViewTreeFamilyType[MAX_OID_LEN] = {
 
96
1, 3, 6, 1, 6, 3, 16, 1, 5, 2, 1, 4},
 
97
    vacmViewTreeFamilyStorageType[MAX_OID_LEN] = {
 
98
1, 3, 6, 1, 6, 3, 16, 1, 5, 2, 1, 5},
 
99
    vacmViewTreeFamilyStatus[MAX_OID_LEN] = {
 
100
1, 3, 6, 1, 6, 3, 16, 1, 5, 2, 1, 6}
 
101
 
 
102
;
 
103
 
 
104
int             viewTreeFamilyType = 1;
 
105
 
 
106
void
 
107
usage(void)
 
108
{
 
109
    fprintf(stderr, "Usage: snmpvacm ");
 
110
    snmp_parse_args_usage(stderr);
 
111
    fprintf(stderr, " COMMAND\n\n");
 
112
    snmp_parse_args_descriptions(stderr);
 
113
    fprintf(stderr, "\nsnmpvacm commands:\n");
 
114
    fprintf(stderr, "        createAccess     GROUPNAME [CONTEXTPREFIX] SECURITYMODEL SECURITYLEVEL CONTEXTMATCH READVIEWNAME WRITEVIEWNAME NOTIFYVIEWNAME\n");
 
115
    fprintf(stderr, "        deleteAccess     GROUPNAME [CONTEXTPREFIX] SECURITYMODEL SECURITYLEVEL\n");
 
116
    fprintf(stderr, "        createSec2Group  MODEL SECURITYNAME  GROUPNAME\n");
 
117
    fprintf(stderr, "        deleteSec2Group  MODEL SECURITYNAME\n");
 
118
    fprintf(stderr, "  [-Ce] createView       NAME SUBTREE [MASK]\n");
 
119
    fprintf(stderr, "        deleteView       NAME SUBTREE\n");
 
120
}
 
121
 
 
122
 
 
123
void
 
124
access_oid(oid * it, size_t * len, const char *groupName,
 
125
           const char *prefix, int model, int level)
 
126
{
 
127
    int             i;
 
128
 
 
129
    int             itIndex = ACCESS_OID_LEN;
 
130
 
 
131
    *len = itIndex + 4 + +strlen(groupName);
 
132
 
 
133
    it[itIndex++] = strlen(groupName);
 
134
    for (i = 0; i < (int) strlen(groupName); i++)
 
135
        it[itIndex++] = groupName[i];
 
136
 
 
137
    if (prefix) {
 
138
        *len += strlen(prefix);
 
139
        it[itIndex++] = strlen(prefix);
 
140
        for (i = 0; i < (int) strlen(prefix); i++)
 
141
            it[itIndex++] = prefix[i];
 
142
    } else
 
143
        it[itIndex++] = 0;
 
144
 
 
145
    it[itIndex++] = model;
 
146
    it[itIndex++] = level;
 
147
}
 
148
 
 
149
 
 
150
void
 
151
sec2group_oid(oid * it, size_t * len, int model, const char *name)
 
152
{
 
153
    int             i;
 
154
 
 
155
    int             itIndex = SEC2GROUP_OID_LEN;
 
156
 
 
157
    *len = itIndex + 2 + strlen(name);
 
158
 
 
159
    it[itIndex++] = model;
 
160
 
 
161
    it[itIndex++] = strlen(name);
 
162
    for (i = 0; i < (int) strlen(name); i++)
 
163
        it[itIndex++] = name[i];
 
164
}
 
165
 
 
166
void
 
167
view_oid(oid * it, size_t * len, const char *viewName, char *viewSubtree)
 
168
{
 
169
    int             i;
 
170
    oid             c_oid[SPRINT_MAX_LEN];
 
171
    size_t          c_oid_length = SPRINT_MAX_LEN;
 
172
 
 
173
    int             itIndex = VIEW_OID_LEN;
 
174
 
 
175
    if (!snmp_parse_oid(viewSubtree, c_oid, &c_oid_length)) {
 
176
        printf("Error parsing subtree (%s)\n", viewSubtree);
 
177
        exit(1);
 
178
    }
 
179
 
 
180
    *len = itIndex + 2 + strlen(viewName) + c_oid_length;
 
181
 
 
182
    it[itIndex++] = strlen(viewName);
 
183
    for (i = 0; i < (int) strlen(viewName); i++)
 
184
        it[itIndex++] = viewName[i];
 
185
 
 
186
    
 
187
    it[itIndex++] = c_oid_length;
 
188
    for (i = 0; i < (int) c_oid_length; i++)
 
189
        it[itIndex++] = c_oid[i];
 
190
 
 
191
    /*
 
192
     * sprint_objid(c_oid, it, *len); 
 
193
     */
 
194
}
 
195
 
 
196
static void
 
197
optProc(int argc, char *const *argv, int opt)
 
198
{
 
199
    switch (opt) {
 
200
    case 'C':
 
201
        while (*optarg) {
 
202
            switch (*optarg++) {
 
203
            case 'e':
 
204
                viewTreeFamilyType = 2;
 
205
                break;
 
206
 
 
207
            default:
 
208
                fprintf(stderr,
 
209
                        "Unknown flag passed to -C: %c\n", optarg[-1]);
 
210
                exit(1);
 
211
            }
 
212
        }
 
213
        break;
 
214
    }
 
215
}
 
216
 
 
217
 
 
218
int
 
219
main(int argc, char *argv[])
 
220
{
 
221
    netsnmp_session session, *ss;
 
222
    netsnmp_pdu    *pdu = NULL, *response = NULL;
 
223
#ifdef notused
 
224
    netsnmp_variable_list *vars;
 
225
#endif
 
226
 
 
227
    int             arg;
 
228
#ifdef notused
 
229
    int             count;
 
230
    int             current_name = 0;
 
231
    int             current_type = 0;
 
232
    int             current_value = 0;
 
233
    char           *names[128];
 
234
    char            types[128];
 
235
    char           *values[128];
 
236
    oid             name[MAX_OID_LEN];
 
237
#endif
 
238
    size_t          name_length;
 
239
    int             status;
 
240
    int             exitval = 0;
 
241
    int             command = 0;
 
242
    long            longvar;
 
243
    int             secModel, secLevel, contextMatch, val, i = 0;
 
244
    char           *mask, *groupName, *prefix;
 
245
    u_char          viewMask[VACMSTRINGLEN];
 
246
 
 
247
 
 
248
    /*
 
249
     * get the common command line arguments 
 
250
     */
 
251
    switch (arg = snmp_parse_args(argc, argv, &session, "C:", optProc)) {
 
252
    case -2:
 
253
        exit(0);
 
254
    case -1:
 
255
        usage();
 
256
        exit(1);
 
257
    default:
 
258
        break;
 
259
    }
 
260
 
 
261
 
 
262
    SOCK_STARTUP;
 
263
 
 
264
    /*
 
265
     * open an SNMP session 
 
266
     */
 
267
    /*
 
268
     * Note:  this wil obtain the engineID needed below 
 
269
     */
 
270
    ss = snmp_open(&session);
 
271
    if (ss == NULL) {
 
272
        /*
 
273
         * diagnose snmp_open errors with the input netsnmp_session pointer 
 
274
         */
 
275
        snmp_sess_perror("snmpvacm", &session);
 
276
        exit(1);
 
277
    }
 
278
 
 
279
    /*
 
280
     * create PDU for SET request and add object names and values to request 
 
281
     */
 
282
    pdu = snmp_pdu_create(SNMP_MSG_SET);
 
283
 
 
284
    if (arg >= argc) {
 
285
        fprintf(stderr, "Please specify a operation to perform.\n");
 
286
        usage();
 
287
        exit(1);
 
288
    }
 
289
 
 
290
    if (strcmp(argv[arg], CMD_DELETEVIEW_NAME) == 0)
 
291
        /*
 
292
         * deleteView: delete a view
 
293
         *
 
294
         * deleteView NAME SUBTREE
 
295
         *
 
296
         */
 
297
    {
 
298
        if (++arg + 2 != argc) {
 
299
            fprintf(stderr, "You must specify the view to delete\n");
 
300
            usage();
 
301
            exit(1);
 
302
        }
 
303
 
 
304
        command = CMD_DELETEVIEW;
 
305
        name_length = VIEW_OID_LEN;
 
306
        view_oid(vacmViewTreeFamilyStatus, &name_length, argv[arg],
 
307
                 argv[arg + 1]);
 
308
        longvar = RS_DESTROY;
 
309
        snmp_pdu_add_variable(pdu, vacmViewTreeFamilyStatus, name_length,
 
310
                              ASN_INTEGER, (u_char *) & longvar,
 
311
                              sizeof(longvar));
 
312
    } else if (strcmp(argv[arg], CMD_CREATEVIEW_NAME) == 0)
 
313
        /*
 
314
         * createView: create a view
 
315
         *
 
316
         * createView NAME SUBTREE MASK
 
317
         *
 
318
         */
 
319
    {
 
320
        if (++arg + 2 > argc) {
 
321
            fprintf(stderr, "You must specify name, subtree and mask\n");
 
322
            usage();
 
323
            exit(1);
 
324
        }
 
325
        command = CMD_CREATEVIEW;
 
326
        name_length = VIEW_OID_LEN;
 
327
        view_oid(vacmViewTreeFamilyStatus, &name_length, argv[arg],
 
328
                 argv[arg + 1]);
 
329
        longvar = RS_CREATEANDGO;
 
330
        snmp_pdu_add_variable(pdu, vacmViewTreeFamilyStatus, name_length,
 
331
                              ASN_INTEGER, (u_char *) & longvar,
 
332
                              sizeof(longvar));
 
333
        /*
 
334
         * Mask
 
335
         */
 
336
        if (arg + 3 == argc) {
 
337
            mask = argv[arg + 2];
 
338
            for (mask = strtok(mask, ".:"); mask; mask = strtok(NULL, ".:")) {
 
339
                if (i >= sizeof(viewMask)) {
 
340
                    printf("MASK too long\n");
 
341
                    exit(1);
 
342
                }
 
343
                if (sscanf(mask, "%x", &val) == 0) {
 
344
                    printf("invalid MASK\n");
 
345
                    exit(1);
 
346
                }
 
347
                viewMask[i] = val;
 
348
                i++;
 
349
            }
 
350
        } else {
 
351
            for (i=0 ; i < ((int)name_length+7)/8; i++)
 
352
                viewMask[i] = (u_char)0xff;
 
353
        }
 
354
        view_oid(vacmViewTreeFamilyMask, &name_length, argv[arg],
 
355
                 argv[arg + 1]);
 
356
        snmp_pdu_add_variable(pdu, vacmViewTreeFamilyMask, name_length,
 
357
                              ASN_OCTET_STR, viewMask, i);
 
358
 
 
359
        view_oid(vacmViewTreeFamilyType, &name_length, argv[arg],
 
360
                 argv[arg + 1]);
 
361
        snmp_pdu_add_variable(pdu, vacmViewTreeFamilyType, name_length,
 
362
                              ASN_INTEGER, (u_char *) & viewTreeFamilyType,
 
363
                              sizeof(viewTreeFamilyType));
 
364
 
 
365
    } else if (strcmp(argv[arg], CMD_DELETESEC2GROUP_NAME) == 0)
 
366
        /*
 
367
         * deleteSec2Group: delete security2group
 
368
         *
 
369
         * deleteSec2Group  MODEL SECURITYNAME
 
370
         *
 
371
         */
 
372
    {
 
373
        if (++arg + 2 != argc) {
 
374
            fprintf(stderr, "You must specify the sec2group to delete\n");
 
375
            usage();
 
376
            exit(1);
 
377
        }
 
378
 
 
379
        command = CMD_DELETESEC2GROUP;
 
380
        name_length = SEC2GROUP_OID_LEN;
 
381
        if (sscanf(argv[arg], "%d", &secModel) == 0) {
 
382
            printf("invalid security model\n");
 
383
            usage();
 
384
            exit(1);
 
385
        }
 
386
        sec2group_oid(vacmSec2GroupStatus, &name_length, secModel,
 
387
                      argv[arg + 1]);
 
388
        longvar = RS_DESTROY;
 
389
        snmp_pdu_add_variable(pdu, vacmSec2GroupStatus, name_length,
 
390
                              ASN_INTEGER, (u_char *) & longvar,
 
391
                              sizeof(longvar));
 
392
    } else if (strcmp(argv[arg], CMD_CREATESEC2GROUP_NAME) == 0)
 
393
        /*
 
394
         * createSec2Group: create a security2group
 
395
         *
 
396
         * createSec2Group  MODEL SECURITYNAME GROUPNAME
 
397
         *
 
398
         */
 
399
    {
 
400
        if (++arg + 3 != argc) {
 
401
            fprintf(stderr,
 
402
                    "You must specify model, security name and group name\n");
 
403
            usage();
 
404
            exit(1);
 
405
        }
 
406
 
 
407
        command = CMD_CREATESEC2GROUP;
 
408
        name_length = SEC2GROUP_OID_LEN;
 
409
        if (sscanf(argv[arg], "%d", &secModel) == 0) {
 
410
            printf("invalid security model\n");
 
411
            usage();
 
412
            exit(1);
 
413
        }
 
414
        sec2group_oid(vacmSec2GroupStatus, &name_length, secModel,
 
415
                      argv[arg + 1]);
 
416
        longvar = RS_CREATEANDGO;
 
417
        snmp_pdu_add_variable(pdu, vacmSec2GroupStatus, name_length,
 
418
                              ASN_INTEGER, (u_char *) & longvar,
 
419
                              sizeof(longvar));
 
420
        sec2group_oid(vacmGroupName, &name_length, secModel,
 
421
                      argv[arg + 1]);
 
422
        snmp_pdu_add_variable(pdu, vacmGroupName, name_length,
 
423
                              ASN_OCTET_STR, (u_char *) argv[arg + 2],
 
424
                              strlen(argv[arg + 2]));
 
425
    } else if (strcmp(argv[arg], CMD_DELETEACCESS_NAME) == 0)
 
426
        /*
 
427
         * deleteAccess: delete access entry
 
428
         *
 
429
         * deleteAccess  GROUPNAME [CONTEXTPREFIX] SECURITYMODEL SECURITYLEVEL
 
430
         *
 
431
         */
 
432
    {
 
433
        if (++arg + 3 > argc) {
 
434
            fprintf(stderr,
 
435
                    "You must specify the access entry to delete\n");
 
436
            usage();
 
437
            exit(1);
 
438
        }
 
439
 
 
440
        command = CMD_DELETEACCESS;
 
441
        name_length = ACCESS_OID_LEN;
 
442
        groupName = argv[arg];
 
443
        if (arg + 4 == argc)
 
444
            prefix = argv[++arg];
 
445
        else
 
446
            prefix = NULL;
 
447
 
 
448
        if (sscanf(argv[arg + 1], "%d", &secModel) == 0) {
 
449
            printf("invalid security model\n");
 
450
            usage();
 
451
            exit(1);
 
452
        }
 
453
        if (sscanf(argv[arg + 2], "%d", &secLevel) == 0) {
 
454
            printf("invalid security level\n");
 
455
            usage();
 
456
            exit(1);
 
457
        }
 
458
        access_oid(vacmAccessStatus, &name_length, groupName, prefix,
 
459
                   secModel, secLevel);
 
460
        longvar = RS_DESTROY;
 
461
        snmp_pdu_add_variable(pdu, vacmAccessStatus, name_length,
 
462
                              ASN_INTEGER, (u_char *) & longvar,
 
463
                              sizeof(longvar));
 
464
    } else if (strcmp(argv[arg], CMD_CREATEACCESS_NAME) == 0)
 
465
        /*
 
466
         * createAccess: create access entry
 
467
         *
 
468
         * createAccess  GROUPNAME [CONTEXTPREFIX] SECURITYMODEL SECURITYLEVEL CONTEXTMATCH READVIEWNAME WRITEVIEWNAME NOTIFYVIEWNAME
 
469
         *
 
470
         */
 
471
    {
 
472
        if (++arg + 7 > argc) {
 
473
            fprintf(stderr,
 
474
                    "You must specify the access entry to create\n");
 
475
            usage();
 
476
            exit(1);
 
477
        }
 
478
 
 
479
        command = CMD_CREATEACCESS;
 
480
        name_length = ACCESS_OID_LEN;
 
481
        groupName = argv[arg];
 
482
        if (arg + 8 == argc)
 
483
            prefix = argv[++arg];
 
484
        else
 
485
            prefix = NULL;
 
486
 
 
487
        if (sscanf(argv[arg + 1], "%d", &secModel) == 0) {
 
488
            printf("invalid security model\n");
 
489
            usage();
 
490
            exit(1);
 
491
        }
 
492
        if (sscanf(argv[arg + 2], "%d", &secLevel) == 0) {
 
493
            printf("invalid security level\n");
 
494
            usage();
 
495
            exit(1);
 
496
        }
 
497
        access_oid(vacmAccessStatus, &name_length, groupName, prefix,
 
498
                   secModel, secLevel);
 
499
        longvar = RS_CREATEANDGO;
 
500
        snmp_pdu_add_variable(pdu, vacmAccessStatus, name_length,
 
501
                              ASN_INTEGER, (u_char *) & longvar,
 
502
                              sizeof(longvar));
 
503
 
 
504
        access_oid(vacmAccessContextMatch, &name_length, groupName, prefix,
 
505
                   secModel, secLevel);
 
506
        if (sscanf(argv[arg + 3], "%d", &contextMatch) == 0) {
 
507
            printf("invalid contextMatch\n");
 
508
            usage();
 
509
            exit(1);
 
510
        }
 
511
        snmp_pdu_add_variable(pdu, vacmAccessContextMatch, name_length,
 
512
                              ASN_INTEGER, (u_char *) & contextMatch,
 
513
                              sizeof(contextMatch));
 
514
 
 
515
        access_oid(vacmAccessReadViewName, &name_length, groupName, prefix,
 
516
                   secModel, secLevel);
 
517
        snmp_pdu_add_variable(pdu, vacmAccessReadViewName, name_length,
 
518
                              ASN_OCTET_STR, (u_char *) argv[arg + 4],
 
519
                              strlen(argv[arg + 4]));
 
520
 
 
521
        access_oid(vacmAccessWriteViewName, &name_length, groupName,
 
522
                   prefix, secModel, secLevel);
 
523
        snmp_pdu_add_variable(pdu, vacmAccessWriteViewName, name_length,
 
524
                              ASN_OCTET_STR, (u_char *) argv[arg + 5],
 
525
                              strlen(argv[arg + 5]));
 
526
 
 
527
        access_oid(vacmAccessNotifyViewName, &name_length, groupName,
 
528
                   prefix, secModel, secLevel);
 
529
        snmp_pdu_add_variable(pdu, vacmAccessNotifyViewName, name_length,
 
530
                              ASN_OCTET_STR, (u_char *) argv[arg + 6],
 
531
                              strlen(argv[arg + 6]));
 
532
    } else {
 
533
        printf("Unknown command\n");
 
534
        usage();
 
535
        exit(1);
 
536
    }
 
537
 
 
538
    /*
 
539
     * do the request 
 
540
     */
 
541
    status = snmp_synch_response(ss, pdu, &response);
 
542
    if (status == STAT_SUCCESS) {
 
543
        if (response) {
 
544
            if (response->errstat == SNMP_ERR_NOERROR) {
 
545
                fprintf(stderr, "%s\n", successNotes[command - 1]);
 
546
            } else {
 
547
                fprintf(stderr, "Error in packet.\nReason: %s\n",
 
548
                        snmp_errstring(response->errstat));
 
549
                if (response->errindex != 0){
 
550
                    int count;
 
551
                    struct variable_list *vars = response->variables;
 
552
                    fprintf(stderr, "Failed object: ");
 
553
                    for(count = 1; vars && (count != response->errindex);
 
554
                            vars = vars->next_variable, count++)
 
555
                        ;
 
556
                    if (vars)
 
557
                        fprint_objid(stderr, vars->name, vars->name_length);
 
558
                    fprintf(stderr, "\n");
 
559
                }
 
560
                exitval = 2;
 
561
            }
 
562
        }
 
563
    } else if (status == STAT_TIMEOUT) {
 
564
        fprintf(stderr, "Timeout: No Response from %s\n",
 
565
                session.peername);
 
566
        exitval = 1;
 
567
    } else {
 
568
        snmp_sess_perror("snmpset", ss);
 
569
        exitval = 1;
 
570
    }
 
571
 
 
572
    if (response)
 
573
        snmp_free_pdu(response);
 
574
 
 
575
    snmp_close(ss);
 
576
    SOCK_CLEANUP;
 
577
    return exitval;
 
578
}