4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
41 #include "repcache_protocol.h"
44 #define INVALID_RESULT ((uint32_t)-1U)
46 static int main_door_fd
= -1;
50 main_switcher(void *cookie
, char *argp
, size_t arg_size
, door_desc_t
*desc
,
53 repository_door_request_t
*request
;
54 repository_door_response_t reply
;
55 door_desc_t reply_desc
;
57 thread_info_t
*ti
= thread_self();
62 thread_newstate(ti
, TI_MAIN_DOOR_CALL
);
63 ti
->ti_main_door_request
= (void *)argp
;
65 assert(cookie
== REPOSITORY_DOOR_COOKIE
);
67 reply
.rdr_status
= INVALID_RESULT
;
69 if (argp
== DOOR_UNREF_DATA
) {
72 exit(CONFIGD_EXIT_LOST_MAIN_DOOR
);
76 * No file descriptors allowed
81 * first, we just check the version
83 if (arg_size
< offsetofend(repository_door_request_t
, rdr_version
)) {
84 reply
.rdr_status
= REPOSITORY_DOOR_FAIL_BAD_REQUEST
;
88 /* LINTED alignment */
89 request
= (repository_door_request_t
*)argp
;
90 ti
->ti_main_door_request
= request
;
92 if (request
->rdr_version
!= REPOSITORY_DOOR_VERSION
) {
93 reply
.rdr_status
= REPOSITORY_DOOR_FAIL_VERSION_MISMATCH
;
98 * Now, check that the argument is of the minimum required size
100 if (arg_size
< offsetofend(repository_door_request_t
, rdr_request
)) {
101 reply
.rdr_status
= REPOSITORY_DOOR_FAIL_BAD_REQUEST
;
105 if (door_ucred(&ti
->ti_ucred
) != 0) {
106 reply
.rdr_status
= REPOSITORY_DOOR_FAIL_PERMISSION_DENIED
;
110 switch (request
->rdr_request
) {
111 case REPOSITORY_DOOR_REQUEST_CONNECT
:
113 reply
.rdr_status
= create_connection(ti
->ti_ucred
, request
,
115 if (reply
.rdr_status
!= REPOSITORY_DOOR_SUCCESS
) {
120 reply_desc
.d_attributes
= DOOR_DESCRIPTOR
| DOOR_RELEASE
;
121 reply_desc
.d_data
.d_desc
.d_descriptor
= fd
;
126 reply
.rdr_status
= REPOSITORY_DOOR_FAIL_BAD_REQUEST
;
131 assert(reply
.rdr_status
!= INVALID_RESULT
);
133 thread_newstate(ti
, TI_DOOR_RETURN
);
134 ti
->ti_main_door_request
= NULL
;
136 (void) door_return((char *)&reply
, sizeof (reply
),
137 &reply_desc
, (send_desc
)? 1:0);
138 (void) door_return(NULL
, 0, NULL
, 0);
142 setup_main_door(const char *doorpath
)
147 int door_flags
= DOOR_UNREF
| DOOR_REFUSE_DESC
;
148 #ifdef DOOR_NO_CANCEL
149 door_flags
|= DOOR_NO_CANCEL
;
151 if ((main_door_fd
= door_create(main_switcher
, REPOSITORY_DOOR_COOKIE
,
153 perror("door_create");
157 #ifdef DOOR_PARAM_DATA_MIN
158 if (door_setparam(main_door_fd
, DOOR_PARAM_DATA_MIN
,
159 offsetofend(repository_door_request_t
, rdr_request
)) == -1 ||
160 door_setparam(main_door_fd
, DOOR_PARAM_DATA_MAX
,
161 sizeof (repository_door_request_t
)) == -1) {
162 perror("door_setparam");
165 #endif /* DOOR_PARAM_DATA_MIN */
168 * Create the file if it doesn't exist. Ignore errors, since
169 * fattach(3C) will catch any real problems.
171 oldmask
= umask(000); /* disable umask temporarily */
172 fd
= open(doorpath
, O_RDWR
| O_CREAT
| O_EXCL
, 0644);
173 (void) umask(oldmask
);
178 if (fattach(main_door_fd
, doorpath
) < 0) {
179 if ((errno
!= EBUSY
) ||
180 (fdetach(doorpath
) < 0) ||
181 (fattach(main_door_fd
, doorpath
) < 0)) {
183 (void) door_revoke(main_door_fd
);