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.

480 lines
11 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. routing\netsh\ras\userhndl.c
  5. Abstract:
  6. Handlers for user commands
  7. Revision History:
  8. pmay
  9. --*/
  10. #include "precomp.h"
  11. #pragma hdrstop
  12. DWORD
  13. HandleUserSet(
  14. IN LPCWSTR pwszMachine,
  15. IN OUT LPWSTR *ppwcArguments,
  16. IN DWORD dwCurrentIndex,
  17. IN DWORD dwArgCount,
  18. IN DWORD dwFlags,
  19. IN LPCVOID pvData,
  20. OUT BOOL *pbDone
  21. )
  22. /*++
  23. Routine Description:
  24. Handler for setting the ras information for a user
  25. Arguments:
  26. ppwcArguments - Argument array
  27. dwCurrentIndex - ppwcArguments[dwCurrentIndex] is the first arg
  28. dwArgCount - ppwcArguments[dwArgCount - 1] is the last arg
  29. Return Value:
  30. NO_ERROR
  31. --*/
  32. {
  33. USERMON_PARAMS* pParams = NULL;
  34. RAS_USER_0 RasUser0;
  35. DWORD dwErr;
  36. RASUSER_DATA UserData, *pUserData = &UserData;
  37. do {
  38. // Initialize
  39. ZeroMemory(&RasUser0, sizeof(RasUser0));
  40. ZeroMemory(pUserData, sizeof(RASUSER_DATA));
  41. // Parse the options
  42. dwErr = UserParseSetOptions(
  43. ppwcArguments,
  44. dwCurrentIndex,
  45. dwArgCount,
  46. &pParams);
  47. if (dwErr isnot NO_ERROR)
  48. {
  49. break;
  50. }
  51. // Read in the current user settings
  52. dwErr = UserGetRasProperties(
  53. g_pServerInfo,
  54. pParams->pwszUser,
  55. &RasUser0);
  56. if (dwErr isnot NO_ERROR)
  57. {
  58. break;
  59. }
  60. // Merge in the dialin bit
  61. if (pParams->lpdwDialin isnot NULL)
  62. {
  63. RasUser0.bfPrivilege &= ~RASPRIV_DialinPrivilege;
  64. RasUser0.bfPrivilege &= ~RASPRIV_DialinPolicy;
  65. RasUser0.bfPrivilege |= *(pParams->lpdwDialin);
  66. }
  67. // Merge in the callback policy
  68. if (pParams->lpdwCallback isnot NULL)
  69. {
  70. RasUser0.bfPrivilege &= ~RASPRIV_NoCallback;
  71. RasUser0.bfPrivilege &= ~RASPRIV_AdminSetCallback;
  72. RasUser0.bfPrivilege &= ~RASPRIV_CallerSetCallback;
  73. RasUser0.bfPrivilege |= *(pParams->lpdwCallback);
  74. }
  75. // Merge in the callback number
  76. if (pParams->pwszCbNumber isnot NULL)
  77. {
  78. wcscpy(RasUser0.wszPhoneNumber, pParams->pwszCbNumber);
  79. if (wcslen(RasUser0.wszPhoneNumber) > 48)
  80. {
  81. dwErr = ERROR_BAD_FORMAT;
  82. break;
  83. }
  84. }
  85. // Make sure that if admin set callback is specified, that we
  86. // force the user to specify a callback number.
  87. //
  88. if ((RasUser0.bfPrivilege & RASPRIV_AdminSetCallback) &&
  89. (wcscmp(RasUser0.wszPhoneNumber, L"") == 0))
  90. {
  91. DisplayMessage(
  92. g_hModule,
  93. EMSG_RASUSER_MUST_PROVIDE_CB_NUMBER);
  94. dwErr = ERROR_CAN_NOT_COMPLETE;
  95. break;
  96. }
  97. // Write out the new user settings
  98. //
  99. dwErr = UserSetRasProperties(
  100. g_pServerInfo,
  101. pParams->pwszUser,
  102. &RasUser0);
  103. if (dwErr isnot NO_ERROR)
  104. {
  105. break;
  106. }
  107. // Read back the settings to see what's
  108. // new
  109. //
  110. dwErr = UserGetRasProperties(
  111. g_pServerInfo,
  112. pParams->pwszUser,
  113. &RasUser0);
  114. if (dwErr isnot NO_ERROR)
  115. {
  116. break;
  117. }
  118. // Display the new user settings
  119. pUserData->pszUsername = pParams->pwszUser;
  120. CopyMemory(&(pUserData->User0), &RasUser0, sizeof(RAS_USER_0));
  121. UserShowReport(pUserData, NULL);
  122. } while (FALSE);
  123. // Cleanup
  124. {
  125. UserFreeParameters(pParams);
  126. }
  127. return dwErr;
  128. }
  129. DWORD
  130. HandleUserShow(
  131. IN LPCWSTR pwszMachine,
  132. IN OUT LPWSTR *ppwcArguments,
  133. IN DWORD dwCurrentIndex,
  134. IN DWORD dwArgCount,
  135. IN DWORD dwFlags,
  136. IN LPCVOID pvData,
  137. OUT BOOL *pbDone
  138. )
  139. /*++
  140. Routine Description:
  141. Handler for displaying interfaces
  142. Arguments:
  143. ppwcArguments - Argument array
  144. dwCurrentIndex - ppwcArguments[dwCurrentIndex] is the first arg
  145. dwArgCount - ppwcArguments[dwArgCount - 1] is the last arg
  146. Return Value:
  147. NO_ERROR
  148. --*/
  149. {
  150. DWORD dwErr = NO_ERROR;
  151. RASUSER_DATA UserData, *pUser = &UserData;
  152. PFN_RASUSER_ENUM_CB pEnumFunc = UserShowReport;
  153. TOKEN_VALUE rgEnumMode[] =
  154. {
  155. {TOKEN_REPORT, 0},
  156. {TOKEN_PERMIT, 1}
  157. };
  158. RASMON_CMD_ARG pArgs[] =
  159. {
  160. {
  161. RASMONTR_CMD_TYPE_STRING,
  162. {TOKEN_NAME, FALSE, FALSE},
  163. NULL,
  164. 0,
  165. NULL
  166. },
  167. {
  168. RASMONTR_CMD_TYPE_ENUM,
  169. {TOKEN_MODE, FALSE, FALSE},
  170. rgEnumMode,
  171. sizeof(rgEnumMode)/sizeof(*rgEnumMode),
  172. NULL
  173. }
  174. };
  175. do {
  176. // Initialize
  177. ZeroMemory(pUser, sizeof(RASUSER_DATA));
  178. // Parse
  179. //
  180. dwErr = RutlParse(
  181. ppwcArguments,
  182. dwCurrentIndex,
  183. dwArgCount,
  184. NULL,
  185. pArgs,
  186. sizeof(pArgs)/sizeof(*pArgs));
  187. if (dwErr isnot NO_ERROR)
  188. {
  189. break;
  190. }
  191. //
  192. // Name
  193. //
  194. pUser->pszUsername = RASMON_CMD_ARG_GetPsz(&pArgs[0]);
  195. //
  196. // Mode
  197. //
  198. if (pArgs[1].rgTag.bPresent)
  199. {
  200. if (pArgs[1].Val.dwValue == 0)
  201. {
  202. pEnumFunc = UserShowReport;
  203. }
  204. else if (pArgs[1].Val.dwValue == 1)
  205. {
  206. pEnumFunc = UserShowPermit;
  207. }
  208. }
  209. // No user, enumerate all
  210. //
  211. if(pUser->pszUsername is NULL)
  212. {
  213. dwErr = UserEnumUsers(
  214. g_pServerInfo,
  215. pEnumFunc,
  216. NULL);
  217. if (dwErr isnot NO_ERROR)
  218. {
  219. DisplayMessage(
  220. g_hModule,
  221. EMSG_UNABLE_TO_ENUM_USERS);
  222. }
  223. }
  224. // Specific user named
  225. //
  226. else
  227. {
  228. // Get the user parms
  229. //
  230. dwErr = UserGetRasProperties(
  231. g_pServerInfo,
  232. pUser->pszUsername,
  233. &(pUser->User0));
  234. if (dwErr isnot NO_ERROR)
  235. {
  236. break;
  237. }
  238. // Display user properties
  239. //
  240. (*pEnumFunc)(pUser, NULL);
  241. }
  242. } while (FALSE);
  243. // Cleanup
  244. {
  245. RutlFree(pUser->pszUsername);
  246. }
  247. return dwErr;
  248. }
  249. DWORD
  250. UserParseSetOptions(
  251. IN OUT LPWSTR *ppwcArguments,
  252. IN DWORD dwCurrentIndex,
  253. IN DWORD dwArgCount,
  254. OUT USERMON_PARAMS** ppParams
  255. )
  256. /*++
  257. Routine Description:
  258. Converts a set of command line arguments into a USERMON_PARAMS
  259. structure. The set operation is assumed.
  260. Arguments:
  261. ppwcArguments - Argument array
  262. dwCurrentIndex - ppwcArguments[dwCurrentIndex] is the first arg
  263. dwArgCount - ppwcArguments[dwArgCount - 1] is the last arg
  264. ppParams - receives the parameters
  265. Return Value:
  266. NO_ERROR
  267. --*/
  268. {
  269. USERMON_PARAMS* pParams = NULL;
  270. DWORD i, dwErr;
  271. BOOL bDone = FALSE;
  272. TOKEN_VALUE rgEnumDialin[] =
  273. {
  274. {TOKEN_PERMIT, RASPRIV_DialinPrivilege},
  275. {TOKEN_POLICY, RASPRIV_DialinPolicy},
  276. {TOKEN_DENY, 0}
  277. };
  278. TOKEN_VALUE rgEnumPolicy[] =
  279. {
  280. {TOKEN_NONE, RASPRIV_NoCallback},
  281. {TOKEN_CALLER, RASPRIV_CallerSetCallback},
  282. {TOKEN_ADMIN, RASPRIV_AdminSetCallback}
  283. };
  284. RASMON_CMD_ARG pArgs[] =
  285. {
  286. {
  287. RASMONTR_CMD_TYPE_STRING,
  288. {TOKEN_NAME, TRUE, FALSE},
  289. NULL,
  290. 0,
  291. NULL
  292. },
  293. {
  294. RASMONTR_CMD_TYPE_ENUM,
  295. {TOKEN_DIALIN,FALSE,FALSE},
  296. rgEnumDialin,
  297. sizeof(rgEnumDialin)/sizeof(*rgEnumDialin),
  298. NULL
  299. },
  300. {
  301. RASMONTR_CMD_TYPE_ENUM,
  302. {TOKEN_CBPOLICY, FALSE,FALSE},
  303. rgEnumPolicy,
  304. sizeof(rgEnumPolicy)/sizeof(*rgEnumPolicy),
  305. NULL
  306. },
  307. {
  308. RASMONTR_CMD_TYPE_STRING,
  309. {TOKEN_CBNUMBER, FALSE,FALSE},
  310. NULL,
  311. 0,
  312. NULL
  313. }
  314. };
  315. do
  316. {
  317. // Allocate and initialize the return value
  318. //
  319. pParams = RutlAlloc(sizeof(USERMON_PARAMS), TRUE);
  320. if (pParams is NULL)
  321. {
  322. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  323. break;
  324. }
  325. // Parse the command line
  326. //
  327. dwErr = RutlParse(
  328. ppwcArguments,
  329. dwCurrentIndex,
  330. dwArgCount,
  331. &bDone,
  332. pArgs,
  333. sizeof(pArgs) / sizeof(*pArgs));
  334. if (dwErr != NO_ERROR)
  335. {
  336. break;
  337. }
  338. // Get strings
  339. //
  340. pParams->pwszUser = RASMON_CMD_ARG_GetPsz(&pArgs[0]);
  341. pParams->pwszCbNumber = RASMON_CMD_ARG_GetPsz(&pArgs[3]);
  342. // Dialin
  343. //
  344. if (pArgs[1].rgTag.bPresent)
  345. {
  346. pParams->lpdwDialin = RutlDwordDup(pArgs[1].Val.dwValue);
  347. }
  348. // Callback policy
  349. //
  350. if (pArgs[2].rgTag.bPresent)
  351. {
  352. pParams->lpdwCallback = RutlDwordDup(pArgs[2].Val.dwValue);
  353. }
  354. } while (FALSE);
  355. // Cleanup
  356. //
  357. {
  358. if (dwErr is NO_ERROR)
  359. {
  360. *ppParams = pParams;
  361. }
  362. else
  363. {
  364. RutlFree(pParams);
  365. *ppParams = NULL;
  366. }
  367. }
  368. return dwErr;
  369. }
  370. DWORD
  371. UserFreeParameters(
  372. IN USERMON_PARAMS * pParams
  373. )
  374. /*++
  375. Routine Description:
  376. Frees the parameter structure returned by UserParseSetOptions
  377. Arguments:
  378. pParams - the parameters to be freed
  379. Return Value:
  380. NO_ERROR
  381. --*/
  382. {
  383. if (pParams)
  384. {
  385. RutlFree(pParams->pwszUser);
  386. RutlFree(pParams->lpdwDialin);
  387. RutlFree(pParams->lpdwCallback);
  388. RutlFree(pParams->pwszCbNumber);
  389. RutlFree(pParams);
  390. }
  391. return NO_ERROR;
  392. }