static int VmDirMain( int argc, char* argv[] ) { DWORD dwError = 0; CHAR pszPath[MAX_PATH]; PSTR pszServerName = NULL; PSTR pszUserName = NULL; PSTR pszPassword = NULL; CHAR pszPasswordBuf[VMDIR_MAX_PWD_LEN + 1] = {0}; PSTR pszErrorMessage = NULL; #ifndef _WIN32 setlocale(LC_ALL, ""); #endif dwError = VmDirGetVmDirLogPath(pszPath, "vdcleavefed.log"); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirLogInitialize( pszPath, FALSE, NULL, VMDIR_LOG_INFO, VMDIR_LOG_MASK_ALL ); BAIL_ON_VMDIR_ERROR(dwError); VmDirLogSetLevel( VMDIR_LOG_VERBOSE ); dwError = VmDirParseArgs( argc, argv, &pszServerName, &pszUserName, &pszPassword); if (dwError != 0) { ShowUsage(); BAIL_ON_VMDIR_ERROR(dwError); } if (pszUserName == NULL) { //Must use administrator as userName ShowUsage(); BAIL_ON_VMDIR_ERROR(dwError); } if (pszPassword == NULL) { // read password from stdin VmDirReadString( "password: "******"vdcleavefd for local server\n"); dwError = _VdcSetReadOnlyState(); BAIL_ON_VMDIR_ERROR(dwError); } else { printf("vdcleavefd offline for server %s\n", pszServerName); } dwError = VmDirLeaveFederation(pszServerName, pszUserName, pszPassword); BAIL_ON_VMDIR_ERROR(dwError); printf(" Leave federation cleanup done\n"); cleanup: memset(pszPasswordBuf, 0, sizeof(pszPasswordBuf)); VMDIR_SAFE_FREE_MEMORY(pszErrorMessage); VmDirLogTerminate(); return dwError; error: VmDirGetErrorMessage(dwError, &pszErrorMessage); printf("Leave federation cleanup failed. Error[%d] - %s\n", dwError, ( pszErrorMessage ) ? pszErrorMessage : ""); goto cleanup; }
DWORD VmDirLogInitialize( PCSTR pszLogFileName, BOOLEAN bUseSysLog, PCSTR pszSyslogName, VMDIR_LOG_LEVEL iInitLogLevel, ULONG iInitLogMask ) { DWORD dwError = 0; BOOLEAN bLogInitFailed = TRUE; if ( _gpVmDirLogCtx ) { bLogInitFailed = FALSE; dwError = VMDIR_ERROR_INVALID_PARAMETER; BAIL_ON_VMDIR_LOG_ERROR(dwError); } dwError = VmDirAllocateMemory( sizeof(*_gpVmDirLogCtx), (PVOID*)&_gpVmDirLogCtx); BAIL_ON_VMDIR_LOG_ERROR(dwError); if (pszLogFileName) { dwError = VmDirAllocateStringA(pszLogFileName, &_gpVmDirLogCtx->pszLogFileName); BAIL_ON_VMDIR_LOG_ERROR(dwError); if ((_gpVmDirLogCtx->pFile = fopen(_gpVmDirLogCtx->pszLogFileName, "a")) == NULL) { dwError = VMDIR_ERROR_IO; BAIL_ON_VMDIR_LOG_ERROR(dwError); } } if (bUseSysLog) { _gpVmDirLogCtx->bSyslog = bUseSysLog; if ( pszSyslogName ) // vmdirclient case, this is NULL. { dwError = VmDirAllocateStringA( pszSyslogName, &_gpVmDirLogCtx->pszSyslogDaemon); BAIL_ON_VMDIR_LOG_ERROR(dwError); openlog(_gpVmDirLogCtx->pszSyslogDaemon, 0, LOG_DAEMON); setlogmask( LOG_UPTO(_logLevelToSysLogLevel( iInitLogLevel )) ); } } else { setlogmask( LOG_UPTO(LOG_ERR) ); } _gpVmDirLogCtx->iLogLevel = iInitLogLevel; _gpVmDirLogCtx->iLogMask = iInitLogMask; cleanup: return dwError; error: if (bLogInitFailed) { VmDirLogTerminate(); } goto cleanup; }
int VmDirMain(int argc, char* argv[]) { DWORD dwError = 0; PSTR pszUserName = NULL; PSTR pszPartnerHost = NULL; PSTR pszPassword = NULL; PSTR pszPasswordBuf = NULL; CHAR pszPath[MAX_PATH]; CHAR pszLocalHostName[VMDIR_MAX_HOSTNAME_LEN] = {0}; #ifndef _WIN32 setlocale(LC_ALL,""); #endif dwError = VmDirGetVmDirLogPath(pszPath, "vdcresetMachineActCred.log"); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirLogInitialize(pszPath, FALSE, NULL, VMDIR_LOG_INFO, VMDIR_LOG_MASK_ALL ); BAIL_ON_VMDIR_ERROR(dwError); //get commandline parameters dwError = VmDirParseArgs(argc, argv, &pszUserName, &pszPartnerHost, &pszPassword); if ( dwError ) { ShowUsage(); goto cleanup; } dwError = VmDirAllocateMemory(VMDIR_MAX_PWD_LEN+1, (PVOID *)&pszPasswordBuf); BAIL_ON_VMDIR_ERROR(dwError); if ( pszPassword != NULL ) { dwError = VmDirStringCpyA(pszPasswordBuf, VMDIR_MAX_PWD_LEN, pszPassword); BAIL_ON_VMDIR_ERROR(dwError); } else //no password, read password from stdin { VmDirReadString("password: "******"vdcresetMachineActCred completed.\n"); VMDIR_LOG_INFO( VMDIR_LOG_MASK_ALL, "vdcresetMachineActCred completed."); cleanup: VMDIR_SAFE_FREE_MEMORY(pszPasswordBuf); VmDirLogTerminate(); return dwError; error: printf("vdcresetMachineActCred failed. Error[%d]\n", dwError); goto cleanup; }
int main( int argc, char * argv[]) { DWORD dwError = 0; const char * logFileName = NULL; const char * pszBootstrapSchemaFile = NULL; const char * pszStateDir = VMDIR_DB_DIR VMDIR_PATH_SEP; BOOLEAN bEnableSysLog = FALSE; BOOLEAN bConsoleMode = FALSE; int iLocalLogMask = 0; BOOLEAN bVmDirInit = FALSE; BOOLEAN bShutdownKDCService = FALSE; BOOLEAN bWaitTimeOut = FALSE; dwError = VmDirSrvUpdateConfig(); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirParseArgs( argc, argv, &pszBootstrapSchemaFile, &iLocalLogMask, &logFileName, &bEnableSysLog, &bConsoleMode); if(dwError != ERROR_SUCCESS) { ShowUsage( argv[0] ); BAIL_ON_VMDIR_ERROR(dwError); } dwError = VmDirAllocateStringA( pszBootstrapSchemaFile, &gVmdirGlobals.pszBootStrapSchemaFile); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirAllocateStringA(pszStateDir, &gVmdirGlobals.pszBDBHome); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirLogInitialize( logFileName, bEnableSysLog, "vmdird", VMDIR_LOG_INFO, iLocalLogMask); BAIL_ON_VMDIR_ERROR(dwError); VmDirdStateSet(VMDIRD_STATE_STARTUP); VMDIR_LOG_INFO( VMDIR_LOG_MASK_ALL, "Lotus Vmdird: starting..."); VmDirBlockSelectedSignals(); dwError = VmDirSetEnvironment(); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirInit(); BAIL_ON_VMDIR_ERROR(dwError); bVmDirInit = TRUE; VMDIR_LOG_INFO( VMDIR_LOG_MASK_ALL, "Lotus Vmkdcd: starting..."); if (VmDirdGetTargetState() != VMDIRD_STATE_RESTORE) { // Normal server startup route dwError = VmKdcServiceStartup(); BAIL_ON_VMDIR_ERROR(dwError); bShutdownKDCService = TRUE; VMDIR_LOG_INFO( VMDIR_LOG_MASK_ALL, "Lotus Vmkdcd: running..."); dwError = VmDirNotifyLikewiseServiceManager(); BAIL_ON_VMDIR_ERROR(dwError); VmDirdStateSet( VmDirdGetTargetState() ); VMDIR_LOG_INFO( VMDIR_LOG_MASK_ALL, "Lotus Vmdird: running... state (%d)", VmDirdState()); // main thread waits on signals dwError = VmDirHandleSignals(); BAIL_ON_VMDIR_ERROR(dwError); } VMDIR_LOG_INFO( VMDIR_LOG_MASK_ALL, "Lotus Vmdird: exiting..." ); cleanup: if ( bShutdownKDCService ) { VmKdcServiceShutdown(); VMDIR_LOG_INFO( VMDIR_LOG_MASK_ALL, "Lotus Vmkdcd: stop" ); } if ( bVmDirInit ) { VmDirdStateSet(VMDIRD_STATE_SHUTDOWN); VmDirShutdown(&bWaitTimeOut); if (bWaitTimeOut) { VMDIR_LOG_INFO( VMDIR_LOG_MASK_ALL, "Lotus Vmdird: stop" ); goto done; } VMDIR_LOG_INFO( VMDIR_LOG_MASK_ALL, "Lotus Vmdird: stop" ); } VmDirLogTerminate(); VmDirSrvFreeConfig(); done: return dwError; error: goto cleanup; }