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.
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.
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]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
36 #include <papi_impl.h>
38 #include <tsol/label.h>
41 papiServiceCreate(papi_service_t
*handle
, char *service_name
,
42 char *user_name
, char *password
,
43 int (*authCB
)(papi_service_t svc
, void *app_data
),
44 papi_encryption_t encryption
, void *app_data
)
46 service_t
*svc
= NULL
;
50 return (PAPI_BAD_ARGUMENT
);
52 if ((*handle
= svc
= calloc(1, sizeof (*svc
))) == NULL
)
53 return (PAPI_TEMPORARY_ERROR
);
55 svc
->md
= mconnect(path
, 0, 0);
56 if (svc
->md
== NULL
) {
58 gettext("can't connect to spooler for %s: %s"),
59 (service_name
? service_name
: ""), strerror(errno
));
60 return (PAPI_SERVICE_UNAVAILABLE
);
63 svc
->msgbuf_size
= MSGMAX
;
64 if ((svc
->msgbuf
= calloc(1, svc
->msgbuf_size
)) == NULL
)
65 return (PAPI_TEMPORARY_ERROR
);
67 if (service_name
!= NULL
)
68 papiAttributeListAddString(&svc
->attributes
, PAPI_ATTR_EXCL
,
69 "service-name", service_name
);
71 (void) papiServiceSetUserName(svc
, user_name
);
72 (void) papiServiceSetPassword(svc
, password
);
73 (void) papiServiceSetAuthCB(svc
, authCB
);
74 (void) papiServiceSetAppData(svc
, app_data
);
75 (void) papiServiceSetEncryption(svc
, encryption
);
81 papiServiceDestroy(papi_service_t handle
)
83 service_t
*svc
= handle
;
88 if (svc
->msgbuf
!= NULL
)
90 papiAttributeListFree(svc
->attributes
);
96 * interface for passing a peer's connection to gather sensitivity labeling
97 * from for Trusted Solaris.
100 papiServiceSetPeer(papi_service_t handle
, int peerfd
)
102 papi_status_t result
= PAPI_OK
;
103 service_t
*svc
= handle
;
106 return (PAPI_BAD_ARGUMENT
);
108 if (is_system_labeled()) {
111 if ((snd_msg(svc
, S_PASS_PEER_CONNECTION
) < 0) ||
112 (ioctl(svc
->md
->writefd
, I_SENDFD
, peerfd
) < 0) ||
113 (rcv_msg(svc
, R_PASS_PEER_CONNECTION
, &status
) < 0))
114 status
= MTRANSMITERR
;
118 gettext("failed to send peer connection: %s"),
119 lpsched_status_string(status
));
120 result
= lpsched_status_to_papi_status(status
);
128 papiServiceSetUserName(papi_service_t handle
, char *user_name
)
130 service_t
*svc
= handle
;
133 return (PAPI_BAD_ARGUMENT
);
135 return (papiAttributeListAddString(&svc
->attributes
, PAPI_ATTR_REPLACE
,
136 "user-name", user_name
));
140 papiServiceSetPassword(papi_service_t handle
, char *password
)
142 service_t
*svc
= handle
;
145 return (PAPI_BAD_ARGUMENT
);
147 return (papiAttributeListAddString(&svc
->attributes
, PAPI_ATTR_REPLACE
,
148 "password", password
));
152 papiServiceSetEncryption(papi_service_t handle
,
153 papi_encryption_t encryption
)
155 service_t
*svc
= handle
;
158 return (PAPI_BAD_ARGUMENT
);
160 return (papiAttributeListAddInteger(&svc
->attributes
, PAPI_ATTR_REPLACE
,
161 "encryption", (int)encryption
));
165 papiServiceSetAuthCB(papi_service_t handle
,
166 int (*authCB
)(papi_service_t svc
, void *app_data
))
168 service_t
*svc
= handle
;
171 return (PAPI_BAD_ARGUMENT
);
173 svc
->authCB
= (int (*)(papi_service_t svc
, void *app_data
))authCB
;
179 papiServiceSetAppData(papi_service_t handle
, void *app_data
)
181 service_t
*svc
= handle
;
184 return (PAPI_BAD_ARGUMENT
);
186 svc
->app_data
= (void *)app_data
;
192 papiServiceGetServiceName(papi_service_t handle
)
194 service_t
*svc
= handle
;
198 papiAttributeListGetString(svc
->attributes
, NULL
,
199 "service-name", &result
);
205 papiServiceGetUserName(papi_service_t handle
)
207 service_t
*svc
= handle
;
211 papiAttributeListGetString(svc
->attributes
, NULL
,
212 "user-name", &result
);
218 papiServiceGetPassword(papi_service_t handle
)
220 service_t
*svc
= handle
;
224 papiAttributeListGetString(svc
->attributes
, NULL
,
225 "password", &result
);
231 papiServiceGetEncryption(papi_service_t handle
)
233 service_t
*svc
= handle
;
234 papi_encryption_t result
= PAPI_ENCRYPT_NEVER
;
237 papiAttributeListGetInteger(svc
->attributes
, NULL
,
238 "encryption", (int *)&result
);
244 papiServiceGetAppData(papi_service_t handle
)
246 service_t
*svc
= handle
;
250 result
= svc
->app_data
;
256 papiServiceGetAttributeList(papi_service_t handle
)
258 service_t
*svc
= handle
;
259 papi_attribute_t
**result
= NULL
;
262 lpsched_service_information(&svc
->attributes
);
263 result
= svc
->attributes
;
270 papiServiceGetStatusMessage(papi_service_t handle
)
272 service_t
*svc
= handle
;
276 papiAttributeListGetString(svc
->attributes
, NULL
,
277 "detailed-status-message", &result
);
283 detailed_error(service_t
*svc
, char *fmt
, ...)
285 if ((svc
!= NULL
) && (fmt
!= NULL
)) {
288 char *message
= alloca(BUFSIZ
);
292 * fill in the message. If the buffer is too small, allocate
293 * one that is large enough and fill it in.
295 if ((size
= vsnprintf(message
, BUFSIZ
, fmt
, ap
)) >= BUFSIZ
)
296 if ((message
= alloca(size
)) != NULL
)
297 vsnprintf(message
, size
, fmt
, ap
);
300 papiAttributeListAddString(&svc
->attributes
, PAPI_ATTR_APPEND
,
301 "detailed-status-message", message
);