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.

768 lines
23 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 APPCREATEOUTPROC w3svc/1/root - Create an out-proc application\n")
  94. _T(" mdutil APPDELETE w3svc/1/root - Delete the application if there is one\n")
  95. _T(" mdutil APPRENAME w3svc/1/root/dira w3svc/1/root/dirb - Rename the application \n")
  96. _T(" mdutil APPUNLOAD w3svc/1/root - Unload an application from w3svc runtime lookup table.\n")
  97. _T(" mdutil APPGETSTATUS w3svc/1/root - Get status of the application\n")
  98. _T("\n")
  99. _T(" -path has format: {computer}/{service}/{instance}/{URL}/{Parameter}\n")
  100. _T("\n")
  101. _T("Samples:\n")
  102. _T(" mdutil GET W3SVC/1/ServerBindings \n")
  103. _T(" mdutil SET JAROSLAD2/W3SVC/1/ServerBindings \":81:\"\n")
  104. _T(" mdutil COPY W3SVC/1/ROOT/iisadmin W3SVC/2/ROOT/adm\n")
  105. _T(" mdutil ENUM_ALL W3SVC\n")
  106. _T(" mdutil ENUM W3SVC/1\n")
  107. _T("\n")
  108. _T("Additional features\n")
  109. _T(" set MDUTIL_BLOCK_ON_ERROR environment variable to block mdutil.exe after error (except ERROR_PATH_NOT_FOUND)\n")
  110. _T(" set MDUTIL_ASCENT_LOG environment variable to force mdutil.exe to append errors to ascent log\n")
  111. _T(" set MDUTIL_PRINT_ID environment variable to force mdutil.exe to print metadata numeric identifiers along with friendly names\n")
  112. }
  113. };
  114. BOOL
  115. ReadFromFiles(
  116. LPTSTR* lplpszPropValue,
  117. DWORD* lpdwPropValueLength,
  118. DWORD dwPropFileValueCount
  119. )
  120. {
  121. DWORD dwL;
  122. while ( dwPropFileValueCount-- )
  123. {
  124. FILE* fIn = _tfopen( lplpszPropValue[dwPropFileValueCount], _T("rb") );
  125. if ( fIn == NULL )
  126. {
  127. return FALSE;
  128. }
  129. if ( fseek( fIn, 0, SEEK_END ) == 0 )
  130. {
  131. dwL = ftell( fIn );
  132. fseek( fIn, 0, SEEK_SET );
  133. }
  134. else
  135. {
  136. fclose( fIn );
  137. return FALSE;
  138. }
  139. if ( (lplpszPropValue[dwPropFileValueCount] = (LPTSTR)malloc( dwL )) == NULL )
  140. {
  141. fclose( fIn );
  142. return FALSE;
  143. }
  144. if ( fread( lplpszPropValue[dwPropFileValueCount], 1, dwL, fIn ) != dwL )
  145. {
  146. fclose( fIn );
  147. return FALSE;
  148. }
  149. fclose( fIn );
  150. lpdwPropValueLength[dwPropFileValueCount] = dwL;
  151. }
  152. return TRUE;
  153. }
  154. ///////////////////////////////
  155. class CScript
  156. {
  157. FILE * m_fpScript;
  158. void GetNextToken(/*OUT*/ LPTSTR * lplpszToken);
  159. DWORD CleanWhiteSpaces(void);
  160. public:
  161. CScript(void) {m_fpScript=0;};
  162. DWORD Open(LPCTSTR lpszFile);
  163. DWORD Close(void);
  164. DWORD GetNextLineTokens(int *argc, /*OUT*/ _TCHAR *** argv);
  165. };
  166. DWORD CScript::CleanWhiteSpaces()
  167. {
  168. if(m_fpScript!=NULL)
  169. {
  170. int LastChar=0;
  171. _TINT c=0;
  172. while(1)
  173. {
  174. LastChar=c;
  175. c=_fgettc(m_fpScript);
  176. if(c==_T('\t') || c==_T(' ') || c==_T('\r'))
  177. { continue;
  178. }
  179. if(c==_T('\\'))
  180. {
  181. int cc=_fgettc(m_fpScript);
  182. if (cc==_T('\r')) //continue with the next line of the file
  183. {
  184. if(_fgettc(m_fpScript)!=_T('\n'))
  185. {
  186. fseek( m_fpScript, -1, SEEK_CUR );
  187. }
  188. continue;
  189. }
  190. else if (cc==_T('\n')) //continue with the next line of the file
  191. {
  192. continue;
  193. }
  194. else
  195. {
  196. fseek( m_fpScript, -2, SEEK_CUR );
  197. break;
  198. }
  199. }
  200. if(c==WEOF)
  201. { break;
  202. }
  203. else
  204. { fseek( m_fpScript, -1, SEEK_CUR ); //return back one position
  205. break;
  206. }
  207. }
  208. }
  209. return 0;
  210. }
  211. void CScript::GetNextToken(LPTSTR * lplpszToken)
  212. {
  213. enum {TERMINATE_QUOTE, TERMINATE_WHITESPACE};
  214. long flag=TERMINATE_WHITESPACE;
  215. //clean white spaces
  216. CleanWhiteSpaces();
  217. //store the beginning offset of token
  218. long Offset = ftell(m_fpScript);
  219. _TINT c=_fgettc(m_fpScript);
  220. long CurrentOffset=0;
  221. if(c==WEOF)
  222. {
  223. *lplpszToken=NULL;
  224. return ;
  225. }
  226. if (c==_T('\n')){
  227. *lplpszToken=_T("\n");
  228. return ;
  229. }
  230. else
  231. {
  232. if (c==_T('\"')) { //token ends with " or the end of the line
  233. flag=TERMINATE_QUOTE;
  234. Offset = ftell(m_fpScript);
  235. }
  236. else {
  237. flag=TERMINATE_WHITESPACE;
  238. }
  239. // find the end of the token
  240. while(1) {
  241. CurrentOffset=ftell(m_fpScript);
  242. c=_fgettc(m_fpScript);
  243. if(c==_T('\n')){
  244. break;
  245. }
  246. if(c==WEOF)
  247. {
  248. break;
  249. }
  250. if( (flag==TERMINATE_QUOTE && c==_T('\"')) || (
  251. flag==TERMINATE_WHITESPACE && (c==_T(' ') || c==_T('\t') || c==_T('\r')) ) ){
  252. break;
  253. }
  254. }
  255. //get the token size
  256. long TokenSize = CurrentOffset - Offset;
  257. if(TokenSize!=0)
  258. {
  259. // allocate mamory for the token
  260. *lplpszToken = new _TCHAR[ TokenSize+1 ];
  261. //read the token
  262. fseek( m_fpScript, Offset, SEEK_SET);
  263. for(int i=0;i<TokenSize;i++)
  264. (*lplpszToken)[i]=(TCHAR)_fgettc(m_fpScript);
  265. //terminate the token
  266. (*lplpszToken)[i]=0;
  267. }
  268. else
  269. { //empty string
  270. *lplpszToken=new _TCHAR[1 ];
  271. (*lplpszToken)[0]=0;
  272. }
  273. //discard double quote if it was at the end of the token
  274. c=_fgettc(m_fpScript);
  275. if(c!=_T('\"'))
  276. fseek( m_fpScript, ((c==WEOF)?0:-1), SEEK_CUR );
  277. }
  278. }
  279. DWORD CScript::Open(LPCTSTR lpszFile)
  280. {
  281. m_fpScript = _tfopen( lpszFile, _T("rt") );
  282. if(m_fpScript==NULL)
  283. return GetLastError();
  284. else
  285. return ERROR_SUCCESS;
  286. }
  287. DWORD CScript::Close()
  288. {
  289. if( m_fpScript!=NULL)
  290. fclose( m_fpScript);
  291. return GetLastError();
  292. }
  293. DWORD CScript::GetNextLineTokens(int *argc, /*OUT*/ _TCHAR *** argv)
  294. {
  295. for(int i=1;i<*argc;i++) {
  296. delete (*argv)[i];
  297. (*argv)[i]=0;
  298. }
  299. *argc=0;
  300. if(*argv==NULL)
  301. (*argv)=new LPTSTR [ MAX_NUMBER_OF_VALUES ];
  302. (*argv)[(*argc)++]=_T("mdutil"); //set zero parameter
  303. LPTSTR lpszNextToken=NULL;
  304. while((*argc)<MAX_NUMBER_OF_VALUES) {
  305. GetNextToken(&lpszNextToken);
  306. if(lpszNextToken==NULL ) //end of file
  307. break;
  308. if(_tcscmp(lpszNextToken,_T("\n"))==0) //new line
  309. break;
  310. (*argv)[(*argc)++]=lpszNextToken;
  311. }
  312. return GetLastError();
  313. }
  314. int MainFunc(int argc, _TCHAR **argv); //declaration
  315. //MAIN FUNCTION
  316. int __cdecl main(int argc, CHAR **_argv)
  317. {
  318. // convert parameters from SBCS to UNICODE;
  319. _TCHAR **argv= new LPTSTR [argc];
  320. for (int i=0;i<argc;i++)
  321. {
  322. argv[i]=new _TCHAR[strlen(_argv[i])+1];
  323. #ifdef UNICODE
  324. MultiByteToWideChar(0, 0, _argv[i], -1, argv[i],strlen(_argv[i])+1 );
  325. #else
  326. strcpy(argv[i],_argv[i]);
  327. #endif
  328. }
  329. DWORD dwCommandCode=0;
  330. DWORD retval=0;
  331. HRESULT hRes;
  332. hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  333. if (FAILED(hRes)) {
  334. fatal_error_printf(_T("CoInitializeEx\n"));
  335. }
  336. //extract command line parameters
  337. ParseParam(argc,argv,CmdLineArgDesc);
  338. //**************************
  339. //PRINT HELP ON REQUEST
  340. if(Params.fFullHelp)
  341. {
  342. //print help
  343. DisplayUsage(argv,CmdLineArgDesc);
  344. PrintTablesInfo();
  345. }
  346. else if(Params.wDefaultArgCount==0 || Params.fHelp)
  347. {
  348. //print help
  349. DisplayUsage(argv,CmdLineArgDesc);
  350. }
  351. else
  352. {
  353. if (Params.wDefaultArgCount>0)
  354. {
  355. //first default has to be command
  356. Params.lpszCommand=Params.lplpszDefaultArg[0];
  357. dwCommandCode = tCommandNameTable::MapNameToCode(Params.lplpszDefaultArg[0]);
  358. if( Params.wDefaultArgCount>1)
  359. { //second default
  360. Params.lpszPath=Params.lplpszDefaultArg[1];
  361. }
  362. if(dwCommandCode==CMD_SCRIPT) //process script
  363. {
  364. tAdmutilParams StoredParams=Params;
  365. CScript Script;
  366. DWORD dwRes;
  367. if((dwRes=Script.Open(Params.lpszPath))!=ERROR_SUCCESS)
  368. fatal_error_printf(_T("cannot open script file %s (error %d)\n"),Params.lpszPath,dwRes);
  369. int l_argc=0;
  370. _TCHAR ** l_argv=NULL;
  371. while(1)
  372. {
  373. Script.GetNextLineTokens(&l_argc,&l_argv);
  374. if(l_argc==1) //end of script file
  375. break;
  376. Params=StoredParams;
  377. _tprintf(_T(">"));
  378. for(int i=1;i<l_argc;i++)
  379. _tprintf(_T("%s "),l_argv[i]);
  380. _tprintf(_T("\n"));
  381. DWORD retval1=MainFunc(l_argc,l_argv);
  382. retval = ((retval==0) ? retval1:retval);
  383. }
  384. if (oAdmin.GetpcAdmCom()!=NULL)
  385. {
  386. if(Params.fNoSave)
  387. {}
  388. else
  389. oAdmin.SaveData();
  390. }
  391. }
  392. else
  393. {
  394. retval=MainFunc(argc,argv); //run only one command typed on the command line
  395. if (oAdmin.GetpcAdmCom()!=NULL)
  396. {
  397. if(Params.fNoSave)
  398. {}
  399. else
  400. oAdmin.SaveData();
  401. }
  402. }
  403. }
  404. }
  405. //close admin object
  406. oAdmin.Close();
  407. //close wam adm object
  408. oAdmin.CloseWamAdm();
  409. CoUninitialize();
  410. //Cleanup of parameters
  411. if(argv!=0)
  412. {
  413. for (int i=0;i<argc;i++)
  414. {
  415. delete [] argv[i];
  416. }
  417. delete argv;
  418. }
  419. return retval;
  420. }
  421. int MainFunc(int argc, _TCHAR **argv)
  422. {
  423. g_argc=argc;
  424. g_argv=argv;
  425. DWORD retval;
  426. LPCTSTR lpszCommand=0;
  427. CAdmNode AdmNode;
  428. CAdmProp AdmProp;
  429. CAdmNode AdmDstNode;
  430. int i;
  431. DWORD dwCommandCode=0;
  432. //extract command line parameters
  433. ParseParam(argc,argv,CmdLineArgDesc);
  434. //PROCESS THE DEFAULT PARAMETERS
  435. // trick: place the default arguments into variables that apply for non default one (see Params structure)
  436. if (Params.wDefaultArgCount>0)
  437. { //first default has to be command
  438. Params.lpszCommand=Params.lplpszDefaultArg[0];
  439. dwCommandCode = tCommandNameTable::MapNameToCode(Params.lplpszDefaultArg[0]);
  440. if( Params.wDefaultArgCount>1)
  441. {//second deault has to be path
  442. Params.lpszPath=Params.lplpszDefaultArg[1];
  443. }
  444. if( Params.wDefaultArgCount>2)
  445. {
  446. switch(dwCommandCode)
  447. {
  448. case CMD_SET:
  449. //the rest of default args are values
  450. Params.wPropValueCount=0;
  451. for(i=2;i<Params.wDefaultArgCount;i++)
  452. {
  453. Params.lplpszPropValue[i-2] = Params.lplpszDefaultArg[i];
  454. Params.wPropValueCount++;
  455. }
  456. break;
  457. case CMD_DELETE:
  458. case CMD_CREATE:
  459. case CMD_GET:
  460. case CMD_ENUM:
  461. case CMD_ENUM_ALL:
  462. if( Params.wDefaultArgCount>2)
  463. {
  464. error_printf(_T("maximum default arguments number exceeds expected (2)\n"));
  465. return 1;
  466. }
  467. break;
  468. case CMD_COPY:
  469. case CMD_RENAME:
  470. case CMD_APPRENAME:
  471. if( Params.wDefaultArgCount>3)
  472. {
  473. error_printf(_T("maximum default arguments number exceeds expected (3)\n"));
  474. return 1;
  475. }
  476. else
  477. Params.lpszPathDst=Params.lplpszDefaultArg[2];
  478. break;
  479. default:
  480. error_printf(_T("command not recognized: %s or number of parameters doesn't match\n"),Params.lpszCommand);
  481. return 1;
  482. }
  483. }
  484. } //end of default argument handling
  485. //extract computer,service,instance, if stored in Path
  486. AdmNode.SetPath(Params.lpszPath);
  487. //valid only for copy function
  488. AdmDstNode.SetPath(Params.lpszPathDst);
  489. //process computer, service, instance, property name arguments
  490. if(Params.lpszComputer!=NULL) {
  491. if(!AdmNode.GetComputer().IsEmpty()) {
  492. error_printf(_T("computer name entered more than once\n"));
  493. return 1;
  494. }
  495. else
  496. AdmNode.SetComputer(Params.lpszComputer);
  497. }
  498. if(Params.lpszService!=NULL) {
  499. if(!AdmNode.GetService().IsEmpty()) {
  500. error_printf(_T("service name entered more than once\n"));
  501. return 1;
  502. }
  503. else {
  504. if(IsServiceName(Params.lpszService))
  505. AdmNode.SetService(Params.lpszService);
  506. else {
  507. error_printf(_T("service name not recognized: %s\n"), Params.lpszService);
  508. return 1;
  509. }
  510. }
  511. }
  512. if(Params.wInstance!=0)
  513. {
  514. if(!AdmNode.GetInstance().IsEmpty()) {
  515. error_printf(_T("instance entered more than once\n"));
  516. return 1;
  517. }
  518. else {
  519. _TCHAR buf[30];
  520. //!!! maybe ltoa should be used
  521. AdmNode.SetInstance(_itot(Params.wInstance,buf,10));
  522. }
  523. }
  524. //******************************************
  525. //process attrib, utype, dtype, value
  526. //property name first
  527. CString strProp=AdmNode.GetProperty();
  528. if(Params.lpszPropName!=NULL && !strProp.IsEmpty())
  529. {
  530. error_printf(_T("property name entered more than once\n"));
  531. return 1;
  532. }
  533. else if (Params.lpszPropName!=NULL)
  534. {
  535. AdmNode.SetProperty(Params.lpszPropName);
  536. }
  537. if(IsNumber(AdmNode.GetProperty()))
  538. {
  539. AdmProp.SetIdentifier(_ttol(AdmNode.GetProperty()));
  540. }
  541. else
  542. {
  543. DWORD dwIdentifier=MapPropertyNameToCode(AdmNode.GetProperty());
  544. if(dwIdentifier==NAME_NOT_FOUND)
  545. {}
  546. else
  547. AdmProp.SetIdentifier(dwIdentifier) ;
  548. }
  549. //process the attrib entered on command line
  550. if(Params.wPropAttribCount!=0)
  551. { DWORD dwAttrib=0;
  552. for (i=0;i<Params.wPropAttribCount;i++)
  553. {
  554. if(IsNumber(Params.lplpszPropAttrib[i]))
  555. dwAttrib += _ttol(Params.lplpszPropAttrib[i]);
  556. else
  557. {
  558. DWORD dwMapped=MapAttribNameToCode(Params.lplpszPropAttrib[i]);
  559. if(dwMapped==NAME_NOT_FOUND)
  560. {
  561. error_printf(_T("attribute name not resolved: %s\n"), Params.lplpszPropAttrib[i]);
  562. return 1;
  563. }
  564. else
  565. dwAttrib |= dwMapped;
  566. }
  567. }
  568. //overwrite the default attrib
  569. AdmProp.SetAttrib(dwAttrib) ;
  570. }
  571. //process the usertype entered on command line
  572. if(Params.wPropUserTypeCount!=0)
  573. { DWORD dwUserType=0;
  574. for (i=0;i<Params.wPropUserTypeCount;i++)
  575. {
  576. if(IsNumber(Params.lplpszPropUserType[i]))
  577. dwUserType += _ttol(Params.lplpszPropUserType[i]);
  578. else
  579. {
  580. DWORD dwMapped=MapUserTypeNameToCode(Params.lplpszPropUserType[i]);
  581. if(dwMapped==NAME_NOT_FOUND)
  582. {
  583. error_printf(_T("user type not resolved: %s\n"), Params.lplpszPropUserType[i]);
  584. return 1;
  585. }
  586. else
  587. dwUserType |= dwMapped;
  588. }
  589. }
  590. //overwrite the default UserType
  591. AdmProp.SetUserType(dwUserType) ;
  592. }
  593. //process the datatype entered on command line
  594. if(Params.wPropDataTypeCount!=0)
  595. { DWORD dwDataType=0;
  596. for (i=0;i<Params.wPropDataTypeCount;i++)
  597. {
  598. if(IsNumber(Params.lplpszPropDataType[i]))
  599. dwDataType += _ttol(Params.lplpszPropDataType[i]);
  600. else
  601. {
  602. DWORD dwMapped=MapDataTypeNameToCode(Params.lplpszPropDataType[i]);
  603. if(dwMapped==NAME_NOT_FOUND)
  604. {
  605. error_printf(_T("DataType type not resolved: %s\n"), Params.lplpszPropDataType[i]);
  606. return 1;
  607. }
  608. else
  609. dwDataType |= dwMapped;
  610. }
  611. }
  612. //overwrite the default DataTypeType
  613. AdmProp.SetDataType(dwDataType) ;
  614. }
  615. //LPCTSTR lplpszPropValue[MAX_NUMBER_OF_PROPERTY_VALUES]; //pointer to array of values (e.g multisz type allows the multiple values for one property
  616. //WORD wPropValueCount;
  617. //create admin object
  618. if(oAdmin.GetpcAdmCom()==NULL)
  619. {
  620. oAdmin.Open(AdmNode.GetComputer());
  621. if( FAILED(oAdmin.QueryLastHresError()))
  622. {
  623. retval= ConvertHresToDword(oAdmin.QueryLastHresError());
  624. }
  625. }
  626. if(oAdmin.GetpcAdmCom()!=NULL)
  627. {
  628. //
  629. // read from files if Params.wPropFileValueCount != 0
  630. //
  631. if ( Params.wPropFileValueCount )
  632. {
  633. if ( !ReadFromFiles( (LPTSTR*)Params.lplpszPropValue, Params.lpdwPropValueLength, Params.wPropFileValueCount ) )
  634. {
  635. error_printf(_T("Can't read value from file %s"), Params.lplpszPropValue[0] );
  636. return 1;
  637. }
  638. Params.wPropValueCount = Params.wPropFileValueCount;
  639. }
  640. oAdmin.Run(CString(Params.lpszCommand),
  641. AdmNode,
  642. AdmProp,
  643. AdmDstNode,
  644. Params.lplpszPropValue,
  645. Params.lpdwPropValueLength,
  646. Params.wPropValueCount);
  647. retval=ConvertHresToDword(oAdmin.QueryLastHresError());
  648. }
  649. return ((retval==0)?0:1);
  650. }