Forked mumble-django project from https://bitbucket.org/Svedrin/mumble-django
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.7 KiB

  1. # -*- coding: utf-8 -*-
  2. """
  3. * Copyright (C) 2009, Michael "Svedrin" Ziegler <diese-addy@funzt-halt.net>
  4. *
  5. * Mumble-Django is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This package is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. """
  15. import os, stat
  16. from mercurial import hg
  17. type_whitelist = [
  18. 'application/x-executable; charset=binary',
  19. 'application/x-sharedlib; charset=binary',
  20. ];
  21. def check_mimetype( filename ):
  22. try:
  23. fileproc = os.popen( 'file -ib %s' % filename );
  24. mtype = fileproc.read().strip();
  25. return (mtype in type_whitelist);
  26. finally:
  27. fileproc.close();
  28. def check_script( filename ):
  29. try:
  30. f = open( filename, "rb" );
  31. return f.read(3) == '#!/';
  32. finally:
  33. f.close();
  34. def checkexec( ui, repo, **kwargs ):
  35. modified, added, removed, deleted, unknown, ignored, clean = repo.status();
  36. # We only care about modified and added files. Check their perms to see if +x
  37. for curfile in (modified+added):
  38. fullpath = os.path.join( repo.root, curfile );
  39. statinfo = os.stat( fullpath );
  40. mode = statinfo.st_mode;
  41. # If executable without being an executable or a script, warn and fail
  42. if ( (mode & stat.S_IXUSR) or (mode & stat.S_IXGRP) or (mode & stat.S_IXOTH) ) and \
  43. not ( check_mimetype( fullpath ) or check_script( fullpath ) ):
  44. ui.warn( "Executable bit set on file %s but not ELF or script\n" % curfile );
  45. return True;
  46. return False;