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.

374 lines
9.3 KiB

  1. //
  2. //
  3. //
  4. #include "olecnfg.h"
  5. const char * GlobalKeyNames[] =
  6. {
  7. 0,
  8. "EnableDCOM",
  9. "DefaultLaunchPermission",
  10. "DefaultAccessPermission",
  11. "LegacyAuthenticationLevel"
  12. };
  13. const char * ClsidKeyNames[] =
  14. {
  15. 0,
  16. "InprocHandler32",
  17. "InprocServer32",
  18. "LocalServer32",
  19. "LocalService",
  20. "RemoteServerName",
  21. "RunAs",
  22. "ActivateAtStorage",
  23. "LaunchPermission",
  24. "AccessPermission"
  25. };
  26. int ArgsLeft;
  27. char ** Args;
  28. HKEY hRegOle = 0;
  29. HKEY hRegClsid = 0;
  30. #define IsDigit(c) (IsCharAlphaNumeric(c) && !IsCharAlpha(c))
  31. void __cdecl main(int argc, char **argv)
  32. {
  33. int GlobalKeys[GLOBAL_KEYS+1];
  34. int Key;
  35. int n;
  36. DWORD Disposition;
  37. long RegStatus;
  38. memset( GlobalKeys, 0, sizeof(GlobalKeys) );
  39. ArgsLeft = argc - 1;
  40. Args = argv + 1;
  41. if ( (argc > 1) &&
  42. ((strcmp( "/?", argv[1] ) == 0) || (strcmp( "-?", argv[1] ) == 0)) )
  43. {
  44. DisplayHelp();
  45. return;
  46. }
  47. //
  48. // With no arguments, display the global registry activation values.
  49. //
  50. if ( ArgsLeft == 0 )
  51. {
  52. DisplayGlobalSettings();
  53. return;
  54. }
  55. //
  56. // Look for specified global registry keys and operations
  57. //
  58. for ( ; ArgsLeft > 0; )
  59. {
  60. if ( _stricmp( *Args, "EnableDCOM" ) == 0 )
  61. Key = ENABLE_NETWORK_OLE;
  62. else if ( _stricmp( *Args, "DefaultLaunchPermission" ) == 0 )
  63. Key = DEFAULT_LAUNCH_PERMISSION;
  64. else if ( _stricmp( *Args, "DefaultAccessPermission" ) == 0 )
  65. Key = DEFAULT_ACCESS_PERMISSION;
  66. else if ( _stricmp( *Args, "LegacyAuthenticationLevel" ) == 0 )
  67. Key = LEGACY_AUTHENTICATION_LEVEL;
  68. else
  69. break;
  70. EAT_ARG();
  71. if ( Key >= 100 )
  72. {
  73. if ( Key == MERGE )
  74. {
  75. MergeHives( );
  76. }
  77. else if ( Key == SAVE_USER )
  78. {
  79. SaveChangesToUser( );
  80. }
  81. else if ( Key == SAVE_COMMON )
  82. {
  83. SaveChangesToCommon( );
  84. }
  85. continue;
  86. }
  87. if ( Key == DEFAULT_ACCESS_PERMISSION )
  88. {
  89. GlobalKeys[Key] = YES;
  90. continue;
  91. }
  92. if ( Key == LEGACY_AUTHENTICATION_LEVEL )
  93. {
  94. if ( ! IsDigit(**Args) || (**Args < '1') || (**Args > '6') )
  95. {
  96. printf( "LegacyAuthenticationLevel must be followed by a 1 to 6.\n" );
  97. return;
  98. }
  99. GlobalKeys[Key] = **Args;
  100. }
  101. else if ( (GlobalKeys[Key] = ReadYesOrNo()) == INVALID )
  102. {
  103. printf( "%s must be followed by 'y' or 'n'\n", Args[-1] );
  104. return;
  105. }
  106. EAT_ARG();
  107. }
  108. //
  109. // Set global keys on or off.
  110. //
  111. for ( Key = 1; Key < sizeof(GlobalKeys)/sizeof(int); Key++ )
  112. {
  113. if ( (Key == LEGACY_AUTHENTICATION_LEVEL) && (GlobalKeys[Key] != 0) )
  114. {
  115. if ( ! SetGlobalKey( Key, GlobalKeys[Key] - '0' ) )
  116. return;
  117. continue;
  118. }
  119. if ( (GlobalKeys[Key] == YES) || (GlobalKeys[Key] == NO) )
  120. if ( ! SetGlobalKey( Key, GlobalKeys[Key] ) )
  121. return;
  122. }
  123. //
  124. // Process any CLSID/ProgID specification.
  125. //
  126. ParseClsidProgId();
  127. if ( hRegOle )
  128. RegCloseKey( hRegOle );
  129. if ( hRegClsid )
  130. RegCloseKey( hRegClsid );
  131. }
  132. void ParseClsidProgId()
  133. {
  134. CLSID_INFO ClsidInfo;
  135. BOOL NoKeys;
  136. int ClsidKey;
  137. if ( ArgsLeft == 0 )
  138. return;
  139. memset( &ClsidInfo, 0, sizeof(CLSID_INFO) );
  140. NoKeys = TRUE;
  141. if ( (ArgsLeft > 0) && (**Args != '{') )
  142. {
  143. ClsidInfo.ProgId = *Args;
  144. EAT_ARG();
  145. if ( (ArgsLeft > 0) &&
  146. (**Args != '{') &&
  147. (NextClsidKey() == UNKNOWN) )
  148. {
  149. ClsidInfo.ProgIdDescription = *Args;
  150. EAT_ARG();
  151. }
  152. }
  153. if ( (ArgsLeft > 0) && (**Args == '{') )
  154. {
  155. ClsidInfo.Clsid = *Args;
  156. EAT_ARG();
  157. if ( (ArgsLeft > 0) &&
  158. (NextClsidKey() == UNKNOWN) )
  159. {
  160. ClsidInfo.ClsidDescription = *Args;
  161. EAT_ARG();
  162. }
  163. }
  164. for (; ArgsLeft > 0;)
  165. {
  166. ClsidKey = NextClsidKey();
  167. if ( (1 <= ClsidKey) && (ClsidKey <= CLSID_KEYS) )
  168. NoKeys = FALSE;
  169. EAT_ARG();
  170. switch ( ClsidKey )
  171. {
  172. case LAUNCH_PERMISSION :
  173. if ( (ClsidInfo.LaunchPermission = ReadYesOrNo()) == INVALID )
  174. {
  175. printf( "%s must be followed by 'y' or 'n'\n",
  176. ClsidKeyNames[LAUNCH_PERMISSION] );
  177. goto ErrorReturn;
  178. }
  179. EAT_ARG();
  180. break;
  181. case ACCESS_PERMISSION :
  182. ClsidInfo.AccessPermission = YES;
  183. break;
  184. case ACTIVATE_AT_STORAGE :
  185. if ( (ClsidInfo.ActivateAtStorage = ReadYesOrNo()) == INVALID )
  186. {
  187. printf( "%s must be followed by 'y' or 'n'\n",
  188. ClsidKeyNames[ACTIVATE_AT_STORAGE] );
  189. goto ErrorReturn;
  190. }
  191. EAT_ARG();
  192. break;
  193. case INPROC_HANDLER32 :
  194. case INPROC_SERVER32 :
  195. case LOCAL_SERVER32 :
  196. case LOCAL_SERVICE :
  197. if ( NextClsidKey() == UNKNOWN )
  198. {
  199. ClsidInfo.ServerPaths[ClsidKey] = *Args;
  200. EAT_ARG();
  201. }
  202. else
  203. {
  204. ClsidInfo.ServerPaths[ClsidKey] = "";
  205. }
  206. break;
  207. case REMOTE_SERVER_NAME :
  208. if ( NextClsidKey() == UNKNOWN )
  209. {
  210. ClsidInfo.RemoteServerName = *Args;
  211. EAT_ARG();
  212. }
  213. else
  214. {
  215. ClsidInfo.RemoteServerName = "";
  216. }
  217. break;
  218. case RUN_AS :
  219. if ( NextClsidKey() == UNKNOWN )
  220. {
  221. ClsidInfo.RunAsUserName = *Args;
  222. EAT_ARG();
  223. if ( _stricmp(ClsidInfo.RunAsUserName,"Interactive User") == 0 )
  224. break;
  225. if ( _stricmp(ClsidInfo.RunAsUserName,"Interactive") == 0 )
  226. {
  227. if ( (ArgsLeft > 0) && (_stricmp(*Args,"User") == 0) )
  228. {
  229. EAT_ARG();
  230. ClsidInfo.RunAsUserName = "Interactive User";
  231. break;
  232. }
  233. }
  234. if ( NextClsidKey() != UNKNOWN )
  235. {
  236. printf( "RunAs password or '*' must follow the user name.\n" );
  237. goto ErrorReturn;
  238. }
  239. ClsidInfo.RunAsPassword = *Args;
  240. EAT_ARG();
  241. }
  242. else
  243. {
  244. ClsidInfo.RunAsUserName = "";
  245. }
  246. break;
  247. default :
  248. printf( "Invalid CLSID/ProgID specification given (%s)\n", Args[-1] );
  249. goto ErrorReturn;
  250. break;
  251. } // switch
  252. } // for
  253. //
  254. // Display current CLSID/ProgID settings if no keys were specified and
  255. // only a CLSID or ProgID (but not both) was given.
  256. //
  257. if ( NoKeys &&
  258. (ClsidInfo.ProgIdDescription == 0) &&
  259. (ClsidInfo.ClsidDescription == 0) &&
  260. ((ClsidInfo.Clsid == 0) || (ClsidInfo.ProgId == 0)) )
  261. DisplayClsidKeys( &ClsidInfo );
  262. else
  263. UpdateClsidKeys( &ClsidInfo );
  264. return;
  265. ErrorReturn:
  266. printf( "No CLSID/ProgID entries were modified\n" );
  267. }
  268. int NextClsidKey()
  269. {
  270. if ( ArgsLeft == 0 )
  271. return END_OF_ARGS;
  272. if ( _stricmp( *Args, "InprocHandler32" ) == 0 )
  273. return INPROC_HANDLER32;
  274. if ( _stricmp( *Args, "InprocServer32" ) == 0 )
  275. return INPROC_SERVER32;
  276. if ( _stricmp( *Args, "LocalServer32" ) == 0 )
  277. return LOCAL_SERVER32;
  278. if ( _stricmp( *Args, "LocalService" ) == 0 )
  279. return LOCAL_SERVICE;
  280. if ( _stricmp( *Args, "RemoteServerName" ) == 0 )
  281. return REMOTE_SERVER_NAME;
  282. if ( _stricmp( *Args, "RunAs" ) == 0 )
  283. return RUN_AS;
  284. if ( _stricmp( *Args, "ActivateAtStorage" ) == 0 )
  285. return ACTIVATE_AT_STORAGE;
  286. if ( _stricmp( *Args, "LaunchPermission" ) == 0 )
  287. return LAUNCH_PERMISSION;
  288. if ( _stricmp( *Args, "AccessPermission" ) == 0 )
  289. return ACCESS_PERMISSION;
  290. return UNKNOWN;
  291. }
  292. int ReadYesOrNo()
  293. {
  294. if ( ArgsLeft == 0 )
  295. return INVALID;
  296. if ( (char)CharUpperA((LPSTR)**Args) == 'Y' )
  297. return YES;
  298. if ( (char)CharUpperA((LPSTR)**Args) == 'N' )
  299. return NO;
  300. return INVALID;
  301. }
  302. void DisplayHelp()
  303. {
  304. puts( "\nolecnfg\n"
  305. "\t[EnableDCOM <y,n>]\n"
  306. "\t[DefaultLaunchPermission <y,n>]\n"
  307. "\t[DefaultAccessPermission]\n"
  308. "\t[LegacyAuthenticationLevel <1,2,3,4,5,6>]\n" );
  309. puts( "\t[[ProgID [Description]] [CLSID [Description]]\n"
  310. "\t\t[InprocHandler32 [Path]]\n"
  311. "\t\t[InprocServer32 [Path]]\n"
  312. "\t\t[LocalServer32 [Path]]\n"
  313. "\t\t[LocalService [Path]]\n"
  314. "\t\t[RemoteServerName [MachineName]]\n"
  315. "\t\t[RunAs [UserName Password]] ]\n"
  316. "\t\t[ActivateAtStorage <y,n>]\n"
  317. "\t\t[LaunchPermission <y,n>]\n"
  318. "\t\t[AccessPermission]\n"
  319. "\t]\n" );
  320. }