1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "sandbox/win/src/restricted_token_utils.h"
6 #include "sandbox/win/tools/finder/finder.h"
8 #define PARAM_IS(y) (argc > i) && (_wcsicmp(argv[i], y) == 0)
10 void PrintUsage(wchar_t *application_name
) {
11 wprintf(L
"\n\nUsage: \n %ls --token type --object ob1 [ob2 ob3] "
12 L
"--access ac1 [ac2 ac3] [--log filename]", application_name
);
13 wprintf(L
"\n\n Token Types : \n\tLOCKDOWN \n\tRESTRICTED "
14 L
"\n\tLIMITED_USER \n\tINTERACTIVE_USER \n\tNON_ADMIN \n\tUNPROTECTED");
15 wprintf(L
"\n Object Types: \n\tREG \n\tFILE \n\tKERNEL");
16 wprintf(L
"\n Access Types: \n\tR \n\tW \n\tALL");
17 wprintf(L
"\n\nSample: \n %ls --token LOCKDOWN --object REG FILE KERNEL "
18 L
"--access R W ALL", application_name
);
21 int wmain(int argc
, wchar_t* argv
[]) {
22 // Extract the filename from the path.
23 wchar_t *app_name
= wcsrchr(argv
[0], L
'\\');
31 ATL::CString log_file
;
32 sandbox::TokenLevel token_type
= sandbox::USER_LOCKDOWN
;
33 DWORD object_type
= 0;
34 DWORD access_type
= 0;
42 // parse command line.
43 for (int i
= 1; i
< argc
; ++i
) {
44 if (PARAM_IS(L
"--token")) {
47 if (PARAM_IS(L
"LOCKDOWN")) {
48 token_type
= sandbox::USER_LOCKDOWN
;
49 } else if (PARAM_IS(L
"RESTRICTED")) {
50 token_type
= sandbox::USER_RESTRICTED
;
51 } else if (PARAM_IS(L
"LIMITED_USER")) {
52 token_type
= sandbox::USER_LIMITED
;
53 } else if (PARAM_IS(L
"INTERACTIVE_USER")) {
54 token_type
= sandbox::USER_INTERACTIVE
;
55 } else if (PARAM_IS(L
"NON_ADMIN")) {
56 token_type
= sandbox::USER_NON_ADMIN
;
57 } else if (PARAM_IS(L
"USER_RESTRICTED_SAME_ACCESS")) {
58 token_type
= sandbox::USER_RESTRICTED_SAME_ACCESS
;
59 } else if (PARAM_IS(L
"UNPROTECTED")) {
60 token_type
= sandbox::USER_UNPROTECTED
;
62 wprintf(L
"\nAbord. Invalid token type \"%ls\"", argv
[i
]);
67 } else if (PARAM_IS(L
"--object")) {
68 bool is_object
= true;
71 if (PARAM_IS(L
"REG")) {
72 object_type
|= kScanRegistry
;
73 } else if (PARAM_IS(L
"FILE")) {
74 object_type
|= kScanFileSystem
;
75 } else if (PARAM_IS(L
"KERNEL")) {
76 object_type
|= kScanKernelObjects
;
82 } else if (PARAM_IS(L
"--access")) {
83 bool is_access
= true;
87 access_type
|= kTestForRead
;
88 } else if (PARAM_IS(L
"W")) {
89 access_type
|= kTestForWrite
;
90 } else if (PARAM_IS(L
"ALL")) {
91 access_type
|= kTestForAll
;
97 } else if (PARAM_IS(L
"--log")) {
103 wprintf(L
"\nAbord. No log file specified");
104 PrintUsage(app_name
);
108 wprintf(L
"\nAbord. Unrecognized parameter \"%ls\"", argv
[i
]);
109 PrintUsage(app_name
);
114 // validate parameters
115 if (0 == access_type
) {
116 wprintf(L
"\nAbord, Access type not specified");
117 PrintUsage(app_name
);
121 if (0 == object_type
) {
122 wprintf(L
"\nAbord, Object type not specified");
123 PrintUsage(app_name
);
130 if (log_file
.GetLength()) {
131 errno_t err
= _wfopen_s(&file_output
, log_file
, L
"w");
133 wprintf(L
"\nAbord, Cannot open file \"%ls\"", log_file
.GetBuffer());
137 file_output
= stdout
;
141 finder_obj
.Init(token_type
, object_type
, access_type
, file_output
);