unsigned int VMCAAddRootCertificate( unsigned char *pszRootCertificate, PWSTR pszPassPhrase, unsigned char *pszPrivateKey, unsigned int dwOverWrite) { DWORD dwError = 0; BOOL bFileExists = FALSE; BOOL bOverWrite = FALSE; BOOLEAN bLocked = FALSE; PSTR pszRootCertFile = NULL; PSTR pszPrivateKeyFile = NULL; PSTR pszPasswordFile = NULL; PSTR pszDataDirectory = NULL; #ifndef _WIN32 struct stat buf = { 0 }; #else struct _stat buf = { 0 }; #endif bOverWrite = (dwOverWrite == 1); // // Grab exclusive lock since we are writing the Root Cert, // and all operations must serialize for this op. // VMCA_LOCK_MUTEX_EXCLUSIVE(&gVMCAServerGlobals.svcMutex, bLocked); dwError = VMCAValidateCACertificatePrivate((LPSTR) pszRootCertificate,NULL, (LPSTR)pszPrivateKey); BAIL_ON_VMCA_ERROR(dwError); dwError = VMCAGetRootCertificateFilePath(&pszRootCertFile); BAIL_ON_VMCA_ERROR(dwError); dwError = VMCAGetPrivateKeyPath(&pszPrivateKeyFile); BAIL_ON_VMCA_ERROR(dwError); dwError = VMCAGetPrivateKeyPasswordPath(&pszPasswordFile); BAIL_ON_VMCA_ERROR(dwError); dwError = VMCAGetDataDirectory(&pszDataDirectory); BAIL_ON_VMCA_ERROR(dwError); bFileExists = (stat(pszRootCertFile,&buf) == ERROR_SUCCESS); if (!bOverWrite && bFileExists) { dwError = VMCA_ROOT_CA_ALREADY_EXISTS; BAIL_ON_VMCA_ERROR(dwError); } if (bOverWrite && bFileExists) { dwError = VMCABackupRootCAFiles(pszRootCertFile, pszPrivateKeyFile, pszPasswordFile); BAIL_ON_VMCA_ERROR(dwError); } if (!bFileExists) { dwError = VMCACreateDirectory(pszDataDirectory, TRUE); BAIL_ON_VMCA_ERROR(dwError); } dwError = VMCAWriteCertificateChainToFile(pszRootCertFile, (PVMCA_CERTIFICATE) pszRootCertificate); BAIL_ON_VMCA_ERROR(dwError); dwError = VMCAWritePrivateKeyToFile( pszPrivateKeyFile, (LPSTR) pszPrivateKey, pszPasswordFile, pszPassPhrase); BAIL_ON_VMCA_ERROR(dwError); dwError = VMCASetKeyPerm(pszPrivateKeyFile); BAIL_ON_VMCA_ERROR(dwError); dwError = VMCASrvInitCA(); BAIL_ON_VMCA_ERROR(dwError); dwError = VMCASrvNotifyDirSync(); BAIL_ON_VMCA_ERROR(dwError); #if 0 #ifdef DEBUG PrintCurrentState(); #endif #endif error : VMCA_LOCK_MUTEX_UNLOCK(&gVMCAServerGlobals.svcMutex, bLocked); if ( pszRootCertFile != NULL) { VMCAFreeStringA(pszRootCertFile); } if( pszPrivateKeyFile != NULL) { VMCAFreeStringA(pszPrivateKeyFile); } if( pszPasswordFile != NULL ) { VMCAFreeStringA(pszPasswordFile); } if (pszDataDirectory != NULL) { VMCAFreeStringA(pszDataDirectory); } return dwError; }
// Timer Callback - armTimer //# Start armTimer_operation Marker void arm_controller::armTimer_operation(const NAMESPACE::TimerEvent& event) { #ifdef USE_ROSMOD comp_queue.ROSMOD_LOGGER->log("DEBUG", "Entering arm_controller::armTimer_operation"); #endif // Business Logic for armTimer_operation if (!paused) { UpdateSensorData(); switch (currentState) { case INIT: Init_StateFunc(); break; case FINDING_PB: if ( CheckGoals() ) Finding_PB_StateFunc(); UpdateArmPosition(); break; case OPENING_PB: Opening_PB_StateFunc(); UpdateArmPosition(); break; case FINDING_SAMPLE: if ( CheckGoals() ) Finding_Sample_StateFunc(); UpdateArmPosition(); break; case GRABBING_SAMPLE: if ( CheckGoals() ) Grabbing_Sample_StateFunc(); UpdateArmPosition(); break; case CARRYING_SAMPLE: if ( CheckGoals() ) Carrying_Sample_StateFunc(); UpdateArmPosition(); break; case INSERTING_SAMPLE: if ( CheckGoals() ) Inserting_Sample_StateFunc(); UpdateArmPosition(); break; case CLOSING_PB: if ( CheckGoals() ) Closing_PB_StateFunc(); UpdateArmPosition(); break; case MOVING_AWAY: if ( CheckGoals() ) Moving_Away_StateFunc(); UpdateArmPosition(); break; default: break; } if ( stateChanged ) { PrintCurrentState(); stateChanged = false; } sampleState_pub.publish(sample); payloadBayState_pub.publish(payloadBay); arm.state = currentState; armState_pub.publish(arm); if ( usingSerialPort ) { char buffer[20]; if ( payloadBayOpened ) { sprintf(buffer,"%s",openPayloadBayString); } else { sprintf(buffer,"%s",closePayloadBayString); } serialPort.sendArray((unsigned char *)buffer,strlen(buffer)); } } #ifdef USE_ROSMOD comp_queue.ROSMOD_LOGGER->log("DEBUG", "Exiting arm_controller::armTimer_operation"); #endif }
int main( int argc, char* argv[] ) { DWORD dwError = 0; const char* pszSmNotify = NULL; int notifyFd = -1; int notifyCode = 0; int ret = -1; BOOL bEnableSysLog = FALSE; BOOL bConsoleLogging = FALSE; setlocale(LC_ALL, ""); VMCABlockSelectedSignals(); dwError = VMCAParseArgs(argc, argv, &bEnableSysLog, &bConsoleLogging); BAIL_ON_VMCA_ERROR(dwError); if (bEnableSysLog) { gVMCALogType = VMCA_LOG_TYPE_SYSLOG; } else if (bConsoleLogging) { gVMCALogType = VMCA_LOG_TYPE_CONSOLE; } else { gVMCALogType = VMCA_LOG_TYPE_FILE; } dwError = VMCAInitialize(0, 0); BAIL_ON_VMCA_ERROR(dwError); VMCA_LOG_INFO("VM Certificate Service started."); #ifdef REST_ENABLED #ifndef _WIN32 dwError = VMCARestServiceStartup(); BAIL_ON_VMCA_ERROR(dwError); VMCA_LOG_INFO("VM Certificate ReST Protocol started."); #endif #endif PrintCurrentState(); // interact with likewise service manager (start/stop control) if ((pszSmNotify = getenv("LIKEWISE_SM_NOTIFY")) != NULL) { notifyFd = atoi(pszSmNotify); do { ret = write(notifyFd, ¬ifyCode, sizeof(notifyCode)); } while (ret != sizeof(notifyCode) && errno == EINTR); if (ret < 0) { VMCA_LOG_ERROR("Could not notify service manager: %s (%i)", strerror(errno), errno); dwError = LwErrnoToWin32Error(errno); BAIL_ON_VMCA_ERROR(dwError); } close(notifyFd); } // main thread waits on signals dwError = VMCAHandleSignals(); BAIL_ON_VMCA_ERROR(dwError); VMCA_LOG_INFO("VM Certificate Service exiting..."); cleanup: VMCAShutdown(); #ifdef REST_ENABLED #ifndef _WIN32 VMCARestServiceShutdown(); #endif #endif return (dwError); error: VMCA_LOG_ERROR("VM Certificate exiting due to error [code:%d]", dwError); goto cleanup; }