int main(int argc, const char *argv[]) { const char* host = "127.0.0.1:2181"; int timeout = 30000; char buffer[512]; int *bufferlen; zoo_set_debug_level(ZOO_LOG_LEVEL_WARN); //设置日志级别,避免出现一些其他信息 zhandle_t* zkhandle = zookeeper_init(host,zktest_watcher_g, timeout, 0, (void *)"hello zookeeper.", 0); if (zkhandle ==NULL) { fprintf(stderr, "Error when connecting to zookeeper servers...\n"); exit(EXIT_FAILURE); } char str[]="/xyz30000000014"; // wexists(zkhandle,str); // printf("---------------\n"); // create(zkhandle,str); get(zkhandle); getChildren(zkhandle,str); getACL(zkhandle,str); while (1) { set(zkhandle, str); sleep(1); } //ddelete(zkhandle,str); }
/*---------------------------------------------------------------------------------------- * Purpose: set the active ACL for the CLients module * Input: commandArgument - A linked list that provides all the parameters the users typed * in. This list is in the same order as they were typed. * clientThreadArguments - A struct providing the basic address information for the * current connection. * commandNode - A pointer to the current node in the command tree structure. * Output: 0 for success or 1 for failure * Note: * Kevin Burnett @ October 26, 2008 * -------------------------------------------------------------------------------------*/ int cmdSetClientListenerAcl(commandArgument * ca, clientThreadArguments * client, commandNode * cn) { AccessControlList * acl = NULL; int type = -1; // figure out what the client-listener type is if(listContainsCommand(cn, "update")) { type = CLIENT_LISTENER_UPDATA; } else if(listContainsCommand(cn, "rib")) { type = CLIENT_LISTENER_RIB; } if(type!=-1) { acl = getACL(ca->commandArgument); if(acl==NULL) { sendMessage(client->socket, "Access Control List [%s] was not found.\n", ca->commandArgument); return 1; } if(type==CLIENT_LISTENER_UPDATA) { LoginSettings.clientUpdateAcl = acl; } else if(type==CLIENT_LISTENER_RIB) { LoginSettings.clientRIBAcl = acl; } } return 0; }
void KrVfsHandler::getACL(vfile *file, QString &acl, QString &defAcl) { Q_UNUSED(file); acl.clear(); defAcl.clear(); #ifdef HAVE_POSIX_ACL QString fileName = vfs::cleanUrl(file->vfile_getUrl()).path(); #ifdef HAVE_NON_POSIX_ACL_EXTENSIONS if (acl_extended_file(fileName)) { #endif acl = getACL(fileName, ACL_TYPE_ACCESS); if (file->vfile_isDir()) defAcl = getACL(fileName, ACL_TYPE_DEFAULT); #ifdef HAVE_NON_POSIX_ACL_EXTENSIONS } #endif #endif }
/*---------------------------------------------------------------------------------------- * Purpose: set the active ACL for the Command Line Interface module * Input: commandArgument - A linked list that provides all the parameters the users typed * in. This list is in the same order as they were typed. * clientThreadArguments - A struct providing the basic address information for the * current connection. * commandNode - A pointer to the current node in the command tree structure. * Output: 0 for success or 1 for failure * Kevin Burnett @ February 5, 2009 * -------------------------------------------------------------------------------------*/ int cmdLoginListenerAcl(commandArgument * ca, clientThreadArguments * client, commandNode * root) { AccessControlList * acl = NULL; acl = getACL(ca->commandArgument); if(acl==NULL) { sendMessage(client->socket, "Access Control List [%s] was not found.\n", ca->commandArgument); return 1; } LoginSettings.cliAcl= acl; return 0; }
/** * 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); }
/*-------------------------------------------------------------------------------------- * Purpose: Read the login control settings from the config file. * Input: none * Output: returns 0 on success, 1 on failure * Kevin Burnett @ November 18, 2008 * -------------------------------------------------------------------------------------*/ int readLoginControlSettings() { int err = 0; int result = 0; int num = 0; char * addr = NULL; char * temp = NULL; // get listen addr and port only if we are not in recovery mode if(!LoginSettings.recoveryMode){ result = getConfigValueAsAddr(&addr, XML_LOGIN_ADDRESS_PATH, ADDR_PASSIVE); if (result == CONFIG_VALID_ENTRY){ result = checkAddress(addr, ADDR_PASSIVE); if(result != ADDR_VALID){ err = 1; log_warning("Invalid configuration of login listen address."); } else { strncpy(LoginSettings.listenAddr, addr, ADDR_MAX_CHARS); } free(addr); }else if ( result == CONFIG_INVALID_ENTRY ){ err = 1; log_warning("Invalid configuration of login listen address."); }else{ log_msg("No configuration of login listen address, using default."); } #ifdef DEBUG debug(__FUNCTION__, "Login Control Addr:%s", LoginSettings.listenAddr); #endif // get listen port result = getConfigValueAsInt(&num, XML_LOGIN_PORT_PATH, 1, 65536); if (result == CONFIG_VALID_ENTRY) { LoginSettings.listenPort = num; }else if( result == CONFIG_INVALID_ENTRY ){ err = 1; log_warning("Invalid configuration of login listen port."); } else{ log_msg("No configuration of login listen port, using default."); } #ifdef DEBUG debug(__FUNCTION__, "Login listen port set to %d", LoginSettings.listenPort); #endif } // get ACCESS_PASSWORD value if(getConfigValueAsString(&temp, XML_LOGIN_ACCESS_PASSWORD_PATH, PASSWORD_MAX_CHARS )) { log_warning("Invalid configuration of Login access password, default value used."); } else { memcpy(LoginSettings.accessPassword, temp, strlen(temp) + 1); free(temp); } // get ENABLE_PASSWORD value if(getConfigValueAsString(&temp, XML_LOGIN_ENABLE_PASSWORD_PATH, PASSWORD_MAX_CHARS)) { log_warning("Invalid configuration of Login enable password, default value used."); } else { memcpy(LoginSettings.enablePassword, temp, strlen(temp) + 1); free(temp); } // get the cli ACL AccessControlList * acl = NULL; #ifdef DEBUG char * aclName = NULL; #endif result = getConfigValueAsString(&temp, XML_LOGIN_CLI_ACL_PATH, PASSWORD_MAX_CHARS); if(result==0) { acl = getACL(temp); if(acl!=NULL) { LoginSettings.cliAcl = acl; #ifdef DEBUG aclName = acl->name; #endif } free(temp); } #ifdef DEBUG debug(__FUNCTION__, "Command Line Interface Access Control List set to [%s]", aclName); #endif // get the client update ACL acl = NULL; #ifdef DEBUG aclName = NULL; #endif result = getConfigValueAsString(&temp, XML_LOGIN_CLIENT_UPDATE_ACL_PATH, PASSWORD_MAX_CHARS); if(result==0) { acl = getACL(temp); if(acl!=NULL) { LoginSettings.clientUpdateAcl = acl; #ifdef DEBUG aclName = acl->name; #endif } free(temp); } #ifdef DEBUG debug(__FUNCTION__, "Client Update's Access Control List set to [%s]", aclName); #endif // get the client rib ACL acl = NULL; #ifdef DEBUG aclName = NULL; #endif result = getConfigValueAsString(&temp, XML_LOGIN_CLIENT_RIB_ACL_PATH, PASSWORD_MAX_CHARS); if(result==0) { acl = getACL(temp); if(acl!=NULL) { LoginSettings.clientRIBAcl = acl; #ifdef DEBUG aclName = acl->name; #endif } free(temp); } #ifdef DEBUG debug(__FUNCTION__, "Client RIB's Access Control List set to [%s]", aclName); #endif // get the mrt ACL acl = NULL; #ifdef DEBUG aclName = NULL; #endif result = getConfigValueAsString(&temp, XML_LOGIN_MRT_ACL_PATH, PASSWORD_MAX_CHARS); if(result==0) { acl = getACL(temp); if(acl!=NULL) { LoginSettings.mrtAcl = acl; #ifdef DEBUG aclName = acl->name; #endif } free(temp); } #ifdef DEBUG debug(__FUNCTION__, "Mrt's Access Control List set to [%s]", aclName); #endif return err; }