Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
bc52693f
Commit
bc52693f
authored
Apr 02, 2024
by
Hans Leidekker
Committed by
Alexandre Julliard
Apr 02, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wmic: Handle multiple properties separated by whitespace.
parent
ca629dec
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
43 deletions
+50
-43
main.c
programs/wmic/main.c
+50
-43
No files found.
programs/wmic/main.c
View file @
bc52693f
...
@@ -107,62 +107,67 @@ static int output_newline( void )
...
@@ -107,62 +107,67 @@ static int output_newline( void )
return
output_string
(
L"
\n
"
);
return
output_string
(
L"
\n
"
);
}
}
static
WCHAR
*
strip_spaces
(
WCHAR
*
start
)
static
WCHAR
*
strip_spaces
(
WCHAR
*
start
)
{
{
WCHAR
*
str
=
start
,
*
end
;
WCHAR
*
str
=
start
,
*
end
=
start
+
wcslen
(
start
)
-
1
;
while
(
*
str
==
' '
)
str
++
;
while
(
*
str
==
' '
)
while
(
end
>=
start
&&
*
end
==
' '
)
*
end
--
=
0
;
str
++
;
return
str
;
}
end
=
start
+
lstrlenW
(
start
)
-
1
;
static
HRESULT
append_property
(
IWbemClassObject
*
obj
,
const
WCHAR
*
prop
,
WCHAR
*
proplist
)
while
(
end
>=
start
&&
*
end
==
' '
)
{
{
HRESULT
hr
;
*
end
=
'\0'
;
end
--
;
}
return
str
;
if
(
FAILED
(
hr
=
IWbemClassObject_Get
(
obj
,
prop
,
0
,
NULL
,
NULL
,
NULL
)))
return
hr
;
if
(
*
proplist
)
wcscat
(
proplist
,
L","
);
wcscat
(
proplist
,
prop
);
return
S_OK
;
}
}
static
HRESULT
process_property_list
(
IWbemClassObject
*
obj
,
const
WCHAR
*
proplist
,
WCHAR
**
ret
)
static
HRESULT
process_property_list
(
IWbemClassObject
*
obj
,
int
argc
,
WCHAR
*
argv
[]
,
WCHAR
**
ret
)
{
{
WCHAR
*
p
,
*
ctx
,
*
ptr
,
*
stripped
;
WCHAR
*
str
=
NULL
,
*
ctx
,
*
ptr
,
*
stripped
;
HRESULT
hr
=
S_OK
;
UINT
i
,
len
=
0
;
HRESULT
hr
;
if
(
!
(
p
=
wcsdup
(
proplist
)))
return
E_OUTOFMEMORY
;
for
(
i
=
0
;
i
<
argc
;
i
++
)
len
+=
wcslen
(
argv
[
i
]
);
if
(
!
(
stripped
=
malloc
(
(
len
+
1
)
*
sizeof
(
*
stripped
)
)))
return
E_OUTOFMEMORY
;
*
stripped
=
0
;
if
(
!
(
stripped
=
malloc
(
(
wcslen
(
proplist
)
+
1
)
*
sizeof
(
**
ret
)
))
)
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
{
free
(
p
);
if
(
!
(
str
=
wcsdup
(
argv
[
i
]
)))
{
free
(
stripped
);
return
E_OUTOFMEMORY
;
return
E_OUTOFMEMORY
;
}
}
*
stripped
=
0
;
/* Validate that every requested property is supported. */
/* Validate that every requested property is supported. */
ptr
=
wcstok_s
(
p
,
L","
,
&
ctx
);
ptr
=
wcstok_s
(
str
,
L","
,
&
ctx
);
if
(
!
ptr
)
{
ptr
=
strip_spaces
(
str
);
if
(
FAILED
(
hr
=
append_property
(
obj
,
ptr
,
stripped
)))
goto
error
;
}
else
{
while
(
ptr
)
while
(
ptr
)
{
{
ptr
=
strip_spaces
(
ptr
);
ptr
=
strip_spaces
(
ptr
);
if
(
FAILED
(
hr
=
append_property
(
obj
,
ptr
,
stripped
)))
goto
error
;
if
(
FAILED
(
IWbemClassObject_Get
(
obj
,
ptr
,
0
,
NULL
,
NULL
,
NULL
)))
{
hr
=
E_FAIL
;
break
;
}
if
(
*
stripped
)
wcscat
(
stripped
,
L","
);
wcscat
(
stripped
,
ptr
);
ptr
=
wcstok_s
(
NULL
,
L","
,
&
ctx
);
ptr
=
wcstok_s
(
NULL
,
L","
,
&
ctx
);
}
}
free
(
p
);
}
free
(
str
);
}
if
(
SUCCEEDED
(
hr
))
*
ret
=
stripped
;
*
ret
=
stripped
;
else
return
S_OK
;
{
free
(
stripped
);
*
ret
=
NULL
;
}
error:
free
(
str
);
free
(
stripped
);
return
hr
;
return
hr
;
}
}
...
@@ -218,7 +223,7 @@ done:
...
@@ -218,7 +223,7 @@ done:
WINE_FIXME
(
"Could not convert variant, vt %u.
\n
"
,
vt
);
WINE_FIXME
(
"Could not convert variant, vt %u.
\n
"
,
vt
);
}
}
static
int
query_prop
(
const
WCHAR
*
class
,
const
WCHAR
*
propnames
)
static
int
query_prop
(
const
WCHAR
*
class
,
int
argc
,
WCHAR
*
argv
[]
)
{
{
HRESULT
hr
;
HRESULT
hr
;
IWbemLocator
*
locator
=
NULL
;
IWbemLocator
*
locator
=
NULL
;
...
@@ -231,8 +236,11 @@ static int query_prop( const WCHAR *class, const WCHAR *propnames )
...
@@ -231,8 +236,11 @@ static int query_prop( const WCHAR *class, const WCHAR *propnames )
IWbemClassObject
*
obj
;
IWbemClassObject
*
obj
;
ULONG
count
,
width
=
0
;
ULONG
count
,
width
=
0
;
VARIANT
v
;
VARIANT
v
;
int
i
;
WINE_TRACE
(
"%s, %s
\n
"
,
debugstr_w
(
class
),
debugstr_w
(
propnames
));
WINE_TRACE
(
"%s"
,
debugstr_w
(
class
)
);
for
(
i
=
0
;
i
<
argc
;
i
++
)
WINE_TRACE
(
" %s"
,
debugstr_w
(
argv
[
i
])
);
WINE_TRACE
(
"
\n
"
);
CoInitialize
(
NULL
);
CoInitialize
(
NULL
);
CoInitializeSecurity
(
NULL
,
-
1
,
NULL
,
NULL
,
RPC_C_AUTHN_LEVEL_DEFAULT
,
CoInitializeSecurity
(
NULL
,
-
1
,
NULL
,
NULL
,
RPC_C_AUTHN_LEVEL_DEFAULT
,
...
@@ -256,7 +264,7 @@ static int query_prop( const WCHAR *class, const WCHAR *propnames )
...
@@ -256,7 +264,7 @@ static int query_prop( const WCHAR *class, const WCHAR *propnames )
}
}
/* Check that this class supports all requested properties. */
/* Check that this class supports all requested properties. */
hr
=
process_property_list
(
obj
,
propnames
,
&
proplist
);
hr
=
process_property_list
(
obj
,
argc
,
argv
,
&
proplist
);
IWbemClassObject_Release
(
obj
);
IWbemClassObject_Release
(
obj
);
if
(
FAILED
(
hr
))
if
(
FAILED
(
hr
))
{
{
...
@@ -337,7 +345,7 @@ done:
...
@@ -337,7 +345,7 @@ done:
static
int
process_args
(
int
argc
,
WCHAR
*
argv
[]
)
static
int
process_args
(
int
argc
,
WCHAR
*
argv
[]
)
{
{
const
WCHAR
*
class
,
*
value
;
const
WCHAR
*
class
;
int
i
;
int
i
;
for
(
i
=
0
;
i
<
argc
&&
argv
[
i
][
0
]
==
'/'
;
i
++
)
for
(
i
=
0
;
i
<
argc
&&
argv
[
i
][
0
]
==
'/'
;
i
++
)
...
@@ -383,8 +391,7 @@ static int process_args( int argc, WCHAR *argv[] )
...
@@ -383,8 +391,7 @@ static int process_args( int argc, WCHAR *argv[] )
{
{
if
(
++
i
>=
argc
)
if
(
++
i
>=
argc
)
goto
not_supported
;
goto
not_supported
;
value
=
argv
[
i
];
return
query_prop
(
class
,
argc
-
i
,
argv
+
i
);
return
query_prop
(
class
,
value
);
}
}
not_supported:
not_supported:
...
@@ -403,14 +410,14 @@ int __cdecl wmain(int argc, WCHAR *argv[])
...
@@ -403,14 +410,14 @@ int __cdecl wmain(int argc, WCHAR *argv[])
{
{
fputws
(
L"wmic:root
\\
cli>"
,
stdout
);
fputws
(
L"wmic:root
\\
cli>"
,
stdout
);
while
(
fgetws
(
cmd
,
sizeof
(
cmd
),
stdin
)
!=
NULL
)
while
(
fgetws
(
cmd
,
sizeof
(
cmd
),
stdin
)
!=
NULL
)
{
{
const
WCHAR
*
stripped
;
const
WCHAR
*
stripped
;
cmd
[
wcslen
(
cmd
)
-
1
]
=
0
;
/* remove trailing '\n' */
cmd
[
wcslen
(
cmd
)
-
1
]
=
0
;
/* remove trailing '\n' */
stripped
=
strip_spaces
(
cmd
);
stripped
=
strip_spaces
(
cmd
);
WINE_TRACE
(
"command: %s
\n
"
,
debugstr_w
(
stripped
)
);
WINE_TRACE
(
"command: %s
\n
"
,
debugstr_w
(
stripped
)
);
if
(
!
wcsicmp
(
stripped
,
L"exit"
)
||
!
wcsicmp
(
stripped
,
L"quit"
))
if
(
!
wcsicmp
(
stripped
,
L"exit"
)
||
!
wcsicmp
(
stripped
,
L"quit"
))
return
0
;
return
0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment