Leaked source code of windows server 2003
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.

240 lines
5.7 KiB

  1. #include "isignup.h"
  2. typedef DWORD (WINAPI *WNETGETUSER)
  3. (LPCTSTR lpName, LPTSTR lpUserName, LPDWORD lpnLength);
  4. typedef DWORD (WINAPI * WNETLOGON)
  5. (LPCTSTR lpProvider, HWND hwndOwner);
  6. #ifdef WIN16
  7. #define MB_SETFOREGROUND 0
  8. #define NO_ERROR ERROR_SUCCESS
  9. //
  10. // MessageId: ERROR_NO_NETWORK
  11. //
  12. // MessageText:
  13. //
  14. // The network is not present or not started.
  15. //
  16. #define ERROR_NO_NETWORK 1222L
  17. //
  18. // MessageId: ERROR_NOT_LOGGED_ON
  19. //
  20. // MessageText:
  21. //
  22. // The operation being requested was not performed because the user
  23. // has not logged on to the network.
  24. // The specified service does not exist.
  25. //
  26. #define ERROR_NOT_LOGGED_ON 1245L
  27. //
  28. // MessageId: ERROR_NOT_CONNECTED
  29. //
  30. // MessageText:
  31. //
  32. // This network connection does not exist.
  33. //
  34. #define ERROR_NOT_CONNECTED 2250L
  35. #endif
  36. #ifdef UNICODE
  37. BOOL WINAPI AutoDialLogonW(HWND, LPCTSTR, DWORD, LPDWORD);
  38. BOOL WINAPI AutoDialLogonA
  39. (
  40. HWND hwndParent,
  41. LPCSTR lpszEntry,
  42. DWORD dwFlags,
  43. LPDWORD pdwRetCode
  44. )
  45. {
  46. TCHAR szEntry[RAS_MaxEntryName + 1];
  47. mbstowcs(szEntry, lpszEntry, lstrlenA(lpszEntry)+1);
  48. return AutoDialLogonW(hwndParent, szEntry, dwFlags, pdwRetCode);
  49. }
  50. BOOL WINAPI AutoDialLogonW
  51. #else
  52. BOOL WINAPI AutoDialLogonA
  53. #endif
  54. (
  55. HWND hwndParent,
  56. LPCTSTR lpszEntry,
  57. DWORD dwFlags,
  58. LPDWORD pdwRetCode
  59. )
  60. {
  61. DWORD dwRet;
  62. TCHAR szUser[80];
  63. DWORD size;
  64. HINSTANCE hLib;
  65. WNETLOGON lpfnWNetLogon;
  66. WNETGETUSER lpfnWNetGetUser;
  67. hLib = LoadLibrary(TEXT("mpr.dll"));
  68. if ((HINSTANCE)32 >= hLib)
  69. {
  70. return 0;
  71. }
  72. #ifdef UNICODE
  73. lpfnWNetLogon = (WNETLOGON) GetProcAddress(hLib, "WNetLogonW");
  74. lpfnWNetGetUser = (WNETGETUSER) GetProcAddress(hLib, "WNetGetUserW");
  75. #else
  76. lpfnWNetLogon = (WNETLOGON) GetProcAddress(hLib, "WNetLogonA");
  77. lpfnWNetGetUser = (WNETGETUSER) GetProcAddress(hLib, "WNetGetUserA");
  78. #endif
  79. if (NULL == lpfnWNetLogon || NULL == lpfnWNetGetUser)
  80. {
  81. FreeLibrary(hLib);
  82. return 0;
  83. }
  84. size = sizeof(szUser);
  85. dwRet = lpfnWNetGetUser(NULL, szUser, &size);
  86. if (NO_ERROR != dwRet)
  87. {
  88. LPTSTR lpszErr;
  89. TCHAR szMsg[256];
  90. TCHAR szCaption[256];
  91. dwRet = GetLastError();
  92. LoadString(
  93. ghInstance,
  94. IDS_LOGONMESSAGE,
  95. szMsg,
  96. SIZEOF_TCHAR_BUFFER(szMsg));
  97. LoadString(
  98. ghInstance,
  99. IDS_LOGONCAPTION,
  100. szCaption,
  101. SIZEOF_TCHAR_BUFFER(szCaption));
  102. switch (dwRet)
  103. {
  104. case ERROR_NOT_LOGGED_ON:
  105. while (1)
  106. {
  107. dwRet = lpfnWNetLogon(NULL, NULL);
  108. if (WN_CANCEL != dwRet)
  109. {
  110. break;
  111. }
  112. if (MessageBox(
  113. hwndParent,
  114. szMsg,
  115. szCaption,
  116. MB_SETFOREGROUND |
  117. MB_ICONWARNING |
  118. MB_RETRYCANCEL) == IDCANCEL)
  119. {
  120. break;
  121. }
  122. }
  123. break;
  124. case ERROR_NO_NETWORK:
  125. lpszErr = TEXT("No Network");
  126. break;
  127. case ERROR_NOT_CONNECTED:
  128. lpszErr = TEXT("Not Connected");
  129. break;
  130. default:
  131. lpszErr = TEXT("Who knows?");
  132. break;
  133. }
  134. MessageBox(NULL, lpszErr, TEXT("WNetGetUser returned"), MB_OK);
  135. }
  136. FreeLibrary(hLib);
  137. *pdwRetCode = ERROR_SUCCESS;
  138. return FALSE;
  139. }
  140. DWORD SignupLogon(
  141. HWND hwndParent
  142. )
  143. {
  144. DWORD dwRet;
  145. TCHAR szUser[80];
  146. DWORD size;
  147. HINSTANCE hLib;
  148. WNETLOGON lpfnWNetLogon;
  149. WNETGETUSER lpfnWNetGetUser;
  150. hLib = LoadLibrary(TEXT("mpr.dll"));
  151. if ((HINSTANCE)32 >= hLib)
  152. {
  153. return GetLastError();
  154. }
  155. #ifdef UNICODE
  156. lpfnWNetLogon = (WNETLOGON) GetProcAddress(hLib, "WNetLogonW");
  157. lpfnWNetGetUser = (WNETGETUSER) GetProcAddress(hLib, "WNetGetUserW");
  158. #else
  159. lpfnWNetLogon = (WNETLOGON) GetProcAddress(hLib, "WNetLogonA");
  160. lpfnWNetGetUser = (WNETGETUSER) GetProcAddress(hLib, "WNetGetUserA");
  161. #endif
  162. if (NULL == lpfnWNetLogon || NULL == lpfnWNetGetUser)
  163. {
  164. FreeLibrary(hLib);
  165. return ERROR_SUCCESS;
  166. }
  167. size = sizeof(szUser);
  168. dwRet = lpfnWNetGetUser(NULL, szUser, &size);
  169. if (NO_ERROR != dwRet)
  170. {
  171. TCHAR szMsg[256];
  172. dwRet = GetLastError();
  173. LoadString(
  174. ghInstance,
  175. IDS_SIGNUPLOGON,
  176. szMsg,
  177. SIZEOF_TCHAR_BUFFER(szMsg));
  178. if (ERROR_NOT_LOGGED_ON == dwRet)
  179. {
  180. while (1)
  181. {
  182. dwRet = lpfnWNetLogon(NULL, NULL);
  183. if (WN_CANCEL != dwRet)
  184. {
  185. dwRet = ERROR_SUCCESS;
  186. break;
  187. }
  188. if (MessageBox(
  189. hwndParent,
  190. szMsg,
  191. cszAppName,
  192. MB_SETFOREGROUND |
  193. MB_ICONWARNING |
  194. MB_RETRYCANCEL) == IDCANCEL)
  195. {
  196. dwRet = ERROR_CANCELLED;
  197. break;
  198. }
  199. }
  200. }
  201. }
  202. FreeLibrary(hLib);
  203. return dwRet;
  204. }