Skip to content

Conversation

maxhbr
Copy link
Member

@maxhbr maxhbr commented Mar 1, 2016

This PR

  • adds permission handling for directories
  • refactors delagent
  • repairs permission checking

this will fix #273
see #602 for the discussion on the previous PR concerned with this issue

This PR should not be merged yet.

@maxhbr
Copy link
Member Author

maxhbr commented Mar 1, 2016

@shaheemazmalmmd: even with the debugger i was not able to find the difference in

PGresult * PQexecCheck(const char *desc, char *SQL, char *file, const int line)
{
  PGresult *result;
  [...]
  result = PQexec(db_conn, SQL);
  if (fo_checkPQcommand(db_conn, result, SQL, file, line))
  {
    exit(-1);
  }
  return result;
}
[...]
#if 0
  result = PQexecCheck(NULL, SQL, __FILE__, __LINE__);
#else
  result = PQexec(db_conn, SQL);
  if (fo_checkPQresult(db_conn, result, SQL, __FILE__, __LINE__))
  {
    exit(-1);
  }
#endif
[...]

I would suggest to remove the #if 0 case.

Btw.: I would rebase this PR if this is OK for you? DONE

@maxhbr maxhbr force-pushed the dev/rewriteDelagentPermissions branch from 5d77b16 to b4645c4 Compare March 1, 2016 13:14
@maxhbr
Copy link
Member Author

maxhbr commented Mar 1, 2016

@shaheemazmalmmd: I have already rebased it but I can revert it if you have problems with that.

@shaheemazmalmmd
Copy link
Member

no, good that you rebased it. i missed it yesterday.

@maxhbr
Copy link
Member Author

maxhbr commented Mar 2, 2016

I think that we have to have a look at the tests for delagent. I think at least the functional agent tests are outdated and also the unit tests should be extended.

There is currently also a logic problem in the code where uploads contained in a Folder get deleted, even without write permissions. I will try to fix this. Fixed

@maxhbr maxhbr changed the title Rewrite/refactor delagent Rewrite/refactor delagent and fix #273 Mar 2, 2016
@maxhbr
Copy link
Member Author

maxhbr commented Mar 9, 2016

Problem: fixed with next commit

./delagent --user rUser --password --rPassword -f, where rUser is a user with read permissions, lists all uploads and ignores permissions

On the other side does ./delagent [...] -u only list uploads where one has read permissions. UPDATE: ./delagent [...] -u only lists uploads, where user is mentioned as user_fk.

Possible solution

Use logic from UploadPermissionDao.php Was done with the GetUploadPerm(..) function.

@maxhbr
Copy link
Member Author

maxhbr commented Mar 9, 2016

@shaheemazmalmmd: I have manually tested that PR and it looks OK. Do you have any ideas what could be missing? Otherwise I would ask @steffen-weber or @wuan to review this PR. After that I might squash the commits and remove that silly #if 0 thing.

BUT: I am still not able to run the functional tests. The used scripts

  • src/testing/db/createTestDB.php
  • src/testing/lib/libTestDB.php and
  • src/testing/db/gtdbcreate.sh

seam to be outdated. I think their functionality should be replaced by the php classes

  • Fossology\Lib\Test\TestPgDb together with
  • Fossology\Lib\Test\TestInstaller.

But in this environment one has no deployed www and thus cant use the upload functionality to set the DB up.

@maxhbr maxhbr force-pushed the dev/rewriteDelagentPermissions branch 3 times, most recently from fd6355d to 9d846a2 Compare March 21, 2016 14:12
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.0002%) to 13.363% when pulling 9d846a2 on siemens:dev/rewriteDelagentPermissions into 09ed2a4 on fossology:master.

shaheemazmalmmd and others added 2 commits March 22, 2016 11:23
any user who is admin or owner can delete the folder, not all users
* pass the variables `user_id` and `user_perm` to all functions where
  they are needed
* extract the permission checks into three functions (for uploads,
  folders, licenses)
* start adding the permission checks into the correct places (not done
  yet, not tested yet)
