Attached is an updated patch for the win32/visualc++ specific parts of
my previous patch, not included in the parts applied by Alvaro.

For win32 in general, this makes it possible to run the regression tests
as an admin user by using the same restricted token method that's used
by pg_ctl and initdb.

For vc++, it adds building of pg_regress.exe, adds a resultmap, and
fixes how it runs the install.

//Magnus

Index: test/regress/pg_regress.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/test/regress/pg_regress.c,v
retrieving revision 1.27
diff -c -r1.27 pg_regress.c
*** test/regress/pg_regress.c   19 Jan 2007 21:21:13 -0000      1.27
--- test/regress/pg_regress.c   23 Jan 2007 13:46:41 -0000
***************
*** 67,73 ****
--- 67,75 ----
  static char *libdir = LIBDIR;
  static char *datadir = PGSHAREDIR;
  static char *host_platform = HOST_TUPLE;
+ #ifndef WIN32_ONLY_COMPILER
  static char *makeprog = MAKEPROG;
+ #endif
  
  #ifndef WIN32                                 /* not used in WIN32 case */
  static char *shellprog = SHELLPROG;
***************
*** 133,138 ****
--- 135,144 ----
     the supplied arguments. */
  __attribute__((format(printf, 2, 3)));
  
+ #ifdef WIN32
+ typedef BOOL(WINAPI * __CreateRestrictedToken) (HANDLE, DWORD, DWORD, 
PSID_AND_ATTRIBUTES, DWORD, PLUID_AND_ATTRIBUTES, DWORD, PSID_AND_ATTRIBUTES, 
PHANDLE);
+ #endif
+ 
  /*
   * allow core files if possible.
   */
***************
*** 855,870 ****
        return pid;
  #else
        char       *cmdline2;
        STARTUPINFO si;
        PROCESS_INFORMATION pi;

        ZeroMemory(&si, sizeof(si));
        si.cb = sizeof(si);
  
        cmdline2 = malloc(strlen(cmdline) + 8);
        sprintf(cmdline2, "cmd /c %s", cmdline);
  
!       if (!CreateProcess(NULL, cmdline2, NULL, NULL, FALSE, 0, NULL, NULL, 
&si, &pi))
        {
                fprintf(stderr, _("could not start process for \"%s\": %lu\n"),
                                cmdline2, GetLastError());
--- 861,934 ----
        return pid;
  #else
        char       *cmdline2;
+       BOOL b;
        STARTUPINFO si;
        PROCESS_INFORMATION pi;
+       HANDLE origToken;
+       HANDLE restrictedToken;
+       SID_IDENTIFIER_AUTHORITY NtAuthority = {SECURITY_NT_AUTHORITY};
+       SID_AND_ATTRIBUTES dropSids[2];
+       __CreateRestrictedToken _CreateRestrictedToken = NULL;
+       HANDLE Advapi32Handle;
  
        ZeroMemory(&si, sizeof(si));
        si.cb = sizeof(si);
+       
+       Advapi32Handle = LoadLibrary("ADVAPI32.DLL");
+       if (Advapi32Handle != NULL)
+       {
+       _CreateRestrictedToken = (__CreateRestrictedToken) 
GetProcAddress(Advapi32Handle, "CreateRestrictedToken");
+    }
+    
+    if (_CreateRestrictedToken == NULL)
+    {
+       if (Advapi32Handle != NULL)
+               FreeLibrary(Advapi32Handle);
+       fprintf(stderr, "ERROR: Unable to create restricted tokens on this 
platform\n");
+       exit_nicely(2);
+    }
+ 
+    /* Open the current token to use as base for the restricted one */
+    if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &origToken))
+    {
+       fprintf(stderr, "Failed to open process token: %lu\n", GetLastError());
+       exit_nicely(2);
+    }
+ 
+       /* Allocate list of SIDs to remove */
+       ZeroMemory(&dropSids, sizeof(dropSids));
+       if (!AllocateAndInitializeSid(&NtAuthority, 2,
+                       SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 
0, 0, 0, 0, 0, 0, &dropSids[0].Sid) ||
+                !AllocateAndInitializeSid(&NtAuthority, 2,
+                  SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_POWER_USERS, 
0, 0, 0, 0, 0, 0, &dropSids[1].Sid))
+    {
+       fprintf(stderr, "Failed to allocate SIDs: %lu\n", GetLastError());
+       exit_nicely(2);
+    }
+       
+       b = _CreateRestrictedToken(origToken,
+           DISABLE_MAX_PRIVILEGE,
+           sizeof(dropSids)/sizeof(dropSids[0]),
+           dropSids,
+           0, NULL,
+           0, NULL,
+           &restrictedToken);
+ 
+    FreeSid(dropSids[1].Sid);
+    FreeSid(dropSids[0].Sid);
+    CloseHandle(origToken);
+    FreeLibrary(Advapi32Handle);
+    
+    if (!b)
+    {
+       fprintf(stderr, "Failed to create restricted token: %lu\n", 
GetLastError());
+       exit_nicely(2);
+    }
  
        cmdline2 = malloc(strlen(cmdline) + 8);
        sprintf(cmdline2, "cmd /c %s", cmdline);
  
