author | David Powell <david.e.powell@oracle.com> |
Tue, 23 Nov 2010 15:54:20 -0800 | |
changeset 604 | 20d9acfeb7fb |
parent 595 | 725a82f60b1c |
child 664 | bf20f6a9e353 |
permissions | -rw-r--r-- |
391 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
5 |
* Common Development and Distribution License (the "License"). |
|
6 |
* You may not use this file except in compliance with the License. |
|
7 |
* |
|
8 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 |
* or http://www.opensolaris.org/os/licensing. |
|
10 |
* See the License for the specific language governing permissions |
|
11 |
* and limitations under the License. |
|
12 |
* |
|
13 |
* When distributing Covered Code, include this CDDL HEADER in each |
|
14 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 |
* If applicable, add the following below this CDDL HEADER, with the |
|
16 |
* fields enclosed by brackets "[]" replaced with your own identifying |
|
17 |
* information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 |
* |
|
19 |
* CDDL HEADER END |
|
20 |
*/ |
|
21 |
||
22 |
/* |
|
500
d134d555588f
15908 create accessors for all ADR data
David Powell <david.e.powell@oracle.com>
parents:
472
diff
changeset
|
23 |
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
391 | 24 |
*/ |
25 |
||
26 |
#include <sys/wait.h> |
|
401
fc1223edbd8d
13421 apache: o.o.o.rad.ContainerException: system error: error talking to slave
David Powell <David.Powell@sun.com>
parents:
391
diff
changeset
|
27 |
#include <sys/stat.h> |
391 | 28 |
#include <stdio.h> |
29 |
#include <stdlib.h> |
|
30 |
#include <signal.h> |
|
31 |
#include <unistd.h> |
|
32 |
#include <locale.h> |
|
33 |
#include <libscf.h> |
|
34 |
#include <errno.h> |
|
35 |
#include <string.h> |
|
36 |
||
37 |
#include <libxml/parser.h> |
|
555
399f1dff49b2
16728 rad uses openssl naively
David Powell <david.e.powell@oracle.com>
parents:
540
diff
changeset
|
38 |
#include <rad/adr_stream.h> |
391 | 39 |
|
540
2a0d274b1469
16571 move all content module interfaces into rad_modapi.h
David Powell <david.e.powell@oracle.com>
parents:
500
diff
changeset
|
40 |
#include "rad.h" |
391 | 41 |
#include "rad_object.h" |
573
f0add9469f92
17058 support removing objects
David Powell <david.e.powell@oracle.com>
parents:
555
diff
changeset
|
42 |
#include "rad_container.h" |
391 | 43 |
#include "rad_module.h" |
44 |
#include "rad_xport.h" |
|
45 |
#include "rad_pam.h" |
|
46 |
#include "rad_ticket.h" |
|
47 |
#include "rad_control.h" |
|
48 |
#include "rad_smf.h" |
|
540
2a0d274b1469
16571 move all content module interfaces into rad_modapi.h
David Powell <david.e.powell@oracle.com>
parents:
500
diff
changeset
|
49 |
#include "rad_modapi.h" |
436
c28d8d667ea1
14688 slave daemons should be placed in own contracts
David Powell <David.Powell@sun.com>
parents:
401
diff
changeset
|
50 |
#include "rad_slave.h" |
391 | 51 |
|
52 |
#include "api_config.h" |
|
53 |
||
54 |
#if !defined(TEXT_DOMAIN) |
|
55 |
#define TEXT_DOMAIN "SYS_TEST" |
|
56 |
#endif |
|
57 |
||
604
20d9acfeb7fb
17421 name key order preservation
David Powell <david.e.powell@oracle.com>
parents:
595
diff
changeset
|
58 |
rad_container_t rad_container_auth; |
20d9acfeb7fb
17421 name key order preservation
David Powell <david.e.powell@oracle.com>
parents:
595
diff
changeset
|
59 |
rad_container_t rad_container_unauth; |
20d9acfeb7fb
17421 name key order preservation
David Powell <david.e.powell@oracle.com>
parents:
595
diff
changeset
|
60 |
rad_container_t rad_container_control; |
575
e5ca78dfe938
17085 add component prefixes to adr's method/attribute
David Powell <david.e.powell@oracle.com>
parents:
573
diff
changeset
|
61 |
rad_container_t *rad_container = &rad_container_auth; |
540
2a0d274b1469
16571 move all content module interfaces into rad_modapi.h
David Powell <david.e.powell@oracle.com>
parents:
500
diff
changeset
|
62 |
|
391 | 63 |
int rad_exit_failure = 1; |
64 |
int rad_exit_config = 1; |
|
65 |
boolean_t rad_isproxy = B_FALSE; |
|
595
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
66 |
data_t *rad_moduledirs; |
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
67 |
data_t *rad_modules; |
391 | 68 |
|
69 |
const char * |
|
70 |
_umem_debug_init() |
|
71 |
{ |
|
72 |
return ("default"); |
|
73 |
} |
|
74 |
||
75 |
/* |
|
76 |
* rad(1M) Configuration |
|
77 |
* --------------------- |
|
78 |
* |
|
79 |
* rad(1M) configuration can be obtained from two sources. Firstly, if |
|
80 |
* rad is started from SMF and the -s option is specified, it will obtain |
|
81 |
* configuration from the corresponding service instance. Secondly, |
|
82 |
* command line arguments can be provided to specify a particular |
|
83 |
* configuration. If configuration is available from both sources, |
|
84 |
* command line configuration is processed before SMF configuration. |
|
85 |
* |
|
86 |
* There are two things that are configurable in rad(1M). |
|
87 |
* |
|
88 |
* 1) The set of directories to scan for modules: |
|
89 |
* SMF: config/moduledir astring[] |
|
90 |
* Command line: '-m <moduledir>' option |
|
91 |
* |
|
92 |
* 2) The set of endpoints to listen on |
|
93 |
* SMF: <pgname>:xport_<xport type> / * |
|
94 |
* Command line: '-t <transport>[:opt1[=val1][,opt2[=val2]...]]' |
|
95 |
* |
|
96 |
* Available transports are 'stdin', 'tcp', 'tls', and 'uds'. |
|
97 |
* All transports take a 'proto' option, which defaults to 'rad'. |
|
98 |
* 'tcp' and 'tls' require a 'port' option. 'uds' requires a |
|
99 |
* 'path' option. |
|
100 |
*/ |
|
101 |
||
102 |
static int |
|
103 |
rad_service_wait() |
|
104 |
{ |
|
105 |
int status; |
|
106 |
pid_t pid; |
|
107 |
int fds[2]; |
|
108 |
||
109 |
if (pipe(fds) == -1) |
|
110 |
rad_log(RL_FATAL, "unable to create pipe: %s", strerror(errno)); |
|
111 |
||
112 |
if ((pid = fork()) == -1) |
|
113 |
rad_log(RL_FATAL, "unable to fork daemon: %s", strerror(errno)); |
|
114 |
||
115 |
if (pid > 0) { |
|
116 |
pid_t wpid; |
|
117 |
||
118 |
(void) close(fds[1]); |
|
119 |
if (read(fds[0], &status, sizeof (status)) == sizeof (status)) |
|
120 |
_exit(status); |
|
121 |
||
122 |
do { |
|
123 |
wpid = waitpid(pid, &status, 0); |
|
124 |
} while (wpid != pid && errno == EINTR); |
|
125 |
if (WIFEXITED(status)) |
|
126 |
_exit(WEXITSTATUS(status)); |
|
127 |
_exit(SMF_EXIT_ERR_FATAL); |
|
128 |
} |
|
129 |
||
130 |
(void) close(fds[0]); |
|
131 |
return (fds[1]); |
|
132 |
} |
|
133 |
||
134 |
static void |
|
135 |
rad_service_done(int fd) |
|
136 |
{ |
|
137 |
int status = SMF_EXIT_OK; |
|
138 |
(void) write(fd, &status, sizeof (status)); |
|
139 |
} |
|
140 |
||
141 |
/* -s is for SMF consumption only; not documented */ |
|
142 |
static const char *usage = |
|
595
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
143 |
"Usage: rad [ -d ] [ -S fmri ] [ -m moduledir ] [ -M modules ] " |
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
144 |
"[ -t transport ]\n"; |
391 | 145 |
|
146 |
int |
|
147 |
main(int argc, char **argv) |
|
148 |
{ |
|
149 |
int opt, i; |
|
595
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
150 |
int nxport = 0, nmoddir = 0, nmods = 0; |
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
151 |
const char *xports[argc], *moddirs[argc], *mods[argc]; |
391 | 152 |
boolean_t smf_startup = B_FALSE; |
153 |
boolean_t smf_config = B_FALSE; |
|
154 |
const char *smf_fmri = NULL; |
|
155 |
sigset_t hupset; |
|
156 |
int svc_fd = -1; |
|
157 |
||
401
fc1223edbd8d
13421 apache: o.o.o.rad.ContainerException: system error: error talking to slave
David Powell <David.Powell@sun.com>
parents:
391
diff
changeset
|
158 |
(void) umask(077); |
391 | 159 |
(void) setlocale(LC_ALL, ""); |
160 |
(void) textdomain(TEXT_DOMAIN); |
|
161 |
||
162 |
(void) sigemptyset(&hupset); |
|
163 |
(void) sigaddset(&hupset, SIGHUP); |
|
164 |
(void) sigprocmask(SIG_BLOCK, &hupset, NULL); |
|
165 |
(void) sigignore(SIGPIPE); |
|
166 |
(void) sigignore(SIGCHLD); |
|
167 |
||
595
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
168 |
while ((opt = getopt(argc, argv, "dpsS:t:m:M:")) != EOF) { |
391 | 169 |
switch (opt) { |
170 |
case 't': |
|
171 |
xports[nxport++] = optarg; |
|
172 |
break; |
|
173 |
case 'm': |
|
174 |
moddirs[nmoddir++] = optarg; |
|
175 |
break; |
|
595
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
176 |
case 'M': |
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
177 |
mods[nmods++] = optarg; |
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
178 |
break; |
391 | 179 |
case 'p': |
180 |
rad_isproxy = B_TRUE; |
|
181 |
break; |
|
182 |
case 's': |
|
183 |
smf_startup = B_TRUE; |
|
184 |
smf_config = B_TRUE; |
|
185 |
rad_exit_failure = SMF_EXIT_ERR_FATAL; |
|
186 |
rad_exit_config = SMF_EXIT_ERR_CONFIG; |
|
187 |
break; |
|
188 |
case 'S': |
|
189 |
/* Read config from specified FMRI */ |
|
190 |
smf_config = B_TRUE; |
|
191 |
smf_fmri = optarg; |
|
192 |
break; |
|
193 |
case 'd': |
|
194 |
rad_loglevel = RL_ALL; |
|
195 |
break; |
|
196 |
default: |
|
197 |
(void) fprintf(stderr, usage); |
|
198 |
exit(2); |
|
199 |
} |
|
200 |
} |
|
201 |
||
595
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
202 |
rad_moduledirs = rad_strarray(moddirs, nmoddir, lt_copy); |
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
203 |
rad_modules = rad_strarray(mods, nmods, lt_copy); |
391 | 204 |
|
205 |
if (smf_config) { |
|
206 |
data_t *config = rad_smf_read_pg_byname(smf_fmri, "config", |
|
207 |
&t__radconfig); |
|
208 |
if (config == NULL) |
|
209 |
rad_log(RL_CONFIG, |
|
210 |
"unable to read configuration from service\n"); |
|
595
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
211 |
|
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
212 |
data_t *moduledir, *modules, *debug; |
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
213 |
if ((debug = struct_get(config, "debug")) != NULL && |
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
214 |
data_to_boolean(debug)) |
391 | 215 |
rad_loglevel = RL_ALL; |
595
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
216 |
if ((moduledir = struct_get(config, "moduledir")) != NULL) |
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
217 |
rad_moduledirs = |
604
20d9acfeb7fb
17421 name key order preservation
David Powell <david.e.powell@oracle.com>
parents:
595
diff
changeset
|
218 |
array_addall(rad_moduledirs, data_ref(moduledir)); |
595
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
219 |
if ((modules = struct_get(config, "modules")) != NULL) |
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
220 |
rad_modules = |
604
20d9acfeb7fb
17421 name key order preservation
David Powell <david.e.powell@oracle.com>
parents:
595
diff
changeset
|
221 |
array_addall(rad_modules, data_ref(modules)); |
595
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
222 |
data_free(config); |
391 | 223 |
} |
224 |
||
225 |
/* parent exits, child returns */ |
|
226 |
if (smf_startup) |
|
227 |
svc_fd = rad_service_wait(); |
|
228 |
||
604
20d9acfeb7fb
17421 name key order preservation
David Powell <david.e.powell@oracle.com>
parents:
595
diff
changeset
|
229 |
cont_create(&rad_container_auth); |
20d9acfeb7fb
17421 name key order preservation
David Powell <david.e.powell@oracle.com>
parents:
595
diff
changeset
|
230 |
cont_create(&rad_container_unauth); |
20d9acfeb7fb
17421 name key order preservation
David Powell <david.e.powell@oracle.com>
parents:
595
diff
changeset
|
231 |
cont_create(&rad_container_control); |
20d9acfeb7fb
17421 name key order preservation
David Powell <david.e.powell@oracle.com>
parents:
595
diff
changeset
|
232 |
|
391 | 233 |
xmlInitParser(); /* So libxml consumers are MT safe */ |
555
399f1dff49b2
16728 rad uses openssl naively
David Powell <david.e.powell@oracle.com>
parents:
540
diff
changeset
|
234 |
adr_ssl_init(); /* So OpenSSL consumers are MT safe */ |
391 | 235 |
rad_ticket_init(); |
236 |
rad_pam_init(); |
|
237 |
rad_module_init(); |
|
238 |
rad_control_init(); |
|
573
f0add9469f92
17058 support removing objects
David Powell <david.e.powell@oracle.com>
parents:
555
diff
changeset
|
239 |
if (!cont_insert_contobj(&rad_container_auth) || |
f0add9469f92
17058 support removing objects
David Powell <david.e.powell@oracle.com>
parents:
555
diff
changeset
|
240 |
!cont_insert_contobj(&rad_container_control)) |
f0add9469f92
17058 support removing objects
David Powell <david.e.powell@oracle.com>
parents:
555
diff
changeset
|
241 |
rad_log(RL_FATAL, "Failed to insert container objects"); |
f0add9469f92
17058 support removing objects
David Powell <david.e.powell@oracle.com>
parents:
555
diff
changeset
|
242 |
|
436
c28d8d667ea1
14688 slave daemons should be placed in own contracts
David Powell <David.Powell@sun.com>
parents:
401
diff
changeset
|
243 |
if (rad_isproxy) |
c28d8d667ea1
14688 slave daemons should be placed in own contracts
David Powell <David.Powell@sun.com>
parents:
401
diff
changeset
|
244 |
rad_slave_init(); |
391 | 245 |
|
595
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
246 |
if (array_size(rad_moduledirs) == 0 && array_size(rad_modules) == 0) |
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
247 |
rad_log(RL_CONFIG, |
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
248 |
"No modules or module directories specified.\n"); |
391 | 249 |
|
595
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
250 |
/* |
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
251 |
* Explicitly specified modules take precedence over modules found by |
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
252 |
* scanning provided module directories. |
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
253 |
*/ |
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
254 |
for (i = 0; i < array_size(rad_modules); i++) |
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
255 |
rad_module_load(data_to_string(array_get(rad_modules, i))); |
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
256 |
|
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
257 |
for (i = 0; i < array_size(rad_moduledirs); i++) |
725a82f60b1c
17332 support loading specific modules
David Powell <david.e.powell@oracle.com>
parents:
575
diff
changeset
|
258 |
rad_module_scan(data_to_string(array_get(rad_moduledirs, i))); |
391 | 259 |
|
260 |
for (i = 0; i < nxport; i++) |
|
261 |
rad_xport_parse(xports[i]); |
|
262 |
||
263 |
if (smf_startup) { |
|
264 |
/* |
|
265 |
* Only process SMF-configured transports when really |
|
266 |
* run as a service. |
|
267 |
*/ |
|
268 |
rad_xport_smf(); |
|
269 |
rad_service_done(svc_fd); |
|
270 |
} |
|
271 |
||
272 |
(void) sigprocmask(SIG_UNBLOCK, &hupset, NULL); |
|
273 |
for (;;) |
|
472
a124d7f07f0e
15466 add lint target for main rad daemon
David Powell <David.Powell@sun.com>
parents:
436
diff
changeset
|
274 |
(void) pause(); |
a124d7f07f0e
15466 add lint target for main rad daemon
David Powell <David.Powell@sun.com>
parents:
436
diff
changeset
|
275 |
/* NOTREACHED */ |
391 | 276 |
} |