/** * Begin the process of getting the KAS users, starting at * startIndex, that belong to the cell. * Returns an iteration ID to be used by subsequent calls to * getKasUsersNextString (or getKasUsersNext) * and getKasUsersDone. * * env the Java environment * cls the current Java class * cellHandle the handle of the cell to which the users belong * startIndex the starting base-zero index * returns an iteration ID */ JNIEXPORT jlong JNICALL Java_org_openafs_jafs_Cell_getKasUsersBeginAt (JNIEnv *env, jclass cls, jlong cellHandle, jint startIndex) { afs_status_t ast; void *iterationId; kas_identity_t who; int i; if( !kas_PrincipalGetBegin( (void *) cellHandle, NULL, &iterationId, &ast ) ) { throwAFSException( env, ast ); return; } for ( i = 1; i < startIndex; i++) { if( !kas_PrincipalGetNext( (void *) iterationId, &who, &ast ) ) { if( ast == ADMITERATORDONE ) { return 0; } else { throwAFSException( env, ast ); return 0; } } } return (jlong) iterationId; }
/** * Fills the next kas user object of the cell. Returns 0 if there * are no more users, != 0 otherwise. * * env the Java environment * cls the current Java class * cellHandle the handle of the cell to which the users belong * iterationId the iteration ID of this iteration * juserObject a User object to be populated with the values of * the next kas user * returns 0 if there are no more users, != 0 otherwise */ JNIEXPORT jint JNICALL Java_org_openafs_jafs_Cell_getKasUsersNext (JNIEnv *env, jclass cls, jlong cellHandle, jlong iterationId, jobject juserObject) { afs_status_t ast; kas_identity_t who; jstring juser; char *fullName = NULL; if( !kas_PrincipalGetNext( (void *) iterationId, &who, &ast ) ) { if( ast == ADMITERATORDONE ) { return 0; // other } else { throwAFSException( env, ast ); return 0; } } // take care of the instance stuff(by concatenating with a period in between) if( strcmp( who.instance, "" ) ) { fullName = malloc( sizeof(char)*( strlen( who.principal ) + strlen( who.instance ) + 2 ) ); if( !fullName ) { throwAFSException( env, JAFSADMNOMEM ); return 0; } *fullName = '\0'; strcat( fullName, who.principal ); strcat( fullName, "." ); strcat( fullName, who.instance ); juser = (*env)->NewStringUTF(env, fullName ); } else { juser = (*env)->NewStringUTF(env, who.principal); } if( userCls == 0 ) { internal_getUserClass( env, juserObject ); } (*env)->SetObjectField(env, juserObject, user_nameField, juser); if( fullName != NULL ) { getUserInfoChar( env, (void *) cellHandle, fullName, juserObject ); free( fullName ); } else { getUserInfoChar( env, (void *) cellHandle, who.principal, juserObject ); } (*env)->SetBooleanField( env, juserObject, user_cachedInfoField, TRUE ); return 1; }
/** * Returns the next kas user of the cell. Returns null if there * are no more users. Appends instance names to principal names as follows: * principal.instance * * env the Java environment * cls the current Java class * iterationId the iteration ID of this iteration * returns the name of the next user of the cell */ JNIEXPORT jstring JNICALL Java_org_openafs_jafs_Cell_getKasUsersNextString (JNIEnv *env, jclass cls, jlong iterationId) { afs_status_t ast; kas_identity_t who; jstring juser; if( !kas_PrincipalGetNext( (void *) iterationId, &who, &ast ) ) { if( ast == ADMITERATORDONE ) { return NULL; // other } else { throwAFSException( env, ast ); return; } } if( strcmp( who.instance, "" ) ) { char *fullName = malloc( sizeof(char)*( strlen( who.principal ) + strlen( who.instance ) + 2 ) ); if( !fullName ) { throwAFSException( env, JAFSADMNOMEM ); return; } *fullName = '\0'; strcat( fullName, who.principal ); strcat( fullName, "." ); strcat( fullName, who.instance ); juser = (*env)->NewStringUTF(env, fullName ); free( fullName ); } else { juser = (*env)->NewStringUTF(env, who.principal); } return juser; }
void EnumeratePrincipalsLocally (LPBROWSEDIALOGPARAMS pbdp) { ULONG status; char szCellA[ MAX_PATH ]; CopyStringToAnsi (szCellA, pbdp->szCell); PVOID hCell; if (afsclient_CellOpen (szCellA, (PVOID)pbdp->hCreds, &hCell, (afs_status_p)&status)) { // Enumerate the principals recognized by KAS. // PVOID hEnum; if (kas_PrincipalGetBegin (hCell, NULL, &hEnum, (afs_status_p)&status)) { pbdp->fCanStopThreadEasily = TRUE; while (!pbdp->fShouldStopThread) { kas_identity_t who; if (!kas_PrincipalGetNext (hEnum, &who, (afs_status_p)&status)) break; LPTSTR pszName; if ((pszName = CloneAnsi ((LPSTR)who.principal)) == NULL) break; PostMessage (pbdp->hDlg, WM_FOUNDNAME, 0, (LPARAM)pszName); // pszName freed by DlgProc_Browse when it receives the message } kas_PrincipalGetDone (hEnum, (afs_status_p)&status); } afsclient_CellClose (hCell, (afs_status_p)&status); } }
/** * Returns the total number of KAS users belonging to the cell denoted * by cellHandle. * * env the Java environment * cls the current Java class * cellHandle the handle of the cell to which the users belong * returns total count of KAS users */ JNIEXPORT jint JNICALL Java_org_openafs_jafs_Cell_getKasUserCount (JNIEnv *env, jclass cls, jlong cellHandle) { afs_status_t ast; void *iterationId; kas_identity_t who; int i = 0; if( !kas_PrincipalGetBegin( (void *) cellHandle, NULL, &iterationId, &ast ) ) { throwAFSException( env, ast ); return -1; } while ( kas_PrincipalGetNext( iterationId, &who, &ast ) ) i++; if( ast != ADMITERATORDONE ) { throwAFSException( env, ast ); return -1; } return i; }