2 * Copyright (c) 2001-2002 International Business Machines Corp.
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
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.
23 #include "org_openafs_jafs_Group.h"
26 #include <afs_ptsAdmin.h>
27 #include <afs_AdminPtsErrors.h>
28 #include <afs_AdminClientErrors.h>
29 #include <afs_AdminCommonErrors.h>
32 ///// definitions in Internal.c ///////////////
34 extern jclass userCls;
35 //extern jfieldID user_cellHandleField;
36 extern jfieldID user_nameField;
37 extern jfieldID user_cachedInfoField;
39 extern jclass groupCls;
40 extern jfieldID group_nameField;
41 extern jfieldID group_nameUidField;
42 extern jfieldID group_ownerUidField;
43 extern jfieldID group_creatorUidField;
44 extern jfieldID group_listStatusField;
45 extern jfieldID group_listGroupsOwnedField;
46 extern jfieldID group_listMembershipField;
47 extern jfieldID group_listAddField;
48 extern jfieldID group_listDeleteField;
49 extern jfieldID group_membershipCountField;
50 extern jfieldID group_ownerField;
51 extern jfieldID group_creatorField;
53 //////////////////////////////////////////////////////
57 * Creates the PTS entry for a new group. Pass in 0 for the uid if PTS is to
58 * automatically assign the group id.
60 * env the Java environment
61 * cls the current Java class
62 * cellHandle the handle of the cell to which the group belongs
63 * jgroupName the name of the group to create
64 * jownerName the owner of this group
65 * gid the group id to assign to the group (0 to have one
66 * automatically assigned)
68 JNIEXPORT void JNICALL
69 Java_org_openafs_jafs_Group_create(JNIEnv * env, jclass cls, jint cellHandle,
70 jstring jgroupName, jstring jownerName,
74 // convert java strings
78 if (jgroupName != NULL) {
79 groupName = getNativeString(env, jgroupName);
80 if (groupName == NULL) {
81 throwAFSException(env, JAFSADMNOMEM);
85 throwAFSException(env, JAFSNULLGROUP);
89 if (jownerName != NULL) {
90 ownerName = getNativeString(env, jownerName);
91 if (ownerName == NULL) {
93 throwAFSException(env, JAFSADMNOMEM);
98 throwAFSException(env, JAFSNULLOWNER);
102 // make sure the name is within the allowed bounds
103 if (strlen(groupName) > PTS_MAX_NAME_LEN) {
104 // release converted java strings
107 throwAFSException(env, ADMPTSGROUPNAMETOOLONG);
112 ((void *)cellHandle, groupName, ownerName, (int *)&gid, &ast)) {
113 // release converted java strings
116 throwAFSException(env, ast);
119 // release converted java strings
125 * Deletes the PTS entry for a group. Deletes this group from the
126 * membership list of the users that belonged to it, but does not delete
127 * the groups owned by this group.
129 * env the Java environment
130 * cls the current Java class
131 * cellHandle the handle of the cell to which the group belongs
132 * jgroupName the name of the group to delete
134 JNIEXPORT void JNICALL
135 Java_org_openafs_jafs_Group_delete(JNIEnv * env, jclass cls, jint cellHandle,
139 // convert java strings
142 if (jgroupName != NULL) {
143 groupName = getNativeString(env, jgroupName);
145 throwAFSException(env, JAFSADMNOMEM);
149 throwAFSException(env, JAFSNULLGROUP);
153 if (!pts_GroupDelete((void *)cellHandle, groupName, &ast)) {
154 throwAFSException(env, ast);
156 // release converted java strings
161 * Retrieve the information for the specified group and populate the
164 * env the Java environment
165 * cellHandle the handle of the cell to which the user belongs
166 * name the name of the group for which to get the info
167 * group the Group object to populate with the info
170 getGroupInfoChar(JNIEnv * env, jint cellHandle, const char *name,
176 pts_GroupEntry_t entry;
178 // get the field ids if you haven't already
180 internal_getGroupClass(env, group);
183 if (!pts_GroupGet((void *)cellHandle, name, &entry, &ast)) {
184 throwAFSException(env, ast);
188 (*env)->SetIntField(env, group, group_nameUidField, entry.nameUid);
189 (*env)->SetIntField(env, group, group_ownerUidField, entry.ownerUid);
190 (*env)->SetIntField(env, group, group_creatorUidField, entry.creatorUid);
191 (*env)->SetIntField(env, group, group_membershipCountField,
192 entry.membershipCount);
194 if (entry.listStatus == PTS_GROUP_OWNER_ACCESS) {
195 (*env)->SetIntField(env, group, group_listStatusField,
196 org_openafs_jafs_Group_GROUP_OWNER_ACCESS);
197 } else if (entry.listStatus == PTS_GROUP_ACCESS) {
198 (*env)->SetIntField(env, group, group_listStatusField,
199 org_openafs_jafs_Group_GROUP_GROUP_ACCESS);
201 (*env)->SetIntField(env, group, group_listStatusField,
202 org_openafs_jafs_Group_GROUP_ANYUSER_ACCESS);
205 if (entry.listGroupsOwned == PTS_GROUP_OWNER_ACCESS) {
206 (*env)->SetIntField(env, group, group_listGroupsOwnedField,
207 org_openafs_jafs_Group_GROUP_OWNER_ACCESS);
208 } else if (entry.listGroupsOwned == PTS_GROUP_ACCESS) {
209 (*env)->SetIntField(env, group, group_listGroupsOwnedField,
210 org_openafs_jafs_Group_GROUP_GROUP_ACCESS);
212 (*env)->SetIntField(env, group, group_listGroupsOwnedField,
213 org_openafs_jafs_Group_GROUP_ANYUSER_ACCESS);
216 if (entry.listMembership == PTS_GROUP_OWNER_ACCESS) {
217 (*env)->SetIntField(env, group, group_listMembershipField,
218 org_openafs_jafs_Group_GROUP_OWNER_ACCESS);
219 } else if (entry.listMembership == PTS_GROUP_ACCESS) {
220 (*env)->SetIntField(env, group, group_listMembershipField,
221 org_openafs_jafs_Group_GROUP_GROUP_ACCESS);
223 (*env)->SetIntField(env, group, group_listMembershipField,
224 org_openafs_jafs_Group_GROUP_ANYUSER_ACCESS);
227 if (entry.listAdd == PTS_GROUP_OWNER_ACCESS) {
228 (*env)->SetIntField(env, group, group_listAddField,
229 org_openafs_jafs_Group_GROUP_OWNER_ACCESS);
230 } else if (entry.listAdd == PTS_GROUP_ACCESS) {
231 (*env)->SetIntField(env, group, group_listAddField,
232 org_openafs_jafs_Group_GROUP_GROUP_ACCESS);
234 (*env)->SetIntField(env, group, group_listAddField,
235 org_openafs_jafs_Group_GROUP_ANYUSER_ACCESS);
238 if (entry.listDelete == PTS_GROUP_OWNER_ACCESS) {
239 (*env)->SetIntField(env, group, group_listDeleteField,
240 org_openafs_jafs_Group_GROUP_OWNER_ACCESS);
241 } else if (entry.listDelete == PTS_GROUP_ACCESS) {
242 (*env)->SetIntField(env, group, group_listDeleteField,
243 org_openafs_jafs_Group_GROUP_GROUP_ACCESS);
245 (*env)->SetIntField(env, group, group_listDeleteField,
246 org_openafs_jafs_Group_GROUP_ANYUSER_ACCESS);
249 jowner = (*env)->NewStringUTF(env, entry.owner);
250 jcreator = (*env)->NewStringUTF(env, entry.creator);
252 (*env)->SetObjectField(env, group, group_ownerField, jowner);
253 (*env)->SetObjectField(env, group, group_creatorField, jcreator);
257 * Fills in the information fields of the provided Group.
258 * Fills in values based on the current PTS information of the group.
260 * env the Java environment
261 * cls the current Java class
262 * cellHandle the handle of the cell to which the group belongs
263 * name the name of the group for which to get the information
264 * group the Group object in which to fill in the
267 JNIEXPORT void JNICALL
268 Java_org_openafs_jafs_Group_getGroupInfo(JNIEnv * env, jclass cls,
269 jint cellHandle, jstring jname,
275 name = getNativeString(env, jname);
277 throwAFSException(env, JAFSADMNOMEM);
281 throwAFSException(env, JAFSNULLGROUP);
284 getGroupInfoChar(env, cellHandle, name, group);
286 // get class fields if need be
288 internal_getGroupClass(env, group);
290 // set name in case blank object
291 (*env)->SetObjectField(env, group, group_nameField, jname);
297 * Sets the information values of this AFS group to be the parameter values.
299 * env the Java environment
300 * cls the current Java class
301 * cellHandle the handle of the cell to which the user belongs
302 * name the name of the user for which to set the information
303 * theGroup the group object containing the desired information
305 JNIEXPORT void JNICALL
306 Java_org_openafs_jafs_Group_setGroupInfo(JNIEnv * env, jclass cls,
307 jint cellHandle, jstring jname,
311 pts_GroupUpdateEntry_t ptsEntry;
315 jint jlistGroupsOwned;
316 jint jlistMembership;
320 // get the field ids if you haven't already
322 internal_getGroupClass(env, group);
325 jlistStatus = (*env)->GetIntField(env, group, group_listStatusField);
327 (*env)->GetIntField(env, group, group_listGroupsOwnedField);
329 (*env)->GetIntField(env, group, group_listMembershipField);
330 jlistAdd = (*env)->GetIntField(env, group, group_listAddField);
331 jlistDelete = (*env)->GetIntField(env, group, group_listDeleteField);
334 name = getNativeString(env, jname);
336 throwAFSException(env, JAFSADMNOMEM);
340 throwAFSException(env, JAFSNULLGROUP);
344 if (jlistStatus == org_openafs_jafs_Group_GROUP_OWNER_ACCESS) {
345 ptsEntry.listStatus = PTS_GROUP_OWNER_ACCESS;
346 } else if (jlistStatus == org_openafs_jafs_Group_GROUP_GROUP_ACCESS) {
347 ptsEntry.listStatus = PTS_GROUP_ACCESS;
349 ptsEntry.listStatus = PTS_GROUP_ANYUSER_ACCESS;
351 if (jlistGroupsOwned == org_openafs_jafs_Group_GROUP_OWNER_ACCESS) {
352 ptsEntry.listGroupsOwned = PTS_GROUP_OWNER_ACCESS;
353 } else if (jlistGroupsOwned == org_openafs_jafs_Group_GROUP_GROUP_ACCESS) {
354 ptsEntry.listGroupsOwned = PTS_GROUP_ACCESS;
356 ptsEntry.listGroupsOwned = PTS_GROUP_ANYUSER_ACCESS;
358 if (jlistMembership == org_openafs_jafs_Group_GROUP_OWNER_ACCESS) {
359 ptsEntry.listMembership = PTS_GROUP_OWNER_ACCESS;
360 } else if (jlistMembership == org_openafs_jafs_Group_GROUP_GROUP_ACCESS) {
361 ptsEntry.listMembership = PTS_GROUP_ACCESS;
363 ptsEntry.listMembership = PTS_GROUP_ANYUSER_ACCESS;
365 if (jlistAdd == org_openafs_jafs_Group_GROUP_OWNER_ACCESS) {
366 ptsEntry.listAdd = PTS_GROUP_OWNER_ACCESS;
367 } else if (jlistAdd == org_openafs_jafs_Group_GROUP_GROUP_ACCESS) {
368 ptsEntry.listAdd = PTS_GROUP_ACCESS;
370 ptsEntry.listAdd = PTS_GROUP_ANYUSER_ACCESS;
372 if (jlistDelete == org_openafs_jafs_Group_GROUP_OWNER_ACCESS) {
373 ptsEntry.listDelete = PTS_GROUP_OWNER_ACCESS;
374 } else if (jlistDelete == org_openafs_jafs_Group_GROUP_GROUP_ACCESS) {
375 ptsEntry.listDelete = PTS_GROUP_ACCESS;
377 ptsEntry.listDelete = PTS_GROUP_ANYUSER_ACCESS;
380 if (!pts_GroupModify((void *)cellHandle, name, &ptsEntry, &ast)) {
381 throwAFSException(env, ast);
388 * Begin the process of getting the users that belong to the group. Returns
389 * an iteration ID to be used by subsequent calls to
390 * getGroupMembersNext and getGroupMembersDone.
392 * env the Java environment
393 * cls the current Java class
394 * cellHandle the handle of the cell to which the group belongs
395 * jname the name of the group for which to get the members
396 * returns an iteration ID
398 JNIEXPORT jint JNICALL
399 Java_org_openafs_jafs_Group_getGroupMembersBegin(JNIEnv * env, jclass cls,
408 name = getNativeString(env, jname);
410 throwAFSException(env, JAFSADMNOMEM);
414 throwAFSException(env, JAFSNULLGROUP);
418 if (!pts_GroupMemberListBegin
419 ((void *)cellHandle, name, &iterationId, &ast)) {
420 throwAFSException(env, ast);
425 return (jint) iterationId;
429 * Returns the next members that belongs to the group. Returns
430 * null if there are no more members.
432 * env the Java environment
433 * cls the current Java class
434 * iterationId the iteration ID of this iteration
435 * returns the name of the next member
437 JNIEXPORT jstring JNICALL
438 Java_org_openafs_jafs_Group_getGroupMembersNextString(JNIEnv * env,
443 char *userName = (char *)malloc(sizeof(char) * PTS_MAX_NAME_LEN);
447 throwAFSException(env, JAFSADMNOMEM);
451 if (!pts_GroupMemberListNext((void *)iterationId, userName, &ast)) {
453 if (ast == ADMITERATORDONE) {
456 throwAFSException(env, ast);
461 juser = (*env)->NewStringUTF(env, userName);
467 * Fills the next user object belonging to that group. Returns 0 if there
468 * are no more users, != 0 otherwise.
470 * env the Java environment
471 * cls the current Java class
472 * cellHandle the handle of the cell to which the users belong
473 * iterationId the iteration ID of this iteration
474 * juserObject a User object to be populated with the values of the
476 * returns 0 if there are no more users, != 0 otherwise
478 JNIEXPORT jint JNICALL
479 Java_org_openafs_jafs_Group_getGroupMembersNext(JNIEnv * env, jclass cls,
488 userName = (char *)malloc(sizeof(char) * PTS_MAX_NAME_LEN);
491 throwAFSException(env, JAFSADMNOMEM);
495 if (!pts_GroupMemberListNext((void *)iterationId, userName, &ast)) {
497 if (ast == ADMITERATORDONE) {
500 throwAFSException(env, ast);
505 juser = (*env)->NewStringUTF(env, userName);
508 internal_getUserClass(env, juserObject);
511 (*env)->SetObjectField(env, juserObject, user_nameField, juser);
513 getUserInfoChar(env, (void *)cellHandle, userName, juserObject);
514 (*env)->SetBooleanField(env, juserObject, user_cachedInfoField, TRUE);
522 * Signals that the iteration is complete and will not be accessed anymore.
524 * env the Java environment
525 * cls the current Java class
526 * iterationId the iteration ID of this iteration
528 JNIEXPORT void JNICALL
529 Java_org_openafs_jafs_Group_getGroupMembersDone(JNIEnv * env, jclass cls,
534 if (!pts_GroupMemberListDone((void *)iterationId, &ast)) {
535 throwAFSException(env, ast);
541 * Adds a user to the specified group.
543 * env the Java environment
544 * cls the current Java class
545 * cellHandle the handle of the cell to which the group belongs
546 * jgroupName the name of the group to which to add a member
547 * juserName the name of the user to add
549 JNIEXPORT void JNICALL
550 Java_org_openafs_jafs_Group_addMember(JNIEnv * env, jclass cls,
551 jint cellHandle, jstring jgroupName,
558 if (jgroupName != NULL) {
559 groupName = getNativeString(env, jgroupName);
560 if (groupName == NULL) {
561 throwAFSException(env, JAFSADMNOMEM);
565 throwAFSException(env, JAFSNULLGROUP);
569 if (juserName != NULL) {
570 userName = getNativeString(env, juserName);
571 if (userName == NULL) {
573 throwAFSException(env, JAFSADMNOMEM);
578 throwAFSException(env, JAFSNULLUSER);
582 if (!pts_GroupMemberAdd((void *)cellHandle, userName, groupName, &ast)) {
583 throwAFSException(env, ast);
591 * Removes a user from the specified group.
593 * env the Java environment
594 * cls the current Java class
595 * cellHandle the handle of the cell to which the group belongs
596 * jgroupName the name of the group from which to remove a
598 * juserName the name of the user to remove
600 JNIEXPORT void JNICALL
601 Java_org_openafs_jafs_Group_removeMember(JNIEnv * env, jclass cls,
602 jint cellHandle, jstring jgroupName,
609 if (jgroupName != NULL) {
610 groupName = getNativeString(env, jgroupName);
611 if (groupName == NULL) {
612 throwAFSException(env, JAFSADMNOMEM);
616 throwAFSException(env, JAFSNULLGROUP);
620 if (juserName != NULL) {
621 userName = getNativeString(env, juserName);
622 if (userName == NULL) {
624 throwAFSException(env, JAFSADMNOMEM);
629 throwAFSException(env, JAFSNULLUSER);
633 if (!pts_GroupMemberRemove((void *)cellHandle, userName, groupName, &ast)) {
634 throwAFSException(env, ast);
642 * Change the owner of the specified group.
644 * env the Java environment
645 * cls the current Java class
646 * cellHandle the handle of the cell to which the group belongs
647 * jgroupName the name of the group of which to change the
649 * jownerName the name of the new owner
651 JNIEXPORT void JNICALL
652 Java_org_openafs_jafs_Group_changeOwner(JNIEnv * env, jclass cls,
653 jint cellHandle, jstring jgroupName,
660 if (jgroupName != NULL) {
661 groupName = getNativeString(env, jgroupName);
662 if (groupName == NULL) {
663 throwAFSException(env, JAFSADMNOMEM);
667 throwAFSException(env, JAFSNULLGROUP);
671 if (jownerName != NULL) {
672 ownerName = getNativeString(env, jownerName);
673 if (ownerName == NULL) {
675 throwAFSException(env, JAFSADMNOMEM);
680 throwAFSException(env, JAFSNULLOWNER);
684 if (!pts_GroupOwnerChange((void *)cellHandle, groupName, ownerName, &ast)) {
685 throwAFSException(env, ast);
693 * Change the name of the specified group.
695 * env the Java environment
696 * cls the current Java class
697 * cellHandle the handle of the cell to which the group belongs
698 * joldGroupName the old name of the group
699 * jnewGroupName the new name for the group
701 JNIEXPORT void JNICALL
702 Java_org_openafs_jafs_Group_rename(JNIEnv * env, jclass cls, jint cellHandle,
703 jstring jgroupOldName,
704 jstring jgroupNewName)
710 if (jgroupOldName != NULL) {
711 groupOldName = getNativeString(env, jgroupOldName);
712 if (groupOldName == NULL) {
713 throwAFSException(env, JAFSADMNOMEM);
717 throwAFSException(env, JAFSNULLGROUP);
721 if (jgroupNewName != NULL) {
722 groupNewName = getNativeString(env, jgroupNewName);
723 if (groupNewName == NULL) {
725 throwAFSException(env, JAFSADMNOMEM);
730 throwAFSException(env, JAFSNULLGROUP);
735 ((void *)cellHandle, groupOldName, groupNewName, &ast)) {
736 throwAFSException(env, ast);
743 // reclaim global memory used by this portion
744 JNIEXPORT void JNICALL
745 Java_org_openafs_jafs_Group_reclaimGroupMemory(JNIEnv * env, jclass cls)
748 (*env)->DeleteGlobalRef(env, groupCls);