Bug 46731 - Make joinscript_get_last_executed_version more robust
Make joinscript_get_last_executed_version more robust
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: Join (univention-join)
UCS 4.2
Other Linux
: P5 normal (vote)
: UCS 4.3-0-errata
Assigned To: Felix Botner
Arvid Requate
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2018-03-23 12:57 CET by Christian Völker
Modified: 2018-05-23 14:27 CEST (History)
1 user (show)

See Also:
What kind of report is it?: Bug Report
What type of bug is this?: 1: Cosmetic issue or missing function but workaround exists
Who will be affected by this bug?: 1: Will affect a very few installed domains
How will those affected feel about the bug?: 5: Blocking further progress on the daily work
User Pain: 0.029
Enterprise Customer affected?:
School Customer affected?: Yes
ISV affected?:
Waiting Support:
Ticket number: 2018031521000171
Bug group (optional):
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Völker univentionstaff 2018-03-23 12:57:17 CET
In a customer environment due to a crash or interruption the file /var/univetion-join/status got corrupted with some binary codes at the end of the file.

univention.run-joinscript failed by complaining every joinscript is invalid:

Search LDAP binddn                                         done
Running 00ucs-school-app-version-check.inst                skipped (invalid joinscript)
Running 00ucs-school-slave-check-ou.inst                   skipped (invalid joinscript)
Running 01univention-ldap-server-init.inst                 skipped (invalid joinscript)
[...]


After some debugging by set -x the following output of the related bash functions:

+ joinscript_get_last_executed_version
+ '[' -n '' ']'
+ joinscript_check_any_version_executed
+ touch /var/univention-join/status
+ grep -qs -E '^univention-samba4 v[0-9]+ successful' /var/univention-join/status
+ return 0
++ grep -E '^univention-samba4 v[0-9]+ successful' /var/univention-join/status
++ sed 's/^univention-samba4 v//'
++ sed 's/ successful.*$//'
++ sort -n
++ tail -n 1
+ JS_LAST_EXECUTED_VERSION='Übereinstimmungen in Binärdatei /var/univention-join/status.'
+ joinscript_is_version 'Übereinstimmungen in Binärdatei /var/univention-join/status.'
+ local 'var=Übereinstimmungen in Binärdatei /var/univention-join/status.'
+ '[' -z 'Übereinstimmungen in Binärdatei /var/univention-join/status.' ']'
++ echo 'Übereinstimmungen in Binärdatei /var/univention-join/status.'
++ tr -d 0-9
+ '[' '!' -z 'Übereinstimmungen in Binärdatei /var/univention-join/status.' ']'
+ return 1
+ return 1
+ return 1
root@bk175134a:/usr/share/univention-join# echo $HS_STATUSFILE
+ echo

So the command returned nothing as the file was partially recognized as binary.

The script should be aware of such errors and log something accordingly.
Comment 1 Felix Botner univentionstaff 2018-05-03 13:34:53 CEST
reproduced with: 
-> head -c60 < /vmlinuz >> /var/univention-join/status
-> univention-run-join-scripts
...
Running 01univention-ldap-server-init.inst      skipped (invalid joinscript)
Running 02univention-directory-notifier.inst    skipped (invalid joinscript)
Running 03univention-directory-listener.inst    skipped (invalid joinscript)
Running 04un...
Comment 2 Christian Völker univentionstaff 2018-05-03 14:39:05 CEST
In this case it should be fine by adding the "-a" parameter to the grep command...
Comment 3 Felix Botner univentionstaff 2018-05-03 17:39:25 CEST
> In this case it should be fine by adding the "-a" parameter
> to the grep command...

no, i do not think it is good to silently ignore a "broken" status file, better let the tools display an appropriate error message

added joinscript_check_status_file to joinscripthelper.lib (checks if $JS_STATUSFILE is a text/plain file, otherwise abort join)

added joinscript_check_status_file call to univention-join, univention-run-join-scripts and to joinscripthelper.lib.joinscript_init()

-> head -c60 < /vmlinuz >> /var/univention-join/status

-> /usr/lib/univention-install/30univention-appcenter.inst
The status file /var/univention-join/status seems to be corrupt (mime type is application/octet-stream, should be text/plain). Please make sure this file is a plain text file.

-> univention-run-join-scripts 
univention-run-join-scripts: runs all join scripts existing on local computer.
copyright (c) 2001-2018 Univention GmbH, Germany

The status file /var/univention-join/status seems to be corrupt (mime type is application/octet-stream, should be text/plain). Please make sure this file is a plain text file.

-> univention-join 
univention-join: joins a computer to an ucs domain
copyright (c) 2001-2018 Univention GmbH, Germany

The status file /var/univention-join/status seems to be corrupt (mime type is application/octet-stream, should be text/plain). Please make sure this file is a plain text file.



univention-join
354959ed8339bfdf05e25897fed2f895288ff163
104578fa2bec555e6134e0b60ad86c3634c3cad5

yaml
bbd509f01a93d25040143863cd003d45a8c18328
Comment 4 Arvid Requate univentionstaff 2018-05-15 14:29:15 CEST
Ok:
* univention-run-join-scripts detects broken satus
* univention-join still works even if status file was broken
* Advisory Ok
Comment 5 Arvid Requate univentionstaff 2018-05-23 14:27:08 CEST
<http://errata.software-univention.de/ucs/4.3/85.html>