|
11 | 11 | * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group |
12 | 12 | * Portions Copyright (c) 1994, Regents of the University of California |
13 | 13 | * |
14 | | - * $PostgreSQL: pgsql/src/test/regress/pg_regress.c,v 1.29 2007/02/07 00:52:35 petere Exp $ |
| 14 | + * $PostgreSQL: pgsql/src/test/regress/pg_regress.c,v 1.30 2007/02/08 15:28:58 momjian Exp $ |
15 | 15 | * |
16 | 16 | *------------------------------------------------------------------------- |
17 | 17 | */ |
@@ -67,7 +67,9 @@ static char *bindir = PGBINDIR; |
67 | 67 | static char *libdir = LIBDIR; |
68 | 68 | static char *datadir = PGSHAREDIR; |
69 | 69 | static char *host_platform = HOST_TUPLE; |
| 70 | +#ifndef WIN32_ONLY_COMPILER |
70 | 71 | static char *makeprog = MAKEPROG; |
| 72 | +#endif |
71 | 73 |
|
72 | 74 | #ifndef WIN32 /* not used in WIN32 case */ |
73 | 75 | static char *shellprog = SHELLPROG; |
@@ -133,6 +135,10 @@ psql_command(const char *database, const char *query,...) |
133 | 135 | the supplied arguments. */ |
134 | 136 | __attribute__((format(printf, 2, 3))); |
135 | 137 |
|
| 138 | +#ifdef WIN32 |
| 139 | +typedef BOOL(WINAPI * __CreateRestrictedToken) (HANDLE, DWORD, DWORD, PSID_AND_ATTRIBUTES, DWORD, PLUID_AND_ATTRIBUTES, DWORD, PSID_AND_ATTRIBUTES, PHANDLE); |
| 140 | +#endif |
| 141 | + |
136 | 142 | /* |
137 | 143 | * allow core files if possible. |
138 | 144 | */ |
@@ -854,16 +860,74 @@ spawn_process(const char *cmdline) |
854 | 860 | return pid; |
855 | 861 | #else |
856 | 862 | char *cmdline2; |
| 863 | + BOOL b; |
857 | 864 | STARTUPINFO si; |
858 | 865 | PROCESS_INFORMATION pi; |
| 866 | + HANDLE origToken; |
| 867 | + HANDLE restrictedToken; |
| 868 | + SID_IDENTIFIER_AUTHORITY NtAuthority = {SECURITY_NT_AUTHORITY}; |
| 869 | + SID_AND_ATTRIBUTES dropSids[2]; |
| 870 | + __CreateRestrictedToken _CreateRestrictedToken = NULL; |
| 871 | + HANDLE Advapi32Handle; |
859 | 872 |
|
860 | 873 | ZeroMemory(&si, sizeof(si)); |
861 | 874 | si.cb = sizeof(si); |
| 875 | + |
| 876 | + Advapi32Handle = LoadLibrary("ADVAPI32.DLL"); |
| 877 | + if (Advapi32Handle != NULL) |
| 878 | + { |
| 879 | + _CreateRestrictedToken = (__CreateRestrictedToken) GetProcAddress(Advapi32Handle, "CreateRestrictedToken"); |
| 880 | + } |
| 881 | + |
| 882 | + if (_CreateRestrictedToken == NULL) |
| 883 | + { |
| 884 | + if (Advapi32Handle != NULL) |
| 885 | + FreeLibrary(Advapi32Handle); |
| 886 | + fprintf(stderr, "ERROR: Unable to create restricted tokens on this platform\n"); |
| 887 | + exit_nicely(2); |
| 888 | + } |
| 889 | + |
| 890 | + /* Open the current token to use as base for the restricted one */ |
| 891 | + if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &origToken)) |
| 892 | + { |
| 893 | + fprintf(stderr, "Failed to open process token: %lu\n", GetLastError()); |
| 894 | + exit_nicely(2); |
| 895 | + } |
| 896 | + |
| 897 | + /* Allocate list of SIDs to remove */ |
| 898 | + ZeroMemory(&dropSids, sizeof(dropSids)); |
| 899 | + if (!AllocateAndInitializeSid(&NtAuthority, 2, |
| 900 | + SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &dropSids[0].Sid) || |
| 901 | + !AllocateAndInitializeSid(&NtAuthority, 2, |
| 902 | + SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_POWER_USERS, 0, 0, 0, 0, 0, 0, &dropSids[1].Sid)) |
| 903 | + { |
| 904 | + fprintf(stderr, "Failed to allocate SIDs: %lu\n", GetLastError()); |
| 905 | + exit_nicely(2); |
| 906 | + } |
| 907 | + |
| 908 | + b = _CreateRestrictedToken(origToken, |
| 909 | + DISABLE_MAX_PRIVILEGE, |
| 910 | + sizeof(dropSids)/sizeof(dropSids[0]), |
| 911 | + dropSids, |
| 912 | + 0, NULL, |
| 913 | + 0, NULL, |
| 914 | + &restrictedToken); |
| 915 | + |
| 916 | + FreeSid(dropSids[1].Sid); |
| 917 | + FreeSid(dropSids[0].Sid); |
| 918 | + CloseHandle(origToken); |
| 919 | + FreeLibrary(Advapi32Handle); |
| 920 | + |
| 921 | + if (!b) |
| 922 | + { |
| 923 | + fprintf(stderr, "Failed to create restricted token: %lu\n", GetLastError()); |
| 924 | + exit_nicely(2); |
| 925 | + } |
862 | 926 |
|
863 | 927 | cmdline2 = malloc(strlen(cmdline) + 8); |
864 | 928 | sprintf(cmdline2, "cmd /c %s", cmdline); |
865 | 929 |
|
866 | | - if (!CreateProcess(NULL, cmdline2, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) |
| 930 | + if (!CreateProcessAsUser(restrictedToken, NULL, cmdline2, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) |
867 | 931 | { |
868 | 932 | fprintf(stderr, _("could not start process for \"%s\": %lu\n"), |
869 | 933 | cmdline2, GetLastError()); |
@@ -1689,9 +1753,15 @@ main(int argc, char *argv[]) |
1689 | 1753 | make_directory(buf); |
1690 | 1754 |
|
1691 | 1755 | /* "make install" */ |
| 1756 | +#ifndef WIN32_ONLY_COMPILER |
1692 | 1757 | snprintf(buf, sizeof(buf), |
1693 | 1758 | SYSTEMQUOTE "\"%s\" -C \"%s\" DESTDIR=\"%s/install\" install with_perl=no with_python=no > \"%s/log/install.log\" 2>&1" SYSTEMQUOTE, |
1694 | 1759 | makeprog, top_builddir, temp_install, outputdir); |
| 1760 | +#else |
| 1761 | + snprintf(buf, sizeof(buf), |
| 1762 | + SYSTEMQUOTE "perl \"%s/src/tools/msvc/install.pl\" \"%s/install\" >\"%s/log/install.log\" 2>&1" SYSTEMQUOTE, |
| 1763 | + top_builddir, temp_install, outputdir); |
| 1764 | +#endif |
1695 | 1765 | if (system(buf)) |
1696 | 1766 | { |
1697 | 1767 | fprintf(stderr, _("\n%s: installation failed\nExamine %s/log/install.log for the reason.\nCommand was: %s\n"), progname, outputdir, buf); |
|
0 commit comments