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

« back to all changes in this revision

Viewing changes to snmplib/vacm.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2007-12-08 14:59:50 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20071208145950-u1tykhpw56nyzqik
Tags: 5.4.1~dfsg-4ubuntu1
* Merge from debian unstable.
* Remaining Ubuntu changes:
  - Remove stop links from rc0 and rc6
  - Munge Maintainer field as per spec.
* Ubuntu changes dropped:
  - Symlink common files between the packages, CDBS ought to handle that
    for us automatically.
* The latest Debian changes has dropped history from the changelog. Slot in
  the Ubuntu changes as best I can. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
static struct vacm_accessEntry *accessList = NULL, *accessScanPtr = NULL;
69
69
static struct vacm_groupEntry *groupList = NULL, *groupScanPtr = NULL;
70
70
 
 
71
/*
 
72
 * Macro to extend view masks with 1 bits when shorter than subtree lengths
 
73
 * REF: vacmViewTreeFamilyMask [RFC3415], snmpNotifyFilterMask [RFC3413]
 
74
 */
 
75
 
 
76
#define VIEW_MASK(viewPtr, idx, mask) \
 
77
    ((idx >= viewPtr->viewMaskLen) ? mask : (viewPtr->viewMask[idx] & mask))
 
78
 
71
79
/**
72
80
 * Initilizes the VACM code.
73
81
 * Specifically:
99
107
    struct vacm_viewEntry *vptr;
100
108
    struct vacm_accessEntry *aptr;
101
109
    struct vacm_groupEntry *gptr;
 
110
    int i;
102
111
 
103
112
    for (vptr = viewList; vptr != NULL; vptr = vptr->next) {
104
113
        if (vptr->viewStorageType == ST_NONVOLATILE)
106
115
    }
107
116
 
108
117
    for (aptr = accessList; aptr != NULL; aptr = aptr->next) {
109
 
        if (aptr->storageType == ST_NONVOLATILE)
110
 
            vacm_save_access(aptr, token, type);
 
118
        if (aptr->storageType == ST_NONVOLATILE) {
 
119
            /* Store the standard views (if set) */
 
120
            if ( aptr->views[VACM_VIEW_READ  ][0] ||
 
121
                 aptr->views[VACM_VIEW_WRITE ][0] ||
 
122
                 aptr->views[VACM_VIEW_NOTIFY][0] )
 
123
                vacm_save_access(aptr, token, type);
 
124
            /* Store any other (valid) access views */
 
125
            for ( i=VACM_VIEW_NOTIFY+1; i<VACM_MAX_VIEWS; i++ ) {
 
126
                if ( aptr->views[i][0] )
 
127
                    vacm_save_auth_access(aptr, token, type, i);
 
128
            }
 
129
        }
111
130
    }
112
131
 
113
132
    for (gptr = groupList; gptr != NULL; gptr = gptr->next) {
134
153
 
135
154
    cptr =
136
155
        read_config_save_octet_string(cptr, (u_char *) view->viewName + 1,
137
 
                                      view->viewName[0] + 1);
 
156
                                      view->viewName[0]);
138
157
    *cptr++ = ' ';
139
158
    cptr =
140
159
        read_config_save_objid(cptr, view->viewSubtree+1,
229
248
}
230
249
 
231
250
void
232
 
vacm_parse_config_access(const char *token, char *line)
 
251
vacm_save_auth_access(struct vacm_accessEntry *access_entry,
 
252
                      const char *token, const char *type, int authtype)
 
253
{
 
254
    char            line[4096];
 
255
    char           *cptr;
 
256
 
 
257
    memset(line, 0, sizeof(line));
 
258
    snprintf(line, sizeof(line), "%s%s %d %d %d %d %d ",
 
259
            token, "AuthAccess", access_entry->status,
 
260
            access_entry->storageType, access_entry->securityModel,
 
261
            access_entry->securityLevel, access_entry->contextMatch);
 
262
    line[ sizeof(line)-1 ] = 0;
 
263
    cptr = &line[strlen(line)]; /* the NULL */
 
264
    cptr =
 
265
        read_config_save_octet_string(cptr,
 
266
                                      (u_char *) access_entry->groupName + 1,
 
267
                                      access_entry->groupName[0] + 1);
 
268
    *cptr++ = ' ';
 
269
    cptr =
 
270
        read_config_save_octet_string(cptr,
 
271
                                      (u_char *) access_entry->contextPrefix + 1,
 
272
                                      access_entry->contextPrefix[0] + 1);
 
273
 
 
274
    snprintf(cptr, sizeof(line)-(cptr-line), " %d ", authtype);
 
275
    while ( *cptr )
 
276
        cptr++;
 
277
 
 
278
    *cptr++ = ' ';
 
279
    cptr = read_config_save_octet_string(cptr,
 
280
                               (u_char *)access_entry->views[authtype],
 
281
                                  strlen(access_entry->views[authtype]) + 1);
 
282
 
 
283
    read_config_store(type, line);
 
284
}
 
