This adds pledge to par2 and its utilities.

The 'create' command needs cpath and wpath to create and write the pars.

The 'repair' command needs cpath to rename damaged files and delete
partial files, and wpath to write the recovered files (at least to
begin with).

The 'verify' command may need cpath to delete files if -p was passed.

'repair' opens all the files it is going to write before it begins
performing the recovery so we can drop wpath at that point. It needs to
hold on to cpath as it deletes any partially reconstructed files if it
encounters an error.

The 'verify' command calls the same function as 'repair' but won't hit
the codepath with the late pledge call.

All the tests pass, but that doesn't mean much...


This patch does the pledge needed by create/repair up front and then
pledges again if running verify, this way we can pledge before the
command line parsing. And does a different pledge for verify depending
on whether -p is set.


--
Carlin



Index: archivers/par2cmdline/Makefile
===================================================================
RCS file: /cvs/ports/archivers/par2cmdline/Makefile,v
retrieving revision 1.11
diff -u -p -u -r1.11 Makefile
--- archivers/par2cmdline/Makefile      5 Oct 2015 16:50:14 -0000       1.11
+++ archivers/par2cmdline/Makefile      8 Jun 2016 11:56:55 -0000
@@ -5,6 +5,7 @@ COMMENT =       command line implementation of
 V =            0.6.14
 DISTNAME =     par2cmdline-$V
 DISTFILES =    ${DISTNAME}{v$V}.tar.gz
+REVISION =     0
 
 CATEGORIES =   archivers
 
@@ -13,6 +14,7 @@ HOMEPAGE =    https://github.com/BlackIkeEa
 # GPLv2+
 PERMIT_PACKAGE_CDROM = Yes
 
+# uses pledge()
 WANTLIB =      c m stdc++
 
 MAINTAINER =   Mikolaj Kucharski <[email protected]>
Index: archivers/par2cmdline/patches/patch-configure_ac
===================================================================
RCS file: archivers/par2cmdline/patches/patch-configure_ac
diff -N archivers/par2cmdline/patches/patch-configure_ac
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ archivers/par2cmdline/patches/patch-configure_ac    8 Jun 2016 11:56:55 
-0000
@@ -0,0 +1,11 @@
+$OpenBSD$
+--- configure.ac.orig  Wed Jun  8 23:30:46 2016
++++ configure.ac       Wed Jun  8 23:31:20 2016
+@@ -56,6 +56,7 @@ dnl Checks for library functions.
+ AC_FUNC_MEMCMP
+ AC_CHECK_FUNCS([stricmp] [strcasecmp])
+ AC_CHECK_FUNCS([strchr] [memcpy])
++AC_CHECK_FUNCS([pledge])
+ 
+ AC_CHECK_FUNCS([getopt] [getopt_long])
+ 
Index: archivers/par2cmdline/patches/patch-par1repairer_cpp
===================================================================
RCS file: archivers/par2cmdline/patches/patch-par1repairer_cpp
diff -N archivers/par2cmdline/patches/patch-par1repairer_cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ archivers/par2cmdline/patches/patch-par1repairer_cpp        8 Jun 2016 
11:56:55 -0000
@@ -0,0 +1,18 @@
+$OpenBSD$
+--- par1repairer.cpp.orig      Wed Jun  8 23:41:11 2016
++++ par1repairer.cpp   Wed Jun  8 23:42:01 2016
+@@ -157,6 +157,14 @@ Result Par1Repairer::Process(const CommandLine &comman
+         if (!CreateTargetFiles())
+           return eFileIOError;
+ 
++#ifdef HAVE_PLEDGE
++        if (pledge("stdio rpath cpath", NULL) == -1)
++        {
++          cerr << "pledge failed" << endl;
++          return eLogicError;
++        }
++#endif
++
+         // Work out which data blocks are available, which need to be 
recreated, 
+         // and compute the appropriate Reed Solomon matrix.
+         if (!ComputeRSmatrix())
Index: archivers/par2cmdline/patches/patch-par2cmdline_cpp
===================================================================
RCS file: archivers/par2cmdline/patches/patch-par2cmdline_cpp
diff -N archivers/par2cmdline/patches/patch-par2cmdline_cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ archivers/par2cmdline/patches/patch-par2cmdline_cpp 8 Jun 2016 11:56:55 
-0000
@@ -0,0 +1,45 @@
+$OpenBSD$
+--- par2cmdline.cpp.orig       Wed Jun  8 23:31:42 2016
++++ par2cmdline.cpp    Wed Jun  8 23:38:36 2016
+@@ -34,6 +34,14 @@ int main(int argc, char *argv[])
+   _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_ALLOC_MEM_DF | 
/*_CRTDBG_CHECK_CRT_DF | */_CRTDBG_DELAY_FREE_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
+ #endif
+ 
++#ifdef HAVE_PLEDGE
++  if (pledge("stdio rpath wpath cpath", NULL) == -1)
++  {
++    cerr << "pledge failed" << endl;
++    return eLogicError;
++  }
++#endif
++
+   // Parse the command line
+   CommandLine *commandline = new CommandLine;
+ 
+@@ -55,6 +63,26 @@ int main(int argc, char *argv[])
+         break;
+       case CommandLine::opVerify:
+         {
++#ifdef HAVE_PLEDGE
++          if (!commandline->GetPurgeFiles())
++          {
++            if (pledge("stdio rpath", NULL) == -1)
++            {
++              cerr << "pledge failed" << endl;
++              result = eLogicError;
++              break;
++            }
++          }
++          else
++          {
++            if (pledge("stdio rpath cpath", NULL) == -1)
++            {
++              cerr << "pledge failed" << endl;
++              result = eLogicError;
++              break;
++            }
++          }
++#endif
+           // Verify damaged files
+           switch (commandline->GetVersion())
+           {
Index: archivers/par2cmdline/patches/patch-par2repairer_cpp
===================================================================
RCS file: archivers/par2cmdline/patches/patch-par2repairer_cpp
diff -N archivers/par2cmdline/patches/patch-par2repairer_cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ archivers/par2cmdline/patches/patch-par2repairer_cpp        8 Jun 2016 
11:56:55 -0000
@@ -0,0 +1,18 @@
+$OpenBSD$
+--- par2repairer.cpp.orig      Wed Jun  8 23:38:53 2016
++++ par2repairer.cpp   Wed Jun  8 23:41:00 2016
+@@ -193,6 +193,14 @@ Result Par2Repairer::Process(const CommandLine &comman
+         if (!CreateTargetFiles())
+           return eFileIOError;
+ 
++#ifdef HAVE_PLEDGE
++        if (pledge("stdio rpath cpath", NULL) == -1)
++        {
++          cerr << "pledge failed" << endl;
++          return eLogicError;
++        }
++#endif
++
+         // Work out which data blocks are available, which need to be copied
+         // directly to the output, and which need to be recreated, and compute
+         // the appropriate Reed Solomon matrix.

Reply via email to