Commit | Line | Data |
---|---|---|
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_User.h" | |
24 | ||
25 | #include <stdio.h> | |
26 | #include <afs_ptsAdmin.h> | |
27 | #include <afs_kasAdmin.h> | |
28 | #include <kautils.h> | |
29 | #include <afs_AdminPtsErrors.h> | |
30 | #include <afs_AdminClientErrors.h> | |
31 | #include <afs_AdminCommonErrors.h> | |
32 | #include <prerror.h> | |
33 | ||
34 | ///// definitions in Internal.c //////////////////// | |
35 | ||
36 | extern jclass userCls; | |
37 | extern jfieldID user_nameField; | |
38 | extern jfieldID user_ptsField; | |
39 | extern jfieldID user_kasField; | |
40 | //pts fields | |
41 | extern jfieldID user_nameUidField; | |
42 | extern jfieldID user_ownerUidField; | |
43 | extern jfieldID user_creatorUidField; | |
44 | extern jfieldID user_listStatusField; | |
45 | extern jfieldID user_listGroupsOwnedField; | |
46 | extern jfieldID user_listMembershipField; | |
47 | extern jfieldID user_groupCreationQuotaField; | |
48 | extern jfieldID user_groupMembershipCountField; | |
49 | extern jfieldID user_ownerField; | |
50 | extern jfieldID user_creatorField; | |
51 | // kas fields | |
52 | extern jfieldID user_adminSettingField; | |
53 | extern jfieldID user_tgsSettingField; | |
54 | extern jfieldID user_encSettingField; | |
55 | extern jfieldID user_cpwSettingField; | |
56 | extern jfieldID user_rpwSettingField; | |
57 | extern jfieldID user_userExpirationField; | |
58 | extern jfieldID user_lastModTimeField; | |
59 | extern jfieldID user_lastModNameField; | |
60 | extern jfieldID user_lastChangePasswordTimeField; | |
61 | extern jfieldID user_maxTicketLifetimeField; | |
62 | extern jfieldID user_keyVersionField; | |
63 | extern jfieldID user_encryptionKeyField; | |
64 | extern jfieldID user_keyCheckSumField; | |
65 | extern jfieldID user_daysToPasswordExpireField; | |
66 | extern jfieldID user_failLoginCountField; | |
67 | extern jfieldID user_lockTimeField; | |
68 | extern jfieldID user_lockedUntilField; | |
69 | ||
70 | extern jclass groupCls; | |
71 | //extern jfieldID group_cellHandleField; | |
72 | extern jfieldID group_nameField; | |
73 | extern jfieldID group_cachedInfoField; | |
74 | ||
75 | ////////////////////////////////////////////////////////////////// | |
76 | ||
77 | /** | |
78 | * Creates the kas and pts entries for a new user. Pass in 0 for the uid | |
79 | * if pts is to automatically assign the user id. | |
80 | * | |
81 | * env the Java environment | |
82 | * cls the current Java class | |
83 | * cellHandle the handle of the cell to which the user belongs | |
84 | * juserName the name of the user to create | |
85 | * jpassword the password for the new user | |
86 | * uid the user id to assign to the user (0 to have one | |
87 | * automatically assigned) | |
88 | */ | |
89 | JNIEXPORT void JNICALL | |
90 | Java_org_openafs_jafs_User_create | |
91 | (JNIEnv *env, jclass cls, jlong cellHandle, jstring juserName, | |
92 | jstring jpassword, jint uid ) | |
93 | { | |
94 | afs_status_t ast; | |
95 | const char *userName; | |
96 | const char *password; | |
97 | kas_identity_p who = (kas_identity_p) malloc( sizeof(kas_identity_t) ); | |
98 | ||
99 | if( !who ) { | |
100 | throwAFSException( env, JAFSADMNOMEM ); | |
101 | return; | |
102 | } | |
103 | ||
104 | // convert java strings | |
105 | if( juserName != NULL ) { | |
106 | userName = (*env)->GetStringUTFChars(env, juserName, 0); | |
107 | if( !userName ) { | |
108 | free( who ); | |
109 | throwAFSException( env, JAFSADMNOMEM ); | |
110 | return; | |
111 | } | |
112 | } else { | |
113 | userName = NULL; | |
114 | } | |
115 | if( jpassword != NULL ) { | |
116 | password = (*env)->GetStringUTFChars(env, jpassword, 0); | |
117 | if( !password ) { | |
118 | free( who ); | |
119 | if( userName != NULL ) { | |
120 | (*env)->ReleaseStringUTFChars(env, juserName, userName); | |
121 | } | |
122 | throwAFSException( env, JAFSADMNOMEM ); | |
123 | return; | |
124 | } | |
125 | } else { | |
126 | password = NULL; | |
127 | } | |
128 | ||
129 | // make sure the name is within the allowed bounds | |
130 | if( userName != NULL && strlen( userName ) > KAS_MAX_NAME_LEN ) { | |
131 | free( who ); | |
132 | // release converted java strings | |
133 | if( userName != NULL ) { | |
134 | (*env)->ReleaseStringUTFChars(env, juserName, userName); | |
135 | } | |
136 | if( password != NULL ) { | |
137 | (*env)->ReleaseStringUTFChars(env, jpassword, password); | |
138 | } | |
139 | throwAFSException( env, ADMPTSUSERNAMETOOLONG ); | |
140 | return; | |
141 | } | |
142 | ||
143 | // make sure name doesn't have ":" in it | |
144 | if( userName != NULL && strchr( userName, ':' ) != (int) NULL ) { | |
145 | free(who); | |
146 | // release converted java strings | |
147 | if( userName != NULL ) { | |
148 | (*env)->ReleaseStringUTFChars(env, juserName, userName); | |
149 | } | |
150 | if( password != NULL ) { | |
151 | (*env)->ReleaseStringUTFChars(env, jpassword, password); | |
152 | } | |
153 | throwAFSException( env, PRBADNAM ); | |
154 | return; | |
155 | } | |
156 | ||
157 | // make sure the id isn't negative | |
158 | if( uid < 0 ) { | |
159 | free(who); | |
160 | // release converted java strings | |
161 | if( userName != NULL ) { | |
162 | (*env)->ReleaseStringUTFChars(env, juserName, userName); | |
163 | } | |
164 | if( password != NULL ) { | |
165 | (*env)->ReleaseStringUTFChars(env, jpassword, password); | |
166 | } | |
167 | // use the "bad arg" error code even though it's an ID exception. | |
168 | // There isn't a bad user ID error code | |
169 | throwAFSException( env, PRBADARG ); | |
170 | return; | |
171 | } | |
172 | ||
173 | if( userName != NULL ) { | |
174 | internal_makeKasIdentity( userName, who ); | |
175 | } | |
176 | ||
177 | // create the kas entry | |
178 | if (!kas_PrincipalCreate( (void *) cellHandle, NULL, who, | |
179 | password, &ast ) ) { | |
180 | free(who); | |
181 | // release converted java strings | |
182 | if( userName != NULL ) { | |
183 | (*env)->ReleaseStringUTFChars(env, juserName, userName); | |
184 | } | |
185 | if( password != NULL ) { | |
186 | (*env)->ReleaseStringUTFChars(env, jpassword, password); | |
187 | } | |
188 | throwAFSException( env, ast ); | |
189 | return; | |
190 | } | |
191 | ||
192 | // create the pts entry - if there's an error, make sure to delete | |
193 | // the kas entry | |
194 | if( !pts_UserCreate( (void *) cellHandle, userName, (int *) &uid, &ast ) ) { | |
195 | afs_status_t ast_kd; | |
196 | kas_PrincipalDelete( (void *) cellHandle, NULL, who, &ast_kd ); | |
197 | free( who ); | |
198 | // release converted java strings | |
199 | if( userName != NULL ) { | |
200 | (*env)->ReleaseStringUTFChars(env, juserName, userName); | |
201 | } | |
202 | if( password != NULL ) { | |
203 | (*env)->ReleaseStringUTFChars(env, jpassword, password); | |
204 | } | |
205 | throwAFSException( env, ast ); | |
206 | return; | |
207 | } | |
208 | ||
209 | free( who ); | |
210 | // release converted java strings | |
211 | if( userName != NULL ) { | |
212 | (*env)->ReleaseStringUTFChars(env, juserName, userName); | |
213 | } | |
214 | if( password != NULL ) { | |
215 | (*env)->ReleaseStringUTFChars(env, jpassword, password); | |
216 | } | |
217 | ||
218 | } | |
219 | ||
220 | /** | |
221 | * Deletes the pts and kas entry for a user. Deletes this user from the | |
222 | * membership list of the groups to which it belonged, but does not delete | |
223 | * the groups owned by this user. | |
224 | * | |
225 | * env the Java environment | |
226 | * cls the current Java class | |
227 | * cellHandle the handle of the cell to which the user belongs | |
228 | * juserName the name of the user to delete | |
229 | */ | |
230 | JNIEXPORT void JNICALL | |
231 | Java_org_openafs_jafs_User_delete | |
232 | (JNIEnv *env, jclass cls, jlong cellHandle, jstring juserName ) | |
233 | { | |
234 | afs_status_t ast; | |
235 | const char *userName; | |
236 | kas_identity_p who = (kas_identity_p) malloc( sizeof(kas_identity_t) ); | |
237 | int kas; | |
238 | ||
239 | if( !who ) { | |
240 | throwAFSException( env, JAFSADMNOMEM ); | |
241 | return; | |
242 | } | |
243 | ||
244 | if( juserName != NULL ) { | |
245 | userName = (*env)->GetStringUTFChars(env, juserName, 0); | |
246 | if( !userName ) { | |
247 | free( who ); | |
248 | throwAFSException( env, JAFSADMNOMEM ); | |
249 | return; | |
250 | } | |
251 | } else { | |
252 | userName = NULL; | |
253 | } | |
254 | ||
255 | // make sure the name is within the allowed bounds | |
256 | if( userName != NULL && strlen( userName ) > KAS_MAX_NAME_LEN ) { | |
257 | free( who ); | |
258 | if( userName != NULL ) { | |
259 | (*env)->ReleaseStringUTFChars(env, juserName, userName); | |
260 | } | |
261 | throwAFSException( env, ADMPTSUSERNAMETOOLONG ); | |
262 | return; | |
263 | } | |
264 | ||
265 | if( userName != NULL ) { | |
266 | internal_makeKasIdentity( userName, who ); | |
267 | } | |
268 | ||
269 | // delete the kas entry | |
270 | if( !kas_PrincipalDelete( (void *) cellHandle, NULL, who, &ast ) ) { | |
271 | if( ast != KANOENT ) { | |
272 | free(who); | |
273 | if( userName != NULL ) { | |
274 | (*env)->ReleaseStringUTFChars(env, juserName, userName); | |
275 | } | |
276 | throwAFSException( env, ast ); | |
277 | return; | |
278 | } else { | |
279 | kas = FALSE; | |
280 | } | |
281 | } | |
282 | ||
283 | //delete the pts entry | |
284 | if( !pts_UserDelete( (void *) cellHandle, userName, &ast ) ) { | |
285 | // throw exception if there was no such pts user only if there was | |
286 | // also no such kas user | |
287 | if( (ast == ADMPTSFAILEDNAMETRANSLATE && !kas ) || | |
288 | ast != ADMPTSFAILEDNAMETRANSLATE ) { | |
289 | free( who ); | |
290 | if( userName != NULL ) { | |
291 | (*env)->ReleaseStringUTFChars(env, juserName, userName); | |
292 | } | |
293 | throwAFSException( env, ast ); | |
294 | return; | |
295 | } | |
296 | } | |
297 | ||
298 | free( who ); | |
299 | // release converted java strings | |
300 | if( userName != NULL ) { | |
301 | (*env)->ReleaseStringUTFChars(env, juserName, userName); | |
302 | } | |
303 | } | |
304 | ||
305 | /** | |
306 | * Unlocks a user. | |
307 | * | |
308 | * env the Java environment | |
309 | * cls the current Java class | |
310 | * cellHandle the handle of the cell to which the user belongs | |
311 | * juserName the name of the user to unlock | |
312 | */ | |
313 | JNIEXPORT void JNICALL | |
314 | Java_org_openafs_jafs_User_unlock | |
315 | (JNIEnv *env, jclass cls, jlong cellHandle, jstring juserName ) | |
316 | { | |
317 | afs_status_t ast; | |
318 | const char *userName; | |
319 | kas_identity_p who = (kas_identity_p) malloc( sizeof(kas_identity_t) ); | |
320 | ||
321 | if( !who ) { | |
322 | throwAFSException( env, JAFSADMNOMEM ); | |
323 | return; | |
324 | } | |
325 | ||
326 | // convert java strings | |
327 | if( juserName != NULL ) { | |
328 | userName = (*env)->GetStringUTFChars(env, juserName, 0); | |
329 | if( !userName ) { | |
330 | throwAFSException( env, JAFSADMNOMEM ); | |
331 | return; | |
332 | } | |
333 | } else { | |
334 | userName = NULL; | |
335 | } | |
336 | ||
337 | // make sure the name is within the allowed bounds | |
338 | if( userName != NULL && strlen( userName ) > KAS_MAX_NAME_LEN ) { | |
339 | free( who ); | |
340 | if( userName != NULL ) { | |
341 | (*env)->ReleaseStringUTFChars(env, juserName, userName); | |
342 | } | |
343 | throwAFSException( env, ADMPTSUSERNAMETOOLONG ); | |
344 | return; | |
345 | } | |
346 | ||
347 | if( userName != NULL ) { | |
348 | internal_makeKasIdentity( userName, who ); | |
349 | } | |
350 | ||
351 | if( !kas_PrincipalUnlock( (void *) cellHandle, NULL, who, &ast ) ) { | |
352 | free( who ); | |
353 | if( userName != NULL ) { | |
354 | (*env)->ReleaseStringUTFChars(env, juserName, userName); | |
355 | } | |
356 | throwAFSException( env, ast ); | |
357 | return; | |
358 | } | |
359 | ||
360 | free( who ); | |
361 | // release converted java strings | |
362 | if( userName != NULL ) { | |
363 | (*env)->ReleaseStringUTFChars(env, juserName, userName); | |
364 | } | |
365 | } | |
366 | ||
367 | /** | |
368 | * Retrieve the information for the specified user and populate the | |
369 | * given object | |
370 | * | |
371 | * env the Java environment | |
372 | * cellHandle the handle of the cell to which the user belongs | |
373 | * name the name of the user for which to get the info | |
374 | * user the User object to populate with the info | |
375 | */ | |
376 | void getUserInfoChar | |
377 | (JNIEnv *env, void *cellHandle, const char *name, jobject user) | |
378 | { | |
379 | jstring jowner; | |
380 | jstring jcreator; | |
381 | jstring jlastModName; | |
382 | jstring jencryptionKey; | |
383 | jboolean pts; | |
384 | jboolean kas; | |
385 | pts_UserEntry_t ptsEntry; | |
386 | afs_status_t ast; | |
387 | kas_identity_p who = (kas_identity_p) malloc( sizeof(kas_identity_t) ); | |
388 | kas_principalEntry_t kasEntry; | |
389 | unsigned int lockedUntil; | |
390 | ||
391 | if( !who ) { | |
392 | throwAFSException( env, JAFSADMNOMEM ); | |
393 | return; | |
394 | } | |
395 | ||
396 | // make sure the name is within the allowed bounds | |
397 | if( name != NULL && strlen( name ) > KAS_MAX_NAME_LEN ) { | |
398 | free( who ); | |
399 | throwAFSException( env, ADMPTSUSERNAMETOOLONG ); | |
400 | return; | |
401 | } | |
402 | ||
403 | if( name != NULL ) { | |
404 | internal_makeKasIdentity( name, who ); | |
405 | } | |
406 | ||
407 | // get all the field ids, if you haven't done so already | |
408 | if( userCls == 0 ) { | |
409 | internal_getUserClass( env, user ); | |
410 | } | |
411 | ||
412 | // get the pts entry | |
413 | if ( !pts_UserGet( cellHandle, name, &ptsEntry, &ast ) ) { | |
414 | // if the user has no pts ptsEntry | |
415 | if( ast == ADMPTSFAILEDNAMETRANSLATE ) { | |
416 | pts = FALSE; | |
417 | } else { | |
418 | free( who ); | |
419 | throwAFSException( env, ast ); | |
420 | return; | |
421 | } | |
422 | } else { | |
423 | pts = TRUE; | |
424 | } | |
425 | ||
426 | ||
427 | // get the kas entry | |
428 | if( !kas_PrincipalGet( cellHandle, NULL, who, &kasEntry, &ast ) ) { | |
429 | // no kas entry | |
430 | if( ast == KANOENT ) { | |
431 | if( !pts ) { | |
432 | free( who ); | |
433 | throwAFSException( env, ast ); | |
434 | return; | |
435 | } else { | |
436 | kas = FALSE; | |
437 | } | |
438 | // other | |
439 | } else { | |
440 | free( who ); | |
441 | throwAFSException( env, ast ); | |
442 | return; | |
443 | } | |
444 | } else { | |
445 | kas = TRUE; | |
446 | } | |
447 | ||
448 | // get the lock status | |
449 | if( kas && !kas_PrincipalLockStatusGet( cellHandle, NULL, who, | |
450 | &lockedUntil, &ast ) ) { | |
451 | free( who ); | |
452 | throwAFSException( env, ast ); | |
453 | return; | |
454 | } | |
455 | ||
456 | (*env)->SetBooleanField(env, user, user_ptsField, pts); | |
457 | (*env)->SetBooleanField(env, user, user_kasField, kas); | |
458 | ||
459 | // set the pts fields | |
460 | if( pts ) { | |
461 | (*env)->SetIntField(env, user, user_nameUidField, ptsEntry.nameUid); | |
462 | (*env)->SetIntField(env, user, user_ownerUidField, ptsEntry.ownerUid); | |
463 | (*env)->SetIntField(env, user, user_creatorUidField, | |
464 | ptsEntry.creatorUid); | |
465 | (*env)->SetIntField(env, user, user_groupCreationQuotaField, | |
466 | ptsEntry.groupCreationQuota); | |
467 | (*env)->SetIntField(env, user, user_groupMembershipCountField, | |
468 | ptsEntry.groupMembershipCount); | |
469 | ||
470 | if( ptsEntry.listStatus == PTS_USER_OWNER_ACCESS ) { | |
471 | (*env)->SetIntField(env, user, user_listStatusField, | |
472 | org_openafs_jafs_User_USER_OWNER_ACCESS); | |
473 | } else { | |
474 | (*env)->SetIntField(env, user, user_listStatusField, | |
475 | org_openafs_jafs_User_USER_ANYUSER_ACCESS); | |
476 | } | |
477 | if( ptsEntry.listGroupsOwned == PTS_USER_OWNER_ACCESS ) { | |
478 | (*env)->SetIntField(env, user, user_listGroupsOwnedField, | |
479 | org_openafs_jafs_User_USER_OWNER_ACCESS); | |
480 | } else { | |
481 | (*env)->SetIntField(env, user, user_listGroupsOwnedField, | |
482 | org_openafs_jafs_User_USER_ANYUSER_ACCESS); | |
483 | } | |
484 | if( ptsEntry.listMembership == PTS_USER_OWNER_ACCESS ) { | |
485 | (*env)->SetIntField(env, user, user_listMembershipField, | |
486 | org_openafs_jafs_User_USER_OWNER_ACCESS); | |
487 | } else { | |
488 | (*env)->SetIntField(env, user, user_listMembershipField, | |
489 | org_openafs_jafs_User_USER_ANYUSER_ACCESS); | |
490 | } | |
491 | ||
492 | jowner = (*env)->NewStringUTF(env, ptsEntry.owner); | |
493 | jcreator = (*env)->NewStringUTF(env, ptsEntry.creator); | |
494 | ||
495 | (*env)->SetObjectField(env, user, user_ownerField, jowner); | |
496 | (*env)->SetObjectField(env, user, user_creatorField, jcreator); | |
497 | ||
498 | } | |
499 | ||
500 | // set the kas fields | |
501 | if( kas ) { | |
502 | char *convertedKey; | |
503 | int i; | |
504 | if( kasEntry.adminSetting == KAS_ADMIN ) { | |
505 | (*env)->SetIntField(env, user, user_adminSettingField, | |
506 | org_openafs_jafs_User_ADMIN); | |
507 | } else { | |
508 | (*env)->SetIntField(env, user, user_adminSettingField, | |
509 | org_openafs_jafs_User_NO_ADMIN); | |
510 | } | |
511 | if( kasEntry.tgsSetting == TGS ) { | |
512 | (*env)->SetIntField(env, user, user_tgsSettingField, | |
513 | org_openafs_jafs_User_GRANT_TICKETS); | |
514 | } else { | |
515 | (*env)->SetIntField(env, user, user_tgsSettingField, | |
516 | org_openafs_jafs_User_NO_GRANT_TICKETS); | |
517 | } | |
518 | if( kasEntry.encSetting != NO_ENCRYPT ) { | |
519 | (*env)->SetIntField(env, user, user_encSettingField, | |
520 | org_openafs_jafs_User_ENCRYPT); | |
521 | } else { | |
522 | (*env)->SetIntField(env, user, user_encSettingField, | |
523 | org_openafs_jafs_User_NO_ENCRYPT); | |
524 | } | |
525 | if( kasEntry.cpwSetting == CHANGE_PASSWORD ) { | |
526 | (*env)->SetIntField(env, user, user_cpwSettingField, | |
527 | org_openafs_jafs_User_CHANGE_PASSWORD); | |
528 | } else { | |
529 | (*env)->SetIntField(env, user, user_cpwSettingField, | |
530 | org_openafs_jafs_User_NO_CHANGE_PASSWORD); | |
531 | } | |
532 | if( kasEntry.rpwSetting == REUSE_PASSWORD ) { | |
533 | (*env)->SetIntField(env, user, user_rpwSettingField, | |
534 | org_openafs_jafs_User_REUSE_PASSWORD); | |
535 | } else { | |
536 | (*env)->SetIntField(env, user, user_rpwSettingField, | |
537 | org_openafs_jafs_User_NO_REUSE_PASSWORD); | |
538 | } | |
539 | (*env)->SetIntField(env, user, user_userExpirationField, | |
540 | kasEntry.userExpiration); | |
541 | (*env)->SetIntField(env, user, user_lastModTimeField, | |
542 | kasEntry.lastModTime); | |
543 | (*env)->SetIntField(env, user, user_lastChangePasswordTimeField, | |
544 | kasEntry.lastChangePasswordTime); | |
545 | (*env)->SetIntField(env, user, user_maxTicketLifetimeField, | |
546 | kasEntry.maxTicketLifetime); | |
547 | (*env)->SetIntField(env, user, user_keyVersionField, | |
548 | kasEntry.keyVersion); | |
549 | (*env)->SetLongField(env, user, user_keyCheckSumField, | |
550 | (unsigned int) kasEntry.keyCheckSum); | |
551 | (*env)->SetIntField(env, user, user_daysToPasswordExpireField, | |
552 | kasEntry.daysToPasswordExpire); | |
553 | (*env)->SetIntField(env, user, user_failLoginCountField, | |
554 | kasEntry.failLoginCount); | |
555 | (*env)->SetIntField(env, user, user_lockTimeField, kasEntry.lockTime); | |
556 | (*env)->SetIntField(env, user, user_lockedUntilField, lockedUntil); | |
557 | ||
558 | jlastModName = (*env)->NewStringUTF(env, | |
559 | kasEntry.lastModPrincipal.principal); | |
560 | (*env)->SetObjectField(env, user, user_lastModNameField, jlastModName); | |
561 | ||
562 | convertedKey = malloc( sizeof(char *) * (sizeof(kasEntry.key.key)*4+1) ); | |
563 | if( !convertedKey ) { | |
564 | throwAFSException( env, JAFSADMNOMEM ); | |
565 | return; | |
566 | } | |
567 | for( i = 0; i < sizeof(kasEntry.key.key); i++ ) { | |
568 | sprintf( &(convertedKey[i*4]), "\\%0.3o", kasEntry.key.key[i] ); | |
569 | } | |
570 | jencryptionKey = (*env)->NewStringUTF(env, convertedKey); | |
571 | (*env)->SetObjectField(env, user, user_encryptionKeyField, | |
572 | jencryptionKey); | |
573 | free( convertedKey ); | |
574 | } | |
575 | free(who); | |
576 | } | |
577 | ||
578 | /** | |
579 | * Fills in the information fields of the provided User. | |
580 | * Fills in values based on the current pts and kas information of the user. | |
581 | * | |
582 | * env the Java environment | |
583 | * cls the current Java class | |
584 | * cellHandle the handle of the cell to which the user belongs | |
585 | * jname the name of the user for which to get the information | |
586 | * user the User object in which to fill in the | |
587 | * information | |
588 | */ | |
589 | JNIEXPORT void JNICALL | |
590 | Java_org_openafs_jafs_User_getUserInfo | |
591 | (JNIEnv *env, jclass cls, jlong cellHandle, jstring jname, jobject user) | |
592 | { | |
593 | const char *name; | |
594 | ||
595 | if( jname != NULL ) { | |
596 | name = (*env)->GetStringUTFChars(env, jname, 0); | |
597 | if( !name ) { | |
598 | throwAFSException( env, JAFSADMNOMEM ); | |
599 | return; | |
600 | } | |
601 | } else { | |
602 | name = NULL; | |
603 | } | |
604 | ||
605 | getUserInfoChar( env, cellHandle, name, user ); | |
606 | ||
607 | // get class fields if need be | |
608 | if( userCls == 0 ) { | |
609 | internal_getUserClass( env, user ); | |
610 | } | |
611 | ||
612 | // set name in case blank object | |
613 | (*env)->SetObjectField(env, user, user_nameField, jname); | |
614 | ||
615 | if( name != NULL ) { | |
616 | (*env)->ReleaseStringUTFChars(env, jname, name); | |
617 | } | |
618 | } | |
619 | ||
620 | /** | |
621 | * Sets the information values of this AFS user to be the parameter values. | |
622 | * Sets both kas and pts fields. | |
623 | * | |
624 | * env the Java environment | |
625 | * cls the current Java class | |
626 | * cellHandle the handle of the cell to which the user belongs | |
627 | * jname the name of the user for which to set the information | |
628 | * user the User object containing the desired | |
629 | * information | |
630 | */ | |
631 | JNIEXPORT void JNICALL | |
632 | Java_org_openafs_jafs_User_setUserInfo | |
633 | (JNIEnv *env, jclass cls, jlong cellHandle, jstring jname, jobject user ) | |
634 | { | |
635 | const char *name; | |
636 | kas_identity_p who = (kas_identity_p) malloc( sizeof(kas_identity_t) ); | |
637 | pts_UserUpdateEntry_t ptsEntry; | |
638 | afs_status_t ast; | |
639 | kas_admin_t isAdmin; | |
640 | kas_tgs_t grantTickets; | |
641 | kas_enc_t canEncrypt; | |
642 | kas_cpw_t canChangePassword; | |
643 | kas_rpw_t passwordReuse; | |
644 | unsigned int expirationDate; | |
645 | unsigned int maxTicketLifetime; | |
646 | unsigned int passwordExpires; | |
647 | unsigned int failedPasswordAttempts; | |
648 | unsigned int failedPasswordLockTime; | |
649 | int kas; | |
650 | int pts; | |
651 | ||
652 | if( !who ) { | |
653 | throwAFSException( env, JAFSADMNOMEM ); | |
654 | return; | |
655 | } | |
656 | ||
657 | if( jname != NULL ) { | |
658 | name = (*env)->GetStringUTFChars(env, jname, 0); | |
659 | if( !name ) { | |
660 | throwAFSException( env, JAFSADMNOMEM ); | |
661 | return; | |
662 | } | |
663 | } else { | |
664 | name = NULL; | |
665 | } | |
666 | ||
667 | // make sure the name is within the allowed bounds | |
668 | if( name != NULL && strlen( name ) > KAS_MAX_NAME_LEN ) { | |
669 | free( who ); | |
670 | (*env)->ReleaseStringUTFChars(env, jname, name); | |
671 | throwAFSException( env, ADMPTSUSERNAMETOOLONG ); | |
672 | return; | |
673 | } | |
674 | ||
675 | if( name != NULL ) { | |
676 | internal_makeKasIdentity( name, who ); | |
677 | } | |
678 | ||
679 | // get class fields if need be | |
680 | if( userCls == 0 ) { | |
681 | internal_getUserClass( env, user ); | |
682 | } | |
683 | ||
684 | kas = (*env)->GetBooleanField(env, user, user_kasField); | |
685 | pts = (*env)->GetBooleanField(env, user, user_ptsField); | |
686 | ||
687 | if( pts ) { | |
688 | // set the pts fields: | |
689 | ptsEntry.flag = PTS_USER_UPDATE_GROUP_CREATE_QUOTA | | |
690 | PTS_USER_UPDATE_PERMISSIONS; | |
691 | ptsEntry.groupCreationQuota = | |
692 | (*env)->GetIntField(env, user, user_groupCreationQuotaField); | |
693 | if( (*env)->GetIntField(env, user, user_listStatusField) == | |
694 | org_openafs_jafs_User_USER_OWNER_ACCESS ) { | |
695 | ptsEntry.listStatus = PTS_USER_OWNER_ACCESS; | |
696 | } else { | |
697 | ptsEntry.listStatus = PTS_USER_ANYUSER_ACCESS; | |
698 | } | |
699 | if( (*env)->GetIntField(env, user, user_listGroupsOwnedField) == | |
700 | org_openafs_jafs_User_USER_OWNER_ACCESS ) { | |
701 | ptsEntry.listGroupsOwned = PTS_USER_OWNER_ACCESS; | |
702 | } else { | |
703 | ptsEntry.listGroupsOwned = PTS_USER_ANYUSER_ACCESS; | |
704 | } | |
705 | if( (*env)->GetIntField(env, user, user_listMembershipField) == | |
706 | org_openafs_jafs_User_USER_OWNER_ACCESS ) { | |
707 | ptsEntry.listMembership = PTS_USER_OWNER_ACCESS; | |
708 | } else { | |
709 | ptsEntry.listMembership = PTS_USER_ANYUSER_ACCESS; | |
710 | } | |
711 | if( !pts_UserModify( (void *) cellHandle, name, &ptsEntry, &ast ) ) { | |
712 | free( who ); | |
713 | if( name != NULL ) { | |
714 | (*env)->ReleaseStringUTFChars(env, jname, name); | |
715 | } | |
716 | throwAFSException( env, ast ); | |
717 | return; | |
718 | } | |
719 | } | |
720 | ||
721 | if( kas ) { | |
722 | // set the kas fields: | |
723 | if( (*env)->GetIntField(env, user, user_adminSettingField) == | |
724 | org_openafs_jafs_User_ADMIN ) { | |
725 | isAdmin = KAS_ADMIN; | |
726 | } else { | |
727 | isAdmin = NO_KAS_ADMIN; | |
728 | } | |
729 | if( (*env)->GetIntField(env, user, user_tgsSettingField) == | |
730 | org_openafs_jafs_User_GRANT_TICKETS ) { | |
731 | grantTickets = TGS; | |
732 | } else { | |
733 | grantTickets = NO_TGS; | |
734 | } | |
735 | if( (*env)->GetIntField(env, user, user_encSettingField) == | |
736 | org_openafs_jafs_User_ENCRYPT ) { | |
737 | canEncrypt = 0; | |
738 | } else { | |
739 | canEncrypt = NO_ENCRYPT; | |
740 | } | |
741 | if( (*env)->GetIntField(env, user, user_cpwSettingField) == | |
742 | org_openafs_jafs_User_CHANGE_PASSWORD ) { | |
743 | canChangePassword = CHANGE_PASSWORD; | |
744 | } else { | |
745 | canChangePassword = NO_CHANGE_PASSWORD; | |
746 | } | |
747 | if( (*env)->GetIntField(env, user, user_rpwSettingField) == | |
748 | org_openafs_jafs_User_REUSE_PASSWORD ) { | |
749 | passwordReuse = REUSE_PASSWORD; | |
750 | } else { | |
751 | passwordReuse = NO_REUSE_PASSWORD; | |
752 | } | |
753 | expirationDate = (*env)->GetIntField(env, user, | |
754 | user_userExpirationField); | |
755 | maxTicketLifetime = (*env)->GetIntField(env, user, | |
756 | user_maxTicketLifetimeField); | |
757 | passwordExpires = (*env)->GetIntField(env, user, | |
758 | user_daysToPasswordExpireField); | |
759 | failedPasswordAttempts = (*env)->GetIntField(env, user, | |
760 | user_failLoginCountField); | |
761 | failedPasswordLockTime = (*env)->GetIntField(env, user, | |
762 | user_lockTimeField); | |
763 | ||
764 | if( !kas_PrincipalFieldsSet( (void *) cellHandle, NULL, who, &isAdmin, | |
765 | &grantTickets, &canEncrypt, | |
766 | &canChangePassword, &expirationDate, | |
767 | &maxTicketLifetime, &passwordExpires, | |
768 | &passwordReuse, &failedPasswordAttempts, | |
769 | &failedPasswordLockTime, &ast ) ) { | |
770 | free( who ); | |
771 | if( name != NULL ) { | |
772 | (*env)->ReleaseStringUTFChars(env, jname, name); | |
773 | } | |
774 | throwAFSException( env, ast ); | |
775 | return; | |
776 | } | |
777 | } | |
778 | ||
779 | free( who ); | |
780 | if( name != NULL ) { | |
781 | (*env)->ReleaseStringUTFChars(env, jname, name); | |
782 | } | |
783 | } | |
784 | ||
785 | /** | |
786 | * Renames the given user. Does not update the info fields of the kas entry | |
787 | * -- the calling code is responsible for that. | |
788 | * | |
789 | * env the Java environment | |
790 | * cls the current Java class | |
791 | * cellHandle the handle of the cell to which the user belongs | |
792 | * joldName the name of the user to rename | |
793 | * jnewName the new name for the user | |
794 | */ | |
795 | JNIEXPORT void JNICALL | |
796 | Java_org_openafs_jafs_User_rename | |
797 | (JNIEnv *env, jclass cls, jlong cellHandle, jstring joldName, jstring jnewName) | |
798 | { | |
799 | ||
800 | const char *oldName; | |
801 | const char *newName; | |
802 | kas_identity_p whoOld = (kas_identity_p) malloc( sizeof(kas_identity_t) ); | |
803 | kas_identity_p whoNew = (kas_identity_p) malloc( sizeof(kas_identity_t) ); | |
804 | kas_principalEntry_t kasEntry; | |
805 | pts_UserEntry_t ptsEntry; | |
806 | afs_status_t ast; | |
807 | int kas; | |
808 | ||
809 | if( !whoOld || !whoNew ) { | |
810 | if( whoOld ) { | |
811 | free( whoOld ); | |
812 | } | |
813 | if( whoNew ) { | |
814 | free( whoNew ); | |
815 | } | |
816 | throwAFSException( env, JAFSADMNOMEM ); | |
817 | return; | |
818 | } | |
819 | ||
820 | if( joldName != NULL ) { | |
821 | oldName = (*env)->GetStringUTFChars(env, joldName, 0); | |
822 | if( !oldName ) { | |
823 | throwAFSException( env, JAFSADMNOMEM ); | |
824 | return; | |
825 | } | |
826 | } else { | |
827 | oldName = NULL; | |
828 | } | |
829 | if( jnewName != NULL ) { | |
830 | newName = (*env)->GetStringUTFChars(env, jnewName, 0); | |
831 | if( !newName ) { | |
832 | if( oldName != NULL ) { | |
833 | (*env)->ReleaseStringUTFChars(env, joldName, oldName); | |
834 | } | |
835 | throwAFSException( env, JAFSADMNOMEM ); | |
836 | return; | |
837 | } | |
838 | } else { | |
839 | newName = NULL; | |
840 | } | |
841 | ||
842 | // make sure the names are within the allowed bounds | |
843 | if( oldName != NULL && strlen( oldName ) > KAS_MAX_NAME_LEN ) { | |
844 | free( whoOld ); | |
845 | free( whoNew ); | |
846 | if( oldName != NULL ) { | |
847 | (*env)->ReleaseStringUTFChars(env, joldName, oldName); | |
848 | } | |
849 | if( newName != NULL ) { | |
850 | (*env)->ReleaseStringUTFChars(env, jnewName, newName); | |
851 | } | |
852 | throwAFSException( env, ADMPTSUSERNAMETOOLONG ); | |
853 | return; | |
854 | } | |
855 | if( newName != NULL && strlen( newName ) > KAS_MAX_NAME_LEN ) { | |
856 | free( whoOld ); | |
857 | free( whoNew ); | |
858 | if( oldName != NULL ) { | |
859 | (*env)->ReleaseStringUTFChars(env, joldName, oldName); | |
860 | } | |
861 | if( newName != NULL ) { | |
862 | (*env)->ReleaseStringUTFChars(env, jnewName, newName); | |
863 | } | |
864 | throwAFSException( env, ADMPTSUSERNAMETOOLONG ); | |
865 | return; | |
866 | } | |
867 | ||
868 | if( oldName != NULL ) { | |
869 | internal_makeKasIdentity( oldName, whoOld ); | |
870 | } | |
871 | if( newName != NULL ) { | |
872 | internal_makeKasIdentity( newName, whoNew ); | |
873 | } | |
874 | ||
875 | // retrieve the old kas info | |
876 | if( !kas_PrincipalGet( (void *) cellHandle, NULL, whoOld, | |
877 | &kasEntry, &ast ) ) { | |
878 | if( ast != KANOENT ) { | |
879 | free( whoOld ); | |
880 | free( whoNew ); | |
881 | if( oldName != NULL ) { | |
882 | (*env)->ReleaseStringUTFChars(env, joldName, oldName); | |
883 | } | |
884 | if( newName != NULL ) { | |
885 | (*env)->ReleaseStringUTFChars(env, jnewName, newName); | |
886 | } | |
887 | throwAFSException( env, ast ); | |
888 | return; | |
889 | } else { | |
890 | kas = FALSE; | |
891 | } | |
892 | } else { | |
893 | kas = TRUE; | |
894 | } | |
895 | ||
896 | if( kas ) { | |
897 | // create a new kas entry | |
898 | // temporarily set the password equal to the new name | |
899 | if (!kas_PrincipalCreate( (void *) cellHandle, NULL, whoNew, | |
900 | newName, &ast ) ) { | |
901 | free( whoOld ); | |
902 | free( whoNew ); | |
903 | if( oldName != NULL ) { | |
904 | (*env)->ReleaseStringUTFChars(env, joldName, oldName); | |
905 | } | |
906 | if( newName != NULL ) { | |
907 | (*env)->ReleaseStringUTFChars(env, jnewName, newName); | |
908 | } | |
909 | throwAFSException( env, ast ); | |
910 | return; | |
911 | } | |
912 | ||
913 | // set the password | |
914 | ast = 0; | |
915 | // For some reason kas_PrincipalKeySet doesn't set the return code | |
916 | // correctly. It always returns 0. | |
917 | // So instead of checking the return code, we see if there's an | |
918 | // error in the status variable. | |
919 | kas_PrincipalKeySet( (void *) cellHandle, NULL, whoNew, 0, | |
920 | &(kasEntry.key), &ast ); | |
921 | if( ast ) { | |
922 | afs_status_t ast_kd; | |
923 | kas_PrincipalDelete( (void *) cellHandle, NULL, whoNew, &ast_kd ); | |
924 | free( whoOld ); | |
925 | free( whoNew ); | |
926 | if( oldName != NULL ) { | |
927 | (*env)->ReleaseStringUTFChars(env, joldName, oldName); | |
928 | } | |
929 | if( newName != NULL ) { | |
930 | (*env)->ReleaseStringUTFChars(env, jnewName, newName); | |
931 | } | |
932 | throwAFSException( env, ast ); | |
933 | return; | |
934 | } | |
935 | } | |
936 | ||
937 | // rename the pts entry | |
938 | if( !pts_UserRename( (void *) cellHandle, oldName, newName, &ast ) ) { | |
939 | // throw exception if there was no such pts user only if | |
940 | // there was also no such kas user | |
941 | if( (ast == ADMPTSFAILEDNAMETRANSLATE && !kas ) || | |
942 | ast != ADMPTSFAILEDNAMETRANSLATE ) { | |
943 | afs_status_t ast_kd; | |
944 | if( kas ) { | |
945 | kas_PrincipalDelete( (void *) cellHandle, NULL, whoNew, | |
946 | &ast_kd ); | |
947 | } | |
948 | free( whoOld ); | |
949 | free( whoNew ); | |
950 | if( oldName != NULL ) { | |
951 | (*env)->ReleaseStringUTFChars(env, joldName, oldName); | |
952 | } | |
953 | if( newName != NULL ) { | |
954 | (*env)->ReleaseStringUTFChars(env, jnewName, newName); | |
955 | } | |
956 | throwAFSException( env, ast ); | |
957 | return; | |
958 | } | |
959 | } | |
960 | ||
961 | if( kas ) { | |
962 | // delete the old kas entry | |
963 | if( !kas_PrincipalDelete( (void *) cellHandle, NULL, whoOld, &ast ) ) { | |
964 | free( whoOld ); | |
965 | free( whoNew ); | |
966 | if( oldName != NULL ) { | |
967 | (*env)->ReleaseStringUTFChars(env, joldName, oldName); | |
968 | } | |
969 | if( newName != NULL ) { | |
970 | (*env)->ReleaseStringUTFChars(env, jnewName, newName); | |
971 | } | |
972 | throwAFSException( env, ast ); | |
973 | return; | |
974 | } | |
975 | } | |
976 | ||
977 | free( whoOld ); | |
978 | free( whoNew ); | |
979 | if( oldName != NULL ) { | |
980 | (*env)->ReleaseStringUTFChars(env, joldName, oldName); | |
981 | } | |
982 | if( newName != NULL ) { | |
983 | (*env)->ReleaseStringUTFChars(env, jnewName, newName); | |
984 | } | |
985 | } | |
986 | ||
987 | /** | |
988 | * Sets the password of the given user. Sets the key version to 0. | |
989 | * | |
990 | * env the Java environment | |
991 | * cls the current Java class | |
992 | * cellHandle the handle of the cell to which the user belongs | |
993 | * juserName the name of the user for which to set the password | |
994 | * jnewPassword the new password for the user | |
995 | */ | |
996 | JNIEXPORT void JNICALL | |
997 | Java_org_openafs_jafs_User_setPassword | |
998 | (JNIEnv *env, jclass cls, jlong cellHandle, jstring juserName, | |
999 | jstring jnewPassword) | |
1000 | { | |
1001 | afs_status_t ast; | |
1002 | char *cellName; | |
1003 | const char *userName; | |
1004 | const char *newPassword; | |
1005 | kas_encryptionKey_p newKey = | |
1006 | (kas_encryptionKey_p) malloc( sizeof(kas_encryptionKey_t) ); | |
1007 | kas_identity_p who = (kas_identity_p) malloc( sizeof(kas_identity_t) ); | |
1008 | ||
1009 | if( !who || !newKey ) { | |
1010 | if( who ) { | |
1011 | free( who ); | |
1012 | } | |
1013 | if( newKey ) { | |
1014 | free( newKey ); | |
1015 | } | |
1016 | throwAFSException( env, JAFSADMNOMEM ); | |
1017 | return; | |
1018 | } | |
1019 | ||
1020 | if( juserName != NULL ) { | |
1021 | userName = (*env)->GetStringUTFChars(env, juserName, 0); | |
1022 | if( !userName ) { | |
1023 | throwAFSException( env, JAFSADMNOMEM ); | |
1024 | return; | |
1025 | } | |
1026 | } else { | |
1027 | userName = NULL; | |
1028 | } | |
1029 | if( jnewPassword != NULL ) { | |
1030 | newPassword = (*env)->GetStringUTFChars(env, jnewPassword, 0); | |
1031 | if( !newPassword ) { | |
1032 | throwAFSException( env, JAFSADMNOMEM ); | |
1033 | return; | |
1034 | } | |
1035 | } else { | |
1036 | newPassword = NULL; | |
1037 | } | |
1038 | ||
1039 | // make sure the name is within the allowed bounds | |
1040 | if( userName != NULL && strlen( userName ) > KAS_MAX_NAME_LEN ) { | |
1041 | free(who); | |
1042 | free( newKey ); | |
1043 | if( userName != NULL ) { | |
1044 | (*env)->ReleaseStringUTFChars(env, juserName, userName); | |
1045 | } | |
1046 | if( newPassword != NULL ) { | |
1047 | (*env)->ReleaseStringUTFChars(env, jnewPassword, newPassword); | |
1048 | } | |
1049 | throwAFSException( env, ADMPTSUSERNAMETOOLONG ); | |
1050 | return; | |
1051 | } | |
1052 | ||
1053 | if( !afsclient_CellNameGet( (void *) cellHandle, &cellName, &ast ) ) { | |
1054 | free(who); | |
1055 | free( newKey ); | |
1056 | if( userName != NULL ) { | |
1057 | (*env)->ReleaseStringUTFChars(env, juserName, userName); | |
1058 | } | |
1059 | if( newPassword != NULL ) { | |
1060 | (*env)->ReleaseStringUTFChars(env, jnewPassword, newPassword); | |
1061 | } | |
1062 | throwAFSException( env, ast ); | |
1063 | return; | |
1064 | } | |
1065 | ||
1066 | if( !kas_StringToKey( cellName, newPassword, newKey, &ast ) ) { | |
1067 | free(who); | |
1068 | free( newKey ); | |
1069 | if( userName != NULL ) { | |
1070 | (*env)->ReleaseStringUTFChars(env, juserName, userName); | |
1071 | } | |
1072 | if( newPassword != NULL ) { | |
1073 | (*env)->ReleaseStringUTFChars(env, jnewPassword, newPassword); | |
1074 | } | |
1075 | throwAFSException( env, ast ); | |
1076 | return; | |
1077 | } | |
1078 | ||
1079 | if( userName != NULL ) { | |
1080 | internal_makeKasIdentity( userName, who ); | |
1081 | } | |
1082 | ||
1083 | ast = 0; | |
1084 | // For some reason kas_PrincipalKeySet doesn't set the return code correctly. | |
1085 | // It always returns 0. | |
1086 | // So instead of checking the return code, we see if there's an error | |
1087 | // in the status variable. | |
1088 | kas_PrincipalKeySet( (void *) cellHandle, NULL, who, 0, newKey, &ast ); | |
1089 | if( ast ) { | |
1090 | free( who ); | |
1091 | free( newKey ); | |
1092 | if( userName != NULL ) { | |
1093 | (*env)->ReleaseStringUTFChars(env, juserName, userName); | |
1094 | } | |
1095 | if( newPassword != NULL ) { | |
1096 | (*env)->ReleaseStringUTFChars(env, jnewPassword, newPassword); | |
1097 | } | |
1098 | throwAFSException( env, ast ); | |
1099 | return; | |
1100 | } | |
1101 | ||
1102 | free( who ); | |
1103 | free( newKey ); | |
1104 | if( userName != NULL ) { | |
1105 | (*env)->ReleaseStringUTFChars(env, juserName, userName); | |
1106 | } | |
1107 | if( newPassword != NULL ) { | |
1108 | (*env)->ReleaseStringUTFChars(env, jnewPassword, newPassword); | |
1109 | } | |
1110 | ||
1111 | } | |
1112 | ||
1113 | /** | |
1114 | * Begin the process of getting the groups to which the user belongs. | |
1115 | * Returns an iteration ID to be used by subsequent calls to | |
1116 | * getUserGroupsNext and getUserGroupsDone. | |
1117 | * | |
1118 | * env the Java environment | |
1119 | * cls the current Java class | |
1120 | * cellHandle the handle of the cell to which the user belongs | |
1121 | * jname the name of the user for which to get the groups | |
1122 | * returns an iteration ID | |
1123 | */ | |
1124 | JNIEXPORT jlong JNICALL | |
1125 | Java_org_openafs_jafs_User_getUserGroupsBegin | |
1126 | (JNIEnv *env, jclass cls, jlong cellHandle, jstring jname) | |
1127 | { | |
1128 | const char *name; | |
1129 | afs_status_t ast; | |
1130 | void *iterationId; | |
1131 | ||
1132 | if( jname != NULL ) { | |
1133 | name = (*env)->GetStringUTFChars(env, jname, 0); | |
1134 | if( !name ) { | |
1135 | throwAFSException( env, JAFSADMNOMEM ); | |
1136 | return; | |
1137 | } | |
1138 | } else { | |
1139 | name = NULL; | |
1140 | } | |
1141 | ||
1142 | if( !pts_UserMemberListBegin( (void *) cellHandle, name, &iterationId, | |
1143 | &ast ) ) { | |
1144 | if( name != NULL ) { | |
1145 | (*env)->ReleaseStringUTFChars(env, jname, name); | |
1146 | } | |
1147 | throwAFSException( env, ast ); | |
1148 | return; | |
1149 | } | |
1150 | ||
1151 | if( name != NULL ) { | |
1152 | (*env)->ReleaseStringUTFChars(env, jname, name); | |
1153 | } | |
1154 | ||
1155 | return (jlong) iterationId; | |
1156 | ||
1157 | } | |
1158 | ||
1159 | /** | |
1160 | * Returns the next group to which the user belongs. Returns | |
1161 | * null if there are no more groups. | |
1162 | * | |
1163 | * env the Java environment | |
1164 | * cls the current Java class | |
1165 | * iterationId the iteration ID of this iteration | |
1166 | * returns the name of the next group | |
1167 | */ | |
1168 | JNIEXPORT jstring JNICALL | |
1169 | Java_org_openafs_jafs_User_getUserGroupsNextString | |
1170 | (JNIEnv *env, jclass cls, jlong iterationId) | |
1171 | { | |
1172 | afs_status_t ast; | |
1173 | char *groupName = malloc( sizeof(char)*PTS_MAX_NAME_LEN); | |
1174 | jstring jgroup; | |
1175 | ||
1176 | if( !groupName ) { | |
1177 | throwAFSException( env, JAFSADMNOMEM ); | |
1178 | return; | |
1179 | } | |
1180 | ||
1181 | if( !pts_UserMemberListNext( (void *) iterationId, groupName, &ast ) ) { | |
1182 | free( groupName ); | |
1183 | if( ast == ADMITERATORDONE ) { | |
1184 | return NULL; | |
1185 | } else { | |
1186 | throwAFSException( env, ast ); | |
1187 | return; | |
1188 | } | |
1189 | } | |
1190 | ||
1191 | jgroup = (*env)->NewStringUTF(env, groupName); | |
1192 | free( groupName ); | |
1193 | return jgroup; | |
1194 | } | |
1195 | ||
1196 | /** | |
1197 | * Fills the next group object of which the user belongs. Returns 0 if there | |
1198 | * are no more groups, != 0 otherwise. | |
1199 | * | |
1200 | * env the Java environment | |
1201 | * cls the current Java class | |
1202 | * cellHandle the handle of the cell to which the users belong | |
1203 | * iterationId the iteration ID of this iteration | |
1204 | * jgroupObject a Group object to be populated with the values of the | |
1205 | * next group | |
1206 | * returns 0 if there are no more users, != 0 otherwise | |
1207 | */ | |
1208 | JNIEXPORT jint JNICALL | |
1209 | Java_org_openafs_jafs_User_getUserGroupsNext | |
1210 | (JNIEnv *env, jclass cls, jlong cellHandle, jlong iterationId, | |
1211 | jobject jgroupObject) | |
1212 | { | |
1213 | afs_status_t ast; | |
1214 | char *groupName; | |
1215 | jstring jgroup; | |
1216 | ||
1217 | groupName = malloc( sizeof(char)*PTS_MAX_NAME_LEN); | |
1218 | ||
1219 | if( !groupName ) { | |
1220 | throwAFSException( env, JAFSADMNOMEM ); | |
1221 | return; | |
1222 | } | |
1223 | ||
1224 | if( !pts_UserMemberListNext( (void *) iterationId, groupName, &ast ) ) { | |
1225 | free( groupName ); | |
1226 | if( ast == ADMITERATORDONE ) { | |
1227 | return 0; | |
1228 | } else { | |
1229 | throwAFSException( env, ast ); | |
1230 | return 0; | |
1231 | } | |
1232 | } | |
1233 | ||
1234 | jgroup = (*env)->NewStringUTF(env, groupName); | |
1235 | ||
1236 | if( groupCls == 0 ) { | |
1237 | internal_getGroupClass( env, jgroupObject ); | |
1238 | } | |
1239 | ||
1240 | (*env)->SetObjectField(env, jgroupObject, group_nameField, jgroup); | |
1241 | ||
1242 | getGroupInfoChar( env, (void *) cellHandle, groupName, jgroupObject ); | |
1243 | (*env)->SetBooleanField( env, jgroupObject, group_cachedInfoField, TRUE ); | |
1244 | ||
1245 | free( groupName ); | |
1246 | return 1; | |
1247 | ||
1248 | } | |
1249 | ||
1250 | /** | |
1251 | * Signals that the iteration is complete and will not be accessed anymore. | |
1252 | * | |
1253 | * env the Java environment | |
1254 | * cls the current Java class | |
1255 | * iterationId the iteration ID of this iteration | |
1256 | */ | |
1257 | JNIEXPORT void JNICALL | |
1258 | Java_org_openafs_jafs_User_getUserGroupsDone | |
1259 | (JNIEnv *env, jclass cls, jlong iterationId) | |
1260 | { | |
1261 | afs_status_t ast; | |
1262 | ||
1263 | if( !pts_UserMemberListDone( (void *) iterationId, &ast ) ) { | |
1264 | throwAFSException( env, ast ); | |
1265 | return; | |
1266 | } | |
1267 | } | |
1268 | ||
1269 | /** | |
1270 | * Returns the total number of groups owned by the user. | |
1271 | * | |
1272 | * env the Java environment | |
1273 | * cls the current Java class | |
1274 | * cellHandle the handle of the cell to which the user belongs | |
1275 | * jname the name of the user for which to get the groups | |
1276 | * returns total number of groups owned by the user | |
1277 | */ | |
1278 | JNIEXPORT jint JNICALL | |
1279 | Java_org_openafs_jafs_User_getGroupsOwnedCount | |
1280 | (JNIEnv *env, jclass cls, jlong cellHandle, jstring jname) | |
1281 | { | |
1282 | afs_status_t ast; | |
1283 | void *iterationId; | |
1284 | char *groupName; | |
1285 | int i = 0; | |
1286 | ||
1287 | iterationId = | |
1288 | (void *) Java_org_openafs_jafs_User_getGroupsOwnedBegin( env, cls, | |
1289 | cellHandle, | |
1290 | jname ); | |
1291 | ||
1292 | groupName = malloc( sizeof(char)*PTS_MAX_NAME_LEN); | |
1293 | ||
1294 | if( !groupName ) { | |
1295 | throwAFSException( env, JAFSADMNOMEM ); | |
1296 | return -1; | |
1297 | } | |
1298 | ||
1299 | while ( pts_OwnedGroupListNext( (void *) iterationId, groupName, &ast ) ) | |
1300 | i++; | |
1301 | ||
1302 | free( groupName ); | |
1303 | ||
1304 | if( ast != ADMITERATORDONE ) { | |
1305 | throwAFSException( env, ast ); | |
1306 | return -1; | |
1307 | } | |
1308 | ||
1309 | return i; | |
1310 | } | |
1311 | ||
1312 | /** | |
1313 | * Begin the process of getting the groups that a user or group owns. | |
1314 | * Returns an iteration ID to be used by subsequent calls to | |
1315 | * getGroupsOwnedNext and getGroupsOwnedDone. | |
1316 | * | |
1317 | * env the Java environment | |
1318 | * cls the current Java class | |
1319 | * cellHandle the handle of the cell to which the user belongs | |
1320 | * jname the name of the user or group for which to get the groups | |
1321 | * returns an iteration ID | |
1322 | */ | |
1323 | JNIEXPORT jlong JNICALL | |
1324 | Java_org_openafs_jafs_User_getGroupsOwnedBegin | |
1325 | (JNIEnv *env, jclass cls, jlong cellHandle, jstring jname) | |
1326 | { | |
1327 | const char *name; | |
1328 | afs_status_t ast; | |
1329 | void *iterationId; | |
1330 | ||
1331 | if( jname != NULL ) { | |
1332 | name = (*env)->GetStringUTFChars(env, jname, 0); | |
1333 | if( !name ) { | |
1334 | throwAFSException( env, JAFSADMNOMEM ); | |
1335 | return; | |
1336 | } | |
1337 | } else { | |
1338 | name = NULL; | |
1339 | } | |
1340 | ||
1341 | if( !pts_OwnedGroupListBegin( (void *) cellHandle, name, | |
1342 | &iterationId, &ast ) ) { | |
1343 | if( jname != NULL ) { | |
1344 | (*env)->ReleaseStringUTFChars(env, jname, name); | |
1345 | } | |
1346 | throwAFSException( env, ast ); | |
1347 | return; | |
1348 | } | |
1349 | ||
1350 | if( jname != NULL ) { | |
1351 | (*env)->ReleaseStringUTFChars(env, jname, name); | |
1352 | } | |
1353 | ||
1354 | return (jlong) iterationId; | |
1355 | ||
1356 | } | |
1357 | ||
1358 | /** | |
1359 | * Returns the next group the user or group owns. Returns null | |
1360 | * if there are no more groups. | |
1361 | * | |
1362 | * env the Java environment | |
1363 | * cls the current Java class | |
1364 | * iterationId the iteration ID of this iteration | |
1365 | * returns the name of the next group | |
1366 | */ | |
1367 | JNIEXPORT jstring JNICALL | |
1368 | Java_org_openafs_jafs_User_getGroupsOwnedNextString | |
1369 | (JNIEnv *env, jclass cls, jlong iterationId) | |
1370 | { | |
1371 | afs_status_t ast; | |
1372 | char *groupName = malloc( sizeof(char)*PTS_MAX_NAME_LEN); | |
1373 | jstring jgroup; | |
1374 | ||
1375 | if( !groupName ) { | |
1376 | throwAFSException( env, JAFSADMNOMEM ); | |
1377 | return; | |
1378 | } | |
1379 | ||
1380 | if( !pts_OwnedGroupListNext( (void *) iterationId, groupName, &ast ) ) { | |
1381 | free( groupName ); | |
1382 | if( ast == ADMITERATORDONE ) { | |
1383 | return NULL; | |
1384 | } else { | |
1385 | throwAFSException( env, ast ); | |
1386 | return; | |
1387 | } | |
1388 | } | |
1389 | ||
1390 | jgroup = (*env)->NewStringUTF(env, groupName); | |
1391 | free( groupName ); | |
1392 | return jgroup; | |
1393 | ||
1394 | } | |
1395 | ||
1396 | /** | |
1397 | * Fills the next group object that the user or group owns. Returns 0 if | |
1398 | * there are no more groups, != 0 otherwise. | |
1399 | * | |
1400 | * env the Java environment | |
1401 | * cls the current Java class | |
1402 | * cellHandle the handle of the cell to which the users belong | |
1403 | * iterationId the iteration ID of this iteration | |
1404 | * jgroupObject a Group object to be populated with the values of the | |
1405 | * next group | |
1406 | * returns 0 if there are no more users, != 0 otherwise | |
1407 | */ | |
1408 | JNIEXPORT jint JNICALL | |
1409 | Java_org_openafs_jafs_User_getGroupsOwnedNext | |
1410 | (JNIEnv *env, jclass cls, jlong cellHandle, jlong iterationId, | |
1411 | jobject jgroupObject) | |
1412 | { | |
1413 | afs_status_t ast; | |
1414 | char *groupName; | |
1415 | jstring jgroup; | |
1416 | ||
1417 | groupName = malloc( sizeof(char)*PTS_MAX_NAME_LEN); | |
1418 | ||
1419 | if( !groupName ) { | |
1420 | throwAFSException( env, JAFSADMNOMEM ); | |
1421 | return; | |
1422 | } | |
1423 | ||
1424 | if( !pts_OwnedGroupListNext( (void *) iterationId, groupName, &ast ) ) { | |
1425 | free( groupName ); | |
1426 | if( ast == ADMITERATORDONE ) { | |
1427 | return 0; | |
1428 | } else { | |
1429 | throwAFSException( env, ast ); | |
1430 | return 0; | |
1431 | } | |
1432 | } | |
1433 | ||
1434 | jgroup = (*env)->NewStringUTF(env, groupName); | |
1435 | ||
1436 | if( groupCls == 0 ) { | |
1437 | internal_getGroupClass( env, jgroupObject ); | |
1438 | } | |
1439 | ||
1440 | (*env)->SetObjectField(env, jgroupObject, group_nameField, jgroup); | |
1441 | ||
1442 | getGroupInfoChar( env, (void *) cellHandle, groupName, jgroupObject ); | |
1443 | (*env)->SetBooleanField( env, jgroupObject, group_cachedInfoField, TRUE ); | |
1444 | ||
1445 | free( groupName ); | |
1446 | return 1; | |
1447 | ||
1448 | } | |
1449 | ||
1450 | /** | |
1451 | * Signals that the iteration is complete and will not be accessed anymore. | |
1452 | * | |
1453 | * env the Java environment | |
1454 | * cls the current Java class | |
1455 | * iterationId the iteration ID of this iteration | |
1456 | */ | |
1457 | JNIEXPORT void JNICALL | |
1458 | Java_org_openafs_jafs_User_getGroupsOwnedDone | |
1459 | (JNIEnv *env, jclass cls, jlong iterationId) | |
1460 | { | |
1461 | afs_status_t ast; | |
1462 | ||
1463 | if( !pts_OwnedGroupListDone( (void *) iterationId, &ast ) ) { | |
1464 | throwAFSException( env, ast ); | |
1465 | return; | |
1466 | } | |
1467 | ||
1468 | } | |
1469 | ||
1470 | // reclaim global memory being used by this portion | |
1471 | JNIEXPORT void JNICALL | |
1472 | Java_org_openafs_jafs_User_reclaimUserMemory | |
1473 | (JNIEnv *env, jclass cls) | |
1474 | { | |
1475 | if( userCls ) { | |
1476 | (*env)->DeleteGlobalRef(env, userCls); | |
1477 | userCls = 0; | |
1478 | } | |
1479 | ||
1480 | } | |
1481 | ||
1482 | ||
1483 |