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.

830 lines
25 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name :
  4. main.cpp
  5. Abstract:
  6. command line admin tool main function
  7. Environment:
  8. Win32 User Mode
  9. Author:
  10. jaroslad (jan 1997)
  11. --*/
  12. #include <tchar.h>
  13. #include <afx.h>
  14. #include <string.h>
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. #include "admutil.h"
  18. #include "tables.h"
  19. #include "jd_misc.h"
  20. CAdmUtil oAdmin; //admin object
  21. #define MAX_NUMBER_OF_SMALL_VALUES 100
  22. #define MAX_NUMBER_OF_VALUES 10100
  23. #define MAX_NUMBER_OF_DEFAULT_ARGS 10110
  24. //structure stores the command line arguments
  25. struct tAdmutilParams
  26. {
  27. WORD fHelp; //print help - flag
  28. WORD fFullHelp; //print help - flag
  29. WORD fNoSave; //do not save metabase
  30. LPCTSTR lpszCommand;
  31. LPCTSTR lpszComputer;
  32. WORD wInstance;
  33. LPCTSTR lpszService;
  34. LPCTSTR lpszPath;
  35. LPCTSTR lpszComputerDst; //for COPY destination
  36. WORD wInstanceDst; //for COPY destination
  37. LPCTSTR lpszServiceDst; //for COPY destination
  38. LPCTSTR lpszPathDst; //for COPY destination
  39. LPCTSTR lplpszDefaultArg[MAX_NUMBER_OF_DEFAULT_ARGS];
  40. WORD wDefaultArgCount;
  41. LPCTSTR lpszPropName;
  42. LPCTSTR lplpszPropAttrib[MAX_NUMBER_OF_SMALL_VALUES];
  43. WORD wPropAttribCount;
  44. LPCTSTR lplpszPropDataType[MAX_NUMBER_OF_SMALL_VALUES];
  45. WORD wPropDataTypeCount;
  46. LPCTSTR lplpszPropUserType[MAX_NUMBER_OF_SMALL_VALUES];
  47. WORD wPropUserTypeCount;
  48. LPCTSTR lplpszPropValue[MAX_NUMBER_OF_VALUES]; //pointer to array of values (e.g multisz type allows the multiple values for one property
  49. DWORD lpdwPropValueLength[MAX_NUMBER_OF_VALUES];
  50. WORD wPropValueCount;
  51. WORD wPropFileValueCount;
  52. };
  53. tAdmutilParams Params;
  54. _TCHAR **g_argv;
  55. int g_argc;
  56. static BOOL CompareOutput(_TCHAR *FileToCompare,_TCHAR* FileTemplate);
  57. // definition of command line syntax with some help text -this is the input for ParseParam()
  58. TParamDef CmdLineArgDesc[]=
  59. {
  60. {_TEXT(""),MAX_NUMBER_OF_DEFAULT_ARGS, (void *) Params.lplpszDefaultArg,TYPE_LPCTSTR,OPT, _TEXT("Command [param ...]"),_TEXT("CMD [param param]"),&Params.wDefaultArgCount},
  61. {_TEXT("svc") ,1, (void *) &Params.lpszService,TYPE_LPCTSTR,OPT,_TEXT("service (MSFTPSVC, W3SVC)")},
  62. {_TEXT("s"), 1, (void *) &Params.lpszComputer,TYPE_LPCTSTR,OPT, _TEXT("name of computer to administer"),_TEXT("comp"),},
  63. {_TEXT("i") ,1, &Params.wInstance, TYPE_WORD, OPT,_TEXT("instance number"),_TEXT("inst")},
  64. {_TEXT("path"),1, (void *) &Params.lpszPath, TYPE_LPCTSTR,OPT, _TEXT("path "),_TEXT("path")},
  65. {_TEXT("pathdst"),1, (void *) &Params.lpszPathDst, TYPE_LPCTSTR,OPT, _TEXT("destination path (use for COPY only)"),_TEXT("path")},
  66. {_TEXT("prop"),1, (void *) &Params.lpszPropName, TYPE_LPCTSTR,OPT, _T("property (IIS parameter) name")},
  67. {_TEXT("attrib"),MAX_NUMBER_OF_SMALL_VALUES, (void *) Params.lplpszPropAttrib,TYPE_LPCTSTR,OPT, _T("property attributes"),_T(""),&Params.wPropAttribCount},
  68. {_TEXT("utype"),MAX_NUMBER_OF_SMALL_VALUES, (void *) Params.lplpszPropUserType,TYPE_LPCTSTR,OPT, _T("property user type"),_T(""),&Params.wPropUserTypeCount},
  69. {_TEXT("dtype"),MAX_NUMBER_OF_SMALL_VALUES, (void *) Params.lplpszPropDataType,TYPE_LPCTSTR,OPT, _T("property data type"),_T(""),&Params.wPropDataTypeCount},
  70. {_TEXT("value"),MAX_NUMBER_OF_VALUES, (void *) Params.lplpszPropValue,TYPE_LPCTSTR,OPT, _T("property values"),_T(""),&Params.wPropValueCount},
  71. {_TEXT("fvalue"),MAX_NUMBER_OF_VALUES, (void *) Params.lplpszPropValue,TYPE_LPCTSTR,OPT, _T("property values as files"),_T(""),&Params.wPropFileValueCount},
  72. {_TEXT("nosave"),0, &Params.fNoSave,TYPE_WORD,OPT, _T("do not save metabase"),_T("")},
  73. {_TEXT("timeout"),1, &g_dwTIMEOUT_VALUE,TYPE_DWORD,OPT, _T("timeout for metabase access in ms (default is 30000 sec"),_T("")},
  74. {_TEXT("delayafteropen"),1, &g_dwDELAY_AFTER_OPEN_VALUE,TYPE_DWORD,OPT, _T("delay after opening node (default is 0 sec)"),_T("")},
  75. {_TEXT("help"),0, &Params.fFullHelp,TYPE_WORD,OPT, _T("print full help"),_T("")},
  76. {_TEXT("?"),0, &Params.fHelp,TYPE_WORD,OPT, _T("print help"),_T("")},
  77. {NULL,0, NULL , TYPE_TCHAR, OPT,
  78. _T("IIS K2 administration utility that enables the manipulation with metabase parameters\n")
  79. _T("\n")
  80. _T("Notes:\n")
  81. _T(" Simpified usage of mdutil doesn't require any switches.\n")
  82. _T(" \n")
  83. _T(" mdutil GET path - display chosen parameter\n")
  84. _T(" mdutil SET path value ... - assign the new value\n")
  85. _T(" mdutil ENUM path - enumerate all parameters for given path\n")
  86. _T(" mdutil ENUM_ALL path - recursively enumerate all parameters\n")
  87. _T(" mdutil DELETE path - delete given path or parameter\n")
  88. _T(" mdutil CREATE path - create given path\n")
  89. _T(" mdutil COPY pathsrc pathdst - copy all from pathsrc to pathdst (will create pathdst)\n")
  90. _T(" mdutil RENAME pathsrc pathdst - rename chosen path\n")
  91. _T(" mdutil SCRIPT scriptname - runs the script\n")
  92. _T(" mdutil APPCREATEINPROC w3svc/1/root - Create an in-proc application \n")
  93. _T(" mdutil APPCREATEOUTPOOL w3svc/1/root - Create an pooled out-proc application \n")
  94. _T(" mdutil APPCREATEOUTPROC w3svc/1/root - Create an out-proc application\n")
  95. _T(" mdutil APPDELETE w3svc/1/root - Delete the application if there is one\n")
  96. _T(" mdutil APPRENAME w3svc/1/root/dira w3svc/1/root/dirb - Rename the application \n")
  97. _T(" mdutil APPUNLOAD w3svc/1/root - Unload an application from w3svc runtime lookup table.\n")
  98. _T(" mdutil APPGETSTATUS w3svc/1/root - Get status of the application\n")
  99. _T("\n")
  100. _T(" -path has format: {computer}/{service}/{instance}/{URL}/{Parameter}\n")
  101. _T("\n")
  102. _T("Samples:\n")
  103. _T(" mdutil GET W3SVC/1/ServerBindings \n")
  104. _T(" mdutil SET JAROSLAD2/W3SVC/1/ServerBindings \":81:\"\n")
  105. _T(" mdutil COPY W3SVC/1/ROOT/iisadmin W3SVC/2/ROOT/adm\n")
  106. _T(" mdutil ENUM_ALL W3SVC\n")
  107. _T(" mdutil ENUM W3SVC/1\n")
  108. _T("\n")
  109. _T("Additional features\n")
  110. _T(" set MDUTIL_BLOCK_ON_ERROR environment variable to block mdutil.exe after error (except ERROR_PATH_NOT_FOUND)\n")
  111. _T(" set MDUTIL_ASCENT_LOG environment variable to force mdutil.exe to append errors to ascent log\n")
  112. _T(" set MDUTIL_PRINT_ID environment variable to force mdutil.exe to print metadata numeric identifiers along with friendly names\n")
  113. }
  114. };
  115. BOOL
  116. ReadFromFiles(
  117. LPTSTR* lplpszPropValue,
  118. DWORD* lpdwPropValueLength,
  119. DWORD dwPropFileValueCount
  120. )
  121. {
  122. DWORD dwL;
  123. while ( dwPropFileValueCount-- )
  124. {
  125. FILE* fIn = _tfopen( lplpszPropValue[dwPropFileValueCount], _T("rb") );
  126. if ( fIn == NULL )
  127. {
  128. return FALSE;
  129. }
  130. if ( fseek( fIn, 0, SEEK_END ) == 0 )
  131. {
  132. dwL = ftell( fIn );
  133. if ( fseek( fIn, 0, SEEK_SET ) != 0 )
  134. {
  135. fclose( fIn );
  136. fatal_error_printf(_T("cannot seek\n"));
  137. return FALSE;
  138. }
  139. }
  140. else
  141. {
  142. fclose( fIn );
  143. return FALSE;
  144. }
  145. if ( (lplpszPropValue[dwPropFileValueCount] = (LPTSTR)malloc( dwL )) == NULL )
  146. {
  147. fclose( fIn );
  148. return FALSE;
  149. }
  150. if ( fread( lplpszPropValue[dwPropFileValueCount], 1, dwL, fIn ) != dwL )
  151. {
  152. fclose( fIn );
  153. return FALSE;
  154. }
  155. fclose( fIn );
  156. lpdwPropValueLength[dwPropFileValueCount] = dwL;
  157. }
  158. return TRUE;
  159. }
  160. ///////////////////////////////
  161. class CScript
  162. {
  163. FILE * m_fpScript;
  164. void GetNextToken(/*OUT*/ LPTSTR * lplpszToken);
  165. DWORD CleanWhiteSpaces(void);
  166. public:
  167. CScript(void) {m_fpScript=0;};
  168. DWORD Open(LPCTSTR lpszFile);
  169. DWORD Close(void);
  170. DWORD GetNextLineTokens(int *argc, /*OUT*/ _TCHAR *** argv);
  171. };
  172. DWORD CScript::CleanWhiteSpaces()
  173. {
  174. if(m_fpScript!=NULL)
  175. {
  176. int LastChar=0;
  177. _TINT c=0;
  178. while(1)
  179. {
  180. LastChar=c;
  181. c=_fgettc(m_fpScript);
  182. if(c==_T('\t') || c==_T(' ') || c==_T('\r'))
  183. {
  184. continue;
  185. }
  186. if(c==_T('\\'))
  187. {
  188. int cc=_fgettc(m_fpScript);
  189. if (cc==_T('\r')) //continue with the next line of the file
  190. {
  191. if(_fgettc(m_fpScript)!=_T('\n'))
  192. {
  193. if ( fseek( m_fpScript, -1, SEEK_CUR ) != 0 )
  194. {
  195. fatal_error_printf(_T("cannot seek\n"));
  196. return 0;
  197. }
  198. }
  199. continue;
  200. }
  201. else if (cc==_T('\n')) //continue with the next line of the file
  202. {
  203. continue;
  204. }
  205. else
  206. {
  207. if ( fseek( m_fpScript, -2, SEEK_CUR ) != 0 )
  208. {
  209. fatal_error_printf(_T("cannot seek\n"));
  210. return 0;
  211. }
  212. break;
  213. }
  214. }
  215. if(c==WEOF)
  216. {
  217. break;
  218. }
  219. else
  220. {
  221. if ( fseek( m_fpScript, -1, SEEK_CUR ) != 0 )
  222. {
  223. fatal_error_printf(_T("cannot seek\n"));
  224. return 0;
  225. }
  226. break;
  227. }
  228. }
  229. }
  230. return 0;
  231. }
  232. void CScript::GetNextToken(LPTSTR * lplpszToken)
  233. {
  234. enum {TERMINATE_QUOTE, TERMINATE_WHITESPACE};
  235. long flag=TERMINATE_WHITESPACE;
  236. //clean white spaces
  237. CleanWhiteSpaces();
  238. //store the beginning offset of token
  239. long Offset = ftell(m_fpScript);
  240. _TINT c=_fgettc(m_fpScript);
  241. long CurrentOffset=0;
  242. if(c==WEOF)
  243. {
  244. *lplpszToken=NULL;
  245. return ;
  246. }
  247. if (c==_T('\n')){
  248. *lplpszToken=_T("\n");
  249. return ;
  250. }
  251. else
  252. {
  253. if (c==_T('\"'))
  254. {
  255. //token ends with " or the end of the line
  256. flag=TERMINATE_QUOTE;
  257. Offset = ftell(m_fpScript);
  258. }
  259. else {
  260. flag=TERMINATE_WHITESPACE;
  261. }
  262. // find the end of the token
  263. while(1) {
  264. CurrentOffset=ftell(m_fpScript);
  265. c=_fgettc(m_fpScript);
  266. if(c==_T('\n')){
  267. break;
  268. }
  269. if(c==WEOF)
  270. {
  271. break;
  272. }
  273. if( (flag==TERMINATE_QUOTE && c==_T('\"')) || (
  274. flag==TERMINATE_WHITESPACE && (c==_T(' ') || c==_T('\t') || c==_T('\r')) ) ){
  275. break;
  276. }
  277. }
  278. //get the token size
  279. long TokenSize = CurrentOffset - Offset;
  280. if(TokenSize!=0)
  281. {
  282. // allocate mamory for the token
  283. *lplpszToken = new _TCHAR[ TokenSize+1 ];
  284. //read the token
  285. if ( fseek( m_fpScript, Offset, SEEK_SET) != 0 )
  286. {
  287. fatal_error_printf(_T("cannot seek\n"));
  288. return;
  289. }
  290. for(int i=0;i<TokenSize;i++)
  291. (*lplpszToken)[i]=(TCHAR)_fgettc(m_fpScript);
  292. //terminate the token
  293. (*lplpszToken)[i]=0;
  294. }
  295. else
  296. {
  297. //empty string
  298. *lplpszToken=new _TCHAR[1 ];
  299. (*lplpszToken)[0]=0;
  300. }
  301. //discard double quote if it was at the end of the token
  302. c=_fgettc(m_fpScript);
  303. if(c!=_T('\"'))
  304. {
  305. if (fseek( m_fpScript, ((c==WEOF)?0:-1), SEEK_CUR ) !=0 )
  306. {
  307. fatal_error_printf(_T("cannot seek\n"));
  308. return;
  309. }
  310. }
  311. }
  312. }
  313. DWORD CScript::Open(LPCTSTR lpszFile)
  314. {
  315. m_fpScript = _tfopen( lpszFile, _T("rt") );
  316. if(m_fpScript==NULL)
  317. return GetLastError();
  318. else
  319. return ERROR_SUCCESS;
  320. }
  321. DWORD CScript::Close()
  322. {
  323. if( m_fpScript!=NULL)
  324. fclose( m_fpScript);
  325. return GetLastError();
  326. }
  327. DWORD CScript::GetNextLineTokens(int *argc, /*OUT*/ _TCHAR *** argv)
  328. {
  329. for(int i=1;i<*argc;i++) {
  330. delete (*argv)[i];
  331. (*argv)[i]=0;
  332. }
  333. *argc=0;
  334. if(*argv==NULL)
  335. (*argv)=new LPTSTR [ MAX_NUMBER_OF_VALUES ];
  336. (*argv)[(*argc)++]=_T("mdutil"); //set zero parameter
  337. LPTSTR lpszNextToken=NULL;
  338. while((*argc)<MAX_NUMBER_OF_VALUES)
  339. {
  340. GetNextToken( &lpszNextToken );
  341. if( lpszNextToken==NULL ) //end of file
  342. {
  343. break;
  344. }
  345. if(_tcscmp(lpszNextToken,_T("\n"))==0) //new line
  346. {
  347. delete lpszNextToken;
  348. lpszNextToken = NULL;
  349. break;
  350. }
  351. (*argv)[(*argc)++]=lpszNextToken;
  352. lpszNextToken = NULL;
  353. }
  354. return GetLastError();
  355. }
  356. int MainFunc(int argc, _TCHAR **argv); //declaration
  357. //MAIN FUNCTION
  358. int __cdecl main(int argc, CHAR **_argv)
  359. {
  360. // convert parameters from SBCS to UNICODE;
  361. _TCHAR **argv= new LPTSTR [argc];
  362. for (int i=0;i<argc;i++)
  363. {
  364. argv[i]=new _TCHAR[strlen(_argv[i])+1];
  365. #ifdef UNICODE
  366. MultiByteToWideChar(0, 0, _argv[i], -1, argv[i],strlen(_argv[i])+1 );
  367. #else
  368. strcpy(argv[i],_argv[i]);
  369. #endif
  370. }
  371. DWORD dwCommandCode=0;
  372. DWORD retval=0;
  373. HRESULT hRes;
  374. hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  375. if (FAILED(hRes)) {
  376. fatal_error_printf(_T("CoInitializeEx\n"));
  377. }
  378. //extract command line parameters
  379. ParseParam(argc,argv,CmdLineArgDesc);
  380. //**************************
  381. //PRINT HELP ON REQUEST
  382. if(Params.fFullHelp)
  383. {
  384. //print help
  385. DisplayUsage(argv,CmdLineArgDesc);
  386. PrintTablesInfo();
  387. }
  388. else if(Params.wDefaultArgCount==0 || Params.fHelp)
  389. {
  390. //print help
  391. DisplayUsage(argv,CmdLineArgDesc);
  392. }
  393. else
  394. {
  395. if (Params.wDefaultArgCount>0)
  396. {
  397. //first default has to be command
  398. Params.lpszCommand=Params.lplpszDefaultArg[0];
  399. dwCommandCode = tCommandNameTable::MapNameToCode(Params.lplpszDefaultArg[0]);
  400. if( Params.wDefaultArgCount>1)
  401. {
  402. //second default
  403. Params.lpszPath=Params.lplpszDefaultArg[1];
  404. }
  405. if(dwCommandCode==CMD_SCRIPT) //process script
  406. {
  407. tAdmutilParams *pStoredParams;
  408. CScript Script;
  409. DWORD dwRes;
  410. pStoredParams = new tAdmutilParams(Params);
  411. if (pStoredParams == NULL)
  412. {
  413. fatal_error_printf(_T("out of memory"));
  414. }
  415. if((dwRes=Script.Open(Params.lpszPath))!=ERROR_SUCCESS)
  416. fatal_error_printf(_T("cannot open script file %s (error %d)\n"),Params.lpszPath,dwRes);
  417. int l_argc=0;
  418. _TCHAR ** l_argv=NULL;
  419. while(1)
  420. {
  421. Script.GetNextLineTokens(&l_argc,&l_argv);
  422. if(l_argc==1) //end of script file
  423. break;
  424. Params=*pStoredParams;
  425. _tprintf(_T(">"));
  426. for(int i=1;i<l_argc;i++)
  427. _tprintf(_T("%s "),l_argv[i]);
  428. _tprintf(_T("\n"));
  429. DWORD retval1=MainFunc(l_argc,l_argv);
  430. retval = ((retval==0) ? retval1:retval);
  431. }
  432. if (oAdmin.GetpcAdmCom()!=NULL)
  433. {
  434. if(!Params.fNoSave)
  435. {
  436. oAdmin.SaveData();
  437. }
  438. }
  439. delete pStoredParams;
  440. }
  441. else
  442. {
  443. retval=MainFunc(argc,argv); //run only one command typed on the command line
  444. if (oAdmin.GetpcAdmCom()!=NULL)
  445. {
  446. if(Params.fNoSave)
  447. {
  448. oAdmin.SaveData();
  449. }
  450. }
  451. }
  452. }
  453. }
  454. //close admin object
  455. oAdmin.Close();
  456. //close wam adm object
  457. oAdmin.CloseWamAdm();
  458. CoUninitialize();
  459. //Cleanup of parameters
  460. if(argv!=0)
  461. {
  462. for (int i=0;i<argc;i++)
  463. {
  464. delete [] argv[i];
  465. }
  466. delete [] argv;
  467. }
  468. return retval;
  469. }
  470. int MainFunc(int argc, _TCHAR **argv)
  471. {
  472. g_argc=argc;
  473. g_argv=argv;
  474. DWORD retval;
  475. LPCTSTR lpszCommand=0;
  476. CAdmNode AdmNode;
  477. CAdmProp AdmProp;
  478. CAdmNode AdmDstNode;
  479. int i;
  480. DWORD dwCommandCode=0;
  481. //extract command line parameters
  482. ParseParam(argc,argv,CmdLineArgDesc);
  483. //PROCESS THE DEFAULT PARAMETERS
  484. // trick: place the default arguments into variables that apply for non default one (see Params structure)
  485. if (Params.wDefaultArgCount>0)
  486. {
  487. //first default has to be command
  488. Params.lpszCommand=Params.lplpszDefaultArg[0];
  489. dwCommandCode = tCommandNameTable::MapNameToCode(Params.lplpszDefaultArg[0]);
  490. if( Params.wDefaultArgCount>1)
  491. {
  492. //second deault has to be path
  493. Params.lpszPath=Params.lplpszDefaultArg[1];
  494. }
  495. if( Params.wDefaultArgCount>2)
  496. {
  497. switch(dwCommandCode)
  498. {
  499. case CMD_SET:
  500. //the rest of default args are values
  501. Params.wPropValueCount=0;
  502. for(i=2;i<Params.wDefaultArgCount;i++)
  503. {
  504. Params.lplpszPropValue[i-2] = Params.lplpszDefaultArg[i];
  505. Params.wPropValueCount++;
  506. }
  507. break;
  508. case CMD_DELETE:
  509. case CMD_CREATE:
  510. case CMD_GET:
  511. case CMD_ENUM:
  512. case CMD_ENUM_ALL:
  513. if( Params.wDefaultArgCount>2)
  514. {
  515. error_printf(_T("maximum default arguments number exceeds expected (2)\n"));
  516. return 1;
  517. }
  518. break;
  519. case CMD_COPY:
  520. case CMD_RENAME:
  521. case CMD_APPRENAME:
  522. if( Params.wDefaultArgCount>3)
  523. {
  524. error_printf(_T("maximum default arguments number exceeds expected (3)\n"));
  525. return 1;
  526. }
  527. else
  528. Params.lpszPathDst=Params.lplpszDefaultArg[2];
  529. break;
  530. default:
  531. error_printf(_T("command not recognized: %s or number of parameters doesn't match\n"),Params.lpszCommand);
  532. return 1;
  533. }
  534. }
  535. } //end of default argument handling
  536. //extract computer,service,instance, if stored in Path
  537. AdmNode.SetPath(Params.lpszPath);
  538. //valid only for copy function
  539. AdmDstNode.SetPath(Params.lpszPathDst);
  540. //process computer, service, instance, property name arguments
  541. if(Params.lpszComputer!=NULL) {
  542. if(!AdmNode.GetComputer().IsEmpty()) {
  543. error_printf(_T("computer name entered more than once\n"));
  544. return 1;
  545. }
  546. else
  547. AdmNode.SetComputer(Params.lpszComputer);
  548. }
  549. if(Params.lpszService!=NULL) {
  550. if(!AdmNode.GetService().IsEmpty()) {
  551. error_printf(_T("service name entered more than once\n"));
  552. return 1;
  553. }
  554. else {
  555. if(IsServiceName(Params.lpszService))
  556. AdmNode.SetService(Params.lpszService);
  557. else {
  558. error_printf(_T("service name not recognized: %s\n"), Params.lpszService);
  559. return 1;
  560. }
  561. }
  562. }
  563. if(Params.wInstance!=0)
  564. {
  565. if(!AdmNode.GetInstance().IsEmpty()) {
  566. error_printf(_T("instance entered more than once\n"));
  567. return 1;
  568. }
  569. else {
  570. _TCHAR buf[30];
  571. //!!! maybe ltoa should be used
  572. AdmNode.SetInstance(_itot(Params.wInstance,buf,10));
  573. }
  574. }
  575. //******************************************
  576. //process attrib, utype, dtype, value
  577. //property name first
  578. CString strProp=AdmNode.GetProperty();
  579. if(Params.lpszPropName!=NULL && !strProp.IsEmpty())
  580. {
  581. error_printf(_T("property name entered more than once\n"));
  582. return 1;
  583. }
  584. else if (Params.lpszPropName!=NULL)
  585. {
  586. AdmNode.SetProperty(Params.lpszPropName);
  587. }
  588. if(IsNumber(AdmNode.GetProperty()))
  589. {
  590. AdmProp.SetIdentifier(_ttol(AdmNode.GetProperty()));
  591. }
  592. else
  593. {
  594. DWORD dwIdentifier=MapPropertyNameToCode(AdmNode.GetProperty());
  595. if(dwIdentifier!=NAME_NOT_FOUND)
  596. {
  597. AdmProp.SetIdentifier(dwIdentifier);
  598. }
  599. }
  600. //process the attrib entered on command line
  601. if(Params.wPropAttribCount!=0)
  602. {
  603. DWORD dwAttrib=0;
  604. for (i=0;i<Params.wPropAttribCount;i++)
  605. {
  606. if(IsNumber(Params.lplpszPropAttrib[i]))
  607. dwAttrib += _ttol(Params.lplpszPropAttrib[i]);
  608. else
  609. {
  610. DWORD dwMapped=MapAttribNameToCode(Params.lplpszPropAttrib[i]);
  611. if(dwMapped==NAME_NOT_FOUND)
  612. {
  613. error_printf(_T("attribute name not resolved: %s\n"), Params.lplpszPropAttrib[i]);
  614. return 1;
  615. }
  616. else
  617. dwAttrib |= dwMapped;
  618. }
  619. }
  620. //overwrite the default attrib
  621. AdmProp.SetAttrib(dwAttrib) ;
  622. }
  623. //process the usertype entered on command line
  624. if(Params.wPropUserTypeCount!=0)
  625. {
  626. DWORD dwUserType=0;
  627. for (i=0;i<Params.wPropUserTypeCount;i++)
  628. {
  629. if(IsNumber(Params.lplpszPropUserType[i]))
  630. dwUserType += _ttol(Params.lplpszPropUserType[i]);
  631. else
  632. {
  633. DWORD dwMapped=MapUserTypeNameToCode(Params.lplpszPropUserType[i]);
  634. if(dwMapped==NAME_NOT_FOUND)
  635. {
  636. error_printf(_T("user type not resolved: %s\n"), Params.lplpszPropUserType[i]);
  637. return 1;
  638. }
  639. else
  640. dwUserType |= dwMapped;
  641. }
  642. }
  643. //overwrite the default UserType
  644. AdmProp.SetUserType(dwUserType) ;
  645. }
  646. //process the datatype entered on command line
  647. if(Params.wPropDataTypeCount!=0)
  648. {
  649. DWORD dwDataType=0;
  650. for (i=0;i<Params.wPropDataTypeCount;i++)
  651. {
  652. if(IsNumber(Params.lplpszPropDataType[i]))
  653. dwDataType += _ttol(Params.lplpszPropDataType[i]);
  654. else
  655. {
  656. DWORD dwMapped=MapDataTypeNameToCode(Params.lplpszPropDataType[i]);
  657. if(dwMapped==NAME_NOT_FOUND)
  658. {
  659. error_printf(_T("DataType type not resolved: %s\n"), Params.lplpszPropDataType[i]);
  660. return 1;
  661. }
  662. else
  663. dwDataType |= dwMapped;
  664. }
  665. }
  666. //overwrite the default DataTypeType
  667. AdmProp.SetDataType(dwDataType) ;
  668. }
  669. //LPCTSTR lplpszPropValue[MAX_NUMBER_OF_PROPERTY_VALUES]; //pointer to array of values (e.g multisz type allows the multiple values for one property
  670. //WORD wPropValueCount;
  671. //create admin object
  672. if(oAdmin.GetpcAdmCom()==NULL)
  673. {
  674. oAdmin.Open(AdmNode.GetComputer());
  675. if( FAILED(oAdmin.QueryLastHresError()))
  676. {
  677. retval= ConvertHresToDword(oAdmin.QueryLastHresError());
  678. }
  679. }
  680. if(oAdmin.GetpcAdmCom()!=NULL)
  681. {
  682. //
  683. // read from files if Params.wPropFileValueCount != 0
  684. //
  685. if ( Params.wPropFileValueCount )
  686. {
  687. if ( !ReadFromFiles( (LPTSTR*)Params.lplpszPropValue, Params.lpdwPropValueLength, Params.wPropFileValueCount ) )
  688. {
  689. error_printf(_T("Can't read value from file %s"), Params.lplpszPropValue[0] );
  690. return 1;
  691. }
  692. Params.wPropValueCount = Params.wPropFileValueCount;
  693. }
  694. {
  695. CString strT(Params.lpszCommand);
  696. oAdmin.Run( strT,
  697. AdmNode,
  698. AdmProp,
  699. AdmDstNode,
  700. Params.lplpszPropValue,
  701. Params.lpdwPropValueLength,
  702. Params.wPropValueCount);
  703. retval=ConvertHresToDword(oAdmin.QueryLastHresError());
  704. }
  705. }
  706. return ((retval==0)?0:1);
  707. }