java-errno-header-20090526
[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 #include <errno.h>
24
25 #ifdef DMALLOC
26 #include "dmalloc.h"
27 #endif
28
29 #ifndef LIBJUAFS
30 // user class and fields //
31 jclass userCls = 0;
32 jfieldID user_ptsField = 0;
33 jfieldID user_kasField = 0;
34 jfieldID user_nameField = 0;
35 //jfieldID user_cellHandleField = 0;
36 jfieldID user_cachedInfoField = 0;
37 //pts fields
38 jfieldID user_nameUidField = 0;
39 jfieldID user_ownerUidField = 0;
40 jfieldID user_creatorUidField = 0;
41 jfieldID user_listStatusField = 0;
42 jfieldID user_listGroupsOwnedField = 0;
43 jfieldID user_listMembershipField = 0;
44 jfieldID user_groupCreationQuotaField = 0;
45 jfieldID user_groupMembershipCountField = 0;
46 jfieldID user_ownerField = 0;
47 jfieldID user_creatorField = 0;
48 // kas fields
49 jfieldID user_adminSettingField = 0;
50 jfieldID user_tgsSettingField = 0;
51 jfieldID user_encSettingField = 0;
52 jfieldID user_cpwSettingField = 0;
53 jfieldID user_rpwSettingField = 0;
54 jfieldID user_userExpirationField = 0;
55 jfieldID user_lastModTimeField = 0;
56 jfieldID user_lastModNameField = 0;
57 jfieldID user_lastChangePasswordTimeField = 0;
58 jfieldID user_maxTicketLifetimeField = 0;
59 jfieldID user_keyVersionField = 0;
60 jfieldID user_encryptionKeyField = 0;
61 jfieldID user_keyCheckSumField = 0;
62 jfieldID user_daysToPasswordExpireField = 0;
63 jfieldID user_failLoginCountField = 0;
64 jfieldID user_lockTimeField = 0;
65 jfieldID user_lockedUntilField = 0;
66
67 // group class and fields //
68 jclass groupCls = 0;
69 jfieldID group_nameField = 0;
70 //jfieldID group_cellHandleField = 0;
71 jfieldID group_cachedInfoField = 0;
72 jfieldID group_nameUidField = 0;
73 jfieldID group_ownerUidField = 0;
74 jfieldID group_creatorUidField = 0;
75 jfieldID group_listStatusField = 0;
76 jfieldID group_listGroupsOwnedField = 0;
77 jfieldID group_listMembershipField = 0;
78 jfieldID group_listAddField = 0;
79 jfieldID group_listDeleteField = 0;
80 jfieldID group_membershipCountField = 0;
81 jfieldID group_ownerField = 0;
82 jfieldID group_creatorField = 0;
83
84 // server class and fields //
85 jclass serverCls = 0;
86 jfieldID server_nameField = 0;
87 //jfieldID server_cellHandleField = 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_serverHandleField = 0;
149 jfieldID process_typeField = 0;
150 jfieldID process_stateField = 0;
151 jfieldID process_goalField = 0;
152 jfieldID process_startTimeField = 0;
153 jfieldID process_numberStartsField = 0;
154 jfieldID process_exitTimeField = 0;
155 jfieldID process_exitErrorTimeField = 0;
156 jfieldID process_errorCodeField = 0;
157 jfieldID process_errorSignalField = 0;
158 jfieldID process_stateOkField = 0;
159 jfieldID process_stateTooManyErrorsField = 0;
160 jfieldID process_stateBadFileAccessField = 0;
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 throwException
169   (JNIEnv *env, jclass *excCls, char *excClsName, jmethodID *initID, int code)
170 {
171   jobject exc;
172   if( *excCls == 0 ) {
173     *excCls = (*env)->NewGlobalRef(env, (*env)->FindClass(env, excClsName ));
174     if( !*excCls ) {
175       fprintf(stderr, "ERROR: Internal::throwException()\n Cannot find class: %s\n", excClsName);
176         return;
177     }
178     *initID = (*env)->GetMethodID( env, *excCls, "<init>", "(I)V" );
179     if( !*initID ) {
180       fprintf(stderr, "ERROR: Internal::throwException()\n Cannot find construction method: %s\n",
181               excClsName);
182         return;
183     }
184   }
185   
186   exc = (*env)->NewObject( env, *excCls, *initID, code );
187   if( !exc ) {
188     fprintf(stderr, "ERROR: Internal::throwException()\n Cannot construct new exception object: %s\n",
189                      excClsName);
190     return;
191   }
192   (*env)->Throw(env, exc);
193 }
194
195 /**
196  * Throws an exception up to the Java layer, constructing it with msg.
197  * This function should only be used when a valid AFS error number/code
198  * is unavailable and it is necessary to interrupt the Java call with an
199  * exception. See Exceptions.h for the available exceptions.
200  */
201 void throwMessageException( JNIEnv *env, char *msg )
202 {
203   jclass excCls = (*env)->FindClass(env, afsExceptionName);
204   if(excCls == 0) {
205     fprintf(stderr, "ERROR: Internal::throwMessageException()\n Cannot find class: %s\n", afsExceptionName);
206     return;
207   }
208   (*env)->ThrowNew(env, excCls, msg);
209 }
210
211 /**
212  * Throws an exception up to the Java layer, using ast as the error code
213  * for the exception.  See Exceptions.h for the available
214  * exceptions.
215  */
216 void throwAFSException( JNIEnv *env, int code )
217 {
218   jclass afsExceptionCls;
219   jmethodID afsExceptionInit;
220   jthrowable exc;
221
222   afsExceptionCls = (*env)->FindClass(env, afsExceptionName);
223   if( !afsExceptionCls ) {
224     fprintf(stderr, "ERROR: Internal::throwAFSException()\n Cannot find class: %s\n", afsExceptionName);
225     return;
226   }
227
228   afsExceptionInit = (*env)->GetMethodID( env, afsExceptionCls, 
229                              "<init>", "(I)V" );
230   if( !afsExceptionInit ) {
231     fprintf(stderr, "ERROR: Internal::throwAFSException()\n Cannot find construction method: %s\n",
232                      afsExceptionName);
233     return;
234   }
235   
236   exc = (*env)->NewObject( env, afsExceptionCls, afsExceptionInit, code );
237
238   if( !exc ) {
239     fprintf(stderr, "ERROR: Internal::throwAFSException()\n Cannot construct new exception object: %s\n",
240                      afsExceptionName);
241     return;
242   }
243   (*env)->Throw(env, exc);
244 }
245
246 /**
247  * Throws an exception up to the Java layer, using ast as the error code
248  * for the exception.  See Exceptions.h for the available
249  * exceptions.
250  */
251 void throwAFSFileException( JNIEnv *env, int code, char *msg )
252 {
253   jclass afsFileExceptionCls;
254   jmethodID afsFileExceptionInit;
255   jthrowable exc;
256
257   afsFileExceptionCls = (*env)->FindClass(env, afsFileExceptionName);
258   if( !afsFileExceptionCls ) {
259     fprintf(stderr, "ERROR: Internal::throwAFSFileException()\n Cannot find class: %s\n", afsFileExceptionName);
260     return;
261   }
262
263   afsFileExceptionInit = (*env)->GetMethodID( env, afsFileExceptionCls, 
264                          "<init>", "(Ljava/lang/String;I)V" );
265   if( !afsFileExceptionInit ) {
266     fprintf(stderr, "ERROR: Internal::throwAFSFileException()\n Cannot find construction method: %s\n",
267                      afsFileExceptionName);
268     return;
269   }
270   
271   exc = (*env)->NewObject( env, afsFileExceptionCls,
272                            afsFileExceptionInit, msg, code );
273   if( !exc ) {
274     fprintf(stderr, "ERROR: Internal::throwAFSFileException()\n Cannot construct new exception object: %s\n",
275                      afsFileExceptionName);
276     return;
277   }
278   (*env)->Throw(env, exc);
279 }
280
281 /**
282  * Throws an exception up to the Java layer, using ast as the error code
283  * for the exception.  See Exceptions.h for the available
284  * exceptions.
285  */
286 void throwAFSSecurityException( JNIEnv *env, int code )
287 {
288   jclass afsSecurityExceptionCls;
289   jmethodID afsSecurityExceptionInit;
290   jthrowable exc;
291
292   afsSecurityExceptionCls = (*env)->FindClass(env, afsSecurityExceptionName);
293   if( !afsSecurityExceptionCls ) {
294     fprintf(stderr, "ERROR: Internal::throwAFSSecurityException()\n Cannot find class: %s\n", afsSecurityExceptionName);
295     return;
296   }
297
298   afsSecurityExceptionInit = (*env)->GetMethodID( env, afsSecurityExceptionCls, 
299                              "<init>", "(I)V" );
300   if( !afsSecurityExceptionInit ) {
301     fprintf(stderr, "ERROR: Internal::throwAFSSecurityException()\n Cannot find construction method: %s\n",
302                      afsSecurityExceptionName);
303     return;
304   }
305   
306   exc = (*env)->NewObject( env, afsSecurityExceptionCls,
307                            afsSecurityExceptionInit, code );
308   if( !exc ) {
309     fprintf(stderr, "ERROR: Internal::throwAFSSecurityException()\n Cannot construct new exception object: %s\n",
310                      afsSecurityExceptionName);
311     return;
312   }
313   (*env)->Throw(env, exc);
314 }
315
316 int setError(JNIEnv *env, jobject *obj, int code)
317 {
318   jfieldID fid;
319   jclass cls = (*env)->GetObjectClass(env, *obj);
320   if (cls != NULL) {
321     fid = (*env)->GetFieldID(env, cls, "errno", "I");
322     if (fid)
323     {
324       (*env)->SetIntField(env, *obj, fid, code);
325       return 0;
326     }
327   }
328   return -1;
329 }
330
331 #ifdef LIBJUAFS
332
333 /**
334  * Opens an AFS file, with the specified name, using the specified flags
335  * with in the specified mode (permission mode).
336  * 
337  *  env         the Java environment
338  *  fileNameUTF name of file to be opened
339  *  flags               open mode: O_CREAT, O_APPEND
340  *  mode                UNIX permission mode mask
341  *  err         error variable
342  *
343  * @returns             file descriptor
344  */
345 int openAFSFile
346   (JNIEnv *env, jstring fileNameUTF, int flags, int mode, int *err)
347 {
348     char *fileName;
349     int fd = -1;
350
351     *err = 0;
352     errno = 0;
353     fileName=(char*) (*env)->GetStringUTFChars(env, fileNameUTF, 0);
354     if(fileName == NULL) {
355       fprintf(stderr, "Internal::openAFSFile(): failed to get fileName\n");
356       *err = -1;
357       return fd;
358     }
359     fd  = uafs_open(fileName, flags, mode);
360     *err = errno;
361     if (errno != 0) {
362       fprintf(stderr, "Internal::openAFSFile(): errno=%d\n", errno);
363       fprintf(stderr, "Internal::openAFSFile(): fd=%d\n", fd);
364     }
365     (*env)->ReleaseStringUTFChars(env, fileNameUTF, fileName);
366     if (fd < 0) {
367       fprintf(stderr, "Internal::openAFSFile(): failed to open fileName\n");
368       fprintf(stderr, "Internal::openAFSFile(): fd=%d\n", fd);
369       return -1;
370     }
371     return fd;
372 }
373
374 int readCacheParms(char *afsMountPoint, char *afsConfDir, char *afsCacheDir,
375                    int *cacheBlocks, int *cacheFiles, int *cacheStatEntries,
376                    int *dCacheSize, int *vCacheSize, int *chunkSize,
377                    int *closeSynch, int *debug, int *nDaemons, int *cacheFlags,
378                    char *logFile)
379 {
380   FILE *f;
381   char line[100];
382   char *p;
383   int len1, len2, n;
384   char cacheConfigFile[100];
385   
386   p = (char *)getenv("LIBJAFS_CACHE_CONFIG");
387   if (p) {
388     strcpy(cacheConfigFile, p);
389   } else {
390     strcpy(cacheConfigFile, "/usr/afswsp/etc/CacheConfig");
391   }
392
393   f = fopen(cacheConfigFile, "r");
394   if (!f) {
395     fprintf(stderr, "Could not open cache config file: %s\n",
396             cacheConfigFile);
397     return -1;
398   }
399
400   while (1) {
401     fgets(line, 100, f);
402     if (feof(f)) break;
403     p = (char *)strchr(line, '\n');
404     if (p) *p = '\0';
405     if (strncmp(line, "#", 1) == 0) continue;  /* comment */
406
407     p = (char *)strchr(line, ' ');
408     if (!p) continue;
409     len1 = p - line;
410     p++; len2 = strlen(p);
411
412     if (strncmp(line, "MountPoint", len1) == 0)
413        strcpy(afsMountPoint, p);
414     else if (strncmp(line, "ConfDir", len1) == 0)
415        strcpy(afsConfDir, p);
416     else if (strncmp(line, "CacheDir", len1) == 0)
417        strcpy(afsCacheDir, p);
418     else if (strncmp(line, "CacheBlocks", len1) == 0)
419        *cacheBlocks = atoi(p);
420     else if (strncmp(line, "CacheFiles", len1) == 0)
421        *cacheFiles = atoi(p);
422     else if (strncmp(line, "CacheStatEntries", len1) == 0)
423        *cacheStatEntries = atoi(p);
424     else if (strncmp(line, "DCacheSize", len1) == 0)
425        *dCacheSize = atoi(p);
426     else if (strncmp(line, "VCacheSize", len1) == 0)
427        *vCacheSize = atoi(p);
428     else if (strncmp(line, "ChunkSize", len1) == 0)
429        *chunkSize = atoi(p);
430     else if (strncmp(line, "CloseSynch", len1) == 0)
431        *closeSynch = atoi(p);
432     else if (strncmp(line, "Debug", len1) == 0)
433        *debug = atoi(p);
434     else if (strncmp(line, "NDaemons", len1) == 0)
435        *nDaemons = atoi(p);
436     else if (strncmp(line, "CacheFlags", len1) == 0)
437        *cacheFlags = atoi(p);
438     else if (strncmp(line, "LogFile", len1) == 0)
439        strcpy(logFile, p);
440   }
441   return 0;
442 }
443
444 int setString(JNIEnv *env, jobject *obj, char *field, char *string)
445 {
446   jclass cls;
447   jstring jstr;
448   jfieldID fid;
449
450   cls = (*env)->GetObjectClass(env, *obj);
451   /*fprintf(stderr, "setString: env=0x%x, obj=0x%x, cls=0x%x\n", env, obj, cls);*/
452   if (cls != NULL) {
453     fid = (*env)->GetFieldID(env, cls, field, "Ljava/lang/String;");
454     /*fprintf(stderr, "setString: field=%s, fid=0x%x\n", field, fid);*/
455     if (fid) {
456       jstr = (*env)->NewStringUTF(env, (string));
457       /*fprintf(stderr, "jstr = 0x%x\n", jstr);*/
458       (*env)->SetObjectField(env, *obj, fid, jstr);
459       return 0;
460     }
461   }
462   return -1;
463 }
464
465 #else
466
467 /**
468  * Makes a kas identity given the full name of a kas user.  If the
469  * name contains a period, everything after the first period is
470  * considered to be the instance of that name, otherwise
471  * the instance is the empty string.  The memory for who 
472  * that's passed in should be fully allocated in advance.
473  */
474 void internal_makeKasIdentity( const char *fullName, 
475                                        kas_identity_p who ) {
476
477   char *period;
478
479   if( (period = (char *) strchr( fullName, '.' )) != NULL ) {
480     strncpy( who->principal, fullName, period - fullName );
481     who->principal[period - fullName] = '\0';
482     strncpy( who->instance, period + 1, 
483              strlen(fullName) - (period - fullName) );
484   } else {
485     strcpy( who->principal, fullName);
486     strcpy( who->instance, "" );
487   }
488
489 }
490
491 /**
492  * Given a Java environment and an instance of a user, gets the object and
493  * field information for the user object from the Java environment.
494  */
495 void internal_getUserClass( JNIEnv *env, jobject user ) {
496   if( userCls == 0 ) {
497     userCls = (*env)->NewGlobalRef( env, (*env)->GetObjectClass(env, user) );
498     if( !userCls ) {
499         throwAFSException( env, JAFSADMCLASSNOTFOUND );
500         return;
501     }
502     user_ptsField = (*env)->GetFieldID( env, userCls, "pts", "Z" );
503     user_kasField = (*env)->GetFieldID( env, userCls, "kas", "Z" );
504     user_nameField = (*env)->GetFieldID( env, userCls, "name", 
505                                          "Ljava/lang/String;" );
506     user_cachedInfoField = (*env)->GetFieldID( env, userCls, "cachedInfo", 
507                                                "Z" );
508     // pts fields
509     user_nameUidField = (*env)->GetFieldID( env, userCls, "nameUID", "I" );
510     user_ownerUidField = (*env)->GetFieldID( env, userCls, "ownerUID", "I" );
511     user_creatorUidField = (*env)->GetFieldID( env, userCls, "creatorUID", 
512                                                "I" );
513     user_listStatusField = (*env)->GetFieldID( env, userCls, "listStatus", 
514                                                "I" );
515     user_listGroupsOwnedField = (*env)->GetFieldID( env, userCls, 
516                                                     "listGroupsOwned", "I" );
517     user_listMembershipField = (*env)->GetFieldID( env, userCls, 
518                                                    "listMembership", "I" );
519     user_groupCreationQuotaField = (*env)->GetFieldID( env, userCls, 
520                                                        "groupCreationQuota", 
521                                                        "I" );
522     user_groupMembershipCountField = (*env)->GetFieldID( env, userCls, 
523                                                         "groupMembershipCount",
524                                                          "I" );
525     user_ownerField = (*env)->GetFieldID( env, userCls, "owner", 
526                                           "Ljava/lang/String;" );
527     user_creatorField = (*env)->GetFieldID( env, userCls, "creator", 
528                                             "Ljava/lang/String;" );
529     // kas fields
530     user_adminSettingField = (*env)->GetFieldID( env, userCls, "adminSetting",
531                                                  "I" );
532     user_tgsSettingField = (*env)->GetFieldID( env, userCls, "tgsSetting", 
533                                                "I" );
534     user_encSettingField = (*env)->GetFieldID( env, userCls, "encSetting", 
535                                                "I" );
536     user_cpwSettingField = (*env)->GetFieldID( env, userCls, "cpwSetting", 
537                                                "I" );
538     user_rpwSettingField = (*env)->GetFieldID( env, userCls, "rpwSetting", 
539                                                "I" );
540     user_userExpirationField = (*env)->GetFieldID( env, userCls, 
541                                                    "userExpiration", "I" );
542     user_lastModTimeField = (*env)->GetFieldID( env, userCls, "lastModTime", 
543                                                 "I" );
544     user_lastModNameField = (*env)->GetFieldID( env, userCls, "lastModName", 
545                                                 "Ljava/lang/String;" );
546     user_lastChangePasswordTimeField = (*env)->GetFieldID( env, userCls, 
547                                                       "lastChangePasswordTime",
548                                                            "I" );
549     user_maxTicketLifetimeField = (*env)->GetFieldID( env, userCls, 
550                                                       "maxTicketLifetime", 
551                                                       "I" );
552     user_keyVersionField = (*env)->GetFieldID( env, userCls, "keyVersion", 
553                                                "I" );
554     user_encryptionKeyField = (*env)->GetFieldID( env, userCls, 
555                                                   "encryptionKey", 
556                                                   "Ljava/lang/String;" );
557     user_keyCheckSumField = (*env)->GetFieldID( env, userCls, "keyCheckSum", 
558                                                 "J" );
559     user_daysToPasswordExpireField = (*env)->GetFieldID( env, userCls, 
560                                                         "daysToPasswordExpire",
561                                                          "I" );
562     user_failLoginCountField = (*env)->GetFieldID( env, userCls, 
563                                                    "failLoginCount", "I" );
564     user_lockTimeField = (*env)->GetFieldID( env, userCls, "lockTime", "I" );
565     user_lockedUntilField = (*env)->GetFieldID( env, userCls, "lockedUntil", 
566                                                 "I" );
567     if( !user_ptsField || !user_kasField || !user_nameField || 
568         !user_cachedInfoField || !user_nameUidField || !user_ownerUidField || 
569         !user_creatorUidField || !user_listStatusField || 
570         !user_listGroupsOwnedField || !user_listMembershipField || 
571         !user_groupCreationQuotaField || !user_groupMembershipCountField || 
572         !user_ownerField || !user_creatorField || !user_adminSettingField || 
573         !user_tgsSettingField || !user_encSettingField || 
574         !user_cpwSettingField || !user_rpwSettingField || 
575         !user_userExpirationField || !user_lastModTimeField || 
576         !user_lastModNameField || !user_lastChangePasswordTimeField || 
577         !user_maxTicketLifetimeField || !user_keyVersionField || 
578         !user_encryptionKeyField || !user_keyCheckSumField || 
579         !user_daysToPasswordExpireField || !user_failLoginCountField || 
580         !user_lockTimeField || !user_lockedUntilField ) {
581
582         throwAFSException( env, JAFSADMFIELDNOTFOUND );
583         return;
584
585     }
586   } 
587 }
588
589 /**
590  * Given a Java environment and an instance of a group, gets the object and
591  * field information for the group object from the Java environment.
592  */
593 void internal_getGroupClass( JNIEnv *env, jobject group ) {
594   if( groupCls == 0 ) {
595     groupCls = (*env)->NewGlobalRef( env, (*env)->GetObjectClass(env, group) );
596     if( !groupCls ) {
597         throwAFSException( env, JAFSADMCLASSNOTFOUND );
598         return;
599     }
600     group_nameField = (*env)->GetFieldID( env, groupCls, "name", 
601                                           "Ljava/lang/String;" );
602     group_cachedInfoField = (*env)->GetFieldID( env, groupCls, "cachedInfo", 
603                                                 "Z" );
604     group_nameUidField = (*env)->GetFieldID( env, groupCls, "nameUID", "I" );
605     group_ownerUidField = (*env)->GetFieldID( env, groupCls, "ownerUID", "I" );
606     group_creatorUidField = (*env)->GetFieldID( env, groupCls, "creatorUID", 
607                                                 "I" );
608     group_listStatusField = (*env)->GetFieldID( env, groupCls, "listStatus", 
609                                                 "I" );
610     group_listGroupsOwnedField = (*env)->GetFieldID( env, groupCls, 
611                                                      "listGroupsOwned", "I" );
612     group_listMembershipField = (*env)->GetFieldID( env, groupCls, 
613                                                     "listMembership", "I" );
614     group_listAddField = (*env)->GetFieldID( env, groupCls, "listAdd", "I" );
615     group_listDeleteField = (*env)->GetFieldID( env, groupCls, "listDelete", 
616                                                 "I" );
617     group_membershipCountField = (*env)->GetFieldID( env, groupCls, 
618                                                      "membershipCount", "I" );
619     group_ownerField = (*env)->GetFieldID( env, groupCls, "owner", 
620                                            "Ljava/lang/String;" );
621     group_creatorField = (*env)->GetFieldID( env, groupCls, "creator", 
622                                              "Ljava/lang/String;" );
623     if( !group_nameField || !group_cachedInfoField || !group_nameUidField || 
624         !group_ownerUidField || !group_creatorUidField || 
625         !group_listStatusField || !group_listGroupsOwnedField || 
626         !group_listMembershipField || !group_listAddField || 
627         !group_listDeleteField || !group_membershipCountField || 
628         !group_ownerField || !group_creatorField ) {
629
630         throwAFSException( env, JAFSADMFIELDNOTFOUND );
631         return;
632
633     }
634   }
635 }
636
637 /**
638  * Given a Java environment and an instance of a server, gets the object and
639  * field information for the server object from the Java environment.
640  */
641 void internal_getServerClass( JNIEnv *env, jobject server ) {
642   if( serverCls == 0 ) {
643     serverCls = (*env)->NewGlobalRef( env,
644                                       (*env)->GetObjectClass(env, server) );
645     if( !serverCls ) {
646         throwAFSException( env, JAFSADMCLASSNOTFOUND );
647         return;
648     }
649     server_nameField = (*env)->GetFieldID( env, serverCls, "name", 
650                                            "Ljava/lang/String;" );
651     server_cachedInfoField = (*env)->GetFieldID( env, serverCls, "cachedInfo",
652                                                  "Z" );
653     server_databaseField = (*env)->GetFieldID( env, serverCls, "database", 
654                                                "Z" );
655     server_fileServerField = (*env)->GetFieldID( env, serverCls, "fileServer", 
656                                                  "Z" );
657     server_badDatabaseField = (*env)->GetFieldID( env, serverCls, 
658                                                   "badDatabase", "Z" );
659     server_badFileServerField = (*env)->GetFieldID( env, serverCls, 
660                                                     "badFileServer", "Z" );
661     server_IPAddressField = (*env)->GetFieldID( env, serverCls, "ipAddresses",
662                                                 "[Ljava/lang/String;" );
663     if( !server_nameField || !server_cachedInfoField || !server_databaseField 
664         || !server_fileServerField || !server_badDatabaseField || 
665         !server_badFileServerField || !server_IPAddressField ) {
666
667         throwAFSException( env, JAFSADMFIELDNOTFOUND );
668         return;
669
670     }
671   }
672 }
673
674 /**
675  * Given a Java environment and an instance of an executableTime, gets the 
676  * object and field information for the executableTime object from the 
677  * Java environment.
678  */
679 void internal_getExecTimeClass( JNIEnv *env, jobject exectime ) {
680   if( exectimeCls == 0 ) {
681     exectimeCls = (*env)->NewGlobalRef( env, 
682                                        (*env)->GetObjectClass(env, exectime) );
683     if( !exectimeCls ) {
684         throwAFSException( env, JAFSADMCLASSNOTFOUND );
685         return;
686     }
687     exectime_HourField  = (*env)->GetFieldID( env, exectimeCls, "hour", "S" );
688     exectime_MinField   = (*env)->GetFieldID( env, exectimeCls, "minute", 
689                                               "S" );
690     exectime_SecField   = (*env)->GetFieldID( env, exectimeCls, "second", 
691                                               "S" );
692     exectime_DayField   = (*env)->GetFieldID( env, exectimeCls, "day", "S" );
693     exectime_NowField   = (*env)->GetFieldID( env, exectimeCls, "now", "Z" );
694     exectime_NeverField = (*env)->GetFieldID( env, exectimeCls, "never", "Z" );
695     if( !exectime_HourField || !exectime_MinField || !exectime_SecField || 
696         !exectime_DayField || !exectime_NowField || !exectime_NeverField ) {
697
698         throwAFSException( env, JAFSADMFIELDNOTFOUND );
699         return;
700
701     }
702   }
703 }
704
705 /**
706  * Given a Java environment and an instance of a partition, gets the object and
707  * field information for the partition object from the Java environment.
708  */
709 void internal_getPartitionClass( JNIEnv *env, jobject partition ) {
710   if( partitionCls == 0 ) {
711     partitionCls = (*env)->NewGlobalRef( env, 
712                                       (*env)->GetObjectClass(env, partition) );
713     if( !partitionCls ) {
714         throwAFSException( env, JAFSADMCLASSNOTFOUND );
715         return;
716     }
717     partition_nameField = (*env)->GetFieldID( env, partitionCls, "name", 
718                                               "Ljava/lang/String;" );
719     partition_deviceNameField = (*env)->GetFieldID( env, partitionCls, 
720                                                     "deviceName", 
721                                                     "Ljava/lang/String;" );
722     partition_idField = (*env)->GetFieldID( env, partitionCls, "id", "I" );
723     partition_cachedInfoField = (*env)->GetFieldID( env, partitionCls, 
724                                                     "cachedInfo", "Z" );
725     partition_lockFileDescriptorField = (*env)->GetFieldID( env, partitionCls,
726                                                           "lockFileDescriptor",
727                                                             "I" );
728     partition_totalSpaceField = (*env)->GetFieldID( env, partitionCls, 
729                                                     "totalSpace", "I" );
730     partition_totalFreeSpaceField = (*env)->GetFieldID( env, partitionCls, 
731                                                         "totalFreeSpace", "I");
732     if( !partition_nameField || !partition_cachedInfoField || 
733         !partition_idField || !partition_deviceNameField || 
734         !partition_lockFileDescriptorField || !partition_totalSpaceField || 
735         !partition_totalFreeSpaceField ) {
736
737         throwAFSException( env, JAFSADMFIELDNOTFOUND );
738         return;
739
740     }
741   }
742 }
743
744 /**
745  * Given a Java environment and an instance of a volume, gets the object and
746  * field information for the volume object from the Java environment.
747  */
748 void internal_getVolumeClass( JNIEnv *env, jobject volume ) {
749   if( volumeCls == 0 ) {
750     volumeCls = (*env)->NewGlobalRef( env, 
751                                       (*env)->GetObjectClass(env, volume) );
752     if( !volumeCls ) {
753         throwAFSException( env, JAFSADMCLASSNOTFOUND );
754         return;
755     }
756     volume_nameField = (*env)->GetFieldID( env, volumeCls, "name", 
757                                            "Ljava/lang/String;" );
758     volume_cachedInfoField = (*env)->GetFieldID( env, volumeCls, "cachedInfo", 
759                                                  "Z" );
760     volume_idField = (*env)->GetFieldID( env, volumeCls, "id", "I" );
761     volume_readWriteIdField = (*env)->GetFieldID( env, volumeCls, 
762                                                   "readWriteID", "I" );
763     volume_readOnlyIdField = (*env)->GetFieldID( env, volumeCls, "readOnlyID", 
764                                                  "I" );
765     volume_backupIdField = (*env)->GetFieldID( env, volumeCls, "backupID", 
766                                                "I" );
767     volume_creationDateField = (*env)->GetFieldID( env, volumeCls, 
768                                                    "creationDate", "J" );
769     volume_lastAccessDateField = (*env)->GetFieldID( env, volumeCls, 
770                                                      "lastAccessDate", "J" );
771     volume_lastUpdateDateField = (*env)->GetFieldID( env, volumeCls, 
772                                                      "lastUpdateDate", "J" );
773     volume_lastBackupDateField = (*env)->GetFieldID( env, volumeCls, 
774                                                      "lastBackupDate", "J" );
775     volume_copyCreationDateField = (*env)->GetFieldID( env, volumeCls, 
776                                                        "copyCreationDate", 
777                                                        "J" );
778     volume_accessesSinceMidnightField = (*env)->GetFieldID( env, volumeCls, 
779                                                        "accessesSinceMidnight",
780                                                             "I" );
781     volume_fileCountField = (*env)->GetFieldID( env, volumeCls, "fileCount", 
782                                                 "I" );
783     volume_maxQuotaField = (*env)->GetFieldID( env, volumeCls, "maxQuota", 
784                                                "I" );
785     volume_currentSizeField = (*env)->GetFieldID( env, volumeCls, 
786                                                   "currentSize", "I" );
787     volume_statusField = (*env)->GetFieldID( env, volumeCls, "status", "I" );
788     volume_dispositionField = (*env)->GetFieldID( env, volumeCls, 
789                                                   "disposition", "I" );
790     volume_typeField = (*env)->GetFieldID( env, volumeCls, "type", "I" );
791     if( !volume_nameField || !volume_cachedInfoField || !volume_idField || 
792         !volume_readWriteIdField || !volume_readOnlyIdField || 
793         !volume_backupIdField || !volume_creationDateField || 
794         !volume_lastAccessDateField || !volume_lastUpdateDateField || 
795         !volume_lastBackupDateField || !volume_copyCreationDateField || 
796         !volume_accessesSinceMidnightField || !volume_fileCountField || 
797         !volume_maxQuotaField || !volume_currentSizeField || 
798         !volume_statusField || !volume_dispositionField || 
799         !volume_typeField ) {
800
801         throwAFSException( env, JAFSADMFIELDNOTFOUND );
802         return;
803
804     }
805   }
806 }
807
808 /**
809  * Given a Java environment and an instance of a key, gets the object and
810  * field information for the key object from the Java environment.
811  */
812 void internal_getKeyClass( JNIEnv *env, jobject key ) {
813   if( keyCls == 0 ) {
814     keyCls = (*env)->NewGlobalRef( env, (*env)->GetObjectClass(env, key) );
815     if( !keyCls ) {
816         throwAFSException( env, JAFSADMCLASSNOTFOUND );
817         return;
818     }
819     key_encryptionKeyField = (*env)->GetFieldID( env, keyCls, 
820                                                  "encryptionKey", 
821                                                  "Ljava/lang/String;" );
822     key_cachedInfoField = (*env)->GetFieldID( env, keyCls, "cachedInfo", "Z" );
823     key_versionField = (*env)->GetFieldID( env, keyCls, "version", "I" );
824     key_lastModDateField = (*env)->GetFieldID( env, keyCls, "lastModDate", 
825                                                "I" );
826     key_lastModMsField = (*env)->GetFieldID( env, keyCls, "lastModMs", "I" );
827     key_checkSumField = (*env)->GetFieldID( env, keyCls, "checkSum", "J" );
828     if( !key_cachedInfoField || !key_versionField || !key_encryptionKeyField 
829         || !key_lastModDateField || !key_lastModMsField || 
830         !key_checkSumField ) {
831
832         throwAFSException( env, JAFSADMFIELDNOTFOUND );
833         return;
834
835     }
836   }
837 }
838
839 /**
840  * Given a Java environment and an instance of a process, gets the object and
841  * field information for the process object from the Java environment.
842  */
843 void internal_getProcessClass( JNIEnv *env, jobject process ) {
844   if( processCls == 0 ) {
845     processCls = (*env)->NewGlobalRef( env, 
846                                        (*env)->GetObjectClass(env, process) );
847     if( !processCls ) {
848         throwAFSException( env, JAFSADMCLASSNOTFOUND );
849         return;
850     }
851     process_cachedInfoField = (*env)->GetFieldID( env, processCls, 
852                                                   "cachedInfo", "Z" );
853     process_nameField = (*env)->GetFieldID( env, processCls, "name", 
854                                             "Ljava/lang/String;" );
855     process_typeField = (*env)->GetFieldID( env, processCls, "type", "I" );
856     process_stateField = (*env)->GetFieldID( env, processCls, "state", "I" );
857     process_goalField = (*env)->GetFieldID( env, processCls, "goal", "I" );
858     process_startTimeField = (*env)->GetFieldID( env, processCls, "startTime", 
859                                                  "J" ); 
860     process_numberStartsField = (*env)->GetFieldID( env, processCls, 
861                                                     "numberStarts", "J" ); 
862     process_exitTimeField = (*env)->GetFieldID( env, processCls, "exitTime", 
863                                                 "J" ); 
864     process_exitErrorTimeField = (*env)->GetFieldID( env, processCls, 
865                                                      "exitErrorTime", "J" ); 
866     process_errorCodeField = (*env)->GetFieldID( env, processCls, "errorCode", 
867                                                  "J" ); 
868     process_errorSignalField = (*env)->GetFieldID( env, processCls, 
869                                                    "errorSignal", "J" ); 
870     process_stateOkField = (*env)->GetFieldID( env, processCls, "stateOk", 
871                                                "Z" ); 
872     process_stateTooManyErrorsField = (*env)->GetFieldID( env, processCls, 
873                                                           "stateTooManyErrors",
874                                                           "Z" ); 
875     process_stateBadFileAccessField = (*env)->GetFieldID( env, processCls, 
876                                                           "stateBadFileAccess",
877                                                           "Z" ); 
878     if( !process_cachedInfoField || !process_nameField || !process_typeField 
879         || !process_stateField || !process_goalField || 
880         !process_startTimeField || !process_numberStartsField || 
881         !process_exitTimeField || !process_exitErrorTimeField || 
882         !process_errorCodeField || !process_errorSignalField || 
883         !process_stateOkField || !process_stateTooManyErrorsField || 
884         !process_stateBadFileAccessField ) {
885
886         throwAFSException( env, JAFSADMFIELDNOTFOUND );
887         return;
888
889     }
890   }
891 }
892
893 #endif /* LIBJUAFS */
894
895