285
 
 
286
char *
 
287
_vacm_parse_config_access_common(struct vacm_accessEntry **aptr, char *line)
233
288
{
234
289
    struct vacm_accessEntry access;
235
 
    struct vacm_accessEntry *aptr;
236
 
    char           *contextPrefix = (char *) &access.contextPrefix;
237
 
    char           *groupName = (char *) &access.groupName;
238
 
    char           *readView, *writeView, *notifyView;
 
290
    char           *cPrefix = (char *) &access.contextPrefix;
 
291
    char           *gName   = (char *) &access.groupName;
239
292
    size_t          len;
240
293
 
241
294
    access.status = atoi(line);
248
301
    line = skip_token(line);
249
302
    access.contextMatch = atoi(line);
250
303
    line = skip_token(line);
251
 
    len = sizeof(access.groupName);
252
 
    line =
253
 
        read_config_read_octet_string(line, (u_char **) & groupName, &len);
254
 
    len = sizeof(access.contextPrefix);
255
 
    line =
256
 
        read_config_read_octet_string(line, (u_char **) & contextPrefix,
257
 
                                      &len);
258
 
 
259
 
    aptr = vacm_createAccessEntry(access.groupName, access.contextPrefix,
260
 
                                  access.securityModel,
261
 
                                  access.securityLevel);
262
 
    if (!aptr)
 
304
    len  = sizeof(access.groupName);
 
305
    line = read_config_read_octet_string(line, (u_char **) &gName,   &len);
 
306
    len  = sizeof(access.contextPrefix);
 
307
    line = read_config_read_octet_string(line, (u_char **) &cPrefix, &len);
 
308
 
 
309
    *aptr = vacm_getAccessEntry(access.groupName,
 
310
                                  access.contextPrefix,
 
311
                                  access.securityModel,
 
312
                                  access.securityLevel);
 
313
    if (!*aptr)
 
314
        *aptr = vacm_createAccessEntry(access.groupName,
 
315
                                  access.contextPrefix,
 
316
                                  access.securityModel,
 
317
                                  access.securityLevel);
 
318
    if (!*aptr)
 
319
        return NULL;
 
320
 
 
321
    (*aptr)->status = access.status;
 
322
    (*aptr)->storageType   = access.storageType;
 
323
    (*aptr)->securityModel = access.securityModel;
 
324
    (*aptr)->securityLevel = access.securityLevel;
 
325
    (*aptr)->contextMatch  = access.contextMatch;
 
326
    return line;
 
327
}
 
328
 
 
329
void
 
330
vacm_parse_config_access(const char *token, char *line)
 
331
{
 
332
    struct vacm_accessEntry *aptr;
 
333
    char           *readView, *writeView, *notifyView;
 
334
    size_t          len;
 
335
 
 
336
    line = _vacm_parse_config_access_common(&aptr, line);
 
337
    if (!line)
263
338
        return;
264
339
 
265
 
    aptr->status = access.status;
266
 
    aptr->storageType = access.storageType;
267
 
    aptr->securityModel = access.securityModel;
268
 
    aptr->securityLevel = access.securityLevel;
269
 
    aptr->contextMatch = access.contextMatch;
270
340
    readView = (char *) aptr->views[VACM_VIEW_READ];
271
341
    len = sizeof(aptr->views[VACM_VIEW_READ]);
272
342
    line =
282
352
                                      &len);
283
353
}
284
354
 
 
355
void
 
356
vacm_parse_config_auth_access(const char *token, char *line)
 
357
{
 
358
    struct vacm_accessEntry *aptr;
 
359
    int             authtype;
 
360
    char           *view;
 
361
    size_t          len;
 
362
 
 
363
    line = _vacm_parse_config_access_common(&aptr, line);
 
364
    if (!line)
 
365
        return;
 
366
 
 
367
    authtype = atoi(line);
 
368
    line = skip_token(line);
 
369
 
 
370
    view = (char *) aptr->views[authtype];
 
371
    len  = sizeof(aptr->views[authtype]);
 
372
    line = read_config_read_octet_string(line, (u_char **) & view, &len);
 
373
}
 
374
 
