Commit fe11f13d63f9545c47b4f59efa4335f2c3ecf4d9

Authored by Jay Berkenbilt
1 parent acfc9db0

Add stub for --remove-restrictions

include/qpdf/QPDFJob.hh
@@ -604,6 +604,7 @@ class QPDFJob @@ -604,6 +604,7 @@ class QPDFJob
604 std::shared_ptr<char> password; 604 std::shared_ptr<char> password;
605 bool linearize{false}; 605 bool linearize{false};
606 bool decrypt{false}; 606 bool decrypt{false};
  607 + bool remove_restrictions{false};
607 int split_pages{0}; 608 int split_pages{0};
608 bool progress{false}; 609 bool progress{false};
609 std::function<void(int)> progress_handler{nullptr}; 610 std::function<void(int)> progress_handler{nullptr};
include/qpdf/auto_job_c_main.hh
@@ -35,6 +35,7 @@ QPDF_DLL Config* recompressFlate(); @@ -35,6 +35,7 @@ QPDF_DLL Config* recompressFlate();
35 QPDF_DLL Config* removePageLabels(); 35 QPDF_DLL Config* removePageLabels();
36 QPDF_DLL Config* reportMemoryUsage(); 36 QPDF_DLL Config* reportMemoryUsage();
37 QPDF_DLL Config* requiresPassword(); 37 QPDF_DLL Config* requiresPassword();
  38 +QPDF_DLL Config* removeRestrictions();
38 QPDF_DLL Config* showEncryption(); 39 QPDF_DLL Config* showEncryption();
39 QPDF_DLL Config* showEncryptionKey(); 40 QPDF_DLL Config* showEncryptionKey();
40 QPDF_DLL Config* showLinearization(); 41 QPDF_DLL Config* showLinearization();
job.sums
@@ -3,15 +3,15 @@ generate_auto_job 9abe2ec994fb98526f5e3c0c199ce2e61a868463cb522a5bc6e9730b655341 @@ -3,15 +3,15 @@ generate_auto_job 9abe2ec994fb98526f5e3c0c199ce2e61a868463cb522a5bc6e9730b655341
3 include/qpdf/auto_job_c_att.hh 4c2b171ea00531db54720bf49a43f8b34481586ae7fb6cbf225099ee42bc5bb4 3 include/qpdf/auto_job_c_att.hh 4c2b171ea00531db54720bf49a43f8b34481586ae7fb6cbf225099ee42bc5bb4
4 include/qpdf/auto_job_c_copy_att.hh 50609012bff14fd82f0649185940d617d05d530cdc522185c7f3920a561ccb42 4 include/qpdf/auto_job_c_copy_att.hh 50609012bff14fd82f0649185940d617d05d530cdc522185c7f3920a561ccb42
5 include/qpdf/auto_job_c_enc.hh 28446f3c32153a52afa239ea40503e6cc8ac2c026813526a349e0cd4ae17ddd5 5 include/qpdf/auto_job_c_enc.hh 28446f3c32153a52afa239ea40503e6cc8ac2c026813526a349e0cd4ae17ddd5
6 -include/qpdf/auto_job_c_main.hh a591693e831d08155da78cbbb13bac46cc3f5dd04de1d10b5810cbd3491bf8a0 6 +include/qpdf/auto_job_c_main.hh dbfc221d1533120d1aa9c361d8d2483dea5fcb1c0fd95144d98d305e64ed32a6
7 include/qpdf/auto_job_c_pages.hh b3cc0f21029f6d89efa043dcdbfa183cb59325b6506001c18911614fe8e568ec 7 include/qpdf/auto_job_c_pages.hh b3cc0f21029f6d89efa043dcdbfa183cb59325b6506001c18911614fe8e568ec
8 include/qpdf/auto_job_c_uo.hh ae21b69a1efa9333050f4833d465f6daff87e5b38e5106e49bbef5d4132e4ed1 8 include/qpdf/auto_job_c_uo.hh ae21b69a1efa9333050f4833d465f6daff87e5b38e5106e49bbef5d4132e4ed1
9 -job.yml 70a670b843284707c54108382cc17ab5c633aacc9a264bc0886a5410bea040e3 9 +job.yml 1f5db325600a763692034835117ac6b1a4b6aba8e73faa13a004ddc086834545
10 libqpdf/qpdf/auto_job_decl.hh 7844eba58edffb9494b19e8eca6fd59a24d6e152ca606c3b07da569f753df2da 10 libqpdf/qpdf/auto_job_decl.hh 7844eba58edffb9494b19e8eca6fd59a24d6e152ca606c3b07da569f753df2da
11 -libqpdf/qpdf/auto_job_help.hh 68bcc56ae2b1a63d47af60f817c39f097756b6d36c733c8efdfbb808bce750c9  
12 -libqpdf/qpdf/auto_job_init.hh da9b10925f3527acdc7cd0217abd2684a721a562f16f2fc0da62339aef3c3629 11 +libqpdf/qpdf/auto_job_help.hh d4650c0d8ea4310ef2ee890a9cd1543ce55c9b6b1c6462e0398955fe68d0d407
  12 +libqpdf/qpdf/auto_job_init.hh e6c09e94c92bd17e9c728b11437e3c98266c93c42c3efbce050c8d288e6b3473
