blob: a1fa4fdce5c48cc6b9cad79f9b8c8aa47923a17b [file] [log] [blame]
Joshua Brindle13cd4c82008-08-19 15:30:36 -04001/*
2 * This file describes the internal interface used by the labeler
3 * for calling the user-supplied memory allocation, validation,
4 * and locking routine.
5 *
6 * Author : Eamon Walsh <ewalsh@epoch.ncsc.mil>
7 */
8#ifndef _SELABEL_INTERNAL_H_
9#define _SELABEL_INTERNAL_H_
10
11#include <stdlib.h>
12#include <stdarg.h>
13#include <selinux/selinux.h>
14#include <selinux/label.h>
15#include "dso.h"
16
17/*
18 * Installed backends
19 */
20int selabel_file_init(struct selabel_handle *rec, struct selinux_opt *opts,
21 unsigned nopts) hidden;
22int selabel_media_init(struct selabel_handle *rec, struct selinux_opt *opts,
23 unsigned nopts) hidden;
24int selabel_x_init(struct selabel_handle *rec, struct selinux_opt *opts,
25 unsigned nopts) hidden;
Eamon Walsh70aeeb92010-03-15 18:38:35 -040026int selabel_db_init(struct selabel_handle *rec,
27 struct selinux_opt *opts, unsigned nopts) hidden;
rpcraigcfc492c2012-05-31 17:09:29 -040028int selabel_property_init(struct selabel_handle *rec,
29 struct selinux_opt *opts, unsigned nopts) hidden;
Joshua Brindle13cd4c82008-08-19 15:30:36 -040030
31/*
32 * Labeling internal structures
33 */
Eamon Walsha00fd942010-12-02 19:21:10 -050034struct selabel_sub {
35 char *src;
36 int slen;
37 char *dst;
38 struct selabel_sub *next;
39};
40
Richard Haines441cf2e2011-04-18 16:41:40 +010041extern struct selabel_sub *selabel_subs_init(const char *path,
42 struct selabel_sub *list);
43
Joshua Brindle13cd4c82008-08-19 15:30:36 -040044struct selabel_lookup_rec {
Stephen Smalley9eb9c932014-02-19 09:16:17 -050045 char * ctx_raw;
46 char * ctx_trans;
Joshua Brindle13cd4c82008-08-19 15:30:36 -040047 int validated;
48};
49
50struct selabel_handle {
51 /* arguments that were passed to selabel_open */
52 unsigned int backend;
53 int validating;
54
55 /* labeling operations */
56 struct selabel_lookup_rec *(*func_lookup) (struct selabel_handle *h,
57 const char *key, int type);
58 void (*func_close) (struct selabel_handle *h);
59 void (*func_stats) (struct selabel_handle *h);
60
61 /* supports backend-specific state information */
62 void *data;
Eamon Walsha00fd942010-12-02 19:21:10 -050063
Richard Haines16a37c92011-12-19 16:51:29 +000064 /*
65 * The main spec file used. Note for file contexts the local and/or
66 * homedirs could also have been used to resolve a context.
67 */
68 char *spec_file;
69
Eamon Walsha00fd942010-12-02 19:21:10 -050070 /* substitution support */
Dan Walshfd56c522013-10-09 15:22:54 -040071 struct selabel_sub *dist_subs;
Eamon Walsha00fd942010-12-02 19:21:10 -050072 struct selabel_sub *subs;
Joshua Brindle13cd4c82008-08-19 15:30:36 -040073};
74
75/*
76 * Validation function
77 */
78extern int
79selabel_validate(struct selabel_handle *rec,
80 struct selabel_lookup_rec *contexts) hidden;
81
82/*
83 * Compatibility support
84 */
85extern int myprintf_compat;
86extern void __attribute__ ((format(printf, 1, 2)))
87(*myprintf) (const char *fmt,...);
88
89#define COMPAT_LOG(type, fmt...) if (myprintf_compat) \
90 myprintf(fmt); \
91 else \
92 selinux_log(type, fmt);
93
94extern int
95compat_validate(struct selabel_handle *rec,
96 struct selabel_lookup_rec *contexts,
97 const char *path, unsigned lineno) hidden;
98
99#endif /* _SELABEL_INTERNAL_H_ */