int handle_file_list(WFM2_FILE_LIST_PARAM *aListParam, WFM2_FILE_OBJECT *aFileObj) { char *full_path=NULL; int exist, i; int g_access=SHARE_NOACCESS, nPermission=0, is_iso=0; char *delim="/", *node_tmp=NULL; int nShareCount=0, nTotalShare=0; //SECTION_INFO *shareList=NULL; char *node1=NULL, *iso=NULL; int nLen=0, nLen1=0; // check iso section node1 = strstr(&aListParam->node[1], "/"); nLen = strlen(aListParam->node); if(node1 != NULL) { nLen1 = strlen(node1); iso = __ax_calloc(1, (nLen - nLen1 + 1)); strncpy(iso, &aListParam->node[1], (nLen - nLen1)); } else { iso = __ax_calloc(1, (nLen + 1)); strncpy(iso, &aListParam->node[1], nLen); } is_iso = 0; /* nShareCount = Get_NAS_Share_List_V2_ISO(&shareList, 0, 0, NULL, ISO_FILTER_ONLY, &nTotalShare); for(i=0; i<nTotalShare; i++){ if (!strcasecmp(iso, shareList[i].section_name)) { is_iso = 1; break; } } if(shareList != NULL) Release_List(shareList); */ if(iso) __ax_free(iso); /*The first request node is "/", but we do not display folder in "/", so * give null share json*/ if (!strcmp(aListParam->node, "/")) { File_List_To_JSON(NULL, 0, 0, 0, 0); return -1; } /* node_tmp = __ax_strdup(aListParam->node); g_access = Get_NAS_User_Security_For_Share_Ex(aListParam->remoteUser, strtok(node_tmp, delim)); #ifdef STORAGE_V2 if(g_access == SHARE_NOACCESS && aListParam->no_check == 0) #else if(g_access == SHARE_NOACCESS) #endif { Status_To_JSON(WFM2_PERMISSION_DENY); if(node_tmp) __ax_free(node_tmp); return -1; } if(node_tmp) __ax_free(node_tmp); */ //nEnd = nStart + nLimit - 1; aListParam->end = aListParam->start + aListParam->limit - 1; full_path = (char *)__ax_malloc(strlen(aListParam->node) + MAX_FILE_LENGTH + PATH_PREFIX_LENGTH + 256); exist = check_exist(aListParam->node, full_path); if(exist < 0) { #ifdef STORAGE_V2 if(aListParam->no_check == 0) #endif #ifdef LIBRSYNC if(aListParam->view_versioning == 0) #endif { Status_To_JSON(WFM2_FILE_NO_EXIST); if(full_path) __ax_free(full_path); return -1; } } #ifdef ACL //if not iso folder, check permission //the external disk and non-ext3 or non-ext4 vdd are not //supported for ACL //so do not check the acl permission if(Is_ACL_Enabled() && No_Support_ACL(aListParam->node) == 0) { #ifdef LIBRSYNC if(aListParam->view_versioning == 0) #endif if(!is_iso) { aListParam->permission = Get_ACL_User_Group_Security_For_Share(aListParam->remoteUser, full_path); if(aListParam->permission < 5) { Status_To_JSON(WFM2_PERMISSION_DENY); if (full_path) __ax_free(full_path); return -1; } } } else nPermission = g_access; #endif // ACL for (i=0; i<sizeof(sort_func)/sizeof(SORT_FUNC); i++) { if (!strcmp(sort_func[i].sort_mode, aListParam->sort)) { aListParam->sortmode = i; break; } } #ifdef STORAGE_V2 if (aListParam->no_check) { if(access(aListParam->node, 0) < 0) { Status_To_JSON(WFM2_FILE_NO_EXIST); if (full_path) __ax_free(full_path); return -1; } else { _get_file_list(aListParam->node, aListParam, aFileObj); } } else _get_file_list(full_path, aListParam, aFileObj); #else _get_file_list(full_path, aListParam, aFileObj); #endif if(full_path) __ax_free(full_path); return 0; }
int op_search(INPUT *input) { int ret = 0; INPUT *keyword = NULL, *start = NULL, *limit = NULL; INPUT *source = NULL, *tmp = NULL, *time = NULL; char *full_path = NULL, *source_tmp = NULL, *sort_type = "ASC"; int exist = 0, end = 0, sort_mode = 0, permission = NO, is_iso = 0; //only for internal use ret = special_search(input); if (ret == 0) return 0; source = CGI_Find_Parameter(input, "source_path"); if (source == NULL) return -1; if(!Check_Illegal_Path(source->val)) { Status_To_JSON(WFM2_ILLEGAL_NAME); return -1; } time = CGI_Find_Parameter(input, "time"); if (time != NULL) { char *ptr = NULL, tmp[12]; struct tm *p; time_t timep; struct stat buf; struct passwd *user; struct group *data; int i; JSON_FILE_OBJECT *file; ptr = time->val; strncpy(tmp, ptr, 4); tmp[4] = 0x0; p = (struct tm *)__ax_malloc(sizeof(struct tm)); p->tm_year = atoi(tmp) - 1900; ptr = ptr + 4; strncpy(tmp, ptr, 2); tmp[2] = 0x0; p->tm_mon = atoi(tmp) - 1; ptr = ptr + 2; strncpy(tmp, ptr, 2); tmp[2] = 0x0; p->tm_mday = atoi(tmp); p->tm_hour = 0; p->tm_min = 0; p->tm_sec = 0; timep = mktime(p); if (p) __ax_free(p); full_path = (char *)__ax_malloc(strlen(source->val) + MAX_FILE_LENGTH + 15); exist = check_exist(source->val, full_path); if (exist < 0) { Status_To_JSON(WFM2_FILE_NO_EXIST); if (full_path) __ax_free(full_path); return -1; } _search_by_time(full_path, timep, 0); file = (JSON_FILE_OBJECT *)__ax_malloc( total_file * sizeof(JSON_FILE_OBJECT)); for (i=0;i<total_file;i++) { lstat(file_list[i], &buf); strcpy((file+i)->filename, file_list[i]); (file+i)->isfolder = 0; (file+i)->filesize = (unsigned long long)(buf.st_size); user = getpwuid(buf.st_uid); if (user == NULL) sprintf((file+i)->owner, "%d", buf.st_uid); else strcpy((file+i)->owner, user->pw_name); data = getgrgid(buf.st_gid); if (data == NULL) sprintf((file+i)->group, "%d", buf.st_gid); else strcpy((file+i)->group, data->gr_name); /* { char sDateStr[64]={0}; char sTimeStr[64]={0}; Change_Date_To_String_By_Format(buf.st_mtime, sDateStr, nDate_format); Change_Time_To_String_By_Format(buf.st_mtime, sTimeStr, 0, nTime_format); sprintf((file+i)->mt_str, "%s %s", sDateStr, sTimeStr); } */ sprintf((file+i)->privilege, "%o", (buf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO))); } File_List_To_JSON(file, total_file, total_file, 0, 0); if (full_path) __ax_free(full_path); if (file) __ax_free(file); return 0; } if((tmp = CGI_Find_Parameter(input, "is_iso"))) is_iso = atoi(tmp->val); /* source_tmp = (char *)__ax_malloc(strlen(source->val) + 1); strcpy(source_tmp, source->val); g_access = Get_NAS_User_Security_For_Share_Ex(remote_user, strtok(source_tmp, delim)); if (g_access == SHARE_NOACCESS) { Status_To_JSON(WFM2_PERMISSION_DENY); if(source_tmp) __ax_free(source_tmp); return -1; } */ full_path = (char *)__ax_malloc(strlen(source->val) + MAX_FILE_LENGTH + 15); exist = check_exist(source->val, full_path); if (exist < 0) { Status_To_JSON(WFM2_FILE_NO_EXIST); if (full_path) __ax_free(full_path); return -1; } #ifdef ACL //if not iso folder, check permission if (Is_ACL_Enabled() && No_Support_ACL(source_tmp) == 0) { if (!is_iso) { permission= Get_ACL_User_Group_Security_For_Share(remote_user, full_path); if (permission < 5) { Status_To_JSON(WFM2_PERMISSION_DENY); if (full_path) __ax_free(full_path); return -1; } } } #endif if(source_tmp) __ax_free(source_tmp); keyword = CGI_Find_Parameter(input, "keyword"); if (keyword == NULL) { //CGI_Free_Input(source); if (full_path) __ax_free(full_path); return -1; } start = CGI_Find_Parameter(input, "start"); if (start == NULL) { if (full_path) __ax_free(full_path); return -1; } limit = CGI_Find_Parameter(input, "limit"); if (limit == NULL) { if (full_path) __ax_free(full_path); return -1; } _search(full_path, keyword); /* if (keyword!=NULL) CGI_Free_Input(keyword); if (source!=NULL) CGI_Free_Input(source); */ int i; end = atoi(start->val) + atoi(limit->val) - 1; if ((tmp = CGI_Find_Parameter(input, "sort"))) { for (i=0; i<sizeof(sort_func)/sizeof(SORT_FUNC); i++) { if (!strcmp(sort_func[i].sort_mode, tmp->val)) { sort_mode = i; break; } } } if ((tmp = CGI_Find_Parameter(input, "dir"))) sort_type = tmp->val; output_search_to_json(atoi(start->val), end, sort_mode, sort_type, permission); if (full_path) __ax_free(full_path); if (file_list) __ax_free(file_list); file_list = NULL; if(folder_list) __ax_free(folder_list); folder_list = NULL; total_match = 0; total_search = 0; total_file = 0; total_folder = 0; return ret; }