Let users execute but not view

  • Thread starter Florian Lindner
  • Start date
F

Florian Lindner

Hi!
I have a python script which should be executed my normal users but they
should not be able to view the sourcecode. Setting permissions to x only
does not help, the python interpreter can not read the file.
How can I do that?
Thanks,
Florian
 
S

Steve Horsley

Florian said:
Hi!
I have a python script which should be executed my normal users but they
should not be able to view the sourcecode. Setting permissions to x only
does not help, the python interpreter can not read the file.
How can I do that?
Thanks,
Florian

I believe that the common thing to do is to remove the .py file but
leave the compiled .pyc file, which is rather more difficult to
reverse-engineer. Not impossible of course.

However, I'm only a newbe and others may know a better way.

Steve
 
D

Dave Kuhlman

Florian said:
Hi!
I have a python script which should be executed my normal users
but they should not be able to view the sourcecode. Setting
permissions to x only does not help, the python interpreter can
not read the file. How can I do that?

Compile it to a .pyc file and give that to your users instead of
the .py file. You can use py_compile or compileall in the Python
standard libraries for this.

Note, however, that this does not protect you from the really
inquisitive or from malicious users and so on. They could use
dis, for example, from the Python standard library to learn about
your code.

Dave
 
D

Dennis Lee Bieber

Florian Lindner fed this fish to the penguins on Sunday 04 January 2004
11:06 am:
Hi!
I have a python script which should be executed my normal users but
they should not be able to view the sourcecode. Setting permissions to
x only does not help, the python interpreter can not read the file.
How can I do that?

Create .pyc (or .pyo) files for all the modules, remove the sources,
and use a very short .py file that just imports the main program and
runs its entry point...

Tedious, but it does add a layer of hassle to anyone trying to get
into it.

No perfect, as there are ways to "decompile" the .pyc files and get
the gist of what is being performed.

--
 
J

John Roth

Florian Lindner said:
Hi!
I have a python script which should be executed my normal users but they
should not be able to view the sourcecode. Setting permissions to x only
does not help, the python interpreter can not read the file.
How can I do that?
Thanks,
Florian

You've already got the standard answers, hopefully that will do
what you need to do.

The other way is to dig into the import mechanics, paying
particular attention to how it unfreezes frozen modules,
and then arrange to decrypt your encrypted pre-compiled
modules when they have to be imported.

That's a *lot* of hassle, and I don't know of anyone
who's actually done it. Whether the work is worth
the benefit is, of course, your decision.

John Roth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,174
Messages
2,570,940
Members
47,486
Latest member
websterztechnologies01

Latest Threads

Top