/lsass/server/rpc/samr/samr_cfg.c

https://github.com/BeyondTrust/pbis-open · C · 324 lines · 218 code · 56 blank · 50 comment · 5 complexity · 8e11e4a769647749ef7be53ca2f93b53 MD5 · raw file

  1. /* Editor Settings: expandtabs and use 4 spaces for indentation
  2. * ex: set softtabstop=4 tabstop=8 expandtab shiftwidth=4: *
  3. */
  4. /*
  5. * Copyright © BeyondTrust Software 2004 - 2019
  6. * All rights reserved.
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. *
  20. * BEYONDTRUST MAKES THIS SOFTWARE AVAILABLE UNDER OTHER LICENSING TERMS AS
  21. * WELL. IF YOU HAVE ENTERED INTO A SEPARATE LICENSE AGREEMENT WITH
  22. * BEYONDTRUST, THEN YOU MAY ELECT TO USE THE SOFTWARE UNDER THE TERMS OF THAT
  23. * SOFTWARE LICENSE AGREEMENT INSTEAD OF THE TERMS OF THE APACHE LICENSE,
  24. * NOTWITHSTANDING THE ABOVE NOTICE. IF YOU HAVE QUESTIONS, OR WISH TO REQUEST
  25. * A COPY OF THE ALTERNATE LICENSING TERMS OFFERED BY BEYONDTRUST, PLEASE CONTACT
  26. * BEYONDTRUST AT beyondtrust.com/contact
  27. */
  28. /*
  29. * Copyright (C) BeyondTrust Software. All rights reserved.
  30. *
  31. * Module Name:
  32. *
  33. * samr_cfg.c
  34. *
  35. * Abstract:
  36. *
  37. * Remote Procedure Call (RPC) Server Interface
  38. *
  39. * Samr rpc server configuration
  40. *
  41. * Authors: Rafal Szczesniak (rafal@likewise.com)
  42. */
  43. #include "includes.h"
  44. DWORD
  45. SamrSrvInitialiseConfig(
  46. PSAMR_SRV_CONFIG pConfig
  47. )
  48. {
  49. DWORD dwError = 0;
  50. memset(pConfig, 0, sizeof(*pConfig));
  51. dwError = LwAllocateString(
  52. SAMR_RPC_CFG_DEFAULT_LPC_SOCKET_PATH,
  53. &pConfig->pszLpcSocketPath);
  54. BAIL_ON_LSA_ERROR(dwError);
  55. dwError = LwAllocateString(
  56. SAMR_RPC_CFG_DEFAULT_LOGIN_SHELL,
  57. &pConfig->pszDefaultLoginShell);
  58. BAIL_ON_LSA_ERROR(dwError);
  59. dwError = LwAllocateString(
  60. SAMR_RPC_CFG_DEFAULT_HOMEDIR_PREFIX,
  61. &pConfig->pszHomedirPrefix);
  62. BAIL_ON_LSA_ERROR(dwError);
  63. dwError = LwAllocateString(
  64. SAMR_RPC_CFG_DEFAULT_HOMEDIR_TEMPLATE,
  65. &pConfig->pszHomedirTemplate);
  66. BAIL_ON_LSA_ERROR(dwError);
  67. pConfig->bRegisterTcpIp = FALSE;
  68. cleanup:
  69. return dwError;
  70. error:
  71. SamrSrvFreeConfigContents(pConfig);
  72. goto cleanup;
  73. }
  74. VOID
  75. SamrSrvFreeConfigContents(
  76. PSAMR_SRV_CONFIG pConfig
  77. )
  78. {
  79. if (pConfig)
  80. {
  81. LW_SAFE_FREE_STRING(pConfig->pszLpcSocketPath);
  82. LW_SAFE_FREE_STRING(pConfig->pszDefaultLoginShell);
  83. LW_SAFE_FREE_STRING(pConfig->pszHomedirPrefix);
  84. LW_SAFE_FREE_STRING(pConfig->pszHomedirTemplate);
  85. }
  86. }
  87. DWORD
  88. SamrSrvReadRegistry(
  89. PSAMR_SRV_CONFIG pConfig
  90. )
  91. {
  92. DWORD dwError = 0;
  93. LWREG_CONFIG_ITEM Config[] =
  94. {
  95. {
  96. "LpcSocketPath",
  97. FALSE,
  98. LwRegTypeString,
  99. 0,
  100. MAXDWORD,
  101. NULL,
  102. &pConfig->pszLpcSocketPath,
  103. NULL
  104. },
  105. {
  106. "LoginShellTemplate",
  107. TRUE,
  108. LwRegTypeString,
  109. 0,
  110. MAXDWORD,
  111. NULL,
  112. &pConfig->pszDefaultLoginShell,
  113. NULL
  114. },
  115. {
  116. "HomeDirPrefix",
  117. TRUE,
  118. LwRegTypeString,
  119. 0,
  120. MAXDWORD,
  121. NULL,
  122. &pConfig->pszHomedirPrefix,
  123. NULL
  124. },
  125. {
  126. "HomeDirTemplate",
  127. TRUE,
  128. LwRegTypeString,
  129. 0,
  130. MAXDWORD,
  131. NULL,
  132. &pConfig->pszHomedirTemplate,
  133. NULL
  134. },
  135. {
  136. "RegisterTcpIp",
  137. TRUE,
  138. LwRegTypeBoolean,
  139. 0,
  140. MAXDWORD,
  141. NULL,
  142. &pConfig->bRegisterTcpIp,
  143. NULL
  144. },
  145. };
  146. dwError = RegProcessConfig(
  147. "Services\\lsass\\Parameters\\RPCServers\\samr",
  148. "Policy\\Services\\lsass\\Parameters\\RPCServers\\samr",
  149. Config,
  150. sizeof(Config)/sizeof(Config[0]));
  151. BAIL_ON_LSA_ERROR(dwError);
  152. cleanup:
  153. return dwError;
  154. error:
  155. goto cleanup;
  156. }
  157. DWORD
  158. SamrSrvConfigGetLpcSocketPath(
  159. PSTR *ppszLpcSocketPath
  160. )
  161. {
  162. DWORD dwError = 0;
  163. BOOL bLocked = 0;
  164. PSTR pszLpcSocketPath = NULL;
  165. GLOBAL_DATA_LOCK(bLocked);
  166. if (LW_IS_NULL_OR_EMPTY_STR(gSamrSrvConfig.pszLpcSocketPath)) {
  167. goto cleanup;
  168. }
  169. dwError = LwAllocateString(gSamrSrvConfig.pszLpcSocketPath,
  170. &pszLpcSocketPath);
  171. BAIL_ON_LSA_ERROR(dwError);
  172. *ppszLpcSocketPath = pszLpcSocketPath;
  173. cleanup:
  174. GLOBAL_DATA_UNLOCK(bLocked);
  175. return dwError;
  176. error:
  177. goto cleanup;
  178. }
  179. DWORD
  180. SamrSrvConfigGetDefaultLoginShell(
  181. PSTR *ppszDefaultLoginShell
  182. )
  183. {
  184. DWORD dwError = 0;
  185. BOOL bLocked = 0;
  186. PSTR pszDefaultLoginShell = NULL;
  187. GLOBAL_DATA_LOCK(bLocked);
  188. if (LW_IS_NULL_OR_EMPTY_STR(gSamrSrvConfig.pszDefaultLoginShell)) {
  189. goto cleanup;
  190. }
  191. dwError = LwAllocateString(gSamrSrvConfig.pszDefaultLoginShell,
  192. &pszDefaultLoginShell);
  193. BAIL_ON_LSA_ERROR(dwError);
  194. *ppszDefaultLoginShell = pszDefaultLoginShell;
  195. cleanup:
  196. GLOBAL_DATA_UNLOCK(bLocked);
  197. return dwError;
  198. error:
  199. goto cleanup;
  200. }
  201. DWORD
  202. SamrSrvConfigGetHomedirPrefix(
  203. PSTR *ppszHomedirPrefix
  204. )
  205. {
  206. DWORD dwError = 0;
  207. BOOL bLocked = 0;
  208. PSTR pszHomedirPrefix = NULL;
  209. GLOBAL_DATA_LOCK(bLocked);
  210. if (LW_IS_NULL_OR_EMPTY_STR(gSamrSrvConfig.pszHomedirPrefix)) {
  211. goto cleanup;
  212. }
  213. dwError = LwAllocateString(gSamrSrvConfig.pszHomedirPrefix,
  214. &pszHomedirPrefix);
  215. BAIL_ON_LSA_ERROR(dwError);
  216. *ppszHomedirPrefix = pszHomedirPrefix;
  217. cleanup:
  218. GLOBAL_DATA_UNLOCK(bLocked);
  219. return dwError;
  220. error:
  221. goto cleanup;
  222. }
  223. DWORD
  224. SamrSrvConfigGetHomedirTemplate(
  225. PSTR *ppszHomedirTemplate
  226. )
  227. {
  228. DWORD dwError = 0;
  229. BOOL bLocked = 0;
  230. PSTR pszHomedirTemplate = NULL;
  231. GLOBAL_DATA_LOCK(bLocked);
  232. if (LW_IS_NULL_OR_EMPTY_STR(gSamrSrvConfig.pszHomedirTemplate)) {
  233. goto cleanup;
  234. }
  235. dwError = LwAllocateString(gSamrSrvConfig.pszHomedirTemplate,
  236. &pszHomedirTemplate);
  237. BAIL_ON_LSA_ERROR(dwError);
  238. *ppszHomedirTemplate = pszHomedirTemplate;
  239. cleanup:
  240. GLOBAL_DATA_UNLOCK(bLocked);
  241. return dwError;
  242. error:
  243. goto cleanup;
  244. }
  245. DWORD
  246. SamrSrvConfigShouldRegisterTcpIp(
  247. BOOLEAN* pbResult
  248. )
  249. {
  250. DWORD dwError = 0;
  251. BOOL bLocked = 0;
  252. GLOBAL_DATA_LOCK(bLocked);
  253. *pbResult = gSamrSrvConfig.bRegisterTcpIp;
  254. cleanup:
  255. GLOBAL_DATA_UNLOCK(bLocked);
  256. return dwError;
  257. error:
  258. *pbResult = FALSE;
  259. goto cleanup;
  260. }
  261. /*
  262. local variables:
  263. mode: c
  264. c-basic-offset: 4
  265. indent-tabs-mode: nil
  266. tab-width: 4
  267. end:
  268. */