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.

369 lines
6.7 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. faxcpl.c
  5. Abstract:
  6. Implementation of the control panel applet entry point
  7. Environment:
  8. Windows NT fax configuration applet
  9. Revision History:
  10. 02/27/96 -davidx-
  11. Created it.
  12. 05/22/96 -davidx-
  13. Share the same DLL with remote admin program.
  14. mm/dd/yy -author-
  15. description
  16. --*/
  17. #include <windows.h>
  18. #include <commctrl.h>
  19. #include <cpl.h>
  20. #include <stdlib.h>
  21. #include <tchar.h>
  22. #include "faxcfg.h"
  23. #include "resource.h"
  24. #include "faxcfgrs.h"
  25. //
  26. // Definition of global variables
  27. //
  28. HINSTANCE ghInstance;
  29. UINT_PTR UserInfoDlgProc(HWND, UINT, WPARAM, LPARAM);
  30. UINT_PTR StatusOptionsProc(HWND, UINT, WPARAM, LPARAM);
  31. UINT_PTR ClientCoverPageProc(HWND, UINT, WPARAM, LPARAM);
  32. UINT_PTR AdvancedOptionsProc(HWND, UINT, WPARAM, LPARAM);
  33. BOOL
  34. IsPriviledgedAccount(
  35. VOID
  36. );
  37. BOOL
  38. IsUserAdmin(
  39. VOID
  40. );
  41. BOOL
  42. DllEntryPoint(
  43. HINSTANCE hModule,
  44. ULONG ulReason,
  45. PCONTEXT pContext
  46. )
  47. /*++
  48. Routine Description:
  49. DLL initialization procedure.
  50. Arguments:
  51. hModule - DLL instance handle
  52. ulReason - Reason for the call
  53. pContext - Pointer to context (not used by us)
  54. Return Value:
  55. TRUE if DLL is initialized successfully, FALSE otherwise.
  56. --*/
  57. {
  58. switch (ulReason) {
  59. case DLL_PROCESS_ATTACH:
  60. ghInstance = hModule;
  61. break;
  62. case DLL_PROCESS_DETACH:
  63. break;
  64. }
  65. return TRUE;
  66. }
  67. int
  68. FaxConfigGetPages(
  69. HINSTANCE hInstance,
  70. HPROPSHEETPAGE *hPsp,
  71. DWORD Count
  72. )
  73. {
  74. PROPSHEETPAGE psp[4];
  75. BOOL ShowAdvanced;
  76. ZeroMemory( &psp, sizeof(psp) );
  77. psp[0].dwSize = sizeof(PROPSHEETPAGE);
  78. psp[0].hInstance = hInstance;
  79. psp[0].pszTemplate = MAKEINTRESOURCE(IDD_USER_INFO);
  80. psp[0].pfnDlgProc = UserInfoDlgProc;
  81. psp[1].dwSize = sizeof(PROPSHEETPAGE);
  82. psp[1].hInstance = hInstance;
  83. psp[1].pszTemplate = MAKEINTRESOURCE(IDD_CLIENT_COVERPG);
  84. psp[1].pfnDlgProc = ClientCoverPageProc;
  85. psp[2].dwSize = sizeof(PROPSHEETPAGE);
  86. psp[2].hInstance = hInstance;
  87. psp[2].pszTemplate = MAKEINTRESOURCE(IDD_STATUS_OPTIONS);
  88. psp[2].pfnDlgProc = StatusOptionsProc;
  89. hPsp[0] = CreatePropertySheetPage( &psp[0] );
  90. hPsp[1] = CreatePropertySheetPage( &psp[1] );
  91. hPsp[2] = CreatePropertySheetPage( &psp[2] );
  92. ShowAdvanced = IsPriviledgedAccount();
  93. if (ShowAdvanced) {
  94. psp[3].dwSize = sizeof(PROPSHEETPAGE);
  95. psp[3].hInstance = hInstance;
  96. psp[3].pszTemplate = MAKEINTRESOURCE(IDD_ADVANCED_OPTIONS);
  97. psp[3].pfnDlgProc = AdvancedOptionsProc;
  98. hPsp[3] = CreatePropertySheetPage( &psp[3] );
  99. }
  100. return ShowAdvanced ? 4 : 3;
  101. }
  102. INT
  103. DoFaxConfiguration(
  104. HWND hwndCPl,
  105. LPTSTR pCmdLine
  106. )
  107. /*++
  108. Routine Description:
  109. Display fax configuration dialogs: client, server, or workstation
  110. Arguments:
  111. hwndCPl - Handle to the Control Panel window
  112. Return Value:
  113. 0 if successful, -1 if there is an error
  114. --*/
  115. #define MAX_PAGES 16
  116. #define MAX_TITLE_LEN 64
  117. {
  118. HPROPSHEETPAGE hPropSheetPages[MAX_PAGES];
  119. PROPSHEETHEADER psh;
  120. TCHAR dlgTitle[MAX_TITLE_LEN];
  121. INT nPages,nStartPage;
  122. //
  123. // Get an array of property sheet page handles
  124. //
  125. nPages = FaxConfigGetPages( ghInstance, hPropSheetPages, MAX_PAGES );
  126. //
  127. // Fill out PROPSHEETHEADER structure
  128. //
  129. LoadString(ghInstance, IDS_FAX_TITLE, dlgTitle, MAX_TITLE_LEN);
  130. nStartPage = nStartPage = pCmdLine ? _ttol(pCmdLine) : 0;
  131. ZeroMemory( &psh, sizeof(psh) );
  132. psh.dwSize = sizeof(PROPSHEETHEADER);
  133. psh.dwFlags = PSH_USEICONID;
  134. psh.hwndParent = hwndCPl;
  135. psh.hInstance = ghInstance;
  136. psh.pszIcon = MAKEINTRESOURCE(IDI_FAX);
  137. psh.pszCaption = dlgTitle;
  138. psh.nPages = nPages;
  139. psh.nStartPage = nStartPage;
  140. psh.phpage = hPropSheetPages;
  141. //
  142. // Display the property sheet
  143. //
  144. return (PropertySheet(&psh) == -1) ? -1 : 0;
  145. }
  146. LONG
  147. CPlApplet(
  148. HWND hwndCPl,
  149. UINT uMsg,
  150. LPARAM lParam1,
  151. LPARAM lParam2
  152. )
  153. /*++
  154. Routine Description:
  155. Control panel applet entry point
  156. Arguments:
  157. hwndCPl - Identifies the Control Panel window
  158. uMsg - Specifies the message being sent to the Control Panel applet
  159. lParam1 - Specifies additional message-specific information
  160. lParam2 - Specifies additional message-specific information
  161. Return Value:
  162. Depends on the message
  163. --*/
  164. {
  165. static BOOL Failed = FALSE;
  166. switch (uMsg) {
  167. case CPL_INIT:
  168. return 1;
  169. case CPL_GETCOUNT:
  170. return 1;
  171. case CPL_INQUIRE:
  172. ((CPLINFO*)lParam2)->lData = 0;
  173. ((CPLINFO*)lParam2)->idIcon = IDI_FAX;
  174. ((CPLINFO*)lParam2)->idName = IDS_FAX;
  175. ((CPLINFO*)lParam2)->idInfo = IDS_CONFIG_FAX;
  176. return 0;
  177. case CPL_DBLCLK:
  178. //
  179. // Treat this as CPL_STARTWPARMS with no parameter
  180. //
  181. if (Failed) {
  182. return 1;
  183. }
  184. return DoFaxConfiguration(hwndCPl,NULL);
  185. case CPL_STARTWPARMS:
  186. //
  187. // Display fax configuration dialog: client, server, or workstation
  188. //
  189. if (!DoFaxConfiguration(hwndCPl,(LPTSTR) lParam2)) {
  190. Failed = TRUE;
  191. return 1;
  192. }
  193. return 0;
  194. case CPL_EXIT:
  195. break;
  196. }
  197. return 0;
  198. }
  199. BOOL
  200. IsPriviledgedAccount(
  201. VOID
  202. )
  203. /*++
  204. Routine Description:
  205. Determines if the currently logged on account is priviledged. If it is priviledged, then
  206. we show the advanced tab in the control panel. I'm still not sure what the priviledge
  207. check will be.
  208. Arguments:
  209. NONE.
  210. Return Value:
  211. TRUE if account is priviledged
  212. --*/
  213. {
  214. return IsUserAdmin();
  215. }
  216. //
  217. // stolen from setupapi\security.c, so that we don't have to link to setupapi...
  218. //
  219. BOOL
  220. IsUserAdmin(
  221. VOID
  222. )
  223. /*++
  224. Routine Description:
  225. This routine returns TRUE if the caller's process is a
  226. member of the Administrators local group.
  227. Caller is NOT expected to be impersonating anyone and IS
  228. expected to be able to open their own process and process
  229. token.
  230. Arguments:
  231. None.
  232. Return Value:
  233. TRUE - Caller has Administrators local group.
  234. FALSE - Caller does not have Administrators local group.
  235. --*/
  236. {
  237. BOOL b;
  238. SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
  239. PSID AdministratorsGroup;
  240. b = AllocateAndInitializeSid(
  241. &NtAuthority,
  242. 2,
  243. SECURITY_BUILTIN_DOMAIN_RID,
  244. DOMAIN_ALIAS_RID_ADMINS,
  245. 0, 0, 0, 0, 0, 0,
  246. &AdministratorsGroup
  247. );
  248. if(b) {
  249. if (!CheckTokenMembership( NULL, AdministratorsGroup, &b)) {
  250. b = FALSE;
  251. }
  252. FreeSid(AdministratorsGroup);
  253. }
  254. return(b);
  255. }