reindent-again-20030808
[openafs.git] / src / JAVA / libjafs / Internal.c
1 /*
2  * Copyright (c) 2001-2002 International Business Machines Corp.
3  * All rights reserved.
4  *
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  * 
9  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
10  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
11  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
12  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR
13  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
14  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
15  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
16  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
17  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
18  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
19  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
20  */
21
22 #include "Internal.h"
23
24 #ifdef DMALLOC
25 #include "dmalloc.h"
26 #endif
27
28 extern int errno;
29
30 jmethodID MID_String_getBytes = 0;
31
32 #ifndef LIBJUAFS
33 /* User Class and Fields */
34 jclass userCls = 0;
35 jfieldID user_ptsField = 0;
36 jfieldID user_kasField = 0;
37 jfieldID user_nameField = 0;
38 jfieldID user_cachedInfoField = 0;
39 /* PTS Fields */
40 jfieldID user_nameUidField = 0;
41 jfieldID user_ownerUidField = 0;
42 jfieldID user_creatorUidField = 0;
43 jfieldID user_listStatusField = 0;
44 jfieldID user_listGroupsOwnedField = 0;
45 jfieldID user_listMembershipField = 0;
46 jfieldID user_groupCreationQuotaField = 0;
47 jfieldID user_groupMembershipCountField = 0;
48 jfieldID user_ownerField = 0;
49 jfieldID user_creatorField = 0;
50 /* KAS Fields */
51 jfieldID user_adminSettingField = 0;
52 jfieldID user_tgsSettingField = 0;
53 jfieldID user_encSettingField = 0;
54 jfieldID user_cpwSettingField = 0;
55 jfieldID user_rpwSettingField = 0;
56 jfieldID user_userExpirationField = 0;
57 jfieldID user_lastModTimeField = 0;
58 jfieldID user_lastModNameField = 0;
59 jfieldID user_lastChangePasswordTimeField = 0;
60 jfieldID user_maxTicketLifetimeField = 0;
61 jfieldID user_keyVersionField = 0;
62 jfieldID user_encryptionKeyField = 0;
63 jfieldID user_keyCheckSumField = 0;
64 jfieldID user_daysToPasswordExpireField = 0;
65 jfieldID user_failLoginCountField = 0;
66 jfieldID user_lockTimeField = 0;
67 jfieldID user_lockedUntilField = 0;
68
69 /* Group Class and Fields */
70 jclass groupCls = 0;
71 jfieldID group_nameField = 0;
72 jfieldID group_cachedInfoField = 0;
73 jfieldID group_nameUidField = 0;
74 jfieldID group_ownerUidField = 0;
75 jfieldID group_creatorUidField = 0;
76 jfieldID group_listStatusField = 0;
77 jfieldID group_listGroupsOwnedField = 0;
78 jfieldID group_listMembershipField = 0;
79 jfieldID group_listAddField = 0;
80 jfieldID group_listDeleteField = 0;
81 jfieldID group_membershipCountField = 0;
82 jfieldID group_ownerField = 0;
83 jfieldID group_creatorField = 0;
84
85 /* Server Class and Fields */
86 jclass serverCls = 0;
87 jfieldID server_nameField = 0;
88 jfieldID server_cachedInfoField = 0;
89 jfieldID server_databaseField = 0;
90 jfieldID server_fileServerField = 0;
91 jfieldID server_badDatabaseField = 0;
92 jfieldID server_badFileServerField = 0;
93 jfieldID server_IPAddressField = 0;
94
95 /* Executable Time Class and Fields */
96 jclass exectimeCls = 0;
97 jfieldID exectime_HourField = 0;
98 jfieldID exectime_MinField = 0;
99 jfieldID exectime_SecField = 0;
100 jfieldID exectime_DayField = 0;
101 jfieldID exectime_NowField = 0;
102 jfieldID exectime_NeverField = 0;
103
104 /* Partition Class and Fields */
105 jclass partitionCls = 0;
106 jfieldID partition_nameField = 0;
107 jfieldID partition_cachedInfoField = 0;
108 jfieldID partition_idField = 0;
109 jfieldID partition_deviceNameField = 0;
110 jfieldID partition_lockFileDescriptorField = 0;
111 jfieldID partition_totalSpaceField = 0;
112 jfieldID partition_totalFreeSpaceField = 0;
113
114 /* Volume Class and Fields */
115 jclass volumeCls = 0;
116 jfieldID volume_nameField = 0;
117 jfieldID volume_cachedInfoField = 0;
118 jfieldID volume_idField = 0;
119 jfieldID volume_readWriteIdField = 0;
120 jfieldID volume_readOnlyIdField = 0;
121 jfieldID volume_backupIdField = 0;
122 jfieldID volume_creationDateField = 0;
123 jfieldID volume_lastAccessDateField = 0;
124 jfieldID volume_lastUpdateDateField = 0;
125 jfieldID volume_lastBackupDateField = 0;
126 jfieldID volume_copyCreationDateField = 0;
127 jfieldID volume_accessesSinceMidnightField = 0;
128 jfieldID volume_fileCountField = 0;
129 jfieldID volume_maxQuotaField = 0;
130 jfieldID volume_currentSizeField = 0;
131 jfieldID volume_statusField = 0;
132 jfieldID volume_dispositionField = 0;
133 jfieldID volume_typeField = 0;
134
135 /* Key Class and Fields */
136 jclass keyCls = 0;
137 jfieldID key_cachedInfoField = 0;
138 jfieldID key_versionField = 0;
139 jfieldID key_encryptionKeyField = 0;
140 jfieldID key_lastModDateField = 0;
141 jfieldID key_lastModMsField = 0;
142 jfieldID key_checkSumField = 0;
143
144 /* Process Class and Fields */
145 jclass processCls = 0;
146 jfieldID process_cachedInfoField = 0;
147 jfieldID process_nameField = 0;
148 jfieldID process_typeField = 0;
149 jfieldID process_stateField = 0;
150 jfieldID process_goalField = 0;
151 jfieldID process_startTimeField = 0;
152 jfieldID process_numberStartsField = 0;
153 jfieldID process_exitTimeField = 0;
154 jfieldID process_exitErrorTimeField = 0;
155 jfieldID process_errorCodeField = 0;
156 jfieldID process_errorSignalField = 0;
157 jfieldID process_stateOkField = 0;
158 jfieldID process_stateTooManyErrorsField = 0;
159 jfieldID process_stateBadFileAccessField = 0;
160
161 #endif /* !LIBJUAFS */
162
163 /**
164  * Throws an exception up to the Java layer, using ast as the error code
165  * for the exception.  See Exceptions.h for the available
166  * exceptions.
167  */
168 void
169 throwException(JNIEnv * env, jclass * excCls, char *excClsName,
170                jmethodID * initID, int code)
171 {
172     jobject exc;
173     if (*excCls == 0) {
174         *excCls =
175             (*env)->NewGlobalRef(env, (*env)->FindClass(env, excClsName));
176         if (!*excCls) {
177             fprintf(stderr,
178                     "ERROR: Internal::throwException()\n Cannot find class: %s\n",
179                     excClsName);
180             return;
181         }
182         *initID = (*env)->GetMethodID(env, *excCls, "<init>", "(I)V");
183         if (!*initID) {
184             fprintf(stderr,
185                     "ERROR: Internal::throwException()\n Cannot find construction method: %s\n",
186                     excClsName);
187             return;
188         }
189     }
190
191     exc = (*env)->NewObject(env, *excCls, *initID, code);
192     if (!exc) {
193         fprintf(stderr,
194                 "ERROR: Internal::throwException()\n Cannot construct new exception object: %s\n",
195                 excClsName);
196         return;
197     }
198     (*env)->Throw(env, exc);
199 }
200
201 /**
202  * Throws an exception up to the Java layer, constructing it with msg.
203  * This function should only be used when a valid AFS error number/code
204  * is unavailable and it is necessary to interrupt the Java call with an
205  * exception. See Exceptions.h for the available exceptions.
206  */
207 void
208 throwMessageException(JNIEnv * env, char *msg)
209 {
210     jclass excCls = (*env)->FindClass(env, afsExceptionName);
211     if (excCls == 0) {
212         fprintf(stderr,
213                 "ERROR: Internal::throwMessageException()\n Cannot find class: %s\n",
214                 afsExceptionName);
215         return;
216     }
217     (*env)->ThrowNew(env, excCls, msg);
218 }
219
220 /**
221  * Throws an exception up to the Java layer, using ast as the error code
222  * for the exception.  See Exceptions.h for the available
223  * exceptions.
224  */
225 void
226 throwAFSException(JNIEnv * env, int code)
227 {
228     jclass afsExceptionCls;
229     jmethodID afsExceptionInit;
230     jthrowable exc;
231
232     afsExceptionCls = (*env)->FindClass(env, afsExceptionName);
233     if (!afsExceptionCls) {
234         fprintf(stderr,
235                 "ERROR: Internal::throwAFSException()\n Cannot find class: %s\n",
236                 afsExceptionName);
237         return;
238     }
239
240     afsExceptionInit =
241         (*env)->GetMethodID(env, afsExceptionCls, "<init>", "(I)V");
242     if (!afsExceptionInit) {
243         fprintf(stderr,
244                 "ERROR: Internal::throwAFSException()\n Cannot find construction method: %s\n",
245                 afsExceptionName);
246         return;
247     }
248
249     exc = (*env)->NewObject(env, afsExceptionCls, afsExceptionInit, code);
250
251     if (!exc) {
252         fprintf(stderr,
253                 "ERROR: Internal::throwAFSException()\n Cannot construct new exception object: %s\n",
254                 afsExceptionName);
255         return;
256     }
257     (*env)->Throw(env, exc);
258 }
259
260 /**
261  * Throws an exception up to the Java layer, using ast as the error code
262  * for the exception.  See Exceptions.h for the available
263  * exceptions.
264  */
265 void
266 throwAFSFileException(JNIEnv * env, int code, char *msg)
267 {
268     jclass afsFileExceptionCls;
269     jmethodID afsFileExceptionInit;
270     jthrowable exc;
271
272     afsFileExceptionCls = (*env)->FindClass(env, afsFileExceptionName);
273     if (!afsFileExceptionCls) {
274         fprintf(stderr,
275                 "ERROR: Internal::throwAFSFileException()\n Cannot find class: %s\n",
276                 afsFileExceptionName);
277         return;
278     }
279
280     afsFileExceptionInit =
281         (*env)->GetMethodID(env, afsFileExceptionCls, "<init>",
282                             "(Ljava/lang/String;I)V");
283
284     if (!afsFileExceptionInit) {
285         fprintf(stderr,
286                 "ERROR: Internal::throwAFSFileException()\n Cannot find construction method: %s\n",
287                 afsFileExceptionName);
288         return;
289     }
290
291     exc =
292         (*env)->NewObject(env, afsFileExceptionCls, afsFileExceptionInit, msg,
293                           code);
294     if (!exc) {
295         fprintf(stderr,
296                 "ERROR: Internal::throwAFSFileException()\n Cannot construct new exception object: %s\n",
297                 afsFileExceptionName);
298         return;
299     }
300     (*env)->Throw(env, exc);
301 }
302
303 /**
304  * Throws an exception up to the Java layer, using ast as the error code
305  * for the exception.  See Exceptions.h for the available
306  * exceptions.
307  */
308 void
309 throwAFSSecurityException(JNIEnv * env, int code)
310 {
311     jclass afsSecurityExceptionCls;
312     jmethodID afsSecurityExceptionInit;
313     jthrowable exc;
314
315     afsSecurityExceptionCls =
316         (*env)->FindClass(env, afsSecurityExceptionName);
317     if (!afsSecurityExceptionCls) {
318         fprintf(stderr,
319                 "ERROR: Internal::throwAFSSecurityException()\n Cannot find class: %s\n",
320                 afsSecurityExceptionName);
321         return;
322     }
323
324     afsSecurityExceptionInit =
325         (*env)->GetMethodID(env, afsSecurityExceptionCls, "<init>", "(I)V");
326     if (!afsSecurityExceptionInit) {
327         fprintf(stderr,
328                 "ERROR: Internal::throwAFSSecurityException()\n Cannot find construction method: %s\n",
329                 afsSecurityExceptionName);
330         return;
331     }
332
333     exc =
334         (*env)->NewObject(env, afsSecurityExceptionCls,
335                           afsSecurityExceptionInit, code);
336
337     if (!exc) {
338         fprintf(stderr,
339                 "ERROR: Internal::throwAFSSecurityException()\n Cannot construct new exception object: %s\n",
340                 afsSecurityExceptionName);
341         return;
342     }
343     (*env)->Throw(env, exc);
344 }
345
346 int
347 setError(JNIEnv * env, jobject * obj, int code)
348 {
349     jfieldID fid;
350     jclass cls = (*env)->GetObjectClass(env, *obj);
351     if (cls != NULL) {
352         fid = (*env)->GetFieldID(env, cls, "errno", "I");
353         if (fid) {
354             (*env)->SetIntField(env, *obj, fid, code);
355             return 0;
356         }
357     }
358     return -1;
359 }
360
361 int
362 setString(JNIEnv * env, jobject * obj, char *field, char *string)
363 {
364     jclass cls;
365     jstring jstr;
366     jfieldID fid;
367
368     cls = (*env)->GetObjectClass(env, *obj);
369     /*fprintf(stderr, "setString: env=0x%x, obj=0x%x, cls=0x%x\n", env, obj, cls); */
370     if (cls != NULL) {
371         fid = (*env)->GetFieldID(env, cls, field, "Ljava/lang/String;");
372         /*fprintf(stderr, "setString: field=%s, fid=0x%x\n", field, fid); */
373         if (fid) {
374             jstr = (*env)->NewStringUTF(env, (string));
375             /*fprintf(stderr, "jstr = 0x%x\n", jstr); */
376             (*env)->SetObjectField(env, *obj, fid, jstr);
377             return 0;
378         }
379     }
380     return -1;
381 }
382
383 /**
384  * Translates a jstring to a locale-specific native C string.
385  * Use in place of "GetStringUTFChars()" for internationalization
386  * purposes.
387  * 
388  * Make sure to "free()" any strings created by this function.
389  *
390  * A NULL (zero) return indicates a critical error has occurred and 
391  * relies on the caller of this function to throw a Java exception.
392  *
393  * This function does not throw any Java exceptions.
394  * 
395  *  env         the Java environment
396  *  jstr        the Java string (UTF) to translate
397  *
398  * @returns         native C string with the appropriate locale-specific 
399  *              representation
400  */
401 char *
402 getNativeString(JNIEnv * env, const jstring jstr)
403 {
404     jbyteArray bytes = 0;
405     char *result = NULL;
406     jint len = 0;
407
408     if ((*env)->EnsureLocalCapacity(env, 2) < 0) {
409         // Out of memory error
410         fprintf(stderr, "Internal::getNativeString(): ");
411         fprintf(stderr,
412                 "EnsureLocalCapacity() failed: Most likely out of memory\n");
413         return NULL;
414     }
415
416     if (!MID_String_getBytes) {
417         jclass stringClass = (*env)->FindClass(env, "java/lang/String");
418         if (!stringClass) {
419             fprintf(stderr, "Internal::getNativeString(): ");
420             fprintf(stderr,
421                     "Could not locate Java class: java.lang.String.\n");
422             return NULL;
423         }
424
425         MID_String_getBytes =
426             (*env)->GetMethodID(env, stringClass, "getBytes", "()[B");
427         if (!MID_String_getBytes) {
428             fprintf(stderr, "Internal::getNativeString(): ");
429             fprintf(stderr,
430                     "Could not get Java method id for java.lang.String method \"getBytes()\".\n");
431             return NULL;
432         }
433     }
434
435     bytes = (*env)->CallObjectMethod(env, jstr, MID_String_getBytes);
436     if (!bytes) {
437         fprintf(stderr, "Internal::getNativeString(): ");
438         fprintf(stderr,
439                 "CallObjectMethod() failed for java.lang.String.getBytes().\n");
440         fprintf(stderr, "\tMID_String_getBytes = %d\n", MID_String_getBytes);
441         return NULL;
442     }
443
444     len = (*env)->GetArrayLength(env, bytes);
445     result = (char *)malloc(len + 1);
446
447     if (!result) {
448         fprintf(stderr, "Internal::getNativeString(): ");
449         fprintf(stderr, "Could not allocate memory for byte array.\n");
450         (*env)->DeleteLocalRef(env, bytes);
451         return NULL;
452     }
453     (*env)->GetByteArrayRegion(env, bytes, 0, len, (jbyte *) result);
454     result[len] = '\0';         // NULL-terminate
455
456     (*env)->DeleteLocalRef(env, bytes);
457     return result;
458 }
459
460 #ifdef LIBJUAFS
461
462 /**
463  * Opens an AFS file, with the specified name, using the specified flags
464  * with in the specified mode (permission mode).
465  * 
466  *  env         the Java environment
467  *  fileNameUTF name of file to be opened
468  *  flags               open mode: O_CREAT, O_APPEND
469  *  mode                UNIX permission mode mask
470  *  err         error variable
471  *
472  * @returns             file descriptor
473  */
474 int
475 openAFSFile(JNIEnv * env, jstring filenameUTF, int flags, int mode, int *err)
476 {
477     char *filename;
478     int fd = -1;
479
480     *err = 0;
481     errno = 0;
482     filename = getNativeString(env, filenameUTF);
483     if (filename == NULL) {
484         fprintf(stderr, "Internal::openAFSFile(): failed to get filename\n");
485         *err = -1;
486         return fd;
487     }
488     fd = uafs_open(filename, flags, mode);
489     free(filename);
490     *err = errno;
491     if (errno != 0) {
492         fprintf(stderr, "Internal::openAFSFile(): errno=%d\n", errno);
493         fprintf(stderr, "Internal::openAFSFile(): fd=%d\n", fd);
494     }
495     if (fd < 0) {
496         fprintf(stderr, "Internal::openAFSFile(): failed to open filename\n");
497         fprintf(stderr, "Internal::openAFSFile(): fd=%d\n", fd);
498         return -1;
499     }
500     return fd;
501 }
502
503 /**
504  * Reads the "CacheConfig" file for user space configuration.
505  * By default, this file resides in "/usr/afswsp/etc/CacheConfig",
506  * however if the environment variable "LIBJAFS_CACHE_CONFIG" is
507  * set this function will use that value instead.
508  *
509  * The CacheConfig file contains several cache tuning parameters 
510  * as well as a few parameters that define the runtime environment 
511  * for the user space client, including: mount point location, 
512  * configuration directory (where to find ThisCell and CellServDB), 
513  * cache directory, debug and verbose options, and log file location.
514  */
515 int
516 readCacheParms(char *afsMountPoint, char *afsConfDir, char *afsCacheDir,
517                int *cacheBlocks, int *cacheFiles, int *cacheStatEntries,
518                int *dCacheSize, int *vCacheSize, int *chunkSize,
519                int *closeSynch, int *debug, int *nDaemons, int *cacheFlags,
520                char *logFile)
521 {
522     FILE *f;
523     char line[100];
524     char *p;
525     int len1, len2, n;
526     char cacheConfigFile[100];
527
528     p = (char *)getenv("LIBJAFS_CACHE_CONFIG");
529     if (p) {
530         strcpy(cacheConfigFile, p);
531     } else {
532         strcpy(cacheConfigFile, "/usr/afswsp/etc/CacheConfig");
533     }
534
535     f = fopen(cacheConfigFile, "r");
536     if (!f) {
537         fprintf(stderr, "Could not open cache config file: %s\n",
538                 cacheConfigFile);
539         return -1;
540     }
541
542     while (1) {
543         fgets(line, 100, f);
544         if (feof(f))
545             break;
546         p = (char *)strchr(line, '\n');
547         if (p)
548             *p = '\0';
549         if (strncmp(line, "#", 1) == 0)
550             continue;           /* comment */
551
552         p = (char *)strchr(line, ' ');
553         if (!p)
554             continue;
555         len1 = p - line;
556         p++;
557         len2 = strlen(p);
558
559         if (strncmp(line, "MountPoint", len1) == 0)
560             strcpy(afsMountPoint, p);
561         else if (strncmp(line, "ConfDir", len1) == 0)
562             strcpy(afsConfDir, p);
563         else if (strncmp(line, "CacheDir", len1) == 0)
564             strcpy(afsCacheDir, p);
565         else if (strncmp(line, "CacheBlocks", len1) == 0)
566             *cacheBlocks = atoi(p);
567         else if (strncmp(line, "CacheFiles", len1) == 0)
568             *cacheFiles = atoi(p);
569         else if (strncmp(line, "CacheStatEntries", len1) == 0)
570             *cacheStatEntries = atoi(p);
571         else if (strncmp(line, "DCacheSize", len1) == 0)
572             *dCacheSize = atoi(p);
573         else if (strncmp(line, "VCacheSize", len1) == 0)
574             *vCacheSize = atoi(p);
575         else if (strncmp(line, "ChunkSize", len1) == 0)
576             *chunkSize = atoi(p);
577         else if (strncmp(line, "CloseSynch", len1) == 0)
578             *closeSynch = atoi(p);
579         else if (strncmp(line, "Debug", len1) == 0)
580             *debug = atoi(p);
581         else if (strncmp(line, "NDaemons", len1) == 0)
582             *nDaemons = atoi(p);
583         else if (strncmp(line, "CacheFlags", len1) == 0)
584             *cacheFlags = atoi(p);
585         else if (strncmp(line, "LogFile", len1) == 0)
586             strcpy(logFile, p);
587     }
588     return 0;
589 }
590
591 #else
592
593 /**
594  * Makes a kas identity given the full name of a kas user.  If the
595  * name contains a period, everything after the first period is
596  * considered to be the instance of that name, otherwise
597  * the instance is the empty string.  The memory for who 
598  * that's passed in should be fully allocated in advance.
599  */
600 void
601 internal_makeKasIdentity(const char *fullName, kas_identity_p who)
602 {
603     char *period;
604
605     if ((period = (char *)strchr(fullName, '.')) != NULL) {
606         strncpy(who->principal, fullName, period - fullName);
607         who->principal[period - fullName] = '\0';
608         strncpy(who->instance, period + 1,
609                 strlen(fullName) - (period - fullName));
610     } else {
611         strcpy(who->principal, fullName);
612         strcpy(who->instance, "");
613     }
614 }
615
616 /**
617  * Given a Java environment and an instance of a user, gets the object and
618  * field information for the user object from the Java environment.
619  */
620 void
621 internal_getUserClass(JNIEnv * env, jobject user)
622 {
623     if (userCls == 0) {
624         userCls =
625             (*env)->NewGlobalRef(env, (*env)->GetObjectClass(env, user));
626         if (!userCls) {
627             throwAFSException(env, JAFSADMCLASSNOTFOUND);
628             return;
629         }
630         user_ptsField = (*env)->GetFieldID(env, userCls, "pts", "Z");
631         user_kasField = (*env)->GetFieldID(env, userCls, "kas", "Z");
632         user_nameField =
633             (*env)->GetFieldID(env, userCls, "name", "Ljava/lang/String;");
634         user_cachedInfoField =
635             (*env)->GetFieldID(env, userCls, "cachedInfo", "Z");
636         // pts fields
637         user_nameUidField = (*env)->GetFieldID(env, userCls, "nameUID", "I");
638         user_ownerUidField =
639             (*env)->GetFieldID(env, userCls, "ownerUID", "I");
640         user_creatorUidField =
641             (*env)->GetFieldID(env, userCls, "creatorUID", "I");
642         user_listStatusField =
643             (*env)->GetFieldID(env, userCls, "listStatus", "I");
644         user_listGroupsOwnedField =
645             (*env)->GetFieldID(env, userCls, "listGroupsOwned", "I");
646         user_listMembershipField =
647             (*env)->GetFieldID(env, userCls, "listMembership", "I");
648         user_groupCreationQuotaField =
649             (*env)->GetFieldID(env, userCls, "groupCreationQuota", "I");
650         user_groupMembershipCountField =
651             (*env)->GetFieldID(env, userCls, "groupMembershipCount", "I");
652         user_ownerField =
653             (*env)->GetFieldID(env, userCls, "owner", "Ljava/lang/String;");
654         user_creatorField =
655             (*env)->GetFieldID(env, userCls, "creator", "Ljava/lang/String;");
656         // kas fields
657         user_adminSettingField =
658             (*env)->GetFieldID(env, userCls, "adminSetting", "I");
659         user_tgsSettingField =
660             (*env)->GetFieldID(env, userCls, "tgsSetting", "I");
661         user_encSettingField =
662             (*env)->GetFieldID(env, userCls, "encSetting", "I");
663         user_cpwSettingField =
664             (*env)->GetFieldID(env, userCls, "cpwSetting", "I");
665         user_rpwSettingField =
666             (*env)->GetFieldID(env, userCls, "rpwSetting", "I");
667         user_userExpirationField =
668             (*env)->GetFieldID(env, userCls, "userExpiration", "I");
669         user_lastModTimeField =
670             (*env)->GetFieldID(env, userCls, "lastModTime", "I");
671         user_lastModNameField =
672             (*env)->GetFieldID(env, userCls, "lastModName",
673                                "Ljava/lang/String;");
674         user_lastChangePasswordTimeField =
675             (*env)->GetFieldID(env, userCls, "lastChangePasswordTime", "I");
676         user_maxTicketLifetimeField =
677             (*env)->GetFieldID(env, userCls, "maxTicketLifetime", "I");
678         user_keyVersionField =
679             (*env)->GetFieldID(env, userCls, "keyVersion", "I");
680         user_encryptionKeyField =
681             (*env)->GetFieldID(env, userCls, "encryptionKey",
682                                "Ljava/lang/String;");
683         user_keyCheckSumField =
684             (*env)->GetFieldID(env, userCls, "keyCheckSum", "J");
685         user_daysToPasswordExpireField =
686             (*env)->GetFieldID(env, userCls, "daysToPasswordExpire", "I");
687         user_failLoginCountField =
688             (*env)->GetFieldID(env, userCls, "failLoginCount", "I");
689         user_lockTimeField =
690             (*env)->GetFieldID(env, userCls, "lockTime", "I");
691         user_lockedUntilField =
692             (*env)->GetFieldID(env, userCls, "lockedUntil", "I");
693         if (!user_ptsField || !user_kasField || !user_nameField
694             || !user_cachedInfoField || !user_nameUidField
695             || !user_ownerUidField || !user_creatorUidField
696             || !user_listStatusField || !user_listGroupsOwnedField
697             || !user_listMembershipField || !user_groupCreationQuotaField
698             || !user_groupMembershipCountField || !user_ownerField
699             || !user_creatorField || !user_adminSettingField
700             || !user_tgsSettingField || !user_encSettingField
701             || !user_cpwSettingField || !user_rpwSettingField
702             || !user_userExpirationField || !user_lastModTimeField
703             || !user_lastModNameField || !user_lastChangePasswordTimeField
704             || !user_maxTicketLifetimeField || !user_keyVersionField
705             || !user_encryptionKeyField || !user_keyCheckSumField
706             || !user_daysToPasswordExpireField || !user_failLoginCountField
707             || !user_lockTimeField || !user_lockedUntilField) {
708
709             throwAFSException(env, JAFSADMFIELDNOTFOUND);
710             return;
711         }
712     }
713 }
714
715 /**
716  * Given a Java environment and an instance of a group, gets the object and
717  * field information for the group object from the Java environment.
718  */
719 void
720 internal_getGroupClass(JNIEnv * env, jobject group)
721 {
722     if (groupCls == 0) {
723         groupCls =
724             (*env)->NewGlobalRef(env, (*env)->GetObjectClass(env, group));
725         if (!groupCls) {
726             throwAFSException(env, JAFSADMCLASSNOTFOUND);
727             return;
728         }
729         group_nameField =
730             (*env)->GetFieldID(env, groupCls, "name", "Ljava/lang/String;");
731         group_cachedInfoField =
732             (*env)->GetFieldID(env, groupCls, "cachedInfo", "Z");
733         group_nameUidField =
734             (*env)->GetFieldID(env, groupCls, "nameUID", "I");
735         group_ownerUidField =
736             (*env)->GetFieldID(env, groupCls, "ownerUID", "I");
737         group_creatorUidField =
738             (*env)->GetFieldID(env, groupCls, "creatorUID", "I");
739         group_listStatusField =
740             (*env)->GetFieldID(env, groupCls, "listStatus", "I");
741         group_listGroupsOwnedField =
742             (*env)->GetFieldID(env, groupCls, "listGroupsOwned", "I");
743         group_listMembershipField =
744             (*env)->GetFieldID(env, groupCls, "listMembership", "I");
745         group_listAddField =
746             (*env)->GetFieldID(env, groupCls, "listAdd", "I");
747         group_listDeleteField =
748             (*env)->GetFieldID(env, groupCls, "listDelete", "I");
749         group_membershipCountField =
750             (*env)->GetFieldID(env, groupCls, "membershipCount", "I");
751         group_ownerField =
752             (*env)->GetFieldID(env, groupCls, "owner", "Ljava/lang/String;");
753         group_creatorField =
754             (*env)->GetFieldID(env, groupCls, "creator",
755                                "Ljava/lang/String;");
756         if (!group_nameField || !group_cachedInfoField || !group_nameUidField
757             || !group_ownerUidField || !group_creatorUidField
758             || !group_listStatusField || !group_listGroupsOwnedField
759             || !group_listMembershipField || !group_listAddField
760             || !group_listDeleteField || !group_membershipCountField
761             || !group_ownerField || !group_creatorField) {
762
763             throwAFSException(env, JAFSADMFIELDNOTFOUND);
764             return;
765         }
766     }
767 }
768
769 /**
770  * Given a Java environment and an instance of a server, gets the object and
771  * field information for the server object from the Java environment.
772  */
773 void
774 internal_getServerClass(JNIEnv * env, jobject server)
775 {
776     if (serverCls == 0) {
777         serverCls =
778             (*env)->NewGlobalRef(env, (*env)->GetObjectClass(env, server));
779         if (!serverCls) {
780             throwAFSException(env, JAFSADMCLASSNOTFOUND);
781             return;
782         }
783         server_nameField =
784             (*env)->GetFieldID(env, serverCls, "name", "Ljava/lang/String;");
785         server_cachedInfoField =
786             (*env)->GetFieldID(env, serverCls, "cachedInfo", "Z");
787         server_databaseField =
788             (*env)->GetFieldID(env, serverCls, "database", "Z");
789         server_fileServerField =
790             (*env)->GetFieldID(env, serverCls, "fileServer", "Z");
791         server_badDatabaseField =
792             (*env)->GetFieldID(env, serverCls, "badDatabase", "Z");
793         server_badFileServerField =
794             (*env)->GetFieldID(env, serverCls, "badFileServer", "Z");
795         server_IPAddressField =
796             (*env)->GetFieldID(env, serverCls, "ipAddresses",
797                                "[Ljava/lang/String;");
798         if (!server_nameField || !server_cachedInfoField
799             || !server_databaseField || !server_fileServerField
800             || !server_badDatabaseField || !server_badFileServerField
801             || !server_IPAddressField) {
802
803             throwAFSException(env, JAFSADMFIELDNOTFOUND);
804             return;
805
806         }
807     }
808 }
809
810 /**
811  * Given a Java environment and an instance of an executableTime, gets the 
812  * object and field information for the executableTime object from the 
813  * Java environment.
814  */
815 void
816 internal_getExecTimeClass(JNIEnv * env, jobject exectime)
817 {
818     if (exectimeCls == 0) {
819         exectimeCls =
820             (*env)->NewGlobalRef(env, (*env)->GetObjectClass(env, exectime));
821         if (!exectimeCls) {
822             throwAFSException(env, JAFSADMCLASSNOTFOUND);
823             return;
824         }
825         exectime_HourField =
826             (*env)->GetFieldID(env, exectimeCls, "hour", "S");
827         exectime_MinField =
828             (*env)->GetFieldID(env, exectimeCls, "minute", "S");
829         exectime_SecField =
830             (*env)->GetFieldID(env, exectimeCls, "second", "S");
831         exectime_DayField = (*env)->GetFieldID(env, exectimeCls, "day", "S");
832         exectime_NowField = (*env)->GetFieldID(env, exectimeCls, "now", "Z");
833         exectime_NeverField =
834             (*env)->GetFieldID(env, exectimeCls, "never", "Z");
835         if (!exectime_HourField || !exectime_MinField || !exectime_SecField
836             || !exectime_DayField || !exectime_NowField
837             || !exectime_NeverField) {
838
839             throwAFSException(env, JAFSADMFIELDNOTFOUND);
840             return;
841
842         }
843     }
844 }
845
846 /**
847  * Given a Java environment and an instance of a partition, gets the object and
848  * field information for the partition object from the Java environment.
849  */
850 void
851 internal_getPartitionClass(JNIEnv * env, jobject partition)
852 {
853     if (partitionCls == 0) {
854         partitionCls =
855             (*env)->NewGlobalRef(env, (*env)->GetObjectClass(env, partition));
856         if (!partitionCls) {
857             throwAFSException(env, JAFSADMCLASSNOTFOUND);
858             return;
859         }
860         partition_nameField =
861             (*env)->GetFieldID(env, partitionCls, "name",
862                                "Ljava/lang/String;");
863         partition_deviceNameField =
864             (*env)->GetFieldID(env, partitionCls, "deviceName",
865                                "Ljava/lang/String;");
866         partition_idField = (*env)->GetFieldID(env, partitionCls, "id", "I");
867         partition_cachedInfoField =
868             (*env)->GetFieldID(env, partitionCls, "cachedInfo", "Z");
869         partition_lockFileDescriptorField =
870             (*env)->GetFieldID(env, partitionCls, "lockFileDescriptor", "I");
871         partition_totalSpaceField =
872             (*env)->GetFieldID(env, partitionCls, "totalSpace", "I");
873         partition_totalFreeSpaceField =
874             (*env)->GetFieldID(env, partitionCls, "totalFreeSpace", "I");
875         if (!partition_nameField || !partition_cachedInfoField
876             || !partition_idField || !partition_deviceNameField
877             || !partition_lockFileDescriptorField
878             || !partition_totalSpaceField || !partition_totalFreeSpaceField) {
879
880             throwAFSException(env, JAFSADMFIELDNOTFOUND);
881             return;
882
883         }
884     }
885 }
886
887 /**
888  * Given a Java environment and an instance of a volume, gets the object and
889  * field information for the volume object from the Java environment.
890  */
891 void
892 internal_getVolumeClass(JNIEnv * env, jobject volume)
893 {
894     if (volumeCls == 0) {
895         volumeCls =
896             (*env)->NewGlobalRef(env, (*env)->GetObjectClass(env, volume));
897         if (!volumeCls) {
898             throwAFSException(env, JAFSADMCLASSNOTFOUND);
899             return;
900         }
901         volume_nameField =
902             (*env)->GetFieldID(env, volumeCls, "name", "Ljava/lang/String;");
903         volume_cachedInfoField =
904             (*env)->GetFieldID(env, volumeCls, "cachedInfo", "Z");
905         volume_idField = (*env)->GetFieldID(env, volumeCls, "id", "I");
906         volume_readWriteIdField =
907             (*env)->GetFieldID(env, volumeCls, "readWriteID", "I");
908         volume_readOnlyIdField =
909             (*env)->GetFieldID(env, volumeCls, "readOnlyID", "I");
910         volume_backupIdField =
911             (*env)->GetFieldID(env, volumeCls, "backupID", "I");
912         volume_creationDateField =
913             (*env)->GetFieldID(env, volumeCls, "creationDate", "J");
914         volume_lastAccessDateField =
915             (*env)->GetFieldID(env, volumeCls, "lastAccessDate", "J");
916         volume_lastUpdateDateField =
917             (*env)->GetFieldID(env, volumeCls, "lastUpdateDate", "J");
918         volume_lastBackupDateField =
919             (*env)->GetFieldID(env, volumeCls, "lastBackupDate", "J");
920         volume_copyCreationDateField =
921             (*env)->GetFieldID(env, volumeCls, "copyCreationDate", "J");
922         volume_accessesSinceMidnightField =
923             (*env)->GetFieldID(env, volumeCls, "accessesSinceMidnight", "I");
924         volume_fileCountField =
925             (*env)->GetFieldID(env, volumeCls, "fileCount", "I");
926         volume_maxQuotaField =
927             (*env)->GetFieldID(env, volumeCls, "maxQuota", "I");
928         volume_currentSizeField =
929             (*env)->GetFieldID(env, volumeCls, "currentSize", "I");
930         volume_statusField =
931             (*env)->GetFieldID(env, volumeCls, "status", "I");
932         volume_dispositionField =
933             (*env)->GetFieldID(env, volumeCls, "disposition", "I");
934         volume_typeField = (*env)->GetFieldID(env, volumeCls, "type", "I");
935         if (!volume_nameField || !volume_cachedInfoField || !volume_idField
936             || !volume_readWriteIdField || !volume_readOnlyIdField
937             || !volume_backupIdField || !volume_creationDateField
938             || !volume_lastAccessDateField || !volume_lastUpdateDateField
939             || !volume_lastBackupDateField || !volume_copyCreationDateField
940             || !volume_accessesSinceMidnightField || !volume_fileCountField
941             || !volume_maxQuotaField || !volume_currentSizeField
942             || !volume_statusField || !volume_dispositionField
943             || !volume_typeField) {
944
945             throwAFSException(env, JAFSADMFIELDNOTFOUND);
946             return;
947
948         }
949     }
950 }
951
952 /**
953  * Given a Java environment and an instance of a key, gets the object and
954  * field information for the key object from the Java environment.
955  */
956 void
957 internal_getKeyClass(JNIEnv * env, jobject key)
958 {
959     if (keyCls == 0) {
960         keyCls = (*env)->NewGlobalRef(env, (*env)->GetObjectClass(env, key));
961         if (!keyCls) {
962             throwAFSException(env, JAFSADMCLASSNOTFOUND);
963             return;
964         }
965         key_encryptionKeyField =
966             (*env)->GetFieldID(env, keyCls, "encryptionKey",
967                                "Ljava/lang/String;");
968         key_cachedInfoField =
969             (*env)->GetFieldID(env, keyCls, "cachedInfo", "Z");
970         key_versionField = (*env)->GetFieldID(env, keyCls, "version", "I");
971         key_lastModDateField =
972             (*env)->GetFieldID(env, keyCls, "lastModDate", "I");
973         key_lastModMsField =
974             (*env)->GetFieldID(env, keyCls, "lastModMs", "I");
975         key_checkSumField = (*env)->GetFieldID(env, keyCls, "checkSum", "J");
976         if (!key_cachedInfoField || !key_versionField
977             || !key_encryptionKeyField || !key_lastModDateField
978             || !key_lastModMsField || !key_checkSumField) {
979
980             throwAFSException(env, JAFSADMFIELDNOTFOUND);
981             return;
982
983         }
984     }
985 }
986
987 /**
988  * Given a Java environment and an instance of a process, gets the object and
989  * field information for the process object from the Java environment.
990  */
991 void
992 internal_getProcessClass(JNIEnv * env, jobject process)
993 {
994     if (processCls == 0) {
995         processCls =
996             (*env)->NewGlobalRef(env, (*env)->GetObjectClass(env, process));
997         if (!processCls) {
998             throwAFSException(env, JAFSADMCLASSNOTFOUND);
999             return;
1000         }
1001         process_cachedInfoField =
1002             (*env)->GetFieldID(env, processCls, "cachedInfo", "Z");
1003         process_nameField =
1004             (*env)->GetFieldID(env, processCls, "name", "Ljava/lang/String;");
1005         process_typeField = (*env)->GetFieldID(env, processCls, "type", "I");
1006         process_stateField =
1007             (*env)->GetFieldID(env, processCls, "state", "I");
1008         process_goalField = (*env)->GetFieldID(env, processCls, "goal", "I");
1009         process_startTimeField =
1010             (*env)->GetFieldID(env, processCls, "startTime", "J");
1011         process_numberStartsField =
1012             (*env)->GetFieldID(env, processCls, "numberStarts", "J");
1013         process_exitTimeField =
1014             (*env)->GetFieldID(env, processCls, "exitTime", "J");
1015         process_exitErrorTimeField =
1016             (*env)->GetFieldID(env, processCls, "exitErrorTime", "J");
1017         process_errorCodeField =
1018             (*env)->GetFieldID(env, processCls, "errorCode", "J");
1019         process_errorSignalField =
1020             (*env)->GetFieldID(env, processCls, "errorSignal", "J");
1021         process_stateOkField =
1022             (*env)->GetFieldID(env, processCls, "stateOk", "Z");
1023         process_stateTooManyErrorsField =
1024             (*env)->GetFieldID(env, processCls, "stateTooManyErrors", "Z");
1025         process_stateBadFileAccessField =
1026             (*env)->GetFieldID(env, processCls, "stateBadFileAccess", "Z");
1027         if (!process_cachedInfoField || !process_nameField
1028             || !process_typeField || !process_stateField || !process_goalField
1029             || !process_startTimeField || !process_numberStartsField
1030             || !process_exitTimeField || !process_exitErrorTimeField
1031             || !process_errorCodeField || !process_errorSignalField
1032             || !process_stateOkField || !process_stateTooManyErrorsField
1033             || !process_stateBadFileAccessField) {
1034
1035             throwAFSException(env, JAFSADMFIELDNOTFOUND);
1036             return;
1037
1038         }
1039     }
1040 }
1041
1042 #endif /* LIBJUAFS */