* move `admin_folder_delete.php` to `delagent/ui`
* general rewriting of the delagent

partly based on work by @shaheemazmalmmd
@maxhbr maxhbr force-pushed the dev/rewriteDelagentPermissions branch from 9d846a2 to eb1856a Compare March 22, 2016 10:26
@maxhbr
Copy link
Member Author

maxhbr commented Mar 22, 2016

Hello,

we need someone to review this PR. Maybe @wuan or @steffen-weber? Or maybe even @fogninid since this is essentially c-code?

When someone volunteers, I will support him actively and give an overview on the changes.

maxhbr and others added 5 commits March 22, 2016 11:36
... and more refactoring

by @shaheemazmalmmd: style(delagent): Alignment of code removed tabs and added spaces
* in `src/delagent/ui/admin-upload-delete.php` was no check for
  permissions, this enabled eveyone to delete every file with the
  correct POST-request
@maxhbr maxhbr force-pushed the dev/rewriteDelagentPermissions branch from eb1856a to 639221c Compare March 22, 2016 10:39
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.01%) to 13.36% when pulling eb1856a on siemens:dev/rewriteDelagentPermissions into cc73013 on fossology:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.01%) to 13.363% when pulling 639221c on siemens:dev/rewriteDelagentPermissions into cc73013 on fossology:master.

@maxhbr
Copy link
Member Author

maxhbr commented Mar 22, 2016

Oh sorry, instead of @fogninid I wanted to write @joshovi.



/***********************************************
Usage():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer all function names and variable names to be start with lower case. It should be uniform at least.

int check_permission_folder(long folder_id, int user_id, int user_perm);
int check_permission_license(long license_id, int user_perm);

/* functions that list things */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the captital letter at the start signify anything?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that is just the style the code was written...

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.01%) to 13.36% when pulling bdc88f0 on siemens:dev/rewriteDelagentPermissions into cc73013 on fossology:master.

@maxhbr
Copy link
Member Author

maxhbr commented Mar 23, 2016

I will refactor the returncodes tomorrow

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.003%) to 13.371% when pulling 0e7c179 on siemens:dev/rewriteDelagentPermissions into cc73013 on fossology:master.

@maxhbr maxhbr force-pushed the dev/rewriteDelagentPermissions branch from 1cd77fe to bf14882 Compare March 24, 2016 11:17
if (ReadParameter(Parm) < 0)
exit(-1);
returnedCode = listUploads(user_id, user_perm);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if returnedCode != 0 you might want to leave the program here before you set it again if listFolder is true

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. Its fixed now

@maxhbr maxhbr force-pushed the dev/rewriteDelagentPermissions branch from bf14882 to 579b71b Compare March 29, 2016 18:17

writeMessageAfterDelete("upload", delUpload, user_name, returnedCode);
}
if (delFolder)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, or are delUpload and delFolder mutually exclusive?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function writeMessageAfterDelete keeps track of that and exits if the returned code is not 0

@maxhbr
Copy link
Member Author

maxhbr commented Mar 29, 2016

@joshovi: your last mentioned issues are solved with the commit 4958b92. When merging this should be squashed into 1676498

maxhbr added 5 commits March 29, 2016 21:27
- rewritten /refactored functions:
  - `DeleteUpload`
  - `DeleteLicense`
  - `UnlinkContent`
  - and more
- rewrite naming of `TempTable`
- remove all unnecessary `memset` calls
- make return codes more consistend
- remove dead code
- die on permission failure
  - this change was made to show delagent jobs, which have had permission
    problems, as failed agents (i.e. red).
* The function `SHA1(...)` could generate strings containing `\000`
  which did not work with the following call of `strlen(...)`
* This is solved, since one knows that a SHA1 hash as hex is 40
  characters long (20 chars for the raw value)
* The old test, whether the creation of the sha1 failed, can not work
  since the first char could also be `\000` ==> removed
`rc=0` should always be the "good" case
`rc>0` is a permission problem
`rc<0` is a database connection problem, which has to be propagated out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

any user who is not the owner can delete any folder via /delagent -F

4 participants