static void PrintError( DWORD dwError ) { PSTR pszErrorMsg = NULL; if (!VmAfdGetErrorString(dwError, &pszErrorMsg)) { fprintf(stderr, "vecs-cli failed. Error %u: %s \n", dwError, pszErrorMsg); } else { fprintf(stderr, "vecs-cli failed with error %u\n", dwError); } VMAFD_SAFE_FREE_STRINGA(pszErrorMsg); }
int main(int argc, char* argv[]) { DWORD dwError = 0; int retCode = 0; PSTR pszDomain = NULL; PSTR pszDomainName = NULL; PSTR pszUserName = NULL; PSTR pszPassword = NULL; PSTR pszPwdFile = NULL; PSTR pszSiteName = NULL; PSTR pszPartnerHostName = NULL; PSTR pszLotusServerName = NULL; PSTR pszPasswordBuf = NULL; FILE * fpPwdFile = NULL; PSTR pszPath = NULL; PSTR pszLogPathName = NULL; size_t dPwdLen = 0; BOOL bLogInitialized = FALSE; PCSTR pszErrorMsg = NULL; PSTR pszErrorDesc = NULL; PCSTR pszLocalhost = "localhost"; PSTR pszPnid = NULL; DNS_INIT_FLAG dnsInitFlag = DNS_NONE; #ifdef _WIN32 WSADATA wsaData = { 0 }; BOOLEAN bWsaStartup = FALSE; #endif #ifndef _WIN32 setlocale(LC_ALL, ""); #else dwError = WSAStartup(MAKEWORD(2, 2), &wsaData); BAIL_ON_VMAFD_ERROR(dwError); bWsaStartup = TRUE; #endif dwError = VmAfCfgInit(); BAIL_ON_VMAFD_ERROR(dwError); #ifndef _WIN32 dwError = VmAfdAllocateStringA(VMAFD_LOG_PATH, &pszLogPathName ); BAIL_ON_VMAFD_ERROR(dwError); #else dwError = VmAfdConfigGetString(VMAFD_SOFTWARE_KEY_PATH, VMAFD_LOGPATH_KEY_VALUE, &pszLogPathName); BAIL_ON_VMAFD_ERROR(dwError); #endif dwError = VmAfdAllocateStringAVsnprintf( &pszPath, "%s%s", pszLogPathName, "vdcpromo.log" ); BAIL_ON_VMAFD_ERROR(dwError); dwError = VmAfdLogInitialize(pszPath, 0, 0); BAIL_ON_VMAFD_ERROR(dwError); bLogInitialized = TRUE; dwError = VmAfdParseArgs(argc, argv, &pszDomain, &pszUserName, &pszPassword, &pszSiteName, &pszPartnerHostName, &pszLotusServerName, &pszPwdFile, &dnsInitFlag); if (dwError) { ShowUsage(); BAIL_ON_VMAFD_ERROR(dwError); } if (IsNullOrEmptyString(pszUserName)) { VmAfdLog(VMAFD_DEBUG_ANY, "Username parameter is not valid"); } else { VmAfdLog(VMAFD_DEBUG_ANY, "Username: \"%s\"", pszUserName); } if (!pszPwdFile && IsNullOrEmptyString(pszPassword)) { VmAfdLog(VMAFD_DEBUG_ANY, "Password parameter is not valid"); } if (IsNullOrEmptyString(pszDomain)) { VmAfdLog(VMAFD_DEBUG_ANY, "Domain parameter is not valid"); } else { VmAfdLog(VMAFD_DEBUG_ANY, "Domain: \"%s\"", pszDomain); } dwError = VmAfdAllocateMemory(VMAFD_MAX_PWD_LEN+1, (PVOID *)&pszPasswordBuf); BAIL_ON_VMAFD_ERROR(dwError); if (pszPassword == NULL && pszPwdFile != NULL) { dwError = VmAfdOpenFilePath(pszPwdFile, "rb", &fpPwdFile); if (dwError != ERROR_SUCCESS) { printf("vdcpromo: cannot open password file %s (%u)\n", pszPwdFile, dwError); dwError = ERROR_LOCAL_PASSWORDFILE_CANNOT_OPEN; BAIL_ON_VMAFD_ERROR(dwError); } if ( (dPwdLen = fread(pszPasswordBuf, 1, VMAFD_MAX_PWD_LEN, fpPwdFile)) == 0) { dwError = ERROR_LOCAL_PASSWORDFILE_CANNOT_READ; printf("vdcpromo: Could not read password file\n"); BAIL_ON_VMAFD_ERROR(dwError); } if (*pszPasswordBuf == '\0') { VmAfdLog(VMAFD_DEBUG_ANY, "password is empty"); dwError = ERROR_LOCAL_PASSWORD_EMPTY; BAIL_ON_VMAFD_ERROR(dwError); } } else if (pszPassword != NULL && pszPwdFile == NULL) { dwError = VmAfdStringCpyA(pszPasswordBuf, VMAFD_MAX_PWD_LEN, pszPassword); BAIL_ON_VMAFD_ERROR(dwError); } else //no password nor password-file, read password from stdin { VmAfdReadString("password: "******"Warning: failed to initialize DNS. Error [%d]\n", dwError); } else { fprintf(stdout, "Successfully initialized DNS.\n"); } BAIL_ON_VMAFD_ERROR(dwError); goto cleanup; } printf("Initializing Directory server instance ... \n"); fflush(stdout); dwError = VmAfdPromoteVmDirA( pszLotusServerName ? pszLotusServerName : pszLocalhost, pszDomain, pszUserName, pszPasswordBuf, pszSiteName, pszPartnerHostName); BAIL_ON_VMAFD_ERROR(dwError); printf("Directory host instance created successfully\n"); cleanup: VmAfCfgShutdown(); if (bLogInitialized) { VmAfdLogTerminate(); } #ifdef _WIN32 if (bWsaStartup != FALSE) { WSACleanup(); } #endif VMAFD_SAFE_FREE_MEMORY(pszPnid); VMAFD_SAFE_FREE_MEMORY(pszPasswordBuf); VMAFD_SAFE_FREE_MEMORY(pszPath); VMAFD_SAFE_FREE_MEMORY(pszLogPathName); VMAFD_SAFE_FREE_MEMORY(pszErrorDesc); VMAFD_SAFE_FREE_MEMORY(pszDomainName); return retCode; error: switch (dwError) { case ERROR_LOCAL_OPTION_UNKNOWN: retCode = 2; pszErrorMsg = "An unknown option was present on the command line."; break; case ERROR_LOCAL_OPTION_INVALID: retCode = 3; pszErrorMsg = "The options present on the command line are not valid."; break; case ERROR_LOCAL_PASSWORDFILE_CANNOT_OPEN: retCode = 4; pszErrorMsg = "Could not open password file.\nVerify the path is correct."; break; case ERROR_LOCAL_PASSWORDFILE_CANNOT_READ: retCode = 5; pszErrorMsg = "Problem reading password file.\nVerify contents of password file."; break; case ERROR_LOCAL_PASSWORD_EMPTY: retCode = 6; pszErrorMsg = "Invalid password; password cannot be empty."; break; case ERROR_CANNOT_CONNECT_VMAFD: retCode = 20; pszErrorMsg = "Could not connect to the local service VMware AFD.\nVerify VMware AFD is running."; break; case VMDIR_ERROR_CANNOT_CONNECT_VMDIR: retCode = 21; pszErrorMsg = "Could not connect to the local service VMware Directory Service.\nVerify VMware Directory Service is running."; break; case ERROR_INVALID_CONFIGURATION: retCode = 22; pszErrorMsg = "Configuration is not correct.\nFirst boot scripts need to be executed."; break; case VMDIR_ERROR_SERVER_DOWN: retCode = 23; pszErrorMsg = "Could not connect to VMware Directory Service via LDAP.\nVerify VMware Directory Service is running on the appropriate system and is reachable from this host."; break; case VMDIR_ERROR_USER_INVALID_CREDENTIAL: retCode = 24; pszErrorMsg = "Authentication to VMware Directory Service failed.\nVerify the username and password."; break; case ERROR_ACCESS_DENIED: retCode = 25; pszErrorMsg = "Authorization failed.\nVerify account has proper administrative privileges."; break; case VMDIR_ERROR_SCHEMA_NOT_COMPATIBLE: retCode = 26; pszErrorMsg = "Could not join to the remote service VMWare Directory Service.\nThe remote schema is incompatible with the local schema."; break; default: retCode = 1; } if (bLogInitialized) { if (pszErrorMsg == NULL) { VmAfdLog(VMAFD_DEBUG_ANY, "Vdcpromo failed. Error[%d]", dwError); } else { VmAfdLog(VMAFD_DEBUG_ANY, "Vdcpromo failed. Error[%d]\n%s", dwError, pszErrorMsg); } } if (pszErrorMsg == NULL) { if (!VmAfdGetErrorString(dwError, &pszErrorDesc)) { printf("Vdcpromo failed. Error %d: %s\n", dwError, pszErrorDesc); } else { printf("Vdcpromo failed. Error %d.\n", dwError); } } else { printf("Vdcpromo failed. Error[%d]\n%s\n", dwError, pszErrorMsg); } goto cleanup; }
int _tmain(int argc, _TCHAR* targv[]) #endif { DWORD dwError = 0; int retCode = 0; PCSTR pszErrorMsg = NULL; PSTR pszErrorDesc = NULL; #ifdef _WIN32 char** allocArgv = NULL; PSTR* argv = NULL; #ifdef UNICODE dwError = VmAfdAllocateArgsAFromArgsW( argc, targv, &allocArgv ); BAIL_ON_VMAFD_ERROR(dwError); argv = allocArgv; #else /* ifndef UNICODE */ argv = targv; // non-unicode => targv is char #endif /* ifdef UNICODE */ #else /* ifndef _WIN32 */ setlocale(LC_ALL, ""); #endif /* ifdef _WIN32 */ dwError = ProcessArgs(argc, argv); BAIL_ON_VMAFD_ERROR(dwError); cleanup: VMAFD_SAFE_FREE_STRINGA(pszErrorDesc); return dwError; error: switch (dwError) { case ERROR_CANNOT_CONNECT_VMAFD: retCode = 20; pszErrorMsg = "Could not connect to the local service VMware AFD.\nVerify VMware AFD is running."; break; case VMDIR_ERROR_CANNOT_CONNECT_VMDIR: retCode = 21; pszErrorMsg = "Could not connect to the local service VMware Directory Service.\nVerify VMware Directory Service is running."; break; case ERROR_INVALID_CONFIGURATION: retCode = 22; pszErrorMsg = "Configuration is not correct.\nFirst boot scripts need to be executed."; break; case VMDIR_ERROR_SERVER_DOWN: retCode = 23; pszErrorMsg = "Could not connect to VMware Directory Service via LDAP.\nVerify VMware Directory Service is running on the appropriate system and is reachable from this host."; break; case VMDIR_ERROR_USER_INVALID_CREDENTIAL: retCode = 24; pszErrorMsg = "Authentication to VMware Directory Service failed.\nVerify the username and password."; break; case ERROR_ACCESS_DENIED: retCode = 25; pszErrorMsg = "Authorization failed.\nVerify account has proper administrative privileges."; break; case ERROR_INVALID_DOMAINNAME: retCode = 26; pszErrorMsg = "Failed to join the domain.\nThe domain name specified is invalid."; break; case ERROR_NO_SUCH_DOMAIN: retCode = 27; pszErrorMsg = "Failed to join the domain.\nA domain controller for the domain could not be located. Verify the DNS settings pertaining to this domain name."; break; case ERROR_PASSWORD_RESTRICTION: retCode = 28; pszErrorMsg = "Failed to join the domain.\nA required password was not specified or did not match complexity requirements."; break; case ERROR_HOST_DOWN: retCode = 29; pszErrorMsg = "Failed to join the domain.\nThe required service on the domain controller is unreachable."; break; default: retCode = 1; } if (retCode != 1) { fprintf( stderr, "domain-join failed, error= %s %u\n", pszErrorMsg, dwError); } else { if (!VmAfdGetErrorString(dwError, &pszErrorDesc)) { fprintf(stderr, "domain-join failed. Error %u: %s \n", dwError, pszErrorDesc); } else { fprintf(stderr, "domain-join failed with error: %u\n", dwError); } } goto cleanup; }