Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6fea31b

Browse files
committed
Win32 regression test fixes:
For win32 in general, this makes it possible to run the regression testsas an admin user by using the same restricted token method that's usedby pg_ctl and initdb.For vc++, it adds building of pg_regress.exe, adds a resultmap, andfixes how it runs the install.Magnus Hagander
1 parent51be14e commit6fea31b

File tree

5 files changed

+96
-15
lines changed

5 files changed

+96
-15
lines changed

‎src/test/regress/pg_regress.c

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
1212
* Portions Copyright (c) 1994, Regents of the University of California
1313
*
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 $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -67,7 +67,9 @@ static char *bindir = PGBINDIR;
6767
staticchar*libdir=LIBDIR;
6868
staticchar*datadir=PGSHAREDIR;
6969
staticchar*host_platform=HOST_TUPLE;
70+
#ifndefWIN32_ONLY_COMPILER
7071
staticchar*makeprog=MAKEPROG;
72+
#endif
7173

7274
#ifndefWIN32/* not used in WIN32 case */
7375
staticchar*shellprog=SHELLPROG;
@@ -133,6 +135,10 @@ psql_command(const char *database, const char *query,...)
133135
the supplied arguments. */
134136
__attribute__((format(printf,2,3)));
135137

138+
#ifdefWIN32
139+
typedefBOOL(WINAPI*__CreateRestrictedToken) (HANDLE,DWORD,DWORD,PSID_AND_ATTRIBUTES,DWORD,PLUID_AND_ATTRIBUTES,DWORD,PSID_AND_ATTRIBUTES,PHANDLE);
140+
#endif
141+
136142
/*
137143
* allow core files if possible.
138144
*/
@@ -854,16 +860,74 @@ spawn_process(const char *cmdline)
854860
returnpid;
855861
#else
856862
char*cmdline2;
863+
BOOLb;
857864
STARTUPINFOsi;
858865
PROCESS_INFORMATIONpi;
866+
HANDLEorigToken;
867+
HANDLErestrictedToken;
868+
SID_IDENTIFIER_AUTHORITYNtAuthority= {SECURITY_NT_AUTHORITY};
869+
SID_AND_ATTRIBUTESdropSids[2];
870+
__CreateRestrictedToken_CreateRestrictedToken=NULL;
871+
HANDLEAdvapi32Handle;
859872

860873
ZeroMemory(&si,sizeof(si));
861874
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+
}
862926

