Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / JAVA / libjafs / Cell.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 "org_openafs_jafs_Cell.h"
24
25 #include <stdio.h>
26 #include <afs_kasAdmin.h>
27 #include <afs_ptsAdmin.h>
28 #include <afs_clientAdmin.h>
29 #include <pterror.h>
30 #include <kautils.h>
31 #include <ptclient.h>
32 #include <afs_AdminPtsErrors.h>
33 #include <afs_AdminClientErrors.h>
34 #include <afs_AdminCommonErrors.h>
35
36 //// definitions in Internal.c //////////////////
37
38 extern jclass userCls;
39 //extern jfieldID user_cellHandleField;
40 extern jfieldID user_nameField;
41 extern jfieldID user_cachedInfoField;
42
43 extern jclass groupCls;
44 //extern jfieldID group_cellHandleField;
45 extern jfieldID group_nameField;
46 extern jfieldID group_cachedInfoField;
47
48 extern jclass serverCls;
49 //extern jfieldID server_cellHandleField;
50 extern jfieldID server_cachedInfoField;
51
52 //////////////////////////////////////////////////////////
53
54 ///// definition in jafs_User.c /////////////////
55
56 extern void getUserInfoChar (JNIEnv *env, void *cellHandle, const char *name,
57 jobject user);
58
59 ///////////////////////////////////////////////////
60
61 ///// definition in jafs_Group.c /////////////////
62
63 extern void getGroupInfoChar (JNIEnv *env, void *cellHandle, const char *name,
64 jobject group);
65
66 ///////////////////////////////////////////////////
67
68 ///// definition in jafs_Server.c /////////////////
69
70 extern void fillServerInfo (JNIEnv *env, void *cellHandle, jobject server,
71 afs_serverEntry_t servEntry);
72
73 ///////////////////////////////////////////////////
74
75 /**
76 * Returns the total number of KAS users belonging to the cell denoted
77 * by cellHandle.
78 *
79 * env the Java environment
80 * cls the current Java class
81 * cellHandle the handle of the cell to which the users belong
82 * returns total count of KAS users
83 */
84 JNIEXPORT jint JNICALL
85 Java_org_openafs_jafs_Cell_getKasUserCount (JNIEnv *env, jclass cls,
86 jlong cellHandle) {
87
88 afs_status_t ast;
89 void *iterationId;
90 kas_identity_t who;
91 int i = 0;
92
93 if( !kas_PrincipalGetBegin( (void *) cellHandle, NULL,
94 &iterationId, &ast ) ) {
95 throwAFSException( env, ast );
96 return -1;
97 }
98
99 while ( kas_PrincipalGetNext( iterationId, &who, &ast ) ) i++;
100
101 if( ast != ADMITERATORDONE ) {
102 throwAFSException( env, ast );
103 return -1;
104 }
105
106 return i;
107 }
108
109
110 /**
111 * Begin the process of getting the kas users that belong to the cell.
112 * Returns an iteration ID to be used by subsequent calls to
113 * getKasUsersNextString (or getKasUsersNext)
114 * and getKasUsersDone.
115 *
116 * env the Java environment
117 * cls the current Java class
118 * cellHandle the handle of the cell to which the users belong
119 * returns an iteration ID
120 */
121 JNIEXPORT jlong JNICALL
122 Java_org_openafs_jafs_Cell_getKasUsersBegin (JNIEnv *env, jclass cls,
123 jlong cellHandle) {
124
125 afs_status_t ast;
126 void *iterationId;
127
128 if( !kas_PrincipalGetBegin( (void *) cellHandle, NULL, &iterationId,
129 &ast ) ) {
130 throwAFSException( env, ast );
131 return;
132 }
133
134 return (jlong) iterationId;
135
136 }
137
138 /**
139 * Begin the process of getting the KAS users, starting at
140 * startIndex, that belong to the cell.
141 * Returns an iteration ID to be used by subsequent calls to
142 * getKasUsersNextString (or getKasUsersNext)
143 * and getKasUsersDone.
144 *
145 * env the Java environment
146 * cls the current Java class
147 * cellHandle the handle of the cell to which the users belong
148 * startIndex the starting base-zero index
149 * returns an iteration ID
150 */
151 JNIEXPORT jlong JNICALL
152 Java_org_openafs_jafs_Cell_getKasUsersBeginAt (JNIEnv *env, jclass cls,
153 jlong cellHandle,
154 jint startIndex) {
155
156 afs_status_t ast;
157 void *iterationId;
158 kas_identity_t who;
159 int i;
160
161 if( !kas_PrincipalGetBegin( (void *) cellHandle, NULL,
162 &iterationId, &ast ) ) {
163 throwAFSException( env, ast );
164 return;
165 }
166
167 for ( i = 1; i < startIndex; i++) {
168 if( !kas_PrincipalGetNext( (void *) iterationId, &who, &ast ) ) {
169 if( ast == ADMITERATORDONE ) {
170 return 0;
171 } else {
172 throwAFSException( env, ast );
173 return 0;
174 }
175 }
176 }
177
178 return (jlong) iterationId;
179
180 }
181
182 /**
183 * Returns the next kas user of the cell. Returns null if there
184 * are no more users. Appends instance names to principal names as follows:
185 * principal.instance
186 *
187 * env the Java environment
188 * cls the current Java class
189 * iterationId the iteration ID of this iteration
190 * returns the name of the next user of the cell
191 */
192 JNIEXPORT jstring JNICALL
193 Java_org_openafs_jafs_Cell_getKasUsersNextString (JNIEnv *env, jclass cls,
194 jlong iterationId) {
195
196 afs_status_t ast;
197 kas_identity_t who;
198 jstring juser;
199
200 if( !kas_PrincipalGetNext( (void *) iterationId, &who, &ast ) ) {
201 if( ast == ADMITERATORDONE ) {
202 return NULL;
203 // other
204 } else {
205 throwAFSException( env, ast );
206 return;
207 }
208 }
209
210 if( strcmp( who.instance, "" ) ) {
211 char *fullName = malloc( sizeof(char)*( strlen( who.principal ) +
212 strlen( who.instance ) + 2 ) );
213 if( !fullName ) {
214 throwAFSException( env, JAFSADMNOMEM );
215 return;
216 }
217 *fullName = '\0';
218 strcat( fullName, who.principal );
219 strcat( fullName, "." );
220 strcat( fullName, who.instance );
221 juser = (*env)->NewStringUTF(env, fullName );
222 free( fullName );
223 } else {
224 juser = (*env)->NewStringUTF(env, who.principal);
225 }
226
227 return juser;
228
229 }
230
231 /**
232 * Fills the next kas user object of the cell. Returns 0 if there
233 * are no more users, != 0 otherwise.
234 *
235 * env the Java environment
236 * cls the current Java class
237 * cellHandle the handle of the cell to which the users belong
238 * iterationId the iteration ID of this iteration
239 * juserObject a User object to be populated with the values of
240 * the next kas user
241 * returns 0 if there are no more users, != 0 otherwise
242 */
243 JNIEXPORT jint JNICALL
244 Java_org_openafs_jafs_Cell_getKasUsersNext (JNIEnv *env, jclass cls,
245 jlong cellHandle,
246 jlong iterationId,
247 jobject juserObject) {
248
249 afs_status_t ast;
250 kas_identity_t who;
251 jstring juser;
252 char *fullName = NULL;
253
254
255 if( !kas_PrincipalGetNext( (void *) iterationId, &who, &ast ) ) {
256 if( ast == ADMITERATORDONE ) {
257 return 0;
258 // other
259 } else {
260 throwAFSException( env, ast );
261 return 0;
262 }
263 }
264
265 // take care of the instance stuff(by concatenating with a period in between)
266 if( strcmp( who.instance, "" ) ) {
267 fullName = malloc( sizeof(char)*( strlen( who.principal ) +
268 strlen( who.instance ) + 2 ) );
269 if( !fullName ) {
270 throwAFSException( env, JAFSADMNOMEM );
271 return 0;
272 }
273 *fullName = '\0';
274 strcat( fullName, who.principal );
275 strcat( fullName, "." );
276 strcat( fullName, who.instance );
277 juser = (*env)->NewStringUTF(env, fullName );
278 } else {
279 juser = (*env)->NewStringUTF(env, who.principal);
280 }
281
282 if( userCls == 0 ) {
283 internal_getUserClass( env, juserObject );
284 }
285
286 (*env)->SetObjectField(env, juserObject, user_nameField, juser);
287
288 if( fullName != NULL ) {
289 getUserInfoChar( env, (void *) cellHandle, fullName, juserObject );
290 free( fullName );
291 } else {
292 getUserInfoChar( env, (void *) cellHandle, who.principal, juserObject );
293 }
294 (*env)->SetBooleanField( env, juserObject, user_cachedInfoField, TRUE );
295
296 return 1;
297
298 }
299
300 /**
301 * Signals that the iteration is complete and will not be accessed anymore.
302 *
303 * env the Java environment
304 * cls the current Java class
305 * iterationId the iteration ID of this iteration
306 */
307 JNIEXPORT void JNICALL
308 Java_org_openafs_jafs_Cell_getKasUsersDone (JNIEnv *env, jclass cls,
309 jlong iterationId) {
310
311 afs_status_t ast;
312
313 if( !kas_PrincipalGetDone( (void *) iterationId, &ast ) ) {
314 throwAFSException( env, ast );
315 return;
316 }
317
318 }
319
320 /**
321 * Returns the name of the cell.
322 *
323 * env the Java environment
324 * cls the current Java class
325 * cellHandle the handle of the cell to which the user belongs
326 * returns the name of the cell
327 */
328 JNIEXPORT jstring JNICALL
329 Java_org_openafs_jafs_Cell_getCellName (JNIEnv *env, jclass cls,
330 jlong cellHandle) {
331
332 afs_status_t ast;
333 char *cellName;
334 jstring jcellName;
335
336 if( !afsclient_CellNameGet( (void *) cellHandle,
337 (const char **) &cellName, &ast ) ) {
338 throwAFSException( env, ast );
339 return;
340 }
341
342 jcellName = (*env)->NewStringUTF(env, cellName);
343
344 return jcellName;
345
346 }
347
348 /**
349 * Returns the total number of PTS users belonging to the cell denoted
350 * by cellHandle.
351 *
352 * env the Java environment
353 * cls the current Java class
354 * cellHandle the handle of the cell to which the users belong
355 * returns total number of PTS users
356 */
357 JNIEXPORT jint JNICALL
358 Java_org_openafs_jafs_Cell_getPtsUserCount (JNIEnv *env, jclass cls,
359 jlong cellHandle) {
360
361 afs_status_t ast;
362 void *iterationId;
363 char *userName;
364 int i = 0;
365
366 if( !pts_UserListBegin( (void *) cellHandle, &iterationId, &ast ) ) {
367 throwAFSException( env, ast );
368 return -1;
369 }
370
371 userName = malloc( sizeof(char)*PTS_MAX_NAME_LEN);
372
373 if( !userName ) {
374 throwAFSException( env, JAFSADMNOMEM );
375 return -1;
376 }
377
378 while ( pts_UserListNext( (void *) iterationId, userName, &ast ) ) i++;
379
380 free( userName );
381
382 if( ast != ADMITERATORDONE ) {
383 throwAFSException( env, ast );
384 return -1;
385 }
386
387 return i;
388 }
389
390 /**
391 * Returns the total number of PTS users, belonging to the cell denoted
392 * by cellHandle, that are not in KAS.
393 *
394 * env the Java environment
395 * cls the current Java class
396 * cellHandle the handle of the cell to which the users belong
397 * returns total number of users that are in PTS and not KAS
398 */
399 JNIEXPORT jint JNICALL
400 Java_org_openafs_jafs_Cell_getPtsOnlyUserCount (JNIEnv *env, jclass cls,
401 jlong cellHandle) {
402
403 afs_status_t ast;
404 void *iterationId;
405 kas_identity_p who = (kas_identity_p) malloc( sizeof(kas_identity_t) );
406 kas_principalEntry_t kasEntry;
407 char *userName;
408 int i = 0;
409
410 if( !who ) {
411 throwAFSException( env, JAFSADMNOMEM );
412 return -1;
413 }
414
415 if( !pts_UserListBegin( (void *) cellHandle, &iterationId, &ast ) ) {
416 free( who );
417 throwAFSException( env, ast );
418 return -1;
419 }
420
421 userName = malloc( sizeof(char)*PTS_MAX_NAME_LEN);
422
423 if( !userName ) {
424 free( who );
425 throwAFSException( env, JAFSADMNOMEM );
426 return -1;
427 }
428
429 while ( pts_UserListNext( (void *) iterationId, userName, &ast ) ) {
430 if( strcmp( userName, "anonymous" ) != 0 ) {
431 // make sure the name is within the allowed bounds
432 if( strlen( userName ) > KAS_MAX_NAME_LEN ) {
433 free( who );
434 free( userName );
435 throwAFSException( env, ADMPTSUSERNAMETOOLONG );
436 return -1;
437 }
438
439 // if there is a kas entry, recurse
440 internal_makeKasIdentity( userName, who );
441 if( !kas_PrincipalGet( (void *) cellHandle, NULL, who,
442 &kasEntry, &ast ) ) i++;
443 }
444 }
445
446 free( userName );
447 free( who );
448
449 if( ast != ADMITERATORDONE ) {
450 throwAFSException( env, ast );
451 return -1;
452 }
453
454 return i;
455 }
456
457 /**
458 * Begin the process of getting the pts users that belong to the cell.
459 * Returns an iteration ID to be used by subsequent calls to
460 * getPtsUsersNextString (or getPtsUsersNext)
461 * and getPtsUsersDone.
462 *
463 * env the Java environment
464 * cls the current Java class
465 * cellHandle the handle of the cell to which the users belong
466 * returns an iteration ID
467 */
468 JNIEXPORT jlong JNICALL
469 Java_org_openafs_jafs_Cell_getPtsUsersBegin (JNIEnv *env, jclass cls,
470 jlong cellHandle) {
471
472 afs_status_t ast;
473 void *iterationId;
474
475 if( !pts_UserListBegin( (void *) cellHandle, &iterationId, &ast ) ) {
476 throwAFSException( env, ast );
477 return;
478 }
479
480 return (jlong) iterationId;
481
482 }
483
484 /**
485 * Returns the next pts user of the cell. Returns null if
486 * there are no more users.
487 *
488 * env the Java environment
489 * cls the current Java class
490 * iterationId the iteration ID of this iteration
491 * returns the name of the next user of the cell
492 */
493 JNIEXPORT jstring JNICALL
494 Java_org_openafs_jafs_Cell_getPtsUsersNextString (JNIEnv *env, jclass cls,
495 jlong iterationId) {
496
497 afs_status_t ast;
498 char *userName;
499 jstring juser;
500
501 userName = malloc( sizeof(char)*PTS_MAX_NAME_LEN);
502
503 if( !userName ) {
504 throwAFSException( env, JAFSADMNOMEM );
505 return;
506 }
507
508 if( !pts_UserListNext( (void *) iterationId, userName, &ast ) ) {
509 free( userName );
510 if( ast == ADMITERATORDONE ) {
511 return NULL;
512 } else {
513 throwAFSException( env, ast );
514 return;
515 }
516 }
517
518 if( strcmp( userName, "anonymous" ) == 0 ) {
519 free( userName );
520 return Java_org_openafs_jafs_Cell_getPtsUsersNextString( env, cls,
521 iterationId );
522 }
523
524 juser = (*env)->NewStringUTF(env, userName);
525 free( userName );
526 return juser;
527
528 }
529
530 /**
531 * Returns the next pts user (who is not a kas user) of the cell.
532 * Returns null if there are no more users.
533 *
534 * env the Java environment
535 * cls the current Java class
536 * iterationId the iteration ID of this iteration
537 * cellHandle the cell handle to which these users will belong
538 * returns the name of the next pts user (not kas user) of the cell
539 */
540 JNIEXPORT jstring JNICALL
541 Java_org_openafs_jafs_Cell_getPtsOnlyUsersNextString (JNIEnv *env,
542 jclass cls,
543 jlong iterationId,
544 jlong cellHandle) {
545
546 kas_identity_p who = (kas_identity_p) malloc( sizeof(kas_identity_t) );
547 kas_principalEntry_t kasEntry;
548 afs_status_t ast;
549 char *userName;
550 jstring juser;
551
552 if( !who ) {
553 throwAFSException( env, JAFSADMNOMEM );
554 return;
555 }
556
557 userName = malloc( sizeof(char)*PTS_MAX_NAME_LEN);
558
559 if( !userName ) {
560 free( who );
561 throwAFSException( env, JAFSADMNOMEM );
562 return;
563 }
564
565 while( 1 ) {
566
567 if( !pts_UserListNext( (void *) iterationId, userName, &ast ) ) {
568 free( userName );
569 free( who );
570 if( ast == ADMITERATORDONE ) {
571 return NULL;
572 } else {
573 throwAFSException( env, ast );
574 return NULL;
575 }
576 }
577
578 if( strcmp( userName, "anonymous" ) == 0 ) {
579 continue;
580 }
581
582 // make sure the name is within the allowed bounds
583 if( strlen( userName ) > KAS_MAX_NAME_LEN ) {
584 free( who );
585 free( userName );
586 throwAFSException( env, ADMPTSUSERNAMETOOLONG );
587 return NULL;
588 }
589
590 // if there is a kas entry, recurse
591 internal_makeKasIdentity( userName, who );
592 if( kas_PrincipalGet( (void *) cellHandle, NULL, who,
593 &kasEntry, &ast ) ) {
594 continue;
595 }
596
597 juser = (*env)->NewStringUTF(env, userName);
598 free( userName );
599 free( who );
600 return juser;
601
602 }
603
604 }
605
606 /**
607 * Fills the next pts user object of the cell. Returns 0 if there
608 * are no more users, != 0 otherwise.
609 *
610 * env the Java environment
611 * cls the current Java class
612 * cellHandle the handle of the cell to which the users belong
613 * iterationId the iteration ID of this iteration
614 * juserObject a User object to be populated with the values of
615 * the next pts user
616 * returns 0 if there are no more users, != 0 otherwise
617 */
618 JNIEXPORT jint JNICALL
619 Java_org_openafs_jafs_Cell_getPtsUsersNext (JNIEnv *env, jclass cls,
620 jlong cellHandle,
621 jlong iterationId,
622 jobject juserObject ) {
623
624 afs_status_t ast;
625 char *userName;
626 jstring juser;
627
628 userName = malloc( sizeof(char)*PTS_MAX_NAME_LEN);
629
630 if( !userName ) {
631 throwAFSException( env, JAFSADMNOMEM );
632 return 0;
633 }
634
635 if( !pts_UserListNext( (void *) iterationId, userName, &ast ) ) {
636 free( userName );
637 if( ast == ADMITERATORDONE ) {
638 return 0;
639 } else {
640 throwAFSException( env, ast );
641 return 0;
642 }
643 }
644
645 if( strcmp( userName, "anonymous" ) == 0 ) {
646 free( userName );
647 return Java_org_openafs_jafs_Cell_getPtsUsersNext( env, cls,
648 cellHandle,
649 iterationId,
650 juserObject );
651 }
652
653 juser = (*env)->NewStringUTF(env, userName);
654
655 if( userCls == 0 ) {
656 internal_getUserClass( env, juserObject );
657 }
658
659 (*env)->SetObjectField(env, juserObject, user_nameField, juser);
660
661 getUserInfoChar( env, (void *) cellHandle, userName, juserObject );
662 (*env)->SetBooleanField( env, juserObject, user_cachedInfoField, TRUE );
663
664 free( userName );
665 return 1;
666
667 }
668
669 /**
670 * Fills the next pts user (who does not have a kas entry) object of
671 * the cell. Returns 0 if there are no more users, != 0 otherwise.
672 *
673 * env the Java environment
674 * cls the current Java class
675 * cellHandle the handle of the cell to which the users belong
676 * iterationId the iteration ID of this iteration
677 * juserObject a User object to be populated with the values of
678 * the next pts (with no kas) user
679 * returns 0 if there are no more users, != 0 otherwise
680 */
681 JNIEXPORT jint JNICALL
682 Java_org_openafs_jafs_Cell_getPtsOnlyUsersNext (JNIEnv *env, jclass cls,
683 jlong cellHandle,
684 jlong iterationId,
685 jobject juserObject ) {
686
687 kas_identity_p who = (kas_identity_p) malloc( sizeof(kas_identity_t) );
688 kas_principalEntry_t kasEntry;
689 afs_status_t ast;
690 char *userName;
691 jstring juser;
692
693 if( !who ) {
694 throwAFSException( env, JAFSADMNOMEM );
695 return 0;
696 }
697
698 userName = malloc( sizeof(char)*PTS_MAX_NAME_LEN);
699
700 if( !userName ) {
701 free( who );
702 throwAFSException( env, JAFSADMNOMEM );
703 return 0;
704 }
705
706 while( 1 ) {
707
708 if( !pts_UserListNext( (void *) iterationId, userName, &ast ) ) {
709 free( userName );
710 free( who );
711 if( ast == ADMITERATORDONE ) {
712 return 0;
713 } else {
714 throwAFSException( env, ast );
715 return 0;
716 }
717 }
718
719 if( strcmp( userName, "anonymous" ) == 0 ) {
720 continue;
721 }
722
723 // make sure the name is within the allowed bounds
724 if( strlen( userName ) > KAS_MAX_NAME_LEN ) {
725 free( userName );
726 free( who );
727 throwAFSException( env, ADMPTSUSERNAMETOOLONG );
728 return 0;
729 }
730
731 if( userCls == 0 ) {
732 internal_getUserClass( env, juserObject );
733 }
734
735
736 // if there is a kas entry, recurse
737 internal_makeKasIdentity( userName, who );
738 if( kas_PrincipalGet( (void *) cellHandle, NULL, who,
739 &kasEntry, &ast ) ) {
740 continue;
741 }
742
743 juser = (*env)->NewStringUTF(env, userName);
744
745 (*env)->SetObjectField(env, juserObject, user_nameField, juser);
746 getUserInfoChar( env, (void *) cellHandle, userName, juserObject );
747 (*env)->SetBooleanField( env, juserObject, user_cachedInfoField, TRUE );
748
749 free( who );
750 free( userName );
751 return 1;
752
753 }
754
755 }
756
757 /**
758 * Signals that the iteration is complete and will not be accessed anymore.
759 *
760 * env the Java environment
761 * cls the current Java class
762 * iterationId the iteration ID of this iteration
763 */
764 JNIEXPORT void JNICALL
765 Java_org_openafs_jafs_Cell_getPtsUsersDone (JNIEnv *env, jclass cls,
766 jlong iterationId) {
767
768 afs_status_t ast;
769
770 if( !pts_UserListDone( (void *) iterationId, &ast ) ) {
771 throwAFSException( env, ast );
772 return;
773 }
774
775 }
776
777 /**
778 * Returns the total number of groups belonging to the cell denoted
779 * by cellHandle.
780 *
781 * env the Java environment
782 * cls the current Java class
783 * cellHandle the handle of the cell to which the groups belong
784 * returns total number of groups
785 */
786 JNIEXPORT jint JNICALL
787 Java_org_openafs_jafs_Cell_getGroupCount (JNIEnv *env, jclass cls,
788 jlong cellHandle) {
789
790 afs_status_t ast;
791 void *iterationId;
792 char *groupName;
793 int i = 0;
794
795 if( !pts_GroupListBegin( (void *) cellHandle, &iterationId, &ast ) ) {
796 throwAFSException( env, ast );
797 return -1;
798 }
799
800 groupName = malloc( sizeof(char)*PTS_MAX_NAME_LEN);
801
802 if( !groupName ) {
803 throwAFSException( env, JAFSADMNOMEM );
804 return -1;
805 }
806
807 while ( pts_GroupListNext( (void *) iterationId, groupName, &ast ) ) i++;
808
809 free( groupName );
810
811 if( ast != ADMITERATORDONE ) {
812 throwAFSException( env, ast );
813 return -1;
814 }
815
816 return i;
817 }
818
819 /**
820 * Begin the process of getting the groups that belong to the cell. Returns
821 * an iteration ID to be used by subsequent calls to
822 * getGroupsNextString (or getGroupsNext) and
823 * getGroupsDone.
824 *
825 * env the Java environment
826 * cls the current Java class
827 * cellHandle the handle of the cell to which the groups belong
828 * returns an iteration ID
829 */
830 JNIEXPORT jlong JNICALL
831 Java_org_openafs_jafs_Cell_getGroupsBegin (JNIEnv *env, jclass cls,
832 jlong cellHandle) {
833
834 afs_status_t ast;
835 void *iterationId;
836
837 if( !pts_GroupListBegin( (void *) cellHandle, &iterationId, &ast ) ) {
838 throwAFSException( env, ast );
839 return;
840 }
841
842 return (jlong) iterationId;
843
844 }
845
846 /**
847 * Begin the process of getting the groups that belong to the cell, starting
848 * with element index startIndex. Returns an iteration ID to
849 * be used by subsequent calls to getGroupsNextString
850 * (or getGroupsNext) and getGroupsDone.
851 *
852 * env the Java environment
853 * cls the current Java class
854 * cellHandle the handle of the cell to which the groups belong
855 * startIndex the starting base-zero index
856 * returns an iteration ID
857 */
858 JNIEXPORT jlong JNICALL
859 Java_org_openafs_jafs_Cell_getGroupsBeginAt (JNIEnv *env, jclass cls,
860 jlong cellHandle,
861 jint startIndex) {
862
863 afs_status_t ast;
864 void *iterationId;
865 char *groupName;
866 int i;
867
868 groupName = malloc( sizeof(char)*PTS_MAX_NAME_LEN);
869
870 if( !pts_GroupListBegin( (void *) cellHandle, &iterationId, &ast ) ) {
871 throwAFSException( env, ast );
872 return 0;
873 }
874
875 for ( i = 1; i < startIndex; i++) {
876 if( !pts_GroupListNext( (void *) iterationId, groupName, &ast ) ) {
877 free( groupName );
878 if( ast == ADMITERATORDONE ) {
879 return 0;
880 } else {
881 throwAFSException( env, ast );
882 return 0;
883 }
884 }
885 }
886
887 free( groupName );
888 return (jlong) iterationId;
889
890 }
891
892 /**
893 * Returns the next group of the cell. Returns null if there
894 * are no more groups.
895 *
896 * env the Java environment
897 * cls the current Java class
898 * iterationId the iteration ID of this iteration
899 * returns the name of the next user of the cell
900 */
901 JNIEXPORT jstring JNICALL
902 Java_org_openafs_jafs_Cell_getGroupsNextString (JNIEnv *env, jclass cls,
903 jlong iterationId) {
904
905 afs_status_t ast;
906 char *groupName;
907 jstring jgroup;
908
909 groupName = malloc( sizeof(char)*PTS_MAX_NAME_LEN);
910
911 if( !groupName ) {
912 throwAFSException( env, JAFSADMNOMEM );
913 return;
914 }
915
916 if( !pts_GroupListNext( (void *) iterationId, groupName, &ast ) ) {
917 free( groupName );
918 if( ast == ADMITERATORDONE ) {
919 return NULL;
920 } else {
921 throwAFSException( env, ast );
922 return;
923 }
924 }
925
926 jgroup = (*env)->NewStringUTF(env, groupName);
927 free( groupName );
928 return jgroup;
929
930 }
931
932 /**
933 * Fills the next group object of the cell. Returns 0 if there
934 * are no more groups, != 0 otherwise.
935 *
936 * env the Java environment
937 * cls the current Java class
938 * cellHandle the handle of the cell to which the users belong
939 * iterationId the iteration ID of this iteration
940 * jgroupObject a Group object to be populated with the values of
941 * the next group
942 * returns 0 if there are no more users, != 0 otherwise
943 */
944 JNIEXPORT jint JNICALL
945 Java_org_openafs_jafs_Cell_getGroupsNext (JNIEnv *env, jclass cls,
946 jlong cellHandle,
947 jlong iterationId,
948 jobject jgroupObject) {
949
950 afs_status_t ast;
951 char *groupName;
952 jstring jgroup;
953
954 groupName = malloc( sizeof(char)*PTS_MAX_NAME_LEN );
955
956 if( !groupName ) {
957 throwAFSException( env, JAFSADMNOMEM );
958 return;
959 }
960
961 if( !pts_GroupListNext( (void *) iterationId, groupName, &ast ) ) {
962 free( groupName );
963 if( ast == ADMITERATORDONE ) {
964 return 0;
965 } else {
966 throwAFSException( env, ast );
967 return 0;
968 }
969 }
970
971 jgroup = (*env)->NewStringUTF(env, groupName);
972
973 if( groupCls == 0 ) {
974 internal_getGroupClass( env, jgroupObject );
975 }
976
977 (*env)->SetObjectField(env, jgroupObject, group_nameField, jgroup);
978 getGroupInfoChar( env, (void *)cellHandle, groupName, jgroupObject );
979 (*env)->SetBooleanField( env, jgroupObject, group_cachedInfoField, TRUE );
980
981 free( groupName );
982 return 1;
983
984 }
985
986 /**
987 * Signals that the iteration is complete and will not be accessed anymore.
988 *
989 * env the Java environment
990 * cls the current Java class
991 * iterationId the iteration ID of this iteration
992 */
993 JNIEXPORT void JNICALL
994 Java_org_openafs_jafs_Cell_getGroupsDone (JNIEnv *env, jclass cls,
995 jlong iterationId) {
996
997 afs_status_t ast;
998
999 if( !pts_GroupListDone( (void *) iterationId, &ast ) ) {
1000 throwAFSException( env, ast );
1001 return;
1002 }
1003
1004 }
1005
1006 /**
1007 * Gets the maximum group pts ID that's been used within a cell.
1008 * The next auto-assigned group ID will be one less (more negative)
1009 * than this value.
1010 *
1011 * env the Java environment
1012 * cls the current Java class
1013 * cellHandle the handle of the cell to which the group belongs
1014 * returns an integer reresenting the max group id in a cell
1015 */
1016 JNIEXPORT jint JNICALL
1017 Java_org_openafs_jafs_Cell_getMaxGroupID (JNIEnv *env, jclass cls,
1018 jlong cellHandle) {
1019
1020 afs_status_t ast;
1021 int maxID;
1022
1023 if( !pts_GroupMaxGet( (void *) cellHandle, &maxID, &ast ) ) {
1024 throwAFSException( env, ast );
1025 return;
1026 }
1027
1028 return (jint)maxID;
1029
1030 }
1031
1032 /**
1033 * Sets the maximum group pts ID that's been used within a cell. The next
1034 * auto-assigned group ID will be one less (more negative) than this value.
1035 *
1036 * env the Java environment
1037 * cls the current Java class
1038 * cellHandle the handle of the cell to which the group belongs
1039 * maxID an integer reresenting the new max group id in a cell
1040 */
1041 JNIEXPORT void JNICALL
1042 Java_org_openafs_jafs_Cell_setMaxGroupID (JNIEnv *env, jclass cls,
1043 jlong cellHandle, jint maxID) {
1044
1045 afs_status_t ast;
1046
1047 if( !pts_GroupMaxSet( (void *) cellHandle, (int) maxID, &ast ) ) {
1048 throwAFSException( env, ast );
1049 return;
1050 }
1051
1052 }
1053
1054 /**
1055 * Gets the maximum user pts ID that's been used within a cell.
1056 * The next auto-assigned user ID will be one greater (more positive)
1057 * than this value.
1058 *
1059 * env the Java environment
1060 * cls the current Java class
1061 * cellHandle the handle of the cell to which the user belongs
1062 * returns an integer reresenting the max user id in a cell
1063 */
1064 JNIEXPORT jint JNICALL
1065 Java_org_openafs_jafs_Cell_getMaxUserID (JNIEnv *env, jclass cls,
1066 jlong cellHandle) {
1067
1068 afs_status_t ast;
1069 int maxID;
1070
1071 if( !pts_UserMaxGet( (void *) cellHandle, &maxID, &ast ) ) {
1072 throwAFSException( env, ast );
1073 return;
1074 }
1075
1076 return (jint)maxID;
1077
1078 }
1079
1080 /**
1081 * Sets the maximum user pts ID that's been used within a cell. The next
1082 * auto-assigned user ID will be one greater (more positive) than this value.
1083 *
1084 * env the Java environment
1085 * cls the current Java class
1086 * cellHandle the handle of the cell to which the user belongs
1087 * maxID an integer reresenting the new max user id in a cell
1088 */
1089 JNIEXPORT void JNICALL
1090 Java_org_openafs_jafs_Cell_setMaxUserID (JNIEnv *env, jclass cls,
1091 jlong cellHandle, jint maxID) {
1092
1093 afs_status_t ast;
1094
1095 if( !pts_UserMaxSet( (void *) cellHandle, (int) maxID, &ast ) ) {
1096 throwAFSException( env, ast );
1097 return;
1098 }
1099
1100 }
1101
1102 /**
1103 * Returns the total number of servers belonging to the cell denoted
1104 * by cellHandle.
1105 *
1106 * env the Java environment
1107 * cls the current Java class
1108 * cellHandle the handle of the cell to which the servers belong
1109 * returns total number of servers
1110 */
1111 JNIEXPORT jint JNICALL
1112 Java_org_openafs_jafs_Cell_getServerCount (JNIEnv *env, jclass cls,
1113 jlong cellHandle) {
1114
1115 afs_status_t ast;
1116 void *iterationId;
1117 afs_serverEntry_t servEntry;
1118 int i = 0;
1119
1120 if( !afsclient_AFSServerGetBegin( (void *) cellHandle,
1121 &iterationId, &ast ) ) {
1122 throwAFSException( env, ast );
1123 return -1;
1124 }
1125
1126 while ( afsclient_AFSServerGetNext( (void *) iterationId,
1127 &servEntry, &ast ) ) i++;
1128
1129 if( ast != ADMITERATORDONE ) {
1130 throwAFSException( env, ast );
1131 return -1;
1132 }
1133
1134 return i;
1135 }
1136
1137 /**
1138 * Begin the process of getting the servers in the cell. Returns
1139 * an iteration ID to be used by subsequent calls to
1140 * getServersNextString and getServersDone.
1141 *
1142 * env the Java environment
1143 * cls the current Java class
1144 * cellHandle the handle of the cell to which the servers belong
1145 * returns an iteration ID
1146 */
1147 JNIEXPORT jlong JNICALL
1148 Java_org_openafs_jafs_Cell_getServersBegin (JNIEnv *env, jclass cls,
1149 jlong cellHandle) {
1150
1151 afs_status_t ast;
1152 void *iterationId;
1153
1154 if( !afsclient_AFSServerGetBegin( (void *) cellHandle,
1155 &iterationId, &ast ) ) {
1156 throwAFSException( env, ast );
1157 return;
1158 }
1159
1160 return (jlong) iterationId;
1161
1162 }
1163
1164 /**
1165 * Returns the next server of the cell. Returns null if there
1166 * are no more servers.
1167 *
1168 * env the Java environment
1169 * cls the current Java class
1170 * iterationId the iteration ID of this iteration
1171 * returns the name of the next server of the cell
1172 */
1173 JNIEXPORT jstring JNICALL
1174 Java_org_openafs_jafs_Cell_getServersNextString (JNIEnv *env, jclass cls,
1175 jlong iterationId) {
1176
1177 afs_status_t ast;
1178 jstring jserver;
1179 afs_serverEntry_t servEntry;
1180
1181 if( !afsclient_AFSServerGetNext( (void *) iterationId, &servEntry, &ast ) ) {
1182 if( ast == ADMITERATORDONE ) {
1183 return NULL;
1184 } else {
1185 throwAFSException( env, ast );
1186 return NULL;
1187 }
1188 }
1189
1190 jserver = (*env)->NewStringUTF(env, "not_implemented"); /* psomogyi 20050514 */
1191
1192 return jserver;
1193 }
1194
1195 /**
1196 * Fills the next server object of the cell. Returns 0 if there are no
1197 * more servers, != 0 otherwise.
1198 *
1199 * env the Java environment
1200 * cls the current Java class
1201 * cellHandle the handle of the cell to which the users belong
1202 * iterationId the iteration ID of this iteration
1203 * jserverObject a Server object to be populated with the values
1204 * of the next server
1205 * returns 0 if there are no more servers, != 0 otherwise
1206 */
1207 JNIEXPORT jint JNICALL
1208 Java_org_openafs_jafs_Cell_getServersNext
1209 (JNIEnv *env, jclass cls, jlong cellHandle, jlong iterationId,
1210 jobject jserverObject)
1211 {
1212 afs_status_t ast;
1213 jstring jserver;
1214 afs_serverEntry_t servEntry;
1215 jintArray jaddress;
1216
1217 if( !afsclient_AFSServerGetNext( (void *) iterationId, &servEntry, &ast ) ) {
1218 if( ast == ADMITERATORDONE ) {
1219 return 0;
1220 } else {
1221 throwAFSException( env, ast );
1222 return 0;
1223 }
1224 }
1225
1226 // get the class fields if need be
1227 if( serverCls == 0 ) {
1228 internal_getServerClass( env, jserverObject );
1229 }
1230
1231 fillServerInfo( env, (void *) cellHandle, jserverObject, servEntry );
1232
1233 (*env)->SetBooleanField( env, jserverObject, server_cachedInfoField, TRUE );
1234
1235 return 1;
1236 }
1237
1238 /**
1239 * Signals that the iteration is complete and will not be accessed anymore.
1240 *
1241 * env the Java environment
1242 * cls the current Java class
1243 * iterationId the iteration ID of this iteration
1244 */
1245 JNIEXPORT void JNICALL
1246 Java_org_openafs_jafs_Cell_getServersDone
1247 (JNIEnv *env, jclass cls, jlong iterationId)
1248 {
1249 afs_status_t ast;
1250
1251 if( !afsclient_AFSServerGetDone( (void *) iterationId, &ast ) ) {
1252 throwAFSException( env, ast );
1253 return;
1254 }
1255
1256 }
1257
1258 /**
1259 * Creates a mount point for a volume within the file system.
1260 *
1261 * env the Java environment
1262 * cls the current Java class
1263 * cellHandle the handle of the cell to which the user belongs
1264 * jdirectory the full path of the place in the AFS file system
1265 * at which to mount the volume
1266 * jvolumeName the name of the volume to mount
1267 * readWrite whether or not this is to be a readwrite mount point
1268 * forceCheck whether or not to check if this volume name exists
1269 */
1270 JNIEXPORT void JNICALL
1271 Java_org_openafs_jafs_Cell_createMountPoint (JNIEnv *env, jclass cls,
1272 jlong cellHandle,
1273 jstring jdirectory,
1274 jstring jvolumeName,
1275 jboolean readWrite,
1276 jboolean forceCheck) {
1277
1278 afs_status_t ast;
1279 const char *directory;
1280 const char *volumeName;
1281 vol_type_t type;
1282 vol_check_t check;
1283
1284 if( jdirectory != NULL ) {
1285 directory = (*env)->GetStringUTFChars(env, jdirectory, 0);
1286 if( !directory ) {
1287 throwAFSException( env, JAFSADMNOMEM );
1288 return;
1289 }
1290 } else {
1291 directory = NULL;
1292 }
1293 if( jvolumeName != NULL ) {
1294 volumeName = (*env)->GetStringUTFChars(env, jvolumeName, 0);
1295 if( !volumeName ) {
1296 if( directory != NULL ) {
1297 (*env)->ReleaseStringUTFChars(env, jdirectory, directory);
1298 }
1299 throwAFSException( env, JAFSADMNOMEM );
1300 return;
1301 }
1302 } else {
1303 volumeName = NULL;
1304 }
1305
1306 if( readWrite ) {
1307 type = READ_WRITE;
1308 } else {
1309 type = READ_ONLY;
1310 }
1311
1312 if( forceCheck ) {
1313 check = CHECK_VOLUME;
1314 } else {
1315 check = DONT_CHECK_VOLUME;
1316 }
1317
1318 if( !afsclient_MountPointCreate( (void *) cellHandle, directory,
1319 volumeName, type, check, &ast ) ) {
1320 if( volumeName != NULL ) {
1321 (*env)->ReleaseStringUTFChars(env, jvolumeName, volumeName);
1322 }
1323 if( directory != NULL ) {
1324 (*env)->ReleaseStringUTFChars(env, jdirectory, directory);
1325 }
1326 throwAFSException( env, ast );
1327 return;
1328 }
1329
1330 if( volumeName != NULL ) {
1331 (*env)->ReleaseStringUTFChars(env, jvolumeName, volumeName);
1332 }
1333 if( directory != NULL ) {
1334 (*env)->ReleaseStringUTFChars(env, jdirectory, directory);
1335 }
1336
1337 }
1338
1339 /*
1340 * Sets an ACL for a given place in the AFS file system.
1341 *
1342 * env the Java environment
1343 * cls the current Java class
1344 * jdirectory the full path of the place in the AFS file system
1345 * for which to add an entry
1346 * jusername the name of the user or group for which to add an entry
1347 * read whether or not to allow read access to this user
1348 * write whether or not to allow write access to this user
1349 * lookup whether or not to allow lookup access to this user
1350 * delete whether or not to allow deletion access to this user
1351 * insert whether or not to allow insertion access to this user
1352 * lock whether or not to allow lock access to this user
1353 * admin whether or not to allow admin access to this user
1354 */
1355 JNIEXPORT void JNICALL
1356 Java_org_openafs_jafs_Cell_setACL (JNIEnv *env, jclass cls,
1357 jstring jdirectory, jstring juserName,
1358 jboolean read, jboolean write,
1359 jboolean lookup, jboolean delete,
1360 jboolean insert, jboolean lock,
1361 jboolean admin) {
1362
1363 afs_status_t ast;
1364 const char *directory;
1365 const char *userName;
1366 acl_t acl;
1367
1368 // Added by MP
1369 if( !afsclient_Init( &ast ) ) {
1370 throwAFSException( env, ast );
1371 return;
1372 }
1373
1374 if( jdirectory != NULL ) {
1375 directory = (*env)->GetStringUTFChars(env, jdirectory, 0);
1376 if( !directory ) {
1377 throwAFSException( env, JAFSADMNOMEM );
1378 return;
1379 }
1380 } else {
1381 directory = NULL;
1382 }
1383 if( juserName != NULL ) {
1384 userName = (*env)->GetStringUTFChars(env, juserName, 0);
1385 if( !userName ) {
1386 if( directory != NULL ) {
1387 (*env)->ReleaseStringUTFChars(env, jdirectory, directory);
1388 }
1389 throwAFSException( env, JAFSADMNOMEM );
1390 return;
1391 }
1392 } else {
1393 userName = NULL;
1394 }
1395
1396 if( read ) {
1397 acl.read = READ;
1398 } else {
1399 acl.read = NO_READ;
1400 }
1401
1402 if( write ) {
1403 acl.write = WRITE;
1404 } else {
1405 acl.write = NO_WRITE;
1406 }
1407
1408 if( lookup ) {
1409 acl.lookup = LOOKUP;
1410 } else {
1411 acl.lookup = NO_LOOKUP;
1412 }
1413
1414 if( delete ) {
1415 acl.del = DELETE;
1416 } else {
1417 acl.del = NO_DELETE;
1418 }
1419
1420 if( insert ) {
1421 acl.insert = INSERT;
1422 } else {
1423 acl.insert = NO_INSERT;
1424 }
1425
1426 if( lock ) {
1427 acl.lock = LOCK;
1428 } else {
1429 acl.lock = NO_LOCK;
1430 }
1431
1432 if( admin ) {
1433 acl.admin = ADMIN;
1434 } else {
1435 acl.admin = NO_ADMIN;
1436 }
1437
1438 if( !afsclient_ACLEntryAdd( directory, userName, &acl, &ast ) ) {
1439 if( userName != NULL ) {
1440 (*env)->ReleaseStringUTFChars(env, juserName, userName);
1441 }
1442 if( directory != NULL ) {
1443 (*env)->ReleaseStringUTFChars(env, jdirectory, directory);
1444 }
1445 throwAFSException( env, ast );
1446 return;
1447 }
1448
1449 if( userName != NULL ) {
1450 (*env)->ReleaseStringUTFChars(env, juserName, userName);
1451 }
1452 if( directory != NULL ) {
1453 (*env)->ReleaseStringUTFChars(env, jdirectory, directory);
1454 }
1455
1456 }
1457
1458 // reclaim global memory used by this portion
1459 JNIEXPORT void JNICALL
1460 Java_org_openafs_jafs_Cell_reclaimCellMemory (JNIEnv *env, jclass cls) {
1461
1462 }
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484