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