| OLD | NEW |
| (Empty) |
| 1 // Copyright 2007-2009 Google Inc. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 // ======================================================================== | |
| 15 | |
| 16 #include "omaha/common/command_line.h" | |
| 17 #include "omaha/base/command_line_parser.h" | |
| 18 #include "omaha/base/debug.h" | |
| 19 #include "omaha/base/logging.h" | |
| 20 #include "omaha/common/goopdate_command_line_validator.h" | |
| 21 | |
| 22 namespace omaha { | |
| 23 | |
| 24 // Returns a pointer to the second token in the cmd_line parameter or an | |
| 25 // empty string. See the implementation in vc7\crt\src\wincmdln.c | |
| 26 // | |
| 27 // TODO(omaha): consider moving this function into the tiny shell, as it | |
| 28 // is logically part of our modified runtime environment. | |
| 29 TCHAR* GetCmdLineTail(const TCHAR* cmd_line) { | |
| 30 ASSERT1(cmd_line); | |
| 31 bool in_quote = false; | |
| 32 | |
| 33 // Skip past program name (first token in command line). | |
| 34 // Check for and handle quoted program name. | |
| 35 | |
| 36 while ((*cmd_line > _T(' ')) || | |
| 37 (*cmd_line && in_quote)) { | |
| 38 // Flip the in_quote if current character is '"'. | |
| 39 if (*cmd_line == _T('"')) { | |
| 40 in_quote = !in_quote; | |
| 41 } | |
| 42 ++cmd_line; | |
| 43 } | |
| 44 | |
| 45 // Skip past any white space preceeding the second token. | |
| 46 while (*cmd_line && (*cmd_line <= _T(' '))) { | |
| 47 cmd_line++; | |
| 48 } | |
| 49 | |
| 50 return const_cast<TCHAR*>(cmd_line); | |
| 51 } | |
| 52 | |
| 53 // Assumption: The metainstaller has verified that space ' ' and | |
| 54 // double quote '"' characters do not appear in the "extra" arguments. | |
| 55 // This is important so that attackers can't create tags that provide a valid | |
| 56 // extra argument string followed by other commands. | |
| 57 HRESULT ParseCommandLine(const TCHAR* cmd_line, CommandLineArgs* args) { | |
| 58 ASSERT1(cmd_line); | |
| 59 ASSERT1(args); | |
| 60 CORE_LOG(L3, (_T("[ParseCommandLine][%s]"), cmd_line)); | |
| 61 | |
| 62 CommandLineParser parser; | |
| 63 HRESULT hr = parser.ParseFromString(cmd_line); | |
| 64 if (FAILED(hr)) { | |
| 65 CORE_LOG(LE, (_T("[ParseCommandLine][ParseFromString failed][0x%x]"), hr)); | |
| 66 return hr; | |
| 67 } | |
| 68 | |
| 69 GoopdateCommandLineValidator validator; | |
| 70 hr = validator.Setup(); | |
| 71 if (FAILED(hr)) { | |
| 72 CORE_LOG(LE, (_T("[ParseCommandLine][Validator Setup failed][0x%x]"), hr)); | |
| 73 return hr; | |
| 74 } | |
| 75 | |
| 76 hr = validator.Validate(&parser, args); | |
| 77 if (FAILED(hr)) { | |
| 78 CORE_LOG(LE, (_T("[ParseCommandLine][Validate failed][0x%x]"), hr)); | |
| 79 return hr; | |
| 80 } | |
| 81 | |
| 82 return S_OK; | |
| 83 } | |
| 84 | |
| 85 } // namespace omaha | |
| 86 | |
| OLD | NEW |