Ask Your Question

how to check if a file is password protected using command line in linux

asked 2019-04-10 11:05:21 +0200

ahmad.alyan gravatar image


how I could check if the uploaded file to my server ( Doc , Docx , Xsl , Xslx ... ) is protected

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2019-04-10 12:44:23 +0200

Opaque gravatar image

updated 2019-04-10 12:46:27 +0200

This is definitely not an easy job, since the method will depend on the file format. E.g. Microsofts .doc/.xls are binary formats while .odt/.docx are zipped archives of XML files For .odt it would be required to extract META-INF/manifest.xml and to perform an analysis of the XML content and entries containing manifest:salt=... (or to look whether any other of the XML files are just text files or are of type data). I'm not aware of any tool, which could provide a simple linux call like IsProtected -f <file> throwing a "yes" or "no".

The only - but heuristic - way may be to call libreoffice6.2 --cat <file>.If <file> ist protected the command results in Error: source file could not be loaded message (tested only for .odt files). Since there may be other reasons for that error message, I call it a heuristic method. It does not allow for a definite decision "is protected".

edit flag offensive delete link more


the libreoffice6.2 --cat <file> would not work with the xslx I have tried it and I have gotten

Error: Please verify input parameters... (SfxBaseModel::impl_store <file:///tmp/brtZFk> failed: 0xc10(Error Area:Io Class:Write Code:16))

ahmad.alyan gravatar imageahmad.alyan ( 2019-04-10 13:10:58 +0200 )edit

As stated above (tested only for .odt files) and fact in my opinion this is not a task for LibreOffice and this forum is not the correct one.

Opaque gravatar imageOpaque ( 2019-04-10 13:17:27 +0200 )edit

Normally if I used a software to read some files the software will try to read them and if they were protected then the software will throw an error that those data is protected this what I have when I use - as for example - Ghostscript to read and merge pdf files

the problem is when I use LibreOffice to convert the word or excel file to pdf it didn't say anything when he failed to convert then it just does nothing and I was searching for a way to know what is happening

ahmad.alyan gravatar imageahmad.alyan ( 2019-04-10 13:51:55 +0200 )edit

I fully understand the requirement. I have repeated the test using a protected .xslx and in fact it also throws an Error: source file could not be loaded message. The message from your first comment, though an error message, indicates that the .xlsx is not protected. Otherwise the "could not be loaded" message would result from the call. Thus in a script the heuritisc decision could be

if [[ "$(libreoffice6.2 --cat <file> | grep "Error: source file could not be loaded")" != "" ]]; then
Opaque gravatar imageOpaque ( 2019-04-10 14:05:16 +0200 )edit

thanx I will try it again

ahmad.alyan gravatar imageahmad.alyan ( 2019-04-10 14:24:23 +0200 )edit

Correction: I forgot 2>&1, thus scriptlet must read:

if [[ "$(libreoffice6.2 --cat <file> 2>&1 |  grep "Error: source file could not be loaded")" != "" ]]; then
Opaque gravatar imageOpaque ( 2019-04-10 14:33:21 +0200 )edit

actually I am trying to execute this command

/usr/bin/libreoffice6.1 -env:UserInstallation=file:///var/www/aalyan/html/trunk/backend/tmp//soffice_profile_${USER} --cat word.docx 2>&1

using PHP exec function but when I call it, it goes and didn't return as a usual

did you have any idea about this

ahmad.alyan gravatar imageahmad.alyan ( 2019-04-11 10:45:21 +0200 )edit

Hello - I got no idea (I'm not very familiar with the command line execution of LO) and I consider this a new question. To increase the probability to get an answer, I'd suggest you create a new question

Opaque gravatar imageOpaque ( 2019-04-11 11:30:29 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-04-10 11:05:21 +0200

Seen: 147 times

Last updated: Apr 10