extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalByRefStruct_Stdcall_OUTER3(ByRefStdcallCaller_OUTER3 caller) { //init OUTER3 outer3; LPSTR str = NULL; for( size_t i = 0; i < NumArrElements; i++ ) { outer3.arr[i].f1 = 77; outer3.arr[i].f2 = 77.0; str = GetNativeString(); outer3.arr[i].f3 = (LPCSTR)str; str = NULL; } str = GetNativeString(); outer3.f4 = (LPCSTR)str; if(!caller(&outer3)) { PRINT_ERR_INFO(); return FALSE; } if( !IsCorrectOUTER3( &outer3 ) ) { PRINT_ERR_INFO(); return FALSE; } return TRUE; }
extern "C" DLL_EXPORT BOOL _cdecl DoCallBack_MarshalByRefStruct_Cdecl_INNER2(ByRefCdeclCaller_INNER2 caller) { //init INNER2 inner2; inner2.f1 = 77; inner2.f2 = 77.0; char* pstr = GetNativeString(); inner2.f3 = pstr; if(!caller(&inner2)) { PRINT_ERR_INFO(); return FALSE; } if(!IsCorrectINNER2(&inner2)) { PRINT_ERR_INFO(); return FALSE; } //TP_CoreClrFree((void*)inner2.f3); return TRUE; }
extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalByRefStruct_Stdcall_InnerArrayExplicit(ByRefStdcallCaller_InnerArrayExplicit caller) { //init InnerArrayExplicit iae; LPSTR str = NULL; for( size_t i = 0; i < NumArrElements; i++ ) { iae.arr[i].f1 = 77; str = GetNativeString(); iae.arr[i].f3 = str; str = NULL; } str = GetNativeString(); iae.f4 = str; if(!caller(&iae)) { PRINT_ERR_INFO(); return FALSE; } for( size_t i = 0; i < NumArrElements; i++ ) { if( iae.arr[i].f1 != 1 || 0 != strcmp((char*)iae.arr[i].f3, "some string")) { PRINT_ERR_INFO(); return FALSE; } } if( 0 != strcmp((char*)iae.f4, "some string") ) { PRINT_ERR_INFO(); return FALSE; } return TRUE; }
extern "C" DLL_EXPORT BOOL __stdcall DoCallBack_MarshalByValStruct_Stdcall_InnerExplicit(ByValStdcallCaller_InnerExplicit caller) { //init InnerExplicit ie; ie.f1 = 1; char* pstr = GetNativeString(); ie.f3 = pstr; if(!caller(ie)) { PRINT_ERR_INFO(); return FALSE; } if( ie.f1 != 1 || 0 != strcmp((char*)ie.f3, (char*)NativeStr) ) { PRINT_ERR_INFO(); return FALSE; } return TRUE; }
/** * Returns a formatted string representing the ACL for the specified path. * * path the directory path * returns NULL if an exception is encountered. */ char* getACL(char *path) { struct ViceIoctl params; char *buffer; int rval1=0; buffer = (char*) malloc(ACL_LEN); params.in = NULL; params.out = NULL; params.in_size = params.out_size = 0; if (!buffer) { fprintf(stderr, "ERROR: ACL::getACL -> could not allocate buffer\n"); return NULL; } params.out = buffer; params.out_size = ACL_LEN; #if defined(AFS_PPC64_LINUX20_ENV) || defined(AFS_S390X_LINUX20_ENV) if(pioctl(path, VIOCGETAL, ¶ms, 1)) { #else /* AFS_PPC_LINUX20_ENV */ if(syscall(AFS_SYSCALL, AFSCALL_PIOCTL, path, VIOCGETAL, ¶ms, 1)) { #endif /* AFS_PPC_LINUX20_ENV */ fprintf(stderr, "ERROR: ACL::getACL -> VIOCGETAL failed: %d, path: %s\n", errno, path); free(buffer); return NULL; } return params.out; } /** * Sets the ACL for the specified path using the provided string * representation. * * path the directory path * aclString string representation of ACL to be set * returns TRUE if the operation succeeds; otherwise FALSE; */ jboolean setACL(char *path, char *aclString) { struct ViceIoctl params; char *redirect, *parentURI, *cptr; params.in = aclString; params.in_size = strlen(aclString) + 1; params.out = NULL; params.out_size = 0; #if defined(AFS_PPC64_LINUX20_ENV) || defined(AFS_S390X_LINUX20_ENV) if(pioctl(path, VIOCSETAL, ¶ms, 1)) { #else /* AFS_PPC_LINUX20_ENV */ if(syscall(AFS_SYSCALL, AFSCALL_PIOCTL, path, VIOCSETAL, ¶ms, 1)) { #endif /* AFS_PPC_LINUX20_ENV */ fprintf(stderr, "ERROR: ACL::setACL -> VIOCSETAL failed: %d, path: %s\n", errno, path); return JNI_FALSE; } return JNI_TRUE; } /** * Returns a formatted string representing the ACL for the specified path. * * The string format is in the form of a ViceIoctl and is as follows: * printf("%d\n%d\n", positiveEntriesCount, negativeEntriesCount); * printf("%s\t%d\n", userOrGroupName, rightsMask); * * path the directory path * returns NULL if an exception is encountered. */ JNIEXPORT jstring JNICALL Java_org_openafs_jafs_ACL_getACLString (JNIEnv *env, jobject obj, jstring pathUTF) { char *path, *acl; jstring answer = NULL; /*jchar* wpath; path = (char*) (*env)->GetStringUTFChars(env, pathUTF, 0); wpath=(jchar*) (*env)->GetStringChars(env,pathUTF,0);*/ path = GetNativeString(env,pathUTF); if(path == NULL) { fprintf(stderr, "ERROR: ACL::getACLString ->"); fprintf(stderr, "path = NULL\n"); throwMessageException( env, "Path is NULL" ); return NULL; } acl = getACL(path); if(acl) { answer = (*env) -> NewStringUTF(env, acl); free(acl); } else { throwAFSException( env, errno ); } /*(*env)->ReleaseStringUTFChars(env, pathUTF, path); (*env)->ReleaseStringChars(env, pathUTF, (jchar*)wpath);*/ free(path); //psomogyi memory leak - added return answer; } /** * Sets the ACL for the specified path using the provided string * representation. * * The string format is in the form of a ViceIoctl and is as follows: * printf("%d\n%d\n", positiveEntriesCount, negativeEntriesCount); * printf("%s\t%d\n", userOrGroupName, rightsMask); * * path the directory path * aclString string representation of ACL to be set * throws an afsAdminExceptionName if an internal exception is encountered. */ JNIEXPORT void JNICALL Java_org_openafs_jafs_ACL_setACLString (JNIEnv *env, jobject obj, jstring pathUTF, jstring aclStringUTF) { char *path, *aclString; if(!pathUTF) { fprintf(stderr, "ERROR: ACL::setACLString -> pathUTF == NULL\n"); throwMessageException( env, "pathUTF == NULL" ); return; } /*path = (char*) (*env)->GetStringUTFChars(env, pathUTF, 0);*/ path = GetNativeString(env,pathUTF); if(path == NULL) { fprintf(stderr, "ERROR: ACL::setACLString -> failed to get path\n"); throwMessageException( env, "Failed to get path" ); return; } if(!aclStringUTF) { fprintf(stderr, "ERROR: ACL::setACLString -> aclStringUTF == NULL\n"); throwMessageException( env, "aclStringUTF == NULL" ); return; } /*aclString = (char*) (*env)->GetStringUTFChars(env, aclStringUTF, 0);*/ aclString = GetNativeString(env,aclStringUTF); if(aclString == NULL) { fprintf(stderr, "ERROR: ACL::setACLString -> failed to get aclString\n"); (*env)->ReleaseStringUTFChars(env, pathUTF, path); throwMessageException( env, "aclString == NULL" ); return; } if (!setACL(path, aclString)) { throwAFSException( env, errno ); } /*(*env)->ReleaseStringUTFChars(env, pathUTF, path); (*env)->ReleaseStringUTFChars(env, aclStringUTF, aclString);*/ free(path); free(aclString); }