!       if (!CreateProcessAsUser(restrictedToken, NULL, cmdline2, NULL, NULL, 
FALSE, 0, NULL, NULL, &si, &pi))
        {
                fprintf(stderr, _("could not start process for \"%s\": %lu\n"),
                                cmdline2, GetLastError());
***************
*** 1690,1698 ****
--- 1754,1768 ----
                        make_directory(buf);
  
                /* "make install" */
+ #ifndef WIN32_ONLY_COMPILER
                snprintf(buf, sizeof(buf),
                                 SYSTEMQUOTE "\"%s\" -C \"%s\" 
DESTDIR=\"%s/install\" install with_perl=no with_python=no > 
\"%s/log/install.log\" 2>&1" SYSTEMQUOTE,
                                 makeprog, top_builddir, temp_install, 
outputdir);
+ #else
+          snprintf(buf, sizeof(buf),
+                 SYSTEMQUOTE "perl \"%s/src/tools/msvc/install.pl\" 
\"%s/install\" >\"%s/log/install.log\" 2>&1" SYSTEMQUOTE,
+              top_builddir, temp_install, outputdir);
+ #endif
                if (system(buf))
                {
                        fprintf(stderr, _("\n%s: installation failed\nExamine 
%s/log/install.log for the reason.\nCommand was: %s\n"), progname, outputdir, 
buf);
Index: test/regress/resultmap
===================================================================
RCS file: /projects/cvsroot/pgsql/src/test/regress/resultmap,v
retrieving revision 1.83
diff -c -r1.83 resultmap
*** test/regress/resultmap      3 Aug 2006 17:04:00 -0000       1.83
--- test/regress/resultmap      23 Jan 2007 13:52:11 -0000
***************
*** 1,8 ****
--- 1,11 ----
  float4/i.86-pc-mingw32=float4-exp-three-digits
+ float4/i.86-pc-win32vc=float4-exp-three-digits
  float8/i.86-.*-freebsd=float8-small-is-zero
  float8/i.86-.*-openbsd=float8-small-is-zero
  float8/i.86-.*-netbsd=float8-small-is-zero
  float8/m68k-.*-netbsd=float8-small-is-zero
  float8/i.86-pc-mingw32=float8-exp-three-digits-win32
+ float8/i.86-pc-win32vc=float8-exp-three-digits-win32
  float8/i.86-pc-cygwin=float8-small-is-zero
  int8/i.86-pc-mingw32=int8-exp-three-digits
+ int8/i.86-pc-win32vc=int8-exp-three-digits
\ No newline at end of file
Index: tools/msvc/Solution.pm
===================================================================
RCS file: /projects/cvsroot/pgsql/src/tools/msvc/Solution.pm,v
retrieving revision 1.6
diff -c -r1.6 Solution.pm
*** tools/msvc/Solution.pm      16 Jan 2007 21:43:19 -0000      1.6
--- tools/msvc/Solution.pm      23 Jan 2007 13:32:19 -0000
***************
*** 88,94 ****
                print O "#define HAVE_LIBZ 1\n" if ($self->{options}->{zlib});
                print O "#define USE_SSL 1\n" if ($self->{options}->{openssl});
                print O "#define ENABLE_NLS 1\n" if ($self->{options}->{nls});
!               print O "#define LOCALEDIR \"/usr/local/pgsql/share/locale\"\n" 
if ($self->{options}->{nls});
                if ($self->{options}->{xml}) {
           print O "#define HAVE_LIBXML2\n";
           print O "#define USE_LIBXML\n";
--- 88,94 ----
                print O "#define HAVE_LIBZ 1\n" if ($self->{options}->{zlib});
                print O "#define USE_SSL 1\n" if ($self->{options}->{openssl});
                print O "#define ENABLE_NLS 1\n" if ($self->{options}->{nls});
!               print O "#define LOCALEDIR \"/share/locale\"\n" if 
($self->{options}->{nls});
                if ($self->{options}->{xml}) {
           print O "#define HAVE_LIBXML2\n";
           print O "#define USE_LIBXML\n";
***************
*** 202,218 ****
                print "Generating pg_config_paths.h...\n";
                open(O,'>', 'src\port\pg_config_paths.h') || confess "Could not 
open pg_config_paths.h";
                print O  <<EOF;
! #define PGBINDIR "/usr/local/pgsql/bin"
! #define PGSHAREDIR "/usr/local/pgsql/share"
! #define SYSCONFDIR "/usr/local/pgsql/etc"
! #define INCLUDEDIR "/usr/local/pgsql/include"
! #define PKGINCLUDEDIR "/usr/local/pgsql/include"
! #define INCLUDEDIRSERVER "/usr/local/pgsql/include/server"
! #define LIBDIR "/usr/local/pgsql/lib"
! #define PKGLIBDIR "/usr/local/pgsql/lib"
! #define LOCALEDIR "/usr/local/pgsql/share/locale"
! #define DOCDIR "/usr/local/pgsql/doc"
! #define MANDIR "/usr/local/pgsql/man"
  EOF
                close(O);
        }
--- 202,218 ----
                print "Generating pg_config_paths.h...\n";
                open(O,'>', 'src\port\pg_config_paths.h') || confess "Could not 
open pg_config_paths.h";
                print O  <<EOF;
! #define PGBINDIR "/bin"
! #define PGSHAREDIR "/share"
! #define SYSCONFDIR "/etc"
! #define INCLUDEDIR "/include"
! #define PKGINCLUDEDIR "/include"
! #define INCLUDEDIRSERVER "/include/server"
! #define LIBDIR "/lib"
! #define PKGLIBDIR "/lib"
! #define LOCALEDIR "/share/locale"
! #define DOCDIR "/doc"
! #define MANDIR "/man"
  EOF
                close(O);
        }
Index: tools/msvc/install.pl
===================================================================
RCS file: /projects/cvsroot/pgsql/src/tools/msvc/install.pl,v
retrieving revision 1.1
diff -c -r1.1 install.pl
*** tools/msvc/install.pl       29 Nov 2006 19:49:31 -0000      1.1
--- tools/msvc/install.pl       23 Jan 2007 13:33:01 -0000
***************
*** 70,78 ****
        open($D, "dir /b /s $spec |") || croak "Could not list $spec\n";
        while (<$D>) {
                chomp;
                my $tgt = $target . basename($_);
                print ".";
!               copy($_, $tgt) || croak "Could not copy $_\n";
        }
        close($D);
        print "\n";
--- 70,79 ----
        open($D, "dir /b /s $spec |") || croak "Could not list $spec\n";
        while (<$D>) {
                chomp;
+               next if /regress/; # Skip temporary install in regression subdir
                my $tgt = $target . basename($_);
                print ".";
!               copy($_, $tgt) || croak "Could not copy $_: $!\n";
        }
        close($D);
        print "\n";
Index: tools/msvc/mkvcbuild.pl
===================================================================
RCS file: /projects/cvsroot/pgsql/src/tools/msvc/mkvcbuild.pl,v
retrieving revision 1.10
diff -c -r1.10 mkvcbuild.pl
*** tools/msvc/mkvcbuild.pl     16 Jan 2007 21:43:19 -0000      1.10
--- tools/msvc/mkvcbuild.pl     23 Jan 2007 13:34:13 -0000
***************
*** 259,269 ****
  }


! # Regression DLLs
  my $regress = $solution->AddProject('regress','dll','misc');
  $regress->AddFile('src\test\regress\regress.c');
  $regress->AddReference($postgres);

  $solution->Save();

  #####################
--- 259,276 ----
  }


! # Regression DLL and EXE
  my $regress = $solution->AddProject('regress','dll','misc');
  $regress->AddFile('src\test\regress\regress.c');
  $regress->AddReference($postgres);

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

  #####################
---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Reply via email to