13 libqpdf/qpdf/auto_job_json_decl.hh 06caa46eaf71db8a50c046f91866baa8087745a9474319fb7c86d92634cc8297 13 libqpdf/qpdf/auto_job_json_decl.hh 06caa46eaf71db8a50c046f91866baa8087745a9474319fb7c86d92634cc8297
14 -libqpdf/qpdf/auto_job_json_init.hh 8eec1d4acdf3e40cea46155cbf23a60d226ae6e9493ab18265b95dca790ed66d  
15 -libqpdf/qpdf/auto_job_schema.hh a960022725ac4a59db531a3e2bc3964e40113b47348864e9229eb0f3fecfbdc0 14 +libqpdf/qpdf/auto_job_json_init.hh 85ac7e5c66f14c767419823eac84bdea4bd72d690bfe12b533321e5708e644b7
  15 +libqpdf/qpdf/auto_job_schema.hh 5e0f5cb7d462716fe52548b2ae1a8eb6f3c900016e915140eea37f78cee45b2b
16 manual/_ext/qpdf.py 6add6321666031d55ed4aedf7c00e5662bba856dfcd66ccb526563bffefbb580 16 manual/_ext/qpdf.py 6add6321666031d55ed4aedf7c00e5662bba856dfcd66ccb526563bffefbb580
17 -manual/cli.rst 84a7290811712d00b243cbcd603bed31e253731eb1b6d6d5c2fafea79bfe299c 17 +manual/cli.rst 255db0c62765b39de9a71d3d755479235f5bbce32f2902ec5e0e201f265e322d
@@ -129,6 +129,7 @@ options: @@ -129,6 +129,7 @@ options:
129 - replace-input 129 - replace-input
130 - report-memory-usage 130 - report-memory-usage
131 - requires-password 131 - requires-password
  132 + - remove-restrictions
132 - show-encryption 133 - show-encryption
133 - show-encryption-key 134 - show-encryption-key
134 - show-linearization 135 - show-linearization
@@ -313,6 +314,7 @@ json: @@ -313,6 +314,7 @@ json:
313 progress: 314 progress:
314 split-pages: 315 split-pages:
315 json-output: 316 json-output:
  317 + remove-restrictions:
316 encrypt: 318 encrypt:
317 _user-password: "user password" 319 _user-password: "user password"
318 _owner-password: "owner password" 320 _owner-password: "owner password"
libqpdf/QPDFJob_config.cc
@@ -518,6 +518,13 @@ QPDFJob::Config::requiresPassword() @@ -518,6 +518,13 @@ QPDFJob::Config::requiresPassword()
518 } 518 }
519 519
520 QPDFJob::Config* 520 QPDFJob::Config*
  521 +QPDFJob::Config::removeRestrictions()
  522 +{
  523 + o.m->remove_restrictions = true;
  524 + return this;
  525 +}
  526 +
  527 +QPDFJob::Config*
