1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24*0Sstevel@tonic-gate * Use is subject to license terms.
25*0Sstevel@tonic-gate */
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate #include <stdarg.h>
30*0Sstevel@tonic-gate #include <dhcp_svc_private.h>
31*0Sstevel@tonic-gate #include <dhcp_symbol.h>
32*0Sstevel@tonic-gate #include <libintl.h>
33*0Sstevel@tonic-gate #include <jni.h>
34*0Sstevel@tonic-gate
35*0Sstevel@tonic-gate #include "dd_misc.h"
36*0Sstevel@tonic-gate #include "exception.h"
37*0Sstevel@tonic-gate
38*0Sstevel@tonic-gate /*
39*0Sstevel@tonic-gate * Note: These must match exactly with the message ids defined in the
40*0Sstevel@tonic-gate * bridge ResourceBundle.properties file.
41*0Sstevel@tonic-gate */
42*0Sstevel@tonic-gate #define DSVC_EXISTS_EX "dsvc_exists_exception"
43*0Sstevel@tonic-gate #define DSVC_ACCESS_EX "dsvc_access_exception"
44*0Sstevel@tonic-gate #define DSVC_CREDENTIAL_EX "dsvc_credential_exception"
45*0Sstevel@tonic-gate #define DSVC_NO_ENT_EX "dsvc_no_ent_exception"
46*0Sstevel@tonic-gate #define DSVC_BUSY_EX "dsvc_busy_exception"
47*0Sstevel@tonic-gate #define DSVC_INVALID_ARGS_EX "dsvc_invalid_args_exception"
48*0Sstevel@tonic-gate #define DSVC_INTERNAL_EX "dsvc_internal_exception"
49*0Sstevel@tonic-gate #define DSVC_UNAVAILABLE_EX "dsvc_unavailable_exception"
50*0Sstevel@tonic-gate #define DSVC_COLLISION_EX "dsvc_collision_exception"
51*0Sstevel@tonic-gate #define DSVC_UNSUPPORTED_EX "dsvc_unsupported_exception"
52*0Sstevel@tonic-gate #define DSVC_NO_MEMORY_EX "dsvc_no_memory_exception"
53*0Sstevel@tonic-gate #define DSVC_NO_RESOURCES_EX "dsvc_no_resources_exception"
54*0Sstevel@tonic-gate #define DSVC_BAD_RESOURCE_EX "dsvc_bad_resource_exception"
55*0Sstevel@tonic-gate #define DSVC_BAD_PATH_EX "dsvc_bad_path_exception"
56*0Sstevel@tonic-gate #define DSVC_MOD_VERSION_EX "dsvc_mod_version_exception"
57*0Sstevel@tonic-gate #define DSVC_MOD_ERR_EX "dsvc_mod_err_exception"
58*0Sstevel@tonic-gate #define DSVC_MOD_LOAD_ERR_EX "dsvc_mod_load_err_exception"
59*0Sstevel@tonic-gate #define DSVC_MOD_UNLOAD_ERR_EX "dsvc_mod_unload_err_exception"
60*0Sstevel@tonic-gate #define DSVC_MOD_CFG_ERR_EX "dsvc_mod_cfg_err_exception"
61*0Sstevel@tonic-gate #define DSVC_SYNCH_ERR_EX "dsvc_synch_err_exception"
62*0Sstevel@tonic-gate #define DSVC_NO_LOCKMGR_EX "dsvc_no_lockmgr_exception"
63*0Sstevel@tonic-gate #define DSVC_NO_LOCATION_EX "dsvc_no_location_exception"
64*0Sstevel@tonic-gate #define DSVC_NO_TABLE_EX "dsvc_no_table_exception"
65*0Sstevel@tonic-gate #define DSVC_TABLE_EXISTS_EX "dsvc_table_exists_exception"
66*0Sstevel@tonic-gate #define DSVC_BAD_CONVER_EX "dsvc_bad_conver_exception"
67*0Sstevel@tonic-gate #define DSVC_INTERNAL_ERROR "dsvc_internal_error"
68*0Sstevel@tonic-gate
69*0Sstevel@tonic-gate #define DSYM_CODE_OUT_OF_RANGE_EX "dsym_code_out_of_range_exception"
70*0Sstevel@tonic-gate #define DSYM_EXCEEDS_CLASS_SIZE_EX "dsym_exceeds_class_size_exception"
71*0Sstevel@tonic-gate #define DSYM_EXCEEDS_MAX_CLASS_SIZE_EX "dsym_exceeds_max_class_size_exception"
72*0Sstevel@tonic-gate #define DSYM_INTERNAL_EX "dsym_internal_exception"
73*0Sstevel@tonic-gate #define DSYM_INVALID_CAT_EX "dsym_invalid_cat_exception"
74*0Sstevel@tonic-gate #define DSYM_INVALID_TYPE_EX "dsym_invalid_type_exception"
75*0Sstevel@tonic-gate #define DSYM_NO_MEMORY_EX "dsym_no_memory_exception"
76*0Sstevel@tonic-gate #define DSYM_TOO_FEW_FIELDS_EX "dsym_too_few_fields_exception"
77*0Sstevel@tonic-gate #define DSYM_SYNTAX_EX "dsym_syntax_exception"
78*0Sstevel@tonic-gate #define DSYM_TOO_MANY_FIELDS_EX "dsym_too_many_fields_exception"
79*0Sstevel@tonic-gate #define DSYM_VALUE_OUT_OF_RANGE_EX "dsym_value_out_of_range_exception"
80*0Sstevel@tonic-gate
81*0Sstevel@tonic-gate static void
throw_exception(JNIEnv * env,const char * name,const char * msgid,int nargs,...)82*0Sstevel@tonic-gate throw_exception(JNIEnv *env, const char *name, const char *msgid,
83*0Sstevel@tonic-gate int nargs, ...)
84*0Sstevel@tonic-gate {
85*0Sstevel@tonic-gate va_list ap;
86*0Sstevel@tonic-gate
87*0Sstevel@tonic-gate jclass class;
88*0Sstevel@tonic-gate jmethodID mid;
89*0Sstevel@tonic-gate jstring jmsgid = NULL;
90*0Sstevel@tonic-gate jobjectArray jlist = NULL;
91*0Sstevel@tonic-gate jthrowable throwObj;
92*0Sstevel@tonic-gate
93*0Sstevel@tonic-gate va_start(ap, nargs);
94*0Sstevel@tonic-gate
95*0Sstevel@tonic-gate class = (*env)->FindClass(env, name);
96*0Sstevel@tonic-gate if (class == NULL) {
97*0Sstevel@tonic-gate /* exception thrown */
98*0Sstevel@tonic-gate va_end(ap);
99*0Sstevel@tonic-gate return;
100*0Sstevel@tonic-gate }
101*0Sstevel@tonic-gate
102*0Sstevel@tonic-gate mid = (*env)->GetMethodID(env, class, "<init>",
103*0Sstevel@tonic-gate "(Ljava/lang/String;[Ljava/lang/Object;)V");
104*0Sstevel@tonic-gate if (mid == NULL) {
105*0Sstevel@tonic-gate /* exception thrown */
106*0Sstevel@tonic-gate va_end(ap);
107*0Sstevel@tonic-gate return;
108*0Sstevel@tonic-gate }
109*0Sstevel@tonic-gate
110*0Sstevel@tonic-gate if (msgid != NULL) {
111*0Sstevel@tonic-gate jmsgid = dd_native_to_jstring(env, msgid);
112*0Sstevel@tonic-gate if (jmsgid == NULL) {
113*0Sstevel@tonic-gate /* exception thrown */
114*0Sstevel@tonic-gate va_end(ap);
115*0Sstevel@tonic-gate return;
116*0Sstevel@tonic-gate }
117*0Sstevel@tonic-gate }
118*0Sstevel@tonic-gate
119*0Sstevel@tonic-gate /* The arguments (if any) are arguments to the message */
120*0Sstevel@tonic-gate if (nargs != 0) {
121*0Sstevel@tonic-gate
122*0Sstevel@tonic-gate jclass strclass;
123*0Sstevel@tonic-gate int i;
124*0Sstevel@tonic-gate strclass = (*env)->FindClass(env, "java/lang/String");
125*0Sstevel@tonic-gate if (strclass == NULL) {
126*0Sstevel@tonic-gate /* exception thrown */
127*0Sstevel@tonic-gate va_end(ap);
128*0Sstevel@tonic-gate return;
129*0Sstevel@tonic-gate }
130*0Sstevel@tonic-gate
131*0Sstevel@tonic-gate jlist = (*env)->NewObjectArray(env, nargs, strclass, NULL);
132*0Sstevel@tonic-gate if (jlist == NULL) {
133*0Sstevel@tonic-gate /* exception thrown */
134*0Sstevel@tonic-gate va_end(ap);
135*0Sstevel@tonic-gate return;
136*0Sstevel@tonic-gate }
137*0Sstevel@tonic-gate
138*0Sstevel@tonic-gate for (i = 0; i < nargs; i++) {
139*0Sstevel@tonic-gate jstring jarg;
140*0Sstevel@tonic-gate char *arg;
141*0Sstevel@tonic-gate
142*0Sstevel@tonic-gate if ((arg = va_arg(ap, char *)) == 0) {
143*0Sstevel@tonic-gate break;
144*0Sstevel@tonic-gate }
145*0Sstevel@tonic-gate
146*0Sstevel@tonic-gate jarg = dd_native_to_jstring(env, arg);
147*0Sstevel@tonic-gate if (jarg == NULL) {
148*0Sstevel@tonic-gate /* exception thrown */
149*0Sstevel@tonic-gate break;
150*0Sstevel@tonic-gate }
151*0Sstevel@tonic-gate
152*0Sstevel@tonic-gate (*env)->SetObjectArrayElement(env, jlist, i, jarg);
153*0Sstevel@tonic-gate if ((*env)->ExceptionOccurred(env) != NULL) {
154*0Sstevel@tonic-gate break;
155*0Sstevel@tonic-gate }
156*0Sstevel@tonic-gate }
157*0Sstevel@tonic-gate
158*0Sstevel@tonic-gate }
159*0Sstevel@tonic-gate
160*0Sstevel@tonic-gate if ((*env)->ExceptionOccurred(env) == NULL) {
161*0Sstevel@tonic-gate throwObj = (jthrowable)(*env)->NewObject(env, class, mid,
162*0Sstevel@tonic-gate jmsgid, jlist);
163*0Sstevel@tonic-gate if (throwObj == NULL) {
164*0Sstevel@tonic-gate /* exception thrown */
165*0Sstevel@tonic-gate va_end(ap);
166*0Sstevel@tonic-gate return;
167*0Sstevel@tonic-gate }
168*0Sstevel@tonic-gate
169*0Sstevel@tonic-gate /* finally! */
170*0Sstevel@tonic-gate (*env)->Throw(env, throwObj);
171*0Sstevel@tonic-gate }
172*0Sstevel@tonic-gate
173*0Sstevel@tonic-gate va_end(ap);
174*0Sstevel@tonic-gate }
175*0Sstevel@tonic-gate
176*0Sstevel@tonic-gate /* Throw an exception indicating record or file exists */
177*0Sstevel@tonic-gate static void
throw_exists_exception(JNIEnv * env,const char * obj)178*0Sstevel@tonic-gate throw_exists_exception(JNIEnv *env, const char *obj)
179*0Sstevel@tonic-gate {
180*0Sstevel@tonic-gate throw_exception(env,
181*0Sstevel@tonic-gate "com/sun/dhcpmgr/bridge/ExistsException", NULL, 1, obj);
182*0Sstevel@tonic-gate }
183*0Sstevel@tonic-gate
184*0Sstevel@tonic-gate /* Throw an exception indicating a table already exists */
185*0Sstevel@tonic-gate static void
throw_table_exists_exception(JNIEnv * env,const char * obj)186*0Sstevel@tonic-gate throw_table_exists_exception(JNIEnv *env, const char *obj)
187*0Sstevel@tonic-gate {
188*0Sstevel@tonic-gate throw_exception(env, "com/sun/dhcpmgr/bridge/TableExistsException",
189*0Sstevel@tonic-gate NULL, 1, obj);
190*0Sstevel@tonic-gate }
191*0Sstevel@tonic-gate
192*0Sstevel@tonic-gate /* Throw an exception indicating a table does not exist */
193*0Sstevel@tonic-gate static void
throw_notable_exception(JNIEnv * env,const char * obj)194*0Sstevel@tonic-gate throw_notable_exception(JNIEnv *env, const char *obj)
195*0Sstevel@tonic-gate {
196*0Sstevel@tonic-gate throw_exception(env,
197*0Sstevel@tonic-gate "com/sun/dhcpmgr/bridge/NoTableException", NULL, 1, obj);
198*0Sstevel@tonic-gate }
199*0Sstevel@tonic-gate
200*0Sstevel@tonic-gate /* Throw a generic bridge exception with a specified message */
201*0Sstevel@tonic-gate void
throw_bridge_exception(JNIEnv * env,const char * msgid)202*0Sstevel@tonic-gate throw_bridge_exception(JNIEnv *env, const char *msgid)
203*0Sstevel@tonic-gate {
204*0Sstevel@tonic-gate throw_exception(env,
205*0Sstevel@tonic-gate "com/sun/dhcpmgr/bridge/BridgeException", msgid, 0);
206*0Sstevel@tonic-gate }
207*0Sstevel@tonic-gate
208*0Sstevel@tonic-gate /* Throw an exception as a result of an remove_dd() error */
209*0Sstevel@tonic-gate void
throw_remove_dd_exception(JNIEnv * env,int rcode,const char * obj)210*0Sstevel@tonic-gate throw_remove_dd_exception(JNIEnv *env, int rcode, const char *obj)
211*0Sstevel@tonic-gate {
212*0Sstevel@tonic-gate switch (rcode) {
213*0Sstevel@tonic-gate case DSVC_NO_TABLE:
214*0Sstevel@tonic-gate throw_notable_exception(env, obj);
215*0Sstevel@tonic-gate break;
216*0Sstevel@tonic-gate default:
217*0Sstevel@tonic-gate throw_libdhcpsvc_exception(env, rcode);
218*0Sstevel@tonic-gate }
219*0Sstevel@tonic-gate }
220*0Sstevel@tonic-gate
221*0Sstevel@tonic-gate /* Throw an exception as a result of an open_dd() error */
222*0Sstevel@tonic-gate void
throw_open_dd_exception(JNIEnv * env,int rcode,const char * obj)223*0Sstevel@tonic-gate throw_open_dd_exception(JNIEnv *env, int rcode, const char *obj)
224*0Sstevel@tonic-gate {
225*0Sstevel@tonic-gate switch (rcode) {
226*0Sstevel@tonic-gate case DSVC_TABLE_EXISTS:
227*0Sstevel@tonic-gate throw_table_exists_exception(env, obj);
228*0Sstevel@tonic-gate break;
229*0Sstevel@tonic-gate case DSVC_NO_TABLE:
230*0Sstevel@tonic-gate throw_notable_exception(env, obj);
231*0Sstevel@tonic-gate break;
232*0Sstevel@tonic-gate default:
233*0Sstevel@tonic-gate throw_libdhcpsvc_exception(env, rcode);
234*0Sstevel@tonic-gate }
235*0Sstevel@tonic-gate }
236*0Sstevel@tonic-gate
237*0Sstevel@tonic-gate /* Throw an exception as a result of an add_dd_entry() error */
238*0Sstevel@tonic-gate void
throw_add_dd_entry_exception(JNIEnv * env,int rcode,const char * obj)239*0Sstevel@tonic-gate throw_add_dd_entry_exception(JNIEnv *env, int rcode, const char *obj)
240*0Sstevel@tonic-gate {
241*0Sstevel@tonic-gate switch (rcode) {
242*0Sstevel@tonic-gate case DSVC_EXISTS:
243*0Sstevel@tonic-gate throw_exists_exception(env, obj);
244*0Sstevel@tonic-gate break;
245*0Sstevel@tonic-gate default:
246*0Sstevel@tonic-gate throw_libdhcpsvc_exception(env, rcode);
247*0Sstevel@tonic-gate }
248*0Sstevel@tonic-gate }
249*0Sstevel@tonic-gate
250*0Sstevel@tonic-gate /* Throw an exception as a result of an delete_dd_entry() error */
251*0Sstevel@tonic-gate void
throw_delete_dd_entry_exception(JNIEnv * env,int rcode,const char * obj)252*0Sstevel@tonic-gate throw_delete_dd_entry_exception(JNIEnv *env, int rcode, const char *obj)
253*0Sstevel@tonic-gate {
254*0Sstevel@tonic-gate switch (rcode) {
255*0Sstevel@tonic-gate case DSVC_NOENT:
256*0Sstevel@tonic-gate throw_noent_exception(env, obj);
257*0Sstevel@tonic-gate break;
258*0Sstevel@tonic-gate default:
259*0Sstevel@tonic-gate throw_libdhcpsvc_exception(env, rcode);
260*0Sstevel@tonic-gate }
261*0Sstevel@tonic-gate }
262*0Sstevel@tonic-gate
263*0Sstevel@tonic-gate /* Throw an exception as a result of an modify_dd_entry() error */
264*0Sstevel@tonic-gate void
throw_modify_dd_entry_exception(JNIEnv * env,int rcode,const char * orig,const char * new)265*0Sstevel@tonic-gate throw_modify_dd_entry_exception(JNIEnv *env, int rcode, const char *orig,
266*0Sstevel@tonic-gate const char *new)
267*0Sstevel@tonic-gate {
268*0Sstevel@tonic-gate switch (rcode) {
269*0Sstevel@tonic-gate case DSVC_EXISTS:
270*0Sstevel@tonic-gate throw_exists_exception(env, new);
271*0Sstevel@tonic-gate break;
272*0Sstevel@tonic-gate case DSVC_NOENT:
273*0Sstevel@tonic-gate throw_noent_exception(env, orig);
274*0Sstevel@tonic-gate break;
275*0Sstevel@tonic-gate default:
276*0Sstevel@tonic-gate throw_libdhcpsvc_exception(env, rcode);
277*0Sstevel@tonic-gate }
278*0Sstevel@tonic-gate }
279*0Sstevel@tonic-gate
280*0Sstevel@tonic-gate /* Throw an out of memory exception */
281*0Sstevel@tonic-gate void
throw_memory_exception(JNIEnv * env)282*0Sstevel@tonic-gate throw_memory_exception(JNIEnv *env)
283*0Sstevel@tonic-gate {
284*0Sstevel@tonic-gate throw_libdhcpsvc_exception(env, DSVC_NO_MEMORY);
285*0Sstevel@tonic-gate }
286*0Sstevel@tonic-gate
287*0Sstevel@tonic-gate /* Throw an exception indicating that there is no DHCP config file */
288*0Sstevel@tonic-gate void
throw_no_defaults_exception(JNIEnv * env)289*0Sstevel@tonic-gate throw_no_defaults_exception(JNIEnv *env)
290*0Sstevel@tonic-gate {
291*0Sstevel@tonic-gate throw_exception(env,
292*0Sstevel@tonic-gate "com/sun/dhcpmgr/bridge/NoDefaultsException", NULL, 0);
293*0Sstevel@tonic-gate }
294*0Sstevel@tonic-gate
295*0Sstevel@tonic-gate /* Throw an exception indicating record or file does not exist */
296*0Sstevel@tonic-gate void
throw_noent_exception(JNIEnv * env,const char * obj)297*0Sstevel@tonic-gate throw_noent_exception(JNIEnv *env, const char *obj)
298*0Sstevel@tonic-gate {
299*0Sstevel@tonic-gate throw_exception(env,
300*0Sstevel@tonic-gate "com/sun/dhcpmgr/bridge/NoEntryException", NULL, 1, obj);
301*0Sstevel@tonic-gate }
302*0Sstevel@tonic-gate
303*0Sstevel@tonic-gate /* Throw an exception indicating an invalid resource */
304*0Sstevel@tonic-gate void
throw_invalid_resource_exception(JNIEnv * env,const char * obj)305*0Sstevel@tonic-gate throw_invalid_resource_exception(JNIEnv *env, const char *obj)
306*0Sstevel@tonic-gate {
307*0Sstevel@tonic-gate throw_exception(env, "com/sun/dhcpmgr/bridge/InvalidRsrcException",
308*0Sstevel@tonic-gate NULL, 1, obj);
309*0Sstevel@tonic-gate }
310*0Sstevel@tonic-gate
311*0Sstevel@tonic-gate /* Throw an exception indicating an invalid path */
312*0Sstevel@tonic-gate void
throw_invalid_path_exception(JNIEnv * env,const char * obj)313*0Sstevel@tonic-gate throw_invalid_path_exception(JNIEnv *env, const char *obj)
314*0Sstevel@tonic-gate {
315*0Sstevel@tonic-gate throw_exception(env, "com/sun/dhcpmgr/bridge/InvalidPathException",
316*0Sstevel@tonic-gate NULL, 1, obj);
317*0Sstevel@tonic-gate }
318*0Sstevel@tonic-gate
319*0Sstevel@tonic-gate /* Throw an exception indicating that the service is not currently running */
320*0Sstevel@tonic-gate void
throw_not_running_exception(JNIEnv * env)321*0Sstevel@tonic-gate throw_not_running_exception(JNIEnv *env)
322*0Sstevel@tonic-gate {
323*0Sstevel@tonic-gate throw_exception(env,
324*0Sstevel@tonic-gate "com/sun/dhcpmgr/bridge/NotRunningException", NULL, 0);
325*0Sstevel@tonic-gate }
326*0Sstevel@tonic-gate
327*0Sstevel@tonic-gate /* Throw exception for a libdhcpsvc error that requires no special treatment */
328*0Sstevel@tonic-gate void
throw_libdhcpsvc_exception(JNIEnv * env,int rcode)329*0Sstevel@tonic-gate throw_libdhcpsvc_exception(JNIEnv *env, int rcode)
330*0Sstevel@tonic-gate {
331*0Sstevel@tonic-gate const char *msgid;
332*0Sstevel@tonic-gate
333*0Sstevel@tonic-gate switch (rcode) {
334*0Sstevel@tonic-gate case DSVC_SUCCESS:
335*0Sstevel@tonic-gate break;
336*0Sstevel@tonic-gate case DSVC_EXISTS:
337*0Sstevel@tonic-gate msgid = DSVC_EXISTS_EX;
338*0Sstevel@tonic-gate break;
339*0Sstevel@tonic-gate case DSVC_ACCESS:
340*0Sstevel@tonic-gate msgid = DSVC_ACCESS_EX;
341*0Sstevel@tonic-gate break;
342*0Sstevel@tonic-gate case DSVC_NO_CRED:
343*0Sstevel@tonic-gate msgid = DSVC_CREDENTIAL_EX;
344*0Sstevel@tonic-gate break;
345*0Sstevel@tonic-gate case DSVC_NOENT:
346*0Sstevel@tonic-gate msgid = DSVC_NO_ENT_EX;
347*0Sstevel@tonic-gate break;
348*0Sstevel@tonic-gate case DSVC_BUSY:
349*0Sstevel@tonic-gate msgid = DSVC_BUSY_EX;
350*0Sstevel@tonic-gate break;
351*0Sstevel@tonic-gate case DSVC_INVAL:
352*0Sstevel@tonic-gate msgid = DSVC_INVALID_ARGS_EX;
353*0Sstevel@tonic-gate break;
354*0Sstevel@tonic-gate case DSVC_INTERNAL:
355*0Sstevel@tonic-gate msgid = DSVC_INTERNAL_EX;
356*0Sstevel@tonic-gate break;
357*0Sstevel@tonic-gate case DSVC_UNAVAILABLE:
358*0Sstevel@tonic-gate msgid = DSVC_UNAVAILABLE_EX;
359*0Sstevel@tonic-gate break;
360*0Sstevel@tonic-gate case DSVC_COLLISION:
361*0Sstevel@tonic-gate msgid = DSVC_COLLISION_EX;
362*0Sstevel@tonic-gate break;
363*0Sstevel@tonic-gate case DSVC_UNSUPPORTED:
364*0Sstevel@tonic-gate msgid = DSVC_UNSUPPORTED_EX;
365*0Sstevel@tonic-gate break;
366*0Sstevel@tonic-gate case DSVC_NO_MEMORY:
367*0Sstevel@tonic-gate msgid = DSVC_NO_MEMORY_EX;
368*0Sstevel@tonic-gate break;
369*0Sstevel@tonic-gate case DSVC_NO_RESOURCES:
370*0Sstevel@tonic-gate msgid = DSVC_NO_RESOURCES_EX;
371*0Sstevel@tonic-gate break;
372*0Sstevel@tonic-gate case DSVC_BAD_RESOURCE:
373*0Sstevel@tonic-gate msgid = DSVC_BAD_RESOURCE_EX;
374*0Sstevel@tonic-gate break;
375*0Sstevel@tonic-gate case DSVC_BAD_PATH:
376*0Sstevel@tonic-gate msgid = DSVC_BAD_PATH_EX;
377*0Sstevel@tonic-gate break;
378*0Sstevel@tonic-gate case DSVC_MODULE_VERSION:
379*0Sstevel@tonic-gate msgid = DSVC_MOD_VERSION_EX;
380*0Sstevel@tonic-gate break;
381*0Sstevel@tonic-gate case DSVC_MODULE_ERR:
382*0Sstevel@tonic-gate msgid = DSVC_MOD_ERR_EX;
383*0Sstevel@tonic-gate break;
384*0Sstevel@tonic-gate case DSVC_MODULE_LOAD_ERR:
385*0Sstevel@tonic-gate msgid = DSVC_MOD_LOAD_ERR_EX;
386*0Sstevel@tonic-gate break;
387*0Sstevel@tonic-gate case DSVC_MODULE_UNLOAD_ERR:
388*0Sstevel@tonic-gate msgid = DSVC_MOD_UNLOAD_ERR_EX;
389*0Sstevel@tonic-gate break;
390*0Sstevel@tonic-gate case DSVC_MODULE_CFG_ERR:
391*0Sstevel@tonic-gate msgid = DSVC_MOD_CFG_ERR_EX;
392*0Sstevel@tonic-gate break;
393*0Sstevel@tonic-gate case DSVC_SYNCH_ERR:
394*0Sstevel@tonic-gate msgid = DSVC_SYNCH_ERR_EX;
395*0Sstevel@tonic-gate break;
396*0Sstevel@tonic-gate case DSVC_NO_LOCKMGR:
397*0Sstevel@tonic-gate msgid = DSVC_NO_LOCKMGR_EX;
398*0Sstevel@tonic-gate break;
399*0Sstevel@tonic-gate case DSVC_NO_LOCATION:
400*0Sstevel@tonic-gate msgid = DSVC_NO_LOCATION_EX;
401*0Sstevel@tonic-gate break;
402*0Sstevel@tonic-gate case DSVC_BAD_CONVER:
403*0Sstevel@tonic-gate msgid = DSVC_BAD_CONVER_EX;
404*0Sstevel@tonic-gate break;
405*0Sstevel@tonic-gate default:
406*0Sstevel@tonic-gate msgid = DSVC_INTERNAL_ERROR;
407*0Sstevel@tonic-gate }
408*0Sstevel@tonic-gate
409*0Sstevel@tonic-gate throw_bridge_exception(env, msgid);
410*0Sstevel@tonic-gate }
411*0Sstevel@tonic-gate
412*0Sstevel@tonic-gate /* Determine whether an exception is a defaults file doesn't exist exception */
413*0Sstevel@tonic-gate boolean_t
is_no_defaults_exception(JNIEnv * env,jthrowable e)414*0Sstevel@tonic-gate is_no_defaults_exception(JNIEnv *env, jthrowable e)
415*0Sstevel@tonic-gate {
416*0Sstevel@tonic-gate jclass class;
417*0Sstevel@tonic-gate boolean_t result = B_FALSE;
418*0Sstevel@tonic-gate
419*0Sstevel@tonic-gate class = (*env)->FindClass(env,
420*0Sstevel@tonic-gate "com/sun/dhcpmgr/bridge/NoDefaultsException");
421*0Sstevel@tonic-gate if (class != NULL) {
422*0Sstevel@tonic-gate if ((*env)->IsInstanceOf(env, e, class) == JNI_TRUE &&
423*0Sstevel@tonic-gate e != NULL) {
424*0Sstevel@tonic-gate result = B_TRUE;
425*0Sstevel@tonic-gate }
426*0Sstevel@tonic-gate }
427*0Sstevel@tonic-gate
428*0Sstevel@tonic-gate return (result);
429*0Sstevel@tonic-gate }
430*0Sstevel@tonic-gate
431*0Sstevel@tonic-gate /* Throw a symbol parsing error */
432*0Sstevel@tonic-gate /* ARGSUSED [one day we should use the `key' argument in messages] */
433*0Sstevel@tonic-gate void
throw_dsym_parser_exception(JNIEnv * env,const char * key,char ** fields,int field,dsym_errcode_t rcode)434*0Sstevel@tonic-gate throw_dsym_parser_exception(JNIEnv *env, const char *key, char **fields,
435*0Sstevel@tonic-gate int field, dsym_errcode_t rcode)
436*0Sstevel@tonic-gate {
437*0Sstevel@tonic-gate const char *dsym_exception = "com/sun/dhcpmgr/bridge/DsymException";
438*0Sstevel@tonic-gate
439*0Sstevel@tonic-gate char ascii_long_1[ULONG_MAX_CHAR + 1];
440*0Sstevel@tonic-gate char ascii_long_2[ULONG_MAX_CHAR + 1];
441*0Sstevel@tonic-gate ushort_t min;
442*0Sstevel@tonic-gate ushort_t max;
443*0Sstevel@tonic-gate
444*0Sstevel@tonic-gate switch (rcode) {
445*0Sstevel@tonic-gate case DSYM_SUCCESS:
446*0Sstevel@tonic-gate break;
447*0Sstevel@tonic-gate case DSYM_SYNTAX_ERROR:
448*0Sstevel@tonic-gate throw_exception(env,
449*0Sstevel@tonic-gate dsym_exception, DSYM_SYNTAX_EX, 1, fields[field]);
450*0Sstevel@tonic-gate break;
451*0Sstevel@tonic-gate case DSYM_CODE_OUT_OF_RANGE:
452*0Sstevel@tonic-gate (void) dsym_get_code_ranges(fields[DSYM_CAT_FIELD],
453*0Sstevel@tonic-gate &min, &max, B_TRUE);
454*0Sstevel@tonic-gate (void) sprintf(ascii_long_1, "%d", min);
455*0Sstevel@tonic-gate (void) sprintf(ascii_long_2, "%d", max);
456*0Sstevel@tonic-gate throw_exception(env, dsym_exception, DSYM_CODE_OUT_OF_RANGE_EX,
457*0Sstevel@tonic-gate 3, fields[DSYM_CAT_FIELD], ascii_long_1, ascii_long_2);
458*0Sstevel@tonic-gate break;
459*0Sstevel@tonic-gate case DSYM_VALUE_OUT_OF_RANGE:
460*0Sstevel@tonic-gate throw_exception(env, dsym_exception,
461*0Sstevel@tonic-gate DSYM_VALUE_OUT_OF_RANGE_EX, 1, fields[field]);
462*0Sstevel@tonic-gate break;
463*0Sstevel@tonic-gate case DSYM_INVALID_CAT:
464*0Sstevel@tonic-gate throw_exception(env, dsym_exception,
465*0Sstevel@tonic-gate DSYM_INVALID_CAT_EX, 1, fields[DSYM_CAT_FIELD]);
466*0Sstevel@tonic-gate break;
467*0Sstevel@tonic-gate case DSYM_INVALID_TYPE:
468*0Sstevel@tonic-gate throw_exception(env, dsym_exception,
469*0Sstevel@tonic-gate DSYM_INVALID_TYPE_EX, 1, fields[DSYM_TYPE_FIELD]);
470*0Sstevel@tonic-gate break;
471*0Sstevel@tonic-gate case DSYM_EXCEEDS_CLASS_SIZE:
472*0Sstevel@tonic-gate (void) sprintf(ascii_long_1, "%d", DSYM_CLASS_SIZE);
473*0Sstevel@tonic-gate throw_exception(env, dsym_exception,
474*0Sstevel@tonic-gate DSYM_EXCEEDS_CLASS_SIZE_EX, 1, ascii_long_1);
475*0Sstevel@tonic-gate break;
476*0Sstevel@tonic-gate case DSYM_EXCEEDS_MAX_CLASS_SIZE:
477*0Sstevel@tonic-gate (void) sprintf(ascii_long_1, "%d", DSYM_MAX_CLASS_SIZE);
478*0Sstevel@tonic-gate throw_exception(env, dsym_exception,
479*0Sstevel@tonic-gate DSYM_EXCEEDS_MAX_CLASS_SIZE_EX, 1, ascii_long_1);
480*0Sstevel@tonic-gate break;
481*0Sstevel@tonic-gate case DSYM_NO_MEMORY:
482*0Sstevel@tonic-gate throw_exception(env, dsym_exception, DSYM_NO_MEMORY_EX, 0);
483*0Sstevel@tonic-gate break;
484*0Sstevel@tonic-gate default:
485*0Sstevel@tonic-gate throw_exception(env, dsym_exception, DSYM_INTERNAL_EX, 0);
486*0Sstevel@tonic-gate }
487*0Sstevel@tonic-gate }
488*0Sstevel@tonic-gate
489*0Sstevel@tonic-gate /* Throw a symbol init parsing error */
490*0Sstevel@tonic-gate void
throw_dsym_parser_init_exception(JNIEnv * env,const char * key,dsym_errcode_t rcode)491*0Sstevel@tonic-gate throw_dsym_parser_init_exception(JNIEnv *env, const char *key,
492*0Sstevel@tonic-gate dsym_errcode_t rcode)
493*0Sstevel@tonic-gate {
494*0Sstevel@tonic-gate const char *dsym_exception = "com/sun/dhcpmgr/bridge/DsymException";
495*0Sstevel@tonic-gate
496*0Sstevel@tonic-gate switch (rcode) {
497*0Sstevel@tonic-gate case DSYM_SUCCESS:
498*0Sstevel@tonic-gate break;
499*0Sstevel@tonic-gate case DSYM_NULL_FIELD:
500*0Sstevel@tonic-gate throw_exception(env,
501*0Sstevel@tonic-gate dsym_exception, DSYM_TOO_FEW_FIELDS_EX, 1, key);
502*0Sstevel@tonic-gate break;
503*0Sstevel@tonic-gate case DSYM_TOO_MANY_FIELDS:
504*0Sstevel@tonic-gate throw_exception(env,
505*0Sstevel@tonic-gate dsym_exception, DSYM_TOO_MANY_FIELDS_EX, 1, key);
506*0Sstevel@tonic-gate break;
507*0Sstevel@tonic-gate case DSYM_NO_MEMORY:
508*0Sstevel@tonic-gate throw_exception(env, dsym_exception, DSYM_NO_MEMORY_EX, 0);
509*0Sstevel@tonic-gate break;
510*0Sstevel@tonic-gate default:
511*0Sstevel@tonic-gate throw_exception(env, dsym_exception, DSYM_INTERNAL_EX, 0);
512*0Sstevel@tonic-gate }
513*0Sstevel@tonic-gate }
514*0Sstevel@tonic-gate
515*0Sstevel@tonic-gate /* Throw an exception indicating an error in wordexp */
516*0Sstevel@tonic-gate void
throw_wordexp_exception(JNIEnv * env,int code)517*0Sstevel@tonic-gate throw_wordexp_exception(JNIEnv *env, int code)
518*0Sstevel@tonic-gate {
519*0Sstevel@tonic-gate char buf[UINT64_MAX_CHAR + 1];
520*0Sstevel@tonic-gate
521*0Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d", code);
522*0Sstevel@tonic-gate throw_exception(env, "com/sun/dhcpmgr/bridge/WordexpException",
523*0Sstevel@tonic-gate NULL, 1, buf);
524*0Sstevel@tonic-gate }
525