Commit graph

147 commits

Author SHA1 Message Date
Ashod Nakashian
4305d333b2 loolwsd: lokit process can only host one url in its lifetime
Change-Id: I561e5b81a748b7ec567af9aff968ba5c66ad44bf
Reviewed-on: https://gerrit.libreoffice.org/23639
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-03-30 01:49:36 +00:00
Ashod Nakashian
3d2c2fde3b loolwsd: logging and misc cleanup
Change-Id: If3cea8191fe15fc752c436cd33d2a68dc2d88598
Reviewed-on: https://gerrit.libreoffice.org/23638
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-03-30 01:46:34 +00:00
Ashod Nakashian
ce2fabb733 loolwsd: moved IO utilities into IoUtil file
Change-Id: I1e8d5562787134cbb490c38b19d83b7514ec9baa
Reviewed-on: https://gerrit.libreoffice.org/23586
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-03-29 14:09:04 +00:00
Tor Lillqvist
a219819ebf Avoid defining constant strings in multiple places
It is not a good idea to have the same string somewhat arbitrarily
both as a static const members of the LOOLWSD class and then as a
file-local static const in another file. Or defined as a separate
local const static in each compilation unit that includes
Common.hpp. Use constexpr instead, in Common.hpp.
2016-03-28 14:17:30 +03:00
Ashod Nakashian
a35006cdef loolwsd: no need to lock in destructor
Change-Id: I1650bc5b44c23f1de8b5f65e621da43f1a2755eb
Reviewed-on: https://gerrit.libreoffice.org/23529
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-03-26 16:53:07 +00:00
Ashod Nakashian
82bd7a606a loolwsd: recursive_mutex -> mutex and new loading synchronization mechanics
Change-Id: I20249ca56ca3e9203e6a989e6fe9972b6b4eca36
Reviewed-on: https://gerrit.libreoffice.org/23528
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-03-26 16:52:25 +00:00
Ashod Nakashian
18829fda3b loolwsd: opportunistic kit session cleanup
When the Document lock cannot be taken
purging doesn't block (which would block
the kit-broker pipe). Instead, purging
is done only when the lock is taken,
otherwise we try again later.

Change-Id: Id201f1c67803d9b1e765e8c55f85206795fe53c0
Reviewed-on: https://gerrit.libreoffice.org/23448
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-03-23 00:01:39 +00:00
Ashod Nakashian
f2eec85b2a loolwsd: jailId ought be random, but must be PID
Ideally, we will have a randomized path for the jails.

Unfortunately, this will make it harder to cleanup
after an ungraceful exit of a child, including recovery
of docs etc.

Having a PID for the jailId makes this issue easier by
implicitly implying the jail path for a given child.

To prevent security leaks, we should at least randomize
the doc directory within the jail, as such:

/chroot/<pid>/user/docs/<rand>/

For now we use jailId=pid=rand.

Change-Id: I948fba0aaef725c9c059780df0a184a86569d898
Reviewed-on: https://gerrit.libreoffice.org/23223
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-03-14 03:15:04 +00:00
Ashod Nakashian
29e9ba68c3 loolwsd: removed unnecessary childId, which is in the child URL
Change-Id: Ibea2cd73657446ad4660400a0a9a38b376499df5
Reviewed-on: https://gerrit.libreoffice.org/23222
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-03-14 03:14:43 +00:00
Ashod Nakashian
8ef45a975e loolwsd: child URI now includes docKey
Change-Id: I62b91fee98fd853c84c3c5cbb48e65e5c9788ef0
Reviewed-on: https://gerrit.libreoffice.org/23215
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-03-14 03:09:14 +00:00
Ashod Nakashian
019aed134e loolwsd: using random jailId
Change-Id: Ie9501e4346a124994270ca1fac61869ed04b9b72
Reviewed-on: https://gerrit.libreoffice.org/23213
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-03-14 03:06:29 +00:00
Ashod Nakashian
1268507bf0 loolwsd: child WS URL format changed
The current format is more flexible and standard.

