Bugzilla – Attachment 170499 Details for
Bug 137926
storeAsURL regression between libreoffice < 7 and libreoffice >=7
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
script I used to test the regression
remove_password.py (text/x-python), 3.86 KB, created by
libreoffice
on 2021-03-15 23:00:13 UTC
(
hide
)
Description:
script I used to test the regression
Filename:
MIME Type:
Creator:
libreoffice
Created:
2021-03-15 23:00:13 UTC
Size:
3.86 KB
patch
obsolete
>#!/usr/bin/python3 ># -*- coding: utf-8 -*- > >import subprocess >import sys >import os >import socket >import time >import uno # pylint: disable=import-error > > >def convert_office_file_to_pdf(file, password): > # Performance could be improved by only starting > # the libreoffice when needed (aka: when the file need to be decrypted). > # But code is simpler that way > > # Launch libreoffice server > # "/home/user/core/instdir/program/soffice", > cmd = [ > #"/usr/lib/libreoffice/program/soffice", > "/home/user/core/instdir/program/soffice", > "--accept=socket,host=localhost,port=2202;urp", > "--headless", > ] > print("libreoffice process") > #with subprocess.Popen(cmd) as libreoffice_process: > # todo force: SAL_ENABLE_FILE_LOCKING=0 > path = {"PATH": os.environ['PATH']} > with subprocess.Popen(cmd, env=path) as libreoffice_process: > > print("wait for socket") > # Wait until libreoffice server is ready > with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: > sock.settimeout(1) > while sock.connect_ex(('127.0.0.1', 2202)) != 0: > time.sleep(1) > > # Remove password from file using libreoffice API > try: > # It doesn't seem that any libreoffice option or parameter work to > # either disable the creation of .~lock* file nor ignoring the > # already existing file. > # I tried all the parameters documented by "libreoffice --help", and > # also tryied to modify the "soffice" bash launching script, but it > # seems that option related to file locking are ignored. > # So I fallback to manually deleting those files before each tries, > # based on their name. This bug was introduced between libreoffice > # 6.4.7 and libreoffice 7.X > delete_libreoffice_lockfile(file) > decrypt(file, password) > except Exception as e: > print("Failure:" +e) > libreoffice_process.terminate() > > >def delete_libreoffice_lockfile(file): > basepath = os.path.dirname(file) + "/.~lock." + os.path.basename(file) > path1 = basepath + "#" > path2 = basepath + ".nopassword#" > if os.path.exists(path1): > os.remove(path1) > if os.path.exists(path2): > os.remove(path2) > > >def decrypt(file, password): > """ > Try to remove the password of a libreoffice-compatible file, > and store the resulting file in INITIAL_NAME.nopassword. > The steps are: > - Connect to a libreoffice API server, listening on localhost on port 2202 > - Try to load a document with additionnal properties: > - "Hidden" to not load any libreoffice GUI > - "Password" to automatically try to decrypt the document > - Store the document without additionnal properties [this remove the password] > """ > > src = f"file://{file}" > dst = f"file://{file}.nopassword" > > local_context = uno.getComponentContext() > resolver = local_context.ServiceManager.createInstanceWithContext( > "com.sun.star.bridge.UnoUrlResolver", > local_context > ) > ctx = resolver.resolve( > "uno:socket,host=localhost,port=2202;urp;StarOffice.ComponentContext" > ) > smgr = ctx.ServiceManager > desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx) > > hidden_property = uno.createUnoStruct("com.sun.star.beans.PropertyValue") > hidden_property.Name = "Hidden" > hidden_property.Value = True > > password_property = uno.createUnoStruct("com.sun.star.beans.PropertyValue") > password_property.Name = "Password" > password_property.Value = password > print(":"+src+":") > document = desktop.loadComponentFromURL( > src, > "_blank", > 0, > (password_property, hidden_property,) > ) > document.storeAsURL(dst, ()) > > >def main(): > convert_office_file_to_pdf(sys.argv[1], sys.argv[2]) > > >if __name__ == "__main__": > main()
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 137926
:
166919
|
166920
| 170499 |
170500
|
170502