-10

I've written a Perl script and placed on Linux/Windows machine and want to restrict it so that

  • If an admin opens the program with Notepad then they will see the whole file

  • If a non-admin opens the program with Notepad then they should see only 30% of the contents

Borodin
  • 126,100
  • 9
  • 70
  • 144
Vamsee Bond
  • 163
  • 1
  • 11
  • I think it is not possible – Jens Jun 28 '17 at 07:18
  • 1
    Might be not possible. However please check with `encrypt/decrypt`. – ssr1012 Jun 28 '17 at 07:26
  • Using another user which only gives permission to execute the script (First user can see 0% of the code). https://stackoverflow.com/a/6905797/223226 – mpapec Jun 28 '17 at 11:44
  • This would be possible only if access to the file were restricted to a specific utility such as a web browser. Changing the behaviour of Notepad depending on who opens the file is impossible. Have you considered having two versions of each file, with non-privileged users having no access to the complete code files at all? – Borodin Jun 28 '17 at 12:56
  • 1
    Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. – jww Jun 28 '17 at 17:49

2 Answers2

5

It's impossible to give access to parts of a file to a certain group of users.

It seems that you need to rethink your security policies. What is in the sections of the file that you don't want most people to see? Perhaps it's not appropriate for that information to be in the file at all?

The most obvious approach to fixing this is to remove the secret code from the file and to store it in a separate module. You can then adjust the permissions of the module so that only the correct people can see it.

It is, however, important to note that a user needs to be able to read a file in order to execute that file. If a particular user cannot read a module that is required by a program, then that user will not be able to run that program.

This is a restriction that is inherent in programming languages like Perl where there is no "compiled" version of the code that you can share. People need to be able to read the source code in order to run the program.

If that's a problem for you, then perhaps Perl is not the right language for this project.

Dave Cross
  • 68,119
  • 3
  • 51
  • 97
  • 1
    Funnily, for _binaries_ it's possible to give them `chmod a=x`, i.e. make them executable but not readable. Unfortunately for the OP, this doesn't work with scripts. – PerlDuck Jun 28 '17 at 09:56
-3

Maybe You can try to adapt/relax your needs with some perl source filter and encoding the source with base64 or some similar tool.

ulix
  • 274
  • 1
  • 2
  • 13