Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
4.2 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. ident.c
  5. Abstract:
  6. This module contains function for processing the identities section of WINBOM.INI
  7. Author:
  8. Stephen Lodwick (stelo) 7/27/2000
  9. Revision History:
  10. --*/
  11. #include "factoryp.h"
  12. #include <setupapi.h>
  13. #include <syssetup.h>
  14. #include <tchar.h>
  15. //
  16. // Internal Defines
  17. //
  18. #define INF_SEC_IDENTITIES _T("UserAccounts")
  19. #define INF_SEC_IDENTITY _T("%s.Account")
  20. #define INF_KEY_ALIAS _T("Alias")
  21. #define INF_KEY_PASSWORD _T("Password")
  22. #define INF_KEY_DESCRIPTION _T("Description")
  23. // Typedefs for external functions
  24. typedef BOOL (WINAPI *CreateLocalAdminAccountExW)
  25. (
  26. PCWSTR UserName,
  27. PCWSTR Password,
  28. PCWSTR Description,
  29. PSID* PointerToUserSid OPTIONAL
  30. );
  31. BOOL UserIdent(LPSTATEDATA lpStateData)
  32. {
  33. LPTSTR lpWinbomPath = lpStateData->lpszWinBOMPath;
  34. HINF hInf = NULL;
  35. CreateLocalAdminAccountExW pCreateAccountW = NULL;
  36. INFCONTEXT InfContext;
  37. BOOL bRet;
  38. TCHAR szIdentity[MAX_PATH],
  39. szIdentitySection[MAX_PATH],
  40. szPassword[MAX_PATH],
  41. szDescription[MAX_PATH];
  42. HINSTANCE hSyssetup = NULL;
  43. DWORD dwReturn = 0;
  44. if ((hInf = SetupOpenInfFile(lpWinbomPath, NULL, INF_STYLE_OLDNT | INF_STYLE_WIN4, NULL)))
  45. {
  46. for ( bRet = SetupFindFirstLine(hInf, INF_SEC_IDENTITIES, NULL, &InfContext);
  47. bRet;
  48. bRet = SetupFindNextLine(&InfContext, &InfContext) )
  49. {
  50. // Make sure we set the line back to nothing
  51. //
  52. szIdentity[0] = NULLCHR;
  53. szPassword[0] = NULLCHR;
  54. // Get the name of the identity.
  55. //
  56. SetupGetStringField(&InfContext, 1, szIdentity, STRSIZE(szIdentity), NULL);
  57. // ISSUE-2002/02/25-acosma,robertko - Doing the same thing twice here. *szIdentity AND szIdentity[0] ARE the same thing!
  58. //
  59. if ( *szIdentity && szIdentity[0] )
  60. {
  61. // Build the name of the section for this identity
  62. //
  63. if ( FAILED ( StringCchPrintf ( szIdentitySection, AS ( szIdentitySection ), INF_SEC_IDENTITY, szIdentity) ) )
  64. {
  65. FacLogFileStr(3, _T("StringCchPrintf failed %s %s" ), INF_SEC_IDENTITY, szIdentity );
  66. }
  67. // Get the Alias field
  68. //
  69. GetPrivateProfileString(szIdentitySection, INF_KEY_ALIAS, szIdentity, szIdentity, STRSIZE(szIdentity), lpWinbomPath);
  70. // Get the Password field
  71. //
  72. // NTRAID#NTBUG9-551766-2002/02/26-acosma, robertko - Clear text password should not exist in winbom.
  73. //
  74. GetPrivateProfileString(szIdentitySection, INF_KEY_PASSWORD, NULLSTR, szPassword, STRSIZE(szPassword), lpWinbomPath);
  75. // Get the Description field
  76. //
  77. GetPrivateProfileString(szIdentitySection, INF_KEY_DESCRIPTION, NULLSTR, szDescription, STRSIZE(szDescription), lpWinbomPath);
  78. // Create the Local User/Admin Account
  79. //
  80. // ISSUE-2002/02/25-acosma, robertko - We don't need to LoadLibrary here since we are already linked to syssetup.lib.
  81. //
  82. if ( hSyssetup = LoadLibrary(_T("SYSSETUP.DLL")) )
  83. {
  84. // ISSUE-2002/02/25-acosma,robertko - dwReturn value is not being used. Remove it.
  85. //
  86. if ( pCreateAccountW = (CreateLocalAdminAccountExW)GetProcAddress(hSyssetup, "CreateLocalAdminAccountEx") )
  87. dwReturn = pCreateAccountW(szIdentity, szPassword, szDescription, NULL);
  88. FreeLibrary(hSyssetup);
  89. }
  90. }
  91. }
  92. SetupCloseInfFile(hInf);
  93. }
  94. return TRUE;
  95. }
  96. BOOL DisplayUserIdent(LPSTATEDATA lpStateData)
  97. {
  98. return IniSettingExists(lpStateData->lpszWinBOMPath, INF_SEC_IDENTITIES, NULL, NULL);
  99. }