/loolwsd/child?sessionId=xxx&jailId=yyy

The sessionId is the client-specific connection ID (which
 is originally passed to the child via the Broker.

The jailId is the PID of the child.

Change-Id: I69c88e84114f9678addf795896ca2da15ca1221b
Reviewed-on: https://gerrit.libreoffice.org/23211
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-03-14 03:05:38 +00:00
Ashod Nakashian
0d8fcf5699 loolwsd: logging
Change-Id: I9a4dc248aca87983e3d7d3ace0071e5bbf92e688
Reviewed-on: https://gerrit.libreoffice.org/23209
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-03-14 03:04:17 +00:00
Tor Lillqvist
e7e1ef58ae Cosmetics: Sort and prune #include and 'using' lines 2016-03-08 09:44:04 +02:00
Tor Lillqvist
61ee1ae842 Use std::getenv() instead of Poco::Environment::get()
Much simpler.

Also, don't duplicate the code informing that LD_BIND_NOW or
LOK_VIEW_CALLBACK are not set. Not that I understand why we need to
inform about that? If the "normal" thing should be that they are set,
why don't make it so by default then?
2016-03-08 09:16:01 +02:00
Tor Lillqvist
06c6a7e1a6 Try harder to avoid deadlock
I occasionally saw a deadlock when running 'make check' where one
thread holds the ChildProcessSession::Mutex and wants the _mutex for a
Document, while another thread holds that _mutex and wants the
Mutex. In particular, it is the Document::onUnload() that wants the
_mutex. So avoid the deadlock by having Document::onUnload() first
take the ChildProcessSession::Mutex.
2016-03-07 20:00:13 +02:00
Tor Lillqvist
9f67eecadd Improve exception logging
Always try to identify *where* we caught the exception. It is not that
useful to have half a dozen places that all just log "Exception:".
2016-03-07 18:36:01 +02:00
Tor Lillqvist
636fafa3b6 We use a recursive mutex, so no need to drop and re-take around documentLoad()
The callbacks from documentLoad() are made in the same thread.

Sure, as such it is not a good thing to use recursive mutexes. If we
switch back to non-recursive mutexes, we will have to stop taking the
lock in callbacks from documentLoad(), i.e. make sure we know those
functions aren't used elsewhere, in places where a lock would be
needed. Or something.

If a client session closes just after sending a load message to load a
document, and another session then fairly immediately connects and
sends a load message for the same document, the latter session gets
handled by the same kit process. Also, the same Document object is
apparently used. In that kit process, the first documentLoad() might
easily still be in progress. The handler for the new session still
calls onLoad(), too, and as the first onLoad() had dropped the lock
for the duration of the documentLoad() call, the new onLoad can take
the lock and call documentLoad(), too, while the first documentLoad()
call in the other thread still is in progress. This leads to
interesting problems.
2016-03-07 12:57:18 +02:00
Tor Lillqvist
6859c85543 Factor out function to get the symbolic name for a LibreOfficeKitCallbackType 2016-03-04 11:49:46 +02:00
Tor Lillqvist
28fd1ace0c Make it clearer in the logging which callback is which 2016-03-04 11:32:25 +02:00
Pranav Kant
ada6a74dc0 loolwsd: Basic layout and interaction with AdminModel
Admin web sessions are added as subscribers to AdminModel. Live
notification fill up the AdminModel, and notifies to
subscribers, if present any. AdminModel can also be queried to
fetch any previous data since the start of the server including
expired documents/views with timestamps for analysis.

There is lot of stuff that can be added in future. This commit
just lays the foundation of appropriate classes.

Change-Id: Ifcf6c2896ef46b33935802e79cd28240fd4f980e
Reviewed-on: https://gerrit.libreoffice.org/22869
Reviewed-by: Tor Lillqvist <tml@collabora.com>
Tested-by: Tor Lillqvist <tml@collabora.com>
2016-03-03 18:30:33 +00:00
Pranav Kant
c1ca746f66 loolwsd: Make notify pipe accessible from child processes
Change-Id: Id91a38c2997cfb359aff0a42d000e9659653598b
Reviewed-on: https://gerrit.libreoffice.org/22830
Reviewed-by: Tor Lillqvist <tml@collabora.com>
Tested-by: Tor Lillqvist <tml@collabora.com>
2016-03-03 18:28:40 +00:00
Tor Lillqvist
2103fe2515 Revert "We use a recursive mutex, so no need to drop and re-take around documentLoad()"
Turns out the callbacks from documentLoad() are in general done on
another thread, not necessarily the same one that did the
documentLoad() call. Not sure why it happened to be the same thread
for me, but oh well. Need to fix the problem described in
3671abf89b in some other way then.

This reverts commit 2fab757462.
2016-03-03 18:37:23 +02:00
Tor Lillqvist
2fab757462 We use a recursive mutex, so no need to drop and re-take around documentLoad()
The callbacks from documentLoad() are made in the same thread.

Sure, as such it is not a good thing to use recursive mutexes. If we
switch back to non-recursive mutexes, we will have to stop taking the
lock in callbacks from documentLoad(), i.e. make sure we know those
functions aren't used elsewhere, in places where a lock would be
needed. Or something.
2016-03-03 17:14:15 +02:00
Tor Lillqvist
bf63df227b The payload can be null
It is always null at least for LOK_CALLBACK_STATUS_INDICATOR_FINISH.
2016-03-02 16:41:49 +02:00
Tor Lillqvist
38ddcf5243 Don't log the CR LF at the end of a response 2016-03-02 13:12:27 +02:00
Tor Lillqvist
02913dcbfc Use std:: consistently for cstdlib functions 2016-03-02 08:47:13 +02:00
Tor Lillqvist
d5292541bd Revert "Also chown the random devices to root:root and chmod to 666"
Not needed after all. It was a red herring. The device files work fine
even if not owned by root:root and with mode 664. The actual problem
was that I used a file system mounted with nodev when testing loolwsd.

This reverts commit 509314d559
2016-03-01 18:24:55 +02:00
Tor Lillqvist
4f701d5d84 Avoid aligning equal signs on sequential lines in a few arbitrary places
If we would use such style, we would need to do it consistently.
2016-03-01 17:28:47 +02:00
Tor Lillqvist
ec33f7b96a Don't use pre-increment when there is no need
We are not interested in the variable being assigned an incremented
value. Its value is not used any more. We are just interested in the
value of the variable plus one. Using pre-increment gives the wrong
impression.

Sure, this is nit-picking.
2016-03-01 15:53:35 +02:00
Tor Lillqvist
673b08bb81 We know that there is a = in the arg as we found a string that includes it
No need to to test again whether it is found. Also, std::strchr()
works fine.
2016-03-01 15:50:39 +02:00
Tor Lillqvist
f8aad3d31f Use the std:: versions of C standard library functions
As mentioned in the coding style part of README.
2016-03-01 15:44:22 +02:00
Miklos Vajna
f46a43b5f5 loolwsd: fix -Werror,-Wunused-parameter 2016-03-01 09:53:37 +01:00
Tor Lillqvist
9d655cbcc0 Don't pretend this will work on anything except Linux 2016-02-29 14:25:12 +02:00
Tor Lillqvist
509314d559 Also chown the random devices to root:root and chmod to 666
Otherwise they won't work. Not that I know whether this helps
anything, really. At least the NSS crypto initialization still takes a
long time.
2016-02-29 12:15:22 +02:00
Tor Lillqvist
ab3169ecdc Add some more Log::info() calls
We want to be able to see exactly when document loading and password
management is done and how long it takes.
2016-02-25 16:43:51 +02:00
Tor Lillqvist
32dc0a3c87 Don't ever attempt to handle the payload of CLOSE frames 2016-02-23 20:03:52 +02:00
Miklos Vajna
7552fcd806 loolwsd: work around -Werror,-Wunused-private-field 2016-02-23 09:35:46 +01:00
Tor Lillqvist
00e3d6ca20 Cosmetics: add a space 2016-02-22 17:09:59 +02:00
Tor Lillqvist
b4387a535a Bin some superfluous using declarations and includes, and actually use others
Sorry, could not resist. Obviously not very important.

In retrospect, maybe it would have been better to have as policy to
*not* use any 'using Poco::Foo'. Now there is an inconsistent mix of
writing out the complete type and using a 'using'. Plus copy-pasted
long lists of 'usings'. And of course, one should never have 'using'
in an include file. Oh well.
2016-02-22 11:37:47 +02:00
Henry Castro
730ec99194 loolwsd: ensure lokit process exited successfully after close the document and views 2016-02-21 08:10:30 -04:00
Henry Castro
b646fca95d loolwsd: add lokit iddle maintenance time out 2016-02-21 08:02:31 -04:00
Pranav Kant
f729156806 loolwsd: Fix misplaced break statement
Probably due to merge conflicts, it ended up in a wrong place.

Change-Id: Ia32e18149d99e901ceaa47a4e984f9ca818d0619
2016-02-21 14:08:00 +05:30
Pranav Kant
b71ebb8dfc loolwsd: Ask for password for multiple views also
This is possible by moving all the password handling logic to
Document container class. When a user opens a password protected
document the first time, it saves all possible data such as
password, password type etc. Upon opening the same document
again, password is matched with the cached password saved in the
document container class before allowing the new view access to
this document.

Change-Id: Id1f2b6e06de806564bf865e83fed51b01c9a0fbc
Reviewed-on: https://gerrit.libreoffice.org/22208
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-02-19 22:00:46 +00:00
Pranav Kant
631ae0f11f loolwsd: Get the first *live* connection
Sometimes there are situations when `connection` map is filled
with dead sessions. We don't want to deal with those dead ones.

Change-Id: I00dda77c39b5adbba69421eace0be0159e02505c
Reviewed-on: https://gerrit.libreoffice.org/22207
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-02-19 21:57:10 +00:00
Pranav Kant
10db02c208 loolwsd: Move document related callback logic to Document class
There are 5 LOK callbacks currently that are triggered on LOKit,
and not on LOKitDocument. These include status indicators, and
document password callbacks during document load. Lets move all
the callbacks called during document load in the Document container
itself, and keep the callbacks called after document load in the
Child session.

Change-Id: I8e43c2baaa12023b34822954dd494780ee6dd7ca
Reviewed-on: https://gerrit.libreoffice.org/22206
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-02-19 21:56:50 +00:00
Pranav Kant
7ecde23422 loolwsd: Remove superfluous registration of callback
Our DocumentCallback is smart enough which checks all the
running connections, and send the callback notification to all of
them. Registering the callback only during the first loadDocument
call should be enough.

Change-Id: I82bcb9525814dae14def3bfb6c088337d0d0ea3c
Reviewed-on: https://gerrit.libreoffice.org/22202
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-02-19 21:55:50 +00:00
Pranav Kant
3667bef9a6 loolwsd: Handle password protected documents
Change-Id: Iceb5bb598ef1517bf640994c27bad4ca36bd72c1
Reviewed-on: https://gerrit.libreoffice.org/21894
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-02-19 21:49:45 +00:00
Tor Lillqvist
7a97e1a1bc Remove pointless duplicated information from a log line
The log lines automatically have information telling which process
they come from.
2016-02-18 18:37:02 +02:00
Henry Castro
10070b11a9 loolwsd: fixes coding style naming convention in LOOLKit.cpp 2016-02-18 12:22:30 -04:00