863927
cmdline2=malloc(strlen(cmdline)+8);
864928
sprintf(cmdline2,"cmd /c %s",cmdline);
865929

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))
867931
{
868932
fprintf(stderr,_("could not start process for \"%s\": %lu\n"),
869933
cmdline2,GetLastError());
@@ -1689,9 +1753,15 @@ main(int argc, char *argv[])
16891753
make_directory(buf);
16901754

16911755
/* "make install" */
1756+
#ifndefWIN32_ONLY_COMPILER
16921757
snprintf(buf,sizeof(buf),
16931758
SYSTEMQUOTE"\"%s\" -C \"%s\" DESTDIR=\"%s/install\" install with_perl=no with_python=no > \"%s/log/install.log\" 2>&1"SYSTEMQUOTE,
16941759
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
16951765
if (system(buf))
16961766
{
16971767
fprintf(stderr,_("\n%s: installation failed\nExamine %s/log/install.log for the reason.\nCommand was: %s\n"),progname,outputdir,buf);

‎src/test/regress/resultmap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
float4/i.86-pc-mingw32=float4-exp-three-digits
2+
float4/i.86-pc-win32vc=float4-exp-three-digits
23
float8/i.86-.*-freebsd=float8-small-is-zero
34
float8/i.86-.*-openbsd=float8-small-is-zero
45
float8/i.86-.*-netbsd=float8-small-is-zero
56
float8/m68k-.*-netbsd=float8-small-is-zero
67
float8/i.86-pc-mingw32=float8-exp-three-digits-win32
8+
float8/i.86-pc-win32vc=float8-exp-three-digits-win32
79
float8/i.86-pc-cygwin=float8-small-is-zero
810
int8/i.86-pc-mingw32=int8-exp-three-digits
11+
int8/i.86-pc-win32vc=int8-exp-three-digits

‎src/tools/msvc/Solution.pm

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ sub GenerateFiles {
8787
print O"#define HAVE_LIBZ 1\n"if ($self->{options}->{zlib});
8888
print O"#define USE_SSL 1\n"if ($self->{options}->{openssl});
8989
print O"#define ENABLE_NLS 1\n"if ($self->{options}->{nls});
90-
print O"#define LOCALEDIR\"/usr/local/pgsql/share/locale\"\n"if ($self->{options}->{nls});
90+
print O"#define LOCALEDIR\"/share/locale\"\n"if ($self->{options}->{nls});
9191
if ($self->{options}->{xml}) {
9292
print O"#define HAVE_LIBXML2\n";
9393
print O"#define USE_LIBXML\n";
@@ -201,17 +201,17 @@ EOF
201201
print"Generating pg_config_paths.h...\n";
202202
open(O,'>','src\port\pg_config_paths.h') || confess"Could not open pg_config_paths.h";
203203
print O<<EOF;
204-
#define PGBINDIR "/usr/local/pgsql/bin"
205-
#define PGSHAREDIR "/usr/local/pgsql/share"
206-
#define SYSCONFDIR "/usr/local/pgsql/etc"
207-
#define INCLUDEDIR "/usr/local/pgsql/include"
208-
#define PKGINCLUDEDIR "/usr/local/pgsql/include"
209-
#define INCLUDEDIRSERVER "/usr/local/pgsql/include/server"
210-
#define LIBDIR "/usr/local/pgsql/lib"
211-
#define PKGLIBDIR "/usr/local/pgsql/lib"
212-
#define LOCALEDIR "/usr/local/pgsql/share/locale"
213-
#define DOCDIR "/usr/local/pgsql/doc"
214-
#define MANDIR "/usr/local/pgsql/man"
204+
#define PGBINDIR "/bin"
205+
#define PGSHAREDIR "/share"
206+
#define SYSCONFDIR "/etc"
207+
#define INCLUDEDIR "/include"
208+
#define PKGINCLUDEDIR "/include"
209+
#define INCLUDEDIRSERVER "/include/server"
210+
#define LIBDIR "/lib"
211+
#define PKGLIBDIR "/lib"
212+
#define LOCALEDIR "/share/locale"
213+
#define DOCDIR "/doc"
214+
#define MANDIR "/man"
215215
EOF
216216
close(O);
217217
}

‎src/tools/msvc/install.pl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ sub CopySetOfFiles {
6969
open($D,"dir /b /s$spec |") || croak"Could not list$spec\n";
7070
while (<$D>) {
7171
chomp;
72+
nextif/regress/;# Skip temporary install in regression subdir
7273
my$tgt =$target . basename($_);
7374
print".";
7475
copy($_,$tgt) || croak"Could not copy$_:$!\n";

‎src/tools/msvc/mkvcbuild.pl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,18 @@
265265
}
266266

267267

268-
# RegressionDLLs
268+
# RegressionDLL and EXE
269269
my$regress =$solution->AddProject('regress','dll','misc');
270270
$regress->AddFile('src\test\regress\regress.c');
271271
$regress->AddReference($postgres);
272272

273+
my$pgregress =$solution->AddProject('pg_regress','exe','misc');
274+
$pgregress->AddFile('src\test\regress\pg_regress.c');
275+
$pgregress->AddIncludeDir('src\port');
276+
$pgregress->AddDefine('HOST_TUPLE="i686-pc-win32vc"');
277+
$pgregress->AddDefine('FRONTEND');
278+
$pgregress->AddReference($libpgport);
279+
273280
$solution->Save();
274281

275282
#####################

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp