void uploadACL(Connection *Conn,PCStr(user),FILE *tc,FILE *oldacl,FILE *newacl,PCStr(aclID),PCStr(mbox),PCStr(durl),void *env,sFUNCP ckfunc) { int errors; int osize; CStr(line,1024); fprintf(tc,"<PLAINTEXT>\r\n"); fprintf(tc,"UPLOAD/UPDATE/REMOVE Gateway Access Control List (GACL)\r\n"); fprintf(tc,"Source GACL URL: <%s>\r\n",durl); fprintf(tc,"\r\n--DIAGNOSIS--\r\n"); osize = file_size(fileno(oldacl)); if( 0 < osize ){ while( fgets(line,sizeof(line),oldacl) != 0 ){ /* skip HTTP header */ if( line[0] == '#' || line[0] == '\r' || line[0] == '\n' ) break; } setACL(Conn,0,aclID,user,durl,oldacl,tc,env,ckfunc); fseek(oldacl,0,0); } if( file_size(fileno(newacl)) <= 0 ){ if( 0 < osize ) fprintf(tc,"Your ACL is removed\r\n"); }else{ errors = setACL(Conn,1,aclID,user,durl,newacl,tc,env,ckfunc); if( errors == 0 ) fprintf(tc,"NO ERROR\r\n"); fseek(newacl,0,0); fprintf(tc,"\r\n--SOURCE--\r\n"); copyfile1(newacl,tc); } if( 0 < osize ){ fprintf(tc,"\r\n--PREVIOUS--\r\n"); copyfile1(oldacl,tc); fseek(oldacl,0,0); } fprintf(tc,"\r\n--END--\r\n"); }
/** * 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); }