/lsass/common/utils/lsapam.c

https://github.com/BeyondTrust/pbis-open · C · 152 lines · 98 code · 30 blank · 24 comment · 5 complexity · b698eeb7c915345f2a8157fadf47f312 MD5 · raw file

  1. /*
  2. * Copyright © BeyondTrust Software 2004 - 2019
  3. * All rights reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. * BEYONDTRUST MAKES THIS SOFTWARE AVAILABLE UNDER OTHER LICENSING TERMS AS
  18. * WELL. IF YOU HAVE ENTERED INTO A SEPARATE LICENSE AGREEMENT WITH
  19. * BEYONDTRUST, THEN YOU MAY ELECT TO USE THE SOFTWARE UNDER THE TERMS OF THAT
  20. * SOFTWARE LICENSE AGREEMENT INSTEAD OF THE TERMS OF THE APACHE LICENSE,
  21. * NOTWITHSTANDING THE ABOVE NOTICE. IF YOU HAVE QUESTIONS, OR WISH TO REQUEST
  22. * A COPY OF THE ALTERNATE LICENSING TERMS OFFERED BY BEYONDTRUST, PLEASE CONTACT
  23. * BEYONDTRUST AT beyondtrust.com/contact
  24. */
  25. #include "includes.h"
  26. #define LSA_PAM_LOGON_RIGHTS_DENIED_MESSAGE "Access denied"
  27. #define LSA_PAM_ACTIVE_DIRECTORY_PASSWORD_PROMPT "Active Directory Password: "
  28. #define LSA_PAM_LOCAL_PASSWORD_PROMPT "Unix Password: "
  29. #define LSA_PAM_OTHER_PASSWORD_PROMPT "Other Password: "
  30. DWORD
  31. LsaUtilAllocatePamConfig(
  32. OUT PLSA_PAM_CONFIG *ppConfig
  33. )
  34. {
  35. DWORD dwError = 0;
  36. PLSA_PAM_CONFIG pConfig = NULL;
  37. dwError = LwAllocateMemory(
  38. sizeof(LSA_PAM_CONFIG),
  39. OUT_PPVOID(&pConfig));
  40. BAIL_ON_LSA_ERROR(dwError);
  41. dwError = LsaUtilInitializePamConfig(pConfig);
  42. BAIL_ON_LSA_ERROR(dwError);
  43. cleanup:
  44. *ppConfig = pConfig;
  45. return dwError;
  46. error:
  47. if (pConfig)
  48. {
  49. LsaUtilFreePamConfig(pConfig);
  50. pConfig = NULL;
  51. }
  52. goto cleanup;
  53. }
  54. DWORD
  55. LsaUtilInitializePamConfig(
  56. OUT PLSA_PAM_CONFIG pConfig
  57. )
  58. {
  59. DWORD dwError = 0;
  60. memset(pConfig, 0, sizeof(LSA_PAM_CONFIG));
  61. pConfig->bLsaPamDisplayMOTD = FALSE;
  62. pConfig->dwLogLevel = LSA_PAM_LOG_LEVEL_ERROR;
  63. dwError = LwAllocateString(
  64. LSA_PAM_LOGON_RIGHTS_DENIED_MESSAGE,
  65. &pConfig->pszAccessDeniedMessage);
  66. BAIL_ON_LSA_ERROR(dwError);
  67. dwError = LwAllocateString(
  68. LSA_PAM_ACTIVE_DIRECTORY_PASSWORD_PROMPT,
  69. &pConfig->pszActiveDirectoryPasswordPrompt);
  70. BAIL_ON_LSA_ERROR(dwError);
  71. dwError = LwAllocateString(
  72. LSA_PAM_LOCAL_PASSWORD_PROMPT,
  73. &pConfig->pszLocalPasswordPrompt);
  74. BAIL_ON_LSA_ERROR(dwError);
  75. dwError = LwAllocateString(
  76. LSA_PAM_OTHER_PASSWORD_PROMPT,
  77. &pConfig->pszOtherPasswordPrompt);
  78. pConfig->bNssApplyAccessControl = FALSE;
  79. cleanup:
  80. return dwError;
  81. error:
  82. LsaUtilFreePamConfigContents(pConfig);
  83. goto cleanup;
  84. }
  85. VOID
  86. LsaUtilFreePamConfig(
  87. IN PLSA_PAM_CONFIG pConfig
  88. )
  89. {
  90. LsaUtilFreePamConfigContents(pConfig);
  91. LW_SAFE_FREE_MEMORY(pConfig);
  92. }
  93. VOID
  94. LsaUtilFreePamConfigContents(
  95. IN PLSA_PAM_CONFIG pConfig
  96. )
  97. {
  98. if (pConfig)
  99. {
  100. DWORD i;
  101. LW_SAFE_FREE_STRING(pConfig->pszAccessDeniedMessage);
  102. LW_SAFE_FREE_STRING(pConfig->pszActiveDirectoryPasswordPrompt);
  103. LW_SAFE_FREE_STRING(pConfig->pszLocalPasswordPrompt);
  104. LW_SAFE_FREE_STRING(pConfig->pszOtherPasswordPrompt);
  105. for (i = 0; i < pConfig->dwNumSmartCardServices; ++i)
  106. {
  107. LW_SAFE_FREE_STRING(pConfig->ppszSmartCardServices[i]);
  108. }
  109. LW_SAFE_FREE_MEMORY(pConfig->ppszSmartCardServices);
  110. for (i = 0; i < pConfig->dwNumSmartCardRemoteServices; ++i)
  111. {
  112. LW_SAFE_FREE_STRING(pConfig->ppszSmartCardRemoteServices[i]);
  113. }
  114. LW_SAFE_FREE_MEMORY(pConfig->ppszSmartCardRemoteServices);
  115. for (i = 0; i < pConfig->dwNumSmartCardPromptGecos; ++i)
  116. {
  117. LW_SAFE_FREE_STRING(pConfig->ppszSmartCardPromptGecos[i]);
  118. }
  119. LW_SAFE_FREE_MEMORY(pConfig->ppszSmartCardPromptGecos);
  120. memset(pConfig, 0, sizeof(LSA_PAM_CONFIG));
  121. }
  122. }