Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / JAVA / libjafs / Group.c
CommitLineData
805e021f
CE
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_Group.h"
24
25#include <afs_vosAdmin.h>
26
27#include <stdio.h>
28#include <afs_ptsAdmin.h>
29#include <afs_AdminPtsErrors.h>
30#include <afs_AdminClientErrors.h>
31#include <afs_AdminCommonErrors.h>
32#include <pterror.h>
33
34///// definitions in Internal.c ///////////////
35
36extern jclass userCls;
37//extern jfieldID user_cellHandleField;
38extern jfieldID user_nameField;
39extern jfieldID user_cachedInfoField;
40
41extern jclass groupCls;
42extern jfieldID group_nameField;
43extern jfieldID group_nameUidField;
44extern jfieldID group_ownerUidField;
45extern jfieldID group_creatorUidField;
46extern jfieldID group_listStatusField;
47extern jfieldID group_listGroupsOwnedField;
48extern jfieldID group_listMembershipField;
49extern jfieldID group_listAddField;
50extern jfieldID group_listDeleteField;
51extern jfieldID group_membershipCountField;
52extern jfieldID group_ownerField;
53extern jfieldID group_creatorField;
54
55//////////////////////////////////////////////////////
56
57
58/**
59 * Creates the PTS entry for a new group. Pass in 0 for the uid if PTS is to
60 * automatically assign the group id.
61 *
62 * env the Java environment
63 * cls the current Java class
64 * cellHandle the handle of the cell to which the group belongs
65 * jgroupName the name of the group to create
66 * jownerName the owner of this group
67 * gid the group id to assign to the group (0 to have one
68 * automatically assigned)
69 */
70JNIEXPORT void JNICALL
71Java_org_openafs_jafs_Group_create
72 (JNIEnv *env, jclass cls, jlong cellHandle, jstring jgroupName,
73 jstring jownerName, jint gid )
74{
75 afs_status_t ast;
76 // convert java strings
77 const char *groupName;
78 const char *ownerName;
79
80 if( jgroupName != NULL ) {
81 groupName = (*env)->GetStringUTFChars(env, jgroupName, 0);
82 if( !groupName ) {
83 throwAFSException( env, JAFSADMNOMEM );
84 return;
85 }
86 } else {
87 groupName = NULL;
88 }
89
90 if( jownerName != NULL ) {
91 ownerName = (*env)->GetStringUTFChars(env, jownerName, 0);
92 if( !ownerName ) {
93 throwAFSException( env, JAFSADMNOMEM );
94 return;
95 }
96 } else {
97 ownerName = NULL;
98 }
99
100 // make sure the name is within the allowed bounds
101 if( groupName != NULL && strlen( groupName ) > PTS_MAX_NAME_LEN ) {
102 // release converted java strings
103 if( groupName != NULL ) {
104 (*env)->ReleaseStringUTFChars(env, jgroupName, groupName);
105 }
106 if( ownerName != NULL ) {
107 (*env)->ReleaseStringUTFChars(env, jownerName, ownerName);
108 }
109 throwAFSException( env, ADMPTSGROUPNAMETOOLONG );
110 return;
111 }
112
113 if( !pts_GroupCreate( (void *) cellHandle, groupName, ownerName,
114 (int *) &gid, &ast ) ) {
115 // release converted java strings
116 if( groupName != NULL ) {
117 (*env)->ReleaseStringUTFChars(env, jgroupName, groupName);
118 }
119 if( ownerName != NULL ) {
120 (*env)->ReleaseStringUTFChars(env, jownerName, ownerName);
121 }
122 throwAFSException( env, ast );
123 return;
124 }
125
126 // release converted java strings
127 if( groupName != NULL ) {
128 (*env)->ReleaseStringUTFChars(env, jgroupName, groupName);
129 }
130 if( ownerName != NULL ) {
131 (*env)->ReleaseStringUTFChars(env, jownerName, ownerName);
132 }
133
134}
135
136/**
137 * Deletes the PTS entry for a group. Deletes this group from the
138 * membership list of the users that belonged to it, but does not delete
139 * the groups owned by this group.
140 *
141 * env the Java environment
142 * cls the current Java class
143 * cellHandle the handle of the cell to which the group belongs
144 * jgroupName the name of the group to delete
145 */
146JNIEXPORT void JNICALL
147Java_org_openafs_jafs_Group_delete
148 (JNIEnv *env, jclass cls, jlong cellHandle, jstring jgroupName )
149{
150 afs_status_t ast;
151 // convert java strings
152 const char *groupName;
153
154 if( jgroupName != NULL ) {
155 groupName = (*env)->GetStringUTFChars(env, jgroupName, 0);
156 if( !groupName ) {
157 throwAFSException( env, JAFSADMNOMEM );
158 return;
159 }
160 } else {
161 groupName = NULL;
162 }
163
164 if( !pts_GroupDelete( (void *) cellHandle, groupName, &ast ) ) {
165 if( groupName != NULL ) {
166 (*env)->ReleaseStringUTFChars(env, jgroupName, groupName);
167 }
168 throwAFSException( env, ast );
169 return;
170 }
171
172 // release converted java strings
173 if( groupName != NULL ) {
174 (*env)->ReleaseStringUTFChars(env, jgroupName, groupName);
175 }
176
177}
178
179/**
180 * Retrieve the information for the specified group and populate the
181 * given object
182 *
183 * env the Java environment
184 * cellHandle the handle of the cell to which the user belongs
185 * name the name of the group for which to get the info
186 * group the Group object to populate with the info
187 */
188void getGroupInfoChar
189 ( JNIEnv *env, void *cellHandle, const char *name, jobject group )
190{
191
192 jstring jowner;
193 jstring jcreator;
194 pts_GroupEntry_t entry;
195 afs_status_t ast;
196
197 // get the field ids if you haven't already
198 if( groupCls == 0 ) {
199 internal_getGroupClass( env, group );
200 }
201 if ( !pts_GroupGet( cellHandle, name, &entry, &ast ) ) {
202 throwAFSException( env, ast );
203 return;
204 }
205
206 // set the fields
207 (*env)->SetIntField(env, group, group_nameUidField, entry.nameUid);
208 (*env)->SetIntField(env, group, group_ownerUidField, entry.ownerUid);
209 (*env)->SetIntField(env, group, group_creatorUidField, entry.creatorUid);
210 (*env)->SetIntField(env, group, group_membershipCountField,
211 entry.membershipCount);
212
213 if( entry.listStatus == PTS_GROUP_OWNER_ACCESS ) {
214 (*env)->SetIntField(env, group, group_listStatusField,
215 org_openafs_jafs_Group_GROUP_OWNER_ACCESS);
216 } else if( entry.listStatus == PTS_GROUP_ACCESS ) {
217 (*env)->SetIntField(env, group, group_listStatusField,
218 org_openafs_jafs_Group_GROUP_GROUP_ACCESS);
219 } else {
220 (*env)->SetIntField(env, group, group_listStatusField,
221 org_openafs_jafs_Group_GROUP_ANYUSER_ACCESS);
222 }
223
224 if( entry.listGroupsOwned == PTS_GROUP_OWNER_ACCESS ) {
225 (*env)->SetIntField(env, group, group_listGroupsOwnedField,
226 org_openafs_jafs_Group_GROUP_OWNER_ACCESS);
227 } else if( entry.listGroupsOwned == PTS_GROUP_ACCESS ) {
228 (*env)->SetIntField(env, group, group_listGroupsOwnedField,
229 org_openafs_jafs_Group_GROUP_GROUP_ACCESS);
230 } else {
231 (*env)->SetIntField(env, group, group_listGroupsOwnedField,
232 org_openafs_jafs_Group_GROUP_ANYUSER_ACCESS);
233 }
234
235 if( entry.listMembership == PTS_GROUP_OWNER_ACCESS ) {
236 (*env)->SetIntField(env, group, group_listMembershipField,
237 org_openafs_jafs_Group_GROUP_OWNER_ACCESS);
238 } else if( entry.listMembership == PTS_GROUP_ACCESS ) {
239 (*env)->SetIntField(env, group, group_listMembershipField,
240 org_openafs_jafs_Group_GROUP_GROUP_ACCESS);
241 } else {
242 (*env)->SetIntField(env, group, group_listMembershipField,
243 org_openafs_jafs_Group_GROUP_ANYUSER_ACCESS);
244 }
245
246 if( entry.listAdd == PTS_GROUP_OWNER_ACCESS ) {
247 (*env)->SetIntField(env, group, group_listAddField,
248 org_openafs_jafs_Group_GROUP_OWNER_ACCESS);
249 } else if( entry.listAdd == PTS_GROUP_ACCESS ) {
250 (*env)->SetIntField(env, group, group_listAddField,
251 org_openafs_jafs_Group_GROUP_GROUP_ACCESS);
252 } else {
253 (*env)->SetIntField(env, group, group_listAddField,
254 org_openafs_jafs_Group_GROUP_ANYUSER_ACCESS);
255 }
256
257 if( entry.listDelete == PTS_GROUP_OWNER_ACCESS ) {
258 (*env)->SetIntField(env, group, group_listDeleteField,
259 org_openafs_jafs_Group_GROUP_OWNER_ACCESS);
260 } else if( entry.listDelete == PTS_GROUP_ACCESS ) {
261 (*env)->SetIntField(env, group, group_listDeleteField,
262 org_openafs_jafs_Group_GROUP_GROUP_ACCESS);
263 } else {
264 (*env)->SetIntField(env, group, group_listDeleteField,
265 org_openafs_jafs_Group_GROUP_ANYUSER_ACCESS);
266 }
267
268 jowner = (*env)->NewStringUTF(env, entry.owner);
269 jcreator = (*env)->NewStringUTF(env, entry.creator);
270
271 (*env)->SetObjectField(env, group, group_ownerField, jowner);
272 (*env)->SetObjectField(env, group, group_creatorField, jcreator);
273
274}
275
276/**
277 * Fills in the information fields of the provided Group.
278 * Fills in values based on the current PTS information of the group.
279 *
280 * env the Java environment
281 * cls the current Java class
282 * cellHandle the handle of the cell to which the group belongs
283 * name the name of the group for which to get the information
284 * group the Group object in which to fill in the
285 * information
286 */
287JNIEXPORT void JNICALL
288Java_org_openafs_jafs_Group_getGroupInfo
289 (JNIEnv *env, jclass cls, jlong cellHandle, jstring jname, jobject group)
290{
291
292 const char *name;
293
294 if( jname != NULL ) {
295 name = (*env)->GetStringUTFChars(env, jname, 0);
296 if( !name ) {
297 throwAFSException( env, JAFSADMNOMEM );
298 return;
299 }
300 } else {
301 name = NULL;
302 }
303 getGroupInfoChar( env, (void *)cellHandle, name, group );
304
305 // get class fields if need be
306 if( groupCls == 0 ) {
307 internal_getGroupClass( env, group );
308 }
309
310 // set name in case blank object
311 (*env)->SetObjectField(env, group, group_nameField, jname);
312
313 if( name != NULL ) {
314 (*env)->ReleaseStringUTFChars(env, jname, name);
315 }
316
317}
318
319/**
320 * Sets the information values of this AFS group to be the parameter values.
321 *
322 * env the Java environment
323 * cls the current Java class
324 * cellHandle the handle of the cell to which the user belongs
325 * name the name of the user for which to set the information
326 * theGroup the group object containing the desired information
327 */
328JNIEXPORT void JNICALL
329Java_org_openafs_jafs_Group_setGroupInfo
330 (JNIEnv *env, jclass cls, jlong cellHandle, jstring jname, jobject group)
331{
332 const char *name;
333 pts_GroupUpdateEntry_t ptsEntry;
334 afs_status_t ast;
335
336 jint jlistStatus;
337 jint jlistGroupsOwned;
338 jint jlistMembership;
339 jint jlistAdd;
340 jint jlistDelete;
341
342 // get the field ids if you haven't already
343 if( groupCls == 0 ) {
344 internal_getGroupClass( env, group );
345 }
346
347 jlistStatus = (*env)->GetIntField(env, group, group_listStatusField);
348 jlistGroupsOwned = (*env)->GetIntField(env, group,
349 group_listGroupsOwnedField);
350 jlistMembership = (*env)->GetIntField(env, group, group_listMembershipField);
351 jlistAdd = (*env)->GetIntField(env, group, group_listAddField);
352 jlistDelete = (*env)->GetIntField(env, group, group_listDeleteField);
353
354 if( jname != NULL ) {
355 name = (*env)->GetStringUTFChars(env, jname, 0);
356 if( !name ) {
357 throwAFSException( env, JAFSADMNOMEM );
358 return;
359 }
360 } else {
361 name = NULL;
362 }
363
364 if( jlistStatus == org_openafs_jafs_Group_GROUP_OWNER_ACCESS ) {
365 ptsEntry.listStatus = PTS_GROUP_OWNER_ACCESS;
366 } else if( jlistStatus == org_openafs_jafs_Group_GROUP_GROUP_ACCESS ) {
367 ptsEntry.listStatus = PTS_GROUP_ACCESS;
368 } else {
369 ptsEntry.listStatus = PTS_GROUP_ANYUSER_ACCESS;
370 }
371 if( jlistGroupsOwned == org_openafs_jafs_Group_GROUP_OWNER_ACCESS ) {
372 ptsEntry.listGroupsOwned = PTS_GROUP_OWNER_ACCESS;
373 } else if( jlistGroupsOwned ==
374 org_openafs_jafs_Group_GROUP_GROUP_ACCESS ) {
375 ptsEntry.listGroupsOwned = PTS_GROUP_ACCESS;
376 } else {
377 ptsEntry.listGroupsOwned = PTS_GROUP_ANYUSER_ACCESS;
378 }
379 if( jlistMembership == org_openafs_jafs_Group_GROUP_OWNER_ACCESS ) {
380 ptsEntry.listMembership = PTS_GROUP_OWNER_ACCESS;
381 } else if( jlistMembership ==
382 org_openafs_jafs_Group_GROUP_GROUP_ACCESS ) {
383 ptsEntry.listMembership = PTS_GROUP_ACCESS;
384 } else {
385 ptsEntry.listMembership = PTS_GROUP_ANYUSER_ACCESS;
386 }
387 if( jlistAdd == org_openafs_jafs_Group_GROUP_OWNER_ACCESS ) {
388 ptsEntry.listAdd = PTS_GROUP_OWNER_ACCESS;
389 } else if( jlistAdd == org_openafs_jafs_Group_GROUP_GROUP_ACCESS ) {
390 ptsEntry.listAdd = PTS_GROUP_ACCESS;
391 } else {
392 ptsEntry.listAdd = PTS_GROUP_ANYUSER_ACCESS;
393 }
394 if( jlistDelete == org_openafs_jafs_Group_GROUP_OWNER_ACCESS ) {
395 ptsEntry.listDelete = PTS_GROUP_OWNER_ACCESS;
396 } else if( jlistDelete == org_openafs_jafs_Group_GROUP_GROUP_ACCESS ) {
397 ptsEntry.listDelete = PTS_GROUP_ACCESS;
398 } else {
399 ptsEntry.listDelete = PTS_GROUP_ANYUSER_ACCESS;
400 }
401 if( !pts_GroupModify( (void *) cellHandle, name, &ptsEntry, &ast ) ) {
402 if( name != NULL ) {
403 (*env)->ReleaseStringUTFChars(env, jname, name);
404 }
405 throwAFSException( env, ast );
406 return;
407 }
408
409 if( name != NULL ) {
410 (*env)->ReleaseStringUTFChars(env, jname, name);
411 }
412
413}
414
415/**
416 * Begin the process of getting the users that belong to the group. Returns
417 * an iteration ID to be used by subsequent calls to
418 * getGroupMembersNext and getGroupMembersDone.
419 *
420 * env the Java environment
421 * cls the current Java class
422 * cellHandle the handle of the cell to which the group belongs
423 * jname the name of the group for which to get the members
424 * returns an iteration ID
425 */
426JNIEXPORT jlong JNICALL
427Java_org_openafs_jafs_Group_getGroupMembersBegin
428 (JNIEnv *env, jclass cls, jlong cellHandle, jstring jname)
429{
430 const char *name;
431 afs_status_t ast;
432 void *iterationId;
433
434 if( jname != NULL ) {
435 name = (*env)->GetStringUTFChars(env, jname, 0);
436 if( !name ) {
437 throwAFSException( env, JAFSADMNOMEM );
438 return;
439 }
440 } else {
441 name = NULL;
442 }
443
444 if( !pts_GroupMemberListBegin( (void *) cellHandle, name, &iterationId,
445 &ast ) ) {
446 if( name != NULL ) {
447 (*env)->ReleaseStringUTFChars(env, jname, name);
448 }
449 throwAFSException( env, ast );
450 return;
451 }
452
453 if( name != NULL ) {
454 (*env)->ReleaseStringUTFChars(env, jname, name);
455 }
456
457 return (jlong) iterationId;
458
459}
460
461/**
462 * Returns the next members that belongs to the group. Returns
463 * null if there are no more members.
464 *
465 * env the Java environment
466 * cls the current Java class
467 * iterationId the iteration ID of this iteration
468 * returns the name of the next member
469 */
470JNIEXPORT jstring JNICALL
471Java_org_openafs_jafs_Group_getGroupMembersNextString
472 (JNIEnv *env, jclass cls, jlong iterationId)
473{
474 afs_status_t ast;
475 char *userName = malloc( sizeof(char)*PTS_MAX_NAME_LEN);
476 jstring juser;
477
478 if( !userName ) {
479 throwAFSException( env, JAFSADMNOMEM );
480 return;
481 }
482
483 if( !pts_GroupMemberListNext( (void *) iterationId, userName, &ast ) ) {
484 free( userName );
485 if( ast == ADMITERATORDONE ) {
486 return NULL;
487 } else {
488 throwAFSException( env, ast );
489 return;
490 }
491 }
492
493 juser = (*env)->NewStringUTF(env, userName);
494 free( userName );
495 return juser;
496}
497
498/**
499 * Fills the next user object belonging to that group. Returns 0 if there
500 * are no more users, != 0 otherwise.
501 *
502 * env the Java environment
503 * cls the current Java class
504 * cellHandle the handle of the cell to which the users belong
505 * iterationId the iteration ID of this iteration
506 * juserObject a User object to be populated with the values of the
507 * next user
508 * returns 0 if there are no more users, != 0 otherwise
509 */
510JNIEXPORT jint JNICALL
511Java_org_openafs_jafs_Group_getGroupMembersNext
512 (JNIEnv *env, jclass cls, jlong cellHandle, jlong iterationId,
513 jobject juserObject)
514{
515 afs_status_t ast;
516 char *userName;
517 jstring juser;
518
519 userName = malloc( sizeof(char)*PTS_MAX_NAME_LEN);
520
521 if( !userName ) {
522 throwAFSException( env, JAFSADMNOMEM );
523 return;
524 }
525
526 if( !pts_GroupMemberListNext( (void *) iterationId, userName, &ast ) ) {
527 free( userName );
528 if( ast == ADMITERATORDONE ) {
529 return 0;
530 } else {
531 throwAFSException( env, ast );
532 return 0;
533 }
534 }
535
536 juser = (*env)->NewStringUTF(env, userName);
537
538 if( userCls == 0 ) {
539 internal_getUserClass( env, juserObject );
540 }
541
542 (*env)->SetObjectField(env, juserObject, user_nameField, juser);
543
544 getUserInfoChar( env, (void *) cellHandle, userName, juserObject );
545 (*env)->SetBooleanField( env, juserObject, user_cachedInfoField, TRUE );
546
547 free( userName );
548 return 1;
549
550}
551
552/**
553 * Signals that the iteration is complete and will not be accessed anymore.
554 *
555 * env the Java environment
556 * cls the current Java class
557 * iterationId the iteration ID of this iteration
558 */
559JNIEXPORT void JNICALL
560Java_org_openafs_jafs_Group_getGroupMembersDone
561 (JNIEnv *env, jclass cls, jlong iterationId)
562{
563 afs_status_t ast;
564
565 if( !pts_GroupMemberListDone( (void *) iterationId, &ast ) ) {
566 throwAFSException( env, ast );
567 return;
568 }
569
570}
571
572/**
573 * Adds a user to the specified group.
574 *
575 * env the Java environment
576 * cls the current Java class
577 * cellHandle the handle of the cell to which the group belongs
578 * jgroupName the name of the group to which to add a member
579 * juserName the name of the user to add
580 */
581JNIEXPORT void JNICALL
582Java_org_openafs_jafs_Group_addMember
583 (JNIEnv *env, jclass cls, jlong cellHandle, jstring jgroupName,
584 jstring juserName )
585{
586 afs_status_t ast;
587 const char *groupName;
588 const char *userName;
589
590 if( jgroupName != NULL ) {
591 groupName = (*env)->GetStringUTFChars(env, jgroupName, 0);
592 if( !groupName ) {
593 throwAFSException( env, JAFSADMNOMEM );
594 return;
595 }
596 } else {
597 groupName = NULL;
598 }
599
600 if( juserName != NULL ) {
601 userName = (*env)->GetStringUTFChars(env, juserName, 0);
602 if( !userName ) {
603 if( groupName != NULL ) {
604 (*env)->ReleaseStringUTFChars(env, jgroupName, groupName);
605 }
606 throwAFSException( env, JAFSADMNOMEM );
607 return;
608 }
609 } else {
610 userName = NULL;
611 }
612
613 if( !pts_GroupMemberAdd( (void *) cellHandle, userName, groupName, &ast ) ) {
614 if( groupName != NULL ) {
615 (*env)->ReleaseStringUTFChars(env, jgroupName, groupName);
616 }
617 if( userName != NULL ) {
618 (*env)->ReleaseStringUTFChars(env, juserName, userName);
619 }
620 throwAFSException( env, ast );
621 return;
622 }
623
624 if( groupName != NULL ) {
625 (*env)->ReleaseStringUTFChars(env, jgroupName, groupName);
626 }
627 if( userName != NULL ) {
628 (*env)->ReleaseStringUTFChars(env, juserName, userName);
629 }
630}
631
632/**
633 * Removes a user from the specified group.
634 *
635 * env the Java environment
636 * cls the current Java class
637 * cellHandle the handle of the cell to which the group belongs
638 * jgroupName the name of the group from which to remove a
639 * member
640 * juserName the name of the user to remove
641 */
642JNIEXPORT void JNICALL
643Java_org_openafs_jafs_Group_removeMember
644 (JNIEnv *env, jclass cls, jlong cellHandle, jstring jgroupName,
645 jstring juserName)
646{
647 afs_status_t ast;
648 const char *groupName;
649 const char *userName;
650
651 if( jgroupName != NULL ) {
652 groupName = (*env)->GetStringUTFChars(env, jgroupName, 0);
653 if( !groupName ) {
654 throwAFSException( env, JAFSADMNOMEM );
655 return;
656 }
657 } else {
658 groupName = NULL;
659 }
660
661 if( juserName != NULL ) {
662 userName = (*env)->GetStringUTFChars(env, juserName, 0);
663 if( !userName ) {
664 if( groupName != NULL ) {
665 (*env)->ReleaseStringUTFChars(env, jgroupName, groupName);
666 }
667 throwAFSException( env, JAFSADMNOMEM );
668 return;
669 }
670 } else {
671 userName = NULL;
672 }
673
674 if( !pts_GroupMemberRemove( (void *)cellHandle, userName,
675 groupName, &ast ) ) {
676 if( groupName != NULL ) {
677 (*env)->ReleaseStringUTFChars(env, jgroupName, groupName);
678 }
679 if( userName != NULL ) {
680 (*env)->ReleaseStringUTFChars(env, juserName, userName);
681 }
682 throwAFSException( env, ast );
683 return;
684 }
685
686 if( groupName != NULL ) {
687 (*env)->ReleaseStringUTFChars(env, jgroupName, groupName);
688 }
689 if( userName != NULL ) {
690 (*env)->ReleaseStringUTFChars(env, juserName, userName);
691 }
692}
693
694/**
695 * Change the owner of the specified group.
696 *
697 * env the Java environment
698 * cls the current Java class
699 * cellHandle the handle of the cell to which the group belongs
700 * jgroupName the name of the group of which to change the
701 * owner
702 * jownerName the name of the new owner
703 */
704JNIEXPORT void JNICALL
705Java_org_openafs_jafs_Group_changeOwner
706 (JNIEnv *env, jclass cls, jlong cellHandle, jstring jgroupName,
707 jstring jownerName )
708{
709 afs_status_t ast;
710 const char *groupName;
711 const char *ownerName;
712
713 if( jgroupName != NULL ) {
714 groupName = (*env)->GetStringUTFChars(env, jgroupName, 0);
715 if( !groupName ) {
716 throwAFSException( env, JAFSADMNOMEM );
717 return;
718 }
719 } else {
720 groupName = NULL;
721 }
722
723 if( jownerName != NULL ) {
724 ownerName = (*env)->GetStringUTFChars(env, jownerName, 0);
725 if( !ownerName ) {
726 if( groupName != NULL ) {
727 (*env)->ReleaseStringUTFChars(env, jgroupName, groupName);
728 }
729 throwAFSException( env, JAFSADMNOMEM );
730 return;
731 }
732 } else {
733 ownerName = NULL;
734 }
735
736 if( !pts_GroupOwnerChange( (void *)cellHandle, groupName,
737 ownerName, &ast ) ) {
738 if( groupName != NULL ) {
739 (*env)->ReleaseStringUTFChars(env, jgroupName, groupName);
740 }
741 if( ownerName != NULL ) {
742 (*env)->ReleaseStringUTFChars(env, jownerName, ownerName);
743 }
744 throwAFSException( env, ast );
745 return;
746 }
747
748 if( groupName != NULL ) {
749 (*env)->ReleaseStringUTFChars(env, jgroupName, groupName);
750 }
751 if( ownerName != NULL ) {
752 (*env)->ReleaseStringUTFChars(env, jownerName, ownerName);
753 }
754
755}
756
757/**
758 * Change the name of the specified group.
759 *
760 * env the Java environment
761 * cls the current Java class
762 * cellHandle the handle of the cell to which the group belongs
763 * joldGroupName the old name of the group
764 * jnewGroupName the new name for the group
765 */
766JNIEXPORT void JNICALL
767Java_org_openafs_jafs_Group_rename
768 (JNIEnv *env, jclass cls, jlong cellHandle, jstring jgroupOldName,
769 jstring jgroupNewName )
770{
771 afs_status_t ast;
772 const char *groupOldName;
773 const char *groupNewName;
774
775 if( jgroupOldName != NULL ) {
776 groupOldName = (*env)->GetStringUTFChars(env, jgroupOldName, 0);
777 if( !groupOldName ) {
778 throwAFSException( env, JAFSADMNOMEM );
779 return;
780 }
781 } else {
782 groupOldName = NULL;
783 }
784
785 if( jgroupNewName != NULL ) {
786 groupNewName = (*env)->GetStringUTFChars(env, jgroupNewName, 0);
787 if( !groupNewName ) {
788 if( groupOldName != NULL ) {
789 (*env)->ReleaseStringUTFChars(env, jgroupOldName, groupOldName);
790 }
791 throwAFSException( env, JAFSADMNOMEM );
792 return;
793 }
794 } else {
795 groupNewName = NULL;
796 }
797
798 if( !pts_GroupRename( (void *)cellHandle, groupOldName,
799 groupNewName, &ast ) ) {
800 if( groupOldName != NULL ) {
801 (*env)->ReleaseStringUTFChars(env, jgroupOldName, groupOldName);
802 }
803 if( groupNewName != NULL ) {
804 (*env)->ReleaseStringUTFChars(env, jgroupNewName, groupNewName);
805 }
806 throwAFSException( env, ast );
807 return;
808 }
809
810 if( groupOldName != NULL ) {
811 (*env)->ReleaseStringUTFChars(env, jgroupOldName, groupOldName);
812 }
813 if( groupNewName != NULL ) {
814 (*env)->ReleaseStringUTFChars(env, jgroupNewName, groupNewName);
815 }
816}
817
818// reclaim global memory used by this portion
819JNIEXPORT void JNICALL
820Java_org_openafs_jafs_Group_reclaimGroupMemory (JNIEnv *env, jclass cls)
821{
822 if( groupCls ) {
823 (*env)->DeleteGlobalRef(env, groupCls);
824 groupCls = 0;
825 }
826}
827
828
829