• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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  */
20 int selabel_file_init(struct selabel_handle *rec, struct selinux_opt *opts,
21 		      unsigned nopts) hidden;
22 int selabel_media_init(struct selabel_handle *rec, struct selinux_opt *opts,
23 		      unsigned nopts) hidden;
24 int selabel_x_init(struct selabel_handle *rec, struct selinux_opt *opts,
25 		   unsigned nopts) hidden;
26 int selabel_db_init(struct selabel_handle *rec,
27 		    struct selinux_opt *opts, unsigned nopts) hidden;
28 int selabel_property_init(struct selabel_handle *rec,
29 			  struct selinux_opt *opts, unsigned nopts) hidden;
30 
31 /*
32  * Labeling internal structures
33  */
34 struct selabel_sub {
35 	char *src;
36 	int slen;
37 	char *dst;
38 	struct selabel_sub *next;
39 };
40 
41 extern struct selabel_sub *selabel_subs_init(const char *path,
42 					     struct selabel_sub *list);
43 
44 struct selabel_lookup_rec {
45 	char * ctx_raw;
46 	char * ctx_trans;
47 	int validated;
48 };
49 
50 struct 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;
63 
64 	/*
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 
70 	/* substitution support */
71 	struct selabel_sub *dist_subs;
72 	struct selabel_sub *subs;
73 };
74 
75 /*
76  * Validation function
77  */
78 extern int
79 selabel_validate(struct selabel_handle *rec,
80 		 struct selabel_lookup_rec *contexts) hidden;
81 
82 /*
83  * Compatibility support
84  */
85 extern int myprintf_compat;
86 extern 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 
94 extern int
95 compat_validate(struct selabel_handle *rec,
96 		struct selabel_lookup_rec *contexts,
97 		const char *path, unsigned lineno) hidden;
98 
99 #endif				/* _SELABEL_INTERNAL_H_ */
100