521 QPDFJob::Config::showAttachment(std::string const& parameter) 528 QPDFJob::Config::showAttachment(std::string const& parameter)
522 { 529 {
523 o.m->attachment_to_show = parameter; 530 o.m->attachment_to_show = parameter;
libqpdf/qpdf/auto_job_help.hh
@@ -156,6 +156,11 @@ ap.addOptionHelp(&quot;--decrypt&quot;, &quot;transformation&quot;, &quot;remove encryption from input fi @@ -156,6 +156,11 @@ ap.addOptionHelp(&quot;--decrypt&quot;, &quot;transformation&quot;, &quot;remove encryption from input fi
156 encrypted. Normally qpdf preserves whatever encryption was 156 encrypted. Normally qpdf preserves whatever encryption was
157 present on the input file. This option overrides that behavior. 157 present on the input file. This option overrides that behavior.
158 )"); 158 )");
  159 +ap.addOptionHelp("--remove-restrictions", "transformation", "remove security restrictions from input file", R"(Remove restrictions associated with digitally signed PDF files.
  160 +This may be combined with --decrypt to allow free editing of
  161 +previously signed/encrypted files. This option invalidates the
  162 +signature but leaves its visual appearance intact.
  163 +)");
159 ap.addOptionHelp("--copy-encryption", "transformation", "copy another file's encryption details", R"(--copy-encryption=file 164 ap.addOptionHelp("--copy-encryption", "transformation", "copy another file's encryption details", R"(--copy-encryption=file
160 165
161 Copy encryption details from the specified file instead of 166 Copy encryption details from the specified file instead of
@@ -167,6 +172,9 @@ ap.addOptionHelp(&quot;--encryption-file-password&quot;, &quot;transformation&quot;, &quot;supply passwor @@ -167,6 +172,9 @@ ap.addOptionHelp(&quot;--encryption-file-password&quot;, &quot;transformation&quot;, &quot;supply passwor
167 If the file named in --copy-encryption requires a password, use 172 If the file named in --copy-encryption requires a password, use
168 this option to supply the password. 173 this option to supply the password.
169 )"); 174 )");
  175 +}
  176 +static void add_help_3(QPDFArgParser& ap)
  177 +{
170 ap.addOptionHelp("--qdf", "transformation", "enable viewing PDF code in a text editor", R"(Create a PDF file suitable for viewing in a text editor and even 178 ap.addOptionHelp("--qdf", "transformation", "enable viewing PDF code in a text editor", R"(Create a PDF file suitable for viewing in a text editor and even
171 editing. This is for editing the PDF code, not the page contents. 179 editing. This is for editing the PDF code, not the page contents.
172 All streams that can be uncompressed are uncompressed, and 180 All streams that can be uncompressed are uncompressed, and
@@ -175,9 +183,6 @@ companion tool &quot;fix-qdf&quot; can be used to repair hand-edited QDF @@ -175,9 +183,6 @@ companion tool &quot;fix-qdf&quot; can be used to repair hand-edited QDF
175 files. QDF is a feature specific to the qpdf tool. Please see 183 files. QDF is a feature specific to the qpdf tool. Please see
176 the "QDF Mode" chapter in the manual. 184 the "QDF Mode" chapter in the manual.
177 )"); 185 )");
178 -}  
179 -static void add_help_3(QPDFArgParser& ap)  
180 -{  
181 ap.addOptionHelp("--no-original-object-ids", "transformation", "omit original object IDs in qdf", R"(Omit comments in a QDF file indicating the object ID an object 186 ap.addOptionHelp("--no-original-object-ids", "transformation", "omit original object IDs in qdf", R"(Omit comments in a QDF file indicating the object ID an object
182 had in the original file. 187 had in the original file.
183 )"); 188 )");
@@ -292,12 +297,12 @@ resulting set of pages, where :odd starts with the first page and @@ -292,12 +297,12 @@ resulting set of pages, where :odd starts with the first page and
292 :even starts with the second page. These are odd and even pages 297 :even starts with the second page. These are odd and even pages
293 from the resulting set, not based on the original page numbers. 298 from the resulting set, not based on the original page numbers.
294 )"); 299 )");
295 -ap.addHelpTopic("modification", "change parts of the PDF", R"(Modification options make systematic changes to certain parts of  
296 -the PDF, causing the PDF to render differently from the original.  
297 -)");  
298 } 300 }
299 static void add_help_4(QPDFArgParser& ap) 301 static void add_help_4(QPDFArgParser& ap)
300 { 302 {
  303 +ap.addHelpTopic("modification", "change parts of the PDF", R"(Modification options make systematic changes to certain parts of
  304 +the PDF, causing the PDF to render differently from the original.
  305 +)");
301 ap.addOptionHelp("--pages", "modification", "begin page selection", R"(--pages file [--password=password] [page-range] [...] -- 306 ap.addOptionHelp("--pages", "modification", "begin page selection", R"(--pages file [--password=password] [page-range] [...] --
302 307
303 Run qpdf --help=page-selection for details. 308 Run qpdf --help=page-selection for details.
@@ -460,14 +465,14 @@ and filling in form fields. For 128-bit and 256-bit encryption, @@ -460,14 +465,14 @@ and filling in form fields. For 128-bit and 256-bit encryption,
460 this also enables editing, creating, and deleting form fields 465 this also enables editing, creating, and deleting form fields
461 unless --modify-other=n or --modify=none is also specified. 466 unless --modify-other=n or --modify=none is also specified.
462 )"); 467 )");
  468 +}
  469 +static void add_help_5(QPDFArgParser& ap)
  470 +{
463 ap.addOptionHelp("--assemble", "encryption", "restrict document assembly", R"(--assemble=[y|n] 471 ap.addOptionHelp("--assemble", "encryption", "restrict document assembly", R"(--assemble=[y|n]
464 472
465 Enable/disable document assembly (rotation and reordering of 473 Enable/disable document assembly (rotation and reordering of
466 pages). This option is not available with 40-bit encryption. 474 pages). This option is not available with 40-bit encryption.
467 )"); 475 )");
468 -}  
469 -static void add_help_5(QPDFArgParser& ap)  
470 -{  
471 ap.addOptionHelp("--extract", "encryption", "restrict text/graphic extraction", R"(--extract=[y|n] 476 ap.addOptionHelp("--extract", "encryption", "restrict text/graphic extraction", R"(--extract=[y|n]
472 477
473 Enable/disable text/graphic extraction for purposes other than 478 Enable/disable text/graphic extraction for purposes other than
@@ -638,14 +643,14 @@ The --copy-attachments-from flag and its options may be repeated @@ -638,14 +643,14 @@ The --copy-attachments-from flag and its options may be repeated
638 to copy attachments from multiple files. Run 643 to copy attachments from multiple files. Run
639 qpdf --help=copy-attachments for details. 644 qpdf --help=copy-attachments for details.
640 )"); 645 )");
  646 +}
  647 +static void add_help_6(QPDFArgParser& ap)
  648 +{
641 ap.addOptionHelp("--remove-attachment", "attachments", "remove an embedded file", R"(--remove-attachment=key 649 ap.addOptionHelp("--remove-attachment", "attachments", "remove an embedded file", R"(--remove-attachment=key
642 650
643 Remove an embedded file using its key. Get the key with 651 Remove an embedded file using its key. Get the key with
644 --list-attachments. 652 --list-attachments.
645 )"); 653 )");
646 -}  
647 -static void add_help_6(QPDFArgParser& ap)  
648 -{  
649 ap.addHelpTopic("pdf-dates", "PDF date format", R"(When a date is required, the date should conform to the PDF date 654 ap.addHelpTopic("pdf-dates", "PDF date format", R"(When a date is required, the date should conform to the PDF date
650 format specification, which is "D:yyyymmddhhmmssz" where "z" is 655 format specification, which is "D:yyyymmddhhmmssz" where "z" is
651 either literally upper case "Z" for UTC or a timezone offset in 656 either literally upper case "Z" for UTC or a timezone offset in
@@ -750,11 +755,11 @@ underlying encryption key to be displayed. @@ -750,11 +755,11 @@ underlying encryption key to be displayed.
750 ap.addOptionHelp("--check-linearization", "inspection", "check linearization tables", R"(Check to see whether a file is linearized and, if so, whether 755 ap.addOptionHelp("--check-linearization", "inspection", "check linearization tables", R"(Check to see whether a file is linearized and, if so, whether
751 the linearization hint tables are correct. 756 the linearization hint tables are correct.
752 )"); 757 )");
753 -ap.addOptionHelp("--show-linearization", "inspection", "show linearization hint tables", R"(Check and display all data in the linearization hint tables.  
754 -)");  
755 } 758 }
756 static void add_help_7(QPDFArgParser& ap) 759 static void add_help_7(QPDFArgParser& ap)
757 { 760 {
  761 +ap.addOptionHelp("--show-linearization", "inspection", "show linearization hint tables", R"(Check and display all data in the linearization hint tables.
  762 +)");
758 ap.addOptionHelp("--show-xref", "inspection", "show cross reference data", R"(Show the contents of the cross-reference table or stream (object 763 ap.addOptionHelp("--show-xref", "inspection", "show cross reference data", R"(Show the contents of the cross-reference table or stream (object
759 locations in the file) in a human-readable form. This is 764 locations in the file) in a human-readable form. This is
760 especially useful for files with cross-reference streams, which 765 especially useful for files with cross-reference streams, which
@@ -853,15 +858,15 @@ ap.addOptionHelp(&quot;--json-input&quot;, &quot;json&quot;, &quot;input file is qpdf JSON&quot;, R&quot;(Treat the @@ -853,15 +858,15 @@ ap.addOptionHelp(&quot;--json-input&quot;, &quot;json&quot;, &quot;input file is qpdf JSON&quot;, R&quot;(Treat the
853 "qpdf JSON Format" section of the manual for information about 858 "qpdf JSON Format" section of the manual for information about
854 how to use this option. 859 how to use this option.
855 )"); 860 )");
  861 +}
  862 +static void add_help_8(QPDFArgParser& ap)
  863 +{
856 ap.addOptionHelp("--update-from-json", "json", "update a PDF from qpdf JSON", R"(--update-from-json=qpdf-json-file 864 ap.addOptionHelp("--update-from-json", "json", "update a PDF from qpdf JSON", R"(--update-from-json=qpdf-json-file
857 865
858 Update a PDF file from a JSON file. Please see the "qpdf JSON" 866 Update a PDF file from a JSON file. Please see the "qpdf JSON"
859 chapter of the manual for information about how to use this 867 chapter of the manual for information about how to use this
860 option. 868 option.
861 )"); 869 )");
862 -}  
863 -static void add_help_8(QPDFArgParser& ap)  
864 -{  
865 ap.addHelpTopic("testing", "options for testing or debugging", R"(The options below are useful when writing automated test code that 870 ap.addHelpTopic("testing", "options for testing or debugging", R"(The options below are useful when writing automated test code that
866 includes files created by qpdf or when testing qpdf itself. 871 includes files created by qpdf or when testing qpdf itself.
867 )"); 872 )");
libqpdf/qpdf/auto_job_init.hh
@@ -71,6 +71,7 @@ this-&gt;ap.addBare(&quot;remove-page-labels&quot;, [this](){c_main-&gt;removePageLabels();}); @@ -71,6 +71,7 @@ this-&gt;ap.addBare(&quot;remove-page-labels&quot;, [this](){c_main-&gt;removePageLabels();});
71 this->ap.addBare("replace-input", b(&ArgParser::argReplaceInput)); 71 this->ap.addBare("replace-input", b(&ArgParser::argReplaceInput));
72 this->ap.addBare("report-memory-usage", [this](){c_main->reportMemoryUsage();}); 72 this->ap.addBare("report-memory-usage", [this](){c_main->reportMemoryUsage();});
73 this->ap.addBare("requires-password", [this](){c_main->requiresPassword();}); 73 this->ap.addBare("requires-password", [this](){c_main->requiresPassword();});
  74 +this->ap.addBare("remove-restrictions", [this](){c_main->removeRestrictions();});
74 this->ap.addBare("show-encryption", [this](){c_main->showEncryption();}); 75 this->ap.addBare("show-encryption", [this](){c_main->showEncryption();});
75 this->ap.addBare("show-encryption-key", [this](){c_main->showEncryptionKey();}); 76 this->ap.addBare("show-encryption-key", [this](){c_main->showEncryptionKey();});
76 this->ap.addBare("show-linearization", [this](){c_main->showLinearization();}); 77 this->ap.addBare("show-linearization", [this](){c_main->showLinearization();});
libqpdf/qpdf/auto_job_json_init.hh
@@ -109,6 +109,9 @@ popHandler(); // key: splitPages @@ -109,6 +109,9 @@ popHandler(); // key: splitPages
109 pushKey("jsonOutput"); 109 pushKey("jsonOutput");
110 addChoices(json_output_choices, false, [this](std::string const& p) { c_main->jsonOutput(p); }); 110 addChoices(json_output_choices, false, [this](std::string const& p) { c_main->jsonOutput(p); });
111 popHandler(); // key: jsonOutput 111 popHandler(); // key: jsonOutput
  112 +pushKey("removeRestrictions");
  113 +addBare([this]() { c_main->removeRestrictions(); });
  114 +popHandler(); // key: removeRestrictions
112 pushKey("encrypt"); 115 pushKey("encrypt");
113 beginDict(bindJSON(&Handlers::beginEncrypt), bindBare(&Handlers::endEncrypt)); // .encrypt 116 beginDict(bindJSON(&Handlers::beginEncrypt), bindBare(&Handlers::endEncrypt)); // .encrypt
114 pushKey("userPassword"); 117 pushKey("userPassword");
libqpdf/qpdf/auto_job_schema.hh
@@ -29,6 +29,7 @@ static constexpr char const* JOB_SCHEMA_DATA = R&quot;({ @@ -29,6 +29,7 @@ static constexpr char const* JOB_SCHEMA_DATA = R&quot;({
29 "progress": "show progress when writing", 29 "progress": "show progress when writing",
30 "splitPages": "write pages to separate files", 30 "splitPages": "write pages to separate files",
31 "jsonOutput": "apply defaults for JSON serialization", 31 "jsonOutput": "apply defaults for JSON serialization",
  32 + "removeRestrictions": "remove security restrictions from input file",
32 "encrypt": { 33 "encrypt": {
33 "userPassword": "user password", 34 "userPassword": "user password",
34 "ownerPassword": "owner password", 35 "ownerPassword": "owner password",
manual/cli.rst
@@ -736,7 +736,22 @@ Related Options @@ -736,7 +736,22 @@ Related Options
736 whatever encryption was present on the input file. This 736 whatever encryption was present on the input file. This
737 functionality is not intended to be used for bypassing copyright 737 functionality is not intended to be used for bypassing copyright
738 restrictions or other restrictions placed on files by their 738 restrictions or other restrictions placed on files by their
739 - producers. See also :qpdf:ref:`--copy-encryption`. 739 + producers. See also :qpdf:ref:`--copy-encryption` and
  740 + :qpdf:ref:`--remove-restrictions`.
  741 +
  742 +.. qpdf:option:: --remove-restrictions
  743 +
  744 + .. help: remove security restrictions from input file
  745 +
  746 + Remove restrictions associated with digitally signed PDF files.
  747 + This may be combined with --decrypt to allow free editing of
  748 + previously signed/encrypted files. This option invalidates the
  749 + signature but leaves its visual appearance intact.
  750 +
  751 + Remove security restrictions associated with digitally signed PDF
  752 + files. This may be combined with :qpdf:option:--decrypt: to allow
  753 + free editing of previously signed/encrypted files. This option
  754 + invalidates the signature but leaves its visual appearance intact.
740 755
741 .. qpdf:option:: --copy-encryption=file 756 .. qpdf:option:: --copy-encryption=file
742 757