wbcErr wbcInterfaceDetails(struct wbcInterfaceDetails **details) { DWORD dwErr = LW_ERROR_INTERNAL; wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; HANDLE hLsa = NULL; PLSA_MACHINE_ACCOUNT_INFO_A pAccountInfo = NULL; size_t hostnameLen = 0; BAIL_ON_NULL_PTR_PARAM(details, dwErr); /* Find our domain */ dwErr = LsaOpenServer(&hLsa); BAIL_ON_LSA_ERR(dwErr); dwErr = LsaAdGetMachineAccountInfo(hLsa, NULL, &pAccountInfo); BAIL_ON_LSA_ERR(dwErr); *details = _wbc_malloc(sizeof(struct wbcInterfaceDetails), FreeInterfaceDetails); BAIL_ON_NULL_PTR(*details, dwErr); (*details)->interface_version = LSA_WBC_INTERFACE_VERSION; (*details)->winbind_version = LSA_WBC_WINBIND_VERSION; (*details)->winbind_separator = '\\'; (*details)->netbios_name = _wbc_strdup(pAccountInfo->SamAccountName); BAIL_ON_NULL_PTR((*details)->netbios_name, dwErr); // Strip off the trailing dollar sign hostnameLen = strlen((*details)->netbios_name); if (hostnameLen > 0 && (*details)->netbios_name[hostnameLen - 1] == '$') { ((char *)(*details)->netbios_name)[hostnameLen - 1] = 0; } (*details)->netbios_domain = _wbc_strdup(pAccountInfo->NetbiosDomainName); BAIL_ON_NULL_PTR((*details)->netbios_domain, dwErr); (*details)->dns_domain = _wbc_strdup(pAccountInfo->DnsDomainName); BAIL_ON_NULL_PTR((*details)->dns_domain, dwErr); cleanup: if (pAccountInfo) { LsaAdFreeMachineAccountInfo(pAccountInfo); } if (hLsa) { LsaCloseServer(hLsa); } wbc_status = map_error_to_wbc_status(dwErr); return wbc_status; }
static DWORD GetCurrentDomain( OUT PSTR* ppszDnsDomainName ) { DWORD dwError = 0; HANDLE hLsa = NULL; PLSA_MACHINE_ACCOUNT_INFO_A pAccountInfo = NULL; PSTR pszDnsDomainName = NULL; dwError = LsaOpenServer(&hLsa); GOTO_CLEANUP_ON_WINERROR(dwError); dwError = LsaAdGetMachineAccountInfo(hLsa, NULL, &pAccountInfo); GOTO_CLEANUP_ON_WINERROR(dwError); dwError = LwAllocateString( pAccountInfo->DnsDomainName, &pszDnsDomainName); GOTO_CLEANUP_ON_WINERROR(dwError); cleanup: if (dwError) { LW_SAFE_FREE_MEMORY(pszDnsDomainName); } if (hLsa) { LsaCloseServer(hLsa); } if (pAccountInfo) { LsaAdFreeMachineAccountInfo(pAccountInfo); } *ppszDnsDomainName = pszDnsDomainName; return dwError; }
DWORD DeletePassword( PCSTR pSmbdPath ) { DWORD error = 0; PLSA_PSTORE_PLUGIN_DISPATCH pDispatch = NULL; PLSA_PSTORE_PLUGIN_CONTEXT pContext = NULL; PSTR pSecretsPath = NULL; LW_HANDLE hLsa = NULL; PLSA_MACHINE_ACCOUNT_INFO_A pAccountInfo = NULL; HANDLE hReg = NULL; error = LwRegOpenServer(&hReg); BAIL_ON_LSA_ERROR(error); // Even though this was set during the install process, we'll try setting // it again. This way if the user calls uninstall without calling install // first, they won't get an error. error = GetSecretsPath( pSmbdPath, &pSecretsPath); BAIL_ON_LSA_ERROR(error); error = LsaOpenServer( &hLsa); if (error) { LW_RTL_LOG_ERROR("Unable to contact lsassd"); } BAIL_ON_LSA_ERROR(error); error = LsaAdGetMachineAccountInfo( hLsa, NULL, &pAccountInfo); BAIL_ON_LSA_ERROR(error); error = RegUtilAddKey( hReg, LSA_PSTORE_REG_ROOT_KEY_PATH, NULL, LSA_PSTORE_REG_ROOT_KEY_RELATIVE_PATH_PLUGINS "\\" PLUGIN_NAME); BAIL_ON_LSA_ERROR(error); error = RegUtilSetValue( hReg, LSA_PSTORE_REG_ROOT_KEY_PATH, NULL, LSA_PSTORE_REG_ROOT_KEY_RELATIVE_PATH_PLUGINS "\\" PLUGIN_NAME, "SecretsPath", REG_SZ, pSecretsPath, strlen(pSecretsPath)); BAIL_ON_LSA_ERROR(error); error = RemoveSambaLoadPath(hReg); BAIL_ON_LSA_ERROR(error); error = LsaPstorePluginInitializeContext( LSA_PSTORE_PLUGIN_VERSION, PLUGIN_NAME, &pDispatch, &pContext); BAIL_ON_LSA_ERROR(error); error = pDispatch->DeletePasswordInfoA( pContext, pAccountInfo); BAIL_ON_LSA_ERROR(error); cleanup: if (pContext) { pDispatch->Cleanup(pContext); } if (hReg != NULL) { LwRegCloseServer(hReg); } if (hLsa != NULL) { LsaCloseServer(hLsa); } if (pAccountInfo != NULL) { LsaAdFreeMachineAccountInfo(pAccountInfo); } return error; }
static DWORD IDMKrbDetermineJoinState( PIDM_KRB_CONTEXT pKrbContext ) { DWORD dwError = 0; DWORD dwCleanupError = 0; HANDLE hLsa = NULL; PLSA_MACHINE_ACCOUNT_INFO_A pAcctInfo = NULL; PSTR pszAccount = NULL; PSTR pszDomain = NULL; BOOLEAN bLocked = FALSE; dwError = LsaOpenServer(&hLsa); BAIL_ON_ERROR(dwError); dwError = LsaAdGetMachineAccountInfo(hLsa, NULL, &pAcctInfo); BAIL_ON_ERROR(dwError); dwError = IDMAllocateStringA( pAcctInfo->DnsDomainName, &pszDomain); BAIL_ON_ERROR(dwError); dwError = IDMAllocateStringA( pAcctInfo->SamAccountName, &pszAccount); BAIL_ON_ERROR(dwError); IDM_RWMUTEX_LOCK_EXCLUSIVE(&pKrbContext->mutex_rw, bLocked, dwError); BAIL_ON_ERROR(dwError); if (pKrbContext->state == IDM_KRB_CONTEXT_STATE_INITIAL) { IDM_SAFE_FREE_MEMORY(pKrbContext->pszAccount); pKrbContext->pszAccount = pszAccount; pszAccount = NULL; IDM_SAFE_FREE_MEMORY(pKrbContext->pszDomain); pKrbContext->pszDomain = pszDomain; pszDomain = NULL; pKrbContext->expiryTime = 0; pKrbContext->state = IDM_KRB_CONTEXT_STATE_JOINED; } cleanup: IDM_RWMUTEX_UNLOCK(&pKrbContext->mutex_rw, bLocked, dwCleanupError); IDM_SAFE_FREE_MEMORY(pszAccount); IDM_SAFE_FREE_MEMORY(pszDomain); if (pAcctInfo) { LsaAdFreeMachineAccountInfo(pAcctInfo); } if (hLsa) { LsaCloseServer(hLsa); } if(!dwError) { dwError = dwCleanupError; } return dwError; error: dwError = ERROR_NOT_JOINED; goto cleanup; }