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.

245 lines
7.5 KiB

  1. // EditAlias.cpp : Implementation of CEditAlias
  2. #include "stdafx.h"
  3. #include "W3PropPage.h"
  4. #include "w3ext.h"
  5. #include "PropShellExt.h"
  6. #include "EditAlias.h"
  7. /////////////////////////////////////////////////////////////////////////////
  8. // CEditAlias
  9. #define TOOLTIP_READ_PERMISSIONS 1000
  10. LRESULT
  11. CEditAlias::OnInitDialog(HWND hDlg, LPARAM lParam)
  12. {
  13. CMetabasePath path(TRUE, SZ_MBN_WEB, m_instance, SZ_MBN_ROOT, m_new ? NULL : m_alias);
  14. CMetaKey mk(LOCAL_KEY, path);
  15. DWORD flags;
  16. m_prev_alias = m_alias;
  17. if (SUCCEEDED(mk.QueryValue(MD_ACCESS_PERM, flags)))
  18. {
  19. m_read = ((flags & MD_ACCESS_READ) != 0);
  20. m_write = ((flags & MD_ACCESS_WRITE) != 0);
  21. m_source = ((flags & MD_ACCESS_SOURCE) != 0);
  22. if (!m_new)
  23. {
  24. if ((flags & MD_ACCESS_EXECUTE) != 0)
  25. m_appcontrol = APP_PERM_EXECUTE;
  26. else if ((flags & MD_ACCESS_SCRIPT) != 0)
  27. m_appcontrol = APP_PERM_SCRIPTS;
  28. }
  29. else
  30. m_appcontrol = APP_PERM_SCRIPTS;
  31. }
  32. else
  33. {
  34. EndDialog(0);
  35. }
  36. if (SUCCEEDED(mk.QueryValue(MD_DIRECTORY_BROWSING, flags)))
  37. {
  38. m_browse = ((flags & MD_DIRBROW_ENABLED) != 0);
  39. }
  40. else
  41. {
  42. EndDialog(0);
  43. }
  44. ::EnableWindow(GetDlgItem(IDOK), m_alias[0] != 0);
  45. m_in_init = TRUE;
  46. DoDataExchange();
  47. m_in_init = FALSE;
  48. // if (NULL != m_tool_tip.Create(hDlg))
  49. // {
  50. // RECT rc;
  51. // ::GetWindowRect(GetDlgItem(IDC_READ), &rc);
  52. // ScreenToClient(&rc);
  53. // m_tool_tip.AddTool(hDlg,
  54. // _T("Users could read this directory"),
  55. // &rc, TOOLTIP_READ_PERMISSIONS
  56. // );
  57. // }
  58. return 1;
  59. }
  60. void
  61. CEditAlias::OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl)
  62. {
  63. CError err;
  64. DWORD app_state = 0;
  65. BOOL bRenamed = FALSE;
  66. DoDataExchange(TRUE);
  67. CMetabasePath alias(FALSE, m_alias);
  68. CMetabasePath::CleanMetaPath(alias);
  69. if (alias.QueryMetaPath()[0] == 0)
  70. {
  71. CString cap, msg;
  72. cap.LoadString(_Module.GetResourceInstance(), IDS_PAGE_TITLE);
  73. msg.Format(_Module.GetResourceInstance(), IDS_BAD_ALIAS, m_alias);
  74. MessageBox(msg, cap);
  75. ::SetFocus(GetDlgItem(IDC_ALIAS));
  76. SendDlgItemMessage(IDC_ALIAS, EM_SETSEL, 0, -1);
  77. return;
  78. }
  79. CMetabasePath path(TRUE, SZ_MBN_WEB, m_instance,
  80. SZ_MBN_ROOT, alias.QueryMetaPath());
  81. CMetabasePath::CleanMetaPath(path);
  82. CMetabasePath parent(path);
  83. CString sub_alias;
  84. CMetabasePath::GetLastNodeName(path, sub_alias);
  85. CMetabasePath::ConvertToParentPath(parent);
  86. CWaitCursor wait;
  87. do
  88. {
  89. if (!m_new)
  90. {
  91. if (m_prev_alias.Compare(m_alias) != 0)
  92. {
  93. CMetabasePath prev_path(TRUE, SZ_MBN_WEB, m_instance, SZ_MBN_ROOT, m_prev_alias);
  94. CIISApplication app(NULL, prev_path);
  95. err = app.QueryResult();
  96. BREAK_ON_ERR_FAILURE(err)
  97. app_state = app.QueryAppState();
  98. err = app.Delete();
  99. BREAK_ON_ERR_FAILURE(err)
  100. CString str;
  101. CMetabasePath::GetLastNodeName(prev_path, str);
  102. CMetabasePath::ConvertToParentPath(prev_path);
  103. CMetaKey mk_prev(LOCAL_KEY, prev_path, METADATA_PERMISSION_WRITE);
  104. err = mk_prev.DeleteKey(str);
  105. BREAK_ON_ERR_FAILURE(err)
  106. bRenamed = TRUE;
  107. }
  108. }
  109. //make sure the parent is there
  110. CMetaKey mk(LOCAL_KEY, parent, METADATA_PERMISSION_READ | METADATA_PERMISSION_WRITE);
  111. err = mk.QueryResult();
  112. if (err.Failed())
  113. {
  114. if (err.Win32Error() == ERROR_PATH_NOT_FOUND)
  115. {
  116. CString caption, msg;
  117. caption.LoadString(_Module.GetResourceInstance(), IDS_PAGE_TITLE);
  118. msg.LoadString(_Module.GetResourceInstance(), IDS_NO_PARENT);
  119. MessageBox (msg, caption, MB_OK);
  120. ::SetFocus(GetDlgItem(IDC_ALIAS));
  121. SendDlgItemMessage(IDC_ALIAS, EM_SETSEL, 0, -1);
  122. break;
  123. }
  124. err.MessageBox();
  125. break;
  126. }
  127. // if we are editing, delete previous vdir and application
  128. if (m_new)
  129. {
  130. // check if this alias is already available
  131. err = mk.DoesPathExist(sub_alias);
  132. if (err.Succeeded())
  133. {
  134. CString caption, fmt, msg;
  135. caption.LoadString(_Module.GetResourceInstance(), IDS_PAGE_TITLE);
  136. fmt.LoadString(_Module.GetResourceInstance(), IDS_ALIAS_IS_TAKEN);
  137. msg.Format(fmt, path.QueryMetaPath());
  138. MessageBox (msg, caption, MB_OK);
  139. ::SetFocus(GetDlgItem(IDC_ALIAS));
  140. SendDlgItemMessage(IDC_ALIAS, EM_SETSEL, 0, -1);
  141. err = E_FAIL;
  142. break;
  143. }
  144. err = S_OK;
  145. }
  146. if (err.Succeeded())
  147. {
  148. if (m_new || bRenamed)
  149. {
  150. err = mk.AddKey(sub_alias);
  151. BREAK_ON_ERR_FAILURE(err)
  152. err = mk.SetValue(MD_KEY_TYPE, CString(_T("IIsWebVirtualDir")), NULL, sub_alias);
  153. BREAK_ON_ERR_FAILURE(err)
  154. err = mk.SetValue(MD_VR_PATH, CString(m_path), NULL, sub_alias);
  155. BREAK_ON_ERR_FAILURE(err)
  156. }
  157. }
  158. // apply permissions
  159. DWORD flags;
  160. mk.QueryValue(MD_ACCESS_PERM, flags, NULL, sub_alias);
  161. flags &= ~(MD_ACCESS_READ|MD_ACCESS_WRITE|MD_ACCESS_SOURCE|MD_ACCESS_SCRIPT|MD_ACCESS_EXECUTE);
  162. flags |= m_read ? MD_ACCESS_READ : 0;
  163. flags |= m_write ? MD_ACCESS_WRITE : 0;
  164. flags |= m_source ? MD_ACCESS_SOURCE : 0;
  165. if (m_appcontrol == APP_PERM_SCRIPTS)
  166. flags |= MD_ACCESS_SCRIPT;
  167. else if (m_appcontrol == APP_PERM_EXECUTE)
  168. flags |= MD_ACCESS_SCRIPT|MD_ACCESS_EXECUTE;
  169. mk.SetValue(MD_ACCESS_PERM, flags, NULL, sub_alias);
  170. mk.QueryValue(MD_DIRECTORY_BROWSING, flags, NULL, sub_alias);
  171. flags &= ~MD_DIRBROW_ENABLED;
  172. flags |= m_browse ? MD_DIRBROW_ENABLED : 0;
  173. err = mk.SetValue(MD_DIRECTORY_BROWSING, flags, NULL, sub_alias);
  174. BREAK_ON_ERR_FAILURE(err)
  175. if (m_new)
  176. {
  177. DWORD dwAuthFlags;
  178. err = mk.QueryValue(MD_AUTHORIZATION, dwAuthFlags, NULL, sub_alias);
  179. BREAK_ON_ERR_FAILURE(err)
  180. dwAuthFlags &= ~(MD_AUTH_BASIC|MD_AUTH_ANONYMOUS|MD_AUTH_MD5);
  181. dwAuthFlags |= MD_AUTH_NT;
  182. err = mk.SetValue(MD_AUTHORIZATION, dwAuthFlags, NULL, sub_alias);
  183. BREAK_ON_ERR_FAILURE(err)
  184. }
  185. } while (FALSE);
  186. if (err.Succeeded())
  187. {
  188. do
  189. {
  190. CIISApplication app(NULL, path);
  191. err = app.QueryResult();
  192. BREAK_ON_ERR_FAILURE(err)
  193. err = app.Create(NULL,
  194. app_state ? app_state : CWamInterface::APP_POOLEDPROC);
  195. BREAK_ON_ERR_FAILURE(err)
  196. EndDialog(wID);
  197. } while (FALSE);
  198. }
  199. }
  200. void
  201. CEditAlias::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl)
  202. {
  203. EndDialog(wID);
  204. }
  205. void
  206. CEditAlias::OnPermissions(WORD wNotifyCode, WORD wID, HWND hWndCtl)
  207. {
  208. if (!m_in_init)
  209. {
  210. DoDataExchange(TRUE);
  211. if (m_write && m_appcontrol > 0)
  212. {
  213. CString caption, msg;
  214. VERIFY(caption.LoadString(_Module.GetResourceInstance(), IDS_PAGE_TITLE));
  215. VERIFY(msg.LoadString(_Module.GetResourceInstance(), IDS_WRITEEXECUTE_DANGER));
  216. if (IDNO == MessageBox(msg, caption, MB_YESNO | MB_ICONEXCLAMATION))
  217. {
  218. CheckDlgButton(wID, 0);
  219. if (wID != IDC_WRITE)
  220. {
  221. CheckDlgButton(IDC_NONE_PERMS, 1);
  222. }
  223. }
  224. }
  225. }
  226. }
  227. void
  228. CEditAlias::OnAliasChange(WORD wNotifyCode, WORD wID, HWND hWndCtl)
  229. {
  230. if (!m_in_init)
  231. {
  232. DoDataExchange(TRUE);
  233. ::EnableWindow(GetDlgItem(IDOK), m_alias[0] != 0);
  234. }
  235. }