2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
6 * This code is derived from software donated to Berkeley by
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * @(#)activate.c 8.3 (Berkeley) 4/28/95
40 #include <sys/cdefs.h>
41 __FBSDID("$FreeBSD$");
46 #include <sys/types.h>
47 #include <sys/param.h>
48 #include <sys/socket.h>
49 #include <sys/syslog.h>
55 * Scan the providers list and call the
56 * appropriate function.
58 static int activate_argv(pcr, key, v, so, fdp)
59 struct portal_cred *pcr;
67 for (pr = providers; pr->pr_match; pr++)
68 if (strcmp(v[0], pr->pr_match) == 0)
69 return ((*pr->pr_func)(pcr, key, v, so, fdp));
74 static int get_request(so, pcr, key, klen)
76 struct portal_cred *pcr;
84 iov[0].iov_base = (caddr_t) pcr;
85 iov[0].iov_len = sizeof(*pcr);
86 iov[1].iov_base = key;
87 iov[1].iov_len = klen;
89 memset(&msg, 0, sizeof(msg));
93 n = recvmsg(so, &msg, 0);
97 if (n <= sizeof(*pcr))
106 static void send_reply(so, fd, error)
116 char control[CMSG_SPACE(sizeof(int))];
120 * Line up error code. Don't worry about byte ordering
121 * because we must be sending to the local machine.
123 iov.iov_base = (caddr_t) &error;
124 iov.iov_len = sizeof(error);
129 memset(&msg, 0, sizeof(msg));
134 * If there is a file descriptor to send then
135 * construct a suitable rights control message.
138 ctl.cmsg.cmsg_len = CMSG_LEN(sizeof(int));
139 ctl.cmsg.cmsg_level = SOL_SOCKET;
140 ctl.cmsg.cmsg_type = SCM_RIGHTS;
141 *((int *)CMSG_DATA(&ctl.cmsg)) = fd;
142 msg.msg_control = (caddr_t) &ctl;
143 msg.msg_controllen = ctl.cmsg.cmsg_len;
149 if ((n = sendmsg(so, &msg, 0)) < 0)
150 syslog(LOG_ERR, "send: %s", strerror(errno));
152 fprintf(stderr, "sent %d bytes\n", n);
156 if (shutdown(so, 2) < 0)
157 syslog(LOG_ERR, "shutdown: %s", strerror(errno));
160 * Throw away the open file descriptor
169 struct portal_cred pcred;
170 char key[MAXPATHLEN+1];
176 * Read the key from the socket
178 error = get_request(so, &pcred, key, sizeof(key));
180 syslog(LOG_ERR, "activate: recvmsg: %s", strerror(error));
185 fprintf(stderr, "lookup key %s\n", key);
189 * Find a match in the configuration file
191 v = conf_match(q, key);
194 * If a match existed, then find an appropriate portal
195 * otherwise simply return ENOENT.
198 error = activate_argv(&pcred, key, v, so, &fd);
208 send_reply(so, fd, error);