/* --------------- Answer to system messages */ void __stdcall CtrlHandler(DWORD CtrlCode) { DWORD StatetoSend = 0; switch(CtrlCode) { case SERVICE_CONTROL_STOP: SendStatus(SERVICE_STOP_PENDING, NO_ERROR, 0, 1, 5000); StopService(); StatetoSend = SERVICE_STOPPED; break; case SERVICE_CONTROL_PAUSE: if(ServiceCurrentStatus == 1) { SendStatus(SERVICE_PAUSE_PENDING, NO_ERROR, 0, 1, 1000); PauseService(); StatetoSend = SERVICE_PAUSED; } break; case SERVICE_CONTROL_CONTINUE: if(ServiceCurrentStatus == 3) { SendStatus(SERVICE_CONTINUE_PENDING, NO_ERROR, 0, 1, 1000); ResumeService(); StatetoSend = SERVICE_RUNNING; } break; case SERVICE_CONTROL_SHUTDOWN: return; } SendStatus(StatetoSend, NO_ERROR, 0, 0, 0); }
/* --------------- Service main handler */ void WINAPI ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv) { ServiceStatus = RegisterServiceCtrlHandler(ServiceName, &CtrlHandler); if(!ServiceStatus) { TerminateService(GetLastError()); return; } SendStatus(SERVICE_START_PENDING, NO_ERROR, 0, 1, 5000); ServiceEvent = CreateEvent(0, TRUE, FALSE, 0); if(!ServiceEvent) { TerminateService(GetLastError()); return; } SendStatus(SERVICE_START_PENDING, NO_ERROR, 0, 2, 1000); SendStatus(SERVICE_START_PENDING, NO_ERROR, 0, 3, 5000); if(!InitServiceThread()) { TerminateService(GetLastError()); return; } SendStatus(SERVICE_RUNNING, NO_ERROR, 0, 0, 0); /* Endless loop */ WaitForSingleObject(ServiceEvent, INFINITE); TerminateService(0); return; }
void DoExtDiskSpace(tBuffer *bIn, tBuffer *bOut, u_int32_t id) { struct STATFS stfs; tFSPath *realPath; char *path; path = convertFromUtf8(BufferGetString(bIn), 1); realPath = FSCheckPath(path); DEBUG((MYLOG_DEBUG, "[DoExtDiskSpaceOpenSSH]Path: %s", path)); if (realPath != NULL && !HAS_BIT(gl_var->flagsDisable, SFTP_DISABLE_STATSFS)) { DEBUG((MYLOG_DEBUG, "[DoExtDiskSpaceOpenSSH]Realpath: %s", realPath->realPath)); if (STATFS(realPath->realPath, &stfs) == 0) { tBuffer *b; b = BufferNew(); BufferPutInt8(b, SSH2_FXP_EXTENDED_REPLY); BufferPutInt32(b, id); BufferPutInt64(b, (u_int64_t) stfs.f_blocks * (u_int64_t) stfs.f_bsize); BufferPutInt64(b, (u_int64_t) stfs.f_bfree * (u_int64_t) stfs.f_bsize); BufferPutInt64(b, 0); BufferPutInt64(b, (u_int64_t) stfs.f_bavail * (u_int64_t) stfs.f_bsize); BufferPutInt32(b, stfs.f_bsize); BufferPutPacket(bOut, b); } else SendStatus(bOut, id, errnoToPortable(errno)); } else SendStatus(bOut, id, SSH2_FX_PERMISSION_DENIED); FSDestroyPath(realPath); free(path); }
void DoAdminUserCreate() { u_int32_t status = SSH2_FX_FAILURE; char *args[5]; char *userName; char *passWord; char *homePath; int ret; userName = BufferGetString(bIn); passWord = BufferGetString(bIn); homePath = BufferGetString(bIn); args[0] = MSS_SFTPUSER; args[1] = "create"; args[2] = userName; args[3] = homePath; args[4] = NULL; (void )ExecCommandWithArgs(args, &ret, passWord, 0); if (ret == 0) { args[1] = "hide"; args[3] = "0"; (void )ExecCommandWithArgs(args, &ret, NULL, 0); status = SSH2_FX_OK; } DEBUG((MYLOG_DEBUG, "[DoAdminUserCreate]User:%s Home:%s Pass:%s status:%i", userName, homePath, passWord, status)); SendStatus(bOut, 0, status); free(userName); free(passWord); free(homePath); }
void Daemon::MoveToStatus(STATUS_t newStatus){ // -- dataType myMex; // -- myMex.append((void*)"STATUS ",7); // -- WORD myStatus=(WORD)newStatus; // -- myMex.append((void*)&myStatus,WORDSIZE); // -- connectionManager_->Send(myMex,StatusSck); ostringstream s; s << "[Daemon]::[DEBUG]::Moving to status " << newStatus; #ifndef FSM_DEBUG if (newStatus<CLEARBUSY || newStatus>READ) Log(s.str(),3); #else Log(s.str(),3); #endif std::cout << s.str() << std::endl; STATUS_t oldStatus = myStatus_; myStatus_=newStatus; myPausedFlag_=false; if (!((oldStatus==CLEARBUSY && newStatus==WAITTRIG) || \ (oldStatus==WAITTRIG && newStatus==READ) || \ (oldStatus==READ && newStatus==CLEARBUSY) )) { SendStatus(oldStatus,newStatus); //Send status to GUI (formatted correctly) } }
// // Notify GM of completed vertex // void DVertexPnController::Terminate(DrError vertexState, UInt32 exitCode) { LogAssert(vertexState != DryadError_VertexRunning); if (vertexState == DrError_OK) { LogAssert(exitCode == DrExitCode_StillActive); } // // take Critical section to update vertex state // { AutoCriticalSection acs(&m_baseCS); m_currentStatus->SetVertexState(vertexState); } // // Log vertex termination // DrLogI( "Terminating vertex. Vertex %u.%u exitCode %s vertexState %s", m_currentStatus->GetProcessStatus()->GetVertexId(), m_currentStatus->GetProcessStatus()->GetVertexInstanceVersion(), DREXITCODESTRING(exitCode), DRERRORSTRING(vertexState)); // // Send status to GM // SendStatus(exitCode, true); }
void ZoneLaunch::Start() { auto spec = new ProcLauncher::Spec(); spec->program = m_config->ZoneExe; if(m_port) { std::string arg = m_zone + std::string(":") + std::to_string(m_port); spec->args.push_back(arg); } else { spec->args.push_back(m_zone); } spec->args.push_back(m_launcherName); spec->handler = this; spec->logFile = m_config->LogPrefix + m_zone + m_config->LogSuffix; //spec is consumed, even on failure m_ref = ProcLauncher::get()->Launch(spec); if(m_ref == ProcLauncher::ProcError) { Log.Out(Logs::Detail, Logs::Launcher, "Failure to launch '%s %s %s'. ", m_config->ZoneExe.c_str(), m_zone.c_str(), m_launcherName); m_timer.Start(m_config->RestartWait); return; } m_startCount++; m_state = StateStarted; s_running++; m_killFails = 0; SendStatus(); Log.Out(Logs::Detail, Logs::Launcher, "Zone %s has been started.", m_zone.c_str()); }
void ZoneLaunch::Start() { ProcLauncher::Spec *spec = new ProcLauncher::Spec(); spec->program = m_config->ZoneExe; // if(m_zone.substr(0,7) == "dynamic") // spec->args.push_back("."); // else spec->args.push_back(m_zone); spec->args.push_back(m_launcherName); spec->handler = this; spec->logFile = m_config->LogPrefix + m_zone + m_config->LogSuffix; //spec is consumed, even on failure m_ref = ProcLauncher::get()->Launch(spec); if(m_ref == ProcLauncher::ProcError) { Log.Out(Logs::Detail, Logs::Launcher, "Failure to launch '%s %s %s'. ", m_config->ZoneExe.c_str(), m_zone.c_str(), m_launcherName); m_timer.Start(m_config->RestartWait); return; } m_startCount++; m_state = StateStarted; s_running++; m_killFails = 0; SendStatus(); Log.Out(Logs::Detail, Logs::Launcher, "Zone %s has been started.", m_zone.c_str()); }
//called when the process actually dies off... void ZoneLaunch::OnTerminate(const ProcLauncher::ProcRef &ref, const ProcLauncher::Spec *spec) { s_running--; switch(m_state) { case StateStartPending: Log.Out(Logs::Detail, Logs::Launcher, "Zone %s has gone down before we started it..?? Restart timer started.", m_zone.c_str()); m_state = StateStartPending; m_timer.Start(m_config->RestartWait); break; case StateStarted: //something happened to our happy process... Log.Out(Logs::Detail, Logs::Launcher, "Zone %s has gone down. Restart timer started.", m_zone.c_str()); m_state = StateStartPending; m_timer.Start(m_config->RestartWait); break; case StateRestartPending: //it finally died, start it on up again Log.Out(Logs::Detail, Logs::Launcher, "Zone %s has terminated. Transitioning to starting state.", m_zone.c_str()); m_state = StateStartPending; break; case StateStopPending: //it finally died, transition to close. Log.Out(Logs::Detail, Logs::Launcher, "Zone %s has terminated. Transitioning to stopped state.", m_zone.c_str()); m_state = StateStopped; break; case StateStopped: //we already thought it was stopped... dont care... Log.Out(Logs::Detail, Logs::Launcher, "Notified of zone %s terminating when we thought it was stopped.", m_zone.c_str()); break; } SendStatus(); }
void DoAdminGetLogContent() { u_int32_t r = 0, status = SSH2_FX_FAILURE; off_t size; char *buffer; size = BufferGetInt32(bIn); if ((buffer = malloc(size)) != NULL) { int fd; if ((fd = open(MSS_LOG, O_RDONLY)) >= 0) { if (lseek(fd, -size, SEEK_END) == (off_t) -1 && errno != EINVAL) status = errnoToPortable(errno); else { r = read(fd, buffer, size); SendData(bOut, 0, buffer, r); status = SSH2_FX_OK; } xclose(fd); } else status = errnoToPortable(errno); free(buffer); } DEBUG((MYLOG_DEBUG, "[DoAdminGetLogContent]wanted:%i / read:%i", size, r)); if (status != SSH2_FX_OK) SendStatus(bOut, 0, status); }
/* --------------- Terminate service */ long TerminateService(DWORD ProvidedErr) { if(ServiceEvent) CloseHandle(ServiceEvent); if(ServiceStatus) SendStatus(SERVICE_STOPPED, ProvidedErr, 0, 0, 0); if(hServiceThread) CloseHandle(hServiceThread); return(0); }
void DoAdminKillUser() { t_sftpwho *who; int pidToKill = (int )BufferGetInt32(bIn); int status = SSH2_FX_OK; DEBUG((MYLOG_DEBUG, "[DoAdminKillUser]Try to kill pid:%i", pidToKill)); who = SftWhoGetAllStructs(); if (who != NULL) { unsigned int pid; int i; pid = (unsigned int )getpid(); for (i = 0; i < SFTPWHO_MAXCLIENT; i++) if ((who[i].status & SFTPWHO_STATUS_MASK) != SFTPWHO_EMPTY) if ((who[i].pid == pidToKill || pidToKill == 0) && who[i].pid != pid) { DEBUG((MYLOG_DEBUG, "[DoAdminKillUser]Send kill to pid:%i", who[i].pid)); if (kill(who[i].pid, SIGHUP) == -1) status = errnoToPortable(errno); } } #ifdef DODEBUG else DEBUG((MYLOG_DEBUG, "[DoAdminKillUser]No global structure !")); #endif SendStatus(bOut, 0, status); }
void StatusReporterModule::TimerEventHandler(u16 passedTime, u32 appTimer) { //Every reporting interval, the node should send its connections if(configuration.connectionReportingIntervalMs != 0 && node->appTimerMs - lastConnectionReportingTimer > configuration.connectionReportingIntervalMs) { //Send connection info SendAllConnections(NODE_ID_BROADCAST, MESSAGE_TYPE_MODULE_GENERAL); lastConnectionReportingTimer = node->appTimerMs; } //Every reporting interval, the node should send its status if(configuration.statusReportingIntervalMs != 0 && node->appTimerMs - lastStatusReportingTimer > configuration.statusReportingIntervalMs) { //Send status SendStatus(NODE_ID_BROADCAST, MESSAGE_TYPE_MODULE_ACTION_RESPONSE); SendDeviceInfo(NODE_ID_BROADCAST, MESSAGE_TYPE_MODULE_ACTION_RESPONSE); lastStatusReportingTimer = node->appTimerMs; } }
void C4Network2Res::OnDiscover(C4Network2IOConnection *pBy) { if (!IsBinaryCompatible()) return; // discovered iLastReqTime = time(NULL); // send status back SendStatus(pBy); }
void DoExtDiskSpaceOpenSSH_Handle(tBuffer *bIn, tBuffer *bOut, u_int32_t id) { tHandle *hdl; if ((hdl = HandleGetDir(BufferGetHandle(bIn))) != NULL) DoExtDiskSpaceOpenSSH_Path(bOut, id, hdl->path); else SendStatus(bOut, id, SSH4_FX_INVALID_HANDLE); }
static void DoExtDiskSpaceOpenSSH_Path(tBuffer *bOut, u_int32_t id, const char *path) { struct STATFS stfs; tFSPath *realPath; DEBUG((MYLOG_DEBUG, "[DoExtDiskSpaceOpenSSH_Path]Path: %s", path)); realPath = FSCheckPath(path); if (realPath != NULL && !HAS_BIT(gl_var->flagsDisable, SFTP_DISABLE_STATSFS)) { DEBUG((MYLOG_DEBUG, "[DoExtDiskSpaceOpenSSH_Path]Realpath: %s", realPath->realPath)); if (STATFS(realPath->realPath, &stfs) == 0) { tBuffer *b; b = BufferNew(); BufferPutInt8(b, SSH2_FXP_EXTENDED_REPLY); BufferPutInt32(b, id); BufferPutInt64(b, stfs.f_bsize); /* file system block size */ BufferPutInt64(b, stfs.f_frsize); /* fundamental fs block size */ BufferPutInt64(b, stfs.f_blocks); /* number of blocks (unit f_frsize) */ BufferPutInt64(b, stfs.f_bfree); /* free blocks in file system */ BufferPutInt64(b, stfs.f_bavail); /* free blocks for non-root */ BufferPutInt64(b, stfs.f_files); /* total file inodes */ BufferPutInt64(b, stfs.f_ffree); /* free file inodes */ BufferPutInt64(b, stfs.f_favail); /* free file inodes for to non-root */ BufferPutInt64(b, stfs.f_fsid); /* file system id */ BufferPutInt64(b, stfs.f_flag); /* bit mask of f_flag values */ BufferPutInt64(b, stfs.f_namemax); /* maximum filename length */ BufferPutPacket(bOut, b); BufferDelete(b); } else { DEBUG((MYLOG_DEBUG, "[DoExtDiskSpaceOpenSSH_Path]error: %s", strerror(errno))); SendStatus(bOut, id, errnoToPortable(errno)); } } else { DEBUG((MYLOG_DEBUG, "[DoExtDiskSpaceOpenSSH_Path]FSCheckPath failed")); SendStatus(bOut, id, SSH2_FX_PERMISSION_DENIED); } FSDestroyPath(realPath); }
void Daemon::PublishStatusWithTimeInterval(){ timeval tv; gettimeofday(&tv,NULL); long timediff = Utility::timevaldiff(&lastSentStatusMessageTime_,&tv); // in usec if (timediff>200000) { // Log("Publish status for timeout",1); SendStatus(myStatus_,myStatus_); } }
void DoExtFileHashing_Handle(tBuffer *bIn, tBuffer *bOut, u_int32_t id) { tHandle *hdl; DEBUG((MYLOG_DEBUG, "[DoExtFileHashing_Handle]...")); if ((hdl = HandleGetFile(BufferGetHandle(bIn))) != NULL) DoExtFileHashing_FD(bIn, bOut, id, hdl->fd); else SendStatus(bOut, id, SSH4_FX_INVALID_HANDLE); }
bool CSmsStatusReplierImpl::handle_reception(const TMsvId& /*entry_id*/, const TMsvId& /*folder_id*/, const TDesC& sender, const TDesC& body) { if (body.Left(KStatusEnquiry().Length()).Compare(KStatusEnquiry)==0) { GetOtherStatus(); SendStatus(sender); return true; } return false; }
void DoExtFileHashing_Name(tBuffer *bIn, tBuffer *bOut, u_int32_t id) { char *file = BufferGetString(bIn); int status, fd; status = FSOpenFile(file, &fd, O_RDONLY, 0, NULL); DEBUG((MYLOG_DEBUG, "[DoExtFileHashing_Name]File: %s Status: %i", file, status)); if (status == SSH2_FX_OK) { DoExtFileHashing_FD(bIn, bOut, id, fd); xclose(fd); } else SendStatus(bOut, id, status); free(file); }
cSoftControl::cSoftControl(cPlayList * PlayList ) : cControl(new cSoftPlayer) { // FIXME delete displayReplay and privateMenu displayReplay=NULL; privateMenu=NULL; OsdActive=OsdNone; shouldStop=false; playList=PlayList; playList->PrepareForPlayback(); SoftPlayer = dynamic_cast<cSoftPlayer*> (player); const char *nextfile=PlayList->NextFile(); if (nextfile) SoftPlayer->PlayFile(nextfile); newFile=true; SendStatus(); };
void DoAdminUserList() { char *args[3]; char *users; int ret; args[0] = MSS_SFTPUSER; args[1] = "list"; args[2] = NULL; users = ExecCommandWithArgs(args, &ret, NULL, 1); DEBUG((MYLOG_DEBUG, "[DoAdminUserList]Return:%i Users:%s", ret, users)); if (ret == 0) SendData(bOut, 0, users, strlen(users)); else SendStatus(bOut, 0, SSH2_FX_FAILURE); if (users != NULL) free(users); }
void DVertexPnController::AssimilateNewStatus(DVertexProcessStatus* status, bool sendUpdate, bool notifyWaiters) { { AutoCriticalSection acs(&m_baseCS); UInt32 i; LogAssert(m_activeVertex == true); DVertexProcessStatus* currentPStatus = m_currentStatus->GetProcessStatus(); LogAssert(status->GetVertexId() == currentPStatus->GetVertexId()); LogAssert(status->GetVertexInstanceVersion() == currentPStatus->GetVertexInstanceVersion()); currentPStatus->SetVertexMetaData(status->GetVertexMetaData(), false); currentPStatus->SetVertexErrorCode(status->GetVertexErrorCode()); currentPStatus->SetVertexErrorString(status->GetVertexErrorString()); LogAssert(status->GetInputChannelCount() == currentPStatus->GetInputChannelCount()); for (i=0; i<status->GetInputChannelCount(); ++i) { AssimilateChannelStatus(&(currentPStatus->GetInputChannels()[i]), &(status->GetInputChannels()[i])); } LogAssert(status->GetOutputChannelCount() == currentPStatus->GetOutputChannelCount()); for (i=0; i<status->GetOutputChannelCount(); ++i) { AssimilateChannelStatus(&(currentPStatus->GetOutputChannels()[i]), &(status->GetOutputChannels()[i])); } } if (sendUpdate) { SendStatus(DrExitCode_StillActive, notifyWaiters); } }
void DoAdminConfigGet() { struct stat st; u_int32_t status = SSH2_FX_FAILURE; int fd; if (stat(CONFIG_FILE, &st) != -1 && (fd = open(CONFIG_FILE, O_RDONLY)) >= 0) { u_int32_t r; tBuffer *b = BufferNew(); char *buffer; BufferPutInt8FAST(b, SSH2_FXP_DATA); BufferPutInt32(b, 0); if ((buffer = malloc(st.st_size)) != NULL) { r = read(fd, buffer, st.st_size); BufferPutData(b, buffer, r); free(buffer); status = SSH2_FX_OK; } xclose(fd); if (stat("/etc/shells", &st) != -1 && (fd = open("/etc/shells", O_RDONLY)) >= 0) { if ((buffer = malloc(st.st_size)) != NULL) { r = read(fd, buffer, st.st_size); BufferPutData(b, buffer, r); free(buffer); } else BufferPutInt32(b, 0); xclose(fd); } if (status == SSH2_FX_OK) BufferPutPacket(bOut, b); BufferDelete(b); } else status = errnoToPortable(errno); DEBUG((MYLOG_DEBUG, "[DoAdminConfigGet]status: %i", status)); if (status != SSH2_FX_OK) SendStatus(bOut, 0, status); }
void DoAdminServerStatus() { int isActive = BufferGetInt8(bIn); int status = SSH2_FX_OK; int fd; if (isActive > 0) { if (unlink(SHUTDOWN_FILE) == -1) status = errnoToPortable(errno); } else { if ((fd = open(SHUTDOWN_FILE, O_CREAT | O_TRUNC | O_RDWR, 0644)) >= 0) xclose(fd); else status = errnoToPortable(errno); } SendStatus(bOut, 0, status); }
void DoAdminUserDelete() { u_int32_t status = SSH2_FX_FAILURE; char *args[5]; char *userName; int ret; userName = BufferGetString(bIn); args[0] = MSS_SFTPUSER; args[1] = "delete"; args[2] = userName; args[3] = "0"; args[4] = NULL; (void )ExecCommandWithArgs(args, &ret, NULL, 0); if (ret == 0) status = SSH2_FX_OK; DEBUG((MYLOG_DEBUG, "[DoAdminUserDelete]User:%s status:%i", userName, status)); SendStatus(bOut, 0, status); free(userName); }
void DoExtHardLink(tBuffer *bIn, tBuffer *bOut, u_int32_t id) { char *link, *target; int status = SSH2_FX_OK; link = convertFromUtf8(BufferGetString(bIn), 1); target = convertFromUtf8(BufferGetString(bIn), 1); if (HAS_BIT(gl_var->flagsDisable, SFTP_DISABLE_SYMLINK)) { DEBUG((MYLOG_DEBUG, "[DoExtHardLink]Disabled by conf.")); status = SSH2_FX_PERMISSION_DENIED; } else { status = FSHardlink(target, link); DEBUG((MYLOG_DEBUG, "[DoExtHardLink]link:'%s' target:'%s' -> %i", link, target, status)); } SendStatus(bOut, id, status); free(target); free(link); }
bool LoginServer::Connect() { char tmp[25]; if(database.GetVariable("loginType",tmp,sizeof(tmp)) && strcasecmp(tmp,"MinILogin") == 0){ minilogin = true; Log.Out(Logs::Detail, Logs::World_Server, "Setting World to MiniLogin Server type"); } else minilogin = false; if (minilogin && WorldConfig::get()->WorldAddress.length()==0) { Log.Out(Logs::Detail, Logs::World_Server, "**** For minilogin to work, you need to set the <address> element in the <world> section."); return false; } char errbuf[TCPConnection_ErrorBufferSize]; if ((LoginServerIP = ResolveIP(LoginServerAddress, errbuf)) == 0) { Log.Out(Logs::Detail, Logs::World_Server, "Unable to resolve '%s' to an IP.",LoginServerAddress); return false; } if (LoginServerIP == 0 || LoginServerPort == 0) { Log.Out(Logs::Detail, Logs::World_Server, "Connect info incomplete, cannot connect: %s:%d",LoginServerAddress,LoginServerPort); return false; } if (tcpc->ConnectIP(LoginServerIP, LoginServerPort, errbuf)) { Log.Out(Logs::Detail, Logs::World_Server, "Connected to Loginserver: %s:%d",LoginServerAddress,LoginServerPort); if (minilogin) SendInfo(); else SendNewInfo(); SendStatus(); zoneserver_list.SendLSZones(); return true; } else { Log.Out(Logs::Detail, Logs::World_Server, "Could not connect to login server: %s:%d %s",LoginServerAddress,LoginServerPort,errbuf); return false; } }
void DoAdminListUsers() { char *buf; int ret; buf = ExecCommand(MSS_SFTPWHO, &ret); if (buf != NULL) { tBuffer *b; b = BufferNew(); BufferPutInt8FAST(b, SSH_ADMIN_LIST_USERS_REPLY); BufferPutString(b, buf); BufferPutPacket(bOut, b); DEBUG((MYLOG_DEBUG, "[DoAdminListUsers]send length:'%i' return:%i", strlen(buf), ret)); BufferDelete(b); free(buf); } else { SendStatus(bOut, 0, SSH2_FX_FAILURE); DEBUG((MYLOG_DEBUG, "[DoAdminListUsers]Error: %s", strerror(errno))); } }
static void DoExtFileHashing_FD(tBuffer *bIn, tBuffer *bOut, u_int32_t id, int fd) { gnutls_digest_algorithm_t gnuTlsAlgo = GNUTLS_DIG_UNKNOWN; u_int64_t offset, length; u_int32_t blockSize; char *algo; algo = BufferGetString(bIn); offset = BufferGetInt64(bIn); length = BufferGetInt64(bIn); blockSize = BufferGetInt32(bIn); if (lseek(fd, offset, SEEK_SET) == -1) { SendStatus(bOut, id, errnoToPortable(errno)); DEBUG((MYLOG_DEBUG, "[DoExtFileHashing_FD]Error lseek1")); goto endOfFileHashing; } if (length == 0)//read the file to the end { u_int64_t endOfFile; if ((endOfFile = lseek(fd, 0, SEEK_END)) == -1) { SendStatus(bOut, id, errnoToPortable(errno)); DEBUG((MYLOG_DEBUG, "[DoExtFileHashing_FD]Error lseek2")); goto endOfFileHashing; } length = endOfFile - offset; if (lseek(fd, offset, SEEK_SET) == -1) { SendStatus(bOut, id, errnoToPortable(errno)); DEBUG((MYLOG_DEBUG, "[DoExtFileHashing_FD]Error lseek3")); goto endOfFileHashing; } } if (blockSize == 0)//read length in one time blockSize = length; DEBUG((MYLOG_DEBUG, "[DoExtFileHashing_FD]Algo:%s Fd:%i Offset:%llu Length:%llu BlockSize:%i", algo, fd, offset, length, blockSize)); if (strcasecmp("md2", algo) == 0) gnuTlsAlgo = GNUTLS_DIG_MD2; else if (strcasecmp("md5", algo) == 0) gnuTlsAlgo = GNUTLS_DIG_MD5; else if (strcasecmp("sha1", algo) == 0) gnuTlsAlgo = GNUTLS_DIG_SHA1; else if (strcasecmp("sha224", algo) == 0) gnuTlsAlgo = GNUTLS_DIG_SHA224; else if (strcasecmp("sha256", algo) == 0) gnuTlsAlgo = GNUTLS_DIG_SHA256; else if (strcasecmp("sha384", algo) == 0) gnuTlsAlgo = GNUTLS_DIG_SHA384; else if (strcasecmp("sha512", algo) == 0) gnuTlsAlgo = GNUTLS_DIG_SHA512; if (gnuTlsAlgo != GNUTLS_DIG_UNKNOWN) { gnutls_hash_hd_t dig; tBuffer *b; size_t keySize = gnutls_hash_get_len(gnuTlsAlgo); char *gnuKey; char data[SSH2_READ_HASH]; int inError = 0; int gnulTlsError; b = BufferNew(); BufferPutInt8FAST(b, SSH2_FXP_EXTENDED_REPLY); BufferPutInt32(b, id); BufferPutString(b, algo); gnuKey = calloc(1, keySize); if (gnuKey == NULL) goto endOfFileHashing; if ((gnulTlsError = gnutls_hash_init(&dig, gnuTlsAlgo)) == 0) { while (length > 0) { u_int32_t r, off, len; length = (length > (u_int64_t) blockSize) ? length - (u_int64_t) blockSize : 0; off = blockSize; len = sizeof(data); DEBUG((MYLOG_DEBUG, "[DoExtFileHashing_FD]Read:%i Rest:%llu", len, length)); while ((r = read(fd, data, len)) > 0) { DEBUG((MYLOG_DEBUG, "[DoExtFileHashing_FD]Compute block (%u/%u %u)", len, r, off)); if ((gnulTlsError = gnutls_hash(dig, data, r)) != 0) { DEBUG((MYLOG_DEBUG, "[DoExtFileHashing_FD]Error gnutls_hmac [error: %i]", gnulTlsError)); inError = 1; break; } off -= r; if (off < sizeof(data)) len = off; if (off == 0) break; } } } else { DEBUG((MYLOG_DEBUG, "[DoExtFileHashing_FD]Error gnutls_hash_init [keySize: %li] [error: %i]", keySize, gnulTlsError)); inError = 1; } if (inError == 0) { DEBUG((MYLOG_DEBUG, "[DoExtFileHashing_FD]Compute key... [keySize: %li][keyPointer: %p]", keySize, gnuKey)); gnutls_hash_deinit(dig, gnuKey); DEBUG((MYLOG_DEBUG, "[DoExtFileHashing_FD]Hash: %X%X%X ...", gnuKey[0], gnuKey[1], gnuKey[2])); BufferPutRawData(b, gnuKey, keySize); BufferPutPacket(bOut, b); } else SendStatus(bOut, id, SSH2_FX_FAILURE); BufferDelete(b); free(gnuKey); } else { DEBUG((MYLOG_DEBUG, "[DoExtFileHashing_FD]No algorithm: %s", algo)); SendStatus(bOut, id, SSH2_FX_OP_UNSUPPORTED); } endOfFileHashing: DEBUG((MYLOG_DEBUG, "[DoExtFileHashing_FD]End")); free(algo); }