DWORD LWSetConfigValueBySectionName( PCFGSECTION pSectionList, PCSTR pszSectionName, PCSTR pszName, PCSTR pszValue ) { DWORD dwError = 0; PCFGSECTION pSection = NULL; if (IsNullOrEmptyString(pszSectionName) || IsNullOrEmptyString(pszName)) { dwError = MAC_AD_ERROR_INVALID_PARAMETER; BAIL_ON_MAC_ERROR(dwError); } while (pSectionList) { if (!strcmp(pSectionList->pszName, pszSectionName)) { pSection = pSectionList; break; } pSectionList = pSectionList->pNext; } if (!pSection) { dwError = MAC_AD_ERROR_INVALID_RECORD_TYPE; goto error; } dwError = LWSetConfigValueBySection(pSection, pszName, pszValue); BAIL_ON_MAC_ERROR(dwError); cleanup: return dwError; error: goto cleanup; }
DWORD CacheUserAttributes( uid_t uid, PGPUSER_AD_ATTRS pUserADAttrs ) { DWORD dwError = MAC_AD_ERROR_SUCCESS; PSTR pszFileDir = NULL; PSTR pszFilePath = NULL; PCFGSECTION pUserSettingsList = NULL; PCFGSECTION pADSection_Name = NULL; PCFGSECTION pADSection_EMail = NULL; PCFGSECTION pADSection_Phone = NULL; PCFGSECTION pADSection_Address = NULL; PCFGSECTION pADSection_Work = NULL; PCFGSECTION pADSection_Network = NULL; BOOLEAN bDirExists = FALSE; LOG("Saving user attributes to user logon cache [uid: %ld, display name: %s]", (long)uid, pUserADAttrs->pszDisplayName ? pUserADAttrs->pszDisplayName : "<null>"); dwError = LwAllocateStringPrintf(&pszFileDir, "/var/lib/pbis/lwedsplugin/user-cache/%ld", (long) uid); BAIL_ON_MAC_ERROR(dwError); dwError = LwAllocateStringPrintf(&pszFilePath, "/var/lib/pbis/lwedsplugin/user-cache/%ld/ad-user-attrs", (long) uid); BAIL_ON_MAC_ERROR(dwError); dwError = LwCheckFileTypeExists(pszFileDir, LWFILE_DIRECTORY, &bDirExists); BAIL_ON_MAC_ERROR(dwError); if (bDirExists == FALSE) { dwError = LwCreateDirectory(pszFileDir, S_IRUSR|S_IRGRP|S_IROTH); BAIL_ON_MAC_ERROR(dwError); } dwError = LWCreateConfigSection(&pUserSettingsList, &pADSection_Name, "User AD Name Attributes"); BAIL_ON_MAC_ERROR(dwError); dwError = LWCreateConfigSection(&pADSection_EMail, &pADSection_EMail, "User AD EMail Attributes"); BAIL_ON_MAC_ERROR(dwError); dwError = LWCreateConfigSection(&pADSection_Phone, &pADSection_Phone, "User AD Phone Attributes"); BAIL_ON_MAC_ERROR(dwError); dwError = LWCreateConfigSection(&pADSection_Address, &pADSection_Address, "User AD Address Attributes"); BAIL_ON_MAC_ERROR(dwError); dwError = LWCreateConfigSection(&pADSection_Work, &pADSection_Work, "User AD Work Attributes"); BAIL_ON_MAC_ERROR(dwError); dwError = LWCreateConfigSection(&pADSection_Network, &pADSection_Network, "User AD Network Settings Attributes"); BAIL_ON_MAC_ERROR(dwError); pADSection_Name->pNext = pADSection_EMail; pADSection_EMail->pNext = pADSection_Phone; pADSection_Phone->pNext = pADSection_Address; pADSection_Address->pNext = pADSection_Work; pADSection_Work->pNext = pADSection_Network; if (pUserADAttrs->pszDisplayName) { dwError = LWSetConfigValueBySection(pUserSettingsList, "displayName", pUserADAttrs->pszDisplayName); BAIL_ON_MAC_ERROR(dwError); } if (pUserADAttrs->pszFirstName) { dwError = LWSetConfigValueBySection(pADSection_Name, "givenName", pUserADAttrs->pszFirstName); BAIL_ON_MAC_ERROR(dwError); } if (pUserADAttrs->pszLastName) { dwError = LWSetConfigValueBySection(pADSection_Name, "sn", pUserADAttrs->pszLastName); BAIL_ON_MAC_ERROR(dwError); } if (pUserADAttrs->pszADDomain) { dwError = LWSetConfigValueBySection(pADSection_Name, "userDomain", pUserADAttrs->pszADDomain); BAIL_ON_MAC_ERROR(dwError); } if (pUserADAttrs->pszKerberosPrincipal) { dwError = LWSetConfigValueBySection(pADSection_Name, "userPrincipalName", pUserADAttrs->pszKerberosPrincipal); BAIL_ON_MAC_ERROR(dwError); } if (pUserADAttrs->pszEMailAddress) { dwError = LWSetConfigValueBySection(pADSection_EMail, "mail", pUserADAttrs->pszEMailAddress); BAIL_ON_MAC_ERROR(dwError); } if (pUserADAttrs->pszMSExchHomeServerName) { dwError = LWSetConfigValueBySection(pADSection_EMail, "msExchHomeServerName", pUserADAttrs->pszMSExchHomeServerName); BAIL_ON_MAC_ERROR(dwError); } if (pUserADAttrs->pszMSExchHomeMDB) { dwError = LWSetConfigValueBySection(pADSection_EMail, "homeMDB", pUserADAttrs->pszMSExchHomeMDB); BAIL_ON_MAC_ERROR(dwError); } if (pUserADAttrs->pszTelephoneNumber) { dwError = LWSetConfigValueBySection(pADSection_Phone, "telephoneNumber", pUserADAttrs->pszTelephoneNumber); BAIL_ON_MAC_ERROR(dwError); } if (pUserADAttrs->pszFaxTelephoneNumber) { dwError = LWSetConfigValueBySection(pADSection_Phone, "facsimileTelephoneNumber", pUserADAttrs->pszFaxTelephoneNumber); BAIL_ON_MAC_ERROR(dwError); } if (pUserADAttrs->pszMobileTelephoneNumber) { dwError = LWSetConfigValueBySection(pADSection_Phone, "mobile", pUserADAttrs->pszMobileTelephoneNumber); BAIL_ON_MAC_ERROR(dwError); } if (pUserADAttrs->pszStreetAddress) { dwError = LWSetConfigValueBySection(pADSection_Address, "streetAddress", pUserADAttrs->pszStreetAddress); BAIL_ON_MAC_ERROR(dwError); } if (pUserADAttrs->pszPostOfficeBox) { dwError = LWSetConfigValueBySection(pADSection_Address, "postOfficeBox", pUserADAttrs->pszPostOfficeBox); BAIL_ON_MAC_ERROR(dwError); } if (pUserADAttrs->pszCity) { dwError = LWSetConfigValueBySection(pADSection_Address, "l", pUserADAttrs->pszCity); BAIL_ON_MAC_ERROR(dwError); } if (pUserADAttrs->pszState) { dwError = LWSetConfigValueBySection(pADSection_Address, "st", pUserADAttrs->pszState); BAIL_ON_MAC_ERROR(dwError); } if (pUserADAttrs->pszPostalCode) { dwError = LWSetConfigValueBySection(pADSection_Address, "postalCode", pUserADAttrs->pszPostalCode); BAIL_ON_MAC_ERROR(dwError); } if (pUserADAttrs->pszCountry) { dwError = LWSetConfigValueBySection(pADSection_Address, "co", pUserADAttrs->pszCountry); BAIL_ON_MAC_ERROR(dwError); } if (pUserADAttrs->pszTitle) { dwError = LWSetConfigValueBySection(pADSection_Work, "title", pUserADAttrs->pszTitle); BAIL_ON_MAC_ERROR(dwError); } if (pUserADAttrs->pszCompany) { dwError = LWSetConfigValueBySection(pADSection_Work, "company", pUserADAttrs->pszCompany); BAIL_ON_MAC_ERROR(dwError); } if (pUserADAttrs->pszDepartment) { dwError = LWSetConfigValueBySection(pADSection_Work, "department", pUserADAttrs->pszDepartment); BAIL_ON_MAC_ERROR(dwError); } if (pUserADAttrs->pszHomeDirectory) { dwError = LWSetConfigValueBySection(pADSection_Network, "homeDirectory", pUserADAttrs->pszHomeDirectory); BAIL_ON_MAC_ERROR(dwError); } if (pUserADAttrs->pszHomeDrive) { dwError = LWSetConfigValueBySection(pADSection_Network, "homeDrive", pUserADAttrs->pszHomeDrive); BAIL_ON_MAC_ERROR(dwError); } if (pUserADAttrs->pszPasswordLastSet) { dwError = LWSetConfigValueBySection(pADSection_Network, "pwdLastSet", pUserADAttrs->pszPasswordLastSet); BAIL_ON_MAC_ERROR(dwError); } if (pUserADAttrs->pszUserAccountControl) { dwError = LWSetConfigValueBySection(pADSection_Network, "userAccountControl", pUserADAttrs->pszUserAccountControl); BAIL_ON_MAC_ERROR(dwError); } if (pUserADAttrs->pszMaxMinutesUntilChangePassword) { dwError = LWSetConfigValueBySection(pADSection_Network, "maxPwdAge", pUserADAttrs->pszMaxMinutesUntilChangePassword); BAIL_ON_MAC_ERROR(dwError); } if (pUserADAttrs->pszMinMinutesUntilChangePassword) { dwError = LWSetConfigValueBySection(pADSection_Network, "minPwdAge", pUserADAttrs->pszMinMinutesUntilChangePassword); BAIL_ON_MAC_ERROR(dwError); } if (pUserADAttrs->pszMaxFailedLoginAttempts) { dwError = LWSetConfigValueBySection(pADSection_Network, "lockoutThreshhold", pUserADAttrs->pszMaxFailedLoginAttempts); BAIL_ON_MAC_ERROR(dwError); } if (pUserADAttrs->pszAllowedPasswordHistory) { dwError = LWSetConfigValueBySection(pADSection_Network, "pwdHistoryLength", pUserADAttrs->pszAllowedPasswordHistory); BAIL_ON_MAC_ERROR(dwError); } if (pUserADAttrs->pszMinCharsAllowedInPassword) { dwError = LWSetConfigValueBySection(pADSection_Network, "minPwdLength", pUserADAttrs->pszMinCharsAllowedInPassword); BAIL_ON_MAC_ERROR(dwError); } dwError = LWSaveConfigSectionList(pszFilePath, pUserSettingsList); BAIL_ON_MAC_ERROR(dwError); error: LW_SAFE_FREE_STRING(pszFilePath); LW_SAFE_FREE_STRING(pszFileDir); LWFreeConfigSectionList(pUserSettingsList); pUserSettingsList = NULL; return dwError; }