~ubuntu-branches/ubuntu/trusty/checkpolicy/trusty

« back to all changes in this revision

Viewing changes to test/dispol.c

  • Committer: Bazaar Package Importer
  • Author(s): Manoj Srivastava
  • Date: 2004-11-24 14:01:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20041124140141-2w64gbhqynveunlv
Tags: 1.18-2
Update download location and copyright file, since the locations we
were pointing to are now forbidden (return a code 403).

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *      displaypol binary_pol_file
18
18
 */
19
19
 
20
 
#include "../policydb.h"
21
 
#include "../avtab.h"
22
 
#include "../services.h"
23
 
#include "../conditional.h"
 
20
#include <sepol/policydb.h>
 
21
#include <sepol/avtab.h>
 
22
#include <sepol/services.h>
 
23
#include <sepol/conditional.h>
24
24
#include <getopt.h>
25
25
#include <assert.h>
 
26
#include <unistd.h>
 
27
#include <stdlib.h>
26
28
#include <sys/stat.h>
27
29
#include <sys/types.h>
28
30
#include <sys/mman.h>
30
32
#include <stdio.h>
31
33
#include <fcntl.h>
32
34
 
33
 
 
34
 
extern policydb_t policydb;
35
 
extern unsigned int ss_initialized;
36
 
 
37
 
/* hack! */
38
 
int avc_ss_reset(__u32 seqno)
39
 
{
40
 
        return 0;
41
 
}
 
35
static policydb_t policydb;
42
36
 
43
37
void usage(char *progname)
44
38
{
66
60
        return 0;
67
61
}
68
62
 
69
 
int render_access_mask(__u32 mask, avtab_key_t *key, policydb_t *p, FILE *fp)
 
63
int render_access_mask(uint32_t mask, avtab_key_t *key, policydb_t *p, FILE *fp)
70
64
{
71
65
        unsigned int i;
72
66
        class_datum_t *cladatum;
90
84
        return 0;
91
85
}
92
86
 
93
 
int render_type(__u32 type, policydb_t *p, FILE *fp)
 
87
int render_type(uint32_t type, policydb_t *p, FILE *fp)
94
88
{
95
89
        fprintf(fp, "%s", p->p_type_val_to_name[type - 1]);
96
90
        return 0;
110
104
#define RENDER_DISABLED         0x0004
111
105
#define RENDER_CONDITIONAL      (RENDER_ENABLED|RENDER_DISABLED)
112
106
 
113
 
int render_av_rule(avtab_key_t *key, avtab_datum_t *datum, __u32 what, policydb_t *p, FILE *fp)
 
107
int render_av_rule(avtab_key_t *key, avtab_datum_t *datum, uint32_t what, policydb_t *p, FILE *fp)
114
108
{
115
109
        if(!(what & RENDER_UNCONDITIONAL)) {
116
110
                if(what != RENDER_CONDITIONAL &&
176
170
        return 0;
177
171
}
178
172
 
179
 
int display_avtab(avtab_t *a, __u32 what, policydb_t *p, FILE *fp)
 
173
int display_avtab(avtab_t *a, uint32_t what, policydb_t *p, FILE *fp)
180
174
{
181
175
        int i;
182
176
        avtab_ptr_t cur;
299
293
        void *map;
300
294
        char *name;
301
295
        int state;
 
296
        struct policy_file pf;
302
297
 
303
298
 
304
299
        if(argc != 2) 
305
300
                usage(argv[0]);
306
 
                
 
301
 
307
302
        fd = open(argv[1], O_RDONLY);
308
303
        if (fd < 0) {
309
304
                fprintf(stderr, "Can't open '%s':  %s\n",
315
310
                        argv[1], strerror(errno));
316
311
                exit(1);
317
312
        }
318
 
        map = mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, fd, 0);
 
313
        map = mmap(NULL, sb.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
319
314
        if (map == MAP_FAILED) {
320
315
                fprintf(stderr, "Can't map '%s':  %s\n",
321
316
                        argv[1], strerror(errno));
324
319
        
325
320
        /* read the binary policy */
326
321
        fprintf(out_fp, "Reading policy...\n");
327
 
        ret = security_load_policy(map,sb.st_size);
 
322
        pf.type = PF_USE_MEMORY;
 
323
        pf.data = map;
 
324
        pf.len = sb.st_size;
 
325
        ret = policydb_read(&policydb, &pf, 1);
328
326
        if (ret) {
329
327
                fprintf(stderr, "%s:  error(s) encountered while parsing configuration\n", argv[0]);
330
328
                exit(1);