285
375
/*
286
376
 * vacm_save_group(): saves a group entry to the persistent cache 
287
377
 */
363
453
            int             oidpos;
364
454
            found = 1;
365
455
 
366
 
            if (mode != VACM_MODE_IGNORE_MASK) {  /* check the mask */
367
 
                for (oidpos = 0;
368
 
                     found && oidpos < (int) vp->viewSubtreeLen - 1;
369
 
                     oidpos++) {
370
 
                    if ((vp->viewMask[maskpos] & mask) != 0) {
371
 
                        if (viewSubtree[oidpos] !=
372
 
                            vp->viewSubtree[oidpos + 1])
373
 
                            found = 0;
374
 
                    }
375
 
                    if (mask == 1) {
376
 
                        mask = 0x80;
377
 
                        maskpos++;
378
 
                    } else
379
 
                        mask >>= 1;
 
456
            for (oidpos = 0;
 
457
                 found && oidpos < (int) vp->viewSubtreeLen - 1;
 
458
                 oidpos++) {
 
459
                if (mode==VACM_MODE_IGNORE_MASK || (VIEW_MASK(vp, maskpos, mask)) != 0) {
 
460
                    if (viewSubtree[oidpos] !=
 
461
                        vp->viewSubtree[oidpos + 1])
 
462
                        found = 0;
380
463
                }
 
464
                if (mask == 1) {
 
465
                    mask = 0x80;
 
466
                    maskpos++;
 
467
                } else
 
468
                    mask >>= 1;
381
469
            }
 
470
 
382
471
            if (found) {
383
472
                /*
384
473
                 * match successful, keep this node if its longer than
440
529
        return VACM_NOTINVIEW;
441
530
    view[0] = glen;
442
531
    strcpy(view + 1, viewName);
 
532
    DEBUGMSGTL(("9:vacm:checkSubtree", "view %s\n", viewName));
443
533
    for (vp = head; vp; vp = vp->next) {
444
534
        if (!memcmp(view, vp->viewName, glen + 1)) {
445
535
            /*
458
548
                for (oidpos = 0;
459
549
                     found && oidpos < (int) vp->viewSubtreeLen - 1;
460
550
                     oidpos++) {
461
 
                    if ((vp->viewMask[maskpos] & mask) != 0) {
 
551
                    if (VIEW_MASK(vp, maskpos, mask) != 0) {
462
552
                        if (viewSubtree[oidpos] !=
463
553
                            vp->viewSubtree[oidpos + 1])
464
554
                            found = 0;
476
566
                     * the previous or (equal and lexicographically greater
477
567
                     * than the previous). 
478
568
                     */
 
569
                    DEBUGMSGTL(("9:vacm:checkSubtree", " %s matched?\n", vp->viewName));
479
570
    
480
571
                    if (vpShorter == NULL
481
572
                        || vp->viewSubtreeLen > vpShorter->viewSubtreeLen
505
596
                for (oidpos = 0;
506
597
                     found && oidpos < (int) viewSubtreeLen;
507
598
                     oidpos++) {
508
 
                    if ((vp->viewMask[maskpos] & mask) != 0) {
 
599
                    if (VIEW_MASK(vp, maskpos, mask) != 0) {
509
600
                        if (viewSubtree[oidpos] !=
510
601
                            vp->viewSubtree[oidpos + 1])
511
602
                            found = 0;
523
614
                     * with a different view type, then parts of the subtree 
524
615
                     * are included and others are excluded, so return UNKNOWN.
525
616
                     */
 
617
                    DEBUGMSGTL(("9:vacm:checkSubtree", " %s matched?\n", vp->viewName));
526
618
                    if (vpLonger != NULL
527
619
                        && (vpLonger->viewType != vp->viewType)) {
528
620
                        DEBUGMSGTL(("vacm:checkSubtree", ", %s\n", "unknown"));
535
627
            }
536
628
        }
537
629
    }
 
630
    DEBUGMSGTL(("9:vacm:checkSubtree", " %s matched\n", vp->viewName));
538
631
 
539
632
    /*
540
633
     * If we found a matching view subtree with a longer OID than the provided
894
987
            break;
895
988
        if (cmp < 0)
896
989
            goto next;
 
990
        if (lp->securityModel > securityModel)
 
991
            break;
897
992
        if (lp->securityModel < securityModel)
898
 
            break;
899
 
        if (lp->securityModel > securityModel)
900
993
            goto next;
901
 
        if (lp->securityLevel < securityLevel)
 
994
        if (lp->securityLevel > securityLevel)
902
995
            break;
903
996
      next:
904
997
        op = lp;