summaryrefslogtreecommitdiff
path: root/libusb/os
diff options
context:
space:
mode:
authorPete Batard <pbatard@gmail.com>2010-03-11 02:32:26 +0000
committerPete Batard <pbatard@gmail.com>2010-03-11 02:32:26 +0000
commit53110b64d149ffd63320dcef3a706d94ebd40d10 (patch)
tree6012ac5c4b333ff99b44b77dfa5904bdc2f81f79 /libusb/os
parent9d1d3d72eeff7bbdd08caca54ac77152a7d9a69b (diff)
downloadlibusb-53110b64d149ffd63320dcef3a706d94ebd40d10.tar.gz
added Vista/7 privilege escalation (WIP)a165
Diffstat (limited to 'libusb/os')
-rw-r--r--libusb/os/driver_install.c69
-rw-r--r--libusb/os/driver_installer.c75
2 files changed, 95 insertions, 49 deletions
diff --git a/libusb/os/driver_install.c b/libusb/os/driver_install.c
index e4338ff..3c2cc36 100644
--- a/libusb/os/driver_install.c
+++ b/libusb/os/driver_install.c
@@ -6,11 +6,13 @@
#include <inttypes.h>
#include <objbase.h> // for GUID ops. requires libole32.a
#include <api/difxapi.h>
+#include <api/shellapi.h>
#include "libusbi.h"
#include "windows_usb.h"
#include "driver_install.h"
+
const char inf[] = "Date = \"03/08/2010\"\n\n" \
"ProviderName = \"libusb 1.0\"\n" \
"WinUSB_SvcDesc = \"WinUSB Driver Service\"\n" \
@@ -352,60 +354,29 @@ int create_inf(struct driver_info* drv_info, char* path)
fprintf(fd, "DeviceGUID = \"%s\"\n", guid_to_string(guid));
fwrite(inf, sizeof(inf)-1, 1, fd);
return 0;
-
- // TODO: extract coinstaller files from resource
- // TODO: create cat file for XP?
}
+// TODO: extract driver-installer.exe into the dest dir
int install_device(char* path)
{
- DWORD r;
- BOOL reboot_needed;
-// INSTALLERINFO installer_info;
-
- r = DriverPackagePreinstall(path, DRIVER_PACKAGE_LEGACY_MODE|DRIVER_PACKAGE_REPAIR);
- // Will fail if inf not signed, unless DRIVER_PACKAGE_LEGACY_MODE is specified.
- // r = 87 ERROR_INVALID_PARAMETER on path == NULL
- // r = 2 ERROR_FILE_NOT_FOUND if no inf in path
- // r = 5 ERROR_ACCESS_DENIED if needs admin elevation
- // r = 0xE0000003 ERROR_GENERAL_SYNTAX the syntax of the inf is invalid
- // r = 0xE0000304 ERROR_INVALID_CATALOG_DATA => no cat
- // r = 0xE0000247 if user decided not to install on warnings
- // r = 0x800B0100 ERROR_WRONG_INF_STYLE => missing cat entry in inf
- // r = 0xB7 => missing DRIVER_PACKAGE_REPAIR flag
- switch(r) {
- case ERROR_INVALID_PARAMETER:
- usbi_err(NULL, "invalid path");
- return -1;
- case ERROR_FILE_NOT_FOUND:
- usbi_err(NULL, "unable to find inf file on %s", path);
- return -1;
- case ERROR_ACCESS_DENIED:
- usbi_err(NULL, "this process needs to be run with administrative privileges");
- return -1;
- case ERROR_WRONG_INF_STYLE:
- case ERROR_GENERAL_SYNTAX:
- usbi_err(NULL, "the syntax of the inf is invalid");
- return -1;
- case ERROR_INVALID_CATALOG_DATA:
- usbi_err(NULL, "unable to locate cat file");
- return -1;
- case ERROR_DRIVER_STORE_ADD_FAILED:
- usbi_err(NULL, "cancelled by user");
- return -1;
- // TODO: make DRIVER_PACKAGE_REPAIR optional
- case ERROR_ALREADY_EXISTS:
- usbi_err(NULL, "driver already exists");
- return -1;
- default:
- usbi_err(NULL, "unhandled error %X", r);
- return -1;
- }
+ SHELLEXECUTEINFO shExecInfo;
+ char exename[MAX_PATH_LENGTH];
+ safe_strcpy(exename, MAX_PATH_LENGTH, path);
+ safe_strcat(exename, MAX_PATH_LENGTH, "\\driver-installer.exe");
+
+ shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
+
+ shExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
+ shExecInfo.hwnd = NULL;
+ shExecInfo.lpVerb = "runas";
+ shExecInfo.lpFile = exename;
+ shExecInfo.lpParameters = NULL;
+ shExecInfo.lpDirectory = path;
+ shExecInfo.nShow = SW_MAXIMIZE;
+ shExecInfo.hInstApp = NULL;
- // TODO: use
- r = DriverPackageInstall(path, DRIVER_PACKAGE_LEGACY_MODE|DRIVER_PACKAGE_REPAIR,
- NULL, &reboot_needed);
- usbi_dbg("ret = %X", r);
+ ShellExecuteEx(&shExecInfo);
+ usbi_dbg("hProcess = %p", shExecInfo.hProcess);
return 0;
} \ No newline at end of file
diff --git a/libusb/os/driver_installer.c b/libusb/os/driver_installer.c
new file mode 100644
index 0000000..7f58d92
--- /dev/null
+++ b/libusb/os/driver_installer.c
@@ -0,0 +1,75 @@
+// This standalone installer is a separate exe, as it needs to be run
+// through ShellExecuteEx() for UAC elevation
+
+#include <config.h>
+#include <windows.h>
+#include <setupapi.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <direct.h>
+#include <api/difxapi.h>
+
+
+#define MAX_PATH_LENGTH 128
+#define safe_strncat(dst, dst_max, src, count) strncat(dst, src, min(count, dst_max - strlen(dst) - 1))
+#define safe_strcat(dst, dst_max, src) safe_strncat(dst, dst_max, src, strlen(src)+1)
+
+
+int main(int argc, char** argv)
+{
+ DWORD r;
+ BOOL reboot_needed;
+ char path[MAX_PATH_LENGTH];
+// INSTALLERINFO installer_info;
+
+ _getcwd(path, MAX_PATH_LENGTH);
+ safe_strcat(path, MAX_PATH_LENGTH, "\\libusb_device.inf");
+
+
+ r = DriverPackagePreinstall(path, DRIVER_PACKAGE_LEGACY_MODE|DRIVER_PACKAGE_REPAIR);
+ // Will fail if inf not signed, unless DRIVER_PACKAGE_LEGACY_MODE is specified.
+ // r = 87 ERROR_INVALID_PARAMETER on path == NULL
+ // r = 2 ERROR_FILE_NOT_FOUND if no inf in path
+ // r = 5 ERROR_ACCESS_DENIED if needs admin elevation
+ // r = 0xE0000003 ERROR_GENERAL_SYNTAX the syntax of the inf is invalid
+ // r = 0xE0000304 ERROR_INVALID_CATALOG_DATA => no cat
+ // r = 0xE0000247 if user decided not to install on warnings
+ // r = 0x800B0100 ERROR_WRONG_INF_STYLE => missing cat entry in inf
+ // r = 0xB7 => missing DRIVER_PACKAGE_REPAIR flag
+ switch(r) {
+ case ERROR_INVALID_PARAMETER:
+ printf("invalid path\n");
+ return -1;
+ case ERROR_FILE_NOT_FOUND:
+ printf("unable to find inf file on %s\n", path);
+ return -1;
+ case ERROR_ACCESS_DENIED:
+ printf("this process needs to be run with administrative privileges\n");
+ return -1;
+ case ERROR_WRONG_INF_STYLE:
+ case ERROR_GENERAL_SYNTAX:
+ printf("the syntax of the inf is invalid\n");
+ return -1;
+ case ERROR_INVALID_CATALOG_DATA:
+ printf("unable to locate cat file\n");
+ return -1;
+ case ERROR_DRIVER_STORE_ADD_FAILED:
+ printf("cancelled by user\n");
+ return -1;
+ // TODO: make DRIVER_PACKAGE_REPAIR optional
+ case ERROR_ALREADY_EXISTS:
+ printf("driver already exists\n");
+ return -1;
+ default:
+ printf("unhandled error %X\n", r);
+ return -1;
+ }
+
+ // TODO: use
+ r = DriverPackageInstall(path, DRIVER_PACKAGE_LEGACY_MODE|DRIVER_PACKAGE_REPAIR,
+ NULL, &reboot_needed);
+ printf("ret = %X\n", r);
+
+ return 0;
+} \ No newline at end of file