int user_transations() { USER usr; memset(&usr,0,USR_LEN); int i=user_temp_p.userid; int is_exist; int is_match; //user结构体status最初被初始化为0,只有上线以后才会变为1 //所以首先检查status的状态 //如果为0,且用户名存在,则表示用户名密码错 //如果为0,且用户名不存在,则表示用户要注册 //如果为1,则表示用户想改密码 if(user_temp_p.status==0) { is_exist=check_exist(); if(is_exist==0) registration(); else login(); } else { c_lseek(user_list_fd,i*USR_LEN,SEEK_SET); c_read(user_list_fd,&usr,USR_LEN); memset(usr.password,0,15); strncpy(usr.password,user_temp_p.password,strlen(user_temp_p.password)); c_lseek(user_list_fd,i*USR_LEN,SEEK_SET); c_write(user_list_fd,&usr,USR_LEN); //modify password; } }
int check_file(const char *filename, int expected_count) { std::ifstream f(filename); int res = 0; int count = 0; int found = 0; char what[1000]; while( f.getline(what,1000) ) { ++count; if (what[0]=='#') continue; int lres = check_exist(what); if (lres) { fprintf(stderr,"Failed on count == %d in %s\n",count,filename); res = lres; } ++found; } if (found != expected_count) { fprintf(stderr,"Found only %d typedefs (expected %d)\n",found, expected_count); if (!res) res = 4; } f.close(); return res; }
// search for QQWry.Dat // first, look for ./QQWry.Dat // then look for /var/lib/QQWry.Dat // then look for $EXEPATH/QQWry.Dat std::string search_qqwrydat(const std::string exepath) { if (check_exist("QQWry.Dat")) { return "QQWry.Dat"; } if (check_exist("/var/lib/QQWry.Dat")) { return "/var/lib/QQWry.Dat"; } // 找 exe 的位置 if (check_exist(exepath + "QQWry.Dat")) { return exepath + "QQWry.Dat"; } // throw std::runtime_error("QQWry.Dat database not found"); std::cout << "qqwry.dat 文件没找到,下载中......" << std::endl; // 解压 std::string deflated = QQWry::decodeQQWryDat( // 下载 copywrite.rar internetDownloadFile(CAODAN("http://update.cz88.net/ip/copywrite.rar")), // 下载 qqwry.rar internetDownloadFile(CAODAN("http://update.cz88.net/ip/qqwry.rar")), // 传入 解压函数 uncompress ); // 解压 qqwry.rar 为 qqwry.dat std::ofstream ofile("QQWry.Dat", std::ios::binary); ofile.write((const char*) deflated.data(), deflated.size()); ofile.close(); if (check_exist("QQWry.Dat")) return "QQWry.Dat"; throw std::runtime_error("not found"); }
static int gen_result(char *pserial, char *pstimeout_min) { char resfile[100]; int pid; int timeout; gen_resfile(pserial, resfile); status = 0; signal(SIGUSR1, worker_handler); timeout = atoi(pstimeout_min); pid = fork(); if(pid == -1) { printf("fork error\n"); return -1; } else if (pid != 0) /* father */ return 0; /* check if exists */ if( check_exist() != 0 ) { printf(" process allready exists \n"); return 0; } gen_worker_pid(); /* become daemon */ if( setsid() == -1) { printf(" setsid error, [%d], [%s]\n", errno, strerror(errno)); return -1; } while(1) { if(status == 1) break; gen_one_record(resfile); sleep(timeout); } get_pid_byfile(&pid); /* send signal SIGUSR2 to Pid */ sleep(3); kill(pid, SIGUSR2); log("worker send SIGUSR2 to [%d]", pid); log("worker process end"); return 0; }
bool instantiateTable(UPDATEQUERYPARSE *& query, string lexeme, vector<vector<string> >& tables) { if(check_exist(lexeme.c_str())) { query->tablename = lexeme; tables.push_back(vector<string>()); tables.back().push_back(lexeme); return true; } cout << "semantic error: table '" << lexeme << "' does not exist" << endl; return false; }
int op_get_chunked_upload_id(INPUT *input) { INPUT *tmp; char id[32] = "---"; int euid, egid, ret = 0; int exist; char *full_path, path[1024]; char lastpath[1024] = "", *filename = NULL; int length = 0; int fd = -1; if( (tmp = CGI_Find_Parameter(input, "upload_root_dir")) ) { snprintf(path, sizeof(path), "%s/%s", tmp->val, UPLOAD_CACHE_DIR); } full_path = (char *)__ax_calloc(1, strlen(path) + MAX_FILE_LENGTH + 15); exist = check_exist(path, full_path); if (exist < 0) { if(mkdir(full_path, S_IRUSR | S_IWUSR | S_IXUSR |S_IRGRP | S_IWGRP | S_IXGRP |S_IROTH | S_IWOTH | S_IXOTH)< 0){ ret = WFM2_OPEN_FILE_FAIL; goto end; } chmod(full_path, S_IRUSR | S_IWUSR | S_IXUSR |S_IRGRP | S_IWGRP | S_IXGRP |S_IROTH | S_IWOTH | S_IXOTH); } // Create unique file strcpy(lastpath, full_path); strcat(lastpath, "/"); length = strlen(lastpath); strcat(lastpath, "XXXXXXX"); mktemp(lastpath); fd = open(lastpath, O_CREAT | O_RDWR); if (fd == -1) { ret = WFM2_OPEN_FILE_FAIL; goto end; } filename = __ax_strndup(lastpath + length, 7); end: printf("{\"status\": %d, \"upload_id\":\"%s\"}\n", ret, filename); if (filename) __ax_free(filename); if (fd != -1) close(fd); if (full_path) __ax_free(full_path); return 0; }
int op_get_chunked_upload_status(INPUT *input) { INPUT *tmp = NULL; int ret = 0, exist = 0, count = 0; char *upload_id = NULL, *full_path = NULL, size_str[64] = "0", size_str2[64] = "0", *upload_dir = NULL; struct stat statbuf; unsigned long long size = 0, total_len = 0; char id[32] = "---"; //char buf[BLK_SIZE], md5_str[128] = "---"; char buf[BLK_SIZE], md5_str[128] = {0}; if( (tmp=CGI_Find_Parameter(input, "upload_id")) ) { upload_id = tmp->val; } if( (tmp=CGI_Find_Parameter(input, "upload_root_dir")) ) { char uppath[1024]; snprintf(uppath, sizeof(uppath), "%s/%s", tmp->val, UPLOAD_CACHE_DIR); upload_dir = (char *)calloc(1, strlen(uppath) + MAX_FILE_LENGTH + 15); exist = check_exist(uppath, upload_dir); if (exist < 0) { ret = WFM2_FILE_NO_EXIST; goto end; } full_path = (char *)calloc(1, strlen(upload_dir) + strlen(upload_id) + 2); sprintf(full_path, "%s/%s", upload_dir, upload_id); } if(!stat(full_path, &statbuf)){ if(S_ISDIR(statbuf.st_mode)){ ret = WFM2_FILE_NO_EXIST; }else{ size = statbuf.st_size; sprintf(size_str, "%lld", statbuf.st_size); } }else ret = WFM2_FILE_NO_EXIST; end: if(full_path) free(full_path); if(upload_dir) free(upload_dir); Status_With_Size_And_MD5_To_JSON(ret, size_str, md5_str, size_str2); return ret; }
int op_delete_chunked_upload_file(INPUT *input) { INPUT *tmp = NULL; int ret = 0, exist = 0; char *upload_id = NULL, *full_path = NULL, *upload_dir = NULL; struct stat statbuf; if( (tmp=CGI_Find_Parameter(input, "upload_id")) ) { upload_id = tmp->val; } if( (tmp=CGI_Find_Parameter(input, "upload_root_dir")) ) { char uppath[1024]; snprintf(uppath, sizeof(uppath), "%s/%s", tmp->val, UPLOAD_CACHE_DIR); upload_dir = (char *)calloc(1, strlen(uppath) + MAX_FILE_LENGTH + 15); exist = check_exist(uppath, upload_dir); if (exist < 0) { ret = WFM2_FILE_NO_EXIST; goto end; } full_path = (char *)calloc(1, strlen(upload_dir) + strlen(upload_id) + 2); sprintf(full_path, "%s/%s", upload_dir, upload_id); } if(!stat(full_path, &statbuf)){ if(S_ISDIR(statbuf.st_mode)) ret = WFM2_OPEN_FILE_FAIL; else #ifdef RECYCLE_EX qnap_unlink(full_path); #else unlink(full_path); #endif }else ret = WFM2_FILE_NO_EXIST; end: if(full_path) free(full_path); if(upload_dir) free(upload_dir); Status_To_JSON(ret); return ret; }
/////////////////////////////////////////////////////////// // Writing function // This function is used to write data into the cache from the memory // If Write back technique is used, the dirty data should be stored in memory as // well. ///////////////////////////////////////////////////////// int RPU::write_data(uint32_t addr,uint32_t data,int loc) { int32_t index_val=address->get_index(addr); uint32_t tag_val=address->get_tag(addr); uint32_t off_val=(address->get_offset(addr))>>2; //int loc; int loc1; if(Ch_assoc_num==0) //Direct { // if((addr&0x0000000F)==0x0) // printf("RPU - MISS\taddr 0x%08X\tindex 0x%03X\n", addr, index_val); storing->write_tag(index_val,tag_val); storing->write_cache(index_val,data,off_val); } else if(Ch_assoc_num==1)//full { //There is a function to get where to place the data //loc=where_to(); if(Ch_replace_type==1) Ch_info[0][loc]=Ch_next_ip++; else if(Ch_replace_type==2) Ch_info[0][loc]=0; //cout<<"Address= "<<addr<<"Data= "<<data<<" Location="<<loc<<endl; storing->write_tag(loc,tag_val); storing->write_cache(tag_val,data,off_val); } else //set associative { loc1=check_exist(addr); if(loc1==-1) loc1=loc; if(Ch_replace_type==1) Ch_info[loc1][index_val]=Ch_next_ip++; else if(Ch_replace_type==2) { for(unsigned int l=0;l<Ch_assoc_num;l++) Ch_info[l][index_val]++; Ch_info[loc1][index_val]=0; } storing->write_tag(index_val,tag_val,loc1); storing->write_cache(index_val,data,off_val,loc1); } return 0; //FIXME dummy value to avoid compiler warnings }
///////////////////////////////////////////////// // The updating function // This function is used along with check function // If a word is requested to be written in the cache from // L1 cache or the processor, and exists in L2 chache. int RPU::update_data(uint32_t addr,uint32_t data) { uint32_t index_val=address->get_index(addr); uint32_t tag_val=address->get_tag(addr); uint32_t off_val=(address->get_offset(addr))>>2; if(Ch_assoc_num==0)//Direct { storing->write_cache(index_val,data,off_val); storing->set_dirty(index_val,1); dirty_locations[0][index_val]=addr; } else if(Ch_assoc_num==1) { if(Ch_replace_type==2)//LRU { for(unsigned int k=0;k<Ch_size/(Ch_line);k++) Ch_info[0][k]++; Ch_info[0][storing->return_index(tag_val)]=0; } storing->write_cache(tag_val,data,off_val); storing->set_dirty(tag_val,1); dirty_locations[0][storing->return_index(tag_val)]=addr; } else { int temp=check_exist(addr); //cout<<"Address "<<hex<<addr<<" Found in "<<temp<<" offset Val is "<<off_val<<endl; if(Ch_replace_type==2) { for(unsigned int l=0;l<Ch_assoc_num;l++) Ch_info[l][index_val]++; Ch_info[temp][index_val]=0; } storing->write_cache(index_val,data,off_val,temp); storing->set_dirty(index_val,data,temp); dirty_locations[temp][index_val]=addr; } return 0; //FIXME dummy value to avoid compiler warnings }
int _get_tree(char *inode, int is_iso) { struct dirent **namelist; int i, total = 0; char *path = NULL; int exist, permission = 0; char (*share)[MAX_FILE_LENGTH], *inode_tmp; char *delim = "/", (*property)[8] = NULL, (*type)[16] = NULL; int g_access=SHARE_NOACCESS; WFM_SECTION_OBJECT *secList=NULL; path = (char *)__ax_malloc(strlen(inode) + SHARE_PATH_LENGTH + 15); exist = check_exist(inode, path); if(exist < 0){ Status_To_JSON(WFM2_FILE_NO_EXIST); if (path) __ax_free(path); return -1; } //for fselect to tell which one is folder or file tmp_path = (char *)__ax_malloc(strlen(path) + 1); strncpy(tmp_path, path, strlen(path)); tmp_path[strlen(path)] = 0x0; total = scandir(path, &namelist, fselect, alphasort); if(total < 0){ perror("scandir"); if (path) __ax_free(path); if (tmp_path) __ax_free(tmp_path); return -1; } else { char *full_path = NULL; share = (char (*)[MAX_FILE_LENGTH]) __ax_malloc(total * MAX_FILE_LENGTH * sizeof(char)); type = (char (*)[16])__ax_malloc(total * 16 * sizeof(char)); #ifdef ACL property = (char (*)[8])__ax_malloc(total * 8 * sizeof(char)); #endif for(i=0; i<total; i++) { int mode = 0; strcpy(share[i], namelist[i]->d_name); strcpy(type[i], "folder"); #ifdef ACL full_path = (char *)__ax_malloc(strlen(path) + strlen(namelist[i]->d_name) + 2); sprintf(full_path, "%s/%s", path, namelist[i]->d_name); if (Is_ACL_Enabled()) { mode = Get_ACL_User_Group_Security_For_Share(remote_user, full_path); sprintf(property[i], "%d", mode); } else { sprintf(property[i], "%d", 7); } if (full_path) __ax_free(full_path); #endif } // for natural sorting secList = __ax_calloc(total, sizeof(WFM_SECTION_OBJECT)); for(i=0; i<total; i++) { strncpy((secList+i)->share, share[i], strlen(share[i])); if(split_sort_filename(share[i], &(secList+i)->split_name) < 0) { int j; for(j=0; j<(i+1); j++) { free_wfm2_split_data((secList+j)->split_name.data); } if(secList != NULL) __ax_free(secList); if(share) __ax_free(share); return -1; } } if(strcmp(gSort_type, "DESC")) sorting_by_natural_tree("ASC", total, secList); else sorting_by_natural_tree("DESC", total, secList); for(i=0; i<total; i++) { memset(share[i], 0, sizeof(share[i])); strncpy(share[i], (secList+i)->share, strlen((secList+i)->share)); } Share_List_To_JSON(inode, share, total, 1, property, type); } // __ax_free for(i=0; i<total; i++) { free_wfm2_split_data((secList+i)->split_name.data); } if(secList != NULL) __ax_free(secList); // end natural sorting if (path) __ax_free(path); if (share) __ax_free(share); if (tmp_path) __ax_free(tmp_path); if (type) __ax_free(type); return -1; }
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_get_file_list(INPUT *input) { INPUT *tmp; WFM2_FILE_LIST_PARAM sFileListParam; char *full_path = NULL; int nRet=0; memset(&sFileListParam, 0, sizeof(WFM2_FILE_LIST_PARAM)); if((tmp = CGI_Find_Parameter(input, "path"))) { full_path = (char *)__ax_malloc(strlen(tmp->val) + MAX_FILE_LENGTH + PATH_PREFIX_LENGTH + 256); int exist = check_exist(tmp->val, full_path); if (exist < 0) { Status_To_JSON(WFM2_FILE_NO_EXIST); if(full_path) __ax_free(full_path); return -1; } sFileListParam.node = __ax_strdup(tmp->val); } if((tmp = CGI_Find_Parameter(input, "list_mode"))) { strncpy(sFileListParam.listMode, tmp->val, WFM2_LIST_MODE_LEN); } if((tmp = CGI_Find_Parameter(input, "start"))) { sFileListParam.start = atoi(tmp->val); } else { sFileListParam.start = 0; } if((tmp = CGI_Find_Parameter(input, "limit"))) { sFileListParam.limit = atoi(tmp->val); } else { sFileListParam.limit = 0; } if((tmp = CGI_Find_Parameter(input, "is_iso"))) { sFileListParam.is_iso = atoi(tmp->val); } else { sFileListParam.is_iso = 0; } if((tmp = CGI_Find_Parameter(input, "type"))) { // 1:music, 2:video, 3:photo, 4: folder sFileListParam.filetype = atoi(tmp->val); if(sFileListParam.filetype < MUSIC || sFileListParam.filetype > MEDIA) sFileListParam.filetype = 0; } if((tmp = CGI_Find_Parameter(input, "mp4_360"))) { sFileListParam.mp4_360 = atoi(tmp->val); } else { sFileListParam.mp4_360 = 0; } if((tmp = CGI_Find_Parameter(input, "mp4_720"))) { sFileListParam.mp4_720 = atoi(tmp->val); } else { sFileListParam.mp4_720 = 0; } if((tmp = CGI_Find_Parameter(input, "mp4_240"))) { sFileListParam.mp4_240 = atoi(tmp->val); } else { sFileListParam.mp4_240 = 0; } if((tmp = CGI_Find_Parameter(input, "mp4_480"))) { sFileListParam.mp4_480 = atoi(tmp->val); } else { sFileListParam.mp4_480 = 0; } if((tmp = CGI_Find_Parameter(input, "mp4_1080"))) { sFileListParam.mp4_1080 = atoi(tmp->val); } else { sFileListParam.mp4_1080 = 0; } // for special video file if((tmp = CGI_Find_Parameter(input, "filename"))) { strncpy(sFileListParam.filename, tmp->val, (MAX_FILE_LENGTH-1)); } if((tmp = CGI_Find_Parameter(input, "sort"))) { strncpy(sFileListParam.sort, tmp->val, WFM2_SORT_MODE_LEN); } if((tmp = CGI_Find_Parameter(input, "dir"))) { strncpy(sFileListParam.dir, tmp->val, WFM2_SORT_TYPE_LEN); } if((tmp = CGI_Find_Parameter(input, "hidden_file"))) { sFileListParam.hidden_file = atoi(tmp->val); } else { sFileListParam.hidden_file = 0; } nRet = handle_file_list(&sFileListParam, NULL); //MARK: original handle list function //sFileListParam.end = sFileListParam.start + sFileListParam.limit - 1; //_get_file_list(full_path, &sFileListParam, NULL); if(full_path) __ax_free(full_path); if(sFileListParam.node != NULL) __ax_free(sFileListParam.node); return nRet; }
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; }
int op_chunked_upload(INPUT *input) { INPUT *tmp; int exist = 0, overwrite = 0, ret = 0; char *dest_path = "", src_name[256], *upload_id = "", *upload_dir = NULL, size_str[64] = "0"; char *path_tmp = NULL, *full_path, *full_upload_path, *full_src_path, *type, *progress; char *rename_string, *full_rename_path, *upload_name; int euid, egid, pid, multipart = 0; long long offset = 0, filesize = 0, cache_filesize = 0; FILE *fp = NULL; struct stat st_buf; time_t mtime = 0, actime = 0; if( (tmp=CGI_Find_Parameter(input, "dest_path")) ) dest_path = tmp->val; if( (tmp=CGI_Find_Parameter(input, "rename_dest")) ) { rename_string = tmp->val; if(strlen(rename_string) == 0) rename_string = NULL; } if( (tmp=CGI_Find_Parameter(input, "upload_name")) ) { upload_name = tmp->val; if(strlen(upload_name) == 0) upload_name = NULL; } //path_tmp = (char *)__ax_calloc(1, strlen(dest_path) + 1); //strcpy(path_tmp, dest_path); /* if(check_user_read_write_privilege(remote_user, path_tmp) < 0){ if(path_tmp) __ax_free(path_tmp); //Status_With_Size_To_JSON(WFM2_PERMISSION_DENY, size_str); return -1; } */ if( (tmp=CGI_Find_Parameter(input, "overwrite")) ) { overwrite = atoi(tmp->val); } if( (tmp=CGI_Find_Parameter(input, "type")) ) { type = tmp->val; } if( (tmp=CGI_Find_Parameter(input, "offset")) ) { offset = atoll(tmp->val); } if( (tmp=CGI_Find_Parameter(input, "filesize")) ) { filesize = atoll(tmp->val); } if( (tmp=CGI_Find_Parameter(input, "multipart")) ) { multipart = atoll(tmp->val); } if( (tmp=CGI_Find_Parameter(input, "upload_id")) ) { upload_id = tmp->val; } //if(path_tmp) __ax_free(path_tmp); if( (tmp=CGI_Find_Parameter(input, "progress")) ) { progress = (char *)__ax_calloc(1, strlen(tmp->val) + 6); if(strlen(tmp->val) > MAX_FILE_NAME_LENGTH) { // if progress name too long. //_get_progress_time_string(progress); } else { sprintf(progress, "/tmp/%s", tmp->val); } //sprintf(progress, "/tmp/%s", tmp->val); fp=fopen(progress, "w+"); if (fp == NULL) { if (progress) __ax_free(progress); // Status_With_Size_To_JSON(WFM2_FAIL, size_str); return -1; } fclose(fp); // Set_Private_Profile_Integer("", UPLOAD_PID, pid, progress); if (progress) __ax_free(progress); } // Become_ID(remote_user, &euid, &egid); if((tmp=CGI_Find_Parameter(input, "upload_root_dir")) ) { char uppath[1024]; snprintf(uppath, sizeof(uppath), "%s/%s", tmp->val, UPLOAD_CACHE_DIR); upload_dir = (char *)__ax_calloc(1, strlen(uppath) + MAX_FILE_LENGTH + 15); exist = check_exist(uppath, upload_dir); if (exist < 0) { //Status_With_Size_To_JSON(WFM2_FILE_NO_EXIST, size_str); if (upload_dir) __ax_free(upload_dir); return -1; } } // Finish uploading, now rename (move) it to real file and name if((tmp=CGI_Find_Parameter(input, "Filename")) && (upload_id != NULL) ) { char final_dest_path[2048], tmpfile[2048]; // Destination folder path strcpy(final_dest_path, "/tmp/mnt"); strcat(final_dest_path, dest_path); strcat(final_dest_path, "/"); char *file_name = tmp->val; if (file_name[0] == '\\') { file_name++; strcat(final_dest_path, file_name); } else strcat(final_dest_path, file_name); // Original temp file path strcpy(tmpfile, upload_dir); strcat(tmpfile, "/"); strcat(tmpfile, upload_id); ret = rename(tmpfile, final_dest_path) ; if(ret) FCGI_LOG("Fail to move from tmp file %s to %s\n", tmpfile, final_dest_path); } if (upload_dir) __ax_free(upload_dir); return ret; }