~ubuntu-branches/ubuntu/wily/apparmor/wily

« back to all changes in this revision

Viewing changes to parser/parser_symtab.c

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2011-04-27 10:38:07 UTC
  • mfrom: (5.1.118 natty)
  • Revision ID: james.westby@ubuntu.com-20110427103807-ym3rhwys6o84ith0
Tags: 2.6.1-2
debian/copyright: clarify for some full organization names.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*       $Id: parser_symtab.c 8 2006-04-12 04:09:10Z steve-beattie $    */
2
 
 
3
1
/*
4
 
 *   Copyright (c) 2005 NOVELL (All rights reserved)
 
2
 *   Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
 
3
 *   NOVELL (All rights reserved)
5
4
 *
6
5
 *   This program is free software; you can redistribute it and/or
7
6
 *   modify it under the terms of version 2 of the GNU General Public
16
15
 *   along with this program; if not, contact Novell, Inc.
17
16
 */
18
17
 
19
 
#define _GNU_SOURCE     /* for tdestroy(3) */
20
18
#include <search.h>
21
19
#include <stdlib.h>
22
20
#include <stdarg.h>
23
21
#include <string.h>
24
22
#include <errno.h>
25
23
#include <libintl.h>
 
24
#include <linux/limits.h>
26
25
#define _(s) gettext(s)
27
26
 
28
27
#include "immunix.h"
33
32
        sd_set,
34
33
};
35
34
 
36
 
struct set_value {
37
 
        char *val;
38
 
        struct set_value *next;
39
 
};
40
 
 
41
35
struct symtab {
42
36
        char *var_name;
43
37
        enum var_type type;
110
104
                free(symtab->var_name);
111
105
 
112
106
        free_values(symtab->values);
 
107
        free_values(symtab->expanded);
113
108
        free(symtab);
114
109
}
115
110
 
287
282
 
288
283
/* returns a pointer to the value list, which should be used as the
289
284
 * argument to the get_next_set_value() function. */
290
 
void *get_set_var(const char *var)
 
285
struct set_value *get_set_var(const char *var)
291
286
{
292
287
        struct symtab *result;
293
288
        struct set_value *valuelist = NULL;
320
315
}
321
316
 
322
317
/* iterator to walk the list of set values */
323
 
char *get_next_set_value(void **list)
 
318
char *get_next_set_value(struct set_value **list)
324
319
{
325
 
        struct set_value **valuelist = (struct set_value **) list;
 
320
        struct set_value *next;
326
321
        char *ret;
327
322
 
328
 
        if (!valuelist || !(*valuelist))
 
323
        if (!list || !(*list))
329
324
                return NULL;
330
325
 
331
 
        ret = (*valuelist)->val;
332
 
        (*valuelist) = (*valuelist)->next;
 
326
        ret = (*list)->val;
 
327
        next = (*list)->next;
 
328
        (*list) = next;
333
329
 
334
330
        return ret;
335
331
}
428
424
 
429
425
                        for (ref_item = ref->expanded; ref_item; ref_item = ref_item->next) {
430
426
                                char *expanded_string;
431
 
                                asprintf(&expanded_string, "%s%s%s",
 
427
                                if (!asprintf(&expanded_string, "%s%s%s",
432
428
                                         split->prefix ?  split->prefix : "",
433
429
                                         ref_item->val,
434
 
                                         split->suffix ?  split->suffix : "");
 
430
                                         split->suffix ?  split->suffix : "")) {
 
431
                                        PERROR("Out of memory\n");
 
432
                                        exit(1);
 
433
                                }
435
434
                                add_to_set(&work_list, expanded_string);
436
435
                                free(expanded_string);
437
436
                        }
532
531
        twalk(my_symtab, &dump_expanded_symtab_entry);
533
532
}
534
533
 
 
534
void free_symtabs(void)
 
535
{
 
536
        if (my_symtab)
 
537
                tdestroy(my_symtab, (__free_fn_t)&free_symtab);
 
538
        my_symtab = NULL;
 
539
}
 
540
 
535
541
#ifdef UNIT_TEST
536
542
#define MY_TEST(statement, error)               \
537
543
        if (!(statement)) {                     \
561
567
{
562
568
        int rc = 0;
563
569
        int retval;
564
 
        void *retptr;
 
570
        struct set_value *retptr;
565
571
        struct symtab *a, *b;
566
572
 
567
573
        a = new_symtab_entry("blah");