1 | /* |
---|
2 | * Copyright (c) 2016 Chris Johns <chrisj@rtems.org>. All rights reserved. |
---|
3 | * |
---|
4 | * Redistribution and use in source and binary forms, with or without |
---|
5 | * modification, are permitted provided that the following conditions |
---|
6 | * are met: |
---|
7 | * 1. Redistributions of source code must retain the above copyright |
---|
8 | * notice, this list of conditions and the following disclaimer. |
---|
9 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
10 | * notice, this list of conditions and the following disclaimer in the |
---|
11 | * documentation and/or other materials provided with the distribution. |
---|
12 | * |
---|
13 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
---|
14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
16 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
---|
17 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
18 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
19 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
20 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
21 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
22 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
23 | * SUCH DAMAGE. |
---|
24 | */ |
---|
25 | |
---|
26 | /* |
---|
27 | * The services available to rc.conf. You define the list you wish to have |
---|
28 | * available in your application and they will be available. |
---|
29 | * |
---|
30 | * A service is a functional unit that can be started. |
---|
31 | */ |
---|
32 | |
---|
33 | #ifndef _RTEMS_BSD_RC_CONF_SERVICES_h |
---|
34 | #define _RTEMS_BSD_RC_CONF_SERVICES_h |
---|
35 | |
---|
36 | #include <sys/queue.h> |
---|
37 | #include <sys/kernel.h> |
---|
38 | |
---|
39 | #include <machine/rtems-bsd-rc-conf.h> |
---|
40 | |
---|
41 | #ifdef __cplusplus |
---|
42 | extern "C" { |
---|
43 | #endif /* __cplusplus */ |
---|
44 | |
---|
45 | /* |
---|
46 | * Structure to pass argc and argv between functions. |
---|
47 | */ |
---|
48 | typedef struct rtems_bsd_rc_conf_argc_argv { |
---|
49 | uint32_t marker; |
---|
50 | char* command; |
---|
51 | int argc; |
---|
52 | const char** argv; |
---|
53 | } rtems_bsd_rc_conf_argc_argv; |
---|
54 | |
---|
55 | /* |
---|
56 | * A service controls a peice of functionalty. It loosely follows the things |
---|
57 | * found in /etc/rc.d in FreeBSD. A service can query the rc.conf file for |
---|
58 | * items of interest. |
---|
59 | */ |
---|
60 | typedef int (*rtems_bsd_rc_conf_service)(rtems_bsd_rc_conf* rc_conf); |
---|
61 | |
---|
62 | /* |
---|
63 | * Register a service. The name is the name of the service and the control |
---|
64 | * string contains the before, after and requires string. |
---|
65 | * |
---|
66 | * The control string has the format of: |
---|
67 | * |
---|
68 | * key:item,item,item; |
---|
69 | * |
---|
70 | * where the keys are: |
---|
71 | * |
---|
72 | * before |
---|
73 | * after |
---|
74 | * require |
---|
75 | * |
---|
76 | * For example "before:telnet;after:net;require:net" |
---|
77 | * |
---|
78 | * Notes |
---|
79 | * |
---|
80 | * 1. The parsing of this string is simple and will not handle any |
---|
81 | * white-space. The tokens are delmiter to delmiter. |
---|
82 | * |
---|
83 | * 2. If there are competing positions in the control string the last one |
---|
84 | * processed is used. After is processed first then 'before'. |
---|
85 | */ |
---|
86 | extern int rtems_bsd_rc_conf_service_add(const char* name, |
---|
87 | const char* control, |
---|
88 | rtems_bsd_rc_conf_service service); |
---|
89 | |
---|
90 | /* |
---|
91 | * Remove a registered a service. |
---|
92 | */ |
---|
93 | extern int rtems_bsd_rc_conf_service_remove(const char* name); |
---|
94 | |
---|
95 | /* |
---|
96 | * Return the name of the file being processed. |
---|
97 | */ |
---|
98 | extern const char* rtems_bsd_rc_conf_name(rtems_bsd_rc_conf* rc_conf); |
---|
99 | |
---|
100 | /* |
---|
101 | * Search for the regular expression in the file for the first occurrence. |
---|
102 | */ |
---|
103 | extern int rtems_bsd_rc_conf_find(rtems_bsd_rc_conf* rc_conf, |
---|
104 | const char* expression, |
---|
105 | rtems_bsd_rc_conf_argc_argv* argc_argv); |
---|
106 | |
---|
107 | /* |
---|
108 | * Search for the next occurance of the regular expression in the file. |
---|
109 | */ |
---|
110 | extern int rtems_bsd_rc_conf_find_next(rtems_bsd_rc_conf* rc_conf, |
---|
111 | rtems_bsd_rc_conf_argc_argv* argc_argv); |
---|
112 | |
---|
113 | /* |
---|
114 | * Create an argc/argv structure. You can reuse this for repeated calls and the |
---|
115 | * rc.conf code manage the resources it uses. Destroy the structure when you |
---|
116 | * have finished. |
---|
117 | */ |
---|
118 | extern rtems_bsd_rc_conf_argc_argv* rtems_bsd_rc_conf_argc_argv_create(void); |
---|
119 | |
---|
120 | /* |
---|
121 | * Destroy the argc/argv structure. |
---|
122 | */ |
---|
123 | extern void rtems_bsd_rc_conf_argc_argv_destroy(rtems_bsd_rc_conf_argc_argv* argc_argv); |
---|
124 | |
---|
125 | /* |
---|
126 | * Return the name of the rc.conf file. |
---|
127 | */ |
---|
128 | extern const char* rtems_bsd_rc_conf_name(rtems_bsd_rc_conf* rc_conf); |
---|
129 | |
---|
130 | /* |
---|
131 | * Return the current find line. |
---|
132 | */ |
---|
133 | extern int rtems_bsd_rc_conf_line(rtems_bsd_rc_conf* rc_conf); |
---|
134 | |
---|
135 | /* |
---|
136 | * Return the verbose state. |
---|
137 | */ |
---|
138 | extern bool rtems_bsd_rc_conf_verbose(rtems_bsd_rc_conf* rc_conf); |
---|
139 | |
---|
140 | /* |
---|
141 | * Print the argv list. Helper for verbose modes. |
---|
142 | */ |
---|
143 | extern void rtems_bsd_rc_conf_print_cmd(rtems_bsd_rc_conf* rc_conf, |
---|
144 | const char* name, |
---|
145 | int arvc, |
---|
146 | const char** argv); |
---|
147 | |
---|
148 | /* |
---|
149 | * Use the same SYSINT for all directives. |
---|
150 | */ |
---|
151 | #define RTEMS_BSD_RC_CONF_SYSINT(_n) \ |
---|
152 | SYSINIT(_n, SI_SUB_CREATE_INIT, SI_ORDER_ANY, _n ## _init, NULL) |
---|
153 | |
---|
154 | /* |
---|
155 | * Decls for the handlers. |
---|
156 | */ |
---|
157 | void rc_conf_net_init(void* arg); /* Installed by default. */ |
---|
158 | void rc_conf_firewall_pf_init(void* arg); /* pf_enabled="YES" */ |
---|
159 | void rc_conf_telnetd_init(void* arg); /* telnetd_enabled="YES" */ |
---|
160 | void rc_conf_ftpd_init(void* arg); /* ftpd_enabled="YES" */ |
---|
161 | |
---|
162 | /* |
---|
163 | * Added services. |
---|
164 | */ |
---|
165 | /* add here */ |
---|
166 | |
---|
167 | #ifdef __cplusplus |
---|
168 | } |
---|
169 | #endif /* __cplusplus */ |
---|
170 | |
---|
171 | #endif |
---|