Skip to content

Can't reshare link with default expiration date #11396

Closed

Description

@nicman42

Steps to reproduce:

  • default expiration date is set
  • share a folder to another user (not a link)
  • the other user can't reshare the folder with the "share link" option

When he clicks on "share link" nothing happens.
The log says:
{"app":"PHP","message":"Call to a member function format() on a non-object at /usr/share/php/Doctrine/DBAL/Types/DateTimeType.php#53","level":3,"time":"2014-10-02T13:04:14+00:00"}

Sharing an own folder (not share by another user) with the "share link" option works.

owncloud 7.0.2.1 (debian package 7.0.2+dfsg-1~bpo70+1)
with postgres
on debian 7.6

Activity

  1. karlitschek commented on Oct 2, 2014

    @karlitschek
    Contributor

    @schiesbn

  2. PVince81 commented on Oct 6, 2014

    @PVince81
    Contributor

    I tried the following steps in v7.0.2 with PostgreSQL:

    1. Go to "Admin" page
    2. Tick "Set default expiration date" and leave the default of 7 days
    3. Create another user "user2"
    4. Create a folder "pics" and upload some pics
    5. Share "pics" with "user2"
    6. Login as "user2"
    7. Share "pics" with link
    8. Open the link

    It works for me.

    Please provide more detailed steps.
    Has this folder ever be shared with link before ?

  3. PVince81 commented on Oct 6, 2014

    @PVince81
    Contributor

    Please also post the matching content of the oc_share table at the end of your steps to see in what format the potential date might appear

  4. nicman42 commented on Oct 7, 2014

    @nicman42
    Author

    Now it's even more strange.
    I reproduced your steps. Most of the time creating the link is now working but then the expiration date is not saved (even if expiration date is forced). In oc_share the column expiration is null.
    The request to share.php is
    action=share&itemType=folder&itemSource=3770&shareType=3&shareWith=&permissions=1&itemSourceName=admin-test&expirationDate=2014-10-14+00%3A00%3A00

    I can reopen the share dialog and set the expiration date and it's saved (expiration in oc_share is "2014-10-09 00:00:00".
    The request to share.php is
    action=setExpirationDate&itemType=folder&itemSource=3770&date=2014-10-14+00%3A00%3A00

    I still try to reproduce the behavior when creating the link is not working and check the expiration date in the request of share.php and in the oc_share. But now it seems like at least this error is gone.

  5. PVince81 commented on Oct 7, 2014

    @PVince81
    Contributor

    I never realized that the date had a "+" in the URL, did you change anything in the server configuration / PHP modules ? Some people reported having issues with URLs with "+" inside.
    That could explain the strange date format issues you were having if the server internally converts it to a " " or something...

  6. nicman42 commented on Oct 7, 2014

    @nicman42
    Author

    I think the "+" is just how Firebug displays the parameters. When I copy the parameters from another part of Firebug it looks like this:
    action share
    expirationDate 2014-10-14 00:00:00
    itemSource 17
    itemSourceName gallery
    itemType folder
    permissions 1
    shareType 3
    shareWith

    I havent't changed anything on php configs.

    But I found the cause of the original issue (can't reshare link). It only appeared at exactly one of my shared folders. And this one has an expiration date in the oc_share ("2014-10-01 09:00:00"). I don't know how this could happen. I haven't changed anything in the database. After I set the expiration to null, creating a link works. It doesn't matter if the expiration date is in the past or in the future.

  7. enoch85 commented on Mar 5, 2015

    @enoch85

    @noooz Tried oC 8?

  8. popov-d commented on May 6, 2015

    @popov-d
    Contributor

    Seems I just got this bug.

    My system is now Debian 7.8, ownCloud 8.0.3 (stable), package owncloud_8.0.3-1_all.deb, updated several times from 7.0, Apache 2.2.22-13+deb7u4, MySQL 5.5.43-0+deb7u1, PHP 5.4.39-0+deb7u2. All are current versions from repositories.

    Only activated apps: Activity, Deleted files, Share Files, Versions, Video Viewer. No external storages, encryption or LDAP, or other extended things.

    The scenario seems to be more complex to me. I also digged the database and source to understand what happens, but didn't find a solution unfortunately.

    1. User A creates a directory, puts some files into it and shares it to user B (or more specific users).
    2. User B can reshare files and subdirectories, either to users/groups or by link. At this point it works ok. As I explain below, this step may be missing, but it happened in practice and it illustrates one side of the problem.
    3. User A shares the same directory also by link with an expiration period. I don't think it matters, if it is a default or changed expiration time.
    4. Then user A shares the same directory to user C. This seems to work ok, but…
    5. When user C tries to re-share this directory or something in it by link, this does not work. Clicking on checkbox in a sharing window does not open the link field.

    The last click produces an error in owncloud.log:

    {"app":"PHP","message":"Call to a member function format() on a non-object at /var/www/owncloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Types/DateTimeType.php#53","level":3,"time":"2015-05-06 14:31:41"}

    And client browser gets 500 Internal Server Error in responce to AJAX request in response to POST /cloud/index.php/core/ajax/share.php .

    I looked into oc_share to check the difference between step 2 (healthy) and step 4 (sick) shares, and found that step 2 gives expiration NULL, but step 4 sets expiration value from sharing in step 3 somehow. And this $value gets somehow to DataTimeType.php line 53, as string, where it is expected to be an object with method.

    Seems to me that 'expiration' field is for link sharing only (share_type==3), according to UI behaviour. In this case bug happens when a non-null value comes with another share_type's.

    I also noticed that in /var/www/owncloud/lib/private/share/share.php, line 2085 the expiration parameter is passed to SQL query in a different way, with an explict datatype. Possibly call to exception place in DateTimeType.php originates from this bindValue(). But I am not sure.

    In my opinion, the bug comes from inheritance of 'expiration' from one share to another. Either it happens when it should not, or is implemented incorrectly.

    By now I 'cured' my step 4 shares with a query:

    update oc_share set expiration=NULL where id in (… sick share id's list…);

    After that re-sharing by link starts working with them as expected. But this fixed only consequences, not the bug. I also instructed some most active users that sharing by link should be the last on a file or directory. Sharing to user after that may give strange results, so should be done before.

  9. PVince81 commented on Aug 18, 2015

    @PVince81
    Contributor
  10. PVince81 commented on Sep 17, 2015

    @PVince81
    Contributor

    @popov-d thanks a lot for the detailed step. I was able to reproduce this on 8.1.1.

    I noticed that whenever an expiration date exists, any local share created after that will have the expiration date set to the local share ! This is wrong as expiration date only applies for link shares.

    This could be part of the problem.

  11. PVince81 commented on Sep 17, 2015

    @PVince81
    Contributor

    Simplified steps:

    1. Go to admin page and tick "Set default expiration date"
    2. User1 creates folder "test"
    3. User1 shares "test" with link (a default exp date will be set, exact value doesn't matter)
    4. User1 shares "test" with "user2" (in that order!)
    5. User2 tries to share "test"

    I tried master (the new share dialog) and it works properly because the new code doesn't send the expiration date for user shares.

    Let's find out if preventing this for regular shared on OC 8.1 works

  12. PVince81 commented on Sep 17, 2015

    @PVince81
    Contributor

    Ok, here is the explanation for the failing "format()" call.

    See this line here: https://github.com/owncloud/core/blob/master/lib/private/share/share.php#L2214
    There is logic that copies the values from the parent share to the child share.
    But here the parent share is a user share and NOT a link share, so the expiration date was not parsed and is still a string. So when the new share gets created, the DB cannot automatically convert the string to a date object, hence the "format()" error above.

    Now the problem is that such parent share should not have an expiration date in the first place.

    Some ideas to fix this:

    Feedback is welcome.

  13. popov-d commented on Sep 17, 2015

    @popov-d
    Contributor

    Would it be enough to set expirationDate only for link shares? Just add condition to that line:

    if($shareType == self::SHARE_TYPE_LINK) {
        $result['expirationDate'] = min($expirationDate, $checkReshare['expiration']);
    }

    By now I have version 8.1.1 and bug is still there. I wrote a small script that runs a sql update like in idea 3, and put it into /etc/cron.hourly/. Once a few days it updates 1 record instead of usual 0. No more complains from users.

    Of course, it will be nice to have a working solution inside OC. Maybe with a fixing query inside upgrade procedure.

  14. PVince81 commented on Sep 17, 2015

    @PVince81
    Contributor

    @popov-d that could do, yes.
    I'm currently trying to find the smallest low-impact fix that could be backported.

  15. PVince81 commented on Sep 17, 2015

    @PVince81
    Contributor

    Here is my fix: #19122

    It's a bit better because it also prevents the OCS share API and other places to return the expiration date when it's not supposed to be there.

  16. popov-d commented on Sep 17, 2015

    @popov-d
    Contributor

    Just applied this to my installation. From user's point of view, bug is gone, resharing works even after link with expiration. Nothing bad in log. But in database oc_share.expiration is still set. Just seems not to break anything now.

    I removed my update script from cron.hourly. Will try to run it this way and write if anything happens.

  17. PVince81 commented on Sep 17, 2015

    @PVince81
    Contributor

    @popov-d thanks for the confirmation.

    I'll write a repair step to auto-clean this column in future versions of OC.
    With the patch above having the expiration date in that column should now be harmless.

  18. PVince81 commented on Sep 17, 2015

    @PVince81
    Contributor

    Repair step here: #19132

  19. added this to the milestone on Sep 25, 2015
  20. locked as resolved and limited conversation to collaborators on Aug 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions